Init state ported and set properly.
This commit is contained in:
@@ -121,6 +121,7 @@ EXTSYM cpucycle,debstop,switchtovirqdeb,debstop3,switchtonmideb
|
|||||||
EXTSYM NetPlayNoMore
|
EXTSYM NetPlayNoMore
|
||||||
EXTSYM statefileloc
|
EXTSYM statefileloc
|
||||||
EXTSYM CHIPBATT,SaveSramData,BackupCVFrame,RestoreCVFrame,loadstate
|
EXTSYM CHIPBATT,SaveSramData,BackupCVFrame,RestoreCVFrame,loadstate
|
||||||
|
EXTSYM InitRewindVars
|
||||||
|
|
||||||
%ifdef OPENSPC
|
%ifdef OPENSPC
|
||||||
EXTSYM OSPC_Run, ospc_cycle_frac
|
EXTSYM OSPC_Run, ospc_cycle_frac
|
||||||
@@ -483,51 +484,6 @@ NEWSYM UpdateRewind
|
|||||||
%endif
|
%endif
|
||||||
ret
|
ret
|
||||||
|
|
||||||
NEWSYM BackupSystemVars
|
|
||||||
pushad
|
|
||||||
mov ebx,BackupArray
|
|
||||||
BackupCVMac cycpbl,2
|
|
||||||
BackupCVMacB sndrot,3019
|
|
||||||
BackupCVMacB soundcycleft,33
|
|
||||||
BackupCVMac spc700read,10
|
|
||||||
BackupCVMac timer2upd,1
|
|
||||||
BackupCVMac xa,14
|
|
||||||
BackupCVMacB spcnumread,4
|
|
||||||
BackupCVMacB spchalted,4
|
|
||||||
BackupCVMac opcd,6
|
|
||||||
BackupCVMacB HIRQCycNext,5
|
|
||||||
BackupCVMac oamaddr,14
|
|
||||||
BackupCVMacB prevoamptr,1
|
|
||||||
BackupCVMac ReadHead,1
|
|
||||||
popad
|
|
||||||
ret
|
|
||||||
|
|
||||||
NEWSYM InitRewindVars
|
|
||||||
mov dword[RewindPos],0
|
|
||||||
mov dword[RewindOldPos],0
|
|
||||||
mov dword[RewindTimer],60*4
|
|
||||||
ret
|
|
||||||
|
|
||||||
NEWSYM RestoreSystemVars
|
|
||||||
pushad
|
|
||||||
call InitRewindVars
|
|
||||||
mov ebx,BackupArray
|
|
||||||
BackupCVRMac cycpbl,2
|
|
||||||
BackupCVRMacB sndrot,3019
|
|
||||||
BackupCVRMacB soundcycleft,33
|
|
||||||
BackupCVRMac spc700read,10
|
|
||||||
BackupCVRMac timer2upd,1
|
|
||||||
BackupCVRMac xa,14
|
|
||||||
BackupCVRMacB spcnumread,4
|
|
||||||
BackupCVRMacB spchalted,4
|
|
||||||
BackupCVRMac opcd,6
|
|
||||||
BackupCVRMacB HIRQCycNext,5
|
|
||||||
BackupCVRMac oamaddr,14
|
|
||||||
BackupCVRMacB prevoamptr,1
|
|
||||||
BackupCVRMac ReadHead,1
|
|
||||||
popad
|
|
||||||
ret
|
|
||||||
|
|
||||||
SECTION .bss
|
SECTION .bss
|
||||||
NEWSYM MuteVoiceF, resb 0
|
NEWSYM MuteVoiceF, resb 0
|
||||||
SECTION .text
|
SECTION .text
|
||||||
@@ -863,7 +819,9 @@ NEWSYM start65816
|
|||||||
|
|
||||||
; Initialize the rewind vars so that the rewind feature works
|
; Initialize the rewind vars so that the rewind feature works
|
||||||
; when ZSnes is launched with a commandline filename
|
; when ZSnes is launched with a commandline filename
|
||||||
|
pushad
|
||||||
call InitRewindVars
|
call InitRewindVars
|
||||||
|
popad
|
||||||
|
|
||||||
NEWSYM continueprog
|
NEWSYM continueprog
|
||||||
|
|
||||||
|
|||||||
@@ -68,30 +68,58 @@ extern short Op28X, Op0CA, Op02FX, Op0AVS, Op06X, Op01m, Op0DX, Op03F, Op14Zr;
|
|||||||
extern short Op0EH;
|
extern short Op0EH;
|
||||||
extern signed short Op10Coefficient;
|
extern signed short Op10Coefficient;
|
||||||
|
|
||||||
|
|
||||||
|
static void copy_snes_data(unsigned char **buffer, void (*copy_func)(unsigned char **, void *, size_t))
|
||||||
|
{
|
||||||
|
//65816 status, etc.
|
||||||
|
copy_func(buffer, &curcyc, PH65816regsize);
|
||||||
|
//SPC Timers
|
||||||
|
copy_func(buffer, &cycpbl, 2*4);
|
||||||
|
//SNES PPU Register status
|
||||||
|
copy_func(buffer, &sndrot, 3019);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void copy_spc_data(unsigned char **buffer, void (*copy_func)(unsigned char **, void *, size_t))
|
||||||
|
{
|
||||||
|
//SPC stuff, DSP stuff
|
||||||
|
copy_func(buffer, spcRam, PHspcsave);
|
||||||
|
copy_func(buffer, BRRBuffer, PHdspsave);
|
||||||
|
copy_func(buffer, DSPMem, sizeof(DSPMem));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void copy_extra_data(unsigned char **buffer, void (*copy_func)(unsigned char **, void *, size_t))
|
||||||
|
{
|
||||||
|
copy_func(buffer, &soundcycleft, 33);
|
||||||
|
copy_func(buffer, &spc700read, 10*4);
|
||||||
|
copy_func(buffer, &timer2upd, 1*4);
|
||||||
|
copy_func(buffer, &xa, 14*4);
|
||||||
|
copy_func(buffer, &spcnumread, 4);
|
||||||
|
copy_func(buffer, &spchalted, 4);
|
||||||
|
copy_func(buffer, &opcd, 6*4);
|
||||||
|
copy_func(buffer, &HIRQCycNext, 5);
|
||||||
|
copy_func(buffer, &oamaddr, 14*4);
|
||||||
|
copy_func(buffer, &prevoamptr, 1);
|
||||||
|
copy_func(buffer, &ReadHead, 1*4);
|
||||||
|
}
|
||||||
|
|
||||||
static size_t load_save_size;
|
static size_t load_save_size;
|
||||||
static unsigned int zst_version;
|
static unsigned int zst_version;
|
||||||
|
|
||||||
//For compatibility with old save states (pre v1.43)
|
//For compatibility with old save states (pre v1.43)
|
||||||
#define loading_old_state (file && read && (zst_version == 60))
|
#define loading_old_state (!buffer && read && (zst_version == 60))
|
||||||
#define loading_state_no_sram (file && read && !SRAMState)
|
#define loading_state_no_sram (!buffer && read && !SRAMState)
|
||||||
|
|
||||||
void copy_state_data(unsigned char *buffer, void (*copy_func)(unsigned char **, void *, size_t), bool file, bool read)
|
void copy_state_data(unsigned char *buffer, void (*copy_func)(unsigned char **, void *, size_t), bool read)
|
||||||
{
|
{
|
||||||
//65816 status, etc.
|
copy_snes_data(&buffer, copy_func);
|
||||||
copy_func(&buffer, &curcyc, PH65816regsize);
|
|
||||||
//SPC Timers
|
|
||||||
copy_func(&buffer, &cycpbl, 2*4);
|
|
||||||
//SNES PPU Register status
|
|
||||||
copy_func(&buffer, &sndrot, 3019);
|
|
||||||
//WRAM (128k), VRAM (64k)
|
//WRAM (128k), VRAM (64k)
|
||||||
copy_func(&buffer, wramdata, 8192*16);
|
copy_func(&buffer, wramdata, 8192*16);
|
||||||
copy_func(&buffer, vram, 4096*16);
|
copy_func(&buffer, vram, 4096*16);
|
||||||
|
|
||||||
if (spcon) //SPC stuff, DSP stuff
|
if (spcon)
|
||||||
{
|
{
|
||||||
copy_func(&buffer, spcRam, PHspcsave);
|
copy_spc_data(&buffer, copy_func);
|
||||||
copy_func(&buffer, BRRBuffer, PHdspsave);
|
|
||||||
copy_func(&buffer, DSPMem, sizeof(DSPMem));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (C4Enable)
|
if (C4Enable)
|
||||||
@@ -143,7 +171,7 @@ void copy_state_data(unsigned char *buffer, void (*copy_func)(unsigned char **,
|
|||||||
{
|
{
|
||||||
copy_func(&buffer, setaramdata, 256*16);
|
copy_func(&buffer, setaramdata, 256*16);
|
||||||
|
|
||||||
//Todo: save the SetaCmdEnable? For completeness we should do it
|
//Todo: copy the SetaCmdEnable? For completeness we should do it
|
||||||
//but currently we ignore it anyway.
|
//but currently we ignore it anyway.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,35 +181,23 @@ void copy_state_data(unsigned char *buffer, void (*copy_func)(unsigned char **,
|
|||||||
copy_func(&buffer, &SPCMultA, PHnum2writespc7110reg);
|
copy_func(&buffer, &SPCMultA, PHnum2writespc7110reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading_old_state)
|
if (!loading_old_state)
|
||||||
{
|
{
|
||||||
return;
|
copy_extra_data(&buffer, copy_func);
|
||||||
}
|
|
||||||
|
|
||||||
copy_func(&buffer, &soundcycleft, 33);
|
|
||||||
copy_func(&buffer, &spc700read, 10*4);
|
|
||||||
copy_func(&buffer, &timer2upd, 1*4);
|
|
||||||
copy_func(&buffer, &xa, 14*4);
|
|
||||||
copy_func(&buffer, &spcnumread, 4);
|
|
||||||
copy_func(&buffer, &spchalted, 4);
|
|
||||||
copy_func(&buffer, &opcd, 6*4);
|
|
||||||
copy_func(&buffer, &HIRQCycNext, 5);
|
|
||||||
copy_func(&buffer, &oamaddr, 14*4);
|
|
||||||
copy_func(&buffer, &prevoamptr, 1);
|
|
||||||
copy_func(&buffer, &ReadHead, 1*4);
|
|
||||||
|
|
||||||
if (loading_state_no_sram)
|
if (loading_state_no_sram)
|
||||||
{
|
{
|
||||||
copy_func(&buffer, sram, ramsize);
|
copy_func(&buffer, sram, ramsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file)
|
if (buffer) //Not to a file, i.e. rewind
|
||||||
{
|
{
|
||||||
copy_func(&buffer, &tempesi, 4);
|
copy_func(&buffer, &tempesi, 4);
|
||||||
copy_func(&buffer, &tempedi, 4);
|
copy_func(&buffer, &tempedi, 4);
|
||||||
copy_func(&buffer, &tempedx, 4);
|
copy_func(&buffer, &tempedx, 4);
|
||||||
copy_func(&buffer, &tempebp, 4);
|
copy_func(&buffer, &tempebp, 4);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -194,7 +210,7 @@ static void memcpyinc(unsigned char **dest, void *src, size_t len)
|
|||||||
void BackupCVFrame()
|
void BackupCVFrame()
|
||||||
{
|
{
|
||||||
unsigned char *curpos = StateBackup + (CBackupPos << 19) + 1024;
|
unsigned char *curpos = StateBackup + (CBackupPos << 19) + 1024;
|
||||||
copy_state_data(curpos, memcpyinc, false, false);
|
copy_state_data(curpos, memcpyinc, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void memcpyrinc(unsigned char **src, void *dest, size_t len)
|
static void memcpyrinc(unsigned char **src, void *dest, size_t len)
|
||||||
@@ -206,7 +222,35 @@ static void memcpyrinc(unsigned char **src, void *dest, size_t len)
|
|||||||
void RestoreCVFrame()
|
void RestoreCVFrame()
|
||||||
{
|
{
|
||||||
unsigned char *curpos = StateBackup + (PBackupPos << 19) + 1024;
|
unsigned char *curpos = StateBackup + (PBackupPos << 19) + 1024;
|
||||||
copy_state_data(curpos, memcpyrinc, false, true);
|
copy_state_data(curpos, memcpyrinc, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern unsigned int RewindPos, RewindOldPos, RewindTimer;
|
||||||
|
|
||||||
|
void InitRewindVars()
|
||||||
|
{
|
||||||
|
RewindPos = 0;
|
||||||
|
RewindOldPos = 0;
|
||||||
|
RewindTimer = 60*4;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is used to preserve system load state between loads
|
||||||
|
static unsigned char BackupSystemBuffer[0x800000]; //Half a megabyte, should be enough for a while
|
||||||
|
void BackupSystemVars()
|
||||||
|
{
|
||||||
|
unsigned char *buffer = BackupSystemBuffer;
|
||||||
|
copy_snes_data(&buffer, memcpyinc);
|
||||||
|
copy_spc_data(&buffer, memcpyinc);
|
||||||
|
copy_extra_data(&buffer, memcpyinc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RestoreSystemVars()
|
||||||
|
{
|
||||||
|
unsigned char *buffer = BackupSystemBuffer;
|
||||||
|
InitRewindVars();
|
||||||
|
copy_snes_data(&buffer, memcpyrinc);
|
||||||
|
copy_spc_data(&buffer, memcpyrinc);
|
||||||
|
copy_extra_data(&buffer, memcpyrinc);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern unsigned int Bank0datr8[256], Bank0datr16[256], Bank0datw8[256];
|
extern unsigned int Bank0datr8[256], Bank0datr16[256], Bank0datw8[256];
|
||||||
@@ -563,7 +607,7 @@ void statesaver()
|
|||||||
SaveSA1(); //Convert SA-1 stuff to standard, non displacement format
|
SaveSA1(); //Convert SA-1 stuff to standard, non displacement format
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_state_data(0, write_save_state_data, true, false);
|
copy_state_data(0, write_save_state_data, false);
|
||||||
|
|
||||||
if (SFXEnable)
|
if (SFXEnable)
|
||||||
{
|
{
|
||||||
@@ -779,7 +823,7 @@ void stateloader (unsigned char *statename, unsigned char keycheck, unsigned cha
|
|||||||
if (zst_version) //Pre v0.60 saves are no longer loaded
|
if (zst_version) //Pre v0.60 saves are no longer loaded
|
||||||
{
|
{
|
||||||
load_save_size = 0;
|
load_save_size = 0;
|
||||||
copy_state_data(0, read_save_state_data, true, true);
|
copy_state_data(0, read_save_state_data, true);
|
||||||
Totalbyteloaded += load_save_size;
|
Totalbyteloaded += load_save_size;
|
||||||
|
|
||||||
if (SFXEnable)
|
if (SFXEnable)
|
||||||
|
|||||||
@@ -501,7 +501,9 @@ NEWSYM GUIDoReset
|
|||||||
mov byte[MovieProcessing],0
|
mov byte[MovieProcessing],0
|
||||||
call Close_File
|
call Close_File
|
||||||
.skipfileend
|
.skipfileend
|
||||||
|
pushad
|
||||||
call RestoreSystemVars
|
call RestoreSystemVars
|
||||||
|
popad
|
||||||
; clear spc700 ram
|
; clear spc700 ram
|
||||||
mov al,0FFh
|
mov al,0FFh
|
||||||
mov edi,spcRam
|
mov edi,spcRam
|
||||||
|
|||||||
@@ -186,7 +186,9 @@ NEWSYM init
|
|||||||
dec ecx
|
dec ecx
|
||||||
jnz .snowloop
|
jnz .snowloop
|
||||||
|
|
||||||
|
pushad
|
||||||
call BackupSystemVars
|
call BackupSystemVars
|
||||||
|
popad
|
||||||
|
|
||||||
xor eax,eax
|
xor eax,eax
|
||||||
mov al,[cfgreinittime]
|
mov al,[cfgreinittime]
|
||||||
|
|||||||
Reference in New Issue
Block a user