From 248bc9acc05e004f960a3b2704af9e5f00cf4275 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Thu, 6 Jan 2022 14:35:25 +0200 Subject: [PATCH] Decompile sub_080517B4 --- asm/non_matching/fileScreen/sub_080517B4.inc | 32 ------------- include/menu.h | 48 ++++++++++---------- src/fileselect.c | 9 ++-- 3 files changed, 29 insertions(+), 60 deletions(-) delete mode 100644 asm/non_matching/fileScreen/sub_080517B4.inc diff --git a/asm/non_matching/fileScreen/sub_080517B4.inc b/asm/non_matching/fileScreen/sub_080517B4.inc deleted file mode 100644 index f9bef9e7..00000000 --- a/asm/non_matching/fileScreen/sub_080517B4.inc +++ /dev/null @@ -1,32 +0,0 @@ - .syntax unified - push {r4, lr} - adds r2, r0, #0 - ldr r0, _080517E4 @ =gUnk_02019EE0 - ldrb r1, [r0, #7] - adds r4, r0, #0 - cmp r2, #0 - beq _080517DE - adds r1, r1, r2 - cmp r1, #4 - bhi _080517DC - ldr r3, _080517E8 @ =gUnk_02000090 -_080517CA: - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, #0 - beq _080517D6 - cmp r0, #4 - bne _080517DE -_080517D6: - adds r1, r1, r2 - cmp r1, #4 - bls _080517CA -_080517DC: - ldrb r1, [r4, #7] -_080517DE: - adds r0, r1, #0 - pop {r4, pc} - .align 2, 0 -_080517E4: .4byte gUnk_02019EE0 -_080517E8: .4byte gUnk_02000090 - .syntax divided diff --git a/include/menu.h b/include/menu.h index 052de3d2..e4c09e84 100644 --- a/include/menu.h +++ b/include/menu.h @@ -33,30 +33,30 @@ typedef struct { extern void sub_080A70AC(const KeyButtonLayout*); typedef struct { - u8 field_0x0; - u8 column_idx; - u8 field_0x2; - u8 field_0x3; - u8 field_0x4; - u8 menuType; - u8 overlayType; - u8 storyPanelIndex; - u16 transitionTimer; - u16 field_0xa; - u8* field_0xc; - u8 focusCoords[2]; - u8 field_0x12; - u8 unk13; - u8 unk14; - u8 unk15; - u8 unk16; - // While struct offsets are usually loaded indirectly, this one is often loaded - // directly in the code. This happens when you take the address off the field with '&`. - // Perhaps they had a macro to cast this to different sized arrays. - u8 selectMtx; - u8 filler18[0x12]; - u8 unk2a; - int field_0x2c; + /*0x00*/ u8 field_0x0; + /*0x01*/ u8 column_idx; + /*0x02*/ u8 field_0x2; + /*0x03*/ u8 field_0x3; + /*0x04*/ u8 field_0x4; + /*0x05*/ u8 menuType; + /*0x06*/ u8 overlayType; + /*0x07*/ u8 storyPanelIndex; + /*0x08*/ u16 transitionTimer; + /*0x0a*/ u16 field_0xa; + /*0x0c*/ u8* field_0xc; + /*0x10*/ u8 focusCoords[2]; + /*0x12*/ u8 field_0x12; + /*0x13*/ u8 unk13; + /*0x14*/ u8 unk14; + /*0x15*/ u8 unk15; + /*0x16*/ u8 unk16; + /* */ // While struct offsets are usually loaded indirectly, this one is often loaded + /* */ // directly in the code. This happens when you take the address off the field with '&`. + /* */ // Perhaps they had a macro to cast this to different sized arrays. + /*0x17*/ u8 selectMtx; + /*0x18*/ u8 filler18[0x12]; + /*0x2a*/ u8 unk2a; + /*0x2c*/ int field_0x2c; } Menu; static_assert(sizeof(Menu) == 0x30); diff --git a/src/fileselect.c b/src/fileselect.c index 71ed5e76..f2e1cb39 100644 --- a/src/fileselect.c +++ b/src/fileselect.c @@ -1124,17 +1124,18 @@ NONMATCH("asm/non_matching/fileScreen/sub_08051738.inc", void sub_08051738(void) } END_NONMATCH -NONMATCH("asm/non_matching/fileScreen/sub_080517B4.inc", s32 sub_080517B4(s32 a1)) { +s32 sub_080517B4(s32 a1) { u32 i = gUnk_02019EE0.unk7; if (a1 != 0) { - for (; i < 5; i += a1) { - if ((&gMenu.selectMtx)[i] != 0 && (&gMenu.selectMtx)[i] != 4) + for (i = i + a1; i < 5; i += a1) { + if ((&gMenu.focusCoords[0])[i] != 0 && (&gMenu.focusCoords[0])[i] != 4) return i; } + + i = gUnk_02019EE0.unk7; } return i; } -END_NONMATCH void sub_080517EC(void) { u32 temp;