Initial support for tools tracking memory reads&writes.

This commit is contained in:
jeblanchard 2008-05-29 01:22:17 +00:00
parent 44ea956424
commit f4ab095a5e
5 changed files with 82 additions and 0 deletions

View File

@ -12,6 +12,7 @@ file.cpp
filter.cpp filter.cpp
ines.cpp ines.cpp
input.cpp input.cpp
mem-cb.cpp
netplay.cpp netplay.cpp
nsf.cpp nsf.cpp
palette.cpp palette.cpp

29
src/mem-cb.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "types.h"
#include "mem-cb.h"
using namespace std;
struct MEMCALLBACKS memCallbacks;
MEMCALLBACKS::~MEMCALLBACKS()
{
delete read_cb;
delete write_cb;
}
void FCEU_AddressReadCallback(uint32 A, readfunc cb)
{
if (!memCallbacks. read_cb) memCallbacks. read_cb = new map<uint32, readfunc>;
(*memCallbacks. read_cb)[FCEU_AddressCanonicalize(A)] = cb;
}
void FCEU_AddressWriteCallback(uint32 A, writefunc cb)
{
if (!memCallbacks.write_cb) memCallbacks.write_cb = new map<uint32, writefunc>;
(*memCallbacks.write_cb)[FCEU_AddressCanonicalize(A)] = cb;
}
uint32 FCEU_AddressCanonicalize(uint32 A)
{
if (A >= 0x0800 && A < 0x2000) return (A & 0x07FF);
return A;
}

17
src/mem-cb.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef MEM_CB_H
#define MEM_CB_H
#include <map>
void FCEU_AddressReadCallback(uint32 A, readfunc cb);
void FCEU_AddressWriteCallback(uint32 A, writefunc cb);
uint32 FCEU_AddressCanonicalize(uint32 A);
extern struct MEMCALLBACKS
{
std::map<uint32, readfunc> * read_cb;
std::map<uint32, writefunc> *write_cb;
~MEMCALLBACKS();
} memCallbacks;
#endif

View File

@ -24,6 +24,7 @@
#include "fceu.h" #include "fceu.h"
#include "debug.h" #include "debug.h"
#include "sound.h" #include "sound.h"
#include "mem-cb.h"
X6502 X; X6502 X;
uint32 timestamp; uint32 timestamp;
@ -37,39 +38,65 @@ void FP_FASTAPASS(1) (*MapIRQHook)(int a);
timestamp+=__x; \ timestamp+=__x; \
} }
static INLINE void RdRunCB(unsigned int A)
{
if (memCallbacks.read_cb)
{
std::map<uint32, readfunc>::const_iterator i =
memCallbacks.read_cb->find(FCEU_AddressCanonicalize(A));
if (i != memCallbacks.read_cb->end()) (i->second)(A);
}
}
static INLINE void WrRunCB(unsigned int A, uint8 V)
{
if (memCallbacks.write_cb)
{
std::map<uint32, writefunc>::const_iterator i =
memCallbacks.write_cb->find(FCEU_AddressCanonicalize(A));
if (i != memCallbacks.write_cb->end()) (i->second)(A, V);
}
}
//normal memory read //normal memory read
static INLINE uint8 RdMem(unsigned int A) static INLINE uint8 RdMem(unsigned int A)
{ {
RdRunCB(A);
return(_DB=ARead[A](A)); return(_DB=ARead[A](A));
} }
//normal memory write //normal memory write
static INLINE void WrMem(unsigned int A, uint8 V) static INLINE void WrMem(unsigned int A, uint8 V)
{ {
WrRunCB(A, V);
BWrite[A](A,V); BWrite[A](A,V);
} }
static INLINE uint8 RdRAM(unsigned int A) static INLINE uint8 RdRAM(unsigned int A)
{ {
//bbit edited: this was changed so cheat substituion would work //bbit edited: this was changed so cheat substituion would work
RdRunCB(A);
return(_DB=ARead[A](A)); return(_DB=ARead[A](A));
// return(_DB=RAM[A]); // return(_DB=RAM[A]);
} }
static INLINE void WrRAM(unsigned int A, uint8 V) static INLINE void WrRAM(unsigned int A, uint8 V)
{ {
WrRunCB(A, V);
RAM[A]=V; RAM[A]=V;
} }
uint8 FASTAPASS(1) X6502_DMR(uint32 A) uint8 FASTAPASS(1) X6502_DMR(uint32 A)
{ {
ADDCYC(1); ADDCYC(1);
RdRunCB(A);
return(X.DB=ARead[A](A)); return(X.DB=ARead[A](A));
} }
void FASTAPASS(2) X6502_DMW(uint32 A, uint8 V) void FASTAPASS(2) X6502_DMW(uint32 A, uint8 V)
{ {
ADDCYC(1); ADDCYC(1);
WrRunCB(A, V);
BWrite[A](A,V); BWrite[A](A,V);
} }

View File

@ -1526,6 +1526,10 @@
RelativePath="..\src\input.h" RelativePath="..\src\input.h"
> >
</File> </File>
<File
RelativePath="..\src\mem-cb.h"
>
</File>
<File <File
RelativePath="..\src\memory.h" RelativePath="..\src\memory.h"
> >
@ -2256,6 +2260,10 @@
RelativePath="..\src\input.cpp" RelativePath="..\src\input.cpp"
> >
</File> </File>
<File
RelativePath="..\src\mem-cb.cpp"
>
</File>
<File <File
RelativePath="..\src\movie.cpp" RelativePath="..\src\movie.cpp"
> >