Add SPC dumping support.

This commit is contained in:
Brandon Wright 2011-06-26 05:33:14 -05:00
parent 2e94b98e90
commit ebc9e721f6
7 changed files with 179 additions and 111 deletions

View File

@ -476,8 +476,8 @@ void S9xSetSoundMute (bool8 mute)
void S9xDumpSPCSnapshot (void)
{
/* TODO: SPC dumping */
/* spc_core->dsp_dump_spc_snapshot(); */
SNES::dsp.spc_dsp.dump_spc_snapshot();
}
static void SPCSnapshotCallback (void)
@ -492,6 +492,8 @@ bool8 S9xInitAPU (void)
spc::shrink_buffer = NULL;
spc::resampler = NULL;
SNES::dsp.spc_dsp.set_spc_snapshot_callback(SPCSnapshotCallback);
return (TRUE);
}
@ -632,3 +634,26 @@ void S9xAPULoadState (uint8 *block)
ptr += sizeof(int32);
memcpy (SNES::cpu.registers, ptr, 4);
}
bool8 S9xSPCDump (const char *filename)
{
FILE *fs;
uint8 buf[SPC_FILE_SIZE];
size_t ignore;
fs = fopen(filename, "wb");
if (!fs)
return (FALSE);
S9xSetSoundMute(TRUE);
SNES::smp.save_spc (buf);
ignore = fwrite(buf, SPC_FILE_SIZE, 1, fs);
fclose(fs);
S9xSetSoundMute(FALSE);
return (TRUE);
}

View File

@ -183,7 +183,8 @@
typedef void (*apu_callback) (void *);
#define SPC_SAVE_STATE_BLOCK_SIZE (1024 * 65)
#define SPC_SAVE_STATE_BLOCK_SIZE (1024 * 65)
#define SPC_FILE_SIZE (66048)
bool8 S9xInitAPU (void);
void S9xDeinitAPU (void);
@ -199,6 +200,7 @@ void S9xAPUAllowTimeOverflow (bool);
void S9xAPULoadState (uint8 *);
void S9xAPUSaveState (uint8 *);
void S9xDumpSPCSnapshot (void);
bool8 S9xSPCDump (const char *);
bool8 S9xInitSound (int, int);
bool8 S9xOpenSoundDevice (void);

View File

@ -837,6 +837,7 @@ void SPC_DSP::init( void* ram_64k )
stereo_switch = 0xffff;
take_spc_snapshot = 0;
spc_snapshot_callback = 0;
rom_enabled = 0;
#ifndef NDEBUG
// be sure this sign-extends

View File

@ -22,6 +22,7 @@ public:
#else
void load_state(uint8 **);
void save_state(uint8 **);
void save_spc (uint8 *);
#endif
SMP();
~SMP();

View File

@ -1,9 +1,75 @@
#include "snes/snes.hpp"
#include <stdio.h>
typedef struct spc_file {
uint8 header[33];
uint8 idtag[3];
uint8 version_minor;
uint8 pc_low;
uint8 pc_high;
uint8 a;
uint8 x;
uint8 y;
uint8 psw;
uint8 sp;
uint8 unused_a[2];
uint8 id666[210];
uint8 apuram[65536];
uint8 dsp_registers[128];
uint8 unused_b[64];
uint8 iplrom[64];
} spc_file;
namespace SNES {
#include "dsp/blargg_endian.h"
void SMP::save_spc (uint8 *block) {
spc_file out;
const char *header = "SNES-SPC700 Sound File Data v0.30";
memcpy (out.header, header, 33);
out.idtag[0] = out.idtag[1] = 26;
out.idtag[2] = 27;
out.version_minor = 30;
out.pc_low = regs.pc & 0xff;
out.pc_high = (regs.pc >> 8) & 0xff;
out.a = regs.a;
out.x = regs.x;
out.y = regs.y;
out.psw = (uint8) ((unsigned) regs.p);
out.sp = regs.sp;
out.unused_a[0] = out.unused_a[1] = 0;
memset (out.id666, 0, 210);
memcpy (out.apuram, apuram, 65536);
for (int i = 0xf2; i <= 0xf7; i++)
{
out.apuram[i] = mmio_read (i);
}
for (int i = 0xfd; i <= 0xff; i++)
{
out.apuram[i] = mmio_read (i);
}
for (int i = 0; i < 128; i++)
{
out.dsp_registers[i] = dsp.read (i);
}
memset (out.unused_b, 0, 64);
memcpy (out.iplrom, iplrom, 64);
memcpy (block, &out, 66048);
}
void SMP::save_state(uint8 **block) {
uint8 *ptr = *block;
memcpy(ptr, apuram, 64 * 1024);
@ -116,4 +182,4 @@ void SMP::load_state(uint8 **block) {
*block = ptr;
}
}
} /* namespace SNES */

View File

@ -2275,29 +2275,3 @@ static void UnfreezeStructFromCopy (void *sbase, FreezeData *fields, int num_fie
}
}
}
bool8 S9xSPCDump (const char *filename)
{
/* TODO: No SPC dumping in byuu SMP */
/*
FILE *fs;
uint8 buf[SNES_SPC::spc_file_size];
size_t ignore;
fs = fopen(filename, "wb");
if (!fs)
return (FALSE);
S9xSetSoundMute(TRUE);
spc_core->init_header(buf);
spc_core->save_spc(buf);
ignore = fwrite(buf, SNES_SPC::spc_file_size, 1, fs);
fclose(fs);
S9xSetSoundMute(FALSE);
*/
return (TRUE);
}

View File

@ -195,6 +195,5 @@ bool8 S9xFreezeGame (const char *);
bool8 S9xUnfreezeGame (const char *);
void S9xFreezeToStream (STREAM);
int S9xUnfreezeFromStream (STREAM);
bool8 S9xSPCDump (const char *);
#endif