compile for spc700 with bass

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
dangu
Posts: 11
Joined: Wed Apr 08, 2020 3:20 am

compile for spc700 with bass

Post by dangu »

Maybe this as been discussed several times, or is beyond my comprension. SPC700 on snes, when I first approached to the concept, it felt like pure programming madness... After writing a succesfull program to transfer data to the spc700, I decided to write a firmware for it, to play the music and comunicate with the snes. I decided to use bass with the table instruction set for that processor. With version v14 under debian, I can't even compile a nop intruction!! Can't find any documentation about. It seems like this chip was developped with the purpose in mind to drive programmers to insanity...

This is the error I get

Code: Select all

michele@michele:/raid/programmazione/Snes/tool/bass_v14/binary$ ./bass test2.asmerror: unrecognized arch spc700n.arch
test2.asm:1:1: arch spc700n.arch
bass: assembly failed
This is the source

Code: Select all

arch spc700n.arch
output "test.bin", create

origin $0000
  
nop
nop
spc700n.arch is in the same directory of the bass binary

Code: Select all

endian lsb

mov a,x          ;$7d
mov a,y          ;$dd
mov x,a          ;$5d
mov y,a          ;$fd
mov x,sp         ;$9d
mov sp,x         ;$bd
mov a,(x)        ;$e6
mov a,(x)+       ;$bf
mov a,[*08+x]    ;$e7 =a
mov a,[*08]+y    ;$f7 =a
mov a,#*08       ;$e8 =a
mov a,!*16+x     ;$f5 =a
mov a,!*16+y     ;$f6 =a
mov a,!*16       ;$e5 =a
mov a,*08+x      ;$f4 =a
mov a,*08        ;$e4 =a
mov x,#*08       ;$cd =a
mov x,*08+y      ;$f9 =a
mov x,!*16       ;$e9 =a
mov x,*08        ;$f8 =a
mov y,#*08       ;$8d =a
mov y,*08+x      ;$fb =a
mov y,!*16       ;$ec =a
mov y,*08        ;$eb =a
mov (x),a        ;$c6
mov (x)+,a       ;$af
mov [*08+x],a    ;$c7 =a
mov [*08]+y,a    ;$d7 =a
mov *08,#*08     ;$8f =b =a
mov !*16+x,a     ;$d5 =a
mov !*16+y,a     ;$d6 =a
mov *08+x,a      ;$d4 =a
mov !*16,a       ;$c5 =a
mov *08,a        ;$c4 =a
mov *08+y,x      ;$d9 =a
mov !*16,x       ;$c9 =a
mov *08,x        ;$d8 =a
mov *08+x,y      ;$db =a
mov !*16,y       ;$cc =a
mov *08,y        ;$cb =a
mov *08,*08      ;$fa =b =a

adc a,(x)        ;$86
adc (x),(y)      ;$99
adc a,[*08+x]    ;$87 =a
adc a,[*08]+y    ;$97 =a
adc a,#*08       ;$88 =a
adc *08,#*08     ;$98 =b =a
adc a,!*16+x     ;$95 =a
adc a,!*16+y     ;$96 =a
adc a,*08+x      ;$94 =a
adc a,!*16       ;$85 =a
adc a,*08        ;$84 =a
adc *08,*08      ;$89 =b =a

sbc a,(x)        ;$a6
sbc (x),(y)      ;$b9
sbc a,[*08+x]    ;$a7 =a
sbc a,[*08]+y    ;$b7 =a
sbc a,#*08       ;$a8 =a
sbc *08,#*08     ;$b8 =b =a
sbc a,!*16+x     ;$b5 =a
sbc a,!*16+y     ;$b6 =a
sbc a,*08+x      ;$b4 =a
sbc a,!*16       ;$a5 =a
sbc a,*08        ;$a4 =a
sbc *08,*08      ;$a9 =b =a

cmp a,(x)        ;$66
cmp (x),(y)      ;$79
cmp a,[*08+x]    ;$67 =a
cmp a,[*08]+y    ;$77 =a
cmp a,#*08       ;$68 =a
cmp a,!*16+x     ;$75 =a
cmp a,!*16+y     ;$76 =a
cmp a,*08+x      ;$74 =a
cmp a,!*16       ;$65 =a
cmp a,*08        ;$64 =a
cmp x,#*08       ;$c8 =a
cmp x,!*16       ;$1e =a
cmp x,*08        ;$3e =a
cmp y,#*08       ;$ad =a
cmp y,!*16       ;$5e =a
cmp y,*08        ;$7e =a
cmp *08,#*08     ;$78 =b =a
cmp *08,*08      ;$69 =b =a

