From bda4e643af0ded56fb5aa7f3832bdbf92e064e4c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 12 Jan 2020 20:46:12 -0600 Subject: [PATCH] [nostalgia/player] Cleanup main --- src/nostalgia/player/main.cpp | 59 +++++++++-------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index 6fad7364..0fd47287 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -28,59 +28,28 @@ ox::Error run(ox::FileSystem *fs) { return OxError(0); } -#ifndef OX_USE_STDLIB - -int main() { - auto rom = loadRom(); - if (!rom) { - return 1; - } - ox::FileSystem32 fs(ox::FileStore32(rom, 32 * ox::units::MB)); - run(&fs); - return 0; -} - -#else - -#include -#include - -std::vector loadFileBuff(const char *path) { - auto file = fopen(path, "r"); - if (file) { - fseek(file, 0, SEEK_END); - const auto size = ftell(file); - rewind(file); - std::vector buff(size); - fread(buff.data(), size, 1, file); - fclose(file); - return buff; - } else { - return {}; - } -} - int main(int argc, const char **argv) { if (argc > 1) { - std::unique_ptr fs; - std::vector rom; - const std::string path = argv[1]; - const auto lastDot = path.find_last_of('.'); - const std::string fsExt = lastDot != std::string::npos ? path.substr(lastDot) : ""; - if (fsExt == ".oxfs") { - rom = loadFileBuff(path.c_str()); - if (!rom.size()) { + ox::FileSystem *fs = nullptr; + uint8_t *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 = loadRom(path); + if (!rom) { return 1; } - fs = std::make_unique(ox::FileStore32(rom.data(), 32 * ox::units::MB)); + fs = new (ox_alloca(sizeof(ox::FileStore32))) ox::FileSystem32(ox::FileStore32(rom, 32 * ox::units::MB)); +#ifdef OX_HAS_PASSTHROUGHFS } else { - fs = std::make_unique(path.c_str()); + fs = new (ox_alloca(sizeof(ox::PassThroughFS))) ox::PassThroughFS(path); +#endif } - auto err = run(fs.get()); + auto err = run(fs); oxAssert(err, "Something went wrong..."); + unloadRom(rom); return err; } return 2; } - -#endif