From 321f62a2424dc886aa85cbbc0c2597f5fe6cacfe Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 29 May 2017 15:04:26 -0400 Subject: [PATCH] Add files via upload --- .../Commodore64/Cartridge/Mapper0007.cs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0007.cs diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0007.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0007.cs new file mode 100644 index 0000000000..6aeb08fd1b --- /dev/null +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/Cartridge/Mapper0007.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using BizHawk.Common; + +namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge +{ + internal sealed class Mapper0007 : CartridgeDevice + { + private int[,] _banks = new int[16,0x2000]; + + private int _bankNumber; + private bool _disabled; + private int _latchedval; + + // Fun Play mapper + // bank switching is done from DE00 + + public Mapper0007(IList newData, bool game, bool exrom) + { + pinGame = game; + pinExRom = exrom; + + _disabled = false; + _latchedval = 0; + + // load data into the banks from the list + for (var j = 0; j < 16; j++) + { + for (var i = 0; i < 0x2000; i++) + { + _banks[j,i] = newData[j][i]; + } + } + _bankNumber = 0; + } + + protected override void SyncStateInternal(Serializer ser) + { + ser.Sync("BankNumber", ref _bankNumber); + ser.Sync("Disabled", ref _disabled); + } + + public override int Peek8000(int addr) + { + if (!_disabled) + return _banks[_bankNumber, addr]; + else + return base.Read8000(addr); + } + + public override void PokeDE00(int addr, int val) + { + if (addr == 0) + { + byte temp_bank = (byte)((val & 0x1) << 3); + temp_bank |= (byte)((val & 0x38) >> 3); + _bankNumber = temp_bank; + if (val == 0x86) + { + _disabled = true; + } + } + } + + public override int Read8000(int addr) + { + if (!_disabled) + return _banks[_bankNumber, addr]; + else + return base.Read8000(addr); + } + + public override void WriteDE00(int addr, int val) + { + if (addr == 0) + { + byte temp_bank = (byte)((val & 0x1) << 3); + temp_bank |= (byte)((val & 0x38) >> 3); + _bankNumber = temp_bank; + if (val==0x86) + { + _disabled = true; + } + } + } + + public override int ReadDF00(int addr) + { + return _latchedval; + } + } +} +