diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2018-11-24 20:04:50 -0500 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2018-11-24 20:04:50 -0500 |
commit | 93f67f9557109d85e191283b171f7f5e8028b7bf (patch) | |
tree | 9de4754893df84f6d11ff7bcb10f9b3e4018e840 | |
parent | 8ef1594d204e0b933fcfc048e17471191dfae720 (diff) |
sub_812CAD8
New macro `PRESSED(x)` tests `gMain.newKeys & (x)`. The macro itself
is inoptimal. However, its use is required to match this function.
We suspect this macro may have been implemented globally, hence we
put it in `global.h`. Propagating its use through the remainder of
this project, as well as [Ruby](/pret/pokeruby) and [Emerald](/pret/pokeemerald),
has been left as a to-do item.
-rw-r--r-- | asm/fame_checker.s | 194 | ||||
-rw-r--r-- | include/global.h | 7 | ||||
-rw-r--r-- | src/fame_checker.c | 81 |
3 files changed, 84 insertions, 198 deletions
diff --git a/asm/fame_checker.s b/asm/fame_checker.s index f87b8622f..80c8fa2a8 100644 --- a/asm/fame_checker.s +++ b/asm/fame_checker.s @@ -5,200 +5,6 @@ .text - thumb_func_start sub_812CAD8 -sub_812CAD8: @ 812CAD8 - push {r4-r6,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, r4, 2 - adds r1, r4 - lsls r1, 3 - ldr r0, _0812CB9C @ =gTasks - adds r5, r1, r0 - adds r0, 0x8 - adds r6, r1, r0 - bl RunTextPrinters - ldr r0, _0812CBA0 @ =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0812CB2E - movs r0, 0x2 - bl IsTextPrinterActive - lsls r0, 16 - cmp r0, 0 - bne _0812CB2E - ldr r0, _0812CBA4 @ =gUnknown_203B0FC - ldr r0, [r0] - movs r2, 0x2 - ldrsh r1, [r6, r2] - adds r0, 0x1D - adds r0, r1 - ldrb r1, [r0] - ldr r2, _0812CBA8 @ =gSprites - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - movs r1, 0x30 - ldrsh r0, [r0, r1] - cmp r0, 0xFF - beq _0812CB2E - adds r0, r4, 0 - bl sub_812CE04 -_0812CB2E: - ldr r0, _0812CBA0 @ =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0812CBB8 - movs r0, 0x5 - bl PlaySE - movs r4, 0 - ldr r6, _0812CBA4 @ =gUnknown_203B0FC -_0812CB44: - ldr r0, [r6] - adds r0, 0x1D - adds r0, r4 - ldrb r0, [r0] - movs r1, 0 - bl sub_812CEFC - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x5 - bls _0812CB44 - bl sub_812CE9C - ldr r2, _0812CBA8 @ =gSprites - movs r0, 0x8 - ldrsh r1, [r5, r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, 0x1C - adds r0, r2 - ldr r1, _0812CBAC @ =sub_812D764 - str r1, [r0] - ldr r0, _0812CBB0 @ =gUnknown_3005EC8 - ldrb r0, [r0] - cmp r0, 0xFF - beq _0812CB80 - bl sub_812DB10 -_0812CB80: - movs r0, 0x1 - bl sub_812E4A4 - movs r0, 0 - bl sub_812D0F4 - bl sub_812E000 - bl sub_812C990 - ldr r0, _0812CBB4 @ =sub_812C694 - str r0, [r5] - b _0812CC62 - .align 2, 0 -_0812CB9C: .4byte gTasks -_0812CBA0: .4byte gMain -_0812CBA4: .4byte gUnknown_203B0FC -_0812CBA8: .4byte gSprites -_0812CBAC: .4byte sub_812D764 -_0812CBB0: .4byte gUnknown_3005EC8 -_0812CBB4: .4byte sub_812C694 -_0812CBB8: - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - bne _0812CBC8 - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _0812CBF4 -_0812CBC8: - ldrh r1, [r5, 0xA] - movs r2, 0xA - ldrsh r0, [r5, r2] - cmp r0, 0x2 - ble _0812CBE4 - subs r0, r1, 0x3 - strh r0, [r5, 0xA] - movs r2, 0x1B - negs r2, r2 - adds r0, r4, 0 - movs r1, 0 - bl sub_812CC68 - b _0812CC62 -_0812CBE4: - adds r0, r1, 0x3 - strh r0, [r5, 0xA] - adds r0, r4, 0 - movs r1, 0 - movs r2, 0x1B - bl sub_812CC68 - b _0812CC62 -_0812CBF4: - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _0812CC26 - ldrh r6, [r5, 0xA] - movs r1, 0xA - ldrsh r0, [r5, r1] - cmp r0, 0 - beq _0812CC12 - movs r1, 0x3 - bl __modsi3 - lsls r0, 16 - cmp r0, 0 - bne _0812CC1C -_0812CC12: - adds r0, r6, 0x2 - strh r0, [r5, 0xA] - adds r0, r4, 0 - movs r1, 0x5E - b _0812CC4A -_0812CC1C: - subs r0, r6, 0x1 - strh r0, [r5, 0xA] - movs r1, 0x2F - negs r1, r1 - b _0812CC48 -_0812CC26: - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _0812CC62 - movs r1, 0xA - ldrsh r0, [r5, r1] - adds r0, 0x1 - movs r1, 0x3 - bl __modsi3 - cmp r0, 0 - bne _0812CC52 - ldrh r0, [r5, 0xA] - subs r0, 0x2 - strh r0, [r5, 0xA] - movs r1, 0x5E - negs r1, r1 -_0812CC48: - adds r0, r4, 0 -_0812CC4A: - movs r2, 0 - bl sub_812CC68 - b _0812CC62 -_0812CC52: - ldrh r0, [r5, 0xA] - adds r0, 0x1 - strh r0, [r5, 0xA] - adds r0, r4, 0 - movs r1, 0x2F - movs r2, 0 - bl sub_812CC68 -_0812CC62: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_812CAD8 - thumb_func_start sub_812CC68 sub_812CC68: @ 812CC68 push {r4-r7,lr} diff --git a/include/global.h b/include/global.h index 050e200f9..3dc11bfbd 100644 --- a/include/global.h +++ b/include/global.h @@ -62,6 +62,13 @@ #define T2_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24)) #define T2_READ_PTR(ptr) (void*) T2_READ_32(ptr) +// This macro is required to prevent the compiler from optimizing +// a dpad up/down check in sub_812CAD8 (fame_checker.c). +// We suspect it was used globally. +// GameFreak never ceases to amaze. +// TODO: Propagate use of this macro +#define PRESSED(button) ({gMain.newKeys & (button);}) + extern u8 gStringVar1[]; extern u8 gStringVar2[]; extern u8 gStringVar3[]; diff --git a/src/fame_checker.c b/src/fame_checker.c index 81aeb7aee..e83eaa301 100644 --- a/src/fame_checker.c +++ b/src/fame_checker.c @@ -1,5 +1,6 @@ #include "global.h" #include "constants/songs.h" +#include "sprite.h" #include "bg.h" #include "graphics.h" #include "new_menu_helpers.h" @@ -58,6 +59,7 @@ void sub_812C990(void); void sub_812C9BC(u8 taskId); void sub_812CA1C(u8 taskId); void sub_812CAD8(u8 taskId); +void sub_812CC68(u8 taskId, s8 dx, s8 dy); void sub_812CD3C(void); void sub_812CE04(u8 taskId); void sub_812CE9C(void); @@ -73,11 +75,13 @@ void sub_812D584(void); void sub_812D594(void); bool8 sub_812D6B4(void); u8 sub_812D724(s16 a0); +void sub_812D764(struct Sprite *sprite); u8 sub_812D7E4(void); void sub_812D800(struct Sprite *sprite); u8 sub_812D888(u8 a0); void sub_812D9A8(u8 a0, u16 a1); void sub_812DA14(u8 a0); +void sub_812DB10(void); void sub_812DB28(void); void sub_812E000(void); void sub_812E048(void); @@ -222,9 +226,9 @@ void sub_812C694(u8 taskId) if (FindTaskIdByFunc(sub_812E110) == 0xFF) { RunTextPrinters(); - if ((gMain.newKeys & SELECT_BUTTON) && !gUnknown_203B0FC->unk_07_1 && gUnknown_203B0FC->unk_00 != sub_8107EB8) + if ((PRESSED(SELECT_BUTTON)) && !gUnknown_203B0FC->unk_07_1 && gUnknown_203B0FC->unk_00 != sub_8107EB8) task->func = sub_812CF3C; - else if (gMain.newKeys & START_BUTTON) + else if (PRESSED(START_BUTTON)) { r4 = sub_812E064(); if (sub_812C8F8(taskId) == TRUE) @@ -248,7 +252,7 @@ void sub_812C694(u8 taskId) task->func = sub_812C9BC; } } - else if (gMain.newKeys & A_BUTTON) + else if (PRESSED(A_BUTTON)) { r4 = ListMenuHandleInput(0); if (r4 == gUnknown_203B0FC->unk_07_2 - 1) @@ -279,7 +283,7 @@ void sub_812C694(u8 taskId) task->func = sub_812CAD8; } } - else if (gMain.newKeys & B_BUTTON) + else if (PRESSED(B_BUTTON)) { if (sub_812C8F8(taskId) != TRUE) task->func = sub_812CF3C; @@ -344,3 +348,72 @@ void sub_812CA1C(u8 taskId) gSprites[task->data[3]].callback = sub_812D800; } } + +void sub_812CAD8(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + s16 *data = gTasks[taskId].data; + + RunTextPrinters(); + if (PRESSED(A_BUTTON) && !IsTextPrinterActive(2)) + { + u8 spriteId = gUnknown_203B0FC->unk_1D[data[1]]; + if (gSprites[spriteId].data[1] != 0xFF) + sub_812CE04(taskId); + } + if (PRESSED(B_BUTTON)) + { + u8 r4; + PlaySE(SE_SELECT); + for (r4 = 0; r4 < 6; r4++) + sub_812CEFC(gUnknown_203B0FC->unk_1D[r4], 0); + sub_812CE9C(); + gSprites[task->data[0]].callback = sub_812D764; + if (gUnknown_3005EC8 != 0xFF) + sub_812DB10(); + sub_812E4A4(1); + sub_812D0F4(0); + sub_812E000(); + sub_812C990(); + task->func = sub_812C694; + } + else if (PRESSED(DPAD_UP) || PRESSED(DPAD_DOWN)) + { + if (task->data[1] >= 3) + { + task->data[1] -= 3; + sub_812CC68(taskId, 0, -0x1b); + } + else + { + task->data[1] += 3; + sub_812CC68(taskId, 0, +0x1b); + } + } + else if (PRESSED(DPAD_LEFT)) + { + if (task->data[1] == 0 || task->data[1] % 3 == 0) + { + task->data[1] += 2; + sub_812CC68(taskId, +0x5e, 0); + } + else + { + task->data[1]--; + sub_812CC68(taskId, -0x2f, 0); + } + } + else if (PRESSED(DPAD_RIGHT)) + { + if ((task->data[1] + 1) % 3 == 0) + { + task->data[1] -= 2; + sub_812CC68(taskId, -0x5e, 0); + } + else + { + task->data[1]++; + sub_812CC68(taskId, +0x2f, 0); + } + } +} |