From 97b5dd6400e78c9ad2c9b3a9278048ce99bca5d1 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 16 Feb 2013 18:51:28 -0500 Subject: [PATCH] toolbox logging flag. --- bin/loader.cpp | 1 + toolbox/mm.cpp | 25 +++++++++++--------- toolbox/mpw_time.cpp | 13 ++++++----- toolbox/os.cpp | 54 +++++++++++++++++++++++--------------------- toolbox/qd.cpp | 37 ++++-------------------------- toolbox/rm.cpp | 8 ++++--- toolbox/toolbox.cpp | 3 +-- toolbox/toolbox.h | 12 ++++++++++ 8 files changed, 73 insertions(+), 80 deletions(-) diff --git a/bin/loader.cpp b/bin/loader.cpp index 2af8a49..eb53c83 100644 --- a/bin/loader.cpp +++ b/bin/loader.cpp @@ -700,6 +700,7 @@ int main(int argc, char **argv) MPW::Init(); MPW::Trace = Flags.traceMPW; + ToolBox::Trace = Flags.traceToolBox; if (!Flags.stack) { diff --git a/toolbox/mm.cpp b/toolbox/mm.cpp index 503bdfb..ee0259a 100644 --- a/toolbox/mm.cpp +++ b/toolbox/mm.cpp @@ -1,4 +1,5 @@ #include "mm.h" +#include "toolbox.h" #include #include @@ -11,6 +12,8 @@ #include +using ToolBox::Log; + namespace { mplite_t pool; @@ -108,7 +111,7 @@ namespace MM uint32_t dest = cpuGetAReg(1); uint32_t count = cpuGetDReg(0); - fprintf(stderr, "%04x BlockMove(%08x, %08x, %08x)\n", + Log("%04x BlockMove(%08x, %08x, %08x)\n", trap, source, dest, count); // TODO -- 32-bit clean? @@ -139,8 +142,9 @@ namespace MM */ uint32_t cbNeeded = cpuGetDReg(0); - fprintf(stderr, "%04x CompactMem(%08x)\n", trap, cbNeeded); + Log("%04x CompactMem(%08x)\n", trap, cbNeeded); + // todo -- add mplite call to return total free mem, largest block. return 0x0f0000; } @@ -165,8 +169,7 @@ namespace MM uint32_t size = cpuGetDReg(0); - fprintf(stderr, "%04x NewPtr(%08x)\n", trap, size); - + Log("%04x NewPtr(%08x)\n", trap, size); // todo -- separate pools for sys vs non-sys? // todo -- NewPtr(0) -- null or empty ptr? @@ -209,7 +212,7 @@ namespace MM uint32_t mcptr = cpuGetAReg(0); - fprintf(stderr, "%04x DisposePtr(%08x)\n", trap, mcptr); + Log("%04x DisposePtr(%08x)\n", trap, mcptr); auto iter = PtrMap.find(mcptr); @@ -237,7 +240,7 @@ namespace MM uint32_t mcptr = cpuGetAReg(0); - fprintf(stderr, "%08x GetPtrSize(%08x,)\n", trap, mcptr); + Log("%08x GetPtrSize(%08x,)\n", trap, mcptr); auto iter = PtrMap.find(mcptr); @@ -261,7 +264,7 @@ namespace MM uint32_t mcptr = cpuGetAReg(0); uint32_t newSize = cpuGetDReg(0); - fprintf(stderr, "%08x SetPtrSize(%08x, %08x)\n", trap, mcptr, newSize); + Log("%08x SetPtrSize(%08x, %08x)\n", trap, mcptr, newSize); auto iter = PtrMap.find(mcptr); @@ -303,7 +306,7 @@ namespace MM uint32_t size = cpuGetDReg(0); - fprintf(stderr, "%04x NewHandle(%08x)\n", trap, size); + Log("%04x NewHandle(%08x)\n", trap, size); if (!HandleQueue.size()) { @@ -356,7 +359,7 @@ namespace MM uint32_t hh = cpuGetAReg(0); - fprintf(stderr, "%04x DisposeHandle(%08x)\n", trap, hh); + Log("%04x DisposeHandle(%08x)\n", trap, hh); auto iter = HandleMap.find(hh); @@ -393,7 +396,7 @@ namespace MM uint32_t hh = cpuGetAReg(0); - fprintf(stderr, "%04x HLock(%08x)\n", trap, hh); + Log("%04x HLock(%08x)\n", trap, hh); auto iter = HandleMap.find(hh); @@ -415,7 +418,7 @@ namespace MM uint32_t hh = cpuGetAReg(0); - fprintf(stderr, "%04x HUnlock(%08x)\n", trap, hh); + Log("%04x HUnlock(%08x)\n", trap, hh); auto iter = HandleMap.find(hh); diff --git a/toolbox/mpw_time.cpp b/toolbox/mpw_time.cpp index 3af81f0..fc41ddc 100644 --- a/toolbox/mpw_time.cpp +++ b/toolbox/mpw_time.cpp @@ -10,14 +10,15 @@ #include "stackframe.h" +using ToolBox::Log; + // todo -- have background thread to update Ticks and Time global variables? -namespace { +namespace +{ const long EpochAdjust = 86400 * (365 * (1970 - 1904) + 17); // 17 leap years. - - } namespace Time { @@ -48,7 +49,7 @@ namespace Time uint32_t secsPtr = cpuGetAReg(0); - fprintf(stderr, "%04x ReadDateTime(%08x)\n", trap, secsPtr); + Log("%04x ReadDateTime(%08x)\n", trap, secsPtr); now = ::time(NULL); @@ -76,7 +77,7 @@ namespace Time uint32_t s = cpuGetDReg(0); uint32_t dtPtr = cpuGetAReg(0); - fprintf(stderr, "%04x SecondsToDate(%08x, %08x)\n", trap, s, dtPtr); + Log("%04x SecondsToDate(%08x, %08x)\n", trap, s, dtPtr); if (dtPtr) @@ -103,7 +104,7 @@ namespace Time { uint32_t ticks; - fprintf(stderr, "%04x TickCount()\n", trap); + Log("%04x TickCount()\n", trap); //auto t = std::chrono::steady_clock::now(); ticks = 0; diff --git a/toolbox/os.cpp b/toolbox/os.cpp index 285c552..ad65281 100644 --- a/toolbox/os.cpp +++ b/toolbox/os.cpp @@ -19,6 +19,8 @@ #include +using ToolBox::Log; + namespace { using namespace OS; @@ -140,13 +142,13 @@ namespace OS uint32_t parm = cpuGetAReg(0); - fprintf(stderr, "%04x Create(%08x)\n", trap, parm); + Log("%04x Create(%08x)\n", trap, parm); - uint32_t ioCompletion = memoryReadLong(parm + 12); + //uint32_t ioCompletion = memoryReadLong(parm + 12); uint32_t namePtr = memoryReadLong(parm + 18); - uint16_t ioVRefNum = memoryReadWord(parm + 22); - uint8_t ioFVersNum = memoryReadByte(parm + 26); + //uint16_t ioVRefNum = memoryReadWord(parm + 22); + //uint8_t ioFVersNum = memoryReadByte(parm + 26); std::string sname = ToolBox::ReadPString(namePtr); @@ -155,7 +157,7 @@ namespace OS memoryWriteWord(bdNamErr, parm + 16); return bdNamErr; } - fprintf(stderr, " Create(%s)\n", sname.c_str()); + Log(" Create(%s)\n", sname.c_str()); int fd; fd = ::open(sname.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0666); @@ -180,13 +182,13 @@ namespace OS uint32_t parm = cpuGetAReg(0); - fprintf(stderr, "%04x Delete(%08x)\n", trap, parm); + Log("%04x Delete(%08x)\n", trap, parm); - uint32_t ioCompletion = memoryReadLong(parm + 12); + //uint32_t ioCompletion = memoryReadLong(parm + 12); uint32_t namePtr = memoryReadLong(parm + 18); - uint16_t ioVRefNum = memoryReadWord(parm + 22); - uint8_t ioFVersNum = memoryReadByte(parm + 26); + //uint16_t ioVRefNum = memoryReadWord(parm + 22); + //uint8_t ioFVersNum = memoryReadByte(parm + 26); std::string sname = ToolBox::ReadPString(namePtr); @@ -195,7 +197,7 @@ namespace OS memoryWriteWord(bdNamErr, parm + 16); return bdNamErr; } - fprintf(stderr, " Delete(%s)\n", sname.c_str()); + Log(" Delete(%s)\n", sname.c_str()); int ok = ::unlink(sname.c_str()); if (ok < 0) @@ -214,9 +216,9 @@ namespace OS uint32_t parm = cpuGetAReg(0); - fprintf(stderr, "%04x GetEOF(%08x)\n", trap, parm); + Log("%04x GetEOF(%08x)\n", trap, parm); - uint32_t ioCompletion = memoryReadLong(parm + 12); + //uint32_t ioCompletion = memoryReadLong(parm + 12); uint16_t ioRefNum = memoryReadWord(parm + 24); struct stat st; @@ -246,10 +248,10 @@ namespace OS { uint32_t parm = cpuGetAReg(0); - fprintf(stderr, "%04x GetVol(%08x)\n", trap, parm); + Log("%04x GetVol(%08x)\n", trap, parm); - uint32_t ioCompletion = memoryReadLong(parm + 12); + //uint32_t ioCompletion = memoryReadLong(parm + 12); uint32_t namePtr = memoryReadLong(parm + 18); // ioResult @@ -270,12 +272,12 @@ namespace OS uint32_t parm = cpuGetAReg(0); - fprintf(stderr, "%04x GetFileInfo(%08x)\n", trap, parm); + Log("%04x GetFileInfo(%08x)\n", trap, parm); - uint32_t ioCompletion = memoryReadLong(parm + 12); + //uint32_t ioCompletion = memoryReadLong(parm + 12); uint32_t ioNamePtr = memoryReadLong(parm + 18); - uint16_t ioVRefNum = memoryReadWord(parm + 22); - uint8_t ioFVersNum = memoryReadByte(parm + 26); + //uint16_t ioVRefNum = memoryReadWord(parm + 22); + //uint8_t ioFVersNum = memoryReadByte(parm + 26); int16_t ioFDirIndex = memoryReadWord(parm + 28); if (ioFDirIndex <= 0) @@ -291,7 +293,7 @@ namespace OS sname = ToolBox::ReadPString(ioNamePtr); - fprintf(stderr, " GetFileInfo(%s)\n", sname.c_str()); + Log(" GetFileInfo(%s)\n", sname.c_str()); // todo -- how are absolute, relative, etc paths handled... @@ -389,18 +391,18 @@ namespace OS uint32_t parm = cpuGetAReg(0); - fprintf(stderr, "%04x SetFileInfo(%08x)\n", trap, parm); + Log("%04x SetFileInfo(%08x)\n", trap, parm); - uint32_t ioCompletion = memoryReadLong(parm + 12); + //uint32_t ioCompletion = memoryReadLong(parm + 12); uint32_t ioNamePtr = memoryReadLong(parm + 18); - uint16_t ioVRefNum = memoryReadWord(parm + 22); - uint8_t ioFVersNum = memoryReadByte(parm + 26); + //uint16_t ioVRefNum = memoryReadWord(parm + 22); + //uint8_t ioFVersNum = memoryReadByte(parm + 26); //int16_t ioFDirIndex = memoryReadWord(parm + 28); // + 32 = finder data - 16 bytes. - uint32_t ioFlCrDat = memoryReadLong(parm + 72); - uint32_t ioFlMdDat = memoryReadLong(parm + 76); + //uint32_t ioFlCrDat = memoryReadLong(parm + 72); + //uint32_t ioFlMdDat = memoryReadLong(parm + 76); // currently, only sets finder info. @@ -411,7 +413,7 @@ namespace OS } sname = ToolBox::ReadPString(ioNamePtr); - fprintf(stderr, " SetFileInfo(%s)\n", sname.c_str()); + Log(" SetFileInfo(%s)\n", sname.c_str()); // check if the file actually exists { diff --git a/toolbox/qd.cpp b/toolbox/qd.cpp index 415aebb..2dd8959 100644 --- a/toolbox/qd.cpp +++ b/toolbox/qd.cpp @@ -7,42 +7,15 @@ #include "stackframe.h" -#if 0 -namespace -{ +using ToolBox::Log; - uint32_t StackFrame(uint32_t &a) - { - uint32_t sp = cpuGetAReg(7); - a = memoryReadLong(sp); sp += 4; - cpuSetAReg(7, sp); - - return sp; - } - - uint32_t StackFrame(uint16_t &a) - { - uint32_t sp = cpuGetAReg(7); - a = memoryReadWord(sp); sp += 2; - cpuSetAReg(7, sp); - - return sp; - } - - void ToolReturn(uint32_t sp, uint32_t value) - { - memoryWriteLong(value, sp); - } - -} -#endif namespace QD { uint16_t ShowCursor(uint16_t trap) { - fprintf(stderr, "%04x ShowCursor()\n", trap); + Log("%04x ShowCursor()\n", trap); return 0; } @@ -53,7 +26,7 @@ namespace QD { sp = StackFrame<2>(cursorID); - fprintf(stderr, "%04x GetCursor(%04x)\n", trap, cursorID); + Log("%04x GetCursor(%04x)\n", trap, cursorID); ToolReturn<4>(sp, 0); @@ -67,7 +40,7 @@ namespace QD { sp = StackFrame<4>(cursor); - fprintf(stderr, "%04x SetCursor(%08x)\n", trap, cursor); + Log("%04x SetCursor(%08x)\n", trap, cursor); return 0; } @@ -83,7 +56,7 @@ namespace QD { sp = StackFrame<8>(fontName, theNum); std::string sname = ToolBox::ReadPString(fontName); - fprintf(stderr, "%04x GetFNum(%s, %08x)\n", trap, sname.c_str(), theNum); + Log("%04x GetFNum(%s, %08x)\n", trap, sname.c_str(), theNum); if (theNum) memoryWriteWord(0, theNum); return 0; diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index e8534a1..033a421 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -8,6 +8,8 @@ #include #include "stackframe.h" +using ToolBox::Log; + namespace RM { uint16_t Get1NamedResource(uint16_t trap) @@ -35,7 +37,7 @@ namespace RM std::string sname = ToolBox::ReadPString(name); - fprintf(stderr, "%04x Get1NamedResource(%08x, %s)\n", trap, theType, sname.c_str()); + Log("%04x Get1NamedResource(%08x, %s)\n", trap, theType, sname.c_str()); ToolReturn<4>(sp, 0); return -192; @@ -64,7 +66,7 @@ namespace RM sp = StackFrame<6>(theType, theID); - fprintf(stderr, "%04x GetResource(%08x, %04x)\n", trap, theType, theID); + Log("%04x GetResource(%08x, %04x)\n", trap, theType, theID); ToolReturn<4>(sp, 0); return -192; @@ -86,7 +88,7 @@ namespace RM sp = StackFrame<4>(routineAddr); - fprintf(stderr, "%04x UnloadSeg(%08x)\n", trap, routineAddr); + Log("%04x UnloadSeg(%08x)\n", trap, routineAddr); return 0; } diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index 04d3cc3..d55ff33 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -20,8 +20,7 @@ extern "C" void cpuSetFlagsNZ00NewW(UWO res); namespace ToolBox { - - + bool Trace = false; void dispatch(uint16_t trap) diff --git a/toolbox/toolbox.h b/toolbox/toolbox.h index 2800f4c..a65b5dc 100644 --- a/toolbox/toolbox.h +++ b/toolbox/toolbox.h @@ -3,8 +3,20 @@ #include +#include +#include + namespace ToolBox { + extern bool Trace; + + template + inline void Log(const char *format, Args... args) + { + if (Trace) fprintf(stderr, format, args...); + } + + void dispatch(uint16_t trap);