From d79067c33cf3d34b4a7caa8d5ebc167b058343ef Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 4 Apr 2014 21:16:43 +0000 Subject: [PATCH] Atari 2600 - implement mapper F8SC. Fix a potential crash in mappers AR and FA --- .../Consoles/Atari/2600/Atari2600.Core.cs | 3 + .../Consoles/Atari/2600/Mappers/mAR.cs | 2 +- .../Consoles/Atari/2600/Mappers/mF8SC.cs | 73 ++++++++++++++++++- .../Consoles/Atari/2600/Mappers/mFA.cs | 2 +- 4 files changed, 75 insertions(+), 5 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index 5b4cd76ba8..b3a47e9971 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -170,6 +170,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 case "F8": mapper = new mF8(); break; + case "F8SC": + mapper = new mF8SC(); + break; case "F6": mapper = new mF6(); break; diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs index ce98845d24..76e879a913 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mAR.cs @@ -50,7 +50,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { base.SyncState(ser); ser.Sync("bank4k", ref _bank4k); - ser.Sync("ram", ref _ram); + ser.Sync("auxRam", ref _ram); } private void Address(ushort addr) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs index fc39b315af..517dfd6820 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs @@ -1,4 +1,4 @@ -using System; +using BizHawk.Common; namespace BizHawk.Emulation.Cores.Atari.Atari2600 { @@ -8,9 +8,76 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 */ internal class mF8SC : MapperBase { - public mF8SC() + private int _bank_4K; + private ByteBuffer _ram = new ByteBuffer(128); + + private byte ReadMem(ushort addr, bool peek) { - throw new NotImplementedException(); + if (!peek) + { + Address(addr); + } + + if (addr < 0x1000) + { + return base.ReadMemory(addr); + } + + //if (addr < 0x1080) + //{ + // _ram[(addr & 0x7F)] = 0xFF; // Reading from the write port triggers an unwanted write of open bus + // return 0xFF; // 0xFF is used for deterministic emulation, in reality it would be a random value based on pins being high or low + //} + //else + if (addr < 0x1100) + { + return _ram[(addr & 0x7F)]; + } + + return core.rom[(_bank_4K << 12) + (addr & 0xFFF)]; + } + + public override byte ReadMemory(ushort addr) + { + return ReadMem(addr, false); + } + + public override byte PeekMemory(ushort addr) + { + return ReadMem(addr, true); + } + + public override void WriteMemory(ushort addr, byte value) + { + Address(addr); + + if (addr < 0x1000) + { + base.WriteMemory(addr, value); + } + else if ((addr & 0x0FFF) < 0x80) + { + _ram[addr & 0x7F] = value; + } + } + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("bank_4k", ref _bank_4K); + ser.Sync("auxRam", ref _ram); + } + + private void Address(ushort addr) + { + if (addr == 0x1FF8) + { + _bank_4K = 0; + } + else if (addr == 0x1FF9) + { + _bank_4K = 1; + } } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mFA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mFA.cs index 476052fd1a..71848e7685 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mFA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mFA.cs @@ -71,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { base.SyncState(ser); ser.Sync("toggle", ref _toggle); - ser.Sync("ram", ref _auxRam); + ser.Sync("auxRam", ref _auxRam); } private void Address(ushort addr)