[nostalgia/core] Add PassthroughFS support to loadRomFs

This commit is contained in:
Gary Talent 2020-02-11 21:34:55 -06:00
parent fffc66f18b
commit 90f94dbfc2
4 changed files with 23 additions and 32 deletions

View File

@ -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);
}
}

View File

@ -6,18 +6,26 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ox/fs/fs.hpp>
#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<char*>(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
}
}
}

View File

@ -8,10 +8,12 @@
#pragma once
#include <ox/std/types.hpp>
#include <ox/fs/fs.hpp>
namespace nostalgia::core {
ox::FileSystem *loadRomFs(const char *path);
char *loadRom(const char *path = "");
void unloadRom(char*);

View File

@ -8,6 +8,7 @@
#include <ox/fs/fs.hpp>
#include <ox/std/units.hpp>
#include <nostalgia/core/core.hpp>
#include <nostalgia/world/world.hpp>
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;
}