From 90f94dbfc2ae391cb92c74622b8c8ca693db7c99 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 11 Feb 2020 21:34:55 -0600 Subject: [PATCH] [nostalgia/core] Add PassthroughFS support to loadRomFs --- src/nostalgia/core/core.cpp | 5 +---- src/nostalgia/core/media.cpp | 22 +++++++++++++++------- src/nostalgia/core/media.hpp | 4 +++- src/nostalgia/player/main.cpp | 24 ++++-------------------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/nostalgia/core/core.cpp b/src/nostalgia/core/core.cpp index 131178ec..f536680a 100644 --- a/src/nostalgia/core/core.cpp +++ b/src/nostalgia/core/core.cpp @@ -12,10 +12,7 @@ namespace nostalgia::core { ox::Error init(Context *ctx) { - auto err = OxError(0); - err = initGfx(ctx); - initHeap(); // this does nothing in userland builds - return err; + return initGfx(ctx); } } diff --git a/src/nostalgia/core/media.cpp b/src/nostalgia/core/media.cpp index 51fd9546..8eff9466 100644 --- a/src/nostalgia/core/media.cpp +++ b/src/nostalgia/core/media.cpp @@ -6,18 +6,26 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include - #include "media.hpp" -#include "ox/std/bit.hpp" namespace nostalgia::core { ox::FileSystem *loadRomFs(const char *path) { - auto rom = loadRom(path); - return new ox::FileSystem32(rom, 32 * ox::units::MB, [](uint8_t *buff) { - unloadRom(ox::bit_cast(buff)); - }); + const auto lastDot = ox_lastIndexOf(path, '.'); + const auto fsExt = lastDot != -1 ? path + lastDot : ""; + if (ox_strcmp(fsExt, ".oxfs") == 0) { + auto rom = core::loadRom(path); + if (!rom) { + return nullptr; + } + return new ox::FileSystem32(rom, 32 * ox::units::MB, unloadRom); + } else { +#ifdef OX_HAS_PASSTHROUGHFS + return new ox::PassThroughFS(path); +#else + return nullptr; +#endif + } } } diff --git a/src/nostalgia/core/media.hpp b/src/nostalgia/core/media.hpp index 06bac96d..6d6ccb9c 100644 --- a/src/nostalgia/core/media.hpp +++ b/src/nostalgia/core/media.hpp @@ -8,10 +8,12 @@ #pragma once -#include +#include namespace nostalgia::core { +ox::FileSystem *loadRomFs(const char *path); + char *loadRom(const char *path = ""); void unloadRom(char*); diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index d5ff48ed..cb29cdea 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -8,6 +8,7 @@ #include #include +#include #include using namespace nostalgia; @@ -28,29 +29,12 @@ ox::Error run(ox::FileSystem *fs) { int main(int argc, const char **argv) { if (argc > 1) { - ox::FileSystem *fs = nullptr; - char *rom = nullptr; auto path = argv[1]; - const auto lastDot = ox_lastIndexOf(path, '.'); - const auto fsExt = lastDot != -1 ? path + lastDot : ""; - if (ox_strcmp(fsExt, ".oxfs") == 0) { - rom = core::loadRom(path); - if (!rom) { - return 1; - } - fs = new (ox_alloca(sizeof(ox::FileStore32))) ox::FileSystem32(ox::FileStore32(rom, 32 * ox::units::MB)); - } else { -#ifdef OX_HAS_PASSTHROUGHFS - fs = new (ox_alloca(sizeof(ox::PassThroughFS))) ox::PassThroughFS(path); -#else - return 2; -#endif - } + auto fs = core::loadRomFs(path); auto err = run(fs); oxAssert(err, "Something went wrong..."); - fs->~FileSystem(); - core::unloadRom(rom); + delete fs; return err; } - return 3; + return 1; }