News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Need help with Gss codes  (Read 1067 times)

yugisokubodai

  • Full Member
  • ***
  • Posts: 141
    • View Profile
    • Assembly
Need help with Gss codes
« on: February 26, 2018, 07:51:04 am »
1. Ask one

I'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

Code: [Select]
.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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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.

Squall_FF8

  • Full Member
  • ***
  • Posts: 198
    • View Profile
Re: Need help with Gss codes
« Reply #1 on: February 26, 2018, 11:38:45 am »
I'm no expert. At first glance it seems OK. At second one thing bothers me:
Code: [Select]
AXY16
lda 7,s
sta.b gss_param
-------
REP #$30
LDA $07,s
STA {gss_param}
Does both codes produce same hex in STA? .b is used to designate byte in WLA. In the xkas code we have REP #$30 (A is 16 bit) so it should store 2 bytes not a single one.

If there is a way to compile both codes, you can compare the output and see where is the difference.

P.S. is the sound engine used in a game?

yugisokubodai

  • Full Member
  • ***
  • Posts: 141
    • View Profile
    • Assembly
Re: Need help with Gss codes
« Reply #2 on: February 26, 2018, 05:19:10 pm »
Yes, this is the sound engine.
I don't know what hex code Wla generates because Wla refuses to run with me forever.
But in xkas, we can use LDA.b to. But this seems to be useless.
I checked when A is 16 bits and both LDA and LDA.b reads 2 bytes.

mopoz

  • Jr. Member
  • **
  • Posts: 65
  • Russia, Vodka and Bears
    • View Profile
Re: Need help with Gss codes
« Reply #3 on: February 26, 2018, 06:34:48 pm »
My code for GSS
Code: [Select]
rep #$20
 lda.w #music
 sta $10
 sep #$20
 lda.b #music>>16
 sta.w $12
 rep #$20
 lda #end_music-music
 tax
 lda Music_adrSPC                                                       
 sta $2142
 jmp Load_INSPC

SPC_Driver:
 sei
 sep #$20
 lda #$aa
-
 cmp.w $2140
 bne -

 rep #$30
 stz $10
 sep #$20
 lda.b #$c1
 sta.w $12
 rep #$20
 lda #spc_driver_end
 tax
 lda #$01fe  //not $200                       
 sta $2142
Load_INSPC:
 sep #$20
 lda #$01
 sta $2141
 lda #$cc
 sta $2140
-
 cmp $2140
 bne -
 
 ldy #$0000
--
 xba
 lda [$10],y
 xba
 tya
 rep #$20
 sta $2140
 sep #$20
-
 cmp $2140
 bne -
 
 iny
 dex
 bne --
 
 xba
 lda #$00
 xba
 clc
 adc #$0c
 rep #$20
 tax
 lda #$0200
 sta $2142
 txa
 sta $2140
 sep #$20
-
 cmp $2140
 bne -
 
 rep #$20
-
 lda $2140
 ora $2142
 bne -
 cli
 rtl

SPC_Instalize:
 rep #$20
 lda #$0001
 sep #$20
 xba
 sta $2141
 xba
 sta $2140
-
 lda $2140
 beq -
 sep #$20
-
 lda $2140
 bne -
 rtl
Everthing works fine.
Skate-punk rulezzzz

Squall_FF8

  • Full Member
  • ***
  • Posts: 198
    • View Profile
Re: Need help with Gss codes
« Reply #4 on: February 27, 2018, 05:00:47 am »
Yes, this is the sound engine.
Maybe you didn't understand my question.  ;)

The question was: in what game that sound engine is used?

yugisokubodai

  • Full Member
  • ***
  • Posts: 141
    • View Profile
    • Assembly
Re: Need help with Gss codes
« Reply #5 on: February 27, 2018, 09:13:41 pm »
I use this (generated by GSS) for my own game.