From d9bb06f3bac1272bdb5e1cff0d5521b02757cf03 Mon Sep 17 00:00:00 2001 From: sup39 Date: Thu, 21 Apr 2022 23:54:05 +0900 Subject: [PATCH] Shorten QFT --- Codes.xml | 2 + Readme.md | 3 +- changelog.md | 4 ++ .../components/codes/qft/code/GMSE01.js | 22 ++---- .../components/codes/qft/code/GMSJ01.js | 70 ++++--------------- .../components/codes/qft/code/GMSJ0A.js | 22 ++---- .../components/codes/qft/code/GMSP01.js | 22 ++---- .../.vuepress/components/codes/qft/codegen.js | 57 +++++++++++++-- .../.vuepress/components/codes/qft/config.vue | 2 +- 9 files changed, 92 insertions(+), 112 deletions(-) diff --git a/Codes.xml b/Codes.xml index ac8e9ac..3513843 100644 --- a/Codes.xml +++ b/Codes.xml @@ -1236,12 +1236,14 @@ + qft timer Quarterframe Timer (Experimental) QFタイマー Noki Doki, sup39(サポミク) 0.5 Nov 28, 2021 + drawText 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 diff --git a/Readme.md b/Readme.md index 6fd7854..af3c021 100644 --- a/Readme.md +++ b/Readme.md @@ -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 diff --git a/changelog.md b/changelog.md index 8a9b6ba..b5b665f 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/site/.vuepress/components/codes/qft/code/GMSE01.js b/site/.vuepress/components/codes/qft/code/GMSE01.js index 3276a98..5c40295 100644 --- a/site/.vuepress/components/codes/qft/code/GMSE01.js +++ b/site/.vuepress/components/codes/qft/code/GMSE01.js @@ -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 = ` diff --git a/site/.vuepress/components/codes/qft/code/GMSJ01.js b/site/.vuepress/components/codes/qft/code/GMSJ01.js index 3447ee5..73c2808 100644 --- a/site/.vuepress/components/codes/qft/code/GMSJ01.js +++ b/site/.vuepress/components/codes/qft/code/GMSJ01.js @@ -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 = ` diff --git a/site/.vuepress/components/codes/qft/code/GMSJ0A.js b/site/.vuepress/components/codes/qft/code/GMSJ0A.js index f1a6e43..b0f88b3 100644 --- a/site/.vuepress/components/codes/qft/code/GMSJ0A.js +++ b/site/.vuepress/components/codes/qft/code/GMSJ0A.js @@ -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 = ` diff --git a/site/.vuepress/components/codes/qft/code/GMSP01.js b/site/.vuepress/components/codes/qft/code/GMSP01.js index 381dd49..c4cc33b 100644 --- a/site/.vuepress/components/codes/qft/code/GMSP01.js +++ b/site/.vuepress/components/codes/qft/code/GMSP01.js @@ -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 = ` diff --git a/site/.vuepress/components/codes/qft/codegen.js b/site/.vuepress/components/codes/qft/codegen.js index ceae46e..c0cf8f9 100644 --- a/site/.vuepress/components/codes/qft/codegen.js +++ b/site/.vuepress/components/codes/qft/codegen.js @@ -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)) { diff --git a/site/.vuepress/components/codes/qft/config.vue b/site/.vuepress/components/codes/qft/config.vue index 5e58a3e..675e3f8 100644 --- a/site/.vuepress/components/codes/qft/config.vue +++ b/site/.vuepress/components/codes/qft/config.vue @@ -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: {