diff --git a/.gitignore b/.gitignore index 9f69537f7..8e5ae8b3f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ *.fwjpnfont *.bat sound/**/*.bin -src/*.s tools/agbcc *.map *.id0 diff --git a/Makefile b/Makefile index 51c25f931..2109838df 100755 --- a/Makefile +++ b/Makefile @@ -106,10 +106,12 @@ MID_BUILDDIR = $(BUILD_DIR)/$(MID_SUBDIR) C_SOURCES := $(wildcard src/*.c) ASM_SOURCES := $(wildcard asm/*.s data/*.s) +C_ASM_SOURCES := $(wildcard src/*.s) C_OBJECTS := $(addprefix $(BUILD_DIR)/, $(C_SOURCES:%.c=%.o)) ASM_OBJECTS := $(addprefix $(BUILD_DIR)/, $(ASM_SOURCES:%.s=%.o)) -ALL_OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS) +C_ASM_OBJECTS := $(addprefix $(BUILD_DIR)/, $(C_ASM_SOURCES:%.s=%.o)) +ALL_OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS) $(C_ASM_OBJECTS) SUBDIRS := $(sort $(dir $(ALL_OBJECTS))) @@ -233,6 +235,13 @@ $(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $(ASM_BUILDDIR)/%.d: $(ASM_SUBDIR)/%.s @$(call scaninc,$(INCLUDE_PATHS)) + +$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s + @$(CPP) -x assembler-with-cpp $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.s + $(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s + +$(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.s + @$(call scaninc,$(INCLUDE_PATHS)) libagbsyscall: @$(MAKE) -C libagbsyscall TOOLCHAIN=$(TOOLCHAIN) diff --git a/include/asm/constants/m4a_constants.inc b/include/asm/constants/m4a_constants.inc index 62ca5bb55..ab069ec7d 100644 --- a/include/asm/constants/m4a_constants.inc +++ b/include/asm/constants/m4a_constants.inc @@ -1,12 +1,46 @@ +#ifndef GUARD_CONSTANTS_M4A_CONSTANTS_INC +#define GUARD_CONSTANTS_M4A_CONSTANTS_INC + .equiv ID_NUMBER, 0x68736d53 .equiv PCM_DMA_BUF_SIZE, 1584 + .equiv MAX_DIRECTSOUND_CHANNELS, 12 + + .equiv C_V, 0x40 .equiv TONEDATA_TYPE_CGB, 0x07 .equiv TONEDATA_TYPE_FIX, 0x08 + .equiv TONEDATA_TYPE_REV, 0x10 + .equiv TONEDATA_TYPE_CMP, 0x20 .equiv TONEDATA_TYPE_SPL, 0x40 @ key split .equiv TONEDATA_TYPE_RHY, 0x80 @ rhythm + .equiv TONEDATA_P_S_PAN, 0xc0 + + .equiv SOUND_CHANNEL_SF_START, 0x80 + .equiv SOUND_CHANNEL_SF_STOP, 0x40 + .equiv SOUND_CHANNEL_SF_SPECIAL, 0x20 + .equiv SOUND_CHANNEL_SF_LOOP, 0x10 + .equiv SOUND_CHANNEL_SF_IEC, 0x04 + .equiv SOUND_CHANNEL_SF_ENV, 0x03 + .equiv SOUND_CHANNEL_SF_ENV_ATTACK, 0x03 + .equiv SOUND_CHANNEL_SF_ENV_DECAY, 0x02 + .equiv SOUND_CHANNEL_SF_ENV_SUSTAIN, 0x01 + .equiv SOUND_CHANNEL_SF_ENV_RELEASE, 0x00 + .equiv SOUND_CHANNEL_SF_ON, (SOUND_CHANNEL_SF_START | SOUND_CHANNEL_SF_STOP | SOUND_CHANNEL_SF_IEC | SOUND_CHANNEL_SF_ENV) + + .equiv CGB_CHANNEL_MO_PIT, 0x02 + .equiv CGB_CHANNEL_MO_VOL, 0x01 + + .equiv WAVE_DATA_FLAG_LOOP, 0xC0 + + .equiv MPT_FLG_VOLSET, 0x01 + .equiv MPT_FLG_VOLCHG, 0x03 + .equiv MPT_FLG_PITSET, 0x04 + .equiv MPT_FLG_PITCHG, 0x0C + .equiv MPT_FLG_START, 0x40 + .equiv MPT_FLG_EXIST, 0x80 + .macro struct_begin .struct 0 .endm @@ -16,6 +50,28 @@ .struct \name + \size .endm + struct_begin + struct_field o_WaveData_type, 2 + struct_field o_WaveData_d1, 1 + struct_field o_WaveData_flags, 1 + struct_field o_WaveData_freq, 4 + struct_field o_WaveData_loopStart, 4 + struct_field o_WaveData_size, 4 + struct_field o_WaveData_data, 0 + struct_field WaveData_size, 0 + + struct_begin + struct_field o_ToneData_type, 1 + struct_field o_ToneData_key, 1 + struct_field o_ToneData_length, 1 + struct_field o_ToneData_pan_sweep, 1 + struct_field o_ToneData_wav, 4 + struct_field o_ToneData_attack, 1 + struct_field o_ToneData_decay, 1 + struct_field o_ToneData_sustain, 1 + struct_field o_ToneData_release, 1 + struct_field ToneData_size, 0 + struct_begin struct_field o_SoundInfo_ident, 4 struct_field o_SoundInfo_pcmDmaCounter, 1 @@ -32,8 +88,8 @@ struct_field o_SoundInfo_pcmFreq, 4 struct_field o_SoundInfo_divFreq, 4 struct_field o_SoundInfo_cgbChans, 4 - struct_field o_SoundInfo_func, 4 - struct_field o_SoundInfo_intp, 4 + struct_field o_SoundInfo_MPlayMainHead, 4 + struct_field o_SoundInfo_musicPlayerHead, 4 struct_field o_SoundInfo_CgbSound, 4 struct_field o_SoundInfo_CgbOscOff, 4 struct_field o_SoundInfo_MidiKeyToCgbFreq, 4 @@ -41,12 +97,12 @@ struct_field o_SoundInfo_plynote, 4 struct_field o_SoundInfo_ExtVolPit, 4 struct_field o_SoundInfo_gap2, 16 - struct_field o_SoundInfo_chans, 768 + struct_field o_SoundInfo_chans, MAX_DIRECTSOUND_CHANNELS * 64 struct_field o_SoundInfo_pcmBuffer, PCM_DMA_BUF_SIZE * 2 struct_field SoundInfo_size, 0 struct_begin - struct_field o_SoundChannel_status, 1 + struct_field o_SoundChannel_statusFlags, 1 struct_field o_SoundChannel_type, 1 struct_field o_SoundChannel_rightVolume, 1 struct_field o_SoundChannel_leftVolume, 1 @@ -54,29 +110,29 @@ struct_field o_SoundChannel_decay, 1 struct_field o_SoundChannel_sustain, 1 struct_field o_SoundChannel_release, 1 - struct_field o_SoundChannel_ky, 1 - struct_field o_SoundChannel_ev, 1 - struct_field o_SoundChannel_er, 1 - struct_field o_SoundChannel_el, 1 - struct_field o_SoundChannel_iev, 1 - struct_field o_SoundChannel_iel, 1 - struct_field o_SoundChannel_d1, 1 - struct_field o_SoundChannel_d2, 1 - struct_field o_SoundChannel_gt, 1 - struct_field o_SoundChannel_mk, 1 - struct_field o_SoundChannel_ve, 1 - struct_field o_SoundChannel_pr, 1 - struct_field o_SoundChannel_rp, 1 - struct_field o_SoundChannel_d3, 3 - struct_field o_SoundChannel_ct, 4 + struct_field o_SoundChannel_key, 1 + struct_field o_SoundChannel_envelopeVolume, 1 + struct_field o_SoundChannel_envelopeVolumeRight, 1 + struct_field o_SoundChannel_envelopeVolumeLeft, 1 + struct_field o_SoundChannel_pseudoEchoVolume, 1 + struct_field o_SoundChannel_pseudoEchoLength, 1 + struct_field o_SoundChannel_dummy1, 1 + struct_field o_SoundChannel_dummy2, 1 + struct_field o_SoundChannel_gateTime, 1 + struct_field o_SoundChannel_midiKey, 1 + struct_field o_SoundChannel_velocity, 1 + struct_field o_SoundChannel_priority, 1 + struct_field o_SoundChannel_rhythmPan, 1 + struct_field o_SoundChannel_dummy3, 3 + struct_field o_SoundChannel_count, 4 struct_field o_SoundChannel_fw, 4 - struct_field o_SoundChannel_freq, 4 + struct_field o_SoundChannel_frequency, 4 struct_field o_SoundChannel_wav, 4 - struct_field o_SoundChannel_cp, 4 + struct_field o_SoundChannel_currentPointer, 4 struct_field o_SoundChannel_track, 4 - struct_field o_SoundChannel_pp, 4 - struct_field o_SoundChannel_np, 4 - struct_field o_SoundChannel_d4, 4 + struct_field o_SoundChannel_prevChannelPointer, 4 + struct_field o_SoundChannel_nextChannelPointer, 4 + struct_field o_SoundChannel_dummy4, 4 struct_field o_SoundChannel_xpi, 2 struct_field o_SoundChannel_xpc, 2 struct_field SoundChannel_size, 0 @@ -112,8 +168,8 @@ struct_field o_MusicPlayerTrack_lfoDelay, 1 struct_field o_MusicPlayerTrack_lfoDelayC, 1 struct_field o_MusicPlayerTrack_priority, 1 - struct_field o_MusicPlayerTrack_echoVolume, 1 - struct_field o_MusicPlayerTrack_echoLength, 1 + struct_field o_MusicPlayerTrack_pseudoEchoVolume, 1 + struct_field o_MusicPlayerTrack_pseudoEchoLength, 1 struct_field o_MusicPlayerTrack_chan, 4 struct_field o_MusicPlayerTrack_ToneData_type, 1 struct_field o_MusicPlayerTrack_ToneData_key, 1 @@ -159,41 +215,43 @@ struct_field MusicPlayerInfo_size, 0 struct_begin - struct_field o_CgbChannel_sf, 1 - struct_field o_CgbChannel_ty, 1 + struct_field o_CgbChannel_statusFlags, 1 + struct_field o_CgbChannel_type, 1 struct_field o_CgbChannel_rightVolume, 1 struct_field o_CgbChannel_leftVolume, 1 - struct_field o_CgbChannel_at, 1 - struct_field o_CgbChannel_de, 1 - struct_field o_CgbChannel_su, 1 - struct_field o_CgbChannel_re, 1 - struct_field o_CgbChannel_ky, 1 - struct_field o_CgbChannel_ev, 1 - struct_field o_CgbChannel_eg, 1 - struct_field o_CgbChannel_ec, 1 - struct_field o_CgbChannel_echoVolume, 1 - struct_field o_CgbChannel_echoLength, 1 - struct_field o_CgbChannel_d1, 1 - struct_field o_CgbChannel_d2, 1 - struct_field o_CgbChannel_gt, 1 - struct_field o_CgbChannel_mk, 1 - struct_field o_CgbChannel_ve, 1 - struct_field o_CgbChannel_pr, 1 - struct_field o_CgbChannel_rp, 1 - struct_field o_CgbChannel_d3, 3 - struct_field o_CgbChannel_d5, 1 - struct_field o_CgbChannel_sg, 1 + struct_field o_CgbChannel_attack, 1 + struct_field o_CgbChannel_decay, 1 + struct_field o_CgbChannel_sustain, 1 + struct_field o_CgbChannel_release, 1 + struct_field o_CgbChannel_key, 1 + struct_field o_CgbChannel_envelopeVolume, 1 + struct_field o_CgbChannel_envelopeGoal, 1 + struct_field o_CgbChannel_envelopeCounter, 1 + struct_field o_CgbChannel_pseudoEchoVolume, 1 + struct_field o_CgbChannel_pseudoEchoLength, 1 + struct_field o_CgbChannel_dummy1, 1 + struct_field o_CgbChannel_dummy2, 1 + struct_field o_CgbChannel_gateTime, 1 + struct_field o_CgbChannel_midiKey, 1 + struct_field o_CgbChannel_velocity, 1 + struct_field o_CgbChannel_priority, 1 + struct_field o_CgbChannel_rhythmPan, 1 + struct_field o_CgbChannel_dummy3, 3 + struct_field o_CgbChannel_dummy5, 1 + struct_field o_CgbChannel_sustainGoal, 1 struct_field o_CgbChannel_n4, 1 struct_field o_CgbChannel_pan, 1 struct_field o_CgbChannel_panMask, 1 - struct_field o_CgbChannel_mo, 1 - struct_field o_CgbChannel_le, 1 - struct_field o_CgbChannel_sw, 1 - struct_field o_CgbChannel_fr, 4 - struct_field o_CgbChannel_wp, 4 - struct_field o_CgbChannel_cp, 4 - struct_field o_CgbChannel_tp, 4 - struct_field o_CgbChannel_pp, 4 - struct_field o_CgbChannel_np, 4 - struct_field o_CgbChannel_d4, 8 + struct_field o_CgbChannel_modify, 1 + struct_field o_CgbChannel_length, 1 + struct_field o_CgbChannel_sweep, 1 + struct_field o_CgbChannel_frequency, 4 + struct_field o_CgbChannel_wavePointer, 4 + struct_field o_CgbChannel_currentPointer, 4 + struct_field o_CgbChannel_track, 4 + struct_field o_CgbChannel_prevChannelPointer, 4 + struct_field o_CgbChannel_nextChannelPointer, 4 + struct_field o_CgbChannel_dummy4, 8 struct_field CgbChannel_size, 0 + +#endif diff --git a/ld_script.txt b/ld_script.txt index 4b5e35bb4..4bf9d509d 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -347,7 +347,7 @@ SECTIONS { asm/ground_effect.o(.text); src/ground_link.o(.text); asm/ground_event.o(.text); - asm/m4a_1.o(.text); + src/m4a_1.o(.text); src/m4a.o(.text); *libagbsyscall.a:CpuSet.o(.text); *libagbsyscall.a:SoundBiasReset.o(.text); diff --git a/asm/m4a_1.s b/src/m4a_1.s similarity index 75% rename from asm/m4a_1.s rename to src/m4a_1.s index b6fe6f95c..8a40a25c6 100644 --- a/asm/m4a_1.s +++ b/src/m4a_1.s @@ -48,15 +48,15 @@ SoundMain_2: adds r1, r2 SoundMain_3: str r1, [sp, 0x14] - ldr r3, [r0, o_SoundInfo_func] + ldr r3, [r0, o_SoundInfo_MPlayMainHead] cmp r3, 0 beq SoundMain_4 - ldr r0, [r0, o_SoundInfo_intp] - bl call_r3 + ldr r0, [r0, o_SoundInfo_musicPlayerHead] + bl call_r3_ ldr r0, [sp, 0x18] SoundMain_4: ldr r3, [r0, o_SoundInfo_CgbSound] - bl call_r3 + bl call_r3_ ldr r0, [sp, 0x18] ldr r3, [r0, o_SoundInfo_pcmSamplesPerVBlank] mov r8, r3 @@ -114,7 +114,7 @@ _080AE314: strb r0, [r5], 0x1 subs r4, r4, 0x1 bgt _080AE314 - add r0, pc, 0x2F + adr r0, _080AE386 + 1 @ plus 1 because THUMB bx r0 .thumb SoundMainRAM_NoReverb: @@ -141,7 +141,7 @@ SoundMainRAM_NoReverb_Loop: stm r6!, {r0} stm r5!, {r0} stm r6!, {r0} - subs r1, 0x1 + subs r1, 1 bgt SoundMainRAM_NoReverb_Loop _080AE386: ldr r4, [sp, 0x18] @@ -162,77 +162,77 @@ SoundMainRAM_ChanLoop: adds r1, TOTAL_SCANLINES _080AE3A4: cmp r1, r0 - bcc _080AE3B0 + blo _080AE3B0 b _080AE682 .pool _080AE3B0: - ldrb r6, [r4, o_SoundChannel_status] - movs r0, 0xC7 + ldrb r6, [r4, o_SoundChannel_statusFlags] + movs r0, SOUND_CHANNEL_SF_ON tst r0, r6 bne _080AE3BA b _080AE678 _080AE3BA: - movs r0, 0x80 + movs r0, SOUND_CHANNEL_SF_START tst r0, r6 beq _080AE3EA - movs r0, 0x40 + movs r0, SOUND_CHANNEL_SF_STOP tst r0, r6 bne _080AE3FA - movs r6, 0x3 - strb r6, [r4, o_SoundChannel_status] + movs r6, SOUND_CHANNEL_SF_ENV_ATTACK + strb r6, [r4, o_SoundChannel_statusFlags] adds r0, r3, 0 - adds r0, 0x10 - str r0, [r4, o_SoundChannel_cp] - ldr r0, [r3, 0xC] - str r0, [r4, o_SoundChannel_ct] + adds r0, o_WaveData_data + str r0, [r4, o_SoundChannel_currentPointer] + ldr r0, [r3, o_WaveData_size] + str r0, [r4, o_SoundChannel_count] movs r5, 0 - strb r5, [r4, o_SoundChannel_ev] + strb r5, [r4, o_SoundChannel_envelopeVolume] str r5, [r4, o_SoundChannel_fw] - ldrb r2, [r3, 0x3] - movs r0, 0xC0 + ldrb r2, [r3, o_WaveData_flags] + movs r0, WAVE_DATA_FLAG_LOOP tst r0, r2 beq _080AE442 - movs r0, 0x10 + movs r0, SOUND_CHANNEL_SF_LOOP orrs r6, r0 - strb r6, [r4, o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_statusFlags] b _080AE442 _080AE3EA: - ldrb r5, [r4, o_SoundChannel_ev] - movs r0, 0x4 + ldrb r5, [r4, o_SoundChannel_envelopeVolume] + movs r0, SOUND_CHANNEL_SF_IEC tst r0, r6 beq _080AE400 - ldrb r0, [r4, o_SoundChannel_iel] - subs r0, 0x1 - strb r0, [r4, o_SoundChannel_iel] + ldrb r0, [r4, o_SoundChannel_pseudoEchoLength] + subs r0, 1 + strb r0, [r4, o_SoundChannel_pseudoEchoLength] bhi _080AE450 _080AE3FA: movs r0, 0 - strb r0, [r4, o_SoundChannel_status] + strb r0, [r4, o_SoundChannel_statusFlags] b _080AE678 _080AE400: - movs r0, 0x40 + movs r0, SOUND_CHANNEL_SF_STOP tst r0, r6 beq _080AE420 ldrb r0, [r4, o_SoundChannel_release] muls r5, r0 lsrs r5, 8 - ldrb r0, [r4, o_SoundChannel_iev] + ldrb r0, [r4, o_SoundChannel_pseudoEchoVolume] cmp r5, r0 bhi _080AE450 _080AE412: - ldrb r5, [r4, o_SoundChannel_iev] + ldrb r5, [r4, o_SoundChannel_pseudoEchoVolume] cmp r5, 0 beq _080AE3FA - movs r0, 0x4 + movs r0, SOUND_CHANNEL_SF_IEC orrs r6, r0 - strb r6, [r4, o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_statusFlags] b _080AE450 _080AE420: - movs r2, 0x3 + movs r2, SOUND_CHANNEL_SF_ENV ands r2, r6 - cmp r2, 0x2 + cmp r2, SOUND_CHANNEL_SF_ENV_DECAY bne _080AE43E ldrb r0, [r4, o_SoundChannel_decay] muls r5, r0 @@ -243,10 +243,10 @@ _080AE420: adds r5, r0, 0 beq _080AE412 subs r6, 0x1 - strb r6, [r4, o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_statusFlags] b _080AE450 _080AE43E: - cmp r2, 0x3 + cmp r2, SOUND_CHANNEL_SF_ENV_ATTACK bne _080AE450 _080AE442: ldrb r0, [r4, o_SoundChannel_attack] @@ -255,9 +255,9 @@ _080AE442: bcc _080AE450 movs r5, 0xFF subs r6, 0x1 - strb r6, [r4, o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_statusFlags] _080AE450: - strb r5, [r4, o_SoundChannel_ev] + strb r5, [r4, o_SoundChannel_envelopeVolume] ldr r0, [sp, 0x18] ldrb r0, [r0, o_SoundChannel_release] adds r0, 0x1 @@ -266,34 +266,34 @@ _080AE450: ldrb r0, [r4, o_SoundChannel_rightVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, o_SoundChannel_er] + strb r0, [r4, o_SoundChannel_envelopeVolumeRight] ldrb r0, [r4, o_SoundChannel_leftVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, o_SoundChannel_el] - movs r0, 0x10 + strb r0, [r4, o_SoundChannel_envelopeVolumeLeft] + movs r0, SOUND_CHANNEL_SF_LOOP ands r0, r6 str r0, [sp, 0x10] beq _080AE484 adds r0, r3, 0 - adds r0, 0x10 - ldr r1, [r3, 0x8] + adds r0, o_WaveData_data + ldr r1, [r3, o_WaveData_loopStart] adds r0, r1 str r0, [sp, 0xC] - ldr r0, [r3, 0xC] + ldr r0, [r3, o_WaveData_size] subs r0, r1 str r0, [sp, 0x10] _080AE484: ldr r5, [sp, 0x8] - ldr r2, [r4, o_SoundChannel_ct] - ldr r3, [r4, o_SoundChannel_cp] + ldr r2, [r4, o_SoundChannel_count] + ldr r3, [r4, o_SoundChannel_currentPointer] adr r0, _080AE490 bx r0 .arm _080AE490: str r8, [sp] - ldrb r10, [r4, o_SoundChannel_er] - ldrb r11, [r4, o_SoundChannel_el] + ldrb r10, [r4, o_SoundChannel_envelopeVolumeRight] + ldrb r11, [r4, o_SoundChannel_envelopeVolumeLeft] mov r10, r10, lsl 16 mov r11, r11, lsl 16 ldrb r0, [r4, o_SoundChannel_type] @@ -313,7 +313,7 @@ _080AE4B0: moveq r2, 0x4 _080AE4DC: ldr r6, [r5] - ldr r7, [r5, 0x630] + ldr r7, [r5, PCM_DMA_BUF_SIZE] _080AE4E4: ldrsb r0, [r3], 0x1 mul r1, r10, r0 @@ -324,7 +324,7 @@ _080AE4E4: add r7, r1, r7, ror 8 adds r5, r5, 0x40000000 bcc _080AE4E4 - str r7, [r5, 0x630] + str r7, [r5, PCM_DMA_BUF_SIZE] str r6, [r5], 0x4 subs r8, r8, 0x4 bgt _080AE4DC @@ -332,7 +332,7 @@ _080AE4E4: beq _080AE664 _080AE520: ldr r6, [r5] - ldr r7, [r5, 0x630] + ldr r7, [r5, PCM_DMA_BUF_SIZE] _080AE528: ldrsb r0, [r3], 0x1 mul r1, r10, r0 @@ -346,7 +346,7 @@ _080AE528: _080AE54C: adds r5, r5, 0x40000000 bcc _080AE528 - str r7, [r5, 0x630] + str r7, [r5, PCM_DMA_BUF_SIZE] str r6, [r5], 0x4 subs r8, r8, 0x4 bgt _080AE4B0 @@ -372,27 +372,27 @@ _080AE598: ldrne r3, [sp, 0xC] bne _080AE54C _080AE5A8: - strb r2, [r4, o_SoundChannel_status] + strb r2, [r4, o_SoundChannel_statusFlags] mov r0, r5, lsr 30 bic r5, r5, 0xC0000000 rsb r0, r0, 0x3 mov r0, r0, lsl 3 mov r6, r6, ror r0 mov r7, r7, ror r0 - str r7, [r5, 0x630] + str r7, [r5, PCM_DMA_BUF_SIZE] str r6, [r5], 0x4 b _080AE66C _080AE5D0: stmdb sp!, {r4,r12} ldr lr, [r4, o_SoundChannel_fw] - ldr r1, [r4, o_SoundChannel_freq] + ldr r1, [r4, o_SoundChannel_frequency] mul r4, r12, r1 ldrsb r0, [r3] ldrsb r1, [r3, 0x1]! sub r1, r1, r0 _080AE5EC: ldr r6, [r5] - ldr r7, [r5, 0x630] + ldr r7, [r5, PCM_DMA_BUF_SIZE] _080AE5F4: mul r9, lr, r1 add r9, r0, r9, asr 23 @@ -417,7 +417,7 @@ _080AE634: _080AE640: adds r5, r5, 0x40000000 bcc _080AE5F4 - str r7, [r5, 0x630] + str r7, [r5, PCM_DMA_BUF_SIZE] str r6, [r5], 0x4 subs r8, r8, 0x4 bgt _080AE5EC @@ -425,8 +425,8 @@ _080AE640: ldmia sp!, {r4,r12} str lr, [r4, o_SoundChannel_fw] _080AE664: - str r2, [r4, o_SoundChannel_ct] - str r3, [r4, o_SoundChannel_cp] + str r2, [r4, o_SoundChannel_count] + str r3, [r4, o_SoundChannel_currentPointer] _080AE66C: ldr r8, [sp] add r0, pc, 0x1 @@ -434,7 +434,7 @@ _080AE66C: .thumb _080AE678: ldr r0, [sp, 0x4] - subs r0, 0x1 + subs r0, 1 ble _080AE682 adds r4, SoundChannel_size b SoundMainRAM_ChanLoop @@ -450,7 +450,7 @@ _080AE682: mov r11, r3 pop {r3} -call_r3: +call_r3_: bx r3 .pool thumb_func_end SoundMainRAM @@ -472,24 +472,24 @@ SoundMainBTM: thumb_func_start RealClearChain RealClearChain: - ldr r3, [r0, 0x2C] + ldr r3, [r0, o_SoundChannel_track] cmp r3, 0 beq _080AE6D2 - ldr r1, [r0, 0x34] - ldr r2, [r0, 0x30] + ldr r1, [r0, o_SoundChannel_nextChannelPointer] + ldr r2, [r0, o_SoundChannel_prevChannelPointer] cmp r2, 0 beq _080AE6C6 - str r1, [r2, 0x34] + str r1, [r2, o_SoundChannel_nextChannelPointer] b _080AE6C8 _080AE6C6: - str r1, [r3, 0x20] + str r1, [r3, o_MusicPlayerTrack_chan] _080AE6C8: cmp r1, 0 beq _080AE6CE - str r2, [r1, 0x30] + str r2, [r1, o_SoundChannel_prevChannelPointer] _080AE6CE: movs r1, 0 - str r1, [r0, 0x2C] + str r1, [r0, o_SoundChannel_track] _080AE6D2: bx lr thumb_func_end RealClearChain @@ -502,22 +502,22 @@ ply_fine: cmp r4, 0 beq ply_fine_done ply_fine_loop: - ldrb r1, [r4] - movs r0, 0xC7 + ldrb r1, [r4, o_SoundChannel_statusFlags] + movs r0, SOUND_CHANNEL_SF_ON tst r0, r1 beq ply_fine_ok - movs r0, 0x40 + movs r0, SOUND_CHANNEL_SF_STOP orrs r1, r0 - strb r1, [r4] + strb r1, [r4, o_SoundChannel_statusFlags] ply_fine_ok: adds r0, r4, 0 bl RealClearChain - ldr r4, [r4, 0x34] + ldr r4, [r4, o_SoundChannel_nextChannelPointer] cmp r4, 0 bne ply_fine_loop ply_fine_done: movs r0, 0 - strb r0, [r5] + strb r0, [r5, o_MusicPlayerTrack_flags] pop {r4,r5} pop {r0} bx r0 @@ -543,30 +543,34 @@ MPlayJumpTableCopy_Loop: ldrb_r3_r2: ldrb r3, [r2] +@ This attempts to protect against reading anything from the BIOS ROM +@ besides the jump table template. +@ It assumes that the jump table template is located at the end of the ROM. .thumb_func chk_adr_r2: push {r0} lsrs r0, r2, 25 - bne chk_adr_r2_done + bne chk_adr_r2_done @ if adr >= 0x2000000 (i.e. not in BIOS ROM), accept it ldr r0, lt_MPlayJumpTableTemplate cmp r2, r0 - bcc chk_adr_r2_reject + blo chk_adr_r2_reject @ if adr < gMPlayJumpTableTemplate, reject it lsrs r0, r2, 14 - beq chk_adr_r2_done + beq chk_adr_r2_done @ if adr < 0x40000 (i.e. in BIOS ROM), accept it chk_adr_r2_reject: movs r3, 0 chk_adr_r2_done: pop {r0} bx lr + .align 2, 0 lt_MPlayJumpTableTemplate: .word gMPlayJumpTableTemplate thumb_func_start ld_r3_tp_adr_i ld_r3_tp_adr_i: - ldr r2, [r1, 0x40] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] _080AE73A: adds r3, r2, 0x1 - str r3, [r1, 0x40] + str r3, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] b chk_adr_r2 thumb_func_end ld_r3_tp_adr_i @@ -594,18 +598,18 @@ ply_goto_1: thumb_func_start ply_patt ply_patt: ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] - cmp r2, 0x3 - bcs _080AE77C + cmp r2, 3 + bhs ply_patt_done lsls r2, 2 adds r3, r1, r2 ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] adds r2, 0x4 str r2, [r3, o_MusicPlayerTrack_patternStack] ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] - adds r2, 0x1 + adds r2, 1 strb r2, [r1, o_MusicPlayerTrack_patternLevel] b ply_goto -_080AE77C: +ply_patt_done: b ply_fine thumb_func_end ply_patt @@ -697,13 +701,13 @@ ply_voice: lsls r2, 2 ldr r3, [r0, o_MusicPlayerInfo_tone] adds r2, r3 - ldr r3, [r2] + ldr r3, [r2, o_ToneData_type] bl chk_adr_r2 str r3, [r1, o_MusicPlayerTrack_ToneData_type] - ldr r3, [r2, 0x4] + ldr r3, [r2, o_ToneData_wav] bl chk_adr_r2 str r3, [r1, o_MusicPlayerTrack_ToneData_wav] - ldr r3, [r2, 0x8] + ldr r3, [r2, o_ToneData_attack] bl chk_adr_r2 str r3, [r1, o_MusicPlayerTrack_ToneData_attack] bx r12 @@ -715,7 +719,7 @@ ply_vol: bl ld_r3_tp_adr_i strb r3, [r1, o_MusicPlayerTrack_vol] ldrb r3, [r1, o_MusicPlayerTrack_flags] - movs r2, 0x3 + movs r2, MPT_FLG_VOLCHG orrs r3, r2 strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 @@ -725,10 +729,10 @@ ply_vol: ply_pan: mov r12, lr bl ld_r3_tp_adr_i - subs r3, 0x40 + subs r3, C_V strb r3, [r1, o_MusicPlayerTrack_pan] ldrb r3, [r1, o_MusicPlayerTrack_flags] - movs r2, 0x3 + movs r2, MPT_FLG_VOLCHG orrs r3, r2 strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 @@ -738,10 +742,10 @@ ply_pan: ply_bend: mov r12, lr bl ld_r3_tp_adr_i - subs r3, 0x40 + subs r3, C_V strb r3, [r1, o_MusicPlayerTrack_bend] ldrb r3, [r1, o_MusicPlayerTrack_flags] - movs r2, 0xC + movs r2, MPT_FLG_PITCHG orrs r3, r2 strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 @@ -753,7 +757,7 @@ ply_bendr: bl ld_r3_tp_adr_i strb r3, [r1, o_MusicPlayerTrack_bendRange] ldrb r3, [r1, o_MusicPlayerTrack_flags] - movs r2, 0xC + movs r2, MPT_FLG_PITCHG orrs r3, r2 strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 @@ -776,7 +780,7 @@ ply_modt: beq _080AE89A strb r3, [r1, o_MusicPlayerTrack_modT] ldrb r3, [r1, o_MusicPlayerTrack_flags] - movs r2, 0xF + movs r2, MPT_FLG_VOLCHG | MPT_FLG_PITCHG orrs r3, r2 strb r3, [r1, o_MusicPlayerTrack_flags] _080AE89A: @@ -787,10 +791,10 @@ _080AE89A: ply_tune: mov r12, lr bl ld_r3_tp_adr_i - subs r3, 0x40 + subs r3, C_V strb r3, [r1, o_MusicPlayerTrack_tune] ldrb r3, [r1, o_MusicPlayerTrack_flags] - movs r2, 0xC + movs r2, MPT_FLG_PITCHG orrs r3, r2 strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 @@ -801,7 +805,7 @@ ply_port: mov r12, lr ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] - adds r2, 0x1 + adds r2, 1 ldr r0, =REG_SOUND1CNT_L @ sound register base address adds r0, r3 bl _080AE73A @@ -819,15 +823,15 @@ m4aSoundVSync: ldr r2, lt2_ID_NUMBER ldr r3, [r0, o_SoundInfo_ident] subs r3, r2 - cmp r3, 0x1 + cmp r3, 1 bhi m4aSoundVSync_Done @ Decrement the PCM DMA counter. If it reaches 0, we need to do a DMA. ldrb r1, [r0, o_SoundInfo_pcmDmaCounter] - subs r1, 0x1 + subs r1, 1 strb r1, [r0, o_SoundInfo_pcmDmaCounter] bgt m4aSoundVSync_Done - + @ Reload the PCM DMA counter. ldrb r1, [r0, o_SoundInfo_pcmDmaPeriod] strb r1, [r0, o_SoundInfo_pcmDmaCounter] @@ -836,7 +840,7 @@ m4aSoundVSync: ldr r1, [r2, 0x8] @ DMA1CNT lsls r1, 7 - bcc m4aSoundVSync_SkipDMA1 + bcc m4aSoundVSync_SkipDMA1 @ branch if repeat bit isn't set ldr r1, =((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4 str r1, [r2, 0x8] @ DMA1CNT @@ -844,16 +848,20 @@ m4aSoundVSync: m4aSoundVSync_SkipDMA1: ldr r1, [r2, 0xC + 0x8] @ DMA2CNT lsls r1, 7 - bcc m4aSoundVSync_SkipDMA2 + bcc m4aSoundVSync_SkipDMA2 @ branch if repeat bit isn't set + ldr r1, =((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4 str r1, [r2, 0xC + 0x8] @ DMA2CNT m4aSoundVSync_SkipDMA2: + + @ turn off DMA1/DMA2 movs r1, DMA_32BIT >> 8 lsls r1, 8 strh r1, [r2, 0xA] @ DMA1CNT_H strh r1, [r2, 0xC + 0xA] @ DMA2CNT_H + @ turn on DMA1/DMA2 direct-sound FIFO mode movs r1, (DMA_ENABLE | DMA_START_SPECIAL | DMA_32BIT | DMA_REPEAT) >> 8 lsls r1, 8 @ LSB is 0, so DMA_SRC_INC is used (destination is always fixed in FIFO mode) strh r1, [r2, 0xA] @ DMA1CNT_H @@ -880,7 +888,7 @@ _080AE91E: cmp r3, 0 beq _080AE930 ldr r0, [r0, o_MusicPlayerInfo_intp] - bl call_r3_2 + bl call_r3 _080AE930: pop {r0} push {r4-r7} @@ -915,8 +923,8 @@ _080AE964: movs r3, 0x1 movs r4, 0 _080AE96C: - ldrb r0, [r5] - movs r1, 0x80 + ldrb r0, [r5, o_MusicPlayerTrack_flags] + movs r1, MPT_FLG_EXIST tst r1, r0 bne _080AE976 b _080AEA88 @@ -928,36 +936,36 @@ _080AE976: cmp r4, 0 beq _080AE9AA _080AE982: - ldrb r1, [r4] - movs r0, 0xC7 + ldrb r1, [r4, o_SoundChannel_statusFlags] + movs r0, SOUND_CHANNEL_SF_ON tst r0, r1 beq _080AE99E - ldrb r0, [r4, 0x10] + ldrb r0, [r4, o_SoundChannel_gateTime] cmp r0, 0 beq _080AE9A4 subs r0, 0x1 - strb r0, [r4, 0x10] + strb r0, [r4, o_SoundChannel_gateTime] bne _080AE9A4 - movs r0, 0x40 + movs r0, SOUND_CHANNEL_SF_STOP orrs r1, r0 - strb r1, [r4] + strb r1, [r4, o_SoundChannel_statusFlags] b _080AE9A4 _080AE99E: adds r0, r4, 0 bl ClearChain _080AE9A4: - ldr r4, [r4, 0x34] + ldr r4, [r4, o_SoundChannel_nextChannelPointer] cmp r4, 0 bne _080AE982 _080AE9AA: ldrb r3, [r5, o_MusicPlayerTrack_flags] - movs r0, 0x40 + movs r0, MPT_FLG_START tst r0, r3 beq _080AEA28 adds r0, r5, 0 bl Clear64byte - movs r0, 0x80 - strb r0, [r5] + movs r0, MPT_FLG_EXIST + strb r0, [r5, o_MusicPlayerTrack_flags] movs r0, 0x2 strb r0, [r5, o_MusicPlayerTrack_bendRange] movs r0, 0x40 @@ -990,7 +998,7 @@ _080AE9E6: subs r0, 0xCF adds r1, r7, 0 adds r2, r5, 0 - bl call_r3_2 + bl call_r3 b _080AEA28 _080AE9FC: cmp r1, 0xB0 @@ -1004,7 +1012,7 @@ _080AE9FC: ldr r3, [r3, r0] adds r0, r7, 0 adds r1, r5, 0 - bl call_r3_2 + bl call_r3 ldrb r0, [r5, o_MusicPlayerTrack_flags] cmp r0, 0 beq _080AEA84 @@ -1060,10 +1068,10 @@ _080AEA62: ldrb r1, [r5, o_MusicPlayerTrack_modT] cmp r1, 0 bne _080AEA7E - movs r1, 0xC + movs r1, MPT_FLG_PITCHG b _080AEA80 _080AEA7E: - movs r1, 0x3 + movs r1, MPT_FLG_VOLCHG _080AEA80: orrs r0, r1 strb r0, [r5, o_MusicPlayerTrack_flags] @@ -1073,7 +1081,7 @@ _080AEA84: _080AEA88: subs r6, 0x1 ble _080AEA94 - movs r0, 0x50 + movs r0, MusicPlayerTrack_size adds r5, r0 lsls r3, 1 b _080AE96C @@ -1090,10 +1098,10 @@ _080AEA94: _080AEAA6: str r4, [r7, o_MusicPlayerInfo_status] ldrh r0, [r7, o_MusicPlayerInfo_tempoC] - subs r0, 0x96 + subs r0, 150 _080AEAAC: strh r0, [r7, o_MusicPlayerInfo_tempoC] - cmp r0, 0x96 + cmp r0, 150 bcc _080AEAB4 b _080AE964 _080AEAB4: @@ -1104,7 +1112,7 @@ _080AEAB8: movs r1, 0x80 tst r1, r0 beq _080AEB52 - movs r1, 0xF + movs r1, MPT_FLG_VOLCHG | MPT_FLG_PITCHG tst r1, r0 beq _080AEB52 mov r9, r2 @@ -1115,8 +1123,8 @@ _080AEAB8: cmp r4, 0 beq _080AEB48 _080AEAD6: - ldrb r1, [r4, o_SoundChannel_status] - movs r0, 0xC7 + ldrb r1, [r4, o_SoundChannel_statusFlags] + movs r0, SOUND_CHANNEL_SF_ON tst r0, r1 bne _080AEAE6 adds r0, r4, 0 @@ -1124,26 +1132,26 @@ _080AEAD6: b _080AEB42 _080AEAE6: ldrb r0, [r4, o_SoundChannel_type] - movs r6, 0x7 + movs r6, TONEDATA_TYPE_CGB ands r6, r0 ldrb r3, [r5, o_MusicPlayerTrack_flags] - movs r0, 0x3 + movs r0, MPT_FLG_VOLCHG tst r0, r3 beq _080AEB04 bl ChnVolSetAsm cmp r6, 0 beq _080AEB04 - ldrb r0, [r4, o_CgbChannel_mo] - movs r1, 0x1 + ldrb r0, [r4, o_CgbChannel_modify] + movs r1, CGB_CHANNEL_MO_VOL orrs r0, r1 - strb r0, [r4, o_CgbChannel_mo] + strb r0, [r4, o_CgbChannel_modify] _080AEB04: ldrb r3, [r5, o_MusicPlayerTrack_flags] - movs r0, 0xC + movs r0, MPT_FLG_PITCHG tst r0, r3 beq _080AEB42 - ldrb r1, [r4, o_SoundChannel_ky] - movs r0, 0x8 + ldrb r1, [r4, o_SoundChannel_key] + movs r0, o_MusicPlayerTrack_keyM ldrsb r0, [r5, r0] adds r2, r1, r0 bpl _080AEB18 @@ -1156,21 +1164,21 @@ _080AEB18: adds r1, r2, 0 ldrb r2, [r5, o_MusicPlayerTrack_pitM] adds r0, r6, 0 - bl call_r3_2 - str r0, [r4, o_CgbChannel_fr] - ldrb r0, [r4, o_CgbChannel_mo] - movs r1, 0x2 + bl call_r3 + str r0, [r4, o_CgbChannel_frequency] + ldrb r0, [r4, o_CgbChannel_modify] + movs r1, CGB_CHANNEL_MO_PIT orrs r0, r1 - strb r0, [r4, o_CgbChannel_mo] + strb r0, [r4, o_CgbChannel_modify] b _080AEB42 _080AEB36: adds r1, r2, 0 ldrb r2, [r5, o_MusicPlayerTrack_pitM] ldr r0, [r4, o_SoundChannel_wav] bl MidiKeyToFreq - str r0, [r4, o_SoundChannel_freq] + str r0, [r4, o_SoundChannel_frequency] _080AEB42: - ldr r4, [r4, o_SoundChannel_np] + ldr r4, [r4, o_SoundChannel_nextChannelPointer] cmp r4, 0 bne _080AEAD6 _080AEB48: @@ -1182,7 +1190,7 @@ _080AEB48: _080AEB52: subs r2, 0x1 ble _080AEB5C - movs r0, 0x50 + movs r0, MusicPlayerTrack_size adds r5, r0 bgt _080AEAB8 _080AEB5C: @@ -1194,10 +1202,11 @@ _080AEB5C: mov r10, r2 mov r11, r3 pop {r3} -call_r3_2: + +call_r3: bx r3 - .align 2, 0 + .align 2, 0 lt_gClockTable: .word gClockTable lt2_SOUND_INFO_PTR: .word SOUND_INFO_PTR lt2_ID_NUMBER: .word ID_NUMBER @@ -1208,7 +1217,7 @@ TrackStop: push {r4-r6,lr} adds r5, r1, 0 ldrb r1, [r5, o_MusicPlayerTrack_flags] - movs r0, 0x80 + movs r0, MPT_FLG_EXIST tst r0, r1 beq TrackStop_Done ldr r4, [r5, o_MusicPlayerTrack_chan] @@ -1216,22 +1225,22 @@ TrackStop: beq TrackStop_3 movs r6, 0 TrackStop_Loop: - ldrb r0, [r4, o_SoundChannel_status] + ldrb r0, [r4, o_SoundChannel_statusFlags] cmp r0, 0 beq TrackStop_2 ldrb r0, [r4, o_SoundChannel_type] - movs r3, 0x7 + movs r3, TONEDATA_TYPE_CGB ands r0, r3 beq TrackStop_1 ldr r3, =SOUND_INFO_PTR ldr r3, [r3] ldr r3, [r3, o_SoundInfo_CgbOscOff] - bl call_r3_2 + bl call_r3 TrackStop_1: - strb r6, [r4, o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_statusFlags] TrackStop_2: str r6, [r4, o_SoundChannel_track] - ldr r4, [r4, o_SoundChannel_np] + ldr r4, [r4, o_SoundChannel_nextChannelPointer] cmp r4, 0 bne TrackStop_Loop TrackStop_3: @@ -1245,31 +1254,31 @@ TrackStop_Done: thumb_func_start ChnVolSetAsm ChnVolSetAsm: - ldrb r1, [r4, 0x12] - movs r0, 0x14 + ldrb r1, [r4, o_SoundChannel_velocity] + movs r0, o_SoundChannel_rhythmPan ldrsb r2, [r4, r0] movs r3, 0x80 adds r3, r2 muls r3, r1 - ldrb r0, [r5, 0x10] + ldrb r0, [r5, o_MusicPlayerTrack_volMR] muls r0, r3 asrs r0, 14 cmp r0, 0xFF bls _080AEBD8 movs r0, 0xFF _080AEBD8: - strb r0, [r4, 0x2] + strb r0, [r4, o_SoundChannel_rightVolume] movs r3, 0x7F subs r3, r2 muls r3, r1 - ldrb r0, [r5, 0x11] + ldrb r0, [r5, o_MusicPlayerTrack_volML] muls r0, r3 asrs r0, 14 cmp r0, 0xFF bls _080AEBEC movs r0, 0xFF _080AEBEC: - strb r0, [r4, 0x3] + strb r0, [r4, o_SoundChannel_leftVolume] bx lr thumb_func_end ChnVolSetAsm @@ -1294,17 +1303,17 @@ ply_note: ldr r3, [r5, o_MusicPlayerTrack_cmdPtr] ldrb r0, [r3] cmp r0, 0x80 - bcs _080AEC36 + bhs _080AEC36 strb r0, [r5, o_MusicPlayerTrack_key] adds r3, 0x1 ldrb r0, [r3] cmp r0, 0x80 - bcs _080AEC34 + bhs _080AEC34 strb r0, [r5, o_MusicPlayerTrack_velocity] adds r3, 0x1 ldrb r0, [r3] cmp r0, 0x80 - bcs _080AEC34 + bhs _080AEC34 ldrb r1, [r5, o_MusicPlayerTrack_gateTime] adds r1, r0 strb r1, [r5, o_MusicPlayerTrack_gateTime] @@ -1339,32 +1348,32 @@ _080AEC58: mov r9, r1 mov r6, r9 ldrb r1, [r6] - movs r0, 0xC0 + movs r0, TONEDATA_TYPE_SPL | TONEDATA_TYPE_RHY tst r0, r1 beq _080AEC70 b _080AEDD6 _080AEC70: - movs r0, 0x80 + movs r0, TONEDATA_TYPE_RHY tst r0, r2 beq _080AEC8C - ldrb r1, [r6, 0x3] + ldrb r1, [r6, o_ToneData_pan_sweep] movs r0, 0x80 tst r0, r1 beq _080AEC84 - subs r1, 0xC0 + subs r1, TONEDATA_P_S_PAN lsls r1, 1 str r1, [sp, 0x14] _080AEC84: - ldrb r3, [r6, 0x1] + ldrb r3, [r6, o_SoundChannel_type] b _080AEC8C _080AEC88: mov r9, r4 - ldrb r3, [r5, 0x5] + ldrb r3, [r5, o_MusicPlayerTrack_key] _080AEC8C: str r3, [sp, 0x8] ldr r6, [sp] - ldrb r1, [r6, 0x9] - ldrb r0, [r5, 0x1D] + ldrb r1, [r6, o_MusicPlayerInfo_priority] + ldrb r0, [r5, o_MusicPlayerTrack_priority] adds r0, r1 cmp r0, 0xFF bls _080AEC9C @@ -1372,13 +1381,13 @@ _080AEC8C: _080AEC9C: str r0, [sp, 0x10] mov r6, r9 - ldrb r0, [r6] - movs r6, 0x7 + ldrb r0, [r6, o_ToneData_type] + movs r6, TONEDATA_TYPE_CGB ands r6, r0 str r6, [sp, 0xC] beq _080AECDC ldr r0, [sp, 0x4] - ldr r4, [r0, 0x1C] + ldr r4, [r0, o_SoundInfo_cgbChans] cmp r4, 0 bne _080AECB4 b _080AEDD6 @@ -1386,21 +1395,21 @@ _080AECB4: subs r6, 0x1 lsls r0, r6, 6 adds r4, r0 - ldrb r1, [r4] - movs r0, 0xC7 + ldrb r1, [r4, o_CgbChannel_statusFlags] + movs r0, SOUND_CHANNEL_SF_ON tst r0, r1 beq _080AED30 - movs r0, 0x40 + movs r0, SOUND_CHANNEL_SF_STOP tst r0, r1 bne _080AED30 - ldrb r1, [r4, 0x13] + ldrb r1, [r4, o_CgbChannel_priority] ldr r0, [sp, 0x10] cmp r1, r0 bcc _080AED30 beq _080AECD4 b _080AEDD6 _080AECD4: - ldr r0, [r4, 0x2C] + ldr r0, [r4, o_CgbChannel_track] cmp r0, r5 bcs _080AED30 b _080AEDD6 @@ -1410,35 +1419,35 @@ _080AECDC: movs r2, 0 mov r8, r2 ldr r4, [sp, 0x4] - ldrb r3, [r4, 0x6] - adds r4, 0x50 + ldrb r3, [r4, o_SoundInfo_maxChans] + adds r4, o_SoundInfo_chans _080AECEA: - ldrb r1, [r4] - movs r0, 0xC7 + ldrb r1, [r4, o_SoundChannel_statusFlags] + movs r0, SOUND_CHANNEL_SF_ON tst r0, r1 beq _080AED30 - movs r0, 0x40 + movs r0, SOUND_CHANNEL_SF_STOP tst r0, r1 beq _080AED04 cmp r2, 0 bne _080AED08 adds r2, 0x1 - ldrb r6, [r4, 0x13] - ldr r7, [r4, 0x2C] + ldrb r6, [r4, o_SoundChannel_priority] + ldr r7, [r4, o_SoundChannel_track] b _080AED22 _080AED04: cmp r2, 0 bne _080AED24 _080AED08: - ldrb r0, [r4, 0x13] + ldrb r0, [r4, o_SoundChannel_priority] cmp r0, r6 bcs _080AED14 adds r6, r0, 0 - ldr r7, [r4, 0x2C] + ldr r7, [r4, o_SoundChannel_track] b _080AED22 _080AED14: bhi _080AED24 - ldr r0, [r4, 0x2C] + ldr r0, [r4, o_SoundChannel_track] cmp r0, r7 bls _080AED20 adds r7, r0, 0 @@ -1448,7 +1457,7 @@ _080AED20: _080AED22: mov r8, r4 _080AED24: - adds r4, 0x40 + adds r4, SoundChannel_size subs r3, 0x1 bgt _080AECEA mov r4, r8 @@ -1458,17 +1467,17 @@ _080AED30: adds r0, r4, 0 bl ClearChain movs r1, 0 - str r1, [r4, 0x30] - ldr r3, [r5, 0x20] - str r3, [r4, 0x34] + str r1, [r4, o_SoundChannel_prevChannelPointer] + ldr r3, [r5, o_MusicPlayerTrack_chan] + str r3, [r4, o_SoundChannel_nextChannelPointer] cmp r3, 0 beq _080AED44 - str r4, [r3, 0x30] + str r4, [r3, o_SoundChannel_prevChannelPointer] _080AED44: - str r4, [r5, 0x20] - str r5, [r4, 0x2C] - ldrb r0, [r5, 0x1B] - strb r0, [r5, 0x1C] + str r4, [r5, o_MusicPlayerTrack_chan] + str r5, [r4, o_SoundChannel_track] + ldrb r0, [r5, o_MusicPlayerTrack_lfoDelay] + strb r0, [r5, o_MusicPlayerTrack_lfoDelayC] cmp r0, r1 beq _080AED56 adds r1, r5, 0 @@ -1477,26 +1486,26 @@ _080AED56: ldr r0, [sp] adds r1, r5, 0 bl TrkVolPitSet - ldr r0, [r5, 0x4] - str r0, [r4, 0x10] + ldr r0, [r5, o_MusicPlayerTrack_gateTime] + str r0, [r4, o_SoundChannel_gateTime] ldr r0, [sp, 0x10] - strb r0, [r4, 0x13] + strb r0, [r4, o_SoundChannel_priority] ldr r0, [sp, 0x8] - strb r0, [r4, 0x8] + strb r0, [r4, o_SoundChannel_key] ldr r0, [sp, 0x14] - strb r0, [r4, 0x14] + strb r0, [r4, o_SoundChannel_rhythmPan] mov r6, r9 - ldrb r0, [r6] - strb r0, [r4, 0x1] - ldr r7, [r6, 0x4] - str r7, [r4, 0x24] - ldr r0, [r6, 0x8] - str r0, [r4, 0x4] - ldrh r0, [r5, 0x1E] - strh r0, [r4, 0xC] + ldrb r0, [r6, o_ToneData_type] + strb r0, [r4, o_SoundChannel_type] + ldr r7, [r6, o_ToneData_wav] + str r7, [r4, o_SoundChannel_wav] + ldr r0, [r6, o_ToneData_attack] + str r0, [r4, o_SoundChannel_attack] + ldrh r0, [r5, o_MusicPlayerTrack_pseudoEchoVolume] + strh r0, [r4, o_SoundChannel_pseudoEchoVolume] bl ChnVolSetAsm - ldrb r1, [r4, 0x8] - movs r0, 0x8 + ldrb r1, [r4, o_SoundChannel_key] + movs r0, o_MusicPlayerTrack_keyM ldrsb r0, [r5, r0] adds r3, r1, r0 bpl _080AED90 @@ -1506,9 +1515,9 @@ _080AED90: cmp r6, 0 beq _080AEDBE mov r6, r9 - ldrb r0, [r6, 0x2] - strb r0, [r4, 0x1E] - ldrb r1, [r6, 0x3] + ldrb r0, [r6, o_ToneData_length] + strb r0, [r4, o_CgbChannel_length] + ldrb r1, [r6, o_ToneData_pan_sweep] movs r0, 0x80 tst r0, r1 bne _080AEDAA @@ -1518,27 +1527,27 @@ _080AED90: _080AEDAA: movs r1, 0x8 _080AEDAC: - strb r1, [r4, 0x1F] - ldrb r2, [r5, 0x9] + strb r1, [r4, o_CgbChannel_sweep] + ldrb r2, [r5, o_MusicPlayerTrack_pitM] adds r1, r3, 0 ldr r0, [sp, 0xC] ldr r3, [sp, 0x4] - ldr r3, [r3, 0x30] - bl call_r3_2 + ldr r3, [r3, o_SoundInfo_MidiKeyToCgbFreq] + bl call_r3 b _080AEDC8 _080AEDBE: - ldrb r2, [r5, 0x9] + ldrb r2, [r5, o_MusicPlayerTrack_pitM] adds r1, r3, 0 adds r0, r7, 0 bl MidiKeyToFreq _080AEDC8: - str r0, [r4, 0x20] - movs r0, 0x80 - strb r0, [r4] - ldrb r1, [r5] + str r0, [r4, o_SoundChannel_frequency] + movs r0, SOUND_CHANNEL_SF_START + strb r0, [r4, o_SoundChannel_statusFlags] + ldrb r1, [r5, o_MusicPlayerTrack_flags] movs r0, 0xF0 ands r0, r1 - strb r0, [r5] + strb r0, [r5, o_MusicPlayerTrack_flags] _080AEDD6: add sp, 0x18 pop {r0-r7} @@ -1557,7 +1566,7 @@ ply_endtie: ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] cmp r3, 0x80 - bcs _080AEE02 + bhs _080AEE02 strb r3, [r1, o_MusicPlayerTrack_key] adds r2, 0x1 str r2, [r1, o_MusicPlayerTrack_cmdPtr] @@ -1568,23 +1577,23 @@ _080AEE04: ldr r1, [r1, o_MusicPlayerTrack_chan] cmp r1, 0 beq _080AEE2C - movs r4, 0x83 - movs r5, 0x40 + movs r4, SOUND_CHANNEL_SF_START | SOUND_CHANNEL_SF_ENV + movs r5, SOUND_CHANNEL_SF_STOP _080AEE0E: - ldrb r2, [r1, o_SoundChannel_status] + ldrb r2, [r1, o_SoundChannel_statusFlags] tst r2, r4 beq _080AEE26 tst r2, r5 bne _080AEE26 - ldrb r0, [r1, o_SoundChannel_mk] + ldrb r0, [r1, o_SoundChannel_midiKey] cmp r0, r3 bne _080AEE26 - movs r0, 0x40 + movs r0, SOUND_CHANNEL_SF_STOP orrs r2, r0 - strb r2, [r1, o_SoundChannel_status] + strb r2, [r1, o_SoundChannel_statusFlags] b _080AEE2C _080AEE26: - ldr r1, [r1, o_SoundChannel_np] + ldr r1, [r1, o_SoundChannel_nextChannelPointer] cmp r1, 0 bne _080AEE0E _080AEE2C: @@ -1600,10 +1609,10 @@ clear_modM: ldrb r2, [r1, o_MusicPlayerTrack_modT] cmp r2, 0 bne _080AEE40 - movs r2, 0xC + movs r2, MPT_FLG_PITCHG b _080AEE42 _080AEE40: - movs r2, 0x3 + movs r2, MPT_FLG_VOLCHG _080AEE42: ldrb r3, [r1, o_MusicPlayerTrack_flags] orrs r3, r2 @@ -1613,9 +1622,9 @@ _080AEE42: thumb_func_start ld_r3_tp_adr_i_unchecked ld_r3_tp_adr_i_unchecked: - ldr r2, [r1, 0x40] - adds r3, r2, 0x1 - str r3, [r1, 0x40] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] + adds r3, r2, 1 + str r3, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] bx lr thumb_func_end ld_r3_tp_adr_i_unchecked