Fix WRAM enable / disable for SNROM

now passes mmc1_a12, which was incorrectly listed as passing before
This commit is contained in:
alyosha-tas 2016-11-26 20:25:46 -05:00 committed by GitHub
parent baded06902
commit 995c5f907c
1 changed files with 53 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using System;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions;
namespace BizHawk.Emulation.Cores.Nintendo.NES
{
@ -82,7 +83,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
int chr_0, chr_1;
//register 3:
int wram_disable;
public bool wram_disable;
int prg;
//regenerable state
@ -177,7 +178,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
break;
case 3: //E000-FFFF
prg = value & 0xF;
wram_disable = (value >> 4) & 1;
wram_disable = value.Bit(4) ? true : false;
break;
}
//board.NES.LogLine("mapping.. chr_mode={0}, chr={1},{2}", chr_mode, chr_0, chr_1);
@ -253,6 +254,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
//let's make the extra space here, instead of in the main NES to avoid confusion
byte[] CIRAM_VS = new byte[0x800];
//for snrom wram disable
public bool _is_snrom;
public bool wram_enable = true;
public bool chr_wram_enable = true;
//state
public MMC1 mmc1;
@ -274,7 +279,36 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
mmc1.Write(addr, value);
if (!disablemirror)
SetMirrorType(mmc1.mirror); //often redundant, but gets the job done
if (_is_snrom)
{
if (addr>0x2000 && addr<0x6000)
{
if ((value & 0x10) == 0)
wram_enable = true;
else
wram_enable = false;
}
}
}
}
public override byte ReadWRAM(int addr)
{
if (_is_snrom)
{
if (wram_enable && !mmc1.wram_disable && chr_wram_enable)
return base.ReadWRAM(addr);
else
return NES.DB;
}
else
{
return base.ReadWRAM(addr);
}
}
public override byte ReadPRG(int addr)
@ -295,6 +329,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{
if (addr < 0x2000)
{
// WRAM enable is tied to ppu a12
if (addr.Bit(12))
chr_wram_enable = false;
else
chr_wram_enable = true;
if (Cart.vram_size != 0)
return VRAM[Gen_CHR_Address(addr) & vram_mask];
else return VROM[Gen_CHR_Address(addr)];
@ -343,6 +383,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
}
else if (addr < 0x2000)
{
// WRAM enable is tied to ppu a12
if (addr.Bit(12))
chr_wram_enable = false;
else
chr_wram_enable = true;
if (Cart.vram_size != 0)
VRAM[Gen_CHR_Address(addr) & vram_mask] = value;
}
@ -354,7 +400,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
base.SyncState(ser);
mmc1.SyncState(ser);
ser.Sync("ppuclock", ref ppuclock);
ser.Sync("wram enable", ref wram_enable);
ser.Sync("chr wram enable", ref chr_wram_enable);
if (NES._isVS)
ser.Sync("VS_CIRAM", ref CIRAM_VS, false);
}
@ -465,6 +512,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
AssertPrg(128, 256); AssertChr(0); AssertVram(8); AssertWram(8);
break;
case "NES-SNROM": //dragon warrior 2
_is_snrom = true;
AssertPrg(128, 256); AssertChr(0); AssertVram(8); AssertWram(8);
break;
case "VIRGIN-SNROM":
case "NES-SNWEPROM": // final fantasy 2 (proto)
AssertPrg(128, 256); AssertChr(0); AssertVram(8); AssertWram(8);