Unhooked rewind buffer and init from unrelated things and put it where it belongs.

This commit is contained in:
n-a-c-h
2005-02-01 17:56:21 +00:00
parent fba4816e68
commit b46372b9ca
6 changed files with 115 additions and 33 deletions

View File

@@ -121,7 +121,6 @@ EXTSYM cpucycle,debstop,switchtovirqdeb,debstop3,switchtonmideb
EXTSYM NetPlayNoMore
EXTSYM statefileloc
EXTSYM CHIPBATT,SaveSramData,BackupCVFrame,RestoreCVFrame,loadstate
EXTSYM InitRewindVars
%ifdef __MSDOS__
EXTSYM dssel
@@ -129,7 +128,6 @@ EXTSYM dssel
SECTION .data
NEWSYM CBackupPos, dd 0
NEWSYM StateBackup, dd 0
NEWSYM PBackupPos, dd 0
NEWSYM PPValue, dd 0 ; Previous PValue
NEWSYM DPValue, dd 0 ; Destination PValue
@@ -734,12 +732,6 @@ NEWSYM start65816
; rep stosd
cmp byte[romloadskip],1
je near StartGUI
; Initialize the rewind vars so that the rewind feature works
; when ZSnes is launched with a commandline filename
pushad
call InitRewindVars
popad
NEWSYM continueprog

View File

