diff --git a/asm/include/overlay_12_02265E28.inc b/asm/include/overlay_12_02265E28.inc deleted file mode 100644 index d40b63ee55..0000000000 --- a/asm/include/overlay_12_02265E28.inc +++ /dev/null @@ -1,26 +0,0 @@ -#include -#pragma once -.public PaletteData_LoadNarc -.public NARC_New -.public NARC_Delete -.public SpriteSystem_LoadCharResObjFromOpenNarc -.public SpriteSystem_LoadPaletteBufferFromOpenNarc -.public SpriteSystem_LoadCellResObjFromOpenNarc -.public SpriteSystem_LoadAnimResObjFromOpenNarc -.public SpriteSystem_NewSprite -.public SpriteManager_UnloadCharObjById -.public SpriteManager_UnloadPlttObjById -.public SpriteManager_UnloadCellObjById -.public SpriteManager_UnloadAnimObjById -.public Sprite_DeleteAndFreeResources -.public Sprite_TickFrame -.public ManagedSprite_SetDrawFlag -.public GF_AssertFail -.public MIi_CpuClearFast -.public BattleSystem_GetSpriteRenderer -.public BattleSystem_GetGfxHandler -.public BattleSystem_GetPaletteData -.public ov12_0223B52C -.public ov12_02265FC4 -.public ov12_02265FD4 -.public ov12_02266008 diff --git a/asm/overlay_12_02265E28.s b/asm/overlay_12_02265E28.s deleted file mode 100644 index 29a6ac9f95..0000000000 --- a/asm/overlay_12_02265E28.s +++ /dev/null @@ -1,289 +0,0 @@ - .include "asm/macros.inc" - .include "overlay_12_02265E28.inc" - .include "global.inc" - - .text - - thumb_func_start ov12_02265E28 -ov12_02265E28: ; 0x02265E28 - push {r3, r4, r5, r6, r7, lr} - sub sp, #0x28 - add r5, r0, #0 - mov r0, #8 - mov r1, #5 - bl NARC_New - add r4, r0, #0 - ldr r0, [r5, #4] - bl BattleSystem_GetSpriteRenderer - str r0, [sp, #0x24] - ldr r0, [r5, #4] - bl BattleSystem_GetGfxHandler - str r0, [sp, #0x20] - ldr r0, [r5, #4] - bl ov12_0223B52C - add r7, r0, #0 - ldrb r0, [r5, #8] - cmp r0, #0 - ldrb r0, [r5, #9] - bne _02265E6E - lsl r1, r0, #1 - ldr r0, _02265F1C ; =ov12_0226E0D0 - ldrh r3, [r0, r1] - ldr r0, _02265F20 ; =0x00004E2D - mov r1, #0x80 - str r1, [sp, #0x1c] - add r6, r0, #0 - mov r1, #0x81 - sub r6, #8 - str r1, [sp, #0x18] - b _02265E82 -_02265E6E: - lsl r1, r0, #1 - ldr r0, _02265F24 ; =ov12_0226E0A0 - ldrh r3, [r0, r1] - ldr r0, _02265F28 ; =0x00004E2E - mov r1, #0x83 - str r1, [sp, #0x1c] - add r6, r0, #0 - mov r1, #0x84 - sub r6, #8 - str r1, [sp, #0x18] -_02265E82: - mov r1, #1 - str r1, [sp] - str r1, [sp, #4] - str r0, [sp, #8] - ldr r0, [sp, #0x24] - ldr r1, [sp, #0x20] - add r2, r4, #0 - bl SpriteSystem_LoadCharResObjFromOpenNarc - ldr r0, [r5, #4] - bl BattleSystem_GetPaletteData - str r4, [sp] - ldrb r1, [r5, #9] - mov r2, #6 - add r3, r1, #0 - mul r3, r2 - ldr r2, _02265F2C ; =ov12_0226E168 - lsl r1, r7, #1 - add r2, r2, r3 - ldrh r1, [r1, r2] - ldr r2, [sp, #0x24] - ldr r3, [sp, #0x20] - str r1, [sp, #4] - mov r1, #0 - str r1, [sp, #8] - mov r1, #1 - str r1, [sp, #0xc] - str r1, [sp, #0x10] - ldr r1, _02265F30 ; =0x00004E29 - str r1, [sp, #0x14] - mov r1, #2 - bl SpriteSystem_LoadPaletteBufferFromOpenNarc - ldr r0, [r5, #4] - bl BattleSystem_GetPaletteData - mov r1, #0 - str r1, [sp] - mov r1, #0x20 - str r1, [sp, #4] - mov r1, #0x70 - str r1, [sp, #8] - ldrb r2, [r5, #9] - mov r3, #6 - lsl r5, r7, #1 - mul r3, r2 - ldr r2, _02265F2C ; =ov12_0226E168 - mov r1, #8 - add r2, r2, r3 - ldrh r2, [r5, r2] - mov r3, #5 - bl PaletteData_LoadNarc - mov r0, #1 - str r0, [sp] - ldr r0, [sp, #0x24] - ldr r1, [sp, #0x20] - ldr r3, [sp, #0x1c] - add r2, r4, #0 - str r6, [sp, #4] - bl SpriteSystem_LoadCellResObjFromOpenNarc - mov r0, #1 - str r0, [sp] - ldr r0, [sp, #0x24] - ldr r1, [sp, #0x20] - ldr r3, [sp, #0x18] - add r2, r4, #0 - str r6, [sp, #4] - bl SpriteSystem_LoadAnimResObjFromOpenNarc - add r0, r4, #0 - bl NARC_Delete - add sp, #0x28 - pop {r3, r4, r5, r6, r7, pc} - .balign 4, 0 -_02265F1C: .word ov12_0226E0D0 -_02265F20: .word 0x00004E2D -_02265F24: .word ov12_0226E0A0 -_02265F28: .word 0x00004E2E -_02265F2C: .word ov12_0226E168 -_02265F30: .word 0x00004E29 - thumb_func_end ov12_02265E28 - - thumb_func_start ov12_02265F34 -ov12_02265F34: ; 0x02265F34 - push {r3, r4, r5, lr} - add r4, r0, #0 - ldr r0, [r4, #4] - bl BattleSystem_GetSpriteRenderer - add r5, r0, #0 - ldr r0, [r4, #4] - bl BattleSystem_GetGfxHandler - add r1, r0, #0 - add r0, r5, #0 - ldrb r3, [r4, #8] - mov r2, #0x34 - ldr r5, _02265F64 ; =ov12_0226E100 - mul r2, r3 - add r2, r5, r2 - bl SpriteSystem_NewSprite - str r0, [r4] - ldr r0, [r0] - bl Sprite_TickFrame - pop {r3, r4, r5, pc} - nop -_02265F64: .word ov12_0226E100 - thumb_func_end ov12_02265F34 - - thumb_func_start ov12_02265F68 -ov12_02265F68: ; 0x02265F68 - push {r4, lr} - add r4, r0, #0 - ldr r0, [r4] - cmp r0, #0 - beq _02265F7A - bl Sprite_DeleteAndFreeResources - mov r0, #0 - str r0, [r4] -_02265F7A: - pop {r4, pc} - thumb_func_end ov12_02265F68 - - thumb_func_start ov12_02265F7C -ov12_02265F7C: ; 0x02265F7C - push {r3, r4, r5, lr} - add r5, r0, #0 - ldr r0, [r5, #4] - bl BattleSystem_GetGfxHandler - add r4, r0, #0 - ldrb r0, [r5, #8] - cmp r0, #0 - bne _02265F92 - ldr r1, _02265FB8 ; =0x00004E2D - b _02265F94 -_02265F92: - ldr r1, _02265FBC ; =0x00004E2E -_02265F94: - add r5, r1, #0 - add r0, r4, #0 - sub r5, #8 - bl SpriteManager_UnloadCharObjById - ldr r1, _02265FC0 ; =0x00004E29 - add r0, r4, #0 - bl SpriteManager_UnloadPlttObjById - add r0, r4, #0 - add r1, r5, #0 - bl SpriteManager_UnloadCellObjById - add r0, r4, #0 - add r1, r5, #0 - bl SpriteManager_UnloadAnimObjById - pop {r3, r4, r5, pc} - .balign 4, 0 -_02265FB8: .word 0x00004E2D -_02265FBC: .word 0x00004E2E -_02265FC0: .word 0x00004E29 - thumb_func_end ov12_02265F7C - - thumb_func_start ov12_02265FC4 -ov12_02265FC4: ; 0x02265FC4 - push {r3, lr} - ldr r0, [r0] - cmp r0, #0 - beq _02265FD0 - bl ManagedSprite_SetDrawFlag -_02265FD0: - pop {r3, pc} - .balign 4, 0 - thumb_func_end ov12_02265FC4 - - thumb_func_start ov12_02265FD4 -ov12_02265FD4: ; 0x02265FD4 - push {r3, r4, r5, r6, r7, lr} - add r5, r0, #0 - add r4, r1, #0 - add r6, r2, #0 - mov r0, #0 - add r1, r5, #0 - mov r2, #0x10 - add r7, r3, #0 - bl MIi_CpuClearFast - str r4, [r5, #4] - strb r6, [r5, #8] - strb r7, [r5, #9] - cmp r7, #0x18 - blt _02265FFA - bl GF_AssertFail - mov r0, #0 - strb r0, [r5, #9] -_02265FFA: - add r0, r5, #0 - bl ov12_02265E28 - add r0, r5, #0 - bl ov12_02265F34 - pop {r3, r4, r5, r6, r7, pc} - thumb_func_end ov12_02265FD4 - - thumb_func_start ov12_02266008 -ov12_02266008: ; 0x02266008 - push {r4, lr} - add r4, r0, #0 - bl ov12_02265F68 - add r0, r4, #0 - bl ov12_02265F7C - mov r0, #0 - add r1, r4, #0 - mov r2, #0x10 - bl MIi_CpuClearFast - pop {r4, pc} - .balign 4, 0 - thumb_func_end ov12_02266008 - - .rodata - - ov12_0226E0A0: ; 0x0226E0A0 - .byte 0x88, 0x00, 0x92, 0x00, 0x82, 0x00, 0x98, 0x00, 0x8C, 0x00, 0x96, 0x00, 0x8E, 0x00, 0x86, 0x00 - .byte 0x8A, 0x00, 0x90, 0x00, 0x94, 0x00, 0x94, 0x00, 0x9A, 0x00, 0x9C, 0x00, 0x9E, 0x00, 0xA0, 0x00 - .byte 0xA2, 0x00, 0xA4, 0x00, 0xA6, 0x00, 0xA8, 0x00, 0xAA, 0x00, 0xAC, 0x00, 0xAE, 0x00, 0xB0, 0x00 - -ov12_0226E0D0: ; 0x0226E0D0 - .byte 0x87, 0x00, 0x91, 0x00, 0x7F, 0x00, 0x97, 0x00, 0x8B, 0x00, 0x95, 0x00, 0x8D, 0x00, 0x85, 0x00 - .byte 0x89, 0x00, 0x8F, 0x00, 0x93, 0x00, 0x97, 0x00, 0x99, 0x00, 0x9B, 0x00, 0x9D, 0x00, 0x9F, 0x00 - .byte 0xA1, 0x00, 0xA3, 0x00, 0xA5, 0x00, 0xA7, 0x00, 0xA9, 0x00, 0xAB, 0x00, 0xAD, 0x00, 0xAF, 0x00 - -ov12_0226E100: ; 0x0226E100 - .byte 0x50, 0x01, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x2D, 0x4E, 0x00, 0x00, 0x29, 0x4E, 0x00, 0x00, 0x25, 0x4E, 0x00, 0x00 - .byte 0x25, 0x4E, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0xB0, 0xFF, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x03, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2E, 0x4E, 0x00, 0x00, 0x29, 0x4E, 0x00, 0x00 - .byte 0x26, 0x4E, 0x00, 0x00, 0x26, 0x4E, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -ov12_0226E168: ; 0x0226E168 - .byte 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x16, 0x00 - .byte 0x17, 0x00, 0x18, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x1F, 0x00, 0x20, 0x00, 0x21, 0x00 - .byte 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00, 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x00, 0x10, 0x00, 0x11, 0x00 - .byte 0x12, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x13, 0x00 - .byte 0x14, 0x00, 0x15, 0x00, 0x19, 0x00, 0x1A, 0x00, 0x1B, 0x00, 0x19, 0x00, 0x1A, 0x00, 0x1B, 0x00 - .byte 0x22, 0x00, 0x23, 0x00, 0x24, 0x00, 0x25, 0x00, 0x26, 0x00, 0x27, 0x00, 0x28, 0x00, 0x29, 0x00 - .byte 0x2A, 0x00, 0x2B, 0x00, 0x2C, 0x00, 0x2D, 0x00, 0x2E, 0x00, 0x2F, 0x00, 0x30, 0x00, 0x31, 0x00 - .byte 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x39, 0x00 - .byte 0x3A, 0x00, 0x3B, 0x00, 0x3C, 0x00, 0x3D, 0x00, 0x3E, 0x00, 0x3F, 0x00, 0x40, 0x00, 0x41, 0x00 - .byte 0x42, 0x00, 0x43, 0x00, 0x44, 0x00, 0x45, 0x00 diff --git a/include/battle/battle_02265E28.h b/include/battle/battle_02265E28.h index 73866e7ced..caa5d8f0be 100644 --- a/include/battle/battle_02265E28.h +++ b/include/battle/battle_02265E28.h @@ -3,6 +3,8 @@ #include "battle.h" -void ov12_02266008(UnkBattleSystemSub17C *a0); +void ov12_02266008(UnkBattleSystemSub17C *arg0); +void ov12_02265FC4(UnkBattleSystemSub17C *arg0, s32 flag); +void ov12_02265FD4(UnkBattleSystemSub17C *arg0, BattleSystem *bsys, s32 unk8, s32 unk9); #endif diff --git a/include/battle/overlay_12_02265E28.h b/include/battle/overlay_12_02265E28.h new file mode 100644 index 0000000000..117ce3f309 --- /dev/null +++ b/include/battle/overlay_12_02265E28.h @@ -0,0 +1,2 @@ + +#include "global.h" diff --git a/main.lsf b/main.lsf index dfe1738126..eba904bad5 100644 --- a/main.lsf +++ b/main.lsf @@ -630,7 +630,7 @@ Overlay OVY_12 Object src/battle/battle_02261FD4.o Object asm/overlay_12_battle_controller.o Object src/battle/battle_hp_bar.o - Object asm/overlay_12_02265E28.o + Object src/battle/battle_02265E28.o Object src/battle/battle_input.o Object asm/overlay_12_02266024.o Object asm/overlay_12_0226ADE0.o diff --git a/src/battle/battle_02265E28.c b/src/battle/battle_02265E28.c new file mode 100644 index 0000000000..aa23dc3944 --- /dev/null +++ b/src/battle/battle_02265E28.c @@ -0,0 +1,204 @@ + +#include "battle/battle_02265E28.h" + +#include "global.h" + +#include "constants/heap.h" + +#include "battle/battle.h" +#include "battle/battle_system.h" +#include "battle/overlay_12_02265E28.h" + +#include "filesystem.h" +#include "filesystem_files_def.h" +#include "sprite_system.h" + +#define UNK_RES_4E2D 0x4E2D +#define UNK_RES_4E2E 0x4E2E +#define UNK_RES_4E29 0x4E29 +#define UNK_RES_4E25 0x4E25 +#define UNK_RES_4E26 0x4E26 + +void ov12_02265E28(UnkBattleSystemSub17C *a0); +void ov12_02265F34(UnkBattleSystemSub17C *arg0); +void ov12_02265F68(UnkBattleSystemSub17C *arg0); +void ov12_02265F7C(UnkBattleSystemSub17C *arg0); + +static const u16 ov12_0226E0A0[] = { + 0x88, + 0x92, + 0x82, + 0x98, + 0x8C, + 0x96, + 0x8E, + 0x86, + 0x8A, + 0x90, + 0x94, + 0x94, + 0x9A, + 0x9C, + 0x9E, + 0xA0, + 0xA2, + 0xA4, + 0xA6, + 0xA8, + 0xAA, + 0xAC, + 0xAE, + 0xB0 +}; + +static const u16 ov12_0226E0D0[] = { + 0x87, + 0x91, + 0x7F, + 0x97, + 0x8B, + 0x95, + 0x8D, + 0x85, + 0x89, + 0x8F, + 0x93, + 0x97, + 0x99, + 0x9B, + 0x9D, + 0x9F, + 0xA1, + 0xA3, + 0xA5, + 0xA7, + 0xA9, + 0xAB, + 0xAD, + 0xAF +}; + +static const ManagedSpriteTemplate ov12_0226E100[] = { + { .x = 0x150, .y = 0x88, .z = 0, .animation = 0, .drawPriority = 0x3E8, .pal = 0, .vram = NNS_G2D_VRAM_TYPE_2DMAIN, .resIdList = { UNK_RES_4E2D, UNK_RES_4E29, UNK_RES_4E25, UNK_RES_4E25, -1, -1 }, .bgPriority = 3, .vramTransfer = 0 }, + { .x = 0xFFB0, .y = 0x58, .z = 0, .animation = 0, .drawPriority = 0x3E8, .pal = 0, .vram = NNS_G2D_VRAM_TYPE_2DMAIN, .resIdList = { UNK_RES_4E2E, UNK_RES_4E29, UNK_RES_4E26, UNK_RES_4E26, -1, -1 }, .bgPriority = 3, .vramTransfer = 0 } +}; + +static const u16 ov12_0226E168[][3] __attribute__((aligned(4))) = { + { 0x07, 0x08, 0x09 }, + { 0x16, 0x17, 0x18 }, + { 0x01, 0x02, 0x03 }, + { 0x1F, 0x20, 0x21 }, + { 0x0D, 0x0E, 0x0F }, + { 0x1C, 0x1D, 0x1E }, + { 0x10, 0x11, 0x12 }, + { 0x04, 0x05, 0x06 }, + { 0x0A, 0x0B, 0x0C }, + { 0x13, 0x14, 0x15 }, + { 0x19, 0x1A, 0x1B }, + { 0x19, 0x1A, 0x1B }, + { 0x22, 0x23, 0x24 }, + { 0x25, 0x26, 0x27 }, + { 0x28, 0x29, 0x2A }, + { 0x2B, 0x2C, 0x2D }, + { 0x2E, 0x2F, 0x30 }, + { 0x31, 0x32, 0x33 }, + { 0x34, 0x35, 0x36 }, + { 0x37, 0x38, 0x39 }, + { 0x3A, 0x3B, 0x3C }, + { 0x3D, 0x3E, 0x3F }, + { 0x40, 0x41, 0x42 }, + { 0x43, 0x44, 0x45 } +}; + +void ov12_02265E28(UnkBattleSystemSub17C *a0) { + u32 r6; + void *narc = NARC_New(NARC_a_0_0_8, HEAP_ID_BATTLE); + + SpriteSystem *spriteSystem = BattleSystem_GetSpriteRenderer(a0->bsys); + SpriteManager *spriteManager = BattleSystem_GetGfxHandler(a0->bsys); + u32 subfile = ov12_0223B52C(a0->bsys); + + u16 charFile; + u32 charResId; + u32 cellFile; + u32 animFile; + if (a0->unk8 == 0) { + charFile = ov12_0226E0D0[a0->unk9]; + charResId = UNK_RES_4E2D; + cellFile = 0x80; + r6 = charResId - 8; + animFile = 0x81; + } else { + charFile = ov12_0226E0A0[a0->unk9]; + charResId = UNK_RES_4E2E; + cellFile = 0x83; + r6 = charResId - 8; + animFile = 0x84; + } + SpriteSystem_LoadCharResObjFromOpenNarc(spriteSystem, spriteManager, narc, charFile, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, charResId); + + void *palette = BattleSystem_GetPaletteData(a0->bsys); + SpriteSystem_LoadPaletteBufferFromOpenNarc(palette, PLTTBUF_MAIN_OBJ, spriteSystem, spriteManager, narc, ov12_0226E168[a0->unk9][subfile], FALSE, 1, NNS_G2D_VRAM_TYPE_2DMAIN, UNK_RES_4E29); + + palette = BattleSystem_GetPaletteData(a0->bsys); + PaletteData_LoadNarc(palette, NARC_a_0_0_8, ov12_0226E168[a0->unk9][subfile], HEAP_ID_BATTLE, PLTTBUF_MAIN_BG, 0x20, 0x70); + + SpriteSystem_LoadCellResObjFromOpenNarc(spriteSystem, spriteManager, narc, cellFile, TRUE, r6); + + SpriteSystem_LoadAnimResObjFromOpenNarc(spriteSystem, spriteManager, narc, animFile, TRUE, r6); + + NARC_Delete(narc); +} + +void ov12_02265F34(UnkBattleSystemSub17C *arg0) { + SpriteSystem *spriteSystem; // r5 + ManagedSprite *managed; + + spriteSystem = BattleSystem_GetSpriteRenderer(arg0->bsys); + managed = SpriteSystem_NewSprite(spriteSystem, BattleSystem_GetGfxHandler(arg0->bsys), &ov12_0226E100[arg0->unk8]); + arg0->unk0 = managed; + Sprite_TickFrame(managed->sprite); +} + +void ov12_02265F68(UnkBattleSystemSub17C *arg0) { + if (arg0->unk0) { + Sprite_DeleteAndFreeResources(arg0->unk0); + arg0->unk0 = NULL; + } +} + +void ov12_02265F7C(UnkBattleSystemSub17C *arg0) { + SpriteManager *manager = BattleSystem_GetGfxHandler(arg0->bsys); + s32 resId = arg0->unk8 == 0 ? UNK_RES_4E2D : UNK_RES_4E2E; + u32 temp = resId - 8; + SpriteManager_UnloadCharObjById(manager, resId); + SpriteManager_UnloadPlttObjById(manager, UNK_RES_4E29); + SpriteManager_UnloadCellObjById(manager, temp); + SpriteManager_UnloadAnimObjById(manager, temp); +} + +void ov12_02265FC4(UnkBattleSystemSub17C *arg0, s32 flag) { + ManagedSprite *sprite = arg0->unk0; + if (sprite) { + ManagedSprite_SetDrawFlag(sprite, flag); + } +} + +void ov12_02265FD4(UnkBattleSystemSub17C *arg0, BattleSystem *bsys, s32 unk8, s32 unk9) { + MIi_CpuClearFast(0, (void *)arg0, sizeof(UnkBattleSystemSub17C)); + arg0->bsys = bsys; + arg0->unk8 = unk8; + arg0->unk9 = unk9; + if (unk9 >= 0x18) { + GF_AssertFail(); + arg0->unk9 = 0; + } + ov12_02265E28(arg0); + ov12_02265F34(arg0); +} + +void ov12_02266008(UnkBattleSystemSub17C *arg0) { + ov12_02265F68(arg0); + ov12_02265F7C(arg0); + MIi_CpuClearFast(0, (void *)arg0, sizeof(UnkBattleSystemSub17C)); +}