diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index a22307c..6183763 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -1,4 +1,5 @@ #include "rm.h" +#include "toolbox.h" #include #include @@ -36,29 +37,21 @@ namespace return sp; } + uint32_t StackFrame(uint32_t &b, uint16_t &a) + { + uint32_t sp = cpuGetAReg(7); + a = memoryReadWord(sp); sp += 2; + b = memoryReadLong(sp); sp += 4; + cpuSetAReg(7, sp); + + return sp; + } + void ToolReturn(uint32_t sp, uint32_t value) { memoryWriteLong(value, sp); } - 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; - } } @@ -87,11 +80,41 @@ namespace RM sp = StackFrame(theType, name); - std::string sname = PString(name); + std::string sname = ToolBox::ReadPString(name); fprintf(stderr, "%04x Get1NamedResource(%08x, %s)\n", trap, theType, sname.c_str()); ToolReturn(sp, (uint32_t)0); return -192; } + + uint16_t GetResource(uint16_t trap) + { + // GetResource (theType: ResType; theID: Integer): Handle; + + /* + * ----------- + * +6 outHandle + * ------------ + * +2 theType + * ------------ + * +0 theID + * ------------ + * + */ + + // nb - return address is not on the stack. + + uint32_t sp; + uint32_t theType; + uint16_t theID; + + sp = StackFrame(theType, theID); + + fprintf(stderr, "%04x GetResource(%08x, %04x)\n", trap, theType, theID); + + ToolReturn(sp, (uint32_t)0); + return -192; + } + } diff --git a/toolbox/rm.h b/toolbox/rm.h index 92c342f..d6f8889 100644 --- a/toolbox/rm.h +++ b/toolbox/rm.h @@ -6,6 +6,8 @@ namespace RM { uint16_t Get1NamedResource(uint16_t trap); + + uint16_t GetResource(uint16_t trap); } #endif \ No newline at end of file diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index ab126fc..f678c26 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -36,7 +36,7 @@ namespace ToolBox { case 0xa009: d0 = OS::Delete(trap); break; - + case 0xA00C: d0 = OS::GetFileInfo(trap); break; @@ -78,11 +78,27 @@ namespace ToolBox { d0 = MM::DisposePtr(trap); break; + // resource manager stuff. + // Get1NamedResource (theType: ResType; name: Str255) : Handle; case 0xa820: d0 = RM::Get1NamedResource(trap); break; + // GetResource (theType: ResType; thelD: INTEGER) : Handle; + case 0xa9a0: + d0 = RM::GetResource(trap); + break; + + // quickdraw + + // _ShowCursor(); + case 0xA853: + d0 = 0; + break; + + + default: fprintf(stderr, "Unsupported tool trap: %04x\n", trap); fprintf(stderr, "pc: %08x\n", cpuGetPC());