From 270cafaab4612dde9d345f5899612f88fd2f2e1c Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Sun, 1 Oct 2017 23:36:50 +0200 Subject: [PATCH] improve LaunchAPPL --- AutomatedTests/Log.c | 11 +++ AutomatedTests/Test.h | 13 ++- Dockerfile | 15 ++++ LaunchAPPL/CMakeLists.txt | 2 +- LaunchAPPL/LaunchAPPL.cc | 176 ++++++++++++++++++++++++++++++++++---- LaunchAPPL/bootblock.c | 67 +++++++++++++++ 6 files changed, 266 insertions(+), 18 deletions(-) create mode 100644 AutomatedTests/Log.c create mode 100644 Dockerfile create mode 100644 LaunchAPPL/bootblock.c diff --git a/AutomatedTests/Log.c b/AutomatedTests/Log.c new file mode 100644 index 0000000000..ec6624054c --- /dev/null +++ b/AutomatedTests/Log.c @@ -0,0 +1,11 @@ +#include "Test.h" + +int main() +{ + TEST_LOG_SIZED("One",3); + TEST_LOG_SIZED("Two",3); + for(;;) + ; + TEST_LOG_SIZED("Three",5); + return 0; +} diff --git a/AutomatedTests/Test.h b/AutomatedTests/Test.h index f8970d0f4d..46c3b66940 100644 --- a/AutomatedTests/Test.h +++ b/AutomatedTests/Test.h @@ -3,12 +3,15 @@ #include #include +#include #define TEST_LOG_SIZED(str, size) \ do { \ HParamBlockRec _hpb; \ + memset(&_hpb,0,sizeof(_hpb)); \ \ unsigned char _fileName[4]; \ + short _ref;\ _fileName[0] = 3; \ _fileName[1] = 'o'; \ _fileName[2] = 'u'; \ @@ -20,19 +23,27 @@ _hpb.fileParam.ioDirID = 0; \ _hpb.ioParam.ioPermssn = fsRdWrPerm; \ PBHOpenSync(&_hpb); \ - \ + _ref = _hpb.ioParam.ioRefNum; \ + \ + memset(&_hpb,0,sizeof(_hpb)); \ _hpb.ioParam.ioBuffer = str; \ _hpb.ioParam.ioReqCount = size; \ _hpb.ioParam.ioPosMode = fsFromLEOF; \ _hpb.ioParam.ioPosOffset = 0; \ + _hpb.ioParam.ioRefNum = _ref; \ PBWriteSync((void*)&_hpb); \ + memset(&_hpb,0,sizeof(_hpb)); \ char _newline = '\n'; \ _hpb.ioParam.ioBuffer = &_newline; \ _hpb.ioParam.ioReqCount = 1; \ _hpb.ioParam.ioPosMode = fsFromLEOF; \ _hpb.ioParam.ioPosOffset = 0; \ + _hpb.ioParam.ioRefNum = _ref; \ PBWriteSync((void*)&_hpb); \ + memset(&_hpb,0,sizeof(_hpb)); \ + _hpb.ioParam.ioRefNum = _ref; \ PBCloseSync((void*)&_hpb); \ + FlushVol(NULL,0); \ } while(0); void TestLog(const char *str); diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..87342f2649 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# vim:ft=dockerfile +FROM ubuntu:16.04 + +RUN apt-get update && apt-get -y install \ + g++ \ + cmake libgmp-dev libmpfr-dev libmpc-dev libboost-all-dev bison \ + zlib1g-dev \ + perl texinfo + +RUN mkdir /root/Retro68 +COPY . /root/Retro68/ + +RUN mkdir /root/Retro68-build + +RUN sh -c "cd /root/Retro68-build && sh ../Retro68/build-toolchain.sh --clean-after-build" \ No newline at end of file diff --git a/LaunchAPPL/CMakeLists.txt b/LaunchAPPL/CMakeLists.txt index 1e98c88d02..14f268d3fd 100644 --- a/LaunchAPPL/CMakeLists.txt +++ b/LaunchAPPL/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(Boost COMPONENTS filesystem program_options) -add_executable(LaunchAPPL LaunchAPPL.cc) +add_executable(LaunchAPPL LaunchAPPL.cc bootblock.c) target_include_directories(LaunchAPPL PRIVATE ${CMAKE_INSTALL_PREFIX}/include ${Boost_INCLUDE_DIR}) target_link_libraries(LaunchAPPL ResourceFiles ${Boost_LIBRARIES}) diff --git a/LaunchAPPL/LaunchAPPL.cc b/LaunchAPPL/LaunchAPPL.cc index 626a3ee75f..e9288c78b7 100644 --- a/LaunchAPPL/LaunchAPPL.cc +++ b/LaunchAPPL/LaunchAPPL.cc @@ -13,6 +13,11 @@ #include "ResourceFork.h" #include "ResourceFile.h" +extern "C" { +#include "hfs.h" +} + + namespace po = boost::program_options; namespace fs = boost::filesystem; @@ -119,12 +124,18 @@ int ChildProcess(string program, vector args) int main(int argc, char *argv[]) { desc.add_options() - ("help,h", "show this help message") - ("executor-path", po::value()->default_value("executor"),"path to executor") + ("help,h", "show this help message") ("executor,e", "run using executor") + ("minivmac,m", "run using executor") + + ("executor-path", po::value()->default_value("executor"),"path to executor") + ("minivmac-path", po::value()->default_value("minivmac"),"path to minivmac") + ("minivmac-dir", po::value()->default_value("."),"directory containing vMac.ROM") + ("system-image", po::value(),"path to disk image with system") + ("timeout,t", po::value(),"abort after timeout") + ("timeout-ok","timeout counts as success") ("logfile", po::value(), "read log file") - ("result,r", "TEST 128") ; po::options_description hidden, alldesc; hidden.add_options() @@ -169,7 +180,6 @@ int main(int argc, char *argv[]) if(options.count("executor")) { fs::path tempDir = fs::unique_path(); - std::cerr << "Unique path: " << tempDir.string() << std::endl; fs::create_directories(tempDir); fs::path appPath = tempDir / "Application"; @@ -194,22 +204,156 @@ int main(int argc, char *argv[]) std::cout << in.rdbuf(); } - - if(result == 0 && options.count("result")) - { - app.read(); - auto& resmap = app.resources.resources; - auto p = resmap.find(ResRef("TEST", 128)); - if(p == resmap.end()) - return 1; - - std::cout << p->second.getData(); - } - fs::remove_all(tempDir); return result; } + if(options.count("minivmac")) + { + assert(options.count("system-image")); + fs::path tempDir = fs::unique_path(); + fs::path path = tempDir / "image.dsk"; + fs::create_directories(tempDir); + + hfsvol *sysvol = hfs_mount(options["system-image"].as().c_str(), + 0, HFS_MODE_RDONLY); + + int size = 5000*1024; + fs::ofstream(path, std::ios::binary | std::ios::trunc).seekp(size-1).put(0); + hfs_format(path.string().c_str(), 0, 0, "SysAndApp", 0, NULL); + hfsvol *vol = hfs_mount(path.string().c_str(), 0, HFS_MODE_RDWR); + + hfsvolent ent; + hfs_vstat(sysvol, &ent); + + hfs_setcwd(sysvol, ent.blessed); + + + + + { + const char *fn = "System"; + hfsdirent fileent; + hfs_stat(sysvol, fn, &fileent); + hfsfile *in = hfs_open(sysvol, fn); + hfsfile *out = hfs_create(vol, fn, fileent.u.file.type,fileent.u.file.creator); + + std::vector buffer(std::max(fileent.u.file.dsize, fileent.u.file.rsize)); + hfs_setfork(in, 0); + hfs_setfork(out, 0); + hfs_read(in, buffer.data(), fileent.u.file.dsize); + hfs_write(out, buffer.data(), fileent.u.file.dsize); + hfs_setfork(in, 1); + hfs_setfork(out, 1); + hfs_read(in, buffer.data(), fileent.u.file.rsize); + hfs_write(out, buffer.data(), fileent.u.file.rsize); + hfs_close(in); + hfs_close(out); + } + { + const char *fn = "Finder"; + hfsdirent fileent; + hfs_stat(sysvol, fn, &fileent); + hfsfile *in = hfs_open(sysvol, fn); + hfsfile *out = hfs_create(vol, fn, fileent.u.file.type,fileent.u.file.creator); + + std::vector buffer(std::max(fileent.u.file.dsize, fileent.u.file.rsize)); + hfs_setfork(in, 0); + hfs_setfork(out, 0); + hfs_read(in, buffer.data(), fileent.u.file.dsize); + hfs_write(out, buffer.data(), fileent.u.file.dsize); + hfs_setfork(in, 1); + hfs_setfork(out, 1); + hfs_read(in, buffer.data(), fileent.u.file.rsize); + hfs_write(out, buffer.data(), fileent.u.file.rsize); + hfs_close(in); + hfs_close(out); + } + { + const char *fn = "MacsBug"; + hfsdirent fileent; + hfs_stat(sysvol, fn, &fileent); + hfsfile *in = hfs_open(sysvol, fn); + hfsfile *out = hfs_create(vol, fn, fileent.u.file.type,fileent.u.file.creator); + + std::vector buffer(std::max(fileent.u.file.dsize, fileent.u.file.rsize)); + hfs_setfork(in, 0); + hfs_setfork(out, 0); + hfs_read(in, buffer.data(), fileent.u.file.dsize); + hfs_write(out, buffer.data(), fileent.u.file.dsize); + hfs_setfork(in, 1); + hfs_setfork(out, 1); + hfs_read(in, buffer.data(), fileent.u.file.rsize); + hfs_write(out, buffer.data(), fileent.u.file.rsize); + hfs_close(in); + hfs_close(out); + } + + { + std::ostringstream rsrcOut; + app.resources.writeFork(rsrcOut); + std::string rsrc = rsrcOut.str(); + std::string& data = app.data; + + hfsfile *file = hfs_create(vol, "App","APPL","????"); + hfs_setfork(file, 0); + hfs_write(file, data.data(), data.size()); + hfs_setfork(file, 1); + hfs_write(file, rsrc.data(), rsrc.size()); + hfs_close(file); + } + + { + hfsfile *out = hfs_create(vol, "out", "TEXT", "????"); + hfs_close(out); + } + + hfs_vstat(vol, &ent); + ent.blessed = hfs_getcwd(vol); + std::cout << "blessed: " << ent.blessed << std::endl; + hfs_vsetattr(vol, &ent); + + hfs_umount(vol); + hfs_umount(sysvol); + + extern unsigned char bootblock[1024]; + std::vector bootblock1(bootblock, bootblock+1024); + std::fstream out(path.string(), std::ios::in | std::ios::out | std::ios::binary); + + bootblock1[0x5A] = 3; + bootblock1[0x5B] = 'A'; + bootblock1[0x5C] = 'p'; + bootblock1[0x5D] = 'p'; + + out.write((const char*) bootblock1.data(), 1024); + + path = fs::absolute(path); + + fs::path minivmacdir = fs::absolute( options["minivmac-dir"].as() ); + fs::path minivmacpath = fs::absolute( minivmacdir / options["minivmac-path"].as() ); + + fs::current_path(minivmacdir); + + int result = ChildProcess(minivmacpath.string(), { path.string() }); + + std::cerr << "volume at: " << path.string() << std::endl; + vol = hfs_mount(path.string().c_str(), 0, HFS_MODE_RDONLY); + { + hfsfile *out = hfs_open(vol, "out"); + if(!out) + return 1; + hfsdirent fileent; + int statres = hfs_stat(vol, "out", &fileent); + std::cerr << "stat: " << statres << "\n"; + std::cerr << "out: " << fileent.u.file.dsize << " bytes\n"; + std::vector buffer(fileent.u.file.dsize); + hfs_setfork(out, 0); + hfs_read(out, buffer.data(), fileent.u.file.dsize); + hfs_close(out); + std::cout << string(buffer.begin(), buffer.end()); + } + hfs_umount(vol); + } return 0; } diff --git a/LaunchAPPL/bootblock.c b/LaunchAPPL/bootblock.c new file mode 100644 index 0000000000..fa1a23eb89 --- /dev/null +++ b/LaunchAPPL/bootblock.c @@ -0,0 +1,67 @@ +unsigned char bootblock[] = { +/* 00000000 */ 0x4c, 0x4b, 0x60, 0x00, 0x00, 0x86, 0x00, 0x17, 0x00, 0x00, 0x06, 0x53, 0x79, 0x73, 0x74, 0x65, /* |LK`........Syste| */ +/* 00000010 */ 0x6d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x06, 0x46, 0x69, 0x6e, 0x64, 0x65, /* |m .Finde| */ +/* 00000020 */ 0x72, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x07, 0x4d, 0x61, 0x63, 0x73, 0x62, /* |r .Macsb| */ +/* 00000030 */ 0x75, 0x67, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0c, 0x44, 0x69, 0x73, 0x61, 0x73, /* |ug .Disas| */ +/* 00000040 */ 0x73, 0x65, 0x6d, 0x62, 0x6c, 0x65, 0x72, 0x20, 0x20, 0x20, 0x0d, 0x53, 0x74, 0x61, 0x72, 0x74, /* |sembler .Start| */ +/* 00000050 */ 0x55, 0x70, 0x53, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x20, 0x06, 0x46, 0x69, 0x6e, 0x64, 0x65, /* |UpScreen .Finde| */ +/* 00000060 */ 0x72, 0x00, 0x81, 0x00, 0x00, 0x72, 0x00, 0x00, 0x64, 0x0c, 0x0e, 0x43, 0x6c, 0x69, 0x70, 0x62, /* |r....r..d..Clipb| */ +/* 00000070 */ 0x6f, 0x61, 0x72, 0x64, 0x20, 0x46, 0x69, 0x6c, 0x65, 0x20, 0x00, 0x0a, 0x00, 0x14, 0x00, 0x00, /* |oard File ......| */ +/* 00000080 */ 0x43, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x02, 0x00, 0x00, 0x22, 0x38, 0x01, 0x08, 0x48, 0x41, /* |C........."8..HA| */ +/* 00000090 */ 0x0c, 0x41, 0x00, 0x04, 0x6e, 0x2c, 0x72, 0x00, 0x50, 0xf9, 0x00, 0x01, 0xff, 0xf0, 0x42, 0xb9, /* |.A..n,r.P.....B.| */ +/* 000000a0 */ 0x00, 0x03, 0xff, 0xf0, 0x4a, 0xb9, 0x00, 0x01, 0xff, 0xf0, 0x67, 0x16, 0x70, 0x02, 0x48, 0x40, /* |....J.....g.p.H@| */ +/* 000000b0 */ 0xd1, 0xb8, 0x01, 0x08, 0xd1, 0xb8, 0x08, 0x24, 0xd1, 0xb8, 0x02, 0x66, 0xd1, 0xb8, 0x01, 0x0c, /* |.......$...f....| */ +/* 000000c0 */ 0x72, 0x04, 0x20, 0x78, 0x02, 0xa6, 0x0c, 0x41, 0x00, 0x08, 0x6f, 0x02, 0x72, 0x08, 0xd1, 0xfb, /* |r. x...A..o.r...| */ +/* 000000d0 */ 0x10, 0xae, 0x2f, 0x08, 0x70, 0x07, 0x41, 0xf8, 0x0a, 0xb8, 0x42, 0x98, 0x51, 0xc8, 0xff, 0xfc, /* |../.p.A...B.Q...| */ +/* 000000e0 */ 0x34, 0x3a, 0xff, 0x9a, 0x70, 0x16, 0xc0, 0xc2, 0x22, 0x00, 0xa7, 0x1e, 0x43, 0xf8, 0x01, 0x54, /* |4:..p..."...C..T| */ +/* 000000f0 */ 0x53, 0x42, 0x32, 0x82, 0x42, 0xa1, 0x42, 0xa1, 0x42, 0x61, 0x23, 0x08, 0x46, 0x58, 0x55, 0x41, /* |SB2.B.B.Ba#.FXUA| */ +/* 00000100 */ 0x66, 0xfa, 0x33, 0x3c, 0xff, 0xef, 0x42, 0x78, 0x01, 0x84, 0x72, 0xfc, 0x70, 0x0f, 0x14, 0x38, /* |f.3<..Bx..r.p..8| */ +/* 00000110 */ 0x02, 0x06, 0xc0, 0x02, 0xd0, 0x40, 0x48, 0x40, 0x10, 0x02, 0xe4, 0x48, 0xc0, 0x41, 0x48, 0x40, /* |.....@H@...H.AH@| */ +/* 00000120 */ 0x21, 0xc0, 0x01, 0x8e, 0x70, 0x0f, 0x14, 0x38, 0x02, 0x09, 0xc0, 0x02, 0xe5, 0x48, 0x21, 0xc0, /* |!...p..8.....H!.| */ +/* 00000130 */ 0x02, 0xf4, 0x10, 0x02, 0xe4, 0x48, 0xc0, 0x41, 0x21, 0xc0, 0x02, 0xf0, 0x41, 0xf8, 0x03, 0x40, /* |.....H.A!...A..@| */ +/* 00000140 */ 0x72, 0x50, 0x42, 0x58, 0x51, 0xc9, 0xff, 0xfc, 0x70, 0x1e, 0xc0, 0xfa, 0xff, 0x2e, 0x32, 0x38, /* |rPBXQ...p.....28| */ +/* 00000150 */ 0x01, 0x08, 0xe2, 0x49, 0xc0, 0xc1, 0x54, 0x40, 0x32, 0x00, 0xa7, 0x1e, 0x21, 0xc8, 0x03, 0x4e, /* |...I..T@2...!..N| */ +/* 00000160 */ 0x30, 0xc1, 0x31, 0xfc, 0x00, 0x02, 0x03, 0x4c, 0x9e, 0xfc, 0x00, 0x32, 0x20, 0x4f, 0x31, 0x78, /* |0.1....L...2 O1x| */ +/* 00000170 */ 0x02, 0x10, 0x00, 0x16, 0xa0, 0x0f, 0x66, 0x00, 0x01, 0xb2, 0xde, 0xfc, 0x00, 0x32, 0x43, 0xf8, /* |......f......2C.| */ +/* 00000180 */ 0x0a, 0xd8, 0x41, 0xfa, 0xfe, 0x86, 0x70, 0x10, 0xa0, 0x2e, 0x55, 0x4f, 0x2f, 0x0f, 0x48, 0x78, /* |..A...p...UO/.Hx| */ +/* 00000190 */ 0x09, 0xfa, 0x20, 0x78, 0x08, 0x10, 0x4e, 0x90, 0x30, 0x1f, 0xe6, 0x48, 0x31, 0xc0, 0x01, 0x06, /* |.. x..N.0..H1...| */ +/* 000001a0 */ 0x08, 0x38, 0x00, 0x06, 0x02, 0x0b, 0x56, 0xf8, 0x08, 0xd3, 0xa8, 0x52, 0x43, 0xfa, 0xfe, 0x9c, /* |.8....V....RC...| */ +/* 000001b0 */ 0x76, 0x01, 0x61, 0x00, 0x01, 0x98, 0x0c, 0x44, 0x40, 0x00, 0x6e, 0x02, 0x70, 0xff, 0x3f, 0x00, /* |v.a....D@.n.p.?.| */ +/* 000001c0 */ 0x66, 0x04, 0x61, 0x00, 0x01, 0xf0, 0xa8, 0x53, 0x55, 0x4f, 0x42, 0xb8, 0x0a, 0xf2, 0xa9, 0x95, /* |f.a....SUOB.....| */ +/* 000001d0 */ 0x4a, 0x5f, 0x6b, 0x00, 0x01, 0x56, 0x3e, 0x1f, 0x20, 0x5f, 0xa0, 0x57, 0x21, 0xf8, 0x02, 0xa6, /* |J_k..V>. _.W!...| */ +/* 000001e0 */ 0x01, 0x18, 0x59, 0x4f, 0x2f, 0x3c, 0x44, 0x53, 0x41, 0x54, 0x42, 0x67, 0xa9, 0xa0, 0x2a, 0x1f, /* |..YO/