Get1Resource, ReleaseResource

This commit is contained in:
Kelvin Sherlock 2013-02-19 18:28:58 -05:00
parent bf47a41ecc
commit 9ed82d7639
3 changed files with 90 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include "rm.h"
#include "toolbox.h"
#include "mm.h"
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
@ -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);

View File

@ -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);
}

View File

@ -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);