From f63fe6c9950c83ec39140efc4e0c154d346bfcf4 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 16 May 2023 21:20:07 -0500 Subject: [PATCH] [nostalgia/core] Cleanup --- src/nostalgia/core/CMakeLists.txt | 50 ++++-------------------- src/nostalgia/core/context.hpp | 2 - src/nostalgia/core/gba/CMakeLists.txt | 16 ++++++++ src/nostalgia/core/gba/context.hpp | 29 ++++++++++++++ src/nostalgia/core/gba/core.arm.cpp | 4 +- src/nostalgia/core/gba/core.cpp | 6 ++- src/nostalgia/core/glfw/CMakeLists.txt | 11 ++++++ src/nostalgia/core/opengl/CMakeLists.txt | 11 ++++++ 8 files changed, 81 insertions(+), 48 deletions(-) create mode 100644 src/nostalgia/core/gba/CMakeLists.txt create mode 100644 src/nostalgia/core/gba/context.hpp create mode 100644 src/nostalgia/core/glfw/CMakeLists.txt create mode 100644 src/nostalgia/core/opengl/CMakeLists.txt diff --git a/src/nostalgia/core/CMakeLists.txt b/src/nostalgia/core/CMakeLists.txt index d6e3ef29..f6d7a3dd 100644 --- a/src/nostalgia/core/CMakeLists.txt +++ b/src/nostalgia/core/CMakeLists.txt @@ -1,5 +1,5 @@ add_library( - NostalgiaCore-Common OBJECT + NostalgiaCore gfx.cpp module.cpp tilesheet.cpp @@ -7,56 +7,20 @@ add_library( typestore.cpp ) -add_library(NostalgiaCore) - -if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA") - target_sources( - NostalgiaCore PRIVATE - glfw/clipboard.cpp - glfw/core.cpp - glfw/gfx.cpp - opengl/gfx.cpp - opengl/gfx_opengl.cpp - ) - target_link_libraries( - NostalgiaCore PUBLIC - glad - glfw - imgui - OxEvent - NostalgiaGlUtils - ) +if(NOSTALGIA_BUILD_TYPE STREQUAL "GBA") + add_subdirectory(gba) else() - enable_language(CXX ASM) - set_source_files_properties(core.arm.cpp irq.arm.cpp PROPERTIES COMPILE_FLAGS -marm) - target_sources( - NostalgiaCore PRIVATE - gba/bios.s - gba/core.arm.cpp - gba/core.cpp - gba/gfx.cpp - gba/irq.arm.cpp - gba/irq.s - gba/panic.cpp - ) - target_link_libraries( - NostalgiaCore PUBLIC - GbaStartup - ) + add_subdirectory(glfw) + add_subdirectory(opengl) endif() if(NOT MSVC) - target_compile_options(NostalgiaCore-Common PUBLIC -Wsign-conversion) + target_compile_options(NostalgiaCore PUBLIC -Wsign-conversion) endif() -target_link_libraries( - NostalgiaCore-Common PUBLIC - Keel -) - target_link_libraries( NostalgiaCore PUBLIC - NostalgiaCore-Common + Keel ) if(NOSTALGIA_BUILD_STUDIO) diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 8ca59e81..09831523 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -116,8 +116,6 @@ class Context: public keel::Context { #ifndef OX_BARE_METAL int uninterruptedRefreshes = 3; ox::UPtr clipboard; -#else - bool running = true; #endif protected: #ifndef OX_BARE_METAL diff --git a/src/nostalgia/core/gba/CMakeLists.txt b/src/nostalgia/core/gba/CMakeLists.txt new file mode 100644 index 00000000..87f5a58a --- /dev/null +++ b/src/nostalgia/core/gba/CMakeLists.txt @@ -0,0 +1,16 @@ +enable_language(CXX ASM) +set_source_files_properties(core.arm.cpp irq.arm.cpp PROPERTIES COMPILE_FLAGS -marm) +target_sources( + NostalgiaCore PRIVATE + bios.s + core.arm.cpp + core.cpp + gfx.cpp + irq.arm.cpp + irq.s + panic.cpp +) +target_link_libraries( + NostalgiaCore PUBLIC + GbaStartup +) diff --git a/src/nostalgia/core/gba/context.hpp b/src/nostalgia/core/gba/context.hpp new file mode 100644 index 00000000..aa74fa38 --- /dev/null +++ b/src/nostalgia/core/gba/context.hpp @@ -0,0 +1,29 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include +#include +#include + +#include +#include + +#include + +namespace nostalgia::core::gba { + +class Context: public core::Context { + public: + bool running = true; + + Context() noexcept = default; + Context(Context &other) noexcept = delete; + Context(const Context &other) noexcept = delete; + Context(const Context &&other) noexcept = delete; +}; + +} + diff --git a/src/nostalgia/core/gba/core.arm.cpp b/src/nostalgia/core/gba/core.arm.cpp index f644e937..4e8d3720 100644 --- a/src/nostalgia/core/gba/core.arm.cpp +++ b/src/nostalgia/core/gba/core.arm.cpp @@ -6,6 +6,7 @@ #include #include "addresses.hpp" +#include "context.hpp" #include "bios.hpp" #include "irq.hpp" #include "core.hpp" @@ -18,7 +19,8 @@ UpdateHandler g_updateHandler = nullptr; ox::Error run(Context *ctx) noexcept { g_wakeupTime = 0; - while (ctx->running) { + const auto gbaCtx = static_cast(ctx); + while (gbaCtx->running) { if (g_wakeupTime <= g_timerMs && g_updateHandler) { auto sleepTime = g_updateHandler(ctx); if (sleepTime >= 0) { diff --git a/src/nostalgia/core/gba/core.cpp b/src/nostalgia/core/gba/core.cpp index cb429a23..b3daf23a 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -9,6 +9,7 @@ #include "addresses.hpp" #include "bios.hpp" #include "irq.hpp" +#include "context.hpp" #include "core.hpp" extern "C" void isr(); @@ -55,7 +56,7 @@ static ox::Result findPreloadSection() noexcept { } ox::Result> init(ox::UniquePtr fs, ox::CRStringView appName) noexcept { - auto ctx = ox::make_unique(); + ox::UPtr ctx(ox::make()); ctx->rom = std::move(fs); ctx->appName = appName; oxReturnError(initGfx(ctx.get())); @@ -78,7 +79,8 @@ bool buttonDown(Context*, Key k) noexcept { } void shutdown(Context *ctx) noexcept { - ctx->running = false; + const auto gbaCtx = static_cast(ctx); + gbaCtx->running = false; } } diff --git a/src/nostalgia/core/glfw/CMakeLists.txt b/src/nostalgia/core/glfw/CMakeLists.txt new file mode 100644 index 00000000..60e5a47b --- /dev/null +++ b/src/nostalgia/core/glfw/CMakeLists.txt @@ -0,0 +1,11 @@ +target_sources( + NostalgiaCore PRIVATE + clipboard.cpp + core.cpp + gfx.cpp +) +target_link_libraries( + NostalgiaCore PUBLIC + glfw + imgui +) diff --git a/src/nostalgia/core/opengl/CMakeLists.txt b/src/nostalgia/core/opengl/CMakeLists.txt new file mode 100644 index 00000000..adbcaacf --- /dev/null +++ b/src/nostalgia/core/opengl/CMakeLists.txt @@ -0,0 +1,11 @@ +target_sources( + NostalgiaCore PRIVATE + gfx.cpp + gfx_opengl.cpp +) +target_link_libraries( + NostalgiaCore PUBLIC + glad + imgui + NostalgiaGlUtils +)