and a,(x)        ;$26
and (x),(y)      ;$39
and a,[*08+x]    ;$27 =a
and a,[*08]+y    ;$37 =a
and a,#*08       ;$28 =a
and *08,#*08     ;$38 =b =a
and a,!*16+x     ;$35 =a
and a,!*16+y     ;$36 =a
and a,*08+x      ;$34 =a
and a,!*16       ;$25 =a
and a,*08        ;$24 =a
and *08,*08      ;$29 =b =a

or a,(x)         ;$06
or (x),(y)       ;$19
or a,[*08+x]     ;$07 =a
or a,[*08]+y     ;$17 =a
or a,#*08        ;$08 =a
or a,!*16+x      ;$15 =a
or a,!*16+y      ;$16 =a
or a,!*16        ;$05 =a
or a,*08+x       ;$14 =a
or a,*08         ;$04 =a
or *08,#*08      ;$18 =b =a
or *08,*08       ;$09 =b =a

eor a,(x)        ;$46
eor (x),(y)      ;$59
eor a,[*08+x]    ;$47 =a
eor a,[*08]+y    ;$57 =a
eor a,#*08       ;$48 =a
eor *08,#*08     ;$58 =b =a
eor a,!*16+x     ;$55 =a
eor a,!*16+y     ;$56 =a
eor a,*08+x      ;$54 =a
eor a,!*16       ;$45 =a
eor a,*08        ;$44 =a
eor *08,*08      ;$49 =b =a

inc a            ;$bc
inc x            ;$3d
inc y            ;$fc
inc *08+x        ;$bb =a
inc !*16         ;$ac =a
inc *08          ;$ab =a

dec a            ;$9c
dec x            ;$1d
dec y            ;$dc
dec *08+x        ;$9b =a
dec !*16         ;$8c =a
dec *08          ;$8b =a

asl a            ;$1c
asl *08+x        ;$1b =a
asl !*16         ;$0c =a
asl *08          ;$0b =a

lsr a            ;$5c
lsr *08+x        ;$5b =a
lsr !*16         ;$4c =a
lsr *08          ;$4b =a

rol a            ;$3c
rol *08+x        ;$3b =a
rol !*16         ;$2c =a
rol *08          ;$2b =a

ror a            ;$7c
ror *08+x        ;$7b =a
ror !*16         ;$6c =a
ror *08          ;$6b =a

xcn a            ;$9f

movw ya,*08      ;$ba =a
movw *08,ya      ;$da =a

incw *08         ;$3a =a
decw *08         ;$1a =a
addw ya,*08      ;$7a =a
subw ya,*08      ;$9a =a
cmpw ya,*08      ;$5a =a

mul ya           ;$cf
div ya,x         ;$9e

das a            ;$be
daa a            ;$df

bra *08          ;$2f +2a
beq *08          ;$f0 +2a
bne *08          ;$d0 +2a
bcs *08          ;$b0 +2a
bcc *08          ;$90 +2a
bvs *08          ;$70 +2a
bvc *08          ;$50 +2a
bmi *08          ;$30 +2a
bpl *08          ;$10 +2a
bbs *08.*03,*08  ;=b %00011 =a +3c
bbc *08.*03,*08  ;=b %10011 =a +3c
cbne *08+x,*08   ;$de =a +3b
cbne *08,*08     ;$2e =a +3b
dbnz y,*08       ;$fe +2a
dbnz *08,*08     ;$6e =a +3b
jmp !*16         ;$5f =a
jmp [!*16+x]     ;$1f =a

call !*16        ;$3f =a
pcall *08        ;$4f =a
tcall *04        ;=a %0001
brk              ;$0f

ret              ;$6f
reti             ;$7f

push a           ;$2d
push x           ;$4d
push y           ;$6d
push psw         ;$0d

pop a            ;$ae
pop x            ;$ce
pop y            ;$ee
pop psw          ;$8e

set1 *08.*03      ;=b %00010 =a
clr1 *08.*03      ;=b %10010 =a

