mpw/toolbox/rm.cpp

121 lines
1.9 KiB
C++
Raw Normal View History

2013-02-07 04:44:12 +00:00
#include "rm.h"
2013-02-14 04:07:33 +00:00
#include "toolbox.h"
2013-02-07 04:44:12 +00:00
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
#include <cpu/fmem.h>
#include <string>
2013-02-08 00:21:47 +00:00
namespace
2013-02-07 04:44:12 +00:00
{
2013-02-08 00:21:47 +00:00
uint32_t PopLong()
{
uint32_t sp = cpuGetAReg(7);
uint32_t value = memoryReadLong(sp);
cpuSetAReg(7, sp + 4);
return value;
}
2013-02-07 04:44:12 +00:00
2013-02-08 00:21:47 +00:00
uint16_t PopWord()
{
uint32_t sp = cpuGetAReg(7);
uint16_t value = memoryReadWord(sp);
cpuSetAReg(7, sp + 2);
return value;
}
2013-02-07 04:44:12 +00:00
2013-02-08 00:21:47 +00:00
uint32_t StackFrame(uint32_t &b, uint32_t &a)
{
uint32_t sp = cpuGetAReg(7);
a = memoryReadLong(sp); sp += 4;
b = memoryReadLong(sp); sp += 4;
cpuSetAReg(7, sp);
2013-02-07 04:44:12 +00:00
2013-02-08 00:21:47 +00:00
return sp;
}
2013-02-07 04:44:12 +00:00
2013-02-14 04:07:33 +00:00
uint32_t StackFrame(uint32_t &b, uint16_t &a)
2013-02-07 04:44:12 +00:00
{
2013-02-14 04:07:33 +00:00
uint32_t sp = cpuGetAReg(7);
a = memoryReadWord(sp); sp += 2;
b = memoryReadLong(sp); sp += 4;
cpuSetAReg(7, sp);
return sp;
2013-02-07 04:44:12 +00:00
}
2013-02-14 04:07:33 +00:00
void ToolReturn(uint32_t sp, uint32_t value)
2013-02-07 04:44:12 +00:00
{
2013-02-14 04:07:33 +00:00
memoryWriteLong(value, sp);
2013-02-07 04:44:12 +00:00
}
2013-02-14 04:07:33 +00:00
2013-02-07 04:44:12 +00:00
}
namespace RM
{
2013-02-08 03:12:30 +00:00
uint16_t Get1NamedResource(uint16_t trap)
2013-02-07 04:44:12 +00:00
{
// 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(theType, name);
2013-02-14 04:07:33 +00:00
std::string sname = ToolBox::ReadPString(name);
2013-02-07 04:44:12 +00:00
2013-02-08 03:12:30 +00:00
fprintf(stderr, "%04x Get1NamedResource(%08x, %s)\n", trap, theType, sname.c_str());
2013-02-07 04:44:12 +00:00
ToolReturn(sp, (uint32_t)0);
2013-02-08 00:21:47 +00:00
return -192;
2013-02-07 04:44:12 +00:00
}
2013-02-14 04:07:33 +00:00
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;
}
2013-02-07 04:44:12 +00:00
}