From 62589d7003946e04355a9a8c7e2f9088e88bffa7 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Sun, 24 Feb 2019 03:33:33 -0500 Subject: [PATCH] Decompiled more, ported asmdiff to powershell --- asm/pokenav.s | 197 -------------------------------------------------- asmdiff.ps1 | 4 + src/pokenav.c | 138 ++++++++++++++++++++++++++++++++--- 3 files changed, 132 insertions(+), 207 deletions(-) create mode 100644 asmdiff.ps1 diff --git a/asm/pokenav.s b/asm/pokenav.s index e17cff277..73a3b8241 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -5,203 +5,6 @@ .text - thumb_func_start sub_81C8254 -sub_81C8254: @ 81C8254 - push {r4,lr} - adds r4, r0, 0 - bl IsDma3ManagerBusyWithBgCopy - lsls r0, 24 - cmp r0, 0 - bne _081C82C0 - movs r0, 0x11 - bl GetSubstructPtr - adds r2, r0, 0 - cmp r4, 0x4 - bhi _081C82D6 - lsls r0, r4, 2 - ldr r1, =_081C827C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081C827C: - .4byte _081C8290 - .4byte _081C829A - .4byte _081C82A4 - .4byte _081C82B8 - .4byte _081C82CC -_081C8290: - adds r0, r2, 0 - bl sub_81C82E4 - movs r0, 0 - b _081C82D8 -_081C829A: - adds r0, r2, 0 - bl sub_81C835C - movs r0, 0 - b _081C82D8 -_081C82A4: - ldr r1, =0x00000888 - adds r0, r2, r1 - adds r1, r2, 0 - bl sub_81C837C - movs r0, 0 - b _081C82D8 - .pool -_081C82B8: - bl sub_81C83E0 - cmp r0, 0 - beq _081C82C4 -_081C82C0: - movs r0, 0x2 - b _081C82D8 -_081C82C4: - bl sub_81C8ED0 - movs r0, 0x1 - b _081C82D8 -_081C82CC: - ldr r1, =0x00000888 - adds r0, r2, r1 - adds r1, r2, 0 - bl sub_81C8EF8 -_081C82D6: - movs r0, 0x4 -_081C82D8: - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81C8254 - - thumb_func_start sub_81C82E4 -sub_81C82E4: @ 81C82E4 - push {r4,r5,lr} - sub sp, 0x8 - adds r5, r0, 0 - ldrb r4, [r5, 0x1] - lsls r4, 12 - ldrh r0, [r5, 0x6] - orrs r4, r0 - lsls r4, 16 - lsrs r4, 16 - ldrb r0, [r5] - ldrh r2, [r5, 0x6] - movs r1, 0x11 - movs r3, 0x1 - bl sub_8199DF0 - ldrb r0, [r5] - ldrh r2, [r5, 0x6] - adds r2, 0x1 - movs r1, 0x44 - movs r3, 0x1 - bl sub_8199DF0 - ldrb r0, [r5] - adds r1, r5, 0 - adds r1, 0x88 - bl SetBgTilemapBuffer - ldrb r0, [r5] - movs r1, 0x20 - str r1, [sp] - str r1, [sp, 0x4] - adds r1, r4, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - ldrb r0, [r5] - movs r1, 0 - movs r2, 0 - bl ChangeBgY - ldrb r0, [r5] - movs r1, 0 - movs r2, 0 - bl ChangeBgX - ldrb r0, [r5] - ldrb r1, [r5, 0x3] - lsls r1, 11 - movs r2, 0x2 - bl ChangeBgY - ldrb r0, [r5] - bl CopyBgTilemapBufferToVram - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_81C82E4 - - thumb_func_start sub_81C835C -sub_81C835C: @ 81C835C - push {r4,lr} - adds r4, r0, 0 - ldrb r0, [r4, 0x8] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldrb r0, [r4, 0x8] - bl PutWindowTilemap - ldrb r0, [r4, 0x8] - movs r1, 0x1 - bl CopyWindowToVram - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_81C835C - - thumb_func_start sub_81C837C -sub_81C837C: @ 81C837C - push {r4,r5,lr} - sub sp, 0x8 - adds r3, r0, 0 - adds r5, r1, 0 - ldrh r0, [r3, 0x2] - ldrh r4, [r3] - subs r2, r0, r4 - ldrh r0, [r3, 0x8] - cmp r2, r0 - ble _081C8392 - adds r2, r0, 0 -_081C8392: - ldr r0, [r3, 0x10] - ldr r3, [r3, 0xC] - movs r1, 0 - str r1, [sp] - str r5, [sp, 0x4] - adds r1, r4, 0 - bl sub_81C83AC - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_81C837C - - thumb_func_start sub_81C83AC -sub_81C83AC: @ 81C83AC - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - ldr r1, [sp, 0x10] - cmp r2, 0 - beq _081C83D6 - adds r0, r5, 0 - muls r0, r3 - adds r0, r4, r0 - str r0, [r1, 0x1C] - str r3, [r1, 0x18] - movs r0, 0 - strh r0, [r1, 0xC] - strh r2, [r1, 0xE] - str r5, [r1, 0x14] - ldr r0, [sp, 0xC] - str r0, [r1, 0x10] - ldr r0, =sub_81C83F0 - movs r1, 0x5 - bl sub_81C7078 -_081C83D6: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81C83AC - thumb_func_start sub_81C83E0 sub_81C83E0: @ 81C83E0 push {lr} diff --git a/asmdiff.ps1 b/asmdiff.ps1 new file mode 100644 index 000000000..17a8cb8e8 --- /dev/null +++ b/asmdiff.ps1 @@ -0,0 +1,4 @@ +$objdump = Join-Path -Path "$($args[0])" -ChildPath "bin\objdump.exe" +&$objdump -D -bbinary -marmv4t -Mforce-thumb --start-address="$($args[1])" --stop-address="$($args[2])" .\baserom.gba > .\baserom.dump +&$objdump -D -bbinary -marmv4t -Mforce-thumb --start-address="$($args[1])" --stop-address="$($args[2])" .\pokeemerald.gba > .\pokeemerald.dump +Compare-Object (Get-Content .\baserom.dump) (Get-Content .\pokeemerald.dump) diff --git a/src/pokenav.c b/src/pokenav.c index ce8606f0d..cb7e2463e 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -28,18 +28,32 @@ enum #define UNKNOWN_OFFSET 100000 -// Sizes based tentatively on loads and stores in sub_81C9160 struct UnknownSubSubStruct_0203CF40 { - u16 unk0; - u16 unk2; + u8 bg; + u8 unk1; + u8 unk2; + u8 unk3; u16 unk4; u16 unk6; u8 windowId; u8 unk9; u16 unkA; u16 unkC; + u16 unkE; }; +struct UnknownSubSubStruct_81C81D4 { + u16 unk0; + u16 unk2; + u16 unk4; + u16 unk6; + u16 unk8; + u16 unkA; + u32 unkC; + u32 unk10; +}; + +// Generally at index 0. struct UnknownSubStruct_0203CF40 { void (*unk0)(u32); @@ -54,12 +68,18 @@ struct UnknownSubStruct_0203CF40 u8 tilemapBuffer[0x800]; }; +// Generally at index 0x11 (17) struct UnknownSubStruct_81C81D4 { struct UnknownSubSubStruct_0203CF40 unk0; - u8 unkE[0x878]; - struct UnknownSubSubStruct_0203CF40 unk888; - u8 unk898[0xC]; + u32 unk10; + u32 unk14; + u32 unk18; + u32 unk1C; + u8 unk20[0x68]; + u8 tilemapBuffer[0x800]; + struct UnknownSubSubStruct_81C81D4 unk888; + u8 unk898[0x6]; }; #define SUBSTRUCT_COUNT 19 @@ -138,9 +158,17 @@ extern u32 sub_81D09F4(void); extern u32 sub_81CFA04(void); extern u32 sub_81CFE08(void); extern u32 sub_81C91AC(struct UnknownSubStruct_81C81D4 *a0, const void *a1, void *a2, s32 a3); -extern u32 sub_81C9160(struct UnknownSubSubStruct_0203CF40 *a0, void *a1); -extern u32 sub_81C8254(s32); +extern u32 sub_81C9160(struct UnknownSubSubStruct_81C81D4 *a0, void *a1); +extern u32 sub_81C83E0(void); +extern void sub_81C8ED0(void); +extern void sub_81C8EF8(struct UnknownSubSubStruct_81C81D4 *a0, struct UnknownSubSubStruct_0203CF40 *a1); +extern u32 sub_81C83F0(s32); +void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownSubStruct_81C81D4 *a5); +void sub_81C837C(struct UnknownSubSubStruct_81C81D4 *a0, struct UnknownSubStruct_81C81D4 *a1); +void sub_81C835C(struct UnknownSubSubStruct_0203CF40 *a0); +void sub_81C82E4(struct UnknownSubStruct_81C81D4 *a0); +u32 sub_81C8254(s32); u32 sub_81C791C(s32 a0); bool32 sub_81C756C(u32 a0); bool32 sub_81C76C4(void); @@ -1468,15 +1496,105 @@ bool32 sub_81C81D4(const void *arg0, void *arg1, s32 arg2) return TRUE; } -bool32 sub_81C8224(void) { +bool32 sub_81C8224(void) +{ return sub_81C7124(sub_81C8254); } -void sub_81C8234(void) { +void sub_81C8234(void) +{ struct UnknownSubStruct_81C81D4 *structPtr; structPtr = GetSubstructPtr(0x11); sub_81C8FE0(); RemoveWindow(structPtr->unk0.windowId); FreeSubstruct(0x11); +} + +u32 sub_81C8254(s32 a0) +{ + struct UnknownSubStruct_81C81D4 *structPtr; + + if (IsDma3ManagerBusyWithBgCopy()) + return 2; + + structPtr = GetSubstructPtr(0x11); + + switch (a0) + { + case 0: + sub_81C82E4(structPtr); + return 0; + case 1: + sub_81C835C(&structPtr->unk0); + return 0; + case 2: + sub_81C837C(&structPtr->unk888, structPtr); + return 0; + case 3: + if (sub_81C83E0()) + { + return 2; + } + else + { + sub_81C8ED0(); + return 1; + } + case 4: + sub_81C8EF8(&structPtr->unk888, &structPtr->unk0); + return 4; + default: + return 4; + } +} + +void sub_81C82E4(struct UnknownSubStruct_81C81D4 *a0) +{ + u16 v1 = (a0->unk0.unk1 << 12) | a0->unk0.unk6; + // TODO: When #553 is merged, use a PALETTE_NUM_TO_FILL_VALUE(1) macro here... + sub_8199DF0(a0->unk0.bg, 0x11, a0->unk0.unk6, 1); + // ...and PALETTE_NUM_TO_FILL_VALUE(4) here. + sub_8199DF0(a0->unk0.bg, 0x44, a0->unk0.unk6 + 1, 1); + SetBgTilemapBuffer(a0->unk0.bg, a0->tilemapBuffer); + FillBgTilemapBufferRect_Palette0(a0->unk0.bg, v1, 0, 0, 32, 32); + ChangeBgY(a0->unk0.bg, 0, 0); + ChangeBgX(a0->unk0.bg, 0, 0); + ChangeBgY(a0->unk0.bg, a0->unk0.unk3 << 11, 2); + CopyBgTilemapBufferToVram(a0->unk0.bg); +} + +void sub_81C835C(struct UnknownSubSubStruct_0203CF40 *a0) +{ + // TODO: When #553 is merged, use a PALETTE_NUM_TO_FILL_VALUE(1) macro here. + FillWindowPixelBuffer(a0->windowId, 0x11); + PutWindowTilemap(a0->windowId); + CopyWindowToVram(a0->windowId, 1); +} + +void sub_81C837C(struct UnknownSubSubStruct_81C81D4 *a0, struct UnknownSubStruct_81C81D4 *a1) +{ + s32 v1; + s32 v2; + + // TODO: Clean this up. + v1 = a0->unk2 - a0->unk0; + v2 = a0->unk8; + if (v1 > a0->unk8) + v1 = v2; + sub_81C83AC(a0->unk10, a0->unk0, v1, a0->unkC, 0, a1); +} + +void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownSubStruct_81C81D4 *a5) +{ + if (a2 == 0) + return; + + a5->unk1C = a0 + a1 * a3; + a5->unk18 = a3; + a5->unk0.unkC = 0; + a5->unk0.unkE = a2; + a5->unk14 = a1; + a5->unk10 = a4; + sub_81C7078(sub_81C83F0, 5); } \ No newline at end of file