Ho
Ive started emulating some chips.. MegaMan2 runs perfectly but ive problems with Zelda and Metroid they hang so it must be some problem with the ROM switching but from what Ive read this is how it should be done. Here is my code for a write:
Do you see any problems?
thanks
Ive started emulating some chips.. MegaMan2 runs perfectly but ive problems with Zelda and Metroid they hang so it must be some problem with the ROM switching but from what Ive read this is how it should be done. Here is my code for a write:
Code:
void NES_CPU_Mapper1(u32 Address, u8 Data)
{
u32 Temp;
// Mapper 1 (MMC1)
if (Address >= 0x8000 && Address < 0x10000)
{
if (Data & BIT(7))
{
g_NesCPUMapper.Register0 |= BIT(2) | BIT(3);
g_NesCPUMapper.Write = 0;
}
else
{
if (g_NesCPUMapper.Write == 4)
{
g_NesCPUMapper.Data |= (Data & 0x1) << g_NesCPUMapper.Write;
if (Address < 0xA000) // Register 0
{
g_NesCPUMapper.Register0 = g_NesCPUMapper.Data;
}
else if (Address < 0xC000) // Register 1
{
if (g_NesCPUMapper.Register0 & BIT(4))
{
NES_CPU_SetCHRROMBank4KB(0, g_NesCPUMapper.Data);
}
else
{
NES_CPU_SetCHRROMBank4KB(0, g_NesCPUMapper.Data*2+0);
NES_CPU_SetCHRROMBank4KB(1, g_NesCPUMapper.Data*2+1);
}
}
else if (Address < 0xE000) // Register 2
{
if (g_NesCPUMapper.Register0 & BIT(4))
NES_CPU_SetCHRROMBank4KB(1, g_NesCPUMapper.Data);
}
else // Register 3
{
Temp = ((g_NesCPUMapper.Register0 >> 2) & 0x3);
if (Temp == 2)
{
NES_CPU_SetPRGROMBank16KB(0, 0);
NES_CPU_SetPRGROMBank16KB(1, g_NesCPUMapper.Data);
}
else if (Temp == 3)
{
NES_CPU_SetPRGROMBank16KB(0, g_NesCPUMapper.Data);
NES_CPU_SetPRGROMBank16KB(1, g_NesPRGROMBankCount - 1);
}
else
{
NES_CPU_SetPRGROMBank16KB(0, (g_NesCPUMapper.Data & ~0x1) + 0);
NES_CPU_SetPRGROMBank16KB(1, (g_NesCPUMapper.Data & ~0x1) + 1);
}
}
g_NesCPUMapper.Data = 0;
g_NesCPUMapper.Write = 0;
}
else
{
g_NesCPUMapper.Data |= (Data & 0x1) << g_NesCPUMapper.Write;
g_NesCPUMapper.Write++;
}
}
}
}
{
u32 Temp;
// Mapper 1 (MMC1)
if (Address >= 0x8000 && Address < 0x10000)
{
if (Data & BIT(7))
{
g_NesCPUMapper.Register0 |= BIT(2) | BIT(3);
g_NesCPUMapper.Write = 0;
}
else
{
if (g_NesCPUMapper.Write == 4)
{
g_NesCPUMapper.Data |= (Data & 0x1) << g_NesCPUMapper.Write;
if (Address < 0xA000) // Register 0
{
g_NesCPUMapper.Register0 = g_NesCPUMapper.Data;
}
else if (Address < 0xC000) // Register 1
{
if (g_NesCPUMapper.Register0 & BIT(4))
{
NES_CPU_SetCHRROMBank4KB(0, g_NesCPUMapper.Data);
}
else
{
NES_CPU_SetCHRROMBank4KB(0, g_NesCPUMapper.Data*2+0);
NES_CPU_SetCHRROMBank4KB(1, g_NesCPUMapper.Data*2+1);
}
}
else if (Address < 0xE000) // Register 2
{
if (g_NesCPUMapper.Register0 & BIT(4))
NES_CPU_SetCHRROMBank4KB(1, g_NesCPUMapper.Data);
}
else // Register 3
{
Temp = ((g_NesCPUMapper.Register0 >> 2) & 0x3);
if (Temp == 2)
{
NES_CPU_SetPRGROMBank16KB(0, 0);
NES_CPU_SetPRGROMBank16KB(1, g_NesCPUMapper.Data);
}
else if (Temp == 3)
{
NES_CPU_SetPRGROMBank16KB(0, g_NesCPUMapper.Data);
NES_CPU_SetPRGROMBank16KB(1, g_NesPRGROMBankCount - 1);
}
else
{
NES_CPU_SetPRGROMBank16KB(0, (g_NesCPUMapper.Data & ~0x1) + 0);
NES_CPU_SetPRGROMBank16KB(1, (g_NesCPUMapper.Data & ~0x1) + 1);
}
}
g_NesCPUMapper.Data = 0;
g_NesCPUMapper.Write = 0;
}
else
{
g_NesCPUMapper.Data |= (Data & 0x1) << g_NesCPUMapper.Write;
g_NesCPUMapper.Write++;
}
}
}
}
Do you see any problems?
thanks