From 7f4732f71437ee6d27df79382f4cac55aad3d26b Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 11 Aug 2023 06:24:48 -0400 Subject: [PATCH 01/27] Match ResetSprites --- asm/sprite.s | 126 ----------------------------------------------- include/sprite.h | 16 +++++- src/sprite.c | 107 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 127 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index 214956ec..b72484b4 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,132 +5,6 @@ .text - thumb_func_start ResetSprites -ResetSprites: - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r1, _08004E68 - movs r0, 0 - str r0, [r1] - ldr r1, _08004E6C - ldr r0, _08004E70 - str r0, [r1] - ldr r1, _08004E74 - ldr r0, _08004E78 - str r0, [r1] - ldr r0, _08004E7C - adds r1, r0, 0 - adds r1, 0x8 - adds r5, r0, 0 - movs r2, 0 - movs r3, 0xF0 -_08004DB0: - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - str r1, [r0] - str r2, [r0, 0x4] - adds r0, 0x8 - adds r1, 0x8 - subs r3, 0x10 - cmp r3, 0 - bge _08004DB0 - cmp r4, 0 - beq _08004E50 - movs r2, 0 - ldr r1, _08004E80 - ldr r0, _08004E84 - movs r3, 0x7F -_08004E42: - str r2, [r0] - str r1, [r0, 0x4] - adds r1, 0x8 - adds r0, 0x8 - subs r3, 0x1 - cmp r3, 0 - bge _08004E42 -_08004E50: - movs r1, 0x80 - lsls r1, 4 - adds r0, r5, r1 - movs r1, 0 - str r1, [r0] - ldr r2, _08004E88 - adds r0, r5, r2 - str r1, [r0] - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_08004E68: .4byte gSpriteCount -_08004E6C: .4byte gCharMemCursor -_08004E70: .4byte 0x06010000 -_08004E74: .4byte gUnknown_203B074 -_08004E78: .4byte gUnknown_20266B0 -_08004E7C: .4byte gUnknown_20256A0 -_08004E80: .4byte gUnknown_20262A8 -_08004E84: .4byte gUnknown_2025EA8 -_08004E88: .4byte 0x00000804 - thumb_func_end ResetSprites - thumb_func_start sub_8004E8C sub_8004E8C: ldr r1, _08004EA4 diff --git a/include/sprite.h b/include/sprite.h index 7790e87e..22e46c10 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -1,11 +1,25 @@ #ifndef GUARD_SPRITE_H #define GUARD_SPRITE_H +// size: 0x8 +struct UnkSpriteLink +{ + struct UnkSpriteLink *unk0; + struct UnkSpriteLink *unk4; +}; +// size: 0x808 +struct SpriteList +{ + struct UnkSpriteLink sprites[16][16]; + u32 unk800; + u32 unk804; +}; + void InitSprites(void); +void ResetSprites(bool8); // sprite.s extern void BlinkSavingIcon(void); -extern void ResetSprites(bool32); extern void SetSavingIconCoords(u32); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/sprite.c b/src/sprite.c index d890ef40..42a88589 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1,8 +1,115 @@ #include "global.h" #include "sprite.h" +extern struct SpriteList gUnknown_20256A0; +extern struct UnkSpriteLink gUnknown_2025EA8[128]; +extern struct UnkSpriteLink gUnknown_20262A8[128]; +extern u32 gSpriteCount; /* 20266A8 */ +extern u32 gUnknown_20266B0; +extern u32 *gCharMemCursor; /* 2026E30 */ +extern u32 *gUnknown_203B074; + void InitSprites(void) { ResetSprites(TRUE); SetSavingIconCoords(0); +} + +void ResetSprites(bool8 a0) +{ + s32 i; + struct UnkSpriteLink *a; + struct UnkSpriteLink *b; + struct UnkSpriteLink *c; + + gSpriteCount = 0; + gCharMemCursor = (u32*)0x6010000; + gUnknown_203B074 = &gUnknown_20266B0; + + a = &gUnknown_20256A0.sprites[0][0]; + b = a + 1; + + // 16 loops, very smart + for (i = 0; i < 0x100; i += 0x10) { + c = NULL; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + a->unk0 = b; + a->unk4 = c; + a++; + b++; + } + + if (a0) { + c = NULL; + b = &gUnknown_20262A8[0]; + a = &gUnknown_2025EA8[0]; + for (i = 0; i < 128; i++) { + a->unk0 = c; + a->unk4 = b; + b++; + a++; + } + } + + gUnknown_20256A0.unk800 = 0; + gUnknown_20256A0.unk804 = 0; } \ No newline at end of file From b162b808fec035149dcd34cb294cdc61acc06029 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 11 Aug 2023 06:34:31 -0400 Subject: [PATCH 02/27] Match sub_8004E8C --- asm/sprite.s | 17 ----------------- include/sprite.h | 13 +++++++++++++ src/sprite.c | 10 ++++++++++ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index b72484b4..8a7213ff 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,23 +5,6 @@ .text - thumb_func_start sub_8004E8C -sub_8004E8C: - ldr r1, _08004EA4 - strh r1, [r0] - movs r1, 0x1 - negs r1, r1 - strh r1, [r0, 0x2] - strh r1, [r0, 0x4] - movs r1, 0 - strh r1, [r0, 0x6] - strh r1, [r0, 0x8] - strh r1, [r0, 0xA] - bx lr - .align 2, 0 -_08004EA4: .4byte 0x0000ffff - thumb_func_end sub_8004E8C - thumb_func_start sub_8004EA8 sub_8004EA8: push {r4-r7,lr} diff --git a/include/sprite.h b/include/sprite.h index 22e46c10..0114092e 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -7,6 +7,7 @@ struct UnkSpriteLink struct UnkSpriteLink *unk0; struct UnkSpriteLink *unk4; }; + // size: 0x808 struct SpriteList { @@ -15,8 +16,20 @@ struct SpriteList u32 unk804; }; +// size: 0xC +struct unkStruct_2039DB0 +{ + u16 unk0; + s16 unk2; + s16 unk4; + u16 unk6; + u16 unk8; + u16 unkA; +}; + void InitSprites(void); void ResetSprites(bool8); +void sub_8004E8C(struct unkStruct_2039DB0 *); // sprite.s extern void BlinkSavingIcon(void); diff --git a/src/sprite.c b/src/sprite.c index 42a88589..ea6075e8 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -112,4 +112,14 @@ void ResetSprites(bool8 a0) gUnknown_20256A0.unk800 = 0; gUnknown_20256A0.unk804 = 0; +} + +void sub_8004E8C(struct unkStruct_2039DB0 *a0) +{ + a0->unk0 = 0xFFFF; + a0->unk2 = -1; + a0->unk4 = -1; + a0->unk6 = 0; + a0->unk8 = 0; + a0->unkA = 0; } \ No newline at end of file From 520bcb39448f9aec25a603f9204adbe3375d4d86 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:35:00 -0400 Subject: [PATCH 03/27] Skipped 2 got 1 lol [sub_8005180] --- asm/sprite.s | 398 ---------------------------- include/rescue_password_menu.h | 10 +- include/sprite.h | 18 +- src/other_menus.c | 12 +- src/pokemon_3.c | 17 +- src/rescue_password_menu.c | 3 +- src/save_menu.c | 11 +- src/sprite.c | 471 ++++++++++++++++++++++++++++++++- src/unk_menu_203B360.c | 13 +- sym_ewram.txt | 4 +- 10 files changed, 490 insertions(+), 467 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index 8a7213ff..dd69ef0e 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,404 +5,6 @@ .text - thumb_func_start sub_8004EA8 -sub_8004EA8: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0xC - adds r5, r0, 0 - mov r8, r1 - adds r0, r2, 0 - adds r6, r3, 0 - cmp r0, 0 - beq _08004EC2 - bl sub_80052BC -_08004EC2: - ldr r0, _08004F40 - ldr r7, [r0] - mov r12, r0 - cmp r7, 0x7F - ble _08004ECE - b _08005082 -_08004ECE: - mov r2, sp - ldrh r0, [r5] - strh r0, [r2] - ldrh r0, [r5, 0x2] - strh r0, [r2, 0x2] - ldrh r4, [r5, 0x4] - ldr r0, _08004F44 - ands r0, r4 - strh r0, [r2, 0x4] - ldrh r3, [r5, 0x6] - ldr r0, _08004F48 - ands r0, r3 - strh r0, [r2, 0x6] - ldrh r0, [r5, 0x8] - strh r0, [r2, 0x8] - movs r1, 0xE0 - lsls r1, 4 - ands r1, r3 - lsrs r1, 9 - ldr r0, _08004F4C - ands r0, r4 - lsls r0, 4 - orrs r1, r0 - strh r1, [r2, 0xA] - lsls r1, r7, 3 - ldr r0, _08004F50 - adds r3, r1, r0 - mov r0, r8 - movs r2, 0x16 - ldrsh r1, [r0, r2] - mov r0, sp - ldrb r0, [r0, 0x3] - lsls r0, 24 - asrs r0, 24 - adds r7, r1, r0 - cmp r7, 0 - bge _08004F1A - movs r7, 0 -_08004F1A: - cmp r7, 0xFF - ble _08004F20 - movs r7, 0xFF -_08004F20: - cmp r6, 0 - bne _08004F54 - add r2, sp, 0x4 - ldrh r0, [r2] - strh r0, [r3] - adds r2, 0x2 - ldrh r0, [r2] - strh r0, [r3, 0x2] - adds r2, 0x2 - adds r1, r3, 0x4 - ldrh r0, [r2] - strh r0, [r1] - adds r2, 0x2 - ldrh r0, [r2] - strh r0, [r1, 0x2] - b _08004F86 - .align 2, 0 -_08004F40: .4byte gSpriteCount -_08004F44: .4byte 0x0000fcff -_08004F48: .4byte 0x0000f1ff -_08004F4C: .4byte 0x000003ff -_08004F50: .4byte gUnknown_20262A8 -_08004F54: - add r4, sp, 0x4 - ldrh r1, [r4] - ldrh r0, [r6] - ands r0, r1 - ldrh r1, [r6, 0x6] - orrs r0, r1 - strh r0, [r3] - adds r4, 0x2 - ldrh r1, [r4] - ldrh r0, [r6, 0x2] - ands r0, r1 - ldrh r1, [r6, 0x8] - orrs r0, r1 - strh r0, [r3, 0x2] - adds r4, 0x2 - adds r2, r3, 0x4 - ldrh r1, [r4] - ldrh r0, [r6, 0x4] - ands r0, r1 - ldrh r1, [r6, 0xA] - orrs r0, r1 - strh r0, [r2] - adds r4, 0x2 - ldrh r0, [r4] - strh r0, [r2, 0x2] -_08004F86: - mov r0, sp - ldrb r0, [r0, 0x2] - cmp r0, 0 - beq _08004FB0 - ldr r1, _08004FA8 - mov r0, sp - ldrb r0, [r0, 0x2] - lsls r0, 1 - adds r1, r0, r1 - movs r4, 0 - ldrsh r0, [r1, r4] - cmp r0, 0 - beq _08004FB0 - adds r1, r0, 0 - ldr r0, _08004FAC - ands r1, r0 - b _08004FC0 - .align 2, 0 -_08004FA8: .4byte gUnknown_2025672 -_08004FAC: .4byte 0x000003ff -_08004FB0: - ldrh r1, [r3, 0x4] - ldr r2, _08005090 - ands r1, r2 - mov r6, r8 - movs r4, 0x14 - ldrsh r0, [r6, r4] - adds r1, r0 - ands r1, r2 -_08004FC0: - ldrh r2, [r3, 0x4] - movs r0, 0xFC - lsls r0, 8 - ands r0, r2 - orrs r0, r1 - strh r0, [r3, 0x4] - ldrh r4, [r3, 0x2] - ldr r5, _08005094 - adds r2, r5, 0 - ands r2, r4 - ldr r6, _08005098 - adds r1, r2, r6 - mov r2, r8 - movs r6, 0 - ldrsh r0, [r2, r6] - adds r2, r1, r0 - movs r0, 0x40 - negs r0, r0 - mov r9, r0 - cmp r2, r9 - blt _08005082 - cmp r2, 0xEF - bgt _08005082 - ands r2, r5 - movs r0, 0xFE - lsls r0, 8 - ands r0, r4 - orrs r0, r2 - strh r0, [r3, 0x2] - ldrh r0, [r3, 0x6] - lsls r4, r0, 16 - ldr r1, _0800509C - adds r5, r1, 0 - lsrs r2, r4, 20 - ldr r6, _080050A0 - adds r1, r2, r6 - mov r2, r8 - movs r6, 0x2 - ldrsh r0, [r2, r6] - adds r2, r1, r0 - cmp r2, r9 - blt _08005082 - cmp r2, 0x9F - bgt _08005082 - movs r0, 0xFF - ands r2, r0 - ldrh r1, [r3] - movs r0, 0xFF - lsls r0, 8 - ands r0, r1 - orrs r0, r2 - strh r0, [r3] - lsrs r0, r4, 17 - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - bne _08005044 - mov r0, r8 - ldrb r1, [r0, 0x1E] - movs r0, 0xF - ands r1, r0 - lsls r1, 12 - ldrh r0, [r3, 0x4] - ands r0, r5 - orrs r0, r1 - strh r0, [r3, 0x4] -_08005044: - mov r0, sp - ldrb r0, [r0, 0x2] - cmp r0, 0 - beq _08005068 - ldr r1, _080050A4 - mov r0, sp - ldrb r0, [r0, 0x2] - lsls r0, 1 - adds r0, r1 - movs r2, 0 - ldrsh r1, [r0, r2] - movs r0, 0xF - ands r1, r0 - lsls r1, 12 - ldrh r0, [r3, 0x4] - ands r0, r5 - orrs r0, r1 - strh r0, [r3, 0x4] -_08005068: - ldr r0, _080050A8 - mov r4, r12 - ldr r3, [r4] - lsls r2, r3, 3 - adds r2, r0 - ldr r1, _080050AC - lsls r0, r7, 3 - adds r0, r1 - ldr r1, [r0] - str r1, [r2] - str r2, [r0] - adds r3, 0x1 - str r3, [r4] -_08005082: - add sp, 0xC - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08005090: .4byte 0x000003ff -_08005094: .4byte 0x000001ff -_08005098: .4byte 0xffffff00 -_0800509C: .4byte 0x00000fff -_080050A0: .4byte 0xfffffe00 -_080050A4: .4byte gUnknown_2025682 -_080050A8: .4byte gUnknown_2025EA8 -_080050AC: .4byte gUnknown_20256A0 - thumb_func_end sub_8004EA8 - - thumb_func_start AddSprite -AddSprite: - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r6, r0, 0 - adds r7, r1, 0 - mov r8, r2 - adds r4, r3, 0 - ldr r0, _080050F4 - ldr r0, [r0] - cmp r0, 0x7F - bgt _08005168 - lsls r1, r0, 3 - ldr r0, _080050F8 - adds r5, r1, r0 - cmp r7, 0 - bge _080050D2 - movs r7, 0 -_080050D2: - cmp r7, 0xFF - ble _080050D8 - movs r7, 0xFF -_080050D8: - cmp r4, 0 - bne _080050FC - ldrh r0, [r6] - strh r0, [r5] - ldrh r0, [r6, 0x2] - strh r0, [r5, 0x2] - adds r1, r6, 0x4 - adds r2, r5, 0x4 - ldrh r0, [r1] - strh r0, [r2] - ldrh r0, [r1, 0x2] - strh r0, [r2, 0x2] - b _08005128 - .align 2, 0 -_080050F4: .4byte gSpriteCount -_080050F8: .4byte gUnknown_20262A8 -_080050FC: - ldrh r1, [r6] - ldrh r0, [r4] - ands r0, r1 - ldrh r1, [r4, 0x6] - orrs r0, r1 - strh r0, [r5] - ldrh r1, [r6, 0x2] - ldrh r0, [r4, 0x2] - ands r0, r1 - ldrh r1, [r4, 0x8] - orrs r0, r1 - strh r0, [r5, 0x2] - adds r2, r6, 0x4 - adds r3, r5, 0x4 - ldrh r1, [r2] - ldrh r0, [r4, 0x4] - ands r0, r1 - ldrh r1, [r4, 0xA] - orrs r0, r1 - strh r0, [r3] - ldrh r0, [r2, 0x2] - strh r0, [r3, 0x2] -_08005128: - ldrh r4, [r5, 0x6] - lsrs r4, 4 - adds r0, r4, 0 - movs r1, 0 - bl nullsub_3 - movs r0, 0xFF - ands r4, r0 - ldrh r1, [r5] - movs r0, 0xFF - lsls r0, 8 - ands r0, r1 - orrs r0, r4 - strh r0, [r5] - mov r0, r8 - cmp r0, 0 - beq _0800514E - bl sub_80052BC -_0800514E: - ldr r0, _08005174 - ldr r4, _08005178 - ldr r3, [r4] - lsls r2, r3, 3 - adds r2, r0 - ldr r1, _0800517C - lsls r0, r7, 3 - adds r0, r1 - ldr r1, [r0] - str r1, [r2] - str r2, [r0] - adds r3, 0x1 - str r3, [r4] -_08005168: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08005174: .4byte gUnknown_2025EA8 -_08005178: .4byte gSpriteCount -_0800517C: .4byte gUnknown_20256A0 - thumb_func_end AddSprite - - thumb_func_start sub_8005180 -sub_8005180: - push {lr} - ldr r2, _080051A8 - adds r1, r2, 0 - cmp r2, 0 - beq _0800519E -_0800518A: - ldr r0, [r1, 0x4] - cmp r0, 0 - beq _08005198 - cmp r2, 0 - beq _08005196 - str r1, [r2] -_08005196: - adds r2, r1, 0 -_08005198: - ldr r1, [r1] - cmp r1, 0 - bne _0800518A -_0800519E: - movs r0, 0 - str r0, [r2] - pop {r0} - bx r0 - .align 2, 0 -_080051A8: .4byte gUnknown_20256A0 - thumb_func_end sub_8005180 - thumb_func_start CopySpritesToOam CopySpritesToOam: push {r4-r6,lr} diff --git a/include/rescue_password_menu.h b/include/rescue_password_menu.h index e9c6d827..e4ce551d 100644 --- a/include/rescue_password_menu.h +++ b/include/rescue_password_menu.h @@ -2,14 +2,8 @@ #define GUARD_RESCUE_PASSWORD_MENU_H #include "menu.h" - -struct unkSprite -{ - u16 unk0; - u16 unk2; - u16 unk4; - u16 unk6; -}; +#include "sprite.h" +#include "text.h" // Similar to unkStruct_203B360 struct RescuePasswordMenu diff --git a/include/sprite.h b/include/sprite.h index 0114092e..125b24e9 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -1,17 +1,32 @@ #ifndef GUARD_SPRITE_H #define GUARD_SPRITE_H +// size: 0x8 +struct unkSprite +{ + u16 unk0; + u16 unk2; + u16 unk4; + u16 unk6; +}; + // size: 0x8 struct UnkSpriteLink { struct UnkSpriteLink *unk0; struct UnkSpriteLink *unk4; }; +// size: 0x8 +struct UnkSpriteLink2 +{ + struct unkSprite *unk0; + struct unkSprite *unk4; +}; // size: 0x808 struct SpriteList { - struct UnkSpriteLink sprites[16][16]; + struct UnkSpriteLink sprites[256]; u32 unk800; u32 unk804; }; @@ -32,6 +47,7 @@ void ResetSprites(bool8); void sub_8004E8C(struct unkStruct_2039DB0 *); // sprite.s +extern void AddSprite(struct unkSprite *, s32, u32 *, struct unkStruct_2039DB0 *); extern void BlinkSavingIcon(void); extern void SetSavingIconCoords(u32); diff --git a/src/other_menus.c b/src/other_menus.c index 74b84f95..00a84feb 100644 --- a/src/other_menus.c +++ b/src/other_menus.c @@ -13,15 +13,6 @@ #include "code_8094F88.h" #include "sprite.h" -struct unkSprite -{ - u16 unk0; - u16 unk2; - u16 unk4; - u16 unk6; -}; - - struct unkStruct_203B35C { // size: 0x504 @@ -471,7 +462,6 @@ s32 sub_8035D3C(void); extern s32 sub_8035D74(void); extern void xxx_call_start_bg_music(void); extern void xxx_draw_string_80144C4(void); -extern void AddSprite(struct unkSprite *, u32, u32, u32); void sub_8036FDC(s32 param_1) { @@ -839,7 +829,7 @@ void sub_8037748(void) gUnknown_203B35C->unkC.unk6 = (gUnknown_203B35C->unkC.unk6 & 0xf) | temp2; if ((gUnknown_203B35C->unk14 & 8) != 0) { - AddSprite(&gUnknown_203B35C->unkC,0x100,0,0x0); + AddSprite(&gUnknown_203B35C->unkC, 0x100, NULL, NULL); } xxx_draw_string_80144C4(); gUnknown_203B35C->unk14++; diff --git a/src/pokemon_3.c b/src/pokemon_3.c index 963ae5de..67f1e4c5 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -5,6 +5,7 @@ #include "random.h" #include "constants/iq_skill.h" #include "constants/tactic.h" +#include "sprite.h" extern u8 *gIQSkillNames[]; extern u32 gIQSkillDescriptions[]; @@ -29,15 +30,7 @@ struct unkStruct_808E9EC }; extern u32 gUnknown_81076C4[]; -struct unkStruct_202F3E8 -{ - u16 unk0; - u16 unk2; - u16 unk4; - u16 unk6; -}; - -extern struct unkStruct_202F3E8 gUnknown_202F3E8[]; +extern struct unkSprite gUnknown_202F3E8[3]; // Shadow sprites of some kind extern s16 gUnknown_810AC60; // 0xC extern s16 gUnknown_810AC62; // 0xC extern s16 gUnknown_810AC68; // 0x8 @@ -47,8 +40,6 @@ extern s16 gUnknown_810AC66; // 0x8 // 2, 4, 6, 7, 8, 9, 0xA, 0xD, 0xF, 0x11 extern s32 gUnknown_810AC90[10]; -extern void AddSprite(u16 *, u32, u32, u32); - extern void SaveDungeonLocation(struct unkStruct_8094924*, struct DungeonLocation*); extern void xxx_save_poke_sub_c_808F41C(struct unkStruct_8094924*, struct unkPokeSubStruct_C*); extern void SavePokemonMoves(struct unkStruct_8094924*, struct Move*); @@ -71,7 +62,7 @@ bool8 sub_808E668(s16 a1, s16* a2, s16* a3) if (((shifted - 0x320000) >> 16) > 1) { u8 shadowSize = GetShadowSize(a1); u32 unk2, unk6; - struct unkStruct_202F3E8* arg0; + struct unkSprite* arg0; unk2 = a2[0] + a3[8]; unk6 = a2[1] + a3[9]; @@ -84,7 +75,7 @@ bool8 sub_808E668(s16 a1, s16* a2, s16* a3) unk6 &= 0xfff; unk6 <<= 4; arg0->unk6 = (arg0->unk6 & 0xf) | unk6; - AddSprite((u16*)arg0, 0, 0, 0); + AddSprite(arg0, 0, NULL, NULL); } return 1; } diff --git a/src/rescue_password_menu.c b/src/rescue_password_menu.c index 5e9b2749..2bde7231 100644 --- a/src/rescue_password_menu.c +++ b/src/rescue_password_menu.c @@ -250,7 +250,6 @@ extern void sub_8031E10(void); extern u32 sub_80154F0(void); extern u32 sub_8031DCC(void); extern void sub_8031E00(void); -extern void AddSprite(struct unkSprite *, u32, u32, u32); extern void xxx_draw_string_80144C4(void); void DisplayRescuePasswordError(u32 error); @@ -747,7 +746,7 @@ void sub_80391F8(void) iVar2->unk6 = temp | temp2; if ((gRescuePasswordMenu->unk210 & 8) != 0) { - AddSprite(iVar2,0x100,0,0); + AddSprite(iVar2, 0x100, NULL, NULL); } xxx_draw_string_80144C4(); gRescuePasswordMenu->unk210 += 1; diff --git a/src/save_menu.c b/src/save_menu.c index a7ffb072..fe67564f 100644 --- a/src/save_menu.c +++ b/src/save_menu.c @@ -7,14 +7,6 @@ #include "sprite.h" #include "code_80130A8.h" -struct unkSprite -{ - u16 unk0; - u16 unk2; - u16 unk4; - u16 unk6; -}; - struct unkStruct_203B360 { // size: 0x1b4 @@ -138,7 +130,6 @@ extern void sub_8038830(); extern void sub_80388C4(void); extern void sub_8014114(); extern void sub_80140F8(void); -extern void AddSprite(struct unkSprite *, u32, u32, u32); void CreateSaveMenu(s32 currMenu) { @@ -338,7 +329,7 @@ void sub_8038830(void) void sub_80388C4(void) { if ((gUnknown_203B364->unk1B0 & 8) != 0) { - AddSprite(&gUnknown_203B364->unk1A8, 0x100, 0, 0); + AddSprite(&gUnknown_203B364->unk1A8, 0x100, NULL, NULL); } gUnknown_203B364->unk1B0++; } diff --git a/src/sprite.c b/src/sprite.c index ea6075e8..3f3f8939 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -2,8 +2,8 @@ #include "sprite.h" extern struct SpriteList gUnknown_20256A0; -extern struct UnkSpriteLink gUnknown_2025EA8[128]; -extern struct UnkSpriteLink gUnknown_20262A8[128]; +extern struct UnkSpriteLink2 gUnknown_2025EA8[128]; +extern struct unkSprite gUnknown_20262A8[128]; extern u32 gSpriteCount; /* 20266A8 */ extern u32 gUnknown_20266B0; extern u32 *gCharMemCursor; /* 2026E30 */ @@ -21,16 +21,19 @@ void ResetSprites(bool8 a0) struct UnkSpriteLink *a; struct UnkSpriteLink *b; struct UnkSpriteLink *c; + struct UnkSpriteLink2 *bro; + struct unkSprite *d; + struct unkSprite *deez; gSpriteCount = 0; gCharMemCursor = (u32*)0x6010000; gUnknown_203B074 = &gUnknown_20266B0; - a = &gUnknown_20256A0.sprites[0][0]; + a = &gUnknown_20256A0.sprites[0]; b = a + 1; // 16 loops, very smart - for (i = 0; i < 0x100; i += 0x10) { + for (i = 0; i < 256; i += 16) { c = NULL; a->unk0 = b; a->unk4 = c; @@ -99,14 +102,14 @@ void ResetSprites(bool8 a0) } if (a0) { - c = NULL; - b = &gUnknown_20262A8[0]; - a = &gUnknown_2025EA8[0]; + deez = NULL; + d = &gUnknown_20262A8[0]; + bro = &gUnknown_2025EA8[0]; for (i = 0; i < 128; i++) { - a->unk0 = c; - a->unk4 = b; - b++; - a++; + bro->unk0 = deez; + bro->unk4 = d; + d++; + bro++; } } @@ -122,4 +125,450 @@ void sub_8004E8C(struct unkStruct_2039DB0 *a0) a0->unk6 = 0; a0->unk8 = 0; a0->unkA = 0; +} + +// Need more structs decomped first https://decomp.me/scratch/VYqKb +NAKED +void sub_8004EA8(s32 a0, s16 *a1, u32 *a2, u16 *a3) +{ + asm_unified( + "push {r4-r7,lr}\n" + "\tmov r7, r9\n" + "\tmov r6, r8\n" + "\tpush {r6,r7}\n" + "\tsub sp, 0xC\n" + "\tadds r5, r0, 0\n" + "\tmov r8, r1\n" + "\tadds r0, r2, 0\n" + "\tadds r6, r3, 0\n" + "\tcmp r0, 0\n" + "\tbeq _08004EC2\n" + "\tbl sub_80052BC\n" +"_08004EC2:\n" + "\tldr r0, _08004F40\n" + "\tldr r7, [r0]\n" + "\tmov r12, r0\n" + "\tcmp r7, 0x7F\n" + "\tble _08004ECE\n" + "\tb _08005082\n" +"_08004ECE:\n" + "\tmov r2, sp\n" + "\tldrh r0, [r5]\n" + "\tstrh r0, [r2]\n" + "\tldrh r0, [r5, 0x2]\n" + "\tstrh r0, [r2, 0x2]\n" + "\tldrh r4, [r5, 0x4]\n" + "\tldr r0, _08004F44\n" + "\tands r0, r4\n" + "\tstrh r0, [r2, 0x4]\n" + "\tldrh r3, [r5, 0x6]\n" + "\tldr r0, _08004F48\n" + "\tands r0, r3\n" + "\tstrh r0, [r2, 0x6]\n" + "\tldrh r0, [r5, 0x8]\n" + "\tstrh r0, [r2, 0x8]\n" + "\tmovs r1, 0xE0\n" + "\tlsls r1, 4\n" + "\tands r1, r3\n" + "\tlsrs r1, 9\n" + "\tldr r0, _08004F4C\n" + "\tands r0, r4\n" + "\tlsls r0, 4\n" + "\torrs r1, r0\n" + "\tstrh r1, [r2, 0xA]\n" + "\tlsls r1, r7, 3\n" + "\tldr r0, _08004F50\n" + "\tadds r3, r1, r0\n" + "\tmov r0, r8\n" + "\tmovs r2, 0x16\n" + "\tldrsh r1, [r0, r2]\n" + "\tmov r0, sp\n" + "\tldrb r0, [r0, 0x3]\n" + "\tlsls r0, 24\n" + "\tasrs r0, 24\n" + "\tadds r7, r1, r0\n" + "\tcmp r7, 0\n" + "\tbge _08004F1A\n" + "\tmovs r7, 0\n" +"_08004F1A:\n" + "\tcmp r7, 0xFF\n" + "\tble _08004F20\n" + "\tmovs r7, 0xFF\n" +"_08004F20:\n" + "\tcmp r6, 0\n" + "\tbne _08004F54\n" + "\tadd r2, sp, 0x4\n" + "\tldrh r0, [r2]\n" + "\tstrh r0, [r3]\n" + "\tadds r2, 0x2\n" + "\tldrh r0, [r2]\n" + "\tstrh r0, [r3, 0x2]\n" + "\tadds r2, 0x2\n" + "\tadds r1, r3, 0x4\n" + "\tldrh r0, [r2]\n" + "\tstrh r0, [r1]\n" + "\tadds r2, 0x2\n" + "\tldrh r0, [r2]\n" + "\tstrh r0, [r1, 0x2]\n" + "\tb _08004F86\n" + "\t.align 2, 0\n" +"_08004F40: .4byte gSpriteCount\n" +"_08004F44: .4byte 0x0000fcff\n" +"_08004F48: .4byte 0x0000f1ff\n" +"_08004F4C: .4byte 0x000003ff\n" +"_08004F50: .4byte gUnknown_20262A8\n" +"_08004F54:\n" + "\tadd r4, sp, 0x4\n" + "\tldrh r1, [r4]\n" + "\tldrh r0, [r6]\n" + "\tands r0, r1\n" + "\tldrh r1, [r6, 0x6]\n" + "\torrs r0, r1\n" + "\tstrh r0, [r3]\n" + "\tadds r4, 0x2\n" + "\tldrh r1, [r4]\n" + "\tldrh r0, [r6, 0x2]\n" + "\tands r0, r1\n" + "\tldrh r1, [r6, 0x8]\n" + "\torrs r0, r1\n" + "\tstrh r0, [r3, 0x2]\n" + "\tadds r4, 0x2\n" + "\tadds r2, r3, 0x4\n" + "\tldrh r1, [r4]\n" + "\tldrh r0, [r6, 0x4]\n" + "\tands r0, r1\n" + "\tldrh r1, [r6, 0xA]\n" + "\torrs r0, r1\n" + "\tstrh r0, [r2]\n" + "\tadds r4, 0x2\n" + "\tldrh r0, [r4]\n" + "\tstrh r0, [r2, 0x2]\n" +"_08004F86:\n" + "\tmov r0, sp\n" + "\tldrb r0, [r0, 0x2]\n" + "\tcmp r0, 0\n" + "\tbeq _08004FB0\n" + "\tldr r1, _08004FA8\n" + "\tmov r0, sp\n" + "\tldrb r0, [r0, 0x2]\n" + "\tlsls r0, 1\n" + "\tadds r1, r0, r1\n" + "\tmovs r4, 0\n" + "\tldrsh r0, [r1, r4]\n" + "\tcmp r0, 0\n" + "\tbeq _08004FB0\n" + "\tadds r1, r0, 0\n" + "\tldr r0, _08004FAC\n" + "\tands r1, r0\n" + "\tb _08004FC0\n" + "\t.align 2, 0\n" +"_08004FA8: .4byte gUnknown_2025672\n" +"_08004FAC: .4byte 0x000003ff\n" +"_08004FB0:\n" + "\tldrh r1, [r3, 0x4]\n" + "\tldr r2, _08005090\n" + "\tands r1, r2\n" + "\tmov r6, r8\n" + "\tmovs r4, 0x14\n" + "\tldrsh r0, [r6, r4]\n" + "\tadds r1, r0\n" + "\tands r1, r2\n" +"_08004FC0:\n" + "\tldrh r2, [r3, 0x4]\n" + "\tmovs r0, 0xFC\n" + "\tlsls r0, 8\n" + "\tands r0, r2\n" + "\torrs r0, r1\n" + "\tstrh r0, [r3, 0x4]\n" + "\tldrh r4, [r3, 0x2]\n" + "\tldr r5, _08005094\n" + "\tadds r2, r5, 0\n" + "\tands r2, r4\n" + "\tldr r6, _08005098\n" + "\tadds r1, r2, r6\n" + "\tmov r2, r8\n" + "\tmovs r6, 0\n" + "\tldrsh r0, [r2, r6]\n" + "\tadds r2, r1, r0\n" + "\tmovs r0, 0x40\n" + "\tnegs r0, r0\n" + "\tmov r9, r0\n" + "\tcmp r2, r9\n" + "\tblt _08005082\n" + "\tcmp r2, 0xEF\n" + "\tbgt _08005082\n" + "\tands r2, r5\n" + "\tmovs r0, 0xFE\n" + "\tlsls r0, 8\n" + "\tands r0, r4\n" + "\torrs r0, r2\n" + "\tstrh r0, [r3, 0x2]\n" + "\tldrh r0, [r3, 0x6]\n" + "\tlsls r4, r0, 16\n" + "\tldr r1, _0800509C\n" + "\tadds r5, r1, 0\n" + "\tlsrs r2, r4, 20\n" + "\tldr r6, _080050A0\n" + "\tadds r1, r2, r6\n" + "\tmov r2, r8\n" + "\tmovs r6, 0x2\n" + "\tldrsh r0, [r2, r6]\n" + "\tadds r2, r1, r0\n" + "\tcmp r2, r9\n" + "\tblt _08005082\n" + "\tcmp r2, 0x9F\n" + "\tbgt _08005082\n" + "\tmovs r0, 0xFF\n" + "\tands r2, r0\n" + "\tldrh r1, [r3]\n" + "\tmovs r0, 0xFF\n" + "\tlsls r0, 8\n" + "\tands r0, r1\n" + "\torrs r0, r2\n" + "\tstrh r0, [r3]\n" + "\tlsrs r0, r4, 17\n" + "\tmovs r1, 0x1\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbne _08005044\n" + "\tmov r0, r8\n" + "\tldrb r1, [r0, 0x1E]\n" + "\tmovs r0, 0xF\n" + "\tands r1, r0\n" + "\tlsls r1, 12\n" + "\tldrh r0, [r3, 0x4]\n" + "\tands r0, r5\n" + "\torrs r0, r1\n" + "\tstrh r0, [r3, 0x4]\n" +"_08005044:\n" + "\tmov r0, sp\n" + "\tldrb r0, [r0, 0x2]\n" + "\tcmp r0, 0\n" + "\tbeq _08005068\n" + "\tldr r1, _080050A4\n" + "\tmov r0, sp\n" + "\tldrb r0, [r0, 0x2]\n" + "\tlsls r0, 1\n" + "\tadds r0, r1\n" + "\tmovs r2, 0\n" + "\tldrsh r1, [r0, r2]\n" + "\tmovs r0, 0xF\n" + "\tands r1, r0\n" + "\tlsls r1, 12\n" + "\tldrh r0, [r3, 0x4]\n" + "\tands r0, r5\n" + "\torrs r0, r1\n" + "\tstrh r0, [r3, 0x4]\n" +"_08005068:\n" + "\tldr r0, _080050A8\n" + "\tmov r4, r12\n" + "\tldr r3, [r4]\n" + "\tlsls r2, r3, 3\n" + "\tadds r2, r0\n" + "\tldr r1, _080050AC\n" + "\tlsls r0, r7, 3\n" + "\tadds r0, r1\n" + "\tldr r1, [r0]\n" + "\tstr r1, [r2]\n" + "\tstr r2, [r0]\n" + "\tadds r3, 0x1\n" + "\tstr r3, [r4]\n" +"_08005082:\n" + "\tadd sp, 0xC\n" + "\tpop {r3,r4}\n" + "\tmov r8, r3\n" + "\tmov r9, r4\n" + "\tpop {r4-r7}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.align 2, 0\n" +"_08005090: .4byte 0x000003ff\n" +"_08005094: .4byte 0x000001ff\n" +"_08005098: .4byte 0xffffff00\n" +"_0800509C: .4byte 0x00000fff\n" +"_080050A0: .4byte 0xfffffe00\n" +"_080050A4: .4byte gUnknown_2025682\n" +"_080050A8: .4byte gUnknown_2025EA8\n" +"_080050AC: .4byte gUnknown_20256A0"); +} + +#ifdef NONMATCHING // https://decomp.me/scratch/YCfKG +// a2 and a3 are always called with NULL lol +void AddSprite(struct unkSprite *a0, s32 a1, u32 *a2, struct unkStruct_2039DB0 *a3) +{ + u16 uVar1; + struct unkSprite *spr; + struct UnkSpriteLink *a; + struct UnkSpriteLink *b; + + if (gSpriteCount >= 128) + return; + + spr = &gUnknown_20262A8[gSpriteCount]; + + if (a1 < 0) + a1 = 0; + if (a1 > 255) + a1 = 255; + + if (a3 == NULL) { + spr->unk0 = a0->unk0; + spr->unk2 = a0->unk2; + spr->unk4 = a0->unk4; + spr->unk6 = a0->unk6; + } + else { + spr->unk0 = (a3->unk0 & a0->unk0) | a3->unk6; + spr->unk2 = (a3->unk2 & a0->unk2) | a3->unk8; + spr->unk4 = (a3->unk4 & a0->unk4) | a3->unkA; + spr->unk6 = a0->unk6; + } + + uVar1 = spr->unk6 >> 4; + nullsub_3(uVar1, 0); + spr->unk0 = (uVar1 & 0xFF) | (spr->unk0 & 0xFF00); + + if (a2 != NULL) + sub_80052BC(a2); + + a = &gUnknown_2025EA8[0]; + a += gSpriteCount; + b = &gUnknown_20256A0.sprites[0]; + b += a1; + a->unk0 = b->unk0; + b->unk0 = a; + + gSpriteCount++; +} +#else +NAKED +void AddSprite(struct unkSprite *a0, s32 a1, u32 *a2, struct unkStruct_2039DB0 *a3) +{ + asm_unified( + "push {r4-r7,lr}\n" + "\tmov r7, r8\n" + "\tpush {r7}\n" + "\tadds r6, r0, 0\n" + "\tadds r7, r1, 0\n" + "\tmov r8, r2\n" + "\tadds r4, r3, 0\n" + "\tldr r0, _080050F4\n" + "\tldr r0, [r0]\n" + "\tcmp r0, 0x7F\n" + "\tbgt _08005168\n" + "\tlsls r1, r0, 3\n" + "\tldr r0, _080050F8\n" + "\tadds r5, r1, r0\n" + "\tcmp r7, 0\n" + "\tbge _080050D2\n" + "\tmovs r7, 0\n" +"_080050D2:\n" + "\tcmp r7, 0xFF\n" + "\tble _080050D8\n" + "\tmovs r7, 0xFF\n" +"_080050D8:\n" + "\tcmp r4, 0\n" + "\tbne _080050FC\n" + "\tldrh r0, [r6]\n" + "\tstrh r0, [r5]\n" + "\tldrh r0, [r6, 0x2]\n" + "\tstrh r0, [r5, 0x2]\n" + "\tadds r1, r6, 0x4\n" + "\tadds r2, r5, 0x4\n" + "\tldrh r0, [r1]\n" + "\tstrh r0, [r2]\n" + "\tldrh r0, [r1, 0x2]\n" + "\tstrh r0, [r2, 0x2]\n" + "\tb _08005128\n" + "\t.align 2, 0\n" +"_080050F4: .4byte gSpriteCount\n" +"_080050F8: .4byte gUnknown_20262A8\n" +"_080050FC:\n" + "\tldrh r1, [r6]\n" + "\tldrh r0, [r4]\n" + "\tands r0, r1\n" + "\tldrh r1, [r4, 0x6]\n" + "\torrs r0, r1\n" + "\tstrh r0, [r5]\n" + "\tldrh r1, [r6, 0x2]\n" + "\tldrh r0, [r4, 0x2]\n" + "\tands r0, r1\n" + "\tldrh r1, [r4, 0x8]\n" + "\torrs r0, r1\n" + "\tstrh r0, [r5, 0x2]\n" + "\tadds r2, r6, 0x4\n" + "\tadds r3, r5, 0x4\n" + "\tldrh r1, [r2]\n" + "\tldrh r0, [r4, 0x4]\n" + "\tands r0, r1\n" + "\tldrh r1, [r4, 0xA]\n" + "\torrs r0, r1\n" + "\tstrh r0, [r3]\n" + "\tldrh r0, [r2, 0x2]\n" + "\tstrh r0, [r3, 0x2]\n" +"_08005128:\n" + "\tldrh r4, [r5, 0x6]\n" + "\tlsrs r4, 4\n" + "\tadds r0, r4, 0\n" + "\tmovs r1, 0\n" + "\tbl nullsub_3\n" + "\tmovs r0, 0xFF\n" + "\tands r4, r0\n" + "\tldrh r1, [r5]\n" + "\tmovs r0, 0xFF\n" + "\tlsls r0, 8\n" + "\tands r0, r1\n" + "\torrs r0, r4\n" + "\tstrh r0, [r5]\n" + "\tmov r0, r8\n" + "\tcmp r0, 0\n" + "\tbeq _0800514E\n" + "\tbl sub_80052BC\n" +"_0800514E:\n" + "\tldr r0, _08005174\n" + "\tldr r4, _08005178\n" + "\tldr r3, [r4]\n" + "\tlsls r2, r3, 3\n" + "\tadds r2, r0\n" + "\tldr r1, _0800517C\n" + "\tlsls r0, r7, 3\n" + "\tadds r0, r1\n" + "\tldr r1, [r0]\n" + "\tstr r1, [r2]\n" + "\tstr r2, [r0]\n" + "\tadds r3, 0x1\n" + "\tstr r3, [r4]\n" +"_08005168:\n" + "\tpop {r3}\n" + "\tmov r8, r3\n" + "\tpop {r4-r7}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.align 2, 0\n" +"_08005174: .4byte gUnknown_2025EA8\n" +"_08005178: .4byte gSpriteCount\n" +"_0800517C: .4byte gUnknown_20256A0"); +} +#endif + +void sub_8005180(void) +{ + struct UnkSpriteLink *r1; + struct UnkSpriteLink *r2; + + r2 = &gUnknown_20256A0.sprites[0]; + r1 = r2; + + if (r2 != NULL) { + do { + if (r1->unk4 != NULL) { + if (r2 != NULL) + r2->unk0 = r1; + r2 = r1; + } + r1 = r1->unk0; + } while (r1 != NULL); + } + + r2->unk0 = NULL; } \ No newline at end of file diff --git a/src/unk_menu_203B360.c b/src/unk_menu_203B360.c index aec1f797..24a1e75c 100644 --- a/src/unk_menu_203B360.c +++ b/src/unk_menu_203B360.c @@ -5,14 +5,7 @@ #include "menu.h" #include "text1.h" #include "menu_input.h" - -struct unkSprite -{ - u16 unk0; - u16 unk2; - u16 unk4; - u16 unk6; -}; +#include "sprite.h" // Similar to RescuePasswordMenu struct unkStruct_203B360 @@ -61,8 +54,6 @@ ALIGNED(4) const u8 StorageEmpty_80E6EE4[] = _("{CENTER_ALIGN}The storage space ALIGNED(4) const u8 Caution_80E6F04[] = _("{CENTER_ALIGN}{COLOR_1 RED}Caution!{END_COLOR_TEXT_1} "); static const u8 fill0[] = "pksdir0"; - -extern void AddSprite(struct unkSprite *, u32, u32, u32); extern void sub_8038440(); extern void sub_80384D0(); @@ -188,7 +179,7 @@ void sub_8038440(void) void sub_80384D0(void) { if ((gUnknown_203B360->unk1B0 & 8) != 0) { - AddSprite(&gUnknown_203B360->unk1A8, 0x100, 0, 0); + AddSprite(&gUnknown_203B360->unk1A8, 0x100, NULL, NULL); } gUnknown_203B360->unk1B0++; } diff --git a/sym_ewram.txt b/sym_ewram.txt index 26864e82..21f40d03 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -900,10 +900,10 @@ gUnknown_2039DA4: /* 2039DA4 */ gUnknown_2039DA8: /* 2039DA8 */ .space 0x8 -gUnknown_2039DB0: /* 2039DB0 */ +gUnknown_2039DB0: /* 2039DB0 [struct unkStruct_2039DB0] */ .space 0x10 -gUnknown_2039DC0: /* 2039DC0 */ +gUnknown_2039DC0: /* 2039DC0 [struct unkStruct_2039DB0] */ .space 0xC gUnknown_2039DCC: /* 2039DCC */ From c16193eea79158afad54e9118a9224b5a280f1fb Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:38:45 -0400 Subject: [PATCH 04/27] Forgor the declaration --- include/sprite.h | 1 + src/code_2.c | 1 - src/code_80118A4.c | 1 - src/code_8012A18.c | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/sprite.h b/include/sprite.h index 125b24e9..ca897f55 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -45,6 +45,7 @@ struct unkStruct_2039DB0 void InitSprites(void); void ResetSprites(bool8); void sub_8004E8C(struct unkStruct_2039DB0 *); +void sub_8005180(void); // sprite.s extern void AddSprite(struct unkSprite *, s32, u32 *, struct unkStruct_2039DB0 *); diff --git a/src/code_2.c b/src/code_2.c index 3572246f..3a835dfd 100644 --- a/src/code_2.c +++ b/src/code_2.c @@ -48,7 +48,6 @@ extern u32 sub_80009D0(u32); extern void xxx_draw_string_80144C4(void); extern void sub_8005838(u32, u32); extern void nullsub_8(u32); -extern void sub_8005180(void); extern void sub_80060EC(void); extern void sub_8011860(void); extern void sub_800CB20(void); diff --git a/src/code_80118A4.c b/src/code_80118A4.c index 444a3ca8..f84f3378 100644 --- a/src/code_80118A4.c +++ b/src/code_80118A4.c @@ -44,7 +44,6 @@ extern void TransferBGPaletteBuffer(void); extern void xxx_call_update_bg_vram(void); extern void sub_8009908(void); extern void xxx_call_update_bg_sound_input(void); -extern void sub_8005180(void); extern void sub_80060EC(void); extern void sub_8011860(void); extern void sub_800CB20(void); diff --git a/src/code_8012A18.c b/src/code_8012A18.c index e20b728a..d71686cd 100644 --- a/src/code_8012A18.c +++ b/src/code_8012A18.c @@ -7,7 +7,6 @@ extern void sub_8011860(); extern void xxx_draw_string_80144C4(); extern void nullsub_8(u8); -extern void sub_8005180(); extern void sub_800CB20(); extern void CopySpritesToOam(); extern void sub_8005304(); From c61c7df7e433b458c258e1e9230f0598f3da9e19 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:13:01 -0400 Subject: [PATCH 05/27] Match CopySpritesToOam AND DISCOVER --- asm/sprite.s | 57 -------------------------------------- include/sprite.h | 10 +++---- src/code_2.c | 1 - src/code_80118A4.c | 1 - src/code_8012A18.c | 1 - src/sprite.c | 68 ++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 63 insertions(+), 75 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index dd69ef0e..8da34500 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,63 +5,6 @@ .text - thumb_func_start CopySpritesToOam -CopySpritesToOam: - push {r4-r6,lr} - ldr r3, _08005204 - ldr r2, _08005208 - movs r4, 0 - ldr r6, _0800520C - cmp r3, 0 - beq _080051E0 - ldr r5, _08005210 -_080051BC: - ldr r1, [r3, 0x4] - cmp r1, 0 - beq _080051D6 - subs r2, 0x4 - ldrh r0, [r1, 0x4] - strh r0, [r2] - subs r2, 0x2 - ldrh r0, [r1, 0x2] - strh r0, [r2] - subs r2, 0x2 - ldrh r0, [r1] - strh r0, [r2] - adds r4, 0x1 -_080051D6: - ldr r3, [r3] - cmp r3, 0 - beq _080051E0 - cmp r2, r5 - bhi _080051BC -_080051E0: - ldr r1, _08005210 - cmp r2, r1 - bls _080051FA - movs r0, 0 - movs r3, 0xA0 -_080051EA: - subs r2, 0x4 - strh r0, [r2] - subs r2, 0x2 - strh r0, [r2] - subs r2, 0x2 - strh r3, [r2] - cmp r2, r1 - bhi _080051EA -_080051FA: - strh r4, [r6] - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_08005204: .4byte gUnknown_20256A0 -_08005208: .4byte 0x07000400 -_0800520C: .4byte gUnknown_2025670 -_08005210: .4byte 0x07000008 - thumb_func_end CopySpritesToOam - thumb_func_start SetSavingIconCoords SetSavingIconCoords: push {lr} diff --git a/include/sprite.h b/include/sprite.h index ca897f55..288d7a9a 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -4,8 +4,11 @@ // size: 0x8 struct unkSprite { + // y/affineMode/objMode/mosaic/bpp/shape u16 unk0; + // x/matrixNum/size u16 unk2; + // tileNum/priority/paletteNum u16 unk4; u16 unk6; }; @@ -14,12 +17,6 @@ struct unkSprite struct UnkSpriteLink { struct UnkSpriteLink *unk0; - struct UnkSpriteLink *unk4; -}; -// size: 0x8 -struct UnkSpriteLink2 -{ - struct unkSprite *unk0; struct unkSprite *unk4; }; @@ -42,6 +39,7 @@ struct unkStruct_2039DB0 u16 unkA; }; +void CopySpritesToOam(void); void InitSprites(void); void ResetSprites(bool8); void sub_8004E8C(struct unkStruct_2039DB0 *); diff --git a/src/code_2.c b/src/code_2.c index 3a835dfd..15c129cf 100644 --- a/src/code_2.c +++ b/src/code_2.c @@ -51,7 +51,6 @@ extern void nullsub_8(u32); extern void sub_80060EC(void); extern void sub_8011860(void); extern void sub_800CB20(void); -extern void CopySpritesToOam(void); extern void sub_8005304(void); extern void TransferBGPaletteBuffer(void); extern void xxx_call_update_bg_vram(void); diff --git a/src/code_80118A4.c b/src/code_80118A4.c index f84f3378..593f4db2 100644 --- a/src/code_80118A4.c +++ b/src/code_80118A4.c @@ -38,7 +38,6 @@ EWRAM_DATA s16 gUnknown_202DE24; void nullsub_8(u32); void sub_8005838(u32, u32); -extern void CopySpritesToOam(void); extern void sub_8005304(void); extern void TransferBGPaletteBuffer(void); extern void xxx_call_update_bg_vram(void); diff --git a/src/code_8012A18.c b/src/code_8012A18.c index d71686cd..9c85d318 100644 --- a/src/code_8012A18.c +++ b/src/code_8012A18.c @@ -8,7 +8,6 @@ extern void sub_8011860(); extern void xxx_draw_string_80144C4(); extern void nullsub_8(u8); extern void sub_800CB20(); -extern void CopySpritesToOam(); extern void sub_8005304(); extern void TransferBGPaletteBuffer(); extern void xxx_call_update_bg_vram(); diff --git a/src/sprite.c b/src/sprite.c index 3f3f8939..17aedbf4 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1,8 +1,9 @@ #include "global.h" #include "sprite.h" +extern u16 gUnknown_2025670; extern struct SpriteList gUnknown_20256A0; -extern struct UnkSpriteLink2 gUnknown_2025EA8[128]; +extern struct UnkSpriteLink gUnknown_2025EA8[128]; extern struct unkSprite gUnknown_20262A8[128]; extern u32 gSpriteCount; /* 20266A8 */ extern u32 gUnknown_20266B0; @@ -20,10 +21,9 @@ void ResetSprites(bool8 a0) s32 i; struct UnkSpriteLink *a; struct UnkSpriteLink *b; - struct UnkSpriteLink *c; - struct UnkSpriteLink2 *bro; + struct unkSprite *c; struct unkSprite *d; - struct unkSprite *deez; + struct UnkSpriteLink *e; gSpriteCount = 0; gCharMemCursor = (u32*)0x6010000; @@ -102,14 +102,14 @@ void ResetSprites(bool8 a0) } if (a0) { - deez = NULL; + e = NULL; d = &gUnknown_20262A8[0]; - bro = &gUnknown_2025EA8[0]; + a = &gUnknown_2025EA8[0]; for (i = 0; i < 128; i++) { - bro->unk0 = deez; - bro->unk4 = d; + a->unk0 = e; + a->unk4 = d; d++; - bro++; + a++; } } @@ -571,4 +571,54 @@ void sub_8005180(void) } r2->unk0 = NULL; +} + +void CopySpritesToOam(void) +{ + struct UnkSpriteLink *sLink; + struct unkSprite *spr; + u16 *oam; + s32 count; + + sLink = &gUnknown_20256A0.sprites[0]; + oam = (u16 *)(OAM + OAM_SIZE); // End of OAM. Work backwards + count = 0; + + while (sLink != NULL && (u32)oam > (OAM + sizeof(struct OamData))) { + spr = sLink->unk4; + + // Each OAM entry is 8 bytes [struct OamData] + if (spr != NULL) { + // Skip affineParam + oam -= 2; + // Set tileNum/priority/paletteNum + *oam = spr->unk4; + // Set x/matrixNum/size + oam--; + *oam = spr->unk2; + // Set y/affineMode/objMode/mosaic/bpp/shape + oam--; + *oam = spr->unk0; + + count++; + } + + sLink = sLink->unk0; + } + + // Clear remaining object slots + while ((u32)oam > (OAM + sizeof(struct OamData))) { + // Skip affineParam + oam -= 2; + // Set tileNum/priority/paletteNum + *oam = 0; + // Set x/matrixNum/size + oam--; + *oam = 0; + // Set y/affineMode/objMode/mosaic/bpp/shape + oam--; + *oam = DISPLAY_HEIGHT; + } + + gUnknown_2025670 = count; } \ No newline at end of file From 02b6c6bd461209f5d979f7103b1fc1dfedea81bb Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 11 Aug 2023 13:53:04 -0400 Subject: [PATCH 06/27] Match SetSavingIconCoords and BlinkSavingIcon --- asm/sprite.s | 89 ------------------------------------------------ include/sprite.h | 6 ++-- src/code_2.c | 2 +- src/sprite.c | 60 ++++++++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 95 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index 8da34500..31ae5c08 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,95 +5,6 @@ .text - thumb_func_start SetSavingIconCoords -SetSavingIconCoords: - push {lr} - adds r3, r0, 0 - cmp r3, 0 - bne _0800522C - ldr r1, _08005228 - strh r3, [r1] - movs r0, 0xA0 - strh r0, [r1, 0x2] - b _0800523C - .align 2, 0 -_08005228: .4byte gUnknown_2025694 -_0800522C: - ldr r1, _08005240 - ldrh r0, [r3] - movs r2, 0 - strh r0, [r1] - ldrh r0, [r3, 0x2] - strh r0, [r1, 0x2] - ldr r0, _08005244 - str r2, [r0] -_0800523C: - pop {r0} - bx r0 - .align 2, 0 -_08005240: .4byte gUnknown_2025694 -_08005244: .4byte gUnknown_2025698 - thumb_func_end SetSavingIconCoords - - thumb_func_start BlinkSavingIcon -BlinkSavingIcon: - push {r4,lr} - movs r2, 0xE0 - lsls r2, 19 - ldr r0, _08005280 - ldr r1, [r0] - adds r3, r1, 0 - adds r1, 0x1 - str r1, [r0] - movs r0, 0x10 - ands r3, r0 - cmp r3, 0 - beq _08005288 - movs r0, 0xA0 - strh r0, [r2] - adds r2, 0x2 - movs r1, 0x80 - lsls r1, 7 - adds r0, r1, 0 - strh r0, [r2] - adds r2, 0x2 - ldr r4, _08005284 - adds r0, r4, 0 - strh r0, [r2] - adds r2, 0x2 - movs r0, 0 - strh r0, [r2] - b _080052A8 - .align 2, 0 -_08005280: .4byte gUnknown_2025698 -_08005284: .4byte 0x0000f3fc -_08005288: - ldr r1, _080052B0 - ldrh r0, [r1, 0x2] - strh r0, [r2] - ldr r2, _080052B4 - movs r4, 0x80 - lsls r4, 7 - adds r0, r4, 0 - ldrh r1, [r1] - adds r0, r1 - strh r0, [r2] - adds r2, 0x2 - ldr r1, _080052B8 - adds r0, r1, 0 - strh r0, [r2] - adds r2, 0x2 - strh r3, [r2] -_080052A8: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_080052B0: .4byte gUnknown_2025694 -_080052B4: .4byte 0x07000002 -_080052B8: .4byte 0x0000f3fc - thumb_func_end BlinkSavingIcon - thumb_func_start sub_80052BC sub_80052BC: push {r4-r6,lr} diff --git a/include/sprite.h b/include/sprite.h index 288d7a9a..17f97dd8 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -1,6 +1,8 @@ #ifndef GUARD_SPRITE_H #define GUARD_SPRITE_H +#include "position.h" + // size: 0x8 struct unkSprite { @@ -39,15 +41,15 @@ struct unkStruct_2039DB0 u16 unkA; }; +void BlinkSavingIcon(void); void CopySpritesToOam(void); void InitSprites(void); void ResetSprites(bool8); +void SetSavingIconCoords(struct Position *); void sub_8004E8C(struct unkStruct_2039DB0 *); void sub_8005180(void); // sprite.s extern void AddSprite(struct unkSprite *, s32, u32 *, struct unkStruct_2039DB0 *); -extern void BlinkSavingIcon(void); -extern void SetSavingIconCoords(u32); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/code_2.c b/src/code_2.c index 15c129cf..248fc4cd 100644 --- a/src/code_2.c +++ b/src/code_2.c @@ -96,7 +96,7 @@ void GameLoop(void) InitializeGameOptions(TRUE); SetWindowTitle(gPMDBuildVersion); sub_800DAAC(); - SetSavingIconCoords(0); + SetSavingIconCoords(NULL); tmp = 0; if (ReadSaveFromPak(&tmp)) sub_800135C(); diff --git a/src/sprite.c b/src/sprite.c index 17aedbf4..d055077b 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -2,6 +2,8 @@ #include "sprite.h" extern u16 gUnknown_2025670; +extern struct Position gUnknown_2025694; +extern u32 gUnknown_2025698; extern struct SpriteList gUnknown_20256A0; extern struct UnkSpriteLink gUnknown_2025EA8[128]; extern struct unkSprite gUnknown_20262A8[128]; @@ -13,7 +15,7 @@ extern u32 *gUnknown_203B074; void InitSprites(void) { ResetSprites(TRUE); - SetSavingIconCoords(0); + SetSavingIconCoords(NULL); } void ResetSprites(bool8 a0) @@ -26,7 +28,7 @@ void ResetSprites(bool8 a0) struct UnkSpriteLink *e; gSpriteCount = 0; - gCharMemCursor = (u32*)0x6010000; + gCharMemCursor = (u32*)OBJ_VRAM0; gUnknown_203B074 = &gUnknown_20266B0; a = &gUnknown_20256A0.sprites[0]; @@ -577,7 +579,7 @@ void CopySpritesToOam(void) { struct UnkSpriteLink *sLink; struct unkSprite *spr; - u16 *oam; + volatile u16 *oam; s32 count; sLink = &gUnknown_20256A0.sprites[0]; @@ -621,4 +623,56 @@ void CopySpritesToOam(void) } gUnknown_2025670 = count; +} + +void SetSavingIconCoords(struct Position *pos) +{ + if (pos == NULL) { + gUnknown_2025694.x = 0; + gUnknown_2025694.y = DISPLAY_HEIGHT; + } + else { + gUnknown_2025694.x = pos->x; + gUnknown_2025694.y = pos->y; + gUnknown_2025698 = 0; + } +} + +void BlinkSavingIcon(void) +{ + volatile u16 *oam; + u32 uVar1; + + oam = (u16 *)OAM; + uVar1 = gUnknown_2025698++; + + if (uVar1 & 16) { + // Set y to 160 + // Set affineMode/objMode/mosaic/bpp/shape to 0 + *oam++ = DISPLAY_HEIGHT; + // Set x/matrixNum to 0 + // Set size to 1 + *oam++ = 0x4000; + // Set tileNum to 0x3FC + // Set priority to 0 + // Set paletteNum to 15 + *oam++ = 0xF3FC; + // Set affineParam to 0 + *oam = 0; + } + else { + // Set y to gUnknown_2025694.y + // Set affineMode/objMode/mosaic/bpp/shape to 0 + *oam++ = gUnknown_2025694.y; + // Set x to gUnknown_2025694.x + // Set matrixNum to 0 + // Set size to 1 + *oam++ = gUnknown_2025694.x + 0x4000; + // Set tileNum to 0x3FC + // Set priority to 0 + // Set paletteNum to 15 + *oam++ = 0xF3FC; + // Set affineParam to 0 + *oam = 0; + } } \ No newline at end of file From 7bcc6e0ea6272480963fcfc7c92f2df4cfb778e3 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sat, 12 Aug 2023 11:57:50 -0400 Subject: [PATCH 07/27] Match sub_80A62F0 and GroundSprite_Reset --- asm/ground_sprite.s | 172 --------------------------------------- include/code_800558C_1.h | 6 ++ include/code_800DAC0.h | 6 ++ include/ground_map_1.h | 6 ++ include/ground_sprite.h | 37 +++++++++ include/sprite.h | 12 +-- ld_script.txt | 1 + src/code_800558C_1.c | 3 +- src/code_800DAC0.c | 1 + src/ground_map_1.c | 1 + src/ground_sprite.c | 103 +++++++++++++++++++++++ src/sprite.c | 4 +- 12 files changed, 166 insertions(+), 186 deletions(-) create mode 100644 include/code_800558C_1.h create mode 100644 include/code_800DAC0.h create mode 100644 include/ground_map_1.h create mode 100644 include/ground_sprite.h create mode 100644 src/ground_sprite.c diff --git a/asm/ground_sprite.s b/asm/ground_sprite.s index 5b0c1e07..d99535a5 100644 --- a/asm/ground_sprite.s +++ b/asm/ground_sprite.s @@ -5,178 +5,6 @@ .text - thumb_func_start sub_80A62F0 -sub_80A62F0: - push {r4-r7,lr} - ldr r4, _080A6378 - movs r0, 0x88 - lsls r0, 1 - movs r1, 0x6 - bl MemoryAlloc - str r0, [r4] - ldr r0, _080A637C - ldr r1, _080A6380 - bl OpenFileAndGetFileDataPtr - ldr r1, _080A6384 - str r0, [r1] - movs r0, 0x1 - bl sub_800DAC0 - ldr r4, [r4] - ldr r1, _080A6388 - movs r0, 0x16 - str r0, [r1] - ldr r1, _080A638C - movs r0, 0x1 - strb r0, [r1] - movs r0, 0 - movs r2, 0 - movs r1, 0x80 - lsls r1, 9 - adds r3, r1, 0 -_080A632A: - str r2, [r4] - lsls r0, 4 - str r0, [r4, 0x4] - str r2, [r4, 0x8] - adds r0, r1, 0 - adds r1, r3 - asrs r0, 16 - adds r4, 0xC - cmp r0, 0x15 - ble _080A632A - ldr r0, _080A6378 - ldr r0, [r0] - movs r1, 0x84 - lsls r1, 1 - adds r4, r0, r1 - movs r6, 0 - movs r7, 0 - movs r5, 0xE8 - lsls r5, 13 -_080A6350: - strh r7, [r4] - strh r7, [r4, 0x2] - lsrs r0, r5, 16 - movs r1, 0 - bl sub_80997F4 - movs r0, 0x80 - lsls r0, 9 - adds r5, r0 - adds r6, 0x1 - adds r4, 0x4 - cmp r6, 0x1 - ble _080A6350 - movs r0, 0x1 - negs r0, r0 - bl GroundSprite_Reset - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080A6378: .4byte gUnknown_3001B7C -_080A637C: .4byte gUnknown_81177CC -_080A6380: .4byte gDungeonFileArchive -_080A6384: .4byte gUnknown_203B4B4 -_080A6388: .4byte gUnknown_2039DD4 -_080A638C: .4byte gUnknown_2039DD0 - thumb_func_end sub_80A62F0 - - thumb_func_start GroundSprite_Reset -GroundSprite_Reset: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - lsls r0, 16 - asrs r0, 16 - mov r9, r0 - ldr r1, _080A641C - movs r0, 0 - bl Log - ldr r0, _080A6420 - movs r1, 0 - mov r8, r1 - strh r1, [r0] - ldr r0, _080A6424 - strh r1, [r0] - bl sub_80A6460 - mov r0, r9 - bl sub_80A4D48 - lsls r0, 24 - movs r1, 0x2 - cmp r0, 0 - beq _080A63C6 - movs r1, 0x3 -_080A63C6: - movs r0, 0xF8 - lsls r0, 1 - bl sub_808E53C - ldr r5, _080A6428 - adds r0, r5, 0 - bl sub_8004E8C - ldr r4, _080A642C - adds r0, r4, 0 - bl sub_8004E8C - ldrh r1, [r4, 0x4] - ldr r6, _080A6430 - adds r0, r6, 0 - ands r0, r1 - strh r0, [r4, 0x4] - ldrh r1, [r4, 0xA] - adds r0, r6, 0 - ands r0, r1 - movs r2, 0x80 - lsls r2, 4 - adds r7, r2, 0 - orrs r0, r7 - strh r0, [r4, 0xA] - mov r0, r9 - bl sub_80A4D48 - lsls r0, 24 - cmp r0, 0 - beq _080A6434 - ldrh r1, [r5, 0x4] - adds r0, r6, 0 - ands r0, r1 - strh r0, [r5, 0x4] - ldrh r1, [r5, 0xA] - adds r0, r6, 0 - ands r0, r1 - movs r2, 0xC0 - lsls r2, 4 - adds r1, r2, 0 - orrs r0, r1 - b _080A6444 - .align 2, 0 -_080A641C: .4byte gUnknown_81177D8 -_080A6420: .4byte gUnknown_2039DCC -_080A6424: .4byte gUnknown_2039DCE -_080A6428: .4byte gUnknown_2039DB0 -_080A642C: .4byte gUnknown_2039DC0 -_080A6430: .4byte 0x0000f3ff -_080A6434: - ldrh r1, [r5, 0x4] - adds r0, r6, 0 - ands r0, r1 - strh r0, [r5, 0x4] - ldrh r1, [r5, 0xA] - adds r0, r6, 0 - ands r0, r1 - orrs r0, r7 -_080A6444: - strh r0, [r5, 0xA] - movs r0, 0x1 - bl ResetSprites - movs r0, 0x1 - bl nullsub_10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end GroundSprite_Reset - thumb_func_start sub_80A6460 sub_80A6460: push {r4-r7,lr} diff --git a/include/code_800558C_1.h b/include/code_800558C_1.h new file mode 100644 index 00000000..4d931ace --- /dev/null +++ b/include/code_800558C_1.h @@ -0,0 +1,6 @@ +#ifndef GUARD_CODE_800558C_1_H +#define GUARD_CODE_800558C_1_H + +void nullsub_10(bool8); + +#endif // GUARD_CODE_800558C_1_H \ No newline at end of file diff --git a/include/code_800DAC0.h b/include/code_800DAC0.h new file mode 100644 index 00000000..b7e0e87d --- /dev/null +++ b/include/code_800DAC0.h @@ -0,0 +1,6 @@ +#ifndef GUARD_CODE_800DAC0_H +#define GUARD_CODE_800DAC0_H + +void sub_800DAC0(u32); + +#endif // GUARD_CODE_800DAC0_H \ No newline at end of file diff --git a/include/ground_map_1.h b/include/ground_map_1.h new file mode 100644 index 00000000..e504d553 --- /dev/null +++ b/include/ground_map_1.h @@ -0,0 +1,6 @@ +#ifndef GUARD_GROUND_MAP_1_H +#define GUARD_GROUND_MAP_1_H + +bool8 sub_80A4D48(s16); + +#endif // GUARD_GROUND_MAP_1_H \ No newline at end of file diff --git a/include/ground_sprite.h b/include/ground_sprite.h new file mode 100644 index 00000000..b743cefc --- /dev/null +++ b/include/ground_sprite.h @@ -0,0 +1,37 @@ +#ifndef GUARD_GROUND_SPRITE_H +#define GUARD_GROUND_SPRITE_H + +// size: 0xC +struct unkStruct_2039DB0 +{ + u16 unk0; + s16 unk2; + u16 unk4; + u16 unk6; + u16 unk8; + u16 unkA; +}; + +// size: 0xC +struct unkStruct_3001B7C_sub0 +{ + u32 unk0; + s32 unk4; + u32 unk8; +}; +// size: 0x4 +struct unkStruct_3001B7C_sub108 +{ + u16 unk0; + u16 unk2; +}; +// size: 0x110 +struct unkStruct_3001B7C +{ + struct unkStruct_3001B7C_sub0 unk0[22]; + struct unkStruct_3001B7C_sub108 unk108[2]; +}; + +void GroundSprite_Reset(s16); + +#endif // GUARD_GROUND_SPRITE_H \ No newline at end of file diff --git a/include/sprite.h b/include/sprite.h index 17f97dd8..d7432220 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -1,6 +1,7 @@ #ifndef GUARD_SPRITE_H #define GUARD_SPRITE_H +#include "ground_sprite.h" #include "position.h" // size: 0x8 @@ -30,17 +31,6 @@ struct SpriteList u32 unk804; }; -// size: 0xC -struct unkStruct_2039DB0 -{ - u16 unk0; - s16 unk2; - s16 unk4; - u16 unk6; - u16 unk8; - u16 unkA; -}; - void BlinkSavingIcon(void); void CopySpritesToOam(void); void InitSprites(void); diff --git a/ld_script.txt b/ld_script.txt index 38bdeda6..9c026266 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -315,6 +315,7 @@ SECTIONS { src/ground_map_1.o(.text); asm/ground_map_1.o(.text); src/ground_map_2.o(.text); + src/ground_sprite.o(.text); asm/ground_sprite.o(.text); src/code_80A7714.o(.text); asm/ground_lives.o(.text); diff --git a/src/code_800558C_1.c b/src/code_800558C_1.c index bdc4980a..cee2eace 100644 --- a/src/code_800558C_1.c +++ b/src/code_800558C_1.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_800558C_1.h" extern u8 gUnknown_2026E38; extern u32 gUnknown_2026E3C; @@ -36,7 +37,7 @@ void nullsub_8(void) void nullsub_9(void) {} -void nullsub_10(void) +void nullsub_10(bool8 a0) {} void nullsub_144(void) diff --git a/src/code_800DAC0.c b/src/code_800DAC0.c index 2db61761..8265ce3c 100644 --- a/src/code_800DAC0.c +++ b/src/code_800DAC0.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_800DAC0.h" #include "file_system.h" #include "memory.h" diff --git a/src/ground_map_1.c b/src/ground_map_1.c index d3d101f1..38cfdf05 100644 --- a/src/ground_map_1.c +++ b/src/ground_map_1.c @@ -1,5 +1,6 @@ #include "global.h" #include "debug.h" +#include "ground_map_1.h" #include "ground_script.h" extern struct GroundScript_ExecutePP_1 *gUnknown_3001B6C; diff --git a/src/ground_sprite.c b/src/ground_sprite.c new file mode 100644 index 00000000..6ac4717f --- /dev/null +++ b/src/ground_sprite.c @@ -0,0 +1,103 @@ +#include "global.h" +#include "code_800558C_1.h" +#include "code_800DAC0.h" +#include "debug.h" +#include "file_system.h" +#include "ground_map_1.h" +#include "ground_sprite.h" +#include "memory.h" +#include "sprite.h" + +extern struct unkStruct_2039DB0 gUnknown_2039DB0; +extern struct unkStruct_2039DB0 gUnknown_2039DC0; +extern u16 gUnknown_2039DCC; +extern u16 gUnknown_2039DCE; +extern u8 gUnknown_2039DD0; +extern u32 gUnknown_2039DD4; +extern struct OpenedFile *gUnknown_203B4B4; +extern struct unkStruct_3001B7C *gUnknown_3001B7C; + +extern const struct FileArchive gDungeonFileArchive; +extern const u8 gUnknown_81177CC[]; +extern const u8 gUnknown_81177D8[]; + +// code_8098BDC.s +extern void sub_80997F4(u16, u16); +// pokemon_2.s +extern void sub_808E53C(u32, u32); + +// ground_sprite.s +extern void sub_80A6460(void); + +void sub_80A62F0(void) +{ + s32 r0; + struct unkStruct_3001B7C_sub0 *sub0; + struct unkStruct_3001B7C_sub108 *sub108; + s32 r6; + + gUnknown_3001B7C = MemoryAlloc(sizeof(struct unkStruct_3001B7C), 6); + gUnknown_203B4B4 = OpenFileAndGetFileDataPtr(gUnknown_81177CC, &gDungeonFileArchive); + + sub_800DAC0(1); + + sub0 = gUnknown_3001B7C->unk0; + gUnknown_2039DD4 = 22; + gUnknown_2039DD0 = 1; + + for (r0 = 0; r0 < 22; r0 = (s16)(r0 + 1), sub0++) + { + sub0->unk0 = 0; + sub0->unk4 = r0 * 16; + sub0->unk8 = 0; + } + + sub108 = gUnknown_3001B7C->unk108; + + for (r6 = 0; r6 < 2; r6++, sub108++) { + sub108->unk0 = 0; + sub108->unk2 = 0; + sub_80997F4(r6 + 29, 0); + } + + GroundSprite_Reset(-1); +} + +void GroundSprite_Reset(s16 a0) +{ + s32 uVar2; + struct unkStruct_2039DB0 *bee; + struct unkStruct_2039DB0 *see; + + uVar2 = a0; + + Log(0, gUnknown_81177D8); + gUnknown_2039DCC = 0; + gUnknown_2039DCE = 0; + sub_80A6460(); + + sub_808E53C(496, sub_80A4D48(uVar2) ? 3 : 2); + + bee = &gUnknown_2039DB0; + sub_8004E8C(bee); + see = &gUnknown_2039DC0; + sub_8004E8C(see); + + see->unk4 &= ~(0x400 | 0x800); + see->unkA &= ~(0x400 | 0x800); + see->unkA |= 0x800; + + if (sub_80A4D48(a0)) { + bee->unk4 &= ~(0x400 | 0x800); + bee->unkA &= ~(0x400 | 0x800); + bee->unkA |= (0x400 | 0x800); + } + else { + bee->unk4 &= ~(0x400 | 0x800); + bee->unkA &= ~(0x400 | 0x800); + bee->unkA |= 0x800; + } + + ResetSprites(TRUE); + nullsub_10(TRUE); +} \ No newline at end of file diff --git a/src/sprite.c b/src/sprite.c index d055077b..8c62f290 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -123,7 +123,7 @@ void sub_8004E8C(struct unkStruct_2039DB0 *a0) { a0->unk0 = 0xFFFF; a0->unk2 = -1; - a0->unk4 = -1; + a0->unk4 = 0xFFFF; a0->unk6 = 0; a0->unk8 = 0; a0->unkA = 0; @@ -394,8 +394,8 @@ void sub_8004EA8(s32 a0, s16 *a1, u32 *a2, u16 *a3) "_080050AC: .4byte gUnknown_20256A0"); } -#ifdef NONMATCHING // https://decomp.me/scratch/YCfKG // a2 and a3 are always called with NULL lol +#ifdef NONMATCHING // https://decomp.me/scratch/YCfKG void AddSprite(struct unkSprite *a0, s32 a1, u32 *a2, struct unkStruct_2039DB0 *a3) { u16 uVar1; From 088162e8bd48bdd80f6424495552b7d46839d8f2 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Tue, 15 Aug 2023 06:47:56 -0400 Subject: [PATCH 08/27] Fakematch sub_80052BC, Match sub_8005304 --- asm/sprite.s | 73 ----------------------- include/cpu.h | 8 ++- include/sprite.h | 20 ++++++- src/bg_palette_buffer.c | 3 +- src/code.c | 2 +- src/code_2.c | 2 - src/code_8009804.c | 2 +- src/code_80118A4.c | 1 - src/code_8012A18.c | 1 - src/cpu.c | 30 +++++----- src/friend_rescue.c | 4 +- src/memory.c | 3 +- src/sprite.c | 112 +++++++++++++++++++++++++++++++----- src/thank_you_wonder_mail.c | 4 +- src/trade_items_menu.c | 4 +- src/wonder_mail.c | 4 +- src/wonder_mail_main_menu.c | 4 +- 17 files changed, 151 insertions(+), 126 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index 31ae5c08..2bd1d057 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,79 +5,6 @@ .text - thumb_func_start sub_80052BC -sub_80052BC: - push {r4-r6,lr} - adds r3, r0, 0 - ldr r0, [r3, 0x4] - cmp r0, 0 - beq _080052F2 - ldr r5, _080052F8 - ldr r6, _080052FC - ldr r4, _08005300 -_080052CC: - ldr r2, [r5] - cmp r2, r6 - bcs _080052F2 - ldr r0, [r3, 0x4] - str r0, [r2] - ldr r0, [r3] - str r0, [r2, 0x4] - ldr r1, [r4] - str r1, [r2, 0x8] - ldr r0, [r3, 0x4] - adds r1, r0 - str r1, [r4] - adds r0, r2, 0 - adds r0, 0xC - str r0, [r5] - adds r3, 0x8 - ldr r0, [r3, 0x4] - cmp r0, 0 - bne _080052CC -_080052F2: - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080052F8: .4byte gUnknown_203B074 -_080052FC: .4byte gCharMemCursor -_08005300: .4byte gCharMemCursor - thumb_func_end sub_80052BC - - thumb_func_start sub_8005304 -sub_8005304: - push {r4,lr} - ldr r4, _0800530C - b _0800532A - .align 2, 0 -_0800530C: .4byte gUnknown_20266B0 -_08005310: - ldr r1, [r4, 0x4] - cmp r1, 0 - beq _08005320 - ldr r0, [r4, 0x8] - ldr r2, [r4] - bl CpuCopy - b _08005328 -_08005320: - ldr r0, [r4, 0x8] - ldr r1, [r4] - bl CpuClear -_08005328: - adds r4, 0xC -_0800532A: - ldr r0, _08005338 - ldr r0, [r0] - cmp r4, r0 - bcc _08005310 - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08005338: .4byte gUnknown_203B074 - thumb_func_end sub_8005304 - thumb_func_start sub_800533C sub_800533C: push {r4-r7,lr} diff --git a/include/cpu.h b/include/cpu.h index 0d5676e2..f2448909 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -1,8 +1,12 @@ #ifndef GUARD_CPU_H #define GUARD_CPU_H +void CpuClear(void *, s32); +void CpuCopy(void *, void *, s32); +void nullsub_23(bool8); +void SetWindowTitle(char *); +void sub_800CDA8(u32); +u32 sub_800CDC8(void); void VBlank_CB(void); -void sub_800CDA8(u32); - #endif //GUARD_CPU_H diff --git a/include/sprite.h b/include/sprite.h index d7432220..9d799259 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -31,6 +31,22 @@ struct SpriteList u32 unk804; }; +// size: 0xC +struct unkStruct_20266B0 +{ + /* 0x0 */ s32 byteCount; + /* 0x4 */ void *src; + /* 0x8 */ void *dest; +}; + +// size: 0x8 +struct UnkSpriteMem +{ + /* 0x0 */ void *src; + /* 0x4 */ s32 byteCount; +}; + +void AddSprite(struct unkSprite *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); void BlinkSavingIcon(void); void CopySpritesToOam(void); void InitSprites(void); @@ -38,8 +54,6 @@ void ResetSprites(bool8); void SetSavingIconCoords(struct Position *); void sub_8004E8C(struct unkStruct_2039DB0 *); void sub_8005180(void); - -// sprite.s -extern void AddSprite(struct unkSprite *, s32, u32 *, struct unkStruct_2039DB0 *); +void sub_8005304(void); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/bg_palette_buffer.c b/src/bg_palette_buffer.c index ceee4969..5d60954b 100644 --- a/src/bg_palette_buffer.c +++ b/src/bg_palette_buffer.c @@ -1,5 +1,6 @@ #include "global.h" #include "bg_palette_buffer.h" +#include "cpu.h" #define BG_PALETTE_BUFFER_SIZE 512 #define BG_PALETTE_BUFFER_CHUNK_SIZE 16 @@ -7,8 +8,6 @@ EWRAM_DATA bool8 gBGPaletteUsed[BG_PALETTE_BUFFER_SIZE / BG_PALETTE_BUFFER_CHUNK_SIZE] = {0}; EWRAM_DATA u16 gBGPaletteBuffer[BG_PALETTE_BUFFER_SIZE] = {0}; -extern void CpuCopy(void* src, void* dest, u32 size); - #ifndef NONMATCHING NAKED #endif diff --git a/src/code.c b/src/code.c index 03d14605..936db6fe 100644 --- a/src/code.c +++ b/src/code.c @@ -27,7 +27,7 @@ void xxx_dungeon_8001340(u32 r0) NDS_LoadOverlay_GroundMain(); } -void nullsub_3(void) +void nullsub_3(s32 a0, s32 a1) { } diff --git a/src/code_2.c b/src/code_2.c index 248fc4cd..a09664f8 100644 --- a/src/code_2.c +++ b/src/code_2.c @@ -30,7 +30,6 @@ extern void SetWindowBGColor(void); extern void LoadItemParameters(void); extern void LoadMailInfo(void); extern void sub_800CD64(u32, u32); -extern void SetWindowTitle(char *); extern void sub_800DAAC(void); extern void sub_800135C(void); extern void xxx_script_related_8001334(u32); @@ -51,7 +50,6 @@ extern void nullsub_8(u32); extern void sub_80060EC(void); extern void sub_8011860(void); extern void sub_800CB20(void); -extern void sub_8005304(void); extern void TransferBGPaletteBuffer(void); extern void xxx_call_update_bg_vram(void); extern void sub_8009908(void); diff --git a/src/code_8009804.c b/src/code_8009804.c index e3cdf570..393f1358 100644 --- a/src/code_8009804.c +++ b/src/code_8009804.c @@ -1,4 +1,5 @@ #include "global.h" +#include "cpu.h" #include "file_system.h" #include "text1.h" @@ -23,7 +24,6 @@ struct unkStruct_202D038 extern struct unkStruct_202D038 gUnknown_202D038[8]; -extern void CpuCopy(void* dest, void *src, s32 size); extern void SetBGPaletteBufferColorArray(s32 index, void *colorArray); extern void sub_8009A1C(u32); u32 sub_80063B0(void); diff --git a/src/code_80118A4.c b/src/code_80118A4.c index 593f4db2..4fce8eff 100644 --- a/src/code_80118A4.c +++ b/src/code_80118A4.c @@ -38,7 +38,6 @@ EWRAM_DATA s16 gUnknown_202DE24; void nullsub_8(u32); void sub_8005838(u32, u32); -extern void sub_8005304(void); extern void TransferBGPaletteBuffer(void); extern void xxx_call_update_bg_vram(void); extern void sub_8009908(void); diff --git a/src/code_8012A18.c b/src/code_8012A18.c index 9c85d318..d4b24b84 100644 --- a/src/code_8012A18.c +++ b/src/code_8012A18.c @@ -8,7 +8,6 @@ extern void sub_8011860(); extern void xxx_draw_string_80144C4(); extern void nullsub_8(u8); extern void sub_800CB20(); -extern void sub_8005304(); extern void TransferBGPaletteBuffer(); extern void xxx_call_update_bg_vram(); extern void sub_8009908(); diff --git a/src/cpu.c b/src/cpu.c index 772d4ecc..688e28ea 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -20,30 +20,32 @@ void SetWindowTitle(char *title) { } -void nullsub_23(void) +void nullsub_23(bool8 a0) { } +// Unused void nullsub_182(void) { } -u32 sub_800CDE0(void) +// Unused +bool8 sub_800CDE0(void) { - return 1; + return TRUE; } -void CpuCopy(void* dest, void *src, s32 size) +void CpuCopy(void *dest, void *src, s32 size) { CpuCopy32(src, dest, size); } -void CpuClear(void* dest, s32 size) +void CpuClear(void *dest, s32 size) { CpuFill32(NULL, dest, size); } -void CpuFill(void* dest, void *value, s32 size) +void CpuFill(void *dest, void *value, s32 size) { CpuFill32(value, dest, size); } @@ -52,12 +54,12 @@ void CpuFill(void* dest, void *value, s32 size) void VBlank_CB(void) { // TODO this is so gross.. looks like a macro or something else but I don't want to deal with this rn - REG_DMA0CNT_H = (REG_DMA0CNT_H | DMA_ENABLE) & 0xcdff; + REG_DMA0CNT_H = (REG_DMA0CNT_H | DMA_ENABLE) & 0xCDFF; asm("mov \tr8, r8"); asm("mov \tr8, r8"); asm("mov \tr8, r8"); asm("mov \tr8, r8"); - REG_DMA0CNT_H &= 0x7fff; + REG_DMA0CNT_H &= 0x7FFF; // Everything below matches @@ -65,16 +67,14 @@ void VBlank_CB(void) REG_WINOUT = WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR | WINOUT_WIN01_BG3 | WINOUT_WIN01_BG2 | WINOUT_WIN01_BG0; REG_BLDCNT = gBldCnt; REG_BLDALPHA = gBldAlpha; - if(gUnknown_2026E38 != 0) - { - DmaSet(0, &gUnknown_2026E3C[2], REG_ADDR_WIN0H, 0xa2600002); + if (gUnknown_2026E38 != 0) { + DmaSet(0, &gUnknown_2026E3C[2], REG_ADDR_WIN0H, 0xA2600002); REG_WIN0H = gUnknown_2026E3C[0]; REG_WIN1H = gUnknown_2026E3C[1]; - REG_WIN0V = 160; - REG_WIN1V = 160; + REG_WIN0V = DISPLAY_HEIGHT; + REG_WIN1V = DISPLAY_HEIGHT; } - else - { + else { REG_WIN0H = 0; REG_WIN1H = 0; REG_WIN0V = 0; diff --git a/src/friend_rescue.c b/src/friend_rescue.c index 2b0327f7..1a53edce 100644 --- a/src/friend_rescue.c +++ b/src/friend_rescue.c @@ -19,6 +19,7 @@ #include "code_801EE10_1.h" #include "code_801C620.h" #include "code_801B3C0.h" +#include "cpu.h" extern void SetFriendRescueMenuState(u32); extern struct PokemonStruct *GetPlayerPokemonStruct(void); @@ -300,7 +301,6 @@ extern s32 GetMailIndex(u8 mailType, u32 param_2); extern char * GetMonSpecies(s16 index); extern struct PokemonStruct *GetPlayerPokemonStruct(void); extern void MemoryFill8(u8 *dest, u8 value, s32 size); -extern void nullsub_23(u32); extern void ResetUnusedInputStruct(void); extern void sprintfStatic(char *buffer, const char *text, ...); extern void xxx_call_start_bg_music(void); @@ -1175,7 +1175,7 @@ void sub_8032828(void) break; case 0xD: case 0x62: - nullsub_23(0); + nullsub_23(FALSE); sub_80141B4(&gUnknown_80E2DD0[0], 0, NULL, 0); break; case 0x64: diff --git a/src/memory.c b/src/memory.c index 92f43c1a..c03a6efc 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,4 +1,5 @@ #include "global.h" +#include "cpu.h" #include "memory.h" extern struct HeapFreeListElement gMainHeapFreeList[32]; @@ -8,8 +9,6 @@ extern struct HeapDescriptor gMainHeapDescriptor; EWRAM_DATA struct HeapDescriptor *gHeapDescriptorList[8] = {0}; EWRAM_DATA u32 gHeapCount = {0}; -extern void CpuClear(u32 *dest, s32 size); - void InitHeapInternal(void); void InitHeap(void) diff --git a/src/sprite.c b/src/sprite.c index 8c62f290..f5c1eae5 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1,4 +1,5 @@ #include "global.h" +#include "cpu.h" #include "sprite.h" extern u16 gUnknown_2025670; @@ -8,9 +9,14 @@ extern struct SpriteList gUnknown_20256A0; extern struct UnkSpriteLink gUnknown_2025EA8[128]; extern struct unkSprite gUnknown_20262A8[128]; extern u32 gSpriteCount; /* 20266A8 */ -extern u32 gUnknown_20266B0; -extern u32 *gCharMemCursor; /* 2026E30 */ -extern u32 *gUnknown_203B074; +extern struct unkStruct_20266B0 gUnknown_20266B0[160]; +extern void *gCharMemCursor; /* 2026E30 */ +extern struct unkStruct_20266B0 *gUnknown_203B074; + +// code.c +extern void nullsub_3(s32, s32); + +void sub_80052BC(struct UnkSpriteMem *); void InitSprites(void) { @@ -28,8 +34,8 @@ void ResetSprites(bool8 a0) struct UnkSpriteLink *e; gSpriteCount = 0; - gCharMemCursor = (u32*)OBJ_VRAM0; - gUnknown_203B074 = &gUnknown_20266B0; + gCharMemCursor = OBJ_VRAM0; + gUnknown_203B074 = &gUnknown_20266B0[0]; a = &gUnknown_20256A0.sprites[0]; b = a + 1; @@ -396,9 +402,9 @@ void sub_8004EA8(s32 a0, s16 *a1, u32 *a2, u16 *a3) // a2 and a3 are always called with NULL lol #ifdef NONMATCHING // https://decomp.me/scratch/YCfKG -void AddSprite(struct unkSprite *a0, s32 a1, u32 *a2, struct unkStruct_2039DB0 *a3) +void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unkStruct_2039DB0 *a3) { - u16 uVar1; + s32 uVar1; struct unkSprite *spr; struct UnkSpriteLink *a; struct UnkSpriteLink *b; @@ -420,15 +426,18 @@ void AddSprite(struct unkSprite *a0, s32 a1, u32 *a2, struct unkStruct_2039DB0 * spr->unk6 = a0->unk6; } else { - spr->unk0 = (a3->unk0 & a0->unk0) | a3->unk6; - spr->unk2 = (a3->unk2 & a0->unk2) | a3->unk8; - spr->unk4 = (a3->unk4 & a0->unk4) | a3->unkA; + spr->unk0 = (a0->unk0 & a3->unk0) | a3->unk6; + spr->unk2 = (a0->unk2 & a3->unk2) | a3->unk8; + spr->unk4 = (a0->unk4 & a3->unk4) | a3->unkA; spr->unk6 = a0->unk6; } - uVar1 = spr->unk6 >> 4; + uVar1 = spr->unk6 / 16; nullsub_3(uVar1, 0); - spr->unk0 = (uVar1 & 0xFF) | (spr->unk0 & 0xFF00); + // uVar1 is the Y position of the sprite, then the rest remains + uVar1 &= 0xFF; + spr->unk0 &= 0xFF00; + spr->unk0 |= uVar1; if (a2 != NULL) sub_80052BC(a2); @@ -444,7 +453,7 @@ void AddSprite(struct unkSprite *a0, s32 a1, u32 *a2, struct unkStruct_2039DB0 * } #else NAKED -void AddSprite(struct unkSprite *a0, s32 a1, u32 *a2, struct unkStruct_2039DB0 *a3) +void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unkStruct_2039DB0 *a3) { asm_unified( "push {r4-r7,lr}\n" @@ -675,4 +684,81 @@ void BlinkSavingIcon(void) // Set affineParam to 0 *oam = 0; } +} + +#ifdef NONMATCHING // https://decomp.me/scratch/taTIU +extern u32 sub_80052BC_end[0] asm("gCharMemCursor"); +void sub_80052BC(struct UnkSpriteMem *a0) +{ + if (a0->byteCount) { + struct unkStruct_20266B0 **r5 = &gUnknown_203B074; + void *r6 = sub_80052BC_end; + void **r4 = &gCharMemCursor; + do { + struct unkStruct_20266B0 *r2 = *r5; + if ((uintptr_t)r2 >= (uintptr_t)r6) + return; + r2->byteCount = a0->byteCount; + r2->src = a0->src; + r2->dest = *r4; + *r4 = r2->dest + a0->byteCount; + *r5 = r2 + 1; + a0++; + } while (a0->byteCount); + } +} +#else +NAKED +void sub_80052BC(struct UnkSpriteMem *a0) +{ + asm_unified( + "push {r4-r6,lr}\n" + "\tadds r3, r0, 0\n" + "\tldr r0, [r3, 0x4]\n" + "\tcmp r0, 0\n" + "\tbeq _080052F2\n" + "\tldr r5, _080052F8\n" + "\tldr r6, _080052FC\n" + "\tldr r4, _08005300\n" +"_080052CC:\n" + "\tldr r2, [r5]\n" + "\tcmp r2, r6\n" + "\tbcs _080052F2\n" + "\tldr r0, [r3, 0x4]\n" + "\tstr r0, [r2]\n" + "\tldr r0, [r3]\n" + "\tstr r0, [r2, 0x4]\n" + "\tldr r1, [r4]\n" + "\tstr r1, [r2, 0x8]\n" + "\tldr r0, [r3, 0x4]\n" + "\tadds r1, r0\n" + "\tstr r1, [r4]\n" + "\tadds r0, r2, 0\n" + "\tadds r0, 0xC\n" + "\tstr r0, [r5]\n" + "\tadds r3, 0x8\n" + "\tldr r0, [r3, 0x4]\n" + "\tcmp r0, 0\n" + "\tbne _080052CC\n" +"_080052F2:\n" + "\tpop {r4-r6}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.align 2, 0\n" +"_080052F8: .4byte gUnknown_203B074\n" +"_080052FC: .4byte gCharMemCursor\n" +"_08005300: .4byte gCharMemCursor"); +} +#endif // NONMATCHING + +void sub_8005304(void) +{ + struct unkStruct_20266B0 *s; + + for (s = &gUnknown_20266B0[0]; s < gUnknown_203B074; s++) { + if (s->src != NULL) + CpuCopy(s->dest, s->src, s->byteCount); + else + CpuClear(s->dest, s->byteCount); + } } \ No newline at end of file diff --git a/src/thank_you_wonder_mail.c b/src/thank_you_wonder_mail.c index 3efd5c73..2b4d7486 100644 --- a/src/thank_you_wonder_mail.c +++ b/src/thank_you_wonder_mail.c @@ -17,6 +17,7 @@ #include "main_menu.h" #include "code_801C620.h" #include "code_801B3C0.h" +#include "cpu.h" extern struct WonderMailStruct_203B2C4 *gUnknown_203B2C4; @@ -218,7 +219,6 @@ extern void sub_80151C0(u32, u8 *); extern void xxx_call_start_bg_music(void); extern void sub_803092C(void); extern void sub_8011830(void); -extern void nullsub_23(u32); extern s32 sub_8037B28(u32); extern u32 sub_8030894(void); extern u32 sub_801D008(void); @@ -1405,7 +1405,7 @@ void UpdateThankYouMailText(void) break; case COMMUNICATING_THANK_YOU_MAIL: // Communicating.. - nullsub_23(0); + nullsub_23(FALSE); sub_80141B4(gUnknown_80DF544,0,0,0); break; case 0x17: diff --git a/src/trade_items_menu.c b/src/trade_items_menu.c index d1a7ab5a..4f639530 100644 --- a/src/trade_items_menu.c +++ b/src/trade_items_menu.c @@ -12,6 +12,7 @@ #include "menu_input.h" #include "text1.h" #include "text2.h" +#include "cpu.h" EWRAM_DATA_2 struct TradeItemsMenu *gTradeItemsMenu = {0}; @@ -88,7 +89,6 @@ extern void sub_8035C1C(); extern u32 sub_801D008(); extern s32 sub_8037B28(u32); extern void sub_8011830(void); -extern void nullsub_23(u32); extern void xxx_call_start_bg_music(void); extern s32 sub_80381F4(u32, void *, void *); extern s32 sub_8037D64(u32, void *, void *); @@ -633,7 +633,7 @@ void sub_8036B28(void) sub_8014248(gUnknown_80E6268,0,5,gUnknown_80E618C,0,4,0,0,0x101); break; case TRADE_ITEMS_IN_COMMUNICATION: - nullsub_23(0); + nullsub_23(FALSE); sub_80141B4(gUnknown_80E62C4,0,0,0); break; case 10: diff --git a/src/wonder_mail.c b/src/wonder_mail.c index 5dd88796..93f3cbef 100644 --- a/src/wonder_mail.c +++ b/src/wonder_mail.c @@ -14,6 +14,7 @@ #include "code_80130A8.h" #include "main_menu.h" #include "code_801EE10_1.h" +#include "cpu.h" extern struct WonderMailStruct_203B2C0 *gUnknown_203B2C0; @@ -56,7 +57,6 @@ extern void sub_8099690(u32); extern void sub_8031E10(void); extern void sub_803084C(void); extern void sub_8030DE4(); -extern void nullsub_23(u32); extern s32 sub_8037D64(u32, void *, void *); extern s32 sub_80381F4(u32, void *, void *); extern void sub_80306A8(u32, u32, u32, u32); @@ -589,7 +589,7 @@ void sub_8028348(void) sub_8014248(gUnknown_80DDFB8, 0, 8, gUnknown_80DDA48, 0, 4, 0, &gUnknown_203B2C0->faceFile,0xC); break; case FRIEND_RESCUE_COMMUNICATING_PRE: - nullsub_23(0); + nullsub_23(FALSE); sub_80141B4(gUnknown_80DE01C, 0 , 0, 0); break; case FRIEND_RESCUE_COMMUNICATING: diff --git a/src/wonder_mail_main_menu.c b/src/wonder_mail_main_menu.c index c1d2186b..55338553 100644 --- a/src/wonder_mail_main_menu.c +++ b/src/wonder_mail_main_menu.c @@ -11,6 +11,7 @@ #include "code_80130A8.h" #include "code_801C620.h" #include "code_801B3C0.h" +#include "cpu.h" #define SELECT_WONDER_MAIL_MODE_MAIN_SCREEN 0 #define SEND_WONDER_MAIL_MAIN_SCREEN 1 @@ -136,7 +137,6 @@ extern s32 sub_80381F4(u32, void *, void *); extern void sub_8011830(void); extern void sub_80151C0(u32, u8 *); extern void xxx_call_start_bg_music(void); -extern void nullsub_23(u32); extern void sub_802EF48(void); extern void sub_802D098(struct WonderMail *); @@ -595,7 +595,7 @@ void WonderMailMainMenuCallback(void) sub_8014248(gUnknown_80E7BEC,0,6,gUnknown_80E78F8,0,4,0,0,0x101); break; case 6: - nullsub_23(0); + nullsub_23(FALSE); sub_80141B4(gUnknown_80E7C48,0,0,0); break; case 9: From 932d0945e0c9c20b9117e280d5d289423a6ed02b Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:06:18 -0400 Subject: [PATCH 09/27] Match sub_800533C --- asm/code_800558C.s | 6 +- asm/code_800DAC0.s | 12 ++-- asm/code_8069E0C.s | 4 +- asm/ground_sprite.s | 6 +- asm/sprite.s | 61 ------------------ include/sprite.h | 29 +++++++++ src/ground_sprite.c | 3 +- src/sprite.c | 148 ++++++++++++++++++++++++++++++++++++++++---- 8 files changed, 179 insertions(+), 90 deletions(-) diff --git a/asm/code_800558C.s b/asm/code_800558C.s index 50cc2309..edf18bd8 100644 --- a/asm/code_800558C.s +++ b/asm/code_800558C.s @@ -5,8 +5,8 @@ .text - thumb_func_start sub_800558C -sub_800558C: + thumb_func_start DoAxFrame_800558C +DoAxFrame_800558C: push {r4-r7,lr} sub sp, 0x4 adds r5, r0, 0 @@ -72,7 +72,7 @@ _08005602: bx r0 .align 2, 0 _0800560C: .4byte 0x0000f7ff - thumb_func_end sub_800558C + thumb_func_end DoAxFrame_800558C thumb_func_start sub_8005610 sub_8005610: diff --git a/asm/code_800DAC0.s b/asm/code_800DAC0.s index 11ea9b4b..69e5960d 100644 --- a/asm/code_800DAC0.s +++ b/asm/code_800DAC0.s @@ -154,7 +154,7 @@ _0800DDCA: str r0, [sp, 0x4] mov r0, r8 adds r1, r4, 0 - bl sub_800558C + bl DoAxFrame_800558C _0800DE26: movs r0, 0x1 _0800DE28: @@ -6081,7 +6081,7 @@ sub_8010A88: add r3, sp, 0x8 str r3, [sp, 0x4] movs r3, 0x3 - bl sub_800558C + bl DoAxFrame_800558C _08010AF6: lsls r0, r5, 16 asrs r0, 16 @@ -6118,7 +6118,7 @@ _08010B04: str r3, [sp, 0x4] adds r0, r5, 0 movs r3, 0x1 - bl sub_800558C + bl DoAxFrame_800558C _08010B40: adds r7, 0x44 subs r6, 0x1 @@ -6632,7 +6632,7 @@ sub_8010F28: str r3, [sp, 0x4] adds r0, r4, 0 movs r3, 0x3 - bl sub_800558C + bl DoAxFrame_800558C movs r7, 0 mov r10, r6 ldr r6, _0801109C @@ -6667,7 +6667,7 @@ _08010F98: str r0, [sp, 0x4] adds r0, r4, 0 movs r3, 0x1 - bl sub_800558C + bl DoAxFrame_800558C _08010FD8: adds r6, 0x50 adds r7, 0x1 @@ -6737,7 +6737,7 @@ _0801101E: add r3, sp, 0x8 str r3, [sp, 0x4] movs r3, 0x2 - bl sub_800558C + bl DoAxFrame_800558C _08011062: adds r6, 0x3C ldr r4, [sp, 0x14] diff --git a/asm/code_8069E0C.s b/asm/code_8069E0C.s index c8e843e9..c979fde1 100644 --- a/asm/code_8069E0C.s +++ b/asm/code_8069E0C.s @@ -5208,7 +5208,7 @@ _0806CAD2: ldr r1, [sp, 0x2C] ldr r2, [sp, 0x30] mov r3, r9 - bl sub_800558C + bl DoAxFrame_800558C b _0806CB16 _0806CAF8: cmp r1, 0x1 @@ -5224,7 +5224,7 @@ _0806CAF8: ldr r1, [sp, 0x2C] ldr r2, [sp, 0x30] mov r3, r9 - bl sub_800558C + bl DoAxFrame_800558C _0806CB16: ldr r0, [r6, 0xC] cmp r0, 0 diff --git a/asm/ground_sprite.s b/asm/ground_sprite.s index d99535a5..0f95cfce 100644 --- a/asm/ground_sprite.s +++ b/asm/ground_sprite.s @@ -1877,7 +1877,7 @@ _080A71BC: adds r0, r7, 0 movs r2, 0xD0 movs r3, 0 - bl sub_800558C + bl DoAxFrame_800558C adds r0, r7, 0 adds r0, 0x70 mov r3, r9 @@ -1909,7 +1909,7 @@ _080A7234: adds r0, r7, 0 adds r1, r5, 0 mov r2, r8 - bl sub_800558C + bl DoAxFrame_800558C movs r0, 0 strb r0, [r4] mov r2, r10 @@ -1942,7 +1942,7 @@ _080A7274: adds r0, r7, 0 movs r2, 0xD0 movs r3, 0 - bl sub_800558C + bl DoAxFrame_800558C movs r0, 0 strb r0, [r4] _080A72A6: diff --git a/asm/sprite.s b/asm/sprite.s index 2bd1d057..11097902 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,67 +5,6 @@ .text - thumb_func_start sub_800533C -sub_800533C: - push {r4-r7,lr} - mov r7, r8 - push {r7} - mov r8, r1 - adds r5, r2, 0 - adds r7, r3, 0 - ldr r1, [sp, 0x18] - lsls r1, 24 - lsrs r6, r1, 24 - movs r2, 0x18 - ldrsh r1, [r5, r2] - lsls r1, 2 - adds r1, r0 - ldr r4, [r1] - ldr r1, _08005368 - movs r2, 0x14 - ldrsh r0, [r5, r2] - lsls r0, 5 - ldr r2, _0800536C - adds r0, r2 - str r0, [r1] - b _0800538E - .align 2, 0 -_08005368: .4byte gCharMemCursor -_0800536C: .4byte 0x06010000 -_08005370: - cmp r6, 0 - beq _08005382 - movs r1, 0 - ldrsh r0, [r4, r1] - cmp r0, 0 - blt _08005382 - lsls r0, 2 - add r0, r8 - ldr r2, [r0] -_08005382: - adds r0, r4, 0 - adds r1, r5, 0 - adds r3, r7, 0 - bl sub_8004EA8 - adds r4, 0xA -_0800538E: - movs r2, 0 - ldrh r1, [r4] - ldr r0, _080053A8 - cmp r1, r0 - bne _08005370 - ldrh r0, [r4, 0x2] - cmp r0, r1 - bne _08005370 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080053A8: .4byte 0x0000ffff - thumb_func_end sub_800533C - thumb_func_start sub_80053AC sub_80053AC: push {r4-r6,lr} diff --git a/include/sprite.h b/include/sprite.h index 9d799259..d0bd6504 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -46,6 +46,35 @@ struct UnkSpriteMem /* 0x4 */ s32 byteCount; }; +// size: 0x20 +struct axdata1 +{ + /* 0x0 */ s16 xPos; + /* 0x2 */ s16 yPos; + /* 0x4 */ u16 xOffset; + /* 0x6 */ u16 yOffset; + /* 0x8 */ u16 xShadow; + /* 0xA */ u16 yShadow; + u32 unkC; + u32 unk10; + /* 0x14 */ s16 vramTileOrMaybeAnimTimer; + s16 unk16; + /* 0x18 */ s16 poseId; + /* 0x1A */ s16 lastPoseId; + u8 fill1C[0x1E - 0x1C]; + u8 paletteNum; +}; + +// size: 0xA +struct __attribute__ ((packed, aligned(2))) ax_pose +{ + s16 sprite; + u16 unk2; // Always 0 in red (except for end markers which are 0xFFFF) + u16 flags1; + u16 flags2; + u16 flags3; +}; + void AddSprite(struct unkSprite *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); void BlinkSavingIcon(void); void CopySpritesToOam(void); diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 6ac4717f..82b258b3 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -45,8 +45,7 @@ void sub_80A62F0(void) gUnknown_2039DD4 = 22; gUnknown_2039DD0 = 1; - for (r0 = 0; r0 < 22; r0 = (s16)(r0 + 1), sub0++) - { + for (r0 = 0; r0 < 22; r0 = (s16)(r0 + 1), sub0++) { sub0->unk0 = 0; sub0->unk4 = r0 * 16; sub0->unk8 = 0; diff --git a/src/sprite.c b/src/sprite.c index f5c1eae5..3a09f14e 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -3,12 +3,14 @@ #include "sprite.h" extern u16 gUnknown_2025670; +extern s16 gUnknown_2025672[8]; +extern s16 gUnknown_2025682[9]; extern struct Position gUnknown_2025694; extern u32 gUnknown_2025698; extern struct SpriteList gUnknown_20256A0; extern struct UnkSpriteLink gUnknown_2025EA8[128]; extern struct unkSprite gUnknown_20262A8[128]; -extern u32 gSpriteCount; /* 20266A8 */ +extern s32 gSpriteCount; /* 20266A8 */ extern struct unkStruct_20266B0 gUnknown_20266B0[160]; extern void *gCharMemCursor; /* 2026E30 */ extern struct unkStruct_20266B0 *gUnknown_203B074; @@ -16,7 +18,7 @@ extern struct unkStruct_20266B0 *gUnknown_203B074; // code.c extern void nullsub_3(s32, s32); -void sub_80052BC(struct UnkSpriteMem *); +void RegisterSpriteParts_80052BC(struct UnkSpriteMem *); void InitSprites(void) { @@ -135,9 +137,112 @@ void sub_8004E8C(struct unkStruct_2039DB0 *a0) a0->unkA = 0; } -// Need more structs decomped first https://decomp.me/scratch/VYqKb +// https://decomp.me/scratch/VYqKb +// spriteMasks is a u16[6] +#if NONMATCHING +void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2, u16 *spriteMasks) +{ + // size: 0xC + struct UnkStackFor8004EA8 + { + u16 unk0; + u8 unk2; + s8 unk3; + u16 flags1; + u16 flags2; + u16 flags3; + u16 unkA; + } sp; + struct unkSprite *sprite; + u32 uVar9; + s32 r7; + + s32 x; + s32 y; + s32 tileNum; + s32 earlyMask; + + if (a2 != NULL) + RegisterSpriteParts_80052BC(a2); + + if (gSpriteCount >= 128) + return; + + sp.unk0 = a0->sprite; + *((u16 *)&sp.unk2) = a0->unk2; // ????????? + sp.flags1 = a0->flags1 & ~(0x100 | 0x200); + sp.flags2 = a0->flags2 & ~(0x200 | 0x400 | 0x800); + sp.flags3 = a0->flags3; + sp.unkA = ((a0->flags2 & (0x200 | 0x400 | 0x800)) >> 9) | ((a0->flags1 & (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x80 | 0x100 | 0x200)) << 4); + sprite = gUnknown_20262A8 + gSpriteCount; + r7 = a1->unk16 + sp.unk3; + + if (r7 < 0) + r7 = 0; + if (r7 > 255) + r7 = 255; + + if (spriteMasks == NULL) { + sprite->unk0 = sp.flags1; + sprite->unk2 = sp.flags2; + sprite->unk4 = sp.flags3; + sprite->unk6 = sp.unkA; + } + else { + sprite->unk0 = (spriteMasks[0] & sp.flags1) | spriteMasks[3]; + sprite->unk2 = (spriteMasks[1] & sp.flags2) | spriteMasks[4]; + sprite->unk4 = (spriteMasks[2] & sp.flags3) | spriteMasks[5]; + sprite->unk6 = sp.unkA; + } + + if (sp.unk2 != 0 && gUnknown_2025672[sp.unk2] != 0) { + tileNum = gUnknown_2025672[sp.unk2] & 0x3FF; + } + else { + tileNum = (sprite->unk4 & 0x3FF) + a1->vramTileOrMaybeAnimTimer; + tileNum &= 0x3FF; + } + + // Set tileNum, maintain priority/paletteNum + sprite->unk4 = tileNum | (sprite->unk4 & 0xFC00); + + x = (sprite->unk2 & 0x1FF) - 256; + x += a1->xPos; + if (x < -64) + return; + if (x >= DISPLAY_WIDTH) + return; + + // Set x, maintain matrixNum/size + sprite->unk2 = (x & 0x1FF) | (sprite->unk2 & 0xFE00); + + uVar9 = sprite->unk6 << 16; + earlyMask = 0xFFF; + + y = (uVar9 >> 20) - 512; + y += a1->yPos; + if (y < -64) + return; + if (y >= DISPLAY_HEIGHT) + return; + + // Set y, maintain affineMode/objMode/mosaic/bpp/shape + sprite->unk0 = (y & 0xFF) | (sprite->unk0 & 0xFF00); + + // Set paletteNum, maintain tileNum/priority + if (((uVar9 >> 17) & 1) == 0) + sprite->unk4 = ((a1->paletteNum & 0xF) << 12) | (sprite->unk4 & earlyMask); + + if (sp.unk2 != 0) + sprite->unk4 = ((gUnknown_2025682[sp.unk2] & 0xF) << 12) | (sprite->unk4 & earlyMask); + + gUnknown_2025EA8[gSpriteCount].unk0 = gUnknown_20256A0.sprites[r7].unk0; + gUnknown_20256A0.sprites[r7].unk0 = gUnknown_2025EA8 + gSpriteCount; + gSpriteCount++; +} +#else NAKED -void sub_8004EA8(s32 a0, s16 *a1, u32 *a2, u16 *a3) +void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2, u16 *spriteMasks) { asm_unified( "push {r4-r7,lr}\n" @@ -151,7 +256,7 @@ void sub_8004EA8(s32 a0, s16 *a1, u32 *a2, u16 *a3) "\tadds r6, r3, 0\n" "\tcmp r0, 0\n" "\tbeq _08004EC2\n" - "\tbl sub_80052BC\n" + "\tbl RegisterSpriteParts_80052BC\n" "_08004EC2:\n" "\tldr r0, _08004F40\n" "\tldr r7, [r0]\n" @@ -399,6 +504,7 @@ void sub_8004EA8(s32 a0, s16 *a1, u32 *a2, u16 *a3) "_080050A8: .4byte gUnknown_2025EA8\n" "_080050AC: .4byte gUnknown_20256A0"); } +#endif // NONMATCHING // a2 and a3 are always called with NULL lol #ifdef NONMATCHING // https://decomp.me/scratch/YCfKG @@ -440,7 +546,7 @@ void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unk spr->unk0 |= uVar1; if (a2 != NULL) - sub_80052BC(a2); + RegisterSpriteParts_80052BC(a2); a = &gUnknown_2025EA8[0]; a += gSpriteCount; @@ -534,7 +640,7 @@ void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unk "\tmov r0, r8\n" "\tcmp r0, 0\n" "\tbeq _0800514E\n" - "\tbl sub_80052BC\n" + "\tbl RegisterSpriteParts_80052BC\n" "_0800514E:\n" "\tldr r0, _08005174\n" "\tldr r4, _08005178\n" @@ -588,11 +694,11 @@ void CopySpritesToOam(void) { struct UnkSpriteLink *sLink; struct unkSprite *spr; - volatile u16 *oam; + vu16 *oam; s32 count; sLink = &gUnknown_20256A0.sprites[0]; - oam = (u16 *)(OAM + OAM_SIZE); // End of OAM. Work backwards + oam = (vu16 *)(OAM + OAM_SIZE); // End of OAM. Work backwards count = 0; while (sLink != NULL && (u32)oam > (OAM + sizeof(struct OamData))) { @@ -687,12 +793,12 @@ void BlinkSavingIcon(void) } #ifdef NONMATCHING // https://decomp.me/scratch/taTIU -extern u32 sub_80052BC_end[0] asm("gCharMemCursor"); -void sub_80052BC(struct UnkSpriteMem *a0) +extern u32 RegisterSpriteParts_80052BC_end[0] asm("gCharMemCursor"); +void RegisterSpriteParts_80052BC(struct UnkSpriteMem *a0) { if (a0->byteCount) { struct unkStruct_20266B0 **r5 = &gUnknown_203B074; - void *r6 = sub_80052BC_end; + void *r6 = RegisterSpriteParts_80052BC_end; void **r4 = &gCharMemCursor; do { struct unkStruct_20266B0 *r2 = *r5; @@ -709,7 +815,7 @@ void sub_80052BC(struct UnkSpriteMem *a0) } #else NAKED -void sub_80052BC(struct UnkSpriteMem *a0) +void RegisterSpriteParts_80052BC(struct UnkSpriteMem *a0) { asm_unified( "push {r4-r6,lr}\n" @@ -761,4 +867,20 @@ void sub_8005304(void) else CpuClear(s->dest, s->byteCount); } +} + +// spriteMasks is a u16[6]. a4 might be a bool8 +void sub_800533C(struct ax_pose **a0, struct UnkSpriteMem **a1, struct axdata1 *a2, u16 *spriteMasks, char a4) +{ + struct UnkSpriteMem *mem; + struct ax_pose *r4; + + r4 = a0[a2->poseId]; + gCharMemCursor = OBJ_VRAM0 + (a2->vramTileOrMaybeAnimTimer * 0x20); + for (mem = NULL; (u16)r4->sprite != 0xFFFF || r4->unk2 != 0xFFFF; r4++, mem = NULL) { + if (a4 != 0 && r4->sprite > -1) + mem = a1[r4->sprite]; + + sub_8004EA8(r4, a2, mem, spriteMasks); + } } \ No newline at end of file From cf4f5297189b3799e517999470f5994cc496aee1 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:32:43 -0400 Subject: [PATCH 10/27] Match sub_80A6460 --- asm/ground_sprite.s | 34 ---------------------------------- src/ground_sprite.c | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/asm/ground_sprite.s b/asm/ground_sprite.s index 0f95cfce..99234a1a 100644 --- a/asm/ground_sprite.s +++ b/asm/ground_sprite.s @@ -5,40 +5,6 @@ .text - thumb_func_start sub_80A6460 -sub_80A6460: - push {r4-r7,lr} - ldr r0, _080A649C - ldr r1, _080A64A0 - bl OpenFileAndGetFileDataPtr - adds r7, r0, 0 - movs r5, 0x80 - lsls r5, 1 - ldr r4, [r7, 0x4] - movs r6, 0xC -_080A6474: - adds r0, r5, 0 - adds r1, r4, 0 - movs r2, 0x10 - bl sub_809971C - adds r0, r5, 0 - adds r0, 0x10 - lsls r0, 16 - lsrs r5, r0, 16 - adds r4, 0x40 - subs r6, 0x1 - cmp r6, 0 - bge _080A6474 - adds r0, r7, 0 - bl CloseFile - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080A649C: .4byte gUnknown_81177EC -_080A64A0: .4byte gMonsterFileArchive - thumb_func_end sub_80A6460 - thumb_func_start sub_80A64A4 sub_80A64A4: push {r4-r7,lr} diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 82b258b3..d3a56c34 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -17,11 +17,17 @@ extern u32 gUnknown_2039DD4; extern struct OpenedFile *gUnknown_203B4B4; extern struct unkStruct_3001B7C *gUnknown_3001B7C; +// dungeon_sbin.s extern const struct FileArchive gDungeonFileArchive; +// monster_sbin.s +extern const struct FileArchive gMonsterFileArchive; +// data_8115F5C.s extern const u8 gUnknown_81177CC[]; extern const u8 gUnknown_81177D8[]; +extern const u8 gUnknown_81177EC[]; // code_8098BDC.s +extern void sub_809971C(u16, u8 *, s16); extern void sub_80997F4(u16, u16); // pokemon_2.s extern void sub_808E53C(u32, u32); @@ -99,4 +105,25 @@ void GroundSprite_Reset(s16 a0) ResetSprites(TRUE); nullsub_10(TRUE); +} + +void sub_80A6460(void) +{ + struct OpenedFile *file; + s32 i; + u8 *data; + u16 something; + + file = OpenFileAndGetFileDataPtr(gUnknown_81177EC, &gMonsterFileArchive); + + something = 0x100; + data = file->data; + + for (i = 0; i < 13; i++) { + sub_809971C(something, data, 0x10); + something += 0x10; + data += 0x40; + } + + CloseFile(file); } \ No newline at end of file From 254f034ea27e762a886eb00350a0c734aa124bba Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Wed, 16 Aug 2023 19:32:51 -0400 Subject: [PATCH 11/27] Match sub_80A64A4 --- asm/ground_sprite.s | 114 ---------------------------------------- include/ground_sprite.h | 2 +- src/ground_sprite.c | 52 ++++++++++++++++++ 3 files changed, 53 insertions(+), 115 deletions(-) diff --git a/asm/ground_sprite.s b/asm/ground_sprite.s index 99234a1a..499032aa 100644 --- a/asm/ground_sprite.s +++ b/asm/ground_sprite.s @@ -5,120 +5,6 @@ .text - thumb_func_start sub_80A64A4 -sub_80A64A4: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r0, _080A6508 - ldr r0, [r0] - movs r1, 0x84 - lsls r1, 1 - adds r7, r0, r1 - bl sub_80A6460 - movs r0, 0 - mov r8, r0 -_080A64C0: - movs r1, 0x2 - ldrsh r0, [r7, r1] - cmp r0, 0 - ble _080A6568 - ldrh r5, [r7] - mov r0, r8 - adds r0, 0x1D - lsls r0, 16 - lsrs r0, 16 - mov r10, r0 - mov r1, r8 - lsls r0, r1, 20 - movs r1, 0xE8 - lsls r1, 17 - adds r0, r1 - lsrs r0, 16 - mov r9, r0 - movs r0, 0x80 - lsls r0, 2 - adds r1, r0, 0 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - beq _080A6514 - ldr r0, _080A650C - ldr r1, _080A6510 - bl OpenFileAndGetFileDataPtr - adds r6, r0, 0 - movs r0, 0xFF - ands r0, r5 - lsls r0, 6 - ldr r1, [r6, 0x4] - adds r2, r1, r0 - b _080A652A - .align 2, 0 -_080A6508: .4byte gUnknown_3001B7C -_080A650C: .4byte gUnknown_81177EC -_080A6510: .4byte gMonsterFileArchive -_080A6514: - movs r0, 0xFF - ands r0, r5 - lsls r0, 2 - ldr r1, _080A6584 - adds r0, r1 - ldr r0, [r0] - ldr r1, _080A6588 - bl OpenFileAndGetFileDataPtr - adds r6, r0, 0 - ldr r2, [r6, 0x4] -_080A652A: - movs r1, 0x80 - lsls r1, 5 - adds r0, r1, 0 - adds r1, r5, 0 - ands r1, r0 - lsls r1, 16 - lsrs r1, 16 - negs r1, r1 - lsrs r4, r1, 31 - movs r1, 0x80 - lsls r1, 6 - adds r0, r1, 0 - ands r5, r0 - cmp r5, 0 - beq _080A654C - movs r0, 0x2 - orrs r4, r0 -_080A654C: - mov r0, r9 - adds r1, r2, 0 - movs r2, 0x10 - bl sub_809971C - mov r0, r10 - adds r1, r4, 0 - bl sub_80997F4 - cmp r6, 0 - beq _080A6568 - adds r0, r6, 0 - bl CloseFile -_080A6568: - movs r0, 0x1 - add r8, r0 - adds r7, 0x4 - mov r1, r8 - cmp r1, 0x1 - ble _080A64C0 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080A6584: .4byte gUnknown_81178F4 -_080A6588: .4byte gOrnamentFileArchive - thumb_func_end sub_80A64A4 - thumb_func_start sub_80A658C sub_80A658C: push {r4,lr} diff --git a/include/ground_sprite.h b/include/ground_sprite.h index b743cefc..306be99a 100644 --- a/include/ground_sprite.h +++ b/include/ground_sprite.h @@ -23,7 +23,7 @@ struct unkStruct_3001B7C_sub0 struct unkStruct_3001B7C_sub108 { u16 unk0; - u16 unk2; + s16 unk2; }; // size: 0x110 struct unkStruct_3001B7C diff --git a/src/ground_sprite.c b/src/ground_sprite.c index d3a56c34..8792e1e1 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -21,10 +21,13 @@ extern struct unkStruct_3001B7C *gUnknown_3001B7C; extern const struct FileArchive gDungeonFileArchive; // monster_sbin.s extern const struct FileArchive gMonsterFileArchive; +// ornament_sbin.s +extern const struct FileArchive gOrnamentFileArchive; // data_8115F5C.s extern const u8 gUnknown_81177CC[]; extern const u8 gUnknown_81177D8[]; extern const u8 gUnknown_81177EC[]; +extern const u8 *gUnknown_81178F4[]; // code_8098BDC.s extern void sub_809971C(u16, u8 *, s16); @@ -126,4 +129,53 @@ void sub_80A6460(void) } CloseFile(file); +} + +void sub_80A64A4(void) +{ + u8 *r2; + u16 r4; + u32 r5; + struct OpenedFile *file; + struct unkStruct_3001B7C_sub108 *r7; + s32 i; + s16 r9; + u16 sl; + u16 flag; + u16 flag2; + + r7 = gUnknown_3001B7C->unk108; + sub_80A6460(); + + for (i = 0; i < 2; i++, r7++) + { + if (r7->unk2 > 0) { + r5 = r7->unk0; + sl = i + 29; + r9 = 0x1D0 + i * 16; + + flag = r5 & 0x200; + if (flag) { + file = OpenFileAndGetFileDataPtr(gUnknown_81177EC, &gMonsterFileArchive); + r2 = file->data + (r5 & 0xFF) * 0x40; + } + else { + file = OpenFileAndGetFileDataPtr((r5 & 0xFF)[gUnknown_81178F4], &gOrnamentFileArchive); + r2 = file->data; + } + + flag2 = r5 & 0x1000; + r4 = flag2 != 0; + + flag = r5 & 0x2000; + if (flag) + r4 |= 2; + + sub_809971C(r9, r2, 16); + sub_80997F4(sl, r4); + + if (file != NULL) + CloseFile(file); + } + } } \ No newline at end of file From d719c71e48072b0aba216b9ad54c2102786a312d Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 18 Aug 2023 08:12:41 -0400 Subject: [PATCH 12/27] Match sub_80A658C through sub_80A65E0 --- asm/ground_sprite.s | 48 ------------------ include/axdata.h | 107 +++++++++++++++++++++++++++++++++++++++ include/code_800558C_1.h | 3 ++ include/code_800DAC0.h | 1 + include/sprite.h | 37 +------------- src/code_800DAC0.c | 1 - src/code_80A7714.c | 59 +++++++++------------ src/ground_sprite.c | 27 ++++++++++ 8 files changed, 163 insertions(+), 120 deletions(-) create mode 100644 include/axdata.h diff --git a/asm/ground_sprite.s b/asm/ground_sprite.s index 499032aa..ca67ea03 100644 --- a/asm/ground_sprite.s +++ b/asm/ground_sprite.s @@ -5,54 +5,6 @@ .text - thumb_func_start sub_80A658C -sub_80A658C: - push {r4,lr} - bl sub_800DB7C - movs r0, 0 - bl ResetSprites - movs r0, 0 - bl nullsub_10 - bl sub_8005180 - bl nullsub_12 - bl CopySpritesToOam - bl nullsub_13 - bl sub_8005304 - bl nullsub_14 - ldr r0, _080A65D0 - ldr r0, [r0] - bl CloseFile - ldr r4, _080A65D4 - ldr r0, [r4] - bl MemoryFree - movs r0, 0 - str r0, [r4] - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_080A65D0: .4byte gUnknown_203B4B4 -_080A65D4: .4byte gUnknown_3001B7C - thumb_func_end sub_80A658C - - thumb_func_start sub_80A65D8 -sub_80A65D8: - adds r0, 0x50 - ldrh r0, [r0] - bx lr - thumb_func_end sub_80A65D8 - - thumb_func_start sub_80A65E0 -sub_80A65E0: - lsrs r0, 16 - ldr r2, _080A65EC - adds r1, r2, 0 - ands r0, r1 - bx lr - .align 2, 0 -_080A65EC: .4byte 0x0000337f - thumb_func_end sub_80A65E0 - thumb_func_start sub_80A65F0 sub_80A65F0: push {r4-r6,lr} diff --git a/include/axdata.h b/include/axdata.h new file mode 100644 index 00000000..5391ac5d --- /dev/null +++ b/include/axdata.h @@ -0,0 +1,107 @@ +#ifndef GUARD_AXDATA_H +#define GUARD_AXDATA_H + +#include "file_system.h" + +// size: 0x8 +struct UnkSpriteMem +{ + /* 0x0 */ void *src; + /* 0x4 */ s32 byteCount; +}; + +// size: 0x20 +struct axdata1 +{ + /* 0x0 */ s16 xPos; + /* 0x2 */ s16 yPos; + /* 0x4 */ u16 xOffset; + /* 0x6 */ u16 yOffset; + /* 0x8 */ u16 xShadow; + /* 0xA */ u16 yShadow; + u32 unkC; + u32 unk10; + /* 0x14 */ s16 vramTileOrMaybeAnimTimer; + s16 unk16; + /* 0x18 */ s16 poseId; + /* 0x1A */ s16 lastPoseId; + u8 fill1C[0x1E - 0x1C]; + u8 paletteNum; +}; + +// size: 0xA +struct __attribute__ ((packed, aligned(2))) ax_pose +{ + /* 0x0 */ s16 sprite; + u16 unk2; // Always 0 in red (except for end markers which are 0xFFFF) + /* 0x4 */ u16 flags1; + /* 0x6 */ u16 flags2; + /* 0x8 */ u16 flags3; +}; + +// size: 0xC +struct ax_anim +{ + /* 0x0 */ u8 frames; + /* 0x1 */ u8 unkFlags; + /* 0x2 */ s16 poseId; + /* 0x4 */ s16 xOffset; + /* 0x6 */ s16 yOffset; + /* 0x8 */ s16 xShadow; + /* 0xA */ s16 yShadow; +}; + +// size: 0x3C +struct axdata +{ + /* 0x0 */ u16 flags; + /* 0x2 */ u16 animFrames; + /* 0x4 */ u16 animWaitFrames; + /* 0x6 */ s16 totalFrames; + /* 0x8 */ struct axdata1 sub1; + /* 0x28 */ struct ax_anim *nextAnimData; + /* 0x2C */ struct ax_anim *activeAnimData; + /* 0x30 */ void *paletteData; // ? + /* 0x34 */ struct ax_pose *poseData; + /* 0x38 */ struct UnkSpriteMem **spriteData; +}; + +// size: 0x14 +struct axmain +{ + /* 0x0 */ struct ax_pose **poses; + /* 0x4 */ struct ax_anim ****animations; + /* 0x8 */ u32 animCount; + /* 0xC */ void *spriteData; // ? + /* 0x10 */ void *palettes; // ? +}; + +// size: ? +struct axPokemon +{ + /* 0x0 */ struct axdata axdata; + /* 0x3C */ struct OpenedFile *spriteFile; + u16 unk40_maybeAnimTimer; + u8 unk42_animId1; + u8 unk43_animId2; + u8 unk44; + u8 unk45_orientation; + u8 unk46; + u8 unk47; + u8 unk48; + u8 fill49[0x4C - 0x49]; + /* 0x4C */ struct axmain *axmain; + u8 flags_0x50; + u8 fill51; + s16 unk52; + u8 fill54[0x66 - 0x54]; + s16 unk66; + u8 fill68[0x6C - 0x68]; + u16 unk6C; + u16 unk6E; + u8 unk70; + u8 fill71[0x7C - 0x71]; + s32 unk7C; +}; + +#endif // GUARD_AXDATA_H \ No newline at end of file diff --git a/include/code_800558C_1.h b/include/code_800558C_1.h index 4d931ace..fd9e1890 100644 --- a/include/code_800558C_1.h +++ b/include/code_800558C_1.h @@ -2,5 +2,8 @@ #define GUARD_CODE_800558C_1_H void nullsub_10(bool8); +void nullsub_12(void); +void nullsub_13(void); +void nullsub_14(void); #endif // GUARD_CODE_800558C_1_H \ No newline at end of file diff --git a/include/code_800DAC0.h b/include/code_800DAC0.h index b7e0e87d..66d71d80 100644 --- a/include/code_800DAC0.h +++ b/include/code_800DAC0.h @@ -2,5 +2,6 @@ #define GUARD_CODE_800DAC0_H void sub_800DAC0(u32); +void sub_800DB7C(void); #endif // GUARD_CODE_800DAC0_H \ No newline at end of file diff --git a/include/sprite.h b/include/sprite.h index d0bd6504..2da32219 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -1,6 +1,7 @@ #ifndef GUARD_SPRITE_H #define GUARD_SPRITE_H +#include "axdata.h" #include "ground_sprite.h" #include "position.h" @@ -39,42 +40,6 @@ struct unkStruct_20266B0 /* 0x8 */ void *dest; }; -// size: 0x8 -struct UnkSpriteMem -{ - /* 0x0 */ void *src; - /* 0x4 */ s32 byteCount; -}; - -// size: 0x20 -struct axdata1 -{ - /* 0x0 */ s16 xPos; - /* 0x2 */ s16 yPos; - /* 0x4 */ u16 xOffset; - /* 0x6 */ u16 yOffset; - /* 0x8 */ u16 xShadow; - /* 0xA */ u16 yShadow; - u32 unkC; - u32 unk10; - /* 0x14 */ s16 vramTileOrMaybeAnimTimer; - s16 unk16; - /* 0x18 */ s16 poseId; - /* 0x1A */ s16 lastPoseId; - u8 fill1C[0x1E - 0x1C]; - u8 paletteNum; -}; - -// size: 0xA -struct __attribute__ ((packed, aligned(2))) ax_pose -{ - s16 sprite; - u16 unk2; // Always 0 in red (except for end markers which are 0xFFFF) - u16 flags1; - u16 flags2; - u16 flags3; -}; - void AddSprite(struct unkSprite *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); void BlinkSavingIcon(void); void CopySpritesToOam(void); diff --git a/src/code_800DAC0.c b/src/code_800DAC0.c index 8265ce3c..40b6dedd 100644 --- a/src/code_800DAC0.c +++ b/src/code_800DAC0.c @@ -57,7 +57,6 @@ extern u8 gefob001_string[]; extern struct FileArchive gEffectFileArchive; extern void sub_8005610(struct OpenedFile *, u32, u32,u32); -extern void sub_800DB7C(void); extern void sub_800F034(void); extern void sub_800ED38(u32); extern void sub_800DC14(void); diff --git a/src/code_80A7714.c b/src/code_80A7714.c index a6b91265..9d0d8904 100644 --- a/src/code_80A7714.c +++ b/src/code_80A7714.c @@ -1,23 +1,24 @@ #include "global.h" +#include "axdata.h" -extern void sub_80A68A0(void); -extern void sub_80A7094(u32 r0, u32 r1, u32 r2, u32 r3); -extern void sub_80A7310(u32 r0, u32 r1, u32 r2, u32 r3); +extern void sub_80A68A0(u32); +extern void sub_80A7094(struct axPokemon *, u32, u32, u32); +extern void sub_80A7310(struct axPokemon *, u32, u32, u32); extern void sub_80A7784(); extern s16 gUnknown_2039DE0; extern u32 gUnknown_8117EFC; extern u32 *gMapScriptTable[]; -void sub_80A7714(void) +void sub_80A7714(u32 a0) { - sub_80A68A0(); + sub_80A68A0(a0); } -void sub_80A7720(u32 r0, u32 r1, u32 r2) +void sub_80A7720(struct axPokemon *a0, u32 a1, u32 a2) { - sub_80A7094(r0, 0, r1, r2); - sub_80A7310(r0, r1, 0, r2); + sub_80A7094(a0, 0, a1, a2); + sub_80A7310(a0, a1, 0, a2); } void sub_80A7744(void) @@ -30,55 +31,43 @@ void sub_80A7754(void) gUnknown_2039DE0 = -1; } -void sub_80A7764(s16 r0) +void sub_80A7764(s16 a0) { - s32 temp = r0; + s32 temp = a0; + sub_80A7784(); - if(temp != -1) - { + + if (temp != -1) gUnknown_2039DE0 = temp; - } } void sub_80A7784(void) { - if(gUnknown_2039DE0 != -1) - { + if (gUnknown_2039DE0 != -1) gUnknown_2039DE0 = -1; - } } -u8 sub_80A77A0(s16 r0) +bool8 sub_80A77A0(s16 a0) { s32 temp; s32 temp2; - temp = r0; + temp = a0; temp2 = temp; - if(gUnknown_2039DE0 != temp) - { - if(temp < 0) - { + if (gUnknown_2039DE0 != temp) { + if (temp < 0) sub_80A7784(); - - } else - { sub_80A7764(temp2); - } - return 1; + return TRUE; } - return 0; + return FALSE; } // TODO review this later -u32 *sub_80A77D0(s16 r0) +u32 *sub_80A77D0(s16 a0) { - if(r0 != -1) - { - return gMapScriptTable[r0]; - } + if (a0 != -1) + return gMapScriptTable[a0]; else - { return &gUnknown_8117EFC; - } } diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 8792e1e1..fcfc4c28 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -178,4 +178,31 @@ void sub_80A64A4(void) CloseFile(file); } } +} + +void sub_80A658C(void) +{ + sub_800DB7C(); + ResetSprites(FALSE); + nullsub_10(0); + sub_8005180(); + nullsub_12(); + CopySpritesToOam(); + nullsub_13(); + sub_8005304(); + nullsub_14(); + CloseFile(gUnknown_203B4B4); + MemoryFree(gUnknown_3001B7C); + gUnknown_3001B7C = NULL; +} + +// Unused +u16 sub_80A65D8(u16 *a0) +{ + return a0[40]; +} + +u16 sub_80A65E0(u32 a0) +{ + return (a0 >> 16) & 0x337F; } \ No newline at end of file From 79b3ea4ed68506dae4c43c68f5f7e5115dd99a1e Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 18 Aug 2023 10:11:34 -0400 Subject: [PATCH 13/27] Match sub_80053AC and make structs AF --- asm/sprite.s | 20 ------- include/axdata.h | 12 ++--- include/code_805D8C8.h | 13 +++++ include/constants/monster.h | 7 +-- include/dungeon_entity.h | 29 ++-------- include/dungeon_global_data.h | 5 +- include/sprite.h | 49 +++++++++++++++++ src/code_806CD90.c | 49 ++++++++--------- src/code_8077274_1.c | 99 +++++++++++++++++------------------ src/code_80958E8.c | 4 +- src/pokemon_mid.c | 2 +- src/rescue_password_menu.c | 2 +- src/sprite.c | 5 ++ 13 files changed, 162 insertions(+), 134 deletions(-) create mode 100644 include/code_805D8C8.h diff --git a/asm/sprite.s b/asm/sprite.s index 11097902..69cd5112 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,26 +5,6 @@ .text - thumb_func_start sub_80053AC -sub_80053AC: - push {r4-r6,lr} - sub sp, 0xC - ldr r5, [sp, 0x1C] - ldr r6, [sp, 0x20] - ldr r4, [sp, 0x24] - lsls r4, 24 - lsrs r4, 24 - ldr r1, [r1, 0x4] - str r5, [sp] - str r6, [sp, 0x4] - str r4, [sp, 0x8] - bl sub_80053D0 - add sp, 0xC - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_80053AC - thumb_func_start sub_80053D0 sub_80053D0: push {r4-r7,lr} diff --git a/include/axdata.h b/include/axdata.h index 5391ac5d..e6c8d897 100644 --- a/include/axdata.h +++ b/include/axdata.h @@ -54,13 +54,13 @@ struct ax_anim // size: 0x3C struct axdata { - /* 0x0 */ u16 flags; - /* 0x2 */ u16 animFrames; - /* 0x4 */ u16 animWaitFrames; - /* 0x6 */ s16 totalFrames; + /* 0x0 */ u16 flags; // 0x8000 - animating, 0x2000 finished? 0x1000 continue + /* 0x2 */ u16 animFrames; // frames left in the current animation frame + /* 0x4 */ u16 animWaitFrames; // frames to not update the animation for + /* 0x6 */ s16 totalFrames; // max 30000 /* 0x8 */ struct axdata1 sub1; - /* 0x28 */ struct ax_anim *nextAnimData; - /* 0x2C */ struct ax_anim *activeAnimData; + /* 0x28 */ struct ax_anim *nextAnimData; // next animation data (if flags&0x1000) + /* 0x2C */ struct ax_anim *activeAnimData; // current animation data /* 0x30 */ void *paletteData; // ? /* 0x34 */ struct ax_pose *poseData; /* 0x38 */ struct UnkSpriteMem **spriteData; diff --git a/include/code_805D8C8.h b/include/code_805D8C8.h new file mode 100644 index 00000000..3bab54c0 --- /dev/null +++ b/include/code_805D8C8.h @@ -0,0 +1,13 @@ +#ifndef GUARD_CODE_805D8C8_H +#define GUARD_CODE_805D8C8_H + +#include "sprite.h" + +extern struct Dungeon_Sub17B44 *sub_80687D0(s16); +/*struct Dungeon_Sub17B44 *sub_80687D0(s16 species) +{ + s32 species32 = species; + return gDungeon->sub17B44[species32]; +}*/ + +#endif // GUARD_CODE_805D8C8_H \ No newline at end of file diff --git a/include/constants/monster.h b/include/constants/monster.h index 8d6a466a..3d4c0929 100644 --- a/include/constants/monster.h +++ b/include/constants/monster.h @@ -1,8 +1,6 @@ #ifndef GUARD_CONSTANTS_MONSTER_H #define GUARD_CONSTANTS_MONSTER_H -#define NUM_MONSTERS 413 - #define MONSTER_NONE 0 #define MONSTER_BULBASAUR 1 #define MONSTER_IVYSAUR 2 @@ -429,4 +427,7 @@ #define MONSTER_STATUE 422 #define MONSTER_RAYQUAZA_CUTSCENE 423 -#endif // GUARD_CONSTANTS_MONSTER_H +#define NUM_MONSTERS MONSTER_JIRACHI +#define MONSTER_MAX MONSTER_RAYQUAZA_CUTSCENE + +#endif // GUARD_CONSTANTS_MONSTER_H \ No newline at end of file diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h index c2e28157..7d9c9f44 100644 --- a/include/dungeon_entity.h +++ b/include/dungeon_entity.h @@ -5,6 +5,7 @@ #include "constants/move.h" #include "item.h" #include "position.h" +#include "sprite.h" #define MAX_STAT_STAGE 20 #define STAT_MULTIPLIER_THRESHOLD 63 @@ -270,32 +271,8 @@ struct Entity // The global spawn index counter starts at 10. Each Pokémon that spawns increments the counter and // gets assigned the current counter value as its spawn index. /* 0x26 */ u16 spawnGenID; - u8 fill28[0x2A - 0x28]; - // 0x2A and 0x2E seem to be related to the sprite animation, though not sure how they're related. - /* 0x2A */ u16 spriteAnimationCounter; - // Each animation has a few different sprites that it transitions between. - // This is the index of the currently displayed sprite within the animation. - // Differs from 0x34 as this index is only between the sprites used by the animation, - // while 0x34 is a shared index among all sprites. - /* 0x2C */ u16 spriteAnimationIndex; - /* 0x2E */ u16 spriteAnimationCounter2; - // The position of the sprite within the tile. The animation may change the position slightly. - /* 0x30 */ struct Position spritePos; - // Offset of the sprite from its position at the start of the animation. Changes alongside spritePos. - /* 0x34 */ struct Position spritePosOffset; - u8 fill38[0x48 - 0x38]; - // The sprite index to display, among the Pokémon's possible sprites. - /* 0x48 */ u16 spriteIndexForEntity; - /* 0x4A */ u16 spriteIndexForEntity2; - u8 unk4C[0x50 - 0x4C]; - // Some kind of base sprite index depending on which way the Pokémon is facing. - // and which animation is playing (e.g., idle, moving). - // Compared to 0x48, 0x50 and 0x54 are much larger and could be global indexes among all sprites in the game. - /* 0x50 */ u16 spriteBaseForDirection; - u8 fill52[0x54 - 0x52]; - /* 0x54 */ u16 spriteGlobalIndex; - u8 fill56[0x64 - 0x56]; - u32 unk64; + /* 0x28*/ struct Entity_Sub28 sub28; + struct Dungeon_Sub17B44 *unk64; s16 unk68; u8 unk6A; u8 unk6B; diff --git a/include/dungeon_global_data.h b/include/dungeon_global_data.h index 27823b47..9ee9762c 100644 --- a/include/dungeon_global_data.h +++ b/include/dungeon_global_data.h @@ -6,6 +6,7 @@ #include "global.h" #include "map.h" #include "position.h" +#include "sprite.h" #define DUNGEON_MAX_SIZE_X 56 #define DUNGEON_MAX_SIZE_Y 32 @@ -197,7 +198,9 @@ struct Dungeon /* 0x17B34 */ u8 fillunk1734[0x17B38 - 0x17B34]; /* 0x17B38 */ u32 unk17B38; /* 0x17B3C */ u32 unk17B3C; - u8 fill17B40[0x181E8 - 0x17B40]; + u8 fill17B40[0x17B44 - 0x17B40]; + struct Dungeon_Sub17B44 *sub17B44[MONSTER_MAX]; // Assuming MONSTER_MAX since the highest value I've seen read is MONSTER_DECOY + u8 fill181E0[0x181E8 - 0x181E0]; /* 0x181E8 */ struct Position cameraPos; /* 0x181EC */ struct Position cameraPosMirror; /* 0x181F0 */ struct Position cameraPixelPos; diff --git a/include/sprite.h b/include/sprite.h index 2da32219..1716a4be 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -40,6 +40,53 @@ struct unkStruct_20266B0 /* 0x8 */ void *dest; }; +// size: ? 0x3C for now +struct Entity_Sub28 +{ + u16 unk0; + // 0x2 and 0x6 seem to be related to the sprite animation, though not sure how they're related. + /* 0x2 */ u16 spriteAnimationCounter; + // Each animation has a few different sprites that it transitions between. + // This is the index of the currently displayed sprite within the animation. + // Differs from 0xC as this index is only between the sprites used by the animation, + // while 0xC is a shared index among all sprites. + /* 0x4 */ u16 spriteAnimationIndex; + /* 0x6 */ u16 spriteAnimationCounter2; + // The position of the sprite within the tile. The animation may change the position slightly. + /* 0x8 */ struct Position spritePos; + // Offset of the sprite from its position at the start of the animation. Changes alongside spritePos. + /* 0xC */ struct Position spritePosOffset; + u8 fill10[0x20 - 0x10]; + // The sprite index to display, among the Pokémon's possible sprites. + /* 0x20 */ u16 spriteIndexForEntity; + /* 0x22 */ u16 spriteIndexForEntity2; + u8 unk24[0x28 - 0x24]; + // Some kind of base sprite index depending on which way the Pokémon is facing. + // and which animation is playing (e.g., idle, moving). + // Compared to 0x20, 0x28 and 0x2C are much larger and could be global indexes among all sprites in the game. + /* 0x28 */ u16 spriteBaseForDirection; + u8 fill2A[0x2C - 0x2A]; + /* 0x2C */ u16 spriteGlobalIndex; + u8 fill2E[0x3C - 0x2E]; +}; + +// size: ? +struct Dungeon_Sub17B44_Sub4 +{ + u32 unk0; + u32 unk4; + u8 fill8[0xC - 0x8]; + u32 unkC; + u32 unk10; +}; + +// size: ? +struct Dungeon_Sub17B44 +{ + u8 fill0[0x4 - 0x0]; + struct Dungeon_Sub17B44_Sub4 *unk4; +}; + void AddSprite(struct unkSprite *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); void BlinkSavingIcon(void); void CopySpritesToOam(void); @@ -49,5 +96,7 @@ void SetSavingIconCoords(struct Position *); void sub_8004E8C(struct unkStruct_2039DB0 *); void sub_8005180(void); void sub_8005304(void); +void sub_80053AC(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, u32, bool8); +extern void sub_80053D0(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/code_806CD90.c b/src/code_806CD90.c index 7e8cba71..1b8998fc 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -1,20 +1,20 @@ #include "global.h" +#include "code_805D8C8.h" #include "constants/direction.h" #include "constants/status.h" #include "dungeon_entity.h" #include "dungeon_global_data.h" #include "dungeon_util.h" #include "pokemon.h" -#include "tile_types.h" #include "random.h" +#include "sprite.h" +#include "tile_types.h" extern u8 sub_806CEBC(struct Entity *); extern void sub_806CCB4(struct Entity *, u8); extern void sub_803E46C(u32); extern bool8 sub_808DA44(s32 a1_, u32 a2_); extern u32 sub_806CF98(struct Entity *); -extern u32 sub_80687D0(s16); -void sub_80053AC(u8 *, s32, u32, u32, u32, u32, u8); void sub_806CDD4(struct Entity *, u8, u32); extern const u8 gUnknown_8106EEF[]; @@ -53,28 +53,29 @@ void sub_806CC70(void) void sub_806CCB4(struct Entity *entity, u8 param_2) { - s32 sVar1; - bool8 flag; - struct EntityInfo *info; + s32 sVar1; + bool8 flag; + struct EntityInfo *info; - info = entity->info; - flag = gDungeon->hallucinating; - if (entity == gDungeon->cameraTarget) { - flag = FALSE; - } - entity->unk6B = param_2; - entity->unk6A = param_2; - entity->direction2 = info->action.direction; - entity->direction = info->action.direction; - entity->unk6F = 0; - sVar1 = entity->unk68; - if ((info->waitingStatus != STATUS_DECOY) && (!flag)) { - sub_80053AC(entity->fill28,entity->unk64,entity->unk6A,entity->direction,sVar1,Rand32Bit() & 3,0); - } - else { - sub_80053AC(entity->fill28,sub_80687D0(0x1a5),entity->unk6A,entity->direction,sVar1,Rand32Bit() & 3,0); - } - entity->unk6E = 0; + info = entity->info; + flag = gDungeon->hallucinating; + + if (entity == gDungeon->cameraTarget) + flag = FALSE; + + entity->unk6B = param_2; + entity->unk6A = param_2; + entity->direction2 = info->action.direction; + entity->direction = info->action.direction; + entity->unk6F = 0; + sVar1 = entity->unk68; + + if (info->waitingStatus != STATUS_DECOY && !flag) + sub_80053AC(&entity->sub28, entity->unk64, entity->unk6A, entity->direction, sVar1, Rand32Bit() & 3, FALSE); + else + sub_80053AC(&entity->sub28, sub_80687D0(MONSTER_DECOY), entity->unk6A, entity->direction, sVar1, Rand32Bit() & 3, FALSE); + + entity->unk6E = 0; } void sub_806CD90(void) diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index f9f81e35..fa2340e4 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -17,6 +17,7 @@ #include "move_effects_target.h" #include "pokemon.h" #include "status_checks_1.h" +#include "code_805D8C8.h" extern u8 gAvailablePokemonNames[0x58]; extern u8 gUnknown_202DFE8[0x58]; @@ -173,7 +174,6 @@ extern void EntityUpdateStatusSprites(struct Entity *); extern void sub_8042A74(struct Entity *r0); extern void sub_807EC28(u32); extern s32 sub_8069F54(struct Entity *param_1, s16 param_2); -extern u32 sub_80687D0(s16); extern void sub_806A898(struct Entity *, u32, u32); extern void HealTargetHP(struct Entity *pokemon, struct Entity *r1, s16, s16, u32); extern void sub_806CE68(struct Entity *, s32); @@ -236,62 +236,61 @@ void MuzzleTarget(struct Entity *pokemon, struct Entity *target) } } -// TODO: still gross but does match void sub_8078E18(struct Entity * pokemon, struct Entity * target) { - s16 species; - s32 iVar5; - s32 apparentID; - s16 apparentID_s16; - s32 index; - struct EntityInfo *entityInfo; - s32 iVar9; - struct PokemonStruct *auStack544[128]; - + s16 species; + s32 iVar5; + s32 apparentID; + s16 apparentID_s16; + s32 index; + struct EntityInfo *entityInfo; + struct Dungeon_Sub17B44 *iVar9; + struct PokemonStruct *auStack544[128]; + + if (!EntityExists(target)) + return; - if (EntityExists(target)) { entityInfo = target->info; - if (entityInfo->transformStatus == STATUS_TRANSFORMED) { - sub_80522F4(pokemon,target,*gUnknown_80FBF04); - } - else { - SetMessageArgument(gAvailablePokemonNames,target,0); - iVar5 = sub_803D870(auStack544,0); - if (iVar5 == 0) { - goto print; - } - else - { - iVar9 = 0; - for(index = 0; index < DUNGEON_MAX_POKEMON; index++) - { - species = ExtractSpeciesIndex(&auStack544[DungeonRandInt(iVar5) << 1]); - apparentID_s16 = sub_8069F54(target, species); - apparentID = apparentID_s16; - if (((apparentID != entityInfo->apparentID) && (sub_806AA0C(apparentID, 1))) && - (iVar9 = sub_80687D0(apparentID), iVar9 != 0)) break; + if (entityInfo->transformStatus == STATUS_TRANSFORMED) + sub_80522F4(pokemon, target, *gUnknown_80FBF04); + else { + SetMessageArgument(gAvailablePokemonNames, target, 0); + iVar5 = sub_803D870(auStack544, 0); + + if (iVar5 == 0) + sub_80522F4(pokemon, target, *gUnknown_80FBEE4); + else { + iVar9 = NULL; + + for (index = 0; index < DUNGEON_MAX_POKEMON; index++) { + species = ExtractSpeciesIndex(&auStack544[DungeonRandInt(iVar5) * 2]); + apparentID_s16 = sub_8069F54(target, species); + apparentID = apparentID_s16; + + if (apparentID != entityInfo->apparentID && sub_806AA0C(apparentID, 1)) { + iVar9 = sub_80687D0(apparentID); + if (iVar9 != NULL) + break; + } + } + + if (index == DUNGEON_MAX_POKEMON || iVar9 == NULL) + sub_80522F4(pokemon, target, *gUnknown_80FBEE4); + else { + entityInfo->apparentID = apparentID; + target->unk64 = iVar9; + entityInfo->transformStatus = STATUS_TRANSFORMED; + entityInfo->transformStatusTurns = CalculateStatusTurns(target, gUnknown_80F4EFC, TRUE) + 1; + sub_806CF98(target); + nullsub_87(target); + sub_806CCB4(target, sub_806CEBC(target)); + CopyCyanMonsterNametoBuffer(gUnknown_202DFE8, entityInfo->apparentID); + sub_80522F4(pokemon, target, *gUnknown_80FBEC0); + EntityUpdateStatusSprites(target); + } } - if ((index == DUNGEON_MAX_POKEMON) || (iVar9 == 0)) { -print: - sub_80522F4(pokemon,target,*gUnknown_80FBEE4); - } - else - { - entityInfo->apparentID = apparentID; - target->unk64 = iVar9; - entityInfo->transformStatus = STATUS_TRANSFORMED; - entityInfo->transformStatusTurns = CalculateStatusTurns(target,gUnknown_80F4EFC,TRUE) + 1; - sub_806CF98(target); - nullsub_87(target); - sub_806CCB4(target, sub_806CEBC(target)); - CopyCyanMonsterNametoBuffer(gUnknown_202DFE8, entityInfo->apparentID); - sub_80522F4(pokemon,target,*gUnknown_80FBEC0); - EntityUpdateStatusSprites(target); - } - } } - } } void MobileStatusTarget(struct Entity * pokemon, struct Entity * target) diff --git a/src/code_80958E8.c b/src/code_80958E8.c index 4ee39320..6b4f3cba 100644 --- a/src/code_80958E8.c +++ b/src/code_80958E8.c @@ -100,14 +100,14 @@ bool8 ValidateWonderMail(struct WonderMail *data) if(data->clientSpecies == MONSTER_NONE) return FALSE; - if(data->clientSpecies > MONSTER_RAYQUAZA_CUTSCENE) + if(data->clientSpecies > MONSTER_MAX) return FALSE; if(data->clientSpecies != GetBaseSpecies(data->clientSpecies)) return FALSE; if(!sub_803C0DC(data->clientSpecies)) return FALSE; - if(data->targetSpecies > MONSTER_RAYQUAZA_CUTSCENE) + if(data->targetSpecies > MONSTER_MAX) return FALSE; if(data->targetSpecies != GetBaseSpecies(data->targetSpecies)) return FALSE; diff --git a/src/pokemon_mid.c b/src/pokemon_mid.c index 17f4205a..7f30686c 100644 --- a/src/pokemon_mid.c +++ b/src/pokemon_mid.c @@ -880,7 +880,7 @@ s32 sub_808E400(s32 _species, s16* _a2, s32 _a3, s32 _a4) register s16* a2 asm("r6"); i = 1; a2 = _a2; - for (i = 1; i <= MONSTER_RAYQUAZA_CUTSCENE; i++) { + for (i = 1; i <= MONSTER_MAX; i++) { register s32 current asm("r8") = (s16)i; if (species != GetPokemonEvolveFrom(i)) { continue; diff --git a/src/rescue_password_menu.c b/src/rescue_password_menu.c index 2bde7231..fb00a658 100644 --- a/src/rescue_password_menu.c +++ b/src/rescue_password_menu.c @@ -636,7 +636,7 @@ u32 sub_8039068(u32 mailMode, u8 *passwordBuffer, struct unkStruct_203B480 *para { if ( (!sub_803D204(passwordBuffer, param_3)) || (WONDER_MAIL_TYPE_OKD < param_3->mailType) || (param_3->dungeon.floor >= GetDungeonFloorCount(param_3->dungeon.id)) || - (param_3->clientSpecies == MONSTER_NONE) || (MONSTER_RAYQUAZA_CUTSCENE < param_3->clientSpecies) || + (param_3->clientSpecies == MONSTER_NONE) || (MONSTER_MAX < param_3->clientSpecies) || (IsInvalidItemReward(param_3->item.id))) { return PASSWORD_ENTRY_INCORRECT_PASSWORD; } diff --git a/src/sprite.c b/src/sprite.c index 3a09f14e..fe6e0949 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -883,4 +883,9 @@ void sub_800533C(struct ax_pose **a0, struct UnkSpriteMem **a1, struct axdata1 * sub_8004EA8(r4, a2, mem, spriteMasks); } +} + +void sub_80053AC(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) +{ + sub_80053D0(a0, a1->unk4, a2, a3, a4, spriteAnimIndex, a6); } \ No newline at end of file From ad5ec244aa927be5a6d496837ea21facb67698d0 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 18 Aug 2023 10:32:15 -0400 Subject: [PATCH 14/27] Match sub_80053D0 --- asm/sprite.s | 59 ------------------------------------------------ include/sprite.h | 19 ++++++++++------ src/sprite.c | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+), 66 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index 69cd5112..171c43f0 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,65 +5,6 @@ .text - thumb_func_start sub_80053D0 -sub_80053D0: - push {r4-r7,lr} - adds r4, r0, 0 - adds r5, r1, 0 - adds r6, r2, 0 - adds r7, r3, 0 - ldr r0, [sp, 0x1C] - lsls r0, 24 - movs r2, 0 - movs r3, 0x80 - lsls r3, 8 - strh r3, [r4] - cmp r0, 0 - beq _080053F6 - movs r0, 0x80 - lsls r0, 5 - adds r1, r0, 0 - adds r0, r3, 0 - orrs r0, r1 - strh r0, [r4] -_080053F6: - strh r2, [r4, 0x2] - ldr r0, [sp, 0x18] - strh r0, [r4, 0x4] - strh r2, [r4, 0xC] - strh r2, [r4, 0xE] - ldr r0, [sp, 0x14] - strh r0, [r4, 0x1C] - ldr r0, _08005438 - strh r0, [r4, 0x20] - movs r0, 0x1 - negs r0, r0 - strh r0, [r4, 0x22] - str r2, [r4, 0x14] - str r2, [r4, 0x18] - strh r2, [r4, 0x6] - ldr r1, [r5, 0x4] - lsls r0, r6, 2 - adds r0, r1 - ldr r1, [r0] - lsls r0, r7, 2 - adds r0, r1 - ldr r0, [r0] - str r0, [r4, 0x28] - str r0, [r4, 0x2C] - ldr r0, [r5] - str r0, [r4, 0x34] - ldr r0, [r5, 0xC] - str r0, [r4, 0x38] - ldr r0, [r5, 0x10] - str r0, [r4, 0x30] - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08005438: .4byte 0x0000ffff - thumb_func_end sub_80053D0 - thumb_func_start sub_800543C sub_800543C: push {r4,r5,lr} diff --git a/include/sprite.h b/include/sprite.h index 1716a4be..9e591840 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -56,7 +56,11 @@ struct Entity_Sub28 /* 0x8 */ struct Position spritePos; // Offset of the sprite from its position at the start of the animation. Changes alongside spritePos. /* 0xC */ struct Position spritePosOffset; - u8 fill10[0x20 - 0x10]; + u8 fill10[0x14 - 0x10]; + u32 unk14; + u32 unk18; + u16 unk1C; + u8 fill1E[0x20 - 0x1E]; // The sprite index to display, among the Pokémon's possible sprites. /* 0x20 */ u16 spriteIndexForEntity; /* 0x22 */ u16 spriteIndexForEntity2; @@ -64,17 +68,18 @@ struct Entity_Sub28 // Some kind of base sprite index depending on which way the Pokémon is facing. // and which animation is playing (e.g., idle, moving). // Compared to 0x20, 0x28 and 0x2C are much larger and could be global indexes among all sprites in the game. - /* 0x28 */ u16 spriteBaseForDirection; - u8 fill2A[0x2C - 0x2A]; - /* 0x2C */ u16 spriteGlobalIndex; - u8 fill2E[0x3C - 0x2E]; + /* 0x28 */ u32 spriteBaseForDirection; + /* 0x2C */ u32 spriteGlobalIndex; + u32 unk30; + u32 unk34; + u32 unk38; }; // size: ? struct Dungeon_Sub17B44_Sub4 { u32 unk0; - u32 unk4; + u32 **unk4; u8 fill8[0xC - 0x8]; u32 unkC; u32 unk10; @@ -97,6 +102,6 @@ void sub_8004E8C(struct unkStruct_2039DB0 *); void sub_8005180(void); void sub_8005304(void); void sub_80053AC(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, u32, bool8); -extern void sub_80053D0(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6); +void sub_80053D0(struct Entity_Sub28 *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, u32, bool8); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/sprite.c b/src/sprite.c index fe6e0949..150fc717 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -888,4 +888,27 @@ void sub_800533C(struct ax_pose **a0, struct UnkSpriteMem **a1, struct axdata1 * void sub_80053AC(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) { sub_80053D0(a0, a1->unk4, a2, a3, a4, spriteAnimIndex, a6); +} + +void sub_80053D0(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 direction, u32 a4, u32 spriteAnimIndex, bool8 a6) +{ + a0->unk0 = 0x8000; + if (a6) + a0->unk0 |= 0x1000; + + a0->spriteAnimationCounter = 0; + a0->spriteAnimationIndex = spriteAnimIndex; + a0->spritePosOffset.x = 0; + a0->spritePosOffset.y = 0; + a0->unk1C = a4; + a0->spriteIndexForEntity = 0xFFFF; + a0->spriteIndexForEntity2 = 0xFFFF; + a0->unk14 = 0; + a0->unk18 = 0; + a0->spriteAnimationCounter2 = 0; + a0->spriteBaseForDirection = a1->unk4[a2][direction]; + a0->spriteGlobalIndex = a0->spriteBaseForDirection; + a0->unk34 = a1->unk0; + a0->unk38 = a1->unkC; + a0->unk30 = a1->unk10; } \ No newline at end of file From 710638ad7adc04f82fea4eef8068c03b5b05fe99 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:20:19 -0400 Subject: [PATCH 15/27] Match sub_800543C and sub_800545C --- asm/sprite.s | 71 ------------------------------------------------ include/sprite.h | 1 + src/sprite.c | 28 +++++++++++++++++++ 3 files changed, 29 insertions(+), 71 deletions(-) diff --git a/asm/sprite.s b/asm/sprite.s index 171c43f0..4d186bd5 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,77 +5,6 @@ .text - thumb_func_start sub_800543C -sub_800543C: - push {r4,r5,lr} - sub sp, 0x8 - ldr r5, [sp, 0x14] - ldr r4, [sp, 0x18] - lsls r4, 24 - lsrs r4, 24 - ldr r1, [r1, 0x4] - str r5, [sp] - str r4, [sp, 0x4] - bl sub_800545C - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_800543C - - thumb_func_start sub_800545C -sub_800545C: - push {r4-r7,lr} - adds r4, r0, 0 - adds r6, r1, 0 - adds r7, r2, 0 - adds r5, r3, 0 - ldr r0, [sp, 0x18] - lsls r0, 24 - movs r2, 0 - movs r3, 0x80 - lsls r3, 8 - strh r3, [r4] - cmp r0, 0 - beq _08005482 - movs r0, 0x80 - lsls r0, 5 - adds r1, r0, 0 - adds r0, r3, 0 - orrs r0, r1 - strh r0, [r4] -_08005482: - strh r2, [r4, 0x2] - ldr r0, [sp, 0x14] - strh r0, [r4, 0x4] - strh r2, [r4, 0xC] - strh r2, [r4, 0xE] - strh r5, [r4, 0x1C] - ldr r0, _080054B8 - strh r0, [r4, 0x20] - movs r0, 0x1 - negs r0, r0 - strh r0, [r4, 0x22] - str r2, [r4, 0x14] - str r2, [r4, 0x18] - strh r2, [r4, 0x6] - ldr r1, [r6, 0x4] - lsls r0, r7, 2 - adds r0, r1 - ldr r0, [r0] - ldr r0, [r0] - str r0, [r4, 0x28] - str r0, [r4, 0x2C] - ldr r0, [r6] - str r0, [r4, 0x34] - str r2, [r4, 0x30] - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080054B8: .4byte 0x0000ffff - thumb_func_end sub_800545C - thumb_func_start sub_80054BC sub_80054BC: push {r4,lr} diff --git a/include/sprite.h b/include/sprite.h index 9e591840..653bc270 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -103,5 +103,6 @@ void sub_8005180(void); void sub_8005304(void); void sub_80053AC(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, u32, bool8); void sub_80053D0(struct Entity_Sub28 *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, u32, bool8); +void sub_800543C(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, bool8); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/sprite.c b/src/sprite.c index 150fc717..db0b4caa 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -19,6 +19,7 @@ extern struct unkStruct_20266B0 *gUnknown_203B074; extern void nullsub_3(s32, s32); void RegisterSpriteParts_80052BC(struct UnkSpriteMem *); +void sub_800545C(struct Entity_Sub28 *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, bool8); void InitSprites(void) { @@ -911,4 +912,31 @@ void sub_80053D0(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a0->unk34 = a1->unk0; a0->unk38 = a1->unkC; a0->unk30 = a1->unk10; +} + +void sub_800543C(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +{ + sub_800545C(a0, a1->unk4, a2, a3, spriteAnimIndex, a5); +} + +void sub_800545C(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +{ + a0->unk0 = 0x8000; + if (a5) + a0->unk0 |= 0x1000; + + a0->spriteAnimationCounter = 0; + a0->spriteAnimationIndex = spriteAnimIndex; + a0->spritePosOffset.x = 0; + a0->spritePosOffset.y = 0; + a0->unk1C = a3; + a0->spriteIndexForEntity = 0xFFFF; + a0->spriteIndexForEntity2 = 0xFFFF; + a0->unk14 = 0; + a0->unk18 = 0; + a0->spriteAnimationCounter2 = 0; + a0->spriteBaseForDirection = a1->unk4[a2][0]; + a0->spriteGlobalIndex = a0->spriteBaseForDirection; + a0->unk34 = a1->unk0; + a0->unk30 = 0; } \ No newline at end of file From 6a633bad911e331baf7921d84ecd192b97464f17 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Fri, 18 Aug 2023 21:54:31 -0400 Subject: [PATCH 16/27] 99.95% matching for sub_80054BC --- asm/sprite.s | 122 -------------------------------- include/axdata.h | 4 +- include/sprite.h | 1 + ld_script.txt | 1 - src/sprite.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 178 insertions(+), 126 deletions(-) delete mode 100644 asm/sprite.s diff --git a/asm/sprite.s b/asm/sprite.s deleted file mode 100644 index 4d186bd5..00000000 --- a/asm/sprite.s +++ /dev/null @@ -1,122 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start sub_80054BC -sub_80054BC: - push {r4,lr} - adds r4, r0, 0 - ldrh r1, [r4] - movs r0, 0x80 - lsls r0, 6 - ands r0, r1 - cmp r0, 0 - beq _080054D0 - movs r0, 0 - b _080054D2 -_080054D0: - lsrs r0, r1, 15 -_080054D2: - cmp r0, 0 - beq _08005586 - movs r1, 0x20 - ldrsh r0, [r4, r1] - ldrh r3, [r4] - cmp r0, 0 - blt _08005524 - movs r0, 0x80 - lsls r0, 7 - ands r0, r3 - cmp r0, 0 - bne _08005586 - ldrh r2, [r4, 0x6] - movs r0, 0x6 - ldrsh r1, [r4, r0] - ldr r0, _0800550C - cmp r1, r0 - bgt _080054FA - adds r0, r2, 0x1 - strh r0, [r4, 0x6] -_080054FA: - ldrh r1, [r4, 0x4] - movs r2, 0x4 - ldrsh r0, [r4, r2] - cmp r0, 0 - beq _08005510 - subs r0, r1, 0x1 - strh r0, [r4, 0x4] - b _08005586 - .align 2, 0 -_0800550C: .4byte 0x0000752f -_08005510: - ldrh r1, [r4, 0x2] - movs r2, 0x2 - ldrsh r0, [r4, r2] - cmp r0, 0 - beq _08005524 - subs r0, r1, 0x1 - strh r0, [r4, 0x2] - lsls r0, 16 - cmp r0, 0 - bgt _08005586 -_08005524: - ldr r0, [r4, 0x2C] - ldrb r0, [r0] - cmp r0, 0 - bne _08005550 - movs r0, 0x80 - lsls r0, 5 - ands r0, r3 - cmp r0, 0 - bne _08005542 - movs r1, 0x80 - lsls r1, 6 - adds r0, r1, 0 - orrs r0, r3 - strh r0, [r4] - b _08005586 -_08005542: - ldr r0, [r4, 0x28] - str r0, [r4, 0x2C] - bl Rand32Bit - movs r1, 0x1 - ands r0, r1 - strh r0, [r4, 0x4] -_08005550: - ldrh r1, [r4] - movs r2, 0x80 - lsls r2, 4 - adds r0, r2, 0 - orrs r0, r1 - strh r0, [r4] - ldr r1, [r4, 0x2C] - ldrb r0, [r1] - strh r0, [r4, 0x2] - ldrh r0, [r1, 0x2] - strh r0, [r4, 0x20] - ldrh r0, [r1, 0x4] - strh r0, [r4, 0xC] - ldrh r0, [r1, 0x6] - strh r0, [r4, 0xE] - ldrh r0, [r1, 0x8] - strh r0, [r4, 0x10] - ldrh r0, [r1, 0xA] - strh r0, [r4, 0x12] - ldrb r0, [r1, 0x1] - str r0, [r4, 0x14] - ldrb r2, [r1, 0x1] - ldr r0, [r4, 0x18] - orrs r0, r2 - str r0, [r4, 0x18] - adds r1, 0xC - str r1, [r4, 0x2C] -_08005586: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_80054BC - - .align 2, 0 @ Don't pad with nop. diff --git a/include/axdata.h b/include/axdata.h index e6c8d897..e570f0e9 100644 --- a/include/axdata.h +++ b/include/axdata.h @@ -55,8 +55,8 @@ struct ax_anim struct axdata { /* 0x0 */ u16 flags; // 0x8000 - animating, 0x2000 finished? 0x1000 continue - /* 0x2 */ u16 animFrames; // frames left in the current animation frame - /* 0x4 */ u16 animWaitFrames; // frames to not update the animation for + /* 0x2 */ s16 animFrames; // frames left in the current animation frame + /* 0x4 */ s16 animWaitFrames; // frames to not update the animation for /* 0x6 */ s16 totalFrames; // max 30000 /* 0x8 */ struct axdata1 sub1; /* 0x28 */ struct ax_anim *nextAnimData; // next animation data (if flags&0x1000) diff --git a/include/sprite.h b/include/sprite.h index 653bc270..743417a6 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -104,5 +104,6 @@ void sub_8005304(void); void sub_80053AC(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, u32, bool8); void sub_80053D0(struct Entity_Sub28 *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, u32, bool8); void sub_800543C(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, bool8); +void sub_80054BC(struct axPokemon *); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/ld_script.txt b/ld_script.txt index 9c026266..af1e11ba 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -61,7 +61,6 @@ SECTIONS { src/input.o(.text); asm/code_8004AA0.o(.text); src/sprite.o(.text); - asm/sprite.o(.text); asm/code_800558C.o(.text); src/code_800558C_1.o(.text); asm/code_8005838.o(.text); diff --git a/src/sprite.c b/src/sprite.c index db0b4caa..c4d67a00 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1,5 +1,6 @@ #include "global.h" #include "cpu.h" +#include "random.h" #include "sprite.h" extern u16 gUnknown_2025670; @@ -939,4 +940,177 @@ void sub_800545C(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a0->spriteGlobalIndex = a0->spriteBaseForDirection; a0->unk34 = a1->unk0; a0->unk30 = 0; -} \ No newline at end of file +} + +#if NONMATCHING // https://decomp.me/scratch/n4Umb +void sub_80054BC(struct axPokemon *a0) +{ + struct ax_anim *aData; + s32 flag; + + if (a0->axdata.flags & 0x2000) + flag = 0; + else + flag = a0->axdata.flags >> 15; + + flag++; flag--; + + if (flag == 0) + return; + + if (a0->axdata.sub1.poseId >= 0) { + if (a0->axdata.flags & 0x4000) + return; + + if (a0->axdata.totalFrames < 30000) + a0->axdata.totalFrames++; + + if (a0->axdata.animWaitFrames != 0) { + a0->axdata.animWaitFrames--; + return; + } + + if (a0->axdata.animFrames != 0 && --a0->axdata.animFrames > 0) + return; + } + + if (a0->axdata.activeAnimData->frames == 0) { + if (!(a0->axdata.flags & 0x1000)) { + a0->axdata.flags |= 0x2000; + return; + } + + a0->axdata.activeAnimData = a0->axdata.nextAnimData; + a0->axdata.animWaitFrames = Rand32Bit() & 1; + } + + a0->axdata.flags |= 0x800; + + aData = a0->axdata.activeAnimData; + a0->axdata.animFrames = aData->frames; + a0->axdata.sub1.poseId = aData->poseId; + a0->axdata.sub1.xOffset = aData->xOffset; + a0->axdata.sub1.yOffset = aData->yOffset; + a0->axdata.sub1.xShadow = aData->xShadow; + a0->axdata.sub1.yShadow = aData->yShadow; + a0->axdata.sub1.unkC = aData->unkFlags; + a0->axdata.sub1.unk10 |= aData->unkFlags; + a0->axdata.activeAnimData = aData + 1; +} +#else +NAKED +void sub_80054BC(struct axPokemon *a0) +{ + asm_unified( + "push {r4,lr}\n" + "\tadds r4, r0, 0\n" + "\tldrh r1, [r4]\n" + "\tmovs r0, 0x80\n" + "\tlsls r0, 6\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _080054D0\n" + "\tmovs r0, 0\n" + "\tb _080054D2\n" +"_080054D0:\n" + "\tlsrs r0, r1, 15\n" +"_080054D2:\n" + "\tcmp r0, 0\n" + "\tbeq _08005586\n" + "\tmovs r1, 0x20\n" + "\tldrsh r0, [r4, r1]\n" + "\tldrh r3, [r4]\n" + "\tcmp r0, 0\n" + "\tblt _08005524\n" + "\tmovs r0, 0x80\n" + "\tlsls r0, 7\n" + "\tands r0, r3\n" + "\tcmp r0, 0\n" + "\tbne _08005586\n" + "\tldrh r2, [r4, 0x6]\n" + "\tmovs r0, 0x6\n" + "\tldrsh r1, [r4, r0]\n" + "\tldr r0, _0800550C\n" + "\tcmp r1, r0\n" + "\tbgt _080054FA\n" + "\tadds r0, r2, 0x1\n" + "\tstrh r0, [r4, 0x6]\n" +"_080054FA:\n" + "\tldrh r1, [r4, 0x4]\n" + "\tmovs r2, 0x4\n" + "\tldrsh r0, [r4, r2]\n" + "\tcmp r0, 0\n" + "\tbeq _08005510\n" + "\tsubs r0, r1, 0x1\n" + "\tstrh r0, [r4, 0x4]\n" + "\tb _08005586\n" + "\t.align 2, 0\n" +"_0800550C: .4byte 0x0000752f\n" +"_08005510:\n" + "\tldrh r1, [r4, 0x2]\n" + "\tmovs r2, 0x2\n" + "\tldrsh r0, [r4, r2]\n" + "\tcmp r0, 0\n" + "\tbeq _08005524\n" + "\tsubs r0, r1, 0x1\n" + "\tstrh r0, [r4, 0x2]\n" + "\tlsls r0, 16\n" + "\tcmp r0, 0\n" + "\tbgt _08005586\n" +"_08005524:\n" + "\tldr r0, [r4, 0x2C]\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0\n" + "\tbne _08005550\n" + "\tmovs r0, 0x80\n" + "\tlsls r0, 5\n" + "\tands r0, r3\n" + "\tcmp r0, 0\n" + "\tbne _08005542\n" + "\tmovs r1, 0x80\n" + "\tlsls r1, 6\n" + "\tadds r0, r1, 0\n" + "\torrs r0, r3\n" + "\tstrh r0, [r4]\n" + "\tb _08005586\n" +"_08005542:\n" + "\tldr r0, [r4, 0x28]\n" + "\tstr r0, [r4, 0x2C]\n" + "\tbl Rand32Bit\n" + "\tmovs r1, 0x1\n" + "\tands r0, r1\n" + "\tstrh r0, [r4, 0x4]\n" +"_08005550:\n" + "\tldrh r1, [r4]\n" + "\tmovs r2, 0x80\n" + "\tlsls r2, 4\n" + "\tadds r0, r2, 0\n" + "\torrs r0, r1\n" + "\tstrh r0, [r4]\n" + "\tldr r1, [r4, 0x2C]\n" + "\tldrb r0, [r1]\n" + "\tstrh r0, [r4, 0x2]\n" + "\tldrh r0, [r1, 0x2]\n" + "\tstrh r0, [r4, 0x20]\n" + "\tldrh r0, [r1, 0x4]\n" + "\tstrh r0, [r4, 0xC]\n" + "\tldrh r0, [r1, 0x6]\n" + "\tstrh r0, [r4, 0xE]\n" + "\tldrh r0, [r1, 0x8]\n" + "\tstrh r0, [r4, 0x10]\n" + "\tldrh r0, [r1, 0xA]\n" + "\tstrh r0, [r4, 0x12]\n" + "\tldrb r0, [r1, 0x1]\n" + "\tstr r0, [r4, 0x14]\n" + "\tldrb r2, [r1, 0x1]\n" + "\tldr r0, [r4, 0x18]\n" + "\torrs r0, r2\n" + "\tstr r0, [r4, 0x18]\n" + "\tadds r1, 0xC\n" + "\tstr r1, [r4, 0x2C]\n" +"_08005586:\n" + "\tpop {r4}\n" + "\tpop {r0}\n" + "\tbx r0"); +} +#endif // NONMATCHING \ No newline at end of file From 0225356d5995c043ff9aee4756553294d46f14cf Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sat, 19 Aug 2023 01:57:56 -0400 Subject: [PATCH 17/27] 99.09% matching for sub_807CB3C --- asm/code_807CABC.s | 266 ------------------------ include/dungeon_ai_attack.h | 1 + ld_script.txt | 1 - src/code_805A120.c | 4 +- src/code_8077274_1.c | 4 +- src/code_807CD9C.c | 6 +- src/dungeon_ai_attack.c | 397 ++++++++++++++++++++++++++++++++++-- 7 files changed, 389 insertions(+), 290 deletions(-) delete mode 100644 asm/code_807CABC.s diff --git a/asm/code_807CABC.s b/asm/code_807CABC.s deleted file mode 100644 index d97abc6c..00000000 --- a/asm/code_807CABC.s +++ /dev/null @@ -1,266 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start sub_807CB3C -sub_807CB3C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x30 - adds r6, r0, 0 - ldr r7, [r6, 0x70] - movs r1, 0 - movs r2, 0x15 - bl sub_8044D90 - adds r2, r0, 0 - ldr r5, [r2] - ldrb r1, [r2] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _0807CB80 - ldr r0, _0807CB78 - adds r1, r2, 0 - bl sub_8045BF8 - ldr r0, _0807CB7C - ldr r1, [r0] - adds r0, r6, 0 - bl SendMessage - b _0807CD54 - .align 2, 0 -_0807CB78: .4byte gUnknown_202DE58 -_0807CB7C: .4byte gUnknown_80FE3E8 -_0807CB80: - add r0, sp, 0x8 - adds r1, r7, 0 - adds r1, 0x44 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - bl IsBossFight - lsls r0, 24 - cmp r0, 0 - beq _0807CBAC - ldr r0, _0807CBA8 - ldr r1, [r0] - adds r0, r6, 0 - bl SendMessage - movs r4, 0x1 - b _0807CCDE - .align 2, 0 -_0807CBA8: .4byte gPtrMysteriousPowerPreventedUseMessage -_0807CBAC: - movs r0, 0x1 - mov r8, r0 - add r4, sp, 0x20 - lsls r5, 8 - lsrs r0, r5, 24 - bl GetItemMoveID - adds r1, r0, 0 - lsls r1, 16 - lsrs r1, 16 - adds r0, r4, 0 - bl InitPokemonMove - ldrb r0, [r7, 0x7] - mov r10, r4 - mov r9, r5 - cmp r0, 0 - bne _0807CC08 - ldr r1, _0807CC20 - ldr r0, [sp, 0x28] - ands r0, r1 - mov r1, r8 - orrs r0, r1 - str r0, [sp, 0x28] - movs r0, 0xA - add r4, sp, 0x28 - str r0, [r4, 0x4] - movs r3, 0x8C - lsls r3, 1 - adds r2, r7, r3 - adds r0, r4, 0 - adds r1, r6, 0 - bl AIConsiderMove - ldrb r0, [r4] - cmp r0, 0 - beq _0807CC08 - ldrb r1, [r4, 0x1] - movs r0, 0x7 - ands r0, r1 - adds r1, r7, 0 - adds r1, 0x46 - strb r0, [r1] - adds r0, r6, 0 - bl TargetTileInFront -_0807CC08: - adds r0, r7, 0 - adds r0, 0xBC - ldrb r0, [r0] - cmp r0, 0x1 - bne _0807CC2C - ldr r0, _0807CC24 - adds r1, r6, 0 - movs r2, 0 - bl SetMessageArgument - ldr r0, _0807CC28 - b _0807CC3C - .align 2, 0 -_0807CC20: .4byte 0xffffff00 -_0807CC24: .4byte gAvailablePokemonNames -_0807CC28: .4byte gUnknown_80FC714 -_0807CC2C: - cmp r0, 0x7 - bne _0807CC50 - ldr r0, _0807CC48 - adds r1, r6, 0 - movs r2, 0 - bl SetMessageArgument - ldr r0, _0807CC4C -_0807CC3C: - ldr r1, [r0] - adds r0, r6, 0 - bl SendMessage - b _0807CCDC - .align 2, 0 -_0807CC48: .4byte gAvailablePokemonNames -_0807CC4C: .4byte gUnknown_80FC718 -_0807CC50: - adds r0, r7, 0 - adds r0, 0xAC - ldrb r0, [r0] - cmp r0, 0x4 - bne _0807CC72 - ldr r0, _0807CCB8 - adds r1, r6, 0 - movs r2, 0 - bl SetMessageArgument - ldr r0, _0807CCBC - ldr r1, [r0] - adds r0, r6, 0 - bl SendMessage - movs r4, 0 - mov r8, r4 -_0807CC72: - mov r0, r8 - cmp r0, 0 - beq _0807CCDC - mov r5, r9 - lsrs r0, r5, 24 - cmp r0, 0xB6 - beq _0807CC84 - cmp r0, 0xBF - bne _0807CCC0 -_0807CC84: - adds r0, r6, 0 - movs r1, 0 - movs r2, 0x7A - bl sub_8044DF0 - mov r2, r10 - ldrb r1, [r2] - movs r0, 0x8 - movs r4, 0 - orrs r0, r1 - add r3, sp, 0x20 - movs r1, 0x4 - orrs r0, r1 - strb r0, [r3] - movs r0, 0xA - strb r0, [r3, 0x4] - lsrs r2, r5, 24 - str r4, [sp] - str r3, [sp, 0x4] - adds r0, r6, 0 - movs r1, 0 - movs r3, 0 - bl sub_8055FA0 - b _0807CCDE - .align 2, 0 -_0807CCB8: .4byte gAvailablePokemonNames -_0807CCBC: .4byte gUnknown_80FC6A8 -_0807CCC0: - mov r3, r9 - lsrs r2, r3, 24 - movs r0, 0 - str r0, [sp] - mov r4, r10 - str r4, [sp, 0x4] - adds r0, r6, 0 - movs r1, 0 - movs r3, 0 - bl sub_8055FA0 - lsls r0, 24 - lsrs r4, r0, 24 - b _0807CCDE -_0807CCDC: - movs r4, 0 -_0807CCDE: - adds r0, r6, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _0807CD38 - cmp r4, 0 - beq _0807CCF8 - adds r0, r6, 0 - movs r1, 0 - movs r2, 0x7A - bl sub_8044DF0 -_0807CCF8: - adds r0, r6, 0 - bl sub_8071DA4 - adds r0, r6, 0 - movs r1, 0x8 - bl sub_806CE68 - ldrb r0, [r7, 0x7] - cmp r0, 0 - beq _0807CD18 - adds r0, r6, 0x4 - bl sub_804AC20 - movs r0, 0 - bl sub_807EC28 -_0807CD18: - adds r0, r6, 0 - bl sub_806A5B8 - ldr r0, _0807CD30 - ldr r0, [r0] - ldr r1, _0807CD34 - adds r0, r1 - ldrb r1, [r0] - adds r0, r6, 0 - bl sub_8075900 - b _0807CD44 - .align 2, 0 -_0807CD30: .4byte gDungeon -_0807CD34: .4byte 0x00003a08 -_0807CD38: - cmp r4, 0 - beq _0807CD44 - add r0, sp, 0x8 - movs r1, 0 - bl sub_8044D40 -_0807CD44: - bl sub_8044B28 - lsls r0, 24 - cmp r0, 0 - bne _0807CD54 - adds r0, r6, 0 - bl sub_806A1B0 -_0807CD54: - add sp, 0x30 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_807CB3C - - .align 2, 0 diff --git a/include/dungeon_ai_attack.h b/include/dungeon_ai_attack.h index c867b253..4f9795ce 100644 --- a/include/dungeon_ai_attack.h +++ b/include/dungeon_ai_attack.h @@ -5,6 +5,7 @@ #define RANGED_ATTACK_RANGE 10 +// size: 0x8 struct AIPossibleMove { bool8 canBeUsed; diff --git a/ld_script.txt b/ld_script.txt index af1e11ba..fdfaaa1a 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -233,7 +233,6 @@ SECTIONS { asm/code_8077274_1.o(.text); src/dungeon_ai_movement.o(.text); src/dungeon_ai_attack.o(.text); - asm/code_807CABC.o(.text); src/targeting_flags.o(.text); asm/code_807CD9C.o(.text); src/code_807CD9C.o(.text); diff --git a/src/code_805A120.c b/src/code_805A120.c index 7bec68cf..d1f8fbb9 100644 --- a/src/code_805A120.c +++ b/src/code_805A120.c @@ -102,7 +102,7 @@ extern u8 sub_8044B28(void); extern u8 sub_803F428(struct Position *pos); extern void IncreaseEntityPixelPos(struct Entity *, u32, u32); extern void sub_803E46C(u32); -extern void sub_807EC28(u32); +extern void sub_807EC28(bool8); extern void sub_806F370(struct Entity *r0, struct Entity *r1, u32, u32, u8 *, u8, s32, u32, u32, u32); void sub_8075900(struct Entity *pokemon, u8 r1); extern void sub_804535C(struct Entity *, u32); @@ -1219,7 +1219,7 @@ _0805AA5E: } if (target->info->isTeamLeader) { sub_804AC20(r9); - sub_807EC28(0); + sub_807EC28(FALSE); } sub_806A5B8(target); sub_8075900(target,gDungeon->unk3A08); diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index fa2340e4..b11ff5d2 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -172,7 +172,7 @@ extern void SetMessageArgument(u8 *buffer, struct Entity *r1, u32); extern void sub_80522F4(struct Entity *pokemon, struct Entity *r1, const char[]); extern void EntityUpdateStatusSprites(struct Entity *); extern void sub_8042A74(struct Entity *r0); -extern void sub_807EC28(u32); +extern void sub_807EC28(bool8); extern s32 sub_8069F54(struct Entity *param_1, s16 param_2); extern void sub_806A898(struct Entity *, u32, u32); extern void HealTargetHP(struct Entity *pokemon, struct Entity *r1, s16, s16, u32); @@ -1515,7 +1515,7 @@ void SendTransformEndMessage(struct Entity * pokemon, struct Entity *target) entityInfo->transformStatus = STATUS_NONE; EntityUpdateStatusSprites(target); if (isInvisible) { - sub_807EC28(1); + sub_807EC28(TRUE); } } diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 2e94e2fe..28f1e994 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -24,7 +24,7 @@ extern void sub_806F370(struct Entity *r0, struct Entity *r1, u32, u32, u8 *, u8 extern void sub_80694C0(struct Entity *, s32, s32, u32); extern void sub_804535C(struct Entity *, u32); extern void sub_804AC20(struct Position *); -extern void sub_807EC28(u32); +extern void sub_807EC28(bool8); extern void sub_806A5B8(struct Entity *); extern u32 gUnknown_80F5FAC[]; @@ -101,7 +101,7 @@ void sub_807E254(struct Entity *pokemon,struct Entity *target) if (EntityExists(pokemon)) { if (pokemon->info->isTeamLeader) { sub_804AC20(&pokemon->pos); - sub_807EC28(0); + sub_807EC28(FALSE); } sub_806A5B8(pokemon); sub_8075900(pokemon,gDungeon->unk3A08); @@ -110,7 +110,7 @@ void sub_807E254(struct Entity *pokemon,struct Entity *target) if (EntityExists(target)) { if (target->info->isTeamLeader) { sub_804AC20(&target->pos); - sub_807EC28(0); + sub_807EC28(FALSE); } sub_806A5B8(target); sub_8075900(target,gDungeon->unk3A08); diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 3af5f4c5..9a275baa 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -45,7 +45,8 @@ extern void sub_806A9B4(struct Entity *, u8); extern bool8 sub_8044B28(void); extern void sub_8057588(struct Entity *, u32); extern void sub_806A1B0(struct Entity *); - +extern struct Item *sub_8044D90(struct Entity *, s32, u32); +extern bool8 sub_8044D40(struct ActionContainer *, u32); void DecideAttack(struct Entity *pokemon) { @@ -932,23 +933,387 @@ bool8 IsTargetInRange(struct Entity *pokemon, struct Entity *targetPokemon, s32 void sub_807CABC(struct Entity *target) { - struct EntityInfo *entityInfo; - s32 counter; + struct EntityInfo *entityInfo; + s32 counter; - counter = 0; - while (1) { - if(counter >= sub_8070828(target, TRUE)) break; + counter = 0; + while (TRUE) { + if (counter >= sub_8070828(target, TRUE)) + break; entityInfo = target->info; - sub_8055A00(target,(entityInfo->action).actionUseIndex,1,0,0); - if(!EntityExists(target)) break; - if(sub_8044B28()) break; - if(entityInfo->unk159) break; + sub_8055A00(target, entityInfo->action.actionUseIndex, 1, 0, 0); + if (!EntityExists(target)) + break; + if (sub_8044B28()) + break; + if (entityInfo->unk159) + break; counter++; - } + } - sub_8057588(target,1); - if (EntityExists(target)) { - sub_806A9B4(target,(target->info->action).actionUseIndex); - } - sub_806A1B0(target); + sub_8057588(target, 1); + if (EntityExists(target)) + sub_806A9B4(target, target->info->action.actionUseIndex); + + sub_806A1B0(target); } + +#if NONMATCHING // 99.09% https://decomp.me/scratch/rpwXh +void sub_807CB3C(struct Entity *pokemon) +{ + bool8 r4; + struct Item *item; + struct Item IVar5; + struct EntityInfo *entityInfo; // r7 + struct ActionContainer act; + struct Move move; + struct AIPossibleMove sp28; + bool8 r8; + + entityInfo = pokemon->info; + item = sub_8044D90(pokemon, 0, 21); + IVar5 = *item; + + if (item->flags & ITEM_FLAG_STICKY) { + sub_8045BF8(gUnknown_202DE58, item); + SendMessage(pokemon, *gUnknown_80FE3E8); + return; + } + + act = entityInfo->action; + + if (IsBossFight()) { + SendMessage(pokemon, *gPtrMysteriousPowerPreventedUseMessage); + r4 = TRUE; + } + else { + r8 = TRUE; + InitPokemonMove(&move, GetItemMoveID(IVar5.id)); + + if (!entityInfo->isTeamLeader) { + sp28.canBeUsed = r8; + sp28.weight = 10; + AIConsiderMove(&sp28, pokemon, entityInfo->moves); + + if (sp28.canBeUsed) { + entityInfo->action.direction = sp28.direction & 7; + TargetTileInFront(pokemon); + } + } + + if (entityInfo->volatileStatus == 1) { + SetMessageArgument(gAvailablePokemonNames, pokemon, 0); + SendMessage(pokemon, *gUnknown_80FC714); + r4 = FALSE; + } + else if (entityInfo->volatileStatus == 7) { + SetMessageArgument(gAvailablePokemonNames, pokemon, 0); + SendMessage(pokemon, *gUnknown_80FC718); + r4 = FALSE; + } + else { + if (entityInfo->nonVolatileStatus == 4) { + SetMessageArgument(gAvailablePokemonNames, pokemon, 0); + SendMessage(pokemon, *gUnknown_80FC6A8); + r4 = FALSE; + r8 = FALSE; + } + if (r8) { + if ((IVar5.id == ITEM_SWITCHER_ORB) || (IVar5.id == ITEM_POUNCE_ORB)) { + sub_8044DF0(pokemon, 0, 122); + move.moveFlags |= MOVE_FLAG_SET; + move.moveFlags |= MOVE_FLAG_ENABLED_FOR_AI; + move.PP = 10; + sub_8055FA0(pokemon, 0, IVar5.id, 0, 0, &move); + r4 = FALSE; + } + else + r4 = sub_8055FA0(pokemon, 0, IVar5.id, 0, 0, &move); + } + else + r4 = FALSE; + } + } + + if (EntityExists(pokemon)) { + if (r4) + sub_8044DF0(pokemon, 0, 122); + + sub_8071DA4(pokemon); + sub_806CE68(pokemon, 8); + + if (entityInfo->isTeamLeader) { + sub_804AC20(&pokemon->pos); + sub_807EC28(FALSE); + } + + sub_806A5B8(pokemon); + sub_8075900(pokemon, gDungeon->unk3A08); + } + else if (r4) + sub_8044D40(&act, 0); + + if (!sub_8044B28()) + sub_806A1B0(pokemon); +} +#else +NAKED +void sub_807CB3C(struct Entity *pokemon) +{ + asm_unified( + "push {r4-r7,lr}\n" + "\tmov r7, r10\n" + "\tmov r6, r9\n" + "\tmov r5, r8\n" + "\tpush {r5-r7}\n" + "\tsub sp, 0x30\n" + "\tadds r6, r0, 0\n" + "\tldr r7, [r6, 0x70]\n" + "\tmovs r1, 0\n" + "\tmovs r2, 0x15\n" + "\tbl sub_8044D90\n" + "\tadds r2, r0, 0\n" + "\tldr r5, [r2]\n" + "\tldrb r1, [r2]\n" + "\tmovs r0, 0x8\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbeq _0807CB80\n" + "\tldr r0, _0807CB78\n" + "\tadds r1, r2, 0\n" + "\tbl sub_8045BF8\n" + "\tldr r0, _0807CB7C\n" + "\tldr r1, [r0]\n" + "\tadds r0, r6, 0\n" + "\tbl SendMessage\n" + "\tb _0807CD54\n" + "\t.align 2, 0\n" +"_0807CB78: .4byte gUnknown_202DE58\n" +"_0807CB7C: .4byte gUnknown_80FE3E8\n" +"_0807CB80:\n" + "\tadd r0, sp, 0x8\n" + "\tadds r1, r7, 0\n" + "\tadds r1, 0x44\n" + "\tldm r1!, {r2-r4}\n" + "\tstm r0!, {r2-r4}\n" + "\tldm r1!, {r2-r4}\n" + "\tstm r0!, {r2-r4}\n" + "\tbl IsBossFight\n" + "\tlsls r0, 24\n" + "\tcmp r0, 0\n" + "\tbeq _0807CBAC\n" + "\tldr r0, _0807CBA8\n" + "\tldr r1, [r0]\n" + "\tadds r0, r6, 0\n" + "\tbl SendMessage\n" + "\tmovs r4, 0x1\n" + "\tb _0807CCDE\n" + "\t.align 2, 0\n" +"_0807CBA8: .4byte gPtrMysteriousPowerPreventedUseMessage\n" +"_0807CBAC:\n" + "\tmovs r0, 0x1\n" + "\tmov r8, r0\n" + "\tadd r4, sp, 0x20\n" + "\tlsls r5, 8\n" + "\tlsrs r0, r5, 24\n" + "\tbl GetItemMoveID\n" + "\tadds r1, r0, 0\n" + "\tlsls r1, 16\n" + "\tlsrs r1, 16\n" + "\tadds r0, r4, 0\n" + "\tbl InitPokemonMove\n" + "\tldrb r0, [r7, 0x7]\n" + "\tmov r10, r4\n" + "\tmov r9, r5\n" + "\tcmp r0, 0\n" + "\tbne _0807CC08\n" + "\tldr r1, _0807CC20\n" + "\tldr r0, [sp, 0x28]\n" + "\tands r0, r1\n" + "\tmov r1, r8\n" + "\torrs r0, r1\n" + "\tstr r0, [sp, 0x28]\n" + "\tmovs r0, 0xA\n" + "\tadd r4, sp, 0x28\n" + "\tstr r0, [r4, 0x4]\n" + "\tmovs r3, 0x8C\n" + "\tlsls r3, 1\n" + "\tadds r2, r7, r3\n" + "\tadds r0, r4, 0\n" + "\tadds r1, r6, 0\n" + "\tbl AIConsiderMove\n" + "\tldrb r0, [r4]\n" + "\tcmp r0, 0\n" + "\tbeq _0807CC08\n" + "\tldrb r1, [r4, 0x1]\n" + "\tmovs r0, 0x7\n" + "\tands r0, r1\n" + "\tadds r1, r7, 0\n" + "\tadds r1, 0x46\n" + "\tstrb r0, [r1]\n" + "\tadds r0, r6, 0\n" + "\tbl TargetTileInFront\n" +"_0807CC08:\n" + "\tadds r0, r7, 0\n" + "\tadds r0, 0xBC\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0x1\n" + "\tbne _0807CC2C\n" + "\tldr r0, _0807CC24\n" + "\tadds r1, r6, 0\n" + "\tmovs r2, 0\n" + "\tbl SetMessageArgument\n" + "\tldr r0, _0807CC28\n" + "\tb _0807CC3C\n" + "\t.align 2, 0\n" +"_0807CC20: .4byte 0xffffff00\n" +"_0807CC24: .4byte gAvailablePokemonNames\n" +"_0807CC28: .4byte gUnknown_80FC714\n" +"_0807CC2C:\n" + "\tcmp r0, 0x7\n" + "\tbne _0807CC50\n" + "\tldr r0, _0807CC48\n" + "\tadds r1, r6, 0\n" + "\tmovs r2, 0\n" + "\tbl SetMessageArgument\n" + "\tldr r0, _0807CC4C\n" +"_0807CC3C:\n" + "\tldr r1, [r0]\n" + "\tadds r0, r6, 0\n" + "\tbl SendMessage\n" + "\tb _0807CCDC\n" + "\t.align 2, 0\n" +"_0807CC48: .4byte gAvailablePokemonNames\n" +"_0807CC4C: .4byte gUnknown_80FC718\n" +"_0807CC50:\n" + "\tadds r0, r7, 0\n" + "\tadds r0, 0xAC\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0x4\n" + "\tbne _0807CC72\n" + "\tldr r0, _0807CCB8\n" + "\tadds r1, r6, 0\n" + "\tmovs r2, 0\n" + "\tbl SetMessageArgument\n" + "\tldr r0, _0807CCBC\n" + "\tldr r1, [r0]\n" + "\tadds r0, r6, 0\n" + "\tbl SendMessage\n" + "\tmovs r4, 0\n" + "\tmov r8, r4\n" +"_0807CC72:\n" + "\tmov r0, r8\n" + "\tcmp r0, 0\n" + "\tbeq _0807CCDC\n" + "\tmov r5, r9\n" + "\tlsrs r0, r5, 24\n" + "\tcmp r0, 0xB6\n" + "\tbeq _0807CC84\n" + "\tcmp r0, 0xBF\n" + "\tbne _0807CCC0\n" +"_0807CC84:\n" + "\tadds r0, r6, 0\n" + "\tmovs r1, 0\n" + "\tmovs r2, 0x7A\n" + "\tbl sub_8044DF0\n" + "\tmov r2, r10\n" + "\tldrb r1, [r2]\n" + "\tmovs r0, 0x8\n" + "\tmovs r4, 0\n" + "\torrs r0, r1\n" + "\tadd r3, sp, 0x20\n" + "\tmovs r1, 0x4\n" + "\torrs r0, r1\n" + "\tstrb r0, [r3]\n" + "\tmovs r0, 0xA\n" + "\tstrb r0, [r3, 0x4]\n" + "\tlsrs r2, r5, 24\n" + "\tstr r4, [sp]\n" + "\tstr r3, [sp, 0x4]\n" + "\tadds r0, r6, 0\n" + "\tmovs r1, 0\n" + "\tmovs r3, 0\n" + "\tbl sub_8055FA0\n" + "\tb _0807CCDE\n" + "\t.align 2, 0\n" +"_0807CCB8: .4byte gAvailablePokemonNames\n" +"_0807CCBC: .4byte gUnknown_80FC6A8\n" +"_0807CCC0:\n" + "\tmov r3, r9\n" + "\tlsrs r2, r3, 24\n" + "\tmovs r0, 0\n" + "\tstr r0, [sp]\n" + "\tmov r4, r10\n" + "\tstr r4, [sp, 0x4]\n" + "\tadds r0, r6, 0\n" + "\tmovs r1, 0\n" + "\tmovs r3, 0\n" + "\tbl sub_8055FA0\n" + "\tlsls r0, 24\n" + "\tlsrs r4, r0, 24\n" + "\tb _0807CCDE\n" +"_0807CCDC:\n" + "\tmovs r4, 0\n" +"_0807CCDE:\n" + "\tadds r0, r6, 0\n" + "\tbl EntityExists\n" + "\tlsls r0, 24\n" + "\tcmp r0, 0\n" + "\tbeq _0807CD38\n" + "\tcmp r4, 0\n" + "\tbeq _0807CCF8\n" + "\tadds r0, r6, 0\n" + "\tmovs r1, 0\n" + "\tmovs r2, 0x7A\n" + "\tbl sub_8044DF0\n" +"_0807CCF8:\n" + "\tadds r0, r6, 0\n" + "\tbl sub_8071DA4\n" + "\tadds r0, r6, 0\n" + "\tmovs r1, 0x8\n" + "\tbl sub_806CE68\n" + "\tldrb r0, [r7, 0x7]\n" + "\tcmp r0, 0\n" + "\tbeq _0807CD18\n" + "\tadds r0, r6, 0x4\n" + "\tbl sub_804AC20\n" + "\tmovs r0, 0\n" + "\tbl sub_807EC28\n" +"_0807CD18:\n" + "\tadds r0, r6, 0\n" + "\tbl sub_806A5B8\n" + "\tldr r0, _0807CD30\n" + "\tldr r0, [r0]\n" + "\tldr r1, _0807CD34\n" + "\tadds r0, r1\n" + "\tldrb r1, [r0]\n" + "\tadds r0, r6, 0\n" + "\tbl sub_8075900\n" + "\tb _0807CD44\n" + "\t.align 2, 0\n" +"_0807CD30: .4byte gDungeon\n" +"_0807CD34: .4byte 0x00003a08\n" +"_0807CD38:\n" + "\tcmp r4, 0\n" + "\tbeq _0807CD44\n" + "\tadd r0, sp, 0x8\n" + "\tmovs r1, 0\n" + "\tbl sub_8044D40\n" +"_0807CD44:\n" + "\tbl sub_8044B28\n" + "\tlsls r0, 24\n" + "\tcmp r0, 0\n" + "\tbne _0807CD54\n" + "\tadds r0, r6, 0\n" + "\tbl sub_806A1B0\n" +"_0807CD54:\n" + "\tadd sp, 0x30\n" + "\tpop {r3-r5}\n" + "\tmov r8, r3\n" + "\tmov r9, r4\n" + "\tmov r10, r5\n" + "\tpop {r4-r7}\n" + "\tpop {r0}\n" + "\tbx r0"); +} +#endif // NONMATCHING \ No newline at end of file From 1d49c480eb139e3fbeee88d4957edcf48abbf8fe Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sat, 26 Aug 2023 10:29:55 -0400 Subject: [PATCH 18/27] Rename and doc SpriteOAM with defines --- data/data_8107010.s | 7 ++- include/rescue_password_menu.h | 2 +- include/sprite.h | 17 ++----- include/sprite_oam.h | 92 ++++++++++++++++++++++++++++++++++ src/other_menus.c | 76 ++++++++++++++++------------ src/pokemon_3.c | 39 +++++++------- src/rescue_password_menu.c | 81 ++++++++++++++++-------------- src/save_menu.c | 68 ++++++++++++++----------- src/sprite.c | 79 ++++++++++++++--------------- src/unk_menu_203B360.c | 61 ++++++++++++---------- 10 files changed, 318 insertions(+), 204 deletions(-) create mode 100644 include/sprite_oam.h diff --git a/data/data_8107010.s b/data/data_8107010.s index 3ddbd98e..0cd739de 100644 --- a/data/data_8107010.s +++ b/data/data_8107010.s @@ -292,7 +292,12 @@ gUnknown_81076BC: @ 81076BC .global gUnknown_81076C4 gUnknown_81076C4: @ 81076C4 -.byte 0xfc, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff +.4byte -4 +.4byte -8 +.4byte -16 +.4byte -4 +.4byte -8 +.4byte -16 .string "pksdir0\0" .global gIQSkillGroups diff --git a/include/rescue_password_menu.h b/include/rescue_password_menu.h index e4ce551d..d2f84f9a 100644 --- a/include/rescue_password_menu.h +++ b/include/rescue_password_menu.h @@ -14,7 +14,7 @@ struct RescuePasswordMenu struct MenuStruct unk8[4]; struct UnkTextStruct2 unk148[4]; struct UnkTextStruct2 unk1A8[4]; - struct unkSprite unk208; + struct SpriteOAM unk208; u32 unk210; }; diff --git a/include/sprite.h b/include/sprite.h index 743417a6..4ade0135 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -4,24 +4,13 @@ #include "axdata.h" #include "ground_sprite.h" #include "position.h" - -// size: 0x8 -struct unkSprite -{ - // y/affineMode/objMode/mosaic/bpp/shape - u16 unk0; - // x/matrixNum/size - u16 unk2; - // tileNum/priority/paletteNum - u16 unk4; - u16 unk6; -}; +#include "sprite_oam.h" // size: 0x8 struct UnkSpriteLink { struct UnkSpriteLink *unk0; - struct unkSprite *unk4; + struct SpriteOAM *unk4; }; // size: 0x808 @@ -92,7 +81,7 @@ struct Dungeon_Sub17B44 struct Dungeon_Sub17B44_Sub4 *unk4; }; -void AddSprite(struct unkSprite *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); +void AddSprite(struct SpriteOAM *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); void BlinkSavingIcon(void); void CopySpritesToOam(void); void InitSprites(void); diff --git a/include/sprite_oam.h b/include/sprite_oam.h new file mode 100644 index 00000000..ea0d66e7 --- /dev/null +++ b/include/sprite_oam.h @@ -0,0 +1,92 @@ +#ifndef GUARD_SPRITE_OAM_H +#define GUARD_SPRITE_OAM_H + +// size: 0x8. Similar to struct OamData but unk6 is not copied to OAM +struct SpriteOAM +{ + // y:8 affineMode1:1 affineMode2:1 objMode:2 mosaic:1 bpp:1 shape:2 + /* 0x0 */ u16 atrib1; + // x:9 matrixNum:5 size:2 + /* 0x2 */ u16 atrib2; + // tileNum:10 priority:2 paletteNum:4 + /* 0x4 */ u16 atrib3; + // unk6_0:1 unk6_1:1 unk6_2:2? unk6_4:12 + u16 unk6; +}; + +// The SpriteOAM struct is handled with macros most likely. +// Most funcs that deal with it look the same and do some weird bit manipulations one by one on the attributes. + +// atrib1 + +#define SPRITEOAM_MAX_Y 0xFF +#define SPRITEOAM_SHIFT_Y 0 +#define SPRITEOAM_MASK_Y (SPRITEOAM_MAX_Y << SPRITEOAM_SHIFT_Y) + +#define SPRITEOAM_MAX_AFFINEMODE1 1 +#define SPRITEOAM_SHIFT_AFFINEMODE1 8 +#define SPRITEOAM_MASK_AFFINEMODE1 (SPRITEOAM_MAX_AFFINEMODE1 << SPRITEOAM_SHIFT_AFFINEMODE1) + +#define SPRITEOAM_MAX_AFFINEMODE2 1 +#define SPRITEOAM_SHIFT_AFFINEMODE2 9 +#define SPRITEOAM_MASK_AFFINEMODE2 (SPRITEOAM_MAX_AFFINEMODE2 << SPRITEOAM_SHIFT_AFFINEMODE2) + +#define SPRITEOAM_MAX_OBJMODE 3 +#define SPRITEOAM_SHIFT_OBJMODE 10 +#define SPRITEOAM_MASK_OBJMODE (SPRITEOAM_MAX_OBJMODE << SPRITEOAM_SHIFT_OBJMODE) + +#define SPRITEOAM_MAX_MOSAIC 1 +#define SPRITEOAM_SHIFT_MOSAIC 12 +#define SPRITEOAM_MASK_MOSAIC (SPRITEOAM_MAX_MOSAIC << SPRITEOAM_SHIFT_MOSAIC) + +#define SPRITEOAM_MAX_BPP 1 +#define SPRITEOAM_SHIFT_BPP 13 +#define SPRITEOAM_MASK_BPP (SPRITEOAM_MAX_BPP << SPRITEOAM_SHIFT_BPP) + +#define SPRITEOAM_MAX_SHAPE 3 +#define SPRITEOAM_SHIFT_SHAPE 14 +#define SPRITEOAM_MASK_SHAPE (SPRITEOAM_MAX_SHAPE << SPRITEOAM_SHIFT_SHAPE) + +// atrib2 + +#define SPRITEOAM_MAX_X 0x1FF +#define SPRITEOAM_SHIFT_X 0 +#define SPRITEOAM_MASK_X (SPRITEOAM_MAX_X << SPRITEOAM_SHIFT_X) + +#define SPRITEOAM_MAX_MATRIXNUM 0x1F +#define SPRITEOAM_SHIFT_MATRIXNUM 9 +#define SPRITEOAM_MASK_MATRIXNUM (SPRITEOAM_MAX_MATRIXNUM << SPRITEOAM_SHIFT_MATRIXNUM) + +#define SPRITEOAM_MAX_SIZE 3 +#define SPRITEOAM_SHIFT_SIZE 12 +#define SPRITEOAM_MASK_SIZE (SPRITEOAM_MAX_SIZE << SPRITEOAM_SHIFT_SIZE) + +// atrib3 + +#define SPRITEOAM_MAX_TILENUM 0x3FF +#define SPRITEOAM_SHIFT_TILENUM 0 +#define SPRITEOAM_MASK_TILENUM (SPRITEOAM_MAX_TILENUM << SPRITEOAM_SHIFT_TILENUM) + +#define SPRITEOAM_MAX_PRIORITY 3 +#define SPRITEOAM_SHIFT_PRIORITY 10 +#define SPRITEOAM_MASK_PRIORITY (SPRITEOAM_MAX_PRIORITY << SPRITEOAM_SHIFT_PRIORITY) + +#define SPRITEOAM_MAX_PALETTENUM 0xF +#define SPRITEOAM_SHIFT_PALETTENUM 12 +#define SPRITEOAM_MASK_PALETTENUM (SPRITEOAM_MAX_PALETTENUM << SPRITEOAM_SHIFT_PALETTENUM) + +// unk6 + +#define SPRITEOAM_MAX_UNK6_0 1 +#define SPRITEOAM_SHIFT_UNK6_0 0 +#define SPRITEOAM_MASK_UNK6_0 (SPRITEOAM_MAX_UNK6_0 << SPRITEOAM_SHIFT_UNK6_0) + +#define SPRITEOAM_MAX_UNK6_1 1 +#define SPRITEOAM_SHIFT_UNK6_1 1 +#define SPRITEOAM_MASK_UNK6_1 (SPRITEOAM_MAX_UNK6_1 << SPRITEOAM_SHIFT_UNK6_1) + +#define SPRITEOAM_MAX_UNK6_4 0xFFF +#define SPRITEOAM_SHIFT_UNK6_4 4 +#define SPRITEOAM_MASK_UNK6_4 (SPRITEOAM_MAX_UNK6_4 << SPRITEOAM_SHIFT_UNK6_4) + +#endif // GUARD_SPRITE_OAM_H \ No newline at end of file diff --git a/src/other_menus.c b/src/other_menus.c index 00a84feb..1e6d4373 100644 --- a/src/other_menus.c +++ b/src/other_menus.c @@ -19,7 +19,7 @@ struct unkStruct_203B35C u32 unk0; u32 linkStatus; u32 state; - struct unkSprite unkC; + struct SpriteOAM unkC; u32 unk14; u8 fill18[0x1C - 0x18]; struct MenuStruct unk1C[4]; @@ -782,57 +782,67 @@ void sub_80376CC(void) #endif u32 r1; u32 r4; - - r1 = gUnknown_203B35C->unkC.unk0; - r0 = 0xfeff; + r1 = gUnknown_203B35C->unkC.atrib1; + r0 = (u16)~SPRITEOAM_MASK_AFFINEMODE1; r0 &= r1; - r0 &= 0xfdff; - r0 &= 0xf3ff; - r0 &= 0xefff; - r0 &= 0xdfff; - r2 = 0x4000; - r0 &= 0x3fff; - r0 |= r2; - gUnknown_203B35C->unkC.unk0 = r0; - r2 = 0x3F0; - r1 = gUnknown_203B35C->unkC.unk4; - r0 = 0xFC00; + r0 &= (u16)~SPRITEOAM_MASK_AFFINEMODE2; + + r0 &= (u16)~SPRITEOAM_MASK_OBJMODE; + + r0 &= (u16)~SPRITEOAM_MASK_MOSAIC; + + r0 &= (u16)~SPRITEOAM_MASK_BPP; + + r2 = 1 << SPRITEOAM_SHIFT_SHAPE; + r0 &= (u16)~SPRITEOAM_MASK_SHAPE; + r0 |= r2; + + gUnknown_203B35C->unkC.atrib1 = r0; + + r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; + r1 = gUnknown_203B35C->unkC.atrib3; + r0 = (u16)~SPRITEOAM_MASK_TILENUM; r0 &= r1; r0 |= r2; - r0 &= 0xf3ff; - r2 = 0xF; - r4 = 0xF000; - r0 &= 0xfff; + + r0 &= (u16)~SPRITEOAM_MASK_PRIORITY; + + r2 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r4 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r4; - gUnknown_203B35C->unkC.unk4 = r0; - r0 = 0; - gUnknown_203B35C->unkC.unk2 = r0; + gUnknown_203B35C->unkC.atrib3 = r0; - r1 = 0xC00; + r0 = 0; // Set x/matrixNum/size to 0 + gUnknown_203B35C->unkC.atrib2 = r0; + + r1 = 192 << SPRITEOAM_SHIFT_UNK6_4; r0 = gUnknown_203B35C->unkC.unk6; r2 &= r0; r2 |= r1; gUnknown_203B35C->unkC.unk6 = r2; - } void sub_8037748(void) { - u32 temp2; + u16 temp2; - gUnknown_203B35C->unkC.unk2 = (gUnknown_203B35C->unkC.unk2 & 0xfe00) | 0x70; + gUnknown_203B35C->unkC.atrib2 &= ~SPRITEOAM_MASK_X; // Clear x + gUnknown_203B35C->unkC.atrib2 |= 112; // Set x to 112 - temp2 = 0x680; - gUnknown_203B35C->unkC.unk6 = (gUnknown_203B35C->unkC.unk6 & 0xf) | temp2; + temp2 = 104 << SPRITEOAM_SHIFT_UNK6_4; + gUnknown_203B35C->unkC.unk6 &= ~SPRITEOAM_MASK_UNK6_4; + gUnknown_203B35C->unkC.unk6 |= temp2; - if ((gUnknown_203B35C->unk14 & 8) != 0) { - AddSprite(&gUnknown_203B35C->unkC, 0x100, NULL, NULL); - } - xxx_draw_string_80144C4(); - gUnknown_203B35C->unk14++; + if ((gUnknown_203B35C->unk14 & 8) != 0) + AddSprite(&gUnknown_203B35C->unkC, 0x100, NULL, NULL); + + xxx_draw_string_80144C4(); + gUnknown_203B35C->unk14++; } u32 sub_8037798(void) diff --git a/src/pokemon_3.c b/src/pokemon_3.c index 67f1e4c5..c18cd4c8 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -28,9 +28,9 @@ struct unkStruct_808E9EC u8 unk12; u8 unk13; }; -extern u32 gUnknown_81076C4[]; +extern s32 gUnknown_81076C4[6]; // x-coord positioning for shadow sprites -extern struct unkSprite gUnknown_202F3E8[3]; // Shadow sprites of some kind +extern struct SpriteOAM gUnknown_202F3E8[3]; // Shadow sprites of some kind extern s16 gUnknown_810AC60; // 0xC extern s16 gUnknown_810AC62; // 0xC extern s16 gUnknown_810AC68; // 0x8 @@ -55,29 +55,30 @@ extern void sub_809447C(struct unkStruct_8094924*, void*); extern void sub_808F428(struct unkStruct_8094924*, struct unkStruct_808E6F4*); -bool8 sub_808E668(s16 a1, s16* a2, s16* a3) +bool8 sub_808E668(s16 species, s16* a2, s16* a3) { - u32 shifted = a1 << 16; + if (species != MONSTER_DIGLETT && species != MONSTER_DUGTRIO) { + u8 shadowSize = GetShadowSize(species); + u32 x, unk6; + struct SpriteOAM* spr; - if (((shifted - 0x320000) >> 16) > 1) { - u8 shadowSize = GetShadowSize(a1); - u32 unk2, unk6; - struct unkSprite* arg0; - - unk2 = a2[0] + a3[8]; + x = a2[0] + a3[8]; unk6 = a2[1] + a3[9]; - unk2 += gUnknown_81076C4[shadowSize]; + x += gUnknown_81076C4[shadowSize]; unk6 -= 4; - unk2 &= 0x1ff; + x &= SPRITEOAM_MAX_X; - arg0 = &gUnknown_202F3E8[shadowSize]; - arg0->unk2 = (arg0->unk2 & 0xfe00) | unk2; - unk6 &= 0xfff; - unk6 <<= 4; - arg0->unk6 = (arg0->unk6 & 0xf) | unk6; - AddSprite(arg0, 0, NULL, NULL); + spr = &gUnknown_202F3E8[shadowSize]; + spr->atrib2 &= ~SPRITEOAM_MASK_X; + spr->atrib2 |= x; + unk6 &= SPRITEOAM_MAX_UNK6_4; + unk6 <<= SPRITEOAM_SHIFT_UNK6_4; + spr->unk6 &= ~SPRITEOAM_MASK_UNK6_4; + spr->unk6 |= unk6; + AddSprite(spr, 0, NULL, NULL); } - return 1; + + return TRUE; } diff --git a/src/rescue_password_menu.c b/src/rescue_password_menu.c index fb00a658..92610d5f 100644 --- a/src/rescue_password_menu.c +++ b/src/rescue_password_menu.c @@ -692,39 +692,43 @@ void sub_8039174(void) #else u32 r2; // r4 but should be r2 #endif //NONMATCHING - struct unkSprite* spr; // r2 but should be r3 + struct SpriteOAM* spr; // r2 but should be r3 u16 r4; // r3 but should be r4 - + spr = &gRescuePasswordMenu->unk208; - spr->unk0 &= ~0x100; - spr->unk0 &= ~0x200; - r4 = ~(0x800 | 0x400); - spr->unk0 &= r4; - spr->unk0 &= ~0x1000; - spr->unk0 &= ~0x2000; - r2 = 0x4000; - temp = 0x8000; - temp = ~(temp | 0x4000); - spr->unk0 &= temp; - spr->unk0 |= r2; + spr->atrib1 &= ~SPRITEOAM_MASK_AFFINEMODE1; - r2 = 0x200 | 0x100 | 0x80 | 0x40 | 0x20 | 0x10; - spr->unk4 &= ~(0x200 | 0x100 | 0x80 | 0x40 | 0x20 | 0x10 | 0x8 | 0x4 | 0x2 | 0x1); - spr->unk4 |= r2; - spr->unk4 &= r4; - r2 = 0x1 | 0x2 | 0x4 | 0x8; - r4 = 0x1000 | 0x2000 | 0x4000 | 0x8000; - temp = ~r4; - spr->unk4 &= temp; - spr->unk4 |= r4; + spr->atrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; + + spr->atrib1 &= ~SPRITEOAM_MASK_OBJMODE; + + spr->atrib1 &= ~SPRITEOAM_MASK_MOSAIC; + + spr->atrib1 &= ~SPRITEOAM_MASK_BPP; + + r2 = 1 << SPRITEOAM_SHIFT_SHAPE; + spr->atrib1 &= ~SPRITEOAM_MASK_SHAPE; + spr->atrib1 |= r2; + + r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; + spr->atrib3 &= ~SPRITEOAM_MASK_TILENUM; + spr->atrib3 |= r2; + + spr->atrib3 &= ~SPRITEOAM_MASK_PRIORITY; + + r2 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r4 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + spr->atrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + spr->atrib3 |= r4; #ifndef NONMATCHING while (0) ; #endif //NONMATCHING - spr->unk2 = 0; // Without the while(0), this 0 is loaded super early and also into r3 + spr->atrib2 = 0; // Without the while(0), this 0 is loaded super early and also into r3 - temp = 0x800 | 0x400; + temp = 192 << SPRITEOAM_SHIFT_UNK6_4; r2 &= spr->unk6; r2 |= temp; spr->unk6 = r2; @@ -732,22 +736,21 @@ void sub_8039174(void) void sub_80391F8(void) { - struct unkSprite *iVar2; - u32 temp; - u32 temp2; + struct SpriteOAM *spr; + u32 val; - iVar2 = &gRescuePasswordMenu->unk208; - - temp = (iVar2->unk2 & 0xfe00); - iVar2->unk2 = temp | 0x70; + spr = &gRescuePasswordMenu->unk208; - temp2 = 0x700; - temp = (iVar2->unk6 & 0xf); - iVar2->unk6 = temp | temp2; + spr->atrib2 &= ~SPRITEOAM_MASK_X; + spr->atrib2 |= 112; - if ((gRescuePasswordMenu->unk210 & 8) != 0) { - AddSprite(iVar2, 0x100, NULL, NULL); - } - xxx_draw_string_80144C4(); - gRescuePasswordMenu->unk210 += 1; + val = 112 << SPRITEOAM_SHIFT_UNK6_4; + spr->unk6 &= ~SPRITEOAM_MASK_UNK6_4; + spr->unk6 |= val; + + if (gRescuePasswordMenu->unk210 & 8) + AddSprite(spr, 0x100, NULL, NULL); + + xxx_draw_string_80144C4(); + gRescuePasswordMenu->unk210++; } diff --git a/src/save_menu.c b/src/save_menu.c index fe67564f..cc5e2154 100644 --- a/src/save_menu.c +++ b/src/save_menu.c @@ -14,7 +14,7 @@ struct unkStruct_203B360 u32 unk4; struct MenuStruct unk8[4]; struct UnkTextStruct2 unk148[4]; - struct unkSprite unk1A8; + struct SpriteOAM unk1A8; u32 unk1B0; // Sprite count? }; @@ -286,50 +286,58 @@ void sub_8038830(void) u32 r1; u32 r4; u32 r5; - struct unkSprite *sprite; - + struct SpriteOAM *sprite; + r5 = 0; sprite = &gUnknown_203B364->unk1A8; - r1 = sprite->unk0; - r0 = 0xfeff; + r1 = sprite->atrib1; + r0 = (u16)~SPRITEOAM_MASK_AFFINEMODE1; r0 &= r1; - r0 &= 0xfdff; - r0 &= 0xf3ff; - r0 &= 0xefff; - r0 &= 0xdfff; - r2 = 0x4000; - r0 &= 0x3fff; - r0 |= r2; - sprite->unk0 = r0; - r2 = 0x3F0; - r1 = sprite->unk4; - r0 = 0xFC00; + r0 &= (u16)~SPRITEOAM_MASK_AFFINEMODE2; + + r0 &= (u16)~SPRITEOAM_MASK_OBJMODE; + + r0 &= (u16)~SPRITEOAM_MASK_MOSAIC; + + r0 &= (u16)~SPRITEOAM_MASK_BPP; + + r2 = 1 << SPRITEOAM_SHIFT_SHAPE; + r0 &= (u16)~SPRITEOAM_MASK_SHAPE; + r0 |= r2; + sprite->atrib1 = r0; + + r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; + r1 = sprite->atrib3; + r0 = (u16)~SPRITEOAM_MASK_TILENUM; r0 &= r1; r0 |= r2; - r0 &= 0xf3ff; - r2 = 0xF; - r4 = 0xF000; - r0 &= 0xfff; + + r0 &= (u16)~SPRITEOAM_MASK_PRIORITY; + + r2 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r4 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r4; + sprite->atrib3 = r0; - sprite->unk4 = r0; - - sprite->unk2 = 0x70; + sprite->atrib2 = 112; // Set x to 112. Set matrixNum/size to 0 - r1 = 0x680; + r1 = 104 << SPRITEOAM_SHIFT_UNK6_4; r2 &= sprite->unk6; r2 |= r1; sprite->unk6 = r2; - + gUnknown_203B364->unk1B0 = r5; ResetSprites(FALSE); } -void sub_80388C4(void) { - if ((gUnknown_203B364->unk1B0 & 8) != 0) { - AddSprite(&gUnknown_203B364->unk1A8, 0x100, NULL, NULL); - } - gUnknown_203B364->unk1B0++; +void sub_80388C4(void) +{ + if (gUnknown_203B364->unk1B0 & 8) + AddSprite(&gUnknown_203B364->unk1A8, 0x100, NULL, NULL); + + gUnknown_203B364->unk1B0++; } diff --git a/src/sprite.c b/src/sprite.c index c4d67a00..d95cd109 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -3,14 +3,14 @@ #include "random.h" #include "sprite.h" -extern u16 gUnknown_2025670; +extern u16 gUnknown_2025670; // Number of sprites in OAM? extern s16 gUnknown_2025672[8]; extern s16 gUnknown_2025682[9]; extern struct Position gUnknown_2025694; extern u32 gUnknown_2025698; extern struct SpriteList gUnknown_20256A0; extern struct UnkSpriteLink gUnknown_2025EA8[128]; -extern struct unkSprite gUnknown_20262A8[128]; +extern struct SpriteOAM gUnknown_20262A8[128]; extern s32 gSpriteCount; /* 20266A8 */ extern struct unkStruct_20266B0 gUnknown_20266B0[160]; extern void *gCharMemCursor; /* 2026E30 */ @@ -33,8 +33,8 @@ void ResetSprites(bool8 a0) s32 i; struct UnkSpriteLink *a; struct UnkSpriteLink *b; - struct unkSprite *c; - struct unkSprite *d; + struct SpriteOAM *c; + struct SpriteOAM *d; struct UnkSpriteLink *e; gSpriteCount = 0; @@ -155,7 +155,7 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 u16 flags3; u16 unkA; } sp; - struct unkSprite *sprite; + struct SpriteOAM *sprite; u32 uVar9; s32 r7; @@ -185,15 +185,15 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 r7 = 255; if (spriteMasks == NULL) { - sprite->unk0 = sp.flags1; - sprite->unk2 = sp.flags2; - sprite->unk4 = sp.flags3; + sprite->atrib1 = sp.flags1; + sprite->atrib2 = sp.flags2; + sprite->atrib3 = sp.flags3; sprite->unk6 = sp.unkA; } else { - sprite->unk0 = (spriteMasks[0] & sp.flags1) | spriteMasks[3]; - sprite->unk2 = (spriteMasks[1] & sp.flags2) | spriteMasks[4]; - sprite->unk4 = (spriteMasks[2] & sp.flags3) | spriteMasks[5]; + sprite->atrib1 = (spriteMasks[0] & sp.flags1) | spriteMasks[3]; + sprite->atrib2 = (spriteMasks[1] & sp.flags2) | spriteMasks[4]; + sprite->atrib3 = (spriteMasks[2] & sp.flags3) | spriteMasks[5]; sprite->unk6 = sp.unkA; } @@ -201,14 +201,14 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 tileNum = gUnknown_2025672[sp.unk2] & 0x3FF; } else { - tileNum = (sprite->unk4 & 0x3FF) + a1->vramTileOrMaybeAnimTimer; + tileNum = (sprite->atrib3 & 0x3FF) + a1->vramTileOrMaybeAnimTimer; tileNum &= 0x3FF; } // Set tileNum, maintain priority/paletteNum - sprite->unk4 = tileNum | (sprite->unk4 & 0xFC00); + sprite->atrib3 = tileNum | (sprite->atrib3 & 0xFC00); - x = (sprite->unk2 & 0x1FF) - 256; + x = (sprite->atrib2 & 0x1FF) - 256; x += a1->xPos; if (x < -64) return; @@ -216,7 +216,7 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 return; // Set x, maintain matrixNum/size - sprite->unk2 = (x & 0x1FF) | (sprite->unk2 & 0xFE00); + sprite->atrib2 = (x & 0x1FF) | (sprite->atrib2 & 0xFE00); uVar9 = sprite->unk6 << 16; earlyMask = 0xFFF; @@ -229,14 +229,14 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 return; // Set y, maintain affineMode/objMode/mosaic/bpp/shape - sprite->unk0 = (y & 0xFF) | (sprite->unk0 & 0xFF00); + sprite->atrib1 = (y & 0xFF) | (sprite->atrib1 & 0xFF00); // Set paletteNum, maintain tileNum/priority if (((uVar9 >> 17) & 1) == 0) - sprite->unk4 = ((a1->paletteNum & 0xF) << 12) | (sprite->unk4 & earlyMask); + sprite->atrib3 = ((a1->paletteNum & 0xF) << 12) | (sprite->atrib3 & earlyMask); if (sp.unk2 != 0) - sprite->unk4 = ((gUnknown_2025682[sp.unk2] & 0xF) << 12) | (sprite->unk4 & earlyMask); + sprite->atrib3 = ((gUnknown_2025682[sp.unk2] & 0xF) << 12) | (sprite->atrib3 & earlyMask); gUnknown_2025EA8[gSpriteCount].unk0 = gUnknown_20256A0.sprites[r7].unk0; gUnknown_20256A0.sprites[r7].unk0 = gUnknown_2025EA8 + gSpriteCount; @@ -510,10 +510,10 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 // a2 and a3 are always called with NULL lol #ifdef NONMATCHING // https://decomp.me/scratch/YCfKG -void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unkStruct_2039DB0 *a3) +void AddSprite(struct SpriteOAM *a0, s32 a1, struct UnkSpriteMem *a2, struct unkStruct_2039DB0 *a3) { - s32 uVar1; - struct unkSprite *spr; + s32 yPos; + struct SpriteOAM *spr; struct UnkSpriteLink *a; struct UnkSpriteLink *b; @@ -528,24 +528,23 @@ void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unk a1 = 255; if (a3 == NULL) { - spr->unk0 = a0->unk0; - spr->unk2 = a0->unk2; - spr->unk4 = a0->unk4; + spr->atrib1 = a0->atrib1; + spr->atrib2 = a0->atrib2; + spr->atrib3 = a0->atrib3; spr->unk6 = a0->unk6; } else { - spr->unk0 = (a0->unk0 & a3->unk0) | a3->unk6; - spr->unk2 = (a0->unk2 & a3->unk2) | a3->unk8; - spr->unk4 = (a0->unk4 & a3->unk4) | a3->unkA; + spr->atrib1 = (a0->atrib1 & a3->unk0) | a3->unk6; + spr->atrib2 = (a0->atrib2 & a3->unk2) | a3->unk8; + spr->atrib3 = (a0->atrib3 & a3->unk4) | a3->unkA; spr->unk6 = a0->unk6; } - uVar1 = spr->unk6 / 16; - nullsub_3(uVar1, 0); - // uVar1 is the Y position of the sprite, then the rest remains - uVar1 &= 0xFF; - spr->unk0 &= 0xFF00; - spr->unk0 |= uVar1; + yPos = spr->unk6 / 16; + nullsub_3(yPos, 0); + yPos &= SPRITEOAM_MAX_Y; + spr->atrib1 &= ~SPRITEOAM_MASK_Y; + spr->atrib1 |= yPos; if (a2 != NULL) RegisterSpriteParts_80052BC(a2); @@ -561,7 +560,7 @@ void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unk } #else NAKED -void AddSprite(struct unkSprite *a0, s32 a1, struct UnkSpriteMem *a2, struct unkStruct_2039DB0 *a3) +void AddSprite(struct SpriteOAM *a0, s32 a1, struct UnkSpriteMem *a2, struct unkStruct_2039DB0 *a3) { asm_unified( "push {r4-r7,lr}\n" @@ -695,7 +694,7 @@ void sub_8005180(void) void CopySpritesToOam(void) { struct UnkSpriteLink *sLink; - struct unkSprite *spr; + struct SpriteOAM *spr; vu16 *oam; s32 count; @@ -711,13 +710,13 @@ void CopySpritesToOam(void) // Skip affineParam oam -= 2; // Set tileNum/priority/paletteNum - *oam = spr->unk4; + *oam = spr->atrib3; // Set x/matrixNum/size oam--; - *oam = spr->unk2; + *oam = spr->atrib2; // Set y/affineMode/objMode/mosaic/bpp/shape oam--; - *oam = spr->unk0; + *oam = spr->atrib1; count++; } @@ -946,15 +945,13 @@ void sub_800545C(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 void sub_80054BC(struct axPokemon *a0) { struct ax_anim *aData; - s32 flag; + s16 flag; if (a0->axdata.flags & 0x2000) flag = 0; else flag = a0->axdata.flags >> 15; - flag++; flag--; - if (flag == 0) return; diff --git a/src/unk_menu_203B360.c b/src/unk_menu_203B360.c index 24a1e75c..03cd4326 100644 --- a/src/unk_menu_203B360.c +++ b/src/unk_menu_203B360.c @@ -15,7 +15,7 @@ struct unkStruct_203B360 u32 unk4; // state struct MenuStruct unk8[4]; struct UnkTextStruct2 unk148[4]; - struct unkSprite unk1A8; + struct SpriteOAM unk1A8; u32 unk1B0; // sprite count? }; @@ -135,43 +135,52 @@ void sub_8038440(void) u32 r1; u32 r4; u32 r5; - struct unkSprite *sprite; - + struct SpriteOAM *sprite; + r5 = 0; sprite = &gUnknown_203B360->unk1A8; - r1 = sprite->unk0; - r0 = 0xfeff; + r1 = sprite->atrib1; + r0 = (u16)~SPRITEOAM_MASK_AFFINEMODE1; r0 &= r1; - r0 &= 0xfdff; - r0 &= 0xf3ff; - r0 &= 0xefff; - r0 &= 0xdfff; - r2 = 0x4000; - r0 &= 0x3fff; - r0 |= r2; - sprite->unk0 = r0; - r2 = 0x3F0; - r1 = sprite->unk4; - r0 = 0xFC00; + r0 &= (u16)~SPRITEOAM_MASK_AFFINEMODE2; + + r0 &= (u16)~SPRITEOAM_MASK_OBJMODE; + + r0 &= (u16)~SPRITEOAM_MASK_MOSAIC; + + r0 &= (u16)~SPRITEOAM_MASK_BPP; + + r2 = 1 << SPRITEOAM_SHIFT_SHAPE; + r0 &= (u16)~SPRITEOAM_MASK_SHAPE; + r0 |= r2; + + sprite->atrib1 = r0; + + r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; + r1 = sprite->atrib3; + r0 = (u16)~SPRITEOAM_MASK_TILENUM; r0 &= r1; r0 |= r2; - r0 &= 0xf3ff; - r2 = 0xF; - r4 = 0xF000; - r0 &= 0xfff; + + r0 &= (u16)~SPRITEOAM_MASK_PRIORITY; + + r2 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r4 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r4; - sprite->unk4 = r0; - - sprite->unk2 = 0x70; - - r1 = 0x700; + sprite->atrib3 = r0; + + sprite->atrib2 = 112; // Set x to 112. Set matrixNum/size to 0 + + r1 = 112 << SPRITEOAM_SHIFT_UNK6_4; r2 &= sprite->unk6; r2 |= r1; sprite->unk6 = r2; - + gUnknown_203B360->unk1B0 = r5; } From 06aeba84790f67d4d391ed8b3a4261728f268d0a Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sat, 26 Aug 2023 10:39:37 -0400 Subject: [PATCH 19/27] Fakematch AddMenuCursorSprite_ too --- asm/menu_input.s | 183 ------------------------------------------- include/input.h | 4 +- include/menu_input.h | 2 + src/menu_input.c | 87 +++++++++++++++++++- 4 files changed, 88 insertions(+), 188 deletions(-) diff --git a/asm/menu_input.s b/asm/menu_input.s index d13df4a6..5b077915 100644 --- a/asm/menu_input.s +++ b/asm/menu_input.s @@ -5,189 +5,6 @@ .text - thumb_func_start AddMenuCursorSprite_ -AddMenuCursorSprite_: - push {r4-r6,lr} - sub sp, 0x8 - adds r6, r0, 0 - movs r0, 0 - movs r1, 0 - str r0, [sp] - str r1, [sp, 0x4] - movs r1, 0x1A - ldrsh r0, [r6, r1] - cmp r0, 0 - bgt _080131CC - b _080132D6 -_080131CC: - adds r0, r6, 0 - bl UpdateMenuCursorSpriteCoords - ldrh r1, [r6, 0x24] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - bne _080132D6 - mov r0, sp - ldrh r0, [r0] - ldr r1, _080132FC - ands r1, r0 - ldr r3, _08013300 - ldr r0, [sp] - ands r0, r3 - orrs r0, r1 - str r0, [sp] - mov r1, sp - ldrh r1, [r1] - adds r2, r3, 0 - ands r2, r0 - orrs r2, r1 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013304 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r4, _08013308 - adds r0, r4, 0 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _0801330C - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013310 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013314 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - ands r3, r1 - orrs r3, r0 - str r3, [sp] - mov r3, sp - movs r2, 0xFD - lsls r2, 2 - ldrh r1, [r3, 0x4] - movs r0, 0xFC - lsls r0, 8 - ands r0, r1 - orrs r0, r2 - ands r0, r4 - movs r5, 0xF - movs r1, 0xF0 - lsls r1, 8 - ldr r4, _08013318 - ands r0, r4 - orrs r0, r1 - strh r0, [r3, 0x4] - ldrh r0, [r3, 0x6] - ldr r1, _0801331C - ands r1, r0 - ldr r0, _08013320 - ands r1, r0 - movs r2, 0x8 - ldrsh r0, [r6, r2] - ldr r2, _08013324 - ands r0, r2 - strh r0, [r3, 0x2] - movs r2, 0xA - ldrsh r0, [r6, r2] - adds r0, 0x1 - ands r0, r4 - lsls r0, 4 - ands r1, r5 - orrs r1, r0 - strh r1, [r3, 0x6] - mov r0, sp - movs r1, 0xFF - movs r2, 0 - movs r3, 0 - bl AddSprite -_080132D6: - adds r0, r6, 0 - bl sub_8013470 - movs r1, 0x14 - ldrsh r0, [r6, r1] - cmp r0, 0 - beq _080132EC - adds r0, r6, 0 - adds r0, 0x14 - bl sub_801332C -_080132EC: - ldrh r0, [r6, 0x24] - adds r0, 0x1 - strh r0, [r6, 0x24] - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080132FC: .4byte 0x0000feff -_08013300: .4byte 0xffff0000 -_08013304: .4byte 0x0000fdff -_08013308: .4byte 0x0000f3ff -_0801330C: .4byte 0x0000efff -_08013310: .4byte 0x0000dfff -_08013314: .4byte 0x00003fff -_08013318: .4byte 0x00000fff -_0801331C: .4byte 0x0000fffe -_08013320: .4byte 0x0000fffd -_08013324: .4byte 0x000001ff - thumb_func_end AddMenuCursorSprite_ - - thumb_func_start nullsub_34 -nullsub_34: - bx lr - thumb_func_end nullsub_34 - thumb_func_start sub_801332C sub_801332C: push {r4-r6,lr} diff --git a/include/input.h b/include/input.h index b71030c1..9451d85e 100644 --- a/include/input.h +++ b/include/input.h @@ -68,8 +68,8 @@ struct MenuInputStruct s32 unk0; u16 unk4; s16 unk6; - u16 unk8; - u16 unkA; + s16 unk8; + s16 unkA; u16 unkC; u16 unkE; u32 unk10; diff --git a/include/menu_input.h b/include/menu_input.h index dd7b60f5..0dad9894 100644 --- a/include/menu_input.h +++ b/include/menu_input.h @@ -40,5 +40,7 @@ bool8 sub_8013938(struct MenuInputStruct *param_1); void sub_8013984(struct MenuInputStruct * param_1); void sub_8013A54(struct MenuInputStruct *param_1); void sub_8013A7C(struct MenuInputStruct *param_1); +void AddMenuCursorSprite_(struct MenuInputStruct *, u32); +void nullsub_34(struct MenuInputStructSub *); #endif // GUARD_MENU_INPUT_H \ No newline at end of file diff --git a/src/menu_input.c b/src/menu_input.c index f9ee9da8..5dc9b4e0 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -7,22 +7,22 @@ #include "code_800D090.h" #include "menu_input.h" #include "code_80130A8.h" +#include "sprite.h" extern u8 gUnknown_80D4828[]; extern void PlayMenuSoundEffect(u32); extern s32 sub_8008ED0(const u8 *); -void AddMenuCursorSprite_(struct MenuInputStruct *, u32); void sub_8012EBC(struct MenuStruct *param_1); extern void sub_8013134(struct MenuInputStruct *, u32, u32); extern s16 sub_8009614(u32, u32); extern u32 ReturnIntFromChar2(u8); extern void nullsub_7(u16 *); -extern void nullsub_34(struct MenuInputStructSub *r0); +void sub_8013470(struct MenuInputStruct *); +void sub_801332C(s16 *); const u32 gDefaultMenuTextColors[] = { COLOR_WHITE_2, COLOR_RED, COLOR_RED }; - u32 sub_8012A64(struct MenuInputStructSub *r0, s32 r1) { if(r0 == NULL) @@ -595,3 +595,84 @@ void AddMenuCursorSprite(struct MenuInputStruct *param_1) { AddMenuCursorSprite_(param_1, 0); } + +void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) +{ + struct SpriteOAM sp = {}; + struct SpriteOAM* ptr; + s32 value; + s32 r0; + s32 r1; + s32 r2; + s32 r5; + + if (a0->unk1A > 0) { + UpdateMenuCursorSpriteCoords(a0); + + if (!(a0->unk24 & 8)) { + register u32 tmp asm("r0"), tmp2 asm("r1"), r4; + + tmp = sp.atrib1; + sp.atrib1 = tmp & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.atrib1 = sp.atrib1; + + tmp2 = sp.atrib1; + sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_AFFINEMODE2; + sp.atrib1 = sp.atrib1; + + tmp2 = sp.atrib1; + tmp = r4 = (u16)~SPRITEOAM_MASK_OBJMODE; + sp.atrib1 = tmp & tmp2; + sp.atrib1 = sp.atrib1; + + tmp2 = sp.atrib1; + sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_MOSAIC; + sp.atrib1 = sp.atrib1; + + tmp2 = sp.atrib1; + sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_BPP; + sp.atrib1 = sp.atrib1; + + tmp2 = sp.atrib1; + sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_SHAPE; + sp.atrib1 = sp.atrib1; + + ptr = &sp; + + r2 = 0x3F4 << SPRITEOAM_SHIFT_TILENUM; + ptr->atrib3 &= ~SPRITEOAM_MASK_TILENUM; + ptr->atrib3 |= r2; + + ptr->atrib3 &= r4; // ~SPRITEOAM_MASK_PRIORITY + + r5 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r1 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + ptr->atrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + ptr->atrib3 |= r1; + + ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_0; + ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_1; + + r0 = a0->unk8; + r0 &= SPRITEOAM_MAX_X; + ptr->atrib2 = r0; + + value = ((a0->unkA + 1) & SPRITEOAM_MAX_UNK6_4) << SPRITEOAM_SHIFT_UNK6_4; + ptr->unk6 &= r5; + ptr->unk6 |= value; + + AddSprite(&sp, 0xFF, 0, 0); + } + } + + sub_8013470(a0); + if (a0->unk14 != 0) + sub_801332C(&a0->unk14); + + a0->unk24++; +} + +void nullsub_34(struct MenuInputStructSub *a0) +{ +} \ No newline at end of file From afbe73020662303033682743f3a535cb42619820 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sat, 26 Aug 2023 12:39:15 -0400 Subject: [PATCH 20/27] Fakematch sub_801332C and sub_8013470 --- asm/menu_input.s | 402 ------------------------------------------- include/input.h | 10 +- include/sprite_oam.h | 7 +- ld_script.txt | 1 - src/menu_input.c | 205 +++++++++++++++++++++- 5 files changed, 208 insertions(+), 417 deletions(-) delete mode 100644 asm/menu_input.s diff --git a/asm/menu_input.s b/asm/menu_input.s deleted file mode 100644 index 5b077915..00000000 --- a/asm/menu_input.s +++ /dev/null @@ -1,402 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start sub_801332C -sub_801332C: - push {r4-r6,lr} - sub sp, 0x8 - movs r1, 0 - movs r2, 0 - str r1, [sp] - str r2, [sp, 0x4] - mov r1, sp - ldrh r1, [r1] - ldr r2, _08013440 - ands r2, r1 - ldr r4, _08013444 - ldr r1, [sp] - ands r1, r4 - orrs r1, r2 - str r1, [sp] - mov r2, sp - ldrh r2, [r2] - adds r3, r4, 0 - ands r3, r1 - orrs r3, r2 - str r3, [sp] - mov r1, sp - ldrh r2, [r1] - ldr r1, _08013448 - ands r1, r2 - adds r2, r4, 0 - ands r2, r3 - orrs r2, r1 - str r2, [sp] - mov r1, sp - ldrh r1, [r1] - adds r3, r4, 0 - ands r3, r2 - orrs r3, r1 - str r3, [sp] - movs r5, 0x80 - lsls r5, 3 - mov r1, sp - ldrh r2, [r1] - ldr r6, _0801344C - adds r1, r6, 0 - ands r1, r2 - adds r2, r4, 0 - ands r2, r3 - orrs r2, r1 - str r2, [sp] - mov r1, sp - ldrh r1, [r1] - orrs r5, r1 - adds r3, r4, 0 - ands r3, r2 - orrs r3, r5 - str r3, [sp] - mov r1, sp - ldrh r2, [r1] - ldr r1, _08013450 - ands r1, r2 - adds r2, r4, 0 - ands r2, r3 - orrs r2, r1 - str r2, [sp] - mov r1, sp - ldrh r1, [r1] - adds r3, r4, 0 - ands r3, r2 - orrs r3, r1 - str r3, [sp] - mov r1, sp - ldrh r2, [r1] - ldr r1, _08013454 - ands r1, r2 - adds r2, r4, 0 - ands r2, r3 - orrs r2, r1 - str r2, [sp] - mov r1, sp - ldrh r1, [r1] - adds r3, r4, 0 - ands r3, r2 - orrs r3, r1 - str r3, [sp] - mov r1, sp - ldrh r2, [r1] - ldr r1, _08013458 - ands r1, r2 - adds r2, r4, 0 - ands r2, r3 - orrs r2, r1 - str r2, [sp] - mov r1, sp - ldrh r1, [r1] - ands r4, r2 - orrs r4, r1 - str r4, [sp] - mov r4, sp - ldr r3, _0801345C - ldrh r2, [r4, 0x4] - movs r1, 0xFC - lsls r1, 8 - ands r1, r2 - orrs r1, r3 - ands r1, r6 - movs r6, 0xF - movs r2, 0xF0 - lsls r2, 8 - ldr r5, _08013460 - ands r1, r5 - orrs r1, r2 - strh r1, [r4, 0x4] - ldrh r1, [r4, 0x6] - ldr r2, _08013464 - ands r2, r1 - ldr r1, _08013468 - ands r2, r1 - movs r3, 0 - ldrsh r1, [r0, r3] - ldr r3, _0801346C - ands r1, r3 - strh r1, [r4, 0x2] - movs r1, 0x2 - ldrsh r0, [r0, r1] - adds r0, 0x1 - ands r0, r5 - lsls r0, 4 - ands r2, r6 - orrs r2, r0 - strh r2, [r4, 0x6] - mov r0, sp - movs r1, 0xFF - movs r2, 0 - movs r3, 0 - bl AddSprite - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_08013440: .4byte 0x0000feff -_08013444: .4byte 0xffff0000 -_08013448: .4byte 0x0000fdff -_0801344C: .4byte 0x0000f3ff -_08013450: .4byte 0x0000efff -_08013454: .4byte 0x0000dfff -_08013458: .4byte 0x00003fff -_0801345C: .4byte 0x000003f5 -_08013460: .4byte 0x00000fff -_08013464: .4byte 0x0000fffe -_08013468: .4byte 0x0000fffd -_0801346C: .4byte 0x000001ff - thumb_func_end sub_801332C - - thumb_func_start sub_8013470 -sub_8013470: - push {r4-r6,lr} - sub sp, 0x8 - adds r6, r0, 0 - movs r0, 0 - movs r1, 0 - str r0, [sp] - str r1, [sp, 0x4] - movs r1, 0xC - ldrsh r0, [r6, r1] - cmp r0, 0 - bne _08013488 - b _08013624 -_08013488: - movs r2, 0x1E - ldrsh r0, [r6, r2] - cmp r0, 0 - beq _08013586 - mov r0, sp - ldrh r0, [r0] - ldr r1, _0801362C - ands r1, r0 - ldr r3, _08013630 - ldr r0, [sp] - ands r0, r3 - orrs r0, r1 - str r0, [sp] - mov r1, sp - ldrh r1, [r1] - adds r2, r3, 0 - ands r2, r0 - orrs r2, r1 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013634 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r4, _08013638 - adds r0, r4, 0 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _0801363C - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013640 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013644 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - ands r3, r1 - orrs r3, r0 - str r3, [sp] - mov r3, sp - ldr r2, _08013648 - ldrh r1, [r3, 0x4] - movs r0, 0xFC - lsls r0, 8 - ands r0, r1 - orrs r0, r2 - ands r0, r4 - movs r5, 0xF - movs r1, 0xF0 - lsls r1, 8 - ldr r4, _0801364C - ands r0, r4 - orrs r0, r1 - strh r0, [r3, 0x4] - ldrh r0, [r3, 0x6] - ldr r1, _08013650 - ands r1, r0 - ldr r0, _08013654 - ands r1, r0 - movs r2, 0xC - ldrsh r0, [r6, r2] - ldr r2, _08013658 - ands r0, r2 - strh r0, [r3, 0x2] - movs r2, 0xE - ldrsh r0, [r6, r2] - ands r0, r4 - lsls r0, 4 - ands r1, r5 - orrs r1, r0 - strh r1, [r3, 0x6] - mov r0, sp - movs r1, 0xFF - movs r2, 0 - movs r3, 0 - bl AddSprite -_08013586: - movs r1, 0x20 - ldrsh r0, [r6, r1] - cmp r0, 0 - beq _08013624 - adds r1, r0, 0 - movs r2, 0x1E - ldrsh r0, [r6, r2] - adds r0, 0x1 - cmp r1, r0 - beq _08013624 - mov r0, sp - ldrh r0, [r0] - ldr r1, _0801362C - ands r1, r0 - mov r0, sp - strh r1, [r0] - strh r1, [r0] - ldr r0, _08013634 - ands r0, r1 - mov r1, sp - strh r0, [r1] - strh r0, [r1] - ldr r4, _08013638 - ands r0, r4 - strh r0, [r1] - strh r0, [r1] - ldr r1, _0801363C - ands r1, r0 - mov r0, sp - strh r1, [r0] - strh r1, [r0] - ldr r2, _08013640 - ands r2, r1 - strh r2, [r0] - strh r2, [r0] - ldr r0, _08013644 - ands r0, r2 - mov r1, sp - strh r0, [r1] - strh r0, [r1] - mov r3, sp - ldr r2, _0801365C - ldrh r1, [r3, 0x4] - movs r0, 0xFC - lsls r0, 8 - ands r0, r1 - orrs r0, r2 - ands r0, r4 - movs r5, 0xF - movs r1, 0xF0 - lsls r1, 8 - ldr r4, _0801364C - ands r0, r4 - orrs r0, r1 - strh r0, [r3, 0x4] - ldrh r0, [r3, 0x6] - ldr r1, _08013650 - ands r1, r0 - ldr r0, _08013654 - ands r1, r0 - movs r2, 0xC - ldrsh r0, [r6, r2] - adds r0, 0xA - ldr r2, _08013658 - ands r0, r2 - strh r0, [r3, 0x2] - movs r2, 0xE - ldrsh r0, [r6, r2] - ands r0, r4 - lsls r0, 4 - ands r1, r5 - orrs r1, r0 - strh r1, [r3, 0x6] - mov r0, sp - movs r1, 0xFF - movs r2, 0 - movs r3, 0 - bl AddSprite -_08013624: - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0801362C: .4byte 0x0000feff -_08013630: .4byte 0xffff0000 -_08013634: .4byte 0x0000fdff -_08013638: .4byte 0x0000f3ff -_0801363C: .4byte 0x0000efff -_08013640: .4byte 0x0000dfff -_08013644: .4byte 0x00003fff -_08013648: .4byte 0x000003f2 -_0801364C: .4byte 0x00000fff -_08013650: .4byte 0x0000fffe -_08013654: .4byte 0x0000fffd -_08013658: .4byte 0x000001ff -_0801365C: .4byte 0x000003f3 - thumb_func_end sub_8013470 - - .align 2,0 diff --git a/include/input.h b/include/input.h index 9451d85e..27d93264 100644 --- a/include/input.h +++ b/include/input.h @@ -68,13 +68,13 @@ struct MenuInputStruct s32 unk0; u16 unk4; s16 unk6; - s16 unk8; + s16 unk8; // Maybe struct Position s16 unkA; - u16 unkC; - u16 unkE; + s16 unkC; // Maybe struct Position + s16 unkE; u32 unk10; - s16 unk14; - u16 unk16; + s16 unk14; // Maybe struct Position + s16 unk16; /* 0x18 */ s16 menuIndex; s16 unk1A; s16 unk1C; diff --git a/include/sprite_oam.h b/include/sprite_oam.h index ea0d66e7..96a39cdc 100644 --- a/include/sprite_oam.h +++ b/include/sprite_oam.h @@ -10,12 +10,13 @@ struct SpriteOAM /* 0x2 */ u16 atrib2; // tileNum:10 priority:2 paletteNum:4 /* 0x4 */ u16 atrib3; - // unk6_0:1 unk6_1:1 unk6_2:2? unk6_4:12 + // unk6_0:1 unk6_1:1 unk6_2:2? unk6_4:12 u16 unk6; }; // The SpriteOAM struct is handled with macros most likely. // Most funcs that deal with it look the same and do some weird bit manipulations one by one on the attributes. +// It seems like there is a macro to initialize the structure to some default values... // atrib1 @@ -53,7 +54,7 @@ struct SpriteOAM #define SPRITEOAM_SHIFT_X 0 #define SPRITEOAM_MASK_X (SPRITEOAM_MAX_X << SPRITEOAM_SHIFT_X) -#define SPRITEOAM_MAX_MATRIXNUM 0x1F +#define SPRITEOAM_MAX_MATRIXNUM 31 #define SPRITEOAM_SHIFT_MATRIXNUM 9 #define SPRITEOAM_MASK_MATRIXNUM (SPRITEOAM_MAX_MATRIXNUM << SPRITEOAM_SHIFT_MATRIXNUM) @@ -71,7 +72,7 @@ struct SpriteOAM #define SPRITEOAM_SHIFT_PRIORITY 10 #define SPRITEOAM_MASK_PRIORITY (SPRITEOAM_MAX_PRIORITY << SPRITEOAM_SHIFT_PRIORITY) -#define SPRITEOAM_MAX_PALETTENUM 0xF +#define SPRITEOAM_MAX_PALETTENUM 15 #define SPRITEOAM_SHIFT_PALETTENUM 12 #define SPRITEOAM_MASK_PALETTENUM (SPRITEOAM_MAX_PALETTENUM << SPRITEOAM_SHIFT_PALETTENUM) diff --git a/ld_script.txt b/ld_script.txt index fdfaaa1a..848933da 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -90,7 +90,6 @@ SECTIONS { src/save.o(.text); src/code_8012A18.o(.text); src/menu_input.o(.text); - asm/menu_input.o(.text); src/menu_input_1.o(.text); asm/code_80130A8.o(.text); src/code_8012A18_1.o(.text); diff --git a/src/menu_input.c b/src/menu_input.c index 5dc9b4e0..ec18eacf 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -18,8 +18,9 @@ extern void sub_8013134(struct MenuInputStruct *, u32, u32); extern s16 sub_8009614(u32, u32); extern u32 ReturnIntFromChar2(u8); extern void nullsub_7(u16 *); -void sub_8013470(struct MenuInputStruct *); + void sub_801332C(s16 *); +void sub_8013470(struct MenuInputStruct *); const u32 gDefaultMenuTextColors[] = { COLOR_WHITE_2, COLOR_RED, COLOR_RED }; @@ -610,7 +611,7 @@ void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) UpdateMenuCursorSpriteCoords(a0); if (!(a0->unk24 & 8)) { - register u32 tmp asm("r0"), tmp2 asm("r1"), r4; + register u32 tmp asm("r0"), tmp2 asm("r1"); tmp = sp.atrib1; sp.atrib1 = tmp & ~SPRITEOAM_MASK_AFFINEMODE1; @@ -621,8 +622,7 @@ void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) sp.atrib1 = sp.atrib1; tmp2 = sp.atrib1; - tmp = r4 = (u16)~SPRITEOAM_MASK_OBJMODE; - sp.atrib1 = tmp & tmp2; + sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_OBJMODE; sp.atrib1 = sp.atrib1; tmp2 = sp.atrib1; @@ -643,7 +643,7 @@ void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) ptr->atrib3 &= ~SPRITEOAM_MASK_TILENUM; ptr->atrib3 |= r2; - ptr->atrib3 &= r4; // ~SPRITEOAM_MASK_PRIORITY + ptr->atrib3 &= ~SPRITEOAM_MASK_PRIORITY; r5 = (u16)~SPRITEOAM_MASK_UNK6_4; @@ -658,7 +658,9 @@ void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) r0 &= SPRITEOAM_MAX_X; ptr->atrib2 = r0; - value = ((a0->unkA + 1) & SPRITEOAM_MAX_UNK6_4) << SPRITEOAM_SHIFT_UNK6_4; + value = a0->unkA + 1; + value &= SPRITEOAM_MAX_UNK6_4; + value <<= SPRITEOAM_SHIFT_UNK6_4; ptr->unk6 &= r5; ptr->unk6 |= value; @@ -675,4 +677,195 @@ void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) void nullsub_34(struct MenuInputStructSub *a0) { +} + +// Maybe struct Position +void sub_801332C(s16 *a0) +{ + struct SpriteOAM sp = {}; + struct SpriteOAM* ptr; + register u32 r0 asm("r0"); + register u32 r1 asm("r1"); + register u32 r2 asm("r2"); + u32 r3; + u32 r5; + u32 r6; + + r1 = sp.atrib1; + sp.atrib1 = r1 & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.atrib1 = sp.atrib1; + + r2 = sp.atrib1; + sp.atrib1 = r2 & ~SPRITEOAM_MASK_AFFINEMODE2; + sp.atrib1 = sp.atrib1; + + r5 = 1 << SPRITEOAM_SHIFT_OBJMODE; + r2 = sp.atrib1; + sp.atrib1 = r2 & ~SPRITEOAM_MASK_OBJMODE; + sp.atrib1 = sp.atrib1 | r5; + + r2 = sp.atrib1; + sp.atrib1 = r2 & ~SPRITEOAM_MASK_MOSAIC; + sp.atrib1 = sp.atrib1; + + r2 = sp.atrib1; + sp.atrib1 = r2 & ~SPRITEOAM_MASK_BPP; + sp.atrib1 = sp.atrib1; + + r2 = sp.atrib1; + sp.atrib1 = r2 & ~SPRITEOAM_MASK_SHAPE; + sp.atrib1 = sp.atrib1; + + ptr = &sp; + + r3 = 0x3F5 << SPRITEOAM_SHIFT_TILENUM; + ptr->atrib3 &= ~SPRITEOAM_MASK_TILENUM; + ptr->atrib3 |= r3; + + ptr->atrib3 &= ~SPRITEOAM_MASK_PRIORITY; + + r6 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r2 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + ptr->atrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + ptr->atrib3 |= r2; + + ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_0; + ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_1; + + r1 = a0[0]; + r1 &= SPRITEOAM_MAX_X; + ptr->atrib2 = r1; + + r0 = a0[1] + 1; + r0 &= SPRITEOAM_MAX_UNK6_4; + r0 <<= SPRITEOAM_SHIFT_UNK6_4; + ptr->unk6 &= r6; + ptr->unk6 |= r0; + + AddSprite(&sp, 0xFF, NULL, NULL); +} + +void sub_8013470(struct MenuInputStruct *a0) +{ + struct SpriteOAM sp = {}; + register struct SpriteOAM* ptr asm("r3"); + register u32 r0 asm("r0"); + register u32 r1 asm("r1"); + u32 r2; + register u32 r5 asm("r5"); + + if (a0->unkC != 0) { + if (a0->unk1E != 0) { + r0 = sp.atrib1; + sp.atrib1 = r0 & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.atrib1 = sp.atrib1; + + r1 = sp.atrib1; + sp.atrib1 = r1 & ~SPRITEOAM_MASK_AFFINEMODE2; + sp.atrib1 = sp.atrib1; + + r1 = sp.atrib1; + sp.atrib1 = r1 & (u16)~SPRITEOAM_MASK_OBJMODE; + sp.atrib1 = sp.atrib1; + + r1 = sp.atrib1; + sp.atrib1 = r1 & ~SPRITEOAM_MASK_MOSAIC; + sp.atrib1 = sp.atrib1; + + r1 = sp.atrib1; + sp.atrib1 = r1 & ~SPRITEOAM_MASK_BPP; + sp.atrib1 = sp.atrib1; + + r1 = sp.atrib1; + sp.atrib1 = r1 & ~SPRITEOAM_MASK_SHAPE; + sp.atrib1 = sp.atrib1; + + ptr = &sp; + + r2 = 0x3F2 << SPRITEOAM_SHIFT_TILENUM; + r1 = ptr->atrib3; + r0 = r1 & (u16)~SPRITEOAM_MASK_TILENUM; + r0 |= r2; + + r0 &= (u16)~SPRITEOAM_MASK_PRIORITY; + + r5 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r1 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; + r0 |= r1; + ptr->atrib3 = r0; + + r0 = ptr->unk6; + r1 = r0 & (u16)~SPRITEOAM_MASK_UNK6_0; + r1 &= (u16)~SPRITEOAM_MASK_UNK6_1; + + r0 = a0->unkC; + r0 &= SPRITEOAM_MAX_X; + ptr->atrib2 = r0; + + r0 = a0->unkE; + r0 &= SPRITEOAM_MAX_UNK6_4; + r0 <<= SPRITEOAM_SHIFT_UNK6_4; + r1 &= r5; + r1 |= r0; + ptr->unk6 = r1; + + AddSprite(&sp, 0xFF, NULL, NULL); + } + if (a0->unk20 != 0 && a0->unk20 != a0->unk1E + 1) { + r0 = sp.atrib1; + sp.atrib1 = r0 & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.atrib1 = sp.atrib1; + + sp.atrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; + sp.atrib1 = sp.atrib1; + + sp.atrib1 &= (u16)~SPRITEOAM_MASK_OBJMODE; + sp.atrib1 = sp.atrib1; + + sp.atrib1 &= ~SPRITEOAM_MASK_MOSAIC; + sp.atrib1 = sp.atrib1; + + sp.atrib1 &= ~SPRITEOAM_MASK_BPP; + sp.atrib1 = sp.atrib1; + + sp.atrib1 &= ~SPRITEOAM_MASK_SHAPE; + sp.atrib1 = sp.atrib1; + + ptr = &sp; + + r2 = 0x3F3 << SPRITEOAM_SHIFT_TILENUM; + r1 = ptr->atrib3; + r0 = r1 & (u16)~SPRITEOAM_MASK_TILENUM; + r0 |= r2; + + r0 &= (u16)~SPRITEOAM_MASK_PRIORITY; + + r5 = (u16)~SPRITEOAM_MASK_UNK6_4; + + r1 = 15 << SPRITEOAM_SHIFT_PALETTENUM; + r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; + r0 |= r1; + ptr->atrib3 = r0; + + r0 = ptr->unk6; + r1 = r0 & (u16)~SPRITEOAM_MASK_UNK6_0; + r1 &= (u16)~SPRITEOAM_MASK_UNK6_1; + + r0 = a0->unkC + 10; + r0 &= SPRITEOAM_MAX_X; + ptr->atrib2 = r0; + + r0 = a0->unkE; + r0 &= SPRITEOAM_MAX_UNK6_4; + r0 <<= SPRITEOAM_SHIFT_UNK6_4; + r1 &= r5; + r1 |= r0; + ptr->unk6 = r1; + + AddSprite(&sp, 0xFF, NULL, NULL); + } + } } \ No newline at end of file From 0a19222313feb7d8e37e525ad51f41530c6fe7f7 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sat, 26 Aug 2023 12:40:32 -0400 Subject: [PATCH 21/27] Merge menu_input files --- ld_script.txt | 1 - src/menu_input.c | 335 +++++++++++++++++++++++++++++++++++++++++++- src/menu_input_1.c | 340 --------------------------------------------- 3 files changed, 334 insertions(+), 342 deletions(-) delete mode 100644 src/menu_input_1.c diff --git a/ld_script.txt b/ld_script.txt index 848933da..7814ecd1 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -90,7 +90,6 @@ SECTIONS { src/save.o(.text); src/code_8012A18.o(.text); src/menu_input.o(.text); - src/menu_input_1.o(.text); asm/code_80130A8.o(.text); src/code_8012A18_1.o(.text); src/felicity_bank.o(.text); diff --git a/src/menu_input.c b/src/menu_input.c index ec18eacf..f53a0a5d 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -18,6 +18,7 @@ extern void sub_8013134(struct MenuInputStruct *, u32, u32); extern s16 sub_8009614(u32, u32); extern u32 ReturnIntFromChar2(u8); extern void nullsub_7(u16 *); +extern void PlayMenuSoundEffect(u32); void sub_801332C(s16 *); void sub_8013470(struct MenuInputStruct *); @@ -868,4 +869,336 @@ void sub_8013470(struct MenuInputStruct *a0) AddSprite(&sp, 0xFF, NULL, NULL); } } -} \ No newline at end of file +} + +void sub_8013660(struct MenuInputStruct *param_1) +{ + if (0 < param_1->unk1A) + { + UpdateMenuCursorSpriteCoords(param_1); + sub_801332C(¶m_1->unk8); + } +} + +void UpdateMenuCursorSpriteCoords(struct MenuInputStruct *param_1) +{ + s32 index; + struct UnkTextStruct1 *temp; + + index = param_1->unk0; + temp = &gUnknown_2027370[index]; + param_1->unk8 = temp->unk0 * 8 + param_1->unk4; + param_1->unkA = temp->unk2 * 8 + sub_8013800(param_1, param_1->menuIndex); +} + +void MoveMenuCursorDown(struct MenuInputStruct *param_1) +{ + param_1->unk24 = 0; + if (param_1->unk1A < 1) { + param_1->menuIndex = 0; + } + else { + param_1->menuIndex++; + if (param_1->menuIndex >= param_1->unk1A) { + param_1->menuIndex = 0; + } + } +} + +void sub_80136E0(struct MenuInputStruct *param_1, u8 param_2) +{ + param_1->unk24 = 0; + if (param_1->unk1A < 1) { + param_1->menuIndex = 0; + } + else { + param_1->menuIndex++; + if (param_1->menuIndex >= param_1->unk1A) { + if (param_2 != 0) { + param_1->menuIndex = 0; + } + else + { + param_1->menuIndex = param_1->unk1A - 1; + } + } + } +} + +void MoveMenuCursorUp(struct MenuInputStruct *param_1) +{ + param_1->unk24 = 0; + if (param_1->unk1A < 1) { + param_1->menuIndex = 0; + } + else { + param_1->menuIndex--; + if (param_1->menuIndex < 0) { + param_1->menuIndex = param_1->unk1A + -1; + } + } +} + +void sub_8013744(struct MenuInputStruct *param_1, u8 param_2) +{ + param_1->unk24 = 0; + if (param_1->unk1A < 1) { + param_1->menuIndex = 0; + } + else { + param_1->menuIndex--; + if (param_1->menuIndex < 0) { + if (param_2 != 0) { + param_1->menuIndex = param_1->unk1A + -1; + } + else { + param_1->menuIndex = 0; + } + } + } +} + +void sub_8013780(struct MenuInputStruct *param_1, s32 param_2) +{ + if (param_2 < 0) { + param_1->menuIndex = 0; + } + else if (param_2 >= param_1->unk1A) { + param_1->menuIndex = param_1->unk1A - 1; + } + else { + param_1->menuIndex = param_2; + } + param_1->unk24 = 0; +} + +s32 sub_80137A8(struct MenuInputStruct *param_1) +{ + return param_1->menuIndex; +} + +void sub_80137B0(struct MenuInputStruct *param_1, s32 param_2) +{ + s32 iVar1; +#ifndef NONMATCHING + register s32 iVar2 asm("r0"); +#else + s32 iVar2; +#endif + + if (param_2 >= 1) { + iVar2 = param_2 << 8; + } + else + { + if (gUnknown_2027370[param_1->unk0].unkC == 6) + { + iVar1 = 0x10; + } + else + { + iVar1 = 0; + } + iVar2 = (gUnknown_2027370[param_1->unk0].unk6 * 8 - iVar1); + iVar2 <<= 8; + } + param_1->unk10 = iVar2 / param_1->unk1C; +} + +void sub_80137F8(struct MenuInputStruct *param_1, u32 param_2) +{ + param_1->unk10 = param_2 << 8; +} + +s32 sub_8013800(struct MenuInputStruct *param_1, s32 param_2) +{ + s32 iVar1; + s32 iVar2; + + iVar2 = param_1->unk6; + iVar1 = param_2 * param_1->unk10; + if (iVar1 < 0) { + iVar1 = iVar1 + 0xff; + } + return (iVar2 + (iVar1 >> 8)); +} + +void sub_8013818(struct MenuInputStruct *param_1, s32 param_2, u32 param_3, s32 param_4) +{ + param_1->unk0 = param_4; + param_1->unk22 = param_2; + param_1->unk1C = param_3; + param_1->unk14 = 0; + param_1->unk24 = 0; + param_1->menuIndex = 0; + param_1->unk1E = 0; + sub_801317C(¶m_1->unk28); + sub_8013984(param_1); + sub_80137F8(param_1,0xC); +} + + +void sub_8013848(struct MenuInputStruct *param_1, s32 param_2, u32 param_3, s32 param_4) +{ + param_1->unk0 = param_4; + param_1->unk22 = param_2; + param_1->unk1C = param_3; + param_1->unk14 = 0; + param_1->unk24 = 0; + param_1->menuIndex = 0; + param_1->unk1E = 0; + sub_801317C(¶m_1->unk28); + sub_8013984(param_1); + sub_80137F8(param_1,0x18); +} + +void sub_8013878(struct MenuInputStruct *param_1, s32 param_2) +{ + if (param_2 < 0) { + param_2 = 0; + } + else if (param_2 >= param_1->unk22) { + param_2 = param_1->unk22 + -1; + } + param_1->unk1E = param_2 / param_1->unk1C; + param_1->menuIndex = param_2 % param_1->unk1C; + param_1->unk24 = 0; + sub_8013984(param_1); +} + +bool8 sub_80138B8(struct MenuInputStruct *param_1, bool8 param_2) +{ + s32 sVar1; + s32 oldIndex; + + sVar1 = param_1->unk1E; + oldIndex = param_1->menuIndex; + AddMenuCursorSprite(param_1); + if(param_2) + { + switch(GetKeyPress(param_1)) + { + case INPUT_DPAD_UP: + MoveMenuCursorUp(param_1); + if(oldIndex != param_1->menuIndex) + PlayMenuSoundEffect(3); + break; + case INPUT_DPAD_DOWN: + MoveMenuCursorDown(param_1); + if(oldIndex != param_1->menuIndex) + PlayMenuSoundEffect(3); + break; + case INPUT_DPAD_LEFT: + sub_8013A7C(param_1); + break; + case INPUT_DPAD_RIGHT: + sub_8013A54(param_1); + break; + } + } + if (sVar1 != param_1->unk1E) { + PlayMenuSoundEffect(4); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 sub_8013938(struct MenuInputStruct *param_1) +{ + s32 sVar1; + + sVar1 = param_1->unk1E; + param_1->unk1A = 0; + param_1->unk14 = 0; + AddMenuCursorSprite(param_1); + switch(GetKeyPress(param_1)) + { + case INPUT_DPAD_LEFT: + sub_8013A7C(param_1); + break; + case INPUT_DPAD_RIGHT: + sub_8013A54(param_1); + break; + } + if (sVar1 != param_1->unk1E) { + PlayMenuSoundEffect(4); + return TRUE; + } + else + { + return FALSE; + } +} + +void sub_8013984(struct MenuInputStruct * param_1) +{ + s32 iVar2; + s32 iVar4; + struct UnkTextStruct1 *ptr; + + iVar4 = param_1->unk0; + ptr = &gUnknown_2027370[iVar4]; + if (param_1->unk1C == 0) { + param_1->unk1C++; + } + param_1->unk20 = param_1->unk22 / param_1->unk1C; + iVar2 = (param_1->unk22 % param_1->unk1C); + if (iVar2 != 0) { + param_1->unk20++; + } + if (param_1->unk1E > param_1->unk20 - 1) { + param_1->unk1E = param_1->unk20 - 1; + } + if ((param_1->unk1E != param_1->unk20 - 1) || (param_1->unk22 % param_1->unk1C == 0)) + { + param_1->unk1A = param_1->unk1C; + } + else + { + param_1->unk1A = param_1->unk22 % param_1->unk1C; + } + if (param_1->menuIndex > param_1->unk1A - 1) { + param_1->menuIndex = param_1->unk1A - 1; + } + param_1->unk4 = 0; + if (ptr->unkC == 6) { + param_1->unk6 = 0x10; + } + else { + param_1->unk6 = 0; + } + if (param_1->unk20 < 2) { + param_1->unkC = 0; + } + else { + param_1->unkC = (ptr->unk0 + ptr->unk4 + -2) * 8; + } + param_1->unkE = ((ptr->unk2) + 1) * 8 + -2; +} + +void sub_8013A54(struct MenuInputStruct *param_1) +{ + if (param_1->unk1E < param_1->unk20 - 1) { + param_1->unk1E++; + } + else + { + param_1->unk1E = 0; + } + sub_8013984(param_1); +} + +void sub_8013A7C(struct MenuInputStruct *param_1) +{ + if (param_1->unk1E < 1) { + param_1->unk1E = param_1->unk20 - 1; + } + else + { + param_1->unk1E--; + } + sub_8013984(param_1); +} diff --git a/src/menu_input_1.c b/src/menu_input_1.c deleted file mode 100644 index 002e74b3..00000000 --- a/src/menu_input_1.c +++ /dev/null @@ -1,340 +0,0 @@ -#include "global.h" -#include "constants/input.h" -#include "input.h" -#include "text1.h" -#include "menu_input.h" - -extern void PlayMenuSoundEffect(u32); -void sub_801332C(u16 *); - -void sub_8013660(struct MenuInputStruct *param_1) -{ - if (0 < param_1->unk1A) - { - UpdateMenuCursorSpriteCoords(param_1); - sub_801332C(¶m_1->unk8); - } -} - -void UpdateMenuCursorSpriteCoords(struct MenuInputStruct *param_1) -{ - s32 index; - struct UnkTextStruct1 *temp; - - index = param_1->unk0; - temp = &gUnknown_2027370[index]; - param_1->unk8 = temp->unk0 * 8 + param_1->unk4; - param_1->unkA = temp->unk2 * 8 + sub_8013800(param_1, param_1->menuIndex); -} - -void MoveMenuCursorDown(struct MenuInputStruct *param_1) -{ - param_1->unk24 = 0; - if (param_1->unk1A < 1) { - param_1->menuIndex = 0; - } - else { - param_1->menuIndex++; - if (param_1->menuIndex >= param_1->unk1A) { - param_1->menuIndex = 0; - } - } -} - -void sub_80136E0(struct MenuInputStruct *param_1, u8 param_2) -{ - param_1->unk24 = 0; - if (param_1->unk1A < 1) { - param_1->menuIndex = 0; - } - else { - param_1->menuIndex++; - if (param_1->menuIndex >= param_1->unk1A) { - if (param_2 != 0) { - param_1->menuIndex = 0; - } - else - { - param_1->menuIndex = param_1->unk1A - 1; - } - } - } -} - -void MoveMenuCursorUp(struct MenuInputStruct *param_1) -{ - param_1->unk24 = 0; - if (param_1->unk1A < 1) { - param_1->menuIndex = 0; - } - else { - param_1->menuIndex--; - if (param_1->menuIndex < 0) { - param_1->menuIndex = param_1->unk1A + -1; - } - } -} - -void sub_8013744(struct MenuInputStruct *param_1, u8 param_2) -{ - param_1->unk24 = 0; - if (param_1->unk1A < 1) { - param_1->menuIndex = 0; - } - else { - param_1->menuIndex--; - if (param_1->menuIndex < 0) { - if (param_2 != 0) { - param_1->menuIndex = param_1->unk1A + -1; - } - else { - param_1->menuIndex = 0; - } - } - } -} - -void sub_8013780(struct MenuInputStruct *param_1, s32 param_2) -{ - if (param_2 < 0) { - param_1->menuIndex = 0; - } - else if (param_2 >= param_1->unk1A) { - param_1->menuIndex = param_1->unk1A - 1; - } - else { - param_1->menuIndex = param_2; - } - param_1->unk24 = 0; -} - -s32 sub_80137A8(struct MenuInputStruct *param_1) -{ - return param_1->menuIndex; -} - -void sub_80137B0(struct MenuInputStruct *param_1, s32 param_2) -{ - s32 iVar1; -#ifndef NONMATCHING - register s32 iVar2 asm("r0"); -#else - s32 iVar2; -#endif - - if (param_2 >= 1) { - iVar2 = param_2 << 8; - } - else - { - if (gUnknown_2027370[param_1->unk0].unkC == 6) - { - iVar1 = 0x10; - } - else - { - iVar1 = 0; - } - iVar2 = (gUnknown_2027370[param_1->unk0].unk6 * 8 - iVar1); - iVar2 <<= 8; - } - param_1->unk10 = iVar2 / param_1->unk1C; -} - -void sub_80137F8(struct MenuInputStruct *param_1, u32 param_2) -{ - param_1->unk10 = param_2 << 8; -} - -s32 sub_8013800(struct MenuInputStruct *param_1, s32 param_2) -{ - s32 iVar1; - s32 iVar2; - - iVar2 = param_1->unk6; - iVar1 = param_2 * param_1->unk10; - if (iVar1 < 0) { - iVar1 = iVar1 + 0xff; - } - return (iVar2 + (iVar1 >> 8)); -} - -void sub_8013818(struct MenuInputStruct *param_1, s32 param_2, u32 param_3, s32 param_4) -{ - param_1->unk0 = param_4; - param_1->unk22 = param_2; - param_1->unk1C = param_3; - param_1->unk14 = 0; - param_1->unk24 = 0; - param_1->menuIndex = 0; - param_1->unk1E = 0; - sub_801317C(¶m_1->unk28); - sub_8013984(param_1); - sub_80137F8(param_1,0xC); -} - - -void sub_8013848(struct MenuInputStruct *param_1, s32 param_2, u32 param_3, s32 param_4) -{ - param_1->unk0 = param_4; - param_1->unk22 = param_2; - param_1->unk1C = param_3; - param_1->unk14 = 0; - param_1->unk24 = 0; - param_1->menuIndex = 0; - param_1->unk1E = 0; - sub_801317C(¶m_1->unk28); - sub_8013984(param_1); - sub_80137F8(param_1,0x18); -} - -void sub_8013878(struct MenuInputStruct *param_1, s32 param_2) -{ - if (param_2 < 0) { - param_2 = 0; - } - else if (param_2 >= param_1->unk22) { - param_2 = param_1->unk22 + -1; - } - param_1->unk1E = param_2 / param_1->unk1C; - param_1->menuIndex = param_2 % param_1->unk1C; - param_1->unk24 = 0; - sub_8013984(param_1); -} - -bool8 sub_80138B8(struct MenuInputStruct *param_1, bool8 param_2) -{ - s32 sVar1; - s32 oldIndex; - - sVar1 = param_1->unk1E; - oldIndex = param_1->menuIndex; - AddMenuCursorSprite(param_1); - if(param_2) - { - switch(GetKeyPress(param_1)) - { - case INPUT_DPAD_UP: - MoveMenuCursorUp(param_1); - if(oldIndex != param_1->menuIndex) - PlayMenuSoundEffect(3); - break; - case INPUT_DPAD_DOWN: - MoveMenuCursorDown(param_1); - if(oldIndex != param_1->menuIndex) - PlayMenuSoundEffect(3); - break; - case INPUT_DPAD_LEFT: - sub_8013A7C(param_1); - break; - case INPUT_DPAD_RIGHT: - sub_8013A54(param_1); - break; - } - } - if (sVar1 != param_1->unk1E) { - PlayMenuSoundEffect(4); - return TRUE; - } - else - { - return FALSE; - } -} - -bool8 sub_8013938(struct MenuInputStruct *param_1) -{ - s32 sVar1; - - sVar1 = param_1->unk1E; - param_1->unk1A = 0; - param_1->unk14 = 0; - AddMenuCursorSprite(param_1); - switch(GetKeyPress(param_1)) - { - case INPUT_DPAD_LEFT: - sub_8013A7C(param_1); - break; - case INPUT_DPAD_RIGHT: - sub_8013A54(param_1); - break; - } - if (sVar1 != param_1->unk1E) { - PlayMenuSoundEffect(4); - return TRUE; - } - else - { - return FALSE; - } -} - -void sub_8013984(struct MenuInputStruct * param_1) -{ - s32 iVar2; - s32 iVar4; - struct UnkTextStruct1 *ptr; - - iVar4 = param_1->unk0; - ptr = &gUnknown_2027370[iVar4]; - if (param_1->unk1C == 0) { - param_1->unk1C++; - } - param_1->unk20 = param_1->unk22 / param_1->unk1C; - iVar2 = (param_1->unk22 % param_1->unk1C); - if (iVar2 != 0) { - param_1->unk20++; - } - if (param_1->unk1E > param_1->unk20 - 1) { - param_1->unk1E = param_1->unk20 - 1; - } - if ((param_1->unk1E != param_1->unk20 - 1) || (param_1->unk22 % param_1->unk1C == 0)) - { - param_1->unk1A = param_1->unk1C; - } - else - { - param_1->unk1A = param_1->unk22 % param_1->unk1C; - } - if (param_1->menuIndex > param_1->unk1A - 1) { - param_1->menuIndex = param_1->unk1A - 1; - } - param_1->unk4 = 0; - if (ptr->unkC == 6) { - param_1->unk6 = 0x10; - } - else { - param_1->unk6 = 0; - } - if (param_1->unk20 < 2) { - param_1->unkC = 0; - } - else { - param_1->unkC = (ptr->unk0 + ptr->unk4 + -2) * 8; - } - param_1->unkE = ((ptr->unk2) + 1) * 8 + -2; -} - -void sub_8013A54(struct MenuInputStruct *param_1) -{ - if (param_1->unk1E < param_1->unk20 - 1) { - param_1->unk1E++; - } - else - { - param_1->unk1E = 0; - } - sub_8013984(param_1); -} - -void sub_8013A7C(struct MenuInputStruct *param_1) -{ - if (param_1->unk1E < 1) { - param_1->unk1E = param_1->unk20 - 1; - } - else - { - param_1->unk1E--; - } - sub_8013984(param_1); -} From 01d6fe2685cfff65e553cd9801acad2fa1680d26 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sat, 26 Aug 2023 13:56:46 -0400 Subject: [PATCH 22/27] Clean menu_input --- include/code_800558C_1.h | 1 + include/code_80118A4.h | 16 + include/gulpin_shop.h | 7 +- include/text_util.h | 1 + src/adventure_log.c | 2 +- src/code_2.c | 3 +- src/code_800558C_1.c | 6 +- src/code_800DAC0.c | 2 +- src/code_80118A4.c | 55 +- src/code_8012A18.c | 4 +- src/code_8012A18_1.c | 3 - src/code_801AFA4.c | 2 +- src/code_801B3C0.c | 3 +- src/code_801C620.c | 3 +- src/code_801D760.c | 2 +- src/code_801EE10_1.c | 2 +- src/code_801EE10_mid.c | 2 +- src/code_8021774.c | 2 +- src/code_8021774_pre.c | 2 +- src/code_8023144.c | 2 +- src/code_8031D70.c | 2 +- src/code_8040094.c | 3 +- src/dungeon_music.c | 3 +- src/felicity_bank.c | 2 +- src/friend_area_action_menu_1.c | 2 +- src/friend_list_menu.c | 2 +- src/friend_rescue.c | 4 +- src/ground_main.c | 3 +- src/gulpin_shop.c | 6 +- src/gulpin_shop_1.c | 3 +- src/hints_menu.c | 4 +- src/kecleon_bros.c | 5 +- src/luminous_cave.c | 6 +- src/mailbox.c | 3 +- src/makuhita_dojo.c | 3 +- src/menu_input.c | 1023 +++++++++++++++---------------- src/options_menu.c | 2 +- src/other_menus.c | 4 +- src/party_list_menu.c | 2 +- src/pelipper_board.c | 2 +- src/personality_test.c | 3 +- src/pokemon_news.c | 2 +- src/post_office_guide.c | 2 +- src/save.c | 5 +- src/text_util.c | 6 +- src/thank_you_wonder_mail.c | 3 +- src/trade_items_menu.c | 3 +- src/wigglytuff_shop.c | 2 +- src/wonder_mail.c | 3 +- src/wonder_mail_2_1.c | 2 +- src/wonder_mail_2_mid.c | 4 +- src/wonder_mail_3.c | 3 +- src/wonder_mail_3_mid.c | 3 +- src/wonder_mail_4.c | 2 +- src/wonder_mail_5.c | 2 +- src/wonder_mail_802DF88.c | 2 +- src/wonder_mail_main_menu.c | 3 +- 57 files changed, 603 insertions(+), 651 deletions(-) create mode 100644 include/code_80118A4.h diff --git a/include/code_800558C_1.h b/include/code_800558C_1.h index fd9e1890..05c624d1 100644 --- a/include/code_800558C_1.h +++ b/include/code_800558C_1.h @@ -1,6 +1,7 @@ #ifndef GUARD_CODE_800558C_1_H #define GUARD_CODE_800558C_1_H +void nullsub_7(s16 *); void nullsub_10(bool8); void nullsub_12(void); void nullsub_13(void); diff --git a/include/code_80118A4.h b/include/code_80118A4.h new file mode 100644 index 00000000..308c910e --- /dev/null +++ b/include/code_80118A4.h @@ -0,0 +1,16 @@ +#ifndef GUARD_CODE_80118A4_H +#define GUARD_CODE_80118A4_H + +void FadeOutAllMusic(u16); +void PlayMenuSoundEffect(u32); +void PlaySound(u16); +void sub_801180C(void); +void sub_8011830(void); +void sub_8011860(void); +void xxx_call_fade_in_new_bgm(u16, u16); +void xxx_call_fade_out_bgm(u16); +void xxx_call_start_bg_music(void); +void xxx_call_stop_bgm(void); +void xxx_call_stop_fanfare_se(u16); + +#endif // GUARD_CODE_80118A4_H \ No newline at end of file diff --git a/include/gulpin_shop.h b/include/gulpin_shop.h index 48ce06f2..6bf6c5a6 100644 --- a/include/gulpin_shop.h +++ b/include/gulpin_shop.h @@ -1,5 +1,10 @@ #ifndef GUARD_GULPIN_SHOP_H -#define GUARD_GULPIN_SHOP_H +#define GUARD_GULPIN_SHOP_H + +#include "constants/move.h" +#include "file_system.h" +#include "menu.h" +#include "text.h" // size: 0x18C struct GulpinShopWork diff --git a/include/text_util.h b/include/text_util.h index cbd3d882..3ae9b765 100644 --- a/include/text_util.h +++ b/include/text_util.h @@ -11,5 +11,6 @@ u8 sub_8092354(u8 index); u8 sub_8092364(u8 index); void CopyAbilityNametoBuffer(char *buffer, u8 index); u8 *GetAbilityDescription(u8 index); +u32 ReturnIntFromChar2(u8); #endif diff --git a/src/adventure_log.c b/src/adventure_log.c index fa883a64..741cfcd4 100644 --- a/src/adventure_log.c +++ b/src/adventure_log.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_80118A4.h" #include "code_80130A8.h" #include "constants/input.h" #include "memory.h" @@ -42,7 +43,6 @@ const u8 fill_adven[] = "pksdir0"; void sub_8032084(); void DisplayAdventureLog(); -extern void PlayMenuSoundEffect(u32); extern bool8 sub_8097710(u8); extern s16 sub_80978B8(); diff --git a/src/code_2.c b/src/code_2.c index a09664f8..277a7689 100644 --- a/src/code_2.c +++ b/src/code_2.c @@ -20,8 +20,8 @@ #include "cpu.h" #include "code_8094F88.h" #include "sprite.h" +#include "code_80118A4.h" -extern void sub_801180C(void); extern void NDS_LoadOverlay_GroundMain(void); extern void sub_8014144(void); extern void sub_8097670(void); @@ -48,7 +48,6 @@ extern void xxx_draw_string_80144C4(void); extern void sub_8005838(u32, u32); extern void nullsub_8(u32); extern void sub_80060EC(void); -extern void sub_8011860(void); extern void sub_800CB20(void); extern void TransferBGPaletteBuffer(void); extern void xxx_call_update_bg_vram(void); diff --git a/src/code_800558C_1.c b/src/code_800558C_1.c index cee2eace..90d74154 100644 --- a/src/code_800558C_1.c +++ b/src/code_800558C_1.c @@ -28,8 +28,10 @@ void sub_8005770(s32 param_1, u8 *RGBArray, s32 a1, u8 *a2) } } -void nullsub_7(void) -{} +// Maybe struct Position +void nullsub_7(s16 *a0) +{ +} void nullsub_8(void) {} diff --git a/src/code_800DAC0.c b/src/code_800DAC0.c index 40b6dedd..1e6ab3da 100644 --- a/src/code_800DAC0.c +++ b/src/code_800DAC0.c @@ -1,5 +1,6 @@ #include "global.h" #include "code_800DAC0.h" +#include "code_80118A4.h" #include "file_system.h" #include "memory.h" @@ -50,7 +51,6 @@ extern void sub_803EAF0(u32, u32); extern void sub_800CD64(u32, u32); extern struct unkStruct_800F18C *sub_800F18C(s32); extern void sub_800DCA8(struct unkStruct_203B0CC_sub *); -extern void PlaySound(u16); extern u8 gefob000_string[]; extern u8 gefob001_string[]; diff --git a/src/code_80118A4.c b/src/code_80118A4.c index 4fce8eff..73533313 100644 --- a/src/code_80118A4.c +++ b/src/code_80118A4.c @@ -1,6 +1,7 @@ #include #include #include "global.h" +#include "code_80118A4.h" #include "music.h" #include "constants/bg_music.h" #include "play_time.h" @@ -10,13 +11,11 @@ #include "game_options.h" #include "sprite.h" -void xxx_call_stop_bgm(void); - extern bool8 sub_80023E4(u8); -extern void xxx_call_stop_fanfare_se(u16 r0); extern struct GameOptions *gGameOptionsRef; +// size: 0x4DD8 struct UnkBgStruct { u8 padding[0x4c4b]; @@ -24,8 +23,8 @@ struct UnkBgStruct u8 padding2[0x17A]; u32 *unk4dcc; u32 unk4dd0; - s16 xoffset; - s16 yoffset; + /* 0x4DD4 */ s16 xoffset; + /* 0x4DD6 */ s16 yoffset; }; extern struct UnkBgStruct *gUnknown_203B0E4; @@ -43,7 +42,6 @@ extern void xxx_call_update_bg_vram(void); extern void sub_8009908(void); extern void xxx_call_update_bg_sound_input(void); extern void sub_80060EC(void); -extern void sub_8011860(void); extern void sub_800CB20(void); extern void sub_8004AF0(u8, u32 *r1, u32, u32, u32 *r2, u32); extern u8 sub_80111C4(); @@ -77,15 +75,15 @@ void sub_801169C(void) void sub_8011760(void) { - if(sub_80023E4(0xD)) + if (sub_80023E4(13)) StartNewBGM(MUS_WORLD_CALAMITY); - else if(sub_80023E4(0xC)) + else if (sub_80023E4(12)) StartNewBGM(MUS_POKEMON_SQUARE); } void sub_801178C(void) { - if(sub_80023E4(0xD)) + if (sub_80023E4(13)) StartNewBGM(MUS_WORLD_CALAMITY); else StartNewBGM(MUS_POKEMON_SQUARE); @@ -93,13 +91,13 @@ void sub_801178C(void) void sub_80117AC(void) { - if(!sub_80023E4(0xD)) - FadeOutBGM(0x1E); + if (!sub_80023E4(13)) + FadeOutBGM(30); } void sub_80117C4(void) { - FadeOutBGM(0x1E); + FadeOutBGM(30); } // Some sound effect @@ -143,18 +141,14 @@ void xxx_call_start_bg_music(void) void sub_8011860(void) { - if(gUnknown_202DE20 > 0) - { + if (gUnknown_202DE20 > 0) gUnknown_202DE20--; - } - if(gUnknown_202DE22 > 0) - { + + if (gUnknown_202DE22 > 0) gUnknown_202DE22--; - } - if(gUnknown_202DE24 > 0) - { + + if (gUnknown_202DE24 > 0) gUnknown_202DE24--; - } } void StopAllMusic_1(void) @@ -196,14 +190,13 @@ void xxx_call_fade_out_bgm(u16 speed) FadeOutBGM(speed); } -u32 IsEqualtoBGTrack(u16 songIndex) +bool8 IsEqualtoBGTrack(u16 songIndex) { u32 currBGSong; currBGSong = GetCurrentBGSong(); - if(songIndex == STOP_BGM) + if (songIndex == STOP_BGM) return currBGSong != STOP_BGM; - return currBGSong == songIndex; } @@ -232,23 +225,25 @@ bool8 IsFanfareSEPlaying_1(u16 songIndex) return IsFanfareSEPlaying(songIndex); } -void PlayMenuSoundEffect(u32 r0) +void PlayMenuSoundEffect(u32 a0) { - if(gUnknown_202DE20 > 0) + if (gUnknown_202DE20 > 0) return; - PlayFanfareSE(gUnknown_80D4144[r0], MAX_VOLUME); + + PlayFanfareSE(gUnknown_80D4144[a0], MAX_VOLUME); gUnknown_202DE20 = 4; } void sub_8011A04(void) { - if(gUnknown_202DE22 > 0) + if (gUnknown_202DE22 > 0) return; + gUnknown_202DE22 = 3; PlayFanfareSE(305, MAX_VOLUME); } -void sub_8011A2C(u32 r0) +UNUSED static void sub_8011A2C(u32 a0) { - gUnknown_202DE1C = r0; + gUnknown_202DE1C = a0; } diff --git a/src/code_8012A18.c b/src/code_8012A18.c index d4b24b84..c98cbd46 100644 --- a/src/code_8012A18.c +++ b/src/code_8012A18.c @@ -1,10 +1,10 @@ #include "global.h" #include "code_800558C.h" -#include "input.h" +#include "code_80118A4.h" #include "game_options.h" +#include "input.h" #include "sprite.h" -extern void sub_8011860(); extern void xxx_draw_string_80144C4(); extern void nullsub_8(u8); extern void sub_800CB20(); diff --git a/src/code_8012A18_1.c b/src/code_8012A18_1.c index 8bfc38cb..3fadc67c 100644 --- a/src/code_8012A18_1.c +++ b/src/code_8012A18_1.c @@ -48,9 +48,6 @@ enum MENU_ACTION_NO, }; -extern u32 ReturnIntFromChar2(u8); - - s32 sub_8015FEC(u8 *buffer, s32 size) { struct unkChar *iVar2; diff --git a/src/code_801AFA4.c b/src/code_801AFA4.c index f4716c5e..9cf65cf0 100644 --- a/src/code_801AFA4.c +++ b/src/code_801AFA4.c @@ -7,6 +7,7 @@ #include "pokemon.h" #include "gulpin_shop.h" #include "code_80130A8.h" +#include "code_80118A4.h" extern void sub_8092C84(u8 *, u16); extern void sub_8099690(u32); @@ -33,7 +34,6 @@ extern void unk_CopyMoves4To8(struct Move *, struct Move *); extern bool8 IsHMItem(u8); extern void sub_801B178(void); extern void sub_8094060(void *, struct Move *); -extern void PlaySound(u32); extern void PrintPokeNameToBuffer(u8 *buffer, struct PokemonStruct *pokemon); extern u32 sub_801E8C0(void); diff --git a/src/code_801B3C0.c b/src/code_801B3C0.c index c2860279..ec900ce9 100644 --- a/src/code_801B3C0.c +++ b/src/code_801B3C0.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_80118A4.h" #include "code_801B3C0.h" #include "constants/colors.h" #include "text1.h" @@ -67,7 +68,6 @@ extern struct UnkTextStruct2 gUnknown_80DBA70; extern void sub_801BB5C(void); extern struct PokemonStruct *GetPlayerPokemonStruct(void); extern void sub_801B748(u32); -extern void PlayMenuSoundEffect(u32); extern void sub_8013F84(void); extern s32 sub_80913E0(struct Item *, u32, struct subStruct_203B240 **); extern void sub_80140B4(struct UnkTextStruct2 *); @@ -83,7 +83,6 @@ extern void sub_801B760(void); extern void sub_801B874(void); extern u32 sub_8001784(u32, u32, u16); extern void sub_800199C(u32, u32, u32, u32); -extern void PlaySound(u32); extern s32 sub_808D544(u32); void sub_801B480(void); diff --git a/src/code_801C620.c b/src/code_801C620.c index e8c56b67..45069161 100644 --- a/src/code_801C620.c +++ b/src/code_801C620.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_80118A4.h" #include "code_801C620.h" #include "constants/item.h" #include "constants/iq_skill.h" @@ -152,7 +153,6 @@ extern void sub_801CC38(void); extern void sub_80140B4(struct UnkTextStruct2 *); extern u32 sub_8097DF0(char *, struct subStruct_203B240 **); extern void sub_8013F84(void); -extern void PlayMenuSoundEffect(u32); extern char * GetIQSkillDescription(u8 r0); extern s32 GetNumAvailableIQSkills(u8 *param_1, s32 pokeIQ); extern char * GetIQSkillName(u8 r0); @@ -170,7 +170,6 @@ void sub_801C6E4(void); void sub_801C848(void); u32 sub_801C308(u8); -extern void PlaySound(u32); void ToggleIQSkill(u8 *param_1, u32 skillIndex); s32 sub_801C390(void); void sub_801C3F8(void); diff --git a/src/code_801D760.c b/src/code_801D760.c index c63394b0..0e10d1d1 100644 --- a/src/code_801D760.c +++ b/src/code_801D760.c @@ -16,6 +16,7 @@ #include "code_800D090.h" #include "menu_input.h" #include "code_8021774.h" +#include "code_80118A4.h" struct unkStruct_203B258 { @@ -31,7 +32,6 @@ extern struct unkStruct_203B258 *gUnknown_203B258; extern struct UnkTextStruct2 gUnknown_80DBF88; extern struct UnkTextStruct2 gUnknown_80DBF70; -extern void PlayMenuSoundEffect(u32); extern void sub_801DB54(); extern void sub_801DBD4(); diff --git a/src/code_801EE10_1.c b/src/code_801EE10_1.c index 0c2e4fa4..af575b31 100644 --- a/src/code_801EE10_1.c +++ b/src/code_801EE10_1.c @@ -8,6 +8,7 @@ #include "text2.h" #include "text_util.h" #include "menu_input.h" +#include "code_80118A4.h" struct unkStruct_203B2AC { @@ -52,7 +53,6 @@ extern bool8 sub_80023E4(u32); extern void sub_808FF20(u32 *, struct PokemonStruct *, bool8); extern void CreatePokemonInfoTabScreen(u32, s16, u32 *, u32 *, u32); extern void sub_802452C(void); -extern void PlayMenuSoundEffect(u32); bool8 ComparePokemonNames(s16 a1, s16 a2); void sub_8024588(void); diff --git a/src/code_801EE10_mid.c b/src/code_801EE10_mid.c index 57157508..4e7dfdaf 100644 --- a/src/code_801EE10_mid.c +++ b/src/code_801EE10_mid.c @@ -11,6 +11,7 @@ #include "sprite.h" #include "code_80130A8.h" #include "code_801EE10_mid.h" +#include "code_80118A4.h" extern struct unkStruct_203B270 *gUnknown_203B270; @@ -56,7 +57,6 @@ extern u8 gAvailablePokemonNames[]; extern u8 gUnknown_80DC310[]; extern u8 gUnknown_80DC2DC[]; -extern void PlayMenuSoundEffect(u32); extern void sub_80140B4(struct UnkTextStruct2 *); extern void sub_801F918(s32); extern void sub_801FA58(void); diff --git a/src/code_8021774.c b/src/code_8021774.c index d7a39a3b..f385b92b 100644 --- a/src/code_8021774.c +++ b/src/code_8021774.c @@ -10,6 +10,7 @@ #include "code_800D090.h" #include "menu_input.h" #include "code_8021774.h" +#include "code_80118A4.h" struct unkStruct_203B28C { @@ -54,7 +55,6 @@ extern void sub_8092578(u8 *buffer, u8 index, u8 r2); extern void sub_8021878(void); extern void sub_8021894(void); -extern void PlayMenuSoundEffect(u32); extern void sub_8021A60(void); void sub_8021820(void); u8 sub_80023E4(u32); diff --git a/src/code_8021774_pre.c b/src/code_8021774_pre.c index 72ceb676..d0e47fff 100644 --- a/src/code_8021774_pre.c +++ b/src/code_8021774_pre.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_80118A4.h" #include "code_801EE10_mid.h" #include "code_8021774_pre.h" #include "constants/friend_area.h" @@ -35,7 +36,6 @@ extern struct UnkTextStruct2 gUnknown_80DC464; u8 sub_8021700(u32 mode); s32 sub_8021664(void); extern void sub_8021410(void); -extern void PlayMenuSoundEffect(u32); bool8 sub_80211AC(u32 param_1, u32 param_2) { diff --git a/src/code_8023144.c b/src/code_8023144.c index b2ebdb39..387a724a 100644 --- a/src/code_8023144.c +++ b/src/code_8023144.c @@ -16,6 +16,7 @@ #include "kecleon_bros.h" #include "code_80130A8.h" #include "code_801B3C0.h" +#include "code_80118A4.h" struct unkStruct_3001B5C { @@ -52,7 +53,6 @@ extern u8 sub_8023704(u8); extern void sub_8023420(void); extern void sub_80234BC(void); extern u32 sub_80236A4(void); -extern void PlayMenuSoundEffect(u32); extern u8 gUnknown_80DC5EC[]; diff --git a/src/code_8031D70.c b/src/code_8031D70.c index 1bde2d79..4f963fbc 100644 --- a/src/code_8031D70.c +++ b/src/code_8031D70.c @@ -9,6 +9,7 @@ #include "pokemon.h" #include "code_8094F88.h" #include "menu_input.h" +#include "code_80118A4.h" struct unkStruct_203B334 { @@ -48,7 +49,6 @@ ALIGNED(4) const u8 gUnknown_80E1FDC[] = "Password"; ALIGNED(4) static const u8 fill0[] = "pksdir0"; extern void sub_803D2C0(u8 *, struct unkStruct_203B480 *); -extern void PlayMenuSoundEffect(u32); void sub_8031E00(void); void sub_8031E58(void); diff --git a/src/code_8040094.c b/src/code_8040094.c index c979d12a..98cf46d1 100644 --- a/src/code_8040094.c +++ b/src/code_8040094.c @@ -1,5 +1,5 @@ #include "global.h" - +#include "code_80118A4.h" #include "code_80521D0.h" #include "dungeon_entity.h" #include "dungeon_global_data.h" @@ -19,7 +19,6 @@ extern void sub_80060EC(void); extern void sub_800CB20(void); extern void LoadBufferedInputs(void); extern void xxx_call_update_bg_sound_input(void); -extern void sub_8011860(void); extern void sub_803F580(u32); extern void sub_8049ED4(); diff --git a/src/dungeon_music.c b/src/dungeon_music.c index da2ea13b..3e5a4b51 100644 --- a/src/dungeon_music.c +++ b/src/dungeon_music.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_80118A4.h" #include "constants/bg_music.h" #include "dungeon.h" #include "music.h" @@ -26,8 +27,6 @@ extern u8 gUnknown_810AC64; // 0x8 extern u8 gUnknown_810AC66; // 0x8 extern void sub_80709C8(u8 *buffer, struct EntityInfo *entityInfo); -void FadeOutAllMusic(u16); -void xxx_call_stop_bgm(void); // Dungeon Music Player adds in this flag to tell // the system to fade in rather than immediately playing diff --git a/src/felicity_bank.c b/src/felicity_bank.c index f48c8f97..b04767e6 100644 --- a/src/felicity_bank.c +++ b/src/felicity_bank.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_80118A4.h" #include "code_80130A8.h" #include "felicity_bank.h" #include "memory.h" @@ -28,7 +29,6 @@ extern u8 gFelicitySavings[]; extern u8 gFelicityMoney[]; extern u8 gUnknown_80DB738; -extern void PlaySound(u32); extern void sub_801645C(); extern void sub_80169BC(); extern void sub_8016B00(); diff --git a/src/friend_area_action_menu_1.c b/src/friend_area_action_menu_1.c index 46df1c08..cb7de6cd 100644 --- a/src/friend_area_action_menu_1.c +++ b/src/friend_area_action_menu_1.c @@ -11,6 +11,7 @@ #include "code_80130A8.h" #include "code_801EE10_1.h" #include "code_801B3C0.h" +#include "code_80118A4.h" extern struct unkStruct_203B2BC *gUnknown_203B2BC; extern struct TeamInventory *gTeamInventoryRef; @@ -19,7 +20,6 @@ extern u32 sub_801EF38(u8 r0); extern void sub_801F214(); extern void SetFriendAreaActionMenuState(u32); -extern void PlaySound(u32); extern void nullsub_104(); extern void sub_8099690(u32); diff --git a/src/friend_list_menu.c b/src/friend_list_menu.c index 2959a375..27405ae4 100644 --- a/src/friend_list_menu.c +++ b/src/friend_list_menu.c @@ -13,6 +13,7 @@ #include "code_801EE10_1.h" #include "code_8012A18_1.h" #include "code_801B3C0.h" +#include "code_80118A4.h" // there might be more overlap with unkStruct_203B2BC // I was working on the moves and put the data that seemed to correspond to that @@ -119,7 +120,6 @@ extern s16 sub_80A5728(void); extern u8 sub_8002658(s16); extern bool8 sub_8024108(u32); extern void sub_801F1B0(u32, u32); -extern void PlaySound(u32); extern void sub_8024458(s16, u32); extern void sub_801BEEC(s16); extern void nullsub_104(void); diff --git a/src/friend_rescue.c b/src/friend_rescue.c index 1a53edce..98021297 100644 --- a/src/friend_rescue.c +++ b/src/friend_rescue.c @@ -20,6 +20,7 @@ #include "code_801C620.h" #include "code_801B3C0.h" #include "cpu.h" +#include "code_80118A4.h" extern void SetFriendRescueMenuState(u32); extern struct PokemonStruct *GetPlayerPokemonStruct(void); @@ -281,7 +282,6 @@ extern void sub_802F2C0(void); extern void sub_8030DE4(void); extern void sub_802453C(void); extern u8 sub_800D588(void); -extern void sub_8011830(void); extern void sub_80151C0(u32, u8 *); extern u32 sub_801D008(void); extern u32 sub_8023CE8(void); @@ -303,8 +303,6 @@ extern struct PokemonStruct *GetPlayerPokemonStruct(void); extern void MemoryFill8(u8 *dest, u8 value, s32 size); extern void ResetUnusedInputStruct(void); extern void sprintfStatic(char *buffer, const char *text, ...); -extern void xxx_call_start_bg_music(void); - u32 CreateFriendRescueMenu(void) { diff --git a/src/ground_main.c b/src/ground_main.c index 6aae8140..ba5fc761 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -4,6 +4,7 @@ #include "debug.h" #include "code_80A26CC.h" #include "event_flag.h" +#include "code_80118A4.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA u32 gUnknown_20398AC = {0}; @@ -49,7 +50,6 @@ extern void sub_809CA20(); extern void sub_80A6E80(); extern void sub_8099BE4(); extern void sub_8099744(); -extern void sub_8011860(); extern void sub_800CB20(); extern void nullsub_120(); extern void sub_80A5E70(); @@ -78,7 +78,6 @@ extern void sub_80961B4(); extern void ClearAllItems_8091FB4(); extern const char *sub_80A2B18(s16); extern void ChooseKecleonShopInventory(u32); -extern void FadeOutAllMusic(u16); extern u8 sub_809C730(); extern s16 sub_80A2750(s16); diff --git a/src/gulpin_shop.c b/src/gulpin_shop.c index 71e8c2c5..e297a0b9 100644 --- a/src/gulpin_shop.c +++ b/src/gulpin_shop.c @@ -1,12 +1,13 @@ #include "global.h" +#include "code_80118A4.h" #include "code_80130A8.h" +#include "gulpin_shop.h" #include "pokemon.h" #include "memory.h" +#include "menu_input.h" #include "moves.h" #include "text1.h" #include "text2.h" -#include "gulpin_shop.h" -#include "menu_input.h" extern struct GulpinShopWork *gGulpinShopWork; extern const struct UnkTextStruct2 gUnknown_80DC11C; @@ -38,7 +39,6 @@ extern void sub_801F280(u32); extern void sub_801F808(u16 *); extern u32 sub_801F890(void); extern void sub_801F8D0(void); -extern void PlaySound(u32); void SetGulpinShopState(u32); u32 CreateGulpinShop(s32 isAsleep, s16 pokeSpecies, struct Move *moves) diff --git a/src/gulpin_shop_1.c b/src/gulpin_shop_1.c index 8ea2ebf1..8ecaf384 100644 --- a/src/gulpin_shop_1.c +++ b/src/gulpin_shop_1.c @@ -11,6 +11,7 @@ #include "felicity_bank.h" #include "code_80130A8.h" #include "code_801EE10_1.h" +#include "code_80118A4.h" // size: 0x1E0 struct unkStruct_203B27C @@ -84,8 +85,6 @@ extern u8 gUnknown_80DC438[]; extern u8 gUnknown_80DC448[]; extern u8 gUnknown_202E128[]; -void PlayMenuSoundEffect(u32); -void PlaySound(u32); bool8 sub_8021178(void); void CreateGulpinShopMenu(void); void sub_8020950(void); diff --git a/src/hints_menu.c b/src/hints_menu.c index a9e4a625..9da423af 100644 --- a/src/hints_menu.c +++ b/src/hints_menu.c @@ -1,9 +1,10 @@ #include "global.h" +#include "code_80118A4.h" #include "memory.h" +#include "menu_input.h" #include "text1.h" #include "text2.h" #include "input.h" -#include "menu_input.h" #define MAX_HINTS 5 @@ -44,7 +45,6 @@ extern struct Hints gGameHints[MAX_HINTS]; extern u8 gUnknown_80DC0D4[MAX_HINTS]; extern void sub_801E714(void); -extern void PlayMenuSoundEffect(u32); extern void sub_801E714(void); extern void sub_801E76C(void); extern void DisplayChosenHint(void); diff --git a/src/kecleon_bros.c b/src/kecleon_bros.c index 5d8fab94..e2105c2e 100644 --- a/src/kecleon_bros.c +++ b/src/kecleon_bros.c @@ -1,5 +1,6 @@ #include "global.h" #include "code_800D090.h" +#include "code_80118A4.h" #include "code_80130A8.h" #include "code_801B3C0.h" #include "constants/input.h" @@ -58,10 +59,6 @@ extern const u8 gTeamToolboxB[]; // code_8098BDC.s extern void sub_8099690(u32); -// code_80118A4.c -extern void PlayMenuSoundEffect(u32); -extern void PlaySound(u16 songIndex); - void sub_8018D30(void); void sub_80194F8(void); void sub_80195C0(void); diff --git a/src/luminous_cave.c b/src/luminous_cave.c index 1e8d92f4..be176ead 100644 --- a/src/luminous_cave.c +++ b/src/luminous_cave.c @@ -14,6 +14,7 @@ #include "code_80130A8.h" #include "code_8012A18_1.h" #include "code_801B3C0.h" +#include "code_80118A4.h" struct unkStruct_203B2B0 { @@ -186,11 +187,7 @@ extern void LuminousCave_AdvancetoFallbackState(void); extern void sub_8024804(void); extern void UpdateLuminousCaveDialogue(void); -void xxx_call_fade_out_bgm(u16 speed); -void xxx_call_stop_fanfare_se(u16 songIndex); -void xxx_call_fade_in_new_bgm(u16 songIndex, u16 speed); void sub_80977D0(void); -void PlaySound(u32); void sub_8024CFC(void); void sub_8025254(void); void sub_8024D48(void); @@ -200,7 +197,6 @@ void sub_8024E30(void); void sub_801AEE4(u32, u32); void sub_808F734(struct PokemonStruct *, s16); extern void sub_8099690(u32); -extern void PlayMenuSoundEffect(u32); extern void sub_808F468(struct PokemonStruct *, u8 *, u32); bool8 LuminousCave_HasOnly1Member(void); diff --git a/src/mailbox.c b/src/mailbox.c index 3b271c27..7fcffdb3 100644 --- a/src/mailbox.c +++ b/src/mailbox.c @@ -7,6 +7,7 @@ #include "mailbox.h" #include "wonder_mail.h" #include "menu_input.h" +#include "code_80118A4.h" EWRAM_DATA_2 struct unkStruct_203B304 *gUnknown_203B304 = {0}; @@ -105,8 +106,6 @@ extern void sub_8096D24(void); extern void ResetMailboxSlot(u8); extern void ReceivePKMNNews(u8); extern void sub_8096078(void); -extern void PlayMenuSoundEffect(u32); -extern void PlaySound(u32); extern void sub_802BEDC(void); extern u8 sub_802BE74(void); extern u8 HasNoAcceptedJobs(void); diff --git a/src/makuhita_dojo.c b/src/makuhita_dojo.c index 959554fc..4062ade0 100644 --- a/src/makuhita_dojo.c +++ b/src/makuhita_dojo.c @@ -1,5 +1,6 @@ #include "global.h" #include "code_800D090.h" +#include "code_80118A4.h" #include "code_80130A8.h" #include "constants/colors.h" #include "constants/input.h" @@ -79,8 +80,6 @@ extern u8 sub_80A2740(s32 r0); extern struct PokemonStruct *GetPlayerPokemonStruct(void); extern bool8 IsMazeCompleted(s32); -extern void PlayMenuSoundEffect(u32); -extern void PlaySound(u16); extern void PrintColoredPokeNameToBuffer(u8 *, struct PokemonStruct *, s32); extern void PrintYellowDungeonNametoBuffer(u8 *, struct DungeonLocation *); diff --git a/src/menu_input.c b/src/menu_input.c index f53a0a5d..df8f4318 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -1,236 +1,228 @@ #include "global.h" +#include "code_800558C_1.h" +#include "code_800D090.h" +#include "code_80118A4.h" +#include "code_80130A8.h" #include "constants/colors.h" #include "constants/input.h" +#include "menu_input.h" +#include "sprite.h" +#include "text_util.h" #include "text1.h" #include "text2.h" #include "util.h" -#include "code_800D090.h" -#include "menu_input.h" -#include "code_80130A8.h" -#include "sprite.h" -extern u8 gUnknown_80D4828[]; +// data_80D47B8.s +extern const u8 gUnknown_80D4828[]; -extern void PlayMenuSoundEffect(u32); +// text.s extern s32 sub_8008ED0(const u8 *); -void sub_8012EBC(struct MenuStruct *param_1); -extern void sub_8013134(struct MenuInputStruct *, u32, u32); extern s16 sub_8009614(u32, u32); -extern u32 ReturnIntFromChar2(u8); -extern void nullsub_7(u16 *); -extern void PlayMenuSoundEffect(u32); -void sub_801332C(s16 *); -void sub_8013470(struct MenuInputStruct *); +static void sub_8013134(struct MenuInputStruct *, u32, u32); +static void sub_801332C(s16 *); +static void sub_8013470(struct MenuInputStruct *); -const u32 gDefaultMenuTextColors[] = { COLOR_WHITE_2, COLOR_RED, COLOR_RED }; +const u32 gDefaultMenuTextColors[3] = { COLOR_WHITE_2, COLOR_RED, COLOR_RED }; u32 sub_8012A64(struct MenuInputStructSub *r0, s32 r1) { - if(r0 == NULL) - { + if (r0 == NULL) return sub_8012AE8(); - } - if(r1 != -1) - { + + if (r1 != -1) nullsub_34(r0); - } - if(r0->a_button != 0) - { + + if (r0->a_button != 0) { r0->a_button = 0; return INPUT_A_BUTTON; } - else if(r0->b_button == 0) - { + + if (r0->b_button == 0) return sub_8012AE8(); - } - else - { - r0->b_button = 0; - return INPUT_B_BUTTON; - } + + r0->b_button = 0; + return INPUT_B_BUTTON; } s32 GetKeyPress(struct MenuInputStruct *r0) { - if(r0 != NULL) - { - if(r0->unk28.a_button != 0) - { + if (r0 != NULL) { + if (r0->unk28.a_button != 0) return INPUT_A_BUTTON; - } - if(r0->unk28.b_button != 0) - { + + if (r0->unk28.b_button != 0) return INPUT_B_BUTTON; - } - if(r0->unk28.dpad_left != 0) - { + + if (r0->unk28.dpad_left != 0) return INPUT_DPAD_LEFT; - } - if(r0->unk28.dpad_right != 0) - { + + if (r0->unk28.dpad_right != 0) return INPUT_DPAD_RIGHT; - } } + return sub_8012AE8(); } s32 sub_8012AE8(void) { - if ((gRealInputs.held & R_BUTTON) != 0) { - if ((gRealInputs.pressed & A_BUTTON) != 0) { - return INPUT_R_A_BUTTONS; + if (gRealInputs.held & R_BUTTON) { + if (gRealInputs.pressed & A_BUTTON) + return INPUT_R_A_BUTTONS; + + if (gRealInputs.repeated & DPAD_UP) + return INPUT_R_DPAD_UP_BUTTONS; + + if (gRealInputs.repeated & DPAD_DOWN) + return INPUT_R_DPAD_DOWN_BUTTONS; + + if (gRealInputs.repeated & DPAD_LEFT) + return INPUT_R_DPAD_LEFT_BUTTONS; + + if (gRealInputs.repeated & DPAD_RIGHT) + return INPUT_R_DPAD_RIGHT_BUTTONS; + + if (gRealInputs.repeated & R_BUTTON) + return INPUT_R_BUTTON; } - if ((gRealInputs.repeated & DPAD_UP) != 0) { - return INPUT_R_DPAD_UP_BUTTONS; + else { + if (gRealInputs.pressed & A_BUTTON) + return INPUT_A_BUTTON; + + if (gRealInputs.pressed & B_BUTTON) + return INPUT_B_BUTTON; + + if (gRealInputs.pressed & SELECT_BUTTON) + return INPUT_SELECT_BUTTON; + + if (gRealInputs.pressed & START_BUTTON) + return INPUT_START_BUTTON; + + if (gRealInputs.repeated & DPAD_UP) + return INPUT_DPAD_UP; + + if (gRealInputs.repeated & DPAD_DOWN) + return INPUT_DPAD_DOWN; + + if (gRealInputs.repeated & DPAD_LEFT) + return INPUT_DPAD_LEFT; + + if (gRealInputs.repeated & DPAD_RIGHT) + return INPUT_DPAD_RIGHT; + + if (gRealInputs.repeated & L_BUTTON) + return INPUT_L_BUTTON; } - if ((gRealInputs.repeated & DPAD_DOWN) != 0) { - return INPUT_R_DPAD_DOWN_BUTTONS; - } - if ((gRealInputs.repeated & DPAD_LEFT) != 0) { - return INPUT_R_DPAD_LEFT_BUTTONS; - } - if ((gRealInputs.repeated & DPAD_RIGHT) != 0) { - return INPUT_R_DPAD_RIGHT_BUTTONS; - } - if ((gRealInputs.repeated & R_BUTTON) != 0) { - return INPUT_R_BUTTON; - } - } - else - { - if ((gRealInputs.pressed & A_BUTTON) != 0) { - return INPUT_A_BUTTON; - } - if ((gRealInputs.pressed & B_BUTTON) != 0) { - return INPUT_B_BUTTON; - } - if ((gRealInputs.pressed & SELECT_BUTTON) != 0) { - return INPUT_SELECT_BUTTON; - } - if ((gRealInputs.pressed & START_BUTTON) != 0) { - return INPUT_START_BUTTON; - } - if ((gRealInputs.repeated & DPAD_UP) != 0) { - return INPUT_DPAD_UP; - } - if ((gRealInputs.repeated & DPAD_DOWN) != 0) { - return INPUT_DPAD_DOWN; - } - if ((gRealInputs.repeated & DPAD_LEFT) != 0) { - return INPUT_DPAD_LEFT; - } - if ((gRealInputs.repeated & DPAD_RIGHT) != 0) { - return INPUT_DPAD_RIGHT; - } - if ((gRealInputs.repeated & L_BUTTON) != 0) { - return INPUT_L_BUTTON; - } - } - return INPUT_NONE; + + return INPUT_NONE; } -void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 param_6) +void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 a5) { - s32 iVar1; - u32 uVar2; - struct unkChar *iVar3; - s32 counter; - s32 *piVar3; - s32 *piVar4; - s32 total_x; - s32 decimal [8]; - - total_x = 0; - ConvertToDecimal(decimal,n,len); - counter = len - 1; - if (0 < counter) { - piVar3 = &decimal[counter]; - if(*piVar3 == 0) - { - do { - *piVar3 = 0xff; - piVar3--; - counter--; - if (counter <= 0) break; - } while(*piVar3 == 0); - } - } + s32 iVar1; + u32 uVar2; + struct unkChar *iVar3; + s32 counter; + s32 *piVar3; + s32 *piVar4; + s32 total_x; + s32 decimal[8]; - counter = 0; - if ((counter < len) && (decimal[0] != 0xFF)) { - piVar4 = &decimal[0]; - do { - iVar1 = *piVar4; - piVar4++; - uVar2 = ReturnIntFromChar2(iVar1 + 0x30); - iVar3 = GetCharacter(uVar2); - total_x += iVar3->unk6; - xxx_call_draw_char(x - total_x,y,uVar2,color,param_6); - counter++; - if (counter >= len) { - break; - } - } while (*piVar4 != 0xff); - } + total_x = 0; + + ConvertToDecimal(decimal, n, len); + + counter = len - 1; + if (counter > 0) { + piVar3 = &decimal[counter]; + if (*piVar3 == 0) { + do { + *piVar3 = 0xFF; + piVar3--; + counter--; + if (counter <= 0) + break; + } while(*piVar3 == 0); + } + } + + counter = 0; + if (counter < len && decimal[0] != 0xFF) { + piVar4 = &decimal[0]; + do { + iVar1 = *piVar4; + piVar4++; + uVar2 = ReturnIntFromChar2(iVar1 + 0x30); + iVar3 = GetCharacter(uVar2); + total_x += iVar3->unk6; + xxx_call_draw_char(x - total_x, y, uVar2, color, a5); + counter++; + if (counter >= len) + break; + } while (*piVar4 != 0xff); + } } -void sub_8012C60(u32 x,u32 y,u32 param_3,u32 color,u32 param_5) +void sub_8012C60(u32 x, u32 y, u32 a2, u32 color, u32 a4) { - u32 add_x; - struct unkChar *iVar3; - u32 uVar2; - - uVar2 = ReturnIntFromChar2(param_3); - iVar3 = GetCharacter(uVar2); - if (iVar3->unk6 < 0xc) { - add_x = ((0xc - iVar3->unk6) / 2); - } - else { - add_x = 0; - } - xxx_call_draw_char(x + add_x,y,uVar2,color,param_5); + u32 add_x; + struct unkChar *iVar3; + u32 uVar2; + + uVar2 = ReturnIntFromChar2(a2); + iVar3 = GetCharacter(uVar2); + + if (iVar3->unk6 < 12) + add_x = ((12 - iVar3->unk6) / 2); + else + add_x = 0; + + xxx_call_draw_char(x + add_x, y, uVar2, color, a4); } -void sub_8012CAC(struct UnkTextStruct2 *param_1, const struct MenuItem *param_2) +void sub_8012CAC(struct UnkTextStruct2 *a0, const struct MenuItem *a1) { - s16 length; - int r5; - int r6; - int r7; - s32 iVar4; -#ifndef NONMATCHING - register s32 r0 asm("r0"); -#else - s32 r0; -#endif - - r7 = 0; - r6 = 0; - if (param_2->text != NULL) { - r5 = 0x10000; - r0 = r5; - do { - r0 = r5; - r5 = r5 + 0x10000; - r7 = r0 >> 0x10; - length = sub_8008ED0(param_2->text); - if (length > r6) { - r6 = length; - } - param_2++; - } while (param_2->text != NULL); - } - if (r6 < 0) - iVar4 = r6 + 7; - else - iVar4 = r6; - param_1->unkC = (iVar4 >> 3) + 2; - sub_8012D08(param_1, r7); + s16 length; + int r5; + int r6; + int r7; + s32 iVar4; + #ifndef NONMATCHING + register s32 r0 asm("r0"); + #else + s32 r0; + #endif + + r7 = 0; + r6 = 0; + + if (a1->text != NULL) { + r5 = 0x10000; // s16 memes? + r0 = r5; + do { + r0 = r5; + r5 = r5 + 0x10000; + r7 = r0 >> 0x10; + length = sub_8008ED0(a1->text); + + if (length > r6) + r6 = length; + + a1++; + } while (a1->text != NULL); + } + + if (r6 < 0) + iVar4 = r6 + 7; + else + iVar4 = r6; + + a0->unkC = (iVar4 >> 3) + 2; + sub_8012D08(a0, r7); } NAKED -void sub_8012D08(struct UnkTextStruct2 *param_1, s32 param_2) +void sub_8012D08(struct UnkTextStruct2 *a0, s32 a1) { asm_unified( "\tpush {r4,lr}\n" @@ -258,7 +250,7 @@ void sub_8012D08(struct UnkTextStruct2 *param_1, s32 param_2) // https://decomp.me/scratch/QadfW (200 - 90% matched) - Seth NAKED -void sub_8012D34(struct UnkTextStruct2 *param_1, s32 param_2) +void sub_8012D34(struct UnkTextStruct2 *a0, s32 a1) { asm_unified( "\tpush {r4,lr}\n" @@ -284,96 +276,99 @@ void sub_8012D34(struct UnkTextStruct2 *param_1, s32 param_2) "\tbx r0"); } -void sub_8012D60(struct MenuStruct *param_1,const struct MenuItem *menuItems,u32 *colorArray,u16 *param_4,s32 menuAction, - s32 index) +void sub_8012D60(struct MenuStruct *param_1, const struct MenuItem *menuItems, u32 *colorArray, u16 *param_4, s32 menuAction, s32 index) { - const u8 *textPtr; - s32 counter; - s32 menuIndex; - s32 iVar1; - - counter = 0; - menuIndex = -1; - iVar1 = 0; - param_1->index = index; - param_1->menuItems = menuItems; - param_1->menuTextColorArray = colorArray; - if (colorArray == NULL) { - param_1->menuTextColorArray = gDefaultMenuTextColors; - } - param_1->unkC = param_4; - textPtr = menuItems->text; - if(textPtr) - { - while (textPtr != 0) { - if ((0 <= menuAction) && (menuAction == menuItems->menuAction)) { - menuIndex = counter; + const u8 *textPtr; + s32 counter; + s32 menuIndex; + s32 iVar1; + + counter = 0; + menuIndex = -1; + iVar1 = 0; + param_1->index = index; + param_1->menuItems = menuItems; + param_1->menuTextColorArray = colorArray; + + if (colorArray == NULL) + param_1->menuTextColorArray = gDefaultMenuTextColors; + + param_1->unkC = param_4; + textPtr = menuItems->text; + + if (textPtr) { + while (textPtr != 0) { + if (menuAction >= 0 && menuAction == menuItems->menuAction) + menuIndex = counter; + + if (*menuItems->text == '*') + iVar1 = counter; + + menuItems++; + counter++; + textPtr = menuItems->text; } - if (*menuItems->text == '*') { - iVar1 = counter; - } - menuItems++; - counter++; - textPtr = menuItems->text; - } - } - if (menuIndex < 0) { - menuIndex = iVar1; - } - sub_8013134(¶m_1->input,counter,index); - param_1->input.menuIndex = menuIndex; - sub_80137B0(¶m_1->input,0); - param_1->unk4C = TRUE; - param_1->unk4D = TRUE; - param_1->unk4E = TRUE; - param_1->menuAction = -1; + } + + if (menuIndex < 0) + menuIndex = iVar1; + + sub_8013134(¶m_1->input, counter, index); + param_1->input.menuIndex = menuIndex; + sub_80137B0(¶m_1->input, 0); + + param_1->unk4C = TRUE; + param_1->unk4D = TRUE; + param_1->unk4E = TRUE; + param_1->menuAction = -1; } -void sub_8012E04(struct MenuStruct *param_1,const struct MenuItem *menuItems,u32 *colorArray,u16 *param_4,s32 menuAction, - s32 index) +void sub_8012E04(struct MenuStruct *param_1, const struct MenuItem *menuItems, u32 *colorArray, u16 *param_4, s32 menuAction, s32 index) { - const u8 *textPtr; - s32 counter; - const struct MenuItem *menuItemPtr; - s32 iVar1; - s32 menuIndex; - - counter = 0; - menuIndex = -1; - iVar1 = 0; - textPtr = menuItems->text; - if (textPtr) { - menuItemPtr = menuItems; - while (textPtr != NULL) { - if ((0 <= menuAction) && (menuAction == menuItemPtr->menuAction)) { - menuIndex = counter; - } - if (*menuItemPtr->text == '*') { - iVar1 = counter; - } - menuItemPtr++; - counter++; - textPtr = menuItemPtr->text; + const u8 *textPtr; + s32 counter; + const struct MenuItem *menuItemPtr; + s32 iVar1; + s32 menuIndex; + + counter = 0; + menuIndex = -1; + iVar1 = 0; + textPtr = menuItems->text; + + if (textPtr) { + menuItemPtr = menuItems; + while (textPtr != NULL) { + if (menuAction >= 0 && menuAction == menuItemPtr->menuAction) + menuIndex = counter; + + if (*menuItemPtr->text == '*') + iVar1 = counter; + + menuItemPtr++; + counter++; + textPtr = menuItemPtr->text; + } } - } - - if (menuIndex < 0) { - menuIndex = iVar1; - } - sub_8013134(¶m_1->input,counter,index); - param_1->input.menuIndex = menuIndex; - sub_80137B0(¶m_1->input,0); - param_1->index = index; - param_1->menuTextColorArray = colorArray; - if (colorArray == NULL) { - param_1->menuTextColorArray = gDefaultMenuTextColors; - } - param_1->unkC = param_4; - param_1->menuItems = menuItems; - param_1->unk4E = FALSE; - param_1->unk4C = TRUE; - param_1->unk4D = TRUE; - param_1->menuAction = -1; + + if (menuIndex < 0) + menuIndex = iVar1; + + sub_8013134(¶m_1->input, counter, index); + param_1->input.menuIndex = menuIndex; + sub_80137B0(¶m_1->input, 0); + + param_1->index = index; + param_1->menuTextColorArray = colorArray; + if (colorArray == NULL) + param_1->menuTextColorArray = gDefaultMenuTextColors; + + param_1->unkC = param_4; + param_1->menuItems = menuItems; + param_1->unk4E = FALSE; + param_1->unk4C = TRUE; + param_1->unk4D = TRUE; + param_1->menuAction = -1; } void sub_8012EA4(struct MenuStruct *param_1, bool8 r1) @@ -385,173 +380,169 @@ void sub_8012EA4(struct MenuStruct *param_1, bool8 r1) void sub_8012EBC(struct MenuStruct *param_1) { - s32 x; - s32 y; - u32 color; - const u8 *textPtr; - const struct MenuItem *menuItemsPtr; - u16 *_puVar2; - const u32 *colorArray; - s32 counter; - s32 index; - struct UnkTextStruct2 textStack[4]; - u8 buffer [256]; - struct UnkTextStruct1 *ptr_text; - struct UnkTextStruct2 *ptr_text2; - - if (param_1->unk4D) { - sub_80073B8(param_1->index); - index = param_1->index; - ptr_text = &gUnknown_2027370[index]; - if ((ptr_text->unkC) == 6) { - ptr_text2 = &textStack[index]; - sub_8006518(textStack); - x = sub_8008ED0(param_1->unk0); - xxx_format_and_draw((((ptr_text2->unk14[2]) * 8 - x) /2) + 8, - 0,param_1->unk0, param_1->index, 0); - } - colorArray = param_1->menuTextColorArray; - menuItemsPtr = param_1->menuItems; - _puVar2 = param_1->unkC; - counter = 0; - if (menuItemsPtr->text != NULL) { - do { - textPtr = menuItemsPtr->text; - if (*textPtr == '*') { - textPtr++; + s32 x; + s32 y; + u32 color; + const u8 *textPtr; + const struct MenuItem *menuItemsPtr; + u16 *_puVar2; + const u32 *colorArray; + s32 counter; + s32 index; + struct UnkTextStruct2 textStack[4]; + u8 buffer[256]; + struct UnkTextStruct1 *ptr_text; + struct UnkTextStruct2 *ptr_text2; + + if (param_1->unk4D) { + sub_80073B8(param_1->index); + index = param_1->index; + ptr_text = &gUnknown_2027370[index]; + + if (ptr_text->unkC == 6) { + ptr_text2 = &textStack[index]; + sub_8006518(textStack); + x = sub_8008ED0(param_1->unk0); + xxx_format_and_draw(((ptr_text2->unk14[2] * 8 - x) / 2) + 8, 0, param_1->unk0, param_1->index, 0); } - if (_puVar2 != NULL) { - color = colorArray[*_puVar2]; - _puVar2++; + + colorArray = param_1->menuTextColorArray; + menuItemsPtr = param_1->menuItems; + _puVar2 = param_1->unkC; + counter = 0; + + if (menuItemsPtr->text != NULL) { + do { + textPtr = menuItemsPtr->text; + if (*textPtr == '*') + textPtr++; + + if (_puVar2 != NULL) { + color = colorArray[*_puVar2]; + _puVar2++; + } + else if (menuItemsPtr->menuAction < 0) + color = colorArray[1]; // Color the action red + else + color = colorArray[0]; // Use the default white + + sprintfStatic(buffer,gUnknown_80D4828, color, textPtr); + y = sub_8013800(¶m_1->input, counter); + xxx_format_and_draw(8, y, buffer, param_1->index, 0); + menuItemsPtr++; + counter++; + } while (menuItemsPtr->text != NULL); } - else if (menuItemsPtr->menuAction < 0) { - // Color the action red - color = colorArray[1]; - } - else { - // Use the default white - color = colorArray[0]; - } - sprintfStatic(buffer,gUnknown_80D4828,color,textPtr); - y = sub_8013800(¶m_1->input,counter); - xxx_format_and_draw(8,y,buffer,param_1->index,0); - menuItemsPtr++; - counter++; - } while (menuItemsPtr->text != NULL); + + sub_80073E0(param_1->index); + param_1->unk4D = FALSE; } - sub_80073E0(param_1->index); - param_1->unk4D = FALSE; - } - if (param_1->unk4E) { - if (param_1->unk4C) { - AddMenuCursorSprite(¶m_1->input); + + if (param_1->unk4E) { + if (param_1->unk4C) + AddMenuCursorSprite(¶m_1->input); + else + sub_8013660(¶m_1->input); } - else { - sub_8013660(¶m_1->input); - } - } } bool8 sub_8012FD8(struct MenuStruct *param_1) { - u32 prevMenuIndex; - s32 index; - const struct MenuItem *item; - - prevMenuIndex = param_1->input.menuIndex; - if (param_1->unk4C) { - switch(GetKeyPress(¶m_1->input)) - { - case INPUT_DPAD_DOWN: - MoveMenuCursorDown(¶m_1->input); - if (prevMenuIndex != param_1->input.menuIndex) { - PlayMenuSoundEffect(3); - } - break; - case INPUT_DPAD_UP: - MoveMenuCursorUp(¶m_1->input); - if (prevMenuIndex != param_1->input.menuIndex) { - PlayMenuSoundEffect(3); - } - break; - case INPUT_A_BUTTON: - index = sub_80137A8(¶m_1->input); - item = ¶m_1->menuItems[index]; - if ((-1 < item->menuAction) && - ((param_1->unkC == NULL || (param_1->unkC[index] != 1)))) { - param_1->menuAction = item->menuAction; - ++param_1; --param_1; - param_1->unk4C = FALSE; - param_1->input.unk24 = 0; - } - else - { - PlayMenuSoundEffect(2); + u32 prevMenuIndex; + s32 index; + const struct MenuItem *item; + + prevMenuIndex = param_1->input.menuIndex; + + if (param_1->unk4C) { + switch (GetKeyPress(¶m_1->input)) { + case INPUT_DPAD_DOWN: + MoveMenuCursorDown(¶m_1->input); + if (prevMenuIndex != param_1->input.menuIndex) + PlayMenuSoundEffect(3); break; - } - if ((param_1->unkC != NULL) && (param_1->unkC[index] == 2)) { - PlayMenuSoundEffect(2); - } - else - PlayMenuSoundEffect(0); - break; - case INPUT_B_BUTTON: - if (-1 < param_1->menuItems[param_1->input.unk1A].menuAction) { - param_1->menuAction = param_1->menuItems[param_1->input.unk1A].menuAction; - param_1->unk4C = FALSE; - PlayMenuSoundEffect(1); - } - break; + case INPUT_DPAD_UP: + MoveMenuCursorUp(¶m_1->input); + if (prevMenuIndex != param_1->input.menuIndex) + PlayMenuSoundEffect(3); + break; + case INPUT_A_BUTTON: + index = sub_80137A8(¶m_1->input); + item = ¶m_1->menuItems[index]; + + if (item->menuAction > -1 && (param_1->unkC == NULL || param_1->unkC[index] != 1)) { + param_1->menuAction = item->menuAction; + ++param_1; --param_1; + param_1->unk4C = FALSE; + param_1->input.unk24 = 0; + } + else { + PlayMenuSoundEffect(2); + break; + } + + if (param_1->unkC != NULL && param_1->unkC[index] == 2) + PlayMenuSoundEffect(2); + else + PlayMenuSoundEffect(0); + break; + case INPUT_B_BUTTON: + if (param_1->menuItems[param_1->input.unk1A].menuAction > -1) { + param_1->menuAction = param_1->menuItems[param_1->input.unk1A].menuAction; + param_1->unk4C = FALSE; + PlayMenuSoundEffect(1); + } + break; + } } - } - sub_8012EBC(param_1); - return param_1->unk4C; + + sub_8012EBC(param_1); + return param_1->unk4C; } bool8 sub_80130A8(struct MenuStruct *param_1) { - s32 index; - s32 menuAction; - const struct MenuItem *menuItem; - - if (param_1->unk4C) { + s32 index; + const struct MenuItem *menuItem; - switch(GetKeyPress(¶m_1->input)) - { - case INPUT_A_BUTTON: - index = sub_80137A8(¶m_1->input); - menuItem = ¶m_1->menuItems[index]; - param_1->menuAction = menuItem->menuAction; - param_1->unk4C = FALSE; - param_1->input.unk24 = 0; - PlayMenuSoundEffect(0); - break; - case INPUT_B_BUTTON: - if(menuAction = param_1->menuItems[param_1->input.unk1A].menuAction, -1 < menuAction) { - param_1->menuAction = menuAction; - param_1->unk4C = FALSE; - PlayMenuSoundEffect(0); - } - break; + if (param_1->unk4C) { + switch (GetKeyPress(¶m_1->input)) + { + case INPUT_A_BUTTON: + index = sub_80137A8(¶m_1->input); + menuItem = ¶m_1->menuItems[index]; + param_1->menuAction = menuItem->menuAction; + param_1->unk4C = FALSE; + param_1->input.unk24 = 0; + PlayMenuSoundEffect(0); + break; + case INPUT_B_BUTTON: + if (param_1->menuItems[param_1->input.unk1A].menuAction > -1) { + param_1->menuAction = param_1->menuItems[param_1->input.unk1A].menuAction; + param_1->unk4C = FALSE; + PlayMenuSoundEffect(0); + } + break; + } } - } - sub_8012EBC(param_1); - return param_1->unk4C; + + sub_8012EBC(param_1); + return param_1->unk4C; } bool8 sub_8013114(struct MenuStruct *param_1, s32 *menuAction) { - if(param_1->unk4C){ + if (param_1->unk4C) return TRUE; - } - if (menuAction != NULL){ + + if (menuAction != NULL) *menuAction = param_1->menuAction; - } + return FALSE; } -void sub_8013134(struct MenuInputStruct *param_1, u32 menuItemCounter, u32 index) { - +static void sub_8013134(struct MenuInputStruct *param_1, u32 menuItemCounter, u32 index) +{ struct UnkTextStruct1 *temp; temp = &gUnknown_2027370[index]; @@ -563,15 +554,10 @@ void sub_8013134(struct MenuInputStruct *param_1, u32 menuItemCounter, u32 index param_1->unk1E = 0; param_1->unk4 = 0; - if(temp->unkC == 6) - { - param_1->unk6 = 0x10; - } + if (temp->unkC == 6) + param_1->unk6 = 16; else - { - param_1->unk6 = 0x2; - } - + param_1->unk6 = 2; param_1->unkC = 0; param_1->unkE = 0; @@ -681,7 +667,7 @@ void nullsub_34(struct MenuInputStructSub *a0) } // Maybe struct Position -void sub_801332C(s16 *a0) +static void sub_801332C(s16 *a0) { struct SpriteOAM sp = {}; struct SpriteOAM* ptr; @@ -747,7 +733,7 @@ void sub_801332C(s16 *a0) AddSprite(&sp, 0xFF, NULL, NULL); } -void sub_8013470(struct MenuInputStruct *a0) +static void sub_8013470(struct MenuInputStruct *a0) { struct SpriteOAM sp = {}; register struct SpriteOAM* ptr asm("r3"); @@ -873,8 +859,7 @@ void sub_8013470(struct MenuInputStruct *a0) void sub_8013660(struct MenuInputStruct *param_1) { - if (0 < param_1->unk1A) - { + if (0 < param_1->unk1A) { UpdateMenuCursorSpriteCoords(param_1); sub_801332C(¶m_1->unk8); } @@ -894,33 +879,31 @@ void UpdateMenuCursorSpriteCoords(struct MenuInputStruct *param_1) void MoveMenuCursorDown(struct MenuInputStruct *param_1) { param_1->unk24 = 0; - if (param_1->unk1A < 1) { + + if (param_1->unk1A < 1) param_1->menuIndex = 0; - } else { param_1->menuIndex++; - if (param_1->menuIndex >= param_1->unk1A) { + + if (param_1->menuIndex >= param_1->unk1A) param_1->menuIndex = 0; - } } } void sub_80136E0(struct MenuInputStruct *param_1, u8 param_2) { param_1->unk24 = 0; - if (param_1->unk1A < 1) { + + if (param_1->unk1A < 1) param_1->menuIndex = 0; - } else { param_1->menuIndex++; + if (param_1->menuIndex >= param_1->unk1A) { - if (param_2 != 0) { - param_1->menuIndex = 0; - } + if (param_2 != 0) + param_1->menuIndex = 0; else - { param_1->menuIndex = param_1->unk1A - 1; - } } } } @@ -928,47 +911,44 @@ void sub_80136E0(struct MenuInputStruct *param_1, u8 param_2) void MoveMenuCursorUp(struct MenuInputStruct *param_1) { param_1->unk24 = 0; - if (param_1->unk1A < 1) { + + if (param_1->unk1A < 1) param_1->menuIndex = 0; - } else { param_1->menuIndex--; - if (param_1->menuIndex < 0) { - param_1->menuIndex = param_1->unk1A + -1; - } + + if (param_1->menuIndex < 0) + param_1->menuIndex = param_1->unk1A - 1; } } void sub_8013744(struct MenuInputStruct *param_1, u8 param_2) { param_1->unk24 = 0; - if (param_1->unk1A < 1) { + + if (param_1->unk1A < 1) param_1->menuIndex = 0; - } else { param_1->menuIndex--; + if (param_1->menuIndex < 0) { - if (param_2 != 0) { - param_1->menuIndex = param_1->unk1A + -1; - } - else { + if (param_2 != 0) + param_1->menuIndex = param_1->unk1A - 1; + else param_1->menuIndex = 0; - } } } } void sub_8013780(struct MenuInputStruct *param_1, s32 param_2) { - if (param_2 < 0) { + if (param_2 < 0) param_1->menuIndex = 0; - } - else if (param_2 >= param_1->unk1A) { + else if (param_2 >= param_1->unk1A) param_1->menuIndex = param_1->unk1A - 1; - } - else { + else param_1->menuIndex = param_2; - } + param_1->unk24 = 0; } @@ -986,22 +966,18 @@ void sub_80137B0(struct MenuInputStruct *param_1, s32 param_2) s32 iVar2; #endif - if (param_2 >= 1) { + if (param_2 >= 1) iVar2 = param_2 << 8; - } - else - { + else { if (gUnknown_2027370[param_1->unk0].unkC == 6) - { - iVar1 = 0x10; - } + iVar1 = 16; else - { iVar1 = 0; - } - iVar2 = (gUnknown_2027370[param_1->unk0].unk6 * 8 - iVar1); + + iVar2 = gUnknown_2027370[param_1->unk0].unk6 * 8 - iVar1; iVar2 <<= 8; } + param_1->unk10 = iVar2 / param_1->unk1C; } @@ -1017,10 +993,10 @@ s32 sub_8013800(struct MenuInputStruct *param_1, s32 param_2) iVar2 = param_1->unk6; iVar1 = param_2 * param_1->unk10; - if (iVar1 < 0) { + if (iVar1 < 0) iVar1 = iVar1 + 0xff; - } - return (iVar2 + (iVar1 >> 8)); + + return iVar2 + (iVar1 >> 8); } void sub_8013818(struct MenuInputStruct *param_1, s32 param_2, u32 param_3, s32 param_4) @@ -1032,9 +1008,10 @@ void sub_8013818(struct MenuInputStruct *param_1, s32 param_2, u32 param_3, s32 param_1->unk24 = 0; param_1->menuIndex = 0; param_1->unk1E = 0; + sub_801317C(¶m_1->unk28); sub_8013984(param_1); - sub_80137F8(param_1,0xC); + sub_80137F8(param_1, 12); } @@ -1047,19 +1024,19 @@ void sub_8013848(struct MenuInputStruct *param_1, s32 param_2, u32 param_3, s32 param_1->unk24 = 0; param_1->menuIndex = 0; param_1->unk1E = 0; + sub_801317C(¶m_1->unk28); sub_8013984(param_1); - sub_80137F8(param_1,0x18); + sub_80137F8(param_1, 24); } void sub_8013878(struct MenuInputStruct *param_1, s32 param_2) { - if (param_2 < 0) { + if (param_2 < 0) param_2 = 0; - } - else if (param_2 >= param_1->unk22) { - param_2 = param_1->unk22 + -1; - } + else if (param_2 >= param_1->unk22) + param_2 = param_1->unk22 - 1; + param_1->unk1E = param_2 / param_1->unk1C; param_1->menuIndex = param_2 % param_1->unk1C; param_1->unk24 = 0; @@ -1074,18 +1051,17 @@ bool8 sub_80138B8(struct MenuInputStruct *param_1, bool8 param_2) sVar1 = param_1->unk1E; oldIndex = param_1->menuIndex; AddMenuCursorSprite(param_1); - if(param_2) - { - switch(GetKeyPress(param_1)) - { + + if (param_2) { + switch (GetKeyPress(param_1)) { case INPUT_DPAD_UP: MoveMenuCursorUp(param_1); - if(oldIndex != param_1->menuIndex) + if (oldIndex != param_1->menuIndex) PlayMenuSoundEffect(3); break; case INPUT_DPAD_DOWN: MoveMenuCursorDown(param_1); - if(oldIndex != param_1->menuIndex) + if (oldIndex != param_1->menuIndex) PlayMenuSoundEffect(3); break; case INPUT_DPAD_LEFT: @@ -1096,14 +1072,12 @@ bool8 sub_80138B8(struct MenuInputStruct *param_1, bool8 param_2) break; } } + if (sVar1 != param_1->unk1E) { PlayMenuSoundEffect(4); return TRUE; } - else - { - return FALSE; - } + return FALSE; } bool8 sub_8013938(struct MenuInputStruct *param_1) @@ -1114,8 +1088,8 @@ bool8 sub_8013938(struct MenuInputStruct *param_1) param_1->unk1A = 0; param_1->unk14 = 0; AddMenuCursorSprite(param_1); - switch(GetKeyPress(param_1)) - { + + switch (GetKeyPress(param_1)) { case INPUT_DPAD_LEFT: sub_8013A7C(param_1); break; @@ -1123,17 +1097,15 @@ bool8 sub_8013938(struct MenuInputStruct *param_1) sub_8013A54(param_1); break; } + if (sVar1 != param_1->unk1E) { PlayMenuSoundEffect(4); return TRUE; } - else - { - return FALSE; - } + return FALSE; } -void sub_8013984(struct MenuInputStruct * param_1) +void sub_8013984(struct MenuInputStruct *param_1) { s32 iVar2; s32 iVar4; @@ -1141,64 +1113,57 @@ void sub_8013984(struct MenuInputStruct * param_1) iVar4 = param_1->unk0; ptr = &gUnknown_2027370[iVar4]; - if (param_1->unk1C == 0) { + + if (param_1->unk1C == 0) param_1->unk1C++; - } + param_1->unk20 = param_1->unk22 / param_1->unk1C; - iVar2 = (param_1->unk22 % param_1->unk1C); - if (iVar2 != 0) { + iVar2 = param_1->unk22 % param_1->unk1C; + if (iVar2 != 0) param_1->unk20++; - } - if (param_1->unk1E > param_1->unk20 - 1) { + + if (param_1->unk1E > param_1->unk20 - 1) param_1->unk1E = param_1->unk20 - 1; - } - if ((param_1->unk1E != param_1->unk20 - 1) || (param_1->unk22 % param_1->unk1C == 0)) - { + + if (param_1->unk1E != param_1->unk20 - 1 || param_1->unk22 % param_1->unk1C == 0) param_1->unk1A = param_1->unk1C; - } else - { param_1->unk1A = param_1->unk22 % param_1->unk1C; - } - if (param_1->menuIndex > param_1->unk1A - 1) { + + if (param_1->menuIndex > param_1->unk1A - 1) param_1->menuIndex = param_1->unk1A - 1; - } + param_1->unk4 = 0; - if (ptr->unkC == 6) { - param_1->unk6 = 0x10; - } - else { + + if (ptr->unkC == 6) + param_1->unk6 = 16; + else param_1->unk6 = 0; - } - if (param_1->unk20 < 2) { + + if (param_1->unk20 < 2) param_1->unkC = 0; - } - else { - param_1->unkC = (ptr->unk0 + ptr->unk4 + -2) * 8; - } - param_1->unkE = ((ptr->unk2) + 1) * 8 + -2; + else + param_1->unkC = (ptr->unk0 + ptr->unk4 - 2) * 8; + + param_1->unkE = (ptr->unk2 + 1) * 8 - 2; } void sub_8013A54(struct MenuInputStruct *param_1) { - if (param_1->unk1E < param_1->unk20 - 1) { - param_1->unk1E++; - } - else - { - param_1->unk1E = 0; - } - sub_8013984(param_1); + if (param_1->unk1E < param_1->unk20 - 1) + param_1->unk1E++; + else + param_1->unk1E = 0; + + sub_8013984(param_1); } void sub_8013A7C(struct MenuInputStruct *param_1) { - if (param_1->unk1E < 1) { - param_1->unk1E = param_1->unk20 - 1; - } - else - { - param_1->unk1E--; - } - sub_8013984(param_1); + if (param_1->unk1E < 1) + param_1->unk1E = param_1->unk20 - 1; + else + param_1->unk1E--; + + sub_8013984(param_1); } diff --git a/src/options_menu.c b/src/options_menu.c index 9008e8ed..fcf30691 100644 --- a/src/options_menu.c +++ b/src/options_menu.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_80118A4.h" #include "code_80130A8.h" #include "constants/colors.h" #include "constants/input.h" @@ -54,7 +55,6 @@ extern const char *gUnknown_80D4928[]; extern s32 sub_8008ED0(u8 *); extern void CreateOthersMenu(void); -void PlayMenuSoundEffect(u32); void CreateOptionsMenu(void); void nullsub_38(void); extern void SetOptionsMenuState(u32); diff --git a/src/other_menus.c b/src/other_menus.c index 1e6d4373..5057077c 100644 --- a/src/other_menus.c +++ b/src/other_menus.c @@ -12,6 +12,7 @@ #include "pokemon.h" #include "code_8094F88.h" #include "sprite.h" +#include "code_80118A4.h" struct unkStruct_203B35C { @@ -444,7 +445,6 @@ extern u32 sub_8037C10(u32); extern void sub_8037748(void); extern void sub_80371B8(void); extern void sub_8037900(void); -extern void PlayMenuSoundEffect(u32); extern u32 sub_8037798(void); extern void sub_8005838(u32, u32); extern void sub_80060EC(); @@ -456,11 +456,9 @@ extern void xxx_call_update_bg_sound_input(); extern s32 sub_8037D64(u32 mode, void *, void *); extern s32 sub_80381F4(u32 mode, void *, void *); extern void sub_8037810(void); -extern void sub_8011830(void); extern s32 sub_8037B28(u32); s32 sub_8035D3C(void); extern s32 sub_8035D74(void); -extern void xxx_call_start_bg_music(void); extern void xxx_draw_string_80144C4(void); void sub_8036FDC(s32 param_1) diff --git a/src/party_list_menu.c b/src/party_list_menu.c index 6399ab55..ca0a365e 100644 --- a/src/party_list_menu.c +++ b/src/party_list_menu.c @@ -14,6 +14,7 @@ #include "kecleon_bros.h" #include "code_80130A8.h" #include "code_801B3C0.h" +#include "code_80118A4.h" struct unkStruct_203B2B8 { @@ -163,7 +164,6 @@ ALIGNED(4) static const u8 fill0[] = "pksdir0"; extern u32 sub_8026F04(struct PokemonStruct *); extern void sub_8026074(s32); -extern void PlaySound(u32); bool8 CanTakePokemonHeldItem(struct PokemonStruct *r0); extern bool8 sub_80023E4(u8); extern struct PokemonStruct *sub_808D3F8(void); diff --git a/src/pelipper_board.c b/src/pelipper_board.c index 73fa6745..0ba24684 100644 --- a/src/pelipper_board.c +++ b/src/pelipper_board.c @@ -11,6 +11,7 @@ #include "menu_input.h" #include "team_inventory.h" #include "pelipper_board.h" +#include "code_80118A4.h" EWRAM_DATA_2 struct unkStruct_203B308 *gPelipperBoard = {0}; @@ -92,7 +93,6 @@ extern void ResetPelipperBoardSlot(u8); extern void sub_80965F4(void); extern void sub_802C2D4(void); extern u32 sub_802C1E4(u32); -extern void PlaySound(u32); extern u8 sub_802C26C(void); extern u8 HasNoAcceptedJobs(void); extern bool8 IsMailinJobSlot(struct WonderMail *mail); diff --git a/src/personality_test.c b/src/personality_test.c index 8589aaf7..c0537584 100644 --- a/src/personality_test.c +++ b/src/personality_test.c @@ -14,6 +14,7 @@ #include "menu_input.h" #include "code_80130A8.h" #include "code_8012A18_1.h" +#include "code_80118A4.h" enum { @@ -50,8 +51,6 @@ extern void SetBGPaletteBufferColorArray(s32 index, u8 *colorArray); extern void RedrawPartnerSelectionMenu(void); -extern void PlayMenuSoundEffect(u32); - extern u32 sub_80095E4(s16, u32); extern struct GameOptions *gGameOptionsRef; diff --git a/src/pokemon_news.c b/src/pokemon_news.c index c605d89d..b53bcd2b 100644 --- a/src/pokemon_news.c +++ b/src/pokemon_news.c @@ -8,6 +8,7 @@ #include "save.h" #include "menu_input.h" #include "code_80130A8.h" +#include "code_80118A4.h" struct unkStruct_203B2CC { @@ -153,7 +154,6 @@ extern u16 gUnknown_203B2DC; extern s32 GetNumPKMNNews(void); extern void sub_802B880(void); extern void CreatePKMNNewsMenu(void); -extern void PlayMenuSoundEffect(u32); extern void sub_802BCC4(void); extern void sub_802BB14(u32); extern u8 HasNoMailinMailbox(void); diff --git a/src/post_office_guide.c b/src/post_office_guide.c index 5884fe0e..7aedc418 100644 --- a/src/post_office_guide.c +++ b/src/post_office_guide.c @@ -9,6 +9,7 @@ #include "code_8094F88.h" #include "menu_input.h" #include "code_80130A8.h" +#include "code_80118A4.h" struct PostOfficeHelper { @@ -177,7 +178,6 @@ extern u8 gUnknown_202DE58[]; extern u8 gUnknown_202E5D8[]; extern u8 gAvailablePokemonNames[]; -extern void PlayMenuSoundEffect(u32); extern void sub_8031A84(); extern void DisplayMissionObjectives(); extern u8 *GetCurrentMissionText(s16 r0); diff --git a/src/save.c b/src/save.c index 0bf2be77..c90b5ea5 100644 --- a/src/save.c +++ b/src/save.c @@ -10,6 +10,7 @@ #include "exclusive_pokemon.h" #include "game_options.h" #include "code_80130A8.h" +#include "code_80118A4.h" EWRAM_DATA_2 u32 gUnknown_203B17C = {0}; EWRAM_DATA_2 char *gUnknown_203B180 = {0}; @@ -141,7 +142,6 @@ ALIGNED(4) static const char fill_save7[] = _("pksdir0"); extern bool8 sub_800DAB0(u16, u8*, s32); extern bool8 sub_800DAB4(u16, u8*, s32); extern bool8 sub_800DAB8(void); -extern void sub_8011830(void); extern void sub_80140DC(); extern void sub_8014114(); extern u32 SaveRecruitedPokemon(u8 *, u32); @@ -168,9 +168,6 @@ extern void sub_80974E8(void); extern void ResetNumAdventures(void); extern void sub_80993D8(void); -extern void xxx_call_start_bg_music(void); - - u32 sub_8011C1C(void) { return gUnknown_203B17C; diff --git a/src/text_util.c b/src/text_util.c index 1c3042cc..fb85c31c 100644 --- a/src/text_util.c +++ b/src/text_util.c @@ -1,4 +1,5 @@ #include "global.h" +#include "text_util.h" #define NUM_POKEMON_TYPES 18 @@ -107,8 +108,7 @@ u32 ReturnIntFromChar2(u8 r0) return r0; } -// Unused -void sub_8092290(u8 *buffer, u8 *string) +UNUSED static void sub_8092290(u8 *buffer, u8 *string) { while( *string != '\0' ) { *buffer++ = ReturnIntFromChar2(*string++); @@ -116,7 +116,7 @@ void sub_8092290(u8 *buffer, u8 *string) *buffer = 0; // append a 0 } -void sub_80922B4(u8 *buffer, u8 *string, s32 size) +void sub_80922B4(u8 *buffer, const u8 *string, s32 size) { while(1) { diff --git a/src/thank_you_wonder_mail.c b/src/thank_you_wonder_mail.c index 2b4d7486..2491eb53 100644 --- a/src/thank_you_wonder_mail.c +++ b/src/thank_you_wonder_mail.c @@ -18,6 +18,7 @@ #include "code_801C620.h" #include "code_801B3C0.h" #include "cpu.h" +#include "code_80118A4.h" extern struct WonderMailStruct_203B2C4 *gUnknown_203B2C4; @@ -216,9 +217,7 @@ extern void SetThankYouMailMenuState(u32); extern struct PokemonStruct *GetPlayerPokemonStruct(void); extern void sub_802F204(struct unkStruct_802F204 *, u32); extern void sub_80151C0(u32, u8 *); -extern void xxx_call_start_bg_music(void); extern void sub_803092C(void); -extern void sub_8011830(void); extern s32 sub_8037B28(u32); extern u32 sub_8030894(void); extern u32 sub_801D008(void); diff --git a/src/trade_items_menu.c b/src/trade_items_menu.c index 4f639530..afaea47c 100644 --- a/src/trade_items_menu.c +++ b/src/trade_items_menu.c @@ -13,6 +13,7 @@ #include "text1.h" #include "text2.h" #include "cpu.h" +#include "code_80118A4.h" EWRAM_DATA_2 struct TradeItemsMenu *gTradeItemsMenu = {0}; @@ -88,8 +89,6 @@ extern void sub_8035C1C(); extern u32 sub_801D008(); extern s32 sub_8037B28(u32); -extern void sub_8011830(void); -extern void xxx_call_start_bg_music(void); extern s32 sub_80381F4(u32, void *, void *); extern s32 sub_8037D64(u32, void *, void *); diff --git a/src/wigglytuff_shop.c b/src/wigglytuff_shop.c index 7c9cc1ee..1c9a1e7c 100644 --- a/src/wigglytuff_shop.c +++ b/src/wigglytuff_shop.c @@ -13,6 +13,7 @@ #include "code_8021774_pre.h" #include "code_801EE10_mid.h" #include "code_8021774.h" +#include "code_80118A4.h" extern struct UnkTextStruct2 gUnknown_80DC534; extern struct UnkTextStruct2 gUnknown_80DC564; @@ -38,7 +39,6 @@ extern const u8 *gUnknown_80D4978[]; u8 sub_8021700(u32); void sub_8092578(u8 *buffer, u8 index, u8 r2); extern void sub_8022380(void); -extern void PlaySound(u32); bool8 sub_8023144(s32 param_1, s32 index, struct UnkTextStruct2_sub *sub, u32 param_4); void sub_8023354(u8 param_1); extern bool8 sub_80023E4(u32); diff --git a/src/wonder_mail.c b/src/wonder_mail.c index 93f3cbef..29c2e816 100644 --- a/src/wonder_mail.c +++ b/src/wonder_mail.c @@ -15,6 +15,7 @@ #include "main_menu.h" #include "code_801EE10_1.h" #include "cpu.h" +#include "code_80118A4.h" extern struct WonderMailStruct_203B2C0 *gUnknown_203B2C0; @@ -61,10 +62,8 @@ extern s32 sub_8037D64(u32, void *, void *); extern s32 sub_80381F4(u32, void *, void *); extern void sub_80306A8(u32, u32, u32, u32); extern s32 sub_8037B28(u32); -extern void sub_8011830(void); extern void sub_8031D70(u8, u32); extern void sub_80151C0(u32, u8 *); -extern void xxx_call_start_bg_music(void); extern u32 sub_8023CE8(void); extern u32 sub_8030894(void); extern void sub_8030F58(u32); diff --git a/src/wonder_mail_2_1.c b/src/wonder_mail_2_1.c index 1fd17dd7..c8344c7b 100644 --- a/src/wonder_mail_2_1.c +++ b/src/wonder_mail_2_1.c @@ -9,6 +9,7 @@ #include "code_802C39C.h" #include "menu_input.h" #include "wonder_mail_2_1.h" +#include "code_80118A4.h" extern struct unkStruct_203B2F0 *gUnknown_203B2F0; extern struct unkStruct_203B2E8* gUnknown_203B2E8; @@ -103,7 +104,6 @@ extern void CreateRescueTitle(struct unkStruct_802C39C *); extern void sub_802C6DC(void); extern void DrawJobListMenu(void); -extern void PlayMenuSoundEffect(u32); extern bool8 IsPelipperBoardSlotEmpty(u8); extern void SetJobListState(u32); extern void sub_802CC00(void); diff --git a/src/wonder_mail_2_mid.c b/src/wonder_mail_2_mid.c index e5abb6b3..9a5981ce 100644 --- a/src/wonder_mail_2_mid.c +++ b/src/wonder_mail_2_mid.c @@ -9,13 +9,13 @@ #include "pokemon_mail.h" #include "wonder_mail.h" #include "code_802C39C.h" -#include "menu_input.h" +#include "menu_input.h" +#include "code_80118A4.h" bool8 IsMailSlotEmpty(u8); extern s32 CountPelipperBoardSlots(void); extern void sub_802C328(void); extern void DrawPelipperBoardJobMenu(void); -extern void PlayMenuSoundEffect(u32); extern u8 HasNoPelipperBoardJobs(void); extern struct WonderMail *GetPelipperBoardSlotInfo(u32); diff --git a/src/wonder_mail_3.c b/src/wonder_mail_3.c index 13d3422d..ded2caab 100644 --- a/src/wonder_mail_3.c +++ b/src/wonder_mail_3.c @@ -12,6 +12,7 @@ #include "code_80958E8.h" #include "wonder_mail_2_1.h" #include "code_80130A8.h" +#include "code_80118A4.h" const struct UnkTextStruct2 gUnknown_80DFDD4 = { @@ -150,7 +151,6 @@ extern void CreateRescueTitle(struct unkStruct_802C39C *); extern u8 gUnknown_80DFDBC[]; extern void sub_802CF5C(void); extern void sub_802CFD0(void); -extern void PlayMenuSoundEffect(u32); extern void sub_802DF24(void); extern void SetJobListState(u32); @@ -159,7 +159,6 @@ extern void ResetJobSlot(u8); extern u8 HasNoAcceptedJobs(void); u32 sub_802C598(u8 param_1); extern void sub_802C688(void); -extern void PlaySound(u32); extern u8 GetPelipperBoardSlotIndex(void); extern struct UnkTextStruct2 gUnknown_80DFD8C; diff --git a/src/wonder_mail_3_mid.c b/src/wonder_mail_3_mid.c index 4ce0fa7e..5e45adb5 100644 --- a/src/wonder_mail_3_mid.c +++ b/src/wonder_mail_3_mid.c @@ -11,6 +11,7 @@ #include "menu_input.h" #include "code_802C39C.h" #include "code_80130A8.h" +#include "code_80118A4.h" struct unkStruct_803B344 { @@ -121,9 +122,7 @@ extern void PrintPokeNameToBuffer(u8 *buffer, struct PokemonStruct *pokemon); extern struct PokemonStruct *GetPlayerPokemonStruct(void); extern void sub_802F6FC(void); extern void ProceedToNextRewardSceneState(void); -extern void PlayMenuSoundEffect(u32); extern void sub_802F300(void); -extern void PlaySound(u32); extern s32 sub_808D544(u32); extern u32 sub_801B60C(u32, u8, u8); extern void sub_8092578(u8 *buffer, u8 index, u8 r2); diff --git a/src/wonder_mail_4.c b/src/wonder_mail_4.c index ba0c04fa..d884485f 100644 --- a/src/wonder_mail_4.c +++ b/src/wonder_mail_4.c @@ -10,6 +10,7 @@ #include "constants/wonder_mail.h" #include "code_802C39C.h" #include "menu_input.h" +#include "code_80118A4.h" struct unkStruct_203B320 { @@ -80,7 +81,6 @@ extern s32 sub_8030A74(void); extern void sub_80308A0(void); extern void sub_803092C(void); -extern void PlayMenuSoundEffect(u32); extern void CreateRescueTitle(struct unkStruct_802C39C *); u32 sub_80306A8(u32 wonderMailType, u32 r1, struct UnkTextStruct2_sub *r2, u32 r3) diff --git a/src/wonder_mail_5.c b/src/wonder_mail_5.c index 4b4e974d..75b18f05 100644 --- a/src/wonder_mail_5.c +++ b/src/wonder_mail_5.c @@ -10,6 +10,7 @@ #include "code_800D090.h" #include "code_802C39C.h" #include "menu_input.h" +#include "code_80118A4.h" struct unkStruct_203B324 { @@ -49,7 +50,6 @@ const u8 gUnknown_80E0938[] = "%-4d"; static const u8 wonder_mail_fill[] = "pksdir0"; extern void sub_8030DD4(void); -extern void PlayMenuSoundEffect(u32); extern void CreateRescueDescription(struct unkStruct_802C39C *); void sub_8030E2C(void); diff --git a/src/wonder_mail_802DF88.c b/src/wonder_mail_802DF88.c index c316d62f..60c10bd8 100644 --- a/src/wonder_mail_802DF88.c +++ b/src/wonder_mail_802DF88.c @@ -7,6 +7,7 @@ #include "text1.h" #include "text2.h" #include "code_80130A8.h" +#include "code_80118A4.h" struct unkStruct_203B2FC { @@ -104,7 +105,6 @@ const struct UnkTextStruct2 gUnknown_80E0264 = static const u8 wonder_mail_802DF88_fill1[] = "pksdir0"; extern void CreateRescueDescription(struct unkStruct_802C39C *); -extern void PlayMenuSoundEffect(u32); extern void sub_802DC28(u32); extern void sub_802F2C0(void); extern void sub_802DC28(u32); diff --git a/src/wonder_mail_main_menu.c b/src/wonder_mail_main_menu.c index 55338553..75bc644f 100644 --- a/src/wonder_mail_main_menu.c +++ b/src/wonder_mail_main_menu.c @@ -12,6 +12,7 @@ #include "code_801C620.h" #include "code_801B3C0.h" #include "cpu.h" +#include "code_80118A4.h" #define SELECT_WONDER_MAIL_MODE_MAIN_SCREEN 0 #define SEND_WONDER_MAIL_MAIN_SCREEN 1 @@ -134,9 +135,7 @@ extern void sub_8031E10(void); extern u8 sub_800D588(void); extern s32 sub_8037D64(u32, void *, void *); extern s32 sub_80381F4(u32, void *, void *); -extern void sub_8011830(void); extern void sub_80151C0(u32, u8 *); -extern void xxx_call_start_bg_music(void); extern void sub_802EF48(void); extern void sub_802D098(struct WonderMail *); From 4dd36687826dabdafa75f4dcf21d2548ed831f31 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sun, 27 Aug 2023 22:35:25 -0400 Subject: [PATCH 23/27] Entity_Sub28 -> EntitySpriteInfo --- include/dungeon_entity.h | 2 +- include/sprite.h | 8 ++++---- src/code_806CD90.c | 4 ++-- src/sprite.c | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h index 7d9c9f44..b4121118 100644 --- a/include/dungeon_entity.h +++ b/include/dungeon_entity.h @@ -271,7 +271,7 @@ struct Entity // The global spawn index counter starts at 10. Each Pokémon that spawns increments the counter and // gets assigned the current counter value as its spawn index. /* 0x26 */ u16 spawnGenID; - /* 0x28*/ struct Entity_Sub28 sub28; + /* 0x28*/ struct EntitySpriteInfo spriteInfo; struct Dungeon_Sub17B44 *unk64; s16 unk68; u8 unk6A; diff --git a/include/sprite.h b/include/sprite.h index 4ade0135..d936a663 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -30,7 +30,7 @@ struct unkStruct_20266B0 }; // size: ? 0x3C for now -struct Entity_Sub28 +struct EntitySpriteInfo { u16 unk0; // 0x2 and 0x6 seem to be related to the sprite animation, though not sure how they're related. @@ -90,9 +90,9 @@ void SetSavingIconCoords(struct Position *); void sub_8004E8C(struct unkStruct_2039DB0 *); void sub_8005180(void); void sub_8005304(void); -void sub_80053AC(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, u32, bool8); -void sub_80053D0(struct Entity_Sub28 *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, u32, bool8); -void sub_800543C(struct Entity_Sub28 *, struct Dungeon_Sub17B44 *, u32, u32, u32, bool8); +void sub_80053AC(struct EntitySpriteInfo *, struct Dungeon_Sub17B44 *, u32, u32, u32, u32, bool8); +void sub_80053D0(struct EntitySpriteInfo *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, u32, bool8); +void sub_800543C(struct EntitySpriteInfo *, struct Dungeon_Sub17B44 *, u32, u32, u32, bool8); void sub_80054BC(struct axPokemon *); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/code_806CD90.c b/src/code_806CD90.c index 1b8998fc..9c5df019 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -71,9 +71,9 @@ void sub_806CCB4(struct Entity *entity, u8 param_2) sVar1 = entity->unk68; if (info->waitingStatus != STATUS_DECOY && !flag) - sub_80053AC(&entity->sub28, entity->unk64, entity->unk6A, entity->direction, sVar1, Rand32Bit() & 3, FALSE); + sub_80053AC(&entity->spriteInfo, entity->unk64, entity->unk6A, entity->direction, sVar1, Rand32Bit() & 3, FALSE); else - sub_80053AC(&entity->sub28, sub_80687D0(MONSTER_DECOY), entity->unk6A, entity->direction, sVar1, Rand32Bit() & 3, FALSE); + sub_80053AC(&entity->spriteInfo, sub_80687D0(MONSTER_DECOY), entity->unk6A, entity->direction, sVar1, Rand32Bit() & 3, FALSE); entity->unk6E = 0; } diff --git a/src/sprite.c b/src/sprite.c index d95cd109..186c4c38 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -20,7 +20,7 @@ extern struct unkStruct_20266B0 *gUnknown_203B074; extern void nullsub_3(s32, s32); void RegisterSpriteParts_80052BC(struct UnkSpriteMem *); -void sub_800545C(struct Entity_Sub28 *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, bool8); +void sub_800545C(struct EntitySpriteInfo *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, bool8); void InitSprites(void) { @@ -886,12 +886,12 @@ void sub_800533C(struct ax_pose **a0, struct UnkSpriteMem **a1, struct axdata1 * } } -void sub_80053AC(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) +void sub_80053AC(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) { sub_80053D0(a0, a1->unk4, a2, a3, a4, spriteAnimIndex, a6); } -void sub_80053D0(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 direction, u32 a4, u32 spriteAnimIndex, bool8 a6) +void sub_80053D0(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 direction, u32 a4, u32 spriteAnimIndex, bool8 a6) { a0->unk0 = 0x8000; if (a6) @@ -914,12 +914,12 @@ void sub_80053D0(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a0->unk30 = a1->unk10; } -void sub_800543C(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +void sub_800543C(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) { sub_800545C(a0, a1->unk4, a2, a3, spriteAnimIndex, a5); } -void sub_800545C(struct Entity_Sub28 *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +void sub_800545C(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) { a0->unk0 = 0x8000; if (a5) From 5923df1f581467fb49b2686e9553fa3823369e58 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sun, 27 Aug 2023 22:41:06 -0400 Subject: [PATCH 24/27] atrib -> attrib --- include/sprite_oam.h | 12 +-- src/menu_input.c | 170 ++++++++++++++++++------------------- src/other_menus.c | 14 +-- src/pokemon_3.c | 4 +- src/rescue_password_menu.c | 30 +++---- src/save_menu.c | 10 +-- src/sprite.c | 48 +++++------ src/unk_menu_203B360.c | 10 +-- 8 files changed, 149 insertions(+), 149 deletions(-) diff --git a/include/sprite_oam.h b/include/sprite_oam.h index 96a39cdc..2464d5bd 100644 --- a/include/sprite_oam.h +++ b/include/sprite_oam.h @@ -5,11 +5,11 @@ struct SpriteOAM { // y:8 affineMode1:1 affineMode2:1 objMode:2 mosaic:1 bpp:1 shape:2 - /* 0x0 */ u16 atrib1; + /* 0x0 */ u16 attrib1; // x:9 matrixNum:5 size:2 - /* 0x2 */ u16 atrib2; + /* 0x2 */ u16 attrib2; // tileNum:10 priority:2 paletteNum:4 - /* 0x4 */ u16 atrib3; + /* 0x4 */ u16 attrib3; // unk6_0:1 unk6_1:1 unk6_2:2? unk6_4:12 u16 unk6; }; @@ -18,7 +18,7 @@ struct SpriteOAM // Most funcs that deal with it look the same and do some weird bit manipulations one by one on the attributes. // It seems like there is a macro to initialize the structure to some default values... -// atrib1 +// attrib1 #define SPRITEOAM_MAX_Y 0xFF #define SPRITEOAM_SHIFT_Y 0 @@ -48,7 +48,7 @@ struct SpriteOAM #define SPRITEOAM_SHIFT_SHAPE 14 #define SPRITEOAM_MASK_SHAPE (SPRITEOAM_MAX_SHAPE << SPRITEOAM_SHIFT_SHAPE) -// atrib2 +// attrib2 #define SPRITEOAM_MAX_X 0x1FF #define SPRITEOAM_SHIFT_X 0 @@ -62,7 +62,7 @@ struct SpriteOAM #define SPRITEOAM_SHIFT_SIZE 12 #define SPRITEOAM_MASK_SIZE (SPRITEOAM_MAX_SIZE << SPRITEOAM_SHIFT_SIZE) -// atrib3 +// attrib3 #define SPRITEOAM_MAX_TILENUM 0x3FF #define SPRITEOAM_SHIFT_TILENUM 0 diff --git a/src/menu_input.c b/src/menu_input.c index df8f4318..87397c3d 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -600,50 +600,50 @@ void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) if (!(a0->unk24 & 8)) { register u32 tmp asm("r0"), tmp2 asm("r1"); - tmp = sp.atrib1; - sp.atrib1 = tmp & ~SPRITEOAM_MASK_AFFINEMODE1; - sp.atrib1 = sp.atrib1; + tmp = sp.attrib1; + sp.attrib1 = tmp & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.attrib1 = sp.attrib1; - tmp2 = sp.atrib1; - sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_AFFINEMODE2; - sp.atrib1 = sp.atrib1; + tmp2 = sp.attrib1; + sp.attrib1 = tmp2 & ~SPRITEOAM_MASK_AFFINEMODE2; + sp.attrib1 = sp.attrib1; - tmp2 = sp.atrib1; - sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_OBJMODE; - sp.atrib1 = sp.atrib1; + tmp2 = sp.attrib1; + sp.attrib1 = tmp2 & ~SPRITEOAM_MASK_OBJMODE; + sp.attrib1 = sp.attrib1; - tmp2 = sp.atrib1; - sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_MOSAIC; - sp.atrib1 = sp.atrib1; + tmp2 = sp.attrib1; + sp.attrib1 = tmp2 & ~SPRITEOAM_MASK_MOSAIC; + sp.attrib1 = sp.attrib1; - tmp2 = sp.atrib1; - sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_BPP; - sp.atrib1 = sp.atrib1; + tmp2 = sp.attrib1; + sp.attrib1 = tmp2 & ~SPRITEOAM_MASK_BPP; + sp.attrib1 = sp.attrib1; - tmp2 = sp.atrib1; - sp.atrib1 = tmp2 & ~SPRITEOAM_MASK_SHAPE; - sp.atrib1 = sp.atrib1; + tmp2 = sp.attrib1; + sp.attrib1 = tmp2 & ~SPRITEOAM_MASK_SHAPE; + sp.attrib1 = sp.attrib1; ptr = &sp; r2 = 0x3F4 << SPRITEOAM_SHIFT_TILENUM; - ptr->atrib3 &= ~SPRITEOAM_MASK_TILENUM; - ptr->atrib3 |= r2; + ptr->attrib3 &= ~SPRITEOAM_MASK_TILENUM; + ptr->attrib3 |= r2; - ptr->atrib3 &= ~SPRITEOAM_MASK_PRIORITY; + ptr->attrib3 &= ~SPRITEOAM_MASK_PRIORITY; r5 = (u16)~SPRITEOAM_MASK_UNK6_4; r1 = 15 << SPRITEOAM_SHIFT_PALETTENUM; - ptr->atrib3 &= ~SPRITEOAM_MASK_PALETTENUM; - ptr->atrib3 |= r1; + ptr->attrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + ptr->attrib3 |= r1; ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_0; ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_1; r0 = a0->unk8; r0 &= SPRITEOAM_MAX_X; - ptr->atrib2 = r0; + ptr->attrib2 = r0; value = a0->unkA + 1; value &= SPRITEOAM_MAX_UNK6_4; @@ -678,51 +678,51 @@ static void sub_801332C(s16 *a0) u32 r5; u32 r6; - r1 = sp.atrib1; - sp.atrib1 = r1 & ~SPRITEOAM_MASK_AFFINEMODE1; - sp.atrib1 = sp.atrib1; + r1 = sp.attrib1; + sp.attrib1 = r1 & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.attrib1 = sp.attrib1; - r2 = sp.atrib1; - sp.atrib1 = r2 & ~SPRITEOAM_MASK_AFFINEMODE2; - sp.atrib1 = sp.atrib1; + r2 = sp.attrib1; + sp.attrib1 = r2 & ~SPRITEOAM_MASK_AFFINEMODE2; + sp.attrib1 = sp.attrib1; r5 = 1 << SPRITEOAM_SHIFT_OBJMODE; - r2 = sp.atrib1; - sp.atrib1 = r2 & ~SPRITEOAM_MASK_OBJMODE; - sp.atrib1 = sp.atrib1 | r5; + r2 = sp.attrib1; + sp.attrib1 = r2 & ~SPRITEOAM_MASK_OBJMODE; + sp.attrib1 = sp.attrib1 | r5; - r2 = sp.atrib1; - sp.atrib1 = r2 & ~SPRITEOAM_MASK_MOSAIC; - sp.atrib1 = sp.atrib1; + r2 = sp.attrib1; + sp.attrib1 = r2 & ~SPRITEOAM_MASK_MOSAIC; + sp.attrib1 = sp.attrib1; - r2 = sp.atrib1; - sp.atrib1 = r2 & ~SPRITEOAM_MASK_BPP; - sp.atrib1 = sp.atrib1; + r2 = sp.attrib1; + sp.attrib1 = r2 & ~SPRITEOAM_MASK_BPP; + sp.attrib1 = sp.attrib1; - r2 = sp.atrib1; - sp.atrib1 = r2 & ~SPRITEOAM_MASK_SHAPE; - sp.atrib1 = sp.atrib1; + r2 = sp.attrib1; + sp.attrib1 = r2 & ~SPRITEOAM_MASK_SHAPE; + sp.attrib1 = sp.attrib1; ptr = &sp; r3 = 0x3F5 << SPRITEOAM_SHIFT_TILENUM; - ptr->atrib3 &= ~SPRITEOAM_MASK_TILENUM; - ptr->atrib3 |= r3; + ptr->attrib3 &= ~SPRITEOAM_MASK_TILENUM; + ptr->attrib3 |= r3; - ptr->atrib3 &= ~SPRITEOAM_MASK_PRIORITY; + ptr->attrib3 &= ~SPRITEOAM_MASK_PRIORITY; r6 = (u16)~SPRITEOAM_MASK_UNK6_4; r2 = 15 << SPRITEOAM_SHIFT_PALETTENUM; - ptr->atrib3 &= ~SPRITEOAM_MASK_PALETTENUM; - ptr->atrib3 |= r2; + ptr->attrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + ptr->attrib3 |= r2; ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_0; ptr->unk6 &= ~SPRITEOAM_MASK_UNK6_1; r1 = a0[0]; r1 &= SPRITEOAM_MAX_X; - ptr->atrib2 = r1; + ptr->attrib2 = r1; r0 = a0[1] + 1; r0 &= SPRITEOAM_MAX_UNK6_4; @@ -744,34 +744,34 @@ static void sub_8013470(struct MenuInputStruct *a0) if (a0->unkC != 0) { if (a0->unk1E != 0) { - r0 = sp.atrib1; - sp.atrib1 = r0 & ~SPRITEOAM_MASK_AFFINEMODE1; - sp.atrib1 = sp.atrib1; + r0 = sp.attrib1; + sp.attrib1 = r0 & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.attrib1 = sp.attrib1; - r1 = sp.atrib1; - sp.atrib1 = r1 & ~SPRITEOAM_MASK_AFFINEMODE2; - sp.atrib1 = sp.atrib1; + r1 = sp.attrib1; + sp.attrib1 = r1 & ~SPRITEOAM_MASK_AFFINEMODE2; + sp.attrib1 = sp.attrib1; - r1 = sp.atrib1; - sp.atrib1 = r1 & (u16)~SPRITEOAM_MASK_OBJMODE; - sp.atrib1 = sp.atrib1; + r1 = sp.attrib1; + sp.attrib1 = r1 & (u16)~SPRITEOAM_MASK_OBJMODE; + sp.attrib1 = sp.attrib1; - r1 = sp.atrib1; - sp.atrib1 = r1 & ~SPRITEOAM_MASK_MOSAIC; - sp.atrib1 = sp.atrib1; + r1 = sp.attrib1; + sp.attrib1 = r1 & ~SPRITEOAM_MASK_MOSAIC; + sp.attrib1 = sp.attrib1; - r1 = sp.atrib1; - sp.atrib1 = r1 & ~SPRITEOAM_MASK_BPP; - sp.atrib1 = sp.atrib1; + r1 = sp.attrib1; + sp.attrib1 = r1 & ~SPRITEOAM_MASK_BPP; + sp.attrib1 = sp.attrib1; - r1 = sp.atrib1; - sp.atrib1 = r1 & ~SPRITEOAM_MASK_SHAPE; - sp.atrib1 = sp.atrib1; + r1 = sp.attrib1; + sp.attrib1 = r1 & ~SPRITEOAM_MASK_SHAPE; + sp.attrib1 = sp.attrib1; ptr = &sp; r2 = 0x3F2 << SPRITEOAM_SHIFT_TILENUM; - r1 = ptr->atrib3; + r1 = ptr->attrib3; r0 = r1 & (u16)~SPRITEOAM_MASK_TILENUM; r0 |= r2; @@ -782,7 +782,7 @@ static void sub_8013470(struct MenuInputStruct *a0) r1 = 15 << SPRITEOAM_SHIFT_PALETTENUM; r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r1; - ptr->atrib3 = r0; + ptr->attrib3 = r0; r0 = ptr->unk6; r1 = r0 & (u16)~SPRITEOAM_MASK_UNK6_0; @@ -790,7 +790,7 @@ static void sub_8013470(struct MenuInputStruct *a0) r0 = a0->unkC; r0 &= SPRITEOAM_MAX_X; - ptr->atrib2 = r0; + ptr->attrib2 = r0; r0 = a0->unkE; r0 &= SPRITEOAM_MAX_UNK6_4; @@ -802,29 +802,29 @@ static void sub_8013470(struct MenuInputStruct *a0) AddSprite(&sp, 0xFF, NULL, NULL); } if (a0->unk20 != 0 && a0->unk20 != a0->unk1E + 1) { - r0 = sp.atrib1; - sp.atrib1 = r0 & ~SPRITEOAM_MASK_AFFINEMODE1; - sp.atrib1 = sp.atrib1; + r0 = sp.attrib1; + sp.attrib1 = r0 & ~SPRITEOAM_MASK_AFFINEMODE1; + sp.attrib1 = sp.attrib1; - sp.atrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; - sp.atrib1 = sp.atrib1; + sp.attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; + sp.attrib1 = sp.attrib1; - sp.atrib1 &= (u16)~SPRITEOAM_MASK_OBJMODE; - sp.atrib1 = sp.atrib1; + sp.attrib1 &= (u16)~SPRITEOAM_MASK_OBJMODE; + sp.attrib1 = sp.attrib1; - sp.atrib1 &= ~SPRITEOAM_MASK_MOSAIC; - sp.atrib1 = sp.atrib1; + sp.attrib1 &= ~SPRITEOAM_MASK_MOSAIC; + sp.attrib1 = sp.attrib1; - sp.atrib1 &= ~SPRITEOAM_MASK_BPP; - sp.atrib1 = sp.atrib1; + sp.attrib1 &= ~SPRITEOAM_MASK_BPP; + sp.attrib1 = sp.attrib1; - sp.atrib1 &= ~SPRITEOAM_MASK_SHAPE; - sp.atrib1 = sp.atrib1; + sp.attrib1 &= ~SPRITEOAM_MASK_SHAPE; + sp.attrib1 = sp.attrib1; ptr = &sp; r2 = 0x3F3 << SPRITEOAM_SHIFT_TILENUM; - r1 = ptr->atrib3; + r1 = ptr->attrib3; r0 = r1 & (u16)~SPRITEOAM_MASK_TILENUM; r0 |= r2; @@ -835,7 +835,7 @@ static void sub_8013470(struct MenuInputStruct *a0) r1 = 15 << SPRITEOAM_SHIFT_PALETTENUM; r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r1; - ptr->atrib3 = r0; + ptr->attrib3 = r0; r0 = ptr->unk6; r1 = r0 & (u16)~SPRITEOAM_MASK_UNK6_0; @@ -843,7 +843,7 @@ static void sub_8013470(struct MenuInputStruct *a0) r0 = a0->unkC + 10; r0 &= SPRITEOAM_MAX_X; - ptr->atrib2 = r0; + ptr->attrib2 = r0; r0 = a0->unkE; r0 &= SPRITEOAM_MAX_UNK6_4; diff --git a/src/other_menus.c b/src/other_menus.c index 5057077c..70621e27 100644 --- a/src/other_menus.c +++ b/src/other_menus.c @@ -781,7 +781,7 @@ void sub_80376CC(void) u32 r1; u32 r4; - r1 = gUnknown_203B35C->unkC.atrib1; + r1 = gUnknown_203B35C->unkC.attrib1; r0 = (u16)~SPRITEOAM_MASK_AFFINEMODE1; r0 &= r1; @@ -797,10 +797,10 @@ void sub_80376CC(void) r0 &= (u16)~SPRITEOAM_MASK_SHAPE; r0 |= r2; - gUnknown_203B35C->unkC.atrib1 = r0; + gUnknown_203B35C->unkC.attrib1 = r0; r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; - r1 = gUnknown_203B35C->unkC.atrib3; + r1 = gUnknown_203B35C->unkC.attrib3; r0 = (u16)~SPRITEOAM_MASK_TILENUM; r0 &= r1; r0 |= r2; @@ -813,10 +813,10 @@ void sub_80376CC(void) r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r4; - gUnknown_203B35C->unkC.atrib3 = r0; + gUnknown_203B35C->unkC.attrib3 = r0; r0 = 0; // Set x/matrixNum/size to 0 - gUnknown_203B35C->unkC.atrib2 = r0; + gUnknown_203B35C->unkC.attrib2 = r0; r1 = 192 << SPRITEOAM_SHIFT_UNK6_4; r0 = gUnknown_203B35C->unkC.unk6; @@ -829,8 +829,8 @@ void sub_8037748(void) { u16 temp2; - gUnknown_203B35C->unkC.atrib2 &= ~SPRITEOAM_MASK_X; // Clear x - gUnknown_203B35C->unkC.atrib2 |= 112; // Set x to 112 + gUnknown_203B35C->unkC.attrib2 &= ~SPRITEOAM_MASK_X; // Clear x + gUnknown_203B35C->unkC.attrib2 |= 112; // Set x to 112 temp2 = 104 << SPRITEOAM_SHIFT_UNK6_4; gUnknown_203B35C->unkC.unk6 &= ~SPRITEOAM_MASK_UNK6_4; diff --git a/src/pokemon_3.c b/src/pokemon_3.c index c18cd4c8..929ce349 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -69,8 +69,8 @@ bool8 sub_808E668(s16 species, s16* a2, s16* a3) x &= SPRITEOAM_MAX_X; spr = &gUnknown_202F3E8[shadowSize]; - spr->atrib2 &= ~SPRITEOAM_MASK_X; - spr->atrib2 |= x; + spr->attrib2 &= ~SPRITEOAM_MASK_X; + spr->attrib2 |= x; unk6 &= SPRITEOAM_MAX_UNK6_4; unk6 <<= SPRITEOAM_SHIFT_UNK6_4; spr->unk6 &= ~SPRITEOAM_MASK_UNK6_4; diff --git a/src/rescue_password_menu.c b/src/rescue_password_menu.c index 92610d5f..2a5abf37 100644 --- a/src/rescue_password_menu.c +++ b/src/rescue_password_menu.c @@ -697,36 +697,36 @@ void sub_8039174(void) spr = &gRescuePasswordMenu->unk208; - spr->atrib1 &= ~SPRITEOAM_MASK_AFFINEMODE1; + spr->attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE1; - spr->atrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; + spr->attrib1 &= ~SPRITEOAM_MASK_AFFINEMODE2; - spr->atrib1 &= ~SPRITEOAM_MASK_OBJMODE; + spr->attrib1 &= ~SPRITEOAM_MASK_OBJMODE; - spr->atrib1 &= ~SPRITEOAM_MASK_MOSAIC; + spr->attrib1 &= ~SPRITEOAM_MASK_MOSAIC; - spr->atrib1 &= ~SPRITEOAM_MASK_BPP; + spr->attrib1 &= ~SPRITEOAM_MASK_BPP; r2 = 1 << SPRITEOAM_SHIFT_SHAPE; - spr->atrib1 &= ~SPRITEOAM_MASK_SHAPE; - spr->atrib1 |= r2; + spr->attrib1 &= ~SPRITEOAM_MASK_SHAPE; + spr->attrib1 |= r2; r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; - spr->atrib3 &= ~SPRITEOAM_MASK_TILENUM; - spr->atrib3 |= r2; + spr->attrib3 &= ~SPRITEOAM_MASK_TILENUM; + spr->attrib3 |= r2; - spr->atrib3 &= ~SPRITEOAM_MASK_PRIORITY; + spr->attrib3 &= ~SPRITEOAM_MASK_PRIORITY; r2 = (u16)~SPRITEOAM_MASK_UNK6_4; r4 = 15 << SPRITEOAM_SHIFT_PALETTENUM; - spr->atrib3 &= ~SPRITEOAM_MASK_PALETTENUM; - spr->atrib3 |= r4; + spr->attrib3 &= ~SPRITEOAM_MASK_PALETTENUM; + spr->attrib3 |= r4; #ifndef NONMATCHING while (0) ; #endif //NONMATCHING - spr->atrib2 = 0; // Without the while(0), this 0 is loaded super early and also into r3 + spr->attrib2 = 0; // Without the while(0), this 0 is loaded super early and also into r3 temp = 192 << SPRITEOAM_SHIFT_UNK6_4; r2 &= spr->unk6; @@ -741,8 +741,8 @@ void sub_80391F8(void) spr = &gRescuePasswordMenu->unk208; - spr->atrib2 &= ~SPRITEOAM_MASK_X; - spr->atrib2 |= 112; + spr->attrib2 &= ~SPRITEOAM_MASK_X; + spr->attrib2 |= 112; val = 112 << SPRITEOAM_SHIFT_UNK6_4; spr->unk6 &= ~SPRITEOAM_MASK_UNK6_4; diff --git a/src/save_menu.c b/src/save_menu.c index cc5e2154..ff7c5f9d 100644 --- a/src/save_menu.c +++ b/src/save_menu.c @@ -291,7 +291,7 @@ void sub_8038830(void) r5 = 0; sprite = &gUnknown_203B364->unk1A8; - r1 = sprite->atrib1; + r1 = sprite->attrib1; r0 = (u16)~SPRITEOAM_MASK_AFFINEMODE1; r0 &= r1; @@ -306,10 +306,10 @@ void sub_8038830(void) r2 = 1 << SPRITEOAM_SHIFT_SHAPE; r0 &= (u16)~SPRITEOAM_MASK_SHAPE; r0 |= r2; - sprite->atrib1 = r0; + sprite->attrib1 = r0; r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; - r1 = sprite->atrib3; + r1 = sprite->attrib3; r0 = (u16)~SPRITEOAM_MASK_TILENUM; r0 &= r1; r0 |= r2; @@ -321,9 +321,9 @@ void sub_8038830(void) r4 = 15 << SPRITEOAM_SHIFT_PALETTENUM; r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r4; - sprite->atrib3 = r0; + sprite->attrib3 = r0; - sprite->atrib2 = 112; // Set x to 112. Set matrixNum/size to 0 + sprite->attrib2 = 112; // Set x to 112. Set matrixNum/size to 0 r1 = 104 << SPRITEOAM_SHIFT_UNK6_4; r2 &= sprite->unk6; diff --git a/src/sprite.c b/src/sprite.c index 186c4c38..366fb974 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -185,15 +185,15 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 r7 = 255; if (spriteMasks == NULL) { - sprite->atrib1 = sp.flags1; - sprite->atrib2 = sp.flags2; - sprite->atrib3 = sp.flags3; + sprite->attrib1 = sp.flags1; + sprite->attrib2 = sp.flags2; + sprite->attrib3 = sp.flags3; sprite->unk6 = sp.unkA; } else { - sprite->atrib1 = (spriteMasks[0] & sp.flags1) | spriteMasks[3]; - sprite->atrib2 = (spriteMasks[1] & sp.flags2) | spriteMasks[4]; - sprite->atrib3 = (spriteMasks[2] & sp.flags3) | spriteMasks[5]; + sprite->attrib1 = (spriteMasks[0] & sp.flags1) | spriteMasks[3]; + sprite->attrib2 = (spriteMasks[1] & sp.flags2) | spriteMasks[4]; + sprite->attrib3 = (spriteMasks[2] & sp.flags3) | spriteMasks[5]; sprite->unk6 = sp.unkA; } @@ -201,14 +201,14 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 tileNum = gUnknown_2025672[sp.unk2] & 0x3FF; } else { - tileNum = (sprite->atrib3 & 0x3FF) + a1->vramTileOrMaybeAnimTimer; + tileNum = (sprite->attrib3 & 0x3FF) + a1->vramTileOrMaybeAnimTimer; tileNum &= 0x3FF; } // Set tileNum, maintain priority/paletteNum - sprite->atrib3 = tileNum | (sprite->atrib3 & 0xFC00); + sprite->attrib3 = tileNum | (sprite->attrib3 & 0xFC00); - x = (sprite->atrib2 & 0x1FF) - 256; + x = (sprite->attrib2 & 0x1FF) - 256; x += a1->xPos; if (x < -64) return; @@ -216,7 +216,7 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 return; // Set x, maintain matrixNum/size - sprite->atrib2 = (x & 0x1FF) | (sprite->atrib2 & 0xFE00); + sprite->attrib2 = (x & 0x1FF) | (sprite->attrib2 & 0xFE00); uVar9 = sprite->unk6 << 16; earlyMask = 0xFFF; @@ -229,14 +229,14 @@ void sub_8004EA8(struct ax_pose *a0, struct axdata1 *a1, struct UnkSpriteMem *a2 return; // Set y, maintain affineMode/objMode/mosaic/bpp/shape - sprite->atrib1 = (y & 0xFF) | (sprite->atrib1 & 0xFF00); + sprite->attrib1 = (y & 0xFF) | (sprite->attrib1 & 0xFF00); // Set paletteNum, maintain tileNum/priority if (((uVar9 >> 17) & 1) == 0) - sprite->atrib3 = ((a1->paletteNum & 0xF) << 12) | (sprite->atrib3 & earlyMask); + sprite->attrib3 = ((a1->paletteNum & 0xF) << 12) | (sprite->attrib3 & earlyMask); if (sp.unk2 != 0) - sprite->atrib3 = ((gUnknown_2025682[sp.unk2] & 0xF) << 12) | (sprite->atrib3 & earlyMask); + sprite->attrib3 = ((gUnknown_2025682[sp.unk2] & 0xF) << 12) | (sprite->attrib3 & earlyMask); gUnknown_2025EA8[gSpriteCount].unk0 = gUnknown_20256A0.sprites[r7].unk0; gUnknown_20256A0.sprites[r7].unk0 = gUnknown_2025EA8 + gSpriteCount; @@ -528,23 +528,23 @@ void AddSprite(struct SpriteOAM *a0, s32 a1, struct UnkSpriteMem *a2, struct unk a1 = 255; if (a3 == NULL) { - spr->atrib1 = a0->atrib1; - spr->atrib2 = a0->atrib2; - spr->atrib3 = a0->atrib3; + spr->attrib1 = a0->attrib1; + spr->attrib2 = a0->attrib2; + spr->attrib3 = a0->attrib3; spr->unk6 = a0->unk6; } else { - spr->atrib1 = (a0->atrib1 & a3->unk0) | a3->unk6; - spr->atrib2 = (a0->atrib2 & a3->unk2) | a3->unk8; - spr->atrib3 = (a0->atrib3 & a3->unk4) | a3->unkA; + spr->attrib1 = (a0->attrib1 & a3->unk0) | a3->unk6; + spr->attrib2 = (a0->attrib2 & a3->unk2) | a3->unk8; + spr->attrib3 = (a0->attrib3 & a3->unk4) | a3->unkA; spr->unk6 = a0->unk6; } yPos = spr->unk6 / 16; nullsub_3(yPos, 0); yPos &= SPRITEOAM_MAX_Y; - spr->atrib1 &= ~SPRITEOAM_MASK_Y; - spr->atrib1 |= yPos; + spr->attrib1 &= ~SPRITEOAM_MASK_Y; + spr->attrib1 |= yPos; if (a2 != NULL) RegisterSpriteParts_80052BC(a2); @@ -710,13 +710,13 @@ void CopySpritesToOam(void) // Skip affineParam oam -= 2; // Set tileNum/priority/paletteNum - *oam = spr->atrib3; + *oam = spr->attrib3; // Set x/matrixNum/size oam--; - *oam = spr->atrib2; + *oam = spr->attrib2; // Set y/affineMode/objMode/mosaic/bpp/shape oam--; - *oam = spr->atrib1; + *oam = spr->attrib1; count++; } diff --git a/src/unk_menu_203B360.c b/src/unk_menu_203B360.c index 03cd4326..46da88de 100644 --- a/src/unk_menu_203B360.c +++ b/src/unk_menu_203B360.c @@ -140,7 +140,7 @@ void sub_8038440(void) r5 = 0; sprite = &gUnknown_203B360->unk1A8; - r1 = sprite->atrib1; + r1 = sprite->attrib1; r0 = (u16)~SPRITEOAM_MASK_AFFINEMODE1; r0 &= r1; @@ -156,10 +156,10 @@ void sub_8038440(void) r0 &= (u16)~SPRITEOAM_MASK_SHAPE; r0 |= r2; - sprite->atrib1 = r0; + sprite->attrib1 = r0; r2 = 0x3F0 << SPRITEOAM_SHIFT_TILENUM; - r1 = sprite->atrib3; + r1 = sprite->attrib3; r0 = (u16)~SPRITEOAM_MASK_TILENUM; r0 &= r1; r0 |= r2; @@ -172,9 +172,9 @@ void sub_8038440(void) r0 &= (u16)~SPRITEOAM_MASK_PALETTENUM; r0 |= r4; - sprite->atrib3 = r0; + sprite->attrib3 = r0; - sprite->atrib2 = 112; // Set x to 112. Set matrixNum/size to 0 + sprite->attrib2 = 112; // Set x to 112. Set matrixNum/size to 0 r1 = 112 << SPRITEOAM_SHIFT_UNK6_4; r2 &= sprite->unk6; From 34d1d0b9b248a46f0f376fdc9782865bf749ad3f Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sun, 27 Aug 2023 22:43:47 -0400 Subject: [PATCH 25/27] Dungeon_Sub17B44 -> Dungeon_ax --- include/code_805D8C8.h | 4 ++-- include/dungeon_entity.h | 2 +- include/dungeon_global_data.h | 2 +- include/sprite.h | 12 ++++++------ src/code_8077274_1.c | 2 +- src/sprite.c | 10 +++++----- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/code_805D8C8.h b/include/code_805D8C8.h index 3bab54c0..5543c1cc 100644 --- a/include/code_805D8C8.h +++ b/include/code_805D8C8.h @@ -3,8 +3,8 @@ #include "sprite.h" -extern struct Dungeon_Sub17B44 *sub_80687D0(s16); -/*struct Dungeon_Sub17B44 *sub_80687D0(s16 species) +extern struct Dungeon_ax *sub_80687D0(s16); +/*struct Dungeon_ax *sub_80687D0(s16 species) { s32 species32 = species; return gDungeon->sub17B44[species32]; diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h index b4121118..479cba39 100644 --- a/include/dungeon_entity.h +++ b/include/dungeon_entity.h @@ -272,7 +272,7 @@ struct Entity // gets assigned the current counter value as its spawn index. /* 0x26 */ u16 spawnGenID; /* 0x28*/ struct EntitySpriteInfo spriteInfo; - struct Dungeon_Sub17B44 *unk64; + struct Dungeon_ax *unk64; s16 unk68; u8 unk6A; u8 unk6B; diff --git a/include/dungeon_global_data.h b/include/dungeon_global_data.h index 9ee9762c..b8d3a1a7 100644 --- a/include/dungeon_global_data.h +++ b/include/dungeon_global_data.h @@ -199,7 +199,7 @@ struct Dungeon /* 0x17B38 */ u32 unk17B38; /* 0x17B3C */ u32 unk17B3C; u8 fill17B40[0x17B44 - 0x17B40]; - struct Dungeon_Sub17B44 *sub17B44[MONSTER_MAX]; // Assuming MONSTER_MAX since the highest value I've seen read is MONSTER_DECOY + struct Dungeon_ax *sub17B44[MONSTER_MAX]; // Assuming MONSTER_MAX since the highest value I've seen read is MONSTER_DECOY u8 fill181E0[0x181E8 - 0x181E0]; /* 0x181E8 */ struct Position cameraPos; /* 0x181EC */ struct Position cameraPosMirror; diff --git a/include/sprite.h b/include/sprite.h index d936a663..34996562 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -65,7 +65,7 @@ struct EntitySpriteInfo }; // size: ? -struct Dungeon_Sub17B44_Sub4 +struct Dungeon_ax_Sub4 { u32 unk0; u32 **unk4; @@ -75,10 +75,10 @@ struct Dungeon_Sub17B44_Sub4 }; // size: ? -struct Dungeon_Sub17B44 +struct Dungeon_ax { u8 fill0[0x4 - 0x0]; - struct Dungeon_Sub17B44_Sub4 *unk4; + struct Dungeon_ax_Sub4 *unk4; }; void AddSprite(struct SpriteOAM *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); @@ -90,9 +90,9 @@ void SetSavingIconCoords(struct Position *); void sub_8004E8C(struct unkStruct_2039DB0 *); void sub_8005180(void); void sub_8005304(void); -void sub_80053AC(struct EntitySpriteInfo *, struct Dungeon_Sub17B44 *, u32, u32, u32, u32, bool8); -void sub_80053D0(struct EntitySpriteInfo *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, u32, bool8); -void sub_800543C(struct EntitySpriteInfo *, struct Dungeon_Sub17B44 *, u32, u32, u32, bool8); +void sub_80053AC(struct EntitySpriteInfo *, struct Dungeon_ax *, u32, u32, u32, u32, bool8); +void sub_80053D0(struct EntitySpriteInfo *, struct Dungeon_ax_Sub4 *, u32, u32, u32, u32, bool8); +void sub_800543C(struct EntitySpriteInfo *, struct Dungeon_ax *, u32, u32, u32, bool8); void sub_80054BC(struct axPokemon *); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index b11ff5d2..77bbbffa 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -244,7 +244,7 @@ void sub_8078E18(struct Entity * pokemon, struct Entity * target) s16 apparentID_s16; s32 index; struct EntityInfo *entityInfo; - struct Dungeon_Sub17B44 *iVar9; + struct Dungeon_ax *iVar9; struct PokemonStruct *auStack544[128]; if (!EntityExists(target)) diff --git a/src/sprite.c b/src/sprite.c index 366fb974..676d7eb1 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -20,7 +20,7 @@ extern struct unkStruct_20266B0 *gUnknown_203B074; extern void nullsub_3(s32, s32); void RegisterSpriteParts_80052BC(struct UnkSpriteMem *); -void sub_800545C(struct EntitySpriteInfo *, struct Dungeon_Sub17B44_Sub4 *, u32, u32, u32, bool8); +void sub_800545C(struct EntitySpriteInfo *, struct Dungeon_ax_Sub4 *, u32, u32, u32, bool8); void InitSprites(void) { @@ -886,12 +886,12 @@ void sub_800533C(struct ax_pose **a0, struct UnkSpriteMem **a1, struct axdata1 * } } -void sub_80053AC(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) +void sub_80053AC(struct EntitySpriteInfo *a0, struct Dungeon_ax *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) { sub_80053D0(a0, a1->unk4, a2, a3, a4, spriteAnimIndex, a6); } -void sub_80053D0(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 direction, u32 a4, u32 spriteAnimIndex, bool8 a6) +void sub_80053D0(struct EntitySpriteInfo *a0, struct Dungeon_ax_Sub4 *a1, u32 a2, u32 direction, u32 a4, u32 spriteAnimIndex, bool8 a6) { a0->unk0 = 0x8000; if (a6) @@ -914,12 +914,12 @@ void sub_80053D0(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44_Sub4 *a1, a0->unk30 = a1->unk10; } -void sub_800543C(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +void sub_800543C(struct EntitySpriteInfo *a0, struct Dungeon_ax *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) { sub_800545C(a0, a1->unk4, a2, a3, spriteAnimIndex, a5); } -void sub_800545C(struct EntitySpriteInfo *a0, struct Dungeon_Sub17B44_Sub4 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +void sub_800545C(struct EntitySpriteInfo *a0, struct Dungeon_ax_Sub4 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) { a0->unk0 = 0x8000; if (a5) From 4784ab68b0ce6bae2520badbc02bb14ea618a01d Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sun, 27 Aug 2023 22:56:09 -0400 Subject: [PATCH 26/27] That's an OpenedFile lol --- include/code_805D8C8.h | 6 +++--- include/dungeon_entity.h | 2 +- include/dungeon_global_data.h | 7 ++++--- include/file_system.h | 27 ++++++++++++++++----------- include/sprite.h | 15 ++++----------- src/code_8077274_1.c | 2 +- src/sprite.c | 14 +++++++------- 7 files changed, 36 insertions(+), 37 deletions(-) diff --git a/include/code_805D8C8.h b/include/code_805D8C8.h index 5543c1cc..075b7ea0 100644 --- a/include/code_805D8C8.h +++ b/include/code_805D8C8.h @@ -3,11 +3,11 @@ #include "sprite.h" -extern struct Dungeon_ax *sub_80687D0(s16); -/*struct Dungeon_ax *sub_80687D0(s16 species) +extern struct OpenedFile *sub_80687D0(s16); +/*struct OpenedFile *sub_80687D0(s16 species) { s32 species32 = species; - return gDungeon->sub17B44[species32]; + return gDungeon->sprites[species32]; }*/ #endif // GUARD_CODE_805D8C8_H \ No newline at end of file diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h index 479cba39..450e53f9 100644 --- a/include/dungeon_entity.h +++ b/include/dungeon_entity.h @@ -272,7 +272,7 @@ struct Entity // gets assigned the current counter value as its spawn index. /* 0x26 */ u16 spawnGenID; /* 0x28*/ struct EntitySpriteInfo spriteInfo; - struct Dungeon_ax *unk64; + struct OpenedFile *unk64; s16 unk68; u8 unk6A; u8 unk6B; diff --git a/include/dungeon_global_data.h b/include/dungeon_global_data.h index b8d3a1a7..b4b3c016 100644 --- a/include/dungeon_global_data.h +++ b/include/dungeon_global_data.h @@ -1,9 +1,10 @@ #ifndef GUARD_DUNGEON_DATA_H #define GUARD_DUNGEON_DATA_H +#include "global.h" #include "constants/monster.h" #include "dungeon_entity.h" -#include "global.h" +#include "file_system.h" #include "map.h" #include "position.h" #include "sprite.h" @@ -199,8 +200,8 @@ struct Dungeon /* 0x17B38 */ u32 unk17B38; /* 0x17B3C */ u32 unk17B3C; u8 fill17B40[0x17B44 - 0x17B40]; - struct Dungeon_ax *sub17B44[MONSTER_MAX]; // Assuming MONSTER_MAX since the highest value I've seen read is MONSTER_DECOY - u8 fill181E0[0x181E8 - 0x181E0]; + /* 0x17B44 */ struct OpenedFile *sprites[MONSTER_MAX + 1]; + u8 fill181E4[0x181E8 - 0x181E4]; /* 0x181E8 */ struct Position cameraPos; /* 0x181EC */ struct Position cameraPosMirror; /* 0x181F0 */ struct Position cameraPixelPos; diff --git a/include/file_system.h b/include/file_system.h index 83b7c5d6..8ce24a15 100644 --- a/include/file_system.h +++ b/include/file_system.h @@ -1,35 +1,40 @@ #ifndef GUARD_FILE_SYSTEM_H #define GUARD_FILE_SYSTEM_H +// size: 0x8 struct File { - char *name; - u8 *data; + /* 0x0 */ char *name; + /* 0x4 */ u8 *data; }; +// size: 0x8 struct OpenedFile { - struct File *file; - u8 *data; + /* 0x0 */ struct File *file; + /* 0x4 */ u8 *data; }; +// size: 0x10 struct FileArchive { - char magic[8]; - s32 count; - struct File *entries; + /* 0x0 */ char magic[8]; + /* 0x8 */ s32 count; + /* 0xC */ struct File *entries; }; +// size: 0x8 struct SiroArchive { - u32 magic; - u8 *data; + /* 0x0 */ u32 magic; + /* 0x4 */ u8 *data; }; +// size: 0x8 struct UnkFileStruct1 { - /* 0x0 */ u32 unk0; - /* 0x4 */ u32 unk4; + u32 unk0; + u32 unk4; }; void InitFileSystem(void); diff --git a/include/sprite.h b/include/sprite.h index 34996562..1e217b36 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -65,7 +65,7 @@ struct EntitySpriteInfo }; // size: ? -struct Dungeon_ax_Sub4 +struct Dungeon_ax { u32 unk0; u32 **unk4; @@ -74,13 +74,6 @@ struct Dungeon_ax_Sub4 u32 unk10; }; -// size: ? -struct Dungeon_ax -{ - u8 fill0[0x4 - 0x0]; - struct Dungeon_ax_Sub4 *unk4; -}; - void AddSprite(struct SpriteOAM *, s32, struct UnkSpriteMem *, struct unkStruct_2039DB0 *); void BlinkSavingIcon(void); void CopySpritesToOam(void); @@ -90,9 +83,9 @@ void SetSavingIconCoords(struct Position *); void sub_8004E8C(struct unkStruct_2039DB0 *); void sub_8005180(void); void sub_8005304(void); -void sub_80053AC(struct EntitySpriteInfo *, struct Dungeon_ax *, u32, u32, u32, u32, bool8); -void sub_80053D0(struct EntitySpriteInfo *, struct Dungeon_ax_Sub4 *, u32, u32, u32, u32, bool8); -void sub_800543C(struct EntitySpriteInfo *, struct Dungeon_ax *, u32, u32, u32, bool8); +void sub_80053AC(struct EntitySpriteInfo *, struct OpenedFile *, u32, u32, u32, u32, bool8); +void sub_80053D0(struct EntitySpriteInfo *, struct Dungeon_ax *, u32, u32, u32, u32, bool8); +void sub_800543C(struct EntitySpriteInfo *, struct OpenedFile *, u32, u32, u32, bool8); void sub_80054BC(struct axPokemon *); #endif // GUARD_SPRITE_H \ No newline at end of file diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index 77bbbffa..358133b1 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -244,7 +244,7 @@ void sub_8078E18(struct Entity * pokemon, struct Entity * target) s16 apparentID_s16; s32 index; struct EntityInfo *entityInfo; - struct Dungeon_ax *iVar9; + struct OpenedFile *iVar9; struct PokemonStruct *auStack544[128]; if (!EntityExists(target)) diff --git a/src/sprite.c b/src/sprite.c index 676d7eb1..e80999b9 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -20,7 +20,7 @@ extern struct unkStruct_20266B0 *gUnknown_203B074; extern void nullsub_3(s32, s32); void RegisterSpriteParts_80052BC(struct UnkSpriteMem *); -void sub_800545C(struct EntitySpriteInfo *, struct Dungeon_ax_Sub4 *, u32, u32, u32, bool8); +void sub_800545C(struct EntitySpriteInfo *, struct Dungeon_ax *, u32, u32, u32, bool8); void InitSprites(void) { @@ -886,12 +886,12 @@ void sub_800533C(struct ax_pose **a0, struct UnkSpriteMem **a1, struct axdata1 * } } -void sub_80053AC(struct EntitySpriteInfo *a0, struct Dungeon_ax *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) +void sub_80053AC(struct EntitySpriteInfo *a0, struct OpenedFile *a1, u32 a2, u32 a3, u32 a4, u32 spriteAnimIndex, bool8 a6) { - sub_80053D0(a0, a1->unk4, a2, a3, a4, spriteAnimIndex, a6); + sub_80053D0(a0, (struct Dungeon_ax *)a1->data, a2, a3, a4, spriteAnimIndex, a6); } -void sub_80053D0(struct EntitySpriteInfo *a0, struct Dungeon_ax_Sub4 *a1, u32 a2, u32 direction, u32 a4, u32 spriteAnimIndex, bool8 a6) +void sub_80053D0(struct EntitySpriteInfo *a0, struct Dungeon_ax *a1, u32 a2, u32 direction, u32 a4, u32 spriteAnimIndex, bool8 a6) { a0->unk0 = 0x8000; if (a6) @@ -914,12 +914,12 @@ void sub_80053D0(struct EntitySpriteInfo *a0, struct Dungeon_ax_Sub4 *a1, u32 a2 a0->unk30 = a1->unk10; } -void sub_800543C(struct EntitySpriteInfo *a0, struct Dungeon_ax *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +void sub_800543C(struct EntitySpriteInfo *a0, struct OpenedFile *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) { - sub_800545C(a0, a1->unk4, a2, a3, spriteAnimIndex, a5); + sub_800545C(a0, (struct Dungeon_ax *)a1->data, a2, a3, spriteAnimIndex, a5); } -void sub_800545C(struct EntitySpriteInfo *a0, struct Dungeon_ax_Sub4 *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) +void sub_800545C(struct EntitySpriteInfo *a0, struct Dungeon_ax *a1, u32 a2, u32 a3, u32 spriteAnimIndex, bool8 a5) { a0->unk0 = 0x8000; if (a5) From 6cfbc9d0a2c6787577f49975a64348394898c9d3 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sun, 27 Aug 2023 23:00:34 -0400 Subject: [PATCH 27/27] Add NONMATCHING for register asm stuff --- src/menu_input.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/menu_input.c b/src/menu_input.c index 87397c3d..7e58cb9a 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -598,7 +598,11 @@ void AddMenuCursorSprite_(struct MenuInputStruct *a0, u32 a1) UpdateMenuCursorSpriteCoords(a0); if (!(a0->unk24 & 8)) { + #ifdef NONMATCHING + u32 tmp, tmp2; + #else register u32 tmp asm("r0"), tmp2 asm("r1"); + #endif tmp = sp.attrib1; sp.attrib1 = tmp & ~SPRITEOAM_MASK_AFFINEMODE1; @@ -671,9 +675,13 @@ static void sub_801332C(s16 *a0) { struct SpriteOAM sp = {}; struct SpriteOAM* ptr; + #ifdef NONMATCHING + u32 r0, r1, r2; + #else register u32 r0 asm("r0"); register u32 r1 asm("r1"); register u32 r2 asm("r2"); + #endif u32 r3; u32 r5; u32 r6; @@ -736,11 +744,16 @@ static void sub_801332C(s16 *a0) static void sub_8013470(struct MenuInputStruct *a0) { struct SpriteOAM sp = {}; - register struct SpriteOAM* ptr asm("r3"); + #if NONMATCHING + struct SpriteOAM *ptr; + u32 r0, r1, r5; + #else + register struct SpriteOAM *ptr asm("r3"); register u32 r0 asm("r0"); register u32 r1 asm("r1"); - u32 r2; register u32 r5 asm("r5"); + #endif + u32 r2; if (a0->unkC != 0) { if (a0->unk1E != 0) {