From 3d1e6ca83004fd576da3a18e6136f8d22c521bc5 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 4 Apr 2014 23:49:03 +0000 Subject: [PATCH] Atari 2600 - implement mapper F6SC, and slight fix to F8SC (uncomment read of write port emulation) --- .../Consoles/Atari/2600/Mappers/mF6SC.cs | 72 +++++++++++++++++-- .../Consoles/Atari/2600/Mappers/mF8SC.cs | 13 ++-- 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF6SC.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF6SC.cs index de61e9a55f..010c9130dd 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF6SC.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF6SC.cs @@ -1,16 +1,78 @@ -using System; +using BizHawk.Common; namespace BizHawk.Emulation.Cores.Atari.Atari2600 { /** - Cartridge class used for Atari's 32K bankswitched games with - 128 bytes of RAM. There are eight 4K banks. + Cartridge class used for Atari's 16K bankswitched games with + 128 bytes of RAM. There are four 4K banks. */ internal class mF6SC : MapperBase { - public mF6SC() + private int _bank4k; + 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[(_bank4k << 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 _bank4k); + ser.Sync("auxRam", ref _ram); + } + + private void Address(ushort addr) + { + if (addr == 0x1FF6) _bank4k = 0; + if (addr == 0x1FF7) _bank4k = 1; + if (addr == 0x1FF8) _bank4k = 2; + if (addr == 0x1FF9) _bank4k = 3; } } } \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs index 517dfd6820..81bbec6be7 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8SC.cs @@ -23,13 +23,12 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 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) + 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)]; }