How to play an SPC from a ROM
Moderator: ZSNES Mods
How to play an SPC from a ROM
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.
AntiRes wrote an "SPC to ROM" program a while ago... the source is available on his site (www.alpha-ii.com)
Yeah whatever... The site you linked to link to http://www.alpha-ii.com/ ...franpa_9 wrote:that sites been dead for years now... http://www.snesmusic.org/v2/players.php is where you download the appropriate stuff.
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.
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.
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.
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?
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.
Steelers now officially own your ass.
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.
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();
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.