#include "sound.h"
#include "cart.h"
+#include "dprintf.h"
+
#ifdef DEBUG_ASM_6502
+#include <stdio.h>
+#include <stdlib.h>
extern uint32 PC_prev, OP_prev;
-extern int cpu_lastval;
+extern uint8 dreads[4];
+extern uint32 dwrites_c[2];
+extern int dread_count_c, dwrite_count_c;
+extern int mapirq_cyc_c;
+extern void (*MapIRQHook)(int a);
+#define DummyRdMem(...)
+#else
+#define DummyRdMem RdMem
+void FP_FASTAPASS(1) (*MapIRQHook)(int a);
#endif
X6502 X;
uint32 timestamp;
-void FP_FASTAPASS(1) (*MapIRQHook)(int a);
#define _PC X.PC
#define _A X.A
#endif
_DB=ARead[A](A);
#ifdef DEBUG_ASM_6502
- // TODO: read counter, not 0x10000..
- if (cpu_lastval)
- cpu_lastval|=_DB<<8;
- else
- cpu_lastval=_DB|0x10000;
- printf("read [%04x] %02x, cpu_lastval=%02x\n", A, _DB, cpu_lastval);
+ //printf("a == %x, pc == %x\n", A, _PC);
+ if (A >= 0x2000 && A != _PC && A != _PC - 1 && A != _PC + 1) {
+ dreads[dread_count_c++] = _DB;
+ if (dread_count_c > 4) { printf("dread_count out of range\n"); exit(1); }
+ }
#endif
return _DB;
}
static INLINE void WrMem(unsigned int A, uint8 V)
{
+ //printf("w [%04x] %02x\n", A, V);
if ((A&0xe000) == 0) { // RAM area (always 0-0x1fff)
RAM[A&0x7FF] = V;
return;
}
BWrite[A](A,V);
+#ifdef DEBUG_ASM_6502
+ dwrites_c[dwrite_count_c++] = (A<<8)|V;
+ if (dwrite_count_c > 2) { printf("dwrite_count_c out of range\n"); exit(1); }
+#endif
}
static INLINE uint8 RdRAM(unsigned int A)
static INLINE void ADDCYC(int x)
{
- //_tcount+=x;
+ _tcount+=x;
_count-=x*48;
timestamp+=x;
}
if((target^tmp)&0x100) \
{ \
target&=0xFFFF; \
- RdMem(target^0x100); \
+ DummyRdMem(target^0x100); \
ADDCYC(1); \
} \
}
target=rt; \
target+=i; \
target&=0xFFFF; \
- RdMem((target&0x00FF)|(rt&0xFF00)); \
+ DummyRdMem((target&0x00FF)|(rt&0xFF00)); \
}
/* Zero Page */
if((target^rt)&0x100) \
{ \
target&=0xFFFF; \
- RdMem(target^0x100); \
+ DummyRdMem(target^0x100); \
ADDCYC(1); \
} \
}
rt|=RdRAM(tmp)<<8; \
target=rt; \
target+=_Y; \
- RdMem((target&0x00FF)|(rt&0xFF00)); \
+ DummyRdMem((target&0x00FF)|(rt&0xFF00)); \
}
/* Now come the macros to wrap up all of the above stuff addressing mode functions
void FASTAPASS(1) X6502_IRQBegin_c(int w)
{
+ dprintf("IRQB %02x",w);
_IRQlow|=w;
}
void FASTAPASS(1) X6502_IRQEnd_c(int w)
{
+ dprintf("IRQE %02x",w);
_IRQlow&=~w;
}
{
if(!_jammed)
{
+ dprintf("NMI");
ADDCYC(7);
PUSH(_PC>>8);
PUSH(_PC);
{
if(!(_PI&I_FLAG) && !_jammed)
{
+ dprintf("IRQ");
ADDCYC(7);
PUSH(_PC>>8);
PUSH(_PC);
{
_PC=RdMem(0xFFFC);
_PC|=RdMem(0xFFFD)<<8;
- if(FCEUGameInfo.type==GIT_NSF) _PC=0x3830;
_jammed=0;
_PI=_P=I_FLAG;
}
TriggerIRQReal();
_IRQlow&=~(FCEU_IQTEMP|FCEU_IQNMI);
- if(_count<=0) {_PI=_P;return;} /* Should increase accuracy without a */
- /* major speed hit. */
+ if(_count<=0)
+ {
+#ifdef DEBUG_ASM_6502
+ if(MapIRQHook) mapirq_cyc_c = _tcount;
+ _tcount=0;
+#endif
+ _PI=_P;
+ return; /* Should increase accuracy without a major speed hit. */
+ }
}
_PI=_P;
b1=RdMem(_PC);
- temp=CycTable[b1];
- ADDCYC(temp);
- //temp=_tcount;
- //_tcount=0;
-
- if(MapIRQHook) MapIRQHook(temp);
+ ADDCYC(CycTable[b1]);
+ temp=_tcount;
temp*=48;
#ifdef DEBUG_ASM_6502
PC_prev = _PC;
OP_prev = b1;
- cpu_lastval = 0;
#endif
//printf("$%04x:$%02x\n",_PC,b1);
//_PC++;
#include "ops.h"
}
+ temp=_tcount; /* Gradius II (J) glitches if _tcount is not used */
+ _tcount=0;
+
+ if(MapIRQHook) {
+#ifdef DEBUG_ASM_6502
+ mapirq_cyc_c = temp;
+#endif
+ MapIRQHook(temp);
+ }
+
#ifdef DEBUG_ASM_6502
_PI=_P;
#endif