svp_t *svp = NULL;
int PicoSVPCycles = 1000; // cycles/line
+/* save state stuff */
+typedef enum {
+ CHUNK_IRAM = CHUNK_CARTHW,
+ CHUNK_DRAM,
+ CHUNK_SSP
+} chunk_name_e;
+
+static carthw_state_chunk svp_states[] =
+{
+ { CHUNK_IRAM, 0x800, NULL },
+ { CHUNK_DRAM, sizeof(svp->dram), NULL },
+ { CHUNK_SSP, sizeof(svp->ssp1601), NULL },
+ { 0, 0, NULL }
+};
+
+
static void PicoSVPReset(void)
{
elprintf(EL_SVP, "SVP reset");
PicoDmaHook = PicoSVPDma;
PicoResetHook = PicoSVPReset;
PicoLineHook = PicoSVPLine;
+
+ // save state stuff
+ svp_states[0].ptr = svp->iram_rom;
+ svp_states[1].ptr = svp->dram;
+ svp_states[2].ptr = &svp->ssp1601;
+ carthw_chunks = svp_states;
}
// sn76496
extern int *sn76496_regs;
+carthw_state_chunk *carthw_chunks;
void (*PicoStateProgressCB)(const char *str) = 0;
CHUNK_SCD,
CHUNK_RC,
CHUNK_MISC_CD,
+ CHUNK_DEFAULT_COUNT
+ // CHUNK_CARTHW = 64, // defined in PicoInt
} chunk_name_e;
}
-#define CHECKED_WRITE(name,len,data) \
- if (PicoStateProgressCB) PicoStateProgressCB(chunk_names[name]); \
- if (!write_chunk(name, len, data, file)) return 1;
+#define CHECKED_WRITE(name,len,data) { \
+ if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT) \
+ PicoStateProgressCB(chunk_names[name]); \
+ if (!write_chunk(name, len, data, file)) return 1; \
+}
-#define CHECKED_WRITE_BUFF(name,buff) \
- if (PicoStateProgressCB) PicoStateProgressCB(chunk_names[name]); \
- if (!write_chunk(name, sizeof(buff), &buff, file)) return 1;
+#define CHECKED_WRITE_BUFF(name,buff) { \
+ if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT) \
+ PicoStateProgressCB(chunk_names[name]); \
+ if (!write_chunk(name, sizeof(buff), &buff, file)) return 1; \
+}
PICO_INTERNAL int PicoCdSaveState(void *file)
{
CHECKED_WRITE_BUFF(CHUNK_VSRAM, Pico.vsram);
CHECKED_WRITE_BUFF(CHUNK_MISC, Pico.m);
CHECKED_WRITE_BUFF(CHUNK_VIDEO, Pico.video);
- if(PicoOpt&7) {
+ if (PicoOpt&7) {
memset(buff, 0, sizeof(buff));
z80_pack(buff);
CHECKED_WRITE_BUFF(CHUNK_Z80, buff);
}
- if(PicoOpt&3)
+ if (PicoOpt&3)
CHECKED_WRITE(CHUNK_PSG, 28*4, sn76496_regs);
- if(PicoOpt&1)
+ if (PicoOpt&1)
CHECKED_WRITE(CHUNK_FM, 0x200+4, ym2612_regs);
if (PicoMCD & 1)
wram_2M_to_1M(Pico_mcd->word_ram2M);
}
+ if (carthw_chunks != NULL)
+ {
+ carthw_state_chunk *chwc;
+ for (chwc = carthw_chunks; chwc->ptr != NULL; chwc++)
+ CHECKED_WRITE(chwc->chunk, chwc->size, chwc->ptr);
+ }
+
return 0;
}
#define R_ERROR_RETURN(error) \
{ \
- elprintf(EL_STATUS, "PicoCdLoadState @ %x: " error "\n", g_read_offs); \
+ elprintf(EL_STATUS, "PicoCdLoadState @ %x: " error, g_read_offs); \
return 1; \
}
CHECKED_READ(1, buff);
CHECKED_READ(4, &len);
if (len < 0 || len > 1024*512) R_ERROR_RETURN("bad length");
- if (buff[0] > CHUNK_FM && !(PicoMCD & 1)) R_ERROR_RETURN("cd chunk in non CD state?");
+ if (buff[0] > CHUNK_FM && buff[0] <= CHUNK_MISC_CD && !(PicoMCD & 1))
+ R_ERROR_RETURN("cd chunk in non CD state?");
switch (buff[0])
{
case CHUNK_MISC_CD: CHECKED_READ_BUFF(Pico_mcd->m); break;
default:
- elprintf(EL_STATUS, "PicoCdLoadState: skipping unknown chunk %i of size %i\n", buff[0], len);
+ if (carthw_chunks != NULL)
+ {
+ carthw_state_chunk *chwc;
+ for (chwc = carthw_chunks; chwc->ptr != NULL; chwc++) {
+ if (chwc->chunk == buff[0]) {
+ CHECKED_READ2(chwc->size, chwc->ptr);
+ goto breakswitch;
+ }
+ }
+ }
+ elprintf(EL_STATUS, "PicoCdLoadState: skipping unknown chunk %i of size %i", buff[0], len);
areaSeek(file, len, SEEK_CUR);
break;
}
+ breakswitch:;
}
- /* after load events */
- if (Pico_mcd->s68k_regs[3]&4) // 1M mode?
- wram_2M_to_1M(Pico_mcd->word_ram2M);
- PicoMemResetCD(Pico_mcd->s68k_regs[3]);
+ if (PicoMCD & 1)
+ {
+ /* after load events */
+ if (Pico_mcd->s68k_regs[3]&4) // 1M mode?
+ wram_2M_to_1M(Pico_mcd->word_ram2M);
+ PicoMemResetCD(Pico_mcd->s68k_regs[3]);
#ifdef _ASM_CD_MEMORY_C
- if (Pico_mcd->s68k_regs[3]&4)
- PicoMemResetCDdecode(Pico_mcd->s68k_regs[3]);
+ if (Pico_mcd->s68k_regs[3]&4)
+ PicoMemResetCDdecode(Pico_mcd->s68k_regs[3]);
#endif
- if (Pico_mcd->m.audio_track > 0 && Pico_mcd->m.audio_track < Pico_mcd->TOC.Last_Track)
- mp3_start_play(Pico_mcd->TOC.Tracks[Pico_mcd->m.audio_track].F, Pico_mcd->m.audio_offset);
- // restore hint vector
- *(unsigned short *)(Pico_mcd->bios + 0x72) = Pico_mcd->m.hint_vector;
+ if (Pico_mcd->m.audio_track > 0 && Pico_mcd->m.audio_track < Pico_mcd->TOC.Last_Track)
+ mp3_start_play(Pico_mcd->TOC.Tracks[Pico_mcd->m.audio_track].F, Pico_mcd->m.audio_offset);
+ // restore hint vector
+ *(unsigned short *)(Pico_mcd->bios + 0x72) = Pico_mcd->m.hint_vector;
+ }
return 0;
}
CHECKED_READ(1, buff);
CHECKED_READ(4, &len);
if (len < 0 || len > 1024*512) R_ERROR_RETURN("bad length");
- if (buff[0] > CHUNK_FM && !(PicoMCD & 1)) R_ERROR_RETURN("cd chunk in non CD state?");
+ if (buff[0] > CHUNK_FM && buff[0] <= CHUNK_MISC_CD && !(PicoMCD & 1))
+ R_ERROR_RETURN("cd chunk in non CD state?");
switch (buff[0])
{