This commit is contained in:
2026-03-23 12:11:07 +01:00
commit e64eb40b38
4573 changed files with 3117439 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include <MemoryHelpers.hpp>
#include <log.hpp>
namespace Util {
#define Z64 0x80371200
#define N64 0x00123780
#define V64 0x37800012
template <bool toBE = false>
FORCE_INLINE void SwapN64Rom(std::vector<u8> &rom, u32 endianness) {
u8 altByteShift = 0;
if (endianness >> 24 != 0x80) {
if ((endianness & 0xFF) != 0x80) {
if ((endianness >> 16 & 0xff) != 0x80) {
Error::GetInstance().Throw({Error::Severity::UNRECOVERABLE}, {Error::Type::ROM_LOAD_ERROR}, {}, {}, "Unrecognized rom endianness");
return;
} else {
altByteShift = 12;
}
} else {
altByteShift = 24;
}
} else {
altByteShift = 0;
}
endianness &= ~(0xFF << altByteShift);
switch (endianness) {
case V64:
SwapBuffer<u16>(rom);
if constexpr (!toBE)
SwapBuffer<u32>(rom);
break;
case N64:
if constexpr (toBE)
SwapBuffer<u32>(rom);
break;
case Z64:
if constexpr (!toBE)
SwapBuffer<u32>(rom);
break;
default:
Error::GetInstance().Throw({Error::Severity::UNRECOVERABLE}, {Error::Type::ROM_LOAD_ERROR}, {}, {}, "Unrecognized rom format! Make sure this is a valid Nintendo 64 ROM dump!");
}
}
} // namespace Util