Atari 2600 - support multi-cart mappers, toggling games is done via Hard Reset
This commit is contained in:
parent
8a239b53bc
commit
391be49081
|
@ -205,7 +205,9 @@
|
|||
<Compile Include="Consoles\Atari\2600\Mappers\mMC.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\mSB.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\mUA.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\Multicart.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\Multicart2K.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\Multicart4K.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\Multicart8K.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\mX07.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\M6532.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Tia\Tia.Audio.cs" />
|
||||
|
|
|
@ -94,17 +94,39 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
CoreComm.MemoryCallbackSystem.CallExecute(addr);
|
||||
}
|
||||
|
||||
private static MapperBase SetMultiCartMapper(int romLength, int gameTotal)
|
||||
{
|
||||
switch(romLength / gameTotal)
|
||||
{
|
||||
case 1024 * 2: // 2K
|
||||
return new Multicart2K(gameTotal);
|
||||
break;
|
||||
default:
|
||||
case 1024 * 4: // 4K
|
||||
return new Multicart4K(gameTotal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void RebootCore()
|
||||
{
|
||||
// Regenerate mapper here to make sure its state is entirely clean
|
||||
switch (this._game.GetOptionsDict()["m"])
|
||||
switch (_game.GetOptionsDict()["m"])
|
||||
{
|
||||
case "2IN1":
|
||||
_mapper = SetMultiCartMapper(Rom.Length, 2);
|
||||
break;
|
||||
case "4IN1":
|
||||
_mapper = SetMultiCartMapper(Rom.Length, 4);
|
||||
break;
|
||||
case "8IN1":
|
||||
_mapper = SetMultiCartMapper(Rom.Length, 8);
|
||||
break;
|
||||
case "16IN1":
|
||||
_mapper = SetMultiCartMapper(Rom.Length, 16);
|
||||
break;
|
||||
case "32IN1":
|
||||
_mapper = new Multicart();
|
||||
_mapper = SetMultiCartMapper(Rom.Length, 32);
|
||||
break;
|
||||
case "AR":
|
||||
_mapper = new mAR();
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||
{
|
||||
/*
|
||||
Mapper used for multi-cart mappers
|
||||
*/
|
||||
internal class Multicart : MapperBase
|
||||
{
|
||||
public Multicart()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000)
|
||||
{
|
||||
return base.ReadMemory(addr);
|
||||
}
|
||||
|
||||
return Core.Rom[addr & 0xFFF];
|
||||
}
|
||||
|
||||
public override byte PeekMemory(ushort addr)
|
||||
{
|
||||
return ReadMemory(addr);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using System.Linq;
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||
{
|
||||
/*
|
||||
Mapper used for multi-cart 2K games
|
||||
*/
|
||||
internal class Multicart2K : MapperBase
|
||||
{
|
||||
private int _gameTotal;
|
||||
private int _currentGame;
|
||||
|
||||
public Multicart2K(int gametotal)
|
||||
{
|
||||
_gameTotal = gametotal;
|
||||
_currentGame = 0;
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
ser.Sync("gameTotal", ref _gameTotal);
|
||||
ser.Sync("currentGame", ref _currentGame);
|
||||
base.SyncState(ser);
|
||||
}
|
||||
|
||||
public override void HardReset()
|
||||
{
|
||||
IncrementGame();
|
||||
}
|
||||
|
||||
private void IncrementGame()
|
||||
{
|
||||
_currentGame++;
|
||||
if (_currentGame >= _gameTotal)
|
||||
{
|
||||
_currentGame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000)
|
||||
{
|
||||
return base.ReadMemory(addr);
|
||||
}
|
||||
|
||||
return this.Core.Rom[(addr & 0x7FF) + (_currentGame * 2048)];
|
||||
}
|
||||
|
||||
public override byte PeekMemory(ushort addr)
|
||||
{
|
||||
return ReadMemory(addr);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using System.Linq;
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||
{
|
||||
/*
|
||||
Mapper used for multi-cart 4K games
|
||||
*/
|
||||
internal class Multicart4K : MapperBase
|
||||
{
|
||||
private int _gameTotal;
|
||||
private int _currentGame;
|
||||
|
||||
public Multicart4K(int gametotal)
|
||||
{
|
||||
_gameTotal = gametotal;
|
||||
_currentGame = 0;
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
ser.Sync("gameTotal", ref _gameTotal);
|
||||
ser.Sync("currentGame", ref _currentGame);
|
||||
base.SyncState(ser);
|
||||
}
|
||||
|
||||
public override void HardReset()
|
||||
{
|
||||
IncrementGame();
|
||||
}
|
||||
|
||||
private void IncrementGame()
|
||||
{
|
||||
_currentGame++;
|
||||
if (_currentGame >= _gameTotal)
|
||||
{
|
||||
_currentGame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000)
|
||||
{
|
||||
return base.ReadMemory(addr);
|
||||
}
|
||||
|
||||
return Core.Rom[(addr & 0xFFF) + (_currentGame * 4096)];
|
||||
}
|
||||
|
||||
public override byte PeekMemory(ushort addr)
|
||||
{
|
||||
return ReadMemory(addr);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
using System.Linq;
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
||||
{
|
||||
/*
|
||||
Mapper used for multi-cart 8K games
|
||||
*/
|
||||
internal class Multicart8K : MapperBase
|
||||
{
|
||||
private int _bank4K;
|
||||
|
||||
private int _gameTotal;
|
||||
private int _currentGame;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
ser.Sync("bank_4k", ref _bank4K);
|
||||
ser.Sync("gameTotal", ref _gameTotal);
|
||||
ser.Sync("currentGame", ref _currentGame);
|
||||
base.SyncState(ser);
|
||||
}
|
||||
|
||||
public override void HardReset()
|
||||
{
|
||||
_bank4K = 0;
|
||||
IncrementGame();
|
||||
}
|
||||
|
||||
private void IncrementGame()
|
||||
{
|
||||
_currentGame++;
|
||||
if (_currentGame >= _gameTotal)
|
||||
{
|
||||
_currentGame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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) + (_currentGame * 8192)];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void Address(ushort addr)
|
||||
{
|
||||
if (addr == 0x1FF8)
|
||||
{
|
||||
_bank4K = 0;
|
||||
}
|
||||
else if (addr == 0x1FF9)
|
||||
{
|
||||
_bank4K = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue