From f4ef62bb4134498a4b4a9c4d61b99bda24c98680 Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Sun, 18 Nov 2018 16:23:57 +0800 Subject: [PATCH] Renamed primary heap variables and partial cleanup m4a.s --- INSTALL.md | 2 + Makefile | 12 +- asm/code_8012A18.s | 244 ++++++++++++++++++------------------ asm/m4a.s | 216 +++++++++++++++---------------- asm/memory.s | 121 ++---------------- asm/rom_header.inc | 33 ++--- asm/save.s | 92 ++++---------- asm/sprite.s | 11 -- asm/text.s | 2 +- constants/m4a_constants.inc | 199 +++++++++++++++++++++++++++++ include/gba/defines.h | 4 +- include/memory.h | 56 +++++++++ ld_script.txt | 2 + src/bg_palette_buffer.c | 15 ++- src/file_system.c | 34 ++--- src/flash.c | 3 +- src/memory.c | 62 ++++++++- src/save.c | 33 +++-- src/save1.c | 13 ++ src/sprite.c | 10 ++ sym_ewram.txt | 49 ++++---- sym_ewram2.txt | 2 +- 22 files changed, 702 insertions(+), 513 deletions(-) create mode 100644 constants/m4a_constants.inc create mode 100644 include/memory.h create mode 100644 src/save1.c create mode 100644 src/sprite.c diff --git a/INSTALL.md b/INSTALL.md index b1149715..de8142dd 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,3 +1,5 @@ +First, you must put a Pokémon Mystery Dungeon Red Rescue Team 1.0 (US) ROM in the root directory of the repository and name it `baserom.gba`. It should have a SHA1 checksum of `9f4cfc5b5f4859d17169a485462e977c7aac2b89`. Then, follow the OS-specific instructions below. + # Linux Install [**devkitARM**](http://devkitpro.org/wiki/Getting_Started/devkitARM). diff --git a/Makefile b/Makefile index 92e1eddb..59e6cafd 100755 --- a/Makefile +++ b/Makefile @@ -6,6 +6,10 @@ else EXE := endif +TITLE := POKE DUNGEON +GAME_CODE := B24E +MAKER_CODE := 01 +REVISION := 0 #### Tools #### @@ -17,6 +21,7 @@ LD := $(PREFIX)ld OBJCOPY := $(PREFIX)objcopy SHA1SUM := sha1sum -c GBAGFX := tools/gbagfx/gbagfx +GBAFIX := tools/gbafix/gbafix AIF2PCM := tools/aif2pcm/aif2pcm MID2AGB := tools/mid2agb/mid2agb PREPROC := tools/preproc/preproc @@ -51,9 +56,9 @@ LIBGCC := tools/agbcc/lib/libgcc.a LD_SCRIPT := $(BUILD_DIR)/ld_script.ld # Special configurations required for lib files -%/src/agb_flash.o : CC1FLAGS := -O -mthumb-interwork -%/src/agb_flash_1m.o: CC1FLAGS := -O -mthumb-interwork -%/src/agb_flash_mx.o: CC1FLAGS := -O -mthumb-interwork +$(BUILD_DIR)/src/agb_flash.o : CC1FLAGS := -O -mthumb-interwork +$(BUILD_DIR)/src/agb_flash_1m.o: CC1FLAGS := -O -mthumb-interwork +$(BUILD_DIR)/src/agb_flash_mx.o: CC1FLAGS := -O -mthumb-interwork #### Main Rules #### @@ -92,6 +97,7 @@ tidy: $(ROM): %.gba: %.elf $(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0xA000000 $< $@ + $(GBAFIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent %.elf: $(LD_SCRIPT) $(ALL_OBJECTS) $(LIBC) cd $(BUILD_DIR) && $(LD) -T ld_script.ld -Map ../../$(MAP) -o ../../$@ ../../$(LIBC) ../../$(LIBGCC) diff --git a/asm/code_8012A18.s b/asm/code_8012A18.s index bf8e2200..b1327f42 100644 --- a/asm/code_8012A18.s +++ b/asm/code_8012A18.s @@ -4698,7 +4698,7 @@ _08014E10: adds r4, r1, r0 b _08014F0C .align 2, 0 -_08014E20: .4byte gUnknown_202D3B8 +_08014E20: .4byte gFileCache + 0x110 _08014E24: adds r5, 0x1 movs r0, 0 @@ -86812,10 +86812,10 @@ _0803DB54: .align 2, 0 _0803DB84: .4byte gUnknown_80F60F8 _0803DB88: .4byte gUnknown_83B0000 -_0803DB8C: .4byte gUnknown_202EC88 +_0803DB8C: .4byte gDungeonNameBannerPalette _0803DB90: .4byte gUnknown_80F6100 -_0803DB94: .4byte gUnknown_202EC8C -_0803DB98: .4byte gUnknown_202EC90 +_0803DB94: .4byte gDungeonNameBannerFontFile +_0803DB98: .4byte gDungeonNameBannerFontFile + 4 _0803DB9C: .4byte 0x06000140 _0803DBA0: .4byte gUnknown_203B418 _0803DBA4: .4byte 0x00000645 @@ -86862,7 +86862,7 @@ _0803DBEA: .align 2, 0 _0803DC08: .4byte gUnknown_80F6118 _0803DC0C: .4byte gUnknown_20274A5 -_0803DC10: .4byte gUnknown_202EC8C +_0803DC10: .4byte gDungeonNameBannerFontFile thumb_func_end ShowDungeonNameBanner thumb_func_start sub_803DC14 @@ -87273,7 +87273,7 @@ sub_803DEC8: adds r1, r5, r0 b _0803DF56 .align 2, 0 -_0803DEFC: .4byte gUnknown_202EC8C +_0803DEFC: .4byte gDungeonNameBannerFontFile _0803DF00: .4byte 0xffff0800 _0803DF04: .4byte 0x000007fe _0803DF08: @@ -87287,7 +87287,7 @@ _0803DF08: adds r0, r2, r0 b _0803DF3A .align 2, 0 -_0803DF1C: .4byte gUnknown_202EC90 +_0803DF1C: .4byte gDungeonNameBannerFontFile + 4 _0803DF20: lsls r0, r1, 3 adds r0, r5 @@ -88555,7 +88555,7 @@ _0803E9B4: .4byte 0x00018215 _0803E9B8: .4byte 0x0001c06c _0803E9BC: .4byte gUnknown_202EE8C _0803E9C0: .4byte gUnknown_202ECA4 -_0803E9C4: .4byte gUnknown_202EC88 +_0803E9C4: .4byte gDungeonNameBannerPalette _0803E9C8: .4byte gUnknown_202D058 _0803E9CC: .4byte 0x000181e4 thumb_func_end sub_803E874 @@ -99078,7 +99078,7 @@ _08043984: .4byte 0xff00ffff _08043988: .4byte gUnknown_202EDC8 _0804398C: .4byte gUnknown_81006A4 _08043990: .4byte 0x00000222 -_08043994: .4byte gUnknown_202EC88 +_08043994: .4byte gDungeonNameBannerPalette _08043998: .4byte gUnknown_203B40C _0804399C: .4byte gUnknown_203B41C _080439A0: @@ -104471,7 +104471,7 @@ sub_8046298: ldrb r0, [r0, 0xD] bx lr .align 2, 0 -_080462A8: .4byte gUnknown_20389A4 +_080462A8: .4byte gItemParametersFile + 4 thumb_func_end sub_8046298 thumb_func_start sub_80462AC @@ -245668,8 +245668,8 @@ _0808CDE4: .4byte gUnknown_203B45C _0808CDE8: .4byte gUnknown_202F400 _0808CDEC: .4byte gUnknown_81075F4 _0808CDF0: .4byte gUnknown_8300500 -_0808CDF4: .4byte gUnknown_202F3E4 -_0808CDF8: .4byte gUnknown_202F3E0 +_0808CDF4: .4byte gMonsterParametersFile +_0808CDF8: .4byte gMonsterParameters _0808CDFC: .4byte gUnknown_20384E8 thumb_func_end LoadMonsterParameters @@ -245907,7 +245907,7 @@ _0808CFB8: pop {r0} bx r0 .align 2, 0 -_0808CFC8: .4byte gUnknown_202F3E0 +_0808CFC8: .4byte gMonsterParameters _0808CFCC: .4byte gUnknown_203B45C thumb_func_end sub_808CE74 @@ -246197,7 +246197,7 @@ sub_808D1DC: bne _0808D238 b _0808D268 .align 2, 0 -_0808D204: .4byte gUnknown_202F3E0 +_0808D204: .4byte gMonsterParameters _0808D208: .4byte gUnknown_203B468 _0808D20C: ldr r0, [r7] @@ -246278,7 +246278,7 @@ sub_808D278: bne _0808D2AA b _0808D2DA .align 2, 0 -_0808D29C: .4byte gUnknown_202F3E0 +_0808D29C: .4byte gMonsterParameters _0808D2A0: .4byte gUnknown_203B468 _0808D2A4: ldr r0, [r7] @@ -247194,7 +247194,7 @@ sub_808D8BC: pop {r0} bx r0 .align 2, 0 -_0808D8DC: .4byte gUnknown_202F3E0 +_0808D8DC: .4byte gMonsterParameters thumb_func_end sub_808D8BC thumb_func_start sub_808D8E0 @@ -247216,7 +247216,7 @@ sub_808D8E0: bx r0 .align 2, 0 _0808D900: .4byte gUnknown_8107600 -_0808D904: .4byte gUnknown_202F3E0 +_0808D904: .4byte gMonsterParameters thumb_func_end sub_808D8E0 thumb_func_start sub_808D908 @@ -247238,7 +247238,7 @@ sub_808D908: bx r0 .align 2, 0 _0808D928: .4byte gUnknown_8107608 -_0808D92C: .4byte gUnknown_202F3E0 +_0808D92C: .4byte gMonsterParameters thumb_func_end sub_808D908 thumb_func_start sub_808D930 @@ -247287,7 +247287,7 @@ _0808D986: bx r0 .align 2, 0 _0808D98C: .4byte gUnknown_8107638 -_0808D990: .4byte gUnknown_202F3E0 +_0808D990: .4byte gMonsterParameters thumb_func_end sub_808D930 thumb_func_start sub_808D994 @@ -247303,7 +247303,7 @@ sub_808D994: ldr r0, [r1] bx lr .align 2, 0 -_0808D9A8: .4byte gUnknown_202F3E0 +_0808D9A8: .4byte gMonsterParameters thumb_func_end sub_808D994 thumb_func_start sub_808D9AC @@ -247468,7 +247468,7 @@ sub_808DAB4: ldr r0, [r1, 0x4] bx lr .align 2, 0 -_0808DAC8: .4byte gUnknown_202F3E0 +_0808DAC8: .4byte gMonsterParameters thumb_func_end sub_808DAB4 thumb_func_start sub_808DACC @@ -247484,7 +247484,7 @@ sub_808DACC: ldrb r0, [r1, 0x9] bx lr .align 2, 0 -_0808DAE0: .4byte gUnknown_202F3E0 +_0808DAE0: .4byte gMonsterParameters thumb_func_end sub_808DACC thumb_func_start sub_808DAE4 @@ -247500,7 +247500,7 @@ sub_808DAE4: ldrb r0, [r1, 0x19] bx lr .align 2, 0 -_0808DAF8: .4byte gUnknown_202F3E0 +_0808DAF8: .4byte gMonsterParameters thumb_func_end sub_808DAE4 thumb_func_start sub_808DAFC @@ -247516,7 +247516,7 @@ sub_808DAFC: ldr r0, [r1, 0xC] bx lr .align 2, 0 -_0808DB10: .4byte gUnknown_202F3E0 +_0808DB10: .4byte gMonsterParameters thumb_func_end sub_808DAFC thumb_func_start sub_808DB14 @@ -247532,7 +247532,7 @@ sub_808DB14: ldrb r0, [r1, 0x15] bx lr .align 2, 0 -_0808DB28: .4byte gUnknown_202F3E0 +_0808DB28: .4byte gMonsterParameters thumb_func_end sub_808DB14 thumb_func_start sub_808DB2C @@ -247550,7 +247550,7 @@ sub_808DB2C: lsrs r0, 24 bx lr .align 2, 0 -_0808DB44: .4byte gUnknown_202F3E0 +_0808DB44: .4byte gMonsterParameters thumb_func_end sub_808DB2C thumb_func_start sub_808DB48 @@ -247566,7 +247566,7 @@ sub_808DB48: ldrb r0, [r1, 0x1C] bx lr .align 2, 0 -_0808DB5C: .4byte gUnknown_202F3E0 +_0808DB5C: .4byte gMonsterParameters thumb_func_end sub_808DB48 thumb_func_start sub_808DB60 @@ -247582,7 +247582,7 @@ sub_808DB60: ldrb r0, [r1, 0x1D] bx lr .align 2, 0 -_0808DB74: .4byte gUnknown_202F3E0 +_0808DB74: .4byte gMonsterParameters thumb_func_end sub_808DB60 thumb_func_start sub_808DB78 @@ -247598,7 +247598,7 @@ sub_808DB78: ldrh r0, [r1, 0x2C] bx lr .align 2, 0 -_0808DB8C: .4byte gUnknown_202F3E0 +_0808DB8C: .4byte gMonsterParameters thumb_func_end sub_808DB78 thumb_func_start sub_808DB90 @@ -247614,7 +247614,7 @@ sub_808DB90: ldrh r0, [r1, 0x2E] bx lr .align 2, 0 -_0808DBA4: .4byte gUnknown_202F3E0 +_0808DBA4: .4byte gMonsterParameters thumb_func_end sub_808DB90 thumb_func_start sub_808DBA8 @@ -247630,7 +247630,7 @@ sub_808DBA8: ldrb r0, [r1, 0x16] bx lr .align 2, 0 -_0808DBBC: .4byte gUnknown_202F3E0 +_0808DBBC: .4byte gMonsterParameters thumb_func_end sub_808DBA8 thumb_func_start sub_808DBC0 @@ -247646,7 +247646,7 @@ sub_808DBC0: ldrh r0, [r1, 0x1E] bx lr .align 2, 0 -_0808DBD4: .4byte gUnknown_202F3E0 +_0808DBD4: .4byte gMonsterParameters thumb_func_end sub_808DBC0 thumb_func_start sub_808DBD8 @@ -247663,7 +247663,7 @@ sub_808DBD8: ldrb r0, [r1] bx lr .align 2, 0 -_0808DBF0: .4byte gUnknown_202F3E0 +_0808DBF0: .4byte gMonsterParameters thumb_func_end sub_808DBD8 thumb_func_start sub_808DBF4 @@ -247679,7 +247679,7 @@ sub_808DBF4: ldrb r0, [r1, 0x12] bx lr .align 2, 0 -_0808DC08: .4byte gUnknown_202F3E0 +_0808DC08: .4byte gMonsterParameters thumb_func_end sub_808DBF4 thumb_func_start sub_808DC0C @@ -247696,7 +247696,7 @@ sub_808DC0C: ldrsh r0, [r1, r2] bx lr .align 2, 0 -_0808DC24: .4byte gUnknown_202F3E0 +_0808DC24: .4byte gMonsterParameters thumb_func_end sub_808DC0C thumb_func_start sub_808DC28 @@ -247715,7 +247715,7 @@ sub_808DC28: ldrh r0, [r2] bx lr .align 2, 0 -_0808DC44: .4byte gUnknown_202F3E0 +_0808DC44: .4byte gMonsterParameters thumb_func_end sub_808DC28 thumb_func_start sub_808DC48 @@ -247734,7 +247734,7 @@ sub_808DC48: ldrh r0, [r2] bx lr .align 2, 0 -_0808DC64: .4byte gUnknown_202F3E0 +_0808DC64: .4byte gMonsterParameters thumb_func_end sub_808DC48 thumb_func_start sub_808DC68 @@ -247752,7 +247752,7 @@ sub_808DC68: ldrb r0, [r2] bx lr .align 2, 0 -_0808DC80: .4byte gUnknown_202F3E0 +_0808DC80: .4byte gMonsterParameters thumb_func_end sub_808DC68 thumb_func_start sub_808DC84 @@ -247770,7 +247770,7 @@ sub_808DC84: ldrb r0, [r2] bx lr .align 2, 0 -_0808DC9C: .4byte gUnknown_202F3E0 +_0808DC9C: .4byte gMonsterParameters thumb_func_end sub_808DC84 thumb_func_start sub_808DCA0 @@ -247790,7 +247790,7 @@ sub_808DCA0: ldrsh r0, [r2, r1] bx lr .align 2, 0 -_0808DCBC: .4byte gUnknown_202F3E0 +_0808DCBC: .4byte gMonsterParameters thumb_func_end sub_808DCA0 thumb_func_start sub_808DCC0 @@ -247808,7 +247808,7 @@ sub_808DCC0: ldrsh r0, [r1, r2] bx lr .align 2, 0 -_0808DCD8: .4byte gUnknown_202F3E0 +_0808DCD8: .4byte gMonsterParameters thumb_func_end sub_808DCC0 thumb_func_start sub_808DCDC @@ -247828,7 +247828,7 @@ sub_808DCDC: ldrsh r0, [r2, r1] bx lr .align 2, 0 -_0808DCF8: .4byte gUnknown_202F3E0 +_0808DCF8: .4byte gMonsterParameters thumb_func_end sub_808DCDC thumb_func_start sub_808DCFC @@ -247845,7 +247845,7 @@ sub_808DCFC: ldrsh r0, [r1, r2] bx lr .align 2, 0 -_0808DD14: .4byte gUnknown_202F3E0 +_0808DD14: .4byte gMonsterParameters thumb_func_end sub_808DCFC thumb_func_start sub_808DD18 @@ -247871,7 +247871,7 @@ sub_808DD18: pop {r1} bx r1 .align 2, 0 -_0808DD44: .4byte gUnknown_202F3E0 +_0808DD44: .4byte gMonsterParameters thumb_func_end sub_808DD18 thumb_func_start sub_808DD48 @@ -247890,7 +247890,7 @@ sub_808DD48: str r3, [r1, 0x4] bx lr .align 2, 0 -_0808DD64: .4byte gUnknown_202F3E0 +_0808DD64: .4byte gMonsterParameters thumb_func_end sub_808DD48 thumb_func_start sub_808DD68 @@ -247909,7 +247909,7 @@ sub_808DD68: ldrb r0, [r0, 0x8] b _0808DD8A .align 2, 0 -_0808DD84: .4byte gUnknown_202F3E0 +_0808DD84: .4byte gMonsterParameters _0808DD88: movs r0, 0xA _0808DD8A: @@ -247940,7 +247940,7 @@ sub_808DD90: bl OpenFile b _0808DDCA .align 2, 0 -_0808DDBC: .4byte gUnknown_202F3E0 +_0808DDBC: .4byte gMonsterParameters _0808DDC0: .4byte gUnknown_8107684 _0808DDC4: .4byte gUnknown_8510000 _0808DDC8: @@ -247974,7 +247974,7 @@ sub_808DDD0: bl OpenFileAndGetFileDataPtr b _0808DE0A .align 2, 0 -_0808DDFC: .4byte gUnknown_202F3E0 +_0808DDFC: .4byte gMonsterParameters _0808DE00: .4byte gUnknown_8107684 _0808DE04: .4byte gUnknown_8510000 _0808DE08: @@ -248001,7 +248001,7 @@ sub_808DE10: ands r0, r1 bx lr .align 2, 0 -_0808DE2C: .4byte gUnknown_202F3E0 +_0808DE2C: .4byte gMonsterParameters thumb_func_end sub_808DE10 thumb_func_start sub_808DE30 @@ -253777,8 +253777,8 @@ _080909B8: .4byte gUnknown_203B460 _080909BC: .4byte gUnknown_20389A8 _080909C0: .4byte gUnknown_8109764 _080909C4: .4byte gUnknown_8300500 -_080909C8: .4byte gUnknown_20389A0 -_080909CC: .4byte gUnknown_20389A4 +_080909C8: .4byte gItemParametersFile +_080909CC: .4byte gItemParametersFile + 4 thumb_func_end sub_8090998 thumb_func_start sub_80909D0 @@ -254085,7 +254085,7 @@ sub_8090BD0: ldrb r0, [r0, 0xC] bx lr .align 2, 0 -_08090BE0: .4byte gUnknown_20389A4 +_08090BE0: .4byte gItemParametersFile + 4 thumb_func_end sub_8090BD0 thumb_func_start sub_8090BE4 @@ -254112,7 +254112,7 @@ _08090BF6: ldr r0, [r0, 0x4] b _08090C24 .align 2, 0 -_08090C10: .4byte gUnknown_20389A4 +_08090C10: .4byte gItemParametersFile + 4 _08090C14: ldrb r0, [r4, 0x2] ldr r1, _08090C2C @@ -254127,7 +254127,7 @@ _08090C24: pop {r1} bx r1 .align 2, 0 -_08090C2C: .4byte gUnknown_20389A4 +_08090C2C: .4byte gItemParametersFile + 4 thumb_func_end sub_8090BE4 thumb_func_start sub_8090C30 @@ -254154,7 +254154,7 @@ _08090C42: ldr r0, [r0, 0x8] b _08090C70 .align 2, 0 -_08090C5C: .4byte gUnknown_20389A4 +_08090C5C: .4byte gItemParametersFile + 4 _08090C60: ldrb r0, [r4, 0x2] ldr r1, _08090C78 @@ -254169,7 +254169,7 @@ _08090C70: pop {r1} bx r1 .align 2, 0 -_08090C78: .4byte gUnknown_20389A4 +_08090C78: .4byte gItemParametersFile + 4 thumb_func_end sub_8090C30 thumb_func_start sub_8090C7C @@ -254197,7 +254197,7 @@ _08090C90: ldr r0, [r0, 0x4] b _08090CC0 .align 2, 0 -_08090CAC: .4byte gUnknown_20389A4 +_08090CAC: .4byte gItemParametersFile + 4 _08090CB0: ldrb r0, [r4, 0x2] ldr r1, _08090CC8 @@ -254212,7 +254212,7 @@ _08090CC0: pop {r1} bx r1 .align 2, 0 -_08090CC8: .4byte gUnknown_20389A4 +_08090CC8: .4byte gItemParametersFile + 4 thumb_func_end sub_8090C7C thumb_func_start sub_8090CCC @@ -254240,7 +254240,7 @@ _08090CE0: ldr r0, [r0, 0x8] b _08090D10 .align 2, 0 -_08090CFC: .4byte gUnknown_20389A4 +_08090CFC: .4byte gItemParametersFile + 4 _08090D00: ldrb r0, [r4, 0x2] ldr r1, _08090D18 @@ -254255,7 +254255,7 @@ _08090D10: pop {r1} bx r1 .align 2, 0 -_08090D18: .4byte gUnknown_20389A4 +_08090D18: .4byte gItemParametersFile + 4 thumb_func_end sub_8090CCC thumb_func_start sub_8090D1C @@ -254268,7 +254268,7 @@ sub_8090D1C: ldr r0, [r0, 0x4] bx lr .align 2, 0 -_08090D2C: .4byte gUnknown_20389A4 +_08090D2C: .4byte gItemParametersFile + 4 thumb_func_end sub_8090D1C thumb_func_start sub_8090D30 @@ -254281,7 +254281,7 @@ sub_8090D30: ldr r0, [r0, 0x8] bx lr .align 2, 0 -_08090D40: .4byte gUnknown_20389A4 +_08090D40: .4byte gItemParametersFile + 4 thumb_func_end sub_8090D30 thumb_func_start sub_8090D44 @@ -254294,7 +254294,7 @@ sub_8090D44: ldrb r0, [r0, 0x1A] bx lr .align 2, 0 -_08090D54: .4byte gUnknown_20389A4 +_08090D54: .4byte gItemParametersFile + 4 thumb_func_end sub_8090D44 thumb_func_start sub_8090D58 @@ -254307,7 +254307,7 @@ sub_8090D58: ldrb r0, [r0, 0x1D] bx lr .align 2, 0 -_08090D68: .4byte gUnknown_20389A4 +_08090D68: .4byte gItemParametersFile + 4 thumb_func_end sub_8090D58 thumb_func_start sub_8090D6C @@ -254320,7 +254320,7 @@ sub_8090D6C: ldrb r0, [r0, 0x1E] bx lr .align 2, 0 -_08090D7C: .4byte gUnknown_20389A4 +_08090D7C: .4byte gItemParametersFile + 4 thumb_func_end sub_8090D6C thumb_func_start sub_8090D80 @@ -254335,7 +254335,7 @@ sub_8090D80: ldrb r0, [r0] bx lr .align 2, 0 -_08090D94: .4byte gUnknown_20389A4 +_08090D94: .4byte gItemParametersFile + 4 thumb_func_end sub_8090D80 thumb_func_start sub_8090D98 @@ -254348,7 +254348,7 @@ sub_8090D98: ldr r0, [r0, 0x10] bx lr .align 2, 0 -_08090DA8: .4byte gUnknown_20389A4 +_08090DA8: .4byte gItemParametersFile + 4 thumb_func_end sub_8090D98 thumb_func_start sub_8090DAC @@ -254363,7 +254363,7 @@ sub_8090DAC: ldrb r0, [r0] bx lr .align 2, 0 -_08090DC0: .4byte gUnknown_20389A4 +_08090DC0: .4byte gItemParametersFile + 4 thumb_func_end sub_8090DAC thumb_func_start sub_8090DC4 @@ -254404,7 +254404,7 @@ sub_8090DC4: pop {r0} bx r0 .align 2, 0 -_08090E10: .4byte gUnknown_20389A4 +_08090E10: .4byte gItemParametersFile + 4 thumb_func_end sub_8090DC4 thumb_func_start sub_8090E14 @@ -254453,7 +254453,7 @@ _08090E50: b _08090EC4 .align 2, 0 _08090E68: .4byte gUnknown_8109770 -_08090E6C: .4byte gUnknown_20389A4 +_08090E6C: .4byte gItemParametersFile + 4 _08090E70: ldr r1, _08090E88 ldrb r0, [r5, 0x2] @@ -254467,7 +254467,7 @@ _08090E70: b _08090EC4 .align 2, 0 _08090E88: .4byte gUnknown_8109778 -_08090E8C: .4byte gUnknown_20389A4 +_08090E8C: .4byte gItemParametersFile + 4 _08090E90: ldrb r0, [r5, 0x2] cmp r0, 0x69 @@ -254544,7 +254544,7 @@ _08090F14: bl sub_8090F58 b _08090F50 .align 2, 0 -_08090F2C: .4byte gUnknown_20389A4 +_08090F2C: .4byte gItemParametersFile + 4 _08090F30: .4byte gUnknown_8109784 _08090F34: .4byte gUnknown_810978C _08090F38: @@ -255209,7 +255209,7 @@ sub_80913CC: ldrh r0, [r0, 0x18] bx lr .align 2, 0 -_080913DC: .4byte gUnknown_20389A4 +_080913DC: .4byte gItemParametersFile + 4 thumb_func_end sub_80913CC thumb_func_start sub_80913E0 @@ -258154,7 +258154,7 @@ LoadWazaParameters: .align 2, 0 _08092868: .4byte gUnknown_81098D0 _0809286C: .4byte gUnknown_8300500 -_08092870: .4byte gUnknown_2038C64 +_08092870: .4byte gWazaParametersFile _08092874: .4byte gUnknown_2038C68 _08092878: .4byte gUnknown_2038C6C thumb_func_end LoadWazaParameters @@ -271490,7 +271490,7 @@ _080988F8: bl GroundEffect_Action bl nullsub_105 bl sub_809B474 - bl sub_80A2380 + bl GroundScript_Unlock bl sub_809D25C bl sub_80A59DC bl sub_809B614 @@ -271783,7 +271783,7 @@ _08098BD2: sub_8098BDC: push {lr} bl sub_809B57C - bl sub_80A2380 + bl GroundScript_Unlock bl sub_809D25C bl sub_80A59DC bl sub_809B614 @@ -279959,7 +279959,7 @@ sub_809CBBC: b _0809CC4A .align 2, 0 _0809CC0C: .4byte gUnknown_81163E4 -_0809CC10: .4byte gUnknown_20389A4 +_0809CC10: .4byte gItemParametersFile + 4 _0809CC14: .4byte gUnknown_203B460 _0809CC18: .4byte 0x0001869f _0809CC1C: @@ -284745,28 +284745,28 @@ _0809F3DC: .4byte gUnknown_2039A32 _0809F3E0: adds r0, r6, 0 adds r1, r5, 0 - bl sub_80A7988 + bl GroundLives_Cancel adds r0, r6, 0 adds r1, r5, 0 - bl sub_80ABC5C + bl GroundObject_Cancel adds r0, r6, 0 adds r1, r5, 0 - bl sub_80ACC98 + bl GroundEffect_Cancel b _0809F41E _0809F3FA: adds r0, r6, 0 adds r1, r5, 0 - bl sub_80A7988 + bl GroundLives_Cancel bl _0809EAE0 _0809F406: adds r0, r6, 0 adds r1, r5, 0 - bl sub_80ABC5C + bl GroundObject_Cancel bl _0809EAE0 _0809F412: adds r0, r6, 0 adds r1, r5, 0 - bl sub_80ACC98 + bl GroundEffect_Cancel bl _0809EAE0 _0809F41E: adds r0, r6, 0 @@ -284777,10 +284777,10 @@ _0809F42A: bl sub_80A79FC bl _0809EAE0 _0809F432: - bl sub_80ABCCC + bl GroundObject_CancelBlank bl _0809EAE0 _0809F43A: - bl sub_80ACD08 + bl GroundEffect_CancelBlank bl _0809EAE0 _0809F442: mov r2, r9 @@ -290448,7 +290448,7 @@ _080A233A: b _080A236A _080A2346: movs r0, 0 - bl sub_80A6C88 + bl GroundSprite_ExtendPaletteDelete b _080A236A _080A234E: movs r0, 0 @@ -290478,8 +290478,8 @@ _080A236C: bx r1 thumb_func_end sub_80A14E8 - thumb_func_start sub_80A2380 -sub_80A2380: + thumb_func_start GroundScript_Unlock +GroundScript_Unlock: push {r4-r7,lr} ldr r1, _080A241C ldrb r0, [r1] @@ -290557,7 +290557,7 @@ _080A241C: .4byte gUnknown_2039A36 _080A2420: .4byte gUnknown_2039A38 _080A2424: .4byte gUnknown_8116848 _080A2428: .4byte gUnknown_2039AC0 - thumb_func_end sub_80A2380 + thumb_func_end GroundScript_Unlock thumb_func_start sub_80A242C sub_80A242C: @@ -299986,7 +299986,7 @@ sub_80A69FC: cmp r4, 0 blt _080A6A7A adds r0, r6, 0 - bl sub_80A6C88 + bl GroundSprite_ExtendPaletteDelete movs r0, 0 str r0, [r5, 0x8] str r0, [r5] @@ -300303,8 +300303,8 @@ _080A6C78: bx r0 thumb_func_end GroundSprite_ExtendPaletteAdd - thumb_func_start sub_80A6C88 -sub_80A6C88: + thumb_func_start GroundSprite_ExtendPaletteDelete +GroundSprite_ExtendPaletteDelete: push {r4-r6,lr} adds r2, r0, 0 cmp r2, 0 @@ -300360,7 +300360,7 @@ _080A6CE6: .align 2, 0 _080A6CEC: .4byte gUnknown_3001B7C _080A6CF0: .4byte gUnknown_81178C0 - thumb_func_end sub_80A6C88 + thumb_func_end GroundSprite_ExtendPaletteDelete thumb_func_start sub_80A6CF4 sub_80A6CF4: @@ -301931,7 +301931,7 @@ _080A787C: cmp r0, r6 beq _080A788A adds r0, r1, 0 - bl sub_80A8684 + bl GroundLives_Delete _080A788A: adds r0, r5, 0 movs r1, 0x80 @@ -302062,8 +302062,8 @@ _080A7980: .4byte gUnknown_811808C _080A7984: .4byte gUnknown_8118098 thumb_func_end GroundLives_Select - thumb_func_start sub_80A7988 -sub_80A7988: + thumb_func_start GroundLives_Cancel +GroundLives_Cancel: push {r4-r7,lr} mov r7, r8 push {r7} @@ -302101,7 +302101,7 @@ _080A79B2: bne _080A79D4 _080A79CE: adds r0, r1, 0 - bl sub_80A8684 + bl GroundLives_Delete _080A79D4: adds r0, r6, 0 movs r1, 0x80 @@ -302121,7 +302121,7 @@ _080A79D4: .align 2, 0 _080A79F4: .4byte gUnknown_81180BC _080A79F8: .4byte gUnknown_3001B84 - thumb_func_end sub_80A7988 + thumb_func_end GroundLives_Cancel thumb_func_start sub_80A79FC sub_80A79FC: @@ -302164,7 +302164,7 @@ _080A7A20: cmp r0, 0 bne _080A7A50 adds r0, r6, 0 - bl sub_80A8684 + bl GroundLives_Delete _080A7A50: adds r0, r6, 0x1 lsls r0, 16 @@ -303749,8 +303749,8 @@ _080A8674: bx r1 thumb_func_end GroundLives_Add - thumb_func_start sub_80A8684 -sub_80A8684: + thumb_func_start GroundLives_Delete +GroundLives_Delete: push {r4,lr} adds r2, r0, 0 lsls r2, 16 @@ -303780,7 +303780,7 @@ sub_80A8684: _080A86BC: .4byte gUnknown_3001B84 _080A86C0: .4byte gUnknown_8118194 _080A86C4: .4byte 0x0000ffff - thumb_func_end sub_80A8684 + thumb_func_end GroundLives_Delete thumb_func_start sub_80A86C8 sub_80A86C8: @@ -309318,7 +309318,7 @@ _080AB278: b _080AB44C _080AB292: mov r0, r9 - bl sub_80A8684 + bl GroundLives_Delete b _080AB47C .align 2, 0 _080AB29C: .4byte gUnknown_3001B84 @@ -310631,8 +310631,8 @@ _080ABC54: .4byte gUnknown_81183E4 _080ABC58: .4byte gUnknown_81183F0 thumb_func_end GroundObject_Select - thumb_func_start sub_80ABC5C -sub_80ABC5C: + thumb_func_start GroundObject_Cancel +GroundObject_Cancel: push {r4-r7,lr} mov r7, r8 push {r7} @@ -310689,10 +310689,10 @@ _080ABCA6: .align 2, 0 _080ABCC4: .4byte gUnknown_8118414 _080ABCC8: .4byte gUnknown_3001B88 - thumb_func_end sub_80ABC5C + thumb_func_end GroundObject_Cancel - thumb_func_start sub_80ABCCC -sub_80ABCCC: + thumb_func_start GroundObject_CancelBlank +GroundObject_CancelBlank: push {r4-r7,lr} mov r7, r8 push {r7} @@ -310752,7 +310752,7 @@ _080ABD20: .align 2, 0 _080ABD40: .4byte gUnknown_811842C _080ABD44: .4byte gUnknown_3001B88 - thumb_func_end sub_80ABCCC + thumb_func_end GroundObject_CancelBlank thumb_func_start sub_80ABD48 sub_80ABD48: @@ -312792,7 +312792,7 @@ _080ACBE4: cmp r0, r6 beq _080ACBF2 adds r0, r1, 0 - bl sub_80AD080 + bl GroundEffect_Delete _080ACBF2: adds r0, r5, 0 movs r1, 0x80 @@ -312882,8 +312882,8 @@ _080ACC90: .4byte gUnknown_8118610 _080ACC94: .4byte gUnknown_811861C thumb_func_end GroundEffect_Select - thumb_func_start sub_80ACC98 -sub_80ACC98: + thumb_func_start GroundEffect_Cancel +GroundEffect_Cancel: push {r4-r7,lr} mov r7, r8 push {r7} @@ -312920,7 +312920,7 @@ _080ACCC0: bne _080ACCE2 _080ACCDC: adds r0, r1, 0 - bl sub_80AD080 + bl GroundEffect_Delete _080ACCE2: adds r0, r6, 0 movs r1, 0x80 @@ -312940,10 +312940,10 @@ _080ACCE2: .align 2, 0 _080ACD00: .4byte gUnknown_8118640 _080ACD04: .4byte gUnknown_3001B8C - thumb_func_end sub_80ACC98 + thumb_func_end GroundEffect_Cancel - thumb_func_start sub_80ACD08 -sub_80ACD08: + thumb_func_start GroundEffect_CancelBlank +GroundEffect_CancelBlank: push {r4-r7,lr} mov r7, r8 push {r7} @@ -312983,7 +312983,7 @@ _080ACD2C: cmp r0, 0 bne _080ACD5C adds r0, r6, 0 - bl sub_80AD080 + bl GroundEffect_Delete _080ACD5C: adds r0, r6, 0x1 lsls r0, 16 @@ -313003,7 +313003,7 @@ _080ACD5C: .align 2, 0 _080ACD7C: .4byte gUnknown_8118658 _080ACD80: .4byte gUnknown_3001B8C - thumb_func_end sub_80ACD08 + thumb_func_end GroundEffect_CancelBlank thumb_func_start sub_80ACD84 sub_80ACD84: @@ -313399,8 +313399,8 @@ _080AD078: .4byte gUnknown_812F1F8 _080AD07C: .4byte gUnknown_81186CC thumb_func_end GroundEffect_Add - thumb_func_start sub_80AD080 -sub_80AD080: + thumb_func_start GroundEffect_Delete +GroundEffect_Delete: push {r4,lr} adds r2, r0, 0 lsls r2, 16 @@ -313432,7 +313432,7 @@ sub_80AD080: _080AD0BC: .4byte gUnknown_3001B8C _080AD0C0: .4byte gUnknown_81186D8 _080AD0C4: .4byte 0x0000ffff - thumb_func_end sub_80AD080 + thumb_func_end GroundEffect_Delete thumb_func_start sub_80AD0C8 sub_80AD0C8: @@ -314398,7 +314398,7 @@ _080AD72C: cmp r0, 0x4 bne _080AD768 adds r0, r7, 0 - bl sub_80AD080 + bl GroundEffect_Delete b _080AD78A .align 2, 0 _080AD754: .4byte gUnknown_3001B8C diff --git a/asm/m4a.s b/asm/m4a.s index 71336705..602f9b93 100644 --- a/asm/m4a.s +++ b/asm/m4a.s @@ -1,5 +1,6 @@ - .include "constants/gba_constants.inc" .include "asm/macros.inc" + .include "constants/gba_constants.inc" + .include "constants/m4a_constants.inc" .syntax unified @@ -18,16 +19,16 @@ _080AE268: thumb_func_start SoundMain SoundMain: - ldr r0, _080AE2E0 + ldr r0, lt_SOUND_INFO_PTR ldr r0, [r0] - ldr r2, _080AE2E4 - ldr r3, [r0] + ldr r2, lt_ID_NUMBER + ldr r3, [r0, o_SoundInfo_ident] cmp r2, r3 - beq _080AE282 - bx lr -_080AE282: - adds r3, 0x1 - str r3, [r0] + beq SoundMain_1 + bx lr @ Exit the function if ident doesn't match ID_NUMBER. +SoundMain_1: + adds r3, 1 + str r3, [r0, o_SoundInfo_ident] push {r4-r7,lr} mov r1, r8 mov r2, r9 @@ -35,65 +36,66 @@ _080AE282: mov r4, r11 push {r0-r4} sub sp, 0x18 - ldrb r1, [r0, 0xC] - cmp r1, 0 - beq _080AE2A6 - ldr r2, _080AE2EC + ldrb r1, [r0, o_SoundInfo_maxLines] + cmp r1, 0 @ if maxLines is 0, there is no maximum + beq SoundMain_3 + ldr r2, lt_REG_VCOUNT ldrb r2, [r2] - cmp r2, 0xA0 - bcs _080AE2A4 - adds r2, 0xE4 -_080AE2A4: + cmp r2, VCOUNT_VBLANK + bhs SoundMain_2 + adds r2, TOTAL_SCANLINES +SoundMain_2: adds r1, r2 -_080AE2A6: +SoundMain_3: str r1, [sp, 0x14] - ldr r3, [r0, 0x20] + ldr r3, [r0, o_SoundInfo_func] cmp r3, 0 - beq _080AE2B6 - ldr r0, [r0, 0x24] + beq SoundMain_4 + ldr r0, [r0, o_SoundInfo_intp] bl call_r3 ldr r0, [sp, 0x18] -_080AE2B6: - ldr r3, [r0, 0x28] +SoundMain_4: + ldr r3, [r0, o_SoundInfo_CgbSound] bl call_r3 ldr r0, [sp, 0x18] - ldr r3, [r0, 0x10] + ldr r3, [r0, o_SoundInfo_pcmSamplesPerVBlank] mov r8, r3 - ldr r5, _080AE2F0 + ldr r5, lt_o_SoundInfo_pcmBuffer adds r5, r0 - ldrb r4, [r0, 0x4] - subs r7, r4, 0x1 - bls _080AE2D6 - ldrb r1, [r0, 0xB] + ldrb r4, [r0, o_SoundInfo_pcmDmaCounter] + subs r7, r4, 1 + bls SoundMain_5 + ldrb r1, [r0, o_SoundInfo_pcmDmaPeriod] subs r1, r7 mov r2, r8 muls r2, r1 adds r5, r2 -_080AE2D6: +SoundMain_5: str r5, [sp, 0x8] - ldr r6, _080AE2F4 - ldr r3, _080AE2E8 + ldr r6, lt_PCM_DMA_BUF_SIZE + ldr r3, lt_SoundMainRAM_Buffer bx r3 + .align 2, 0 -_080AE2E0: .4byte SOUND_INFO_PTR -_080AE2E4: .4byte 0x68736d53 -_080AE2E8: .4byte SoundMainRAM_Buffer + 1 -_080AE2EC: .4byte 0x04000006 -_080AE2F0: .4byte 0x00000350 -_080AE2F4: .4byte 0x00000630 +lt_SOUND_INFO_PTR: .word SOUND_INFO_PTR +lt_ID_NUMBER: .word ID_NUMBER +lt_SoundMainRAM_Buffer: .word SoundMainRAM_Buffer + 1 +lt_REG_VCOUNT: .word REG_VCOUNT +lt_o_SoundInfo_pcmBuffer: .word o_SoundInfo_pcmBuffer +lt_PCM_DMA_BUF_SIZE: .word PCM_DMA_BUF_SIZE thumb_func_end SoundMain - thumb_func_start sub_80AE2F8 -sub_80AE2F8: - ldrb r3, [r0, 0x5] + thumb_func_start SoundMainRAM +SoundMainRAM: + ldrb r3, [r0, o_SoundInfo_reverb] cmp r3, 0 - beq _080AE358 - adr r1, _080AE304 + beq SoundMainRAM_NoReverb + adr r1, SoundMainRAM_Reverb bx r1 .arm -_080AE304: +SoundMainRAM_Reverb: cmp r4, 0x2 - addeq r7, r0, 0x350 + addeq r7, r0, o_SoundInfo_pcmBuffer addne r7, r5, r8 mov r4, r8 _080AE314: @@ -115,22 +117,22 @@ _080AE314: add r0, pc, 0x2F bx r0 .thumb -_080AE358: +SoundMainRAM_NoReverb: movs r0, 0 mov r1, r8 adds r6, r5 lsrs r1, 3 - bcc _080AE366 + bcc SoundMainRAM_NoReverb_Ok stm r5!, {r0} stm r6!, {r0} -_080AE366: +SoundMainRAM_NoReverb_Ok: lsrs r1, 1 - bcc _080AE372 + bcc SoundMainRAM_NoReverb_Loop stm r5!, {r0} stm r6!, {r0} stm r5!, {r0} stm r6!, {r0} -_080AE372: +SoundMainRAM_NoReverb_Loop: stm r5!, {r0} stm r6!, {r0} stm r5!, {r0} @@ -140,31 +142,33 @@ _080AE372: stm r5!, {r0} stm r6!, {r0} subs r1, 0x1 - bgt _080AE372 + bgt SoundMainRAM_NoReverb_Loop +_080AE386: ldr r4, [sp, 0x18] - ldr r0, [r4, 0x18] + ldr r0, [r4, o_SoundInfo_divFreq] mov r12, r0 - ldrb r0, [r4, 0x6] - adds r4, 0x50 -_080AE390: + ldrb r0, [r4, o_SoundInfo_maxChans] + adds r4, o_SoundInfo_chans +SoundMainRAM_ChanLoop: str r0, [sp, 0x4] - ldr r3, [r4, 0x24] + ldr r3, [r4, o_SoundChannel_wav] ldr r0, [sp, 0x14] cmp r0, 0 beq _080AE3B0 - ldr r1, _080AE3AC + ldr r1, =REG_VCOUNT ldrb r1, [r1] - cmp r1, 0xA0 - bcs _080AE3A4 - adds r1, 0xE4 + cmp r1, VCOUNT_VBLANK + bhs _080AE3A4 + adds r1, TOTAL_SCANLINES _080AE3A4: cmp r1, r0 bcc _080AE3B0 b _080AE682 - .align 2, 0 -_080AE3AC: .4byte 0x04000006 + + .pool + _080AE3B0: - ldrb r6, [r4] + ldrb r6, [r4, o_SoundChannel_status] movs r0, 0xC7 tst r0, r6 bne _080AE3BA @@ -177,96 +181,96 @@ _080AE3BA: tst r0, r6 bne _080AE3FA movs r6, 0x3 - strb r6, [r4] + strb r6, [r4, o_SoundChannel_status] adds r0, r3, 0 adds r0, 0x10 - str r0, [r4, 0x28] + str r0, [r4, o_SoundChannel_cp] ldr r0, [r3, 0xC] - str r0, [r4, 0x18] + str r0, [r4, o_SoundChannel_ct] movs r5, 0 - strb r5, [r4, 0x9] - str r5, [r4, 0x1C] + strb r5, [r4, o_SoundChannel_ev] + str r5, [r4, o_SoundChannel_fw] ldrb r2, [r3, 0x3] movs r0, 0xC0 tst r0, r2 beq _080AE442 movs r0, 0x10 orrs r6, r0 - strb r6, [r4] + strb r6, [r4, o_SoundChannel_status] b _080AE442 _080AE3EA: - ldrb r5, [r4, 0x9] + ldrb r5, [r4, o_SoundChannel_ev] movs r0, 0x4 tst r0, r6 beq _080AE400 - ldrb r0, [r4, 0xD] + ldrb r0, [r4, o_SoundChannel_iel] subs r0, 0x1 - strb r0, [r4, 0xD] + strb r0, [r4, o_SoundChannel_iel] bhi _080AE450 _080AE3FA: movs r0, 0 - strb r0, [r4] + strb r0, [r4, o_SoundChannel_status] b _080AE678 _080AE400: movs r0, 0x40 tst r0, r6 beq _080AE420 - ldrb r0, [r4, 0x7] + ldrb r0, [r4, o_SoundChannel_release] muls r5, r0 lsrs r5, 8 - ldrb r0, [r4, 0xC] + ldrb r0, [r4, o_SoundChannel_iev] cmp r5, r0 bhi _080AE450 _080AE412: - ldrb r5, [r4, 0xC] + ldrb r5, [r4, o_SoundChannel_iev] cmp r5, 0 beq _080AE3FA movs r0, 0x4 orrs r6, r0 - strb r6, [r4] + strb r6, [r4, o_SoundChannel_status] b _080AE450 _080AE420: movs r2, 0x3 ands r2, r6 cmp r2, 0x2 bne _080AE43E - ldrb r0, [r4, 0x5] + ldrb r0, [r4, o_SoundChannel_decay] muls r5, r0 lsrs r5, 8 - ldrb r0, [r4, 0x6] + ldrb r0, [r4, o_SoundChannel_sustain] cmp r5, r0 bhi _080AE450 adds r5, r0, 0 beq _080AE412 subs r6, 0x1 - strb r6, [r4] + strb r6, [r4, o_SoundChannel_status] b _080AE450 _080AE43E: cmp r2, 0x3 bne _080AE450 _080AE442: - ldrb r0, [r4, 0x4] + ldrb r0, [r4, o_SoundChannel_attack] adds r5, r0 cmp r5, 0xFF bcc _080AE450 movs r5, 0xFF subs r6, 0x1 - strb r6, [r4] + strb r6, [r4, o_SoundChannel_status] _080AE450: - strb r5, [r4, 0x9] + strb r5, [r4, o_SoundChannel_ev] ldr r0, [sp, 0x18] - ldrb r0, [r0, 0x7] + ldrb r0, [r0, o_SoundChannel_release] adds r0, 0x1 muls r0, r5 lsrs r5, r0, 4 - ldrb r0, [r4, 0x2] + ldrb r0, [r4, o_SoundChannel_rightVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, 0xA] - ldrb r0, [r4, 0x3] + strb r0, [r4, o_SoundChannel_er] + ldrb r0, [r4, o_SoundChannel_leftVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, 0xB] + strb r0, [r4, o_SoundChannel_el] movs r0, 0x10 ands r0, r6 str r0, [sp, 0x10] @@ -281,18 +285,18 @@ _080AE450: str r0, [sp, 0x10] _080AE484: ldr r5, [sp, 0x8] - ldr r2, [r4, 0x18] - ldr r3, [r4, 0x28] + ldr r2, [r4, o_SoundChannel_ct] + ldr r3, [r4, o_SoundChannel_cp] adr r0, _080AE490 bx r0 .arm _080AE490: str r8, [sp] - ldrb r10, [r4, 0xA] - ldrb r11, [r4, 0xB] + ldrb r10, [r4, o_SoundChannel_er] + ldrb r11, [r4, o_SoundChannel_el] mov r10, r10, lsl 16 mov r11, r11, lsl 16 - ldrb r0, [r4, 0x1] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x8 beq _080AE5D0 _080AE4B0: @@ -368,7 +372,7 @@ _080AE598: ldrne r3, [sp, 0xC] bne _080AE54C _080AE5A8: - strb r2, [r4] + strb r2, [r4, o_SoundChannel_status] mov r0, r5, lsr 30 bic r5, r5, 0xC0000000 rsb r0, r0, 0x3 @@ -380,8 +384,8 @@ _080AE5A8: b _080AE66C _080AE5D0: stmdb sp!, {r4,r12} - ldr lr, [r4, 0x1C] - ldr r1, [r4, 0x20] + ldr lr, [r4, o_SoundChannel_fw] + ldr r1, [r4, o_SoundChannel_freq] mul r4, r12, r1 ldrsb r0, [r3] ldrsb r1, [r3, 0x1]! @@ -419,10 +423,10 @@ _080AE640: bgt _080AE5EC sub r3, r3, 0x1 ldmia sp!, {r4,r12} - str lr, [r4, 0x1C] + str lr, [r4, o_SoundChannel_fw] _080AE664: - str r2, [r4, 0x18] - str r3, [r4, 0x28] + str r2, [r4, o_SoundChannel_ct] + str r3, [r4, o_SoundChannel_cp] _080AE66C: ldr r8, [sp] add r0, pc, 0x1 @@ -432,11 +436,11 @@ _080AE678: ldr r0, [sp, 0x4] subs r0, 0x1 ble _080AE682 - adds r4, 0x40 - b _080AE390 + adds r4, SoundChannel_size + b SoundMainRAM_ChanLoop _080AE682: ldr r0, [sp, 0x18] - ldr r3, _080AE698 + ldr r3, =ID_NUMBER str r3, [r0] add sp, 0x1C pop {r0-r7} @@ -448,10 +452,8 @@ _080AE682: call_r3: bx r3 - - .align 2, 0 -_080AE698: .4byte 0x68736D53 - thumb_func_end sub_80AE2F8 + .pool + thumb_func_end SoundMainRAM thumb_func_start sub_80AE69C sub_80AE69C: @@ -1770,7 +1772,7 @@ _080AEF72: pop {r0} bx r0 .align 2, 0 -_080AEF78: .4byte sub_80AE2F8 +_080AEF78: .4byte SoundMainRAM _080AEF7C: .4byte SoundMainRAM_Buffer _080AEF80: .4byte 0x04000100 _080AEF84: .4byte gUnknown_2039ED0 diff --git a/asm/memory.s b/asm/memory.s index 418056cd..1b9d36eb 100644 --- a/asm/memory.s +++ b/asm/memory.s @@ -5,107 +5,6 @@ .text - thumb_func_start InitHeapInternal -InitHeapInternal: - push {lr} - sub sp, 0x8 - ldr r0, =gHeap - str r0, [sp] - movs r0, 0x90 - lsls r0, 10 - str r0, [sp, 0x4] - ldr r1, =gUnknown_2000EA8 - movs r0, 0 - str r0, [r1] - ldr r0, =gUnknown_2000EB0 - ldr r2, =gHeapHeader - mov r1, sp - movs r3, 0x20 - bl DoInitHeap - add sp, 0x8 - pop {r0} - bx r0 - .align 2, 0 - .pool - thumb_func_end InitHeapInternal - - thumb_func_start DoInitHeap -DoInitHeap: - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - ldr r4, [r1, 0x4] - mov r9, r4 - movs r4, 0x4 - negs r4, r4 - mov r5, r9 - ands r5, r4 - mov r9, r5 - ldr r6, =gUnknown_2000E88 - ldr r4, =gUnknown_2000EA8 - mov r8, r4 - ldr r5, [r4] - lsls r4, r5, 2 - adds r4, r6 - str r0, [r4] - adds r5, 0x1 - mov r4, r8 - str r5, [r4] - ldr r5, [r1] - str r5, [r0, 0x14] - mov r1, r9 - str r1, [r0, 0x18] - movs r1, 0x2 - str r1, [r0] - movs r4, 0 - str r4, [r0, 0x4] - str r2, [r0, 0x8] - movs r1, 0x1 - str r1, [r0, 0xC] - str r3, [r0, 0x10] - str r4, [r2] - str r4, [r2, 0x4] - str r5, [r2, 0xC] - mov r5, r9 - str r5, [r2, 0x10] - str r4, [r2, 0x14] - str r4, [r2, 0x8] - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 - .pool - thumb_func_end DoInitHeap - - thumb_func_start InitSubHeap -InitSubHeap: - push {r4,r5,lr} - sub sp, 0x8 - adds r3, r2, 0 - lsls r4, r3, 1 - adds r4, r3 - movs r2, 0x4 - negs r2, r2 - lsls r4, 3 - ldr r5, [r1, 0x4] - subs r5, r4 - ands r5, r2 - ldr r2, [r1] - adds r4, r2, r4 - str r4, [sp] - str r5, [sp, 0x4] - mov r1, sp - bl DoInitHeap - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end InitSubHeap - thumb_func_start xxx_memory_attr_related xxx_memory_attr_related: push {lr} @@ -201,7 +100,7 @@ _080030C2: _080030CC: movs r7, 0x1 negs r7, r7 - ldr r1, =0x24001 + ldr r1, _08003100 movs r4, 0 ldr r3, [r5, 0x8] ldr r2, [r5, 0xC] @@ -229,7 +128,7 @@ _080030FC: adds r0, r7, 0 b _08003108 .align 2, 0 - .pool +_08003100: .4byte 0x00024001 _08003104: movs r0, 0x1 negs r0, r0 @@ -555,7 +454,7 @@ _LocateSet: adds r6, r2, 0 cmp r5, 0 bne _0800335C - ldr r5, =gUnknown_2000EB0 + ldr r5, =gMainHeapDescriptor _0800335C: asrs r4, r6, 8 movs r0, 0x1 @@ -619,7 +518,7 @@ MemoryAlloc: push {lr} adds r3, r0, 0 adds r2, r1, 0 - ldr r0, =gUnknown_2000EB0 + ldr r0, =gMainHeapDescriptor adds r1, r3, 0 bl DoAlloc pop {r1} @@ -632,7 +531,7 @@ MemoryAlloc: MemoryFree: push {lr} adds r1, r0, 0 - ldr r0, =gUnknown_2000EB0 + ldr r0, =gMainHeapDescriptor bl DoFree pop {r0} bx r0 @@ -650,7 +549,7 @@ MemoryLocate_LocalCreate: adds r6, r3, 0 cmp r4, 0 bne _08003412 - ldr r4, =gUnknown_2000EB0 + ldr r4, =gMainHeapDescriptor _08003412: adds r0, r4, 0 movs r1, 0x9 @@ -728,11 +627,11 @@ _080034A2: movs r0, 0 mov r12, r0 movs r3, 0 - ldr r6, =gUnknown_2000EA8 + ldr r6, =gHeapCount ldr r0, [r6] cmp r12, r0 bge _080034F2 - ldr r5, =gUnknown_2000E88 + ldr r5, =gHeapDescriptorList adds r1, r6, 0 adds r7, r5, 0 movs r2, 0 @@ -746,7 +645,7 @@ _080034BC: str r0, [r1] cmp r3, r0 bge _080034F8 - ldr r1, =gUnknown_2000EA8 + ldr r1, =gHeapCount adds r2, r7 _080034D2: ldr r0, [r2, 0x4] @@ -800,7 +699,7 @@ DoFree: adds r4, r0, 0 cmp r4, 0 bne _0800352E - ldr r4, =gUnknown_2000EB0 + ldr r4, =gMainHeapDescriptor _0800352E: cmp r1, 0 beq _080035E4 diff --git a/asm/rom_header.inc b/asm/rom_header.inc index 09b95ece..6730efae 100644 --- a/asm/rom_header.inc +++ b/asm/rom_header.inc @@ -1,37 +1,19 @@ .global RomHeaderNintendoLogo RomHeaderNintendoLogo: - .byte 0x24,0xff,0xae,0x51,0x69,0x9a,0xa2,0x21 - .byte 0x3d,0x84,0x82,0x0a,0x84,0xe4,0x09,0xad - .byte 0x11,0x24,0x8b,0x98,0xc0,0x81,0x7f,0x21 - .byte 0xa3,0x52,0xbe,0x19,0x93,0x09,0xce,0x20 - .byte 0x10,0x46,0x4a,0x4a,0xf8,0x27,0x31,0xec - .byte 0x58,0xc7,0xe8,0x33,0x82,0xe3,0xce,0xbf - .byte 0x85,0xf4,0xdf,0x94,0xce,0x4b,0x09,0xc1 - .byte 0x94,0x56,0x8a,0xc0,0x13,0x72,0xa7,0xfc - .byte 0x9f,0x84,0x4d,0x73,0xa3,0xca,0x9a,0x61 - .byte 0x58,0x97,0xa3,0x27,0xfc,0x03,0x98,0x76 - .byte 0x23,0x1d,0xc7,0x61,0x03,0x04,0xae,0x56 - .byte 0xbf,0x38,0x84,0x00,0x40,0xa7,0x0e,0xfd - .byte 0xff,0x52,0xfe,0x03,0x6f,0x95,0x30,0xf1 - .byte 0x97,0xfb,0xc0,0x85,0x60,0xd6,0x80,0x25 - .byte 0xa9,0x63,0xbe,0x03,0x01,0x4e,0x38,0xe2 - .byte 0xf9,0xa2,0x34,0xff,0xbb,0x3e,0x03,0x44 - .byte 0x78,0x00,0x90,0xcb,0x88,0x11,0x3a,0x94 - .byte 0x65,0xc0,0x7c,0x63,0x87,0xf0,0x3c,0xaf - .byte 0xd6,0x25,0xe4,0x8b,0x38,0x0a,0xac,0x72 - .byte 0x21,0xd4,0xf8,0x07 + .space 156 RomHeaderGameTitle: - .ascii "POKE DUNGEON" + .space 12 + .global RomHeaderGameCode RomHeaderGameCode: - .ascii "B24E" + .space 4 RomHeaderMakerCode: - .ascii "01" + .space 2 RomHeaderMagic: - .byte 0x96 + .byte 0 RomHeaderMainUnitCode: .byte 0 @@ -42,11 +24,12 @@ RomHeaderDeviceType: RomHeaderReserved1: .space 7 + .global RomHeaderSoftwareVersion RomHeaderSoftwareVersion: .byte 0 RomHeaderChecksum: - .byte 0xA4 + .byte 0 RomHeaderReserved2: .space 2 diff --git a/asm/save.s b/asm/save.s index b4e748f5..2ebaaa41 100644 --- a/asm/save.s +++ b/asm/save.s @@ -5,48 +5,18 @@ .text - thumb_func_start sub_8011C7C -sub_8011C7C: - push {r4,lr} - adds r4, r0, 0 - movs r2, 0 - lsrs r1, 2 - cmp r1, 0x1 - ble _08011C96 - adds r3, r4, 0x4 - subs r1, 0x1 -_08011C8C: - ldm r3!, {r0} - adds r2, r0 - subs r1, 0x1 - cmp r1, 0 - bne _08011C8C -_08011C96: - ldr r0, [r4] - cmp r0, r2 - bne _08011CA0 - movs r0, 0 - b _08011CA2 -_08011CA0: - movs r0, 0x1 -_08011CA2: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8011C7C - thumb_func_start sub_8011CA8 sub_8011CA8: push {lr} adds r3, r0, 0 adds r2, r1, 0 - ldr r0, _08011CCC + ldr r0, =gUnknown_203B184 ldr r0, [r0] - ldr r0, _08011CD0 + ldr r0, =0xfff adds r1, r2, r0 cmp r1, 0 bge _08011CBE - ldr r0, _08011CD4 + ldr r0, =0x1ffe adds r1, r2, r0 _08011CBE: asrs r1, 12 @@ -56,13 +26,11 @@ _08011CBE: pop {r0} bx r0 .align 2, 0 -_08011CCC: .4byte gUnknown_203B184 -_08011CD0: .4byte 0x00000fff -_08011CD4: .4byte 0x00001ffe + .pool thumb_func_end sub_8011CA8 - thumb_func_start sub_8011CD8 -sub_8011CD8: + thumb_func_start WriteSaveSector +WriteSaveSector: push {r4-r6,lr} adds r5, r1, 0 adds r4, r2, 0 @@ -71,7 +39,7 @@ sub_8011CD8: bl sub_8011CA8 adds r0, r5, 0 adds r1, r4, 0 - bl sub_8011C58 + bl CalculateChecksum ldr r0, _08011D04 ldr r0, [r0] cmp r0, 0 @@ -115,10 +83,10 @@ _08011D3A: pop {r4-r6} pop {r1} bx r1 - thumb_func_end sub_8011CD8 + thumb_func_end WriteSaveSector - thumb_func_start sub_8011D40 -sub_8011D40: + thumb_func_start ReadSaveSector +ReadSaveSector: push {r4-r6,lr} adds r5, r1, 0 adds r4, r2, 0 @@ -160,7 +128,7 @@ _08011D8A: _08011D8E: adds r0, r5, 0 adds r1, r4, 0 - bl sub_8011C7C + bl ValidateChecksum lsls r0, 24 cmp r0, 0 bne _08011DA0 @@ -172,7 +140,7 @@ _08011DA2: pop {r4-r6} pop {r1} bx r1 - thumb_func_end sub_8011D40 + thumb_func_end ReadSaveSector thumb_func_start sub_8011DA8 sub_8011DA8: @@ -197,14 +165,14 @@ sub_8011DAC: adds r0, r6, 0 adds r1, r5, 0 mov r2, r8 - bl sub_8011D40 + bl ReadSaveSector adds r7, r0, 0 cmp r7, 0 beq _08011DE8 adds r0, r6, 0 adds r1, r5, 0 mov r2, r8 - bl sub_8011D40 + bl ReadSaveSector adds r7, r0, 0 b _08011DF0 .align 2, 0 @@ -423,7 +391,7 @@ _08011F98: .4byte 0x00000444 thumb_func_start sub_8011F9C sub_8011F9C: push {lr} - bl sub_8011D40 + bl ReadSaveSector pop {r1} bx r1 thumb_func_end sub_8011F9C @@ -443,7 +411,7 @@ sub_8011FA8: mov r0, sp adds r1, r5, 0 adds r2, r4, 0 - bl sub_8011D40 + bl ReadSaveSector adds r2, r0, 0 cmp r2, 0 bne _08011FD8 @@ -486,7 +454,7 @@ sub_8011FF8: mov r0, sp adds r1, r5, 0 adds r2, r4, 0 - bl sub_8011D40 + bl ReadSaveSector cmp r0, 0 bne _08012028 ldr r1, [r5, 0x14] @@ -654,12 +622,12 @@ _080120E8: adds r0, r7, 0 adds r1, r6, 0 adds r2, r4, 0 - bl sub_8011CD8 + bl WriteSaveSector adds r5, r0, 0 adds r0, r7, 0 adds r1, r6, 0 adds r2, r4, 0 - bl sub_8011CD8 + bl WriteSaveSector adds r4, r0, 0 adds r0, r6, 0 bl MemoryFree @@ -692,7 +660,7 @@ _080121CE: thumb_func_start sub_80121D4 sub_80121D4: push {lr} - bl sub_8011CD8 + bl WriteSaveSector pop {r1} bx r1 thumb_func_end sub_80121D4 @@ -728,7 +696,7 @@ sub_80121E0: mov r0, sp adds r1, r4, 0 adds r2, r6, 0 - bl sub_8011CD8 + bl WriteSaveSector adds r5, r0, 0 adds r0, r4, 0 bl MemoryFree @@ -1724,22 +1692,4 @@ _080129F2: bx r1 thumb_func_end sub_80128B0 - thumb_func_start sub_80129FC -sub_80129FC: - push {r4,lr} - ldr r4, _08012A14 - ldr r0, [r4] - cmp r0, 0 - beq _08012A0E - bl MemoryFree - movs r0, 0 - str r0, [r4] -_08012A0E: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08012A14: .4byte gUnknown_203B194 - thumb_func_end sub_80129FC - .align 2, 0 @ Don't pad with nop. diff --git a/asm/sprite.s b/asm/sprite.s index 5081f374..06d87f0d 100644 --- a/asm/sprite.s +++ b/asm/sprite.s @@ -5,17 +5,6 @@ .text - thumb_func_start InitSprites -InitSprites: - push {lr} - movs r0, 0x1 - bl sub_8004D8C - movs r0, 0 - bl SetSavingIconCoords - pop {r0} - bx r0 - thumb_func_end InitSprites - thumb_func_start sub_8004D8C sub_8004D8C: push {r4,r5,lr} diff --git a/asm/text.s b/asm/text.s index a8e6dc56..bf0c037c 100644 --- a/asm/text.s +++ b/asm/text.s @@ -121,7 +121,7 @@ _080062AC: _080062F4: .4byte gUnknown_20274AC _080062F8: .4byte gUnknown_80B87B4 _080062FC: .4byte gUnknown_8300500 -_08006300: .4byte gUnknown_202AFB4 +_08006300: .4byte gKanji _08006304: .4byte gUnknown_80B87BC _08006308: .4byte gUnknown_2027490 _0800630C: .4byte gUnknown_202B028 diff --git a/constants/m4a_constants.inc b/constants/m4a_constants.inc new file mode 100644 index 00000000..62ca5bb5 --- /dev/null +++ b/constants/m4a_constants.inc @@ -0,0 +1,199 @@ + .equiv ID_NUMBER, 0x68736d53 + + .equiv PCM_DMA_BUF_SIZE, 1584 + + .equiv TONEDATA_TYPE_CGB, 0x07 + .equiv TONEDATA_TYPE_FIX, 0x08 + .equiv TONEDATA_TYPE_SPL, 0x40 @ key split + .equiv TONEDATA_TYPE_RHY, 0x80 @ rhythm + + .macro struct_begin + .struct 0 + .endm + + .macro struct_field name, size +\name: + .struct \name + \size + .endm + + struct_begin + struct_field o_SoundInfo_ident, 4 + struct_field o_SoundInfo_pcmDmaCounter, 1 + struct_field o_SoundInfo_reverb, 1 + struct_field o_SoundInfo_maxChans, 1 + struct_field o_SoundInfo_masterVolume, 1 + struct_field o_SoundInfo_freq, 1 + struct_field o_SoundInfo_mode, 1 + struct_field o_SoundInfo_c15, 1 + struct_field o_SoundInfo_pcmDmaPeriod, 1 + struct_field o_SoundInfo_maxLines, 1 + struct_field o_SoundInfo_gap, 3 + struct_field o_SoundInfo_pcmSamplesPerVBlank, 4 + struct_field o_SoundInfo_pcmFreq, 4 + struct_field o_SoundInfo_divFreq, 4 + struct_field o_SoundInfo_cgbChans, 4 + struct_field o_SoundInfo_func, 4 + struct_field o_SoundInfo_intp, 4 + struct_field o_SoundInfo_CgbSound, 4 + struct_field o_SoundInfo_CgbOscOff, 4 + struct_field o_SoundInfo_MidiKeyToCgbFreq, 4 + struct_field o_SoundInfo_MPlayJumpTable, 4 + struct_field o_SoundInfo_plynote, 4 + struct_field o_SoundInfo_ExtVolPit, 4 + struct_field o_SoundInfo_gap2, 16 + struct_field o_SoundInfo_chans, 768 + struct_field o_SoundInfo_pcmBuffer, PCM_DMA_BUF_SIZE * 2 + struct_field SoundInfo_size, 0 + + struct_begin + struct_field o_SoundChannel_status, 1 + struct_field o_SoundChannel_type, 1 + struct_field o_SoundChannel_rightVolume, 1 + struct_field o_SoundChannel_leftVolume, 1 + struct_field o_SoundChannel_attack, 1 + struct_field o_SoundChannel_decay, 1 + struct_field o_SoundChannel_sustain, 1 + struct_field o_SoundChannel_release, 1 + struct_field o_SoundChannel_ky, 1 + struct_field o_SoundChannel_ev, 1 + struct_field o_SoundChannel_er, 1 + struct_field o_SoundChannel_el, 1 + struct_field o_SoundChannel_iev, 1 + struct_field o_SoundChannel_iel, 1 + struct_field o_SoundChannel_d1, 1 + struct_field o_SoundChannel_d2, 1 + struct_field o_SoundChannel_gt, 1 + struct_field o_SoundChannel_mk, 1 + struct_field o_SoundChannel_ve, 1 + struct_field o_SoundChannel_pr, 1 + struct_field o_SoundChannel_rp, 1 + struct_field o_SoundChannel_d3, 3 + struct_field o_SoundChannel_ct, 4 + struct_field o_SoundChannel_fw, 4 + struct_field o_SoundChannel_freq, 4 + struct_field o_SoundChannel_wav, 4 + struct_field o_SoundChannel_cp, 4 + struct_field o_SoundChannel_track, 4 + struct_field o_SoundChannel_pp, 4 + struct_field o_SoundChannel_np, 4 + struct_field o_SoundChannel_d4, 4 + struct_field o_SoundChannel_xpi, 2 + struct_field o_SoundChannel_xpc, 2 + struct_field SoundChannel_size, 0 + + struct_begin + struct_field o_MusicPlayerTrack_flags, 1 + struct_field o_MusicPlayerTrack_wait, 1 + struct_field o_MusicPlayerTrack_patternLevel, 1 + struct_field o_MusicPlayerTrack_repN, 1 + struct_field o_MusicPlayerTrack_gateTime, 1 + struct_field o_MusicPlayerTrack_key, 1 + struct_field o_MusicPlayerTrack_velocity, 1 + struct_field o_MusicPlayerTrack_runningStatus, 1 + struct_field o_MusicPlayerTrack_keyM, 1 + struct_field o_MusicPlayerTrack_pitM, 1 + struct_field o_MusicPlayerTrack_keyShift, 1 + struct_field o_MusicPlayerTrack_keyShiftX, 1 + struct_field o_MusicPlayerTrack_tune, 1 + struct_field o_MusicPlayerTrack_pitX, 1 + struct_field o_MusicPlayerTrack_bend, 1 + struct_field o_MusicPlayerTrack_bendRange, 1 + struct_field o_MusicPlayerTrack_volMR, 1 + struct_field o_MusicPlayerTrack_volML, 1 + struct_field o_MusicPlayerTrack_vol, 1 + struct_field o_MusicPlayerTrack_volX, 1 + struct_field o_MusicPlayerTrack_pan, 1 + struct_field o_MusicPlayerTrack_panX, 1 + struct_field o_MusicPlayerTrack_modM, 1 + struct_field o_MusicPlayerTrack_mod, 1 + struct_field o_MusicPlayerTrack_modT, 1 + struct_field o_MusicPlayerTrack_lfoSpeed, 1 + struct_field o_MusicPlayerTrack_lfoSpeedC, 1 + struct_field o_MusicPlayerTrack_lfoDelay, 1 + struct_field o_MusicPlayerTrack_lfoDelayC, 1 + struct_field o_MusicPlayerTrack_priority, 1 + struct_field o_MusicPlayerTrack_echoVolume, 1 + struct_field o_MusicPlayerTrack_echoLength, 1 + struct_field o_MusicPlayerTrack_chan, 4 + struct_field o_MusicPlayerTrack_ToneData_type, 1 + struct_field o_MusicPlayerTrack_ToneData_key, 1 + struct_field o_MusicPlayerTrack_ToneData_length, 1 + struct_field o_MusicPlayerTrack_ToneData_pan_sweep, 1 + struct_field o_MusicPlayerTrack_ToneData_wav, 4 + struct_field o_MusicPlayerTrack_ToneData_attack, 1 + struct_field o_MusicPlayerTrack_ToneData_decay, 1 + struct_field o_MusicPlayerTrack_ToneData_sustain, 1 + struct_field o_MusicPlayerTrack_ToneData_release, 1 + struct_field o_MusicPlayerTrack_gap, 10 + struct_field o_MusicPlayerTrack_unk_3A, 2 + struct_field o_MusicPlayerTrack_unk_3C, 4 + struct_field o_MusicPlayerTrack_cmdPtr, 4 + struct_field o_MusicPlayerTrack_patternStack, 12 + struct_field MusicPlayerTrack_size, 0 + + .equiv o_MusicPlayerTrack_ToneData_keySplitTable, o_MusicPlayerTrack_ToneData_attack + + struct_begin + struct_field o_MusicPlayerInfo_songHeader, 4 + struct_field o_MusicPlayerInfo_status, 4 + struct_field o_MusicPlayerInfo_trackCount, 1 + struct_field o_MusicPlayerInfo_priority, 1 + struct_field o_MusicPlayerInfo_cmd, 1 + struct_field o_MusicPlayerInfo_unk_B, 1 + struct_field o_MusicPlayerInfo_clock, 4 + struct_field o_MusicPlayerInfo_gap, 8 + struct_field o_MusicPlayerInfo_memAccArea, 4 + struct_field o_MusicPlayerInfo_tempoD, 2 + struct_field o_MusicPlayerInfo_tempoU, 2 + struct_field o_MusicPlayerInfo_tempoI, 2 + struct_field o_MusicPlayerInfo_tempoC, 2 + struct_field o_MusicPlayerInfo_fadeOI, 2 + struct_field o_MusicPlayerInfo_fadeOC, 2 + struct_field o_MusicPlayerInfo_fadeOV, 2 + struct_field o_MusicPlayerInfo_padding, 2 + struct_field o_MusicPlayerInfo_tracks, 4 + struct_field o_MusicPlayerInfo_tone, 4 + struct_field o_MusicPlayerInfo_ident, 4 + struct_field o_MusicPlayerInfo_func, 4 + struct_field o_MusicPlayerInfo_intp, 4 + struct_field MusicPlayerInfo_size, 0 + + struct_begin + struct_field o_CgbChannel_sf, 1 + struct_field o_CgbChannel_ty, 1 + struct_field o_CgbChannel_rightVolume, 1 + struct_field o_CgbChannel_leftVolume, 1 + struct_field o_CgbChannel_at, 1 + struct_field o_CgbChannel_de, 1 + struct_field o_CgbChannel_su, 1 + struct_field o_CgbChannel_re, 1 + struct_field o_CgbChannel_ky, 1 + struct_field o_CgbChannel_ev, 1 + struct_field o_CgbChannel_eg, 1 + struct_field o_CgbChannel_ec, 1 + struct_field o_CgbChannel_echoVolume, 1 + struct_field o_CgbChannel_echoLength, 1 + struct_field o_CgbChannel_d1, 1 + struct_field o_CgbChannel_d2, 1 + struct_field o_CgbChannel_gt, 1 + struct_field o_CgbChannel_mk, 1 + struct_field o_CgbChannel_ve, 1 + struct_field o_CgbChannel_pr, 1 + struct_field o_CgbChannel_rp, 1 + struct_field o_CgbChannel_d3, 3 + struct_field o_CgbChannel_d5, 1 + struct_field o_CgbChannel_sg, 1 + struct_field o_CgbChannel_n4, 1 + struct_field o_CgbChannel_pan, 1 + struct_field o_CgbChannel_panMask, 1 + struct_field o_CgbChannel_mo, 1 + struct_field o_CgbChannel_le, 1 + struct_field o_CgbChannel_sw, 1 + struct_field o_CgbChannel_fr, 4 + struct_field o_CgbChannel_wp, 4 + struct_field o_CgbChannel_cp, 4 + struct_field o_CgbChannel_tp, 4 + struct_field o_CgbChannel_pp, 4 + struct_field o_CgbChannel_np, 4 + struct_field o_CgbChannel_d4, 8 + struct_field CgbChannel_size, 0 diff --git a/include/gba/defines.h b/include/gba/defines.h index 7fd429d9..5f0123a3 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -8,6 +8,8 @@ #define IWRAM_DATA __attribute__((section("iwram_data"))) #define EWRAM_DATA __attribute__((section("ewram_data"))) +#define UNUSED __attribute__((unused)) +#define NAKED __attribute__((naked)) #define ALIGNED(n) __attribute__((aligned(n))) @@ -59,4 +61,4 @@ #define WIN_RANGE(a, b) (((a) << 8) | (b)) -#endif // GUARD_GBA_DEFINES +#endif // GUARD_GBA_DEFINES \ No newline at end of file diff --git a/include/memory.h b/include/memory.h new file mode 100644 index 00000000..99b03e0e --- /dev/null +++ b/include/memory.h @@ -0,0 +1,56 @@ +#ifndef GUARD_MEMORY_H +#define GUARD_MEMORY_H + +#define HEAP_SIZE 0x24000 + +struct HeapSettings +{ + u8 *start; + u32 size; +}; + +struct HeapMemoryBlock { + u8 *start; + s32 size; + s32 allocatedSize; +}; + +struct HeapFreeListElement +{ + u32 unk_atb; + u32 atb; + u32 grp; + struct HeapMemoryBlock block; +}; + +struct HeapDescriptor +{ + u32 unk0; + u32 unk4; + struct HeapFreeListElement *freeList; + s32 freeCount; + u32 freeListLength; + u8 *start; + u32 size; +}; + +void InitHeap(void); + +void MemoryClear8(u8 *dest, s32 size); +void MemoryClear16(u16 *dest, s32 size); +void MemoryClear32(u32 *dest, s32 size); +void MemoryFill8(u8 *dest, u8 value, s32 size); +void MemoryFill16(u16 *dest, u16 value, s32 size); +void MemoryFill32(u32 *dest, u32 value, s32 size); +void MemoryCopy8(u8 *dest, u8 *src, s32 size); +void MemoryCopy16(u16 *dest, u16 *src, s32 size); +void MemoryCopy32(u32 *dest, u32 *src, s32 size); +void MemoryCopy8(u8 *dest, u8 *src, s32 size); +void MemoryCopy16(u16 *dest, u16 *src, s32 size); +void MemoryCopy32(u32 *dest, u32 *src, s32 size); + +void InitHeapInternal(void); +void DoInitHeap(struct HeapDescriptor *, struct HeapSettings *, struct HeapFreeListElement *, u32); +void InitSubHeap(struct HeapDescriptor *, struct HeapFreeListElement *, u32); + +#endif // GUARD_MEMORY_H \ No newline at end of file diff --git a/ld_script.txt b/ld_script.txt index d1bbded9..304c9c8a 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -57,6 +57,7 @@ SECTIONS { src/bg_palette_buffer.o(.text); asm/input.o(.text); asm/code_8004AA0.o(.text); + src/sprite.o(.text); asm/sprite.o(.text); asm/code_800558C.o(.text); src/random.o(.text); @@ -70,6 +71,7 @@ SECTIONS { asm/code_800D090.o(.text); src/save.o(.text); asm/save.o(.text); + src/save1.o(.text); asm/code_8012A18.o(.text); asm/m4a.o(.text); asm/syscall.o(.text); diff --git a/src/bg_palette_buffer.c b/src/bg_palette_buffer.c index 5e078a06..6301bfa1 100644 --- a/src/bg_palette_buffer.c +++ b/src/bg_palette_buffer.c @@ -1,7 +1,10 @@ #include "global.h" -extern u16 gBGPaletteBuffer[512]; -extern bool8 gBGPaletteUsed[32]; +#define BG_PALETTE_BUFFER_SIZE 512 +#define BG_PALETTE_BUFFER_CHUNK_SIZE 16 + +extern u16 gBGPaletteBuffer[BG_PALETTE_BUFFER_SIZE]; +extern bool8 gBGPaletteUsed[BG_PALETTE_BUFFER_SIZE / BG_PALETTE_BUFFER_CHUNK_SIZE]; extern void CpuCopy(void* src, void* dest, u32 size); @@ -55,13 +58,13 @@ void SetBGPaletteBufferColorRGB(s32 index, u8 *RGBArray, s32 a3, u8 *a4) void SetBGPaletteBufferColorArray(s32 index, u8 *colorArray) { - gBGPaletteUsed[index / 16] = TRUE; + gBGPaletteUsed[index / BG_PALETTE_BUFFER_CHUNK_SIZE] = TRUE; gBGPaletteBuffer[index] = (colorArray[2] >> 3) << 10 | (colorArray[1] >> 3) << 5 | colorArray[0] >> 3; } void SetBGPaletteBufferColor(s32 index, u16 *color) { - gBGPaletteUsed[index / 16] = TRUE; + gBGPaletteUsed[index / BG_PALETTE_BUFFER_CHUNK_SIZE] = TRUE; gBGPaletteBuffer[index] = *color; } @@ -98,5 +101,5 @@ void TransferBGPaletteBuffer(void) dest += 16; paletteBufferIndex += 16; } - while ( paletteBufferIndex < 512 ); -} \ No newline at end of file + while ( paletteBufferIndex < BG_PALETTE_BUFFER_SIZE ); +} diff --git a/src/file_system.c b/src/file_system.c index 296478d2..9c069ffa 100644 --- a/src/file_system.c +++ b/src/file_system.c @@ -25,9 +25,9 @@ struct SiroArchive u8 *data; }; -extern struct OpenedFile gUnknown_202D2A8[]; +extern struct OpenedFile gFileCache[64]; -extern u32 gUnknown_203B094; +extern u32 gFileCacheCursorPosition; extern u32 gUnknown_202D2A4; extern int sprintf(char *, const char *, ...); @@ -41,11 +41,11 @@ void InitFileSystem(void) for (i = 0; i < 64; i++) { - gUnknown_202D2A8[i].file = NULL; - gUnknown_202D2A8[i].data = NULL; + gFileCache[i].file = NULL; + gFileCache[i].data = NULL; } - gUnknown_203B094 = 0; + gFileCacheCursorPosition = 0; gUnknown_202D2A4 = 1; } @@ -62,8 +62,8 @@ struct OpenedFile *OpenFile(char *filename, struct FileArchive *arc) s32 left, right; s32 cursor; s32 i; - s32 magic = 0; - s32 magicFound; + u32 magic = 0; + bool32 magicFound; struct File *entries; struct File *file; @@ -71,7 +71,7 @@ struct OpenedFile *OpenFile(char *filename, struct FileArchive *arc) magicFound = 0; - if (!(u8)magic) + if (!(bool8)magic) magicFound = 1; if (!magicFound) @@ -108,18 +108,18 @@ struct OpenedFile *OpenFile(char *filename, struct FileArchive *arc) return NULL; } - cursor = gUnknown_203B094; + cursor = gFileCacheCursorPosition; for (i = 0; i < 64; i++) { cursor++; if (cursor > 63) cursor = 0; - if (!gUnknown_202D2A8[cursor].file) + if (!gFileCache[cursor].file) { - gUnknown_202D2A8[cursor].file = file; - gUnknown_202D2A8[cursor].data = NULL; - return &gUnknown_202D2A8[cursor]; + gFileCache[cursor].file = file; + gFileCache[cursor].data = NULL; + return &gFileCache[cursor]; } } @@ -157,11 +157,11 @@ void CloseFile(struct OpenedFile *openedFile) for (i = 0; i < 64; i++) { - if (&gUnknown_202D2A8[i] == openedFile) + if (&gFileCache[i] == openedFile) { - gUnknown_202D2A8[i].file = NULL; - gUnknown_202D2A8[i].data = NULL; - gUnknown_203B094 = i; + gFileCache[i].file = NULL; + gFileCache[i].data = NULL; + gFileCacheCursorPosition = i; return; } } diff --git a/src/flash.c b/src/flash.c index b9ccf40b..11520b46 100644 --- a/src/flash.c +++ b/src/flash.c @@ -1,12 +1,11 @@ #include "global.h" #include "gba/flash.h" #include "flash.h" +#include "memory.h" extern u8 gFlashEnabled; extern FlashIntrFunc *sub_800B6E8(s32); -extern void MemoryFill8(void *, u8, s32); -extern void MemoryCopy8(void *, void *, s32); static u8 TryProgramSector(s32, u8 *); diff --git a/src/memory.c b/src/memory.c index 1ccbe540..0d282d5c 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,8 +1,16 @@ #include "global.h" +#include "memory.h" + +extern struct HeapFreeListElement gMainHeapFreeList[32]; +extern u8 gMainHeap[HEAP_SIZE]; +extern u32 gHeapCount; +extern struct HeapDescriptor gMainHeapDescriptor; +extern struct HeapDescriptor *gHeapDescriptorList[8]; -extern void InitHeapInternal(void); extern void CpuClear(u32 *dest, s32 size); +void InitHeapInternal(void); + void InitHeap(void) { InitHeapInternal(); @@ -82,4 +90,56 @@ void MemoryCopy32(u32 *dest, u32 *src, s32 size) size -= 4; *dest++ = *src++; } +} + +void InitHeapInternal(void) +{ + struct HeapSettings settings; + + settings.start = gMainHeap; + settings.size = HEAP_SIZE; + gHeapCount = 0; + DoInitHeap(&gMainHeapDescriptor, &settings, gMainHeapFreeList, sizeof(gMainHeapFreeList) / sizeof(struct HeapFreeListElement)); +} + +void DoInitHeap(struct HeapDescriptor *descriptor, struct HeapSettings *settings, struct HeapFreeListElement *freeList, u32 freeListLength) +{ + u32 aligned_size; + + aligned_size = settings->size & 0xFFFFFFFC; + + gHeapDescriptorList[gHeapCount++] = descriptor; + + descriptor->start = settings->start; + descriptor->size = aligned_size; + descriptor->unk0 = 2; + descriptor->unk4 = 0; + descriptor->freeList = freeList; + descriptor->freeCount = 1; + descriptor->freeListLength = freeListLength; + + freeList->unk_atb = 0; + freeList->atb = 0; + freeList->block.start = descriptor->start; + freeList->block.size = aligned_size; + freeList->block.allocatedSize = 0; + freeList->grp = 0; +} + +void InitSubHeap(struct HeapDescriptor *parentHeap, struct HeapFreeListElement *start, u32 freeListMax) +{ + u32 freeListSize; + u32 aligned_size; + u32 alignment; + struct HeapFreeListElement *freeList; + struct HeapSettings settings; + + freeListSize = freeListMax * 3; + alignment = ~3; + freeListSize *= 8; + aligned_size = (start->atb - freeListSize) & alignment; //possible struct misalignment? + freeList = (struct HeapFreeListElement *)start->unk_atb; + settings.start = &((u8 *)start->unk_atb)[freeListSize]; + settings.size = aligned_size; + DoInitHeap(parentHeap, &settings, freeList, freeListMax); } \ No newline at end of file diff --git a/src/save.c b/src/save.c index 575d4f18..5d39bfe5 100644 --- a/src/save.c +++ b/src/save.c @@ -2,8 +2,10 @@ extern u32 gUnknown_203B17C; extern u32 gUnknown_203B180; +extern u32 *gUnknown_203B184; extern u32 gUnknown_202DE28; + u32 sub_8011C1C(void) { return gUnknown_203B17C; @@ -29,17 +31,34 @@ u32 sub_8011C4C(void) return gUnknown_203B180; } -void sub_8011C58(u32 *out, u32 len) +void CalculateChecksum(u8 *out, u32 size) { - u32 sum = 0; - s32 i = len / 4; + u32 checksum = 0; + s32 i = size / 4; if (i > 1) { - u32 *ptr = &out[1]; + u32 *ptr = (u32 *)&out[4]; --i; do - sum += *ptr++; + checksum += *ptr++; while (--i); } - *out = sum; -} \ No newline at end of file + *(u32 *)out = checksum; +} + +bool8 ValidateChecksum(u8 *in, u32 size) +{ + u32 checksum = 0; + s32 i = size / 4; + if (i > 1) + { + u32 *ptr = (u32 *)&in[4]; + --i; + do + checksum += *ptr++; + while (--i); + } + if (*(u32 *)in != checksum) + return TRUE; + return FALSE; +} diff --git a/src/save1.c b/src/save1.c new file mode 100644 index 00000000..94f9c2b3 --- /dev/null +++ b/src/save1.c @@ -0,0 +1,13 @@ +#include "global.h" + +extern void MemoryFree(void *); + +extern u8 *gUnknown_203B194; + +void sub_80129FC() +{ + if (gUnknown_203B194) { + MemoryFree(gUnknown_203B194); + gUnknown_203B194 = NULL; + } +} \ No newline at end of file diff --git a/src/sprite.c b/src/sprite.c new file mode 100644 index 00000000..41a2a962 --- /dev/null +++ b/src/sprite.c @@ -0,0 +1,10 @@ +#include "global.h" + +void sub_8004D8C(u32); +void SetSavingIconCoords(u32); + +void InitSprites(void) +{ + sub_8004D8C(1); + SetSavingIconCoords(0); +} \ No newline at end of file diff --git a/sym_ewram.txt b/sym_ewram.txt index fb753c95..517dfc54 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -15,19 +15,20 @@ gUnknown_2000A80 = .; /* 2000A80 */ gUnknown_2000A88 = .; /* 2000A88 */ . += 0x400; -gUnknown_2000E88 = .; /* 2000E88 */ +gHeapDescriptorList = .; /* 2000E88 */ . += 0x20; -gUnknown_2000EA8 = .; /* 2000EA8 */ - . += 0x8; +gHeapCount = .; /* 2000EA8 */ + . += 0x4; + . = ALIGN(16); -gUnknown_2000EB0 = .; /* 2000EB0 */ +gMainHeapDescriptor = .; /* 2000EB0 */ . += 0x20; -gHeapHeader = .; /* 2000ED0 */ +gMainHeapFreeList = .; /* 2000ED0 */ . += 0x300; -gHeap = .; /* 20011D0 */ +gMainHeap = .; /* 20011D0 */ . += 0x24000; gBGPaletteUsed = .; /* 20251D0 */ @@ -156,8 +157,11 @@ gUnknown_20274B0 = .; /* 20274B0 */ gUnknown_20274B4 = .; /* 20274B4 */ . += 0x3B00; -gUnknown_202AFB4 = .; /* 202AFB4 */ - . += 0xC; +gKanji = .; /* 202AFB4 */ + . += 0x8; + +gUnknown_202AFBC = .; /* 202AFBC */ + . += 0x4; gUnknown_202AFC0 = .; /* 202AFC0 */ . += 0x60; @@ -237,11 +241,8 @@ gUnknown_202D2A0 = .; /* 202D2A0 */ gUnknown_202D2A4 = .; /* 202D2A4 */ . += 0x4; -gUnknown_202D2A8 = .; /* 202D2A8 */ - . += 0x110; - -gUnknown_202D3B8 = .; /* 202D3B8 */ - . += 0xF0; +gFileCache = .; /* 202D2A8 */ + . += 0x200; gUnknown_202D4A8 = .; /* 202D4A8 */ . += 0x4; @@ -514,14 +515,11 @@ gUnknown_202EC4C = .; /* 202EC4C */ gUnknown_202EC50 = .; /* 202EC50 */ . += 0x38; -gUnknown_202EC88 = .; /* 202EC88 */ +gDungeonNameBannerPalette = .; /* 202EC88 */ . += 0x4; -gUnknown_202EC8C = .; /* 202EC8C */ - . += 0x4; - -gUnknown_202EC90 = .; /* 202EC90 */ - . += 0x4; +gDungeonNameBannerFontFile = .; /* 202EC8C */ + . += 0x8; gUnknown_202EC94 = .; /* 202EC94 */ . += 0x4; @@ -850,10 +848,10 @@ gUnknown_202F3D0 = .; /* 202F3D0 */ gUnknown_202F3D8 = .; /* 202F3D8 */ . += 0x8; -gUnknown_202F3E0 = .; /* 202F3E0 */ +gMonsterParameters = .; /* 202F3E0 */ . += 0x4; -gUnknown_202F3E4 = .; /* 202F3E4 */ +gMonsterParametersFile = .; /* 202F3E4 */ . += 0x4; gUnknown_202F3E8 = .; /* 202F3E8 */ @@ -868,11 +866,8 @@ gUnknown_20384E8 = .; /* 20384E8 */ gUnknown_20384F0 = .; /* 20384F0 */ . += 0x4B0; -gUnknown_20389A0 = .; /* 20389A0 */ - . += 0x4; - -gUnknown_20389A4 = .; /* 20389A4 */ - . += 0x4; +gItemParametersFile = .; /* 20389A0 */ + . += 0x8; gUnknown_20389A8 = .; /* 20389A8 */ . += 0x268; @@ -883,7 +878,7 @@ gUnknown_2038C10 = .; /* 2038C10 */ gUnknown_2038C28 = .; /* 2038C28 */ . += 0x3C; -gUnknown_2038C64 = .; /* 2038C64 */ +gWazaParametersFile = .; /* 2038C64 */ . += 0x4; gUnknown_2038C68 = .; /* 2038C68 */ diff --git a/sym_ewram2.txt b/sym_ewram2.txt index 5df20ac5..6e714820 100644 --- a/sym_ewram2.txt +++ b/sym_ewram2.txt @@ -86,7 +86,7 @@ gUnknown_203B08C = .; /* 203B08C */ gUnknown_203B090 = .; /* 203B090 */ . += 0x4; -gUnknown_203B094 = .; /* 203B094 */ +gFileCacheCursorPosition = .; /* 203B094 */ . += 0x4; gUnknown_203B098 = .; /* 203B098 */