From cdc540938a031724ebe5f0cab2fa34346229121b Mon Sep 17 00:00:00 2001 From: James Benton Date: Fri, 25 May 2018 11:48:37 +0100 Subject: [PATCH] Improve the helloworld sample. --- samples/helloworld/CMakeLists.txt | 2 + samples/helloworld/main.cpp | 98 +++++++------------------------ 2 files changed, 24 insertions(+), 76 deletions(-) diff --git a/samples/helloworld/CMakeLists.txt b/samples/helloworld/CMakeLists.txt index 85459a5..4e22896 100644 --- a/samples/helloworld/CMakeLists.txt +++ b/samples/helloworld/CMakeLists.txt @@ -4,6 +4,8 @@ include("${WUT_ROOT}/share/wut.cmake" REQUIRED) add_executable(helloworld main.cpp) target_link_libraries(helloworld + whb + defaultheap coreinit proc_ui sysapp) diff --git a/samples/helloworld/main.cpp b/samples/helloworld/main.cpp index 47cbc96..5795944 100644 --- a/samples/helloworld/main.cpp +++ b/samples/helloworld/main.cpp @@ -1,89 +1,35 @@ -#include -#include #include -#include -#include -#include -#include +#include +#include -bool isAppRunning = true; -std::string testStr = "Initial Value"; - -static void -SaveCallback() -{ - OSSavesDone_ReadyToRelease(); // Required -} - -static bool -AppRunning() -{ - if (!OSIsMainCore()) { - ProcUISubProcessMessages(true); - } else { - ProcUIStatus status = ProcUIProcessMessages(true); - - if (status == PROCUI_STATUS_EXITING) { - // Being closed, deinit, free, and prepare to exit - testStr = "PROCUI_STATUS_EXITING"; - isAppRunning = false; - ProcUIShutdown(); - } else if (status == PROCUI_STATUS_RELEASE_FOREGROUND) { - // Free up MEM1 to next foreground app, deinit screen, etc. - testStr = "PROCUI_STATUS_RELEASE_FOREGROUND"; - ProcUIDrawDoneRelease(); - } else if(status == PROCUI_STATUS_IN_FOREGROUND) { - // Executed while app is in foreground - testStr = "PROCUI_STATUS_IN_FOREGROUND"; - } - } - - return isAppRunning; -} - -static int -CoreEntryPoint(int argc, const char **argv) -{ - OSReport("Hello world from %s %s", argv[0], testStr.c_str()); - return argc; -} +#include +#include +#include int main(int argc, char **argv) { - ProcUIInit(&SaveCallback); - OSReport("Main thread running on core %d", OSGetCoreId()); + OSCalendarTime tm; - // Run thread on core 0 - OSThread *threadCore0 = OSGetDefaultThread(0); + WHBProcInit(); + WHBLogConsoleInit(); + WHBLogPrintf("Hello World!"); - const char *core0Args[] = { - "Core 0" - }; + while(WHBProcIsRunning()) { + OSTicksToCalendarTime(OSGetTime(), &tm); + WHBLogPrintf("%02d/%02d/%04d %02d:%02d:%02d I'm still here.", + tm.tm_mday, tm.tm_mon, tm.tm_year, + tm.tm_hour, tm.tm_min, tm.tm_sec); - OSRunThread(threadCore0, CoreEntryPoint, 0, core0Args); + WHBLogConsoleDraw(); + OSSleepTicks(OSMilliseconds(1000)); + } - // Run thread on core 2 - OSThread *threadCore2 = OSGetDefaultThread(2); + WHBLogPrintf("Exiting... good bye."); + WHBLogConsoleDraw(); + OSSleepTicks(OSMilliseconds(1000)); - const char *core2Args[] = { - "Core 2" - }; - - OSRunThread(threadCore2, CoreEntryPoint, 2, core2Args); - - // Wait for threads to return - int resultCore0 = -1, resultCore2 = -1; - OSJoinThread(threadCore0, &resultCore0); - OSJoinThread(threadCore2, &resultCore2); - - OSReport("Core 0 thread returned %d", resultCore0); - OSReport("Core 2 thread returned %d", resultCore2); - - // Sends messages for ProcUI to release foreground, exit - // and launch into the system menu immediately. - SYSLaunchMenu(); - - while(AppRunning()); + WHBLogConsoleFree(); + WHBProcShutdown(); return 0; }