From 86cfa69b989191474d2b9f6a8da27f77c2925e40 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 18 May 2017 16:18:49 -0400 Subject: [PATCH] C64: Add Mapper 0008 --- .../Commodore64/Cartridge/CartridgeDevice.cs | 3 + .../Commodore64/Cartridge/Mapper0008.cs | 104 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0008.cs diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/CartridgeDevice.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/CartridgeDevice.cs index 478e84ffa7..4ce22ca688 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/CartridgeDevice.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/CartridgeDevice.cs @@ -81,6 +81,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge case 0x0005: // Ocean result = new Mapper0005(chipAddress, chipBank, chipData); break; + case 0x0008: // SuperGame + result = new Mapper0008(chipData); + break; case 0x000A: // Epyx FastLoad result = new Mapper000A(chipData); break; diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0008.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0008.cs new file mode 100644 index 0000000000..a9c1be9960 --- /dev/null +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0008.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using BizHawk.Common; + +namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge +{ + internal sealed class Mapper0008 : CartridgeDevice + { + private int[,] _banks = new int[4,0x4000]; + + private int _bankMask; + private int _bankNumber; + private bool _disabled; + private int _latchedval; + + // SuperGame mapper + // bank switching is done from DF00 + + public Mapper0008(IList newData) + { + pinGame = false; + pinExRom = false; + + _bankMask = 0x03; + _disabled = false; + _latchedval = 0; + + // load data into the banks from the list + for (var j = 0; j < 4; j++) + { + for (var i = 0; i < 0x4000; i++) + { + _banks[j,i] = newData[j][i]; + } + } + BankSet(0); + } + + protected override void SyncStateInternal(Serializer ser) + { + ser.Sync("BankMask", ref _bankMask); + ser.Sync("BankNumber", ref _bankNumber); + ser.Sync("Disabled", ref _disabled); + ser.Sync("Latchedvalue", ref _latchedval); + } + + public void BankSet(int index) + { + if (!_disabled) + { + _bankNumber = index & _bankMask; + pinExRom = (index & 0x4) > 0; + pinGame = (index & 0x4) > 0; + _disabled = (index & 0x8) > 0; + _latchedval = index; + } + } + + public override int Peek8000(int addr) + { + return _banks[_bankNumber, addr]; + } + + public override int PeekA000(int addr) + { + return _banks[_bankNumber, addr + 0x2000]; + } + + public override void PokeDF00(int addr, int val) + { + if (addr == 0) + BankSet(val); + } + + public override int Read8000(int addr) + { + return _banks[_bankNumber, addr]; + } + + public override int ReadA000(int addr) + { + return _banks[_bankNumber, addr + 0x2000]; + } + + public override void WriteDF00(int addr, int val) + { + if (addr == 0) + BankSet(val); + } + + public override int ReadDF00(int addr) + { + return _latchedval; + } + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + if (ser.IsReader) + BankSet(_bankNumber); + } + } +} +