1. Ask oneI'm using
Gss (
https://www.romhacking.net/utilities/1248/) to compose a song. Gss exports the data to 2 files: music_1.bin and spc700.bin. The spc700.bin has the sound driver. To communicate with the sound routine inside, one must use the 65816 routines included in snes\sneslib.asm. The problem is, I'm used to xkas style xyntax (the same as debugged code) while the samples in sneslib.asm are written for Wla, which uses different syntax. This led to many errors when I tried "converting" these routines to xkas style. So I post the original routines (for WLA) and my convert (for xkas plus, v14) here. Please correct me if you find the convert wrong.
spc_command_asm:
Original
.ifndef DISABLE_SOUND
A8
-
lda.l APU0
bne -
A16
lda.b gss_param
sta.l APU23
lda.b gss_command
A8
xba
sta.l APU1
xba
sta.l APU0
cmp.b #SCMD_LOAD ;don't wait acknowledge
beq +
-
lda.l APU0
beq -
+
.endif
rtl
My rewrite:
SEP #$20
waitapu0a:
LDA $2140
BNE waitapu0a
REP #$20
LDA {gss_param}
STA $2143
LDA {gss_command}
SEP #$20
XBA
STA $2141
XBA
STA $2140
CMP #({SCMD_LOAD)} //load the address of smcd_load
BEQ endrountine
waitapu0b:
LDA $2140
BEQ waitapu0b
RTL
spc_command:
Original code:
php
AXY16
lda 7,s ;param
sta.b gss_param
lda 5,s ;command
sta.b gss_command
jsl spc_command_asm
plp
rtl
Rewrite:
PHP
REP #$30
LDA $07,s
STA {gss_param}
LDA $05,s
STA {gss_command}
JSL spc_command_asm
PLP
RTL
spc_stereo:
Original code:
php
AXY16
lda 5,s ;stereo
sta.b gss_param
lda.w #SCMD_STEREO
sta.b gss_command
jsl spc_command_asm
plp
rtl
Rewrite:
PHP
REP #$30
LDA $05,s
STA {gss_param}
LDA #({SCMD_STEREO}) //load address of smcd_stereo
STA {gss_command}
JSL spc_command_asm
PLP
RTL
Other routines are the same.
2. Ask two:In the spc_stereo routine, we can see:
LDA $05,s
Can anyone explain to me why the author uses this relative stack addressing mode to read data. My understand is will be read data changes depend on the stack, and the stack changes depend on previous routine.