tset1 !*16       ;$0e =a
tclr1 !*16       ;$4e =a

and1 c,/*13.*03  ;$6a ~b ~a
and1 c,*13.*03   ;$4a ~b ~a
or1 c,/*13.*03   ;$2a ~b ~a
or1 c,*13.*03    ;$0a ~b ~a
eor1 c,*13.*03   ;$8a ~b ~a
not1 *13.*03     ;$ea ~b ~a
mov1 c,*13.*03   ;$aa ~b ~a
mov1 *13.*03,c   ;$ca ~b ~a

clrc             ;$60
setc             ;$80
notc             ;$ed
clrv             ;$e0
clrp             ;$20
setp             ;$40
ei               ;$a0
di               ;$c0

nop              ;$00
sleep            ;$ef
stop             ;$ff
This is for sure a problem about program usage, but can't figure out what
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: compile for spc700 with bass

Post by Pokun »

I don't know how much of this matters (and documentation doesn't tell everything) but I did it like so:

Code: Select all

architecture spc700n
output "test.bin", create
origin $0000
  nop
The spc700n.arch file shouldn't be in the same directory as bass. It should be in a directory named "architectures" which in turn is in the same directory as bass.


BTW is spc700n.arch the one I made by any chance?
dangu
Posts: 11
Joined: Wed Apr 08, 2020 3:20 am

Re: compile for spc700 with bass

Post by dangu »

Pokun wrote: Fri Mar 12, 2021 12:58 pm The spc700n.arch file shouldn't be in the same directory as bass. It should be in a directory named "architectures" which in turn is in the same directory as bass.
Nope.. Does not compile.. spc700n.arch is in both arch, architecture and same directory as bass, but still does no compile
Pokun wrote: Fri Mar 12, 2021 12:58 pm BTW is spc700n.arch the one I made by any chance?
It may be. Found using search on the forum here
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: compile for spc700 with bass

Post by Pokun »

Did you try my example exactly as I typed? Your example doesn't work for me on bass v15 which I used. The directory is not "architecture" it should be "architectures".

Here is a compiled bass with documentation. It's not the latest version but it's the latest Windows binary build I could find and it works for me.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: compile for spc700 with bass

Post by calima »

Remember that bass changed syntax many times over development. An arch file or sample code from years ago may not work with today's bass. It was a PITA to find a version able to compile Shiru's GSS source.
dangu
Posts: 11
Joined: Wed Apr 08, 2020 3:20 am

Re: compile for spc700 with bass

Post by dangu »

Pokun wrote: Fri Mar 12, 2021 2:48 pm Did you try my example exactly as I typed? Your example doesn't work for me on bass v15 which I used. The directory is not "architecture" it should be "architectures".

Here is a compiled bass with documentation. It's not the latest version but it's the latest Windows binary build I could find and it works for me.
With v15 you posted, it was assembled with no problem using wine!
Maybe it was syntax issue of v14 I was using? :roll:
Now I'm trying to compile the binaries from source to have a linux version of the assembler, but without success...

Code: Select all

michele@michele:/raid/programmazione/Snes/tool/bass_v15/bass$ make
g++-4.9 -x c++ -std=c++14  -O3 -fno-strict-aliasing -fwrapv -I.. -o obj/bass.o -c bass.cpp
make: g++-4.9: Command not found
make: *** [GNUmakefile:14: obj/bass.o] Error 127
dangu
Posts: 11
Joined: Wed Apr 08, 2020 3:20 am

Re: compile for spc700 with bass

Post by dangu »

Oh! another syntax question.
How do I define costants and macros?? And correct syntax for labels and comments? :roll:
For exemple, this does not work

Code: Select all

#define KON $4C
.
.
mov a,#KON
nor this

Code: Select all

.MACRO WDSP
	mov a,#\1
	mov y,#\2
.ENDM
I'm using the arch with the native spc700 syntax
dangu
Posts: 11
Joined: Wed Apr 08, 2020 3:20 am

Re: compile for spc700 with bass

Post by dangu »

Ok. I'm starting to understand this not-so-standard syntax... I manged to write a simple program to init the dsp chip, and hopefully play a squarewave on channel 0, but obviously it does not work.. maybe I missed something to initialize??
This should reset all DSP RAM, init volumes, pitch, adsr, gain and set source on sample 0, then play a note forever, but I only get a random blip on rom load :roll:

Code: Select all

architecture spc700n
output "firmware.bin", create

//SPC REGISTERS

define	UNDOCUMENTED	=$F0	//Undocumented	?/W
define	CONTROL		=$F1	//Control Register	/W
define	DSPADD		=$F2	//DSP Register Address	R/W
define	DSPDATA		=$F3	//DSP Register Data	R/W
define	APU0		=$F4	//Port 0	R/W
define	APU1		=$F5	//Port 1	R/W
define	APU2		=$F6	//Port 2	R/W
define	APU3		=$F7	//Port 3	R/W
//define	UNDOCUMENTED	=$F8	//Regular Memory	R/W
//define	UNDOCUMENTED	=$F9	//Regular Memory	R/W
define	TMR0L		=$FA	//Timer-0	/W
define	TMR1L		=$FB	//Timer-1	/W
define	TMR2L		=$FC	//Timer-2	/W
define	TMR0H		=$FD	//Counter-0	R/
define	TMR1H		=$FE	//Counter-1	R/
define	TMR2H		=$FF	//Counter-2	R/

//DSP ADDRESSES

define	CH0VOLL		=$00	//VOL (L)	Left channel volume.
define	CH0VOLR		=$01	//VOL (R)	Right channel volume.
define	CH0PITCHL	=$02	//P (L)		Lower 8 bits of pitch.
define	CH0PITCHH	=$03	//P (H)		Higher 8-bits of pitch.
define	CH0SRCN		=$04	//SRCN		Source number (0-255). (references the source directory)
define	CH0ADSR1	=$05	//ADSR (1)	If bit7 is set, ADSR is enabled. If cleared GAIN is used.
define	CH0ADSR2	=$06	//ADSR (2)	These two registers control the ADSR envelope.
define	CH0GAIN		=$07	//GAIN		This register provides function for software envelopes.
define	CH0ENVX		=$08	//-ENVX		The DSP writes the current value of the envelope to this register. (read it)
define	CH0OUTX		=$09	//-OUTX		The DSP writes the current waveform value after envelope multiplication and before volume multiplication.

define	MAINVOLL	=$0C	//MVOL (L)	Main Volume (left output)
define	MAINVOLR	=$1C	//MVOL (R)	Main Volume (right output)
define	ECHOVOLL	=$2C	//EVOL (L)	Echo Volume (left output)
define	ECHOVOLR	=$3C	//EVOL (R)	Echo Volume (right output)
define	KON		=$4C	//KON		Key On (1 bit for each voice)
define	KOF		=$5C	//KOF		Key Off (1 bit for each voice)
define	DSPFLAGS	=$6C	//FLG		DSP Flags. (used for MUTE,ECHO,RESET,NOISE CLOCK)
define	ENDX		=$7C	//-ENDX		1 bit for each voice.
define	ECHOFBK		=$0D	//EFB		Echo Feedback
				//1D		---	Not used
define	PITCHMOD	=$2D	//PMON		Pitch modulation
define	NOISE_EN	=$3D	//NON		Noise enable
define	ECHO_EN		=$4D	//EON		Echo enable
define	DIR		=$5D	//DIR		Offset of source directory (DIR*100h = memory offset)
define	ESA		=$6D	//ESA		Echo buffer start offset (ESA*100h = memory offset)
define	EDL		=$7D	//EDL		Echo delay, 4-bits, higher values require more memory.
//define	COEF	=$xF	//COEF		8-tap FIR Filter coefficients




origin $0200
  nop


//RESET DSP RAM
    mov a,#$00			//Dsp address
    mov y,#$00			//dsp data
dspCLEAR:
    movw {DSPADD},ya		//Scrive address+data direttamente con 1 comando
    inc a			//incrementa a
    bne	dspCLEAR	

//INIT CHANNEL STUFF
    mov a,#{DIR}		//
    mov y,#$04			//Sample directory  $0400
    movw {DSPADD},ya		//Write address+data in one cmnd


    mov a,#{MAINVOLL}		//Master volume L
    mov y,#$7f			//
    movw {DSPADD},ya		//
    mov a,#{MAINVOLR}		//Master volume R
    movw {DSPADD},ya		//

    mov a,#{CH0VOLL}		//Channel 0 volume L
    mov y,#$7f			//
    movw {DSPADD},ya		//
    mov a,#{CH0VOLR}		//Channel 0 volume R
    movw {DSPADD},ya		//

    mov a,#{CH0SRCN}		//Canale 0 source Sample 
    mov y,#$00			//num 0
    movw {DSPADD},ya		//

    mov a,#{CH0PITCHL}		//PITCH LOW
    mov y,#$9A			//
    movw {DSPADD},ya		//
    mov a,#{CH0PITCHH}		//PITCH HIGH
    mov y,#$00			//
    movw {DSPADD},ya		//

    mov a,#{CH0ADSR1}		//adsr1
    mov y,#$ff			//
    movw {DSPADD},ya		//

    mov a,#{CH0ADSR2}		//adsr2
    mov y,#$e0			//
    movw {DSPADD},ya		//

    mov a,#{CH0GAIN}		//gain
    mov y,#$a0			//
    movw {DSPADD},ya		//

//PLAY!!!...but not
    mov a,#{KON}		//KEY ON
    mov y,#$01			//CH0
    movw {DSPADD},ya		//


nop

//4ever loop
lollll:
bra lollll

origin $0400

//square wave sample???
db  $C7, $FF, $FF, $FF, $FF, $00, $00, $00, $00

origin $0600
This is loaded correctly in the APU, I'm using bsnes as for debug
dangu
Posts: 11
Joined: Wed Apr 08, 2020 3:20 am

Re: compile for spc700 with bass

Post by dangu »

dangu wrote: Sun Mar 14, 2021 12:22 pm Ok. I'm starting to understand this not-so-standard syntax... I manged to write a simple program to init the dsp chip, and hopefully play a squarewave on channel 0, but obviously it does not work.. maybe I missed something to initialize??
This should reset all DSP RAM, init volumes, pitch, adsr, gain and set source on sample 0, then play a note forever, but I only get a random blip on rom load :roll:

Code: Select all

architecture spc700n
output "firmware.bin", create

//SPC REGISTERS

define	UNDOCUMENTED	=$F0	//Undocumented	?/W
define	CONTROL		=$F1	//Control Register	/W
define	DSPADD		=$F2	//DSP Register Address	R/W
define	DSPDATA		=$F3	//DSP Register Data	R/W
define	APU0		=$F4	//Port 0	R/W
define	APU1		=$F5	//Port 1	R/W
define	APU2		=$F6	//Port 2	R/W
define	APU3		=$F7	//Port 3	R/W
//define	UNDOCUMENTED	=$F8	//Regular Memory	R/W
//define	UNDOCUMENTED	=$F9	//Regular Memory	R/W
define	TMR0L		=$FA	//Timer-0	/W
define	TMR1L		=$FB	//Timer-1	/W
define	TMR2L		=$FC	//Timer-2	/W
define	TMR0H		=$FD	//Counter-0	R/
define	TMR1H		=$FE	//Counter-1	R/
define	TMR2H		=$FF	//Counter-2	R/

//DSP ADDRESSES

define	CH0VOLL		=$00	//VOL (L)	Left channel volume.
define	CH0VOLR		=$01	//VOL (R)	Right channel volume.
define	CH0PITCHL	=$02	//P (L)		Lower 8 bits of pitch.
define	CH0PITCHH	=$03	//P (H)		Higher 8-bits of pitch.
define	CH0SRCN		=$04	//SRCN		Source number (0-255). (references the source directory)
define	CH0ADSR1	=$05	//ADSR (1)	If bit7 is set, ADSR is enabled. If cleared GAIN is used.
define	CH0ADSR2	=$06	//ADSR (2)	These two registers control the ADSR envelope.
define	CH0GAIN		=$07	//GAIN		This register provides function for software envelopes.
define	CH0ENVX		=$08	//-ENVX		The DSP writes the current value of the envelope to this register. (read it)
define	CH0OUTX		=$09	//-OUTX		The DSP writes the current waveform value after envelope multiplication and before volume multiplication.

define	MAINVOLL	=$0C	//MVOL (L)	Main Volume (left output)
define	MAINVOLR	=$1C	//MVOL (R)	Main Volume (right output)
define	ECHOVOLL	=$2C	//EVOL (L)	Echo Volume (left output)
define	ECHOVOLR	=$3C	//EVOL (R)	Echo Volume (right output)
define	KON		=$4C	//KON		Key On (1 bit for each voice)
define	KOF		=$5C	//KOF		Key Off (1 bit for each voice)
define	DSPFLAGS	=$6C	//FLG		DSP Flags. (used for MUTE,ECHO,RESET,NOISE CLOCK)
define	ENDX		=$7C	//-ENDX		1 bit for each voice.
define	ECHOFBK		=$0D	//EFB		Echo Feedback
				//1D		---	Not used
define	PITCHMOD	=$2D	//PMON		Pitch modulation
define	NOISE_EN	=$3D	//NON		Noise enable
define	ECHO_EN		=$4D	//EON		Echo enable
define	DIR		=$5D	//DIR		Offset of source directory (DIR*100h = memory offset)
define	ESA		=$6D	//ESA		Echo buffer start offset (ESA*100h = memory offset)
define	EDL		=$7D	//EDL		Echo delay, 4-bits, higher values require more memory.
//define	COEF	=$xF	//COEF		8-tap FIR Filter coefficients




origin $0200
  nop


//RESET DSP RAM
    mov a,#$00			//Dsp address
    mov y,#$00			//dsp data
dspCLEAR:
    movw {DSPADD},ya		//Scrive address+data direttamente con 1 comando
    inc a			//incrementa a
    bne	dspCLEAR	

//INIT CHANNEL STUFF
    mov a,#{DIR}		//
    mov y,#$04			//Sample directory  $0400
    movw {DSPADD},ya		//Write address+data in one cmnd


    mov a,#{MAINVOLL}		//Master volume L
    mov y,#$7f			//
    movw {DSPADD},ya		//
    mov a,#{MAINVOLR}		//Master volume R
    movw {DSPADD},ya		//

    mov a,#{CH0VOLL}		//Channel 0 volume L
    mov y,#$7f			//
    movw {DSPADD},ya		//
    mov a,#{CH0VOLR}		//Channel 0 volume R
    movw {DSPADD},ya		//

    mov a,#{CH0SRCN}		//Canale 0 source Sample 
    mov y,#$00			//num 0
    movw {DSPADD},ya		//

    mov a,#{CH0PITCHL}		//PITCH LOW
    mov y,#$9A			//
    movw {DSPADD},ya		//
    mov a,#{CH0PITCHH}		//PITCH HIGH
    mov y,#$00			//
    movw {DSPADD},ya		//

    mov a,#{CH0ADSR1}		//adsr1
    mov y,#$ff			//
    movw {DSPADD},ya		//

    mov a,#{CH0ADSR2}		//adsr2
    mov y,#$e0			//
    movw {DSPADD},ya		//

    mov a,#{CH0GAIN}		//gain
    mov y,#$a0			//
    movw {DSPADD},ya		//

//PLAY!!!...but not
    mov a,#{KON}		//KEY ON
    mov y,#$01			//CH0
    movw {DSPADD},ya		//


nop

//4ever loop
lollll:
bra lollll

origin $0400

//square wave sample???
db  $C7, $FF, $FF, $FF, $FF, $00, $00, $00, $00

origin $0600
This is loaded correctly in the APU, I'm using bsnes as for debug
Solved... I wasn't passing the correct pointer in the sample directory....
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: compile for spc700 with bass

Post by Pokun »

Good that you figured it out.
Yeah syntax is weird and seems to change all the time between versions like Calima said.

Some things like "variable declarations" in RAM requires macro as there is no directive for reserving address space.
This is how I did it:

Code: Select all

//Macro definitions:
  macro res(variable size) {  //reserves storage in address space
    base (pc() + size)        //usable for defining variables in RAM
  }
  
  macro lo(variable n) {      //takes out the low byte of a 16-bit value
    n & $00FF
  }
  
  macro hi(variable n) {      //takes out the high byte of a 16-bit value
    (n & $FF00) >> 8
  }

//RAM defines:
  base $0000        //Page 0 Audio RAM ($0000~$00EF, 240 B)
reg0:
  res(8)            //general-purpose work register
pointer0:
  res(2)            //general-purpose pointer

  base $0100        //Page 1 Audio RAM ($0100~$01FF, 256 B)
reg1:
  res(8)            //general-purpose work register

  base $0180
stack:
  res(128)          //top 128 byte of page 1 reserved for stack
  base $0200        //Page 2~ Audio work RAM ($0200~$07FF, 1 536 B)
I'm glad that the native syntax I made got some use. I think I'm just going to use ca65 (with the SPC700 macro pack) for S-APU coding in the future though.


BTW I think you want a "clrp" somewhere early in your program to make sure page 0 is the direct page. Stack pointer is set by the IPL-ROM, but I set mine to $FF.
dangu
Posts: 11
Joined: Wed Apr 08, 2020 3:20 am

Re: compile for spc700 with bass

Post by dangu »

Pokun wrote: Mon Mar 15, 2021 7:09 am Good that you figured it out.
Yeah syntax is weird and seems to change all the time between versions like Calima said.

Some things like "variable declarations" in RAM requires macro as there is no directive for reserving address space.
This is how I did it:

Code: Select all

//Macro definitions:
  macro res(variable size) {  //reserves storage in address space
    base (pc() + size)        //usable for defining variables in RAM
  }
  
  macro lo(variable n) {      //takes out the low byte of a 16-bit value
    n & $00FF
  }
  
  macro hi(variable n) {      //takes out the high byte of a 16-bit value
    (n & $FF00) >> 8
  }

//RAM defines:
  base $0000        //Page 0 Audio RAM ($0000~$00EF, 240 B)
reg0:
  res(8)            //general-purpose work register
pointer0:
  res(2)            //general-purpose pointer

  base $0100        //Page 1 Audio RAM ($0100~$01FF, 256 B)
reg1:
  res(8)            //general-purpose work register

  base $0180
stack:
  res(128)          //top 128 byte of page 1 reserved for stack
  base $0200        //Page 2~ Audio work RAM ($0200~$07FF, 1 536 B)
I'm glad that the native syntax I made got some use. I think I'm just going to use ca65 (with the SPC700 macro pack) for S-APU coding in the future though.


BTW I think you want a "clrp" somewhere early in your program to make sure page 0 is the direct page. Stack pointer is set by the IPL-ROM, but I set mine to $FF.
Thanks for the suggestions.
Right now I was playing around with the ADSR filter, but noticed some strange things.
First, if KON is set for a channel and then immediately reset to 0, the note won't be triggered. It needs to wait an unknown time before resetting the register.
Second I was expecting the note to be played on KON, and remain on sustain level indefinitely untill KOF is triggered for release to occour, but this is not the case. Note is played through ADSR but fades out without to wait for KOF.. This is waird.
Third, I still got some obscure points about BRR samples in relation to the pitch it needs to be played. For exemple.. I'd like to sample an electric bass and I'm using audacity to produce a wav file. At which frequency should it be recorded and which note to sample to do an efficent/good brr sample? And after this, how to calculate the PITCH value for the DSP to reproduce the same recorded pitch?
Is there some doc that covers brr reduction with some exemple??
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: compile for spc700 with bass

Post by Pokun »

I think the devdocs mentions that about KON and KOF. This is from my own notes:

Code: Select all

DSP_KON      = $4C
DSP_KOF      = $5C
Key ON and Key OFF Registers
In both registers, D0~D7 corresponds to each voice 0~7. Both registers are
active when 1 and inactive when 0, but they don't need to be cleared.
When setting a bit in KON, the corresponding voice will start or restart.
When setting a bit in KOF, the voice will fade out from 1 to 0 in a period of
8 ms, by subtracting the fixed value 1/256 continuously.
If writing KON and KOF in succession, waiting two Ts (62.5 μs) is necessary
or the written data may be useless.
As for what pitch you need for a BRR sample I have no idea. I remember reading a lot about it so there are details out there, but I don't remember, and haven't succeeded in making any samples other than simple synthetic ones (by entering the value manually to make square waves and so on).
Look at Nocash' fullsnes document, wiki.superfamicom.org and possibly the readme of Bregalad's BRR tool. The official devdocs might also say something.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: compile for spc700 with bass

Post by tepples »

In some ways it's a "how long is a piece of string?"-type question. What pitch do you need for a sample in OpenMPT?

Once you know that: The value written to the DSP's frequency register specifies sample rate in 7.8125 Hz units.
Post Reply