Skip to content

Commit

Permalink
Fixing issues with Flamedriver integration
Browse files Browse the repository at this point in the history
Forgot about the split music/SFX queues caused some in S3&K because they
were not completely careful about which function to use in a few spots.
  • Loading branch information
flamewing committed Sep 18, 2020
1 parent 0d0080b commit 49433a4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 58 deletions.
108 changes: 51 additions & 57 deletions sonic3k.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,13 @@ SndDrvInit:
lea (Z80_RAM).l,a1
bsr.w Kos_Decomp
; Load default variables
lea (Z80_DefaultVariables).l,a0
lea (Z80_RAM+zDataStart).l,a1
move.w #Z80_DefaultVariables_end-Z80_DefaultVariables-1,d0
moveq #0,d1
lea (Z80_RAM+z80_stack).l,a1
move.w #bytesToXcnt(zTracksStart-z80_stack, 8),d0
-
move.b (a0)+,(a1)+
movep.l d1,0(a1)
movep.l d1,1(a1)
addq.w #8,a1
dbf d0,-
; Detect PAL region consoles
btst #6,(Graphics_flags).w
Expand All @@ -1357,29 +1359,6 @@ SndDrvInit:
rts
; End of function SndDrvInit

; ---------------------------------------------------------------------------
; Default Z80 variables. These are actually set to more meaningful values
; in other SMPS Z80 drivers.
; ---------------------------------------------------------------------------
Z80_DefaultVariables:
dc.b 0 ; Unused 1
dc.b 0 ; Unused 2
dc.b 0 ; zPalFlag
dc.b 0 ; Unused 3
dc.b 0 ; zPalDblUpdCounter
dc.b 0 ; zSoundQueue0
dc.b 0 ; zSoundQueue1
dc.b 0 ; zSoundQueue2
dc.b 0 ; zTempoSpeedup
dc.b 0 ; zNextSound
dc.b 0 ; zMusicNumber
dc.b 0 ; zSFXNumber0
dc.b 0 ; zSFXNumber1
dc.b 0 ; zFadeOutTimeout
dc.b 0 ; zFadeDelay
dc.b 0 ; zFadeDelayTimeout
Z80_DefaultVariables_end:

; ---------------------------------------------------------------------------
; Always replaces an index previous passed to this function
; ---------------------------------------------------------------------------
Expand Down Expand Up @@ -5035,7 +5014,7 @@ loc_41D4:
move.l #5000,(Next_extra_life_score).w
move.l #5000,(Next_extra_life_score_P2).w ;CHECKLATER
moveq #mus_FadeOut,d0
bsr.w Play_Sound_2 ; Fade out the title screen music
bsr.w Play_Sound ; Fade out the title screen music
moveq #0,d0
move.b (Title_screen_option).w,d0 ; Selection is stored here.
bne.w loc_4264
Expand All @@ -5057,7 +5036,7 @@ loc_4270:

loc_4278:
moveq #mus_FadeOut,d0
bsr.w Play_Sound_2 ; Fade out music
bsr.w Play_Sound ; Fade out music
move.w (Next_demo_number).w,d0 ; Get index of current demo to run
move.w d0,(Demo_number).w
andi.w #7,d0
Expand Down Expand Up @@ -5979,7 +5958,7 @@ loc_539A:
move.l #5000,(Next_extra_life_score).w
move.l #5000,(Next_extra_life_score_P2).w
moveq #mus_FadeOut,d0
bsr.w Play_Sound_2
bsr.w Play_Sound
moveq #0,d0
move.b (Title_screen_option).w,d0
cmpi.b #2,d0
Expand Down Expand Up @@ -6012,7 +5991,7 @@ locret_546A:

loc_546C:
moveq #mus_FadeOut,d0 ; Start demo by fading out music
bsr.w Play_Sound_2
bsr.w Play_Sound
move.w (Next_demo_number).w,d0 ; Get demo number
cmpi.w #3,d0
bhs.s loc_547E
Expand Down Expand Up @@ -6893,7 +6872,7 @@ Level:
tst.w (Demo_mode_flag).w
bmi.s loc_5FC4
moveq #mus_FadeOut,d0 ; If a demo
bsr.w Play_Sound_2
bsr.w Play_Sound

