toolbox logging flag.

This commit is contained in:
Kelvin Sherlock 2013-02-16 18:51:28 -05:00
parent adc17ebe9c
commit 97b5dd6400
8 changed files with 73 additions and 80 deletions

View File

@ -700,6 +700,7 @@ int main(int argc, char **argv)
MPW::Init();
MPW::Trace = Flags.traceMPW;
ToolBox::Trace = Flags.traceToolBox;
if (!Flags.stack)
{

View File

@ -1,4 +1,5 @@
#include "mm.h"
#include "toolbox.h"
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
@ -11,6 +12,8 @@
#include <mplite/mplite.h>
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);

View File

@ -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;

View File

@ -19,6 +19,8 @@
#include <strings.h>
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
{

View File

@ -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;

View File

@ -8,6 +8,8 @@
#include <string>
#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;
}

View File

@ -20,8 +20,7 @@ extern "C" void cpuSetFlagsNZ00NewW(UWO res);
namespace ToolBox {
bool Trace = false;
void dispatch(uint16_t trap)

View File

@ -3,8 +3,20 @@
#include <string>
#include <cstdint>
#include <cstdio>
namespace ToolBox
{
extern bool Trace;
template<typename... Args>
inline void Log(const char *format, Args... args)
{
if (Trace) fprintf(stderr, format, args...);
}
void dispatch(uint16_t trap);