@@ -29,7 +29,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#define DIR_SLASH "\\"
#endif
@@ -46,7 +45,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define stim()
#endif
extern unsigned int CBackupPos, PBackupPos, cycpbl, PH65816regsize;
extern unsigned int cycpbl, PH65816regsize;
extern unsigned int *wramdata, *vram, PHspcsave, PHdspsave, *C4Ram, *sfxramdata;
extern unsigned int PHnum2writesa1reg, SA1Mode, prevedi, SA1xpc, sa1dmaptr;
extern unsigned int soundcycleft, spc700read, timer2upd, xa, PHnum2writesfxreg;
@@ -54,10 +53,10 @@ extern unsigned int spcnumread, spchalted, opcd, HIRQCycNext, oamaddr;
extern unsigned int SfxR0, ReadHead, *setaramdata, ramsize, *sram;
extern unsigned int tempesi, tempedi, tempedx, tempebp;
extern unsigned int SPCMultA, PHnum2writespc7110reg;
extern unsigned char *StateBackup, sndrot, spcRam[65472];
extern unsigned char sndrot, spcRam[65472];
extern unsigned char DSPMem[256], SA1Status, *SA1RAMArea, DSP1Type, DSP1COp;
extern unsigned char prevoamptr, BRRBuffer[32], *romdata, curcyc;
extern unsigned char vidmemch4[4096], vidmemch8[4096], vidmemch2[4096];
extern bool C4Enable, SFXEnable, SA1Enable, SPC7110Enable, SETAEnable, spcon, SRAMState;
@@ -200,37 +199,134 @@ static void copy_state_data(unsigned char *buffer, void (*copy_func)(unsigned ch
}
}
static void memcpyinc(unsigned char **dest, void *src, size_t len)
{
memcpy(*dest, src, len);
*dest += len;
}
void BackupCVFrame()
{
unsigned char *curpos = StateBackup + (CBackupPos << 19) + 1024;
copy_state_data(curpos, memcpyinc, false);
}
static void memcpyrinc(unsigned char **src, void *dest, size_t len)
{
memcpy(dest, *src, len);
*src += len;
}
void RestoreCVFrame()
extern unsigned int RewindTimer;
extern unsigned char RewindStates;
unsigned char *StateBackup = 0;
size_t rewind_state_size, cur_zst_size, old_zst_size;
/* A nice idea, but needs more ported from the assembly first.
size_t RewindPos, RewindEarliestPos;
void BackupCVFrame()
{
unsigned char *curpos = StateBackup + (PBackupPos << 19) + 1024;
copy_state_data(curpos, memcpyrinc, true);
unsigned char *RewindBufferPos = StateBackup + RewindPos*rewind_state_size;
printf("Backing up rewind in slot #%u\n", RewindPos);
copy_state_data(RewindBufferPos, memcpyinc, false);
RewindPos++;
if (RewindPos == RewindStates)
{
RewindPos = 0;
}
if (RewindPos == RewindEarliestPos)
{
RewindEarliestPos++;
if (RewindEarliestPos == RewindStates)
{
RewindEarliestPos = 0;
}
}
RewindTimer = 60*3;
}
extern unsigned int RewindPos, RewindOldPos, RewindTimer;
void RestoreCVFrame()
{
if (RewindPos != RewindEarliestPos)
{
unsigned char *RewindBufferPos;
if (!RewindPos)
{
RewindPos = RewindStates;
}
RewindPos--;
RewindBufferPos = StateBackup + RewindPos*rewind_state_size;
printf("Restoring rewind in slot #%u\n", RewindPos);
copy_state_data(RewindBufferPos, memcpyrinc, true);
//Clear Cache Check
memset(vidmemch2, 1, sizeof(vidmemch2));
memset(vidmemch4, 1, sizeof(vidmemch4));
memset(vidmemch8, 1, sizeof(vidmemch8));
RewindTimer = 60*3;
}
}
void MultipleFrameBack(unsigned int i)
{
while (i--)
{
if (RewindPos != RewindEarliestPos)
{
if (!RewindPos)
{
RewindPos = RewindStates;
}
RewindPos--;
}
else
{
break;
}
}
}
void SetupRewindBuffer()
{
if (StateBackup){ free(StateBackup); }
for (; RewindStates; RewindStates--)
{
StateBackup = 0;
StateBackup = (unsigned char *)malloc(rewind_state_size*RewindStates);
if (StateBackup) { break; }
}
}
*/
extern unsigned int CBackupPos, PBackupPos, RewindPos, RewindOldPos;
void BackupCVFrame()
{
unsigned char *RewindBufferPos = StateBackup + (CBackupPos << 19) + 1024;
copy_state_data(RewindBufferPos, memcpyinc, false);
}
void RestoreCVFrame()
{
unsigned char *RewindBufferPos = StateBackup + (PBackupPos << 19) + 1024;
copy_state_data(RewindBufferPos, memcpyrinc, true);
}
void SetupRewindBuffer()
{
extern void outofmemory();
if (!StateBackup)
{
StateBackup = (unsigned char *)malloc(4096*128*16);
}
if (!StateBackup) { outofmemory(); }
}
void InitRewindVars()
{
SetupRewindBuffer();
RewindPos = 0;
RewindOldPos = 0;
//RewindEarliestPos = 0;
RewindTimer = 60*4;
}
@@ -552,7 +648,6 @@ static void state_size_tally(unsigned char **dest, void *src, size_t len)
state_size += len;
}
size_t rewind_state_size, cur_zst_size, old_zst_size;
void calculate_state_sizes()
{
state_size = 0;
@@ -794,9 +889,7 @@ void initpitch()
extern unsigned int KeyLoadState, Totalbyteloaded, SfxMemTable[256], SfxCPB;
extern unsigned int SfxPBR, SfxROMBR, SfxRAMBR;
extern unsigned char pressed[256+128+64], multchange, txtloadmsg[15];
extern unsigned char txtconvmsg[16], txtnfndmsg[23], vidmemch2[4096];
extern unsigned char vidmemch4[4096], vidmemch8[4096],
MovieProcessing;
extern unsigned char txtconvmsg[16], txtnfndmsg[23], MovieProcessing;
extern unsigned char ioportval, SDD1Enable, nexthdma;
void procexecloop();

View File

@@ -642,6 +642,7 @@ NEWSYM SPL4Path, times 1024 db 0
NEWSYM AutoPatch, db 1
NEWSYM RomInfo, db 1
NEWSYM SRAMState, db 0
NEWSYM RewindStates, db 16
GUIsave equ $-GUIRAdd

View File

@@ -132,7 +132,7 @@ EXTSYM IntlEHi
EXTSYM CHIPBATT,SFXEnable,C4Enable,SPC7110Enable,RTCEnable,SA1Enable,SDD1Enable,OBCEnable
EXTSYM SETAEnable,ST18Enable,SGBEnable,DSP1Enable,DSP2Enable,DSP3Enable,DSP4Enable,BSEnable
EXTSYM calculate_state_sizes
EXTSYM calculate_state_sizes,InitRewindVars
EXTSYM SetaCmdEnable,setaramdata
EXTSYM setaaccessbankr8,setaaccessbankw8,setaaccessbankr8a,setaaccessbankw8a
@@ -3169,6 +3169,7 @@ NEWSYM SetupROM
pushad
call SetupSramSize
call calculate_state_sizes
call InitRewindVars
popad
; get pal/ntsc

View File

@@ -28,7 +28,6 @@ EXTSYM FPSOn,FPSAtStart,cfgsoundon
EXTSYM xa
EXTSYM ram7fa,wramdataa
EXTSYM malloc,free
EXTSYM StateBackup
EXTSYM ADSRGAINSwitch,MMXSupport,ScreenScale,SoundQuality
EXTSYM debugger,pl1contrl,pl2contrl,romtype,smallscreence
EXTSYM smallscreenon,spcon
@@ -656,10 +655,7 @@ NEWSYM allocptr
%ifndef __MSDOS__
AllocmemFail 4096*128*16+4096+65536*16,StateBackup,outofmemory
mov eax,[StateBackup]
add eax,4096*128*16
mov [BitConv32Ptr],eax
AllocmemFail 4096+65536*16,BitConv32Ptr,outofmemory
%endif
; Memory Allocation

View File

@@ -31,7 +31,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
extern void outofmemory();
extern unsigned char *spc7110romptr;
extern unsigned char *StateBackup;
extern unsigned char *spcBuffera;
extern unsigned char *spritetablea;
extern unsigned char *vbufaptr;