fixed fresh bug in movie savestates

thought of a better way to do the _P -> __P and _S -> __S conversion (simply make a new file x6502abbrev.h that has _P and _S defined in it which is to be included last in any file that needs it)
This commit is contained in:
zeromus 2008-06-17 07:10:53 +00:00
parent e0a14909f0
commit ce3a9796c3
6 changed files with 95 additions and 83 deletions

View File

@ -13,6 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include "x6502abbrev.h"
int offsetStringToInt(unsigned int type, const char* offsetBuffer)
{
int offset = 0;
@ -386,14 +388,14 @@ int getValue(int type)
case 'A': return _A;
case 'X': return _X;
case 'Y': return _Y;
case 'N': return __P & N_FLAG ? 1 : 0;
case 'V': return __P & V_FLAG ? 1 : 0;
case 'U': return __P & U_FLAG ? 1 : 0;
case 'B': return __P & B_FLAG ? 1 : 0;
case 'D': return __P & D_FLAG ? 1 : 0;
case 'I': return __P & I_FLAG ? 1 : 0;
case 'Z': return __P & Z_FLAG ? 1 : 0;
case 'C': return __P & C_FLAG ? 1 : 0;
case 'N': return _P & N_FLAG ? 1 : 0;
case 'V': return _P & V_FLAG ? 1 : 0;
case 'U': return _P & U_FLAG ? 1 : 0;
case 'B': return _P & B_FLAG ? 1 : 0;
case 'D': return _P & D_FLAG ? 1 : 0;
case 'I': return _P & I_FLAG ? 1 : 0;
case 'Z': return _P & Z_FLAG ? 1 : 0;
case 'C': return _P & C_FLAG ? 1 : 0;
case 'P': return _PC;
}

View File

@ -791,7 +791,7 @@ bool FCEUMOV_ReadState(std::istream* is, uint32 size)
////---------
//memorystream mstemp(&buf);
MovieData tempMovieData = MovieData();
LoadFM2(tempMovieData, is);
LoadFM2(tempMovieData, is, size);
//complex TAS logic for when a savestate is loaded:
//----------------

View File

