diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index 033a421..c3c5668 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -1,5 +1,6 @@ #include "rm.h" #include "toolbox.h" +#include "mm.h" #include #include @@ -10,6 +11,26 @@ using ToolBox::Log; +namespace +{ + + std::string TypeToString(uint32_t type) + { + char tmp[5] = { 0, 0, 0, 0, 0}; + + for (unsigned i = 0; i < 4; ++i) + { + char c = type & 0xff; + type >>= 8; + + c = isprint(c) ? c : '.'; + + tmp[3 - i] = c; + } + + return std::string(tmp); + } +} namespace RM { uint16_t Get1NamedResource(uint16_t trap) @@ -43,6 +64,8 @@ namespace RM return -192; } + + uint16_t GetResource(uint16_t trap) { // GetResource (theType: ResType; theID: Integer): Handle; @@ -66,12 +89,64 @@ namespace RM sp = StackFrame<6>(theType, theID); - Log("%04x GetResource(%08x, %04x)\n", trap, theType, theID); + Log("%04x GetResource(%08x ('%s'), %04x)\n", trap, theType, TypeToString(theType).c_str(), theID); ToolReturn<4>(sp, 0); return -192; } + uint16_t Get1Resource(uint16_t trap) + { + // Get1Resource (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<6>(theType, theID); + + Log("%04x Get1Resource(%08x ('%s'), %04x)\n", trap, theType, TypeToString(theType).c_str(), theID); + + ToolReturn<4>(sp, 0); + return -192; + } + + + uint16_t ReleaseResource(uint16_t trap) + { + // ReleaseResource (theResource: Handle); + + /* + * ------------ + * +0 theResource + * ------------ + * + */ + + uint32_t sp; + uint32_t theResource; + + sp = StackFrame<4>(theResource); + + Log("%04x ReleaseResource(%08x)\n", trap, theResource); + + return 0; + } + + uint16_t UnloadSeg(uint16_t trap) { // UnloadSeg (routineAddr: Ptr); diff --git a/toolbox/rm.h b/toolbox/rm.h index 73e9302..299a64b 100644 --- a/toolbox/rm.h +++ b/toolbox/rm.h @@ -5,11 +5,15 @@ namespace RM { + uint16_t GetNamedResource(uint16_t trap); uint16_t Get1NamedResource(uint16_t trap); uint16_t GetResource(uint16_t trap); + uint16_t Get1Resource(uint16_t trap); uint16_t UnloadSeg(uint16_t trap); + + uint16_t ReleaseResource(uint16_t trap); } diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index f7b7397..0ed57c7 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -134,6 +134,11 @@ namespace ToolBox { // resource manager stuff. + // Get1Resource (theType: ResType; thelD: INTEGER) : Handle; + case 0xa81f: + d0 = RM::Get1Resource(trap); + break; + // Get1NamedResource (theType: ResType; name: Str255) : Handle; case 0xa820: d0 = RM::Get1NamedResource(trap); @@ -144,6 +149,11 @@ namespace ToolBox { d0 = RM::GetResource(trap); break; + // ReleaseResource (theResource: Handle); + case 0xa9a3: + d0 = RM::ReleaseResource(trap); + break; + // UnloadSeg (routineAddr: Ptr); case 0xa9f1: d0 = RM::UnloadSeg(trap);