From ab6259c0305f291969f298befda8fa60c481fc4e Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 2 Feb 2015 17:02:57 -0500 Subject: [PATCH] GetIntlResource stub, move pack6 to its own file. --- toolbox/CMakeLists.txt | 1 + toolbox/os.cpp | 51 ------------- toolbox/packages.cpp | 161 +++++++++++++++++++++++++++++++++++++++++ toolbox/packages.h | 27 +++++++ toolbox/toolbox.cpp | 3 +- 5 files changed, 190 insertions(+), 53 deletions(-) create mode 100644 toolbox/packages.cpp create mode 100644 toolbox/packages.h diff --git a/toolbox/CMakeLists.txt b/toolbox/CMakeLists.txt index 5ad0d3f..bbeb198 100644 --- a/toolbox/CMakeLists.txt +++ b/toolbox/CMakeLists.txt @@ -21,6 +21,7 @@ set(TOOLBOX_SRC qd.cpp sane.cpp saneparser.cpp + packages.cpp pathnames.cpp process.cpp utility.cpp diff --git a/toolbox/os.cpp b/toolbox/os.cpp index c37a0b3..cca50d5 100644 --- a/toolbox/os.cpp +++ b/toolbox/os.cpp @@ -954,57 +954,6 @@ 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; - } #pragma mark - Trap Manager diff --git a/toolbox/packages.cpp b/toolbox/packages.cpp new file mode 100644 index 0000000..fd8c631 --- /dev/null +++ b/toolbox/packages.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2015, Kelvin W Sherlock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +#include "toolbox.h" +#include "stackframe.h" +#include "os.h" +#include "packages.h" + +using ToolBox::Log; +using OS::MacToUnix; + +namespace Packages { + + + uint16_t IUDateString() + { + // void IUDateString(long dateTime,DateForm longFlag,Str255 result) + // DateForm doesn't seem to do anything. + + char buffer[256]; + int length; + std::string out; + + uint32_t dateTime; + uint8_t flag; + uint32_t result; + + + StackFrame<10>(dateTime, flag, result); + + Log(" IUDateString(%08x, %02x, %08x)\n", dateTime, flag, result); + + time_t t = MacToUnix(dateTime); + struct tm *tm = ::localtime(&t); + + // not strictly correct -- uses %d/%d/%2d form. + length = std::strftime(buffer, sizeof(buffer), "%m/%d/%y", tm); + out.assign(buffer, length); + + ToolBox::WritePString(result, out); + return 0; + } + + uint16_t IUTimeString() + { + // void IUTimeString(long dateTime,Boolean wantSeconds,Str255 result) + // output: 12:00:00 AM or 12:00 AM + + char buffer[256]; + int length; + std::string out; + + uint32_t dateTime; + uint8_t wantSeconds; + uint32_t result; + + + StackFrame<10>(dateTime, wantSeconds, result); + Log(" IUTimeString(%08x, %02x, %08x)\n", dateTime, wantSeconds, result); + + time_t t = MacToUnix(dateTime); + struct tm *tm = ::localtime(&t); + + length = std::strftime(buffer, sizeof(buffer), wantSeconds ? "%I:%M:%S %p" : "%I:%M %p", tm); + + out.assign(buffer, length); + + ToolBox::WritePString(result, out); + return 0; + } + + uint16_t GetIntlResource() + { + // FUNCTION GetIntlResource (theID: Integer) :Handle; + + // todo -- actually load the resource + + /* + * theID Contains an integer (0, 1, 2, 4, or 5 respectively for + * the 'itl0', 'itl1', 'itl2', 'itl4', and 'itl5'resources) to + * identify the type of the desired international resource. + */ + + + uint16_t theID; + + uint32_t sp = StackFrame<2>(theID); + + Log(" GetIntlResource(%04x)\n", theID); + + ToolReturn<4>(sp, 0); + return 0; // should set res error. + } + + uint16_t Pack6(uint16_t trap) + { + + uint16_t selector; + StackFrame<2>(selector); + + Log("%04x Pack6(%04x)\n", trap, selector); + + switch(selector) + { + case 0x0000: + return IUDateString(); + case 0x0002: + return IUTimeString(); + case 0x0006: + return GetIntlResource(); + + default: + fprintf(stderr, "Pack6: selector %04x not supported\n", selector); + exit(1); + } + return 0; + } + + +} diff --git a/toolbox/packages.h b/toolbox/packages.h new file mode 100644 index 0000000..92538a0 --- /dev/null +++ b/toolbox/packages.h @@ -0,0 +1,27 @@ +#ifndef __mpw_packages_h__ +#define __mpw_packages_h__ + +#include + +namespace Packages { + + uint16_t Pack0(uint16_t); + uint16_t Pack1(uint16_t); + uint16_t Pack2(uint16_t); + uint16_t Pack3(uint16_t); + uint16_t Pack4(uint16_t); + uint16_t Pack5(uint16_t); + uint16_t Pack6(uint16_t); + uint16_t Pack7(uint16_t); + uint16_t Pack8(uint16_t); + uint16_t Pack9(uint16_t); + uint16_t Pack10(uint16_t); + uint16_t Pack11(uint16_t); + uint16_t Pack12(uint16_t); + uint16_t Pack13(uint16_t); + uint16_t Pack14(uint16_t); + uint16_t Pack15(uint16_t); + +} + +#endif diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index 2af6a1f..f53ec3f 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -51,7 +51,6 @@ - // yuck. TST.W d0 extern "C" void cpuSetFlagsNZ00NewW(UWO res); @@ -376,7 +375,7 @@ namespace ToolBox { case 0xa9ed: - d0 = OS::Pack6(trap); + d0 = Packages::Pack6(trap); break; //_CmpString [MARKS,CASE]