How to play an SPC from a ROM

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
pagefault
ZSNES Developer
ZSNES Developer
Posts: 812
Joined: Tue Aug 17, 2004 5:24 am
Location: In your garden

How to play an SPC from a ROM

Post by pagefault »

Hi, I was wondering if any of you had some code to load an SPC in a ROM and play it. I am not too sure how this is done exactly, can anyone post some code to do it? I would like to put in a SPC player in ZSNES by 'patching' a ROM and playing it in the internal emulator.
taezou

Post by taezou »

AntiRes wrote an "SPC to ROM" program a while ago... the source is available on his site (www.alpha-ii.com)
Hyos
Regular
Posts: 207
Joined: Mon Aug 15, 2005 2:15 pm

Post by Hyos »

franpa_9 wrote:that sites been dead for years now... http://www.snesmusic.org/v2/players.php is where you download the appropriate stuff.
Yeah whatever... The site you linked to link to http://www.alpha-ii.com/ ...

And the sources are still avaiable, the last update was 01/16/2006.
Dead for years? You could have looked at the link before posting, at least.
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

i did via google and it took me to a redirection url. but your link didnt (grrrr) so meh it was my fault i guess.
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
Hyos
Regular
Posts: 207
Joined: Mon Aug 15, 2005 2:15 pm

Post by Hyos »

Sorry if I was harsh.
OptiRoc
Rookie
Posts: 18
Joined: Mon Jan 10, 2005 12:31 am

Post by OptiRoc »

Internally cooking up a "ROM image" to implement an SPC player seems like an awkward way to approach it.

Being in "god mode" over the SNES machine, like you are from the emulators code's point of view, is exactly what you'd want when trying to get SPC dumps to play back on a SNES. It's quite a bit of a hassle to transfer the 64k of SPC memory, initializing all the registers without leaving any (harmful) trace, considering only the SPC700-CPU itself has access to its memory and registers.

All that can be avoided when you have access to every byte of memory and every register -- which I presume is no problem from the emus point of view. Just transfer the RAM dump to SPC memory, set the registers, and let it roll.
kevman
Redneck Gamer-Mod
Posts: 433
Joined: Wed Aug 04, 2004 2:15 am
Location: Pittsburgh

Post by kevman »

SPC2ROM does it by looking in the SPC dump for unused memory and loading a little program there that sets the registers and jumps to the correct location.

This, I would think, would not really be needed in the emulated enviroment. Maybe just code a little SNES program which does nothing to the SPC and just makes the main CPU do nothing, then load the SPC data as if from a save state, and go?
SHREIK!!!!!!! DDdddnnnnnnaaaa! GESTAHLLLLLLLLLL!!!!!!!!

Steelers now officially own your ass.
gladius
Rookie
Posts: 16
Joined: Wed Nov 30, 2005 8:10 am
Contact:

Post by gladius »

To do an SPC player all that is neccesary is emulating the SPC chip, as others have suggested just directly copy the stuff from the SPC into internal emulator state and you can use a massively simplified loop that emulates 32 cycles of SPC700, one dsp tick, then spits out a sample, ad infinitum.

That's all I did for my spc players and it worked quite well. There is a bit of fun in getting the state properly initialized from the SPC state, but hopefully that won't be too hard.

Here is pretty much my entire init code for the SPC path in my emulators.

Code: Select all

    // Load the SPC
    ApuReset();
    DspReset();

// 0 - A, 1 - X, 2 - Y, 3 - RAMBASE, 4 - DP, 5 - PC (Adjusted into rambase)
// 6 - Cycles (bit 0 - C, bit 1 - v, bit 2 - h, bits 3+ cycles left)
// 7 - Optable
// 8 - NZ

    APU_STATE[0] = spc[0x27]<<24; // A
    APU_STATE[1] = spc[0x28]<<24; // X
    APU_STATE[2] = spc[0x29]<<24; // Y
    SetStateFromRawPSW(APU_STATE, spc[0x2A]);
    APU_SP = 0x100 | spc[0x2B]; // SP
    APU_STATE[5] = APU_STATE[3] + (spc[0x25] | (spc[0x26] << 8)); // PC

    for (int i=0; i<=0xffff; i++) APU_MEM[i] = spc[0x100 + i];
    for (int i=0; i<=0x7f; i++) DSP_MEM[i] = spc[0x10100 + i];
    for (int i=0; i<=0x3f; i++) APU_EXTRA_MEM[i] = spc[0x101c0 + i];

    ApuPrepareStateAfterReload();
    DspPrepareStateAfterReload();
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

I'm not sure if he ever released the update to that SPC2ROM code. I've used a modified version of the code to play SPC files on my SNES and it works well. I can help if the code there doesn't work (as I remember, the original code had a bug in it). I don't have a PC so maybe he's posted builds only of the more current code; I didn't see any recent source code on the site.
Post Reply