loc_5FC4:
clr.w (Ending_running_flag).w
Expand Down Expand Up @@ -9699,7 +9678,7 @@ LevelSelect_StartZone:
move.l #5000,(Next_extra_life_score).w
move.l #5000,(Next_extra_life_score_P2).w
moveq #mus_FadeOut,d0
jsr (Play_Sound_2).l
jsr (Play_Sound).l
moveq #0,d0
move.w d0,(Competition_mode_monitors).w
move.w d0,(Competition_mode).w
Expand Down Expand Up @@ -9774,16 +9753,31 @@ loc_7ED6:

loc_7EE4:
move.w d0,(Sound_test_sound).w
btst #5,d1
btst #4,d1
beq.s loc_7EF8
move.w (Sound_test_sound).w,d0
jsr (Play_Sound).l
moveq #mus_MutePSG,d0
jmp (Play_Sound).l
; ---------------------------------------------------------------------------

loc_7EF8:
btst #4,d1
btst #5,d1
beq.s locret_7F06
moveq #mus_MutePSG,d0
jsr (Play_Sound).l
move.w (Sound_test_sound).w,d0
if sfx_First<>0
cmpi.b #sfx_First,d0
blo.s .play_music
endif
if sfx_First<$ff
cmpi.b #sfx__End,d0
bhi.s .play_music
endif
jmp (Play_Sound_2).l
; ---------------------------------------------------------------------------

.play_music:
jmp (Play_Sound).l

; ---------------------------------------------------------------------------

locret_7F06:
rts
Expand Down Expand Up @@ -11673,7 +11667,7 @@ loc_9838:
subq.w #1,(Special_stage_rings_left).w
bne.s loc_984C
moveq #sfx_Perfect,d0
jsr (Play_Sound).l
jsr (Play_Sound_2).l

loc_984C:
addi.w #1,(Special_stage_ring_count).w
Expand All @@ -11687,7 +11681,7 @@ loc_984C:
bne.s loc_987E
addq.b #1,(Continue_count).w
move.w #$FF00|sfx_Continue,d0
jmp (Play_Sound).l
jmp (Play_Sound_2).l
; ---------------------------------------------------------------------------

loc_987E:
Expand Down Expand Up @@ -12024,7 +12018,7 @@ sub_9B62:
cmpi.w #2,(Special_stage_clear_timer).w
bne.s loc_9B8C
moveq #sfx_AllSpheres,d0
jsr (Play_Sound).l
jsr (Play_Sound_2).l

loc_9B8C:
cmpi.w #$40,(Special_stage_clear_timer).w
Expand Down Expand Up @@ -40151,7 +40145,7 @@ loc_1D8DA:

loc_1D8F6:
moveq #sfx_RingRight,d0
jmp (Play_Sound).l
jmp (Play_Sound_2).l
; ---------------------------------------------------------------------------

