.spc file loading paradox question

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

.spc file loading paradox question

Post by psycopathicteen »

I've looked up the data format for .spc music files, and the format expects both the contents of RAM and what's in the registers themselves? How is it possible to load both at the same time?

The spc700 needs it's registers to copy memory, while it needs it's memory to load it's registers.
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: .spc file loading paradox question

Post by lidnariq »

SPC files are comprehensive dumps for emulators, not bare data to be uploaded to the coprocessor.

You might be able to get away with taking the last 0xFF00 bytes (not including the DSP parameters or registers) and just try uploading that. Maybe.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: .spc file loading paradox question

Post by tepples »

If you have composed original music for your game and are using a homebrew music engine, the music engine's manual and build process should be able to tell you 1. how much you actually need to upload and 2. how to change songs.

If all you have is a random SPC rip, and you're fine with not being able to change songs until reset, then in the majority of the cases, you should be able to load the DSP and timer registers through the IPL, and then just above the top of stack, add some code:

Code: Select all

  MOV X,#<here
  MOV SP,X
  MOV A,#a_value
  MOV X,#x_value
  MOV Y,#y_value
  MOV $00,#ram_0000
  MOV $01,#ram_0001
  RETI
here:
  .byte psw_value
  .addr pc_value
Optiroc
Posts: 129
Joined: Thu Feb 07, 2013 1:15 am
Location: Sweden

Re: .spc file loading paradox question

Post by Optiroc »

Blargg has that covered. The final stages of how the CPU state is transferred is really rather masterful...

I can't find the original source right now, but I've adapted his code to my SNES framework here:
https://github.com/Optiroc/libSFX/blob/ ... /CPU/SMP.s
(with some other relevant snippets in libSFX/CPU_SMP.i and libSFX/SMP/System.s700)
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: .spc file loading paradox question

Post by mic_ »

How is it possible to load both at the same time?
By not loading both at the same time. What I do in my SPC loader is to divide the loading process into two stages:

Stage 1: a routine is copied to the first page of SPC RAM, which will receive data going into the SPC RAM range $00f8..$ffff.

Stage 2: another routine is copied to address XXXX in SPC RAM, which will recieve data going into the SPC RAM range $00..$f1, initialize EDL and FLG, initialize A/X/Y/SP/PSW, and finally jump to the init address.

(My way of finding address XXXX is to search the RAM dump part of the SPC file for free RAM somewhere in the range $0100..$ff9f, where a free chunk is defined as a string of adequate length that contains only the value $00 or $ff (i.e. either 00000000.. or FFFFFFFF..)).
Optiroc
Posts: 129
Joined: Thu Feb 07, 2013 1:15 am
Location: Sweden

Re: .spc file loading paradox question

Post by Optiroc »

mic_ wrote:
How is it possible to load both at the same time?
By not loading both at the same time. What I do in my SPC loader is to divide the loading process into two stages:

Stage 1: a routine is copied to the first page of SPC RAM, which will receive data going into the SPC RAM range $00f8..$ffff.

Stage 2: another routine is copied to address XXXX in SPC RAM, which will recieve data going into the SPC RAM range $00..$f1, initialize EDL and FLG, initialize A/X/Y/SP/PSW, and finally jump to the init address.

(My way of finding address XXXX is to search the RAM dump part of the SPC file for free RAM somewhere in the range $0100..$ff9f, where a free chunk is defined as a string of adequate length that contains only the value $00 or $ff (i.e. either 00000000.. or FFFFFFFF..)).
That's how I used to do it as well, before finding Blargg's ingenious piece of code which can transfer the complete state dump without any fiddling with (hopefully) unused memory and such.

How is it done? The last pieces of state is transferred by setting up a loop within the 4 I/O registers, and by carefully timing writes to the registers from the S-CPU side the needed instructions (mov a,#value, mov $dest, a and so on) are executed.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: .spc file loading paradox question

Post by tepples »

What tool are you using to create this .spc file? Or do you plan to play only one song after reset and no sound effects?
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

Re: .spc file loading paradox question

Post by psycopathicteen »

SNESmod and SNES-GSS both output in .spc files.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: .spc file loading paradox question

Post by tepples »

In that case, there ought to be no paradox. The manuals for SNESmod and SNES-GSS should help you figure out what parts need to be uploaded and what parts don't. If they don't, file bugs against the manuals.
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

Re: .spc file loading paradox question

Post by psycopathicteen »

https://github.com/DanielOaks/sneskit/b ... nesmod.asm

Found it. Boy it's hard to find the information I need.
Post Reply