clean up the toolbox...

This commit is contained in:
Kelvin Sherlock 2013-02-07 19:21:47 -05:00
parent 23dd8f2722
commit 883816f7cd
5 changed files with 96 additions and 82 deletions

View File

@ -5,7 +5,7 @@ set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Wno-deprecated-declaration
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
set(TOOLBOX_SRC
dispatch.cpp
toolbox.cpp
rm.cpp
)

View File

@ -1,37 +0,0 @@
#include <cstdio>
#include <cstdint>
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
#include <cpu/fmem.h>
#include "toolbox.h"
// yuck. TST.W d0
extern "C" void cpuSetFlagsNZ00NewW(UWO res);
void toolbox(uint16_t trap)
{
// todo -- remove extra bits for save a0, toolglue
uint32_t d0 = 0;
switch (trap)
{
_Get1NamedResource
// Get1NamedResource (theType: ResType; name: Str255) : Handle;
case 0xa820:
d0 = RM::Get1NamedResource();
break;
default:
fprintf(stderr, "Unsupported tool trap: %08x\n", trap);
fprintf(stderr, "pc: %08x\n", cpuGetPC());
exit(255);
}
cpuSetDReg(0, d0);
cpuSetFlagsNZ00NewW(d0);
}

View File

@ -6,53 +6,60 @@
#include <string>
uint32_t PopLong()
namespace
{
uint32_t sp = cpuGetAReg(7);
uint32_t value = memoryReadLong(a7);
cpuSetAReg(7, sp + 4);
return value;
}
uint16_t PopWord()
{
uint32_t sp = cpuGetAReg(7);
uint16_t value = memoryReadWord(a7);
cpuSetAReg(7, sp + 2);
return value;
}
uint32_t StackFrame(uint32_t &b, uint32_t &a)
{
uint32_t sp = cpuGetAReg(7);
a = memoryReadLong(sp); sp += 4;
b = memoryReadLong(sp); sp += 4;
cpuSetAReg(7, sp);
}
void ToolReturn(uint32_t sp, uint32_t value)
{
memoryWriteLong(sp, value);
}
std::string PString(uint32_t address)
{
std::string s;
unsigned length = address == 0 ? 0 : memoryReadByte(address++);
if (length == 0)
uint32_t PopLong()
{
uint32_t sp = cpuGetAReg(7);
uint32_t value = memoryReadLong(sp);
cpuSetAReg(7, sp + 4);
return value;
}
uint16_t PopWord()
{
uint32_t sp = cpuGetAReg(7);
uint16_t value = memoryReadWord(sp);
cpuSetAReg(7, sp + 2);
return value;
}
uint32_t StackFrame(uint32_t &b, uint32_t &a)
{
uint32_t sp = cpuGetAReg(7);
a = memoryReadLong(sp); sp += 4;
b = memoryReadLong(sp); sp += 4;
cpuSetAReg(7, sp);
return sp;
}
void ToolReturn(uint32_t sp, uint32_t value)
{
memoryWriteLong(sp, value);
}
std::string PString(uint32_t address)
{
std::string s;
unsigned length = address == 0 ? 0 : memoryReadByte(address++);
if (length == 0)
{
return s;
}
s.reserve(length);
for (unsigned i = 0; i < length; ++i)
{
s.push_back((char)memoryReadByte(address++));
}
return s;
}
s.reserve(length);
for (unsigned i = 0; i < length; ++i)
{
s.push_back((char)memoryReadByte(address++));
}
return s;
}
namespace RM
@ -82,9 +89,9 @@ namespace RM
std::string sname = PString(name);
printf(stderr, "Get1NamedResource(%08x, %s)\n", theType, sname.c_str());
fprintf(stderr, "Get1NamedResource(%08x, %s)\n", theType, sname.c_str());
ToolReturn(sp, (uint32_t)0);
return 192;
return -192;
}
}

40
toolbox/toolbox.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <cstdio>
#include <cstdint>
#include <stdlib.h>
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
#include <cpu/fmem.h>
#include "toolbox.h"
#include "rm.h"
// yuck. TST.W d0
extern "C" void cpuSetFlagsNZ00NewW(UWO res);
namespace ToolBox {
void dispatch(uint16_t trap)
{
// todo -- check/remove extra bits for save a0, toolglue, etc.
uint32_t d0 = 0;
switch (trap)
{
// Get1NamedResource (theType: ResType; name: Str255) : Handle;
case 0xa820:
d0 = RM::Get1NamedResource();
break;
default:
fprintf(stderr, "Unsupported tool trap: %04x\n", trap);
fprintf(stderr, "pc: %08x\n", cpuGetPC());
exit(255);
}
cpuSetDReg(0, d0);
cpuSetFlagsNZ00NewW(d0);
}
}

View File

@ -1,6 +1,10 @@
#ifndef __mpw_toolbox_h__
#define __mpw_toolbox_h__
extern "C" void toolbox(uint16_t trap);
namespace ToolBox
{
void dispatch(uint16_t trap);
}
#endif