Shorten QFT

This commit is contained in:
sup39 2022-04-21 23:54:05 +09:00
parent d0cf826395
commit d9bb06f3ba
9 changed files with 92 additions and 112 deletions

View file

@ -1236,12 +1236,14 @@
</source>
</code>
<code>
<id>qft</id>
<category>timer</category>
<title lang="en-US">Quarterframe Timer (Experimental)</title>
<title lang="ja-JP">QFタイマー</title>
<author>Noki Doki, sup39(サポミク)</author>
<version>0.5</version>
<date>Nov 28, 2021</date>
<dependencies version="GMSJ01">drawText</dependencies>
<description lang="en-US">
Adds an in-game timer to every level, starting on the last black frame after the
loading screen and ending as soon as the 'Shine Get' animation starts

View file

@ -51,7 +51,8 @@ Some codes store some states in the games memory starting from address 0x817F000
| ![](./docs/buffer.svg) | `0x10D` | `0x10F` | Buffer (Ingame Timer) |
| ![](./docs/reserved.svg) | `0x110` | `0x237` | QF Timer: Timer Textbox |
| ![](./docs/reserved.svg) | `0x238` | `0x347` | General Function (`drawText`) |
| ![](./docs/unallocated.svg) | `0x348` | `0xFFF` | Not Allocated |
| ![](./docs/buffer.svg) | `0x348` | `0x3BF` | Buffer (QF Timer) |
| ![](./docs/unallocated.svg) | `0x3C0` | `0xFFF` | Not Allocated |
### Adding translations

View file

@ -1,5 +1,9 @@
# Changelog
## Apr 21, 2022
### Shortened QFT
- Shortened QFT's freeze code by replacing C2 with 04(bl@event) and 07.
- Reserve `817F0348`~`817F03BF` (120 bytes)
### Reduced code size of Pattern Selector
Reduce 240 bytes of PS by replacing switch case with lookup table.

View file

