Core: Handle rom written to better

This commit is contained in:
zilmar 2022-08-01 10:15:56 +09:30
parent d6a217ca86
commit cffeceef70
4 changed files with 28 additions and 23 deletions

View File

@ -1,8 +1,10 @@
#include "stdafx.h"
#include "CartridgeDomain1Address1Handler.h"
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64Rom.h>
CartridgeDomain1Address1Handler::CartridgeDomain1Address1Handler(CN64Rom * DDRom) :
CartridgeDomain1Address1Handler::CartridgeDomain1Address1Handler(CRegisters & Reg, CN64Rom * DDRom) :
m_Reg(Reg),
m_DDRom(DDRom != nullptr ? DDRom->GetRomAddress() : nullptr),
m_DDRomSize(DDRom != nullptr ? DDRom->GetRomSize() : 0)
{
@ -16,6 +18,7 @@ bool CartridgeDomain1Address1Handler::Read32(uint32_t Address, uint32_t & Value)
}
else
{
m_Reg.PI_CART_ADDR_REG = (Address + 4) & ~1;
Value = ((Address & 0xFFFF) << 16) | (Address & 0xFFFF);
}
return true;

View File

@ -1,13 +1,14 @@
#pragma once
#include "MemoryHandler.h"
class CRegisters;
class CN64Rom;
class CartridgeDomain1Address1Handler :
public MemoryHandler
{
public:
CartridgeDomain1Address1Handler(CN64Rom * DDRom);
CartridgeDomain1Address1Handler(CRegisters & Reg, CN64Rom * DDRom);
bool Read32(uint32_t Address, uint32_t & Value);
bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask);
@ -17,6 +18,7 @@ private:
CartridgeDomain1Address1Handler(const CartridgeDomain1Address1Handler &);
CartridgeDomain1Address1Handler & operator=(const CartridgeDomain1Address1Handler &);
CRegisters & m_Reg;
uint32_t m_DDRomSize;
uint8_t * m_DDRom;
};

View File

@ -18,43 +18,43 @@ RomMemoryHandler::RomMemoryHandler(CN64System & System, CRegisters & Reg, CN64Ro
bool RomMemoryHandler::Read32(uint32_t Address, uint32_t & Value)
{
uint32_t ReadAddr = (Address + 2) & ~0x3;
if (g_DDRom == nullptr)
{
m_Reg.PI_CART_ADDR_REG = Address + 4;
m_Reg.PI_CART_ADDR_REG = (Address + 4) & ~1;
}
if (m_RomWrittenTo)
{
Value = m_RomWroteValue;
//LogMessage("%X: Read crap from ROM %08X from %08X",PROGRAM_COUNTER,*Value,PAddr);
m_RomWrittenTo = false;
}
else if ((Address & 0xFFFFFFF) < m_Rom.GetRomSize())
{
Value = *(uint32_t *)&m_Rom.GetRomAddress()[(Address & 0xFFFFFFF)];
}
else
Value = *(uint32_t *)&m_Rom.GetRomAddress()[(ReadAddr & 0xFFFFFFF)];
if (LogRomHeader() && (ReadAddr & 0x1FFFFFFF) >= 0x10000000 && (ReadAddr & 0x1FFFFFFF) < 0x10000040)
{
Value = (Address << 16) | (Address & 0xFFFF);
}
if (LogRomHeader() && (Address & 0x1FFFFFFF) >= 0x10000000 && (Address & 0x1FFFFFFF) < 0x10000040)
{
switch (Address & 0x1FFFFFFF)
switch (ReadAddr & 0x1FFFFFFF)
{
case 0x10000004: LogMessage("%08X: read from ROM clock rate (%08X)", m_PC, Value); break;
case 0x10000008: LogMessage("%08X: read from ROM boot address offset (%08X)", m_PC, Value); break;
case 0x1000000C: LogMessage("%08X: read from ROM release offset (%08X)", m_PC, Value); break;
case 0x10000010: LogMessage("%08X: read from ROM CRC1 (%08X)", m_PC, Value); break;
case 0x10000014: LogMessage("%08X: read from ROM CRC2 (%08X)", m_PC, Value); break;
default: LogMessage("%08X: read from ROM header 0x%X (%08X)", m_PC, Address & 0xFF, Value); break;
default: LogMessage("%08X: read from ROM header 0x%X (%08X)", m_PC, ReadAddr & 0xFF, Value); break;
}
}
}
else
{
Value = (Address << 16) | (Address & 0xFFFF);
}
return true;
}
bool RomMemoryHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask)
bool RomMemoryHandler::Write32(uint32_t /*Address*/, uint32_t Value, uint32_t Mask)
{
if (((Address & 0x1FFFFFFF) - 0x10000000) < m_Rom.GetRomSize())
if (!m_RomWrittenTo)
{
m_RomWrittenTo = true;
m_RomWroteValue = (Value & Mask);

View File

@ -22,7 +22,7 @@ CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) :
m_System(System),
m_Reg(System.m_Reg),
m_AudioInterfaceHandler(System, System.m_Reg),
m_CartridgeDomain1Address1Handler(g_DDRom),
m_CartridgeDomain1Address1Handler(System.m_Reg, g_DDRom),
m_CartridgeDomain2Address1Handler(System.m_Reg),
m_CartridgeDomain2Address2Handler(System, System.m_Reg, *this, SavesReadOnly),
m_RDRAMRegistersHandler(System.m_Reg),
@ -602,7 +602,7 @@ bool CMipsMemoryVM::LB_NonMemory(uint32_t VAddr, uint8_t & Value)
else if (PAddr >= 0x10000000 && PAddr < 0x16000000)
{
uint32_t Value32;
if (!m_RomMemoryHandler.Read32((PAddr + 2) & ~0x3, Value32))
if (!m_RomMemoryHandler.Read32(PAddr, Value32))
{
return false;
}
@ -635,7 +635,7 @@ bool CMipsMemoryVM::LH_NonMemory(uint32_t VAddr, uint16_t & Value)
else if (PAddr >= 0x10000000 && PAddr < 0x16000000)
{
uint32_t Value32;
if (!m_RomMemoryHandler.Read32((PAddr + 2) & ~0x3, Value32))
if (!m_RomMemoryHandler.Read32(PAddr, Value32))
{
return false;
}