From 04739004f5c6dcc40f42902fbb53346e98de9240 Mon Sep 17 00:00:00 2001 From: Jaby Date: Fri, 16 Dec 2022 03:47:30 +0100 Subject: [PATCH] Use main --- include/PSX/jabyengine.h | 21 ++++++++++++++---- .../include/BootLoader/boot_loader.hpp | 4 ++++ .../src/BootLoader/boot_file/main_boot.cpp | 11 ++++++++++ src/Library/src/BootLoader/start_boot.cpp | 2 +- src/Library/src/startup.cpp | 22 +++++++++++++++++-- 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/Library/src/BootLoader/boot_file/main_boot.cpp diff --git a/include/PSX/jabyengine.h b/include/PSX/jabyengine.h index 0d17bfe2..a8509581 100644 --- a/include/PSX/jabyengine.h +++ b/include/PSX/jabyengine.h @@ -4,20 +4,33 @@ namespace JabyEngine { struct NextRoutine { - typedef NextRoutine (*ExecutionFunction)(); + static constexpr uintptr_t OverlayBit = (1 << ((sizeof(uintptr_t)*8) - 2)); + typedef NextRoutine (*MainRoutine)(); uintptr_t value; - static NextRoutine null() { + constexpr static NextRoutine null() { return {.value = 0}; } - static NextRoutine from(ExecutionFunction function) { + static NextRoutine from(MainRoutine function) { return {.value = reinterpret_cast(function)}; } + + constexpr bool is_overlay() const { + return (this->value & OverlayBit); + } + + constexpr bool is_absolute() const { + return !NextRoutine::is_overlay(); + } + + constexpr bool is_null() const { + return this->value == 0; + } }; - typedef NextRoutine::ExecutionFunction ExecutionFunction; + typedef NextRoutine::MainRoutine MainRoutine; } #endif //!__JABYENGINE__H__ \ No newline at end of file diff --git a/src/Library/include/BootLoader/boot_loader.hpp b/src/Library/include/BootLoader/boot_loader.hpp index 14becdf8..560e48e0 100644 --- a/src/Library/include/BootLoader/boot_loader.hpp +++ b/src/Library/include/BootLoader/boot_loader.hpp @@ -16,4 +16,8 @@ namespace Setup { JabyEngine::NextRoutine start(); } +namespace BootFile { + JabyEngine::NextRoutine setup(); +} + #endif //!BOOT_LOADER_HPP \ No newline at end of file diff --git a/src/Library/src/BootLoader/boot_file/main_boot.cpp b/src/Library/src/BootLoader/boot_file/main_boot.cpp new file mode 100644 index 00000000..9d87d864 --- /dev/null +++ b/src/Library/src/BootLoader/boot_file/main_boot.cpp @@ -0,0 +1,11 @@ +#include "../../../include/BootLoader/boot_loader.hpp" +#include + +extern JabyEngine::NextRoutine main(); + +namespace BootFile { + JabyEngine::NextRoutine setup() { + printf("Running main!\n"); + return JabyEngine::NextRoutine::from(main); + } +} \ No newline at end of file diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index 3b804362..33cc98d3 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -17,6 +17,6 @@ namespace Setup { //Pause?? SPU::setup(); - return JabyEngine::NextRoutine::null(); + return BootFile::setup(); } } \ No newline at end of file diff --git a/src/Library/src/startup.cpp b/src/Library/src/startup.cpp index 117883f6..cfd0d651 100644 --- a/src/Library/src/startup.cpp +++ b/src/Library/src/startup.cpp @@ -2,9 +2,27 @@ #include namespace JabyEngine { + static NextRoutine execute(NextRoutine routine) { + // Support currently only direct call + return reinterpret_cast((routine.value & ~JabyEngine::NextRoutine::OverlayBit))(); + } + void start() { - printf("Starting Planschbecken\n"); - Setup::start(); + NextRoutine next_routine = JabyEngine::NextRoutine::from(Setup::start); + + printf("Starting Planschbecken 0x%p\n", next_routine.value); + while(true) { + if(next_routine.is_null()) { + break; + } + + if(next_routine.is_overlay()) { + printf("Overlay not supported yet!\n"); + break; + } + + next_routine = execute(next_routine); + } printf("Stop!\n"); } } \ No newline at end of file