diff --git a/LaunchAPPL/Server/AppLauncher.cc b/LaunchAPPL/Server/AppLauncher.cc new file mode 100644 index 0000000000..c593d11ad5 --- /dev/null +++ b/LaunchAPPL/Server/AppLauncher.cc @@ -0,0 +1,122 @@ +#include "AppLauncher.h" + +#include +#include +#include + +class AppLauncherSingle : public AppLauncher +{ +public: + virtual bool Launch(ConstStr255Param name) + { + LaunchParamBlockRec lpb; + memset(&lpb, 0, sizeof(lpb)); + + lpb.reserved1 = (unsigned long) name; + lpb.reserved2 = 0; + lpb.launchBlockID = extendedBlock; + lpb.launchEPBLength = 6; + lpb.launchFileFlags = 0; + lpb.launchControlFlags = 0xC000; + + LaunchApplication(&lpb); + + return false; + } + + virtual bool IsRunning(ConstStr255Param name) + { + return false; + } +}; + +class AppLauncher7 : public AppLauncher +{ + ProcessSerialNumber psn; +public: + virtual bool Launch(ConstStr255Param name) + { + LaunchParamBlockRec lpb; + memset(&lpb, 0, sizeof(lpb)); + FSSpec spec; + FSMakeFSSpec(0,0,name,&spec); + lpb.launchBlockID = extendedBlock; + lpb.launchEPBLength = extendedBlockLen; + lpb.launchFileFlags = 0; + lpb.launchControlFlags = launchContinue; + lpb.launchAppSpec = &spec; + + OSErr err = LaunchApplication(&lpb); + + psn = lpb.launchProcessSN; + + return err >= 0; + } + virtual bool IsRunning(ConstStr255Param name) + { + ProcessInfoRec info; + memset(&info, 0, sizeof(info)); + info.processInfoLength = sizeof(info); + OSErr err = GetProcessInformation(&psn,&info); + return err == noErr; + } +}; + +class AppLauncherMultiFinder : public AppLauncher +{ +public: + virtual bool Launch(ConstStr255Param name) + { + LaunchParamBlockRec lpb; + memset(&lpb, 0, sizeof(lpb)); + + lpb.reserved1 = (unsigned long) name; + lpb.reserved2 = 0; + lpb.launchBlockID = extendedBlock; + lpb.launchEPBLength = 6; + lpb.launchFileFlags = 0; + lpb.launchControlFlags = 0xC000; + + OSErr err = LaunchApplication(&lpb); + + return err >= 0; + } + virtual bool IsRunning(ConstStr255Param name) + { + uint8_t *fcbs = *(uint8_t**)0x34E; // FCBSPtr; + + uint16_t bufSize = * (uint16_t*) fcbs; + uint8_t *end = fcbs + bufSize; + + for(uint8_t *fcb = fcbs + 2; fcb < end; fcb += 94) + { + if(*(uint32_t*) fcb == 0) + continue; + if(*(OSType*) (fcb + 0x32) != 'APPL') + continue; + if(EqualString(fcb + 0x3E, "\pRetro68App", true, true)) + return true; + } + return false; + } +}; + +std::unique_ptr CreateAppLauncher() +{ +#if TARGET_API_MAC_CARBON || TARGET_RT_MAC_CFM + return std::make_unique(); +#else + SysEnvRec environ; + SysEnvirons(curSysEnvVers, &environ); + if(environ.systemVersion >= 0x0700) + return std::make_unique(); + else + { + uint32_t& Twitcher2 = *(uint32_t*) 0xB7C; + if(Twitcher2 == 0 || Twitcher2 == 0xFFFFFFFF) + return std::make_unique(); + else + return std::make_unique(); + } +#endif +} diff --git a/LaunchAPPL/Server/AppLauncher.h b/LaunchAPPL/Server/AppLauncher.h new file mode 100644 index 0000000000..77b5510698 --- /dev/null +++ b/LaunchAPPL/Server/AppLauncher.h @@ -0,0 +1,11 @@ +#include +#include + +class AppLauncher +{ +public: + virtual bool Launch(ConstStr255Param name) = 0; + virtual bool IsRunning(ConstStr255Param name) = 0; +}; + +std::unique_ptr CreateAppLauncher(); diff --git a/LaunchAPPL/Server/CMakeLists.txt b/LaunchAPPL/Server/CMakeLists.txt index 19603f4607..0b3c3a4519 100644 --- a/LaunchAPPL/Server/CMakeLists.txt +++ b/LaunchAPPL/Server/CMakeLists.txt @@ -2,7 +2,9 @@ add_application(LaunchAPPLServer LaunchAPPLServer.r LaunchAPPLServer.cc MacSerialStream.h - MacSerialStream.cc) + MacSerialStream.cc + AppLauncher.h + AppLauncher.cc) target_link_libraries(LaunchAPPLServer LaunchAPPLCommon) set_target_properties(LaunchAPPLServer PROPERTIES diff --git a/LaunchAPPL/Server/LaunchAPPLServer.cc b/LaunchAPPL/Server/LaunchAPPLServer.cc index a23847b258..565924d1cb 100644 --- a/LaunchAPPL/Server/LaunchAPPLServer.cc +++ b/LaunchAPPL/Server/LaunchAPPLServer.cc @@ -29,6 +29,8 @@ #include "MacSerialStream.h" +#include "AppLauncher.h" + #include #include #include @@ -341,111 +343,6 @@ void SetBaud(long baud) gSerialStream->setBaud(baud); } -class AppLauncher -{ -public: - virtual bool Launch(ConstStr255Param name) = 0; - virtual bool IsRunning(ConstStr255Param name) = 0; -}; - -class AppLauncherSingle : public AppLauncher -{ -public: - virtual bool Launch(ConstStr255Param name) - { - gSerialStream->close(); - - LaunchParamBlockRec lpb; - memset(&lpb, 0, sizeof(lpb)); - - lpb.reserved1 = (unsigned long) name; - lpb.reserved2 = 0; - lpb.launchBlockID = extendedBlock; - lpb.launchEPBLength = 6; - lpb.launchFileFlags = 0; - lpb.launchControlFlags = 0xC000; - - LaunchApplication(&lpb); - - return false; - } - - virtual bool IsRunning(ConstStr255Param name) - { - return false; - } -}; - -class AppLauncher7 : public AppLauncher -{ - ProcessSerialNumber psn; -public: - virtual bool Launch(ConstStr255Param name) - { - LaunchParamBlockRec lpb; - memset(&lpb, 0, sizeof(lpb)); - FSSpec spec; - FSMakeFSSpec(0,0,name,&spec); - lpb.launchBlockID = extendedBlock; - lpb.launchEPBLength = extendedBlockLen; - lpb.launchFileFlags = 0; - lpb.launchControlFlags = launchContinue; - lpb.launchAppSpec = &spec; - - OSErr err = LaunchApplication(&lpb); - - psn = lpb.launchProcessSN; - - return err >= 0; - } - virtual bool IsRunning(ConstStr255Param name) - { - ProcessInfoRec info; - memset(&info, 0, sizeof(info)); - info.processInfoLength = sizeof(info); - OSErr err = GetProcessInformation(&psn,&info); - return err == noErr; - } -}; - -class AppLauncherMultiFinder : public AppLauncher -{ -public: - virtual bool Launch(ConstStr255Param name) - { - LaunchParamBlockRec lpb; - memset(&lpb, 0, sizeof(lpb)); - - lpb.reserved1 = (unsigned long) name; - lpb.reserved2 = 0; - lpb.launchBlockID = extendedBlock; - lpb.launchEPBLength = 6; - lpb.launchFileFlags = 0; - lpb.launchControlFlags = 0xC000; - - OSErr err = LaunchApplication(&lpb); - - return err >= 0; - } - virtual bool IsRunning(ConstStr255Param name) - { - uint8_t *fcbs = *(uint8_t**)0x34E; // FCBSPtr; - - uint16_t bufSize = * (uint16_t*) fcbs; - uint8_t *end = fcbs + bufSize; - - for(uint8_t *fcb = fcbs + 2; fcb < end; fcb += 94) - { - if(*(uint32_t*) fcb == 0) - continue; - if(*(OSType*) (fcb + 0x32) != 'APPL') - continue; - if(EqualString(fcb + 0x3E, "\pRetro68App", true, true)) - return true; - } - return false; - } -}; int main() @@ -480,24 +377,7 @@ int main() LaunchServer server(&rStream); - std::unique_ptr appLauncher; - -#if TARGET_API_MAC_CARBON || TARGET_RT_MAC_CFM - appLauncher = std::make_unique(); -#else - SysEnvRec environ; - SysEnvirons(curSysEnvVers, &environ); - if(environ.systemVersion >= 0x0700) - appLauncher = std::make_unique(); - else - { - uint32_t& Twitcher2 = *(uint32_t*) 0xB7C; - if(Twitcher2 == 0 || Twitcher2 == 0xFFFFFFFF) - appLauncher = std::make_unique(); - else - appLauncher = std::make_unique(); - } -#endif + std::unique_ptr appLauncher = CreateAppLauncher(); for(;;) { @@ -558,7 +438,9 @@ int main() if(server.state == LaunchServer::State::launch) { - if(appLauncher->Launch("\pRetro68App")) + gSerialStream->close(); + bool launched = appLauncher->Launch("\pRetro68App"); + if(launched) { server.state = LaunchServer::State::wait; nullEventCounter = 0; @@ -575,6 +457,7 @@ int main() { if(!appLauncher->IsRunning("\pRetro68App")) { + gSerialStream->open(); server.state = LaunchServer::State::respond; uint32_t zero = 0; rStream.write(&zero, 4); diff --git a/LaunchAPPL/Server/MacSerialStream.cc b/LaunchAPPL/Server/MacSerialStream.cc index d096e5f463..413c8be203 100644 --- a/LaunchAPPL/Server/MacSerialStream.cc +++ b/LaunchAPPL/Server/MacSerialStream.cc @@ -7,18 +7,8 @@ MacSerialStream::MacSerialStream() { - OSErr err; - err = OpenDriver("\p.AOut", &outRefNum); - err = OpenDriver("\p.AIn", &inRefNum); - SerSetBuf(inRefNum, inputBuffer, kInputBufferSize); - - - SerShk shk; - memset(&shk, 0, sizeof(shk)); - shk.fCTS = true; - Control(outRefNum, kSERDHandshake, &shk); - - SerReset(outRefNum, baud19200 | data8 | noParity | stop10); + curBaud = 19200; + open(); } void MacSerialStream::close() @@ -32,6 +22,22 @@ void MacSerialStream::close() inRefNum = outRefNum = 0; } +void MacSerialStream::open() +{ + OSErr err; + err = OpenDriver("\p.AOut", &outRefNum); + err = OpenDriver("\p.AIn", &inRefNum); + SerSetBuf(inRefNum, inputBuffer, kInputBufferSize); + + + SerShk shk; + memset(&shk, 0, sizeof(shk)); + shk.fCTS = true; + Control(outRefNum, kSERDHandshake, &shk); + + setBaud(curBaud); +} + MacSerialStream::~MacSerialStream() { close(); @@ -70,6 +76,7 @@ void MacSerialStream::idle() void MacSerialStream::setBaud(int baud) { + curBaud = baud; short baudval = 0; switch(baud) { diff --git a/LaunchAPPL/Server/MacSerialStream.h b/LaunchAPPL/Server/MacSerialStream.h index 2c246c23ca..c1fa76c0c9 100644 --- a/LaunchAPPL/Server/MacSerialStream.h +++ b/LaunchAPPL/Server/MacSerialStream.h @@ -11,6 +11,7 @@ class MacSerialStream : public Stream char readBuffer[kReadBufferSize]; short outRefNum, inRefNum; + int curBaud; public: virtual void write(const void* p, size_t n) override; @@ -20,6 +21,7 @@ public: ~MacSerialStream(); void close(); + void open(); void setBaud(int baud); };