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:
+148
-144
@@ -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 ®s = 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 ®s = 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 ®s = 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 ®s = 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 ®s = 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 ®s = 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 ®s = 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 ®s = 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
|
||||
|
||||
Reference in New Issue
Block a user