Roms list properly handle sorting + use ircolib's log so i can stop worrying about re-definition of macros and shit

This commit is contained in:
2026-06-15 17:06:15 +02:00
parent 642fc17391
commit cf0378719c
53 changed files with 3131 additions and 3079 deletions
+8 -8
View File
@@ -1,35 +1,35 @@
#pragma once
#include <types.hpp>
#include <ircolib/types.hpp>
#include <fstream>
#include <vector>
#include <filesystem>
namespace ircolib {
namespace fs = std::filesystem;
namespace ircolib {
static inline std::vector<u8> ReadFileBinary(const std::string &path) {
static inline std::vector<u8> read_file_binary(const std::string &path) {
std::ifstream file(path, std::ios::binary);
return {std::istreambuf_iterator{file}, {}};
}
static inline void WriteFileBinary(const std::vector<u8> &data, const std::string &path) {
static inline void write_file_binary(const std::vector<u8> &data, const std::string &path) {
std::ofstream file(path, std::ios::binary);
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
}
static inline void WriteFileBinary(const u8 *data, const size_t size, const std::string &path) {
static inline void write_file_binary(const u8 *data, const u32 size, const std::string &path) {
FILE *out = fopen(path.c_str(), "wb");
fwrite(data, size, 1, out);
fclose(out);
}
template <size_t Size>
static inline void WriteFileBinary(const std::array<u8, Size> &data, const std::string &path) {
static inline void write_file_binary(const std::array<u8, Size> &data, const std::string &path) {
std::ofstream file(path, std::ios::binary);
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
}
static inline size_t NextPow2(size_t num) {
static inline u32 next_pow2(u32 num) {
// Taken from "Bit Twiddling Hacks" by Sean Anderson:
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
--num;
@@ -40,4 +40,4 @@ static inline size_t NextPow2(size_t num) {
num |= num >> 16;
return num + 1;
}
} // namespace Util
} // namespace ircolib
+2 -3
View File
@@ -1,6 +1,5 @@
#pragma once
#include <cmath>
#include <types.hpp>
#include <ircolib/types.hpp>
namespace ircolib {
static inline auto roundCeil(float f) {
@@ -103,4 +102,4 @@ static inline auto roundTrunc(double f) {
return trunc(f);
#endif
}
} // namespace Util
} // namespace ircolib
+61
View File
@@ -0,0 +1,61 @@
#pragma once
#include <print>
#include <ircolib/types.hpp>
namespace ircolib {
enum LogLevel : u8 { Trace, Debug, Info, Warn, Error, Always };
constexpr LogLevel globalLogLevel = Warn;
template <typename... Args>
void panic(std::format_string<Args...> fmt, Args &&...args) {
std::print("[FATAL] ");
std::println(fmt, std::forward<Args>(args)...);
exit(1);
}
template <typename... Args>
void error(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Error >= globalLogLevel) {
std::print("[ERROR] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void warn(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Warn >= globalLogLevel) {
std::print("[WARN] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void info(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Info >= globalLogLevel) {
std::print("[INFO] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void debug(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Debug >= globalLogLevel) {
std::print("[DEBUG] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void trace(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Trace >= globalLogLevel) {
std::print("[TRACE] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void always(std::format_string<Args...> fmt, Args &&...args) {
std::println(fmt, std::forward<Args>(args)...);
}
} // namespace ircolib
+45 -31
View File
@@ -1,5 +1,6 @@
#pragma once
#include <types.hpp>
#include "types.hpp"
#include <cstddef>
#include <cstring>
#include <functional>
#include <bit>
@@ -8,7 +9,7 @@
#include <concepts>
namespace ircolib {
static inline std::vector<u8> IntegralToBuffer(const std::integral auto &val) {
static inline std::vector<u8> integral_to_buffer(const std::integral auto &val) {
std::vector<u8> ret{};
ret.resize(sizeof(val));
@@ -17,28 +18,35 @@ static inline std::vector<u8> IntegralToBuffer(const std::integral auto &val) {
return ret;
}
static inline constexpr bool IsInsideRange(const std::integral auto& addr,
const std::integral auto& start,
static inline auto integral_to_slice(const std::integral auto &val) -> std::array<u8, sizeof(val)> {
std::array<u8, sizeof(val)> ret{};
memcpy(ret.data(), &val, sizeof(val));
return ret;
}
static inline constexpr bool is_inside_range(const std::integral auto &addr, const std::integral auto &start,
const std::integral auto &end) {
return addr >= start && addr <= end;
}
template <typename T>
static constexpr inline T ReadAccess(const u8 *data, const u32 index);
static constexpr inline T read_access(const u8 *data, const u32 index);
template <typename T>
static constexpr inline T ReadAccess(const std::vector<u8> &data, const u32 index);
static constexpr inline T read_access(const std::vector<u8> &data, const u32 index);
template <typename T, size_t Size>
static constexpr inline T ReadAccess(const std::array<u8, Size> &data, const u32 index);
static constexpr inline T read_access(const std::array<u8, Size> &data, const u32 index);
template <typename T>
static constexpr inline void WriteAccess(u8 *data, const u32 index, const T val);
static constexpr inline void write_access(u8 *data, const u32 index, const T val);
template <typename T>
static constexpr inline void WriteAccess(std::vector<u8> &data, const u32 index, const T val);
static constexpr inline void write_access(std::vector<u8> &data, const u32 index, const T val);
template <typename T, size_t Size>
static constexpr inline void WriteAccess(std::array<u8, Size> &data, const u32 index, const T val);
static constexpr inline void write_access(std::array<u8, Size> &data, const u32 index, const T val);
template <>
constexpr inline u64 ReadAccess(const u8 *data, const u32 index) {
constexpr inline u64 read_access(const u8 *data, const u32 index) {
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
const auto &result = static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
@@ -46,36 +54,36 @@ constexpr inline u64 ReadAccess(const u8 *data, const u32 index) {
}
template <typename T>
static constexpr inline T ReadAccess(const u8 *data, const u32 index) {
static constexpr inline T read_access(const u8 *data, const u32 index) {
return *reinterpret_cast<const T *>(&data[index]);
}
template <>
constexpr inline u64 ReadAccess(const std::vector<u8> &data, const u32 index) {
constexpr inline u64 read_access(const std::vector<u8> &data, const u32 index) {
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
return (static_cast<u64>(hi) << 32) | static_cast<u64>(lo);
}
template <typename T>
static constexpr inline T ReadAccess(const std::vector<u8> &data, const u32 index) {
static constexpr inline T read_access(const std::vector<u8> &data, const u32 index) {
return *reinterpret_cast<const T *>(&data[index]);
}
template <size_t Size>
constexpr inline u64 ReadAccess(const std::array<u8, Size> &data, const u32 index) {
static constexpr inline u64 read_access(const std::array<u8, Size> &data, const u32 index) {
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
return static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
}
template <typename T, size_t Size>
static constexpr inline T ReadAccess(const std::array<u8, Size> &data, const u32 index) {
static constexpr inline T read_access(const std::array<u8, Size> &data, const u32 index) {
return *reinterpret_cast<const T *>(&data[index]);
}
template <size_t Size>
constexpr inline void WriteAccess(std::array<u8, Size> &data, const u32 index, const u64 val) {
static constexpr inline void write_access(std::array<u8, Size> &data, const u32 index, const u64 val) {
const u32 hi = val >> 32;
const u32 lo = val;
@@ -84,12 +92,12 @@ constexpr inline void WriteAccess(std::array<u8, Size> &data, const u32 index, c
}
template <typename T, size_t Size>
static constexpr inline void WriteAccess(std::array<u8, Size> &data, const u32 index, const T val) {
static constexpr inline void write_access(std::array<u8, Size> &data, const u32 index, const T val) {
*reinterpret_cast<T *>(&data[index]) = val;
}
template <>
constexpr inline void WriteAccess(std::vector<u8> &data, const u32 index, const u64 val) {
constexpr inline void write_access(std::vector<u8> &data, const u32 index, const u64 val) {
const u32 hi = val >> 32;
const u32 lo = val;
@@ -98,12 +106,12 @@ constexpr inline void WriteAccess(std::vector<u8> &data, const u32 index, const
}
template <typename T>
static constexpr inline void WriteAccess(std::vector<u8> &data, const u32 index, const T val) {
static constexpr inline void write_access(std::vector<u8> &data, const u32 index, const T val) {
*reinterpret_cast<T *>(&data[index]) = val;
}
template <>
constexpr inline void WriteAccess(u8 *data, const u32 index, const u64 val) {
constexpr inline void write_access(u8 *data, const u32 index, const u64 val) {
const u32 hi = val >> 32;
const u32 lo = val;
@@ -112,35 +120,41 @@ constexpr inline void WriteAccess(u8 *data, const u32 index, const u64 val) {
}
template <typename T>
static constexpr inline void WriteAccess(u8 *data, const u32 index, const T val) {
static constexpr inline void write_access(u8 *data, const u32 index, const T val) {
*reinterpret_cast<T *>(&data[index]) = val;
}
template <typename T>
static constexpr inline void SwapBuffer(std::vector<u8> &data) {
for (size_t i = 0; i < data.size(); i += sizeof(T)) {
static constexpr inline void swap_buffer(std::vector<u8> &data) {
for (u32 i = 0; i < data.size(); i += sizeof(T)) {
const T original = *reinterpret_cast<T *>(&data[i]);
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
}
}
template <typename T, size_t Size>
static constexpr inline void SwapBuffer(std::array<u8, Size> &data) {
for (size_t i = 0; i < data.size(); i += sizeof(T)) {
static constexpr inline void swap_buffer(std::array<u8, Size> &data) {
for (u32 i = 0; i < data.size(); i += sizeof(T)) {
const T original = *reinterpret_cast<T *>(&data[i]);
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
}
}
template <typename T>
static constexpr inline void swap_buffer(u8 *data, u32 size) {
for (u32 i = 0; i < size; i += sizeof(T)) {
const T original = *reinterpret_cast<T *>(&data[i]);
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
}
}
#ifdef _WIN32
inline void *aligned_alloc(const size_t alignment, const size_t size) { return _aligned_malloc(size, alignment); }
inline void *aligned_alloc(const u32 alignment, const u32 size) { return _aligned_malloc(size, alignment); }
inline void aligned_free(void *ptr) { _aligned_free(ptr); }
#else
inline void *aligned_alloc(const size_t alignment, const size_t size) {
return std::aligned_alloc(alignment, size);
}
inline void *aligned_alloc(const u32 alignment, const u32 size) { return std::aligned_alloc(alignment, size); }
inline void aligned_free(void *ptr) { std::free(ptr); }
#endif
} // namespace Util
} // namespace ircolib
+35
View File
@@ -1,5 +1,11 @@
#pragma once
#include <cstdint>
#ifdef USE_NEON
#include <sse2neon.h>
#else
#include <emmintrin.h>
#include <smmintrin.h>
#endif
namespace ircolib {
using u8 = uint8_t;
@@ -10,4 +16,33 @@ using s8 = int8_t;
using s16 = int16_t;
using s32 = int32_t;
using s64 = int64_t;
template <typename T, u32 bit>
static constexpr bool is_bit_set(const T &val) {
return val & (1 << bit);
}
template <typename T, u32 bit>
static constexpr void set_bit(T &val) {
val |= 1 << bit;
}
template <typename T>
inline bool is_bit_set(const T &val, const u32 &bit) {
return val & (1 << bit);
}
template <typename T>
inline void set_bit(T &val, const u32 &bit) {
val |= 1 << bit;
}
template <typename T>
inline void clear_bit(T &val, const u32 &bit) {
val &= ~(1 << bit);
}
} // namespace ircolib
constexpr ircolib::u32 operator""_kib(const unsigned long long v) { return v * 1024; }
constexpr ircolib::u32 operator""_mib(const unsigned long long v) { return v * 1024 * 1024; }
constexpr ircolib::u32 operator""_gib(const unsigned long long v) { return v * 1024 * 1024 * 1024; }
+7 -6
View File
@@ -38,7 +38,7 @@ Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, const unsig
if (!new_context->init_instance(instance_ext.data(), instance_ext.size(),
CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT)) {
panic("Failed to create Vulkan instance.\n");
ircolib::panic("Failed to create Vulkan instance.\n");
}
const auto tmp_surface = platform->create_surface(new_context->get_instance(), VK_NULL_HANDLE);
@@ -51,7 +51,7 @@ Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, const unsig
}
if (!ret) {
panic("Failed to create Vulkan device.\n");
ircolib::panic("Failed to create Vulkan device.\n");
}
return new_context;
@@ -67,15 +67,15 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<WSIPlatform> &wsi_platfo
if (constexpr Context::SystemHandles handles;
!wsi->init_from_existing_context(InitVulkanContext(wsi_platform.get(), 1, handles, instanceFactory))) {
panic("Failed to initialize WSI: init_from_existing_context() failed");
ircolib::panic("Failed to initialize WSI: init_from_existing_context() failed");
}
if (!wsi->init_device()) {
panic("Failed to initialize WSI: init_device() failed");
ircolib::panic("Failed to initialize WSI: init_device() failed");
}
if (!wsi->init_surface_swapchain()) {
panic("Failed to initialize WSI: init_surface_swapchain() failed");
ircolib::panic("Failed to initialize WSI: init_surface_swapchain() failed");
}
windowInfo = newWindowInfo;
@@ -124,7 +124,8 @@ void ParallelRDP::Init(const std::shared_ptr<WSIPlatform> &wsiPlatform,
offset, 8 * 1024 * 1024, 4 * 1024 * 1024, flags);
if (!command_processor->device_is_supported()) {
panic("This device probably does not support 8/16-bit storage. Make sure you're using up-to-date drivers!");
ircolib::panic(
"This device probably does not support 8/16-bit storage. Make sure you're using up-to-date drivers!");
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ u32 Core::StepCPU() {
if (cpuType == CachedInterpreter)
return interpreter.ExecuteCached() + regs.PopStalledCycles();
panic("Invalid CPU type?");
ircolib::panic("Invalid CPU type?");
}
void Core::StepRSP(const u32 cpuCycles) {
+2 -2
View File
@@ -73,7 +73,7 @@ std::string GameDB::match(ROM &rom) {
return result;
}
info("Matched code for {}, but not region! Game supposedly exists in regions [{}] but this image has "
ircolib::info("Matched code for {}, but not region! Game supposedly exists in regions [{}] but this image has "
"region {}",
name, regions, rom.header.countryCode);
rom.saveType = saveType;
@@ -81,7 +81,7 @@ std::string GameDB::match(ROM &rom) {
return result;
}
info("Did not match any Game DB entries. Code: {} Region: {}", rom.code, rom.header.countryCode);
ircolib::info("Did not match any Game DB entries. Code: {} Region: {}", rom.code, rom.header.countryCode);
rom.gameNameDB = "";
rom.saveType = SAVE_NONE;
+1 -1
View File
@@ -1,6 +1,6 @@
#include <Netplay.hpp>
#include <PIF.hpp>
#include <array>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace Netplay {}
+7 -7
View File
@@ -1,6 +1,6 @@
#pragma once
#include <ircolib/mem_access.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace Util {
#define Z64 0x80371200
@@ -13,7 +13,7 @@ FORCE_INLINE void SwapN64Rom(std::vector<u8> &rom, u32 endianness) {
if (endianness >> 24 != 0x80) {
if ((endianness & 0xFF) != 0x80) {
if ((endianness >> 16 & 0xff) != 0x80) {
panic("Unrecognized rom endianness");
ircolib::panic("Unrecognized rom endianness");
return;
} else {
altByteShift = 12;
@@ -29,20 +29,20 @@ FORCE_INLINE void SwapN64Rom(std::vector<u8> &rom, u32 endianness) {
switch (endianness) {
case V64:
ircolib::SwapBuffer<u16>(rom);
ircolib::swap_buffer<u16>(rom);
if constexpr (!toBE)
ircolib::SwapBuffer<u32>(rom);
ircolib::swap_buffer<u32>(rom);
break;
case N64:
if constexpr (toBE)
ircolib::SwapBuffer<u32>(rom);
ircolib::swap_buffer<u32>(rom);
break;
case Z64:
if constexpr (!toBE)
ircolib::SwapBuffer<u32>(rom);
ircolib::swap_buffer<u32>(rom);
break;
default:
panic("Unrecognized rom format! Make sure this is a valid Nintendo 64 ROM dump!");
ircolib::panic("Unrecognized rom format! Make sure this is a valid Nintendo 64 ROM dump!");
}
}
} // namespace Util
+2 -2
View File
@@ -63,10 +63,10 @@ void Scheduler::HandleEvents() {
case NONE:
break;
case IMPOSSIBLE:
panic("Impossible scheduler event happened");
ircolib::panic("Impossible scheduler event happened");
return;
default:
panic("Unknown scheduler event type {}", static_cast<int>(type));
ircolib::panic("Unknown scheduler event type {}", static_cast<int>(type));
return;
}
events.pop();
+2 -1
View File
@@ -1,7 +1,8 @@
#pragma once
#include <functional>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <queue>
#include <types.hpp>
enum EventType { NONE, PAUSE, STOP, RESET, PI_BUS_WRITE_COMPLETE, PI_DMA_COMPLETE, SI_DMA, IMPOSSIBLE };
+8 -14
View File
@@ -4,13 +4,14 @@
Disassembler::DisassemblyResult Disassembler::DisassembleSimple(const u32 address, const u32 instruction) const {
cs_insn *insn;
const auto bytes = ircolib::IntegralToBuffer(std::byteswap(instruction));
const auto bytes = ircolib::integral_to_buffer(std::byteswap(instruction));
const auto count = cs_disasm(handle, bytes.data(), bytes.size(), address, 0, &insn);
if (count <= 0)
return {};
DisassemblyResult result{true, std::format("0x{:016X}:\t{}\t{}", insn[0].address, insn[0].mnemonic, insn[0].op_str)};
DisassemblyResult result{true,
std::format("0x{:016X}:\t{}\t{}", insn[0].address, insn[0].mnemonic, insn[0].op_str)};
cs_free(insn, count);
@@ -30,7 +31,7 @@ Disassembler::DisassemblyResult Disassembler::DisassembleSimple(const u32 addres
Disassembler::DisassemblyResult Disassembler::DisassembleDetailed(const u32 address, const u32 instruction) const {
n64::Core &core = n64::Core::GetInstance();
cs_insn *insn;
const auto bytes = ircolib::IntegralToBuffer(std::byteswap(instruction));
const auto bytes = ircolib::integral_to_buffer(std::byteswap(instruction));
const auto count = cs_disasm(handle, bytes.data(), bytes.size(), address, 0, &insn);
if (count <= 0)
@@ -47,20 +48,13 @@ Disassembler::DisassemblyResult Disassembler::DisassembleDetailed(const u32 addr
auto formatOperand = [&](const cs_mips_op &operand) {
switch (operand.type) {
case MIPS_OP_IMM:
return DisassemblyResult::Operand{
0xffcbf1ae,
std::format("#{:X}", operand.is_unsigned ? operand.uimm : operand.imm)
};
return DisassemblyResult::Operand{0xffcbf1ae,
std::format("#{:X}", operand.is_unsigned ? operand.uimm : operand.imm)};
case MIPS_OP_MEM:
return DisassemblyResult::Operand{
0xffaef1c3,
std::format("{}(0x{:X})", cs_reg_name(handle, operand.mem.base), operand.mem.disp)
};
0xffaef1c3, std::format("{}(0x{:X})", cs_reg_name(handle, operand.mem.base), operand.mem.disp)};
case MIPS_OP_REG:
return DisassemblyResult::Operand{
0xffaef1eb,
std::format("{}", cs_reg_name(handle, operand.reg))
};
return DisassemblyResult::Operand{0xffaef1eb, std::format("{}", cs_reg_name(handle, operand.reg))};
default:
return DisassemblyResult::Operand{0xff808080, ""};
}
+4 -3
View File
@@ -1,8 +1,9 @@
#pragma once
#include <capstone/capstone.h>
#include <utils/log.hpp>
#include <ircolib/log.hpp>
#include <ircolib/mem_access.hpp>
#include <array>
#include <types.hpp>
struct Disassembler {
struct DisassemblyResult {
@@ -32,11 +33,11 @@ struct Disassembler {
explicit Disassembler(const bool rsp) : rsp(rsp) {
if (cs_open(CS_ARCH_MIPS, static_cast<cs_mode>((rsp ? CS_MODE_32 : CS_MODE_64) | CS_MODE_BIG_ENDIAN),
&handle) != CS_ERR_OK) {
panic("Could not initialize {} disassembler!", rsp ? "RSP" : "CPU");
ircolib::panic("Could not initialize {} disassembler!", rsp ? "RSP" : "CPU");
}
if (cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON) != CS_ERR_OK) {
warn("Could not enable disassembler's details!");
ircolib::warn("Could not enable disassembler's details!");
details = false;
}
}
+3 -3
View File
@@ -126,7 +126,7 @@ bool Interpreter::DetectIdleLoop(const std::array<Instruction, MAX_INSTR_PER_BLO
const u64 address = regs.Read<s64>(load.rs()) + offset;
u32 paddr;
if (!regs.cop0.MapVAddr(Cop0::LOAD, address, paddr))
panic("Failed to translate load address in DetectIdleLoop");
ircolib::panic("Failed to translate load address in DetectIdleLoop");
return isLoad && delay.opcode() == Instruction::ANDI && branch.IsBranch() && branch.offset() == -8 &&
load.rt() == delay.rs() && delay.rt() == branch.rs() && IsAddressMMIOorRDRAM(paddr);
@@ -148,7 +148,7 @@ bool Interpreter::DetectIdleLoop(const std::array<Instruction, MAX_INSTR_PER_BLO
if (isLoad) {
u32 paddr;
if (!regs.cop0.MapVAddr(Cop0::LOAD, address, paddr))
panic("Failed to translate load address in DetectIdleLoop");
ircolib::panic("Failed to translate load address in DetectIdleLoop");
return isLoad && andi.opcode() == Instruction::ANDI && branch.IsBranch() && branch.offset() == -12 &&
load.rt() == andi.rs() && andi.rt() == branch.rs() && IsAddressMMIOorRDRAM(paddr);
@@ -234,7 +234,7 @@ u32 Interpreter::ExecuteCached() {
}
if (blockCycles == 0)
panic("Cycles are 0");
ircolib::panic("Cycles are 0");
return blockCycles;
}
+2 -2
View File
@@ -32,7 +32,7 @@ u32 MMIO::Read(u32 addr) {
case SI_REGION:
return si.Read(addr);
default:
panic("Unhandled mmio read at addr {:08X}", addr);
ircolib::panic("Unhandled mmio read at addr {:08X}", addr);
}
}
@@ -63,7 +63,7 @@ void MMIO::Write(const u32 addr, const u32 val) {
si.Write(addr, val);
break;
default:
panic("Unhandled mmio write at addr {:08X} with val {:08X}", addr, val);
ircolib::panic("Unhandled mmio write at addr {:08X} with val {:08X}", addr, val);
}
}
} // namespace n64
+148 -144
View File
@@ -20,7 +20,7 @@ void Mem::Reset() {
std::error_code err;
saveData.sync(err);
if (err) {
error("[Mem]: Could not sync save data!");
ircolib::error("[Mem]: Could not sync save data!");
return;
}
saveData.unmap();
@@ -39,26 +39,26 @@ void Mem::LoadSRAM(SaveType save_type, fs::path path) {
if (saveData.is_mapped()) {
saveData.sync(err);
if (err) {
error(R"([Mem]: Could not sync save data stored @ "{}")", sramPath);
ircolib::error(R"([Mem]: Could not sync save data stored @ "{}")", sramPath);
return;
}
saveData.unmap();
}
auto sramVec = ircolib::ReadFileBinary(sramPath);
auto sramVec = ircolib::read_file_binary(sramPath);
if (sramVec.empty()) {
ircolib::WriteFileBinary(std::array<u8, SRAM_SIZE>{}, sramPath);
sramVec = ircolib::ReadFileBinary(sramPath);
ircolib::write_file_binary(std::array<u8, SRAM_SIZE>{}, sramPath);
sramVec = ircolib::read_file_binary(sramPath);
}
if (sramVec.size() != SRAM_SIZE) {
error("[Mem]: Save data is corrupt or has unexpected size! (it's {} KiB)", sramVec.size() / 1024);
ircolib::error("[Mem]: Save data is corrupt or has unexpected size! (it's {} KiB)", sramVec.size() / 1024);
return;
}
saveData = mio::make_mmap_sink(sramPath, err);
if (err) {
error(R"([Mem]: Could not create file sink for save data @ "{}")", sramPath);
ircolib::error(R"([Mem]: Could not create file sink for save data @ "{}")", sramPath);
}
}
}
@@ -84,7 +84,7 @@ FORCE_INLINE void SetROMCIC(u32 checksum, ROM &rom) {
rom.cicType = CIC_NUS_6106_7106;
break;
default:
warn("Could not determine CIC TYPE! Checksum: 0x{:08X} is unknown!", checksum);
ircolib::warn("Could not determine CIC TYPE! Checksum: 0x{:08X} is unknown!", checksum);
rom.cicType = UNKNOWN_CIC_TYPE;
break;
}
@@ -104,7 +104,7 @@ ROM Mem::LoadROM(const bool isArchive, const std::string &filename) {
buf = Util::OpenROM(filename, sizeAdjusted);
}
endianness = std::byteswap(ircolib::ReadAccess<u32>(buf, 0));
endianness = std::byteswap(ircolib::read_access<u32>(buf, 0));
Util::SwapN64Rom<true>(buf, endianness);
std::ranges::copy(buf, res.cart.begin());
@@ -130,7 +130,7 @@ ROM Mem::LoadROM(const bool isArchive, const std::string &filename) {
const u32 checksum = SDL_crc32(0, &res.cart[0x40], 0x9C0);
SetROMCIC(checksum, res);
endianness = std::byteswap(ircolib::ReadAccess<u32>(res.cart, 0));
endianness = std::byteswap(ircolib::read_access<u32>(res.cart, 0));
Util::SwapN64Rom(res.cart, endianness);
res.pal = IsROMPAL(res);
return res;
@@ -141,38 +141,38 @@ u8 Mem::Read(const u32 paddr) {
n64::Registers &regs = n64::Core::GetRegs();
const SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
return mmio.rdp.ReadRDRAM<u8>(paddr);
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
const auto &src = paddr & 0x1000 ? mmio.rsp.imem : mmio.rsp.dmem;
return src[BYTE_ADDRESS(paddr & 0xfff)];
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
return mmio.pi.BusRead<u8, false>(paddr);
if (ircolib::IsInsideRange(paddr, AI_REGION_START, AI_REGION_END)) {
if (ircolib::is_inside_range(paddr, AI_REGION_START, AI_REGION_END)) {
const u32 w = mmio.ai.Read(paddr & ~3);
const int offs = 3 - (paddr & 3);
return w >> offs * 8 & 0xff;
}
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2)) {
panic("8-bit read access from MMIO addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2)) {
ircolib::panic("8-bit read access from MMIO addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
return 0;
}
if (ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
if (ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
return si.pif.bootrom[BYTE_ADDRESS(paddr) - PIF_ROM_REGION_START];
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
return si.pif.ram[paddr - PIF_RAM_REGION_START];
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return 0;
panic("8-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
ircolib::panic("8-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
return 0;
}
@@ -181,29 +181,29 @@ u16 Mem::Read(const u32 paddr) {
n64::Registers &regs = n64::Core::GetRegs();
const SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
return mmio.rdp.ReadRDRAM<u16>(paddr);
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
const auto &src = paddr & 0x1000 ? mmio.rsp.imem : mmio.rsp.dmem;
return ircolib::ReadAccess<u16>(src, HALF_ADDRESS(paddr & 0xfff));
return ircolib::read_access<u16>(src, HALF_ADDRESS(paddr & 0xfff));
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
return mmio.pi.BusRead<u16, false>(paddr);
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
return mmio.Read(paddr);
if (ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
return ircolib::ReadAccess<u16>(si.pif.bootrom, HALF_ADDRESS(paddr) - PIF_ROM_REGION_START);
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
return std::byteswap(ircolib::ReadAccess<u16>(si.pif.ram, paddr - PIF_RAM_REGION_START));
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
return ircolib::read_access<u16>(si.pif.bootrom, HALF_ADDRESS(paddr) - PIF_ROM_REGION_START);
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
return std::byteswap(ircolib::read_access<u16>(si.pif.ram, paddr - PIF_RAM_REGION_START));
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return 0;
panic("16-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
ircolib::panic("16-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
return 0;
}
@@ -212,30 +212,30 @@ u32 Mem::Read(const u32 paddr) {
n64::Registers &regs = n64::Core::GetRegs();
const SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
return mmio.rdp.ReadRDRAM<u32>(paddr);
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
const auto &src = paddr & 0x1000 ? mmio.rsp.imem : mmio.rsp.dmem;
return ircolib::ReadAccess<u32>(src, paddr & 0xfff);
return ircolib::read_access<u32>(src, paddr & 0xfff);
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
return mmio.pi.BusRead<u32, false>(paddr);
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
return mmio.Read(paddr);
if (ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
return ircolib::ReadAccess<u32>(si.pif.bootrom, paddr - PIF_ROM_REGION_START);
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
return std::byteswap(ircolib::ReadAccess<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START));
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
return ircolib::read_access<u32>(si.pif.bootrom, paddr - PIF_ROM_REGION_START);
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
return std::byteswap(ircolib::read_access<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START));
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return 0;
panic("32-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
ircolib::panic("32-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
return 0;
}
@@ -244,30 +244,30 @@ u64 Mem::Read(const u32 paddr) {
n64::Registers &regs = n64::Core::GetRegs();
const SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END))
return mmio.rdp.ReadRDRAM<u64>(paddr);
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
const auto &src = paddr & 0x1000 ? mmio.rsp.imem : mmio.rsp.dmem;
return ircolib::ReadAccess<u64>(src, paddr & 0xfff);
return ircolib::read_access<u64>(src, paddr & 0xfff);
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2))
return mmio.pi.BusRead<u64, false>(paddr);
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
return mmio.Read(paddr);
if (ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
return ircolib::ReadAccess<u64>(si.pif.bootrom, paddr - PIF_ROM_REGION_START);
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
return std::byteswap(ircolib::ReadAccess<u64>(si.pif.ram, paddr - PIF_RAM_REGION_START));
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END))
return ircolib::read_access<u64>(si.pif.bootrom, paddr - PIF_ROM_REGION_START);
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END))
return std::byteswap(ircolib::read_access<u64>(si.pif.ram, paddr - PIF_RAM_REGION_START));
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return 0;
panic("64-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
ircolib::panic("64-bit read access in unhandled addr 0x{:08X} @ pc 0x{:016X}", paddr, (u64)regs.pc);
return 0;
}
@@ -276,45 +276,46 @@ void Mem::Write<u8>(u32 paddr, u32 val) {
n64::Registers &regs = n64::Core::GetRegs();
SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
mmio.rdp.WriteRDRAM<u8>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
val = val << (8 * (3 - (paddr & 3)));
bool is_imem = paddr & 0x1000;
auto &dest = is_imem ? mmio.rsp.imem : mmio.rsp.dmem;
paddr = (paddr & 0xFFF) & ~3;
ircolib::WriteAccess<u32>(dest, paddr, val);
ircolib::write_access<u32>(dest, paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
trace("BusWrite<u8> @ {:08X} = {:02X}", paddr, val);
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
ircolib::trace("BusWrite<u8> @ {:08X} = {:02X}", paddr, val);
mmio.pi.BusWrite<u8, false>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
panic("MMIO Write<u8>!");
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
ircolib::panic("MMIO Write<u8>!");
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
val = val << (8 * (3 - (paddr & 3)));
paddr = (paddr - PIF_RAM_REGION_START) & ~3;
ircolib::WriteAccess<u32>(si.pif.ram, paddr, std::byteswap(val));
ircolib::write_access<u32>(si.pif.ram, paddr, std::byteswap(val));
si.pif.ProcessCommands();
return;
}
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return;
panic("Unimplemented 8-bit write at address {:08X} with value {:02X} (PC = {:016X})", paddr, val, (u64)regs.pc);
ircolib::panic("Unimplemented 8-bit write at address {:08X} with value {:02X} (PC = {:016X})", paddr, val,
(u64)regs.pc);
}
template <>
@@ -322,45 +323,46 @@ void Mem::Write<u16>(u32 paddr, u32 val) {
n64::Registers &regs = n64::Core::GetRegs();
SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
mmio.rdp.WriteRDRAM<u16>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
val = val << (16 * !(paddr & 2));
bool is_imem = paddr & 0x1000;
auto &dest = is_imem ? mmio.rsp.imem : mmio.rsp.dmem;
paddr = (paddr & 0xFFF) & ~3;
ircolib::WriteAccess<u32>(dest, paddr, val);
ircolib::write_access<u32>(dest, paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
trace("BusWrite<u8> @ {:08X} = {:04X}", paddr, val);
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
ircolib::trace("BusWrite<u8> @ {:08X} = {:04X}", paddr, val);
mmio.pi.BusWrite<u16, false>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
panic("MMIO Write<u16>!");
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
ircolib::panic("MMIO Write<u16>!");
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
val = val << (16 * !(paddr & 2));
paddr &= ~3;
ircolib::WriteAccess<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START, std::byteswap(val));
ircolib::write_access<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START, std::byteswap(val));
si.pif.ProcessCommands();
return;
}
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return;
panic("Unimplemented 16-bit write at address {:08X} with value {:04X} (PC = {:016X})", paddr, val, (u64)regs.pc);
ircolib::panic("Unimplemented 16-bit write at address {:08X} with value {:04X} (PC = {:016X})", paddr, val,
(u64)regs.pc);
}
template <>
@@ -368,85 +370,87 @@ void Mem::Write<u32>(const u32 paddr, const u32 val) {
n64::Registers &regs = n64::Core::GetRegs();
SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
mmio.rdp.WriteRDRAM<u32>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
bool is_imem = paddr & 0x1000;
auto &dest = is_imem ? mmio.rsp.imem : mmio.rsp.dmem;
ircolib::WriteAccess<u32>(dest, paddr & 0xfff, val);
ircolib::write_access<u32>(dest, paddr & 0xfff, val);
return;
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
trace("BusWrite<u8> @ {:08X} = {:08X}", paddr, val);
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
ircolib::trace("BusWrite<u8> @ {:08X} = {:08X}", paddr, val);
mmio.pi.BusWrite<u32, false>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2)) {
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2)) {
mmio.Write(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
ircolib::WriteAccess<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START, std::byteswap(val));
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
ircolib::write_access<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START, std::byteswap(val));
si.pif.ProcessCommands();
return;
}
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return;
panic("Unimplemented 32-bit write at address {:08X} with value {:08X} (PC = {:016X})", paddr, val, (u64)regs.pc);
ircolib::panic("Unimplemented 32-bit write at address {:08X} with value {:08X} (PC = {:016X})", paddr, val,
(u64)regs.pc);
}
void Mem::Write(const u32 paddr, u64 val) {
n64::Registers &regs = n64::Core::GetRegs();
SI &si = mmio.si;
if (ircolib::IsInsideRange(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
if (ircolib::is_inside_range(paddr, RDRAM_REGION_START, RDRAM_REGION_END)) {
mmio.rdp.WriteRDRAM<u64>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
if (ircolib::is_inside_range(paddr, DMEM_REGION_START, RSP_MEM_REGION_END)) {
bool is_imem = paddr & 0x1000;
auto &dest = is_imem ? mmio.rsp.imem : mmio.rsp.dmem;
val >>= 32;
ircolib::WriteAccess<u32>(dest, paddr & 0xfff, val);
ircolib::write_access<u32>(dest, paddr & 0xfff, val);
return;
}
if (ircolib::IsInsideRange(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
trace("BusWrite<u64> @ {:08X} = {:016X}", paddr, val);
if (ircolib::is_inside_range(paddr, CART_REGION_START_2_1, CART_REGION_END_1_2)) {
ircolib::trace("BusWrite<u64> @ {:08X} = {:016X}", paddr, val);
mmio.pi.BusWrite<false>(paddr, val);
return;
}
if (ircolib::IsInsideRange(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
panic("MMIO Write<u64>!");
if (ircolib::is_inside_range(paddr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(paddr, MMIO_REGION_START_2, MMIO_REGION_END_2))
ircolib::panic("MMIO Write<u64>!");
if (ircolib::IsInsideRange(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
ircolib::WriteAccess<u64>(si.pif.ram, paddr - PIF_RAM_REGION_START, std::byteswap(val));
if (ircolib::is_inside_range(paddr, PIF_RAM_REGION_START, PIF_RAM_REGION_END)) {
ircolib::write_access<u64>(si.pif.ram, paddr - PIF_RAM_REGION_START, std::byteswap(val));
si.pif.ProcessCommands();
return;
}
if (ircolib::IsInsideRange(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::IsInsideRange(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::IsInsideRange(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::IsInsideRange(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::IsInsideRange(paddr, UNUSED_START_4, UNUSED_END_4))
if (ircolib::is_inside_range(paddr, UNUSED_START_1, UNUSED_END_1) || // unused
ircolib::is_inside_range(paddr, UNUSED_START_2, UNUSED_END_2) ||
ircolib::is_inside_range(paddr, UNUSED_START_3, UNUSED_END_3) ||
ircolib::is_inside_range(paddr, PIF_ROM_REGION_START, PIF_ROM_REGION_END) ||
ircolib::is_inside_range(paddr, UNUSED_START_4, UNUSED_END_4))
return;
panic("Unimplemented 64-bit write at address {:08X} with value {:016X} (PC = {:016X})", paddr, val, (u64)regs.pc);
ircolib::panic("Unimplemented 64-bit write at address {:08X} with value {:016X} (PC = {:016X})", paddr, val,
(u64)regs.pc);
}
template <>
@@ -456,14 +460,14 @@ u32 Mem::BackupRead<u32>(const u32 addr) {
return 0;
case SAVE_EEPROM_4k:
case SAVE_EEPROM_16k:
warn("Accessing cartridge backup type SAVE_EEPROM, returning 0 for word read");
ircolib::warn("Accessing cartridge backup type SAVE_EEPROM, returning 0 for word read");
return 0;
case SAVE_FLASH_1m:
return flash.Read<u32>(addr);
case SAVE_SRAM_256k:
return 0xFFFFFFFF;
default:
panic("Backup read word with unknown save type");
ircolib::panic("Backup read word with unknown save type");
}
}
@@ -474,7 +478,7 @@ u8 Mem::BackupRead<u8>(const u32 addr) {
return 0;
case SAVE_EEPROM_4k:
case SAVE_EEPROM_16k:
warn("Accessing cartridge backup type SAVE_EEPROM, returning 0 for word read");
ircolib::warn("Accessing cartridge backup type SAVE_EEPROM, returning 0 for word read");
return 0;
case SAVE_FLASH_1m:
return flash.Read<u8>(addr);
@@ -483,10 +487,10 @@ u8 Mem::BackupRead<u8>(const u32 addr) {
assert(addr < saveData.size());
return saveData[addr];
} else {
panic("Invalid backup Read<u8> if save data is not initialized");
ircolib::panic("Invalid backup Read<u8> if save data is not initialized");
}
default:
panic("Backup read word with unknown save type");
ircolib::panic("Backup read word with unknown save type");
}
}
@@ -494,18 +498,18 @@ template <>
void Mem::BackupWrite<u32>(const u32 addr, const u32 val) {
switch (rom.saveType) {
case SAVE_NONE:
warn("Accessing cartridge with save type SAVE_NONE in write word");
ircolib::warn("Accessing cartridge with save type SAVE_NONE in write word");
break;
case SAVE_EEPROM_4k:
case SAVE_EEPROM_16k:
panic("Accessing cartridge with save type SAVE_EEPROM in write word");
ircolib::panic("Accessing cartridge with save type SAVE_EEPROM in write word");
case SAVE_FLASH_1m:
flash.Write<u32>(addr, val);
break;
case SAVE_SRAM_256k:
break;
default:
panic("Backup read word with unknown save type");
ircolib::panic("Backup read word with unknown save type");
}
}
@@ -513,11 +517,11 @@ template <>
void Mem::BackupWrite<u8>(const u32 addr, const u8 val) {
switch (rom.saveType) {
case SAVE_NONE:
warn("Accessing cartridge with save type SAVE_NONE in write word");
ircolib::warn("Accessing cartridge with save type SAVE_NONE in write word");
break;
case SAVE_EEPROM_4k:
case SAVE_EEPROM_16k:
panic("Accessing cartridge with save type SAVE_EEPROM in write word");
ircolib::panic("Accessing cartridge with save type SAVE_EEPROM in write word");
case SAVE_FLASH_1m:
flash.Write<u8>(addr, val);
break;
@@ -526,11 +530,11 @@ void Mem::BackupWrite<u8>(const u32 addr, const u8 val) {
assert(addr < saveData.size());
saveData[addr] = val;
} else {
panic("Invalid backup Write<u8> if save data is not initialized");
ircolib::panic("Invalid backup Write<u8> if save data is not initialized");
}
break;
default:
panic("Backup read word with unknown save type");
ircolib::panic("Backup read word with unknown save type");
}
}
} // namespace n64
+7 -7
View File
@@ -4,7 +4,7 @@
#include <backend/MemoryRegions.hpp>
#include <backend/core/MMIO.hpp>
#include <common.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <vector>
#include <algorithm>
@@ -100,22 +100,22 @@ struct Mem {
std::vector<u8> temp{};
temp.resize(size);
std::copy(mmio.rdp.rdram.begin() + start, mmio.rdp.rdram.begin() + size - 1, temp.begin());
ircolib::SwapBuffer<u32>(temp);
ircolib::WriteFileBinary(temp, "rdram.bin");
ircolib::swap_buffer<u32>(temp);
ircolib::write_file_binary(temp, "rdram.bin");
}
FORCE_INLINE void DumpIMEM() const {
std::array<u8, IMEM_SIZE> temp{};
std::ranges::copy(mmio.rsp.imem, temp.begin());
ircolib::SwapBuffer<u32>(temp);
ircolib::WriteFileBinary(temp, "imem.bin");
ircolib::swap_buffer<u32>(temp);
ircolib::write_file_binary(temp, "imem.bin");
}
FORCE_INLINE void DumpDMEM() const {
std::array<u8, DMEM_SIZE> temp{};
std::ranges::copy(mmio.rsp.dmem, temp.begin());
ircolib::SwapBuffer<u32>(temp);
ircolib::WriteFileBinary(temp, "dmem.bin");
ircolib::swap_buffer<u32>(temp);
ircolib::write_file_binary(temp, "dmem.bin");
}
MMIO mmio;
+12 -12
View File
@@ -1,4 +1,4 @@
#include <log.hpp>
#include <ircolib/log.hpp>
#include <parallel-rdp/ParallelRDPWrapper.hpp>
#include <Core.hpp>
@@ -25,21 +25,21 @@ void RDP::WriteRDRAM<u8>(const size_t idx, const u8 v) {
template <>
void RDP::WriteRDRAM<u16>(const size_t idx, const u16 v) {
if (const size_t real = HALF_ADDRESS(idx); real < RDRAM_SIZE) [[likely]] {
ircolib::WriteAccess<u16>(rdram, real, v);
ircolib::write_access<u16>(rdram, real, v);
}
}
template <>
void RDP::WriteRDRAM<u32>(const size_t idx, const u32 v) {
if (idx < RDRAM_SIZE) [[likely]] {
ircolib::WriteAccess<u32>(rdram, idx, v);
ircolib::write_access<u32>(rdram, idx, v);
}
}
template <>
void RDP::WriteRDRAM<u64>(const size_t idx, const u64 v) {
if (idx < RDRAM_SIZE) [[likely]] {
ircolib::WriteAccess<u64>(rdram, idx, v);
ircolib::write_access<u64>(rdram, idx, v);
}
}
@@ -54,7 +54,7 @@ u8 RDP::ReadRDRAM<u8>(const size_t idx) {
template <>
u16 RDP::ReadRDRAM<u16>(const size_t idx) {
if (const size_t real = HALF_ADDRESS(idx); real < RDRAM_SIZE) [[likely]]
return ircolib::ReadAccess<u16>(rdram, real);
return ircolib::read_access<u16>(rdram, real);
return 0;
}
@@ -62,7 +62,7 @@ u16 RDP::ReadRDRAM<u16>(const size_t idx) {
template <>
u32 RDP::ReadRDRAM<u32>(const size_t idx) {
if (idx < RDRAM_SIZE) [[likely]]
return ircolib::ReadAccess<u32>(rdram, idx);
return ircolib::read_access<u32>(rdram, idx);
return 0;
}
@@ -70,7 +70,7 @@ u32 RDP::ReadRDRAM<u32>(const size_t idx) {
template <>
u64 RDP::ReadRDRAM<u64>(const size_t idx) {
if (idx < RDRAM_SIZE) [[likely]]
return ircolib::ReadAccess<u64>(rdram, idx);
return ircolib::read_access<u64>(rdram, idx);
return 0;
}
@@ -98,7 +98,7 @@ auto RDP::Read(const u32 addr) const -> u32 {
case 0x0410001C:
return dpc.tmem;
default:
panic("Unhandled DP Command Registers read (addr: {:08X})", addr);
ircolib::panic("Unhandled DP Command Registers read (addr: {:08X})", addr);
}
return 0;
@@ -116,7 +116,7 @@ void RDP::Write(const u32 addr, const u32 val) {
WriteStatus(val);
break;
default:
panic("Unhandled DP Command Registers write (addr: {:08X}, val: {:08X})", addr, val);
ircolib::panic("Unhandled DP Command Registers write (addr: {:08X}, val: {:08X})", addr, val);
}
}
@@ -216,13 +216,13 @@ void RDP::RunCommand() {
return;
if (len + remaining_cmds * 4 > COMMAND_BUFFER_SIZE) {
panic("Too many RDP commands");
ircolib::panic("Too many RDP commands");
return;
}
if (dpc.status.xbusDmemDma) {
for (int i = 0; i < len; i += 4) {
const u32 cmd = ircolib::ReadAccess<u32>(mem.mmio.rsp.dmem, current + i & 0xFFF);
const u32 cmd = ircolib::read_access<u32>(mem.mmio.rsp.dmem, current + i & 0xFFF);
cmd_buf[remaining_cmds + (i >> 2)] = cmd;
}
} else {
@@ -231,7 +231,7 @@ void RDP::RunCommand() {
}
for (int i = 0; i < len; i += 4) {
const u32 cmd = ircolib::ReadAccess<u32>(rdram, current + i);
const u32 cmd = ircolib::read_access<u32>(rdram, current + i);
cmd_buf[remaining_cmds + (i >> 2)] = cmd;
}
}
+8 -8
View File
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
RSP::RSP() { Reset(); }
@@ -53,8 +53,8 @@ auto RSP::Read(const u32 addr) -> u32 {
{
auto &regs = Core::GetRegs();
panic("Unimplemented SP register read {:08X} (cpu pc: 0x{:016X}, rsp pc: 0x{:04X}, ra: 0x{:016X})", addr,
(u64)regs.oldPC, pc & 0xffc, (u64)regs.gpr[31]);
ircolib::panic("Unimplemented SP register read {:08X} (cpu pc: 0x{:016X}, rsp pc: 0x{:04X}, ra: 0x{:016X})",
addr, (u64)regs.oldPC, pc & 0xffc, (u64)regs.gpr[31]);
}
}
}
@@ -111,7 +111,7 @@ void RSP::DMA<true>() {
u32 mem_address = spDMASPAddr.address & 0xFF8;
u32 dram_address = spDMADRAMAddr.address & 0xFFFFF8;
trace("SP DMA from RSP to RDRAM (size: {} B, {:08X} to {:08X})", length, mem_address, dram_address);
ircolib::trace("SP DMA from RSP to RDRAM (size: {} B, {:08X} to {:08X})", length, mem_address, dram_address);
for (u32 i = 0; i < spDMALen.count + 1; i++) {
for (u32 j = 0; j < length; j++) {
@@ -125,7 +125,7 @@ void RSP::DMA<true>() {
mem_address += length;
mem_address &= 0xFF8;
}
trace("Addresses after: RSP: 0x{:08X}, Dram: 0x{:08X}", mem_address, dram_address);
ircolib::trace("Addresses after: RSP: 0x{:08X}, Dram: 0x{:08X}", mem_address, dram_address);
lastSuccessfulSPAddr.address = mem_address;
lastSuccessfulSPAddr.bank = spDMASPAddr.bank;
@@ -145,7 +145,7 @@ void RSP::DMA<false>() {
u32 mem_address = spDMASPAddr.address & 0xFF8;
u32 dram_address = spDMADRAMAddr.address & 0xFFFFF8;
trace("SP DMA from RDRAM to RSP (size: {} B, {:08X} to {:08X})", length, dram_address, mem_address);
ircolib::trace("SP DMA from RDRAM to RSP (size: {} B, {:08X} to {:08X})", length, dram_address, mem_address);
for (u32 i = 0; i < spDMALen.count + 1; i++) {
for (u32 j = 0; j < length; j++) {
@@ -159,7 +159,7 @@ void RSP::DMA<false>() {
mem_address += length;
mem_address &= 0xFF8;
}
trace("Addresses after: RSP: 0x{:08X}, Dram: 0x{:08X}", mem_address, dram_address);
ircolib::trace("Addresses after: RSP: 0x{:08X}, Dram: 0x{:08X}", mem_address, dram_address);
lastSuccessfulSPAddr.address = mem_address;
lastSuccessfulSPAddr.bank = spDMASPAddr.bank;
@@ -195,7 +195,7 @@ void RSP::Write(const u32 addr, const u32 val) {
}
break;
default:
panic("Unimplemented SP register write {:08X}, val: {:08X}", addr, val);
ircolib::panic("Unimplemented SP register write {:08X}, val: {:08X}", addr, val);
}
}
} // namespace n64
+1 -1
View File
@@ -150,7 +150,7 @@ struct RSP {
FORCE_INLINE void Step() {
gpr[0] = 0;
const u32 instr = ircolib::ReadAccess<u32>(imem, pc & IMEM_DSIZE);
const u32 instr = ircolib::read_access<u32>(imem, pc & IMEM_DSIZE);
oldPC = pc & 0xFFC;
pc = nextPC & 0xFFC;
nextPC += 4;
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <ranges>
namespace n64 {
@@ -42,11 +42,12 @@ void Cop0::eret() {
void Cop0::tlbr() {
if (index.i >= 32) {
panic("TLBR with TLB index {}", index.i);
auto i = index.i;
if (i >= 32) {
ircolib::panic("TLBR with TLB index {}", i);
}
const TLBEntry entry = tlb[index.i];
const TLBEntry entry = tlb[i];
entryHi.raw = entry.entryHi.raw;
entryLo0.raw = entry.entryLo0.raw & 0x3FFFFFFF;
@@ -64,7 +65,7 @@ void Cop0::tlbw(const int index_) {
page_mask.mask = top | (top >> 1);
if (index_ >= 32) {
panic("TLBWI with TLB index {}", index_);
ircolib::panic("TLBWI with TLB index {}", index_);
}
tlb[index_].entryHi.raw = entryHi.raw;
@@ -555,7 +555,7 @@ void Cop1::cfc1(const Instruction instr) {
val = fcr31.read();
break;
default:
panic("Undefined CFC1 with rd != 0 or 31");
ircolib::panic("Undefined CFC1 with rd != 0 or 31");
}
regs.Write(instr.rt(), val);
}
@@ -604,7 +604,7 @@ void Cop1::ctc1(const Instruction instr) {
}
break;
default:
panic("Undefined CTC1 with rd != 0 or 31");
ircolib::panic("Undefined CTC1 with rd != 0 or 31");
}
}
+5 -5
View File
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <Instruction.hpp>
namespace n64 {
@@ -164,7 +164,7 @@ void Interpreter::special(const Instruction instr) {
dsra32(instr);
break;
default:
panic("Unimplemented special {} {} ({:08X}) (pc: {:016X})", instr.instr.opcode.special_hi,
ircolib::panic("Unimplemented special {} {} ({:08X}) (pc: {:016X})", instr.instr.opcode.special_hi,
instr.instr.opcode.special_lo, instr.instr.raw, static_cast<u64>(regs.oldPC));
}
}
@@ -215,7 +215,7 @@ void Interpreter::regimm(const Instruction instr) {
bllink(instr, regs.Read<s64>(instr.rs()) >= 0);
break;
default:
panic("Unimplemented regimm {} {} ({:08X}) (pc: {:016X})", instr.instr.opcode.regimm_hi,
ircolib::panic("Unimplemented regimm {} {} ({:08X}) (pc: {:016X})", instr.instr.opcode.regimm_hi,
instr.instr.opcode.regimm_lo, u32(instr), static_cast<u64>(regs.oldPC));
}
}
@@ -327,7 +327,7 @@ void Interpreter::DecodeExecute(const Instruction instr) {
bl(instr, regs.cop1.fcr31.compare);
break;
default:
panic("Undefined BC COP1 {:02X}", instr.cop_rt());
ircolib::panic("Undefined BC COP1 {:02X}", instr.cop_rt());
}
return;
}
@@ -450,7 +450,7 @@ void Interpreter::DecodeExecute(const Instruction instr) {
sd(instr);
break;
default:
panic("Unimplemented instruction {:02X} ({:08X}) (pc: {:016X})", instr.instr.opcode.op, u32(instr),
ircolib::panic("Unimplemented instruction {:02X} ({:08X}) (pc: {:016X})", instr.instr.opcode.op, u32(instr),
static_cast<u64>(regs.oldPC));
}
}
@@ -876,7 +876,7 @@ void Interpreter::cache(const Instruction instr) {
u32 ptag = GetPhysicalAddressPTag(paddr);
if (type > 1)
panic("Unknown cache type {}", type);
ircolib::panic("Unknown cache type {}", type);
if (type == 0)
return CacheTypeInstruction(op, vaddr, paddr, ptag);
@@ -905,7 +905,7 @@ void Interpreter::CacheTypeInstruction(const u8 op, const u64 vaddr, const u32 p
icache.WriteBack(vaddr, paddr, ptag);
break;
default:
panic("Unimplemented icache op 0b{:03b}", op);
ircolib::panic("Unimplemented icache op 0b{:03b}", op);
}
}
@@ -941,7 +941,7 @@ void Interpreter::CacheTypeData(const u8 op, const u64 vaddr, const u32 paddr, c
dcache.WriteBack(vaddr, paddr, ptag);
break;
default:
panic("Unimplemented dcache op 0b{:03b}", op);
ircolib::panic("Unimplemented dcache op 0b{:03b}", op);
}
}*/
} // namespace n64
+23 -23
View File
@@ -28,32 +28,32 @@ void Flash::Load(SaveType saveType, const std::string &path) {
if (saveData.is_mapped()) {
saveData.sync(error);
if (error) {
panic("Could not sync {}", flashPath);
ircolib::panic("Could not sync {}", flashPath);
}
saveData.unmap();
}
auto flashVec = ircolib::ReadFileBinary(flashPath);
auto flashVec = ircolib::read_file_binary(flashPath);
if (flashVec.empty()) {
std::vector<u8> dummy{};
dummy.resize(FLASH_SIZE);
ircolib::WriteFileBinary(dummy, flashPath);
flashVec = ircolib::ReadFileBinary(flashPath);
ircolib::write_file_binary(dummy, flashPath);
flashVec = ircolib::read_file_binary(flashPath);
}
if (flashVec.size() != FLASH_SIZE) {
panic("Corrupt SRAM!");
ircolib::panic("Corrupt SRAM!");
}
saveData = mio::make_mmap_sink(flashPath, error);
if (error) {
panic("Could not make mmap {}", flashPath);
ircolib::panic("Could not make mmap {}", flashPath);
}
}
}
void Flash::CommandExecute() const {
trace("Flash::CommandExecute");
ircolib::trace("Flash::CommandExecute");
switch (state) {
case FlashState::Idle:
break;
@@ -63,7 +63,7 @@ void Flash::CommandExecute() const {
saveData[eraseOffs + i] = 0xFF;
}
} else {
panic("Accessing flash when not mapped!");
ircolib::panic("Accessing flash when not mapped!");
}
break;
case FlashState::Write:
@@ -72,11 +72,11 @@ void Flash::CommandExecute() const {
saveData[writeOffs + i] = writeBuf[i];
}
} else {
panic("Accessing flash when not mapped!");
ircolib::panic("Accessing flash when not mapped!");
}
break;
case FlashState::Read:
panic("Execute command when flash in read state");
ircolib::panic("Execute command when flash in read state");
break;
case FlashState::Status:
break;
@@ -134,10 +134,10 @@ void Flash::Write<u32>(u32 index, u32 val) {
CommandRead();
break;
default:
warn("Invalid flash command: {:02X}", cmd);
ircolib::warn("Invalid flash command: {:02X}", cmd);
}
} else {
warn("Flash Write of {:08X} @ {:08X}", val, index);
ircolib::warn("Flash Write of {:08X} @ {:08X}", val, index);
}
}
@@ -145,19 +145,19 @@ template <>
void Flash::Write<u8>(u32 index, u8 val) {
switch (state) {
case FlashState::Idle:
panic("Invalid FlashState::Idle with Write<u8>");
ircolib::panic("Invalid FlashState::Idle with Write<u8>");
case FlashState::Status:
panic("Invalid FlashState::Status with Write<u8>");
ircolib::panic("Invalid FlashState::Status with Write<u8>");
case FlashState::Erase:
panic("Invalid FlashState::Erase with Write<u8>");
ircolib::panic("Invalid FlashState::Erase with Write<u8>");
case FlashState::Read:
panic("Invalid FlashState::Read with Write<u8>");
ircolib::panic("Invalid FlashState::Read with Write<u8>");
case FlashState::Write:
assert(index <= 0x7F && "Out of range flash Write8");
writeBuf[index] = val;
break;
default:
warn("Invalid flash state on Write<u8>: {:02X}", static_cast<u8>(state));
ircolib::warn("Invalid flash state on Write<u8>: {:02X}", static_cast<u8>(state));
}
}
@@ -165,27 +165,27 @@ template <>
u8 Flash::Read<u8>(const u32 index) const {
switch (state) {
case FlashState::Idle:
panic("Flash read byte while in state FLASH_STATE_IDLE");
ircolib::panic("Flash read byte while in state FLASH_STATE_IDLE");
case FlashState::Write:
panic("Flash read byte while in state FLASH_STATE_WRITE");
ircolib::panic("Flash read byte while in state FLASH_STATE_WRITE");
case FlashState::Read:
if (saveData.is_mapped()) {
const u8 value = saveData[index];
trace("Flash read byte in state read: index {:08X} = {:02X}", index, value);
ircolib::trace("Flash read byte in state read: index {:08X} = {:02X}", index, value);
return value;
}
panic("Accessing flash when not mapped!");
ircolib::panic("Accessing flash when not mapped!");
case FlashState::Status:
{
const u32 offset = (7 - (index % 8)) * 8;
const u8 value = (status >> offset) & 0xFF;
trace("Flash read byte in state status: index {:08X} = {:02X}", index, value);
ircolib::trace("Flash read byte in state status: index {:08X} = {:02X}", index, value);
return value;
}
default:
panic("Flash read byte while in unknown state");
ircolib::panic("Flash read byte while in unknown state");
return 0;
}
}
+3 -3
View File
@@ -5,11 +5,11 @@
namespace n64 {
static bool IsAddressMMIOorRDRAM(u32 addr) {
if (ircolib::IsInsideRange(addr, RDRAM_REGION_START, RDRAM_REGION_END))
if (ircolib::is_inside_range(addr, RDRAM_REGION_START, RDRAM_REGION_END))
return true;
if (ircolib::IsInsideRange(addr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::IsInsideRange(addr, MMIO_REGION_START_2, MMIO_REGION_END_2))
if (ircolib::is_inside_range(addr, MMIO_REGION_START_1, MMIO_REGION_END_1) ||
ircolib::is_inside_range(addr, MMIO_REGION_START_2, MMIO_REGION_END_2))
return true;
return false;
+2 -2
View File
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <Options.hpp>
namespace n64 {
@@ -76,7 +76,7 @@ void AI::Write(const u32 addr, const u32 val) {
dac.precision = bitrate + 1;
break;
default:
panic("Unhandled AI write at addr {:08X} with val {:08X}", addr, val);
ircolib::panic("Unhandled AI write at addr {:08X} with val {:08X}", addr, val);
}
}
+4 -4
View File
@@ -1,5 +1,5 @@
#include <Audio.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <SDL3/SDL.h>
namespace n64 {
@@ -11,7 +11,7 @@ namespace n64 {
AudioDevice::AudioDevice() {
audioStreamMutex = SDL_CreateMutex();
if (!audioStreamMutex) {
panic("Unable to initialize audio mutex: {}", SDL_GetError());
ircolib::panic("Unable to initialize audio mutex: {}", SDL_GetError());
}
SDL_InitSubSystem(SDL_INIT_AUDIO);
@@ -19,7 +19,7 @@ AudioDevice::AudioDevice() {
audioStream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &request, nullptr, nullptr);
if (!audioStream) {
panic("Unable to create audio stream: {}", SDL_GetError());
ircolib::panic("Unable to create audio stream: {}", SDL_GetError());
}
}
@@ -50,7 +50,7 @@ void AudioDevice::AdjustSampleRate(int sampleRate) {
audioStream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &request, nullptr, nullptr);
if (!audioStream) {
panic("Unable to create audio stream: {}", SDL_GetError());
ircolib::panic("Unable to create audio stream: {}", SDL_GetError());
}
UnlockMutex();
}
+3 -3
View File
@@ -1,6 +1,6 @@
#include <core/mmio/MI.hpp>
#include <core/registers/Registers.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#define MI_VERSION_REG 0x02020102
@@ -24,7 +24,7 @@ auto MI::Read(u32 paddr) const -> u32 {
case 0xC:
return intrMask.raw & 0x3F;
default:
panic("Unhandled MI[{:08X}] read", paddr);
ircolib::panic("Unhandled MI[{:08X}] read", paddr);
}
}
@@ -59,7 +59,7 @@ void MI::Write(u32 paddr, u32 val) {
UpdateInterrupt();
break;
default:
panic("Unhandled MI write @ 0x{:08X} with value 0x{:08X}", paddr, val);
ircolib::panic("Unhandled MI write @ 0x{:08X} with value 0x{:08X}", paddr, val);
}
}
} // namespace n64
+103 -70
View File
@@ -2,7 +2,7 @@
#include <Scheduler.hpp>
#include <cmath>
#include <core/mmio/PI.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
PI::PI() { Reset(); }
@@ -52,15 +52,18 @@ auto PI::BusRead<u8, true>(u32 addr) -> u8 {
switch (addr) {
case REGION_PI_UNKNOWN:
mem.DumpRDRAM();
panic("Reading byte from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
ircolib::panic(
"Reading byte from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
"returning FF because it is not emulated (pc: 0x{:016X})",
addr, (u64)Core::GetRegs().oldPC);
case REGION_PI_64DD_REG:
panic("Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
ircolib::panic(
"Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
"returning FF because it is not emulated",
addr);
case REGION_PI_64DD_ROM:
warn("Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
ircolib::warn(
"Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
"returning FF because it is not emulated",
addr);
return 0xFF;
@@ -71,14 +74,16 @@ auto PI::BusRead<u8, true>(u32 addr) -> u8 {
// round to nearest 4 byte boundary, keeping old LSB
const u32 index = BYTE_ADDRESS(addr) - SREGION_PI_ROM;
if (index >= mem.rom.cart.size()) {
warn("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM! ({}/0x{:016X})", addr,
ircolib::warn(
"Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM! ({}/0x{:016X})", addr,
index, index, mem.rom.cart.size(), mem.rom.cart.size());
return 0xFF;
}
return mem.rom.cart[index];
}
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -91,15 +96,18 @@ auto PI::BusRead<u8, false>(u32 addr) -> u8 {
switch (addr) {
case REGION_PI_UNKNOWN:
panic("Reading byte from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
ircolib::panic(
"Reading byte from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
"returning FF because it is not emulated",
addr);
case REGION_PI_64DD_REG:
panic("Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
ircolib::panic(
"Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
"returning FF because it is not emulated",
addr);
case REGION_PI_64DD_ROM:
warn("Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
ircolib::warn(
"Reading byte from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
"returning FF because it is not emulated",
addr);
return 0xFF;
@@ -111,14 +119,16 @@ auto PI::BusRead<u8, false>(u32 addr) -> u8 {
// round to nearest 4 byte boundary, keeping old LSB
const u32 index = BYTE_ADDRESS(addr) - SREGION_PI_ROM;
if (index >= mem.rom.cart.size()) {
warn("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM! ({}/0x{:016X})", addr,
ircolib::warn(
"Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM! ({}/0x{:016X})", addr,
index, index, mem.rom.cart.size(), mem.rom.cart.size());
return 0xFF;
}
return mem.rom.cart[index];
}
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -127,25 +137,28 @@ void PI::BusWrite<u8, true>(u32 addr, u32 val) {
n64::Mem &mem = n64::Core::GetMem();
switch (addr) {
case REGION_PI_UNKNOWN:
panic("Writing byte 0x{:02X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val, addr);
ircolib::panic("Writing byte 0x{:02X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val, addr);
case REGION_PI_64DD_REG:
if (addr == 0x05000020) {
fprintf(stderr, "%c", val);
} else {
warn("Writing byte 0x{:02X} to address 0x{:08X} in region: REGION_PI_64DD_ROM, this is the 64DD, ignoring!",
ircolib::warn(
"Writing byte 0x{:02X} to address 0x{:08X} in region: REGION_PI_64DD_ROM, this is the 64DD, ignoring!",
val, addr);
}
break;
case REGION_PI_64DD_ROM:
panic("Writing byte 0x{:02X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val, addr);
ircolib::panic("Writing byte 0x{:02X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val,
addr);
case REGION_PI_SRAM:
mem.BackupWrite<u8>(addr - SREGION_PI_SRAM, val);
break;
case REGION_PI_ROM:
warn("Writing byte 0x{:02X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
ircolib::warn("Writing byte 0x{:02X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
break;
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -169,31 +182,35 @@ auto PI::BusRead<u16, false>(u32 addr) -> u16 {
switch (addr) {
case REGION_PI_UNKNOWN:
panic("Reading half from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
ircolib::panic(
"Reading half from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
"returning FF because it is not emulated",
addr);
case REGION_PI_64DD_REG:
panic("Reading half from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
ircolib::panic(
"Reading half from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
"returning FF because it is not emulated",
addr);
case REGION_PI_64DD_ROM:
panic("Reading half from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
ircolib::panic(
"Reading half from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
"returning FF because it is not emulated",
addr);
case REGION_PI_SRAM:
panic("Reading half from address 0x{:08X} in unsupported region: REGION_PI_SRAM", addr);
ircolib::panic("Reading half from address 0x{:08X} in unsupported region: REGION_PI_SRAM", addr);
case REGION_PI_ROM:
{
addr = (addr + 2) & ~3;
const u32 index = HALF_ADDRESS(addr) - SREGION_PI_ROM;
if (index > mem.rom.cart.size() - 1) {
panic("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM!", addr, index,
index);
ircolib::panic("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM!", addr,
index, index);
}
return ircolib::ReadAccess<u16>(mem.rom.cart, index);
return ircolib::read_access<u16>(mem.rom.cart, index);
}
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -210,19 +227,22 @@ void PI::BusWrite<u16, false>(u32 addr, u32 val) {
switch (addr) {
case REGION_PI_UNKNOWN:
panic("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val, addr);
ircolib::panic("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val, addr);
case REGION_PI_64DD_REG:
panic("Writing half 0x{:04X} to address 0x{:08X} in region: REGION_PI_64DD_ROM, this is the 64DD, ignoring!",
val, addr);
ircolib::panic(
"Writing half 0x{:04X} to address 0x{:08X} in region: REGION_PI_64DD_ROM, this is the 64DD, ignoring!", val,
addr);
case REGION_PI_64DD_ROM:
panic("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val, addr);
ircolib::panic("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val,
addr);
case REGION_PI_SRAM:
panic("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_SRAM", val, addr);
ircolib::panic("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_SRAM", val, addr);
case REGION_PI_ROM:
warn("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
ircolib::warn("Writing half 0x{:04X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
break;
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -240,17 +260,20 @@ auto PI::BusRead<u32, false>(u32 addr) -> u32 {
switch (addr) {
case REGION_PI_UNKNOWN:
warn("Reading word from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
ircolib::warn(
"Reading word from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN - This is the N64DD, "
"returning FF because it is not emulated",
addr);
return 0xFF;
case REGION_PI_64DD_REG:
warn("Reading word from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
ircolib::warn(
"Reading word from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG - This is the N64DD, "
"returning FF because it is not emulated",
addr);
return 0xFF;
case REGION_PI_64DD_ROM:
warn("Reading word from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
ircolib::warn(
"Reading word from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM - This is the N64DD, "
"returning FF because it is not emulated",
addr);
return 0xFF;
@@ -263,20 +286,22 @@ auto PI::BusRead<u32, false>(u32 addr) -> u32 {
switch (addr) {
case REGION_CART_ISVIEWER_BUFFER:
return std::byteswap<u32>(
ircolib::ReadAccess<u32>(mem.isviewer, addr - SREGION_CART_ISVIEWER_BUFFER));
ircolib::read_access<u32>(mem.isviewer, addr - SREGION_CART_ISVIEWER_BUFFER));
case CART_ISVIEWER_FLUSH:
panic("Read from ISViewer flush!");
ircolib::panic("Read from ISViewer flush!");
default:
break;
}
warn("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM!", addr, index, index);
ircolib::warn("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM!", addr,
index, index);
return 0;
}
return ircolib::ReadAccess<u32>(mem.rom.cart, index);
return ircolib::read_access<u32>(mem.rom.cart, index);
}
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -293,20 +318,21 @@ void PI::BusWrite<u32, false>(u32 addr, u32 val) {
if (!WriteLatch(val)) [[unlikely]] {
return;
}
warn("Writing word 0x{:08X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val, addr);
ircolib::warn("Writing word 0x{:08X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val, addr);
return;
case REGION_PI_64DD_REG:
if (!WriteLatch(val)) [[unlikely]] {
return;
}
warn("Writing word 0x{:08X} to address 0x{:08X} in region: REGION_PI_64DD_ROM, this is the 64DD, ignoring!",
val, addr);
ircolib::warn(
"Writing word 0x{:08X} to address 0x{:08X} in region: REGION_PI_64DD_ROM, this is the 64DD, ignoring!", val,
addr);
return;
case REGION_PI_64DD_ROM:
if (!WriteLatch(val)) [[unlikely]] {
return;
}
warn("Writing word 0x{:08X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val, addr);
ircolib::warn("Writing word 0x{:08X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val, addr);
return;
case REGION_PI_SRAM:
if (!WriteLatch(val)) [[unlikely]] {
@@ -317,7 +343,7 @@ void PI::BusWrite<u32, false>(u32 addr, u32 val) {
case REGION_PI_ROM:
switch (addr) {
case REGION_CART_ISVIEWER_BUFFER:
ircolib::WriteAccess<u32>(mem.isviewer, addr - SREGION_CART_ISVIEWER_BUFFER, std::byteswap(val));
ircolib::write_access<u32>(mem.isviewer, addr - SREGION_CART_ISVIEWER_BUFFER, std::byteswap(val));
break;
case CART_ISVIEWER_FLUSH:
{
@@ -327,21 +353,23 @@ void PI::BusWrite<u32, false>(u32 addr, u32 val) {
mem.isviewer_sink << message;
mem.isviewer_sink.flush();
} else {
panic("ISViewer buffer size is emulated at {} bytes, but received a flush command for {} bytes!",
ircolib::panic(
"ISViewer buffer size is emulated at {} bytes, but received a flush command for {} bytes!",
CART_ISVIEWER_SIZE, val);
}
break;
}
default:
if (!WriteLatch(val)) [[unlikely]] {
warn("Couldn't latch PI bus, ignoring write to REGION_PI_ROM");
ircolib::warn("Couldn't latch PI bus, ignoring write to REGION_PI_ROM");
return;
}
warn("Writing word 0x{:08X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
ircolib::warn("Writing word 0x{:08X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
}
return;
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -359,24 +387,25 @@ auto PI::BusRead<u64, false>(u32 addr) -> u64 {
switch (addr) {
case REGION_PI_UNKNOWN:
panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", addr);
ircolib::panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", addr);
case REGION_PI_64DD_REG:
panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG", addr);
ircolib::panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_64DD_REG", addr);
case REGION_PI_64DD_ROM:
panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", addr);
ircolib::panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", addr);
case REGION_PI_SRAM:
panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_SRAM", addr);
ircolib::panic("Reading dword from address 0x{:08X} in unsupported region: REGION_PI_SRAM", addr);
case REGION_PI_ROM:
{
const u32 index = addr - SREGION_PI_ROM;
if (index > mem.rom.cart.size() - 7) { // -7 because we're reading an entire dword
panic("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM!", addr, index,
index);
ircolib::panic("Address 0x{:08X} accessed an index {}/0x{:X} outside the bounds of the ROM!", addr,
index, index);
}
return ircolib::ReadAccess<u64>(mem.rom.cart, index);
return ircolib::read_access<u64>(mem.rom.cart, index);
}
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -393,18 +422,22 @@ void PI::BusWrite<false>(u32 addr, u64 val) {
switch (addr) {
case REGION_PI_UNKNOWN:
panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val, addr);
ircolib::panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_UNKNOWN", val,
addr);
case REGION_PI_64DD_REG:
panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_REG", val, addr);
ircolib::panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_REG", val,
addr);
case REGION_PI_64DD_ROM:
panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val, addr);
ircolib::panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_64DD_ROM", val,
addr);
case REGION_PI_SRAM:
panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_SRAM", val, addr);
ircolib::panic("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_SRAM", val, addr);
case REGION_PI_ROM:
warn("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
ircolib::warn("Writing dword 0x{:016X} to address 0x{:08X} in unsupported region: REGION_PI_ROM", val, addr);
break;
default:
panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!", addr);
ircolib::panic("Should never end up here! Access to address {:08X} which did not match any PI bus regions!",
addr);
}
}
@@ -451,7 +484,7 @@ auto PI::Read(u32 addr) const -> u32 {
case 0x04600030:
return piBsdDom2Rls;
default:
panic("Unhandled PI[{:08X}] read", addr);
ircolib::panic("Unhandled PI[{:08X}] read", addr);
}
}
@@ -465,7 +498,7 @@ u8 PI::GetDomain(const u32 address) {
case REGION_PI_SRAM:
return 2;
default:
panic("Unknown PI domain for address {:08X}!", address);
ircolib::panic("Unknown PI domain for address {:08X}!", address);
}
}
@@ -490,7 +523,7 @@ u32 PI::AccessTiming(const u8 domain, const u32 length) const {
page_size = 1 << (piBsdDom2Pgs + 2);
break;
default:
panic("Unknown PI domain: {}\n", domain);
ircolib::panic("Unknown PI domain: {}\n", domain);
}
const uint32_t pages = static_cast<uint32_t>(ceil(static_cast<double>(length) / static_cast<double>(page_size)));
@@ -506,7 +539,7 @@ template <>
void PI::DMA<false>() {
n64::Mem &mem = n64::Core::GetMem();
const s32 len = rdLen + 1;
trace("PI DMA from RDRAM to CARTRIDGE (size: {} B, {:08X} to {:08X})", len, dramAddr, cartAddr);
ircolib::trace("PI DMA from RDRAM to CARTRIDGE (size: {} B, {:08X} to {:08X})", len, dramAddr, cartAddr);
if (mem.rom.saveType == SAVE_FLASH_1m && cartAddr >= SREGION_PI_SRAM && cartAddr < (CART_REGION_START_2_2 + 1_mb)) {
cartAddr = SREGION_PI_SRAM | ((cartAddr & (1_mb - 1)) << 1);
}
@@ -524,7 +557,7 @@ void PI::DMA<false>() {
dmaBusy = true;
u64 completo = AccessTiming(GetDomain(cartAddr), len);
trace("Will complete in {} cycles", completo);
ircolib::trace("Will complete in {} cycles", completo);
Scheduler::GetInstance().EnqueueRelative(completo, PI_DMA_COMPLETE);
}
@@ -533,7 +566,7 @@ template <>
void PI::DMA<true>() {
n64::Mem &mem = n64::Core::GetMem();
const s32 len = wrLen + 1;
trace("PI DMA from CARTRIDGE to RDRAM (size: {} B, {:08X} to {:08X})", len, cartAddr, dramAddr);
ircolib::trace("PI DMA from CARTRIDGE to RDRAM (size: {} B, {:08X} to {:08X})", len, cartAddr, dramAddr);
if (mem.rom.saveType == SAVE_FLASH_1m && cartAddr >= SREGION_PI_SRAM && cartAddr < (CART_REGION_START_2_2 + 1_mb)) {
cartAddr = SREGION_PI_SRAM | ((cartAddr & (1_mb - 1)) << 1);
@@ -551,7 +584,7 @@ void PI::DMA<true>() {
dmaBusy = true;
u64 completo = AccessTiming(GetDomain(cartAddr), len);
trace("Will complete in {} cycles", completo);
ircolib::trace("Will complete in {} cycles", completo);
Scheduler::GetInstance().EnqueueRelative(completo, PI_DMA_COMPLETE);
}
@@ -603,7 +636,7 @@ void PI::Write(u32 addr, u32 val) {
piBsdDom2Rls = val & 0xff;
break;
default:
panic("Unhandled PI[{:08X}] write ({:08X})", val, addr);
ircolib::panic("Unhandled PI[{:08X}] write ({:08X})", val, addr);
}
}
} // namespace n64
+24 -24
View File
@@ -2,7 +2,7 @@
#include <cassert>
#include <cic_nus_6105/n64_cic_nus_6105.hpp>
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <Options.hpp>
#define MEMPAK_SIZE 32768
@@ -17,14 +17,14 @@ void PIF::Reset() {
if (mempak.is_mapped()) {
mempak.sync(error);
if (error) {
panic("Could not sync {}", mempakPath);
ircolib::panic("Could not sync {}", mempakPath);
}
mempak.unmap();
}
if (eeprom.is_mapped()) {
eeprom.sync(error);
if (error) {
panic("Could not sync {}", eepromPath);
ircolib::panic("Could not sync {}", eepromPath);
}
eeprom.unmap();
}
@@ -48,25 +48,25 @@ void PIF::MaybeLoadMempak() {
if (mempak.is_mapped()) {
mempak.sync(error);
if (error) {
panic("Could not sync {}", mempakPath);
ircolib::panic("Could not sync {}", mempakPath);
}
mempak.unmap();
}
auto mempakVec = ircolib::ReadFileBinary(mempakPath);
auto mempakVec = ircolib::read_file_binary(mempakPath);
if (mempak.empty()) {
info(R"(Empty mempak, making one @ "{}" ...)", mempakPath);
ircolib::WriteFileBinary(std::array<u8, MEMPAK_SIZE>{}, mempakPath);
mempakVec = ircolib::ReadFileBinary(mempakPath);
ircolib::info(R"(Empty mempak, making one @ "{}" ...)", mempakPath);
ircolib::write_file_binary(std::array<u8, MEMPAK_SIZE>{}, mempakPath);
mempakVec = ircolib::read_file_binary(mempakPath);
}
if (mempakVec.size() != MEMPAK_SIZE) {
panic("Corrupt mempak!");
ircolib::panic("Corrupt mempak!");
}
mempak = mio::make_mmap_sink(mempakPath, error);
if (error) {
panic("Could not open {}", mempakPath);
ircolib::panic("Could not open {}", mempakPath);
}
mempakOpen = true;
}
@@ -85,7 +85,7 @@ FORCE_INLINE size_t GetSaveSize(SaveType saveType) {
case SAVE_FLASH_1m:
return 131072;
default:
panic("Unknown save type!");
ircolib::panic("Unknown save type!");
}
}
@@ -101,28 +101,28 @@ void PIF::LoadEeprom(const SaveType saveType, const std::string &path) {
if (eeprom.is_mapped()) {
eeprom.sync(error);
if (error) {
panic("Could not sync {}", eepromPath);
ircolib::panic("Could not sync {}", eepromPath);
}
eeprom.unmap();
}
eepromSize = GetSaveSize(saveType);
auto eepromVec = ircolib::ReadFileBinary(eepromPath);
auto eepromVec = ircolib::read_file_binary(eepromPath);
if (eepromVec.empty()) {
std::vector<u8> dummy{};
dummy.resize(GetSaveSize(saveType));
ircolib::WriteFileBinary(dummy, eepromPath);
ircolib::write_file_binary(dummy, eepromPath);
eepromVec = dummy;
}
if (eepromVec.size() != eepromSize) {
panic("Corrupt eeprom!");
ircolib::panic("Corrupt eeprom!");
}
eeprom = mio::make_mmap_sink(eepromPath, error);
if (error) {
panic("Could not open {}. Reason {}", eepromPath, error.message());
ircolib::panic("Could not open {}. Reason {}", eepromPath, error.message());
}
}
}
@@ -254,7 +254,7 @@ void PIF::ConfigureJoyBusFrame() {
}
break;
default:
panic("Invalid read RTC block {}", commandStart);
ircolib::panic("Invalid read RTC block {}", commandStart);
}
}
break;
@@ -262,7 +262,7 @@ void PIF::ConfigureJoyBusFrame() {
memset(res, 0, 8);
break;
default:
panic("Invalid PIF command: {:X}", commandIndex);
ircolib::panic("Invalid PIF command: {:X}", commandIndex);
}
i += commandLength + reslen;
@@ -351,12 +351,12 @@ void PIF::EepromRead(const u8 *cmd, u8 *res) const {
if (channel == 4) {
const u8 offset = cmd[3];
if ((offset * 8) >= GetSaveSize(mem.rom.saveType)) {
panic("Out of range EEPROM read! offset: {:02X}", offset);
ircolib::panic("Out of range EEPROM read! offset: {:02X}", offset);
}
std::copy_n(eeprom.begin() + offset * 8, 8, res);
} else {
panic("EEPROM read on bad channel {}", channel);
ircolib::panic("EEPROM read on bad channel {}", channel);
}
}
@@ -366,14 +366,14 @@ void PIF::EepromWrite(const u8 *cmd, u8 *res) {
if (channel == 4) {
const u8 offset = cmd[3];
if ((offset * 8) >= GetSaveSize(mem.rom.saveType)) {
panic("Out of range EEPROM write! offset: {:02X}", offset);
ircolib::panic("Out of range EEPROM write! offset: {:02X}", offset);
}
std::copy_n(cmd + 4, 8, eeprom.begin() + offset * 8);
res[0] = 0; // Error byte, I guess it always succeeds?
} else {
panic("EEPROM write on bad channel {}", channel);
ircolib::panic("EEPROM write on bad channel {}", channel);
}
}
@@ -384,7 +384,7 @@ void PIF::HLE(const bool pal, const CICType cicType) const {
switch (cicType) {
case UNKNOWN_CIC_TYPE:
warn("Unknown CIC type!");
ircolib::warn("Unknown CIC type!");
break;
case CIC_NUS_6101:
regs.Write<u64>(0, 0x0000000000000000);
@@ -651,7 +651,7 @@ void PIF::Execute() const {
mem.Write<u32>(PIF_RAM_REGION_START + 0x24, cicSeeds[cicType]);
switch (cicType) {
case UNKNOWN_CIC_TYPE:
warn("Unknown CIC type!");
ircolib::warn("Unknown CIC type!");
break;
case CIC_NUS_6101 ... CIC_NUS_6103_7103:
mem.Write<u32>(0x318, RDRAM_SIZE);
+2 -2
View File
@@ -1,7 +1,7 @@
#include <Netplay.hpp>
#include <PIF.hpp>
#include <PIF/MupenMovie.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
void PIF::InitDevices(SaveType saveType) {
@@ -72,7 +72,7 @@ void PIF::ControllerID(u8 *res) const {
break;
}
} else {
panic("Device ID on unknown channel {}", channel);
ircolib::panic("Device ID on unknown channel {}", channel);
}
}
+26 -29
View File
@@ -3,7 +3,6 @@
#include <File.hpp>
#include <PIF.hpp>
union TASMovieControllerData {
struct {
unsigned dpadRight : 1;
@@ -31,9 +30,9 @@ static_assert(sizeof(TASMovieControllerData) == 4);
void MupenMovie::Load(const fs::path &path) {
filename = path.stem().string();
loadedTasMovie = ircolib::ReadFileBinary(path.string());
loadedTasMovie = ircolib::read_file_binary(path.string());
if (!IsLoaded()) {
error("Error loading movie!");
ircolib::error("Error loading movie!");
return;
}
@@ -41,36 +40,34 @@ void MupenMovie::Load(const fs::path &path) {
if (loadedTasMovieHeader.signature[0] != 0x4D || loadedTasMovieHeader.signature[1] != 0x36 ||
loadedTasMovieHeader.signature[2] != 0x34 || loadedTasMovieHeader.signature[3] != 0x1A) {
error("Failed to load movie: incorrect signature. Are you sure this is a valid movie?");
ircolib::error("Failed to load movie: incorrect signature. Are you sure this is a valid movie?");
return;
}
if (loadedTasMovieHeader.version != 3) {
error("This movie is version {}: only version 3 is supported.", loadedTasMovieHeader.version);
ircolib::error("This movie is version {}: only version 3 is supported.", loadedTasMovieHeader.version);
return;
}
if (loadedTasMovieHeader.startType != 2) {
error("Movie start type is {} - only movies with a start type of 2 are supported (start at power on)",
ircolib::error("Movie start type is {} - only movies with a start type of 2 are supported (start at power on)",
loadedTasMovieHeader.startType);
return;
}
info("Loaded movie '{}' ", loadedTasMovieHeader.movie_description);
info("by {}", loadedTasMovieHeader.author_name);
info("{} controller(s) connected", loadedTasMovieHeader.numControllers);
ircolib::info("Loaded movie '{}' ", loadedTasMovieHeader.movie_description);
ircolib::info("by {}", loadedTasMovieHeader.author_name);
ircolib::info("{} controller(s) connected", loadedTasMovieHeader.numControllers);
if (loadedTasMovieHeader.numControllers != 1) {
error("Currently, only movies with 1 controller connected are supported.");
ircolib::error("Currently, only movies with 1 controller connected are supported.");
return;
}
loadedTasMovieIndex = sizeof(TASMovieHeader) - 4; // skip header
}
MupenMovie::MupenMovie(const fs::path &path) {
Load(path);
}
MupenMovie::MupenMovie(const fs::path &path) { Load(path); }
void MupenMovie::Reset() {
if (!IsLoaded())
@@ -80,22 +77,22 @@ void MupenMovie::Reset() {
}
FORCE_INLINE void LogController(const n64::Controller &controller) {
debug("c_right: {}", controller.cRight);
debug("c_left: {}", controller.cLeft);
debug("c_down: {}", controller.cDown);
debug("c_up: {}", controller.cUp);
debug("r: {}", controller.r);
debug("l: {}", controller.l);
debug("dp_right: {}", controller.dpRight);
debug("dp_left: {}", controller.dpLeft);
debug("dp_down: {}", controller.dpDown);
debug("dp_up: {}", controller.dpUp);
debug("z: {}", controller.z);
debug("b: {}", controller.b);
debug("a: {}", controller.a);
debug("start: {}", controller.start);
debug("joy_x: {}", controller.joyX);
debug("joy_y: {}", controller.joyY);
ircolib::debug("c_right: {}", controller.cRight);
ircolib::debug("c_left: {}", controller.cLeft);
ircolib::debug("c_down: {}", controller.cDown);
ircolib::debug("c_up: {}", controller.cUp);
ircolib::debug("r: {}", controller.r);
ircolib::debug("l: {}", controller.l);
ircolib::debug("dp_right: {}", controller.dpRight);
ircolib::debug("dp_left: {}", controller.dpLeft);
ircolib::debug("dp_down: {}", controller.dpDown);
ircolib::debug("dp_up: {}", controller.dpUp);
ircolib::debug("z: {}", controller.z);
ircolib::debug("b: {}", controller.b);
ircolib::debug("a: {}", controller.a);
ircolib::debug("start: {}", controller.start);
ircolib::debug("joy_x: {}", controller.joyX);
ircolib::debug("joy_y: {}", controller.joyY);
}
n64::Controller MupenMovie::NextInputs() {
+3 -3
View File
@@ -1,5 +1,5 @@
#include <core/mmio/RI.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
RI::RI() { Reset(); }
@@ -22,7 +22,7 @@ auto RI::Read(u32 addr) const -> u32 {
case 0x04700010:
return refresh;
default:
panic("Unhandled RI[{:08X}] read", addr);
ircolib::panic("Unhandled RI[{:08X}] read", addr);
}
}
@@ -41,7 +41,7 @@ void RI::Write(u32 addr, u32 val) {
refresh = val;
break;
default:
panic("Unhandled RI[{:08X}] write with val {:08X}", addr, val);
ircolib::panic("Unhandled RI[{:08X}] write with val {:08X}", addr, val);
}
}
} // namespace n64
+4 -4
View File
@@ -32,7 +32,7 @@ auto SI::Read(u32 addr) const -> u32 {
return val;
}
default:
panic("Unhandled SI[{:08X}] read", addr);
ircolib::panic("Unhandled SI[{:08X}] read", addr);
}
}
@@ -44,7 +44,7 @@ void SI::DMA<true>() {
for (int i = 0; i < 64; i++) {
mem.mmio.rdp.WriteRDRAM<u8>(dramAddr + i, pif.Read(pifAddr + i));
}
trace("SI DMA from PIF RAM to RDRAM ({:08X} to {:08X})", pifAddr, dramAddr);
ircolib::trace("SI DMA from PIF RAM to RDRAM ({:08X} to {:08X})", pifAddr, dramAddr);
}
// rdram -> pif
@@ -54,7 +54,7 @@ void SI::DMA<false>() {
for (int i = 0; i < 64; i++) {
pif.Write(pifAddr + i, mem.mmio.rdp.ReadRDRAM<u8>(dramAddr + i));
}
trace("SI DMA from RDRAM to PIF RAM ({:08X} to {:08X})", dramAddr, pifAddr);
ircolib::trace("SI DMA from RDRAM to PIF RAM ({:08X} to {:08X})", dramAddr, pifAddr);
}
void SI::DMA() {
@@ -89,7 +89,7 @@ void SI::Write(u32 addr, u32 val) {
mem.mmio.mi.InterruptLower(MI::Interrupt::SI);
break;
default:
panic("Unhandled SI[{:08X}] write ({:08X})", addr, val);
ircolib::panic("Unhandled SI[{:08X}] write ({:08X})", addr, val);
}
}
} // namespace n64
+3 -3
View File
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
VI::VI() { Reset(); }
@@ -55,7 +55,7 @@ u32 VI::Read(const u32 paddr) const {
default:
{
n64::Registers &regs = n64::Core::GetRegs();
panic("32-bit read access on unhandled VI register @ pc 0x{:016X}", u64(regs.oldPC));
ircolib::panic("32-bit read access on unhandled VI register @ pc 0x{:016X}", u64(regs.oldPC));
return 0;
}
}
@@ -120,7 +120,7 @@ void VI::Write(const u32 paddr, const u32 val) {
case 0x0440003C:
break;
default:
panic("Unimplemented VI[{:08X}] write ({:08X})", paddr, val);
ircolib::panic("Unimplemented VI[{:08X}] write ({:08X})", paddr, val);
}
}
} // namespace n64
+32 -32
View File
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
Cop0::Cop0() { Reset(); }
@@ -103,7 +103,7 @@ u32 Cop0::GetReg32(const u8 addr) {
case 31:
return openbus;
default:
panic("Unsupported word read from COP0 register {}", addr);
ircolib::panic("Unsupported word read from COP0 register {}", addr);
}
}
@@ -140,7 +140,7 @@ u64 Cop0::GetReg64(const u8 addr) const {
case 31:
return openbus;
default:
panic("Unsupported dword read from COP0 register {}", addr);
ircolib::panic("Unsupported dword read from COP0 register {}", addr);
}
}
@@ -236,7 +236,7 @@ void Cop0::SetReg32(const u8 addr, const u32 value) {
case 31:
break;
default:
panic("Unsupported word write from COP0 register {}", addr);
ircolib::panic("Unsupported word write from COP0 register {}", addr);
}
}
@@ -281,7 +281,7 @@ void Cop0::SetReg64(const u8 addr, const u64 value) {
ErrorEPC = (s64)value;
break;
default:
panic("Unsupported dword write to COP0 register {}", addr);
ircolib::panic("Unsupported dword write to COP0 register {}", addr);
}
}
@@ -387,7 +387,7 @@ void Cop0::FireException(const ExceptionCode code, const int cop, s64 pc) {
}
if (status.bev) {
panic("BEV bit set!");
ircolib::panic("BEV bit set!");
}
regs.SetPC32(s32(0x80000000 + vectorOffset));
@@ -408,7 +408,7 @@ void Cop0::HandleTLBException(const u64 vaddr) {
Cop0::ExceptionCode Cop0::GetTLBExceptionCode(const TLBError error, const TLBAccessType accessType) {
switch (error) {
case NONE:
panic("Getting TLB exception with error NONE");
ircolib::panic("Getting TLB exception with error NONE");
case INVALID:
case MISS:
return accessType == LOAD ? ExceptionCode::TLBLoad : ExceptionCode::TLBStore;
@@ -417,7 +417,7 @@ Cop0::ExceptionCode Cop0::GetTLBExceptionCode(const TLBError error, const TLBAcc
case DISALLOWED_ADDRESS:
return accessType == LOAD ? ExceptionCode::AddressErrorLoad : ExceptionCode::AddressErrorStore;
default:
panic("Getting TLB exception for unknown error code! ({})", static_cast<u8>(error));
ircolib::panic("Getting TLB exception for unknown error code! ({})", static_cast<u8>(error));
return {};
}
}
@@ -459,14 +459,14 @@ void Cop0::decode(const Instruction instr) {
}
break;
default:
panic("Unimplemented COP0 instruction {}", instr.cop_rs());
ircolib::panic("Unimplemented COP0 instruction {}", instr.cop_rs());
}
}
template <>
bool Cop0::MapVirtualAddress<u32, true>(const TLBAccessType accessType, const u64 vaddr, u32 &paddr) {
if (ircolib::IsInsideRange(vaddr, START_VREGION_KUSEG, END_VREGION_KUSEG))
if (ircolib::is_inside_range(vaddr, START_VREGION_KUSEG, END_VREGION_KUSEG))
return ProbeTLB(accessType, s64(s32(vaddr)), paddr);
tlbError = DISALLOWED_ADDRESS;
@@ -476,25 +476,25 @@ bool Cop0::MapVirtualAddress<u32, true>(const TLBAccessType accessType, const u6
template <>
bool Cop0::MapVirtualAddress<u32, false>(const TLBAccessType accessType, const u64 vaddr, u32 &paddr) {
u8 segment = static_cast<u32>(vaddr) >> 29 & 7;
if (ircolib::IsInsideRange(segment, 0, 3) || segment == 7)
if (ircolib::is_inside_range(segment, 0, 3) || segment == 7)
return ProbeTLB(accessType, static_cast<s32>(vaddr), paddr);
if (ircolib::IsInsideRange(segment, 4, 5)) {
if (ircolib::is_inside_range(segment, 4, 5)) {
paddr = vaddr & 0x1FFFFFFF;
return true;
}
if (segment == 6)
panic("Unimplemented virtual mapping in KSSEG! ({:08X})", vaddr);
ircolib::panic("Unimplemented virtual mapping in KSSEG! ({:08X})", vaddr);
panic("Should never end up in base case in MapVirtualAddress! ({:08X})", vaddr);
ircolib::panic("Should never end up in base case in MapVirtualAddress! ({:08X})", vaddr);
return false;
}
template <>
bool Cop0::MapVirtualAddress<u64, true>(const TLBAccessType accessType, const u64 vaddr, u32 &paddr) {
if (ircolib::IsInsideRange(vaddr, 0x0000000000000000, 0x000000FFFFFFFFFF))
if (ircolib::is_inside_range(vaddr, 0x0000000000000000, 0x000000FFFFFFFFFF))
return ProbeTLB(accessType, vaddr, paddr);
tlbError = DISALLOWED_ADDRESS;
@@ -503,19 +503,19 @@ bool Cop0::MapVirtualAddress<u64, true>(const TLBAccessType accessType, const u6
template <>
bool Cop0::MapVirtualAddress<u64, false>(const TLBAccessType accessType, const u64 vaddr, u32 &paddr) {
if (ircolib::IsInsideRange(vaddr, 0x0000000000000000, 0x000000FFFFFFFFFF) || // VREGION_XKUSEG
ircolib::IsInsideRange(vaddr, 0x4000000000000000, 0x400000FFFFFFFFFF) || // VREGION_XKSSEG
ircolib::IsInsideRange(vaddr, 0xC000000000000000, 0xC00000FF7FFFFFFF) || // VREGION_XKSEG
ircolib::IsInsideRange(vaddr, 0xFFFFFFFFE0000000, 0xFFFFFFFFFFFFFFFF)) // VREGION_CKSEG3
if (ircolib::is_inside_range(vaddr, 0x0000000000000000, 0x000000FFFFFFFFFF) || // VREGION_XKUSEG
ircolib::is_inside_range(vaddr, 0x4000000000000000, 0x400000FFFFFFFFFF) || // VREGION_XKSSEG
ircolib::is_inside_range(vaddr, 0xC000000000000000, 0xC00000FF7FFFFFFF) || // VREGION_XKSEG
ircolib::is_inside_range(vaddr, 0xFFFFFFFFE0000000, 0xFFFFFFFFFFFFFFFF)) // VREGION_CKSEG3
return ProbeTLB(accessType, vaddr, paddr);
if (ircolib::IsInsideRange(vaddr, 0x8000000000000000, 0xBFFFFFFFFFFFFFFF)) { // VREGION_XKPHYS
if (ircolib::is_inside_range(vaddr, 0x8000000000000000, 0xBFFFFFFFFFFFFFFF)) { // VREGION_XKPHYS
if (!kernelMode)
panic("Access to XKPHYS address 0x{:016X} when outside kernel mode!", vaddr);
ircolib::panic("Access to XKPHYS address 0x{:016X} when outside kernel mode!", vaddr);
const u8 high_two_bits = (vaddr >> 62) & 0b11;
if (high_two_bits != 0b10)
panic("Access to XKPHYS address 0x{:016X} with high two bits != 0b10!", vaddr);
ircolib::panic("Access to XKPHYS address 0x{:016X} with high two bits != 0b10!", vaddr);
const u8 subsegment = (vaddr >> 59) & 0b11;
bool cached = subsegment != 2; // do something with this eventually
@@ -530,31 +530,31 @@ bool Cop0::MapVirtualAddress<u64, false>(const TLBAccessType accessType, const u
return true;
}
if (ircolib::IsInsideRange(vaddr, 0xFFFFFFFF80000000, 0xFFFFFFFF9FFFFFFF) || // VREGION_CKSEG0
ircolib::IsInsideRange(vaddr, 0xFFFFFFFFA0000000, 0xFFFFFFFFBFFFFFFF)) { // VREGION_CKSEG1
if (ircolib::is_inside_range(vaddr, 0xFFFFFFFF80000000, 0xFFFFFFFF9FFFFFFF) || // VREGION_CKSEG0
ircolib::is_inside_range(vaddr, 0xFFFFFFFFA0000000, 0xFFFFFFFFBFFFFFFF)) { // VREGION_CKSEG1
u32 cut = u32(vaddr) >> 28;
u32 num = cut == 0xA;
// Identical to ksegX in 32 bit mode.
// Unmapped translation. Subtract the base address of the space to get the physical address.
paddr = vaddr - (cut << 28); // Implies cutting off the high 32 bits
trace("CKSEG{}: Translated 0x{:016X} to 0x{:08X}", num, vaddr, paddr);
ircolib::trace("CKSEG{}: Translated 0x{:016X} to 0x{:08X}", num, vaddr, paddr);
return true;
}
if (ircolib::IsInsideRange(vaddr, 0x0000010000000000, 0x3FFFFFFFFFFFFFFF) || // VREGION_XBAD1
ircolib::IsInsideRange(vaddr, 0x4000010000000000, 0x7FFFFFFFFFFFFFFF) || // VREGION_XBAD2
ircolib::IsInsideRange(vaddr, 0xC00000FF80000000, 0xFFFFFFFF7FFFFFFF)) { // VREGION_XBAD3
if (ircolib::is_inside_range(vaddr, 0x0000010000000000, 0x3FFFFFFFFFFFFFFF) || // VREGION_XBAD1
ircolib::is_inside_range(vaddr, 0x4000010000000000, 0x7FFFFFFFFFFFFFFF) || // VREGION_XBAD2
ircolib::is_inside_range(vaddr, 0xC00000FF80000000, 0xFFFFFFFF7FFFFFFF)) { // VREGION_XBAD3
tlbError = DISALLOWED_ADDRESS;
return false;
}
panic("Resolving virtual address 0x{:016X} in 64 bit mode", vaddr);
ircolib::panic("Resolving virtual address 0x{:016X} in 64 bit mode", vaddr);
return false; // just to silence warning
}
bool Cop0::MapVAddr(const TLBAccessType accessType, const u64 vaddr, u32 &paddr) {
if (supervisorMode)
panic("Supervisor mode memory access");
ircolib::panic("Supervisor mode memory access");
if (is64BitAddressing) [[unlikely]] {
if (kernelMode) [[likely]]
@@ -562,7 +562,7 @@ bool Cop0::MapVAddr(const TLBAccessType accessType, const u64 vaddr, u32 &paddr)
if (userMode)
return MapVirtualAddress<u64, true>(accessType, vaddr, paddr);
panic("Unknown mode! This should never happen!");
ircolib::panic("Unknown mode! This should never happen!");
}
if (kernelMode) [[likely]]
@@ -570,6 +570,6 @@ bool Cop0::MapVAddr(const TLBAccessType accessType, const u64 vaddr, u32 &paddr)
if (userMode)
return MapVirtualAddress<u32, true>(accessType, vaddr, paddr);
panic("Unknown mode! This should never happen!");
ircolib::panic("Unknown mode! This should never happen!");
}
} // namespace n64
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include <common.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <unordered_map>
#include <Instruction.hpp>
+2 -2
View File
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
Cop1::Cop1() { Reset(); }
@@ -284,7 +284,7 @@ void Cop1::decode(const Instruction instr) {
}
break;
default:
panic("Unimplemented COP1 instruction {}", instr.cop_rs());
ircolib::panic("Unimplemented COP1 instruction {}", instr.cop_rs());
}
}
} // namespace n64
+10 -10
View File
@@ -1,5 +1,5 @@
#include <Core.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
void RSP::special(const Instruction instr) {
@@ -66,7 +66,7 @@ void RSP::special(const Instruction instr) {
sltu(instr);
break;
default:
panic("Unhandled RSP special instruction ({:06b})", instr.cop_funct());
ircolib::panic("Unhandled RSP special instruction ({:06b})", instr.cop_funct());
}
}
@@ -85,7 +85,7 @@ void RSP::regimm(const Instruction instr) {
blink(instr, gpr[instr.rs()] >= 0);
break;
default:
panic("Unhandled RSP regimm instruction ({:05b})", instr.cop_rt());
ircolib::panic("Unhandled RSP regimm instruction ({:05b})", instr.cop_rt());
}
}
@@ -127,7 +127,7 @@ void RSP::lwc2(const Instruction instr) {
ltv(instr);
break;
default:
panic("Unhandled RSP LWC2 {:05b}", instr.rd());
ircolib::panic("Unhandled RSP LWC2 {:05b}", instr.rd());
}
}
@@ -170,7 +170,7 @@ void RSP::swc2(const Instruction instr) {
stv(instr);
break;
default:
panic("Unhandled RSP SWC2 {:05b}", instr.rd());
ircolib::panic("Unhandled RSP SWC2 {:05b}", instr.rd());
}
}
@@ -194,7 +194,7 @@ void RSP::cop2(const Instruction instr) {
ctc2(instr);
break;
default:
panic("Unhandled RSP COP2 sub ({:05b})", instr.cop_rs());
ircolib::panic("Unhandled RSP COP2 sub ({:05b})", instr.cop_rs());
}
}
break;
@@ -339,7 +339,7 @@ void RSP::cop2(const Instruction instr) {
case 0x3F:
break;
default:
panic("Unhandled RSP COP2 ({:06b})", instr.cop_funct());
ircolib::panic("Unhandled RSP COP2 ({:06b})", instr.cop_funct());
}
}
@@ -353,10 +353,10 @@ void RSP::cop0(const Instruction instr) {
mtc0(instr);
break;
default:
panic("Unhandled RSP COP0 ({:05b})", instr.cop_rs());
ircolib::panic("Unhandled RSP COP0 ({:05b})", instr.cop_rs());
}
} else {
panic("RSP COP0 unknown {:08X}", u32(instr));
ircolib::panic("RSP COP0 unknown {:08X}", u32(instr));
}
}
@@ -450,7 +450,7 @@ void RSP::Exec(const Instruction instr) {
break;
default:
mem.DumpIMEM();
panic("Unhandled RSP instruction ({:06b}, {:04X})", instr.opcode(), oldPC);
ircolib::panic("Unhandled RSP instruction ({:06b}, {:04X})", instr.opcode(), oldPC);
}
}
} // namespace n64
+5 -5
View File
@@ -1,7 +1,7 @@
#include <Core.hpp>
#include <RCP.hpp>
#include <RSQ.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
namespace n64 {
FORCE_INLINE bool AcquireSemaphore(RSP &rsp) {
@@ -57,7 +57,7 @@ FORCE_INLINE auto GetCop0Reg(RSP &rsp, const RDP &rdp, const u8 index) -> u32 {
case 15:
return rdp.dpc.status.tmemBusy;
default:
panic("Unhandled RSP COP0 register read at index {}", index);
ircolib::panic("Unhandled RSP COP0 register read at index {}", index);
return 0;
}
}
@@ -88,7 +88,7 @@ FORCE_INLINE void SetCop0Reg(Mem &mem, const u8 index, const u32 val) {
if (val == 0) {
ReleaseSemaphore(rsp);
} else {
panic("Write with non-zero value to RSP_COP0_RESERVED ({})", val);
ircolib::panic("Write with non-zero value to RSP_COP0_RESERVED ({})", val);
}
break;
case 8:
@@ -101,7 +101,7 @@ FORCE_INLINE void SetCop0Reg(Mem &mem, const u8 index, const u32 val) {
rdp.WriteStatus(val);
break;
default:
panic("Unhandled RSP COP0 register write at index {}", index);
ircolib::panic("Unhandled RSP COP0 register write at index {}", index);
}
}
@@ -931,7 +931,7 @@ void RSP::vmov(const Instruction instr) {
se = (e & 0b111) | (vs & 0b000);
break;
default:
panic("VMOV: This should be unreachable!");
ircolib::panic("VMOV: This should be unreachable!");
}
const u8 de = vs & 7;
+3 -3
View File
@@ -14,9 +14,9 @@ void EmuThread::run() {
const auto index = e.gdevice.which;
gamepad = SDL_OpenGamepad(index);
warn("Found controller!");
warn("Name: {}", SDL_GetGamepadName(gamepad));
warn("Vendor: {}", SDL_GetGamepadVendor(gamepad));
ircolib::warn("Found controller!");
ircolib::warn("Name: {}", SDL_GetGamepadName(gamepad));
ircolib::warn("Vendor: {}", SDL_GetGamepadVendor(gamepad));
}
}
+1 -19
View File
@@ -36,26 +36,8 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
connect(romsListTable, &RomsListTable::cleared, this, [&] { centralWidget->setCurrentWidget(romPathNotSet); });
connect(romsListTable, &RomsListTable::populateFinished, this, [&] {
for (int i = 0; i < romsListTable->size(); i++) {
const auto &[countryCode, version, _, name, regions, lastPlayed, timePlayed] = (*romsListTable)[i];
romsListTable->insertRow(i);
romsListTable->setItem(
i, 0,
new QTableWidgetItem(
std::format("{} ({}) (Rev {})", name, n64::GameDB::regionCodeToReadable(countryCode), version)
.c_str()));
romsListTable->setItem(i, 1, new QTableWidgetItem(regions.c_str()));
romsListTable->setItem(i, 2, new QTableWidgetItem(lastPlayed.c_str()));
romsListTable->setItem(i, 3, new QTableWidgetItem(timePlayed.c_str()));
}
romsListTable->resizeRowsToContents();
centralWidget->setCurrentWidget(romsListTable);
});
connect(romsListTable, &QTableWidget::cellDoubleClicked, this,
[&](int row, int) { LoadROM((*romsListTable)[row].path); });
[&](int row, int) { LoadROM(romsListTable->GetPathForClickedCell(row)); });
installEventFilter(this);
+2 -2
View File
@@ -16,7 +16,7 @@ static CompositorCategory GetOSCompositorCategory() {
if (platform_name == QStringLiteral("cocoa") || platform_name == QStringLiteral("ios"))
return CompositorCategory::MacOS;
warn("Unknown Qt platform!");
ircolib::warn("Unknown Qt platform!");
return CompositorCategory::Windows;
}
@@ -34,7 +34,7 @@ RenderWidget::RenderWidget() {
}
if (!Vulkan::Context::init_loader(nullptr)) {
panic("Could not initialize Vulkan ICD");
ircolib::panic("Could not initialize Vulkan ICD");
}
qtVkInstanceFactory = std::make_unique<QtInstanceFactory>();
+18 -16
View File
@@ -13,38 +13,31 @@ RomsListTable::RomsListTable(GeneralSettings *general) {
setSelectionBehavior(QAbstractItemView::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSortingEnabled(true);
setColumnCount(4);
setColumnCount(5);
setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
setHorizontalHeaderItem(1, new QTableWidgetItem("Regions"));
setHorizontalHeaderItem(2, new QTableWidgetItem("Last played"));
setHorizontalHeaderItem(3, new QTableWidgetItem("Time played"));
setHorizontalHeaderItem(4, new QTableWidgetItem("__path__"));
hideColumn(4);
connect(general, &GeneralSettings::romFolderSelected, this, [&] {
std::thread popThread([&] {
populate(Options::GetRomsPath());
emit populateFinished();
});
std::thread popThread([&] { populate(Options::GetRomsPath()); });
popThread.detach();
});
connect(general, &GeneralSettings::romFolderCleared, this, [&] {
for (int i = 0; i < rowCount(); i++)
removeRow(i);
romsList = {};
clearContents();
emit cleared();
});
std::thread popThread([&] {
populate(Options::GetRomsPath());
emit populateFinished();
});
std::thread popThread([&] { populate(Options::GetRomsPath()); });
popThread.detach();
}
void RomsListTable::populate(const std::string &romsPath) {
if (!romsPath.empty()) {
int i = 0;
for (const auto &file : fs::recursive_directory_iterator{romsPath}) {
if (!file.is_regular_file())
continue;
@@ -67,8 +60,17 @@ void RomsListTable::populate(const std::string &romsPath) {
if (rom.gameNameDB.empty())
rom.gameNameDB = fs::path(filename).stem().string();
romsList.push_back(
{rom.header.countryCode, rom.header.version, filename, rom.gameNameDB, regions, "Never", "0h 00m 00s"});
insertRow(i);
setItem(i, 0,
new QTableWidgetItem(std::format("{} ({}) (Rev {})", rom.gameNameDB,
n64::GameDB::regionCodeToReadable(rom.header.countryCode),
rom.header.version)
.c_str()));
setItem(i, 1, new QTableWidgetItem(regions.c_str()));
setItem(i, 2, new QTableWidgetItem("Never"));
setItem(i, 3, new QTableWidgetItem("0h 0m 0s"));
setItem(i, 4, new QTableWidgetItem(filename.c_str()));
i++;
}
}
}
+2 -4
View File
@@ -19,14 +19,12 @@ class RomsListTable : public QTableWidget {
void populate(const std::string &);
public:
std::vector<RomsListEntry> romsList;
RomsListTable(GeneralSettings *);
size_t size() { return romsList.size(); }
size_t size() { return rowCount(); }
RomsListEntry &operator[](const size_t i) { return romsList[i]; }
std::string GetPathForClickedCell(int i) const { return item(i, 4)->text().toStdString(); }
signals:
void populateFinished();
void cleared();
};
+1 -1
View File
@@ -1,6 +1,6 @@
#include <CPUSettings.hpp>
#include <Options.hpp>
#include <log.hpp>
#include <ircolib/log.hpp>
CPUSettings::CPUSettings() : settings(QSettings::UserScope) {
types = new QComboBox();
+1 -1
View File
@@ -2,7 +2,7 @@
#include <Options.hpp>
#include <QFileDialog>
#include <QCoreApplication>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <QPushButton>
GeneralSettings::GeneralSettings() : settings(QSettings::UserScope) {
-6
View File
@@ -1,11 +1,5 @@
#pragma once
#include <ircolib/types.hpp>
#ifdef USE_NEON
#include <sse2neon.h>
#else
#include <emmintrin.h>
#include <smmintrin.h>
#endif
using u8 = ircolib::u8;
using u16 = ircolib::u16;
+8 -7
View File
@@ -4,8 +4,8 @@
namespace Util {
std::vector<u8> OpenROM(const std::string &filename, size_t &sizeAdjusted) {
auto buf = ircolib::ReadFileBinary(filename);
sizeAdjusted = ircolib::NextPow2(buf.size());
auto buf = ircolib::read_file_binary(filename);
sizeAdjusted = ircolib::next_pow2(buf.size());
return buf;
}
@@ -13,7 +13,7 @@ std::vector<u8> 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?");
ircolib::panic("Could not open archive! Are you sure it's an archive?");
}
ar_archive *archive = ar_open_zip_archive(stream, false);
@@ -27,7 +27,8 @@ std::vector<u8> OpenArchive(const std::string &path, size_t &sizeAdjusted) {
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)");
ircolib::panic(
"Could not open archive! Are you sure it's a supported archive? (7z, zip, rar and tar are supported)");
}
std::vector<u8> buf{};
@@ -40,7 +41,7 @@ std::vector<u8> OpenArchive(const std::string &path, size_t &sizeAdjusted) {
if (std::ranges::any_of(rom_exts, [&](const auto &x) { return extension == x; })) {
const auto size = ar_entry_get_size(archive);
sizeAdjusted = ircolib::NextPow2(size);
sizeAdjusted = ircolib::next_pow2(size);
buf.resize(sizeAdjusted);
ar_entry_uncompress(archive, buf.data(), size);
break;
@@ -48,11 +49,11 @@ std::vector<u8> OpenArchive(const std::string &path, size_t &sizeAdjusted) {
ar_close_archive(archive);
ar_close(stream);
panic("Could not find any rom image in the archive!");
ircolib::panic("Could not find any rom image in the archive!");
}
ar_close_archive(archive);
ar_close(stream);
return buf;
}
}
} // namespace Util
+2 -1
View File
@@ -1,9 +1,10 @@
#pragma once
#include <fstream>
#include <log.hpp>
#include <ircolib/log.hpp>
#include <vector>
#include <filesystem>
#include <ircolib/file.hpp>
#include <types.hpp>
namespace fs = std::filesystem;
-67
View File
@@ -1,67 +0,0 @@
#pragma once
#include <common.hpp>
#include <print>
#include <string>
#if !defined(NDEBUG) && !defined(_WIN32)
#include <dlfcn.h>
#endif
namespace Util {
enum LogLevel : u8 { Trace, Debug, Info, Warn, Error, Always };
#ifndef NDEBUG
static constexpr auto globalLogLevel = Debug;
#else
static constexpr auto globalLogLevel = Warn;
#endif
template <LogLevel messageType = Info, class... Args>
void print(const std::format_string<Args...> fmt, Args... args) {
if (messageType >= globalLogLevel) {
if (messageType <= Debug) {
#ifndef NDEBUG
std::println(fmt, std::forward<Args>(args)...);
#endif
} else {
std::println(fmt, std::forward<Args>(args)...);
}
}
}
#define panic(fmt, ...) \
do { \
Util::print<Util::Error>("[FATAL] " fmt __VA_OPT__(, ) __VA_ARGS__); \
exit(-1); \
} \
while (0)
#define error(fmt, ...) \
do { \
Util::print<Util::Error>("[ERROR] " fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
while (0)
#define warn(fmt, ...) \
do { \
Util::print<Util::Warn>("[WARN] " fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
while (0)
#define info(fmt, ...) \
do { \
Util::print<Util::Info>("[INFO] " fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
while (0)
#define debug(fmt, ...) \
do { \
Util::print<Util::Debug>("[DEBUG] " fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
while (0)
#define trace(fmt, ...) \
do { \
Util::print<Util::Trace>("[TRACE] " fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
while (0)
#define always(fmt, ...) \
do { \
Util::print<Util::Always>(fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
while (0)
} // namespace Util