@ -1,19 +1,9 @@
export const freezeCodegen = {
redCoin: (s) => `
C21BE474 00000004
80AD9FB8 8005005C
3CA0817F 900500B8
3800${s} 900500BC
38A00000 00000000
`,
blueCoin: (s) => `
C21BE288 00000005
7C030378 80A3005C
38A50003 54A0003A
3CA0817F 900500B8
3800${s} 900500BC
60000000 00000000
`,
/**
* @type {{[key: string]: [addr: number, orig: number]}}
*/
export const freezeCodeInfo = {
redCoin: [0x801be474, 0x38a00000],
blueCoin: [0x801be288, 0x7c030378], // TODO QF+3 &0xfffffffc
};
export const baseCode = `

View file

@ -1,61 +1,15 @@
export const freezeCodegen = {
yellowCoin: (s) => `
C2196B54 00000004
806d97e8 8083005c
3c60817f 908300b8
3880${s} 908300bc
8805000E 00000000
`,
redCoin: (s) => `
C2196314 00000004
80AD97E8 8005005C
3CA0817F 900500B8
3800${s} 900500BC
38A00000 00000000
`,
blueCoin: (s) => `
C2196128 00000005
7C030378 80A3005C
38A50003 54A0003A
3CA0817F 900500B8
3800${s} 900500BC
60000000 00000000
`,
item: (s) => `
C21971F8 00000004
806d97e8 8083005c
3c60817f 908300b8
3880${s} 908300bc
8001001C 00000000
`,
talk: (s) => `
C20EB6E4 00000004
807f005c 3c80817f
906400b8 3860${s}
906400bc 60000000
807f00b0 00000000
`,
demo: (s) => `
C20EB74C 00000004
807f005c 3c80817f
906400b8 3860${s}
906400bc 60000000
806DA8B0 00000000
`,
cleaned: (s) => `
C217A3C0 00000004
806d97e8 8083005c
3c60817f 908300b8
3880${s} 908300bc
80010044 00000000
`,
bowser: (s) => `
C21D3C78 00000004
806d97e8 8083005c
3c60817f 908300b8
3880${s} 908300bc
2c1d0003 00000000
`,
/**
* @type {{[key: string]: [addr: number, orig: number]}}
*/
export const freezeCodeInfo = {
yellowCoin: [0x80196b54, 0x8805000e],
redCoin: [0x80196314, 0x38a00000],
blueCoin: [0x80196128, 0x7c030378], // TODO QF+3 &0xfffffffc
item: [0x801971f8, 0x8001001c],
talk: [0x800eb6e4, 0x807f00b0],
demo: [0x800eb74c, 0x806da8b0],
cleaned: [0x8017a3c0, 0x80010044],
bowser: [0x801d3c78, 0x2c1d0003],
};
export const baseCode = `

View file

@ -1,19 +1,9 @@
export const freezeCodegen = {
redCoin: (s) => `
C219E1FC 00000004
80AD9E78 8005005C
3CA0817F 900500B8
3800${s} 900500BC
38A00000 00000000
`,
blueCoin: (s) => `
C219E010 00000005
7C030378 80A3005C
38A50003 54A0003A
3CA0817F 900500B8
3800${s} 900500BC
60000000 00000000
`,
/**
* @type {{[key: string]: [addr: number, orig: number]}}
*/
export const freezeCodeInfo = {
redCoin: [0x8019e1fc, 0x38a00000],
blueCoin: [0x8019e010, 0x7c030378], // TODO QF+3 &0xfffffffc
};
export const baseCode = `

View file

@ -1,19 +1,9 @@
export const freezeCodegen = {
redCoin: (s) => `
C21B632C 00000004
80AD9EE0 8005005C
3CA0817F 900500B8
3800${s} 900500BC
38A00000 00000000
`,
blueCoin: (s) => `
C21B6140 00000005
7C030378 80A3005C
38A50003 54A0003A
3CA0817F 900500B8
3800${s} 900500BC
60000000 00000000
`,
/**
* @type {{[key: string]: [addr: number, orig: number]}}
*/
export const freezeCodeInfo = {
redCoin: [0x801b632c, 0x38a00000],
blueCoin: [0x801b6140, 0x7c030378], // TODO QF+3 &0xfffffffc
};
export const baseCode = `

View file

@ -45,17 +45,66 @@ import * as GMSP01 from './code/GMSP01.js';
import * as GMSJ0A from './code/GMSJ0A.js';
export const codes = { GMSJ01, GMSE01, GMSP01, GMSJ0A };
/****
## save freeze frame, load and save QF
## this function destroys r11(freeze frame), r12
077F0348:
lis r12, 0x817F
stw r11, 0xBC(r12)
lwz r11, -0x6818(r13)
lwz r11, 0x5C(r11)
stw r11, 0xB8(r12)
blr
## for each code
ORIG
li r11, xxxx
b 817f0348
04xxxxxx:
bl 817fxxxx
****/
const freezeCodeAddr = 0x817f0348;
const freezeCode = [0x3d80817f, 0x916c00bc, 0x816d97e8, 0x816b005c, 0x916c00b8, 0x4e800020];
export default function codegen(version) {
const config = getConfig();
const { freezeCodegen, baseCode } = codes[version] ?? {};
const { freezeCodeInfo, baseCode } = codes[version] ?? {};
if (baseCode == null) return '';
let code = baseCode;
// freeze code
Object.entries(config.freeze).forEach(
([key, frame]) => (code += frame > 0 ? freezeCodegen[key]?.(int16(frame)) ?? '' : ''),
const code04 = [];
const code07 = [...freezeCode];
let dst = freezeCodeAddr + 24;
for (const [key, frame] of Object.entries(config.freeze)) {
const info = freezeCodeInfo[key];
if (frame > 0 && info) {
const [addr, orig] = info;
code07.push(
orig, // [dst] original instruction
0x39600000 | (frame & 0xffff), // li r11, $frame
0x4c000000 + (freezeCodeAddr - dst - 8), // b freezeCode
);
code04.push(
0x04000000 | (addr & 0x1ffffff), // 04xxxxxx
0x48000001 | (dst - addr), // bl
);
dst += 12;
}
}
if (code04.length) {
code07.unshift(
0x06000000 | (freezeCodeAddr & 0x1ffffff), // 07xxxxxx
code07.length * 4,
);
if (code07.length & 1) {
// odd -> add 0
code07.push(0);
}
code += [...code04, ...code07].map(int32).join('');
}
// ui (GMSJ01 only)
if (['GMSJ01'].includes(version)) {

View file

@ -99,7 +99,7 @@ export default {
fgRGB, fgA, fgRGB2, fgA2, bgRGB, bgA,
freeze,
// const
freezeKeys: Object.keys(codes[this.version]?.freezeCodegen ?? {}),
freezeKeys: Object.keys(codes[this.version]?.freezeCodeInfo ?? {}),
};
},
computed: {