diff --git a/toolbox/qd.cpp b/toolbox/qd.cpp index f8ffafb..415aebb 100644 --- a/toolbox/qd.cpp +++ b/toolbox/qd.cpp @@ -5,7 +5,9 @@ #include #include +#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; + } + } \ No newline at end of file diff --git a/toolbox/qd.h b/toolbox/qd.h index c727298..0cb07a2 100644 --- a/toolbox/qd.h +++ b/toolbox/qd.h @@ -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 diff --git a/toolbox/stackframe.h b/toolbox/stackframe.h new file mode 100644 index 0000000..e7ac43f --- /dev/null +++ b/toolbox/stackframe.h @@ -0,0 +1,58 @@ +#ifndef __StackFrame_h__ +#define __StackFrame_h__ + +#include + +// + +template +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 +uint32_t StackFrame__(uint32_t sp) +{ + static_assert(Offset == 0, "Invalid Stack Size"); + + cpuSetAReg(7, sp + Bytes); + return sp + Bytes; +} + +template +uint32_t StackFrame__(uint32_t sp, uint32_t &x, Args&... args) +{ + x = memoryReadLong(sp + Offset - 4); + + return StackFrame__(sp, args...); +} + +template +uint32_t StackFrame__(uint32_t sp, uint16_t &x, Args&... args) +{ + x = memoryReadWord(sp + Offset - 2); + + return StackFrame__(sp, args...); +} + +template +uint32_t StackFrame(Args&... args) +{ + uint32_t sp = cpuGetAReg(7); + + return StackFrame__(sp, args...); +} + + + +#endif \ No newline at end of file