Skip to content

Commit

Permalink
Limit minigame error, dialog open, dialog close effects using sq2_sfx
Browse files Browse the repository at this point in the history
In the entrypoints, save the stack pointer S; and restore it in WaitForVBlank_L
instead of setting it to $FD, in case that would break an NSF player.

Label variables and add comments.
  • Loading branch information
aldonunez committed Feb 26, 2021
1 parent 37c7aa5 commit 21280fe
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 31 deletions.
Binary file modified Tools/ExtractRes/Data/nsf-sfx.bin
Binary file not shown.
6 changes: 3 additions & 3 deletions Tools/ExtractRes/Data/nsf-sfx.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
src_name, src_addr, dst_addr, length
, 0, 0, 6263
, 0, 0, 627A
rom, 2E04D, BD, 15
rom, 3AD94, E04, 2F
rom, 36EDF, F4F, 75
rom, 33EC8, 1F38, 148
rom, 3C010, 2080, 4000
nsf-sfx.bin, 0, 0, 80
nsf-sfx.bin, 80, 6080, 1E3
nsf-sfx.bin, 263, 5F28, 4
nsf-sfx.bin, 80, 6080, 1FA
nsf-sfx.bin, 27A, 5F28, 4
92 changes: 64 additions & 28 deletions Tools/ExtractRes/NsfSfx/nsf-sfx.asm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@

.SEGMENT "ENTRY"

; Variables for the NSF. As far I can tell, they're not used by the game.

NsfCurSfxId := $E0
NsfSfxCounter := $E1
NsfSavedS := $E2


; Code in the original game

Nsf_InitMenuConfirm := $AD84 ; bank E
Nsf_InitMenuCursor := $AD9D ; bank E
Nsf_InitMinigameError := $AF2C ; bank D
Expand Down Expand Up @@ -80,14 +89,14 @@ InitAddrs:
PlayAddrs:
.ADDR Nothing
.ADDR Nothing
.ADDR Nothing
.ADDR Nsf_PlaySimpleSq2
.ADDR Nsf_PlayAirship
.ADDR Nsf_PlayShip
.ADDR Nothing
.ADDR Nothing
.ADDR Nothing
.ADDR Nothing
.ADDR Nothing
.ADDR Nsf_PlaySimpleSq2
.ADDR Nsf_PlaySimpleSq2
.ADDR Nsf_PlayWipeOpen
.ADDR Nsf_PlayWipeClose
.ADDR Nsf_PlayFight
Expand All @@ -101,27 +110,31 @@ PlayAddrs:
.ADDR Nsf_PlayChaos

Nothing:
RTS
RTS

Init:
STA $E0
ASL
TAY
LDA InitAddrs, Y
STA $00
LDA InitAddrs+1, Y
STA $01
JMP ($0000)
TSX
STX NsfSavedS
STA NsfCurSfxId
ASL
TAY
LDA InitAddrs, Y
STA $00
LDA InitAddrs+1, Y
STA $01
JMP ($0000)

Play:
LDA $E0
ASL
TAY
LDA PlayAddrs, Y
STA $00
LDA PlayAddrs+1, Y
STA $01
JMP ($0000)
TSX
STX NsfSavedS
LDA NsfCurSfxId
ASL
TAY
LDA PlayAddrs, Y
STA $00
LDA PlayAddrs+1, Y
STA $01
JMP ($0000)


;=============================================================================
Expand All @@ -145,7 +158,27 @@ Play:

; Certain labels of data and code are based on Disch's disassembly.

tmp := $10

; Variables used by the game

tmp := $10
sq2_sfx := $7E


; MinigameError is also limited this way, and lasts $14 frames.

Nsf_PlaySimpleSq2:
; Limit the sound effect to the number of frames in sq2_fx,
; as the game does in MusicPlay [$B099 :: 0x370A9 (bank D)]
LDA sq2_sfx
BEQ :+
DEC sq2_sfx
BEQ :+
RTS
:
LDA #$30
STA $4004
RTS


Nsf_PlayAirship:
Expand All @@ -158,10 +191,14 @@ Nsf_PlayShip:


Nsf_InitDialogOpen:
LDA #$35
STA sq2_sfx
LDA #$8E
JMP $D6C7

Nsf_InitDialogClose:
LDA #$25
STA sq2_sfx
LDA #$95
JMP $D6C7

Expand Down Expand Up @@ -304,21 +341,20 @@ Nsf_PlayAltar:
; Jump into the middle of the MainLoop of DoAltarEffect, after the call to AltarFrame.
JMP $DA8E


Nsf_InitError:
LDY #$0F
STY $E1
; Won't return.
STY NsfSfxCounter
; Won't return normally, only by way of WaitForVBlank overlay.
JSR PlaySFX_Error
RTS

Nsf_PlayError:
LDA $E1
LDA NsfSfxCounter
BPL :+
RTS
:
JSR $DB4B
DEC $E1
DEC NsfSfxCounter
BMI :+
RTS
:
Expand All @@ -340,6 +376,6 @@ Nsf_PlayError:
; the NSF player wait for the next frame.

WaitForVBlank_L:
LDX #$FD ; Pop everything but the first address pushed
TXS ; by setting the stack pointer to $01FD.
LDX NsfSavedS ; Set the stack pointer to its original value
TXS ; in INIT and PLAY entrypoints.
RTS ; Now we can return from the game to the player.

0 comments on commit 21280fe

Please sign in to comment.