From f4ab095a5ea4f86a24df6a4b0b942280d043c1e8 Mon Sep 17 00:00:00 2001 From: jeblanchard Date: Thu, 29 May 2008 01:22:17 +0000 Subject: [PATCH] Initial support for tools tracking memory reads&writes. --- src/SConscript | 1 + src/mem-cb.cpp | 29 +++++++++++++++++++++++++++++ src/mem-cb.h | 17 +++++++++++++++++ src/x6502.cpp | 27 +++++++++++++++++++++++++++ vc8/fceux.vcproj | 8 ++++++++ 5 files changed, 82 insertions(+) create mode 100644 src/mem-cb.cpp create mode 100644 src/mem-cb.h diff --git a/src/SConscript b/src/SConscript index 21b4c31b..49031d28 100644 --- a/src/SConscript +++ b/src/SConscript @@ -12,6 +12,7 @@ file.cpp filter.cpp ines.cpp input.cpp +mem-cb.cpp netplay.cpp nsf.cpp palette.cpp diff --git a/src/mem-cb.cpp b/src/mem-cb.cpp new file mode 100644 index 00000000..46379972 --- /dev/null +++ b/src/mem-cb.cpp @@ -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; + (*memCallbacks. read_cb)[FCEU_AddressCanonicalize(A)] = cb; +} + +void FCEU_AddressWriteCallback(uint32 A, writefunc cb) +{ + if (!memCallbacks.write_cb) memCallbacks.write_cb = new map; + (*memCallbacks.write_cb)[FCEU_AddressCanonicalize(A)] = cb; +} + +uint32 FCEU_AddressCanonicalize(uint32 A) +{ + if (A >= 0x0800 && A < 0x2000) return (A & 0x07FF); + return A; +} diff --git a/src/mem-cb.h b/src/mem-cb.h new file mode 100644 index 00000000..b777d02c --- /dev/null +++ b/src/mem-cb.h @@ -0,0 +1,17 @@ +#ifndef MEM_CB_H +#define MEM_CB_H + +#include + +void FCEU_AddressReadCallback(uint32 A, readfunc cb); +void FCEU_AddressWriteCallback(uint32 A, writefunc cb); +uint32 FCEU_AddressCanonicalize(uint32 A); + +extern struct MEMCALLBACKS +{ + std::map * read_cb; + std::map *write_cb; + ~MEMCALLBACKS(); +} memCallbacks; + +#endif diff --git a/src/x6502.cpp b/src/x6502.cpp index 367b991b..7f36eaf6 100644 --- a/src/x6502.cpp +++ b/src/x6502.cpp @@ -24,6 +24,7 @@ #include "fceu.h" #include "debug.h" #include "sound.h" +#include "mem-cb.h" X6502 X; uint32 timestamp; @@ -37,39 +38,65 @@ void FP_FASTAPASS(1) (*MapIRQHook)(int a); timestamp+=__x; \ } +static INLINE void RdRunCB(unsigned int A) +{ + if (memCallbacks.read_cb) + { + std::map::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::const_iterator i = + memCallbacks.write_cb->find(FCEU_AddressCanonicalize(A)); + if (i != memCallbacks.write_cb->end()) (i->second)(A, V); + } +} + //normal memory read static INLINE uint8 RdMem(unsigned int A) { + RdRunCB(A); return(_DB=ARead[A](A)); } //normal memory write static INLINE void WrMem(unsigned int A, uint8 V) { + WrRunCB(A, V); BWrite[A](A,V); } static INLINE uint8 RdRAM(unsigned int A) { //bbit edited: this was changed so cheat substituion would work + RdRunCB(A); return(_DB=ARead[A](A)); // return(_DB=RAM[A]); } static INLINE void WrRAM(unsigned int A, uint8 V) { + WrRunCB(A, V); RAM[A]=V; } uint8 FASTAPASS(1) X6502_DMR(uint32 A) { ADDCYC(1); + RdRunCB(A); return(X.DB=ARead[A](A)); } void FASTAPASS(2) X6502_DMW(uint32 A, uint8 V) { ADDCYC(1); + WrRunCB(A, V); BWrite[A](A,V); } diff --git a/vc8/fceux.vcproj b/vc8/fceux.vcproj index 8e824892..02919192 100644 --- a/vc8/fceux.vcproj +++ b/vc8/fceux.vcproj @@ -1526,6 +1526,10 @@ RelativePath="..\src\input.h" > + + @@ -2256,6 +2260,10 @@ RelativePath="..\src\input.cpp" > + +