loc_1D8FE:
Expand Down Expand Up @@ -40190,7 +40184,7 @@ Monitor_Give_Fire_Shield:
bset #0,$2B(a1)
bset #4,$2B(a1)
moveq #sfx_FireShield,d0
jsr (Play_Sound).l
jsr (Play_Sound_2).l
tst.b $43(a0)
bne.s loc_1D984
move.l #Obj_Fire_Shield,(Shield).w
Expand All @@ -40210,7 +40204,7 @@ Monitor_Give_Lightning_Shield:
bset #0,$2B(a1)
bset #5,$2B(a1)
moveq #sfx_ElectricShield,d0
jsr (Play_Sound).l
jsr (Play_Sound_2).l
tst.b $43(a0)
bne.s loc_1D9C2
move.l #Obj_Lightning_Shield,(Shield).w
Expand All @@ -40230,7 +40224,7 @@ Monitor_Give_Bubble_Shield:
bset #0,$2B(a1)
bset #6,$2B(a1)
moveq #sfx_BubbleShield,d0
jsr (Play_Sound).l
jsr (Play_Sound_2).l
tst.b $43(a0)
bne.s loc_1DA00
move.l #Obj_Bubble_Shield,(Shield).w
Expand Down Expand Up @@ -64938,9 +64932,9 @@ loc_300C8:
bmi.s loc_30100
clr.b (Palette_cycle_counters+$00).w
move.w #$FF00|mus_MutePSG,d0
jsr (Play_Sound_2).l
jsr (Play_Sound).l
move.w #$FF00|mus_StopSFX,d0
jsr (Play_Sound_2).l
jsr (Play_Sound).l
move.w #$96,$30(a0)
move.l #loc_30106,(a0)
rts
Expand Down Expand Up @@ -65260,11 +65254,11 @@ loc_3052A:
tst.b 4(a0)
bmi.s loc_3056E
move.w #$FF00|mus_StopSFX,d0
jsr (Play_Sound_2).l
jsr (Play_Sound).l
move.w #$FF00|mus_MutePSG,d0
jsr (Play_Sound_2).l ; this will actually never play... Why is any of this here?
jsr (Play_Sound).l ; this will actually never play... Why is any of this here?
move.w #$FF00|mus_StopSFX,d0
jsr (Play_Sound_2).l
jsr (Play_Sound).l
move.b #0,(Palette_cycle_counters+$00).w
move.w respawn_addr(a0),d0
beq.s loc_30560
Expand Down Expand Up @@ -99021,7 +99015,7 @@ loc_4BE10:
bne.s loc_4BE32
addq.b #1,(Continue_count).w
moveq #sfx_Continue,d0
jsr (Play_Sound).l
jsr (Play_Sound_2).l

loc_4BE32:
moveq #0,d4
Expand Down Expand Up @@ -128707,7 +128701,7 @@ loc_611D6:
moveq #4,d0
bsr.w sub_61254
moveq #sfx_FireShield,d0
jmp (Play_Sound).l
jmp (Play_Sound_2).l
; ---------------------------------------------------------------------------

loc_61200:
Expand All @@ -128719,7 +128713,7 @@ loc_61200:
moveq #6,d0
bsr.w sub_61254
moveq #sfx_BubbleShield,d0
jmp (Play_Sound).l
jmp (Play_Sound_2).l
; ---------------------------------------------------------------------------

loc_6122A:
Expand All @@ -128731,7 +128725,7 @@ loc_6122A:
moveq #5,d0
bsr.w sub_61254
moveq #sfx_ElectricShield,d0
jmp (Play_Sound).l
jmp (Play_Sound_2).l

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -182228,7 +182222,7 @@ loc_86116:

loc_86132:
moveq #sfx_RingRight,d0
jmp (Play_Sound).l
jmp (Play_Sound_2).l
; ---------------------------------------------------------------------------

loc_8613A:
Expand Down Expand Up @@ -189509,7 +189503,7 @@ loc_8A6C6:
move.l #loc_8A656,(a0)
bclr #1,$38(a0)
moveq #mus_StopSFX,d0
jsr (Play_Sound_2).l
jsr (Play_Sound).l
jmp Sprite_CheckDeleteTouch(pc)
; ---------------------------------------------------------------------------
word_8A6DE: dc.w $40
Expand Down
2 changes: 1 addition & 1 deletion sonic3k.constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ mus_DataSelect ds.b 1 ; $2F
mus_FinalBoss ds.b 1 ; $30
mus_Drowning ds.b 1 ; $31
mus_Ending ds.b 1 ; $32
mus_CreditsK ds.b 1 ; $DC - Can also be treated as SFX?
Mus__End = * ; next ID after last music

; ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1281,7 +1282,6 @@ sfx_UnknownSaw ds.b 1 ; $D8
sfx_MagneticSpike ds.b 1 ; $D9
sfx_LeafBlower ds.b 1 ; $DA
sfx_WaterSkid ds.b 1 ; $DB
mus_CreditsK ds.b 1 ; $DC - Can also be treated as SFX?
ds.b 3 ; unused SFX slots, the driver will happily play them though
sfx__End = * ; next ID after the last sound effect

Expand Down

0 comments on commit 49433a4

Please sign in to comment.