2012-11-29 16:33:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-12 20:13:05 +00:00
|
|
|
|
|
2013-11-04 00:36:15 +00:00
|
|
|
|
using BizHawk.Common;
|
|
|
|
|
|
2016-02-22 23:50:11 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
|
2012-11-29 16:33:04 +00:00
|
|
|
|
{
|
2017-05-12 20:13:05 +00:00
|
|
|
|
internal sealed class Mapper0012 : CartridgeDevice
|
2017-04-24 13:35:05 +00:00
|
|
|
|
{
|
2017-05-12 20:13:05 +00:00
|
|
|
|
private readonly int[] _bankMain;
|
2017-05-13 15:11:13 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
private readonly int[][] _bankHigh;
|
2017-05-13 15:11:13 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
private int[] _bankHighSelected;
|
2017-05-13 15:11:13 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
private int _bankIndex;
|
2016-02-22 23:50:11 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
// Zaxxon and Super Zaxxon cartridges
|
|
|
|
|
// - read to 8xxx selects bank 0 in A000-BFFF
|
|
|
|
|
// - read to 9xxx selects bank 1 in A000-BFFF
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
public Mapper0012(IList<int> newAddresses, IList<int> newBanks, IList<int[]> newData)
|
|
|
|
|
{
|
|
|
|
|
_bankMain = new int[0x2000];
|
|
|
|
|
_bankHigh = new int[2][];
|
|
|
|
|
var dummyBank = new int[0x2000];
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
// create dummy bank just in case
|
|
|
|
|
for (var i = 0; i < 0x2000; i++)
|
|
|
|
|
dummyBank[i] = 0xFF;
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
_bankHigh[0] = dummyBank;
|
|
|
|
|
_bankHigh[1] = dummyBank;
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
// load in the banks
|
|
|
|
|
for (var i = 0; i < newAddresses.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (newAddresses[i] == 0x8000)
|
|
|
|
|
Array.Copy(newData[i], _bankMain, 0x1000);
|
|
|
|
|
else if ((newAddresses[i] == 0xA000 || newAddresses[i] == 0xE000) && newBanks[i] < 2)
|
|
|
|
|
_bankHigh[newBanks[i]] = newData[i];
|
|
|
|
|
}
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
// mirror the main rom from 8000 to 9000
|
|
|
|
|
Array.Copy(_bankMain, 0x0000, _bankMain, 0x1000, 0x1000);
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
// set both pins low for 16k rom config
|
|
|
|
|
pinExRom = false;
|
|
|
|
|
pinGame = false;
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
}
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-13 15:11:13 +00:00
|
|
|
|
protected override void SyncStateInternal(Serializer ser)
|
|
|
|
|
{
|
|
|
|
|
ser.Sync("BankHighSelected", ref _bankHighSelected, useNull: false);
|
|
|
|
|
ser.Sync("BankIndex", ref _bankIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
public override int Peek8000(int addr)
|
|
|
|
|
{
|
|
|
|
|
return _bankMain[addr];
|
|
|
|
|
}
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
public override int PeekA000(int addr)
|
|
|
|
|
{
|
|
|
|
|
return _bankHighSelected[addr];
|
|
|
|
|
}
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
public override int Read8000(int addr)
|
|
|
|
|
{
|
|
|
|
|
_bankIndex = (addr & 0x1000) >> 12;
|
|
|
|
|
_bankHighSelected = _bankHigh[_bankIndex];
|
|
|
|
|
return _bankMain[addr];
|
|
|
|
|
}
|
2012-11-29 16:33:04 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
public override int ReadA000(int addr)
|
|
|
|
|
{
|
|
|
|
|
return _bankHighSelected[addr];
|
2017-04-24 13:35:05 +00:00
|
|
|
|
}
|
2012-12-03 08:38:12 +00:00
|
|
|
|
|
2017-05-12 20:13:05 +00:00
|
|
|
|
public override void SyncState(Serializer ser)
|
|
|
|
|
{
|
|
|
|
|
base.SyncState(ser);
|
|
|
|
|
if (ser.IsReader)
|
|
|
|
|
_bankHighSelected = _bankHigh[_bankIndex];
|
|
|
|
|
}
|
2017-04-24 13:35:05 +00:00
|
|
|
|
}
|
2012-11-29 16:33:04 +00:00
|
|
|
|
}
|