mpw/toolbox/rm.cpp
2013-02-06 23:44:12 -05:00

91 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "rm.h"
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
#include <cpu/fmem.h>
#include <string>
uint32_t PopLong()
{
uint32_t sp = cpuGetAReg(7);
uint32_t value = memoryReadLong(a7);
cpuSetAReg(7, sp + 4);
return value;
}
uint16_t PopWord()
{
uint32_t sp = cpuGetAReg(7);
uint16_t value = memoryReadWord(a7);
cpuSetAReg(7, sp + 2);
return value;
}
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);
}
void ToolReturn(uint32_t sp, uint32_t value)
{
memoryWriteLong(sp, value);
}
std::string PString(uint32_t address)
{
std::string s;
unsigned length = address == 0 ? 0 : memoryReadByte(address++);
if (length == 0)
{
return s;
}
s.reserve(length);
for (unsigned i = 0; i < length; ++i)
{
s.push_back((char)memoryReadByte(address++));
}
return s;
}
namespace RM
{
uint16_t Get1NamedResource()
{
// 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);
std::string sname = PString(name);
printf(stderr, "Get1NamedResource(%08x, %s)\n", theType, sname.c_str());
ToolReturn(sp, (uint32_t)0);
return 192;
}
}