mpw trace flag

This commit is contained in:
Kelvin Sherlock 2013-02-16 18:32:37 -05:00
parent 0cc361bab0
commit acd4765317
7 changed files with 56 additions and 15 deletions

View File

@ -24,11 +24,14 @@ struct {
uint32_t ram;
uint32_t stack;
uint32_t machine;
bool traceCPU;
bool traceMacsbug;
bool traceGlobals;
bool traceToolBox;
bool traceMPW;
} Flags = { 16 * 1024 * 1024, 8 * 1024, 68030, false, false, false };
} Flags = { 16 * 1024 * 1024, 8 * 1024, 68030, false, false, false, false, false};
uint8_t *Memory;
@ -598,6 +601,8 @@ int main(int argc, char **argv)
kTraceCPU = 1,
kTraceMacsBug,
kTraceGlobals,
kTraceToolBox,
kTraceMPW,
};
static struct option LongOpts[] =
{
@ -607,6 +612,8 @@ int main(int argc, char **argv)
{ "trace-cpu", no_argument, NULL, kTraceCPU },
{ "trace-macsbug", no_argument, NULL, kTraceMacsBug },
{ "trace-globals", no_argument, NULL, kTraceGlobals },
{ "trace-toolbox", no_argument, NULL, kTraceToolBox },
{ "trace-mpw", no_argument, NULL, kTraceMPW },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
@ -629,6 +636,14 @@ int main(int argc, char **argv)
Flags.traceGlobals = true;
break;
case kTraceToolBox:
Flags.traceToolBox = true;
break;
case kTraceMPW:
Flags.traceMPW = true;
break;
case 'm':
if (!parse_number(optarg, &Flags.machine))
exit(EX_CONFIG);
@ -682,6 +697,9 @@ int main(int argc, char **argv)
InitializeMPW(argc, argv);
MPW::Init();
MPW::Trace = Flags.traceMPW;
if (!Flags.stack)
{

View File

@ -29,6 +29,8 @@ namespace MPW
{
using namespace Internal;
bool Trace = false;
int errno_to_errno(int xerrno)
{
switch (xerrno)
@ -90,7 +92,8 @@ namespace MPW
void ftrap_quit(uint16_t trap)
{
fprintf(stderr, "%04x Quit()\n", trap);
Log("%04x Quit()\n", trap);
//fprintf(stderr, "%04x Quit()\n", trap);
cpuSetStop(true);
}

View File

@ -5,6 +5,9 @@
namespace MPW {
extern bool Trace;
struct MPWFile
{

View File

@ -65,7 +65,8 @@ namespace MPW
sname = ToolBox::ReadCString(name);
fprintf(stderr, " open(%s, %04x)\n", sname.c_str(), f.flags);
//fprintf(stderr, " open(%s, %04x)\n", sname.c_str(), f.flags);
Log(" open(%s, %04x)\n", sname.c_str(), f.flags);
// TODO -- can you create a resource file like this?
@ -128,8 +129,9 @@ namespace MPW
uint32_t op = memoryReadLong(sp + 8);
uint32_t parm = memoryReadLong(sp + 12);
fprintf(stderr, "%04x Access(%08x, %04x, %08x)\n", trap, name, op, parm);
//fprintf(stderr, "%04x Access(%08x, %04x, %08x)\n", trap, name, op, parm);
Log("%04x Access(%08x, %04x, %08x)\n", trap, name, op, parm);
switch (op)
{
case kF_OPEN:

View File

@ -40,7 +40,8 @@ namespace MPW
f.buffer = memoryReadLong(parm + 16);
fprintf(stderr, "%04x Close(%08x)\n", trap, parm);
//fprintf(stderr, "%04x Close(%08x)\n", trap, parm);
Log("%04x Close(%08x)\n", trap, parm);
if (!parm)
{
@ -60,6 +61,7 @@ namespace MPW
{
if (--FDTable[fd] == 0)
{
Log(" close(%02x)\n", fd);
::close(fd);
f.error = 0;
d0 = 0;

View File

@ -2,9 +2,17 @@
#define __MPW_INTERNAL_H__
#include <vector>
#include <cstdio>
namespace MPW
{
template<typename... Args>
inline void Log(const char *format, Args... args)
{
if (Trace) fprintf(stderr, format, args...);
}
namespace Internal
{
// for dup counts, etc.

View File

@ -44,7 +44,8 @@ namespace MPW
int fd = f.cookie;
fprintf(stderr, " dup(%02x)\n", fd);
//fprintf(stderr, " dup(%02x)\n", fd);
Log(" dup(%02x)\n", fd);
if (fd < 0 || fd >= FDTable.size() || !FDTable[fd])
{
@ -78,8 +79,8 @@ namespace MPW
int fd = f.cookie;
fprintf(stderr, " bufsize(%02x)\n", fd);
//fprintf(stderr, " bufsize(%02x)\n", fd);
Log(" bufsize(%02x)\n", fd);
memoryWriteWord(f.error, parm + 2);
return kEINVAL;
@ -110,7 +111,8 @@ namespace MPW
int fd = f.cookie;
fprintf(stderr, " interactive(%02x)\n", fd);
//fprintf(stderr, " interactive(%02x)\n", fd);
Log(" interactive(%02x)\n", fd);
//d0 = kEINVAL;
@ -150,7 +152,8 @@ namespace MPW
int fd = f.cookie;
fprintf(stderr, " fname(%02x)\n", fd);
//fprintf(stderr, " fname(%02x)\n", fd);
Log(" fname(%02x)\n", fd);
memoryWriteWord(f.error, parm + 2);
return kEINVAL;
@ -174,7 +177,8 @@ namespace MPW
int fd = f.cookie;
fprintf(stderr, " refnum(%02x)\n", fd);
//fprintf(stderr, " refnum(%02x)\n", fd);
Log(" refnum(%02x)\n", fd);
if (fd < 0 || fd >= FDTable.size() || !FDTable[fd])
{
@ -238,7 +242,8 @@ namespace MPW
return kEINVAL;
}
fprintf(stderr, " lseek(%02x, %08x, %02x)\n", fd, offset, nativeWhence);
//fprintf(stderr, " lseek(%02x, %08x, %02x)\n", fd, offset, nativeWhence);
Log(" lseek(%02x, %08x, %02x)\n", fd, offset, nativeWhence);
if (::isatty(fd))
{
@ -264,7 +269,6 @@ namespace MPW
{
d0 = 0;
f.error = 0;
fprintf(stderr, "-> %lld\n", rv);
}
memoryWriteLong(rv, arg + 4);
@ -285,7 +289,8 @@ namespace MPW
uint32_t cmd = memoryReadLong(sp + 8);
uint32_t arg = memoryReadLong(sp + 12);
fprintf(stderr, "%04x IOCtl(%08x, %08x, %08x)\n", trap, fd, cmd, arg);
//fprintf(stderr, "%04x IOCtl(%08x, %08x, %08x)\n", trap, fd, cmd, arg);
Log("%04x IOCtl(%08x, %08x, %08x)\n", trap, fd, cmd, arg);
switch (cmd)
{