From e4cf98bfe1b811abec1ffd9a3195e94b5c041dfc Mon Sep 17 00:00:00 2001 From: Godzil Date: Sun, 4 Apr 2021 21:05:48 +0100 Subject: [PATCH] Add a debug function to log all access to IO regs. --- source/io.cpp | 22 ++++++++++++++++++++++ source/nec/nec.cpp | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/source/io.cpp b/source/io.cpp index 400b816..7cc3be8 100644 --- a/source/io.cpp +++ b/source/io.cpp @@ -29,10 +29,13 @@ #include "audio.h" #include "memory.h" +#define IO_DUMP + extern uint8_t *externalEeprom; extern uint32_t romAddressMask; extern uint16_t *internalEeprom; extern nec_Regs I; +extern uint64_t nec_monotonicCycles; enum { @@ -86,6 +89,8 @@ uint8_t ws_key_flipped; int rtcDataRegisterReadCount=0; +FILE *ioLogFp = NULL; + //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// @@ -139,6 +144,10 @@ void ws_io_init(void) ws_io_reset(); ws_key_flipped=0; + +#ifdef IO_DUMP + ioLogFp = fopen("iodump.csv", "wt"); +#endif } //////////////////////////////////////////////////////////////////////////////// // @@ -172,6 +181,10 @@ void ws_io_done(void) { free(ws_ioRam); } + +#ifdef IO_DUMP + fclose(ioLogFp); +#endif } /* Serial port */ @@ -582,6 +595,10 @@ uint8_t cpu_readport(uint8_t port) exit: + if (ioLogFp) + { + fprintf(ioLogFp, "%ld, R, %02X, %02X\n", nec_monotonicCycles, port, retVal); + } return retVal; } //////////////////////////////////////////////////////////////////////////////// @@ -600,6 +617,11 @@ void cpu_writeport(uint32_t port,uint8_t value) int unknown_io_port=0; + if (ioLogFp) + { + fprintf(ioLogFp, "%ld, W, %02X, %02X\n", nec_monotonicCycles, port, value); + } + if (port > 0x100) { port &= 0xFF; diff --git a/source/nec/nec.cpp b/source/nec/nec.cpp index ff79ac1..1f4b76f 100644 --- a/source/nec/nec.cpp +++ b/source/nec/nec.cpp @@ -38,6 +38,7 @@ /* cpu state */ /***************************************************************************/ +uint64_t nec_monotonicCycles; int nec_ICount; nec_Regs I; @@ -65,6 +66,7 @@ void nec_reset (void *param) unsigned int i,j,c; BREGS reg_name[8]= { AL, CL, DL, BL, AH, CH, DH, BH }; + nec_monotonicCycles = 0; memset( &I, 0, sizeof(I) ); @@ -3912,7 +3914,7 @@ const char *instructionsName[256] = int nec_execute(int cycles) { - + int done; nec_ICount=cycles; // cpu_type=V30; @@ -3928,6 +3930,10 @@ int nec_execute(int cycles) // nec_ICount++; } - return cycles - nec_ICount; + done = cycles - nec_ICount; + + nec_monotonicCycles += done; + + return done; }