Retail 64DD IPL ROM support (boots)

This commit is contained in:
luigiblood 2016-01-18 20:15:01 +01:00
parent 691f09159b
commit 4fb6c2219d
6 changed files with 128 additions and 4 deletions

View File

@ -34,6 +34,7 @@ void CDMA::OnFirstDMA()
{
case CIC_NUS_6101: offset = +0x0318; break;
case CIC_NUS_5167: offset = +0x0318; break;
case CIC_NUS_8303: offset = +0x0318; break;
case CIC_UNKNOWN:
case CIC_NUS_6102: offset = +0x0318; break;
case CIC_NUS_6103: offset = +0x0318; break;
@ -75,7 +76,7 @@ void CDMA::PI_DMA_READ()
uint8_t * ROM = g_Rom->GetRomAddress();
uint8_t * RDRAM = g_MMU->Rdram();
ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READWRITE);
ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READWRITE);
g_Reg->PI_CART_ADDR_REG -= 0x10000000;
if (g_Reg->PI_CART_ADDR_REG + PI_RD_LEN_REG < g_Rom->GetRomSize())
{
@ -105,7 +106,7 @@ void CDMA::PI_DMA_READ()
g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG, CRecompiler::Remove_DMA);
}
ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READONLY);
ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READONLY);
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
g_Reg->MI_INTR_REG |= MI_INTR_PI;
@ -181,6 +182,75 @@ void CDMA::PI_DMA_WRITE()
return;
}
//64DD IPL ROM
if (g_Reg->PI_CART_ADDR_REG >= 0x06000000 && g_Reg->PI_CART_ADDR_REG <= 0x063FFFFF)
{
uint32_t i;
#ifdef legacycode
#ifdef ROM_IN_MAPSPACE
if (WrittenToRom)
{
uint32_t OldProtect;
VirtualProtect(ROM, m_RomFileSize, PAGE_READONLY, &OldProtect);
}
#endif
#endif
uint8_t * ROM = g_DDRom->GetRomAddress();
uint8_t * RDRAM = g_MMU->Rdram();
g_Reg->PI_CART_ADDR_REG -= 0x06000000;
if (g_Reg->PI_CART_ADDR_REG + PI_WR_LEN_REG < g_DDRom->GetRomSize())
{
for (i = 0; i < PI_WR_LEN_REG; i++)
{
*(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3));
}
}
else if (g_Reg->PI_CART_ADDR_REG >= g_DDRom->GetRomSize())
{
uint32_t cart = g_Reg->PI_CART_ADDR_REG - g_DDRom->GetRomSize();
while (cart >= g_DDRom->GetRomSize())
{
cart -= g_DDRom->GetRomSize();
}
for (i = 0; i < PI_WR_LEN_REG; i++)
{
*(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM + ((cart + i) ^ 3));
}
}
else
{
uint32_t Len;
Len = g_DDRom->GetRomSize() - g_Reg->PI_CART_ADDR_REG;
for (i = 0; i < Len; i++)
{
*(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM + ((g_Reg->PI_CART_ADDR_REG + i) ^ 3));
}
for (i = Len; i < PI_WR_LEN_REG - Len; i++)
{
*(RDRAM + ((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = 0;
}
}
g_Reg->PI_CART_ADDR_REG += 0x06000000;
if (!g_System->DmaUsed())
{
g_System->SetDmaUsed(true);
OnFirstDMA();
}
if (g_Recompiler && g_System->bSMM_PIDMA())
{
g_Recompiler->ClearRecompCode_Phys(g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_WR_LEN_REG, CRecompiler::Remove_DMA);
}
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
g_Reg->MI_INTR_REG |= MI_INTR_PI;
g_Reg->CheckInterrupts();
//ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9) + 50);
//ChangeTimer(PiTimer,(int32_t)(PI_WR_LEN_REG * 8.9));
return;
}
if (g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08088000)
{
if (g_System->m_SaveUsing == SaveChip_Auto)

View File

@ -194,6 +194,33 @@ bool CMipsMemoryVM::Initialize()
m_Rom = g_Rom->GetRomAddress();
m_RomSize = g_Rom->GetRomSize();
}
//64DD IPL
if (g_DDRom != NULL)
{
if (g_Settings->LoadBool(Game_LoadRomToMemory))
{
m_DDRomMapped = true;
m_DDRom = m_RDRAM + 0x06000000;
m_DDRomSize = g_DDRom->GetRomSize();
if (CommitMemory(m_DDRom, g_DDRom->GetRomSize(), MEM_READWRITE) == NULL)
{
WriteTrace(TraceN64System, TraceError, "Failed to Allocate Rom (Size: 0x%X)", g_DDRom->GetRomSize());
FreeMemory();
return false;
}
memcpy(m_DDRom, g_DDRom->GetRomAddress(), g_DDRom->GetRomSize());
::ProtectMemory(m_DDRom, g_DDRom->GetRomSize(), MEM_READONLY);
}
else
{
m_DDRomMapped = false;
m_DDRom = g_DDRom->GetRomAddress();
m_DDRomSize = g_DDRom->GetRomSize();
}
}
CPifRam::Reset();
m_TLB_ReadMap = new size_t[0x100000];
@ -928,6 +955,12 @@ void CMipsMemoryVM::Compile_LW(x86Reg Reg, uint32_t VAddr)
sprintf(VarName, "m_RDRAM + %X", PAddr);
MoveVariableToX86reg(PAddr + m_RDRAM, VarName, Reg);
}
else if ((PAddr & 0xFF000000) == 0x06000000 && (PAddr - 0x06000000) < m_DDRomSize)
{
// read from ddrom
sprintf(VarName, "m_RDRAM + %X", PAddr);
MoveVariableToX86reg(PAddr + m_RDRAM, VarName, Reg);
}
else
{
MoveConstToX86reg(((PAddr & 0xFFFF) << 16) | (PAddr & 0xFFFF), Reg);
@ -4682,8 +4715,16 @@ void CMipsMemoryVM::Load32SerialInterface(void)
void CMipsMemoryVM::Load32CartridgeDomain1Address1(void)
{
m_MemLookupValue.UW[0] = m_MemLookupAddress & 0xFFFF;
m_MemLookupValue.UW[0] = (m_MemLookupValue.UW[0] << 16) | m_MemLookupValue.UW[0];
//64DD IPL ROM
if (g_DDRom != NULL && (m_MemLookupAddress & 0xFFFFFF) < g_MMU->m_DDRomSize)
{
m_MemLookupValue.UW[0] = *(uint32_t *)&g_MMU->m_DDRom[(m_MemLookupAddress & 0xFFFFFF)];
}
else
{
m_MemLookupValue.UW[0] = m_MemLookupAddress & 0xFFFF;
m_MemLookupValue.UW[0] = (m_MemLookupValue.UW[0] << 16) | m_MemLookupValue.UW[0];
}
}
void CMipsMemoryVM::Load32CartridgeDomain1Address3(void)

View File

@ -216,6 +216,11 @@ private:
bool m_RomWrittenTo;
uint32_t m_RomWroteValue;
//DDRom Information
bool m_DDRomMapped;
uint8_t * m_DDRom;
uint32_t m_DDRomSize;
//Current Half line
void UpdateHalfLine();
uint32_t m_HalfLine;

View File

@ -212,6 +212,12 @@ bool CN64System::RunFileImage(const char * FileLoc)
WriteTrace(TraceN64System, TraceDebug, "Loading \"%s\"", FileLoc);
if (g_Rom->LoadN64Image(FileLoc))
{
if (g_Rom->CicChipID() == CIC_NUS_8303)
{
//64DD IPL
g_DDRom = g_Rom;
}
g_System->RefreshGameSettings();
g_Settings->SaveString(Game_File, FileLoc);

View File

@ -21,6 +21,7 @@ CRegisters * g_Reg = NULL; //Current Register Set attacted to the g_MMU
CNotification * g_Notify = NULL;
CPlugins * g_Plugins = NULL;
CN64Rom * g_Rom = NULL; //The current rom that this system is executing.. it can only execute one file at the time
CN64Rom * g_DDRom = NULL; //64DD IPL ROM
CAudio * g_Audio = NULL;
CSystemTimer * g_SystemTimer = NULL;
CTransVaddr * g_TransVaddr = NULL;

View File

@ -35,6 +35,7 @@ extern CPlugins * g_Plugins;
class CN64Rom;
extern CN64Rom * g_Rom; //The current rom that this system is executing.. it can only execute one file at the time
extern CN64Rom * g_DDRom; //64DD IPL ROM
class CAudio;
extern CAudio * g_Audio;