Atari2600 cleanup - pass Atari2600 core into constructor instead of setting after, use switch expression for mapper instantiation logic
This commit is contained in:
parent
c52bc603d7
commit
8c10ca3e14
|
@ -60,18 +60,15 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
// keeps track of tia cycles, 3 cycles per CPU cycle
|
||||
private int cyc_counter;
|
||||
|
||||
private static MapperBase SetMultiCartMapper(int romLength, int gameTotal)
|
||||
private MapperBase SetMultiCartMapper(int romLength, int gameTotal)
|
||||
{
|
||||
switch (romLength / gameTotal)
|
||||
return (romLength / gameTotal) switch
|
||||
{
|
||||
case 1024 * 2: // 2K
|
||||
return new Multicart2K(gameTotal);
|
||||
default:
|
||||
case 1024 * 4: // 4K
|
||||
return new Multicart4K(gameTotal);
|
||||
case 1024 * 8: // 8K
|
||||
return new Multicart8K(gameTotal);
|
||||
}
|
||||
1024 * 2 => new Multicart2K(this, gameTotal),
|
||||
1024 * 4 => new Multicart4K(this, gameTotal),
|
||||
1024 * 8 => new Multicart8K(this, gameTotal),
|
||||
_ => new Multicart4K(this, gameTotal)
|
||||
};
|
||||
}
|
||||
|
||||
internal byte BaseReadMemory(ushort addr)
|
||||
|
@ -199,123 +196,47 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private void RebootCore()
|
||||
{
|
||||
// Regenerate mapper here to make sure its state is entirely clean
|
||||
switch (_game.GetOptionsDict()["m"])
|
||||
_mapper = _game.GetOptionsDict()["m"] switch
|
||||
{
|
||||
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 = SetMultiCartMapper(Rom.Length, 32);
|
||||
break;
|
||||
case "AR":
|
||||
_mapper = new mAR(this); // This mapper has to set up configurations in the contructor.
|
||||
break;
|
||||
case "4K":
|
||||
_mapper = new m4K();
|
||||
break;
|
||||
case "2K":
|
||||
_mapper = new m2K();
|
||||
break;
|
||||
case "CM":
|
||||
_mapper = new mCM();
|
||||
break;
|
||||
case "CV":
|
||||
_mapper = new mCV();
|
||||
break;
|
||||
case "DPC":
|
||||
_mapper = new mDPC();
|
||||
break;
|
||||
case "DPC+":
|
||||
_mapper = new mDPCPlus();
|
||||
break;
|
||||
case "F8":
|
||||
_mapper = new mF8();
|
||||
break;
|
||||
case "F8SC":
|
||||
_mapper = new mF8SC();
|
||||
break;
|
||||
case "F6":
|
||||
_mapper = new mF6();
|
||||
break;
|
||||
case "F6SC":
|
||||
_mapper = new mF6SC();
|
||||
break;
|
||||
case "F4":
|
||||
_mapper = new mF4();
|
||||
break;
|
||||
case "F4SC":
|
||||
_mapper = new mF4SC();
|
||||
break;
|
||||
case "FE":
|
||||
_mapper = new mFE();
|
||||
break;
|
||||
case "E0":
|
||||
_mapper = new mE0();
|
||||
break;
|
||||
case "3F":
|
||||
_mapper = new m3F();
|
||||
break;
|
||||
case "FA":
|
||||
_mapper = new mFA();
|
||||
break;
|
||||
case "FA2":
|
||||
_mapper = new mFA2();
|
||||
break;
|
||||
case "E7":
|
||||
_mapper = new mE7();
|
||||
break;
|
||||
case "F0":
|
||||
_mapper = new mF0();
|
||||
break;
|
||||
case "UA":
|
||||
_mapper = new mUA();
|
||||
break;
|
||||
|
||||
// Special Sega Mapper which has swapped banks
|
||||
case "F8_sega":
|
||||
_mapper = new mF8_sega();
|
||||
break;
|
||||
"2IN1" => SetMultiCartMapper(Rom.Length, 2),
|
||||
"4IN1" => SetMultiCartMapper(Rom.Length, 4),
|
||||
"8IN1" => SetMultiCartMapper(Rom.Length, 8),
|
||||
"16IN1" => SetMultiCartMapper(Rom.Length, 16),
|
||||
"32IN1" => SetMultiCartMapper(Rom.Length, 32),
|
||||
"AR" => new mAR(this),
|
||||
"4K" => new m4K(this),
|
||||
"2K" => new m2K(this),
|
||||
"CM" => new mCM(this),
|
||||
"CV" => new mCV(this),
|
||||
"DPC" => new mDPC(this),
|
||||
"DPC+" => new mDPCPlus(this),
|
||||
"F8" => new mF8(this),
|
||||
"F8SC" => new mF8SC(this),
|
||||
"F6" => new mF6(this),
|
||||
"F6SC" => new mF6SC(this),
|
||||
"F4" => new mF4(this),
|
||||
"F4SC" => new mF4SC(this),
|
||||
"FE" => new mFE(this),
|
||||
"E0" => new mE0(this),
|
||||
"3F" => new m3F(this),
|
||||
"FA" => new mFA(this),
|
||||
"FA2" => new mFA2(this),
|
||||
"E7" => new mE7(this),
|
||||
"F0" => new mF0(this),
|
||||
"UA" => new mUA(this),
|
||||
"F8_sega" => new mF8_sega(this),
|
||||
|
||||
// Homebrew mappers
|
||||
case "3E":
|
||||
_mapper = new m3E();
|
||||
break;
|
||||
case "0840":
|
||||
_mapper = new m0840();
|
||||
break;
|
||||
case "MC":
|
||||
_mapper = new mMC();
|
||||
break;
|
||||
case "EF":
|
||||
_mapper = new mEF();
|
||||
break;
|
||||
case "EFSC":
|
||||
_mapper = new mEFSC();
|
||||
break;
|
||||
case "X07":
|
||||
_mapper = new mX07();
|
||||
break;
|
||||
case "4A50":
|
||||
_mapper = new m4A50();
|
||||
break;
|
||||
case "SB":
|
||||
_mapper = new mSB();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException("mapper not supported: " + _game.GetOptionsDict()["m"]);
|
||||
}
|
||||
|
||||
_mapper.Core = this;
|
||||
"3E" => new m3E(this),
|
||||
"0840" => new m0840(this),
|
||||
"MC" => new mMC(this),
|
||||
"EF" => new mEF(this),
|
||||
"EFSC" => new mEFSC(this),
|
||||
"X07" => new mX07(this),
|
||||
"4A50" => new m4A50(this),
|
||||
"SB" => new mSB(this),
|
||||
_ => throw new InvalidOperationException("mapper not supported: " + _game.GetOptionsDict()["m"])
|
||||
};
|
||||
|
||||
_lagCount = 0;
|
||||
Cpu = new MOS6502X<CpuLink>(new CpuLink(this));
|
||||
|
@ -342,7 +263,6 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
HardReset();
|
||||
|
||||
// Show mapper class on romstatusdetails
|
||||
RomDetails = $"{_game.Name}\r\nSHA1:{Rom.HashSHA1()}\r\nMD5:{Rom.HashMD5()}\r\nMapper Impl \"{_mapper.GetType()}\"";
|
||||
|
||||
// Some games (ex. 3D tic tac toe), turn off the screen for extended periods, so we need to allow for this here.
|
||||
|
|
|
@ -4,29 +4,26 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
public class MapperBase
|
||||
{
|
||||
public Atari2600 Core { get; set; }
|
||||
public MapperBase(Atari2600 core)
|
||||
{
|
||||
Core = core;
|
||||
}
|
||||
|
||||
protected readonly Atari2600 Core;
|
||||
|
||||
public virtual byte[] CartRam => new byte[0];
|
||||
|
||||
public virtual byte ReadMemory(ushort addr)
|
||||
{
|
||||
return Core.BaseReadMemory(addr);
|
||||
}
|
||||
=> Core.BaseReadMemory(addr);
|
||||
|
||||
public virtual byte PeekMemory(ushort addr)
|
||||
{
|
||||
return Core.BasePeekMemory(addr);
|
||||
}
|
||||
=> Core.BasePeekMemory(addr);
|
||||
|
||||
public virtual void WriteMemory(ushort addr, byte value)
|
||||
{
|
||||
Core.BaseWriteMemory(addr, value);
|
||||
}
|
||||
=> Core.BaseWriteMemory(addr, value);
|
||||
|
||||
public virtual void PokeMemory(ushort addr, byte value)
|
||||
{
|
||||
Core.BasePokeMemory(addr, value);
|
||||
}
|
||||
=> Core.BasePokeMemory(addr, value);
|
||||
|
||||
public virtual void SyncState(Serializer ser)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private int _gameTotal;
|
||||
private int _currentGame;
|
||||
|
||||
public Multicart2K(int gameTotal)
|
||||
public Multicart2K(Atari2600 core, int gameTotal)
|
||||
: base(core)
|
||||
{
|
||||
_gameTotal = gameTotal;
|
||||
_currentGame = 0;
|
||||
|
|
|
@ -10,7 +10,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private int _gameTotal;
|
||||
private int _currentGame;
|
||||
|
||||
public Multicart4K(int gameTotal)
|
||||
public Multicart4K(Atari2600 core, int gameTotal)
|
||||
: base(core)
|
||||
{
|
||||
_gameTotal = gameTotal;
|
||||
_currentGame = 0;
|
||||
|
|
|
@ -12,7 +12,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private int _gameTotal;
|
||||
private int _currentGame;
|
||||
|
||||
public Multicart8K(int gameTotal)
|
||||
public Multicart8K(Atari2600 core, int gameTotal)
|
||||
: base(core)
|
||||
{
|
||||
_gameTotal = gameTotal;
|
||||
_currentGame = 0;
|
||||
|
|
|
@ -23,6 +23,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class m0840 : MapperBase
|
||||
{
|
||||
public m0840(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _bank4K;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
{
|
||||
internal class m2K : MapperBase
|
||||
{
|
||||
public m2K(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000)
|
||||
|
|
|
@ -22,6 +22,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class m3E : MapperBase
|
||||
{
|
||||
public m3E(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _lowbank2K;
|
||||
private int _rambank1K;
|
||||
private bool _hasRam;
|
||||
|
|
|
@ -23,6 +23,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
internal class m3F : MapperBase
|
||||
{
|
||||
public m3F(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _lowbank2K;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
|
|
|
@ -43,6 +43,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
internal class m4A50 : MapperBase
|
||||
{
|
||||
public m4A50(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private byte[] _ram = new byte[32768];
|
||||
|
||||
private byte _lastData = 0xFF;
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
{
|
||||
internal class m4K : MapperBase
|
||||
{
|
||||
public m4K(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000)
|
||||
|
|
|
@ -33,9 +33,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
internal class mAR : MapperBase
|
||||
{
|
||||
public mAR(Atari2600 core)
|
||||
public mAR(Atari2600 core) : base(core)
|
||||
{
|
||||
Core = core;
|
||||
InitializeSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -179,6 +179,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class mCM : MapperBase
|
||||
{
|
||||
public mCM(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: PokeMem
|
||||
private byte[] _ram = new byte[2048];
|
||||
private int _bank4K = 3; // On Start up, controller port is all 1's, so start on the last bank, flags enabled
|
||||
|
|
|
@ -17,6 +17,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class mCV : MapperBase
|
||||
{
|
||||
public mCV(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private byte[] _ram = new byte[1024];
|
||||
|
||||
public override byte[] CartRam => _ram;
|
||||
|
|
|
@ -225,6 +225,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class mDPC : MapperBase
|
||||
{
|
||||
public mDPC(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
// Table for computing the input bit of the random number generator's
|
||||
// shift register (it's the NOT of the EOR of four bits)
|
||||
private readonly byte[] _randomInputBits = { 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 };
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
internal class mDPCPlus : MapperBase
|
||||
{
|
||||
// TODO: PokeMem, and everything else
|
||||
public mDPCPlus()
|
||||
public mDPCPlus(Atari2600 core) : base(core)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
internal class mE0 : MapperBase
|
||||
{
|
||||
public mE0(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _toggle1;
|
||||
private int _toggle2;
|
||||
private int _toggle3;
|
||||
|
|
|
@ -36,6 +36,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
private bool _enableRam0;
|
||||
|
||||
public mE7(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -16,6 +16,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
private int _toggle;
|
||||
|
||||
public mEF(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -9,6 +9,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class mEFSC : MapperBase
|
||||
{
|
||||
public mEFSC(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _bank4k;
|
||||
private byte[] _ram = new byte[128];
|
||||
|
||||
|
|
|
@ -22,6 +22,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
private int _bank;
|
||||
|
||||
public mF0(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -14,6 +14,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
private int _toggle;
|
||||
|
||||
public mF4(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -11,6 +11,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private int _bank4k;
|
||||
private byte[] _ram = new byte[128];
|
||||
|
||||
public mF4SC(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override byte[] CartRam => _ram;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
|
|
|
@ -13,6 +13,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
internal class mF6 : MapperBase
|
||||
{
|
||||
public mF6(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _toggle;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
|
|
|
@ -8,6 +8,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class mF6SC : MapperBase
|
||||
{
|
||||
public mF6SC(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _bank4k;
|
||||
private byte[] _ram = new byte[128];
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
private int _bank4K;
|
||||
|
||||
public mF8(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -8,6 +8,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class mF8SC : MapperBase
|
||||
{
|
||||
public mF8SC(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _bank_4K;
|
||||
private byte[] _ram = new byte[128];
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
private int _bank4K = 1;
|
||||
|
||||
public mF8_sega(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -19,6 +19,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private int _toggle;
|
||||
private byte[] _ram = new byte[256];
|
||||
|
||||
public mFA(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -10,6 +10,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
*/
|
||||
internal class mFA2 : MapperBase
|
||||
{
|
||||
public mFA2(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _bank4k;
|
||||
private byte[] _ram = new byte[256];
|
||||
|
||||
|
|
|
@ -56,6 +56,10 @@
|
|||
*/
|
||||
internal class mFE : MapperBase
|
||||
{
|
||||
public mFE(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000)
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
internal class mMC : MapperBase
|
||||
{
|
||||
public mMC()
|
||||
public mMC(Atari2600 core) : base(core)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
private int _bank4K;
|
||||
private int myStartBank => (Core.Rom.Length >> 12) - 1;
|
||||
|
||||
public mSB(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
|
|
|
@ -14,6 +14,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
internal class mUA : MapperBase
|
||||
{
|
||||
public mUA(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _toggle;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
|
|
|
@ -35,6 +35,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
internal class mX07 : MapperBase
|
||||
{
|
||||
public mX07(Atari2600 core) : base(core)
|
||||
{
|
||||
}
|
||||
|
||||
private int _rombank2K;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
|
|
Loading…
Reference in New Issue