@ -22,17 +22,17 @@ case 0x00: /* BRK */
_PC++;
PUSH(_PC>>8);
PUSH(_PC);
PUSH(__P|U_FLAG|B_FLAG);
__P|=I_FLAG;
PUSH(_P|U_FLAG|B_FLAG);
_P|=I_FLAG;
_PI|=I_FLAG;
_PC=RdMem(0xFFFE);
_PC|=RdMem(0xFFFF)<<8;
break;
case 0x40: /* RTI */
__P=POP();
_P=POP();
/* _PI=_P; This is probably incorrect, so it's commented out. */
_PI = __P;
_PI = _P;
_PC=POP();
_PC|=POP()<<8;
break;
@ -47,14 +47,14 @@ case 0x48: /* PHA */
PUSH(_A);
break;
case 0x08: /* PHP */
PUSH(__P|U_FLAG|B_FLAG);
PUSH(_P|U_FLAG|B_FLAG);
break;
case 0x68: /* PLA */
_A=POP();
X_ZN(_A);
break;
case 0x28: /* PLP */
__P=POP();
_P=POP();
break;
case 0x4C:
{
@ -107,11 +107,11 @@ case 0x98: /* TYA */
break;
case 0xBA: /* TSX */
_X=__S;
_X=_S;
X_ZN(_X);
break;
case 0x9A: /* TXS */
__S=_X;
_S=_X;
break;
case 0xCA: /* DEX */
@ -133,26 +133,26 @@ case 0xC8: /* INY */
break;
case 0x18: /* CLC */
__P&=~C_FLAG;
_P&=~C_FLAG;
break;
case 0xD8: /* CLD */
__P&=~D_FLAG;
_P&=~D_FLAG;
break;
case 0x58: /* CLI */
__P&=~I_FLAG;
_P&=~I_FLAG;
break;
case 0xB8: /* CLV */
__P&=~V_FLAG;
_P&=~V_FLAG;
break;
case 0x38: /* SEC */
__P|=C_FLAG;
_P|=C_FLAG;
break;
case 0xF8: /* SED */
__P|=D_FLAG;
_P|=D_FLAG;
break;
case 0x78: /* SEI */
__P|=I_FLAG;
_P|=I_FLAG;
break;
case 0xEA: /* NOP */
@ -296,28 +296,28 @@ case 0x94: ST_ZPX(_Y);
case 0x8C: ST_AB(_Y);
/* BCC */
case 0x90: JR(!(__P&C_FLAG)); break;
case 0x90: JR(!(_P&C_FLAG)); break;
/* BCS */
case 0xB0: JR(__P&C_FLAG); break;
case 0xB0: JR(_P&C_FLAG); break;
/* BEQ */
case 0xF0: JR(__P&Z_FLAG); break;
case 0xF0: JR(_P&Z_FLAG); break;
/* BNE */
case 0xD0: JR(!(__P&Z_FLAG)); break;
case 0xD0: JR(!(_P&Z_FLAG)); break;
/* BMI */
case 0x30: JR(__P&N_FLAG); break;
case 0x30: JR(_P&N_FLAG); break;
/* BPL */
case 0x10: JR(!(__P&N_FLAG)); break;
case 0x10: JR(!(_P&N_FLAG)); break;
/* BVC */
case 0x50: JR(!(__P&V_FLAG)); break;
case 0x50: JR(!(_P&V_FLAG)); break;
/* BVS */
case 0x70: JR(__P&V_FLAG); break;
case 0x70: JR(_P&V_FLAG); break;
//default: printf("Bad %02x at $%04x\n",b1,X.PC);break;
//ifdef moo
@ -327,7 +327,7 @@ case 0x70: JR(__P&V_FLAG); break;
/* AAC */
case 0x2B:
case 0x0B: LD_IM(AND;__P&=~C_FLAG;__P|=_A>>7);
case 0x0B: LD_IM(AND;_P&=~C_FLAG;_P|=_A>>7);
/* AAX */
case 0x87: ST_ZP(_A&_X);
@ -338,7 +338,7 @@ case 0x83: ST_IX(_A&_X);
/* ARR - ARGH, MATEY! */
case 0x6B: {
uint8 arrtmp;
LD_IM(AND;__P&=~V_FLAG;__P|=(_A^(_A>>1))&0x40;arrtmp=_A>>7;_A>>=1;_A|=(__P&C_FLAG)<<7;__P&=~C_FLAG;__P|=arrtmp;X_ZN(_A));
LD_IM(AND;_P&=~V_FLAG;_P|=(_A^(_A>>1))&0x40;arrtmp=_A>>7;_A>>=1;_A|=(_P&C_FLAG)<<7;_P&=~C_FLAG;_P|=arrtmp;X_ZN(_A));
}
/* ASR */
case 0x4B: LD_IM(AND;LSRA);
@ -404,7 +404,7 @@ case 0xF2:ADDCYC(0xFF);
break;
/* LAR */
case 0xBB: RMW_ABY(__S&=x;_A=_X=__S;X_ZN(_X));
case 0xBB: RMW_ABY(_S&=x;_A=_X=_S;X_ZN(_X));
/* LAX */
case 0xA7: LD_ZP(LDA;LDX);
@ -469,7 +469,7 @@ case 0x9C: ST_ABX(_Y&(((A-_X)>>8)+1));
case 0x9E: ST_ABY(_X&(((A-_Y)>>8)+1));
/* XAS */
case 0x9B: __S=_A&_X;ST_ABY(__S& (((A-_Y)>>8)+1) );
case 0x9B: _S=_A&_X;ST_ABY(_S& (((A-_Y)>>8)+1) );
/* TOP */
case 0x0C: LD_AB(;);

View File

@ -25,6 +25,8 @@
#include "debug.h"
#include "sound.h"
#include "x6502abbrev.h"
X6502 X;
uint32 timestamp;
void (*MapIRQHook)(int a);
@ -76,18 +78,18 @@ void X6502_DMW(uint32 A, uint8 V)
#define PUSH(V) \
{ \
uint8 VTMP=V; \
WrRAM(0x100+__S,VTMP); \
__S--; \
WrRAM(0x100+_S,VTMP); \
_S--; \
}
#define POP() RdRAM(0x100+(++__S))
#define POP() RdRAM(0x100+(++_S))
static uint8 ZNTable[256];
/* Some of these operations will only make sense if you know what the flag
constants are. */
#define X_ZN(zort) __P&=~(Z_FLAG|N_FLAG);__P|=ZNTable[zort]
#define X_ZNT(zort) __P|=ZNTable[zort]
#define X_ZN(zort) _P&=~(Z_FLAG|N_FLAG);_P|=ZNTable[zort]
#define X_ZNT(zort) _P|=ZNTable[zort]
#define JR(cond); \
{ \
@ -113,24 +115,24 @@ static uint8 ZNTable[256];
/* All of the freaky arithmetic operations. */
#define AND _A&=x;X_ZN(_A)
#define BIT __P&=~(Z_FLAG|V_FLAG|N_FLAG);__P|=ZNTable[x&_A]&Z_FLAG;__P|=x&(V_FLAG|N_FLAG)
#define BIT _P&=~(Z_FLAG|V_FLAG|N_FLAG);_P|=ZNTable[x&_A]&Z_FLAG;_P|=x&(V_FLAG|N_FLAG)
#define EOR _A^=x;X_ZN(_A)
#define ORA _A|=x;X_ZN(_A)
#define ADC { \
uint32 l=_A+x+(__P&1); \
__P&=~(Z_FLAG|C_FLAG|N_FLAG|V_FLAG); \
__P|=((((_A^x)&0x80)^0x80) & ((_A^l)&0x80))>>1; \
__P|=(l>>8)&C_FLAG; \
uint32 l=_A+x+(_P&1); \
_P&=~(Z_FLAG|C_FLAG|N_FLAG|V_FLAG); \
_P|=((((_A^x)&0x80)^0x80) & ((_A^l)&0x80))>>1; \
_P|=(l>>8)&C_FLAG; \
_A=l; \
X_ZNT(_A); \
}
#define SBC { \
uint32 l=_A-x-((__P&1)^1); \
__P&=~(Z_FLAG|C_FLAG|N_FLAG|V_FLAG); \
__P|=((_A^l)&(_A^x)&0x80)>>1; \
__P|=((l>>8)&C_FLAG)^C_FLAG; \
uint32 l=_A-x-((_P&1)^1); \
_P&=~(Z_FLAG|C_FLAG|N_FLAG|V_FLAG); \
_P|=((_A^l)&(_A^x)&0x80)>>1; \
_P|=((l>>8)&C_FLAG)^C_FLAG; \
_A=l; \
X_ZNT(_A); \
}
@ -138,16 +140,16 @@ static uint8 ZNTable[256];
#define CMPL(a1,a2) { \
uint32 t=a1-a2; \
X_ZN(t&0xFF); \
__P&=~C_FLAG; \
__P|=((t>>8)&C_FLAG)^C_FLAG; \
_P&=~C_FLAG; \
_P|=((t>>8)&C_FLAG)^C_FLAG; \
}
/* Special undocumented operation. Very similar to CMP. */
#define AXS { \
uint32 t=(_A&_X)-x; \
X_ZN(t&0xFF); \
__P&=~C_FLAG; \
__P|=((t>>8)&C_FLAG)^C_FLAG; \
_P&=~C_FLAG; \
_P|=((t>>8)&C_FLAG)^C_FLAG; \
_X=t; \
}
@ -159,26 +161,26 @@ static uint8 ZNTable[256];
#define DEC x--;X_ZN(x)
#define INC x++;X_ZN(x)
#define ASL __P&=~C_FLAG;__P|=x>>7;x<<=1;X_ZN(x)
#define LSR __P&=~(C_FLAG|N_FLAG|Z_FLAG);__P|=x&1;x>>=1;X_ZNT(x)
#define ASL _P&=~C_FLAG;_P|=x>>7;x<<=1;X_ZN(x)
#define LSR _P&=~(C_FLAG|N_FLAG|Z_FLAG);_P|=x&1;x>>=1;X_ZNT(x)
/* For undocumented instructions, maybe for other things later... */
#define LSRA __P&=~(C_FLAG|N_FLAG|Z_FLAG);__P|=_A&1;_A>>=1;X_ZNT(_A)
#define LSRA _P&=~(C_FLAG|N_FLAG|Z_FLAG);_P|=_A&1;_A>>=1;X_ZNT(_A)
#define ROL { \
uint8 l=x>>7; \
x<<=1; \
x|=__P&C_FLAG; \
__P&=~(Z_FLAG|N_FLAG|C_FLAG); \
__P|=l; \
x|=_P&C_FLAG; \
_P&=~(Z_FLAG|N_FLAG|C_FLAG); \
_P|=l; \
X_ZNT(x); \
}
#define ROR { \
uint8 l=x&1; \
x>>=1; \
x|=(__P&C_FLAG)<<7; \
__P&=~(Z_FLAG|N_FLAG|C_FLAG); \
__P|=l; \
x|=(_P&C_FLAG)<<7; \
_P&=~(Z_FLAG|N_FLAG|C_FLAG); \
_P|=l; \
X_ZNT(x); \
}
@ -392,7 +394,7 @@ void X6502_Init(void)
void X6502_Power(void)
{
_count=_tcount=_IRQlow=_PC=_A=_X=_Y=__S=__P=_PI=_DB=_jammed=0;
_count=_tcount=_IRQlow=_PC=_A=_X=_Y=_S=_P=_PI=_DB=_jammed=0;
timestamp=0;
X6502_Reset();
}
@ -419,7 +421,7 @@ void X6502_Run(int32 cycles)
_PC=RdMem(0xFFFC);
_PC|=RdMem(0xFFFD)<<8;
_jammed=0;
_PI=__P=I_FLAG;
_PI=_P=I_FLAG;
_IRQlow&=~FCEU_IQRESET;
}
else if(_IRQlow&FCEU_IQNMI2)
@ -434,8 +436,8 @@ void X6502_Run(int32 cycles)
ADDCYC(7);
PUSH(_PC>>8);
PUSH(_PC);
PUSH((__P&~B_FLAG)|(U_FLAG));
__P|=I_FLAG;
PUSH((_P&~B_FLAG)|(U_FLAG));
_P|=I_FLAG;
DEBUG( if(debug_loggingCD) LogCDVectors(1) );
_PC=RdMem(0xFFFA);
_PC|=RdMem(0xFFFB)<<8;
@ -449,8 +451,8 @@ void X6502_Run(int32 cycles)
ADDCYC(7);
PUSH(_PC>>8);
PUSH(_PC);
PUSH((__P&~B_FLAG)|(U_FLAG));
__P|=I_FLAG;
PUSH((_P&~B_FLAG)|(U_FLAG));
_P|=I_FLAG;
DEBUG( if(debug_loggingCD) LogCDVectors(1) );
_PC=RdMem(0xFFFE);
_PC|=RdMem(0xFFFF)<<8;
@ -459,7 +461,7 @@ void X6502_Run(int32 cycles)
_IRQlow&=~(FCEU_IQTEMP);
if(_count<=0)
{
_PI=__P;
_PI=_P;
return;
} //Should increase accuracy without a
//major speed hit.
@ -468,7 +470,7 @@ void X6502_Run(int32 cycles)
//will probably cause a major speed decrease on low-end systems
DEBUG( DebugCycle() );
_PI=__P;
_PI=_P;
b1=RdMem(_PC);
ADDCYC(CycTable[b1]);

View File

@ -23,18 +23,6 @@
#include "x6502struct.h"
extern X6502 X;
#define _PC X.PC
#define _A X.A
#define _X X.X
#define _Y X.Y
#define __S X.S
#define __P X.P
#define _PI X.mooPI
#define _DB X.DB
#define _count X.count
#define _tcount X.tcount
#define _IRQlow X.IRQlow
#define _jammed X.jammed
//the opsize table is used to quickly grab the instruction sizes (in bytes)

20
src/x6502abbrev.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef _X6502ABBREV_H_
#define _X6502ABBREV_H_
//include this file LAST, or else the #defines will overwrite CRT and STL symbols
#define _PC X.PC
#define _A X.A
#define _X X.X
#define _Y X.Y
#define _S X.S
#define _P X.P
#define _PI X.mooPI
#define _DB X.DB
#define _count X.count
#define _tcount X.tcount
#define _IRQlow X.IRQlow
#define _jammed X.jammed
#endif