From 9a80b550f0adc7faad4a323f3c7baeb2f9de6102 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Wed, 15 Feb 2017 16:25:21 -0500 Subject: [PATCH] finish decompiling main.c (#17) * partially decompile battle_ai.c up to tai60_unk * nonmatching tai60_unk * decompile more of battle_ai.c * formatting * finish porting battle_ai.c * formatting * decompile up to nonmatching VBlankIntr * finish decompiling main.c * formatting --- asm/berry_blender.s | 14 +- asm/cable_club.s | 12 +- asm/contest_link_80FC4F4.s | 2 +- asm/crt0.s | 2 +- asm/evolution_scene.s | 4 +- asm/link.s | 78 +++--- asm/main.s | 505 ------------------------------------- asm/naming_screen.s | 2 +- asm/pokedex_cry_screen.s | 2 +- asm/record_mixing.s | 6 +- asm/rom3.s | 4 +- asm/rom4.s | 18 +- asm/rom5.s | 2 +- asm/rom6.s | 2 +- asm/rom_8034C54.s | 28 +- asm/rom_80C6FA0.s | 2 +- asm/rom_8158B30.s | 6 +- asm/rom_81BAD84.s | 10 +- asm/start_menu.s | 2 +- asm/trade.s | 28 +- asm/trainer_card.s | 2 +- ld_script.txt | 1 - src/main.c | 196 +++++++++++--- sym_common.txt | 23 +- 24 files changed, 288 insertions(+), 663 deletions(-) delete mode 100644 asm/main.s diff --git a/asm/berry_blender.s b/asm/berry_blender.s index 16c04e024..78cd941cc 100644 --- a/asm/berry_blender.s +++ b/asm/berry_blender.s @@ -516,7 +516,7 @@ _0807FBBE: ldrb r0, [r0] cmp r0, 0 beq _0807FC14 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0807FC14 @@ -1122,7 +1122,7 @@ _08080126: bne _0808016A b _080804F8 _0808016A: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08080174 @@ -3334,7 +3334,7 @@ sub_80814B0: @ 80814B0 ldrb r0, [r0] cmp r0, 0 beq _080814E4 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080814E4 @@ -4706,7 +4706,7 @@ sub_8081F94: @ 8081F94 ldrb r0, [r0] cmp r0, 0 beq _08081FB8 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08081FB8 @@ -4852,7 +4852,7 @@ _080820EC: ldrb r0, [r0] cmp r0, 0 beq _0808218C - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0808218C @@ -4968,7 +4968,7 @@ _080821D4: ldrb r0, [r0] cmp r0, 0 beq _08082254 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08082254 @@ -6250,7 +6250,7 @@ sub_8082D28: @ 8082D28 lsls r0, 24 lsrs r1, r0, 24 _08082D3C: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08082DCC diff --git a/asm/cable_club.s b/asm/cable_club.s index cde4bf865..f08e56d8e 100644 --- a/asm/cable_club.s +++ b/asm/cable_club.s @@ -2172,7 +2172,7 @@ sub_80B360C: @ 80B360C movs r5, 0x1 eors r0, r5 bl sub_813C2A0 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080B36B2 @@ -2512,7 +2512,7 @@ _080B391C: thumb_func_start sub_80B3924 sub_80B3924: @ 80B3924 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080B3940 @@ -2552,7 +2552,7 @@ sub_80B3968: @ 80B3968 ldr r2, =0x00002211 adds r0, r2, 0 strh r0, [r1] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080B3994 @@ -2661,7 +2661,7 @@ _080B3A62: ldrb r0, [r0] cmp r0, 0 beq _080B3AA6 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080B3AA0 @@ -2752,7 +2752,7 @@ _080B3B20: beq _080B3B9E b _080B3BB8 _080B3B2A: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080B3B40 @@ -2825,7 +2825,7 @@ _080B3BB8: thumb_func_start sub_80B3BC4 sub_80B3BC4: @ 80B3BC4 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080B3BD6 diff --git a/asm/contest_link_80FC4F4.s b/asm/contest_link_80FC4F4.s index be38d0d16..d3984fb0d 100644 --- a/asm/contest_link_80FC4F4.s +++ b/asm/contest_link_80FC4F4.s @@ -147,7 +147,7 @@ sub_80FC5DC: @ 80FC5DC ldr r1, =gUnknown_02039F2A movs r0, 0x1 strb r0, [r1] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _080FC60C diff --git a/asm/crt0.s b/asm/crt0.s index a65ae1b7e..14675fe4c 100644 --- a/asm/crt0.s +++ b/asm/crt0.s @@ -128,7 +128,7 @@ IntrMain_FoundIntr: bic r3, r3, PSR_I_BIT | PSR_F_BIT | PSR_MODE_MASK orr r3, r3, PSR_SYS_MODE msr cpsr_cf, r3 - ldr r1, =gUnknown_03002710 + ldr r1, =gIntrTable add r1, r1, r12 ldr r0, [r1] stmdb sp!, {lr} diff --git a/asm/evolution_scene.s b/asm/evolution_scene.s index 93d8bd2a2..dd6b9c3c4 100644 --- a/asm/evolution_scene.s +++ b/asm/evolution_scene.s @@ -756,7 +756,7 @@ _0813E0F0: b _0813E1C8 .pool _0813E160: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0813E174 @@ -3359,7 +3359,7 @@ _0813FA24: beq _0813FA32 b _0813FCC4 _0813FA32: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0813FA3E diff --git a/asm/link.s b/asm/link.s index 198807457..4644d9f4a 100644 --- a/asm/link.s +++ b/asm/link.s @@ -387,7 +387,7 @@ _08009726: thumb_func_start sub_8009734 sub_8009734: @ 8009734 push {r4-r6,lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r4, [r0] cmp r4, 0 bne _080097A8 @@ -451,7 +451,7 @@ sub_80097E8: @ 80097E8 ldr r0, =gUnknown_03003124 movs r4, 0 strb r4, [r0] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080097FC @@ -1278,7 +1278,7 @@ _08009F06: thumb_func_start sub_8009F18 sub_8009F18: @ 8009F18 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08009F26 @@ -1295,7 +1295,7 @@ _08009F26: thumb_func_start sub_8009F3C sub_8009F3C: @ 8009F3C push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08009F50 @@ -1336,7 +1336,7 @@ _08009F80: thumb_func_start sub_8009F8C sub_8009F8C: @ 8009F8C push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r1, [r0] cmp r1, 0 beq _08009FA0 @@ -1355,7 +1355,7 @@ _08009FA4: thumb_func_start sub_8009FAC sub_8009FAC: @ 8009FAC push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r1, [r0] cmp r1, 0 beq _08009FC0 @@ -1374,7 +1374,7 @@ _08009FC4: thumb_func_start sub_8009FCC sub_8009FCC: @ 8009FCC push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08009FEC @@ -1934,7 +1934,7 @@ sub_800A418: @ 800A418 ldr r1, =gUnknown_020223C0 movs r0, 0 str r0, [r1] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0800A438 @@ -1972,7 +1972,7 @@ sub_800A458: @ 800A458 thumb_func_start link_get_multiplayer_id link_get_multiplayer_id: @ 800A468 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 beq _0800A484 @@ -2014,7 +2014,7 @@ link_0800A448: @ 800A4AC adds r3, r1, 0 lsls r2, 16 lsrs r1, r2, 16 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 beq _0800A4C8 @@ -2038,7 +2038,7 @@ sub_800A4D8: @ 800A4D8 lsls r0, 24 lsrs r1, r0, 24 adds r2, r1, 0 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800A4F8 @@ -2071,7 +2071,7 @@ _0800A514: thumb_func_start sub_800A520 sub_800A520: @ 800A520 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800A538 @@ -2098,7 +2098,7 @@ _0800A546: thumb_func_start sub_800A550 sub_800A550: @ 800A550 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 beq _0800A57C @@ -2129,7 +2129,7 @@ sub_800A588: @ 800A588 push {lr} lsls r0, 24 lsrs r1, r0, 24 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800A5A4 @@ -2151,7 +2151,7 @@ _0800A5AC: thumb_func_start sub_800A5B4 sub_800A5B4: @ 800A5B4 push {r4,lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800A5D4 @@ -2186,7 +2186,7 @@ sub_800A5EC: @ 800A5EC push {lr} lsls r0, 24 lsrs r1, r0, 24 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800A608 @@ -2932,7 +2932,7 @@ sub_800ABAC: @ 800ABAC thumb_func_start sub_800ABBC sub_800ABBC: @ 800ABBC push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _0800ABDC @@ -2965,7 +2965,7 @@ sub_800ABF4: @ 800ABF4 push {lr} lsls r0, 16 lsrs r3, r0, 16 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800AC0C @@ -2992,7 +2992,7 @@ _0800AC20: thumb_func_start sub_800AC34 sub_800AC34: @ 800AC34 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800AC48 @@ -3090,7 +3090,7 @@ _0800ACF4: thumb_func_start sub_800AD10 sub_800AD10: @ 800AD10 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800AD24 @@ -3194,7 +3194,7 @@ _0800ADDA: thumb_func_start sub_800ADF8 sub_800ADF8: @ 800ADF8 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _0800AE0C @@ -3361,7 +3361,7 @@ c2_800ACD4: @ 800AF30 bl rboxid_80040B8 bl ResetTasks bl remove_some_task - ldr r1, =gUnknown_030030FC + ldr r1, =gLinkVSyncDisabled ldrb r0, [r1] cmp r0, 0 beq _0800AF8C @@ -3615,7 +3615,7 @@ _0800B20C: bl audio_play b _0800B260 _0800B214: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x2 bne _0800B244 @@ -3654,7 +3654,7 @@ _0800B260: ldrb r1, [r1] cmp r1, 0xA0 bne _0800B2D0 - ldr r4, =gUnknown_030030FC + ldr r4, =gLinkVSyncDisabled ldrb r2, [r4] cmp r2, 0x1 bne _0800B2A8 @@ -3856,7 +3856,7 @@ _0800B3F4: thumb_func_start HandleLinkConnection HandleLinkConnection: @ 800B40C push {r4,r5,lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _0800B45C @@ -3911,7 +3911,7 @@ sub_800B488: @ 800B488 ldrb r0, [r0] cmp r0, 0 bne _0800B498 - ldr r1, =gUnknown_030030FC + ldr r1, =gLinkVSyncDisabled movs r0, 0x1 strb r0, [r1] _0800B498: @@ -3927,7 +3927,7 @@ sub_800B4A4: @ 800B4A4 ldrb r1, [r0] cmp r1, 0 bne _0800B4B2 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled strb r1, [r0] _0800B4B2: pop {r0} @@ -3942,7 +3942,7 @@ sub_800B4C0: @ 800B4C0 ldrb r1, [r0] cmp r1, 0 bne _0800B4CE - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled strb r1, [r0] _0800B4CE: pop {r0} @@ -3953,7 +3953,7 @@ _0800B4CE: thumb_func_start sub_800B4DC sub_800B4DC: @ 800B4DC push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _0800B4FC @@ -3987,7 +3987,7 @@ _0800B514: thumb_func_start sub_800B518 sub_800B518: @ 800B518 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] bx lr .pool @@ -9900,7 +9900,7 @@ sub_800E3A8: @ 800E3A8 mov r5, r8 push {r5-r7} sub sp, 0x20 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _0800E3BE @@ -10274,7 +10274,7 @@ _0800E64A: thumb_func_start sub_800E6D0 sub_800E6D0: @ 800E6D0 push {r4-r6,lr} - ldr r4, =gUnknown_03002710 + ldr r4, =gIntrTable ldr r5, [r4, 0x4] ldr r6, [r4, 0x8] bl sub_800E700 @@ -10298,7 +10298,7 @@ sub_800E700: @ 800E700 push {r4,lr} ldr r0, =gUnknown_03004190 ldr r1, =0x00000e64 - ldr r4, =gUnknown_03002714 + ldr r4, =gIntrTable + 0x4 adds r2, r4, 0 movs r3, 0x1 bl rfu_initializeAPI @@ -14983,7 +14983,7 @@ sub_8010DB4: @ 8010DB4 cmp r0, 0 beq _08010DE4 _08010DDE: - ldr r1, =gUnknown_030030FC + ldr r1, =gLinkVSyncDisabled movs r0, 0x2 strb r0, [r1] _08010DE4: @@ -16561,13 +16561,13 @@ sub_8011AB0: @ 8011AB0 .pool thumb_func_end sub_8011AB0 - thumb_func_start rfu_syncVBlank__ -rfu_syncVBlank__: @ 8011ABC + thumb_func_start LinkVSync +LinkVSync: @ 8011ABC push {lr} bl rfu_syncVBlank_ pop {r0} bx r0 - thumb_func_end rfu_syncVBlank__ + thumb_func_end LinkVSync thumb_func_start sub_8011AC8 sub_8011AC8: @ 8011AC8 @@ -39668,7 +39668,7 @@ sub_801DD98: @ 801DD98 bl Alloc str r0, [r4] bl sub_801DDD0 - ldr r1, =gUnknown_030022B0 + ldr r1, =gKeyRepeatStartDelay movs r0, 0x14 strh r0, [r1] movs r0, 0 @@ -45490,7 +45490,7 @@ sub_8020C70: @ 8020C70 ldrb r0, [r0] cmp r0, 0 beq _08020C8E - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08020CAC diff --git a/asm/main.s b/asm/main.s deleted file mode 100644 index 3d02e3869..000000000 --- a/asm/main.s +++ /dev/null @@ -1,505 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start EnableVCountIntrAtLine150 -@ void EnableVCountIntrAtLine150() -EnableVCountIntrAtLine150: @ 8000594 - push {lr} - movs r0, 0x4 - bl GetGpuReg - movs r1, 0xFF - ands r1, r0 - movs r2, 0x96 - lsls r2, 8 - adds r0, r2, 0 - orrs r1, r0 - movs r0, 0x20 - orrs r1, r0 - movs r0, 0x4 - bl SetGpuReg - movs r0, 0x4 - bl EnableInterrupts - pop {r0} - bx r0 - thumb_func_end EnableVCountIntrAtLine150 - - thumb_func_start InitKeys -@ void InitKeypadData() -InitKeys: @ 80005BC - ldr r1, =gUnknown_030026FC - movs r0, 0x5 - strh r0, [r1] - ldr r1, =gUnknown_030022B0 - movs r0, 0x28 - strh r0, [r1] - ldr r1, =gMain - movs r0, 0 - strh r0, [r1, 0x2C] - strh r0, [r1, 0x2E] - strh r0, [r1, 0x30] - strh r0, [r1, 0x28] - strh r0, [r1, 0x2A] - bx lr - .pool - thumb_func_end InitKeys - - thumb_func_start ReadKeys -@ void ReadKeypad() -ReadKeys: @ 80005E4 - push {lr} - ldr r0, =0x04000130 - ldrh r1, [r0] - ldr r2, =0x000003ff - adds r0, r2, 0 - adds r3, r0, 0 - eors r3, r1 - ldr r1, =gMain - ldrh r2, [r1, 0x28] - adds r0, r3, 0 - bics r0, r2 - strh r0, [r1, 0x2A] - strh r0, [r1, 0x2E] - strh r0, [r1, 0x30] - adds r2, r1, 0 - cmp r3, 0 - beq _08000630 - ldrh r0, [r2, 0x2C] - cmp r0, r3 - bne _08000630 - ldrh r0, [r2, 0x32] - subs r0, 0x1 - strh r0, [r2, 0x32] - lsls r0, 16 - cmp r0, 0 - bne _08000636 - strh r3, [r2, 0x30] - ldr r0, =gUnknown_030026FC - b _08000632 - .pool -_08000630: - ldr r0, =gUnknown_030022B0 -_08000632: - ldrh r0, [r0] - strh r0, [r2, 0x32] -_08000636: - strh r3, [r2, 0x28] - strh r3, [r2, 0x2C] - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r0, [r0, 0x13] - cmp r0, 0x2 - bne _08000668 - ldrh r1, [r2, 0x2E] - movs r3, 0x80 - lsls r3, 2 - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - beq _08000658 - movs r0, 0x1 - orrs r0, r1 - strh r0, [r2, 0x2E] -_08000658: - ldrh r1, [r2, 0x2C] - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - beq _08000668 - movs r0, 0x1 - orrs r0, r1 - strh r0, [r2, 0x2C] -_08000668: - ldrh r1, [r2, 0x2E] - ldrh r0, [r2, 0x36] - ands r0, r1 - cmp r0, 0 - beq _08000676 - movs r0, 0x1 - strh r0, [r2, 0x34] -_08000676: - pop {r0} - bx r0 - .pool - thumb_func_end ReadKeys - - thumb_func_start InitIntrHandlers -@ void InitIntrHandlers() -InitIntrHandlers: @ 8000684 - push {r4,r5,lr} - ldr r5, =IntrMain - ldr r4, =gUnknown_03002750 - ldr r3, =gIntrTableTemplate - ldr r2, =gUnknown_03002710 - movs r1, 0xD -_08000690: - ldm r3!, {r0} - stm r2!, {r0} - subs r1, 0x1 - cmp r1, 0 - bge _08000690 - ldr r0, =0x040000d4 - str r5, [r0] - str r4, [r0, 0x4] - ldr r1, =0x84000200 - str r1, [r0, 0x8] - ldr r0, [r0, 0x8] - ldr r0, =gUnknown_03007FFC - str r4, [r0] - movs r0, 0 - bl SetVBlankCallback - movs r0, 0 - bl SetHBlankCallback - movs r0, 0 - bl SetSerialCallback - ldr r1, =0x04000208 - movs r0, 0x1 - strh r0, [r1] - movs r0, 0x1 - bl EnableInterrupts - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end InitIntrHandlers - - thumb_func_start SetVBlankCallback -@ void SetVBlankCallback(void ( *func)()) -SetVBlankCallback: @ 80006F0 - ldr r1, =gMain - str r0, [r1, 0xC] - bx lr - .pool - thumb_func_end SetVBlankCallback - - thumb_func_start SetHBlankCallback -@ void SetHBlankCallback(void ( *func)()) -SetHBlankCallback: @ 80006FC - ldr r1, =gMain - str r0, [r1, 0x10] - bx lr - .pool - thumb_func_end SetHBlankCallback - - thumb_func_start SetVCountCallback -@ void SetVCountCallback(void ( *func)()) -SetVCountCallback: @ 8000708 - ldr r1, =gMain - str r0, [r1, 0x14] - bx lr - .pool - thumb_func_end SetVCountCallback - - thumb_func_start RestoreSerialTimer3IntrHandlers -@ void RestoreSerialTimer3IntrHandlers() -RestoreSerialTimer3IntrHandlers: @ 8000714 - ldr r0, =gUnknown_03002710 - ldr r1, =SerialIntr - str r1, [r0, 0x4] - ldr r1, =Timer3Intr - str r1, [r0, 0x8] - bx lr - .pool - thumb_func_end RestoreSerialTimer3IntrHandlers - - thumb_func_start SetSerialCallback -@ void SetSerialCallback(void ( *func)()) -SetSerialCallback: @ 800072C - ldr r1, =gMain - str r0, [r1, 0x18] - bx lr - .pool - thumb_func_end SetSerialCallback - - thumb_func_start VBlankIntr -@ void VBlankIntr() -VBlankIntr: @ 8000738 - push {r4,lr} - ldr r0, =gUnknown_030030FC - ldrb r0, [r0] - cmp r0, 0 - beq _0800074C - bl rfu_syncVBlank__ - b _08000758 - .pool -_0800074C: - ldr r0, =gUnknown_03002748 - ldrb r0, [r0] - cmp r0, 0 - bne _08000758 - bl sub_800B9B8 -_08000758: - ldr r0, =gMain - ldr r1, [r0, 0x20] - adds r1, 0x1 - str r1, [r0, 0x20] - ldr r1, =gUnknown_0203CF5C - ldr r1, [r1] - adds r4, r0, 0 - cmp r1, 0 - beq _08000778 - ldr r2, [r1] - movs r0, 0x2 - negs r0, r0 - cmp r2, r0 - bhi _08000778 - adds r0, r2, 0x1 - str r0, [r1] -_08000778: - ldr r0, [r4, 0xC] - cmp r0, 0 - beq _08000782 - bl _call_via_r0 -_08000782: - ldr r0, [r4, 0x24] - adds r0, 0x1 - str r0, [r4, 0x24] - bl CopyBufferedValuesToGpuRegs - bl ProcessDma3Requests - ldr r1, =gUnknown_03002F50 - ldr r0, =gSoundInfo - ldrb r0, [r0, 0x4] - strb r0, [r1] - bl m4aSoundMain - bl sub_8033648 - ldr r1, =0x00000439 - adds r0, r4, r1 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _080007BA - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x013f0102 - ands r0, r1 - cmp r0, 0 - bne _080007BE -_080007BA: - bl Random -_080007BE: - bl sub_800E174 - ldr r2, =gUnknown_03007FF8 - ldrh r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strh r0, [r2] - ldr r0, =gMain - ldrh r2, [r0, 0x1C] - ldrh r3, [r0, 0x1C] - orrs r1, r2 - strh r1, [r0, 0x1C] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end VBlankIntr - - thumb_func_start StartFlashMemoryTimer -@ void StartFlashMemoryTimer() -StartFlashMemoryTimer: @ 8000800 - push {lr} - ldr r1, =gUnknown_0300272C - movs r0, 0x2 - bl SetFlashTimerIntr - pop {r0} - bx r0 - .pool - thumb_func_end StartFlashMemoryTimer - - thumb_func_start HBlankIntr -@ void HBlankIntr() -HBlankIntr: @ 8000814 - push {r4,lr} - ldr r4, =gMain - ldr r0, [r4, 0x10] - cmp r0, 0 - beq _08000822 - bl _call_via_r0 -_08000822: - ldr r2, =gUnknown_03007FF8 - ldrh r0, [r2] - movs r1, 0x2 - orrs r0, r1 - strh r0, [r2] - ldrh r0, [r4, 0x1C] - ldrh r2, [r4, 0x1C] - orrs r1, r0 - strh r1, [r4, 0x1C] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end HBlankIntr - - thumb_func_start VCountIntr -@ void VCountIntr() -VCountIntr: @ 8000844 - push {r4,lr} - ldr r4, =gMain - ldr r0, [r4, 0x14] - cmp r0, 0 - beq _08000852 - bl _call_via_r0 -_08000852: - bl m4aSoundVSync - ldr r2, =gUnknown_03007FF8 - ldrh r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strh r0, [r2] - ldrh r0, [r4, 0x1C] - ldrh r2, [r4, 0x1C] - orrs r1, r0 - strh r1, [r4, 0x1C] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end VCountIntr - - thumb_func_start SerialIntr -@ void SerialIntr() -SerialIntr: @ 8000878 - push {r4,lr} - ldr r4, =gMain - ldr r0, [r4, 0x18] - cmp r0, 0 - beq _08000886 - bl _call_via_r0 -_08000886: - ldr r2, =gUnknown_03007FF8 - ldrh r0, [r2] - movs r1, 0x80 - orrs r0, r1 - strh r0, [r2] - ldrh r0, [r4, 0x1C] - ldrh r2, [r4, 0x1C] - orrs r1, r0 - strh r1, [r4, 0x1C] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end SerialIntr - - thumb_func_start IntrDummy -@ void IntrDummy() -IntrDummy: @ 80008A8 - bx lr - thumb_func_end IntrDummy - - thumb_func_start WaitForVBlank -@ void WaitForVBlankIntr() -WaitForVBlank: @ 80008AC - push {lr} - ldr r2, =gMain - ldrh r1, [r2, 0x1C] - ldr r0, =0x0000fffe - ands r0, r1 - ldrh r1, [r2, 0x1C] - strh r0, [r2, 0x1C] - ldrh r1, [r2, 0x1C] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _080008D0 - movs r3, 0x1 -_080008C6: - ldrh r1, [r2, 0x1C] - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - beq _080008C6 -_080008D0: - pop {r0} - bx r0 - .pool - thumb_func_end WaitForVBlank - - thumb_func_start sub_80008DC -sub_80008DC: @ 80008DC - ldr r1, =gUnknown_0203CF5C - str r0, [r1] - bx lr - .pool - thumb_func_end sub_80008DC - - thumb_func_start sub_80008E8 -sub_80008E8: @ 80008E8 - ldr r1, =gUnknown_0203CF5C - movs r0, 0 - str r0, [r1] - bx lr - .pool - thumb_func_end sub_80008E8 - - thumb_func_start DoSoftReset -@ void Reset() -DoSoftReset: @ 80008F4 - push {r4,lr} - ldr r1, =0x04000208 - movs r0, 0 - strh r0, [r1] - bl m4aSoundVSyncOff - bl remove_some_task - ldr r1, =0x040000bc - ldrh r2, [r1, 0xA] - ldr r3, =0x0000c5ff - adds r0, r3, 0 - ands r0, r2 - strh r0, [r1, 0xA] - ldrh r4, [r1, 0xA] - ldr r2, =0x00007fff - adds r0, r2, 0 - ands r0, r4 - strh r0, [r1, 0xA] - ldrh r0, [r1, 0xA] - adds r1, 0xC - ldrh r4, [r1, 0xA] - adds r0, r3, 0 - ands r0, r4 - strh r0, [r1, 0xA] - ldrh r4, [r1, 0xA] - adds r0, r2, 0 - ands r0, r4 - strh r0, [r1, 0xA] - ldrh r0, [r1, 0xA] - ldr r0, =0x040000d4 - ldrh r1, [r0, 0xA] - ands r3, r1 - strh r3, [r0, 0xA] - ldrh r1, [r0, 0xA] - ands r2, r1 - strh r2, [r0, 0xA] - ldrh r0, [r0, 0xA] - bl SiiRtcProtect - movs r0, 0xFF - bl SoftReset - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end DoSoftReset - - thumb_func_start ClearPokemonCrySongs -ClearPokemonCrySongs: @ 8000964 - push {lr} - sub sp, 0x4 - mov r1, sp - movs r0, 0 - strh r0, [r1] - ldr r1, =gPokemonCrySongs - ldr r2, =0x01000034 - mov r0, sp - bl CpuSet - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end ClearPokemonCrySongs - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/naming_screen.s b/asm/naming_screen.s index 6585a4f43..2199b0420 100644 --- a/asm/naming_screen.s +++ b/asm/naming_screen.s @@ -209,7 +209,7 @@ choose_name_or_words_screen_setup: @ 80E2EA8 strh r0, [r1] _080E2F2C: ldr r0, [r5] - ldr r4, =gUnknown_030022B0 + ldr r4, =gKeyRepeatStartDelay ldrh r1, [r4] ldr r2, =0x00001e25 adds r0, r2 diff --git a/asm/pokedex_cry_screen.s b/asm/pokedex_cry_screen.s index fddf56816..81da8368a 100644 --- a/asm/pokedex_cry_screen.s +++ b/asm/pokedex_cry_screen.s @@ -295,7 +295,7 @@ sub_8145588: @ 8145588 thumb_func_start sub_81455A8 sub_81455A8: @ 81455A8 push {r4,lr} - ldr r3, =gUnknown_03002F50 + ldr r3, =gPcmDmaCounter movs r0, 0 ldrsb r0, [r3, r0] cmp r0, 0x1 diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 352066d57..b5da0864f 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -621,7 +621,7 @@ _080E726C: bne _080E730A movs r0, 0x4 strh r0, [r5] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080E7296 @@ -664,7 +664,7 @@ _080E72C0: ldr r0, [r0] bl Free bl sub_808729C - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080E72F8 @@ -2393,7 +2393,7 @@ _080E80C0: lsls r0, 24 cmp r0, 0 bne _080E810A - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080E80E8 diff --git a/asm/rom3.s b/asm/rom3.s index f71e20d8e..380f605a1 100644 --- a/asm/rom3.s +++ b/asm/rom3.s @@ -14,7 +14,7 @@ battle_wireless_setup_if_required_maybe: @ 8032654 ands r0, r1 cmp r0, 0 beq _08032686 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0803266E @@ -1675,7 +1675,7 @@ _080334E0: adds r0, 0x1 b _0803363E _080334E6: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08033504 diff --git a/asm/rom4.s b/asm/rom4.s index 5d26d3461..8440c5374 100644 --- a/asm/rom4.s +++ b/asm/rom4.s @@ -3395,7 +3395,7 @@ c2_8056854: @ 8086140 ldr r0, =c1_link_related bl set_callback1 bl sub_8086C2C - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08086174 @@ -3586,7 +3586,7 @@ sub_808631C: @ 808631C bne _0808632E bl sub_80097E8 _0808632E: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08086348 @@ -3768,7 +3768,7 @@ _080864DA: bl cur_mapheader_run_tileset_funcs_after_some_cpuset b _08086506 _080864E0: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08086506 @@ -4056,7 +4056,7 @@ _08086766: bl cur_mapheader_run_tileset_funcs_after_some_cpuset b _08086792 _0808676C: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08086792 @@ -4565,7 +4565,7 @@ _08086BCA: thumb_func_start c1_link_related c1_link_related: @ 8086BD8 push {r4,lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08086BF2 @@ -4631,7 +4631,7 @@ c1_link_related_func_set: @ 8086C50 thumb_func_start sub_8086C64 sub_8086C64: @ 8086C64 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08086C82 @@ -5029,7 +5029,7 @@ _08086FC0: movs r0, 0x11 strh r0, [r1] _08086FC6: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08086FFC @@ -5926,7 +5926,7 @@ _08087666: thumb_func_start sub_808766C sub_808766C: @ 808766C push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08087688 @@ -5946,7 +5946,7 @@ _0808768A: thumb_func_start sub_8087690 sub_8087690: @ 8087690 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080876B0 diff --git a/asm/rom5.s b/asm/rom5.s index f90aabca5..2175e992b 100644 --- a/asm/rom5.s +++ b/asm/rom5.s @@ -271,7 +271,7 @@ _080A955C: ldrb r0, [r0] movs r1, 0 bl sub_8059CB4 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080A95D2 diff --git a/asm/rom6.s b/asm/rom6.s index ebb3c955a..ea3097383 100644 --- a/asm/rom6.s +++ b/asm/rom6.s @@ -11823,7 +11823,7 @@ _0813B790: b _0813B7C6 .pool _0813B7A8: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _0813B7B4 diff --git a/asm/rom_8034C54.s b/asm/rom_8034C54.s index c91cd93c0..161724a59 100644 --- a/asm/rom_8034C54.s +++ b/asm/rom_8034C54.s @@ -4091,7 +4091,7 @@ _0803703C: movs r0, 0x1 strb r0, [r1] _08037068: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08037072 @@ -4154,7 +4154,7 @@ _080370D8: ldr r0, =gUnknown_02024332 strb r6, [r0] _080370EE: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080370F8 @@ -4559,7 +4559,7 @@ _080374E0: movs r0, 0x1 strb r0, [r1] _0803750C: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08037518 @@ -4644,7 +4644,7 @@ _08037530: movs r0, 0x2 strb r0, [r1] _080375C4: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080375CE @@ -5365,7 +5365,7 @@ _08037C64: ldrb r0, [r5] adds r0, 0x1 strb r0, [r5] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08037C98 @@ -5376,7 +5376,7 @@ _08037C98: bl sub_800AC34 b _08037D0A _08037C9E: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08037CE4 @@ -5566,7 +5566,7 @@ _08037E64: movs r0, 0x1 strb r0, [r1] _08037E90: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08037E9A @@ -5618,7 +5618,7 @@ _08037EBE: adds r0, 0x1 strb r0, [r1] _08037F02: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08037F0C @@ -7734,7 +7734,7 @@ _0803914C: bne _080391C6 b _08039172 _08039166: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08039172 @@ -7757,7 +7757,7 @@ _08039184: adds r3, r2, 0 cmp r0, 0 beq _080391A6 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080391A6 @@ -8210,7 +8210,7 @@ _080395DA: ands r0, r1 cmp r0, 0 beq _080395F6 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080395F6 @@ -8231,7 +8231,7 @@ _08039610: adds r3, r2, 0 cmp r0, 0 beq _08039634 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08039634 @@ -64531,7 +64531,7 @@ _080586E8: thumb_func_start sub_80586F8 sub_80586F8: @ 80586F8 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _0805875C @@ -64615,7 +64615,7 @@ sub_80587B0: @ 80587B0 lsls r0, 24 cmp r0, 0 beq _08058832 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _080587F0 diff --git a/asm/rom_80C6FA0.s b/asm/rom_80C6FA0.s index db3c701e5..545988904 100644 --- a/asm/rom_80C6FA0.s +++ b/asm/rom_80C6FA0.s @@ -1866,7 +1866,7 @@ sub_80C7E98: @ 80C7E98 adds r1, 0x10 movs r2, 0x8 bl sub_80D2A90 - ldr r1, =gUnknown_030022B0 + ldr r1, =gKeyRepeatStartDelay movs r0, 0x14 strh r0, [r1] bl clear_scheduled_bg_copies_to_vram diff --git a/asm/rom_8158B30.s b/asm/rom_8158B30.s index e7f93f1dc..5e0958efe 100644 --- a/asm/rom_8158B30.s +++ b/asm/rom_8158B30.s @@ -23265,7 +23265,7 @@ _08164D14: ldrb r0, [r0] cmp r0, 0 beq _08164DB0 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _08164DB0 @@ -23303,7 +23303,7 @@ _08164DB6: thumb_func_start sub_8164DCC sub_8164DCC: @ 8164DCC push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08164DDA @@ -26046,7 +26046,7 @@ _08166468: bne _08166556 b _0816653C _08166474: - ldr r1, =gUnknown_030022B0 + ldr r1, =gKeyRepeatStartDelay movs r0, 0x14 strh r0, [r1] bl sub_8167420 diff --git a/asm/rom_81BAD84.s b/asm/rom_81BAD84.s index ffc1631e6..df1f6587f 100644 --- a/asm/rom_81BAD84.s +++ b/asm/rom_81BAD84.s @@ -34484,7 +34484,7 @@ sub_81CCFD8: @ 81CCFD8 adds r0, r4, r1 bl sub_81D1ED4 bl sub_81CD970 - ldr r1, =gUnknown_030022B0 + ldr r1, =gKeyRepeatStartDelay movs r0, 0x14 strh r0, [r1] ldr r0, =0x00006304 @@ -34515,7 +34515,7 @@ sub_81CD024: @ 81CD024 adds r0, r4, r1 bl sub_81D1ED4 bl sub_81CD9F8 - ldr r1, =gUnknown_030022B0 + ldr r1, =gKeyRepeatStartDelay movs r0, 0x14 strh r0, [r1] ldr r0, =0x00006304 @@ -40982,10 +40982,10 @@ sub_81D0450: @ 81D0450 adds r1, 0x98 ldr r0, =sub_81D04C4 str r0, [r1] - ldr r1, =gUnknown_030026FC + ldr r1, =gKeyRepeatContinueDelay movs r0, 0x3 strh r0, [r1] - ldr r1, =gUnknown_030022B0 + ldr r1, =gKeyRepeatStartDelay movs r0, 0xA strh r0, [r1] movs r0, 0x1 @@ -50412,7 +50412,7 @@ sub_81D4D50: @ 81D4D50 strh r0, [r1] movs r0, 0 strh r0, [r4] - ldr r1, =gUnknown_03002710 + ldr r1, =gIntrTable ldr r0, =sub_81D3FAC str r0, [r1, 0x4] ldr r0, =sub_81D3F9C diff --git a/asm/start_menu.s b/asm/start_menu.s index 4a3e54026..0e67e01e8 100644 --- a/asm/start_menu.s +++ b/asm/start_menu.s @@ -2092,7 +2092,7 @@ _080A05AC: movs r2, 0x10 movs r3, 0 bl pal_fade_maybe - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080A0620 diff --git a/asm/trade.s b/asm/trade.s index eced98662..0c85c2711 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -135,7 +135,7 @@ _08077258: thumb_func_start sub_8077260 sub_8077260: @ 8077260 push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08077280 @@ -409,7 +409,7 @@ _080774B2: ldr r0, [r0] adds r0, 0xA8 strb r2, [r0] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08077528 @@ -531,7 +531,7 @@ _08077600: ldr r0, [r0] adds r0, 0xA8 strb r2, [r0] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 bne _0807762A @@ -543,7 +543,7 @@ _0807762A: b _08077B46 .pool _08077648: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08077680 @@ -1182,7 +1182,7 @@ _08077C28: b _080780D8 .pool _08077C3C: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08077C50 @@ -1780,7 +1780,7 @@ sub_807816C: @ 807816C adds r0, 0x7E ldrb r0, [r0] strb r0, [r1, 0x1] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080781B4 @@ -1809,7 +1809,7 @@ sub_80781C8: @ 80781C8 ldr r5, =gMain ldr r0, =sub_80773AC str r0, [r5, 0x8] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08078220 @@ -4004,7 +4004,7 @@ sub_8079490: @ 8079490 ands r0, r1 cmp r0, 0 bne _080794C4 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _080794B4 @@ -4029,7 +4029,7 @@ _080794C4: thumb_func_start sub_80794CC sub_80794CC: @ 80794CC push {lr} - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _08079518 @@ -7507,7 +7507,7 @@ _0807B0F0: ands r0, r1 cmp r0, 0 bne _0807B116 - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0807B110 @@ -13831,7 +13831,7 @@ _0807EDC0: movs r0, 0x15 bl sav12_xor_increment _0807EDCE: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0807EDF6 @@ -14044,7 +14044,7 @@ _0807EFA4: lsrs r0, 24 cmp r0, 0x1 bne _0807F03A - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0807EFD8 @@ -14071,7 +14071,7 @@ _0807EFE4: b _0807F03A .pool _0807EFF0: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0807F028 @@ -14141,7 +14141,7 @@ c2_080543C4: @ 807F068 ldr r0, [r4] bl Free str r5, [r4] - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0 beq _0807F0B6 diff --git a/asm/trainer_card.s b/asm/trainer_card.s index 9b22b7ccd..849b7b4bc 100644 --- a/asm/trainer_card.s +++ b/asm/trainer_card.s @@ -187,7 +187,7 @@ _080C2830: bl sub_80C4630 b _080C28D4 _080C2836: - ldr r0, =gUnknown_030030FC + ldr r0, =gLinkVSyncDisabled ldrb r0, [r0] cmp r0, 0x1 bne _080C2852 diff --git a/ld_script.txt b/ld_script.txt index 1f31ca849..c6c40a62f 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -42,7 +42,6 @@ SECTIONS { { asm/crt0.o(.text); src/main.o(.text); - asm/main.o(.text); src/malloc.o(.text); asm/dma3_manager.o(.text); src/gpu_regs.o(.text); diff --git a/src/main.c b/src/main.c index ff28b1e84..32e0429d3 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,12 @@ #include "gba/flash_internal.h" #include "gba/m4a_internal.h" +extern u16 GetGpuReg(u8); +extern void SetGpuReg(u8, u16); +extern void LinkVSync(void); +extern void sub_800E174(void); +extern void sub_800B9B8(void); + extern struct SoundInfo gSoundInfo; extern u32 gFlashMemoryPresent; extern u32 IntrMain[]; @@ -10,7 +16,10 @@ extern u8 gHeap[]; extern struct SaveBlock2 gUnknown_02024A54; extern char *gUnknown_03005D94; extern char gUnknown_02029808[]; -extern u32 gUnknown_0203CF5C; +extern u16 gIntrCheck; +extern u32 gBattleTypeFlags; +extern u8 gUnknown_03002748; +//extern u32 gUnknown_0203CF5C; void Timer3Intr(void); bool8 HandleLinkConnection(void); @@ -22,7 +31,6 @@ static void VCountIntr(void); static void SerialIntr(void); static void IntrDummy(void); - const u8 gGameVersion = VERSION_EMERALD; const u8 gGameLanguage = GAME_LANGUAGE; // English @@ -70,7 +78,7 @@ static void InitMainCallbacks(void); static void CallCallbacks(void); static void SeedRngWithRtc(void); static void ReadKeys(void); -static void InitIntrHandlers(void); +void InitIntrHandlers(void); static void WaitForVBlank(void); #define B_START_SELECT (B_BUTTON | START_BUTTON | SELECT_BUTTON) @@ -149,10 +157,17 @@ static void UpdateLinkAndCallCallbacks(void) CallCallbacks(); } +struct gUnknown_0203CF5C_Struct +{ + u32 value; +}; + +extern struct gUnknown_0203CF5C_Struct gUnknown_0203CF5C; + static void InitMainCallbacks(void) { gMain.vblankCounter1 = 0; - gUnknown_0203CF5C = 0; + gUnknown_0203CF5C.value = 0; gMain.vblankCounter2 = 0; gMain.callback1 = NULL; SetMainCallback2(c2_copyright_1); @@ -193,12 +208,19 @@ u16 GetTrainerId(void) return gTrainerId; } -/* +void EnableVCountIntrAtLine150(void) +{ + u16 gpuReg = GetGpuReg(0x4) & 0xFF | 0x9600; + + SetGpuReg(4, gpuReg | 0x20); + EnableInterrupts(0x4); // please use IRQ_MASK_VCOUNT +} + void InitKeys(void) { gKeyRepeatContinueDelay = 5; gKeyRepeatStartDelay = 40; - + gMain.heldKeys = 0; gMain.newKeys = 0; gMain.newAndRepeatedKeys = 0; @@ -237,7 +259,7 @@ static void ReadKeys(void) gMain.heldKeys = gMain.heldKeysRaw; // Remap L to A if the L=A option is enabled. - if (gSaveBlock2.optionsButtonMode == 2) + if (gSaveBlock2Ptr->optionsButtonMode == 2) { if (gMain.newKeys & L_BUTTON) gMain.newKeys |= A_BUTTON; @@ -250,7 +272,7 @@ static void ReadKeys(void) gMain.watchedKeysPressed = TRUE; } -static void InitIntrHandlers(void) +void InitIntrHandlers(void) { int i; @@ -266,9 +288,8 @@ static void InitIntrHandlers(void) SetSerialCallback(NULL); REG_IME = 1; - REG_IE = INTR_FLAG_VBLANK; - REG_DISPSTAT = DISPSTAT_VBLANK_INTR; - REG_IE |= INTR_FLAG_VBLANK; + + EnableInterrupts(0x1); } void SetVBlankCallback(IntrCallback callback) @@ -286,43 +307,146 @@ void SetVCountCallback(IntrCallback callback) gMain.vcountCallback = callback; } +void RestoreSerialTimer3IntrHandlers(void) +{ + gIntrTable[1] = SerialIntr; + gIntrTable[2] = Timer3Intr; +} + void SetSerialCallback(IntrCallback callback) { gMain.serialCallback = callback; } +extern void CopyBufferedValuesToGpuRegs(void); +extern void ProcessDma3Requests(void); + +#ifdef NONMATCHING static void VBlankIntr(void) { - u16 savedIme; - - if (!gLinkVSyncDisabled) + if (gLinkVSyncDisabled != FALSE) LinkVSync(); + else if(gUnknown_03002748 == FALSE) + sub_800B9B8(); - savedIme = REG_IME; - REG_IME = 0; - m4aSoundVSync(); - REG_IME = savedIme; - - gMain.vblankCounter1++; + gMain.vblankCounter1++; // in the original asm, gMain is put into r0 for this addition and then preserved in r4 after it. the compiler wants to skip that and put it in either r4 or r1. + if(gUnknown_0203CF5C.value > 0) + if(gUnknown_0203CF5C.value < 0xFFFFFFFF) + gUnknown_0203CF5C.value++; + if (gMain.vblankCallback) gMain.vblankCallback(); gMain.vblankCounter2++; + + CopyBufferedValuesToGpuRegs(); + ProcessDma3Requests(); gPcmDmaCounter = gSoundInfo.pcmDmaCounter; m4aSoundMain(); - sub_800C35C(); - Random(); + sub_8033648(); - INTR_CHECK |= INTR_FLAG_VBLANK; + if(!gMain.inBattle || (gBattleTypeFlags & 0x013F0102) == 0) + Random(); + + sub_800E174(); + + gIntrCheck |= INTR_FLAG_VBLANK; gMain.intrCheck |= INTR_FLAG_VBLANK; } - -void InitFlashTimer(void) +#else +__attribute__((naked)) +static void VBlankIntr(void) { - SetFlashTimerIntr(2, gFlashTimerIntrFunc); + asm(".syntax unified\n\ + push {r4,lr}\n\ + ldr r0, =gLinkVSyncDisabled\n\ + ldrb r0, [r0]\n\ + cmp r0, 0\n\ + beq _0800074C\n\ + bl LinkVSync\n\ + b _08000758\n\ + .pool\n\ +_0800074C:\n\ + ldr r0, =gUnknown_03002748\n\ + ldrb r0, [r0]\n\ + cmp r0, 0\n\ + bne _08000758\n\ + bl sub_800B9B8\n\ +_08000758:\n\ + ldr r0, =gMain\n\ + ldr r1, [r0, 0x20]\n\ + adds r1, 0x1\n\ + str r1, [r0, 0x20]\n\ + ldr r1, =gUnknown_0203CF5C\n\ + ldr r1, [r1]\n\ + adds r4, r0, 0\n\ + cmp r1, 0\n\ + beq _08000778\n\ + ldr r2, [r1]\n\ + movs r0, 0x2\n\ + negs r0, r0\n\ + cmp r2, r0\n\ + bhi _08000778\n\ + adds r0, r2, 0x1\n\ + str r0, [r1]\n\ +_08000778:\n\ + ldr r0, [r4, 0xC]\n\ + cmp r0, 0\n\ + beq _08000782\n\ + bl _call_via_r0\n\ +_08000782:\n\ + ldr r0, [r4, 0x24]\n\ + adds r0, 0x1\n\ + str r0, [r4, 0x24]\n\ + bl CopyBufferedValuesToGpuRegs\n\ + bl ProcessDma3Requests\n\ + ldr r1, =gPcmDmaCounter\n\ + ldr r0, =gSoundInfo\n\ + ldrb r0, [r0, 0x4]\n\ + strb r0, [r1]\n\ + bl m4aSoundMain\n\ + bl sub_8033648\n\ + ldr r1, =0x00000439\n\ + adds r0, r4, r1\n\ + ldrb r1, [r0]\n\ + movs r0, 0x2\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _080007BA\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + ldr r1, =0x013f0102\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _080007BE\n\ +_080007BA:\n\ + bl Random\n\ +_080007BE:\n\ + bl sub_800E174\n\ + ldr r2, =gIntrCheck\n\ + ldrh r0, [r2]\n\ + movs r1, 0x1\n\ + orrs r0, r1\n\ + strh r0, [r2]\n\ + ldr r0, =gMain\n\ + ldrh r2, [r0, 0x1C]\n\ + ldrh r3, [r0, 0x1C]\n\ + orrs r1, r2\n\ + strh r1, [r0, 0x1C]\n\ + pop {r4}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + .syntax divided"); +} +#endif + +void StartFlashMemoryTimer(void) +{ + SetFlashTimerIntr(2, gIntrTable + 0x7); } static void HBlankIntr(void) @@ -339,7 +463,8 @@ static void VCountIntr(void) if (gMain.vcountCallback) gMain.vcountCallback(); - INTR_CHECK |= INTR_FLAG_VCOUNT; + m4aSoundVSync(); + gIntrCheck |= INTR_FLAG_VCOUNT; gMain.intrCheck |= INTR_FLAG_VCOUNT; } @@ -348,7 +473,7 @@ static void SerialIntr(void) if (gMain.serialCallback) gMain.serialCallback(); - INTR_CHECK |= INTR_FLAG_SERIAL; + gIntrCheck |= INTR_FLAG_SERIAL; gMain.intrCheck |= INTR_FLAG_SERIAL; } @@ -358,7 +483,19 @@ static void IntrDummy(void) static void WaitForVBlank(void) { gMain.intrCheck &= ~INTR_FLAG_VBLANK; - VBlankIntrWait(); + + while(!(gMain.intrCheck & 0x1)) + ; +} + +void sub_80008DC(u32 var) +{ + gUnknown_0203CF5C.value = var; +} + +void sub_80008E8(void) +{ + gUnknown_0203CF5C.value = 0; } void DoSoftReset(void) @@ -377,4 +514,3 @@ void ClearPokemonCrySongs(void) { CpuFill16(0, gPokemonCrySongs, MAX_POKEMON_CRIES * sizeof(struct PokemonCrySong)); } -*/ \ No newline at end of file diff --git a/sym_common.txt b/sym_common.txt index f93a021cb..963686122 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -1,6 +1,6 @@ .space 0x8 -gUnknown_030022B0: @ 30022B0 +gKeyRepeatStartDelay: @ 30022B0 .space 0x4 gUnknown_030022B4: @ 30022B4 @@ -21,28 +21,22 @@ gUnknown_030024F8: @ 30024F8 gUnknown_030026F8: @ 30026F8 .space 0x4 -gUnknown_030026FC: @ 30026FC +gKeyRepeatContinueDelay: @ 30026FC .space 0x4 gSoftResetDisabled: @ 3002700 .space 0x10 -gUnknown_03002710: @ 3002710 - .space 0x4 - -gUnknown_03002714: @ 3002714 - .space 0x18 - -gUnknown_0300272C: @ 300272C - .space 0x1C +gIntrTable: @ 3002710 + .space 0x38 gUnknown_03002748: @ 3002748 .space 0x8 -gUnknown_03002750: @ 3002750 +IntrMain_Buffer: @ 3002750 .space 0x800 -gUnknown_03002F50: @ 3002F50 +gPcmDmaCounter: @ 3002F50 .space 0x4 gUnknown_03002F54: @ 3002F54 @@ -135,7 +129,7 @@ gUnknown_030030F4: @ 30030F4 gUnknown_030030F8: @ 30030F8 .space 0x4 -gUnknown_030030FC: @ 30030FC +gLinkVSyncDisabled: @ 30030FC .space 0x4 gUnknown_03003100: @ 3003100 @@ -531,7 +525,8 @@ gUnknown_03007F00: @ 3007F00 gUnknown_03007FF0: @ 3007FF0 .space 0x8 -gUnknown_03007FF8: @ 3007FF8 +gIntrCheck: @ 3007FF8 .space 0x4 gUnknown_03007FFC: @ 3007FFC + .space 0x4