mirror of
https://github.com/ksherlock/mpw.git
synced 2024-11-22 15:31:50 +00:00
172 lines
2.6 KiB
C++
172 lines
2.6 KiB
C++
#include "rm.h"
|
|
#include "toolbox.h"
|
|
#include "mm.h"
|
|
|
|
#include <cpu/defs.h>
|
|
#include <cpu/CpuModule.h>
|
|
#include <cpu/fmem.h>
|
|
|
|
#include <string>
|
|
#include "stackframe.h"
|
|
|
|
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)
|
|
{
|
|
// Get1NamedResource (theType: ResType; name: Str255) : Handle;
|
|
|
|
/*
|
|
* -----------
|
|
* +8 outHandle
|
|
* ------------
|
|
* +4 theType
|
|
* ------------
|
|
* +0 name
|
|
* ------------
|
|
*
|
|
*/
|
|
|
|
// nb - return address is not on the stack.
|
|
|
|
uint32_t sp;
|
|
uint32_t theType;
|
|
uint32_t name;
|
|
|
|
sp = StackFrame<8>(theType, name);
|
|
|
|
std::string sname = ToolBox::ReadPString(name);
|
|
|
|
Log("%04x Get1NamedResource(%08x, %s)\n", trap, theType, sname.c_str());
|
|
|
|
ToolReturn<4>(sp, 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<6>(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);
|
|
|
|
/*
|
|
* ------------
|
|
* +0 routineAddr
|
|
* ------------
|
|
*
|
|
*/
|
|
|
|
uint32_t sp;
|
|
uint32_t routineAddr;
|
|
|
|
sp = StackFrame<4>(routineAddr);
|
|
|
|
Log("%04x UnloadSeg(%08x)\n", trap, routineAddr);
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|