diff --git a/CMakeLists.txt b/CMakeLists.txt index 927eb1a83f..04da98e6b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,9 +52,10 @@ add_subdirectory(Samples/SystemExtension) add_subdirectory(Samples/WDEF) endif() +add_subdirectory(LaunchAPPL) + enable_testing() add_subdirectory(AutomatedTests) - else() set(RETRO68_ROOT ${CMAKE_INSTALL_PREFIX}) diff --git a/LaunchAPPL/CMakeLists.txt b/LaunchAPPL/CMakeLists.txt index ca372552f4..0b4b58faea 100644 --- a/LaunchAPPL/CMakeLists.txt +++ b/LaunchAPPL/CMakeLists.txt @@ -1,38 +1,5 @@ -find_package(Boost COMPONENTS filesystem program_options) - -set(LAUNCHMETHODS - Executor.h Executor.cc - MiniVMac.h MiniVMac.cc - SSH.h SSH.cc -) - -if(APPLE) - LIST(APPEND LAUNCHMETHODS - Classic.h Classic.cc - ) - LIST(APPEND LAUNCHMETHODS - Carbon.h Carbon.cc) +if(CMAKE_SYSTEM_NAME MATCHES Retro.*) + add_subdirectory(Server) +else() + add_subdirectory(Client) endif() -add_definitions(-DRETRO68_PREFIX="${CMAKE_INSTALL_PREFIX}") - -add_executable(LaunchAPPL - LaunchAPPL.cc - MakeExecutable.cc - - LaunchMethod.h LaunchMethod.cc - Launcher.h Launcher.cc - - Utilities.h Utilities.cc - - ${LAUNCHMETHODS}) - - -target_include_directories(LaunchAPPL PRIVATE ${CMAKE_INSTALL_PREFIX}/include ${Boost_INCLUDE_DIR}) -target_link_libraries(LaunchAPPL ResourceFiles ${Boost_LIBRARIES}) - -if(APPLE) - find_library(APPLICATIONSERVICES_FW ApplicationServices) - target_link_libraries(LaunchAPPL ${APPLICATIONSERVICES_FW}) -endif() - -install(TARGETS LaunchAPPL RUNTIME DESTINATION bin) diff --git a/LaunchAPPL/Client/CMakeLists.txt b/LaunchAPPL/Client/CMakeLists.txt new file mode 100644 index 0000000000..ca372552f4 --- /dev/null +++ b/LaunchAPPL/Client/CMakeLists.txt @@ -0,0 +1,38 @@ +find_package(Boost COMPONENTS filesystem program_options) + +set(LAUNCHMETHODS + Executor.h Executor.cc + MiniVMac.h MiniVMac.cc + SSH.h SSH.cc +) + +if(APPLE) + LIST(APPEND LAUNCHMETHODS + Classic.h Classic.cc + ) + LIST(APPEND LAUNCHMETHODS + Carbon.h Carbon.cc) +endif() +add_definitions(-DRETRO68_PREFIX="${CMAKE_INSTALL_PREFIX}") + +add_executable(LaunchAPPL + LaunchAPPL.cc + MakeExecutable.cc + + LaunchMethod.h LaunchMethod.cc + Launcher.h Launcher.cc + + Utilities.h Utilities.cc + + ${LAUNCHMETHODS}) + + +target_include_directories(LaunchAPPL PRIVATE ${CMAKE_INSTALL_PREFIX}/include ${Boost_INCLUDE_DIR}) +target_link_libraries(LaunchAPPL ResourceFiles ${Boost_LIBRARIES}) + +if(APPLE) + find_library(APPLICATIONSERVICES_FW ApplicationServices) + target_link_libraries(LaunchAPPL ${APPLICATIONSERVICES_FW}) +endif() + +install(TARGETS LaunchAPPL RUNTIME DESTINATION bin) diff --git a/LaunchAPPL/Carbon.cc b/LaunchAPPL/Client/Carbon.cc similarity index 100% rename from LaunchAPPL/Carbon.cc rename to LaunchAPPL/Client/Carbon.cc diff --git a/LaunchAPPL/Carbon.h b/LaunchAPPL/Client/Carbon.h similarity index 100% rename from LaunchAPPL/Carbon.h rename to LaunchAPPL/Client/Carbon.h diff --git a/LaunchAPPL/Classic.cc b/LaunchAPPL/Client/Classic.cc similarity index 100% rename from LaunchAPPL/Classic.cc rename to LaunchAPPL/Client/Classic.cc diff --git a/LaunchAPPL/Classic.h b/LaunchAPPL/Client/Classic.h similarity index 100% rename from LaunchAPPL/Classic.h rename to LaunchAPPL/Client/Classic.h diff --git a/LaunchAPPL/Executor.cc b/LaunchAPPL/Client/Executor.cc similarity index 100% rename from LaunchAPPL/Executor.cc rename to LaunchAPPL/Client/Executor.cc diff --git a/LaunchAPPL/Executor.h b/LaunchAPPL/Client/Executor.h similarity index 100% rename from LaunchAPPL/Executor.h rename to LaunchAPPL/Client/Executor.h diff --git a/LaunchAPPL/LaunchAPPL.cc b/LaunchAPPL/Client/LaunchAPPL.cc similarity index 100% rename from LaunchAPPL/LaunchAPPL.cc rename to LaunchAPPL/Client/LaunchAPPL.cc diff --git a/LaunchAPPL/LaunchAPPL.cfg.example b/LaunchAPPL/Client/LaunchAPPL.cfg.example similarity index 100% rename from LaunchAPPL/LaunchAPPL.cfg.example rename to LaunchAPPL/Client/LaunchAPPL.cfg.example diff --git a/LaunchAPPL/LaunchMethod.cc b/LaunchAPPL/Client/LaunchMethod.cc similarity index 100% rename from LaunchAPPL/LaunchMethod.cc rename to LaunchAPPL/Client/LaunchMethod.cc diff --git a/LaunchAPPL/LaunchMethod.h b/LaunchAPPL/Client/LaunchMethod.h similarity index 100% rename from LaunchAPPL/LaunchMethod.h rename to LaunchAPPL/Client/LaunchMethod.h diff --git a/LaunchAPPL/Launcher.cc b/LaunchAPPL/Client/Launcher.cc similarity index 100% rename from LaunchAPPL/Launcher.cc rename to LaunchAPPL/Client/Launcher.cc diff --git a/LaunchAPPL/Launcher.h b/LaunchAPPL/Client/Launcher.h similarity index 100% rename from LaunchAPPL/Launcher.h rename to LaunchAPPL/Client/Launcher.h diff --git a/LaunchAPPL/MakeExecutable.cc b/LaunchAPPL/Client/MakeExecutable.cc similarity index 100% rename from LaunchAPPL/MakeExecutable.cc rename to LaunchAPPL/Client/MakeExecutable.cc diff --git a/LaunchAPPL/MiniVMac.cc b/LaunchAPPL/Client/MiniVMac.cc similarity index 100% rename from LaunchAPPL/MiniVMac.cc rename to LaunchAPPL/Client/MiniVMac.cc diff --git a/LaunchAPPL/MiniVMac.h b/LaunchAPPL/Client/MiniVMac.h similarity index 100% rename from LaunchAPPL/MiniVMac.h rename to LaunchAPPL/Client/MiniVMac.h diff --git a/LaunchAPPL/SSH.cc b/LaunchAPPL/Client/SSH.cc similarity index 100% rename from LaunchAPPL/SSH.cc rename to LaunchAPPL/Client/SSH.cc diff --git a/LaunchAPPL/SSH.h b/LaunchAPPL/Client/SSH.h similarity index 100% rename from LaunchAPPL/SSH.h rename to LaunchAPPL/Client/SSH.h diff --git a/LaunchAPPL/Utilities.cc b/LaunchAPPL/Client/Utilities.cc similarity index 100% rename from LaunchAPPL/Utilities.cc rename to LaunchAPPL/Client/Utilities.cc diff --git a/LaunchAPPL/Utilities.h b/LaunchAPPL/Client/Utilities.h similarity index 100% rename from LaunchAPPL/Utilities.h rename to LaunchAPPL/Client/Utilities.h diff --git a/LaunchAPPL/Server/CMakeLists.txt b/LaunchAPPL/Server/CMakeLists.txt new file mode 100644 index 0000000000..72bf987be8 --- /dev/null +++ b/LaunchAPPL/Server/CMakeLists.txt @@ -0,0 +1 @@ +add_application(LaunchAPPLServer CONSOLE main.cc) diff --git a/LaunchAPPL/Server/Stream.h b/LaunchAPPL/Server/Stream.h new file mode 100644 index 0000000000..e4e4469316 --- /dev/null +++ b/LaunchAPPL/Server/Stream.h @@ -0,0 +1,38 @@ +#include +#include + +class Block +{ + uint8_t *begin_ = nullptr; + uint8_t *end_ = nullptr; +public: + Block() = default; + Block(uint8_t *p, size_t len) : begin_(p), end_(p+len) {} + Block(uint8_t *b, uint8_t *e) : begin_(b), end_(e) {} + + uint8_t * begin() { return begin_; } + const uint8_t * begin() const { return begin_; } + uint8_t * end() { return end_; } + const uint8_t * end() const { return end_; } + + size_t size() const { return end_ - begin_; } +}; + +class StreamListener +{ +public: + virtual void onReceive(const Block& b) = 0; +}; + +class Stream +{ + StreamListener *listener_; +public: + void setListener(StreamListener *l) { listener_ = l; } + + virtual void send(const Block& b) = 0; + +protected: + void onReceive(const Block& b) + { if(listener_) listener_->onReceive(b); } +}; diff --git a/LaunchAPPL/Server/main.cc b/LaunchAPPL/Server/main.cc new file mode 100644 index 0000000000..98de49d26a --- /dev/null +++ b/LaunchAPPL/Server/main.cc @@ -0,0 +1,113 @@ + +#include +#include +#include +#include +#include + +#include "Stream.h" + +class MacSerialStream : public Stream +{ + static const long kInputBufferSize = 4096; + static const long kReadBufferSize = 4096; + char inputBuffer[kInputBufferSize]; + char readBuffer[kReadBufferSize]; + + short outRefNum, inRefNum; +public: + virtual void send(const Block& b) override; + + void idle(); + + MacSerialStream(); + ~MacSerialStream(); +}; + +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); +} + +MacSerialStream::~MacSerialStream() +{ + SerSetBuf(inRefNum, NULL, 0); + + CloseDriver(inRefNum); + CloseDriver(outRefNum); +} + +void MacSerialStream::send(const Block& b) +{ + ParamBlockRec pb; + memset(&pb, 0, sizeof(pb)); + pb.ioParam.ioRefNum = outRefNum; + pb.ioParam.ioBuffer = (Ptr)b.begin(); + pb.ioParam.ioReqCount = b.size(); + OSErr err = PBWriteSync(&pb); + +} + +void MacSerialStream::idle() +{ + long count = 0; + SerGetBuf(inRefNum, &count); + + while(count > 0) + { + long count1 = count > kReadBufferSize ? kReadBufferSize : count; + ParamBlockRec pb; + memset(&pb, 0, sizeof(pb)); + pb.ioParam.ioRefNum = inRefNum; + pb.ioParam.ioBuffer = (Ptr)&readBuffer; + pb.ioParam.ioReqCount = count1; + OSErr err = PBReadSync(&pb); + if(err) + return; + count -= count1; + + onReceive(Block((uint8_t*)readBuffer, count1)); + } +} + + +class DumpToConsole : public StreamListener +{ +public: + void onReceive(const Block& b) + { + for(uint8_t c : b) + putchar(c); + } +}; + +int main() +{ + OSErr err; + short outRefNum, inRefNum; + + printf("Hello.\n"); + + { + MacSerialStream stream; + DumpToConsole listener; + stream.setListener(&listener); + + while(!Button()) + stream.idle(); + } + + return 0; +} +