From f6132773dbb8c182615bbc4d504d3fc98f0e03f7 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 23 Jun 2013 22:05:57 -0400 Subject: [PATCH] OpenRFPerm --- toolbox/rm.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ toolbox/rm.h | 1 + toolbox/toolbox.cpp | 6 ++++++ 3 files changed, 50 insertions(+) diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index d8b196c..18ef7fb 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -381,6 +381,49 @@ namespace RM + uint16_t OpenRFPerm(uint16_t trap) + { + // FUNCTION OpenRFPerm (fileName: Str255; vRefNum: Integer; + // permission: SignedByte): Integer; + ResFileRefNum refNum; + FSRef ref; + + uint32_t sp; + uint32_t fileName; + uint16_t vRefNum; + uint16_t permission; + OSErr error; + + sp = StackFrame<8>(fileName, vRefNum, permission); + + std::string sname = ToolBox::ReadPString(fileName, true); + Log("%04x OpenRFPerm(%s, %04x, %04x)\n", + trap, sname.c_str(), vRefNum, permission); + + error = FSPathMakeRef( (const UInt8 *)sname.c_str(), &ref, NULL); + if (error != noErr) + { + ToolReturn<2>(sp, (uint16_t)-1); + return SetResError(error); + } + + HFSUniStr255 fork = {0,{0}}; + FSGetResourceForkName(&fork); + + refNum = -1; + error = FSOpenResourceFile(&ref, + fork.length, + fork.unicode, + permission, + &refNum); + + ToolReturn<2>(sp, (uint16_t)refNum); + + return SetResError(error); + } + + + // todo -- move since it's not RM related. uint16_t UnloadSeg(uint16_t trap) { diff --git a/toolbox/rm.h b/toolbox/rm.h index 68e340d..660815f 100644 --- a/toolbox/rm.h +++ b/toolbox/rm.h @@ -24,6 +24,7 @@ namespace RM uint16_t ResError(uint16_t trap); uint16_t OpenResFile(uint16_t trap); + uint16_t OpenRFPerm(uint16_t trap); uint16_t SetResLoad(uint16_t trap); diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index 207075a..af44680 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -310,6 +310,12 @@ namespace ToolBox { d0 = RM::CreateResFile(trap); break; + // OpenRFPerm (fileName: Str255; vRefNum: Integer; + // permission: SignedByte): Integer; + case 0xa9c4: + d0 = RM::OpenRFPerm(trap); + break; + // UnloadSeg (routineAddr: Ptr); case 0xa9f1: d0 = RM::UnloadSeg(trap);