From 360c364bf94b1553ff44b851a98e6a1790a17c2d Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Wed, 9 Jan 2019 00:31:32 +0100 Subject: [PATCH] LaunchAPPLServer: optional embedded debug console --- LaunchAPPL/Server/CMakeLists.txt | 10 ++++++ LaunchAPPL/Server/LaunchAPPLServer.cc | 15 ++++++--- LaunchAPPL/Server/LaunchAPPLServer.r | 2 +- LaunchAPPL/Server/StatusDisplay.cc | 44 +++++++++++++++++++++++++++ LaunchAPPL/Server/StatusDisplay.h | 8 +++++ 5 files changed, 74 insertions(+), 5 deletions(-) diff --git a/LaunchAPPL/Server/CMakeLists.txt b/LaunchAPPL/Server/CMakeLists.txt index 991f157406..37f313f425 100644 --- a/LaunchAPPL/Server/CMakeLists.txt +++ b/LaunchAPPL/Server/CMakeLists.txt @@ -25,10 +25,17 @@ else() ) endif() +option(LAUNCHAPPLSERVER_DEBUG_CONSOLE "Add a debug console to LaunchAPPLServer" FALSE) + +set(MAYBE_CONSOLE) +if(LAUNCHAPPLSERVER_DEBUG_CONSOLE) + set(MAYBE_CONSOLE "CONSOLE") +endif() add_application(LaunchAPPLServer TYPE "APPL" CREATOR "R68L" + ${MAYBE_CONSOLE} LaunchAPPLServer.r LauncherIcon.r @@ -46,6 +53,9 @@ add_application(LaunchAPPLServer ${CONNECTION_SOURCES} ) +if(LAUNCHAPPLSERVER_DEBUG_CONSOLE) + target_compile_definitions(LaunchAPPLServer PRIVATE DEBUG_CONSOLE) +endif() target_link_libraries(LaunchAPPLServer LaunchAPPLCommon) set_target_properties(LaunchAPPLServer PROPERTIES diff --git a/LaunchAPPL/Server/LaunchAPPLServer.cc b/LaunchAPPL/Server/LaunchAPPLServer.cc index d2edca2397..50610dc438 100644 --- a/LaunchAPPL/Server/LaunchAPPLServer.cc +++ b/LaunchAPPL/Server/LaunchAPPLServer.cc @@ -300,6 +300,9 @@ public: size_t onReceive(const uint8_t* p, size_t n) { +#ifdef DEBUG_CONSOLE + printf("Received %d bytes in state %d.\n", (int)n, (int)state); +#endif switch(state) { case State::command: @@ -309,6 +312,7 @@ public: command = (RemoteCommand)p[0]; if(command == RemoteCommand::launchApp || command == RemoteCommand::upgradeLauncher) state = State::header; + return 1; } @@ -333,8 +337,8 @@ public: if(dataSize) { - state = State::data; - remainingSize = dataSize; + state = State::data; + remainingSize = dataSize; } else if(rsrcSize) { @@ -365,8 +369,8 @@ public: OpenRF("\pRetro68App", 0, &refNum); if(rsrcSize) { - state = State::rsrc; - remainingSize = rsrcSize; + state = State::rsrc; + remainingSize = rsrcSize; } else state = State::launch; @@ -458,6 +462,9 @@ public: } else { +#ifdef DEBUG_CONSOLE + printf("Failed to Launch.\n"); +#endif connection->resume(); onReset(); } diff --git a/LaunchAPPL/Server/LaunchAPPLServer.r b/LaunchAPPL/Server/LaunchAPPLServer.r index 071e603c10..7e568394a6 100644 --- a/LaunchAPPL/Server/LaunchAPPLServer.r +++ b/LaunchAPPL/Server/LaunchAPPLServer.r @@ -103,7 +103,7 @@ resource 'WIND' (128, "About") { resource 'WIND' (129, "Main") { {50, 10, 200, 400}, noGrowDocProc; - visible; + invisible; noGoAway; 0, "Retro68 Application Launching Server"; centerMainScreen; diff --git a/LaunchAPPL/Server/StatusDisplay.cc b/LaunchAPPL/Server/StatusDisplay.cc index f405df8a0d..4ef63a3580 100644 --- a/LaunchAPPL/Server/StatusDisplay.cc +++ b/LaunchAPPL/Server/StatusDisplay.cc @@ -72,6 +72,22 @@ StatusDisplay::StatusDisplay() tableTop + (i/2+1) * tableLineHeight); } +#ifdef DEBUG_CONSOLE + short consoleTop = tableTop + (nValues+1)/2 * tableLineHeight + 10; + SetRect(&consoleRect, 10, consoleTop, + bounds.right - 10, consoleTop + 150); +#if TARGET_API_MAC_CARBON + console = retro::Console(GetWindowPort(statusWindow), consoleRect); +#else + console = retro::Console(statusWindow, consoleRect); +#endif + retro::Console::currentInstance = &console; + + bounds.bottom = consoleRect.bottom + 10; +#else + bounds.bottom = tableTop + (nValues+1)/2 * tableLineHeight + 10; +#endif + RgnHandle tmp = NewRgn(); background = NewRgn(); RectRgn(background, &bounds); @@ -82,6 +98,11 @@ StatusDisplay::StatusDisplay() RectRgn(tmp, &valueRects[i]); DiffRgn(background, tmp, background); } +#ifdef DEBUG_CONSOLE + RectRgn(tmp, &consoleRect); + DiffRgn(background, tmp, background); +#endif + DisposeRgn(tmp); if(hasColorQD) @@ -89,6 +110,9 @@ StatusDisplay::StatusDisplay() progressBg = GetPixPat(128); progressFg = GetPixPat(129); } + + SizeWindow(statusWindow, bounds.right, bounds.bottom, false); + ShowWindow(statusWindow); } StatusDisplay::~StatusDisplay() @@ -199,6 +223,21 @@ void StatusDisplay::Update() DrawValue(Stat::timeRemaining, timeRemaining); DrawValue(Stat::transmissionErrors, errorCount); +#ifdef DEBUG_CONSOLE + Rect updateRect; +#if TARGET_API_MAC_CARBON + RgnHandle rgn = NewRgn(); + GetPortVisibleRegion(GetWindowPort(statusWindow), rgn); + GetRegionBounds(rgn, &updateRect); + DisposeRgn(rgn); +#else + updateRect = (*qd.thePort->visRgn)->rgnBBox; // Life was simple back then. +#endif + + console.Draw(updateRect); + FrameRect(&consoleRect); +#endif + EndUpdate(statusWindow); } @@ -244,6 +283,11 @@ void StatusDisplay::SetStatus(AppStatus stat) startTime = TickCount(); GetIndString(statusString,128,(short)stat); Inval(statusRect); + +#ifdef DEBUG_CONSOLE + statusString[statusString[0]+1] = 0; + printf("%s\n", (const char*)statusString+1); +#endif } } diff --git a/LaunchAPPL/Server/StatusDisplay.h b/LaunchAPPL/Server/StatusDisplay.h index 7238b7727c..d8357ee4e9 100644 --- a/LaunchAPPL/Server/StatusDisplay.h +++ b/LaunchAPPL/Server/StatusDisplay.h @@ -3,6 +3,9 @@ #include #include "Window.h" +#ifdef DEBUG_CONSOLE +#include +#endif enum class AppStatus { @@ -39,6 +42,11 @@ class StatusDisplay : public Window PixPatHandle progressBg, progressFg; +#ifdef DEBUG_CONSOLE + Rect consoleRect; + retro::Console console; +#endif + enum class Stat : short; void DrawValue(Stat stat, ConstStr255Param str);