a2600-add mapper system
This commit is contained in:
parent
91f5733662
commit
6fc4ff01c5
|
@ -78,6 +78,9 @@
|
|||
<Compile Include="Buffer.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Atari2600.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Atari2600.Core.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\m2K.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\m4K.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\Mappers\mF8.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\oldTIA.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\M6532.cs" />
|
||||
<Compile Include="Consoles\Atari\2600\TIA.cs">
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace BizHawk
|
|||
public MOS6502X cpu;
|
||||
public M6532 m6532;
|
||||
public TIA tia;
|
||||
public byte[] ram = new byte[128];
|
||||
public MapperBase mapper;
|
||||
|
||||
bool resetSignal;
|
||||
|
||||
|
@ -56,7 +58,7 @@ namespace BizHawk
|
|||
// registers
|
||||
// else
|
||||
// ROM
|
||||
public byte ReadMemory(ushort addr)
|
||||
public byte BaseReadMemory(ushort addr)
|
||||
{
|
||||
addr = (ushort)(addr & 0x1FFF);
|
||||
if ((addr & 0x1080) == 0)
|
||||
|
@ -73,7 +75,7 @@ namespace BizHawk
|
|||
}
|
||||
}
|
||||
|
||||
public void WriteMemory(ushort addr, byte value)
|
||||
public void BaseWriteMemory(ushort addr, byte value)
|
||||
{
|
||||
addr = (ushort)(addr & 0x1FFF);
|
||||
if ((addr & 0x1080) == 0)
|
||||
|
@ -90,8 +92,28 @@ namespace BizHawk
|
|||
}
|
||||
}
|
||||
|
||||
public byte ReadMemory(ushort addr)
|
||||
{
|
||||
return mapper.ReadMemory((ushort)(addr&0x1FFF));
|
||||
}
|
||||
|
||||
public void WriteMemory(ushort addr, byte value)
|
||||
{
|
||||
mapper.WriteMemory((ushort)(addr & 0x1FFF), value);
|
||||
}
|
||||
|
||||
public void HardReset()
|
||||
{
|
||||
//regenerate mapper here to make sure its state is entirely clean
|
||||
switch (game.GetOptionsDict()["m"])
|
||||
{
|
||||
case "4K": mapper = new m4K(); break;
|
||||
case "2K": mapper = new m2K(); break;
|
||||
case "F8": mapper = new mF8(); break;
|
||||
default: throw new InvalidOperationException("mapper not supported: " + game.GetOptionsDict()["m"]);
|
||||
}
|
||||
mapper.core = this;
|
||||
|
||||
_lagcount = 0;
|
||||
cpu = new MOS6502X();
|
||||
//cpu.debug = true;
|
||||
|
@ -107,8 +129,9 @@ namespace BizHawk
|
|||
|
||||
//setup the system state here. for instance..
|
||||
// Read from the reset vector for where to start
|
||||
cpu.PC = (ushort)(ReadMemory(0xFFFC) + (ReadMemory(0xFFFD) << 8)); //set the initial PC
|
||||
cpu.PC = (ushort)(ReadMemory(0x1FFC) + (ReadMemory(0x1FFD) << 8)); //set the initial PC
|
||||
//cpu.PC = 0x0000; //set the initial PC
|
||||
|
||||
}
|
||||
|
||||
public void FrameAdvance(bool render)
|
||||
|
@ -184,7 +207,13 @@ namespace BizHawk
|
|||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class MapperBase
|
||||
{
|
||||
public Atari2600 core;
|
||||
public virtual byte ReadMemory(ushort addr) { return core.BaseReadMemory(addr); }
|
||||
public virtual void WriteMemory(ushort addr, byte value) { core.BaseWriteMemory(addr, value); }
|
||||
public virtual void SyncState(Serializer ser) { }
|
||||
}
|
||||
}
|
|
@ -7,22 +7,24 @@ namespace BizHawk
|
|||
public partial class Atari2600 : IEmulator, IVideoProvider, ISoundProvider
|
||||
{
|
||||
public string SystemId { get { return "A26"; } }
|
||||
public GameInfo game;
|
||||
|
||||
public int[] frameBuffer = new int[320 * 262];
|
||||
public CoreInputComm CoreInputComm { get; set; }
|
||||
public CoreOutputComm CoreOutputComm { get; private set; }
|
||||
public IVideoProvider VideoProvider { get { return this; } }
|
||||
public ISoundProvider SoundProvider { get { return this; } }
|
||||
public byte[] ram = new byte[128];
|
||||
|
||||
public Atari2600(GameInfo game, byte[] rom)
|
||||
{
|
||||
var domains = new List<MemoryDomain>(1);
|
||||
Console.WriteLine("Game uses mapper " + game.GetOptionsDict()["m"]);
|
||||
domains.Add(new MemoryDomain("Main RAM", 128, Endian.Little, addr => ram[addr & 127], (addr, value) => ram[addr & 127] = value));
|
||||
memoryDomains = domains.AsReadOnly();
|
||||
CoreOutputComm = new CoreOutputComm();
|
||||
CoreInputComm = new CoreInputComm();
|
||||
this.rom = rom;
|
||||
this.game = game;
|
||||
Console.WriteLine("Game uses mapper " + game.GetOptionsDict()["m"]);
|
||||
HardReset();
|
||||
}
|
||||
public void ResetFrameCounter()
|
||||
|
@ -47,6 +49,8 @@ namespace BizHawk
|
|||
ser.Sync("ram", ref ram, false);
|
||||
ser.Sync("Lag", ref _lagcount);
|
||||
ser.Sync("Frame", ref _frame);
|
||||
//TODO - you need to sync your m6532 and tia
|
||||
mapper.SyncState(ser);
|
||||
}
|
||||
|
||||
public ControllerDefinition ControllerDefinition { get { return Atari2600ControllerDefinition; } }
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BizHawk.Emulation.CPUs.M6502;
|
||||
using BizHawk.Emulation.Consoles.Atari;
|
||||
|
||||
namespace BizHawk
|
||||
{
|
||||
partial class Atari2600
|
||||
{
|
||||
class m2K : MapperBase
|
||||
{
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000) return base.ReadMemory(addr);
|
||||
return core.rom[addr & 0x7FF];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BizHawk.Emulation.CPUs.M6502;
|
||||
using BizHawk.Emulation.Consoles.Atari;
|
||||
|
||||
namespace BizHawk
|
||||
{
|
||||
partial class Atari2600
|
||||
{
|
||||
class m4K : MapperBase
|
||||
{
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x1000) return base.ReadMemory(addr);
|
||||
return core.rom[addr & 0xFFF];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BizHawk.Emulation.CPUs.M6502;
|
||||
using BizHawk.Emulation.Consoles.Atari;
|
||||
|
||||
namespace BizHawk
|
||||
{
|
||||
partial class Atari2600
|
||||
{
|
||||
class mF8 : MapperBase
|
||||
{
|
||||
int toggle = 0;
|
||||
|
||||
public override byte ReadMemory(ushort addr)
|
||||
{
|
||||
Address(addr);
|
||||
if (addr < 0x1000) return base.ReadMemory(addr);
|
||||
return core.rom[toggle*4*1024 + (addr&0xFFF)];
|
||||
}
|
||||
public override void WriteMemory(ushort addr, byte value)
|
||||
{
|
||||
Address(addr);
|
||||
if (addr < 0x1000) base.WriteMemory(addr, value);
|
||||
}
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
base.SyncState(ser);
|
||||
ser.Sync("toggle", ref toggle);
|
||||
}
|
||||
|
||||
void Address(ushort addr)
|
||||
{
|
||||
if (addr == 0x1FF8) toggle = 0;
|
||||
if (addr == 0x1FF9) toggle = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue