Leverage new bswap functions to the fullest

This commit is contained in:
SimoneN64
2024-09-25 22:18:57 +02:00
parent 2744de8d3e
commit 521cd7c2e0
4 changed files with 24 additions and 46 deletions

View File

@@ -10,10 +10,10 @@ namespace Util {
template <bool toBE = false>
FORCE_INLINE void SwapN64Rom(std::vector<u8> &rom, u32 endianness) {
u8 altByteShift = 0;
if ((endianness >> 24) != 0x80) {
if (endianness >> 24 != 0x80) {
if ((endianness & 0xFF) != 0x80) {
if (((endianness >> 16) & 0xff) != 0x80) {
Util::panic("TODO: Unrecognized rom endianness. Ideally, this should be more robust");
if ((endianness >> 16 & 0xff) != 0x80) {
panic("TODO: Unrecognized rom endianness. Ideally, this should be more robust");
} else {
altByteShift = 12;
}
@@ -28,17 +28,17 @@ FORCE_INLINE void SwapN64Rom(std::vector<u8> &rom, u32 endianness) {
switch (endianness) {
case V64:
SwapBuffer16(rom);
SwapBuffer<u16>(rom);
if constexpr (!toBE)
SwapBuffer32(rom);
SwapBuffer<u32>(rom);
break;
case N64:
if constexpr (toBE)
SwapBuffer32(rom);
SwapBuffer<u32>(rom);
break;
case Z64:
if constexpr (!toBE)
SwapBuffer32(rom);
SwapBuffer<u32>(rom);
break;
default:
panic("Unrecognized rom format! Make sure this is a valid Nintendo 64 ROM dump!");

View File

@@ -109,21 +109,21 @@ struct Mem {
std::vector<u8> temp{};
temp.resize(RDRAM_SIZE);
std::copy(mmio.rdp.rdram.begin(), mmio.rdp.rdram.end(), temp.begin());
Util::SwapBuffer32(temp);
Util::SwapBuffer<u32>(temp);
Util::WriteFileBinary(temp, "rdram.bin");
}
FORCE_INLINE void DumpIMEM() const {
std::array<u8, IMEM_SIZE> temp{};
std::copy(mmio.rsp.imem.begin(), mmio.rsp.imem.end(), temp.begin());
Util::SwapBuffer32(temp);
Util::SwapBuffer<u32>(temp);
Util::WriteFileBinary(temp, "imem.bin");
}
FORCE_INLINE void DumpDMEM() const {
std::array<u8, DMEM_SIZE> temp{};
std::copy(mmio.rsp.dmem.begin(), mmio.rsp.dmem.end(), temp.begin());
Util::SwapBuffer32(temp);
Util::SwapBuffer<u32>(temp);
Util::WriteFileBinary(temp, "dmem.bin");
}
ROM rom;