These can be Utility functions
This commit is contained in:
@@ -86,68 +86,15 @@ FORCE_INLINE void SetROMCIC(u32 checksum, ROM &rom) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u8> Mem::OpenArchive(const std::string &path, size_t &sizeAdjusted) {
|
|
||||||
const auto stream = ar_open_file(fs::path(path).string().c_str());
|
|
||||||
|
|
||||||
if (!stream) {
|
|
||||||
panic("Could not open archive! Are you sure it's an archive?");
|
|
||||||
}
|
|
||||||
|
|
||||||
ar_archive *archive = ar_open_zip_archive(stream, false);
|
|
||||||
|
|
||||||
if (!archive)
|
|
||||||
archive = ar_open_rar_archive(stream);
|
|
||||||
if (!archive)
|
|
||||||
archive = ar_open_7z_archive(stream);
|
|
||||||
if (!archive)
|
|
||||||
archive = ar_open_tar_archive(stream);
|
|
||||||
|
|
||||||
if (!archive) {
|
|
||||||
ar_close(stream);
|
|
||||||
panic("Could not open archive! Are you sure it's a supported archive? (7z, zip, rar and tar are supported)");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<u8> buf{};
|
|
||||||
|
|
||||||
std::vector<std::string> rom_exts{".n64", ".z64", ".v64", ".N64", ".Z64", ".V64"};
|
|
||||||
|
|
||||||
while (ar_parse_entry(archive)) {
|
|
||||||
auto filename = ar_entry_get_name(archive);
|
|
||||||
auto extension = fs::path(filename).extension();
|
|
||||||
|
|
||||||
if (std::ranges::any_of(rom_exts, [&](const auto &x) { return extension == x; })) {
|
|
||||||
const auto size = ar_entry_get_size(archive);
|
|
||||||
sizeAdjusted = Util::NextPow2(size);
|
|
||||||
buf.resize(sizeAdjusted);
|
|
||||||
ar_entry_uncompress(archive, buf.data(), size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ar_close_archive(archive);
|
|
||||||
ar_close(stream);
|
|
||||||
panic("Could not find any rom image in the archive!");
|
|
||||||
}
|
|
||||||
|
|
||||||
ar_close_archive(archive);
|
|
||||||
ar_close(stream);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<u8> Mem::OpenROM(const std::string &filename, size_t &sizeAdjusted) {
|
|
||||||
auto buf = Util::ReadFileBinary(filename);
|
|
||||||
sizeAdjusted = Util::NextPow2(buf.size());
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mem::LoadROM(const bool isArchive, const std::string &filename) {
|
void Mem::LoadROM(const bool isArchive, const std::string &filename) {
|
||||||
u32 endianness;
|
u32 endianness;
|
||||||
{
|
{
|
||||||
size_t sizeAdjusted;
|
size_t sizeAdjusted;
|
||||||
std::vector<u8> buf{};
|
std::vector<u8> buf{};
|
||||||
if (isArchive) {
|
if (isArchive) {
|
||||||
buf = OpenArchive(filename, sizeAdjusted);
|
buf = Util::OpenArchive(filename, sizeAdjusted);
|
||||||
} else {
|
} else {
|
||||||
buf = OpenROM(filename, sizeAdjusted);
|
buf = Util::OpenROM(filename, sizeAdjusted);
|
||||||
}
|
}
|
||||||
|
|
||||||
endianness = std::byteswap(Util::ReadAccess<u32>(buf, 0));
|
endianness = std::byteswap(Util::ReadAccess<u32>(buf, 0));
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ struct Mem {
|
|||||||
Mem(JIT * = nullptr);
|
Mem(JIT * = nullptr);
|
||||||
void Reset();
|
void Reset();
|
||||||
void LoadSRAM(SaveType, fs::path);
|
void LoadSRAM(SaveType, fs::path);
|
||||||
static std::vector<u8> OpenROM(const std::string &, size_t &);
|
|
||||||
static std::vector<u8> OpenArchive(const std::string &, size_t &);
|
|
||||||
void LoadROM(bool, const std::string &);
|
void LoadROM(bool, const std::string &);
|
||||||
[[nodiscard]] auto GetRDRAMPtr() -> u8 * { return mmio.rdp.rdram.data(); }
|
[[nodiscard]] auto GetRDRAMPtr() -> u8 * { return mmio.rdp.rdram.data(); }
|
||||||
|
|
||||||
|
|||||||
@@ -37,4 +37,57 @@ FORCE_INLINE size_t NextPow2(size_t num) {
|
|||||||
num |= num >> 16;
|
num |= num >> 16;
|
||||||
return num + 1;
|
return num + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE std::vector<u8> OpenROM(const std::string &, size_t &) {
|
||||||
|
auto buf = Util::ReadFileBinary(filename);
|
||||||
|
sizeAdjusted = Util::NextPow2(buf.size());
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE std::vector<u8> OpenArchive(const std::string &, size_t &) {
|
||||||
|
const auto stream = ar_open_file(fs::path(path).string().c_str());
|
||||||
|
|
||||||
|
if (!stream) {
|
||||||
|
panic("Could not open archive! Are you sure it's an archive?");
|
||||||
|
}
|
||||||
|
|
||||||
|
ar_archive *archive = ar_open_zip_archive(stream, false);
|
||||||
|
|
||||||
|
if (!archive)
|
||||||
|
archive = ar_open_rar_archive(stream);
|
||||||
|
if (!archive)
|
||||||
|
archive = ar_open_7z_archive(stream);
|
||||||
|
if (!archive)
|
||||||
|
archive = ar_open_tar_archive(stream);
|
||||||
|
|
||||||
|
if (!archive) {
|
||||||
|
ar_close(stream);
|
||||||
|
panic("Could not open archive! Are you sure it's a supported archive? (7z, zip, rar and tar are supported)");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<u8> buf{};
|
||||||
|
|
||||||
|
std::vector<std::string> rom_exts{".n64", ".z64", ".v64", ".N64", ".Z64", ".V64"};
|
||||||
|
|
||||||
|
while (ar_parse_entry(archive)) {
|
||||||
|
auto filename = ar_entry_get_name(archive);
|
||||||
|
auto extension = fs::path(filename).extension();
|
||||||
|
|
||||||
|
if (std::ranges::any_of(rom_exts, [&](const auto &x) { return extension == x; })) {
|
||||||
|
const auto size = ar_entry_get_size(archive);
|
||||||
|
sizeAdjusted = Util::NextPow2(size);
|
||||||
|
buf.resize(sizeAdjusted);
|
||||||
|
ar_entry_uncompress(archive, buf.data(), size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ar_close_archive(archive);
|
||||||
|
ar_close(stream);
|
||||||
|
panic("Could not find any rom image in the archive!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ar_close_archive(archive);
|
||||||
|
ar_close(stream);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
} // namespace Util
|
} // namespace Util
|
||||||
|
|||||||
Reference in New Issue
Block a user