From 1565a0adf81f14c1578bde7fd8fa1415070a78a0 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 20 May 2016 09:05:57 -0400 Subject: [PATCH] add sega mapper mod mod to F8 that starts in bank 1 --- .../Consoles/Atari/2600/Mappers/mF8_sega.cs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8_sega.cs diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8_sega.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8_sega.cs new file mode 100644 index 0000000000..aa5d519283 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/mF8_sega.cs @@ -0,0 +1,98 @@ +using BizHawk.Common; + +namespace BizHawk.Emulation.Cores.Atari.Atari2600 +{ + /* + F8 (Atari style 8K) + ----- + + This is the fairly standard way 8K of cartridge ROM was implemented. There are two + 4K ROM banks, which get mapped into the 4K of cartridge space. Accessing 1FF8 or + 1FF9 selects one of the two 4K banks. When one of these two addresses are accessed, + the banks switch spontaniously. + + ANY kind of access will trigger the switching- reading or writing. Usually games use + LDA or BIT on 1FF8/1FF9 to perform the switch. + + When the switch occurs, the entire 4K ROM bank switches, including the code that is + reading the 1FF8/1FF9 location. Usually, games put a small stub of code in BOTH banks + so when the switch occurs, the code won't crash. + */ + + internal class mF8_sega : MapperBase + { + private int _bank4K=1; + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("bank_4k", ref _bank4K); + } + + public override void HardReset() + { + _bank4K = 1; + base.HardReset(); + } + + private byte ReadMem(ushort addr, bool peek) + { + if (!peek) + { + Address(addr); + } + + if (addr < 0x1000) + { + return base.ReadMemory(addr); + } + + 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); + } + + private void WriteMem(ushort addr, byte value, bool poke) + { + if (!poke) + { + Address(addr); + } + + if (addr < 0x1000) + { + base.WriteMemory(addr, value); + } + } + + public override void WriteMemory(ushort addr, byte value) + { + WriteMem(addr, value, poke: false); + } + + public override void PokeMemory(ushort addr, byte value) + { + WriteMem(addr, value, poke: true); + } + + private void Address(ushort addr) + { + if (addr == 0x1FF8) + { + _bank4K = 0; + } + else if (addr == 0x1FF9) + { + _bank4K = 1; + } + } + } +} \ No newline at end of file