[nostalgia/core] Add PassthroughFS support to loadRomFs
This commit is contained in:
parent
fffc66f18b
commit
90f94dbfc2
@ -12,10 +12,7 @@
|
|||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Error init(Context *ctx) {
|
ox::Error init(Context *ctx) {
|
||||||
auto err = OxError(0);
|
return initGfx(ctx);
|
||||||
err = initGfx(ctx);
|
|
||||||
initHeap(); // this does nothing in userland builds
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,26 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ox/fs/fs.hpp>
|
|
||||||
|
|
||||||
#include "media.hpp"
|
#include "media.hpp"
|
||||||
#include "ox/std/bit.hpp"
|
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::FileSystem *loadRomFs(const char *path) {
|
ox::FileSystem *loadRomFs(const char *path) {
|
||||||
auto rom = loadRom(path);
|
const auto lastDot = ox_lastIndexOf(path, '.');
|
||||||
return new ox::FileSystem32(rom, 32 * ox::units::MB, [](uint8_t *buff) {
|
const auto fsExt = lastDot != -1 ? path + lastDot : "";
|
||||||
unloadRom(ox::bit_cast<char*>(buff));
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ox/std/types.hpp>
|
#include <ox/fs/fs.hpp>
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
ox::FileSystem *loadRomFs(const char *path);
|
||||||
|
|
||||||
char *loadRom(const char *path = "");
|
char *loadRom(const char *path = "");
|
||||||
|
|
||||||
void unloadRom(char*);
|
void unloadRom(char*);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <ox/fs/fs.hpp>
|
#include <ox/fs/fs.hpp>
|
||||||
#include <ox/std/units.hpp>
|
#include <ox/std/units.hpp>
|
||||||
|
#include <nostalgia/core/core.hpp>
|
||||||
#include <nostalgia/world/world.hpp>
|
#include <nostalgia/world/world.hpp>
|
||||||
|
|
||||||
using namespace nostalgia;
|
using namespace nostalgia;
|
||||||
@ -28,29 +29,12 @@ ox::Error run(ox::FileSystem *fs) {
|
|||||||
|
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char **argv) {
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
ox::FileSystem *fs = nullptr;
|
|
||||||
char *rom = nullptr;
|
|
||||||
auto path = argv[1];
|
auto path = argv[1];
|
||||||
const auto lastDot = ox_lastIndexOf(path, '.');
|
auto fs = core::loadRomFs(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 err = run(fs);
|
auto err = run(fs);
|
||||||
oxAssert(err, "Something went wrong...");
|
oxAssert(err, "Something went wrong...");
|
||||||
fs->~FileSystem();
|
delete fs;
|
||||||
core::unloadRom(rom);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
return 3;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user