From 395b10956aaa102789e8c5665a8e07684de4b00b Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 25 Sep 2011 02:26:50 +0000 Subject: [PATCH] nes-add mapper 47 (mmc3 multicart) --- BizHawk.Emulation/BizHawk.Emulation.csproj | 34 ++++++++++ .../Consoles/Nintendo/Docs/compatibility.txt | 2 +- .../NES/Boards/MMC3_family/MMC3_family.cs | 19 +++++- .../Nintendo/NES/Boards/MMC3_family/NES-QJ.cs | 67 +++++++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/NES-QJ.cs diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index 29d6b8d2df..b2b9aa818f 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -119,6 +119,7 @@ + @@ -261,6 +262,39 @@ + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + diff --git a/BizHawk.Emulation/Consoles/Nintendo/Docs/compatibility.txt b/BizHawk.Emulation/Consoles/Nintendo/Docs/compatibility.txt index 7864f0da70..57503a6dfa 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Docs/compatibility.txt +++ b/BizHawk.Emulation/Consoles/Nintendo/Docs/compatibility.txt @@ -41,7 +41,7 @@ Open bus and bus conflict emulation is not considered complete or thorough in an 044 Multicart Junk 045 Multicart Junk 046 Multicart Junk -047 MMC3Multi Needed (1st party) +047 MMC3Multi Decent 048 MMC3Variant Needed (similar to mmc3, should inherit) 049 Multicart Junk 050 Pirate Junk diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs index 827211de5a..1afe4e3a3e 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs @@ -120,6 +120,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo int a12_old; byte irq_reload, irq_counter; bool irq_pending, irq_enable; + public bool wram_enable, wram_write_protect; //it really seems like these should be the same but i cant seem to unify them. //theres no sense in delaying the IRQ, so its logic must be tied to the separator. @@ -146,6 +147,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo ser.Sync("irq_enable", ref irq_enable); ser.Sync("separator_counter", ref separator_counter); ser.Sync("irq_countdown", ref irq_countdown); + ser.Sync("wram_enable", ref wram_enable); + ser.Sync("wram_write_protect", ref wram_write_protect); } void SyncIRQ() @@ -168,6 +171,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo break; case 0x2001: //$A001 //wram enable/protect + wram_write_protect = value.Bit(6); + wram_enable = value.Bit(7); break; case 0x4000: //$C000 - IRQ Reload value irq_reload = value; @@ -276,9 +281,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo mapper.SyncState(ser); } + protected virtual int Get_CHRBank_1K(int addr) + { + return mapper.Get_CHRBank_1K(addr); + } + int MapCHR(int addr) { - int bank_1k = mapper.Get_CHRBank_1K(addr); + int bank_1k = Get_CHRBank_1K(addr); bank_1k &= chr_mask; addr = (bank_1k << 10) | (addr & 0x3FF); return addr; @@ -313,9 +323,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo mapper.WritePRG(addr, value); } + protected virtual int Get_PRGBank_8K(int addr) + { + return mapper.Get_PRGBank_8K(addr); + } + public override byte ReadPRG(int addr) { - int bank_8k = mapper.Get_PRGBank_8K(addr); + int bank_8k = Get_PRGBank_8K(addr); bank_8k &= prg_mask; addr = (bank_8k << 13) | (addr & 0x1FFF); return ROM[addr]; diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/NES-QJ.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/NES-QJ.cs new file mode 100644 index 0000000000..06456aecaf --- /dev/null +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/NES-QJ.cs @@ -0,0 +1,67 @@ +using System; +using System.IO; +using System.Diagnostics; + +namespace BizHawk.Emulation.Consoles.Nintendo +{ + public class NES_QJ : MMC3Board_Base + { + //state + int block; + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("block", ref block); + } + + public override void WritePRG(int addr, byte value) + { + base.WritePRG(addr, value); + SetMirrorType(mmc3.MirrorType); //often redundant, but gets the job done + } + + public override bool Configure(NES.EDetectionOrigin origin) + { + //analyze board type + switch (Cart.board_type) + { + case "NES-QJ": //super spike v'ball / nintendo world cup + AssertPrg(256); AssertChr(256); AssertVram(0); AssertWram(0); + AssertBattery(false); + break; + default: + return false; + } + + BaseSetup(); + + return true; + } + + protected override int Get_PRGBank_8K(int addr) + { + //base logic will return the mmc reg, which needs to be masked without awareness of the extra block + return (base.Get_PRGBank_8K(addr) & 0xF) + block * 16; + } + + protected override int Get_CHRBank_1K(int addr) + { + //base logic will return the mmc reg, which needs to be masked without awareness of the extra block + return (base.Get_CHRBank_1K(addr) & 0x7F) + block * 128; + } + + public override byte ReadWRAM(int addr) + { + return (byte)block; + } + public override void WriteWRAM(int addr, byte value) + { + if (mmc3.wram_enable && !mmc3.wram_write_protect) + { + block = value & 1; + } + } + + } +} \ No newline at end of file