diff --git a/bin/loader.cpp b/bin/loader.cpp index 80032f9..b63e9cb 100644 --- a/bin/loader.cpp +++ b/bin/loader.cpp @@ -25,6 +25,7 @@ #include #include +#include struct { uint32_t ram; @@ -128,6 +129,8 @@ uint32_t load(const char *file) uint32_t jtStart = 0; uint32_t jtEnd = 0; + // todo -- call RM::Native to open and load the Resource File. + assert(FSPathMakeRef( (const UInt8 *)file, &ref, NULL) == noErr); refNum = FSOpenResFile(&ref, fsRdPerm); assert(refNum != -1 ); @@ -281,8 +284,6 @@ void GlobalInit() } -extern "C" { const char *TrapName(uint16_t trap); } - void LogToolBox(uint32_t pc, uint16_t trap) { const char *name; @@ -378,6 +379,45 @@ void InstructionLogger() } +void MemoryLogger(uint32_t address, int size, int readWrite, uint32_t value) +{ + if (address < kGlobalSize) + { + const char *name = GlobalName(address); + if (!name) name = "unknown"; + + fprintf(stderr, "%-20s %08x - ", name, address); + if (readWrite) + { + fprintf(stderr, " write %d bytes", size); + switch(size) + { + case 1: + fprintf(stderr, " [%02x]\n", value); + break; + case 2: + fprintf(stderr, " [%04x]\n", value); + break; + case 3: + fprintf(stderr, " [%06x]\n", value); + break; + case 4: + fprintf(stderr, " [%08x]\n", value); + break; + default: + fprintf(stderr, "\n"); + break; + } + } + else + { + fprintf(stderr, " read %d bytes\n", size); + } + + } +} + + #define MPW_VERSION "0.4" void help() { @@ -654,8 +694,8 @@ int main(int argc, char **argv) cpuSetFLineExceptionFunc(MPW::dispatch); - if (Flags.traceGlobals) memorySetGlobalLog(kGlobalSize); - + if (Flags.traceGlobals) //memorySetGlobalLog(kGlobalSize); + memorySetLoggingFunc(MemoryLogger); MPW::Trace = Flags.traceMPW; ToolBox::Trace = Flags.traceToolBox; @@ -705,6 +745,7 @@ int main(int argc, char **argv) if (cpuGetStop()) break; // will this also be set by an interrupt? + #ifndef CPU_INSTRUCTION_LOGGING if (Flags.traceCPU || Flags.traceMacsbug) diff --git a/cpu/CpuModule.h b/cpu/CpuModule.h index 7e932d6..2d3e956 100644 --- a/cpu/CpuModule.h +++ b/cpu/CpuModule.h @@ -21,6 +21,10 @@ extern void cpuCheckPendingInterrupts(void); extern void cpuSetUpInterrupt(void); extern void cpuInitializeFromNewPC(ULO new_pc); + +typedef void (*memoryLoggingFunc)(uint32_t address, int size, int readWrite, uint32_t value); +extern void memorySetLoggingFunc(memoryLoggingFunc func); + // Logging interface #ifdef CPU_INSTRUCTION_LOGGING diff --git a/cpu/memory.c b/cpu/memory.c index a7d532c..107c670 100644 --- a/cpu/memory.c +++ b/cpu/memory.c @@ -48,6 +48,14 @@ static uint8_t *Memory = NULL; static uint32_t MemorySize = 0; static uint32_t MemoryGlobalLog = 0; +static memoryLoggingFunc MemoryLoggingFunc = NULL; + +void memorySetLoggingFunc(memoryLoggingFunc func) +{ + MemoryLoggingFunc = func; +} + + void memorySetMemory(uint8_t *memory, uint32_t size) { Memory = memory; @@ -70,10 +78,9 @@ uint8_t *memoryPointer(uint32_t address) UBY memoryReadByte(ULO address) { - if (address < MemoryGlobalLog) - { - fprintf(stderr, "memoryReadByte(%08x)\n", address); - } + if (MemoryLoggingFunc) + MemoryLoggingFunc(address, 1, 0, 0); + // hmmm... 32-bit clean addresses? if (address < MemorySize) @@ -84,11 +91,8 @@ UBY memoryReadByte(ULO address) UWO memoryReadWord(ULO address) { - if (address < MemoryGlobalLog) - { - fprintf(stderr, "memoryReadWord(%08x)\n", address); - } - + if (MemoryLoggingFunc) + MemoryLoggingFunc(address, 2, 0, 0); if (address & 0x01) memoryOddRead(address); @@ -101,10 +105,9 @@ UWO memoryReadWord(ULO address) ULO memoryReadLong(ULO address) { - if (address < MemoryGlobalLog) - { - fprintf(stderr, "memoryReadLong(%08x)\n", address); - } + + if (MemoryLoggingFunc) + MemoryLoggingFunc(address, 4, 0, 0); if (address & 0x01) memoryOddRead(address); @@ -131,10 +134,9 @@ uint64_t memoryReadLongLong(ULO address) void memoryWriteByte(UBY data, ULO address) { - if (address < MemoryGlobalLog) - { - fprintf(stderr, "memoryWriteByte(%02x, %08x)\n", data, address); - } + + if (MemoryLoggingFunc) + MemoryLoggingFunc(address, 1, 1, data); if (address < MemorySize) { @@ -145,10 +147,8 @@ void memoryWriteByte(UBY data, ULO address) void memoryWriteWord(UWO data, ULO address) { - if (address < MemoryGlobalLog) - { - fprintf(stderr, "memoryWriteWord(%04x, %08x)\n", data, address); - } + if (MemoryLoggingFunc) + MemoryLoggingFunc(address, 2, 1, data); if (address & 0x01) memoryOddWrite(address); @@ -162,10 +162,8 @@ void memoryWriteWord(UWO data, ULO address) void memoryWriteLong(ULO data, ULO address) { - if (address < MemoryGlobalLog) - { - fprintf(stderr, "memoryWriteLong(%08x, %08x)\n", data, address); - } + if (MemoryLoggingFunc) + MemoryLoggingFunc(address, 4, 1, data); if (address & 0x01) memoryOddWrite(address); @@ -182,10 +180,6 @@ void memoryWriteLong(ULO data, ULO address) void memoryWriteLongLong(uint64_t data, ULO address) { - if (address < MemoryGlobalLog) - { - fprintf(stderr, "memoryWriteLongLong(%08llx, %08x)\n", data, address); - } if (address & 0x01) memoryOddWrite(address);