diff --git a/toolbox/CMakeLists.txt b/toolbox/CMakeLists.txt index 0db46cf..78ab8f4 100644 --- a/toolbox/CMakeLists.txt +++ b/toolbox/CMakeLists.txt @@ -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 ) diff --git a/toolbox/dispatch.cpp b/toolbox/dispatch.cpp deleted file mode 100644 index edef35d..0000000 --- a/toolbox/dispatch.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include - -#include -#include -#include - -#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); -} \ No newline at end of file diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index 138372b..b291c7c 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -6,53 +6,60 @@ #include -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; } } diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp new file mode 100644 index 0000000..9cbe5d5 --- /dev/null +++ b/toolbox/toolbox.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +#include +#include +#include + +#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); + } + +} \ No newline at end of file diff --git a/toolbox/toolbox.h b/toolbox/toolbox.h index d9736c7..3bc2471 100644 --- a/toolbox/toolbox.h +++ b/toolbox/toolbox.h @@ -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 \ No newline at end of file