From 8235193554969509ea6339402132267782834ef0 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 24 Feb 2013 23:21:48 -0500 Subject: [PATCH] Pack6 support (very limited) --- toolbox/os.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ toolbox/os.h | 1 + toolbox/toolbox.cpp | 4 ++++ 3 files changed, 58 insertions(+) diff --git a/toolbox/os.cpp b/toolbox/os.cpp index 985b5d3..df52638 100644 --- a/toolbox/os.cpp +++ b/toolbox/os.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -683,5 +684,57 @@ namespace OS return 0; } + uint16_t Pack6(uint16_t trap) + { + char buffer[256]; + int length; + std::string out; + + uint32_t dateTime; + uint16_t flag; + uint32_t result; + uint16_t selector; + + // todo -- variable number of args. Pop selector, act from that. + + StackFrame<12>(dateTime, flag, result, selector); + + Log("%04x Pack6(%08x, %04x, %08x, %04x)\n", + trap, dateTime, flag, result, selector); + + struct tm *tm; + time_t t; + t = MacToUnix(dateTime); + + tm = ::localtime(&t); + + if (selector == 0x00) + { + // void IUDateString(long dateTime,DateForm longFlag,Str255 result) + // DateForm doesn't seem to do anything. + + // not strictly correct -- uses %d/%d/%2d form. + length = std::strftime(buffer, sizeof(buffer), "%m/%d/%y", tm); + out.assign(buffer, length); + } + else if (selector == 0x02) + { + // void IUTimeString(long dateTime,Boolean wantSeconds,Str255 result) + // output: 12:00:00 AM or 12:00 AM + + length = std::strftime(buffer, sizeof(buffer), flag ? "%I:%M:%S %p" : "%I:%M %p", tm); + + out.assign(buffer, length); + } + else + { + fprintf(stderr, "Pack6: selector %04x not supported\n", selector); + exit(1); + } + + ToolBox::WritePString(result, out); + return 0; + } + } \ No newline at end of file diff --git a/toolbox/os.h b/toolbox/os.h index e506459..cad88aa 100644 --- a/toolbox/os.h +++ b/toolbox/os.h @@ -127,6 +127,7 @@ namespace OS #pragma mark - Time Utilities uint16_t ReadDateTime(uint16_t trap); uint16_t SecondsToDate(uint16_t trap); + uint16_t Pack6(uint16_t trap); uint16_t TickCount(uint16_t trap); diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index b66884c..89af252 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -113,6 +113,10 @@ namespace ToolBox { d0 = OS::TickCount(trap); break; + case 0xa9ed: + d0 = OS::Pack6(trap); + break; + //_CmpString [MARKS,CASE] case 0xa03c: case 0xa23c: