From 80737e80970a121e06300514cef703fda93501de Mon Sep 17 00:00:00 2001 From: goyuken Date: Tue, 16 Oct 2012 21:37:25 +0000 Subject: [PATCH] nes Mapper 42: dumb FDS conversion pirate stuff Ai Senshi Nicol [p1].nes Bio Miracle Bokutte Upa (J) (Mario Baby - FDS Conversion).nes --- BizHawk.Emulation/BizHawk.Emulation.csproj | 1 + .../Consoles/Nintendo/NES/Boards/Mapper042.cs | 117 ++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper042.cs diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index f9c68fe7ba..4033ed011a 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -155,6 +155,7 @@ + diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper042.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper042.cs new file mode 100644 index 0000000000..9b2d4d7fce --- /dev/null +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper042.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Consoles.Nintendo +{ + // pirate FDS conversion + // this is probably two different boards, but they seem to work well enough the same + public class Mapper042 : NES.NESBoardBase + { + int prg = 0; + int chr = 0; + int irqcnt = 0; + bool irqenable = false; + + public override bool Configure(NES.EDetectionOrigin origin) + { + switch (Cart.board_type) + { + case "MAPPER042": + break; + default: + return false; + } + AssertPrg(128); + + if (Cart.vram_size == 0) + AssertChr(128); + else + { + AssertVram(8); + AssertChr(0); + } + + AssertWram(0); + // not sure on initial mirroring + SetMirrorType(EMirrorType.Vertical); + return true; + } + + public override void WritePRG(int addr, byte value) + { + addr &= 0x6003; + switch (addr) + { + case 0x0000: + chr = value & 15; + break; + case 0x6000: + prg = value & 15; + break; + case 0x6001: + if ((value & 8) != 0) + SetMirrorType(EMirrorType.Horizontal); + else + SetMirrorType(EMirrorType.Vertical); + break; + case 0x6002: + Console.WriteLine("{0:x4}:{1:x2} @{2}", addr + 0x8000, value, NES.ppu.ppur.status.sl); + if ((value & 2) == 0) + { + irqcnt = 0; + irqenable = false; + IRQSignal = false; + } + else + irqenable = true; + break; + } + } + + public override byte ReadPRG(int addr) + { + return ROM[addr | 0x18000]; + } + public override byte ReadWRAM(int addr) + { + return ROM[addr | prg << 13]; + } + + public override void ClockPPU() + { + if (irqenable) + { + irqcnt++; + + if (irqcnt >= 32768 * 3) + irqcnt -= 32768 * 3; + + IRQSignal = irqcnt >= 24576 * 3; + } + } + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("prg", ref prg); + ser.Sync("chr", ref chr); + ser.Sync("irqenable", ref irqenable); + ser.Sync("irqcnt", ref irqcnt); + } + + public override byte ReadPPU(int addr) + { + if (addr < 0x2000) + { + if (VRAM != null) + return VRAM[addr]; + else + return VROM[addr | chr << 13]; + } + else + return base.ReadPPU(addr); + } + } +}