diff --git a/Makefile b/Makefile index 32cc9df73..091cba61f 100644 --- a/Makefile +++ b/Makefile @@ -130,8 +130,7 @@ $(C_BUILDDIR)/agb_flash.o: CFLAGS := -O -mthumb-interwork $(C_BUILDDIR)/agb_flash_1m.o: CFLAGS := -O -mthumb-interwork $(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork -$(C_BUILDDIR)/m4a_2.o: CC1 := tools/agbcc/bin/old_agbcc -$(C_BUILDDIR)/m4a_4.o: CC1 := tools/agbcc/bin/old_agbcc +$(C_BUILDDIR)/m4a.o: CC1 := tools/agbcc/bin/old_agbcc $(C_BUILDDIR)/record_mixing.o: CFLAGS += -ffreestanding diff --git a/asm/m4a_3.s b/asm/m4a_3.s deleted file mode 100644 index a842ae925..000000000 --- a/asm/m4a_3.s +++ /dev/null @@ -1,574 +0,0 @@ - .include "asm/macros.inc" - .include "constants/gba_constants.inc" - .include "constants/m4a_constants.inc" - - .syntax unified - - .text - - thumb_func_start CgbSound -CgbSound: @ 81DEA70 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x1C - ldr r0, =SOUND_INFO_PTR - ldr r0, [r0] - str r0, [sp, 0x4] - ldrb r0, [r0, 0xA] - cmp r0, 0 - beq _081DEA94 - subs r0, 0x1 - ldr r1, [sp, 0x4] - strb r0, [r1, 0xA] - b _081DEA9A - .pool -_081DEA94: - movs r0, 0xE - ldr r2, [sp, 0x4] - strb r0, [r2, 0xA] -_081DEA9A: - movs r6, 0x1 - ldr r0, [sp, 0x4] - ldr r4, [r0, 0x1C] -_081DEAA0: - ldrb r1, [r4] - movs r0, 0xC7 - ands r0, r1 - adds r2, r6, 0x1 - mov r10, r2 - movs r2, 0x40 - adds r2, r4 - mov r9, r2 - cmp r0, 0 - bne _081DEAB6 - b _081DEEA0 -_081DEAB6: - cmp r6, 0x2 - beq _081DEAE8 - cmp r6, 0x2 - bgt _081DEAC4 - cmp r6, 0x1 - beq _081DEACA - b _081DEB20 -_081DEAC4: - cmp r6, 0x3 - beq _081DEB00 - b _081DEB20 -_081DEACA: - ldr r0, =REG_NR10 - str r0, [sp, 0x8] - ldr r7, =REG_NR11 - ldr r2, =REG_NR12 - str r2, [sp, 0xC] - adds r0, 0x4 - str r0, [sp, 0x10] - adds r2, 0x2 - b _081DEB30 - .pool -_081DEAE8: - ldr r0, =REG_NR10 + 1 - str r0, [sp, 0x8] - ldr r7, =REG_NR21 - ldr r2, =REG_NR22 - b _081DEB28 - .pool -_081DEB00: - ldr r0, =REG_NR30 - str r0, [sp, 0x8] - ldr r7, =REG_NR31 - ldr r2, =REG_NR32 - str r2, [sp, 0xC] - adds r0, 0x4 - str r0, [sp, 0x10] - adds r2, 0x2 - b _081DEB30 - .pool -_081DEB20: - ldr r0, =REG_NR30 + 1 - str r0, [sp, 0x8] - ldr r7, =REG_NR41 - ldr r2, =REG_NR42 -_081DEB28: - str r2, [sp, 0xC] - adds r0, 0xB - str r0, [sp, 0x10] - adds r2, 0x4 -_081DEB30: - str r2, [sp, 0x14] - ldr r0, [sp, 0x4] - ldrb r0, [r0, 0xA] - str r0, [sp] - ldr r2, [sp, 0xC] - ldrb r0, [r2] - mov r8, r0 - adds r2, r1, 0 - movs r0, 0x80 - ands r0, r2 - cmp r0, 0 - beq _081DEC26 - movs r3, 0x40 - adds r0, r3, 0 - ands r0, r2 - lsls r0, 24 - lsrs r5, r0, 24 - adds r0, r6, 0x1 - mov r10, r0 - movs r1, 0x40 - adds r1, r4 - mov r9, r1 - cmp r5, 0 - bne _081DEC4A - movs r0, 0x3 - strb r0, [r4] - strb r0, [r4, 0x1D] - adds r0, r4, 0 - str r3, [sp, 0x18] - bl CgbModVol - ldr r3, [sp, 0x18] - cmp r6, 0x2 - beq _081DEB98 - cmp r6, 0x2 - bgt _081DEB8C - cmp r6, 0x1 - beq _081DEB92 - b _081DEBEC - .pool -_081DEB8C: - cmp r6, 0x3 - beq _081DEBA4 - b _081DEBEC -_081DEB92: - ldrb r0, [r4, 0x1F] - ldr r2, [sp, 0x8] - strb r0, [r2] -_081DEB98: - ldr r0, [r4, 0x24] - lsls r0, 6 - ldrb r1, [r4, 0x1E] - adds r0, r1, r0 - strb r0, [r7] - b _081DEBF8 -_081DEBA4: - ldr r1, [r4, 0x24] - ldr r0, [r4, 0x28] - cmp r1, r0 - beq _081DEBCC - ldr r2, [sp, 0x8] - strb r3, [r2] - ldr r1, =REG_WAVE_RAM - ldr r2, [r4, 0x24] - ldr r0, [r2] - str r0, [r1] - adds r1, 0x4 - ldr r0, [r2, 0x4] - str r0, [r1] - adds r1, 0x4 - ldr r0, [r2, 0x8] - str r0, [r1] - adds r1, 0x4 - ldr r0, [r2, 0xC] - str r0, [r1] - str r2, [r4, 0x28] -_081DEBCC: - ldr r0, [sp, 0x8] - strb r5, [r0] - ldrb r0, [r4, 0x1E] - strb r0, [r7] - ldrb r0, [r4, 0x1E] - cmp r0, 0 - beq _081DEBE4 - movs r0, 0xC0 - b _081DEC06 - .pool -_081DEBE4: - movs r1, 0x80 - negs r1, r1 - strb r1, [r4, 0x1A] - b _081DEC08 -_081DEBEC: - ldrb r0, [r4, 0x1E] - strb r0, [r7] - ldr r0, [r4, 0x24] - lsls r0, 3 - ldr r2, [sp, 0x10] - strb r0, [r2] -_081DEBF8: - ldrb r0, [r4, 0x4] - adds r0, 0x8 - mov r8, r0 - ldrb r0, [r4, 0x1E] - cmp r0, 0 - beq _081DEC06 - movs r0, 0x40 -_081DEC06: - strb r0, [r4, 0x1A] -_081DEC08: - ldrb r1, [r4, 0x4] - movs r2, 0 - strb r1, [r4, 0xB] - movs r0, 0xFF - ands r0, r1 - adds r1, r6, 0x1 - mov r10, r1 - movs r1, 0x40 - adds r1, r4 - mov r9, r1 - cmp r0, 0 - bne _081DEC22 - b _081DED5E -_081DEC22: - strb r2, [r4, 0x9] - b _081DED8C -_081DEC26: - movs r0, 0x4 - ands r0, r2 - cmp r0, 0 - beq _081DEC58 - ldrb r0, [r4, 0xD] - subs r0, 0x1 - strb r0, [r4, 0xD] - movs r2, 0xFF - ands r0, r2 - lsls r0, 24 - adds r1, r6, 0x1 - mov r10, r1 - movs r2, 0x40 - adds r2, r4 - mov r9, r2 - cmp r0, 0 - ble _081DEC4A - b _081DED9E -_081DEC4A: - lsls r0, r6, 24 - lsrs r0, 24 - bl CgbOscOff - movs r0, 0 - strb r0, [r4] - b _081DEE9C -_081DEC58: - movs r0, 0x40 - ands r0, r1 - adds r2, r6, 0x1 - mov r10, r2 - movs r2, 0x40 - adds r2, r4 - mov r9, r2 - cmp r0, 0 - beq _081DEC98 - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - beq _081DEC98 - movs r0, 0xFC - ands r0, r1 - movs r2, 0 - strb r0, [r4] - ldrb r1, [r4, 0x7] - strb r1, [r4, 0xB] - movs r0, 0xFF - ands r0, r1 - cmp r0, 0 - beq _081DECCA - movs r0, 0x1 - ldrb r1, [r4, 0x1D] - orrs r0, r1 - strb r0, [r4, 0x1D] - cmp r6, 0x3 - beq _081DED8C - ldrb r2, [r4, 0x7] - mov r8, r2 - b _081DED8C -_081DEC98: - ldrb r0, [r4, 0xB] - cmp r0, 0 - bne _081DED8C - cmp r6, 0x3 - bne _081DECAA - movs r0, 0x1 - ldrb r1, [r4, 0x1D] - orrs r0, r1 - strb r0, [r4, 0x1D] -_081DECAA: - adds r0, r4, 0 - bl CgbModVol - movs r0, 0x3 - ldrb r2, [r4] - ands r0, r2 - cmp r0, 0 - bne _081DECFE - ldrb r0, [r4, 0x9] - subs r0, 0x1 - strb r0, [r4, 0x9] - movs r1, 0xFF - ands r0, r1 - lsls r0, 24 - cmp r0, 0 - bgt _081DECFA -_081DECCA: - ldrb r2, [r4, 0xC] - ldrb r1, [r4, 0xA] - adds r0, r2, 0 - muls r0, r1 - adds r0, 0xFF - asrs r0, 8 - movs r1, 0 - strb r0, [r4, 0x9] - lsls r0, 24 - cmp r0, 0 - beq _081DEC4A - movs r0, 0x4 - ldrb r2, [r4] - orrs r0, r2 - strb r0, [r4] - movs r0, 0x1 - ldrb r1, [r4, 0x1D] - orrs r0, r1 - strb r0, [r4, 0x1D] - cmp r6, 0x3 - beq _081DED9E - movs r2, 0x8 - mov r8, r2 - b _081DED9E -_081DECFA: - ldrb r0, [r4, 0x7] - b _081DED8A -_081DECFE: - cmp r0, 0x1 - bne _081DED0A -_081DED02: - ldrb r0, [r4, 0x19] - strb r0, [r4, 0x9] - movs r0, 0x7 - b _081DED8A -_081DED0A: - cmp r0, 0x2 - bne _081DED4E - ldrb r0, [r4, 0x9] - subs r0, 0x1 - strb r0, [r4, 0x9] - movs r1, 0xFF - ands r0, r1 - lsls r0, 24 - ldrb r2, [r4, 0x19] - lsls r1, r2, 24 - cmp r0, r1 - bgt _081DED4A -_081DED22: - ldrb r0, [r4, 0x6] - cmp r0, 0 - bne _081DED32 - movs r0, 0xFC - ldrb r1, [r4] - ands r0, r1 - strb r0, [r4] - b _081DECCA -_081DED32: - ldrb r0, [r4] - subs r0, 0x1 - strb r0, [r4] - movs r0, 0x1 - ldrb r2, [r4, 0x1D] - orrs r0, r2 - strb r0, [r4, 0x1D] - cmp r6, 0x3 - beq _081DED02 - movs r0, 0x8 - mov r8, r0 - b _081DED02 -_081DED4A: - ldrb r0, [r4, 0x5] - b _081DED8A -_081DED4E: - ldrb r0, [r4, 0x9] - adds r0, 0x1 - strb r0, [r4, 0x9] - movs r1, 0xFF - ands r0, r1 - ldrb r2, [r4, 0xA] - cmp r0, r2 - bcc _081DED88 -_081DED5E: - ldrb r0, [r4] - subs r0, 0x1 - movs r2, 0 - strb r0, [r4] - ldrb r1, [r4, 0x5] - strb r1, [r4, 0xB] - movs r0, 0xFF - ands r0, r1 - cmp r0, 0 - beq _081DED22 - movs r0, 0x1 - ldrb r1, [r4, 0x1D] - orrs r0, r1 - strb r0, [r4, 0x1D] - ldrb r0, [r4, 0xA] - strb r0, [r4, 0x9] - cmp r6, 0x3 - beq _081DED8C - ldrb r2, [r4, 0x5] - mov r8, r2 - b _081DED8C -_081DED88: - ldrb r0, [r4, 0x4] -_081DED8A: - strb r0, [r4, 0xB] -_081DED8C: - ldrb r0, [r4, 0xB] - subs r0, 0x1 - strb r0, [r4, 0xB] - ldr r0, [sp] - cmp r0, 0 - bne _081DED9E - subs r0, 0x1 - str r0, [sp] - b _081DEC98 -_081DED9E: - movs r0, 0x2 - ldrb r1, [r4, 0x1D] - ands r0, r1 - cmp r0, 0 - beq _081DEE16 - cmp r6, 0x3 - bgt _081DEDDE - movs r0, 0x8 - ldrb r2, [r4, 0x1] - ands r0, r2 - cmp r0, 0 - beq _081DEDDE - ldr r0, =REG_SOUNDBIAS + 1 - ldrb r0, [r0] - cmp r0, 0x3F - bgt _081DEDD0 - ldr r0, [r4, 0x20] - adds r0, 0x2 - ldr r1, =0x000007fc - b _081DEDDA - .pool -_081DEDD0: - cmp r0, 0x7F - bgt _081DEDDE - ldr r0, [r4, 0x20] - adds r0, 0x1 - ldr r1, =0x000007fe -_081DEDDA: - ands r0, r1 - str r0, [r4, 0x20] -_081DEDDE: - cmp r6, 0x4 - beq _081DEDF0 - ldr r0, [r4, 0x20] - ldr r1, [sp, 0x10] - strb r0, [r1] - b _081DEDFE - .pool -_081DEDF0: - ldr r2, [sp, 0x10] - ldrb r0, [r2] - movs r1, 0x8 - ands r1, r0 - ldr r0, [r4, 0x20] - orrs r0, r1 - strb r0, [r2] -_081DEDFE: - movs r0, 0xC0 - ldrb r1, [r4, 0x1A] - ands r0, r1 - adds r1, r4, 0 - adds r1, 0x21 - ldrb r1, [r1] - adds r0, r1, r0 - strb r0, [r4, 0x1A] - movs r2, 0xFF - ands r0, r2 - ldr r1, [sp, 0x14] - strb r0, [r1] -_081DEE16: - movs r0, 0x1 - ldrb r2, [r4, 0x1D] - ands r0, r2 - cmp r0, 0 - beq _081DEE9C - ldr r1, =REG_NR51 - ldrb r0, [r1] - ldrb r2, [r4, 0x1C] - bics r0, r2 - ldrb r2, [r4, 0x1B] - orrs r0, r2 - strb r0, [r1] - cmp r6, 0x3 - bne _081DEE68 - ldr r0, =gCgb3Vol - ldrb r1, [r4, 0x9] - adds r0, r1, r0 - ldrb r0, [r0] - ldr r2, [sp, 0xC] - strb r0, [r2] - movs r1, 0x80 - adds r0, r1, 0 - ldrb r2, [r4, 0x1A] - ands r0, r2 - cmp r0, 0 - beq _081DEE9C - ldr r0, [sp, 0x8] - strb r1, [r0] - ldrb r0, [r4, 0x1A] - ldr r1, [sp, 0x14] - strb r0, [r1] - movs r0, 0x7F - ldrb r2, [r4, 0x1A] - ands r0, r2 - strb r0, [r4, 0x1A] - b _081DEE9C - .pool -_081DEE68: - movs r0, 0xF - mov r1, r8 - ands r1, r0 - mov r8, r1 - ldrb r2, [r4, 0x9] - lsls r0, r2, 4 - add r0, r8 - ldr r1, [sp, 0xC] - strb r0, [r1] - movs r2, 0x80 - ldrb r0, [r4, 0x1A] - orrs r0, r2 - ldr r1, [sp, 0x14] - strb r0, [r1] - cmp r6, 0x1 - bne _081DEE9C - ldr r0, [sp, 0x8] - ldrb r1, [r0] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - bne _081DEE9C - ldrb r0, [r4, 0x1A] - orrs r0, r2 - ldr r1, [sp, 0x14] - strb r0, [r1] -_081DEE9C: - movs r0, 0 - strb r0, [r4, 0x1D] -_081DEEA0: - mov r6, r10 - mov r4, r9 - cmp r6, 0x4 - bgt _081DEEAA - b _081DEAA0 -_081DEEAA: - add sp, 0x1C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end CgbSound - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/rom_8011DC0.s b/asm/rom_8011DC0.s index 64c021001..af7fdbf3d 100644 --- a/asm/rom_8011DC0.s +++ b/asm/rom_8011DC0.s @@ -731,7 +731,7 @@ _080171DC: _08017228: mov r3, r9 ldrb r0, [r3] - bl ListMenuHandleInputGetItemId + bl ListMenu_ProcessInput mov r8, r0 ldr r0, =gMain ldrh r1, [r0, 0x2E] @@ -847,7 +847,7 @@ _08017314: _0801731C: mov r3, r10 ldrb r0, [r3] - bl ListMenuHandleInputGetItemId + bl ListMenu_ProcessInput adds r1, r0, 0 ldr r0, =gMain ldrh r2, [r0, 0x2E] diff --git a/common_syms/contest_painting.txt b/common_syms/contest_painting.txt new file mode 100644 index 000000000..1fba37a59 --- /dev/null +++ b/common_syms/contest_painting.txt @@ -0,0 +1,4 @@ +gUnknown_03006190 +gUnknown_030061A0 +gUnknown_030061C0 +gContestPaintingMonPalette diff --git a/common_syms/contest_painting_effects.txt b/common_syms/contest_painting_effects.txt new file mode 100644 index 000000000..2f3d79219 --- /dev/null +++ b/common_syms/contest_painting_effects.txt @@ -0,0 +1,10 @@ +gUnknown_03006164 +gUnknown_03006168 +gUnknown_0300616C +gUnknown_03006170 +gUnknown_03006174 +gUnknown_03006178 +gUnknown_0300617C +gUnknown_03006180 +gUnknown_03006184 +gUnknown_03006188 diff --git a/common_syms/evolution_scene.txt b/common_syms/evolution_scene.txt new file mode 100644 index 000000000..137cd3e05 --- /dev/null +++ b/common_syms/evolution_scene.txt @@ -0,0 +1 @@ +gCB2_AfterEvolution diff --git a/common_syms/m4a_2.txt b/common_syms/m4a.txt similarity index 100% rename from common_syms/m4a_2.txt rename to common_syms/m4a.txt diff --git a/common_syms/party_menu.txt b/common_syms/party_menu.txt new file mode 100644 index 000000000..53e72fa53 --- /dev/null +++ b/common_syms/party_menu.txt @@ -0,0 +1 @@ +gUnknown_03006328 diff --git a/common_syms/pokedex_cry_screen.txt b/common_syms/pokedex_cry_screen.txt new file mode 100644 index 000000000..d16ec36d6 --- /dev/null +++ b/common_syms/pokedex_cry_screen.txt @@ -0,0 +1 @@ +gDexCryScreenState diff --git a/data/battle_anim_80A9C70.s b/data/battle_anim_80A9C70.s deleted file mode 100644 index f82a657b9..000000000 --- a/data/battle_anim_80A9C70.s +++ /dev/null @@ -1,89 +0,0 @@ -#include "constants/battle_anim.h" - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gUnknown_0853EDE4:: @ 853EDE4 - .2byte 0x0000, 0x0003, 0x0004, 0x0003, 0x0008, 0x0003, 0x000c, 0x0003, 0xfffe, 0x0000 - - .align 2 -gUnknown_0853EDF8:: @ 853EDF8 - .4byte gUnknown_0853EDE4 - - .align 2 -gUnknown_0853EDFC:: @ 853EDFC - spr_template ANIM_TAG_UNUSED_ORB, ANIM_TAG_UNUSED_ORB, gUnknown_0852490C, gUnknown_0853EDF8, NULL, gDummySpriteAffineAnimTable, sub_80A8AEC - spr_template ANIM_TAG_UNUSED_ORB, ANIM_TAG_UNUSED_ORB, gUnknown_0852490C, gUnknown_0853EDF8, NULL, gDummySpriteAffineAnimTable, sub_80A8A6C - - .align 2 -gUnknown_0853EE2C:: @ 853EE2C - .2byte 0x0000, 0x0003, 0xfffe, 0x0000 - - .align 2 -gUnknown_0853EE34:: @ 853EE34 - .4byte gUnknown_0853EE2C - - .align 2 -gUnknown_0853EE38:: @ 853EE38 - spr_template ANIM_TAG_WEATHER_BALL, ANIM_TAG_WEATHER_BALL, gUnknown_08524914, gUnknown_0853EE34, NULL, gDummySpriteAffineAnimTable, sub_80A8E30 - - .align 2 -gUnknown_0853EE50:: @ 853EE50 - spr_template ANIM_TAG_WEATHER_BALL, ANIM_TAG_WEATHER_BALL, gUnknown_08524914, gUnknown_0853EE34, NULL, gDummySpriteAffineAnimTable, sub_80A8EE4 - - .align 2 -gUnknown_0853EE68:: @ 853EE68 - .2byte 0x0000, 0x0003, 0x0010, 0x0003, 0x0020, 0x0003, 0x0030, 0x0003, 0x0040, 0x0003, 0xffff, 0x0000 - - .align 2 -gUnknown_0853EE80:: @ 853EE80 - .4byte gUnknown_0853EE68 - - .align 2 -gUnknown_0853EE84:: @ 853EE84 - spr_template ANIM_TAG_SPARKLE_4, ANIM_TAG_SPARKLE_4, gUnknown_08524914, gUnknown_0853EE80, NULL, gDummySpriteAffineAnimTable, sub_80A8B64 - spr_template ANIM_TAG_UNUSED_MONSTER_FOOT, ANIM_TAG_UNUSED_MONSTER_FOOT, gUnknown_08524914, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, sub_80A8AEC - - .align 2 -gUnknown_0853EEB4:: @ 853EEB4 - .2byte 0x0000, 0x0005, 0xfffe, 0x0000 - - .align 2 -gUnknown_0853EEBC:: @ 853EEBC - .2byte 0x0000, 0x0005, 0xfffe, 0x0000 - - .align 2 -gUnknown_0853EEC4:: @ 853EEC4 - .2byte 0x0000, 0x0005, 0xfffe, 0x0000 - - .align 2 -gUnknown_0853EECC:: @ 853EECC - .4byte gUnknown_0853EEB4 - .4byte gUnknown_0853EEBC - .4byte gUnknown_0853EEC4 - - .align 2 -gUnknown_0853EED8:: @ 853EED8 - spr_template ANIM_TAG_IMPACT, ANIM_TAG_IMPACT, gUnknown_08524914, gUnknown_0853EECC, NULL, gDummySpriteAffineAnimTable, sub_80A8AEC - - .align 2 -gUnknown_0853EEF0:: @ 853EEF0 - .2byte 0x0000, 0x000f, 0xfffe, 0x0000 - - .align 2 -gUnknown_0853EEF8:: @ 853EEF8 - .4byte gUnknown_0853EEF0 - - .align 2 -gUnknown_0853EEFC:: @ 853EEFC - .2byte 0x0060, 0x0060, 0x0000, 0x0000, 0x0002, 0x0002, 0x0100, 0x0000, 0x7ffe, 0x0001, 0x0000, 0x0000 - - .align 2 -gUnknown_0853EF14:: @ 853EF14 - .4byte gUnknown_0853EEFC - - .align 2 -gUnknown_0853EF18:: @ 853EF18 - spr_template ANIM_TAG_UNUSED_ORB, ANIM_TAG_UNUSED_ORB, gUnknown_085249CC, gUnknown_0853EEF8, NULL, gUnknown_0853EF14, sub_80A8A6C diff --git a/include/battle.h b/include/battle.h index 88aee0a70..731c5775d 100644 --- a/include/battle.h +++ b/include/battle.h @@ -29,10 +29,11 @@ #define B_ACTION_SAFARI_GO_NEAR 7 #define B_ACTION_SAFARI_RUN 8 #define B_ACTION_WALLY_THROW 9 -// The exact purposes of these are unclear -#define B_ACTION_EXEC_SCRIPT 10 // when executing an action +#define B_ACTION_EXEC_SCRIPT 10 +#define B_ACTION_TRY_FINISH 11 +#define B_ACTION_FINISHED 12 + #define B_ACTION_CANCEL_PARTNER 12 // when choosing an action -#define B_ACTION_FINISHED 12 // when executing an action #define B_ACTION_NOTHING_FAINTED 13 // when choosing an action #define B_ACTION_DEBUG 20 #define B_ACTION_NONE 0xFF @@ -182,7 +183,6 @@ struct ProtectStruct u32 helpingHand:1; u32 bounceMove:1; u32 stealMove:1; - u32 flag0Unknown:1; u32 prlzImmobility:1; u32 confusionSelfDmg:1; u32 targetNotAffected:1; @@ -192,10 +192,10 @@ struct ProtectStruct u32 loveImmobility:1; u32 usedDisabledMove:1; u32 usedTauntedMove:1; - u32 flag2Unknown:1; + u32 flag2Unknown:1; // Only set to 0 once. Checked in 'WasUnableToUseMove' function. u32 flinchImmobility:1; u32 notFirstStrike:1; - u32 palaceAbleToUseMove:1; + u32 palaceUnableToUseMove:1; u32 usesBouncedMove:1; u32 usedHealBlockedMove:1; u32 usedGravityPreventedMove:1; diff --git a/include/battle_anim.h b/include/battle_anim.h index 95e9b1b36..105e911ae 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -75,6 +75,10 @@ int GetAnimBgAttribute(u8 bgId, u8 attributeId); // battle_anim_80A5C6C.s void sub_80A6450(struct Sprite *sprite); +void sub_80A8AEC(struct Sprite *sprite); +void sub_80A8A6C(struct Sprite *sprite); +void sub_80A8E30(struct Sprite *sprite); +void sub_80A8B64(struct Sprite *sprite); void SetAverageBattlerPositions(u8 battlerId, bool8 respectMonPicOffsets, s16 *x, s16 *y); void DestroySpriteAndMatrix(struct Sprite *sprite); void AnimTranslateLinearSimple(struct Sprite *sprite); diff --git a/include/contest.h b/include/contest.h index 35b88698e..e4391a327 100644 --- a/include/contest.h +++ b/include/contest.h @@ -437,6 +437,8 @@ extern u8 gHighestRibbonRank; extern struct ContestResources *gContestResources; extern u8 sContestBgCopyFlags; extern struct ContestWinner gUnknown_02039F3C; +extern u8 gUnknown_02039F5C; +extern u8 gUnknown_02039F5D; extern u32 gContestRngValue; diff --git a/include/contest_painting.h b/include/contest_painting.h index ca03a72b5..c633c50cc 100644 --- a/include/contest_painting.h +++ b/include/contest_painting.h @@ -13,7 +13,4 @@ enum void sub_812FDA8(int); void CB2_ContestPainting(void); -extern u8 gUnknown_02039F5C; -extern u8 gUnknown_02039F5D; - #endif diff --git a/include/gba/m4a_internal.h b/include/gba/m4a_internal.h index 339a0774e..e2836c6f6 100644 --- a/include/gba/m4a_internal.h +++ b/include/gba/m4a_internal.h @@ -69,38 +69,38 @@ struct ToneData struct CgbChannel { - u8 sf; - u8 ty; - u8 rightVolume; - u8 leftVolume; - u8 at; - u8 de; - u8 su; - u8 re; - u8 ky; - u8 ev; - u8 eg; - u8 ec; - u8 echoVolume; - u8 echoLength; - u8 d1; - u8 d2; - u8 gt; - u8 mk; - u8 ve; - u8 pr; - u8 rp; - u8 d3[3]; - u8 d5; - u8 sg; - u8 n4; - u8 pan; - u8 panMask; - u8 mo; - u8 le; - u8 sw; - u32 fr; - u32 wp; + u8 sf; // 0x0 + u8 ty; // 0x1 + u8 rightVolume; // 0x2 + u8 leftVolume; // 0x3 + u8 at; // 0x4 + u8 de; // 0x5 + u8 su; // 0x6 + u8 re; // 0x7 + u8 ky; // 0x8 + u8 ev; // 0x9 + u8 eg; // 0xA + u8 ec; // 0xB + u8 echoVolume; // 0xC + u8 echoLength; // 0xD + u8 d1; // 0xE + u8 d2; // 0xF + u8 gt; // 0x10 + u8 mk; // 0x11 + u8 ve; // 0x12 + u8 pr; // 0x13 + u8 rp; // 0x14 + u8 d3[3]; // 0x15, 0x16, 0x17 + u8 d5; // 0x18 + u8 sg; // 0x19 + u8 n4; // 0x1A + u8 pan; // 0x1B + u8 panMask; // 0x1C + u8 mo; // 0x1D + u8 le; // 0x1E + u8 sw; // 0x1F + u32 fr; // 0x20 + u32 *wp; u32 cp; u32 tp; u32 pp; @@ -397,6 +397,7 @@ void m4aSoundMode(u32 mode); void MPlayOpen(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track, u8 a3); void CgbSound(void); void CgbOscOff(u8); +void CgbModVol(struct CgbChannel *chan); u32 MidiKeyToCgbFreq(u8, u8, u8); void DummyFunc(void); void MPlayJumpTableCopy(void **mplayJumpTable); diff --git a/include/list_menu.h b/include/list_menu.h index 84c38306b..ef23688d8 100644 --- a/include/list_menu.h +++ b/include/list_menu.h @@ -101,7 +101,7 @@ extern struct ListMenuTemplate gMultiuseListMenuTemplate; s32 DoMysteryGiftListMenu(struct WindowTemplate *windowTemplate, struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum); u8 ListMenuInit(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 selectedRow); u8 ListMenuInitInRect(struct ListMenuTemplate *listMenuTemplate, struct ListMenuWindowRect *arg1, u16 scrollOffset, u16 selectedRow); -s32 ListMenuHandleInputGetItemId(u8 listTaskId); +s32 ListMenu_ProcessInput(u8 listTaskId); void DestroyListMenuTask(u8 listTaskId, u16 *scrollOffset, u16 *selectedRow); void RedrawListMenu(u8 listTaskId); void ChangeListMenuPals(u8 listTaskId, u8 cursorPal, u8 fillValue, u8 cursorShadowPal); diff --git a/include/party_menu.h b/include/party_menu.h index ae7c414a8..702b4fde1 100644 --- a/include/party_menu.h +++ b/include/party_menu.h @@ -48,6 +48,8 @@ extern MainCallback gPostMenuFieldCallback; extern u8 gSelectedOrderFromParty[4]; extern u8 gUnknown_0203CF00[3]; +extern void (*gUnknown_03006328)(u8, TaskFunc); + extern const u16 gTutorMoves[]; void sub_81B0FCC(u8 slot, u8 b); diff --git a/include/pokedex_cry_screen.h b/include/pokedex_cry_screen.h index 392e80a6d..93f1b02a5 100755 --- a/include/pokedex_cry_screen.h +++ b/include/pokedex_cry_screen.h @@ -10,6 +10,8 @@ struct CryRelatedStruct u8 yPos; }; +extern u8 gDexCryScreenState; + bool8 sub_8145354(struct CryRelatedStruct*, u8); void sub_814545C(u8); void sub_8145534(u16); diff --git a/include/trade.h b/include/trade.h index 95a10cacf..0c95e1e81 100644 --- a/include/trade.h +++ b/include/trade.h @@ -6,8 +6,11 @@ // Exported type declarations // Exported RAM declarations +extern struct MailStruct gUnknown_020321C0[PARTY_SIZE]; +extern u8 gUnknown_02032298[2]; // Exported ROM declarations +extern const struct WindowTemplate gUnknown_0833900C; s32 sub_807A728(void); void sub_80773AC(void); diff --git a/ld_script.txt b/ld_script.txt index 1b95e3aae..0a26d7715 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -27,7 +27,7 @@ SECTIONS { INCLUDE "sym_bss.ld" /* .bss.code starts at 0x3001AA8 */ - src/m4a_2.o(.bss.code); + src/m4a.o(.bss.code); /* COMMON starts at 0x30022A8 */ INCLUDE "sym_common.ld" @@ -320,9 +320,7 @@ SECTIONS { { asm/libgcnmultiboot.o(.text); asm/m4a_1.o(.text); - src/m4a_2.o(.text); - asm/m4a_3.o(.text); - src/m4a_4.o(.text); + src/m4a.o(.text); src/agb_flash.o(.text); src/agb_flash_1m.o(.text); src/agb_flash_mx.o(.text); @@ -444,7 +442,6 @@ SECTIONS { src/battle_anim.o(.rodata); src/battle_anim_80A5C6C.o(.rodata); data/map_events.o(.rodata); - data/battle_anim_80A9C70.o(.rodata); src/battle_anim_80A9C70.o(.rodata); src/title_screen.o(.rodata); src/field_weather.o(.rodata); diff --git a/src/battle_anim_80A9C70.c b/src/battle_anim_80A9C70.c index 001f99d7f..1271680e0 100644 --- a/src/battle_anim_80A9C70.c +++ b/src/battle_anim_80A9C70.c @@ -28,6 +28,182 @@ static void sub_80A9E44(struct Sprite *sprite); static void sub_80A9E78(struct Sprite *sprite); // const rom data +static const union AnimCmd sSpriteAnim_853EDE4[] = +{ + ANIMCMD_FRAME(0, 3), + ANIMCMD_FRAME(4, 3), + ANIMCMD_FRAME(8, 3), + ANIMCMD_FRAME(12, 3), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sSpriteAnimTable_853EDF8[] = +{ + sSpriteAnim_853EDE4 +}; + +const struct SpriteTemplate gUnknown_0853EDFC = +{ + .tileTag = ANIM_TAG_UNUSED_ORB, + .paletteTag = ANIM_TAG_UNUSED_ORB, + .oam = &gUnknown_0852490C, + .anims = sSpriteAnimTable_853EDF8, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80A8AEC, +}; + +const struct SpriteTemplate gUnknown_0853EE14 = +{ + .tileTag = ANIM_TAG_UNUSED_ORB, + .paletteTag = ANIM_TAG_UNUSED_ORB, + .oam = &gUnknown_0852490C, + .anims = sSpriteAnimTable_853EDF8, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80A8A6C, +}; + +static const union AnimCmd sSpriteAnim_853EE2C[] = +{ + ANIMCMD_FRAME(0, 3), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sSpriteAnimTable_853EE34[] = +{ + sSpriteAnim_853EE2C +}; + +const struct SpriteTemplate gUnknown_0853EE38 = +{ + .tileTag = ANIM_TAG_WEATHER_BALL, + .paletteTag = ANIM_TAG_WEATHER_BALL, + .oam = &gUnknown_08524914, + .anims = sSpriteAnimTable_853EE34, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80A8E30, +}; + +const struct SpriteTemplate gUnknown_0853EE50 = +{ + .tileTag = ANIM_TAG_WEATHER_BALL, + .paletteTag = ANIM_TAG_WEATHER_BALL, + .oam = &gUnknown_08524914, + .anims = sSpriteAnimTable_853EE34, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80A8EE4, +}; + +static const union AnimCmd sSpriteAnim_853EE68[] = +{ + ANIMCMD_FRAME(0, 3), + ANIMCMD_FRAME(16, 3), + ANIMCMD_FRAME(32, 3), + ANIMCMD_FRAME(48, 3), + ANIMCMD_FRAME(64, 3), + ANIMCMD_END +}; + +static const union AnimCmd *const sSpriteAnimTable_853EE80[] = +{ + sSpriteAnim_853EE68 +}; + +const struct SpriteTemplate gUnknown_0853EE84 = +{ + .tileTag = ANIM_TAG_SPARKLE_4, + .paletteTag = ANIM_TAG_SPARKLE_4, + .oam = &gUnknown_08524914, + .anims = sSpriteAnimTable_853EE80, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80A8B64, +}; + +const struct SpriteTemplate gUnknown_0853EE9C = +{ + .tileTag = ANIM_TAG_UNUSED_MONSTER_FOOT, + .paletteTag = ANIM_TAG_UNUSED_MONSTER_FOOT, + .oam = &gUnknown_08524914, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80A8AEC, +}; + +static const union AnimCmd sSpriteAnim_853EEB4[] = +{ + ANIMCMD_FRAME(0, 5), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sSpriteAnim_853EEBC[] = +{ + ANIMCMD_FRAME(0, 5), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sSpriteAnim_853EEC4[] = +{ + ANIMCMD_FRAME(0, 5), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sSpriteAnimTable_853EECC[] = +{ + sSpriteAnim_853EEB4, + sSpriteAnim_853EEBC, + sSpriteAnim_853EEC4 +}; + +const struct SpriteTemplate gUnknown_0853EED8 = +{ + .tileTag = ANIM_TAG_IMPACT, + .paletteTag = ANIM_TAG_IMPACT, + .oam = &gUnknown_08524914, + .anims = sSpriteAnimTable_853EECC, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = sub_80A8AEC, +}; + +static const union AnimCmd sSpriteAnim_853EEF0[] = +{ + ANIMCMD_FRAME(0, 15), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sSpriteAnimTable_853EEF8[] = +{ + sSpriteAnim_853EEF0 +}; + +static const union AffineAnimCmd sSpriteAffineAnim_853EEFC[] = +{ + AFFINEANIMCMD_FRAME(96, 96, 0, 0), + AFFINEANIMCMD_FRAME(2, 2, 0, 1), + AFFINEANIMCMD_JUMP(1) +}; + +static const union AffineAnimCmd *const sSpriteAffineAnimTable_853EEF8[] = +{ + sSpriteAffineAnim_853EEFC +}; + +const struct SpriteTemplate gUnknown_0853EF18 = +{ + .tileTag = ANIM_TAG_UNUSED_ORB, + .paletteTag = ANIM_TAG_UNUSED_ORB, + .oam = &gUnknown_085249CC, + .anims = sSpriteAnimTable_853EEF8, + .images = NULL, + .affineAnims = sSpriteAffineAnimTable_853EEF8, + .callback = sub_80A8A6C, +}; + static const struct Subsprite gUnknown_0853EF30[] = { {.x = -16, .y = -16, .shape = ST_OAM_SQUARE, .size = 3, .tileOffset = 0, .priority = 2}, diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 0f714b6c8..1df9b71de 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -1280,7 +1280,7 @@ static void LinkOpponentHandleDrawTrainerPic(void) else if ((gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].version & 0xFF) == VERSION_FIRE_RED || (gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].version & 0xFF) == VERSION_LEAF_GREEN) { - if (gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].gender != 0) + if (gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].gender != MALE) trainerPicId = gFacilityClassToPicIndex[FACILITY_CLASS_LEAF]; else trainerPicId = gFacilityClassToPicIndex[FACILITY_CLASS_RED]; @@ -1288,7 +1288,7 @@ static void LinkOpponentHandleDrawTrainerPic(void) else if ((gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].version & 0xFF) == VERSION_RUBY || (gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].version & 0xFF) == VERSION_SAPPHIRE) { - if (gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].gender != 0) + if (gLinkPlayers[GetMultiplayerId() ^ BIT_SIDE].gender != MALE) trainerPicId = gFacilityClassToPicIndex[FACILITY_CLASS_RS_MAY]; else trainerPicId = gFacilityClassToPicIndex[FACILITY_CLASS_RS_BRENDAN]; diff --git a/src/battle_debug.c b/src/battle_debug.c index 4986b09b3..35cc13f37 100644 --- a/src/battle_debug.c +++ b/src/battle_debug.c @@ -701,7 +701,7 @@ static void Task_DebugMenuProcessInput(u8 taskId) // A main list item is active, handle input. if (data->activeWindow == ACTIVE_WIN_MAIN) { - listItemId = ListMenuHandleInputGetItemId(data->mainListTaskId); + listItemId = ListMenu_ProcessInput(data->mainListTaskId); if (listItemId != LIST_B_PRESSED && listItemId != LIST_NOTHING_CHOSEN && listItemId < LIST_ITEM_COUNT) { data->currentMainListItemId = listItemId; @@ -715,7 +715,7 @@ static void Task_DebugMenuProcessInput(u8 taskId) // Secondary list is active, handle input. else if (data->activeWindow == ACTIVE_WIN_SECONDARY) { - listItemId = ListMenuHandleInputGetItemId(data->secondaryListTaskId); + listItemId = ListMenu_ProcessInput(data->secondaryListTaskId); if (listItemId == LIST_B_PRESSED) { DestroyListMenuTask(data->secondaryListTaskId, NULL, NULL); diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index 79cf05e03..a27d32acc 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -205,13 +205,13 @@ u16 ChooseMoveAndTargetInBattlePalace(void) if (Random() % 100 > 49) { - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; return 0; } } else { - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; return 0; } } diff --git a/src/battle_main.c b/src/battle_main.c index 378e01f28..7a4bb2541 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -130,7 +130,7 @@ static void HandleAction_ThrowPokeblock(void); static void HandleAction_GoNear(void); static void HandleAction_SafariZoneRun(void); static void HandleAction_WallyBallThrow(void); -static void HandleAction_Action11(void); +static void HandleAction_TryFinish(void); static void HandleAction_NothingIsFainted(void); static void HandleAction_ActionFinished(void); @@ -416,7 +416,7 @@ static void (* const sTurnActionsFuncsTable[])(void) = [B_ACTION_SAFARI_RUN] = HandleAction_SafariZoneRun, [B_ACTION_WALLY_THROW] = HandleAction_WallyBallThrow, [B_ACTION_EXEC_SCRIPT] = HandleAction_RunBattleScript, - [11] = HandleAction_Action11, // not sure about this one + [B_ACTION_TRY_FINISH] = HandleAction_TryFinish, [B_ACTION_FINISHED] = HandleAction_ActionFinished, [B_ACTION_NOTHING_FAINTED] = HandleAction_NothingIsFainted, }; @@ -3103,7 +3103,6 @@ void FaintClearSetData(void) gProtectStructs[gActiveBattler].helpingHand = 0; gProtectStructs[gActiveBattler].bounceMove = 0; gProtectStructs[gActiveBattler].stealMove = 0; - gProtectStructs[gActiveBattler].flag0Unknown = 0; gProtectStructs[gActiveBattler].prlzImmobility = 0; gProtectStructs[gActiveBattler].confusionSelfDmg = 0; gProtectStructs[gActiveBattler].targetNotAffected = 0; @@ -5302,7 +5301,7 @@ static void HandleAction_UseMove(void) // Choose battlescript. if (gBattleTypeFlags & BATTLE_TYPE_PALACE - && gProtectStructs[gBattlerAttacker].palaceAbleToUseMove) + && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) { if (gBattleMons[gBattlerAttacker].hp == 0) { @@ -5656,7 +5655,7 @@ static void HandleAction_WallyBallThrow(void) gActionsByTurnOrder[1] = B_ACTION_FINISHED; } -static void HandleAction_Action11(void) +static void HandleAction_TryFinish(void) { if (!HandleFaintedMonActions()) { diff --git a/src/battle_message.c b/src/battle_message.c index 9c79b2a18..1faa6543b 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -38,8 +38,6 @@ struct BattleWindowText u8 shadowColor; }; -extern u8 gUnknown_0203C7B4; - extern const u8 gTrainerClassNames[][13]; extern const u16 gUnknown_08D85620[]; diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 50baf48fd..9bed2ab43 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -853,7 +853,7 @@ static void Task_HandlePyramidBagInput(u8 taskId) } else { - s32 listId = ListMenuHandleInputGetItemId(data[0]); + s32 listId = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); switch (listId) { @@ -945,9 +945,9 @@ static void HandleFewMenuActionsInput(u8 taskId) s32 id = Menu_ProcessInputNoWrap(); switch (id) { - case -2: + case MENU_NOTHING_CHOSEN: break; - case -1: + case MENU_B_PRESSED: PlaySE(SE_SELECT); sMenuActions[ACTION_CANCEL].func.void_u8(taskId); break; @@ -1285,7 +1285,7 @@ static void Task_ItemSwapHandleInput(u8 taskId) } else { - s32 id = ListMenuHandleInputGetItemId(data[0]); + s32 id = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); sub_81C7028(FALSE); sub_81C704C(gPyramidBagCursorData.cursorPosition); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9a2ee0347..41e54dd5a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3816,13 +3816,13 @@ static void atk3D_end(void) gMoveResultFlags = 0; gActiveBattler = 0; - gCurrentActionFuncId = 0xB; + gCurrentActionFuncId = B_ACTION_TRY_FINISH; } static void atk3E_end2(void) { gActiveBattler = 0; - gCurrentActionFuncId = 0xB; + gCurrentActionFuncId = B_ACTION_TRY_FINISH; } static void atk3F_end3(void) // pops the main function stack diff --git a/src/battle_util.c b/src/battle_util.c index 892df2eac..42c55541c 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -624,7 +624,7 @@ u8 TrySetCantSelectMoveBattleScript(void) if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingDisabledMoveInPalace; - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -639,7 +639,7 @@ u8 TrySetCantSelectMoveBattleScript(void) if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingTormentedMoveInPalace; - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -654,7 +654,7 @@ u8 TrySetCantSelectMoveBattleScript(void) if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveTauntInPalace; - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -669,7 +669,7 @@ u8 TrySetCantSelectMoveBattleScript(void) if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingImprisionedMoveInPalace; - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -684,7 +684,7 @@ u8 TrySetCantSelectMoveBattleScript(void) if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveGravityInPalace; - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -699,7 +699,7 @@ u8 TrySetCantSelectMoveBattleScript(void) if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedMoveHealBlockInPalace; - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -714,7 +714,7 @@ u8 TrySetCantSelectMoveBattleScript(void) if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingNotAllowedBelchInPalace; - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -730,7 +730,7 @@ u8 TrySetCantSelectMoveBattleScript(void) gLastUsedItem = gBattleMons[gActiveBattler].item; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -744,7 +744,7 @@ u8 TrySetCantSelectMoveBattleScript(void) gLastUsedItem = gBattleMons[gActiveBattler].item; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { @@ -757,7 +757,7 @@ u8 TrySetCantSelectMoveBattleScript(void) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gProtectStructs[gActiveBattler].palaceAbleToUseMove = 1; + gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { diff --git a/src/berry_blender.c b/src/berry_blender.c index ea9c6c4ff..f2e3c7d14 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -1438,7 +1438,7 @@ static void Blender_SetOpponentsBerryData(u16 playerBerryItemId, u8 playersNum, { opponentBerryId = sOpponentBerrySets[opponentSetId][i]; var = playerBerryItemId - 163; - if (!FlagGet(0x340) && gSpecialVar_0x8004 == 1) + if (!FlagGet(FLAG_HIDE_LILYCOVE_CONTEST_HALL_BLEND_MASTER_ONLOOKERS) && gSpecialVar_0x8004 == 1) { opponentSetId %= 5; opponentBerryId = sSpecialOpponentBerrySets[opponentSetId]; diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index b17ffad33..6be8ba4a4 100644 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c @@ -447,25 +447,25 @@ bool8 ShouldDoBrailleRegicePuzzle(void) if (i < 16) { - u16 val = VarGet(0x403B); + u16 val = VarGet(VAR_0x403B); val |= 1 << i; - VarSet(0x403B, val); + VarSet(VAR_0x403B, val); } else if (i < 32) { - u16 val = VarGet(0x403C); + u16 val = VarGet(VAR_0x403C); val |= 1 << (i - 16); - VarSet(0x403C, val); + VarSet(VAR_0x403C, val); } else { - u16 val = VarGet(0x403D); + u16 val = VarGet(VAR_0x403D); val |= 1 << (i - 32); - VarSet(0x403D, val); + VarSet(VAR_0x403D, val); } - varValue = VarGet(0x403B); - if (varValue != 0xFFFF || VarGet(0x403C) != varValue || VarGet(0x403D) != 0xF) + varValue = VarGet(VAR_0x403B); + if (varValue != 0xFFFF || VarGet(VAR_0x403C) != varValue || VarGet(VAR_0x403D) != 0xF) return FALSE; if (gSaveBlock1Ptr->pos.x == 8 && gSaveBlock1Ptr->pos.y == 21) diff --git a/src/cable_club.c b/src/cable_club.c index ce9b9db05..303b0d016 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -27,12 +27,10 @@ #include "task.h" #include "trade.h" #include "trainer_card.h" +#include "party_menu.h" #include "window.h" #include "constants/songs.h" -extern u8 gUnknown_02032298[2]; -extern u8 gSelectedOrderFromParty[]; - static const struct WindowTemplate gUnknown_08550594 = { .bg = 0, .tilemapLeft = 16, diff --git a/src/contest.c b/src/contest.c index b24036f39..cf084e35e 100644 --- a/src/contest.c +++ b/src/contest.c @@ -214,6 +214,8 @@ EWRAM_DATA u8 gHighestRibbonRank = 0; EWRAM_DATA struct ContestResources *gContestResources = NULL; EWRAM_DATA u8 sContestBgCopyFlags = 0; EWRAM_DATA struct ContestWinner gUnknown_02039F3C = {0}; +EWRAM_DATA u8 gUnknown_02039F5C = 0; +EWRAM_DATA u8 gUnknown_02039F5D = 0; // IWRAM common vars. u32 gContestRngValue; diff --git a/src/contest_link_80F57C4.c b/src/contest_link_80F57C4.c index 721a4f870..381fb34fa 100644 --- a/src/contest_link_80F57C4.c +++ b/src/contest_link_80F57C4.c @@ -3,7 +3,6 @@ #include "bg.h" #include "contest.h" #include "contest_link_80F57C4.h" -#include "contest_painting.h" #include "decompress.h" #include "dma3.h" #include "event_data.h" @@ -67,10 +66,9 @@ struct ContestLink80F57C4 u8 *unkC[4]; }; +EWRAM_DATA struct ContestLink80F57C4 *gUnknown_0203A034 = NULL; + extern const struct CompressedSpriteSheet gMonFrontPicTable[]; - -extern struct ContestLink80F57C4 *gUnknown_0203A034; - extern const struct BgTemplate gUnknown_0858D888[4]; extern const struct WindowTemplate gUnknown_0858D898[]; extern const struct CompressedSpriteSheet gUnknown_0858D878[]; @@ -138,7 +136,7 @@ void sub_80F57C4(void) InitBgsFromTemplates(0, gUnknown_0858D888, ARRAY_COUNT(gUnknown_0858D888)); for (i = 0; i < 4; i++) SetBgTilemapBuffer(i, gUnknown_0203A034->unkC[i]); - + InitWindows(gUnknown_0858D898); DeactivateAllTextPrinters(); SetGpuReg(REG_OFFSET_MOSAIC, 0); @@ -720,7 +718,7 @@ static void sub_80F66B4(u8 taskId) { nationalDexNum = SpeciesToNationalPokedexNum(gContestMons[i].species); GetSetPokedexFlag(nationalDexNum, FLAG_SET_SEEN); - } + } } gTasks[taskId].data[10] = 0; @@ -761,7 +759,7 @@ static void sub_80F67C4(u8 taskId) { if (!(gIsLinkContest & 0x1)) BravoTrainerPokemonProfile_BeforeInterview2(gContestFinalStandings[gContestPlayerMonIndex]); - + BeginHardwarePaletteFade(0xFF, 0, 0, 16, 0); gTasks[taskId].func = sub_80F6820; } @@ -1282,7 +1280,7 @@ static void sub_80F6F68(struct Sprite *sprite) struct Sprite *sprite2 = &gSprites[sprite->data[i]]; sprite2->pos1.x = sprite->pos1.x + sprite->pos2.x + (i + 1) * 64; } - + if (sprite->pos1.x == sprite->data[4]) sprite->callback = sub_80F6FDC; } @@ -1348,7 +1346,7 @@ static void sub_80F7144(void) sprite->invisible = 1; for (i = 0; i < 3; i++) gSprites[sprite->data[i]].invisible = 1; - + gBattle_WIN0H = 0; gBattle_WIN0V = 0; SetGpuReg(REG_OFFSET_WIN0H, gBattle_WIN0H); diff --git a/src/contest_painting.c b/src/contest_painting.c index 0ed169a77..71a110aa8 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -20,10 +20,11 @@ #include "window.h" #include "constants/rgb.h" -extern u16 (*gUnknown_03006190)[][32]; -extern struct ContestWinner *gUnknown_030061C0; -extern u16 *gContestPaintingMonPalette; -extern struct Unk030061A0 gUnknown_030061A0; +// IWRAM common +u16 (*gUnknown_03006190)[][32]; +struct Unk030061A0 gUnknown_030061A0; +struct ContestWinner *gUnknown_030061C0; +u16 *gContestPaintingMonPalette; // IWRAM bss IWRAM_DATA u8 gContestPaintingState; @@ -103,7 +104,7 @@ const u8 *const gContestRankTextPointers[] = gContestLink, }; -const struct BgTemplate gUnknown_085B07E8[] = +const struct BgTemplate gUnknown_085B07E8[] = { { .bg = 1, @@ -116,7 +117,7 @@ const struct BgTemplate gUnknown_085B07E8[] = }, }; -const struct WindowTemplate gUnknown_085B07EC = +const struct WindowTemplate gUnknown_085B07EC = { .bg = 1, .tilemapLeft = 2, diff --git a/src/contest_painting_effects.c b/src/contest_painting_effects.c index 187a0f196..142ad7bc9 100644 --- a/src/contest_painting_effects.c +++ b/src/contest_painting_effects.c @@ -3,14 +3,17 @@ #include "contest_painting.h" #include "constants/rgb.h" -extern u8 gUnknown_03006164; -extern u16 (*gUnknown_03006168)[][32]; -extern u8 gUnknown_0300616C; -extern u8 gUnknown_03006170; -extern u8 gUnknown_03006174; -extern u8 gUnknown_03006178; -extern u8 gUnknown_0300617C; -extern u8 gUnknown_03006180; +// IWRAM common +u8 gUnknown_03006164; +u16 (*gUnknown_03006168)[][32]; +u8 gUnknown_0300616C; +u8 gUnknown_03006170; +u8 gUnknown_03006174; +u8 gUnknown_03006178; +u8 gUnknown_0300617C; +u8 gUnknown_03006180; +u16 gUnknown_03006184; +u16 gUnknown_03006188; // this file's functions void sub_8125230(void); diff --git a/src/data/pokemon/trainer_class_lookups.h b/src/data/pokemon/trainer_class_lookups.h index 6e8474c12..04c7ab3c4 100644 --- a/src/data/pokemon/trainer_class_lookups.h +++ b/src/data/pokemon/trainer_class_lookups.h @@ -146,10 +146,10 @@ const u8 gFacilityClassToTrainerClass[] = [FACILITY_CLASS_TWINS] = TRAINER_CLASS_TWINS, [FACILITY_CLASS_SAILOR] = TRAINER_CLASS_SAILOR, [FACILITY_CLASS_WALLY] = TRAINER_CLASS_PKMN_TRAINER_3, - [FACILITY_CLASS_MAY] = TRAINER_CLASS_PKMN_TRAINER_3, + [FACILITY_CLASS_BRENDAN] = TRAINER_CLASS_PKMN_TRAINER_3, [FACILITY_CLASS_BRENDAN_2] = TRAINER_CLASS_PKMN_TRAINER_3, [FACILITY_CLASS_BRENDAN_3] = TRAINER_CLASS_PKMN_TRAINER_3, - [FACILITY_CLASS_BRENDAN] = TRAINER_CLASS_PKMN_TRAINER_3, + [FACILITY_CLASS_MAY] = TRAINER_CLASS_PKMN_TRAINER_3, [FACILITY_CLASS_MAY_2] = TRAINER_CLASS_PKMN_TRAINER_3, [FACILITY_CLASS_MAY_3] = TRAINER_CLASS_PKMN_TRAINER_3, [FACILITY_CLASS_PKMN_BREEDER_M] = TRAINER_CLASS_PKMN_BREEDER, diff --git a/src/data/trainer_graphics/back_pic_anims.h b/src/data/trainer_graphics/back_pic_anims.h index 21dbda597..0cc4bb203 100644 --- a/src/data/trainer_graphics/back_pic_anims.h +++ b/src/data/trainer_graphics/back_pic_anims.h @@ -70,13 +70,13 @@ const union AnimCmd gAnimCmd_RubySapphireMay_1[] = const union AnimCmd *const gTrainerBackAnims_Brendan[] = { - AnimCmd_82FF540, + gAnimCmd_General_Frame3, gAnimCmd_Brendan_1, }; const union AnimCmd *const gTrainerBackAnims_May[] = { - AnimCmd_82FF540, + gAnimCmd_General_Frame3, gAnimCmd_May_Steven_1, }; @@ -94,25 +94,25 @@ const union AnimCmd *const gTrainerBackAnims_Leaf[] = const union AnimCmd *const gTrainerBackAnims_RubySapphireBrendan[] = { - AnimCmd_82FF540, + gAnimCmd_General_Frame3, gAnimCmd_RubySapphireBrendan_1, }; const union AnimCmd *const gTrainerBackAnims_RubySapphireMay[] = { - AnimCmd_82FF540, + gAnimCmd_General_Frame3, gAnimCmd_RubySapphireMay_1, }; const union AnimCmd *const gTrainerBackAnims_Wally[] = { - AnimCmd_82FF540, + gAnimCmd_General_Frame3, gAnimCmd_Wally_1, }; const union AnimCmd *const gTrainerBackAnims_Steven[] = { - AnimCmd_82FF540, + gAnimCmd_General_Frame3, gAnimCmd_May_Steven_1, }; diff --git a/src/data/trainer_graphics/back_pic_tables.h b/src/data/trainer_graphics/back_pic_tables.h index 920ecbb39..0f6b0cb91 100644 --- a/src/data/trainer_graphics/back_pic_tables.h +++ b/src/data/trainer_graphics/back_pic_tables.h @@ -15,24 +15,24 @@ const struct MonCoords gTrainerBackPicCoords[] = // the casts are so they'll play nice with the strict struct definition const struct CompressedSpriteSheet gTrainerBackPicTable[] = { - (const u32 *)gTrainerBackPic_Brendan, 0x2000, 0, - (const u32 *)gTrainerBackPic_May, 0x2000, 1, - (const u32 *)gTrainerBackPic_Red, 0x2800, 2, - (const u32 *)gTrainerBackPic_Leaf, 0x2800, 3, - (const u32 *)gTrainerBackPic_RubySapphireBrendan, 0x2000, 4, - (const u32 *)gTrainerBackPic_RubySapphireMay, 0x2000, 5, - (const u32 *)gTrainerBackPic_Wally, 0x2000, 6, - (const u32 *)gTrainerBackPic_Steven, 0x2000, 7, + (const u32 *)gTrainerBackPic_Brendan, 0x2000, TRAINER_BACK_PIC_BRENDAN, + (const u32 *)gTrainerBackPic_May, 0x2000, TRAINER_BACK_PIC_MAY, + (const u32 *)gTrainerBackPic_Red, 0x2800, TRAINER_BACK_PIC_RED, + (const u32 *)gTrainerBackPic_Leaf, 0x2800, TRAINER_BACK_PIC_LEAF, + (const u32 *)gTrainerBackPic_RubySapphireBrendan, 0x2000, TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN, + (const u32 *)gTrainerBackPic_RubySapphireMay, 0x2000, TRAINER_BACK_PIC_RUBY_SAPPHIRE_MAY, + (const u32 *)gTrainerBackPic_Wally, 0x2000, TRAINER_BACK_PIC_WALLY, + (const u32 *)gTrainerBackPic_Steven, 0x2000, TRAINER_BACK_PIC_STEVEN, }; const struct CompressedSpritePalette gTrainerBackPicPaletteTable[] = { - gTrainerPalette_Brendan, 0, - gTrainerPalette_May, 1, - gTrainerBackPicPalette_Red, 2, - gTrainerBackPicPalette_Leaf, 3, - gTrainerPalette_RubySapphireBrendan, 4, - gTrainerPalette_RubySapphireMay, 5, - gTrainerPalette_Wally, 6, - gTrainerPalette_Steven, 7, + gTrainerPalette_Brendan, TRAINER_BACK_PIC_BRENDAN, + gTrainerPalette_May, TRAINER_BACK_PIC_MAY, + gTrainerBackPicPalette_Red, TRAINER_BACK_PIC_RED, + gTrainerBackPicPalette_Leaf, TRAINER_BACK_PIC_LEAF, + gTrainerPalette_RubySapphireBrendan, TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN, + gTrainerPalette_RubySapphireMay, TRAINER_BACK_PIC_RUBY_SAPPHIRE_MAY, + gTrainerPalette_Wally, TRAINER_BACK_PIC_WALLY, + gTrainerPalette_Steven, TRAINER_BACK_PIC_STEVEN, }; diff --git a/src/data2b.c b/src/data2b.c index bb1baa266..af76390a4 100644 --- a/src/data2b.c +++ b/src/data2b.c @@ -40,7 +40,7 @@ const struct SpriteFrameImage gUnknown_082FF408[] = gHeap + 0xF800, 0x800, }; -const struct SpriteFrameImage gUnknown_082FF428[] = +const struct SpriteFrameImage gTrainerBackPicTable_Brendan[] = { gTrainerBackPic_Brendan, 0x0800, gTrainerBackPic_Brendan + 0x0800, 0x0800, @@ -48,7 +48,7 @@ const struct SpriteFrameImage gUnknown_082FF428[] = gTrainerBackPic_Brendan + 0x1800, 0x0800, }; -const struct SpriteFrameImage gUnknown_082FF448[] = +const struct SpriteFrameImage gTrainerBackPicTable_May[] = { gTrainerBackPic_May, 0x0800, gTrainerBackPic_May + 0x0800, 0x0800, @@ -56,7 +56,7 @@ const struct SpriteFrameImage gUnknown_082FF448[] = gTrainerBackPic_May + 0x1800, 0x0800, }; -const struct SpriteFrameImage gUnknown_082FF468[] = +const struct SpriteFrameImage gTrainerBackPicTable_Red[] = { gTrainerBackPic_Red, 0x0800, gTrainerBackPic_Red + 0x0800, 0x0800, @@ -65,7 +65,7 @@ const struct SpriteFrameImage gUnknown_082FF468[] = gTrainerBackPic_Red + 0x2000, 0x0800, }; -const struct SpriteFrameImage gUnknown_082FF490[] = +const struct SpriteFrameImage gTrainerBackPicTable_Leaf[] = { gTrainerBackPic_Leaf, 0x0800, gTrainerBackPic_Leaf + 0x0800, 0x0800, @@ -74,7 +74,7 @@ const struct SpriteFrameImage gUnknown_082FF490[] = gTrainerBackPic_Leaf + 0x2000, 0x0800, }; -const struct SpriteFrameImage gUnknown_082FF4B8[] = +const struct SpriteFrameImage gTrainerBackPicTable_RubySapphireBrendan[] = { gTrainerBackPic_RubySapphireBrendan, 0x0800, gTrainerBackPic_RubySapphireBrendan + 0x0800, 0x0800, @@ -82,7 +82,7 @@ const struct SpriteFrameImage gUnknown_082FF4B8[] = gTrainerBackPic_RubySapphireBrendan + 0x1800, 0x0800, }; -const struct SpriteFrameImage gUnknown_082FF4D8[] = +const struct SpriteFrameImage gTrainerBackPicTable_RubySapphireMay[] = { gTrainerBackPic_RubySapphireMay, 0x0800, gTrainerBackPic_RubySapphireMay + 0x0800, 0x0800, @@ -90,7 +90,7 @@ const struct SpriteFrameImage gUnknown_082FF4D8[] = gTrainerBackPic_RubySapphireMay + 0x1800, 0x0800, }; -const struct SpriteFrameImage gUnknown_082FF4F8[] = +const struct SpriteFrameImage gTrainerBackPicTable_Wally[] = { gTrainerBackPic_Wally, 0x0800, gTrainerBackPic_Wally + 0x0800, 0x0800, @@ -98,7 +98,7 @@ const struct SpriteFrameImage gUnknown_082FF4F8[] = gTrainerBackPic_Wally + 0x1800, 0x0800, }; -const struct SpriteFrameImage gUnknown_082FF518[] = +const struct SpriteFrameImage gTrainerBackPicTable_Steven[] = { gTrainerBackPic_Steven, 0x0800, gTrainerBackPic_Steven + 0x0800, 0x0800, @@ -112,7 +112,7 @@ const union AnimCmd gAnimCmd_General_Frame0[] = ANIMCMD_END, }; -const union AnimCmd AnimCmd_82FF540[] = +const union AnimCmd gAnimCmd_General_Frame3[] = { ANIMCMD_FRAME(3, 0), ANIMCMD_END, diff --git a/src/daycare.c b/src/daycare.c index 6bdbd987e..b75fab292 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -1244,15 +1244,15 @@ static void DaycarePrintMonInfo(u8 windowId, s32 daycareSlotId, u8 y) static void Task_HandleDaycareLevelMenuInput(u8 taskId) { - u32 var = ListMenuHandleInputGetItemId(gTasks[taskId].tMenuListTaskId); + u32 input = ListMenu_ProcessInput(gTasks[taskId].tMenuListTaskId); if (gMain.newKeys & A_BUTTON) { - switch (var) + switch (input) { case 0: case 1: - gSpecialVar_Result = var; + gSpecialVar_Result = input; break; case 5: gSpecialVar_Result = 2; diff --git a/src/decoration.c b/src/decoration.c index c4c3d6171..2ac49b98c 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -526,14 +526,14 @@ void sub_8126B80(u8 taskId) PlaySE(SE_SELECT); sSecretBasePCMenuActions[sSecretBasePCMenuCursorPos].func.void_u8(taskId); break; - case -2: + case MENU_NOTHING_CHOSEN: sSecretBasePCMenuCursorPos = Menu_GetCursorPos(); if ((s8)menuPos != sSecretBasePCMenuCursorPos) { sub_8126C08(); } break; - case -1: + case MENU_B_PRESSED: PlaySE(SE_SELECT); SecretBasePC_Cancel(taskId); break; @@ -713,12 +713,12 @@ void sub_8127088(u8 taskId) input = Menu_ProcessInput(); switch (input) { - case -1: + case MENU_B_PRESSED: case 8: PlaySE(SE_SELECT); sub_812719C(taskId); break; - case -2: + case MENU_NOTHING_CHOSEN: break; default: PlaySE(SE_SELECT); @@ -933,13 +933,13 @@ void sub_812764C(u8 taskId) data = gTasks[taskId].data; if (!gPaletteFade.active) { - input = ListMenuHandleInputGetItemId(data[13]); + input = ListMenu_ProcessInput(data[13]); ListMenuGetScrollAndRow(data[13], &sSecretBasePCSelectDecorPageNo, &sSecretBasePCSelectDecorLineNo); switch (input) { - case -1: + case LIST_NOTHING_CHOSEN: break; - case -2: + case LIST_B_PRESSED: PlaySE(SE_SELECT); SecretBasePC_SelectedDecorActions[data[11]][1](taskId); break; @@ -1244,17 +1244,17 @@ void sub_8127E18(void) for (i = 0; i < 14; i ++) { - if (FlagGet(0xAE + i) == TRUE) + if (FlagGet(FLAG_DECORATION_1 + i) == TRUE) { - FlagClear(0xAE + i); + FlagClear(FLAG_DECORATION_1 + i); for (j = 0; j < gMapHeader.events->eventObjectCount; j ++) { - if (gMapHeader.events->eventObjects[j].flagId == 0xAE + i) + if (gMapHeader.events->eventObjects[j].flagId == FLAG_DECORATION_1 + i) { break; } } - VarSet(0x3F20 + gMapHeader.events->eventObjects[j].graphicsId, sPlaceDecorationGraphicsDataBuffer.decoration->tiles[0]); + VarSet(VAR_0x3F20 + gMapHeader.events->eventObjects[j].graphicsId, sPlaceDecorationGraphicsDataBuffer.decoration->tiles[0]); gSpecialVar_0x8005 = gMapHeader.events->eventObjects[j].localId; gSpecialVar_0x8006 = sCurDecorMapX; gSpecialVar_0x8007 = sCurDecorMapY; diff --git a/src/dragon.c b/src/dragon.c index 4a2ac1c51..9b39a8a30 100644 --- a/src/dragon.c +++ b/src/dragon.c @@ -5,8 +5,6 @@ #include "trig.h" #include "constants/rgb.h" -extern u16 gUnknown_0203A100[]; - void sub_8113064(struct Sprite *); void sub_81131B4(struct Sprite *); void sub_8113224(struct Sprite *); @@ -17,6 +15,8 @@ static void sub_81134B8(u8); static void sub_8113574(struct Task *); static void sub_811369C(struct Sprite *); +EWRAM_DATA static u16 gUnknown_0203A100[7] = {0}; + const union AnimCmd gUnknown_08596E60[] = { ANIMCMD_FRAME(0, 4), diff --git a/src/evolution_scene.c b/src/evolution_scene.c index c97e2d10f..4bf7701be 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -9,6 +9,7 @@ #include "evolution_graphics.h" #include "gpu_regs.h" #include "link.h" +#include "link_rfu.h" #include "m4a.h" #include "main.h" #include "menu.h" @@ -16,10 +17,12 @@ #include "palette.h" #include "pokedex.h" #include "pokemon.h" +#include "pokemon_summary_screen.h" #include "scanline_effect.h" #include "sound.h" #include "sprite.h" #include "string_util.h" +#include "strings.h" #include "task.h" #include "text.h" #include "text_window.h" @@ -39,22 +42,18 @@ struct EvoInfo u16 savedPalette[48]; }; +// EWRAM vars static EWRAM_DATA struct EvoInfo *sEvoStructPtr = NULL; static EWRAM_DATA u16 *sEvoMovingBgPtr = NULL; +// IWRAM common +void (*gCB2_AfterEvolution)(void); + #define sEvoCursorPos gBattleCommunication[1] // when learning a new move #define sEvoGraphicsTaskID gBattleCommunication[2] -extern const struct WindowTemplate gUnknown_0833900C; extern const struct CompressedSpriteSheet gMonFrontPicTable[]; -// strings -extern const u8 gText_CommunicationStandby5[]; - -extern void ShowSelectMovePokemonSummaryScreen(struct Pokemon *party, u8 monId, u8 partyCount, void *CB2_ptr, u16 move); -extern u8 sub_81C1B94(void); -extern void sub_800E084(void); - // this file's functions static void Task_EvolutionScene(u8 taskID); static void Task_TradeEvolutionScene(u8 taskID); diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index 7423216a4..b1291f0ce 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -90,7 +90,7 @@ static bool8 sub_808B618(void); static bool8 PlayerIsAnimActive(void); static bool8 PlayerCheckIfAnimFinishedOrInactive(void); -static void PlayerRun(u8); +static void PlayerRun(u8); static void PlayerNotOnBikeCollide(u8); static void PlayerNotOnBikeCollideWithFarawayIslandMew(u8); @@ -343,7 +343,7 @@ static bool8 TryInterruptEventObjectSpecialAnim(struct EventObject *playerEventO u8 r5 = direction; register u8 r6 asm("r6") = direction; #endif - //a very bad HACK + //a very bad HACK if (EventObjectIsMovementOverridden(playerEventObj) && !EventObjectClearHeldMovementIfFinished(playerEventObj)) @@ -821,24 +821,14 @@ void SetPlayerAvatarTransitionFlags(u16 transitionFlags) static void DoPlayerAvatarTransition(void) { u8 i; - u32 flags = gPlayerAvatar.unk1; + u8 flags = gPlayerAvatar.unk1; if (flags != 0) { for (i = 0; i < 8; i++, flags >>= 1) { -#ifdef NONMATCHING if (flags & 1) - { gUnknown_084974B8[i](&gEventObjects[gPlayerAvatar.eventObjectId]); - } -#else - if (flags & 1) - { - register void (*const *funcs)(struct EventObject *) asm("r0") = gUnknown_084974B8; - funcs[i](&gEventObjects[gPlayerAvatar.eventObjectId]); - } -#endif } gPlayerAvatar.unk1 = 0; } @@ -1151,7 +1141,7 @@ void PlayerGetDestCoords(s16 *x, s16 *y) u8 player_get_pos_including_state_based_drift(s16 *x, s16 *y) { struct EventObject *object = &gEventObjects[gPlayerAvatar.eventObjectId]; - + if (object->heldMovementActive && !object->heldMovementFinished && !gSprites[object->spriteId].data[2]) { *x = object->currentCoords.x; @@ -1765,7 +1755,7 @@ static bool8 Fishing2(struct Task *task) static bool8 Fishing3(struct Task *task) { AlignFishingAnimationFrames(); - + // Wait one second task->tFrameCounter++; if (task->tFrameCounter >= 60) diff --git a/src/field_special_scene.c b/src/field_special_scene.c index 579188f36..2b518808b 100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -300,8 +300,8 @@ void Task_HandlePorthole(u8 taskId) } break; case EXIT_PORTHOLE: // exit porthole. - FlagClear(0x4001); - FlagClear(0x4000); + FlagClear(FLAG_SPECIAL_FLAG_0x4001); + FlagClear(FLAG_SPECIAL_FLAG_0x4000); SetWarpDestinationToDynamicWarp(0); DoDiveWarp(); DestroyTask(taskId); @@ -315,7 +315,7 @@ void sub_80FB6EC(void) gSprites[spriteId].coordOffsetEnabled = FALSE; - if (VarGet(0x40B4) == 2) + if (VarGet(VAR_PORTHOLE_STATE) == 2) { StartSpriteAnim(&gSprites[spriteId], GetFaceDirectionAnimNum(4)); } @@ -337,8 +337,8 @@ void sub_80FB768(void) void sub_80FB7A4(void) { FlagSet(FLAG_SYS_CRUISE_MODE); - FlagSet(0x4001); - FlagSet(0x4000); + FlagSet(FLAG_SPECIAL_FLAG_0x4001); + FlagSet(FLAG_SPECIAL_FLAG_0x4000); SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); sub_80FB59C(); sub_80AF8B8(); diff --git a/src/field_specials.c b/src/field_specials.c index 0dc1bf18b..f2ebf2b8e 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -2603,9 +2603,9 @@ static void sub_813A46C(s32 itemIndex, bool8 onInit, struct ListMenu *list) static void sub_813A4EC(u8 taskId) { struct Task *task = &gTasks[taskId]; - s32 itemId = ListMenuHandleInputGetItemId(task->data[14]); + s32 input = ListMenu_ProcessInput(task->data[14]); - switch (itemId) + switch (input) { case LIST_NOTHING_CHOSEN: break; @@ -2615,13 +2615,13 @@ static void sub_813A4EC(u8 taskId) sub_813A570(taskId); break; default: - gSpecialVar_Result = itemId; + gSpecialVar_Result = input; PlaySE(SE_SELECT); if (!task->data[6]) { sub_813A570(taskId); } - else if (itemId == task->data[1] - 1) + else if (input == task->data[1] - 1) { sub_813A570(taskId); } diff --git a/src/ice.c b/src/ice.c index 77b3700ef..d354fce7e 100644 --- a/src/ice.c +++ b/src/ice.c @@ -530,7 +530,7 @@ static void sub_810B6C4(struct Sprite *sprite) { s16 targetX, targetY, attackerX, attackerY; s16 i; - + sprite->oam.tileNum += 7; targetX = GetBattlerSpriteCoord(gBattleAnimTarget, 2); targetY = GetBattlerSpriteCoord(gBattleAnimTarget, 3); @@ -811,7 +811,7 @@ void AnimIceBeamParticle(struct Sprite *sprite) sprite->callback = StartAnimLinearTranslation; } -// Animates the ice crystals at the end of Ice Punch, Ice Beam, Tri Attack, +// Animates the ice crystals at the end of Ice Punch, Ice Beam, Tri Attack, // Weather Ball (Hail), Blizzard, and Powder Snow. // arg 0: target x offset // arg 1: target y offset @@ -917,7 +917,7 @@ void AnimSwirlingSnowball_Step2(struct Sprite *sprite) sprite->pos2.x = 0; sprite->data[0] = 128; - tempVar = GetBattlerSide(gBattleAnimAttacker) != 0 ? 20 : -20; + tempVar = GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER ? 20 : -20; sprite->data[3] = Sin(sprite->data[0], tempVar); sprite->data[4] = Cos(sprite->data[0], 0xF); @@ -1069,7 +1069,7 @@ void AnimWaveFromCenterOfTarget(struct Sprite *sprite) sprite->pos1.y += gBattleAnimArgs[1]; } - sprite->data[0]++; + sprite->data[0]++; } else { @@ -1099,9 +1099,9 @@ void InitSwirlingFogAnim(struct Sprite *sprite) else { SetAverageBattlerPositions(gBattleAnimAttacker, 0, &sprite->pos1.x, &sprite->pos1.y); - if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) + if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) sprite->pos1.x -= gBattleAnimArgs[0]; - else + else sprite->pos1.x += gBattleAnimArgs[0]; sprite->pos1.y += gBattleAnimArgs[1]; @@ -1109,18 +1109,18 @@ void InitSwirlingFogAnim(struct Sprite *sprite) battler = gBattleAnimAttacker; } - else + else { if (gBattleAnimArgs[5] == 0) { InitSpritePosToAnimTarget(sprite, FALSE); } - else + else { SetAverageBattlerPositions(gBattleAnimTarget, 0, &sprite->pos1.x, &sprite->pos1.y); if (GetBattlerSide(gBattleAnimTarget) != B_SIDE_PLAYER) sprite->pos1.x -= gBattleAnimArgs[0]; - else + else sprite->pos1.x += gBattleAnimArgs[0]; sprite->pos1.y += gBattleAnimArgs[1]; @@ -1130,7 +1130,7 @@ void InitSwirlingFogAnim(struct Sprite *sprite) } sprite->data[7] = battler; - if (gBattleAnimArgs[5] == 0 || !IsDoubleBattle()) + if (gBattleAnimArgs[5] == 0 || !IsDoubleBattle()) tempVar = 0x20; else tempVar = 0x40; @@ -1161,7 +1161,7 @@ void AnimSwirlingFogAnim(struct Sprite *sprite) sprite->pos2.y += Cos(sprite->data[5], -6); if ((u16)(sprite->data[5] - 64) <= 0x7F) - sprite->oam.priority = GetBattlerSpriteBGPriority(sprite->data[7]); + sprite->oam.priority = GetBattlerSpriteBGPriority(sprite->data[7]); else sprite->oam.priority = GetBattlerSpriteBGPriority(sprite->data[7]) + 1; @@ -1195,7 +1195,7 @@ void AnimTask_Haze1(u8 taskId) LoadBgTiles(subStruct.bgId, gWeatherFog1Tiles, 0x800, subStruct.tilesOffset); sub_80A6D60(&subStruct, gBattleAnimFogTilemap, 0); LoadPalette(&gUnknown_083970E8, subStruct.unk8 * 16, 32); - + gTasks[taskId].func = AnimTask_Haze2; } @@ -1208,62 +1208,63 @@ void AnimTask_Haze2(u8 taskId) switch (gTasks[taskId].data[12]) { - case 0: - if (++gTasks[taskId].data[10] == 4) - { - gTasks[taskId].data[10] = 0; - gTasks[taskId].data[9]++; - gTasks[taskId].data[11] = gUnknown_08595C5C[gTasks[taskId].data[9]]; + case 0: + if (++gTasks[taskId].data[10] == 4) + { + gTasks[taskId].data[10] = 0; + gTasks[taskId].data[9]++; + gTasks[taskId].data[11] = gUnknown_08595C5C[gTasks[taskId].data[9]]; - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 16 - gTasks[taskId].data[11])); - if (gTasks[taskId].data[11] == 9) - { - gTasks[taskId].data[12]++; - gTasks[taskId].data[11] = 0; - } - } - break; - case 1: - if (++gTasks[taskId].data[11] == 0x51) + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 16 - gTasks[taskId].data[11])); + if (gTasks[taskId].data[11] == 9) { - gTasks[taskId].data[11] = 9; gTasks[taskId].data[12]++; + gTasks[taskId].data[11] = 0; } - break; - case 2: - if (++gTasks[taskId].data[10] == 4) - { - gTasks[taskId].data[10] = 0; - gTasks[taskId].data[11]--; - - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 16 - gTasks[taskId].data[11])); - if (gTasks[taskId].data[11] == 0) - { - gTasks[taskId].data[12]++; - gTasks[taskId].data[11] = 0; - } - } - break; - case 3: - sub_80A6B30(&subStruct); - sub_80A6C68(1); - sub_80A6C68(2); - + } + break; + case 1: + if (++gTasks[taskId].data[11] == 0x51) + { + gTasks[taskId].data[11] = 9; gTasks[taskId].data[12]++; - - // fall through - case 4: - if (!IsContest()) - SetAnimBgAttribute(1, BG_ANIM_CHAR_BASE_BLOCK, 0); + } + break; + case 2: + if (++gTasks[taskId].data[10] == 4) + { + gTasks[taskId].data[10] = 0; + gTasks[taskId].data[11]--; - gBattle_BG1_X = 0; - gBattle_BG1_Y = 0; - SetGpuReg(REG_OFFSET_BLDCNT, 0); - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 0)); - SetAnimBgAttribute(1, BG_ANIM_PRIORITY, 1); - DestroyAnimVisualTask(taskId); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 16 - gTasks[taskId].data[11])); + if (gTasks[taskId].data[11] == 0) + { + gTasks[taskId].data[12]++; + gTasks[taskId].data[11] = 0; + } + } + break; + case 3: + sub_80A6B30(&subStruct); + sub_80A6C68(1); + sub_80A6C68(2); + + gTasks[taskId].data[12]++; + + // fall through + case 4: + if (!IsContest()) + SetAnimBgAttribute(1, BG_ANIM_CHAR_BASE_BLOCK, 0); + + gBattle_BG1_X = 0; + gBattle_BG1_Y = 0; + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 0)); + SetAnimBgAttribute(1, BG_ANIM_PRIORITY, 1); + DestroyAnimVisualTask(taskId); + break; } -} +} // Throws the ball in Mist Ball. // arg 0: initial x pixel offset @@ -1301,7 +1302,7 @@ void AnimTask_LoadMistTiles(u8 taskId) LoadBgTiles(subStruct.bgId, gWeatherFog1Tiles, 0x800, subStruct.tilesOffset); sub_80A6D60(&subStruct, gBattleAnimFogTilemap, 0); LoadPalette(&gUnknown_083970E8, subStruct.unk8 * 16, 32); - + gTasks[taskId].data[15] = -1; gTasks[taskId].func = AnimTask_OverlayFogTiles; } @@ -1315,54 +1316,55 @@ void AnimTask_OverlayFogTiles(u8 taskId) switch (gTasks[taskId].data[12]) { - case 0: - gTasks[taskId].data[9] += 1; - gTasks[taskId].data[11] = gUnknown_08595C88[gTasks[taskId].data[9]]; - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 17 - gTasks[taskId].data[11])); - if (gTasks[taskId].data[11] == 5) + case 0: + gTasks[taskId].data[9] += 1; + gTasks[taskId].data[11] = gUnknown_08595C88[gTasks[taskId].data[9]]; + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 17 - gTasks[taskId].data[11])); + if (gTasks[taskId].data[11] == 5) + { + gTasks[taskId].data[12]++; + gTasks[taskId].data[11] = 0; + } + break; + case 1: + if (++gTasks[taskId].data[11] == 0x51) + { + gTasks[taskId].data[11] = 5; + gTasks[taskId].data[12]++; + } + break; + case 2: + if (++gTasks[taskId].data[10] == 4) + { + gTasks[taskId].data[10] = 0; + gTasks[taskId].data[11] -= 1; + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 16 - gTasks[taskId].data[11])); + if (gTasks[taskId].data[11] == 0) { gTasks[taskId].data[12]++; gTasks[taskId].data[11] = 0; } - break; - case 1: - if (++gTasks[taskId].data[11] == 0x51) - { - gTasks[taskId].data[11] = 5; - gTasks[taskId].data[12]++; - } - break; - case 2: - if (++gTasks[taskId].data[10] == 4) - { - gTasks[taskId].data[10] = 0; - gTasks[taskId].data[11] -= 1; - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[11], 16 - gTasks[taskId].data[11])); - if (gTasks[taskId].data[11] == 0) - { - gTasks[taskId].data[12]++; - gTasks[taskId].data[11] = 0; - } - } - break; - case 3: - sub_80A6B30(&subStruct); - sub_80A6C68(1); - sub_80A6C68(2); - - gTasks[taskId].data[12]++; - - // fall through - case 4: - if (!IsContest()) - SetAnimBgAttribute(1, BG_ANIM_CHAR_BASE_BLOCK, 0); + } + break; + case 3: + sub_80A6B30(&subStruct); + sub_80A6C68(1); + sub_80A6C68(2); - gBattle_BG1_X = 0; - gBattle_BG1_Y = 0; - SetGpuReg(REG_OFFSET_BLDCNT, 0); - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 0)); - SetAnimBgAttribute(1, BG_ANIM_PRIORITY, 1); - DestroyAnimVisualTask(taskId); + gTasks[taskId].data[12]++; + + // fall through + case 4: + if (!IsContest()) + SetAnimBgAttribute(1, BG_ANIM_CHAR_BASE_BLOCK, 0); + + gBattle_BG1_X = 0; + gBattle_BG1_Y = 0; + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 0)); + SetAnimBgAttribute(1, BG_ANIM_PRIORITY, 1); + DestroyAnimVisualTask(taskId); + break; } } @@ -1390,7 +1392,7 @@ void InitPoisonGasCloudAnim(struct Sprite *sprite) if ((sprite->data[7] & 0x8000) && !(gBattlerPositions[gBattleAnimAttacker] & 1)) sprite->subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; - sprite->data[6] = 1; + sprite->data[6] = 1; } sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); @@ -1410,7 +1412,7 @@ void InitPoisonGasCloudAnim(struct Sprite *sprite) sprite->data[3] = sprite->pos1.y + gBattleAnimArgs[2]; sprite->data[4] = GetBattlerSpriteCoord(gBattleAnimTarget, 1) + gBattleAnimArgs[4]; sprite->data[7] |= GetBattlerSpriteBGPriority(gBattleAnimTarget) << 8; - } + } if (IsContest()) { @@ -1425,8 +1427,6 @@ void InitPoisonGasCloudAnim(struct Sprite *sprite) void MovePoisonGasCloud(struct Sprite *sprite) { int value; - register s16 value2 asm("r5"); - int unused; switch (sprite->data[7] & 0xFF) { @@ -1441,8 +1441,7 @@ void MovePoisonGasCloud(struct Sprite *sprite) if (sprite->data[0] <= 0) { - value2 = 80; - sprite->data[0] = value2; + sprite->data[0] = 80; sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimTarget, 0); sprite->data[1] = sprite->pos1.x; sprite->data[2] = sprite->pos1.x; @@ -1450,10 +1449,12 @@ void MovePoisonGasCloud(struct Sprite *sprite) sprite->data[3] = sprite->pos1.y; sprite->data[4] = sprite->pos1.y + 29; sprite->data[7]++; - if (!IsContest() && gBattlerPositions[gBattleAnimTarget] & 1) + if (IsContest()) + sprite->data[5] = 80; + else if (GET_BATTLER_SIDE2(gBattleAnimTarget) != B_SIDE_PLAYER) sprite->data[5] = 204; else - sprite->data[5] = value2; + sprite->data[5] = 80; sprite->pos2.y = 0; value = gSineTable[sprite->data[5]]; @@ -1490,13 +1491,13 @@ void MovePoisonGasCloud(struct Sprite *sprite) if (sprite->data[0] <= 0) { - asm("mov r5, #0"); // unused local variable? - unused = 0; sprite->data[0] = 0x300; sprite->data[1] = sprite->pos1.x += sprite->pos2.x; sprite->data[3] = sprite->pos1.y += sprite->pos2.y; sprite->data[4] = sprite->pos1.y + 4; - if (!IsContest() && gBattlerPositions[gBattleAnimTarget] & 1) + if (IsContest()) + sprite->data[2] = -0x10; + else if (GET_BATTLER_SIDE2(gBattleAnimTarget) != B_SIDE_PLAYER) sprite->data[2] = 0x100; else sprite->data[2] = -0x10; @@ -1535,43 +1536,43 @@ void AnimTask_Hail2(u8 taskId) struct Task *task = &gTasks[taskId]; switch (task->data[0]) { - case 0: - if (++task->data[4] > 2) - { - task->data[4] = 0; - task->data[5] = 0; - task->data[2] = 0; - task->data[0]++; - } - break; - case 1: - if (task->data[5] == 0) - { - if (GenerateHailParticle(task->data[3], task->data[2], taskId, 1)) - task->data[1]++; - - if (++task->data[2] == 3) - { - if (++task->data[3] == 10) - task->data[0]++; - else - task->data[0]--; - } - else - { - task->data[5] = 1; - } + case 0: + if (++task->data[4] > 2) + { + task->data[4] = 0; + task->data[5] = 0; + task->data[2] = 0; + task->data[0]++; + } + break; + case 1: + if (task->data[5] == 0) + { + if (GenerateHailParticle(task->data[3], task->data[2], taskId, 1)) + task->data[1]++; + if (++task->data[2] == 3) + { + if (++task->data[3] == 10) + task->data[0]++; + else + task->data[0]--; } else { - task->data[5]--; + task->data[5] = 1; } - break; - case 2: - if (task->data[1] == 0) - DestroyAnimVisualTask(taskId); - break; + + } + else + { + task->data[5]--; + } + break; + case 2: + if (task->data[1] == 0) + DestroyAnimVisualTask(taskId); + break; } } @@ -1587,7 +1588,7 @@ bool8 GenerateHailParticle(u8 a, u8 b, u8 taskId, u8 c) u8 spriteId; // struct Sprite *sprite; s16 spriteX; - + if (unk != 2) { battler = GetBattlerAtPosition(hailData->unk2); @@ -1820,7 +1821,7 @@ void AnimHailBegin(struct Sprite *sprite) if (sprite->data[0] == 1 && sprite->data[5] == 0) { - spriteId = CreateSprite(&gUnknown_08595B68, + spriteId = CreateSprite(&gUnknown_08595B68, sprite->data[3], sprite->data[4], sprite->subpriority); sprite->data[0] = spriteId; @@ -1935,6 +1936,6 @@ void AnimTask_GetRolloutCounter(u8 taskId) { u8 arg = gBattleAnimArgs[0]; - gBattleAnimArgs[arg] = gAnimDisableStructPtr->rolloutTimerStartValue - gAnimDisableStructPtr->rolloutTimer - 1; + gBattleAnimArgs[arg] = gAnimDisableStructPtr->rolloutTimerStartValue - gAnimDisableStructPtr->rolloutTimer - 1; DestroyAnimVisualTask(taskId); } diff --git a/src/item_menu.c b/src/item_menu.c index a220f02ef..24a50aa9a 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -1102,7 +1102,7 @@ void Task_BagMenu(u8 taskId) } else { - int listPosition = ListMenuHandleInputGetItemId(data[0]); + int listPosition = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], scrollPos, cursorPos); switch (listPosition) { @@ -1304,7 +1304,7 @@ void bag_menu_swap_items(u8 taskId) void sub_81AC3C0(u8 taskId) { s16* data = gTasks[taskId].data; - int r7; + int input; if (sub_81221EC() != TRUE) { @@ -1316,15 +1316,15 @@ void sub_81AC3C0(u8 taskId) } else { - r7 = ListMenuHandleInputGetItemId(data[0]); + input = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], &gUnknown_0203CE58.scrollPosition[gUnknown_0203CE58.pocket], &gUnknown_0203CE58.cursorPosition[gUnknown_0203CE58.pocket]); sub_80D4FC8(0); sub_80D4FEC(gUnknown_0203CE58.cursorPosition[gUnknown_0203CE58.pocket]); - switch (r7) + switch (input) { - case -1: + case LIST_NOTHING_CHOSEN: break; - case -2: + case LIST_B_PRESSED: PlaySE(SE_SELECT); if (gMain.newKeys & A_BUTTON) sub_81AC498(taskId); @@ -1546,9 +1546,9 @@ void Task_HandleInBattleItemMenuInput(u8 taskId) s8 r4 = Menu_ProcessInputNoWrap(); switch (r4) { - case -2: + case MENU_NOTHING_CHOSEN: break; - case -1: + case MENU_B_PRESSED: PlaySE(SE_SELECT); gUnknown_08613FB4[4].func.void_u8(taskId); break; diff --git a/src/item_use.c b/src/item_use.c index 4f2639431..d1fcb4a0b 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -38,8 +38,6 @@ #include "constants/songs.h" #include "constants/vars.h" -extern void(*gUnknown_0203A0F4)(u8 taskId); -extern void (*gUnknown_03006328)(u8, TaskFunc); extern void unknown_ItemMenu_Confirm(u8 taskId); extern void sub_81C5B14(u8 taskId); extern void ScriptUnfreezeEventObjects(void); @@ -100,6 +98,9 @@ void sub_80FDBEC(void); bool8 sub_80FDE2C(void); void ItemUseOutOfBattle_CannotUse(u8 taskId); +// EWRAM variables +EWRAM_DATA static void(*gUnknown_0203A0F4)(u8 taskId) = NULL; + // .rodata static const MainCallback gUnknown_085920D8[] = diff --git a/src/learn_move.c b/src/learn_move.c index 4db83861e..7a6916013 100644 --- a/src/learn_move.c +++ b/src/learn_move.c @@ -638,7 +638,7 @@ static void HideSpritesAndPrintTeachText(bool8 a) static void HandleInput(bool8 showContest) { - s32 itemId = ListMenuHandleInputGetItemId(sLearnMoveStruct->listMenuTask); + s32 itemId = ListMenu_ProcessInput(sLearnMoveStruct->listMenuTask); ListMenuGetScrollAndRow(sLearnMoveStruct->listMenuTask, &sLearnMoveStruct2.listOffset, &sLearnMoveStruct2.listRow); switch (itemId) diff --git a/src/list_menu.c b/src/list_menu.c index 2476fae26..7a9547661 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -334,7 +334,7 @@ s32 DoMysteryGiftListMenu(struct WindowTemplate *windowTemplate, struct ListMenu sMysteryGiftLinkMenu.state = 1; break; case 1: - sMysteryGiftLinkMenu.currItemId = ListMenuHandleInputGetItemId(sMysteryGiftLinkMenu.listTaskId); + sMysteryGiftLinkMenu.currItemId = ListMenu_ProcessInput(sMysteryGiftLinkMenu.listTaskId); if (gMain.newKeys & A_BUTTON) { sMysteryGiftLinkMenu.state = 2; @@ -406,7 +406,7 @@ u8 ListMenuInitInRect(struct ListMenuTemplate *listMenuTemplate, struct ListMenu return taskId; } -s32 ListMenuHandleInputGetItemId(u8 listTaskId) +s32 ListMenu_ProcessInput(u8 listTaskId) { struct ListMenu *list = (void*) gTasks[listTaskId].data; diff --git a/src/m4a.c b/src/m4a.c new file mode 100644 index 000000000..7b4441ca4 --- /dev/null +++ b/src/m4a.c @@ -0,0 +1,1779 @@ +#include "gba/m4a_internal.h" + +extern const u8 gCgb3Vol[]; + +#define BSS_CODE __attribute__((section(".bss.code"))) + +BSS_CODE ALIGNED(4) char SoundMainRAM_Buffer[0x800] = {0}; + +struct SoundInfo gSoundInfo; +struct PokemonCrySong gPokemonCrySongs[MAX_POKEMON_CRIES]; +struct MusicPlayerInfo gPokemonCryMusicPlayers[MAX_POKEMON_CRIES]; +void *gMPlayJumpTable[36]; +struct CgbChannel gCgbChans[4]; +struct MusicPlayerTrack gPokemonCryTracks[MAX_POKEMON_CRIES * 2]; +struct PokemonCrySong gPokemonCrySong; +struct MusicPlayerInfo gMPlayInfo_BGM; +struct MusicPlayerInfo gMPlayInfo_SE1; +struct MusicPlayerInfo gMPlayInfo_SE2; +struct MusicPlayerInfo gMPlayInfo_SE3; +u8 gMPlayMemAccArea[0x10]; + +u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust) +{ + u32 val1; + u32 val2; + u32 fineAdjustShifted = fineAdjust << 24; + + if (key > 178) + { + key = 178; + fineAdjustShifted = 255 << 24; + } + + val1 = gScaleTable[key]; + val1 = gFreqTable[val1 & 0xF] >> (val1 >> 4); + + val2 = gScaleTable[key + 1]; + val2 = gFreqTable[val2 & 0xF] >> (val2 >> 4); + + return umul3232H32(wav->freq, val1 + umul3232H32(val2 - val1, fineAdjustShifted)); +} + +void UnusedDummyFunc(void) +{ +} + +void MPlayContinue(struct MusicPlayerInfo *mplayInfo) +{ + if (mplayInfo->ident == ID_NUMBER) + { + mplayInfo->ident++; + mplayInfo->status &= ~MUSICPLAYER_STATUS_PAUSE; + mplayInfo->ident = ID_NUMBER; + } +} + +void MPlayFadeOut(struct MusicPlayerInfo *mplayInfo, u16 speed) +{ + if (mplayInfo->ident == ID_NUMBER) + { + mplayInfo->ident++; + mplayInfo->fadeOC = speed; + mplayInfo->fadeOI = speed; + mplayInfo->fadeOV = (64 << FADE_VOL_SHIFT); + mplayInfo->ident = ID_NUMBER; + } +} + +void m4aSoundInit(void) +{ + s32 i; + + CpuCopy32((void *)((s32)SoundMainRAM & ~1), SoundMainRAM_Buffer, sizeof(SoundMainRAM_Buffer)); + + SoundInit(&gSoundInfo); + MPlayExtender(gCgbChans); + m4aSoundMode(SOUND_MODE_DA_BIT_8 + | SOUND_MODE_FREQ_13379 + | (12 << SOUND_MODE_MASVOL_SHIFT) + | (5 << SOUND_MODE_MAXCHN_SHIFT)); + + for (i = 0; i < NUM_MUSIC_PLAYERS; i++) + { + struct MusicPlayerInfo *mplayInfo = gMPlayTable[i].info; + MPlayOpen(mplayInfo, gMPlayTable[i].track, gMPlayTable[i].unk_8); + mplayInfo->unk_B = gMPlayTable[i].unk_A; + mplayInfo->memAccArea = gMPlayMemAccArea; + } + + memcpy(&gPokemonCrySong, &gPokemonCrySongTemplate, sizeof(struct PokemonCrySong)); + + for (i = 0; i < MAX_POKEMON_CRIES; i++) + { + struct MusicPlayerInfo *mplayInfo = &gPokemonCryMusicPlayers[i]; + struct MusicPlayerTrack *track = &gPokemonCryTracks[i * 2]; + MPlayOpen(mplayInfo, track, 2); + track->chan = 0; + } +} + +void m4aSoundMain(void) +{ + SoundMain(); +} + +void m4aSongNumStart(u16 n) +{ + const struct MusicPlayer *mplayTable = gMPlayTable; + const struct Song *songTable = gSongTable; + const struct Song *song = &songTable[n]; + const struct MusicPlayer *mplay = &mplayTable[song->ms]; + + MPlayStart(mplay->info, song->header); +} + +void m4aSongNumStartOrChange(u16 n) +{ + const struct MusicPlayer *mplayTable = gMPlayTable; + const struct Song *songTable = gSongTable; + const struct Song *song = &songTable[n]; + const struct MusicPlayer *mplay = &mplayTable[song->ms]; + + if (mplay->info->songHeader != song->header) + { + MPlayStart(mplay->info, song->header); + } + else + { + if ((mplay->info->status & MUSICPLAYER_STATUS_TRACK) == 0 + || (mplay->info->status & MUSICPLAYER_STATUS_PAUSE)) + { + MPlayStart(mplay->info, song->header); + } + } +} + +void m4aSongNumStartOrContinue(u16 n) +{ + const struct MusicPlayer *mplayTable = gMPlayTable; + const struct Song *songTable = gSongTable; + const struct Song *song = &songTable[n]; + const struct MusicPlayer *mplay = &mplayTable[song->ms]; + + if (mplay->info->songHeader != song->header) + MPlayStart(mplay->info, song->header); + else if ((mplay->info->status & MUSICPLAYER_STATUS_TRACK) == 0) + MPlayStart(mplay->info, song->header); + else if (mplay->info->status & MUSICPLAYER_STATUS_PAUSE) + MPlayContinue(mplay->info); +} + +void m4aSongNumStop(u16 n) +{ + const struct MusicPlayer *mplayTable = gMPlayTable; + const struct Song *songTable = gSongTable; + const struct Song *song = &songTable[n]; + const struct MusicPlayer *mplay = &mplayTable[song->ms]; + + if (mplay->info->songHeader == song->header) + m4aMPlayStop(mplay->info); +} + +void m4aSongNumContinue(u16 n) +{ + const struct MusicPlayer *mplayTable = gMPlayTable; + const struct Song *songTable = gSongTable; + const struct Song *song = &songTable[n]; + const struct MusicPlayer *mplay = &mplayTable[song->ms]; + + if (mplay->info->songHeader == song->header) + MPlayContinue(mplay->info); +} + +void m4aMPlayAllStop(void) +{ + s32 i; + + for (i = 0; i < NUM_MUSIC_PLAYERS; i++) + m4aMPlayStop(gMPlayTable[i].info); + + for (i = 0; i < MAX_POKEMON_CRIES; i++) + m4aMPlayStop(&gPokemonCryMusicPlayers[i]); +} + +void m4aMPlayContinue(struct MusicPlayerInfo *mplayInfo) +{ + MPlayContinue(mplayInfo); +} + +void m4aMPlayAllContinue(void) +{ + s32 i; + + for (i = 0; i < NUM_MUSIC_PLAYERS; i++) + MPlayContinue(gMPlayTable[i].info); + + for (i = 0; i < MAX_POKEMON_CRIES; i++) + MPlayContinue(&gPokemonCryMusicPlayers[i]); +} + +void m4aMPlayFadeOut(struct MusicPlayerInfo *mplayInfo, u16 speed) +{ + MPlayFadeOut(mplayInfo, speed); +} + +void m4aMPlayFadeOutTemporarily(struct MusicPlayerInfo *mplayInfo, u16 speed) +{ + if (mplayInfo->ident == ID_NUMBER) + { + mplayInfo->ident++; + mplayInfo->fadeOC = speed; + mplayInfo->fadeOI = speed; + mplayInfo->fadeOV = (64 << FADE_VOL_SHIFT) | TEMPORARY_FADE; + mplayInfo->ident = ID_NUMBER; + } +} + +void m4aMPlayFadeIn(struct MusicPlayerInfo *mplayInfo, u16 speed) +{ + if (mplayInfo->ident == ID_NUMBER) + { + mplayInfo->ident++; + mplayInfo->fadeOC = speed; + mplayInfo->fadeOI = speed; + mplayInfo->fadeOV = (0 << FADE_VOL_SHIFT) | FADE_IN; + mplayInfo->status &= ~MUSICPLAYER_STATUS_PAUSE; + mplayInfo->ident = ID_NUMBER; + } +} + +void m4aMPlayImmInit(struct MusicPlayerInfo *mplayInfo) +{ + s32 trackCount = mplayInfo->trackCount; + struct MusicPlayerTrack *track = mplayInfo->tracks; + + while (trackCount > 0) + { + if (track->flags & MPT_FLG_EXIST) + { + if (track->flags & MPT_FLG_START) + { + Clear64byte(track); + track->flags = MPT_FLG_EXIST; + track->bendRange = 2; + track->volX = 64; + track->lfoSpeed = 22; + track->tone.type = 1; + } + } + + trackCount--; + track++; + } +} + +void MPlayExtender(struct CgbChannel *cgbChans) +{ + struct SoundInfo *soundInfo; + u32 ident; + + REG_SOUNDCNT_X = SOUND_MASTER_ENABLE + | SOUND_4_ON + | SOUND_3_ON + | SOUND_2_ON + | SOUND_1_ON; + REG_SOUNDCNT_L = 0; // set master volume to zero + REG_NR12 = 0x8; + REG_NR22 = 0x8; + REG_NR42 = 0x8; + REG_NR14 = 0x80; + REG_NR24 = 0x80; + REG_NR44 = 0x80; + REG_NR30 = 0; + REG_NR50 = 0x77; + + soundInfo = SOUND_INFO_PTR; + + ident = soundInfo->ident; + + if (ident != ID_NUMBER) + return; + + soundInfo->ident++; + + gMPlayJumpTable[8] = ply_memacc; + gMPlayJumpTable[17] = ply_lfos; + gMPlayJumpTable[19] = ply_mod; + gMPlayJumpTable[28] = ply_xcmd; + gMPlayJumpTable[29] = ply_endtie; + gMPlayJumpTable[30] = SampleFreqSet; + gMPlayJumpTable[31] = TrackStop; + gMPlayJumpTable[32] = FadeOutBody; + gMPlayJumpTable[33] = TrkVolPitSet; + + soundInfo->cgbChans = (struct CgbChannel *)cgbChans; + soundInfo->CgbSound = CgbSound; + soundInfo->CgbOscOff = CgbOscOff; + soundInfo->MidiKeyToCgbFreq = MidiKeyToCgbFreq; + soundInfo->maxLines = MAX_LINES; + + CpuFill32(0, cgbChans, sizeof(struct CgbChannel) * 4); + + cgbChans[0].ty = 1; + cgbChans[0].panMask = 0x11; + cgbChans[1].ty = 2; + cgbChans[1].panMask = 0x22; + cgbChans[2].ty = 3; + cgbChans[2].panMask = 0x44; + cgbChans[3].ty = 4; + cgbChans[3].panMask = 0x88; + + soundInfo->ident = ident; +} + +void MusicPlayerJumpTableCopy(void) +{ + asm("swi 0x2A"); +} + +void ClearChain(void *x) +{ + void (*func)(void *) = *(&gMPlayJumpTable[34]); + func(x); +} + +void Clear64byte(void *x) +{ + void (*func)(void *) = *(&gMPlayJumpTable[35]); + func(x); +} + +void SoundInit(struct SoundInfo *soundInfo) +{ + soundInfo->ident = 0; + + if (REG_DMA1CNT & (DMA_REPEAT << 16)) + REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + + if (REG_DMA2CNT & (DMA_REPEAT << 16)) + REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + + REG_DMA1CNT_H = DMA_32BIT; + REG_DMA2CNT_H = DMA_32BIT; + REG_SOUNDCNT_X = SOUND_MASTER_ENABLE + | SOUND_4_ON + | SOUND_3_ON + | SOUND_2_ON + | SOUND_1_ON; + REG_SOUNDCNT_H = SOUND_B_FIFO_RESET | SOUND_B_TIMER_0 | SOUND_B_LEFT_OUTPUT + | SOUND_A_FIFO_RESET | SOUND_A_TIMER_0 | SOUND_A_RIGHT_OUTPUT + | SOUND_ALL_MIX_FULL; + REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | 0x40; + + REG_DMA1SAD = (s32)soundInfo->pcmBuffer; + REG_DMA1DAD = (s32)®_FIFO_A; + REG_DMA2SAD = (s32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE; + REG_DMA2DAD = (s32)®_FIFO_B; + + SOUND_INFO_PTR = soundInfo; + CpuFill32(0, soundInfo, sizeof(struct SoundInfo)); + + soundInfo->maxChans = 8; + soundInfo->masterVolume = 15; + soundInfo->plynote = (u32)ply_note; + soundInfo->CgbSound = DummyFunc; + soundInfo->CgbOscOff = (void (*)(u8))DummyFunc; + soundInfo->MidiKeyToCgbFreq = (u32 (*)(u8, u8, u8))DummyFunc; + soundInfo->ExtVolPit = (u32)DummyFunc; + + MPlayJumpTableCopy(gMPlayJumpTable); + + soundInfo->MPlayJumpTable = (u32)gMPlayJumpTable; + + SampleFreqSet(SOUND_MODE_FREQ_13379); + + soundInfo->ident = ID_NUMBER; +} + +void SampleFreqSet(u32 freq) +{ + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + + freq = (freq & 0xF0000) >> 16; + soundInfo->freq = freq; + soundInfo->pcmSamplesPerVBlank = gPcmSamplesPerVBlankTable[freq - 1]; + soundInfo->pcmDmaPeriod = PCM_DMA_BUF_SIZE / soundInfo->pcmSamplesPerVBlank; + + // LCD refresh rate 59.7275Hz + soundInfo->pcmFreq = (597275 * soundInfo->pcmSamplesPerVBlank + 5000) / 10000; + + // CPU frequency 16.78Mhz + soundInfo->divFreq = (16777216 / soundInfo->pcmFreq + 1) >> 1; + + // Turn off timer 0. + REG_TM0CNT_H = 0; + + // cycles per LCD fresh 280896 + REG_TM0CNT_L = -(280896 / soundInfo->pcmSamplesPerVBlank); + + m4aSoundVSyncOn(); + + while (*(vu8 *)REG_ADDR_VCOUNT == 159) + ; + + while (*(vu8 *)REG_ADDR_VCOUNT != 159) + ; + + REG_TM0CNT_H = TIMER_ENABLE | TIMER_1CLK; +} + +void m4aSoundMode(u32 mode) +{ + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + u32 temp; + + if (soundInfo->ident != ID_NUMBER) + return; + + soundInfo->ident++; + + temp = mode & (SOUND_MODE_REVERB_SET | SOUND_MODE_REVERB_VAL); + + if (temp) + soundInfo->reverb = temp & SOUND_MODE_REVERB_VAL; + + temp = mode & SOUND_MODE_MAXCHN; + + if (temp) + { + struct SoundChannel *chan; + + soundInfo->maxChans = temp >> SOUND_MODE_MAXCHN_SHIFT; + + temp = MAX_DIRECTSOUND_CHANNELS; + chan = &soundInfo->chans[0]; + + while (temp != 0) + { + chan->status = 0; + temp--; + chan++; + } + } + + temp = mode & SOUND_MODE_MASVOL; + + if (temp) + soundInfo->masterVolume = temp >> SOUND_MODE_MASVOL_SHIFT; + + temp = mode & SOUND_MODE_DA_BIT; + + if (temp) + { + temp = (temp & 0x300000) >> 14; + REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | temp; + } + + temp = mode & SOUND_MODE_FREQ; + + if (temp) + { + m4aSoundVSyncOff(); + SampleFreqSet(temp); + } + + soundInfo->ident = ID_NUMBER; +} + +void SoundClear(void) +{ + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + s32 i; + void *chan; + + if (soundInfo->ident != ID_NUMBER) + return; + + soundInfo->ident++; + + i = MAX_DIRECTSOUND_CHANNELS; + chan = &soundInfo->chans[0]; + + while (i > 0) + { + ((struct SoundChannel *)chan)->status = 0; + i--; + chan = (void *)((s32)chan + sizeof(struct SoundChannel)); + } + + chan = soundInfo->cgbChans; + + if (chan) + { + i = 1; + + while (i <= 4) + { + soundInfo->CgbOscOff(i); + ((struct CgbChannel *)chan)->sf = 0; + i++; + chan = (void *)((s32)chan + sizeof(struct CgbChannel)); + } + } + + soundInfo->ident = ID_NUMBER; +} + +void m4aSoundVSyncOff(void) +{ + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + + if (soundInfo->ident >= ID_NUMBER && soundInfo->ident <= ID_NUMBER + 1) + { + soundInfo->ident += 10; + + if (REG_DMA1CNT & (DMA_REPEAT << 16)) + REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + + if (REG_DMA2CNT & (DMA_REPEAT << 16)) + REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + + REG_DMA1CNT_H = DMA_32BIT; + REG_DMA2CNT_H = DMA_32BIT; + + CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer)); + } +} + +void m4aSoundVSyncOn(void) +{ + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + u32 ident = soundInfo->ident; + + if (ident == ID_NUMBER) + return; + + REG_DMA1CNT_H = DMA_ENABLE | DMA_START_SPECIAL | DMA_32BIT | DMA_REPEAT; + REG_DMA2CNT_H = DMA_ENABLE | DMA_START_SPECIAL | DMA_32BIT | DMA_REPEAT; + + soundInfo->pcmDmaCounter = 0; + soundInfo->ident = ident - 10; +} + +void MPlayOpen(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tracks, u8 trackCount) +{ + struct SoundInfo *soundInfo; + + if (trackCount == 0) + return; + + if (trackCount > MAX_MUSICPLAYER_TRACKS) + trackCount = MAX_MUSICPLAYER_TRACKS; + + soundInfo = SOUND_INFO_PTR; + + if (soundInfo->ident != ID_NUMBER) + return; + + soundInfo->ident++; + + Clear64byte(mplayInfo); + + mplayInfo->tracks = tracks; + mplayInfo->trackCount = trackCount; + mplayInfo->status = MUSICPLAYER_STATUS_PAUSE; + + while (trackCount != 0) + { + tracks->flags = 0; + trackCount--; + tracks++; + } + + if (soundInfo->func != 0) + { + mplayInfo->func = soundInfo->func; + mplayInfo->intp = soundInfo->intp; + soundInfo->func = 0; + } + + soundInfo->intp = (u32)mplayInfo; + soundInfo->func = (u32)MPlayMain; + soundInfo->ident = ID_NUMBER; + mplayInfo->ident = ID_NUMBER; +} + +void MPlayStart(struct MusicPlayerInfo *mplayInfo, struct SongHeader *songHeader) +{ + s32 i; + u8 unk_B; + struct MusicPlayerTrack *track; + + if (mplayInfo->ident != ID_NUMBER) + return; + + unk_B = mplayInfo->unk_B; + + if (!unk_B + || ((!mplayInfo->songHeader || !(mplayInfo->tracks[0].flags & MPT_FLG_START)) + && ((mplayInfo->status & MUSICPLAYER_STATUS_TRACK) == 0 + || (mplayInfo->status & MUSICPLAYER_STATUS_PAUSE))) + || (mplayInfo->priority <= songHeader->priority)) + { + mplayInfo->ident++; + mplayInfo->status = 0; + mplayInfo->songHeader = songHeader; + mplayInfo->tone = songHeader->tone; + mplayInfo->priority = songHeader->priority; + mplayInfo->clock = 0; + mplayInfo->tempoD = 150; + mplayInfo->tempoI = 150; + mplayInfo->tempoU = 0x100; + mplayInfo->tempoC = 0; + mplayInfo->fadeOI = 0; + + i = 0; + track = mplayInfo->tracks; + + while (i < songHeader->trackCount && i < mplayInfo->trackCount) + { + TrackStop(mplayInfo, track); + track->flags = MPT_FLG_EXIST | MPT_FLG_START; + track->chan = 0; + track->cmdPtr = songHeader->part[i]; + i++; + track++; + } + + while (i < mplayInfo->trackCount) + { + TrackStop(mplayInfo, track); + track->flags = 0; + i++; + track++; + } + + if (songHeader->reverb & 0x80) + m4aSoundMode(songHeader->reverb); + + mplayInfo->ident = ID_NUMBER; + } +} + +void m4aMPlayStop(struct MusicPlayerInfo *mplayInfo) +{ + s32 i; + struct MusicPlayerTrack *track; + + if (mplayInfo->ident != ID_NUMBER) + return; + + mplayInfo->ident++; + mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE; + + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) + { + TrackStop(mplayInfo, track); + i--; + track++; + } + + mplayInfo->ident = ID_NUMBER; +} + +void FadeOutBody(struct MusicPlayerInfo *mplayInfo) +{ + s32 i; + struct MusicPlayerTrack *track; + u16 fadeOV; +#ifdef NONMATCHING + u16 mask; +#else + register u16 mask asm("r2"); +#endif // NONMATCHING + + if (mplayInfo->fadeOI == 0) + return; + + mplayInfo->fadeOC--; + mask = 0xFFFF; + + if (mplayInfo->fadeOC != 0) + return; + + mplayInfo->fadeOC = mplayInfo->fadeOI; + + if (mplayInfo->fadeOV & FADE_IN) + { + mplayInfo->fadeOV += (4 << FADE_VOL_SHIFT); + + if ((u16)(mplayInfo->fadeOV & mask) >= (64 << FADE_VOL_SHIFT)) + { + mplayInfo->fadeOV = (64 << FADE_VOL_SHIFT); + mplayInfo->fadeOI = 0; + } + } + else + { + mplayInfo->fadeOV -= (4 << FADE_VOL_SHIFT); + + if ((s16)(mplayInfo->fadeOV & mask) <= 0) + { + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) + { + u32 val; + + TrackStop(mplayInfo, track); + + val = TEMPORARY_FADE; + fadeOV = mplayInfo->fadeOV; + val &= fadeOV; + + if (!val) + track->flags = 0; + + i--; + track++; + } + + if (mplayInfo->fadeOV & TEMPORARY_FADE) + mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE; + else + mplayInfo->status = MUSICPLAYER_STATUS_PAUSE; + + mplayInfo->fadeOI = 0; + return; + } + } + + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) + { + if (track->flags & MPT_FLG_EXIST) + { + fadeOV = mplayInfo->fadeOV; + + track->volX = (fadeOV >> FADE_VOL_SHIFT); + track->flags |= MPT_FLG_VOLCHG; + } + + i--; + track++; + } +} + +void TrkVolPitSet(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + if (track->flags & MPT_FLG_VOLSET) + { + s32 x; + s32 y; + + x = (u32)(track->vol * track->volX) >> 5; + + if (track->modT == 1) + x = (u32)(x * (track->modM + 128)) >> 7; + + y = 2 * track->pan + track->panX; + + if (track->modT == 2) + y += track->modM; + + if (y < -128) + y = -128; + else if (y > 127) + y = 127; + + track->volMR = (u32)((y + 128) * x) >> 8; + track->volML = (u32)((127 - y) * x) >> 8; + } + + if (track->flags & MPT_FLG_PITSET) + { + s32 bend = track->bend * track->bendRange; + s32 x = (track->tune + bend) + * 4 + + (track->keyShift << 8) + + (track->keyShiftX << 8) + + track->pitX; + + if (track->modT == 0) + x += 16 * track->modM; + + track->keyM = x >> 8; + track->pitM = x; + } + + track->flags &= ~(MPT_FLG_PITSET | MPT_FLG_VOLSET); +} + +u32 MidiKeyToCgbFreq(u8 chanNum, u8 key, u8 fineAdjust) +{ + if (chanNum == 4) + { + if (key <= 20) + { + key = 0; + } + else + { + key -= 21; + if (key > 59) + key = 59; + } + + return gNoiseTable[key]; + } + else + { + s32 val1; + s32 val2; + + if (key <= 35) + { + fineAdjust = 0; + key = 0; + } + else + { + key -= 36; + if (key > 130) + { + key = 130; + fineAdjust = 255; + } + } + + val1 = gCgbScaleTable[key]; + val1 = gCgbFreqTable[val1 & 0xF] >> (val1 >> 4); + + val2 = gCgbScaleTable[key + 1]; + val2 = gCgbFreqTable[val2 & 0xF] >> (val2 >> 4); + + return val1 + ((fineAdjust * (val2 - val1)) >> 8) + 2048; + } +} + +void CgbOscOff(u8 chanNum) +{ + switch (chanNum) + { + case 1: + REG_NR12 = 8; + REG_NR14 = 0x80; + break; + case 2: + REG_NR22 = 8; + REG_NR24 = 0x80; + break; + case 3: + REG_NR30 = 0; + break; + default: + REG_NR42 = 8; + REG_NR44 = 0x80; + } +} + +static inline int CgbPan(struct CgbChannel *chan) +{ + u32 rightVolume = chan->rightVolume; + u32 leftVolume = chan->leftVolume; + + if ((rightVolume = (u8)rightVolume) >= (leftVolume = (u8)leftVolume)) + { + if (rightVolume / 2 >= leftVolume) + { + chan->pan = 0x0F; + return 1; + } + } + else + { + if (leftVolume / 2 >= rightVolume) + { + chan->pan = 0xF0; + return 1; + } + } + + return 0; +} + +void CgbModVol(struct CgbChannel *chan) +{ + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + + if ((soundInfo->mode & 1) || !CgbPan(chan)) + { + chan->pan = 0xFF; + chan->eg = (u32)(chan->rightVolume + chan->leftVolume) >> 4; + } + else + { + // Force chan->rightVolume and chan->leftVolume to be read from memory again, + // even though there is no reason to do so. + // The command line option "-fno-gcse" achieves the same result as this. + asm("" : : : "memory"); + + chan->eg = (u32)(chan->rightVolume + chan->leftVolume) >> 4; + if (chan->eg > 15) + chan->eg = 15; + } + + chan->sg = (chan->eg * chan->su + 15) >> 4; + chan->pan &= chan->panMask; +} + +void CgbSound(void) +{ + s32 ch; + struct CgbChannel *channels; + s32 evAdd; + s32 prevC15; + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + vu8 *nrx0ptr; + vu8 *nrx1ptr; + vu8 *nrx2ptr; + vu8 *nrx3ptr; + vu8 *nrx4ptr; + + // Most comparision operations that cast to s8 perform 'and' by 0xFF. + int mask = 0xff; + + if (soundInfo->c15) + soundInfo->c15--; + else + soundInfo->c15 = 14; + + for (ch = 1, channels = soundInfo->cgbChans; ch <= 4; ch++, channels++) + { + if (!(channels->sf & 0xc7)) + continue; + + switch (ch) + { + case 1: + nrx0ptr = (vu8 *)(REG_ADDR_NR10); + nrx1ptr = (vu8 *)(REG_ADDR_NR11); + nrx2ptr = (vu8 *)(REG_ADDR_NR12); + nrx3ptr = (vu8 *)(REG_ADDR_NR13); + nrx4ptr = (vu8 *)(REG_ADDR_NR14); + break; + case 2: + nrx0ptr = (vu8 *)(REG_ADDR_NR10+1); + nrx1ptr = (vu8 *)(REG_ADDR_NR21); + nrx2ptr = (vu8 *)(REG_ADDR_NR22); + nrx3ptr = (vu8 *)(REG_ADDR_NR23); + nrx4ptr = (vu8 *)(REG_ADDR_NR24); + break; + case 3: + nrx0ptr = (vu8 *)(REG_ADDR_NR30); + nrx1ptr = (vu8 *)(REG_ADDR_NR31); + nrx2ptr = (vu8 *)(REG_ADDR_NR32); + nrx3ptr = (vu8 *)(REG_ADDR_NR33); + nrx4ptr = (vu8 *)(REG_ADDR_NR34); + break; + default: + nrx0ptr = (vu8 *)(REG_ADDR_NR30+1); + nrx1ptr = (vu8 *)(REG_ADDR_NR41); + nrx2ptr = (vu8 *)(REG_ADDR_NR42); + nrx3ptr = (vu8 *)(REG_ADDR_NR43); + nrx4ptr = (vu8 *)(REG_ADDR_NR44); + break; + } + + prevC15 = soundInfo->c15; + evAdd = *nrx2ptr; + + if (channels->sf & 0x80) + { + if (!(channels->sf & 0x40)) + { + channels->sf = 3; + channels->mo = 3; + CgbModVol(channels); + switch (ch) + { + case 1: + *nrx0ptr = channels->sw; + // fallthrough + case 2: + *nrx1ptr = ((u32)channels->wp << 6) + channels->le; + goto loc_82E0E30; + case 3: + if ((u32)channels->wp != channels->cp) + { + *nrx0ptr = 0x40; + REG_WAVE_RAM0 = channels->wp[0]; + REG_WAVE_RAM1 = channels->wp[1]; + REG_WAVE_RAM2 = channels->wp[2]; + REG_WAVE_RAM3 = channels->wp[3]; + channels->cp = (u32)channels->wp; + } + *nrx0ptr = 0; + *nrx1ptr = channels->le; + if (channels->le) + channels->n4 = -64; + else + channels->n4 = -128; + break; + default: + *nrx1ptr = channels->le; + *nrx3ptr = (u32)channels->wp << 3; + loc_82E0E30: + evAdd = channels->at + 8; + if (channels->le) + channels->n4 = 64; + else + channels->n4 = 0; + break; + } + channels->ec = channels->at; + if ((s8)(channels->at & mask)) + { + channels->ev = 0; + goto EC_MINUS; + } + else + { + goto loc_82E0F96; + } + } + else + { + goto loc_82E0E82; + } + } + else if (channels->sf & 0x04) + { + channels->echoLength--; + if ((s8)(channels->echoLength & mask) <= 0) + { + loc_82E0E82: + CgbOscOff(ch); + channels->sf = 0; + goto LAST_LABEL; + } + goto loc_82E0FD6; + } + else if ((channels->sf & 0x40) && (channels->sf & 0x03)) + { + channels->sf &= 0xfc; + channels->ec = channels->re; + if ((s8)(channels->re & mask)) + { + channels->mo |= 1; + if (ch != 3) + { + evAdd = channels->re; + } + goto EC_MINUS; + } + else + { + goto loc_82E0F02; + } + } + else + { + loc_82E0ED0: + if (channels->ec == 0) + { + if (ch == 3) + { + channels->mo |= 1; + } + CgbModVol(channels); + if ((channels->sf & 0x3) == 0) + { + channels->ev--; + if ((s8)(channels->ev & mask) <= 0) + { + loc_82E0F02: + channels->ev = ((channels->eg * channels->echoVolume) + 0xFF) >> 8; + if (channels->ev) + { + channels->sf |= 0x4; + channels->mo |= 1; + if (ch != 3) + { + evAdd = 8; + } + goto loc_82E0FD6; + } + else + { + goto loc_82E0E82; + } + } + else + { + channels->ec = channels->re; + } + } + else if ((channels->sf & 0x3) == 1) + { + loc_82E0F3A: + channels->ev = channels->sg; + channels->ec = 7; + } + else if ((channels->sf & 0x3) == 2) + { + int ev, sg; + + channels->ev--; + ev = (s8)(channels->ev & mask); + sg = (s8)(channels->sg); + if (ev <= sg) + { + loc_82E0F5A: + if (channels->su == 0) + { + channels->sf &= 0xfc; + goto loc_82E0F02; + } + else + { + channels->sf--; + channels->mo |= 1; + if (ch != 3) + { + evAdd = 8; + } + goto loc_82E0F3A; + } + } + else + { + channels->ec = channels->de; + } + } + else + { + channels->ev++; + if ((u8)(channels->ev & mask) >= channels->eg) + { + loc_82E0F96: + channels->sf--; + channels->ec = channels->de; + if ((u8)(channels->ec & mask)) + { + channels->mo |= 1; + channels->ev = channels->eg; + if (ch != 3) + { + evAdd = channels->de; + } + } + else + { + goto loc_82E0F5A; + } + } + else + { + channels->ec = channels->at; + } + } + } + } + + EC_MINUS: + channels->ec--; + if (prevC15 == 0) + { + prevC15--; + goto loc_82E0ED0; + } + + loc_82E0FD6: + if (channels->mo & 0x2) + { + if (ch < 4 && (channels->ty & 0x08)) + { + int biasH = REG_SOUNDBIAS_H; + + if (biasH < 64) + { + channels->fr = (channels->fr + 2) & 0x7fc; + } + else if (biasH < 128) + { + channels->fr = (channels->fr + 1) & 0x7fe; + } + } + if (ch != 4) + { + *nrx3ptr = channels->fr; + } + else + { + *nrx3ptr = (*nrx3ptr & 0x08) | channels->fr; + } + channels->n4 = (channels->n4 & 0xC0) + (*((u8*)(&channels->fr) + 1)); + *nrx4ptr = (s8)(channels->n4 & mask); + } + + if (channels->mo & 1) + { + REG_NR51 = (REG_NR51 & ~channels->panMask) | channels->pan; + if (ch == 3) + { + *nrx2ptr = gCgb3Vol[channels->ev]; + if (channels->n4 & 0x80) + { + *nrx0ptr = 0x80; + *nrx4ptr = channels->n4; + channels->n4 &= 0x7f; + } + } + else + { + evAdd &= 0xf; + *nrx2ptr = (channels->ev << 4) + evAdd; + *nrx4ptr = channels->n4 | 0x80; + if (ch == 1 && !(*nrx0ptr & 0x08)) + { + *nrx4ptr = channels->n4 | 0x80; + } + } + } + + LAST_LABEL: + channels->mo = 0; + } +} + +void m4aMPlayTempoControl(struct MusicPlayerInfo *mplayInfo, u16 tempo) +{ + if (mplayInfo->ident == ID_NUMBER) + { + mplayInfo->ident++; + mplayInfo->tempoU = tempo; + mplayInfo->tempoI = (mplayInfo->tempoD * mplayInfo->tempoU) >> 8; + mplayInfo->ident = ID_NUMBER; + } +} + +void m4aMPlayVolumeControl(struct MusicPlayerInfo *mplayInfo, u16 trackBits, u16 volume) +{ + s32 i; + u32 bit; + struct MusicPlayerTrack *track; + + if (mplayInfo->ident != ID_NUMBER) + return; + + mplayInfo->ident++; + + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + bit = 1; + + while (i > 0) + { + if (trackBits & bit) + { + if (track->flags & MPT_FLG_EXIST) + { + track->volX = volume / 4; + track->flags |= MPT_FLG_VOLCHG; + } + } + + i--; + track++; + bit <<= 1; + } + + mplayInfo->ident = ID_NUMBER; +} + +void m4aMPlayPitchControl(struct MusicPlayerInfo *mplayInfo, u16 trackBits, s16 pitch) +{ + s32 i; + u32 bit; + struct MusicPlayerTrack *track; + + if (mplayInfo->ident != ID_NUMBER) + return; + + mplayInfo->ident++; + + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + bit = 1; + + while (i > 0) + { + if (trackBits & bit) + { + if (track->flags & MPT_FLG_EXIST) + { + track->keyShiftX = pitch >> 8; + track->pitX = pitch; + track->flags |= MPT_FLG_PITCHG; + } + } + + i--; + track++; + bit <<= 1; + } + + mplayInfo->ident = ID_NUMBER; +} + +void m4aMPlayPanpotControl(struct MusicPlayerInfo *mplayInfo, u16 trackBits, s8 pan) +{ + s32 i; + u32 bit; + struct MusicPlayerTrack *track; + + if (mplayInfo->ident != ID_NUMBER) + return; + + mplayInfo->ident++; + + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + bit = 1; + + while (i > 0) + { + if (trackBits & bit) + { + if (track->flags & MPT_FLG_EXIST) + { + track->panX = pan; + track->flags |= MPT_FLG_VOLCHG; + } + } + + i--; + track++; + bit <<= 1; + } + + mplayInfo->ident = ID_NUMBER; +} + +void ClearModM(struct MusicPlayerTrack *track) +{ + track->lfoSpeedC = 0; + track->modM = 0; + + if (track->modT == 0) + track->flags |= MPT_FLG_PITCHG; + else + track->flags |= MPT_FLG_VOLCHG; +} + +void m4aMPlayModDepthSet(struct MusicPlayerInfo *mplayInfo, u16 trackBits, u8 modDepth) +{ + s32 i; + u32 bit; + struct MusicPlayerTrack *track; + + if (mplayInfo->ident != ID_NUMBER) + return; + + mplayInfo->ident++; + + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + bit = 1; + + while (i > 0) + { + if (trackBits & bit) + { + if (track->flags & MPT_FLG_EXIST) + { + track->mod = modDepth; + + if (!track->mod) + ClearModM(track); + } + } + + i--; + track++; + bit <<= 1; + } + + mplayInfo->ident = ID_NUMBER; +} + +void m4aMPlayLFOSpeedSet(struct MusicPlayerInfo *mplayInfo, u16 trackBits, u8 lfoSpeed) +{ + s32 i; + u32 bit; + struct MusicPlayerTrack *track; + + if (mplayInfo->ident != ID_NUMBER) + return; + + mplayInfo->ident++; + + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + bit = 1; + + while (i > 0) + { + if (trackBits & bit) + { + if (track->flags & MPT_FLG_EXIST) + { + track->lfoSpeed = lfoSpeed; + + if (!track->lfoSpeed) + ClearModM(track); + } + } + + i--; + track++; + bit <<= 1; + } + + mplayInfo->ident = ID_NUMBER; +} + +#define MEMACC_COND_JUMP(cond) \ +if (cond) \ + goto cond_true; \ +else \ + goto cond_false; \ + +void ply_memacc(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + u32 op; + u8 *addr; + u8 data; + + op = *track->cmdPtr; + track->cmdPtr++; + + addr = mplayInfo->memAccArea + *track->cmdPtr; + track->cmdPtr++; + + data = *track->cmdPtr; + track->cmdPtr++; + + switch (op) + { + case 0: + *addr = data; + return; + case 1: + *addr += data; + return; + case 2: + *addr -= data; + return; + case 3: + *addr = mplayInfo->memAccArea[data]; + return; + case 4: + *addr += mplayInfo->memAccArea[data]; + return; + case 5: + *addr -= mplayInfo->memAccArea[data]; + return; + case 6: + MEMACC_COND_JUMP(*addr == data) + return; + case 7: + MEMACC_COND_JUMP(*addr != data) + return; + case 8: + MEMACC_COND_JUMP(*addr > data) + return; + case 9: + MEMACC_COND_JUMP(*addr >= data) + return; + case 10: + MEMACC_COND_JUMP(*addr <= data) + return; + case 11: + MEMACC_COND_JUMP(*addr < data) + return; + case 12: + MEMACC_COND_JUMP(*addr == mplayInfo->memAccArea[data]) + return; + case 13: + MEMACC_COND_JUMP(*addr != mplayInfo->memAccArea[data]) + return; + case 14: + MEMACC_COND_JUMP(*addr > mplayInfo->memAccArea[data]) + return; + case 15: + MEMACC_COND_JUMP(*addr >= mplayInfo->memAccArea[data]) + return; + case 16: + MEMACC_COND_JUMP(*addr <= mplayInfo->memAccArea[data]) + return; + case 17: + MEMACC_COND_JUMP(*addr < mplayInfo->memAccArea[data]) + return; + default: + return; + } + +cond_true: + { + void (*func)(struct MusicPlayerInfo *, struct MusicPlayerTrack *) = *(&gMPlayJumpTable[1]); + func(mplayInfo, track); + return; + } + +cond_false: + track->cmdPtr += 4; +} + +void ply_xcmd(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + u32 n = *track->cmdPtr; + track->cmdPtr++; + + gXcmdTable[n](mplayInfo, track); +} + +void ply_xxx(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + void (*func)(struct MusicPlayerInfo *, struct MusicPlayerTrack *) = *(&gMPlayJumpTable[0]); + func(mplayInfo, track); +} + +#define READ_XCMD_BYTE(var, n) \ +{ \ + u32 byte = track->cmdPtr[(n)]; \ + byte <<= n * 8; \ + (var) &= ~(0xFF << (n * 8)); \ + (var) |= byte; \ +} + +void ply_xwave(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + u32 wav; + + READ_XCMD_BYTE(wav, 0) // UB: uninitialized variable + READ_XCMD_BYTE(wav, 1) + READ_XCMD_BYTE(wav, 2) + READ_XCMD_BYTE(wav, 3) + + track->tone.wav = (struct WaveData *)wav; + track->cmdPtr += 4; +} + +void ply_xtype(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->tone.type = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xatta(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->tone.attack = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xdeca(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->tone.decay = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xsust(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->tone.sustain = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xrele(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->tone.release = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xiecv(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->echoVolume = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xiecl(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->echoLength = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xleng(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->tone.length = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xswee(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + track->tone.pan_sweep = *track->cmdPtr; + track->cmdPtr++; +} + +void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + u32 unk; + + READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable + READ_XCMD_BYTE(unk, 1) + + if (track->unk_3A < (u16)unk) + { + track->unk_3A++; + track->cmdPtr -= 2; + track->wait = 1; + } + else + { + track->unk_3A = 0; + track->cmdPtr += 2; + } +} + +void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) +{ + u32 unk; + + READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable + READ_XCMD_BYTE(unk, 1) + READ_XCMD_BYTE(unk, 2) + READ_XCMD_BYTE(unk, 3) + + track->unk_3C = unk; + track->cmdPtr += 4; +} + +void DummyFunc(void) +{ +} + +struct MusicPlayerInfo *SetPokemonCryTone(struct ToneData *tone) +{ + u32 maxClock = 0; + s32 maxClockIndex = 0; + s32 i; + struct MusicPlayerInfo *mplayInfo; + + for (i = 0; i < MAX_POKEMON_CRIES; i++) + { + struct MusicPlayerTrack *track = &gPokemonCryTracks[i * 2]; + + if (!track->flags && (!track->chan || track->chan->track != track)) + goto start_song; + + if (maxClock < gPokemonCryMusicPlayers[i].clock) + { + maxClock = gPokemonCryMusicPlayers[i].clock; + maxClockIndex = i; + } + } + + i = maxClockIndex; + +start_song: + mplayInfo = &gPokemonCryMusicPlayers[i]; + mplayInfo->ident++; + +#define CRY ((s32)&gPokemonCrySongs + i * sizeof(struct PokemonCrySong)) +#define CRY_OFS(field) offsetof(struct PokemonCrySong, field) + + memcpy((void *)CRY, &gPokemonCrySong, sizeof(struct PokemonCrySong)); + + *(u32 *)(CRY + CRY_OFS(tone)) = (u32)tone; + *(u32 *)(CRY + CRY_OFS(part)) = CRY + CRY_OFS(part0); + *(u32 *)(CRY + CRY_OFS(part) + 4) = CRY + CRY_OFS(part1); + *(u32 *)(CRY + CRY_OFS(gotoTarget)) = CRY + CRY_OFS(cont); + +#undef CRY_OFS +#undef CRY + + mplayInfo->ident = ID_NUMBER; + + MPlayStart(mplayInfo, (struct SongHeader *)(&gPokemonCrySongs[i])); + + return mplayInfo; +} + +void SetPokemonCryVolume(u8 val) +{ + gPokemonCrySong.volumeValue = val & 0x7F; +} + +void SetPokemonCryPanpot(s8 val) +{ + gPokemonCrySong.panValue = (val + C_V) & 0x7F; +} + +void SetPokemonCryPitch(s16 val) +{ + s16 b = val + 0x80; + u8 a = gPokemonCrySong.tuneValue2 - gPokemonCrySong.tuneValue; + gPokemonCrySong.tieKeyValue = (b >> 8) & 0x7F; + gPokemonCrySong.tuneValue = (b >> 1) & 0x7F; + gPokemonCrySong.tuneValue2 = (a + ((b >> 1) & 0x7F)) & 0x7F; +} + +void SetPokemonCryLength(u16 val) +{ + gPokemonCrySong.unkCmd0CParam = val; +} + +void SetPokemonCryRelease(u8 val) +{ + gPokemonCrySong.releaseValue = val; +} + +void SetPokemonCryProgress(u32 val) +{ + gPokemonCrySong.unkCmd0DParam = val; +} + +int IsPokemonCryPlaying(struct MusicPlayerInfo *mplayInfo) +{ + struct MusicPlayerTrack *track = mplayInfo->tracks; + + if (track->chan && track->chan->track == track) + return 1; + else + return 0; +} + +void SetPokemonCryChorus(s8 val) +{ + if (val) + { + gPokemonCrySong.trackCount = 2; + gPokemonCrySong.tuneValue2 = (val + gPokemonCrySong.tuneValue) & 0x7F; + } + else + { + gPokemonCrySong.trackCount = 1; + } +} + +void SetPokemonCryStereo(u32 val) +{ + struct SoundInfo *soundInfo = SOUND_INFO_PTR; + + if (val) + { + REG_SOUNDCNT_H = SOUND_B_TIMER_0 | SOUND_B_LEFT_OUTPUT + | SOUND_A_TIMER_0 | SOUND_A_RIGHT_OUTPUT + | SOUND_ALL_MIX_FULL; + soundInfo->mode &= ~1; + } + else + { + REG_SOUNDCNT_H = SOUND_B_TIMER_0 | SOUND_B_LEFT_OUTPUT | SOUND_B_RIGHT_OUTPUT + | SOUND_A_TIMER_0 | SOUND_A_LEFT_OUTPUT | SOUND_A_RIGHT_OUTPUT + | SOUND_B_MIX_HALF | SOUND_A_MIX_HALF | SOUND_CGB_MIX_FULL; + soundInfo->mode |= 1; + } +} + +void SetPokemonCryPriority(u8 val) +{ + gPokemonCrySong.priority = val; +} diff --git a/src/m4a_2.c b/src/m4a_2.c deleted file mode 100644 index 0625f05d1..000000000 --- a/src/m4a_2.c +++ /dev/null @@ -1,912 +0,0 @@ -#include "gba/m4a_internal.h" - -#define BSS_CODE __attribute__((section(".bss.code"))) - -BSS_CODE ALIGNED(4) char SoundMainRAM_Buffer[0x800] = {0}; - -struct SoundInfo gSoundInfo; -struct PokemonCrySong gPokemonCrySongs[MAX_POKEMON_CRIES]; -struct MusicPlayerInfo gPokemonCryMusicPlayers[MAX_POKEMON_CRIES]; -void *gMPlayJumpTable[36]; -struct CgbChannel gCgbChans[4]; -struct MusicPlayerTrack gPokemonCryTracks[MAX_POKEMON_CRIES * 2]; -struct PokemonCrySong gPokemonCrySong; -struct MusicPlayerInfo gMPlayInfo_BGM; -struct MusicPlayerInfo gMPlayInfo_SE1; -struct MusicPlayerInfo gMPlayInfo_SE2; -struct MusicPlayerInfo gMPlayInfo_SE3; -u8 gMPlayMemAccArea[0x10]; - -u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust) -{ - u32 val1; - u32 val2; - u32 fineAdjustShifted = fineAdjust << 24; - - if (key > 178) - { - key = 178; - fineAdjustShifted = 255 << 24; - } - - val1 = gScaleTable[key]; - val1 = gFreqTable[val1 & 0xF] >> (val1 >> 4); - - val2 = gScaleTable[key + 1]; - val2 = gFreqTable[val2 & 0xF] >> (val2 >> 4); - - return umul3232H32(wav->freq, val1 + umul3232H32(val2 - val1, fineAdjustShifted)); -} - -void UnusedDummyFunc() -{ -} - -void MPlayContinue(struct MusicPlayerInfo *mplayInfo) -{ - if (mplayInfo->ident == ID_NUMBER) - { - mplayInfo->ident++; - mplayInfo->status &= ~MUSICPLAYER_STATUS_PAUSE; - mplayInfo->ident = ID_NUMBER; - } -} - -void MPlayFadeOut(struct MusicPlayerInfo *mplayInfo, u16 speed) -{ - if (mplayInfo->ident == ID_NUMBER) - { - mplayInfo->ident++; - mplayInfo->fadeOC = speed; - mplayInfo->fadeOI = speed; - mplayInfo->fadeOV = (64 << FADE_VOL_SHIFT); - mplayInfo->ident = ID_NUMBER; - } -} - -void m4aSoundInit(void) -{ - s32 i; - - CpuCopy32((void *)((s32)SoundMainRAM & ~1), SoundMainRAM_Buffer, sizeof(SoundMainRAM_Buffer)); - - SoundInit(&gSoundInfo); - MPlayExtender(gCgbChans); - m4aSoundMode(SOUND_MODE_DA_BIT_8 - | SOUND_MODE_FREQ_13379 - | (12 << SOUND_MODE_MASVOL_SHIFT) - | (5 << SOUND_MODE_MAXCHN_SHIFT)); - - for (i = 0; i < NUM_MUSIC_PLAYERS; i++) - { - struct MusicPlayerInfo *mplayInfo = gMPlayTable[i].info; - MPlayOpen(mplayInfo, gMPlayTable[i].track, gMPlayTable[i].unk_8); - mplayInfo->unk_B = gMPlayTable[i].unk_A; - mplayInfo->memAccArea = gMPlayMemAccArea; - } - - memcpy(&gPokemonCrySong, &gPokemonCrySongTemplate, sizeof(struct PokemonCrySong)); - - for (i = 0; i < MAX_POKEMON_CRIES; i++) - { - struct MusicPlayerInfo *mplayInfo = &gPokemonCryMusicPlayers[i]; - struct MusicPlayerTrack *track = &gPokemonCryTracks[i * 2]; - MPlayOpen(mplayInfo, track, 2); - track->chan = 0; - } -} - -void m4aSoundMain(void) -{ - SoundMain(); -} - -void m4aSongNumStart(u16 n) -{ - const struct MusicPlayer *mplayTable = gMPlayTable; - const struct Song *songTable = gSongTable; - const struct Song *song = &songTable[n]; - const struct MusicPlayer *mplay = &mplayTable[song->ms]; - - MPlayStart(mplay->info, song->header); -} - -void m4aSongNumStartOrChange(u16 n) -{ - const struct MusicPlayer *mplayTable = gMPlayTable; - const struct Song *songTable = gSongTable; - const struct Song *song = &songTable[n]; - const struct MusicPlayer *mplay = &mplayTable[song->ms]; - - if (mplay->info->songHeader != song->header) - { - MPlayStart(mplay->info, song->header); - } - else - { - if ((mplay->info->status & MUSICPLAYER_STATUS_TRACK) == 0 - || (mplay->info->status & MUSICPLAYER_STATUS_PAUSE)) - { - MPlayStart(mplay->info, song->header); - } - } -} - -void m4aSongNumStartOrContinue(u16 n) -{ - const struct MusicPlayer *mplayTable = gMPlayTable; - const struct Song *songTable = gSongTable; - const struct Song *song = &songTable[n]; - const struct MusicPlayer *mplay = &mplayTable[song->ms]; - - if (mplay->info->songHeader != song->header) - MPlayStart(mplay->info, song->header); - else if ((mplay->info->status & MUSICPLAYER_STATUS_TRACK) == 0) - MPlayStart(mplay->info, song->header); - else if (mplay->info->status & MUSICPLAYER_STATUS_PAUSE) - MPlayContinue(mplay->info); -} - -void m4aSongNumStop(u16 n) -{ - const struct MusicPlayer *mplayTable = gMPlayTable; - const struct Song *songTable = gSongTable; - const struct Song *song = &songTable[n]; - const struct MusicPlayer *mplay = &mplayTable[song->ms]; - - if (mplay->info->songHeader == song->header) - m4aMPlayStop(mplay->info); -} - -void m4aSongNumContinue(u16 n) -{ - const struct MusicPlayer *mplayTable = gMPlayTable; - const struct Song *songTable = gSongTable; - const struct Song *song = &songTable[n]; - const struct MusicPlayer *mplay = &mplayTable[song->ms]; - - if (mplay->info->songHeader == song->header) - MPlayContinue(mplay->info); -} - -void m4aMPlayAllStop(void) -{ - s32 i; - - for (i = 0; i < NUM_MUSIC_PLAYERS; i++) - m4aMPlayStop(gMPlayTable[i].info); - - for (i = 0; i < MAX_POKEMON_CRIES; i++) - m4aMPlayStop(&gPokemonCryMusicPlayers[i]); -} - -void m4aMPlayContinue(struct MusicPlayerInfo *mplayInfo) -{ - MPlayContinue(mplayInfo); -} - -void m4aMPlayAllContinue(void) -{ - s32 i; - - for (i = 0; i < NUM_MUSIC_PLAYERS; i++) - MPlayContinue(gMPlayTable[i].info); - - for (i = 0; i < MAX_POKEMON_CRIES; i++) - MPlayContinue(&gPokemonCryMusicPlayers[i]); -} - -void m4aMPlayFadeOut(struct MusicPlayerInfo *mplayInfo, u16 speed) -{ - MPlayFadeOut(mplayInfo, speed); -} - -void m4aMPlayFadeOutTemporarily(struct MusicPlayerInfo *mplayInfo, u16 speed) -{ - if (mplayInfo->ident == ID_NUMBER) - { - mplayInfo->ident++; - mplayInfo->fadeOC = speed; - mplayInfo->fadeOI = speed; - mplayInfo->fadeOV = (64 << FADE_VOL_SHIFT) | TEMPORARY_FADE; - mplayInfo->ident = ID_NUMBER; - } -} - -void m4aMPlayFadeIn(struct MusicPlayerInfo *mplayInfo, u16 speed) -{ - if (mplayInfo->ident == ID_NUMBER) - { - mplayInfo->ident++; - mplayInfo->fadeOC = speed; - mplayInfo->fadeOI = speed; - mplayInfo->fadeOV = (0 << FADE_VOL_SHIFT) | FADE_IN; - mplayInfo->status &= ~MUSICPLAYER_STATUS_PAUSE; - mplayInfo->ident = ID_NUMBER; - } -} - -void m4aMPlayImmInit(struct MusicPlayerInfo *mplayInfo) -{ - s32 trackCount = mplayInfo->trackCount; - struct MusicPlayerTrack *track = mplayInfo->tracks; - - while (trackCount > 0) - { - if (track->flags & MPT_FLG_EXIST) - { - if (track->flags & MPT_FLG_START) - { - Clear64byte(track); - track->flags = MPT_FLG_EXIST; - track->bendRange = 2; - track->volX = 64; - track->lfoSpeed = 22; - track->tone.type = 1; - } - } - - trackCount--; - track++; - } -} - -void MPlayExtender(struct CgbChannel *cgbChans) -{ - struct SoundInfo *soundInfo; - u32 ident; - - REG_SOUNDCNT_X = SOUND_MASTER_ENABLE - | SOUND_4_ON - | SOUND_3_ON - | SOUND_2_ON - | SOUND_1_ON; - REG_SOUNDCNT_L = 0; // set master volume to zero - REG_NR12 = 0x8; - REG_NR22 = 0x8; - REG_NR42 = 0x8; - REG_NR14 = 0x80; - REG_NR24 = 0x80; - REG_NR44 = 0x80; - REG_NR30 = 0; - REG_NR50 = 0x77; - - soundInfo = SOUND_INFO_PTR; - - ident = soundInfo->ident; - - if (ident != ID_NUMBER) - return; - - soundInfo->ident++; - - gMPlayJumpTable[8] = ply_memacc; - gMPlayJumpTable[17] = ply_lfos; - gMPlayJumpTable[19] = ply_mod; - gMPlayJumpTable[28] = ply_xcmd; - gMPlayJumpTable[29] = ply_endtie; - gMPlayJumpTable[30] = SampleFreqSet; - gMPlayJumpTable[31] = TrackStop; - gMPlayJumpTable[32] = FadeOutBody; - gMPlayJumpTable[33] = TrkVolPitSet; - - soundInfo->cgbChans = (struct CgbChannel *)cgbChans; - soundInfo->CgbSound = CgbSound; - soundInfo->CgbOscOff = CgbOscOff; - soundInfo->MidiKeyToCgbFreq = MidiKeyToCgbFreq; - soundInfo->maxLines = MAX_LINES; - - CpuFill32(0, cgbChans, sizeof(struct CgbChannel) * 4); - - cgbChans[0].ty = 1; - cgbChans[0].panMask = 0x11; - cgbChans[1].ty = 2; - cgbChans[1].panMask = 0x22; - cgbChans[2].ty = 3; - cgbChans[2].panMask = 0x44; - cgbChans[3].ty = 4; - cgbChans[3].panMask = 0x88; - - soundInfo->ident = ident; -} - -void MusicPlayerJumpTableCopy(void) -{ - asm("swi 0x2A"); -} - -void ClearChain(void *x) -{ - void (*func)(void *) = *(&gMPlayJumpTable[34]); - func(x); -} - -void Clear64byte(void *x) -{ - void (*func)(void *) = *(&gMPlayJumpTable[35]); - func(x); -} - -void SoundInit(struct SoundInfo *soundInfo) -{ - soundInfo->ident = 0; - - if (REG_DMA1CNT & (DMA_REPEAT << 16)) - REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - - if (REG_DMA2CNT & (DMA_REPEAT << 16)) - REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - - REG_DMA1CNT_H = DMA_32BIT; - REG_DMA2CNT_H = DMA_32BIT; - REG_SOUNDCNT_X = SOUND_MASTER_ENABLE - | SOUND_4_ON - | SOUND_3_ON - | SOUND_2_ON - | SOUND_1_ON; - REG_SOUNDCNT_H = SOUND_B_FIFO_RESET | SOUND_B_TIMER_0 | SOUND_B_LEFT_OUTPUT - | SOUND_A_FIFO_RESET | SOUND_A_TIMER_0 | SOUND_A_RIGHT_OUTPUT - | SOUND_ALL_MIX_FULL; - REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | 0x40; - - REG_DMA1SAD = (s32)soundInfo->pcmBuffer; - REG_DMA1DAD = (s32)®_FIFO_A; - REG_DMA2SAD = (s32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE; - REG_DMA2DAD = (s32)®_FIFO_B; - - SOUND_INFO_PTR = soundInfo; - CpuFill32(0, soundInfo, sizeof(struct SoundInfo)); - - soundInfo->maxChans = 8; - soundInfo->masterVolume = 15; - soundInfo->plynote = (u32)ply_note; - soundInfo->CgbSound = DummyFunc; - soundInfo->CgbOscOff = (void (*)(u8))DummyFunc; - soundInfo->MidiKeyToCgbFreq = (u32 (*)(u8, u8, u8))DummyFunc; - soundInfo->ExtVolPit = (u32)DummyFunc; - - MPlayJumpTableCopy(gMPlayJumpTable); - - soundInfo->MPlayJumpTable = (u32)gMPlayJumpTable; - - SampleFreqSet(SOUND_MODE_FREQ_13379); - - soundInfo->ident = ID_NUMBER; -} - -void SampleFreqSet(u32 freq) -{ - struct SoundInfo *soundInfo = SOUND_INFO_PTR; - - freq = (freq & 0xF0000) >> 16; - soundInfo->freq = freq; - soundInfo->pcmSamplesPerVBlank = gPcmSamplesPerVBlankTable[freq - 1]; - soundInfo->pcmDmaPeriod = PCM_DMA_BUF_SIZE / soundInfo->pcmSamplesPerVBlank; - - // LCD refresh rate 59.7275Hz - soundInfo->pcmFreq = (597275 * soundInfo->pcmSamplesPerVBlank + 5000) / 10000; - - // CPU frequency 16.78Mhz - soundInfo->divFreq = (16777216 / soundInfo->pcmFreq + 1) >> 1; - - // Turn off timer 0. - REG_TM0CNT_H = 0; - - // cycles per LCD fresh 280896 - REG_TM0CNT_L = -(280896 / soundInfo->pcmSamplesPerVBlank); - - m4aSoundVSyncOn(); - - while (*(vu8 *)REG_ADDR_VCOUNT == 159) - ; - - while (*(vu8 *)REG_ADDR_VCOUNT != 159) - ; - - REG_TM0CNT_H = TIMER_ENABLE | TIMER_1CLK; -} - -void m4aSoundMode(u32 mode) -{ - struct SoundInfo *soundInfo = SOUND_INFO_PTR; - u32 temp; - - if (soundInfo->ident != ID_NUMBER) - return; - - soundInfo->ident++; - - temp = mode & (SOUND_MODE_REVERB_SET | SOUND_MODE_REVERB_VAL); - - if (temp) - soundInfo->reverb = temp & SOUND_MODE_REVERB_VAL; - - temp = mode & SOUND_MODE_MAXCHN; - - if (temp) - { - struct SoundChannel *chan; - - soundInfo->maxChans = temp >> SOUND_MODE_MAXCHN_SHIFT; - - temp = MAX_DIRECTSOUND_CHANNELS; - chan = &soundInfo->chans[0]; - - while (temp != 0) - { - chan->status = 0; - temp--; - chan++; - } - } - - temp = mode & SOUND_MODE_MASVOL; - - if (temp) - soundInfo->masterVolume = temp >> SOUND_MODE_MASVOL_SHIFT; - - temp = mode & SOUND_MODE_DA_BIT; - - if (temp) - { - temp = (temp & 0x300000) >> 14; - REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | temp; - } - - temp = mode & SOUND_MODE_FREQ; - - if (temp) - { - m4aSoundVSyncOff(); - SampleFreqSet(temp); - } - - soundInfo->ident = ID_NUMBER; -} - -void SoundClear(void) -{ - struct SoundInfo *soundInfo = SOUND_INFO_PTR; - s32 i; - void *chan; - - if (soundInfo->ident != ID_NUMBER) - return; - - soundInfo->ident++; - - i = MAX_DIRECTSOUND_CHANNELS; - chan = &soundInfo->chans[0]; - - while (i > 0) - { - ((struct SoundChannel *)chan)->status = 0; - i--; - chan = (void *)((s32)chan + sizeof(struct SoundChannel)); - } - - chan = soundInfo->cgbChans; - - if (chan) - { - i = 1; - - while (i <= 4) - { - soundInfo->CgbOscOff(i); - ((struct CgbChannel *)chan)->sf = 0; - i++; - chan = (void *)((s32)chan + sizeof(struct CgbChannel)); - } - } - - soundInfo->ident = ID_NUMBER; -} - -void m4aSoundVSyncOff(void) -{ - struct SoundInfo *soundInfo = SOUND_INFO_PTR; - - if (soundInfo->ident >= ID_NUMBER && soundInfo->ident <= ID_NUMBER + 1) - { - soundInfo->ident += 10; - - if (REG_DMA1CNT & (DMA_REPEAT << 16)) - REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - - if (REG_DMA2CNT & (DMA_REPEAT << 16)) - REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - - REG_DMA1CNT_H = DMA_32BIT; - REG_DMA2CNT_H = DMA_32BIT; - - CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer)); - } -} - -void m4aSoundVSyncOn(void) -{ - struct SoundInfo *soundInfo = SOUND_INFO_PTR; - u32 ident = soundInfo->ident; - - if (ident == ID_NUMBER) - return; - - REG_DMA1CNT_H = DMA_ENABLE | DMA_START_SPECIAL | DMA_32BIT | DMA_REPEAT; - REG_DMA2CNT_H = DMA_ENABLE | DMA_START_SPECIAL | DMA_32BIT | DMA_REPEAT; - - soundInfo->pcmDmaCounter = 0; - soundInfo->ident = ident - 10; -} - -void MPlayOpen(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tracks, u8 trackCount) -{ - struct SoundInfo *soundInfo; - - if (trackCount == 0) - return; - - if (trackCount > MAX_MUSICPLAYER_TRACKS) - trackCount = MAX_MUSICPLAYER_TRACKS; - - soundInfo = SOUND_INFO_PTR; - - if (soundInfo->ident != ID_NUMBER) - return; - - soundInfo->ident++; - - Clear64byte(mplayInfo); - - mplayInfo->tracks = tracks; - mplayInfo->trackCount = trackCount; - mplayInfo->status = MUSICPLAYER_STATUS_PAUSE; - - while (trackCount != 0) - { - tracks->flags = 0; - trackCount--; - tracks++; - } - - if (soundInfo->func != 0) - { - mplayInfo->func = soundInfo->func; - mplayInfo->intp = soundInfo->intp; - soundInfo->func = 0; - } - - soundInfo->intp = (u32)mplayInfo; - soundInfo->func = (u32)MPlayMain; - soundInfo->ident = ID_NUMBER; - mplayInfo->ident = ID_NUMBER; -} - -void MPlayStart(struct MusicPlayerInfo *mplayInfo, struct SongHeader *songHeader) -{ - s32 i; - u8 unk_B; - struct MusicPlayerTrack *track; - - if (mplayInfo->ident != ID_NUMBER) - return; - - unk_B = mplayInfo->unk_B; - - if (!unk_B - || ((!mplayInfo->songHeader || !(mplayInfo->tracks[0].flags & MPT_FLG_START)) - && ((mplayInfo->status & MUSICPLAYER_STATUS_TRACK) == 0 - || (mplayInfo->status & MUSICPLAYER_STATUS_PAUSE))) - || (mplayInfo->priority <= songHeader->priority)) - { - mplayInfo->ident++; - mplayInfo->status = 0; - mplayInfo->songHeader = songHeader; - mplayInfo->tone = songHeader->tone; - mplayInfo->priority = songHeader->priority; - mplayInfo->clock = 0; - mplayInfo->tempoD = 150; - mplayInfo->tempoI = 150; - mplayInfo->tempoU = 0x100; - mplayInfo->tempoC = 0; - mplayInfo->fadeOI = 0; - - i = 0; - track = mplayInfo->tracks; - - while (i < songHeader->trackCount && i < mplayInfo->trackCount) - { - TrackStop(mplayInfo, track); - track->flags = MPT_FLG_EXIST | MPT_FLG_START; - track->chan = 0; - track->cmdPtr = songHeader->part[i]; - i++; - track++; - } - - while (i < mplayInfo->trackCount) - { - TrackStop(mplayInfo, track); - track->flags = 0; - i++; - track++; - } - - if (songHeader->reverb & 0x80) - m4aSoundMode(songHeader->reverb); - - mplayInfo->ident = ID_NUMBER; - } -} - -void m4aMPlayStop(struct MusicPlayerInfo *mplayInfo) -{ - s32 i; - struct MusicPlayerTrack *track; - - if (mplayInfo->ident != ID_NUMBER) - return; - - mplayInfo->ident++; - mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE; - - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - - while (i > 0) - { - TrackStop(mplayInfo, track); - i--; - track++; - } - - mplayInfo->ident = ID_NUMBER; -} - -void FadeOutBody(struct MusicPlayerInfo *mplayInfo) -{ - s32 i; - struct MusicPlayerTrack *track; - u16 fadeOI = mplayInfo->fadeOI; - register u32 temp asm("r3"); - register u16 mask asm("r2"); - - if (fadeOI == 0) - return; - - mplayInfo->fadeOC--; - - temp = 0xFFFF; - mask = temp; - - if (mplayInfo->fadeOC != 0) - return; - - mplayInfo->fadeOC = fadeOI; - - if (mplayInfo->fadeOV & FADE_IN) - { - mplayInfo->fadeOV += (4 << FADE_VOL_SHIFT); - - if ((u16)(mplayInfo->fadeOV & mask) >= (64 << FADE_VOL_SHIFT)) - { - mplayInfo->fadeOV = (64 << FADE_VOL_SHIFT); - mplayInfo->fadeOI = 0; - } - } - else - { - mplayInfo->fadeOV -= (4 << FADE_VOL_SHIFT); - - if ((s16)(mplayInfo->fadeOV & mask) <= 0) - { - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - - while (i > 0) - { - register u32 fadeOV asm("r7"); - u32 val; - - TrackStop(mplayInfo, track); - - val = TEMPORARY_FADE; - fadeOV = mplayInfo->fadeOV; - val &= fadeOV; - - if (!val) - track->flags = 0; - - i--; - track++; - } - - if (mplayInfo->fadeOV & TEMPORARY_FADE) - mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE; - else - mplayInfo->status = MUSICPLAYER_STATUS_PAUSE; - - mplayInfo->fadeOI = 0; - return; - } - } - - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - - while (i > 0) - { - if (track->flags & MPT_FLG_EXIST) - { - track->volX = (mplayInfo->fadeOV >> FADE_VOL_SHIFT); - track->flags |= MPT_FLG_VOLCHG; - } - - i--; - track++; - } -} - -void TrkVolPitSet(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - if (track->flags & MPT_FLG_VOLSET) - { - s32 x; - s32 y; - - x = (u32)(track->vol * track->volX) >> 5; - - if (track->modT == 1) - x = (u32)(x * (track->modM + 128)) >> 7; - - y = 2 * track->pan + track->panX; - - if (track->modT == 2) - y += track->modM; - - if (y < -128) - y = -128; - else if (y > 127) - y = 127; - - track->volMR = (u32)((y + 128) * x) >> 8; - track->volML = (u32)((127 - y) * x) >> 8; - } - - if (track->flags & MPT_FLG_PITSET) - { - s32 bend = track->bend * track->bendRange; - register s32 x asm("r1") = track->tune; - x += bend; - x *= 4; - x += (track->keyShift << 8); - x += (track->keyShiftX << 8); - x += track->pitX; - - if (track->modT == 0) - x += 16 * track->modM; - - track->keyM = x >> 8; - track->pitM = x; - } - - track->flags &= ~(MPT_FLG_PITSET | MPT_FLG_VOLSET); -} - -u32 MidiKeyToCgbFreq(u8 chanNum, u8 key, u8 fineAdjust) -{ - if (chanNum == 4) - { - if (key <= 20) - { - key = 0; - } - else - { - key -= 21; - if (key > 59) - key = 59; - } - - return gNoiseTable[key]; - } - else - { - s32 val1; - s32 val2; - - if (key <= 35) - { - fineAdjust = 0; - key = 0; - } - else - { - key -= 36; - if (key > 130) - { - key = 130; - fineAdjust = 255; - } - } - - val1 = gCgbScaleTable[key]; - val1 = gCgbFreqTable[val1 & 0xF] >> (val1 >> 4); - - val2 = gCgbScaleTable[key + 1]; - val2 = gCgbFreqTable[val2 & 0xF] >> (val2 >> 4); - - return val1 + ((fineAdjust * (val2 - val1)) >> 8) + 2048; - } -} - -void CgbOscOff(u8 chanNum) -{ - switch (chanNum) - { - case 1: - REG_NR12 = 8; - REG_NR14 = 0x80; - break; - case 2: - REG_NR22 = 8; - REG_NR24 = 0x80; - break; - case 3: - REG_NR30 = 0; - break; - default: - REG_NR42 = 8; - REG_NR44 = 0x80; - } -} - -static inline int CgbPan(struct CgbChannel *chan) -{ - u32 rightVolume = chan->rightVolume; - u32 leftVolume = chan->leftVolume; - - if ((rightVolume = (u8)rightVolume) >= (leftVolume = (u8)leftVolume)) - { - if (rightVolume / 2 >= leftVolume) - { - chan->pan = 0x0F; - return 1; - } - } - else - { - if (leftVolume / 2 >= rightVolume) - { - chan->pan = 0xF0; - return 1; - } - } - - return 0; -} - -void CgbModVol(struct CgbChannel *chan) -{ - struct SoundInfo *soundInfo = SOUND_INFO_PTR; - - if ((soundInfo->mode & 1) || !CgbPan(chan)) - { - chan->pan = 0xFF; - chan->eg = (u32)(chan->rightVolume + chan->leftVolume) >> 4; - } - else - { - // Force chan->rightVolume and chan->leftVolume to be read from memory again, - // even though there is no reason to do so. - // The command line option "-fno-gcse" achieves the same result as this. - asm("" : : : "memory"); - - chan->eg = (u32)(chan->rightVolume + chan->leftVolume) >> 4; - if (chan->eg > 15) - chan->eg = 15; - } - - chan->sg = (chan->eg * chan->su + 15) >> 4; - chan->pan &= chan->panMask; -} diff --git a/src/m4a_4.c b/src/m4a_4.c deleted file mode 100644 index e645fbef5..000000000 --- a/src/m4a_4.c +++ /dev/null @@ -1,545 +0,0 @@ -#include "gba/m4a_internal.h" - -void m4aMPlayTempoControl(struct MusicPlayerInfo *mplayInfo, u16 tempo) -{ - if (mplayInfo->ident == ID_NUMBER) - { - mplayInfo->ident++; - mplayInfo->tempoU = tempo; - mplayInfo->tempoI = (mplayInfo->tempoD * mplayInfo->tempoU) >> 8; - mplayInfo->ident = ID_NUMBER; - } -} - -void m4aMPlayVolumeControl(struct MusicPlayerInfo *mplayInfo, u16 trackBits, u16 volume) -{ - s32 i; - u32 bit; - struct MusicPlayerTrack *track; - - if (mplayInfo->ident != ID_NUMBER) - return; - - mplayInfo->ident++; - - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - bit = 1; - - while (i > 0) - { - if (trackBits & bit) - { - if (track->flags & MPT_FLG_EXIST) - { - track->volX = volume / 4; - track->flags |= MPT_FLG_VOLCHG; - } - } - - i--; - track++; - bit <<= 1; - } - - mplayInfo->ident = ID_NUMBER; -} - -void m4aMPlayPitchControl(struct MusicPlayerInfo *mplayInfo, u16 trackBits, s16 pitch) -{ - s32 i; - u32 bit; - struct MusicPlayerTrack *track; - - if (mplayInfo->ident != ID_NUMBER) - return; - - mplayInfo->ident++; - - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - bit = 1; - - while (i > 0) - { - if (trackBits & bit) - { - if (track->flags & MPT_FLG_EXIST) - { - track->keyShiftX = pitch >> 8; - track->pitX = pitch; - track->flags |= MPT_FLG_PITCHG; - } - } - - i--; - track++; - bit <<= 1; - } - - mplayInfo->ident = ID_NUMBER; -} - -void m4aMPlayPanpotControl(struct MusicPlayerInfo *mplayInfo, u16 trackBits, s8 pan) -{ - s32 i; - u32 bit; - struct MusicPlayerTrack *track; - - if (mplayInfo->ident != ID_NUMBER) - return; - - mplayInfo->ident++; - - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - bit = 1; - - while (i > 0) - { - if (trackBits & bit) - { - if (track->flags & MPT_FLG_EXIST) - { - track->panX = pan; - track->flags |= MPT_FLG_VOLCHG; - } - } - - i--; - track++; - bit <<= 1; - } - - mplayInfo->ident = ID_NUMBER; -} - -void ClearModM(struct MusicPlayerTrack *track) -{ - track->lfoSpeedC = 0; - track->modM = 0; - - if (track->modT == 0) - track->flags |= MPT_FLG_PITCHG; - else - track->flags |= MPT_FLG_VOLCHG; -} - -void m4aMPlayModDepthSet(struct MusicPlayerInfo *mplayInfo, u16 trackBits, u8 modDepth) -{ - s32 i; - u32 bit; - struct MusicPlayerTrack *track; - - if (mplayInfo->ident != ID_NUMBER) - return; - - mplayInfo->ident++; - - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - bit = 1; - - while (i > 0) - { - if (trackBits & bit) - { - if (track->flags & MPT_FLG_EXIST) - { - track->mod = modDepth; - - if (!track->mod) - ClearModM(track); - } - } - - i--; - track++; - bit <<= 1; - } - - mplayInfo->ident = ID_NUMBER; -} - -void m4aMPlayLFOSpeedSet(struct MusicPlayerInfo *mplayInfo, u16 trackBits, u8 lfoSpeed) -{ - s32 i; - u32 bit; - struct MusicPlayerTrack *track; - - if (mplayInfo->ident != ID_NUMBER) - return; - - mplayInfo->ident++; - - i = mplayInfo->trackCount; - track = mplayInfo->tracks; - bit = 1; - - while (i > 0) - { - if (trackBits & bit) - { - if (track->flags & MPT_FLG_EXIST) - { - track->lfoSpeed = lfoSpeed; - - if (!track->lfoSpeed) - ClearModM(track); - } - } - - i--; - track++; - bit <<= 1; - } - - mplayInfo->ident = ID_NUMBER; -} - -#define MEMACC_COND_JUMP(cond) \ -if (cond) \ - goto cond_true; \ -else \ - goto cond_false; \ - -void ply_memacc(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - u32 op; - u8 *addr; - u8 data; - - op = *track->cmdPtr; - track->cmdPtr++; - - addr = mplayInfo->memAccArea + *track->cmdPtr; - track->cmdPtr++; - - data = *track->cmdPtr; - track->cmdPtr++; - - switch (op) - { - case 0: - *addr = data; - return; - case 1: - *addr += data; - return; - case 2: - *addr -= data; - return; - case 3: - *addr = mplayInfo->memAccArea[data]; - return; - case 4: - *addr += mplayInfo->memAccArea[data]; - return; - case 5: - *addr -= mplayInfo->memAccArea[data]; - return; - case 6: - MEMACC_COND_JUMP(*addr == data) - return; - case 7: - MEMACC_COND_JUMP(*addr != data) - return; - case 8: - MEMACC_COND_JUMP(*addr > data) - return; - case 9: - MEMACC_COND_JUMP(*addr >= data) - return; - case 10: - MEMACC_COND_JUMP(*addr <= data) - return; - case 11: - MEMACC_COND_JUMP(*addr < data) - return; - case 12: - MEMACC_COND_JUMP(*addr == mplayInfo->memAccArea[data]) - return; - case 13: - MEMACC_COND_JUMP(*addr != mplayInfo->memAccArea[data]) - return; - case 14: - MEMACC_COND_JUMP(*addr > mplayInfo->memAccArea[data]) - return; - case 15: - MEMACC_COND_JUMP(*addr >= mplayInfo->memAccArea[data]) - return; - case 16: - MEMACC_COND_JUMP(*addr <= mplayInfo->memAccArea[data]) - return; - case 17: - MEMACC_COND_JUMP(*addr < mplayInfo->memAccArea[data]) - return; - default: - return; - } - -cond_true: - { - void (*func)(struct MusicPlayerInfo *, struct MusicPlayerTrack *) = *(&gMPlayJumpTable[1]); - func(mplayInfo, track); - return; - } - -cond_false: - track->cmdPtr += 4; -} - -void ply_xcmd(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - u32 n = *track->cmdPtr; - track->cmdPtr++; - - gXcmdTable[n](mplayInfo, track); -} - -void ply_xxx(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - void (*func)(struct MusicPlayerInfo *, struct MusicPlayerTrack *) = *(&gMPlayJumpTable[0]); - func(mplayInfo, track); -} - -#define READ_XCMD_BYTE(var, n) \ -{ \ - u32 byte = track->cmdPtr[(n)]; \ - byte <<= n * 8; \ - (var) &= ~(0xFF << (n * 8)); \ - (var) |= byte; \ -} - -void ply_xwave(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - u32 wav; - - READ_XCMD_BYTE(wav, 0) // UB: uninitialized variable - READ_XCMD_BYTE(wav, 1) - READ_XCMD_BYTE(wav, 2) - READ_XCMD_BYTE(wav, 3) - - track->tone.wav = (struct WaveData *)wav; - track->cmdPtr += 4; -} - -void ply_xtype(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->tone.type = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xatta(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->tone.attack = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xdeca(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->tone.decay = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xsust(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->tone.sustain = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xrele(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->tone.release = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xiecv(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->echoVolume = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xiecl(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->echoLength = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xleng(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->tone.length = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xswee(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - track->tone.pan_sweep = *track->cmdPtr; - track->cmdPtr++; -} - -void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - u32 unk; - - READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable - READ_XCMD_BYTE(unk, 1) - - if (track->unk_3A < (u16)unk) - { - track->unk_3A++; - track->cmdPtr -= 2; - track->wait = 1; - } - else - { - track->unk_3A = 0; - track->cmdPtr += 2; - } -} - -void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) -{ - u32 unk; - - READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable - READ_XCMD_BYTE(unk, 1) - READ_XCMD_BYTE(unk, 2) - READ_XCMD_BYTE(unk, 3) - - track->unk_3C = unk; - track->cmdPtr += 4; -} - -void DummyFunc(void) -{ -} - -struct MusicPlayerInfo *SetPokemonCryTone(struct ToneData *tone) -{ - u32 maxClock = 0; - s32 maxClockIndex = 0; - s32 i; - struct MusicPlayerInfo *mplayInfo; - - for (i = 0; i < MAX_POKEMON_CRIES; i++) - { - struct MusicPlayerTrack *track = &gPokemonCryTracks[i * 2]; - - if (!track->flags && (!track->chan || track->chan->track != track)) - goto start_song; - - if (maxClock < gPokemonCryMusicPlayers[i].clock) - { - maxClock = gPokemonCryMusicPlayers[i].clock; - maxClockIndex = i; - } - } - - i = maxClockIndex; - -start_song: - mplayInfo = &gPokemonCryMusicPlayers[i]; - mplayInfo->ident++; - -#define CRY ((s32)&gPokemonCrySongs + i * sizeof(struct PokemonCrySong)) -#define CRY_OFS(field) offsetof(struct PokemonCrySong, field) - - memcpy((void *)CRY, &gPokemonCrySong, sizeof(struct PokemonCrySong)); - - *(u32 *)(CRY + CRY_OFS(tone)) = (u32)tone; - *(u32 *)(CRY + CRY_OFS(part)) = CRY + CRY_OFS(part0); - *(u32 *)(CRY + CRY_OFS(part) + 4) = CRY + CRY_OFS(part1); - *(u32 *)(CRY + CRY_OFS(gotoTarget)) = CRY + CRY_OFS(cont); - -#undef CRY_OFS -#undef CRY - - mplayInfo->ident = ID_NUMBER; - - MPlayStart(mplayInfo, (struct SongHeader *)(&gPokemonCrySongs[i])); - - return mplayInfo; -} - -void SetPokemonCryVolume(u8 val) -{ - gPokemonCrySong.volumeValue = val & 0x7F; -} - -void SetPokemonCryPanpot(s8 val) -{ - gPokemonCrySong.panValue = (val + C_V) & 0x7F; -} - -void SetPokemonCryPitch(s16 val) -{ - s16 b = val + 0x80; - u8 a = gPokemonCrySong.tuneValue2 - gPokemonCrySong.tuneValue; - gPokemonCrySong.tieKeyValue = (b >> 8) & 0x7F; - gPokemonCrySong.tuneValue = (b >> 1) & 0x7F; - gPokemonCrySong.tuneValue2 = (a + ((b >> 1) & 0x7F)) & 0x7F; -} - -void SetPokemonCryLength(u16 val) -{ - gPokemonCrySong.unkCmd0CParam = val; -} - -void SetPokemonCryRelease(u8 val) -{ - gPokemonCrySong.releaseValue = val; -} - -void SetPokemonCryProgress(u32 val) -{ - gPokemonCrySong.unkCmd0DParam = val; -} - -int IsPokemonCryPlaying(struct MusicPlayerInfo *mplayInfo) -{ - struct MusicPlayerTrack *track = mplayInfo->tracks; - - if (track->chan && track->chan->track == track) - return 1; - else - return 0; -} - -void SetPokemonCryChorus(s8 val) -{ - if (val) - { - gPokemonCrySong.trackCount = 2; - gPokemonCrySong.tuneValue2 = (val + gPokemonCrySong.tuneValue) & 0x7F; - } - else - { - gPokemonCrySong.trackCount = 1; - } -} - -void SetPokemonCryStereo(u32 val) -{ - struct SoundInfo *soundInfo = SOUND_INFO_PTR; - - if (val) - { - REG_SOUNDCNT_H = SOUND_B_TIMER_0 | SOUND_B_LEFT_OUTPUT - | SOUND_A_TIMER_0 | SOUND_A_RIGHT_OUTPUT - | SOUND_ALL_MIX_FULL; - soundInfo->mode &= ~1; - } - else - { - REG_SOUNDCNT_H = SOUND_B_TIMER_0 | SOUND_B_LEFT_OUTPUT | SOUND_B_RIGHT_OUTPUT - | SOUND_A_TIMER_0 | SOUND_A_LEFT_OUTPUT | SOUND_A_RIGHT_OUTPUT - | SOUND_B_MIX_HALF | SOUND_A_MIX_HALF | SOUND_CGB_MIX_FULL; - soundInfo->mode |= 1; - } -} - -void SetPokemonCryPriority(u8 val) -{ - gPokemonCrySong.priority = val; -} diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index 930f1f35b..fd8e74c0a 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -572,9 +572,6 @@ static void Task_BardSong(u8 taskId) struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; u8 *str = gStringVar4 + task->tCharIndex; u16 wordLen = 0; - // Can't get it to match without hacking - u32 temp; - register s16 zero asm("r1"); while (*str != CHAR_SPACE && *str != CHAR_NEWLINE @@ -588,17 +585,22 @@ static void Task_BardSong(u8 taskId) sUnknownBardRelated = MACRO2(bard->songLyrics[task->tCurrWord]); else sUnknownBardRelated = MACRO2(bard->temporaryLyrics[task->tCurrWord]); - temp = gBardSong.length / wordLen; - zero = 0; - gBardSong.length = temp; + + gBardSong.length /= wordLen; if (gBardSong.length <= 0) gBardSong.length = 1; task->tCurrWord++; + if (task->data[2] == 0) + { task->tState = 3; + task->data[1] = 0; + } else + { task->tState = 5; - task->data[1] = zero; + task->data[1] = 0; + } } break; case 5: @@ -1180,9 +1182,9 @@ static void Task_StoryListMenu(u8 taskId) // Task_StoryListMenu break; case 1: selection = Menu_ProcessInput(); - if (selection == -2) + if (selection == MENU_NOTHING_CHOSEN) break; - if (selection == -1 || selection == GetFreeStorySlot()) + if (selection == MENU_B_PRESSED || selection == GetFreeStorySlot()) { gSpecialVar_Result = 0; } diff --git a/src/palette.c b/src/palette.c index deb07b066..be5143876 100644 --- a/src/palette.c +++ b/src/palette.c @@ -154,7 +154,7 @@ void ReadPlttIntoBuffers(void) bool8 BeginNormalPaletteFade(u32 selectedPalettes, s8 delay, u8 startY, u8 targetY, u16 blendColor) { u8 temp; - register u32 _blendColor asm("r8") = blendColor; + u16 color = blendColor; if (gPaletteFade.active) { @@ -175,7 +175,7 @@ bool8 BeginNormalPaletteFade(u32 selectedPalettes, s8 delay, u8 startY, u8 targe gPaletteFade_delay = delay; gPaletteFade.y = startY; gPaletteFade.targetY = targetY; - gPaletteFade.blendColor = _blendColor; + gPaletteFade.blendColor = color; gPaletteFade.active = 1; gPaletteFade.mode = NORMAL_FADE; @@ -881,7 +881,7 @@ void TintPalette_SepiaTone(u16 *palette, u16 count) { s32 r, g, b, i; u32 gray; - + for (i = 0; i < count; i++) { r = (*palette >> 0) & 0x1F; diff --git a/src/party_menu.c b/src/party_menu.c index 58f0e097b..155bcc4a1 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -119,6 +119,7 @@ struct Struct203CEDC u8 unkC; }; +// EWRAM vars static EWRAM_DATA struct Struct203CEC4 *gUnknown_0203CEC4 = NULL; EWRAM_DATA struct Struct203CEC8 gUnknown_0203CEC8 = {0}; static EWRAM_DATA struct Struct203CEDC *gUnknown_0203CEDC = NULL; @@ -134,7 +135,8 @@ static EWRAM_DATA u16 gUnknown_0203CEFC = 0; static EWRAM_DATA u16 gUnknown_0203CEFE = 0; // unused EWRAM_DATA u8 gUnknown_0203CF00[3] = {0}; -extern void (*gUnknown_03006328)(u8, TaskFunc); +// IWRAM common +void (*gUnknown_03006328)(u8, TaskFunc); static void reset_brm(void); static void PartyMenuInitCallback(void); @@ -2087,7 +2089,8 @@ static bool8 RenderPartyMenuBoxes(void) RenderPartyMenuBox(gUnknown_0203CEC4->data[0]); if (++gUnknown_0203CEC4->data[0] == 6) return TRUE; - return FALSE; + else + return FALSE; } static u8* GetPartyMiscGraphicsTile(u16 tileId) @@ -2130,7 +2133,8 @@ static bool8 party_menu_add_per_mon_objects(void) party_menu_add_per_mon_objects_internal(gUnknown_0203CEC4->data[0]); if (++gUnknown_0203CEC4->data[0] == 6) return TRUE; - return FALSE; + else + return FALSE; } static void sub_81B0F28(void) @@ -2202,6 +2206,7 @@ void sub_81B0FCC(u8 slot, u8 b) static u8 GetPartyBoxPalBitfield(u8 slot, u8 b) { u8 returnVar = 0; + if (b == 1) returnVar |= 1; if (GetMonData(&gPlayerParty[slot], MON_DATA_HP) == 0) @@ -2321,7 +2326,8 @@ static s8* sub_81B13EC(void) { if (gUnknown_0203CEC8.unkB == 8 || gUnknown_0203CEC8.unkB == 10) return &gUnknown_0203CEC8.unkA; - return &gUnknown_0203CEC8.unk9; + else + return &gUnknown_0203CEC8.unk9; } static void sub_81B140C(u8 taskId, s8 *ptr) @@ -2836,7 +2842,7 @@ static void sub_81B1DB8(struct Pokemon *mon, u16 item) SetMonData(mon, MON_DATA_HELD_ITEM, itemBytes); } -static u8 sub_81B1E00(struct Pokemon* mon) +static u8 TryTakeMonItem(struct Pokemon* mon) { u16 item = GetMonData(mon, MON_DATA_HELD_ITEM); @@ -4265,7 +4271,7 @@ static void CursorCb_TakeItem(u8 taskId) PlaySE(SE_SELECT); sub_81B302C(&gUnknown_0203CEC4->unkC[0]); sub_81B302C(&gUnknown_0203CEC4->unkC[1]); - switch (sub_81B1E00(mon)) + switch (TryTakeMonItem(mon)) { case 0: GetMonNickname(mon, gStringVar1); @@ -5203,7 +5209,7 @@ void sub_81B617C(void) bool8 inBattle; u8 i; u8 msgIdMaybe; - register TaskFunc task asm("r0"); + TaskFunc task; if (gMain.inBattle) { @@ -5215,6 +5221,7 @@ void sub_81B617C(void) inBattle = FALSE; doubleBattleStatus = 0; } + if (GetItemEffectType(gSpecialVar_ItemId) == 10) { gUnknown_0203CEC8.unk9 = 0; @@ -5231,9 +5238,14 @@ void sub_81B617C(void) } else { - msgIdMaybe = (GetPocketByItemId(gSpecialVar_ItemId) == POCKET_TM_HM) ? 4 : 5; + if (GetPocketByItemId(gSpecialVar_ItemId) == POCKET_TM_HM) + msgIdMaybe = 4; + else + msgIdMaybe = 5; + task = sub_81B1370; } + InitPartyMenu(inBattle, doubleBattleStatus, 3, 1, msgIdMaybe, task, callback); } @@ -5263,9 +5275,11 @@ static bool8 IsHPRecoveryItem(u16 item) effect = gSaveBlock1Ptr->enigmaBerry.itemEffect; else effect = gItemEffectTable[item - ITEM_POTION]; + if ((effect[4] & 4) != 0) return TRUE; - return FALSE; + else + return FALSE; } static void GetMedicineItemEffectMessage(u16 item) @@ -5575,6 +5589,7 @@ void dp05_ether(u8 taskId, TaskFunc task) effect = gSaveBlock1Ptr->enigmaBerry.itemEffect; else effect = gItemEffectTable[item - ITEM_POTION]; + if ((effect[4] & 0x10) == 0) { gUnknown_0203CEC8.unkE = 0; @@ -6196,151 +6211,69 @@ void sub_81B7C74(u8 taskId, TaskFunc task) u8 GetItemEffectType(u16 item) { const u8 *itemEffect; -#ifndef NONMATCHING - register u8 itemEffect0 asm("r1"); - register u8 itemEffect3 asm("r3"); - register u32 itemEffect0_r0 asm("r0"); // u32 to prevent shifting when transferring itemEffect0 to this - u8 mask; -#else -#define itemEffect0 itemEffect[0] -#define itemEffect3 itemEffect[3] -#define mask 0x3F -#endif + u32 statusCure; if (!IS_POKEMON_ITEM(item)) - { return 22; - } + + // Read the item's effect properties. + if (item == ITEM_ENIGMA_BERRY) + itemEffect = gSaveBlock1Ptr->enigmaBerry.itemEffect; else + itemEffect = gItemEffectTable[item - ITEM_POTION]; + + if ((itemEffect[0] & 0x3F) || itemEffect[1] || itemEffect[2] || (itemEffect[3] & 0x80)) + return 0; + else if (itemEffect[0] & 0x40) + return 10; + else if (itemEffect[3] & 0x40) + return 1; + + statusCure = itemEffect[3] & 0x3F; + if (statusCure || (itemEffect[0] >> 7)) { - // Read the item's effect properties. - if (item == ITEM_ENIGMA_BERRY) - { - itemEffect = gSaveBlock1Ptr->enigmaBerry.itemEffect; - } + if (statusCure == 0x20) + return 4; + else if (statusCure == 0x10) + return 3; + else if (statusCure == 0x8) + return 5; + else if (statusCure == 0x4) + return 6; + else if (statusCure == 0x2) + return 7; + else if (statusCure == 0x1) + return 8; + else if (itemEffect[0] >> 7 && !statusCure) + return 9; else - { - itemEffect = gItemEffectTable[item - ITEM_POTION]; - } - -#ifndef NONMATCHING - itemEffect0 = itemEffect[0]; - mask = 0x3F; -#endif - - if ((itemEffect0 & mask) || itemEffect[1] || itemEffect[2]) - { - return 0; - } -#ifndef NONMATCHING - itemEffect3 = itemEffect[3]; -#endif - if (itemEffect3 & 0x80) - { - return 0; - } - else if (itemEffect0 & 0x40) - { - return 10; - } - else if (itemEffect3 & 0x40) - { - return 1; - } - else if ((itemEffect3 & mask) || (itemEffect0 >> 7)) - { - if ((itemEffect3 & mask) == 0x20) - { - return 4; - } - else if ((itemEffect3 & mask) == 0x10) - { - return 3; - } - else if ((itemEffect3 & mask) == 0x8) - { - return 5; - } - else if ((itemEffect3 & mask) == 0x4) - { - return 6; - } - else if ((itemEffect3 & mask) == 0x2) - { - return 7; - } - else if ((itemEffect3 & mask) == 0x1) - { - return 8; - } - // alternate fakematching - // itemEffect0_r0 = itemEffect0 >> 7; - // asm(""); // increase live length for greg - // if ((itemEffect0_r0 != 0) && (itemEffect3 & mask) == 0) -#ifndef NONMATCHING - else if (((itemEffect0_r0 = itemEffect0 >> 7) != 0) && (itemEffect3 & mask) == 0) -#else - else if (((itemEffect[0] >> 7) != 0) && (itemEffect[3] & 0x3F) == 0) -#endif - { - return 9; - } - else - { - return 11; - } - } - else if (itemEffect[4] & 0x44) - { - return 2; - } - else if (itemEffect[4] & 0x2) - { - return 12; - } - else if (itemEffect[4] & 0x1) - { - return 13; - } - else if (itemEffect[5] & 0x8) - { - return 14; - } - else if (itemEffect[5] & 0x4) - { - return 15; - } - else if (itemEffect[5] & 0x2) - { - return 16; - } - else if (itemEffect[5] & 0x1) - { - return 17; - } - else if (itemEffect[4] & 0x80) - { - return 18; - } - else if (itemEffect[4] & 0x20) - { - return 19; - } - else if (itemEffect[5] & 0x10) - { - return 20; - } - else if (itemEffect[4] & 0x18) - { - return 21; - } - return 22; + return 11; } -#ifdef NONMATCHING -#undef itemEffect0 -#undef itemEffect3 -#undef mask -#endif + + if (itemEffect[4] & 0x44) + return 2; + else if (itemEffect[4] & 0x2) + return 12; + else if (itemEffect[4] & 0x1) + return 13; + else if (itemEffect[5] & 0x8) + return 14; + else if (itemEffect[5] & 0x4) + return 15; + else if (itemEffect[5] & 0x2) + return 16; + else if (itemEffect[5] & 0x1) + return 17; + else if (itemEffect[4] & 0x80) + return 18; + else if (itemEffect[4] & 0x20) + return 19; + else if (itemEffect[5] & 0x10) + return 20; + else if (itemEffect[4] & 0x18) + return 21; + else + return 22; } static void sub_81B7E4C(u8 taskId) diff --git a/src/player_pc.c b/src/player_pc.c index 474cecaf5..0d08a5e7b 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -355,11 +355,11 @@ static void PlayerPCProcessMenuInput(u8 taskId) else inputOptionId = Menu_ProcessInputNoWrap(); - switch(inputOptionId) + switch (inputOptionId) { - case -2: + case MENU_NOTHING_CHOSEN: break; - case -1: + case MENU_B_PRESSED: PlaySE(SE_SELECT); sub_8198070(data[4], FALSE); ClearWindowTilemap(data[4]); @@ -464,13 +464,13 @@ static void ItemStorageMenuProcessInput(u8 taskId) r5 = Menu_GetCursorPos(); inputOptionId = Menu_ProcessInput(); r2 = Menu_GetCursorPos(); - switch(inputOptionId) + switch (inputOptionId) { - case -2: + case MENU_NOTHING_CHOSEN: if (r5 != r2) ItemStorageMenuPrint(gPCText_OptionDescList[r2]); break; - case -1: + case MENU_B_PRESSED: PlaySE(SE_SELECT); ItemStorage_Exit(taskId); break; @@ -638,14 +638,14 @@ static void Mailbox_ProcessInput(u8 taskId) if (!gPaletteFade.active) { - inputOptionId = ListMenuHandleInputGetItemId(data[5]); + inputOptionId = ListMenu_ProcessInput(data[5]); ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - switch(inputOptionId) + switch (inputOptionId) { - case -1: + case LIST_NOTHING_CHOSEN: break; - case -2: + case LIST_B_PRESSED: PlaySE(SE_SELECT); RemoveScrollIndicatorArrowPair(playerPCItemPageInfo.scrollIndicatorId); Mailbox_ReturnToPlayerPC(taskId); @@ -1145,13 +1145,13 @@ static void ItemStorage_ProcessInput(u8 taskId) } else { - id = ListMenuHandleInputGetItemId(data[5]); + id = ListMenu_ProcessInput(data[5]); ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); switch(id) { - case -1: + case LIST_NOTHING_CHOSEN: break; - case -2: + case LIST_B_PRESSED: PlaySE(SE_SELECT); ItemStorage_GoBackToPlayerPCMenu(taskId); break; @@ -1218,21 +1218,23 @@ static void sub_816C4FC(u8 taskId) ItemStorage_DoItemSwap(taskId, FALSE); return; } - id = ListMenuHandleInputGetItemId(data[5]); + id = ListMenu_ProcessInput(data[5]); ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); sub_81223FC(gUnknown_0203BCC4->spriteIds, 7, 0); sub_816C690(playerPCItemPageInfo.cursorPos); switch(id) { - case -1: + case LIST_NOTHING_CHOSEN: break; - case -2: + case LIST_B_PRESSED: if (gMain.newKeys & A_BUTTON) { ItemStorage_DoItemSwap(taskId, FALSE); } else + { ItemStorage_DoItemSwap(taskId, TRUE); + } break; default: ItemStorage_DoItemSwap(taskId, FALSE); diff --git a/src/pokeblock.c b/src/pokeblock.c index 7c07f9655..3fd4f34df 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -998,7 +998,7 @@ static void Task_HandlePokeblockMenuInput(u8 taskId) else { u16 oldPosition = sSavedPokeblockData.lastItemPos; - s32 itemId = ListMenuHandleInputGetItemId(data[0]); + s32 itemId = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); if (oldPosition != sSavedPokeblockData.lastItemPos) @@ -1044,7 +1044,7 @@ static void Task_HandlePokeblocksSwapInput(u8 taskId) { u16 i = sSavedPokeblockData.lastItemPage; u16 var = sSavedPokeblockData.lastItemPos; - s32 itemId = ListMenuHandleInputGetItemId(data[0]); + s32 itemId = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); if (i != sSavedPokeblockData.lastItemPage || var != sSavedPokeblockData.lastItemPos) diff --git a/src/pokedex.c b/src/pokedex.c index f99a8226a..c47ada5b8 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -30,8 +30,6 @@ #include "constants/songs.h" #include "constants/species.h" -extern u8 gDexCryScreenState; - // EWRAM static EWRAM_DATA struct PokedexView *sPokedexView = NULL; static EWRAM_DATA u16 gUnknown_02039B50 = 0; diff --git a/src/pokedex_cry_screen.c b/src/pokedex_cry_screen.c index 4a9227b99..c385141d5 100755 --- a/src/pokedex_cry_screen.c +++ b/src/pokedex_cry_screen.c @@ -39,7 +39,10 @@ static void sub_8145824(u8, s16, u8); static void sub_814596C(struct Sprite *); static void sub_8145B24(s8); -extern u8 gDexCryScreenState; +// IWRAM common +u8 gDexCryScreenState; + +// EWRAM vars static EWRAM_DATA struct PokedexCryScreen *sDexCryScreen = NULL; static EWRAM_DATA u8 *sCryWaveformWindowTiledata = NULL; static EWRAM_DATA struct PokedexCryVolumeMeter *sCryVolumeMeter = NULL; diff --git a/src/pokemon.c b/src/pokemon.c index 249febec5..59cf154c9 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -52,14 +52,14 @@ extern const struct SpriteFrameImage gUnknown_082FF3A8[]; extern const struct SpriteFrameImage gUnknown_082FF3C8[]; extern const struct SpriteFrameImage gUnknown_082FF3E8[]; extern const struct SpriteFrameImage gUnknown_082FF408[]; -extern const struct SpriteFrameImage gUnknown_082FF428[]; -extern const struct SpriteFrameImage gUnknown_082FF448[]; -extern const struct SpriteFrameImage gUnknown_082FF468[]; -extern const struct SpriteFrameImage gUnknown_082FF490[]; -extern const struct SpriteFrameImage gUnknown_082FF4B8[]; -extern const struct SpriteFrameImage gUnknown_082FF4D8[]; -extern const struct SpriteFrameImage gUnknown_082FF4F8[]; -extern const struct SpriteFrameImage gUnknown_082FF518[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_Brendan[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_May[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_Red[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_Leaf[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_RubySapphireBrendan[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_RubySapphireMay[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_Wally[]; +extern const struct SpriteFrameImage gTrainerBackPicTable_Steven[]; extern const union AffineAnimCmd *const gUnknown_082FF618[]; extern const union AffineAnimCmd *const gUnknown_082FF694[]; extern const union AnimCmd *gPlayerMonSpriteAnimsTable[]; @@ -2307,14 +2307,14 @@ const struct SpriteTemplate gUnknown_08329D98[MAX_BATTLERS_COUNT] = }, }; -static const struct SpriteTemplate gUnknown_08329DF8[] = +static const struct SpriteTemplate gSpriteTemplateTable_TrainerBackSprites[] = { { .tileTag = 0xFFFF, .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF428, + .images = gTrainerBackPicTable_Brendan, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -2323,7 +2323,7 @@ static const struct SpriteTemplate gUnknown_08329DF8[] = .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF448, + .images = gTrainerBackPicTable_May, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -2332,7 +2332,7 @@ static const struct SpriteTemplate gUnknown_08329DF8[] = .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF468, + .images = gTrainerBackPicTable_Red, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -2341,7 +2341,7 @@ static const struct SpriteTemplate gUnknown_08329DF8[] = .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF490, + .images = gTrainerBackPicTable_Leaf, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -2350,7 +2350,7 @@ static const struct SpriteTemplate gUnknown_08329DF8[] = .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF4B8, + .images = gTrainerBackPicTable_RubySapphireBrendan, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -2359,7 +2359,7 @@ static const struct SpriteTemplate gUnknown_08329DF8[] = .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF4D8, + .images = gTrainerBackPicTable_RubySapphireMay, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -2368,7 +2368,7 @@ static const struct SpriteTemplate gUnknown_08329DF8[] = .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF4F8, + .images = gTrainerBackPicTable_Wally, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -2377,7 +2377,7 @@ static const struct SpriteTemplate gUnknown_08329DF8[] = .paletteTag = 0, .oam = &gOamData_831ACB0, .anims = NULL, - .images = gUnknown_082FF518, + .images = gTrainerBackPicTable_Steven, .affineAnims = gUnknown_082FF618, .callback = sub_8039BB4, }, @@ -3532,7 +3532,7 @@ void SetMultiuseSpriteTemplateToTrainerBack(u16 trainerSpriteId, u8 battlerPosit gMultiuseSpriteTemplate.paletteTag = trainerSpriteId; if (battlerPosition == B_POSITION_PLAYER_LEFT || battlerPosition == B_POSITION_PLAYER_RIGHT) { - gMultiuseSpriteTemplate = gUnknown_08329DF8[trainerSpriteId]; + gMultiuseSpriteTemplate = gSpriteTemplateTable_TrainerBackSprites[trainerSpriteId]; gMultiuseSpriteTemplate.anims = gTrainerBackAnimsPtrTable[trainerSpriteId]; } else diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index bcbb60e21..ecb8f4950 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -1238,7 +1238,6 @@ const u16* GetValidMonIconPalettePtr(u16 species) return gMonIconPaletteTable[gMonIconPaletteIndices[species]].data; } -// TODO: try to find a way to avoid using asm statement u8 UpdateMonIconFrame(struct Sprite *sprite) { u8 result = 0; @@ -1262,10 +1261,7 @@ u8 UpdateMonIconFrame(struct Sprite *sprite) (u8 *)sprite->images + (sSpriteImageSizes[sprite->oam.shape][sprite->oam.size] * frame), (u8 *)(OBJ_VRAM0 + sprite->oam.tileNum * TILE_SIZE_4BPP), sSpriteImageSizes[sprite->oam.shape][sprite->oam.size]); - { - register u8 duration asm("r0") = sprite->anims[sprite->animNum][sprite->animCmdIndex].frame.duration; - sprite->animDelayCounter = duration; - } + sprite->animDelayCounter = sprite->anims[sprite->animNum][sprite->animCmdIndex].frame.duration & 0xFF; sprite->animCmdIndex++; result = sprite->animCmdIndex; break; diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 78fec2fc5..c0aec4ddd 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -1753,7 +1753,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) task->data[2] = Menu_ProcessInput(); switch(task->data[2]) { - case -2: + case MENU_NOTHING_CHOSEN: task->data[3] = task->data[1]; if (gMain.newKeys & DPAD_UP && --task->data[3] < 0) task->data[3] = 4; @@ -1767,7 +1767,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); } break; - case -1: + case MENU_B_PRESSED: case 4: sub_819746C(task->data[15], TRUE); ScriptContext2_Disable(); diff --git a/src/rom_8011DC0.c b/src/rom_8011DC0.c index 41f7eeee7..9bdd86167 100644 --- a/src/rom_8011DC0.c +++ b/src/rom_8011DC0.c @@ -189,8 +189,6 @@ extern u16 gUnknown_02022C3C; extern u8 gUnknown_02022C20[]; extern u8 gFieldLinkPlayerCount; extern u8 gUnknown_03005DB4; -extern struct MailStruct gUnknown_020321C0[PARTY_SIZE]; -extern u8 gUnknown_02032298[2]; // IWRAM vars IWRAM_DATA struct UnkStruct_Leader *gUnknown_03000DA0; @@ -1105,7 +1103,7 @@ void sub_80134E8(u8 taskId) RedrawListMenu(data->listTaskId); break; case 0: - id = ListMenuHandleInputGetItemId(data->listTaskId); + id = ListMenu_ProcessInput(data->listTaskId); if (gMain.newKeys & A_BUTTON && id != -1) { // this unused variable along with the assignment is needed to match @@ -2176,7 +2174,7 @@ void sub_8014F48(u8 taskId) RedrawListMenu(data->listTaskId); break; case 0: - id = ListMenuHandleInputGetItemId(data->listTaskId); + id = ListMenu_ProcessInput(data->listTaskId); if (gMain.newKeys & A_BUTTON && id != -1) { // this unused variable along with the assignment is needed to match @@ -2340,7 +2338,7 @@ void sub_80152F4(u8 taskId) break; case 0: if (data->field_13 != 0) - id = ListMenuHandleInputGetItemId(data->listTaskId); + id = ListMenu_ProcessInput(data->listTaskId); if (data->field_14 > 120) { if (data->field_0->arr[0].field_1A_0 == 1 && !data->field_0->arr[0].unk.field_0.unk_0a_7) diff --git a/src/script_menu.c b/src/script_menu.c index a4f4c6086..7180bfc60 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -1170,9 +1170,9 @@ static void Task_HandleMultichoiceInput(u8 taskId) sub_80E2A94(tMultichoiceId); } - if (selection != -2) + if (selection != MENU_NOTHING_CHOSEN) { - if (selection == -1) + if (selection == MENU_B_PRESSED) { if (tIgnoreBPress) return; diff --git a/src/secret_base.c b/src/secret_base.c index de5fae077..adcab9cbc 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -953,13 +953,13 @@ void sub_80E9E90(u8 taskId) s32 input; data = gTasks[taskId].data; - input = ListMenuHandleInputGetItemId(data[5]); + input = ListMenu_ProcessInput(data[5]); ListMenuGetScrollAndRow(data[5], &data[2], &data[1]); switch (input) { - case -1: + case LIST_NOTHING_CHOSEN: break; - case -2: + case LIST_B_PRESSED: PlaySE(SE_SELECT); DestroyListMenuTask(data[5], NULL, NULL); RemoveScrollIndicatorArrowPair(data[8]); @@ -1002,11 +1002,11 @@ void sub_80E9FB0(u8 taskId) input = Menu_ProcessInputNoWrap(); switch (input) { - case -1: + case MENU_B_PRESSED: PlaySE(SE_SELECT); sub_80EA18C(taskId); break; - case -2: + case MENU_NOTHING_CHOSEN: break; default: PlaySE(SE_SELECT); diff --git a/src/shop.c b/src/shop.c index c44cbca12..8eefd5e97 100755 --- a/src/shop.c +++ b/src/shop.c @@ -328,9 +328,9 @@ static void Task_ShopMenu(u8 taskId) s8 inputCode = Menu_ProcessInputNoWrap(); switch (inputCode) { - case LIST_B_PRESSED: + case MENU_NOTHING_CHOSEN: break; - case LIST_NOTHING_CHOSEN: + case MENU_B_PRESSED: PlaySE(SE_SELECT); Task_HandleShopMenuQuit(taskId); break; @@ -911,7 +911,7 @@ static void Task_BuyMenu(u8 taskId) if (!gPaletteFade.active) { - s32 itemId = ListMenuHandleInputGetItemId(tListTaskId); + s32 itemId = ListMenu_ProcessInput(tListTaskId); ListMenuGetScrollAndRow(tListTaskId, &gShopDataPtr->scrollOffset, &gShopDataPtr->selectedRow); switch (itemId) diff --git a/src/siirtc.c b/src/siirtc.c index 965a068f1..f7e85ef4f 100644 --- a/src/siirtc.c +++ b/src/siirtc.c @@ -46,6 +46,19 @@ #define CMD_TIME CMD(3) #define CMD_ALARM CMD(4) +#define SCK_HI 1 +#define SIO_HI 2 +#define CS_HI 4 + +#define DIR_0_IN 0 +#define DIR_0_OUT 1 +#define DIR_1_IN 0 +#define DIR_1_OUT 2 +#define DIR_2_IN 0 +#define DIR_2_OUT 4 +#define DIR_ALL_IN (DIR_0_IN | DIR_1_IN | DIR_2_IN) +#define DIR_ALL_OUT (DIR_0_OUT | DIR_1_OUT | DIR_2_OUT) + #define GPIO_PORT_DATA (*(vu16 *)0x80000C4) #define GPIO_PORT_DIRECTION (*(vu16 *)0x80000C6) #define GPIO_PORT_READ_ENABLE (*(vu16 *)0x80000C8) @@ -126,15 +139,15 @@ bool8 SiiRtcReset() sLocked = TRUE; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - GPIO_PORT_DIRECTION = 7; + GPIO_PORT_DIRECTION = DIR_ALL_OUT; WriteCommand(CMD_RESET | WR); - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -154,14 +167,14 @@ bool8 SiiRtcGetStatus(struct SiiRtcInfo *rtc) sLocked = TRUE; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - GPIO_PORT_DIRECTION = 7; + GPIO_PORT_DIRECTION = DIR_ALL_OUT; WriteCommand(CMD_STATUS | RD); - GPIO_PORT_DIRECTION = 5; + GPIO_PORT_DIRECTION = DIR_0_OUT | DIR_1_IN | DIR_2_OUT; statusData = ReadData(); @@ -170,8 +183,8 @@ bool8 SiiRtcGetStatus(struct SiiRtcInfo *rtc) | ((statusData & STATUS_INTME) >> 2) | ((statusData & STATUS_INTFE) >> 1); - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -187,22 +200,22 @@ bool8 SiiRtcSetStatus(struct SiiRtcInfo *rtc) sLocked = TRUE; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; statusData = STATUS_24HOUR | ((rtc->status & SIIRTCINFO_INTAE) << 3) | ((rtc->status & SIIRTCINFO_INTME) << 2) | ((rtc->status & SIIRTCINFO_INTFE) << 1); - GPIO_PORT_DIRECTION = 7; + GPIO_PORT_DIRECTION = DIR_ALL_OUT; WriteCommand(CMD_STATUS | WR); WriteData(statusData); - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -218,22 +231,22 @@ bool8 SiiRtcGetDateTime(struct SiiRtcInfo *rtc) sLocked = TRUE; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - GPIO_PORT_DIRECTION = 7; + GPIO_PORT_DIRECTION = DIR_ALL_OUT; WriteCommand(CMD_DATETIME | RD); - GPIO_PORT_DIRECTION = 5; + GPIO_PORT_DIRECTION = DIR_0_OUT | DIR_1_IN | DIR_2_OUT; for (i = 0; i < DATETIME_BUF_LEN; i++) DATETIME_BUF(rtc, i) = ReadData(); INFO_BUF(rtc, OFFSET_HOUR) &= 0x7F; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -249,18 +262,18 @@ bool8 SiiRtcSetDateTime(struct SiiRtcInfo *rtc) sLocked = TRUE; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - GPIO_PORT_DIRECTION = 7; + GPIO_PORT_DIRECTION = DIR_ALL_OUT; WriteCommand(CMD_DATETIME | WR); for (i = 0; i < DATETIME_BUF_LEN; i++) WriteData(DATETIME_BUF(rtc, i)); - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -276,22 +289,22 @@ bool8 SiiRtcGetTime(struct SiiRtcInfo *rtc) sLocked = TRUE; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - GPIO_PORT_DIRECTION = 7; + GPIO_PORT_DIRECTION = DIR_ALL_OUT; WriteCommand(CMD_TIME | RD); - GPIO_PORT_DIRECTION = 5; + GPIO_PORT_DIRECTION = DIR_0_OUT | DIR_1_IN | DIR_2_OUT; for (i = 0; i < TIME_BUF_LEN; i++) TIME_BUF(rtc, i) = ReadData(); INFO_BUF(rtc, OFFSET_HOUR) &= 0x7F; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -307,18 +320,18 @@ bool8 SiiRtcSetTime(struct SiiRtcInfo *rtc) sLocked = TRUE; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - GPIO_PORT_DIRECTION = 7; + GPIO_PORT_DIRECTION = DIR_ALL_OUT; WriteCommand(CMD_TIME | WR); for (i = 0; i < TIME_BUF_LEN; i++) WriteData(TIME_BUF(rtc, i)); - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -347,18 +360,18 @@ bool8 SiiRtcSetAlarm(struct SiiRtcInfo *rtc) alarmData[1] = rtc->alarmMinute; - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - GPIOPortDirection = 7; // Why is this the only instance that uses a symbol? + GPIOPortDirection = DIR_ALL_OUT; // Why is this the only instance that uses a symbol? WriteCommand(CMD_ALARM | WR); for (i = 0; i < 2; i++) WriteData(alarmData[i]); - GPIO_PORT_DATA = 1; - GPIO_PORT_DATA = 1; + GPIO_PORT_DATA = SCK_HI; + GPIO_PORT_DATA = SCK_HI; sLocked = FALSE; @@ -373,10 +386,10 @@ static int WriteCommand(u8 value) for (i = 0; i < 8; i++) { temp = ((value >> (7 - i)) & 1); - GPIO_PORT_DATA = (temp << 1) | 4; - GPIO_PORT_DATA = (temp << 1) | 4; - GPIO_PORT_DATA = (temp << 1) | 4; - GPIO_PORT_DATA = (temp << 1) | 5; + GPIO_PORT_DATA = (temp << 1) | CS_HI; + GPIO_PORT_DATA = (temp << 1) | CS_HI; + GPIO_PORT_DATA = (temp << 1) | CS_HI; + GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI; } // control reaches end of non-void function @@ -390,10 +403,10 @@ static int WriteData(u8 value) for (i = 0; i < 8; i++) { temp = ((value >> i) & 1); - GPIO_PORT_DATA = (temp << 1) | 4; - GPIO_PORT_DATA = (temp << 1) | 4; - GPIO_PORT_DATA = (temp << 1) | 4; - GPIO_PORT_DATA = (temp << 1) | 5; + GPIO_PORT_DATA = (temp << 1) | CS_HI; + GPIO_PORT_DATA = (temp << 1) | CS_HI; + GPIO_PORT_DATA = (temp << 1) | CS_HI; + GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI; } // control reaches end of non-void function @@ -407,14 +420,14 @@ static u8 ReadData() for (i = 0; i < 8; i++) { - GPIO_PORT_DATA = 4; - GPIO_PORT_DATA = 4; - GPIO_PORT_DATA = 4; - GPIO_PORT_DATA = 4; - GPIO_PORT_DATA = 4; - GPIO_PORT_DATA = 5; + GPIO_PORT_DATA = CS_HI; + GPIO_PORT_DATA = CS_HI; + GPIO_PORT_DATA = CS_HI; + GPIO_PORT_DATA = CS_HI; + GPIO_PORT_DATA = CS_HI; + GPIO_PORT_DATA = SCK_HI | CS_HI; - temp = ((GPIO_PORT_DATA & 2) >> 1); + temp = ((GPIO_PORT_DATA & SIO_HI) >> 1); value = (value >> 1) | (temp << 7); // UB: accessing uninitialized var } diff --git a/src/trader.c b/src/trader.c index e23efb4ce..b5c159fb9 100644 --- a/src/trader.c +++ b/src/trader.c @@ -113,9 +113,9 @@ void Task_HandleGetDecorationMenuInput(u8 taskId) switch (input) { - case -2: + case MENU_NOTHING_CHOSEN: break; - case -1: + case MENU_B_PRESSED: case 4: PlaySE(SE_SELECT); sub_8133BE4(taskId, 0); diff --git a/src/trainer_card.c b/src/trainer_card.c index b7bd5cc1d..49a62284f 100755 --- a/src/trainer_card.c +++ b/src/trainer_card.c @@ -93,6 +93,7 @@ struct TrainerCardData extern u8 sub_80D30A0(u16); // EWRAM +EWRAM_DATA struct TrainerCard gTrainerCards[4] = {0}; EWRAM_DATA static struct TrainerCardData *sData = NULL; //this file's functions diff --git a/src/tv.c b/src/tv.c index 5b640836f..651bd3c8f 100644 --- a/src/tv.c +++ b/src/tv.c @@ -972,7 +972,7 @@ void GabbyAndTyBeforeInterview(void) TakeTVShowInSearchOfTrainersOffTheAir(); if (gSaveBlock1Ptr->gabbyAndTyData.lastMove == MOVE_NONE) { - FlagSet(0x0001); + FlagSet(FLAG_TEMP_1); } } @@ -2564,13 +2564,13 @@ void sub_80EEA70(void) show->secretBaseSecrets.kind = TVSHOW_SECRET_BASE_SECRETS; show->secretBaseSecrets.active = FALSE; StringCopy(show->secretBaseSecrets.playerName, gSaveBlock2Ptr->playerName); - show->secretBaseSecrets.stepsInBase = VarGet(0x40ec); + show->secretBaseSecrets.stepsInBase = VarGet(VAR_0x40EC); sub_80E980C(); StringCopy(strbuf, gStringVar1); StripExtCtrlCodes(strbuf); StringCopy(show->secretBaseSecrets.baseOwnersName, strbuf); - show->secretBaseSecrets.item = VarGet(0x40ed); - show->secretBaseSecrets.flags = VarGet(0x40ee) + (VarGet(0x40ef) << 16); + show->secretBaseSecrets.item = VarGet(VAR_0x40ED); + show->secretBaseSecrets.flags = VarGet(VAR_0x40EE) + (VarGet(VAR_0x40EF) << 16); tv_store_id_3x(show); show->secretBaseSecrets.language = gGameLanguage; if (show->secretBaseSecrets.language == LANGUAGE_JAPANESE || gSaveBlock1Ptr->secretBases[VarGet(VAR_CURRENT_SECRET_BASE)].language == LANGUAGE_JAPANESE) @@ -3604,7 +3604,7 @@ void sub_80F01B8(void) { VarSet(VAR_0x40BC, 0); RemoveEventObjectByLocalIdAndMap(5, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); - FlagSet(0x396); + FlagSet(FLAG_HIDE_BATTLE_TOWER_REPORTER); } void ReceiveTvShowsData(void *src, u32 size, u8 masterIdx) diff --git a/sym_common.txt b/sym_common.txt index 3a7d698fd..414d223e9 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -23,57 +23,14 @@ .include "contest.o" .include "tv.o" .include "mauville_old_man.o" - -gUnknown_03006164: @ 3006164 + .include "contest_painting_effects.o" + .space 0x4 - -gUnknown_03006168: @ 3006168 - .space 0x4 - -gUnknown_0300616C: @ 300616C - .space 0x4 - -gUnknown_03006170: @ 3006170 - .space 0x4 - -gUnknown_03006174: @ 3006174 - .space 0x4 - -gUnknown_03006178: @ 3006178 - .space 0x4 - -gUnknown_0300617C: @ 300617C - .space 0x4 - -gUnknown_03006180: @ 3006180 - .space 0x4 - -gUnknown_03006184: @ 3006184 - .space 0x4 - -gUnknown_03006188: @ 3006188 - .space 0x8 - -gUnknown_03006190: @ 3006190 - .space 0x10 - -gUnknown_030061A0: @ 30061A0 - .space 0x20 - -gUnknown_030061C0: @ 30061C0 - .space 0x4 - -gContestPaintingMonPalette: @ 30061C4 - .space 0xC - + + .include "contest_painting.o" .include "field_specials.o" - -gCB2_AfterEvolution: @ 30061E8 - .space 0x4 - -gDexCryScreenState: @ 30061EC - .space 0x4 - + .include "evolution_scene.o" + .include "pokedex_cry_screen.o" .include "save.o" .include "battle_tower.o" .include "intro.o" @@ -84,14 +41,14 @@ gDexCryScreenState: @ 30061EC .space 0x8 .include "list_menu.o" - -gUnknown_03006328: @ 3006328 - .space 0x48 + .include "party_menu.o" + + .space 0x44 gUnknown_03006370: @ 3006370 .space 0x10 - .include "m4a_2.o" + .include "m4a.o" .include "agb_flash.o" gRfuState: @ 3007868 diff --git a/sym_ewram.txt b/sym_ewram.txt index 9e836d0fe..361c0921f 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -140,19 +140,6 @@ gUnknown_02022D00: @ 2022D00 .include "src/scanline_effect.o" .include "src/option_menu.o" .include "src/pokedex.o" - -gTrainerCards: @ 2039B58 - .space 0x14 - -gUnknown_02039B6C: @ 2039B6C - .space 0x2 - -gUnknown_02039B6E: @ 2039B6E - .space 0x1A - -gUnknown_02039B88: @ 2039B88 - .space 0x160 - .include "src/trainer_card.o" .include "src/frontier_pass.o" .include "src/pokemon_storage_system.o" @@ -161,14 +148,6 @@ gUnknown_02039B88: @ 2039B88 .include "src/map_name_popup.o" .include "src/item.o" .include "src/contest.o" - - .align 2 -gUnknown_02039F5C: @ 2039F5C - .space 0x1 - -gUnknown_02039F5D: @ 2039F5D - .space 0x3 - .include "src/shop.o" .include "src/fldeff_escalator.o" .include "src/script_menu.o" @@ -177,21 +156,12 @@ gUnknown_02039F5D: @ 2039F5D .include "src/record_mixing.o" .include "src/secret_base.o" .include "src/tv.o" - -gUnknown_0203A034: @ 203A034 - .space 0x4 - + .include "src/contest_link_80F57C4.o" .include "src/rotating_gate.o" .include "src/safari_zone.o" - -gUnknown_0203A0F4: @ 203A0F4 - .space 0x4 - + .include "src/item_use.o" .include "src/battle_anim_effects_1.o" - -gUnknown_0203A100: @ 203A100 - .space 0x10 - + .include "src/dragon.o" .include "src/battle_anim_utility_funcs.o" .include "src/battle_intro.o" .include "src/easy_chat.o"