mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
SVP save support
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@352 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
94fc546caa
commit
945c2fdcfd
5 changed files with 85 additions and 24 deletions
|
@ -174,7 +174,7 @@ int PmovState(int PmovAction, void *PmovFile)
|
|||
int minimum=0;
|
||||
unsigned char head[32];
|
||||
|
||||
if (PicoMCD & 1)
|
||||
if ((PicoMCD & 1) || carthw_chunks != NULL)
|
||||
{
|
||||
if (PmovAction&1) return PicoCdSaveState(PmovFile);
|
||||
if (PmovAction&2) return PicoCdLoadState(PmovFile);
|
||||
|
|
|
@ -497,6 +497,7 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize)
|
|||
PicoDmaHook = NULL;
|
||||
PicoResetHook = NULL;
|
||||
PicoLineHook = NULL;
|
||||
carthw_chunks = NULL;
|
||||
|
||||
PicoMemReset();
|
||||
|
||||
|
|
|
@ -367,6 +367,14 @@ PICO_INTERNAL int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub);
|
|||
PICO_INTERNAL int PicoCdSaveState(void *file);
|
||||
PICO_INTERNAL int PicoCdLoadState(void *file);
|
||||
|
||||
typedef struct {
|
||||
int chunk;
|
||||
int size;
|
||||
void *ptr;
|
||||
} carthw_state_chunk;
|
||||
extern carthw_state_chunk *carthw_chunks;
|
||||
#define CHUNK_CARTHW 64
|
||||
|
||||
// Cart.c
|
||||
PICO_INTERNAL void PicoCartDetect(void);
|
||||
|
||||
|
|
|
@ -11,6 +11,22 @@
|
|||
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");
|
||||
|
@ -79,5 +95,11 @@ void PicoSVPInit(void)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
// sn76496
|
||||
extern int *sn76496_regs;
|
||||
|
||||
carthw_state_chunk *carthw_chunks;
|
||||
void (*PicoStateProgressCB)(const char *str) = 0;
|
||||
|
||||
|
||||
|
@ -38,6 +39,8 @@ typedef enum {
|
|||
CHUNK_SCD,
|
||||
CHUNK_RC,
|
||||
CHUNK_MISC_CD,
|
||||
CHUNK_DEFAULT_COUNT
|
||||
// CHUNK_CARTHW = 64, // defined in PicoInt
|
||||
} chunk_name_e;
|
||||
|
||||
|
||||
|
@ -81,13 +84,17 @@ static int write_chunk(chunk_name_e name, int len, void *data, void *file)
|
|||
}
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
@ -143,6 +150,13 @@ PICO_INTERNAL int PicoCdSaveState(void *file)
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -150,7 +164,7 @@ static int g_read_offs = 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; \
|
||||
}
|
||||
|
||||
|
@ -189,7 +203,8 @@ PICO_INTERNAL int PicoCdLoadState(void *file)
|
|||
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])
|
||||
{
|
||||
|
@ -235,12 +250,25 @@ PICO_INTERNAL int PicoCdLoadState(void *file)
|
|||
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:;
|
||||
}
|
||||
|
||||
if (PicoMCD & 1)
|
||||
{
|
||||
/* after load events */
|
||||
if (Pico_mcd->s68k_regs[3]&4) // 1M mode?
|
||||
wram_2M_to_1M(Pico_mcd->word_ram2M);
|
||||
|
@ -253,6 +281,7 @@ PICO_INTERNAL int PicoCdLoadState(void *file)
|
|||
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;
|
||||
}
|
||||
|
@ -273,7 +302,8 @@ int PicoCdLoadStateGfx(void *file)
|
|||
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])
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue