GetFNum, StackFrame template

This commit is contained in:
Kelvin Sherlock 2013-02-15 00:00:15 -05:00
parent 326e2eacc8
commit f226bdd60c
3 changed files with 81 additions and 3 deletions

View File

@ -5,7 +5,9 @@
#include <cpu/CpuModule.h>
#include <cpu/fmem.h>
#include "stackframe.h"
#if 0
namespace
{
@ -33,6 +35,7 @@ namespace
}
}
#endif
namespace QD {
@ -48,12 +51,12 @@ namespace QD {
uint32_t sp;
uint16_t cursorID;
sp = StackFrame(cursorID);
sp = StackFrame<2>(cursorID);
fprintf(stderr, "%04x GetCursor(%04x)\n", trap, cursorID);
ToolReturn(sp, 0);
ToolReturn<4>(sp, 0);
return 0;
}
@ -62,7 +65,7 @@ namespace QD {
uint32_t sp;
uint32_t cursor;
sp = StackFrame(cursor);
sp = StackFrame<4>(cursor);
fprintf(stderr, "%04x SetCursor(%08x)\n", trap, cursor);
@ -70,4 +73,20 @@ namespace QD {
}
uint16_t GetFNum(uint16_t trap)
{
uint32_t sp;
uint32_t fontName;
uint32_t theNum;
sp = StackFrame<8>(fontName, theNum);
std::string sname = ToolBox::ReadPString(fontName);
fprintf(stderr, "%04x GetFNum(%s, %08x)\n", trap, sname.c_str(), theNum);
if (theNum) memoryWriteWord(0, theNum);
return 0;
}
}

View File

@ -10,6 +10,7 @@ namespace QD
uint16_t GetCursor(uint16_t trap);
uint16_t SetCursor(uint16_t trap);
uint16_t GetFNum(uint16_t trap);
}
#endif

58
toolbox/stackframe.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef __StackFrame_h__
#define __StackFrame_h__
#include <cstdint>
//
template<unsigned N>
void ToolReturn(uint32_t sp, uint32_t value)
{
static_assert(N == 2 || N == 4, "Invalid Return Size");
if (N == 4)
{
memoryWriteLong(value, sp);
}
if (N == 2)
{
memoryWriteWord(value, sp);
}
}
template<int Bytes, int Offset>
uint32_t StackFrame__(uint32_t sp)
{
static_assert(Offset == 0, "Invalid Stack Size");
cpuSetAReg(7, sp + Bytes);
return sp + Bytes;
}
template<int Bytes, int Offset, typename... Args>
uint32_t StackFrame__(uint32_t sp, uint32_t &x, Args&... args)
{
x = memoryReadLong(sp + Offset - 4);
return StackFrame__<Bytes, Offset - 4>(sp, args...);
}
template<int Bytes, int Offset, typename... Args>
uint32_t StackFrame__(uint32_t sp, uint16_t &x, Args&... args)
{
x = memoryReadWord(sp + Offset - 2);
return StackFrame__<Bytes, Offset - 2>(sp, args...);
}
template<int Bytes, typename... Args>
uint32_t StackFrame(Args&... args)
{
uint32_t sp = cpuGetAReg(7);
return StackFrame__<Bytes, Bytes>(sp, args...);
}
#endif