Start an atari 7800 core based on emu7800, if you have bios files in very specific locations and filenames, you can open 2k ntsc games, and watch with no sound or controls!
This commit is contained in:
parent
2cdeabfcf3
commit
427a80548c
|
@ -103,6 +103,72 @@
|
|||
<Compile Include="Consoles\Atari\2600\TIA.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Atari\7800\Atari7800.Core.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\Atari7800.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\AddressSpace.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Bios7800.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\BufferElement.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart7808.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart7816.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart7832.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart7832P.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart7848.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart78AB.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart78AC.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart78S4.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart78S9.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart78SG.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Cart78SGP.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA16K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA16KR.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA2K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA32K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA32KR.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA4K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA8K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartA8KR.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartCBS12K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartDC8K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartDPC.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartMN16K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartPB8K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartTV8K.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\CartType.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\ConsoleSwitch.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Controller.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\ControllerAction.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\DeserializationContext.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Emu7800Exception.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Emu7800SerializationException.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\FontRenderer.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\FrameBuffer.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\HSC7800.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\IDevice.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\ILogger.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\InputState.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\M6502.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\M6502DASM.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Machine2600.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Machine2600NTSC.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Machine2600PAL.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Machine7800.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Machine7800NTSC.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Machine7800PAL.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\MachineBase.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\MachineInput.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\MachineType.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\Maria.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\MariaTables.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\NullDevice.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\NullLogger.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\PIA.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\PokeySound.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\RAM6116.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\SerializationContext.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\TIA.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\TIASound.cs" />
|
||||
<Compile Include="Consoles\Atari\7800\EMU7800\TIATables.cs" />
|
||||
<Compile Include="Consoles\Calculator\TI83.cs" />
|
||||
<Compile Include="Consoles\Coleco\ColecoVision.Core.cs" />
|
||||
<Compile Include="Consoles\Coleco\ColecoVision.cs" />
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BizHawk.Emulation.CPUs.M6502;
|
||||
using BizHawk.Emulation.Consoles.Atari;
|
||||
using EMU7800.Core;
|
||||
|
||||
namespace BizHawk
|
||||
{
|
||||
partial class Atari7800
|
||||
{
|
||||
public byte[] rom;
|
||||
Bios7800 BIOS;
|
||||
public byte[] hsbios;
|
||||
Cart cart;
|
||||
Machine7800NTSC theMachine; //TODO: PAL support
|
||||
}
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using EMU7800.Core;
|
||||
|
||||
namespace BizHawk
|
||||
{
|
||||
public partial class Atari7800 : IEmulator
|
||||
{
|
||||
public string SystemId { get { return "A78"; } } //TODO: are we going to allow this core to do 2600 games?
|
||||
public GameInfo game;
|
||||
|
||||
public void FrameAdvance(bool render, bool rendersound)
|
||||
{
|
||||
_frame++;
|
||||
_islag = true;
|
||||
|
||||
//TODO
|
||||
FrameBuffer fb = new FrameBuffer(0, 262); //TODO: 262 is NTSC
|
||||
theMachine.ComputeNextFrame(fb);
|
||||
if (_islag)
|
||||
{
|
||||
LagCount++;
|
||||
}
|
||||
|
||||
videoProvider.FillFrameBuffer();
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
public CoreInputComm CoreInputComm { get; set; }
|
||||
public CoreOutputComm CoreOutputComm { get; private set; }
|
||||
public ISyncSoundProvider SyncSoundProvider { get { return null; } }
|
||||
public bool StartAsyncSound() { return true; }
|
||||
public void EndAsyncSound() { }
|
||||
public bool DeterministicEmulation { get; set; }
|
||||
public void SaveStateText(TextWriter writer) { }
|
||||
public void LoadStateText(TextReader reader) { }
|
||||
public void SaveStateBinary(BinaryWriter bw) { }
|
||||
public void LoadStateBinary(BinaryReader br) { }
|
||||
private IList<MemoryDomain> memoryDomains;
|
||||
public IList<MemoryDomain> MemoryDomains { get { return null; } }
|
||||
public MemoryDomain MainMemory { get { return null; } }
|
||||
/********************/
|
||||
|
||||
public int Frame { get { return _frame; } set { _frame = value; } }
|
||||
public int LagCount { get { return _lagcount; } set { _lagcount = value; } }
|
||||
public bool IsLagFrame { get { return _islag; } }
|
||||
private bool _islag = true;
|
||||
private int _lagcount = 0;
|
||||
private int _frame = 0;
|
||||
|
||||
public byte[] ReadSaveRam() { return null; }
|
||||
public void StoreSaveRam(byte[] data) { }
|
||||
public void ClearSaveRam() { }
|
||||
public bool SaveRamModified { get; set; }
|
||||
public void Dispose() { }
|
||||
public IVideoProvider VideoProvider { get { return videoProvider; } }
|
||||
public ISoundProvider SoundProvider { get { return soundProvider; } }
|
||||
|
||||
|
||||
public void ResetFrameCounter()
|
||||
{
|
||||
_frame = 0;
|
||||
}
|
||||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
public ControllerDefinition ControllerDefinition { get { return Atari7800ControllerDefinition; } }
|
||||
public IController Controller { get; set; }
|
||||
public static readonly ControllerDefinition Atari7800ControllerDefinition = new ControllerDefinition
|
||||
{
|
||||
Name = "Atari 7800 Basic Controller", //TODO
|
||||
BoolButtons =
|
||||
{
|
||||
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button",
|
||||
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button",
|
||||
"Reset", "Select"
|
||||
}
|
||||
};
|
||||
|
||||
public Atari7800(GameInfo game, byte[] rom, byte[] bios, byte[] highscoreBIOS)
|
||||
{
|
||||
var domains = new List<MemoryDomain>(1);
|
||||
domains.Add(new MemoryDomain("Main RAM", 1, Endian.Little, addr => 0xFF, null)); //TODO
|
||||
memoryDomains = domains.AsReadOnly();
|
||||
CoreOutputComm = new CoreOutputComm();
|
||||
CoreInputComm = new CoreInputComm();
|
||||
this.rom = rom;
|
||||
this.game = game;
|
||||
this.hsbios = highscoreBIOS;
|
||||
BIOS = new Bios7800(bios);
|
||||
videoProvider = new MyVideoProvider(this);
|
||||
soundProvider = new MySoundProvider(); //TODO
|
||||
HardReset();
|
||||
}
|
||||
|
||||
public void HardReset()
|
||||
{
|
||||
_lagcount = 0;
|
||||
// show mapper class on romstatusdetails
|
||||
CoreOutputComm.RomStatusDetails =
|
||||
string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\nMapper Impl \"{3}\"",
|
||||
game.Name,
|
||||
Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(rom)),
|
||||
Util.BytesToHexString(System.Security.Cryptography.MD5.Create().ComputeHash(rom)),
|
||||
"TODO");
|
||||
|
||||
cart = new CartA2K(rom); //TODO: mapper selection system
|
||||
|
||||
int[] bob = new int[] { 0, 0, 0 };
|
||||
|
||||
FileStream fs = new FileStream("C:\\dummy", FileMode.Create, FileAccess.ReadWrite); //TODO: I don't see what this context is used for, see if it can be whacked or pass in a null
|
||||
BinaryReader blah = new BinaryReader(fs);
|
||||
DeserializationContext george = new DeserializationContext(blah);
|
||||
NullLogger logger = new NullLogger();
|
||||
HSC7800 hsc7800 = new HSC7800(hsbios, new byte[4096]); //TODO: why should I have to feed it ram? how much?
|
||||
theMachine = new Machine7800NTSC(cart, BIOS, hsc7800, logger);
|
||||
//TODO: clean up, the hs and bios are passed in, the bios has an object AND byte array in the core, and naming is inconsistent
|
||||
}
|
||||
|
||||
void SyncState(Serializer ser) //TODO
|
||||
{
|
||||
ser.Sync("Lag", ref _lagcount);
|
||||
ser.Sync("Frame", ref _frame);
|
||||
ser.Sync("IsLag", ref _islag);
|
||||
}
|
||||
|
||||
private void SoftReset() //TOOD: hook this up
|
||||
{
|
||||
theMachine.Reset();
|
||||
}
|
||||
|
||||
MyVideoProvider videoProvider;
|
||||
|
||||
class MyVideoProvider : IVideoProvider
|
||||
{
|
||||
public int top = 0; //TODO: I should delete these probably
|
||||
public int bottom = 262;
|
||||
public int left = 0;
|
||||
public int right = 320;
|
||||
|
||||
Atari7800 emu;
|
||||
public MyVideoProvider(Atari7800 emu)
|
||||
{
|
||||
this.emu = emu;
|
||||
}
|
||||
|
||||
int[] buffer = new int[262 * 320]; //TODO: use videobuffer values for this if there's a logical way
|
||||
|
||||
public void FillFrameBuffer() //TODO: don't recalculate consantly, fill this on frame advance instead
|
||||
{
|
||||
FrameBuffer fb = emu.theMachine.CreateFrameBuffer();
|
||||
|
||||
|
||||
for (int i = 0; i < 262; i++)
|
||||
{
|
||||
for (int j = 0; j < 320; j++)
|
||||
{
|
||||
buffer[(i * fb.VisiblePitch) + j] = fb.VideoBuffer[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int[] GetVideoBuffer()
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public int VirtualWidth { get { return BufferWidth; } }
|
||||
public int BufferWidth { get { return right - left + 1; } }
|
||||
public int BufferHeight { get { return bottom - top + 1; } }
|
||||
public int BackgroundColor { get { return 0; } }
|
||||
}
|
||||
|
||||
MySoundProvider soundProvider;
|
||||
|
||||
class MySoundProvider : ISoundProvider
|
||||
{
|
||||
public int MaxVolume { get { return 0; } set { } }
|
||||
public void DiscardSamples()
|
||||
{
|
||||
}
|
||||
|
||||
public void GetSamples(short[] samples)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* AddressSpace.cs
|
||||
*
|
||||
* The class representing the memory map or address space of a machine.
|
||||
*
|
||||
* Copyright © 2003, 2011 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class AddressSpace
|
||||
{
|
||||
public MachineBase M { get; private set; }
|
||||
|
||||
readonly int AddrSpaceShift;
|
||||
readonly int AddrSpaceSize;
|
||||
readonly int AddrSpaceMask;
|
||||
|
||||
readonly int PageShift;
|
||||
readonly int PageSize;
|
||||
|
||||
readonly IDevice[] MemoryMap;
|
||||
IDevice Snooper;
|
||||
|
||||
public byte DataBusState { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "AddressSpace";
|
||||
}
|
||||
|
||||
public byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Snooper != null)
|
||||
{
|
||||
// here DataBusState is just facilitating a dummy read to the snooper device
|
||||
// the read operation may have important side effects within the device
|
||||
DataBusState = Snooper[addr];
|
||||
}
|
||||
var pageno = (addr & AddrSpaceMask) >> PageShift;
|
||||
var dev = MemoryMap[pageno];
|
||||
DataBusState = dev[addr];
|
||||
return DataBusState;
|
||||
}
|
||||
set
|
||||
{
|
||||
DataBusState = value;
|
||||
if (Snooper != null)
|
||||
{
|
||||
Snooper[addr] = DataBusState;
|
||||
}
|
||||
var pageno = (addr & AddrSpaceMask) >> PageShift;
|
||||
var dev = MemoryMap[pageno];
|
||||
dev[addr] = DataBusState;
|
||||
}
|
||||
}
|
||||
|
||||
public void Map(ushort basea, ushort size, IDevice device)
|
||||
{
|
||||
if (device == null)
|
||||
throw new ArgumentNullException("device");
|
||||
|
||||
for (int addr = basea; addr < basea + size; addr += PageSize)
|
||||
{
|
||||
var pageno = (addr & AddrSpaceMask) >> PageShift;
|
||||
MemoryMap[pageno] = device;
|
||||
}
|
||||
|
||||
LogDebug("{0}: Mapped {1} to ${2:x4}:${3:x4}", this, device, basea, basea + size - 1);
|
||||
}
|
||||
|
||||
public void Map(ushort basea, ushort size, Cart cart)
|
||||
{
|
||||
if (cart == null)
|
||||
throw new ArgumentNullException("cart");
|
||||
|
||||
cart.Attach(M);
|
||||
var device = (IDevice)cart;
|
||||
if (cart.RequestSnooping)
|
||||
{
|
||||
Snooper = device;
|
||||
}
|
||||
Map(basea, size, device);
|
||||
}
|
||||
|
||||
#region Constructors
|
||||
|
||||
private AddressSpace()
|
||||
{
|
||||
}
|
||||
|
||||
public AddressSpace(MachineBase m, int addrSpaceShift, int pageShift)
|
||||
{
|
||||
if (m == null)
|
||||
throw new ArgumentNullException("m");
|
||||
|
||||
M = m;
|
||||
|
||||
AddrSpaceShift = addrSpaceShift;
|
||||
AddrSpaceSize = 1 << AddrSpaceShift;
|
||||
AddrSpaceMask = AddrSpaceSize - 1;
|
||||
|
||||
PageShift = pageShift;
|
||||
PageSize = 1 << PageShift;
|
||||
|
||||
MemoryMap = new IDevice[1 << addrSpaceShift >> PageShift];
|
||||
IDevice nullDev = new NullDevice(M);
|
||||
for (var pageno=0; pageno < MemoryMap.Length; pageno++)
|
||||
{
|
||||
MemoryMap[pageno] = nullDev;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public AddressSpace(DeserializationContext input, MachineBase m, int addrSpaceShift, int pageShift) : this(m, addrSpaceShift, pageShift)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
DataBusState = input.ReadByte();
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(DataBusState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
[System.Diagnostics.Conditional("DEBUG")]
|
||||
void LogDebug(string format, params object[] args)
|
||||
{
|
||||
if (M == null || M.Logger == null)
|
||||
return;
|
||||
M.Logger.WriteLine(format, args);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* BIOS7800.cs
|
||||
*
|
||||
* The BIOS of the Atari 7800.
|
||||
*
|
||||
* Copyright © 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class Bios7800 : IDevice
|
||||
{
|
||||
readonly byte[] ROM;
|
||||
readonly ushort Mask;
|
||||
|
||||
public ushort Size { get { return (ushort)ROM.Length; } }
|
||||
|
||||
public void Reset() { }
|
||||
|
||||
public byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr & Mask]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public Bios7800(byte[] rom)
|
||||
{
|
||||
if (rom == null)
|
||||
throw new ArgumentNullException("rom");
|
||||
if (rom.Length != 4096 && rom.Length != 16384)
|
||||
throw new ArgumentException("ROM size not 4096 or 16384", "rom");
|
||||
|
||||
ROM = rom;
|
||||
Mask = (ushort)ROM.Length;
|
||||
Mask--;
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Bios7800(DeserializationContext input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
ROM = input.ReadExpectedBytes(4096, 16384);
|
||||
|
||||
Mask = (ushort)ROM.Length;
|
||||
Mask--;
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Frames are composed of <see cref="BufferElement"/>s,
|
||||
/// that group bytes into machine words for efficient array processing.
|
||||
/// Bytes are packed in logical little endian order.
|
||||
/// </summary>
|
||||
public struct BufferElement
|
||||
{
|
||||
/// <summary>
|
||||
/// The number of bytes contained within a <see cref="BufferElement"/>.
|
||||
/// </summary>
|
||||
public const int SIZE = 4; // 2^SHIFT
|
||||
|
||||
/// <summary>
|
||||
/// The mask value applied against a byte array index to access the individual bytes within a <see cref="BufferElement"/>.
|
||||
/// </summary>
|
||||
public const int MASK = 3; // SIZE - 1
|
||||
|
||||
/// <summary>
|
||||
/// The left shift value to convert a byte array index to a <see cref="BufferElement"/> array index.
|
||||
/// </summary>
|
||||
public const int SHIFT = 2;
|
||||
|
||||
uint _data;
|
||||
|
||||
/// <summary>
|
||||
/// A convenience accessor for reading/writing individual bytes within this <see cref="BufferElement"/>.
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
public byte this[int offset]
|
||||
{
|
||||
get
|
||||
{
|
||||
var i = (offset & MASK) << 3;
|
||||
return (byte)(_data >> i);
|
||||
}
|
||||
set
|
||||
{
|
||||
var i = (offset & MASK) << 3;
|
||||
var d = (uint)value << i;
|
||||
var di = (uint)0xff << i;
|
||||
_data = _data & ~di | d;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Zeros out all bytes of this <see cref="BufferElement"/>.
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
_data = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Cart.cs
|
||||
*
|
||||
* An abstraction of a game cart. Attributable to Kevin Horton's Bankswitching
|
||||
* document, the Stella source code, and Eckhard Stolberg's 7800 Bankswitching Guide.
|
||||
*
|
||||
* Copyright Š 2003, 2004, 2010, 2011 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public abstract class Cart : IDevice
|
||||
{
|
||||
static int _multicartBankSelector;
|
||||
|
||||
protected MachineBase M { get; set; }
|
||||
protected internal byte[] ROM { get; set; }
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public virtual void Reset() { }
|
||||
|
||||
public abstract byte this[ushort addr] { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public virtual void Attach(MachineBase m)
|
||||
{
|
||||
if (m == null)
|
||||
throw new ArgumentNullException("m");
|
||||
if (M != null && M != m)
|
||||
throw new InvalidOperationException("Cart already attached to a different machine.");
|
||||
M = m;
|
||||
}
|
||||
|
||||
public virtual void StartFrame()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void EndFrame()
|
||||
{
|
||||
}
|
||||
|
||||
protected internal virtual bool RequestSnooping
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the specified cart.
|
||||
/// </summary>
|
||||
/// <param name="romBytes"></param>
|
||||
/// <param name="cartType"></param>
|
||||
/// <exception cref="Emu7800Exception">Specified CartType is unexpected.</exception>
|
||||
public static Cart Create(byte[] romBytes, CartType cartType)
|
||||
{
|
||||
if (cartType == CartType.None)
|
||||
{
|
||||
switch (romBytes.Length)
|
||||
{
|
||||
case 2048:
|
||||
cartType = CartType.A2K;
|
||||
break;
|
||||
case 4096:
|
||||
cartType = CartType.A4K;
|
||||
break;
|
||||
case 8192:
|
||||
cartType = CartType.A8K;
|
||||
break;
|
||||
case 16384:
|
||||
cartType = CartType.A16K;
|
||||
break;
|
||||
case 32768:
|
||||
cartType = CartType.A32K;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (cartType)
|
||||
{
|
||||
case CartType.A2K: return new CartA2K(romBytes);
|
||||
case CartType.A4K: return new CartA4K(romBytes);
|
||||
case CartType.A8K: return new CartA8K(romBytes);
|
||||
case CartType.A8KR: return new CartA8KR(romBytes);
|
||||
case CartType.A16K: return new CartA16K(romBytes);
|
||||
case CartType.A16KR: return new CartA16KR(romBytes);
|
||||
case CartType.DC8K: return new CartDC8K(romBytes);
|
||||
case CartType.PB8K: return new CartPB8K(romBytes);
|
||||
case CartType.TV8K: return new CartTV8K(romBytes);
|
||||
case CartType.CBS12K: return new CartCBS12K(romBytes);
|
||||
case CartType.A32K: return new CartA32K(romBytes);
|
||||
case CartType.A32KR: return new CartA32KR(romBytes);
|
||||
case CartType.MN16K: return new CartMN16K(romBytes);
|
||||
case CartType.DPC: return new CartDPC(romBytes);
|
||||
case CartType.M32N12K: return new CartA2K(romBytes, _multicartBankSelector++);
|
||||
case CartType.A7808: return new Cart7808(romBytes);
|
||||
case CartType.A7816: return new Cart7816(romBytes);
|
||||
case CartType.A7832P: return new Cart7832P(romBytes);
|
||||
case CartType.A7832: return new Cart7832(romBytes);
|
||||
case CartType.A7848: return new Cart7848(romBytes);
|
||||
case CartType.A78SGP: return new Cart78SGP(romBytes);
|
||||
case CartType.A78SG: return new Cart78SG(romBytes, false);
|
||||
case CartType.A78SGR: return new Cart78SG(romBytes, true);
|
||||
case CartType.A78S9: return new Cart78S9(romBytes);
|
||||
case CartType.A78S4: return new Cart78S4(romBytes, false);
|
||||
case CartType.A78S4R: return new Cart78S4(romBytes, true);
|
||||
case CartType.A78AB: return new Cart78AB(romBytes);
|
||||
case CartType.A78AC: return new Cart78AC(romBytes);
|
||||
default:
|
||||
throw new Emu7800Exception("Unexpected CartType: " + cartType);
|
||||
}
|
||||
}
|
||||
|
||||
protected void LoadRom(byte[] romBytes, int multicartBankSize, int multicartBankNo)
|
||||
{
|
||||
if (romBytes == null)
|
||||
throw new ArgumentNullException("romBytes");
|
||||
|
||||
ROM = new byte[multicartBankSize];
|
||||
Buffer.BlockCopy(romBytes, multicartBankSize*multicartBankNo, ROM, 0, multicartBankSize);
|
||||
}
|
||||
|
||||
protected void LoadRom(byte[] romBytes, int minSize)
|
||||
{
|
||||
if (romBytes == null)
|
||||
throw new ArgumentNullException("romBytes");
|
||||
|
||||
if (romBytes.Length >= minSize)
|
||||
{
|
||||
ROM = romBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
ROM = new byte[minSize];
|
||||
Buffer.BlockCopy(romBytes, 0, ROM, 0, romBytes.Length);
|
||||
}
|
||||
}
|
||||
|
||||
protected void LoadRom(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, romBytes.Length);
|
||||
}
|
||||
|
||||
protected Cart()
|
||||
{
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
protected Cart(DeserializationContext input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
}
|
||||
|
||||
public virtual void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 non-bankswitched 8KB cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart7808 : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// 0x0000:0x2000 0xE000:0x2000 (repeated downward to 0x4000)
|
||||
//
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr & 0x1fff]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart7808()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart7808(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x2000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart7808(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x2000), 0x2000);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 non-bankswitched 16KB cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart7816 : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// 0x0000:0x4000 0xC000:0x4000 (repeated downward to 0x4000)
|
||||
//
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr & 0x3fff]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart7816()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart7816(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x4000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart7816(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x4000), 0x4000);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 non-bankswitched 32KB cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart7832 : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// 0x0000:0x8000 0x8000:0x8000 (repeated downward until 0x4000)
|
||||
//
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr & 0x7fff]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart7832()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart7832(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x8000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart7832(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x8000), 0x8000);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 non-bankswitched 32KB cartridge w/Pokey
|
||||
/// </summary>
|
||||
public sealed class Cart7832P : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// 0x4000:0x4000 Pokey
|
||||
// 0x0000:0x8000 0x8000:0x8000
|
||||
//
|
||||
PokeySound _pokeySound;
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
if (_pokeySound != null)
|
||||
_pokeySound.Reset();
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((addr & 0xF000) == 0x4000 && _pokeySound != null) ? _pokeySound.Read(addr) : ROM[addr & 0x7fff];
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((addr & 0xF000) == 0x4000 && _pokeySound != null)
|
||||
_pokeySound.Update(addr, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void Attach(MachineBase m)
|
||||
{
|
||||
base.Attach(m);
|
||||
if (_pokeySound == null)
|
||||
_pokeySound = new PokeySound(M);
|
||||
}
|
||||
|
||||
public override void StartFrame()
|
||||
{
|
||||
if (_pokeySound != null)
|
||||
_pokeySound.StartFrame();
|
||||
}
|
||||
|
||||
public override void EndFrame()
|
||||
{
|
||||
if (_pokeySound != null)
|
||||
_pokeySound.EndFrame();
|
||||
}
|
||||
|
||||
private Cart7832P()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart7832P(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x8000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart7832P(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x8000), 0x8000);
|
||||
_pokeySound = input.ReadOptionalPokeySound(m);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (_pokeySound == null)
|
||||
throw new Emu7800SerializationException("Cart7832P must be attached before serialization.");
|
||||
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.WriteOptional(_pokeySound);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 non-bankswitched 48KB cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart7848 : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// 0x0000:0xc000 0x4000:0xc000
|
||||
//
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr - 0x4000]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart7848()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart7848(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0xc000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart7848(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0xc000), 0xc000);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 Absolute bankswitched cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart78AB : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank0: 0x00000:0x4000
|
||||
// Bank1: 0x04000:0x4000 0x4000:0x4000 Bank0-1 (0 on startup)
|
||||
// Bank2: 0x08000:0x4000 0x8000:0x4000 Bank2
|
||||
// Bank3: 0x0c000:0x4000 0xc000:0x4000 Bank3
|
||||
//
|
||||
readonly int[] Bank = new int[4];
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[ (Bank[addr >> 14] << 14) | (addr & 0x3fff) ]; }
|
||||
set
|
||||
{
|
||||
if ((addr >> 14) == 2)
|
||||
{
|
||||
Bank[1] = (value - 1) & 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart78AB()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart78AB(byte[] romBytes)
|
||||
{
|
||||
Bank[1] = 0;
|
||||
Bank[2] = 2;
|
||||
Bank[3] = 3;
|
||||
LoadRom(romBytes, 0x10000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart78AB(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
var version = input.CheckVersion(1, 2);
|
||||
LoadRom(input.ReadBytes());
|
||||
Bank = input.ReadIntegers(4);
|
||||
if (version == 1)
|
||||
input.ReadInt32();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(2);
|
||||
output.Write(ROM);
|
||||
output.Write(Bank);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 Activision bankswitched cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart78AC : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank0 : 0x00000:0x2000
|
||||
// Bank1 : 0x02000:0x2000
|
||||
// Bank2 : 0x04000:0x2000 0x4000:0x2000 Bank13
|
||||
// Bank3 : 0x06000:0x2000 0x6000:0x2000 Bank12
|
||||
// Bank4 : 0x08000:0x2000 0x8000:0x2000 Bank15
|
||||
// Bank5 : 0x0a000:0x2000 0xa000:0x2000 Bank(2*n) n in [0-7], n=0 on startup
|
||||
// Bank6 : 0x0c000:0x2000 0xc000:0x2000 Bank(2*n+1)
|
||||
// Bank7 : 0x0e000:0x2000 0xe000:0x2000 Bank14
|
||||
// Bank8 : 0x10000:0x2000
|
||||
// Bank9 : 0x12000:0x2000
|
||||
// Bank10: 0x14000:0x2000
|
||||
// Bank11: 0x16000:0x2000
|
||||
// Bank12: 0x18000:0x2000
|
||||
// Bank13: 0x1a000:0x2000
|
||||
// Bank14: 0x1c000:0x2000
|
||||
// Bank15: 0x1e000:0x2000
|
||||
//
|
||||
// Banks are actually 16KB, but handled as 8KB for implementation ease.
|
||||
//
|
||||
readonly int[] Bank = new int[8];
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
return ROM[ (Bank[addr >> 13] << 13) | (addr & 0x1fff) ];
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((addr & 0xfff0) == 0xff80)
|
||||
{
|
||||
Bank[5] = (addr & 7) << 1;
|
||||
Bank[6] = Bank[5] + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart78AC()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart78AC(byte[] romBytes)
|
||||
{
|
||||
Bank[2] = 13;
|
||||
Bank[3] = 12;
|
||||
Bank[4] = 15;
|
||||
Bank[5] = 0;
|
||||
Bank[6] = 1;
|
||||
Bank[7] = 14;
|
||||
LoadRom(romBytes, 0x20000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart78AC(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadBytes());
|
||||
Bank = input.ReadIntegers(8);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(Bank);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 SuperGame S4 bankswitched cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart78S4 : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank0: 0x00000:0x4000
|
||||
// Bank1: 0x04000:0x4000 0x4000:0x4000 Bank2
|
||||
// Bank2: 0x08000:0x4000 0x8000:0x4000 Bank0 (0 on startup)
|
||||
// Bank3: 0x0c000:0x4000 0xc000:0x4000 Bank3
|
||||
//
|
||||
// Banks 0-3 are the same as banks 4-7
|
||||
//
|
||||
readonly byte[] RAM;
|
||||
readonly int[] Bank = new int[4];
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (RAM != null && addr >= 0x6000 && addr <= 0x7fff)
|
||||
{
|
||||
return RAM[addr & 0x1fff];
|
||||
}
|
||||
return ROM[(Bank[addr >> 14] << 14) | (addr & 0x3fff)];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (RAM != null && addr >= 0x6000 && addr <= 0x7fff)
|
||||
{
|
||||
RAM[addr & 0x1fff] = value;
|
||||
}
|
||||
else if ((addr >> 14) == 2)
|
||||
{
|
||||
Bank[2] = value & 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart78S4()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart78S4(byte[] romBytes, bool needRAM)
|
||||
{
|
||||
if (needRAM)
|
||||
{
|
||||
RAM = new byte[0x2000];
|
||||
}
|
||||
|
||||
LoadRom(romBytes, 0xffff);
|
||||
|
||||
Bank[1] = 2;
|
||||
Bank[2] = 0;
|
||||
Bank[3] = 3;
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart78S4(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
var version = input.CheckVersion(1, 2);
|
||||
LoadRom(input.ReadBytes());
|
||||
Bank = input.ReadIntegers(4);
|
||||
if (version == 1)
|
||||
input.ReadInt32();
|
||||
RAM = input.ReadOptionalBytes();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(2);
|
||||
output.Write(ROM);
|
||||
output.Write(Bank);
|
||||
output.WriteOptional(RAM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 SuperGame S9 bankswitched cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart78S9 : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank0: 0x00000:0x4000
|
||||
// Bank1: 0x04000:0x4000 0x4000:0x4000 Bank0
|
||||
// Bank2: 0x08000:0x4000 0x8000:0x4000 Bank0-8 (1 on startup)
|
||||
// Bank3: 0x0c000:0x4000 0xc000:0x4000 Bank8
|
||||
// Bank4: 0x10000:0x4000
|
||||
// Bank5: 0x14000:0x4000
|
||||
// Bank6: 0x18000:0x4000
|
||||
// Bank7: 0x1c000:0x4000
|
||||
// Bank8: 0x20000:0x4000
|
||||
//
|
||||
readonly int[] Bank = new int[4];
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[ (Bank[addr >> 14] << 14) | (addr & 0x3fff) ]; }
|
||||
set
|
||||
{
|
||||
if ((addr >> 14) == 2 && value < 8)
|
||||
{
|
||||
Bank[2] = (value + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart78S9()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart78S9(byte[] romBytes)
|
||||
{
|
||||
Bank[1] = 0;
|
||||
Bank[2] = 1;
|
||||
Bank[3] = 8;
|
||||
LoadRom(romBytes, 0x24000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart78S9(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadBytes());
|
||||
Bank = input.ReadIntegers(4);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(Bank);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 SuperGame bankswitched cartridge
|
||||
/// </summary>
|
||||
public sealed class Cart78SG : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank0: 0x00000:0x4000
|
||||
// Bank1: 0x04000:0x4000 0x4000:0x4000 Bank6
|
||||
// Bank2: 0x08000:0x4000 0x8000:0x4000 Bank0-7 (0 on startup)
|
||||
// Bank3: 0x0c000:0x4000 0xc000:0x4000 Bank7
|
||||
// Bank4: 0x10000:0x4000
|
||||
// Bank5: 0x14000:0x4000
|
||||
// Bank6: 0x18000:0x4000
|
||||
// Bank7: 0x1c000:0x4000
|
||||
//
|
||||
readonly int[] Bank = new int[4];
|
||||
readonly byte[] RAM;
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
var bankNo = addr >> 14;
|
||||
if (RAM != null && bankNo == 1)
|
||||
{
|
||||
return RAM[addr & 0x3fff];
|
||||
}
|
||||
return ROM[ (Bank[bankNo] << 14) | (addr & 0x3fff) ];
|
||||
}
|
||||
set
|
||||
{
|
||||
var bankNo = addr >> 14;
|
||||
if (bankNo == 2)
|
||||
{
|
||||
Bank[2] = value & 7;
|
||||
}
|
||||
else if (RAM != null && bankNo == 1)
|
||||
{
|
||||
RAM[addr & 0x3fff] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Cart78SG()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart78SG(byte[] romBytes, bool needRAM)
|
||||
{
|
||||
if (needRAM)
|
||||
{
|
||||
// This works for titles that use 8KB instead of 16KB
|
||||
RAM = new byte[0x4000];
|
||||
}
|
||||
|
||||
Bank[1] = 6;
|
||||
Bank[2] = 0;
|
||||
Bank[3] = 7;
|
||||
|
||||
LoadRom(romBytes, 0x20000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart78SG(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
var version = input.CheckVersion(1, 2);
|
||||
LoadRom(input.ReadBytes());
|
||||
Bank = input.ReadIntegers(4);
|
||||
if (version == 1)
|
||||
input.ReadInt32();
|
||||
RAM = input.ReadOptionalBytes(0x4000);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(2);
|
||||
output.Write(ROM);
|
||||
output.Write(Bank);
|
||||
output.WriteOptional(RAM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari 7800 SuperGame bankswitched cartridge w/Pokey
|
||||
/// </summary>
|
||||
public sealed class Cart78SGP : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank0: 0x00000:0x4000
|
||||
// Bank1: 0x04000:0x4000 0x4000:0x4000 Pokey
|
||||
// Bank2: 0x08000:0x4000 0x8000:0x4000 Bank0-7 (0 on startup)
|
||||
// Bank3: 0x0c000:0x4000 0xc000:0x4000 Bank7
|
||||
// Bank4: 0x10000:0x4000
|
||||
// Bank5: 0x14000:0x4000
|
||||
// Bank6: 0x18000:0x4000
|
||||
// Bank7: 0x1c000:0x4000
|
||||
//
|
||||
readonly int[] _bank = new int[4];
|
||||
PokeySound _pokeySound;
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
if (_pokeySound != null)
|
||||
_pokeySound.Reset();
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
var bankNo = addr >> 14;
|
||||
switch (bankNo)
|
||||
{
|
||||
case 1:
|
||||
return (_pokeySound != null) ? _pokeySound.Read(addr) : (byte)0;
|
||||
default:
|
||||
return ROM[(_bank[bankNo] << 14) | (addr & 0x3fff)];
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
var bankNo = addr >> 14;
|
||||
switch (bankNo)
|
||||
{
|
||||
case 1:
|
||||
if (_pokeySound != null)
|
||||
_pokeySound.Update(addr, value);
|
||||
break;
|
||||
case 2:
|
||||
_bank[2] = value & 7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void Attach(MachineBase m)
|
||||
{
|
||||
base.Attach(m);
|
||||
if (_pokeySound == null)
|
||||
_pokeySound = new PokeySound(M);
|
||||
}
|
||||
|
||||
public override void StartFrame()
|
||||
{
|
||||
if (_pokeySound != null)
|
||||
_pokeySound.StartFrame();
|
||||
}
|
||||
|
||||
public override void EndFrame()
|
||||
{
|
||||
if (_pokeySound != null)
|
||||
_pokeySound.EndFrame();
|
||||
}
|
||||
|
||||
private Cart78SGP()
|
||||
{
|
||||
}
|
||||
|
||||
public Cart78SGP(byte[] romBytes)
|
||||
{
|
||||
_bank[2] = 0;
|
||||
_bank[3] = 7;
|
||||
|
||||
LoadRom(romBytes, 0x20000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Cart78SGP(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadBytes());
|
||||
_bank = input.ReadIntegers(4);
|
||||
_pokeySound = input.ReadOptionalPokeySound(m);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (_pokeySound == null)
|
||||
throw new Emu7800SerializationException("Cart78SGP must be attached before serialization.");
|
||||
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(_bank);
|
||||
output.WriteOptional(_pokeySound);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 16KB bankswitched carts
|
||||
/// </summary>
|
||||
public sealed class CartA16K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by accessing 0x1ff9-0x1ff9
|
||||
// Bank2: 0x1000:0x1000
|
||||
// Bank3: 0x2000:0x1000
|
||||
// Bank4: 0x3000:0x1000
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 0;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA16K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA16K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x4000);
|
||||
Bank = 0;
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
if (addr < 0x0ff6 || addr > 0x0ff9)
|
||||
{}
|
||||
else
|
||||
{
|
||||
Bank = addr - 0x0ff6;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA16K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x4000), 0x4000);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(BankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 16KB bankswitched carts with 128 bytes of RAM
|
||||
/// </summary>
|
||||
public sealed class CartA16KR : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by accessing 0x1ff9-0x1ff9
|
||||
// Bank2: 0x1000:0x1000
|
||||
// Bank3: 0x2000:0x1000
|
||||
// Bank4: 0x3000:0x1000
|
||||
// Shadows ROM
|
||||
// 0x1000:0x0080 RAM write port
|
||||
// 0x1080:0x0080 RAM read port
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
readonly byte[] RAM;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 0;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0100 && addr >= 0x0080)
|
||||
{
|
||||
return RAM[addr & 0x7f];
|
||||
}
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0080)
|
||||
{
|
||||
RAM[addr & 0x7f] = value;
|
||||
return;
|
||||
}
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA16KR()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA16KR(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x4000);
|
||||
Bank = 0;
|
||||
RAM = new byte[0x80];
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
if (addr < 0x0ff6 || addr > 0x0ff9)
|
||||
{}
|
||||
else
|
||||
{
|
||||
Bank = addr - 0x0ff6;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA16KR(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x4000), 0x4000);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(BankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 2KB carts (no bankswitching)
|
||||
/// </summary>
|
||||
public sealed class CartA2K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// 0x0000:0x0800 0x1000:0x0800
|
||||
// 0x1800:0x0800 (1st 2k bank repeated)
|
||||
//
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr & 0x07ff]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA2K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA2K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x0800);
|
||||
}
|
||||
|
||||
public CartA2K(byte[] romBytes, int multicartBankSelector)
|
||||
{
|
||||
LoadRom(romBytes, 0x800, multicartBankSelector & 0x1f);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA2K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x0800), 0x0800);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 32KB bankswitched carts
|
||||
/// </summary>
|
||||
public sealed class CartA32K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by accessing 0x0ff4-0x0ffc
|
||||
// Bank2: 0x1000:0x1000
|
||||
// Bank3: 0x2000:0x1000
|
||||
// Bank4: 0x3000:0x1000
|
||||
// Bank5: 0x4000:0x1000
|
||||
// Bank6: 0x5000:0x1000
|
||||
// Bank7: 0x6000:0x1000
|
||||
// Bank8: 0x7000:0x1000
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 7;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA32K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA32K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x8000);
|
||||
Bank = 7;
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
if (addr < 0x0ffc && addr >= 0x0ff4)
|
||||
{
|
||||
Bank = addr - 0x0ff4;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA32K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x8000), 0x8000);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(BankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 32KB bankswitched carts with 128 bytes of RAM
|
||||
/// </summary>
|
||||
public sealed class CartA32KR : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by accessing 0x0ff4-0x0ffc
|
||||
// Bank2: 0x1000:0x1000
|
||||
// Bank3: 0x2000:0x1000
|
||||
// Bank4: 0x3000:0x1000
|
||||
// Bank5: 0x4000:0x1000
|
||||
// Bank6: 0x5000:0x1000
|
||||
// Bank7: 0x6000:0x1000
|
||||
// Bank8: 0x7000:0x1000
|
||||
// Shadows ROM
|
||||
// 0x1000:0x80 RAM write port
|
||||
// 0x1080:0x80 RAM read port
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
readonly byte[] RAM;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 7;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr >= 0x0080 && addr < 0x0100)
|
||||
{
|
||||
return RAM[addr & 0x007f];
|
||||
}
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0080)
|
||||
{
|
||||
RAM[addr & 0x007f] = value;
|
||||
return;
|
||||
}
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA32KR()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA32KR(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x8000);
|
||||
RAM = new byte[0x80];
|
||||
Bank = 7;
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
if (addr < 0x0ffc && addr >= 0x0ff4 )
|
||||
{
|
||||
Bank = addr - 0x0ff4;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA32KR(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x8000), 0x8000);
|
||||
RAM = input.ReadExpectedBytes(0x80);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(RAM);
|
||||
output.Write(BankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 4KB carts (no bankswitching)
|
||||
/// </summary>
|
||||
public sealed class CartA4K : Cart
|
||||
{
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset() { }
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr & 0x0fff]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA4K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA4K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x1000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA4K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x1000), 0x1000);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 8KB bankswitched carts
|
||||
/// </summary>
|
||||
public sealed class CartA8K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by accessing 0x1ff8,0x1ff9
|
||||
// Bank2: 0x1000:0x1000
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 1;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA8K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA8K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x2000);
|
||||
Bank = 1;
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
switch(addr)
|
||||
{
|
||||
case 0x0ff8:
|
||||
Bank = 0;
|
||||
break;
|
||||
case 0x0ff9:
|
||||
Bank = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA8K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x2000), 0x2000);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(BankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Atari standard 8KB bankswitched carts with 128 bytes of RAM
|
||||
/// </summary>
|
||||
public sealed class CartA8KR : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by accessing 0x1ff8,0x1ff9
|
||||
// Bank2: 0x1000:0x1000
|
||||
// Shadows ROM
|
||||
// 0x1000:0x0080 RAM write port
|
||||
// 0x1080:0x0080 RAM read port
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
readonly byte[] RAM;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 1;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0100 && addr >= 0x0080)
|
||||
{
|
||||
return RAM[addr & 0x7f];
|
||||
}
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0080)
|
||||
{
|
||||
RAM[addr & 0x7f] = value;
|
||||
return;
|
||||
}
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartA8KR()
|
||||
{
|
||||
}
|
||||
|
||||
public CartA8KR(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x2000);
|
||||
Bank = 1;
|
||||
RAM = new byte[0x80];
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
switch(addr)
|
||||
{
|
||||
case 0x0ff8:
|
||||
Bank = 0;
|
||||
break;
|
||||
case 0x0ff9:
|
||||
Bank = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartA8KR(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x2000), 0x2000);
|
||||
RAM = input.ReadExpectedBytes(0x80);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(RAM);
|
||||
output.Write(BankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// CBS RAM Plus 12KB bankswitched carts with 128 bytes of RAM.
|
||||
/// </summary>
|
||||
public sealed class CartCBS12K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 Bank1:0x1000:0x1000 Select Segment: 0ff8-0ffa
|
||||
// Bank2: 0x1000:0x1000
|
||||
// Bank3: 0x2000:0x1000
|
||||
// Shadows ROM
|
||||
// 0x1000:0x80 RAM write port
|
||||
// 0x1080:0x80 RAM read port
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
readonly byte[] RAM;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 2;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0200 && addr >= 0x0100)
|
||||
{
|
||||
return RAM[addr & 0xff];
|
||||
}
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0100)
|
||||
{
|
||||
RAM[addr & 0xff] = value;
|
||||
return;
|
||||
}
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartCBS12K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartCBS12K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x3000);
|
||||
Bank = 2;
|
||||
RAM = new byte[0x100];
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
if (addr < 0x0ff8 || addr > 0x0ffa) { }
|
||||
else
|
||||
{
|
||||
Bank = addr - 0x0ff8;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartCBS12K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x3000), 0x3000);
|
||||
RAM = input.ReadExpectedBytes(0x100);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(RAM);
|
||||
output.Write(BankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Activison's Robot Tank and Decathlon 8KB bankswitching cart.
|
||||
/// </summary>
|
||||
public sealed class CartDC8K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by A13=0/1?
|
||||
// Bank2: 0x1000:0x1000
|
||||
//
|
||||
// This does what the Stella code does, which is to follow A13 to determine
|
||||
// the bank. Since A0-A12 are the only significant bits on the program
|
||||
// counter, I am unsure how the cart/hardware could utilize this.
|
||||
//
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get { return (addr & 0x2000) == 0 ? ROM[addr & 0x0fff + 0x1000] : ROM[addr & 0x0fff]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartDC8K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartDC8K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x2000);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartDC8K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x2000), 0x2000);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,341 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Pitfall II cartridge.
|
||||
/// There are two 4k banks, 2k display bank, and the DPC chip.
|
||||
/// For complete details on the DPC chip see David P. Crane's United States Patent Number 4,644,495.
|
||||
/// </summary>
|
||||
public sealed class CartDPC : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Bank1: 0x0000:0x1000 0x1000:0x1000 Bank selected by accessing 0x1ff8,0x1ff9
|
||||
// Bank2: 0x1000:0x1000
|
||||
//
|
||||
const ushort DisplayBaseAddr = 0x2000;
|
||||
ushort BankBaseAddr;
|
||||
|
||||
readonly byte[] MusicAmplitudes = new byte[] { 0x00, 0x04, 0x05, 0x09, 0x06, 0x0a, 0x0b, 0x0f };
|
||||
|
||||
readonly byte[] Tops = new byte[8];
|
||||
readonly byte[] Bots = new byte[8];
|
||||
readonly ushort[] Counters = new ushort[8];
|
||||
readonly byte[] Flags = new byte[8];
|
||||
readonly bool[] MusicMode = new bool[3];
|
||||
|
||||
ulong LastSystemClock;
|
||||
double FractionalClocks;
|
||||
|
||||
byte _ShiftRegister;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set { BankBaseAddr = (ushort)(value * 0x1000); }
|
||||
}
|
||||
|
||||
//
|
||||
// Generate a sequence of pseudo-random numbers 255 numbers long
|
||||
// by emulating an 8-bit shift register with feedback taps at
|
||||
// bits 4, 3, 2, and 0.
|
||||
byte ShiftRegister
|
||||
{
|
||||
get
|
||||
{
|
||||
var a = _ShiftRegister;
|
||||
a &= (1 << 0);
|
||||
|
||||
var x = _ShiftRegister;
|
||||
x &= (1 << 2);
|
||||
x >>= 2;
|
||||
a ^= x;
|
||||
|
||||
x = _ShiftRegister;
|
||||
x &= (1 << 3);
|
||||
x >>= 3;
|
||||
a ^= x;
|
||||
|
||||
x = _ShiftRegister;
|
||||
x &= (1 << 4);
|
||||
x >>= 4;
|
||||
a ^= x;
|
||||
|
||||
a <<= 7;
|
||||
_ShiftRegister >>= 1;
|
||||
_ShiftRegister |= a;
|
||||
|
||||
return _ShiftRegister;
|
||||
}
|
||||
set { _ShiftRegister = value; }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 1;
|
||||
LastSystemClock = 3*M.CPU.Clock;
|
||||
FractionalClocks = 0.0;
|
||||
ShiftRegister = 1;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr < 0x0040)
|
||||
{
|
||||
return ReadPitfall2Reg(addr);
|
||||
}
|
||||
UpdateBank(addr);
|
||||
return ROM[BankBaseAddr + addr];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
if (addr >= 0x0040 && addr < 0x0080)
|
||||
{
|
||||
WritePitfall2Reg(addr, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateBank(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartDPC()
|
||||
{
|
||||
}
|
||||
|
||||
public CartDPC(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x2800);
|
||||
Bank = 1;
|
||||
}
|
||||
|
||||
void UpdateBank(ushort addr)
|
||||
{
|
||||
switch(addr)
|
||||
{
|
||||
case 0x0ff8:
|
||||
Bank = 0;
|
||||
break;
|
||||
case 0x0ff9:
|
||||
Bank = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
byte ReadPitfall2Reg(ushort addr)
|
||||
{
|
||||
byte result;
|
||||
|
||||
var i = addr & 0x07;
|
||||
var fn = (addr >> 3) & 0x07;
|
||||
|
||||
// Update flag register for selected data fetcher
|
||||
if ((Counters[i] & 0x00ff) == Tops[i])
|
||||
{
|
||||
Flags[i] = 0xff;
|
||||
}
|
||||
else if ((Counters[i] & 0x00ff) == Bots[i])
|
||||
{
|
||||
Flags[i] = 0x00;
|
||||
}
|
||||
|
||||
switch (fn)
|
||||
{
|
||||
case 0x00:
|
||||
if (i < 4)
|
||||
{
|
||||
// This is a random number read
|
||||
result = ShiftRegister;
|
||||
break;
|
||||
}
|
||||
// Its a music read
|
||||
UpdateMusicModeDataFetchers();
|
||||
|
||||
byte j = 0;
|
||||
if (MusicMode[0] && Flags[5] != 0)
|
||||
{
|
||||
j |= 0x01;
|
||||
}
|
||||
if (MusicMode[1] && Flags[6] != 0)
|
||||
{
|
||||
j |= 0x02;
|
||||
}
|
||||
if (MusicMode[2] && Flags[7] != 0)
|
||||
{
|
||||
j |= 0x04;
|
||||
}
|
||||
result = MusicAmplitudes[j];
|
||||
break;
|
||||
// DFx display data read
|
||||
case 0x01:
|
||||
result = ROM[DisplayBaseAddr + 0x7ff - Counters[i]];
|
||||
break;
|
||||
// DFx display data read AND'd w/flag
|
||||
case 0x02:
|
||||
result = ROM[DisplayBaseAddr + 0x7ff - Counters[i]];
|
||||
result &= Flags[i];
|
||||
break;
|
||||
// DFx flag
|
||||
case 0x07:
|
||||
result = Flags[i];
|
||||
break;
|
||||
default:
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Clock the selected data fetcher's counter if needed
|
||||
if (i < 5 || i >= 5 && MusicMode[i - 5] == false)
|
||||
{
|
||||
Counters[i]--;
|
||||
Counters[i] &= 0x07ff;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void UpdateMusicModeDataFetchers()
|
||||
{
|
||||
var sysClockDelta = 3*M.CPU.Clock - LastSystemClock;
|
||||
LastSystemClock = 3*M.CPU.Clock;
|
||||
|
||||
var OSCclocks = ((15750.0 * sysClockDelta) / 1193191.66666667) + FractionalClocks;
|
||||
|
||||
var wholeClocks = (int)OSCclocks;
|
||||
FractionalClocks = OSCclocks - wholeClocks;
|
||||
if (wholeClocks <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i=0; i < 3; i++)
|
||||
{
|
||||
var r = i + 5;
|
||||
if (!MusicMode[i]) continue;
|
||||
|
||||
var top = Tops[r] + 1;
|
||||
var newLow = Counters[r] & 0x00ff;
|
||||
|
||||
if (Tops[r] != 0)
|
||||
{
|
||||
newLow -= (wholeClocks % top);
|
||||
if (newLow < 0)
|
||||
{
|
||||
newLow += top;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newLow = 0;
|
||||
}
|
||||
|
||||
if (newLow <= Bots[r])
|
||||
{
|
||||
Flags[r] = 0x00;
|
||||
}
|
||||
else if (newLow <= Tops[r])
|
||||
{
|
||||
Flags[r] = 0xff;
|
||||
}
|
||||
|
||||
Counters[r] = (ushort)((Counters[r] & 0x0700) | (ushort)newLow);
|
||||
}
|
||||
}
|
||||
|
||||
void WritePitfall2Reg(ushort addr, byte val)
|
||||
{
|
||||
var i = addr & 0x07;
|
||||
var fn = (addr >> 3) & 0x07;
|
||||
|
||||
switch (fn)
|
||||
{
|
||||
// DFx top count
|
||||
case 0x00:
|
||||
Tops[i] = val;
|
||||
Flags[i] = 0x00;
|
||||
break;
|
||||
// DFx bottom count
|
||||
case 0x01:
|
||||
Bots[i] = val;
|
||||
break;
|
||||
// DFx counter low
|
||||
case 0x02:
|
||||
Counters[i] &= 0x0700;
|
||||
if (i >= 5 && MusicMode[i - 5])
|
||||
{
|
||||
// Data fetcher is in music mode so its low counter value
|
||||
// should be loaded from the top register not the poked value
|
||||
Counters[i] |= Tops[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Data fetcher is either not a music mode data fetcher or it
|
||||
// isn't in music mode so it's low counter value should be loaded
|
||||
// with the poked value
|
||||
Counters[i] |= val;
|
||||
}
|
||||
break;
|
||||
// DFx counter high
|
||||
case 0x03:
|
||||
Counters[i] &= 0x00ff;
|
||||
Counters[i] |= (ushort)((val & 0x07) << 8);
|
||||
// Execute special code for music mode data fetchers
|
||||
if (i >= 5)
|
||||
{
|
||||
MusicMode[i - 5] = (val & 0x10) != 0;
|
||||
// NOTE: We are not handling the clock source input for
|
||||
// the music mode data fetchers. We're going to assume
|
||||
// they always use the OSC input.
|
||||
}
|
||||
break;
|
||||
// Random Number Generator Reset
|
||||
case 0x06:
|
||||
ShiftRegister = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartDPC(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x2800), 0x2800);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
Tops = input.ReadExpectedBytes(8);
|
||||
Bots = input.ReadExpectedBytes(8);
|
||||
Counters = input.ReadUnsignedShorts(8);
|
||||
Flags = input.ReadExpectedBytes(8);
|
||||
MusicMode = input.ReadBooleans(3);
|
||||
LastSystemClock = input.ReadUInt64();
|
||||
FractionalClocks = input.ReadDouble();
|
||||
_ShiftRegister = input.ReadByte();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(BankBaseAddr);
|
||||
output.Write(Tops);
|
||||
output.Write(Bots);
|
||||
output.Write(Counters);
|
||||
output.Write(Flags);
|
||||
output.Write(MusicMode);
|
||||
output.Write(LastSystemClock);
|
||||
output.Write(FractionalClocks);
|
||||
output.Write(_ShiftRegister);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// M-Network 16KB bankswitched carts with 2KB RAM.
|
||||
/// </summary>
|
||||
public sealed class CartMN16K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Segment1: 0x0000:0x0800 Bank1:0x1000:0x0800 Select Seg: 1fe0-1fe6, 1fe7=RAM Seg1
|
||||
// Segment2: 0x0800:0x0800 Bank2:0x1800:0x0800 Always Seg8
|
||||
// Segment3: 0x1000:0x0800
|
||||
// Segment4: 0x1800:0x0800
|
||||
// Segment5: 0x2000:0x0800
|
||||
// Segment6: 0x2800:0x0800
|
||||
// Segment7: 0x3000:0x0800
|
||||
// Segment8: 0x3800:0x0800
|
||||
//
|
||||
// RAM RAM Segment1 when 1fe7 select is accessed
|
||||
// Segment1: 0x0000:0x0400 0x1000-0x13FF write port
|
||||
// Segment2: 0x0400:0x0400 0x1400-0x17FF read port
|
||||
//
|
||||
// RAM Segment2: 1ff8-1ffb selects 256-byte block
|
||||
// 0x1800-0x18ff write port
|
||||
// 0x1900-0x19ff read port
|
||||
//
|
||||
ushort BankBaseAddr, BankBaseRAMAddr;
|
||||
bool RAMBankOn;
|
||||
readonly byte[] RAM;
|
||||
|
||||
int Bank
|
||||
{
|
||||
set
|
||||
{
|
||||
BankBaseAddr = (ushort)(value << 11); // multiply by 2048
|
||||
RAMBankOn = (value == 0x07);
|
||||
}
|
||||
}
|
||||
|
||||
int BankRAM
|
||||
{
|
||||
set { BankBaseRAMAddr = (ushort) (value << 8); } // multiply by 256
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 0;
|
||||
BankRAM = 0;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBanks(addr);
|
||||
if (RAMBankOn && addr >= 0x0400 && addr < 0x0800)
|
||||
{
|
||||
return RAM[addr & 0x03ff];
|
||||
}
|
||||
if (addr >= 0x0900 && addr < 0x0a00)
|
||||
{
|
||||
return RAM[0x400 + BankBaseRAMAddr + (addr & 0xff)];
|
||||
}
|
||||
return addr < 0x0800 ? ROM[BankBaseAddr + (addr & 0x07ff)] : ROM[0x3800 + (addr & 0x07ff)];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateBanks(addr);
|
||||
if (RAMBankOn && addr < 0x0400)
|
||||
{
|
||||
RAM[addr & 0x03ff] = value;
|
||||
}
|
||||
else if (addr >= 0x0800 && addr < 0x0900)
|
||||
{
|
||||
RAM[0x400 + BankBaseRAMAddr + (addr & 0xff)] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartMN16K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartMN16K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x4000);
|
||||
RAM = new byte[0x800];
|
||||
Bank = 0;
|
||||
BankRAM = 0;
|
||||
}
|
||||
|
||||
void UpdateBanks(ushort addr)
|
||||
{
|
||||
if (addr >= 0x0fe0 && addr < 0x0fe8)
|
||||
{
|
||||
Bank = addr & 0x07;
|
||||
}
|
||||
else if (addr >= 0x0fe8 && addr < 0x0fec)
|
||||
{
|
||||
BankRAM = addr & 0x03;
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartMN16K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x4000), 0x4000);
|
||||
RAM = input.ReadExpectedBytes(0x800);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
BankBaseRAMAddr = input.ReadUInt16();
|
||||
RAMBankOn = input.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(RAM);
|
||||
output.Write(BankBaseAddr);
|
||||
output.Write(BankBaseRAMAddr);
|
||||
output.Write(RAMBankOn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Parker Brothers 8KB bankswitched carts.
|
||||
/// </summary>
|
||||
public sealed class CartPB8K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Segment1: 0x0000:0x0400 Bank1:0x1000:0x0400 Select Segment: 1fe0-1fe7
|
||||
// Segment2: 0x0400:0x0400 Bank2:0x1400:0x0400 Select Segment: 1fe8-1ff0
|
||||
// Segment3: 0x0800:0x0400 Bank3:0x1800:0x0400 Select Segment: 1ff0-1ff8
|
||||
// Segment4: 0x0c00:0x0400 Bank4:0x1c00:0x0400 Always Segment8
|
||||
// Segment5: 0x1000:0x0400
|
||||
// Segment6: 0x1400:0x0400
|
||||
// Segment7: 0x1800:0x0400
|
||||
// Segment8: 0x1c00:0x0400
|
||||
//
|
||||
readonly ushort[] SegmentBase;
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
SegmentBase[0] = ComputeSegmentBase(4);
|
||||
SegmentBase[1] = ComputeSegmentBase(5);
|
||||
SegmentBase[2] = ComputeSegmentBase(6);
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateSegmentBases(addr);
|
||||
return ROM[SegmentBase[addr >> 10] + (addr & 0x03ff)];
|
||||
}
|
||||
set
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
UpdateSegmentBases(addr);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartPB8K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartPB8K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x2000);
|
||||
SegmentBase = new ushort[4];
|
||||
SegmentBase[0] = ComputeSegmentBase(4);
|
||||
SegmentBase[1] = ComputeSegmentBase(5);
|
||||
SegmentBase[2] = ComputeSegmentBase(6);
|
||||
SegmentBase[3] = ComputeSegmentBase(7);
|
||||
}
|
||||
|
||||
static ushort ComputeSegmentBase(int slice)
|
||||
{
|
||||
return (ushort)(slice << 10); // multiply by 1024
|
||||
}
|
||||
|
||||
void UpdateSegmentBases(ushort addr)
|
||||
{
|
||||
if (addr < 0xfe0 || addr >= 0x0ff8) { }
|
||||
else if (addr >= 0x0fe0 && addr < 0x0fe8)
|
||||
{
|
||||
SegmentBase[0] = ComputeSegmentBase(addr & 0x07);
|
||||
}
|
||||
else if (addr >= 0x0fe8 && addr < 0x0ff0)
|
||||
{
|
||||
SegmentBase[1] = ComputeSegmentBase(addr & 0x07);
|
||||
}
|
||||
else if (addr >= 0x0ff0 && addr < 0x0ff8)
|
||||
{
|
||||
SegmentBase[2] = ComputeSegmentBase(addr & 0x07);
|
||||
}
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartPB8K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x2000), 0x2000);
|
||||
SegmentBase = input.ReadUnsignedShorts();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(SegmentBase);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Tigervision 8KB bankswitched carts
|
||||
/// </summary>
|
||||
public sealed class CartTV8K : Cart
|
||||
{
|
||||
//
|
||||
// Cart Format Mapping to ROM Address Space
|
||||
// Segment1: 0x0000:0x0800 0x1000:0x0800 Selected segment via $003F
|
||||
// Segment2: 0x0800:0x0800 0x1800:0x0800 Always last segment
|
||||
// Segment3: 0x1000:0x0800
|
||||
// Segment4: 0x1800:0x0800
|
||||
//
|
||||
ushort BankBaseAddr;
|
||||
readonly ushort LastBankBaseAddr;
|
||||
|
||||
byte Bank
|
||||
{
|
||||
set
|
||||
{
|
||||
BankBaseAddr = (ushort)(0x0800 * value);
|
||||
BankBaseAddr %= (ushort)ROM.Length;
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override bool RequestSnooping
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Bank = 0;
|
||||
}
|
||||
|
||||
public override byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
addr &= 0x0fff;
|
||||
return addr < 0x0800 ? ROM[BankBaseAddr + (addr & 0x07ff)] : ROM[LastBankBaseAddr + (addr & 0x07ff)];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (addr <= 0x003f)
|
||||
{
|
||||
Bank = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CartTV8K()
|
||||
{
|
||||
}
|
||||
|
||||
public CartTV8K(byte[] romBytes)
|
||||
{
|
||||
LoadRom(romBytes, 0x1000);
|
||||
Bank = 0;
|
||||
LastBankBaseAddr = (ushort)(ROM.Length - 0x0800);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public CartTV8K(DeserializationContext input, MachineBase m) : base(input)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
LoadRom(input.ReadExpectedBytes(0x1000), 0x1000);
|
||||
BankBaseAddr = input.ReadUInt16();
|
||||
LastBankBaseAddr = input.ReadUInt16();
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(BankBaseAddr);
|
||||
output.Write(LastBankBaseAddr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* CartType.cs
|
||||
*
|
||||
* Defines the set of all known Game Cartridges.
|
||||
*
|
||||
* 2010 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public enum CartType
|
||||
{
|
||||
None,
|
||||
A2K, // Atari 2kb cart
|
||||
TV8K, // Tigervision 8kb bankswitched cart
|
||||
A4K, // Atari 4kb cart
|
||||
PB8K, // Parker Brothers 8kb bankswitched cart
|
||||
MN16K, // M-Network 16kb bankswitched cart
|
||||
A16K, // Atari 16kb bankswitched cart
|
||||
A16KR, // Atari 16kb bankswitched cart w/128 bytes RAM
|
||||
A8K, // Atari 8KB bankswitched cart
|
||||
A8KR, // Atari 8KB bankswitched cart w/128 bytes RAM
|
||||
A32K, // Atari 32KB bankswitched cart
|
||||
A32KR, // Atari 32KB bankswitched cart w/128 bytes RAM
|
||||
CBS12K, // CBS' RAM Plus bankswitched cart w/256 bytes RAM
|
||||
DC8K, // Special Activision cart (Robot Tank and Decathlon)
|
||||
DPC, // Pitfall II DPC cart
|
||||
M32N12K, // 32N1 Multicart: 32x2KB
|
||||
A7808, // Atari7800 non-bankswitched 8KB cart
|
||||
A7816, // Atari7800 non-bankswitched 16KB cart
|
||||
A7832, // Atari7800 non-bankswitched 32KB cart
|
||||
A7832P, // Atari7800 non-bankswitched 32KB cart w/Pokey
|
||||
A7848, // Atari7800 non-bankswitched 48KB cart
|
||||
A78SG, // Atari7800 SuperGame cart
|
||||
A78SGP, // Atari7800 SuperGame cart w/Pokey
|
||||
A78SGR, // Atari7800 SuperGame cart w/RAM
|
||||
A78S9, // Atari7800 SuperGame cart, nine banks
|
||||
A78S4, // Atari7800 SuperGame cart, four banks
|
||||
A78S4R, // Atari7800 SuperGame cart, four banks, w/RAM
|
||||
A78AB, // F18 Hornet cart (Absolute)
|
||||
A78AC, // Double dragon cart (Activision)
|
||||
};
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
internal enum ConsoleSwitch
|
||||
{
|
||||
GameReset,
|
||||
GameSelect,
|
||||
GameBW,
|
||||
LeftDifficultyA,
|
||||
RightDifficultyA,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public enum Controller
|
||||
{
|
||||
None,
|
||||
Joystick,
|
||||
Paddles,
|
||||
Keypad,
|
||||
Driving,
|
||||
BoosterGrip,
|
||||
ProLineJoystick,
|
||||
Lightgun,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public enum ControllerAction
|
||||
{
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
Trigger, // Interpretation: 7800 RFire; 2600 Fire, BoosterGrip top
|
||||
Trigger2, // Interpretation: 7800 LFire, BoosterGrip trigger
|
||||
Keypad1, Keypad2, Keypad3,
|
||||
Keypad4, Keypad5, Keypad6,
|
||||
Keypad7, Keypad8, Keypad9,
|
||||
KeypadA, Keypad0, KeypadP,
|
||||
Driving0, Driving1, Driving2, Driving3,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,245 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A context for deserializing <see cref="MachineBase"/> objects.
|
||||
/// </summary>
|
||||
public class DeserializationContext
|
||||
{
|
||||
#region Fields
|
||||
|
||||
readonly BinaryReader _binaryReader;
|
||||
|
||||
#endregion
|
||||
|
||||
public bool ReadBoolean()
|
||||
{
|
||||
return _binaryReader.ReadBoolean();
|
||||
}
|
||||
|
||||
public byte ReadByte()
|
||||
{
|
||||
return _binaryReader.ReadByte();
|
||||
}
|
||||
|
||||
public ushort ReadUInt16()
|
||||
{
|
||||
return _binaryReader.ReadUInt16();
|
||||
}
|
||||
|
||||
public int ReadInt32()
|
||||
{
|
||||
return _binaryReader.ReadInt32();
|
||||
}
|
||||
|
||||
public uint ReadUInt32()
|
||||
{
|
||||
return _binaryReader.ReadUInt32();
|
||||
}
|
||||
|
||||
public long ReadInt64()
|
||||
{
|
||||
return _binaryReader.ReadInt64();
|
||||
}
|
||||
|
||||
public ulong ReadUInt64()
|
||||
{
|
||||
return _binaryReader.ReadUInt64();
|
||||
}
|
||||
|
||||
public double ReadDouble()
|
||||
{
|
||||
return _binaryReader.ReadDouble();
|
||||
}
|
||||
|
||||
public BufferElement ReadBufferElement()
|
||||
{
|
||||
var be = new BufferElement();
|
||||
for (var i = 0; i < BufferElement.SIZE; i++)
|
||||
be[i] = ReadByte();
|
||||
return be;
|
||||
}
|
||||
|
||||
public byte[] ReadBytes()
|
||||
{
|
||||
var count = _binaryReader.ReadInt32();
|
||||
if (count <= 0)
|
||||
return new byte[0];
|
||||
if (count > 0x40000)
|
||||
throw new Emu7800SerializationException("Byte array length too large.");
|
||||
return _binaryReader.ReadBytes(count);
|
||||
}
|
||||
|
||||
public byte[] ReadExpectedBytes(params int[] expectedSizes)
|
||||
{
|
||||
var count = _binaryReader.ReadInt32();
|
||||
if (!expectedSizes.Any(t => t == count))
|
||||
throw new Emu7800SerializationException("Byte array length incorrect.");
|
||||
return _binaryReader.ReadBytes(count);
|
||||
}
|
||||
|
||||
public byte[] ReadOptionalBytes(params int[] expectedSizes)
|
||||
{
|
||||
var hasBytes = _binaryReader.ReadBoolean();
|
||||
return (hasBytes) ? ReadExpectedBytes(expectedSizes) : null;
|
||||
}
|
||||
|
||||
public ushort[] ReadUnsignedShorts(params int[] expectedSizes)
|
||||
{
|
||||
var bytes = ReadExpectedBytes(expectedSizes.Select(t => t << 1).ToArray());
|
||||
var ushorts = new ushort[bytes.Length >> 1];
|
||||
Buffer.BlockCopy(bytes, 0, ushorts, 0, bytes.Length);
|
||||
return ushorts;
|
||||
}
|
||||
|
||||
public int[] ReadIntegers(params int[] expectedSizes)
|
||||
{
|
||||
var bytes = ReadExpectedBytes(expectedSizes.Select(t => t << 2).ToArray());
|
||||
var integers = new int[bytes.Length >> 2];
|
||||
Buffer.BlockCopy(bytes, 0, integers, 0, bytes.Length);
|
||||
return integers;
|
||||
}
|
||||
|
||||
public uint[] ReadUnsignedIntegers(params int[] expectedSizes)
|
||||
{
|
||||
var bytes = ReadExpectedBytes(expectedSizes.Select(t => t << 2).ToArray());
|
||||
var uints = new uint[bytes.Length >> 2];
|
||||
Buffer.BlockCopy(bytes, 0, uints, 0, bytes.Length);
|
||||
return uints;
|
||||
}
|
||||
|
||||
public bool[] ReadBooleans(params int[] expectedSizes)
|
||||
{
|
||||
var bytes = ReadExpectedBytes(expectedSizes);
|
||||
var booleans = new bool[bytes.Length];
|
||||
for (var i = 0; i < bytes.Length; i++)
|
||||
booleans[i] = (bytes[i] != 0);
|
||||
return booleans;
|
||||
}
|
||||
|
||||
public int CheckVersion(params int[] validVersions)
|
||||
{
|
||||
var magicNumber = _binaryReader.ReadInt32();
|
||||
if (magicNumber != 0x78000087)
|
||||
throw new Emu7800SerializationException("Magic number not found.");
|
||||
var version = _binaryReader.ReadInt32();
|
||||
if (!validVersions.Any(t => t == version))
|
||||
throw new Emu7800SerializationException("Invalid version number found.");
|
||||
return version;
|
||||
}
|
||||
|
||||
public MachineBase ReadMachine()
|
||||
{
|
||||
var typeName = _binaryReader.ReadString();
|
||||
if (string.IsNullOrWhiteSpace(typeName))
|
||||
throw new Emu7800SerializationException("Invalid type name.");
|
||||
|
||||
var type = Type.GetType(typeName);
|
||||
if (type == null)
|
||||
throw new Emu7800SerializationException("Unable to resolve type name: " + typeName);
|
||||
|
||||
return (MachineBase)Activator.CreateInstance(type, new object[] { this });
|
||||
}
|
||||
|
||||
public AddressSpace ReadAddressSpace(MachineBase m, int addrSpaceShift, int pageShift)
|
||||
{
|
||||
var addressSpace = new AddressSpace(this, m, addrSpaceShift, pageShift);
|
||||
return addressSpace;
|
||||
}
|
||||
|
||||
public M6502 ReadM6502(MachineBase m, int runClocksMultiple)
|
||||
{
|
||||
var cpu = new M6502(this, m, runClocksMultiple);
|
||||
return cpu;
|
||||
}
|
||||
|
||||
public Maria ReadMaria(Machine7800 m, int scanlines)
|
||||
{
|
||||
var maria = new Maria(this, m, scanlines);
|
||||
return maria;
|
||||
}
|
||||
|
||||
public PIA ReadPIA(MachineBase m)
|
||||
{
|
||||
var pia = new PIA(this, m);
|
||||
return pia;
|
||||
}
|
||||
|
||||
public TIA ReadTIA(MachineBase m)
|
||||
{
|
||||
var tia = new TIA(this, m);
|
||||
return tia;
|
||||
}
|
||||
|
||||
public TIASound ReadTIASound(MachineBase m, int cpuClocksPerSample)
|
||||
{
|
||||
var tiaSound = new TIASound(this, m, cpuClocksPerSample);
|
||||
return tiaSound;
|
||||
}
|
||||
|
||||
public RAM6116 ReadRAM6116()
|
||||
{
|
||||
var ram6116 = new RAM6116(this);
|
||||
return ram6116;
|
||||
}
|
||||
|
||||
public InputState ReadInputState()
|
||||
{
|
||||
var inputState = new InputState(this);
|
||||
return inputState;
|
||||
}
|
||||
|
||||
public HSC7800 ReadOptionalHSC7800()
|
||||
{
|
||||
var exist = ReadBoolean();
|
||||
return exist ? new HSC7800(this) : null;
|
||||
}
|
||||
|
||||
public Bios7800 ReadOptionalBios7800()
|
||||
{
|
||||
var exist = ReadBoolean();
|
||||
return exist ? new Bios7800(this) : null;
|
||||
}
|
||||
|
||||
public PokeySound ReadOptionalPokeySound(MachineBase m)
|
||||
{
|
||||
var exist = ReadBoolean();
|
||||
return exist ? new PokeySound(this, m) : null;
|
||||
}
|
||||
|
||||
public Cart ReadCart(MachineBase m)
|
||||
{
|
||||
var typeName = _binaryReader.ReadString();
|
||||
if (string.IsNullOrWhiteSpace(typeName))
|
||||
throw new Emu7800SerializationException("Invalid type name.");
|
||||
|
||||
var type = Type.GetType(typeName);
|
||||
if (type == null)
|
||||
throw new Emu7800SerializationException("Unable to resolve type name: " + typeName);
|
||||
|
||||
return (Cart)Activator.CreateInstance(type, new object[] { this, m });
|
||||
}
|
||||
|
||||
#region Constructors
|
||||
|
||||
private DeserializationContext()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new instance of <see cref="DeserializationContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="binaryReader"/>
|
||||
internal DeserializationContext(BinaryReader binaryReader)
|
||||
{
|
||||
if (binaryReader == null)
|
||||
throw new ArgumentNullException("binaryReader");
|
||||
_binaryReader = binaryReader;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public class Emu7800Exception : Exception
|
||||
{
|
||||
internal Emu7800Exception()
|
||||
{
|
||||
}
|
||||
|
||||
internal Emu7800Exception(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
internal Emu7800Exception(string message, Exception ex) : base(message, ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public class Emu7800SerializationException : Emu7800Exception
|
||||
{
|
||||
private Emu7800SerializationException()
|
||||
{
|
||||
}
|
||||
|
||||
internal Emu7800SerializationException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
internal Emu7800SerializationException(string message, Exception ex) : base(message, ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* FontRenderer
|
||||
*
|
||||
* A simple font renderer for displaying text during emulation. Font data and
|
||||
* rendering algorithm courtesy of Bradford W. Mott's Stella source.
|
||||
*
|
||||
* Copyright © 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple font renderer for displaying text during emulation.
|
||||
/// </summary>
|
||||
public class FontRenderer
|
||||
{
|
||||
static readonly uint[] AlphaFontData =
|
||||
{
|
||||
0x699f999, // A
|
||||
0xe99e99e, // B
|
||||
0x6988896, // C
|
||||
0xe99999e, // D
|
||||
0xf88e88f, // E
|
||||
0xf88e888, // F
|
||||
0x698b996, // G
|
||||
0x999f999, // H
|
||||
0x7222227, // I
|
||||
0x72222a4, // J
|
||||
0x9accaa9, // K
|
||||
0x888888f, // L
|
||||
0x9ff9999, // M
|
||||
0x9ddbb99, // N
|
||||
0x6999996, // O
|
||||
0xe99e888, // P
|
||||
0x69999b7, // Q
|
||||
0xe99ea99, // R
|
||||
0x6986196, // S
|
||||
0x7222222, // T
|
||||
0x9999996, // U
|
||||
0x9999966, // V
|
||||
0x9999ff9, // W
|
||||
0x99fff99, // X
|
||||
0x9996244, // Y
|
||||
0xf12488f // Z
|
||||
};
|
||||
|
||||
static readonly uint[] DigitFontData =
|
||||
{
|
||||
0x69bd996, // 0
|
||||
0x2622227, // 1
|
||||
0x691248f, // 2
|
||||
0x6916196, // 3
|
||||
0xaaaf222, // 4
|
||||
0xf88e11e, // 5
|
||||
0x698e996, // 6
|
||||
0xf112244, // 7
|
||||
0x6996996, // 8
|
||||
0x6997196 // 9
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Draw specified text at specified position using the specified foreground and background colors.
|
||||
/// </summary>
|
||||
/// <param name="frameBuffer"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="xoffset"></param>
|
||||
/// <param name="yoffset"></param>
|
||||
/// <param name="fore"></param>
|
||||
/// <param name="back"></param>
|
||||
/// <exception cref="ArgumentNullException">text must be non-null.</exception>
|
||||
public void DrawText(FrameBuffer frameBuffer, string text, int xoffset, int yoffset, byte fore, byte back)
|
||||
{
|
||||
if (text == null)
|
||||
throw new ArgumentNullException("text");
|
||||
|
||||
var textchars = text.ToUpper().ToCharArray();
|
||||
|
||||
for (var i = 0; i < text.Length + 1; i++)
|
||||
{
|
||||
for (var j = 0; j < 9; j++)
|
||||
{
|
||||
var pos = (j + yoffset) * frameBuffer.VisiblePitch + i * 5;
|
||||
for (var k = 0; k < 5; k++)
|
||||
{
|
||||
while (pos >= frameBuffer.VideoBufferByteLength)
|
||||
{
|
||||
pos -= frameBuffer.VideoBufferByteLength;
|
||||
}
|
||||
while (pos < 0)
|
||||
{
|
||||
pos += frameBuffer.VideoBufferByteLength;
|
||||
}
|
||||
frameBuffer.VideoBuffer[pos >> BufferElement.SHIFT][pos++] = back;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < text.Length; i++)
|
||||
{
|
||||
var c = textchars[i];
|
||||
uint fdata;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '/':
|
||||
case '\\':
|
||||
fdata = 0x0122448;
|
||||
break;
|
||||
case '(':
|
||||
fdata = 0x2488842;
|
||||
break;
|
||||
case ')':
|
||||
fdata = 0x4211124;
|
||||
break;
|
||||
case '.':
|
||||
fdata = 0x0000066;
|
||||
break;
|
||||
case ':':
|
||||
fdata = 0x0660660;
|
||||
break;
|
||||
case '-':
|
||||
fdata = 0x0007000;
|
||||
break;
|
||||
default:
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
{
|
||||
fdata = AlphaFontData[c - 'A'];
|
||||
}
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
fdata = DigitFontData[c - '0'];
|
||||
}
|
||||
else
|
||||
{
|
||||
fdata = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var ypos = 8;
|
||||
for (var j = 0; j < 32; j++)
|
||||
{
|
||||
var xpos = j & 3;
|
||||
if (xpos == 0)
|
||||
{
|
||||
ypos--;
|
||||
}
|
||||
|
||||
var pos = (ypos + yoffset) * frameBuffer.VisiblePitch + (4 - xpos) + xoffset;
|
||||
while (pos >= frameBuffer.VideoBufferByteLength)
|
||||
{
|
||||
pos -= frameBuffer.VideoBufferByteLength;
|
||||
}
|
||||
while (pos < 0)
|
||||
{
|
||||
pos += frameBuffer.VideoBufferByteLength;
|
||||
}
|
||||
if (((fdata >> j) & 1) != 0)
|
||||
{
|
||||
frameBuffer.VideoBuffer[pos >> BufferElement.SHIFT][pos] = fore;
|
||||
}
|
||||
}
|
||||
xoffset += 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public class FrameBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of visible pixels on a single horizontal line.
|
||||
/// </summary>
|
||||
public int VisiblePitch { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of <see cref="BufferElement"/>s that represent <c>VisiblePitch</c>.
|
||||
/// </summary>
|
||||
public int VideoBufferElementVisiblePitch { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of visible scan lines.
|
||||
/// </summary>
|
||||
public int Scanlines { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of bytes contained by <c>VideoBuffer</c>.
|
||||
/// </summary>
|
||||
public int VideoBufferByteLength { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of <see cref="BufferElement"/>s contained by <c>VideoBuffer</c>
|
||||
/// </summary>
|
||||
public int VideoBufferElementLength { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of bytes contained by <c>SoundBuffer</c>.
|
||||
/// </summary>
|
||||
public int SoundBufferByteLength { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of <see cref="BufferElement"/>s contained by <c>SoundBuffer</c>
|
||||
/// </summary>
|
||||
public int SoundBufferElementLength { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The buffer containing computed pixel data.
|
||||
/// </summary>
|
||||
public BufferElement[] VideoBuffer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The buffer containing computed PCM audio data.
|
||||
/// </summary>
|
||||
public BufferElement[] SoundBuffer { get; private set; }
|
||||
|
||||
#region Constructors
|
||||
|
||||
private FrameBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
internal FrameBuffer(int visiblePitch, int scanLines)
|
||||
{
|
||||
if (visiblePitch < 0)
|
||||
throw new ArgumentException("visiblePitch must be non-negative.");
|
||||
if (scanLines < 0)
|
||||
throw new ArgumentException("scanLines must be non-negative.");
|
||||
|
||||
VisiblePitch = visiblePitch;
|
||||
VideoBufferElementVisiblePitch = VisiblePitch >> BufferElement.SHIFT;
|
||||
Scanlines = scanLines;
|
||||
VideoBufferByteLength = VisiblePitch * Scanlines;
|
||||
VideoBufferElementLength = VideoBufferElementVisiblePitch * Scanlines;
|
||||
SoundBufferByteLength = Scanlines << 1;
|
||||
SoundBufferElementLength = SoundBufferByteLength >> BufferElement.SHIFT;
|
||||
|
||||
VideoBuffer = new BufferElement[VideoBufferElementLength + (64 >> BufferElement.SHIFT)];
|
||||
SoundBuffer = new BufferElement[SoundBufferElementLength + (64 >> BufferElement.SHIFT)];
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* HSC7800.cs
|
||||
*
|
||||
* The 7800 High Score cartridge--courtesy of Matthias <matthias@atari8bit.de>.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class HSC7800 : IDevice
|
||||
{
|
||||
readonly byte[] ROM;
|
||||
readonly ushort Mask;
|
||||
|
||||
public static ushort Size { get; private set; }
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public byte this[ushort addr]
|
||||
{
|
||||
get { return ROM[addr & Mask]; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public RAM6116 SRAM { get; private set; }
|
||||
|
||||
#region Constructors
|
||||
|
||||
private HSC7800()
|
||||
{
|
||||
}
|
||||
|
||||
public HSC7800(byte[] hscRom, byte[] ram)
|
||||
{
|
||||
if (hscRom == null)
|
||||
throw new ArgumentNullException("hscRom");
|
||||
if (ram == null)
|
||||
throw new ArgumentNullException("ram");
|
||||
if (hscRom.Length != 4096)
|
||||
throw new ArgumentException("ROM size not 4096", "hscRom");
|
||||
|
||||
ROM = hscRom;
|
||||
SRAM = new RAM6116(ram);
|
||||
|
||||
Size = Mask = (ushort)ROM.Length;
|
||||
Mask--;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public HSC7800(DeserializationContext input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
ROM = input.ReadExpectedBytes(4096);
|
||||
SRAM = input.ReadRAM6116();
|
||||
|
||||
Size = Mask = (ushort)ROM.Length;
|
||||
Mask--;
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(ROM);
|
||||
output.Write(SRAM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* IDevice.cs
|
||||
*
|
||||
* Defines interface for devices accessable via the AddressSpace class.
|
||||
*
|
||||
* Copyright © 2003, 2011 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public interface IDevice
|
||||
{
|
||||
void Reset();
|
||||
byte this[ushort addr] { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
void WriteLine(string format, params object[] args);
|
||||
void WriteLine(object value);
|
||||
void Write(string format, params object[] args);
|
||||
void Write(object value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,368 @@
|
|||
/*
|
||||
* InputState.cs
|
||||
*
|
||||
* Class containing the input state of the console and its controllers,
|
||||
* mapping emulator input devices to external input.
|
||||
*
|
||||
* Copyright © 2003-2010 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public class InputState
|
||||
{
|
||||
#region Fields
|
||||
|
||||
const int
|
||||
PaddleOhmMin = 100000,
|
||||
PaddleOhmMax = 800000;
|
||||
|
||||
const int
|
||||
LeftControllerJackIndex = 0,
|
||||
RightControllerJackIndex = 1,
|
||||
ConsoleSwitchIndex = 2,
|
||||
ControllerActionStateIndex = 3,
|
||||
OhmsIndex = ControllerActionStateIndex + 4,
|
||||
LightgunPositionIndex = ControllerActionStateIndex + 4,
|
||||
InputStateSize = ControllerActionStateIndex + 8 + 1;
|
||||
|
||||
// For driving controllers
|
||||
readonly byte[] _rotGrayCodes = new byte[] { 0x0f, 0x0d, 0x0c, 0x0e };
|
||||
readonly int[] _rotState = new int[2];
|
||||
|
||||
readonly int[] _nextInputState = new int[InputStateSize];
|
||||
readonly int[] _inputState = new int[InputStateSize];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Enables the incoming input state buffer to be populated prior to the start of the frame.
|
||||
/// Useful for input playback senarios.
|
||||
/// </summary>
|
||||
/// <return>Return value is ignored.</return>
|
||||
public Func<int[], object> InputAdvancing { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enables access to the input state buffer.
|
||||
/// Useful for input recording senarios.
|
||||
/// </summary>
|
||||
/// <return>Return value is ignored.</return>
|
||||
public Func<int[], object> InputAdvanced { get; set; }
|
||||
|
||||
public void CaptureInputState()
|
||||
{
|
||||
if (InputAdvancing != null)
|
||||
InputAdvancing(_nextInputState);
|
||||
Buffer.BlockCopy(_nextInputState, 0, _inputState, 0, InputStateSize * sizeof(int));
|
||||
if (InputAdvanced != null)
|
||||
InputAdvanced(_inputState);
|
||||
}
|
||||
|
||||
public Controller LeftControllerJack
|
||||
{
|
||||
get { return (Controller)_nextInputState[LeftControllerJackIndex]; }
|
||||
set { _nextInputState[LeftControllerJackIndex] = (int)value; }
|
||||
}
|
||||
|
||||
public Controller RightControllerJack
|
||||
{
|
||||
get { return (Controller)_nextInputState[RightControllerJackIndex]; }
|
||||
set { _nextInputState[RightControllerJackIndex] = (int)value; }
|
||||
}
|
||||
|
||||
public bool IsGameBWConsoleSwitchSet
|
||||
{
|
||||
get { return (_nextInputState[ConsoleSwitchIndex] & (1 << (int) ConsoleSwitch.GameBW)) != 0; }
|
||||
}
|
||||
|
||||
public bool IsLeftDifficultyAConsoleSwitchSet
|
||||
{
|
||||
get { return (_nextInputState[ConsoleSwitchIndex] & (1 << (int)ConsoleSwitch.LeftDifficultyA)) != 0; }
|
||||
}
|
||||
|
||||
public bool IsRightDifficultyAConsoleSwitchSet
|
||||
{
|
||||
get { return (_nextInputState[ConsoleSwitchIndex] & (1 << (int)ConsoleSwitch.RightDifficultyA)) != 0; }
|
||||
}
|
||||
|
||||
public void RaiseInput(int playerNo, MachineInput input, bool down)
|
||||
{
|
||||
switch (input)
|
||||
{
|
||||
case MachineInput.Fire:
|
||||
SetControllerActionState(playerNo, ControllerAction.Trigger, down);
|
||||
break;
|
||||
case MachineInput.Fire2:
|
||||
SetControllerActionState(playerNo, ControllerAction.Trigger2, down);
|
||||
break;
|
||||
case MachineInput.Left:
|
||||
SetControllerActionState(playerNo, ControllerAction.Left, down);
|
||||
if (down) SetControllerActionState(playerNo, ControllerAction.Right, false);
|
||||
break;
|
||||
case MachineInput.Up:
|
||||
SetControllerActionState(playerNo, ControllerAction.Up, down);
|
||||
if (down) SetControllerActionState(playerNo, ControllerAction.Down, false);
|
||||
break;
|
||||
case MachineInput.Right:
|
||||
SetControllerActionState(playerNo, ControllerAction.Right, down);
|
||||
if (down) SetControllerActionState(playerNo, ControllerAction.Left, false);
|
||||
break;
|
||||
case MachineInput.Down:
|
||||
SetControllerActionState(playerNo, ControllerAction.Down, down);
|
||||
if (down) SetControllerActionState(playerNo, ControllerAction.Up, false);
|
||||
break;
|
||||
case MachineInput.NumPad7:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad7, down);
|
||||
break;
|
||||
case MachineInput.NumPad8:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad8, down);
|
||||
break;
|
||||
case MachineInput.NumPad9:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad9, down);
|
||||
break;
|
||||
case MachineInput.NumPad4:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad4, down);
|
||||
break;
|
||||
case MachineInput.NumPad5:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad5, down);
|
||||
break;
|
||||
case MachineInput.NumPad6:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad6, down);
|
||||
break;
|
||||
case MachineInput.NumPad1:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad1, down);
|
||||
break;
|
||||
case MachineInput.NumPad2:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad2, down);
|
||||
break;
|
||||
case MachineInput.NumPad3:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad3, down);
|
||||
break;
|
||||
case MachineInput.NumPadMult:
|
||||
SetControllerActionState(playerNo, ControllerAction.KeypadA, down);
|
||||
break;
|
||||
case MachineInput.NumPad0:
|
||||
SetControllerActionState(playerNo, ControllerAction.Keypad0, down);
|
||||
break;
|
||||
case MachineInput.NumPadHash:
|
||||
SetControllerActionState(playerNo, ControllerAction.KeypadP, down);
|
||||
break;
|
||||
case MachineInput.Driving0:
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving0, true);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving1, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving2, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving3, false);
|
||||
break;
|
||||
case MachineInput.Driving1:
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving0, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving1, true);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving2, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving3, false);
|
||||
break;
|
||||
case MachineInput.Driving2:
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving0, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving1, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving2, true);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving3, false);
|
||||
break;
|
||||
case MachineInput.Driving3:
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving0, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving1, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving2, false);
|
||||
SetControllerActionState(playerNo, ControllerAction.Driving3, true);
|
||||
break;
|
||||
case MachineInput.Reset:
|
||||
SetConsoleSwitchState(ConsoleSwitch.GameReset, down);
|
||||
break;
|
||||
case MachineInput.Select:
|
||||
SetConsoleSwitchState(ConsoleSwitch.GameSelect, down);
|
||||
break;
|
||||
case MachineInput.Color:
|
||||
if (down) ToggleConsoleSwitchState(ConsoleSwitch.GameBW);
|
||||
break;
|
||||
case MachineInput.LeftDifficulty:
|
||||
if (down) ToggleConsoleSwitchState(ConsoleSwitch.LeftDifficultyA);
|
||||
break;
|
||||
case MachineInput.RightDifficulty:
|
||||
if (down) ToggleConsoleSwitchState(ConsoleSwitch.RightDifficultyA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void RaisePaddleInput(int playerNo, int valMax, int val)
|
||||
{
|
||||
var ohms = PaddleOhmMax - (PaddleOhmMax - PaddleOhmMin) / valMax * val;
|
||||
_nextInputState[OhmsIndex + (playerNo & 3)] = ohms;
|
||||
}
|
||||
|
||||
public void RaiseLightgunPos(int playerNo, int scanline, int hpos)
|
||||
{
|
||||
var i = LightgunPositionIndex + ((playerNo & 1) << 1);
|
||||
_nextInputState[i++] = scanline;
|
||||
_nextInputState[i] = hpos;
|
||||
}
|
||||
|
||||
public void ClearAllInput()
|
||||
{
|
||||
_nextInputState[ConsoleSwitchIndex] = 0;
|
||||
ClearLeftJackInput();
|
||||
ClearRightJackInput();
|
||||
}
|
||||
|
||||
public void ClearInputByPlayer(int playerNo)
|
||||
{
|
||||
_nextInputState[OhmsIndex + (playerNo & 3)] = 0;
|
||||
_nextInputState[ControllerActionStateIndex + (playerNo & 3)] = 0;
|
||||
_nextInputState[LightgunPositionIndex + ((playerNo & 1) << 1)] = _nextInputState[LightgunPositionIndex + ((playerNo & 1) << 1) + 1] = 0;
|
||||
}
|
||||
|
||||
public void ClearLeftJackInput()
|
||||
{
|
||||
_nextInputState[OhmsIndex] = _nextInputState[OhmsIndex + 1] = 0;
|
||||
_nextInputState[ControllerActionStateIndex] = 0;
|
||||
switch (LeftControllerJack)
|
||||
{
|
||||
case Controller.Paddles:
|
||||
_nextInputState[ControllerActionStateIndex] = _nextInputState[ControllerActionStateIndex + 1] = 0;
|
||||
break;
|
||||
default:
|
||||
_nextInputState[ControllerActionStateIndex] = 0;
|
||||
break;
|
||||
}
|
||||
_nextInputState[LightgunPositionIndex] = _nextInputState[LightgunPositionIndex + 1] = 0;
|
||||
}
|
||||
|
||||
public void ClearRightJackInput()
|
||||
{
|
||||
_nextInputState[OhmsIndex + 2] = _nextInputState[OhmsIndex + 3] = 0;
|
||||
switch (RightControllerJack)
|
||||
{
|
||||
case Controller.Paddles:
|
||||
_nextInputState[ControllerActionStateIndex + 2] = _nextInputState[ControllerActionStateIndex + 3] = 0;
|
||||
break;
|
||||
default:
|
||||
_nextInputState[ControllerActionStateIndex + 1] = 0;
|
||||
break;
|
||||
}
|
||||
_nextInputState[LightgunPositionIndex + 2] = _nextInputState[LightgunPositionIndex + 3] = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public InputState()
|
||||
{
|
||||
}
|
||||
|
||||
public InputState(DeserializationContext input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
_rotState = input.ReadIntegers(2);
|
||||
_nextInputState = input.ReadIntegers(InputStateSize);
|
||||
_inputState = input.ReadIntegers(InputStateSize);
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(_rotState);
|
||||
output.Write(_nextInputState);
|
||||
output.Write(_inputState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Members
|
||||
|
||||
internal bool SampleCapturedConsoleSwitchState(ConsoleSwitch consoleSwitch)
|
||||
{
|
||||
return (_inputState[ConsoleSwitchIndex] & (1 << (int)consoleSwitch)) != 0;
|
||||
}
|
||||
|
||||
internal bool SampleCapturedControllerActionState(int playerno, ControllerAction action)
|
||||
{
|
||||
return (_inputState[ControllerActionStateIndex + (playerno & 3)] & (1 << (int)action)) != 0;
|
||||
}
|
||||
|
||||
internal int SampleCapturedOhmState(int playerNo)
|
||||
{
|
||||
return _inputState[OhmsIndex + (playerNo & 3)];
|
||||
}
|
||||
|
||||
internal void SampleCapturedLightGunPosition(int playerNo, out int scanline, out int hpos)
|
||||
{
|
||||
var i = LightgunPositionIndex + ((playerNo & 1) << 1);
|
||||
scanline = _inputState[i++];
|
||||
hpos = _inputState[i];
|
||||
}
|
||||
|
||||
internal byte SampleCapturedDrivingState(int playerNo)
|
||||
{
|
||||
if (SampleCapturedControllerActionState(playerNo, ControllerAction.Driving0))
|
||||
_rotState[playerNo] = 0;
|
||||
else if (SampleCapturedControllerActionState(playerNo, ControllerAction.Driving1))
|
||||
_rotState[playerNo] = 1;
|
||||
else if (SampleCapturedControllerActionState(playerNo, ControllerAction.Driving2))
|
||||
_rotState[playerNo] = 2;
|
||||
else if (SampleCapturedControllerActionState(playerNo, ControllerAction.Driving3))
|
||||
_rotState[playerNo] = 3;
|
||||
return _rotGrayCodes[_rotState[playerNo]];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Object Overrides
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return GetType().Name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
void SetControllerActionState(int playerNo, ControllerAction action, bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
_nextInputState[ControllerActionStateIndex + (playerNo & 3)] |= (1 << (int)action);
|
||||
}
|
||||
else
|
||||
{
|
||||
_nextInputState[ControllerActionStateIndex + (playerNo & 3)] &= ~(1 << (int)action);
|
||||
}
|
||||
}
|
||||
|
||||
void SetConsoleSwitchState(ConsoleSwitch consoleSwitch, bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
_nextInputState[ConsoleSwitchIndex] |= (byte)(1 << (byte)consoleSwitch);
|
||||
}
|
||||
else
|
||||
{
|
||||
_nextInputState[ConsoleSwitchIndex] &= (byte)~(1 << (byte)consoleSwitch);
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleConsoleSwitchState(ConsoleSwitch consoleSwitch)
|
||||
{
|
||||
var consoleSwitchState = (_nextInputState[ConsoleSwitchIndex] & (1 << (int) consoleSwitch)) != 0;
|
||||
SetConsoleSwitchState(consoleSwitch, !consoleSwitchState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,242 @@
|
|||
/*
|
||||
* M6502DASM.cs
|
||||
*
|
||||
* Provides disassembly services.
|
||||
*
|
||||
* Copyright © 2003, 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public static class M6502DASM
|
||||
{
|
||||
// Instruction Mnemonics
|
||||
enum m : uint
|
||||
{
|
||||
ADC = 1, AND, ASL,
|
||||
BIT, BCC, BCS, BEQ, BMI, BNE, BPL, BRK, BVC, BVS,
|
||||
CLC, CLD, CLI, CLV, CMP, CPX, CPY,
|
||||
DEC, DEX, DEY,
|
||||
EOR,
|
||||
INC, INX, INY,
|
||||
JMP, JSR,
|
||||
LDA, LDX, LDY, LSR,
|
||||
NOP,
|
||||
ORA,
|
||||
PLA, PLP, PHA, PHP,
|
||||
ROL, ROR, RTI, RTS,
|
||||
SEC, SEI, STA, SBC, SED, STX, STY,
|
||||
TAX, TAY, TSX, TXA, TXS, TYA,
|
||||
|
||||
// Illegal/undefined opcodes
|
||||
isb,
|
||||
kil,
|
||||
lax,
|
||||
rla,
|
||||
sax,
|
||||
top
|
||||
}
|
||||
|
||||
// Addressing Modes
|
||||
enum a : uint
|
||||
{
|
||||
REL, // Relative: $aa (branch instructions only)
|
||||
ZPG, // Zero Page: $aa
|
||||
ZPX, // Zero Page Indexed X: $aa,X
|
||||
ZPY, // Zero Page Indexed Y: $aa,Y
|
||||
ABS, // Absolute: $aaaa
|
||||
ABX, // Absolute Indexed X: $aaaa,X
|
||||
ABY, // Absolute Indexed Y: $aaaa,Y
|
||||
IDX, // Indexed Indirect: ($aa,X)
|
||||
IDY, // Indirect Indexed: ($aa),Y
|
||||
IND, // Indirect Absolute: ($aaaa) (JMP only)
|
||||
IMM, // Immediate: #aa
|
||||
IMP, // Implied
|
||||
ACC // Accumulator
|
||||
}
|
||||
|
||||
static readonly m[] MnemonicMatrix = {
|
||||
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
/*0*/ m.BRK, m.ORA, m.kil, 0, 0, m.ORA, m.ASL, 0, m.PHP, m.ORA, m.ASL, 0, m.top, m.ORA, m.ASL, 0,/*0*/
|
||||
/*1*/ m.BPL, m.ORA, m.kil, 0, 0, m.ORA, m.ASL, 0, m.CLC, m.ORA, 0, 0, m.top, m.ORA, m.ASL, 0,/*1*/
|
||||
/*2*/ m.JSR, m.AND, m.kil, 0, m.BIT, m.AND, m.ROL, 0, m.PLP, m.AND, m.ROL, 0, m.BIT, m.AND, m.ROL, 0,/*2*/
|
||||
/*3*/ m.BMI, m.AND, m.kil, 0, 0, m.AND, m.ROL, 0, m.SEC, m.AND, 0, 0, m.top, m.AND, m.ROL, m.rla,/*3*/
|
||||
/*4*/ m.RTI, m.EOR, m.kil, 0, 0, m.EOR, m.LSR, 0, m.PHA, m.EOR, m.LSR, 0, m.JMP, m.EOR, m.LSR, 0,/*4*/
|
||||
/*5*/ m.BVC, m.EOR, m.kil, 0, 0, m.EOR, m.LSR, 0, m.CLI, m.EOR, 0, 0, m.top, m.EOR, m.LSR, 0,/*5*/
|
||||
/*6*/ m.RTS, m.ADC, m.kil, 0, 0, m.ADC, m.ROR, 0, m.PLA, m.ADC, m.ROR, 0, m.JMP, m.ADC, m.ROR, 0,/*6*/
|
||||
/*7*/ m.BVS, m.ADC, m.kil, 0, 0, m.ADC, m.ROR, 0, m.SEI, m.ADC, 0, 0, m.top, m.ADC, m.ROR, 0,/*7*/
|
||||
/*8*/ 0, m.STA, 0, m.sax, m.STY, m.STA, m.STX, m.sax, m.DEY, 0, m.TXA, 0, m.STY, m.STA, m.STX, m.sax,/*8*/
|
||||
/*9*/ m.BCC, m.STA, m.kil, 0, m.STY, m.STA, m.STX, m.sax, m.TYA, m.STA, m.TXS, 0, m.top, m.STA, 0, 0,/*9*/
|
||||
/*A*/ m.LDY, m.LDA, m.LDX, m.lax, m.LDY, m.LDA, m.LDX, m.lax, m.TAY, m.LDA, m.TAX, 0, m.LDY, m.LDA, m.LDX, m.lax,/*A*/
|
||||
/*B*/ m.BCS, m.LDA, m.kil, m.lax, m.LDY, m.LDA, m.LDX, m.lax, m.CLV, m.LDA, m.TSX, 0, m.LDY, m.LDA, m.LDX, m.lax,/*B*/
|
||||
/*C*/ m.CPY, m.CMP, 0, 0, m.CPY, m.CMP, m.DEC, 0, m.INY, m.CMP, m.DEX, 0, m.CPY, m.CMP, m.DEC, 0,/*C*/
|
||||
/*D*/ m.BNE, m.CMP, m.kil, 0, 0, m.CMP, m.DEC, 0, m.CLD, m.CMP, 0, 0, m.top, m.CMP, m.DEC, 0,/*D*/
|
||||
/*E*/ m.CPX, m.SBC, 0, 0, m.CPX, m.SBC, m.INC, 0, m.INX, m.SBC, m.NOP, 0, m.CPX, m.SBC, m.INC, m.isb,/*E*/
|
||||
/*F*/ m.BEQ, m.SBC, m.kil, 0, 0, m.SBC, m.INC, 0, m.SED, m.SBC, 0, 0, m.top, m.SBC, m.INC, m.isb /*F*/
|
||||
};
|
||||
|
||||
static readonly a[] AddressingModeMatrix = {
|
||||
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
/*0*/ a.IMP, a.IDX, a.IMP, 0, 0, a.ZPG, a.ZPG, 0, a.IMP, a.IMM, a.ACC, 0, a.ABS, a.ABS, a.ABS, 0,/*0*/
|
||||
/*1*/ a.REL, a.IDY, a.IMP, 0, 0, a.ZPG, a.ZPG, 0, a.IMP, a.ABY, 0, 0, a.ABS, a.ABX, a.ABX, 0,/*1*/
|
||||
/*2*/ a.ABS, a.IDX, a.IMP, 0, a.ZPG, a.ZPG, a.ZPG, 0, a.IMP, a.IMM, a.ACC, 0, a.ABS, a.ABS, a.ABS, 0,/*2*/
|
||||
/*3*/ a.REL, a.IDY, a.IMP, 0, 0, a.ZPG, a.ZPG, 0, a.IMP, a.ABY, 0, 0, a.ABS, a.ABX, a.ABX, a.ABX,/*3*/
|
||||
/*4*/ a.IMP, a.IDY, a.IMP, 0, 0, a.ZPG, a.ZPG, 0, a.IMP, a.IMM, a.ACC, 0, a.ABS, a.ABS, a.ABS, 0,/*4*/
|
||||
/*5*/ a.REL, a.IDY, a.IMP, 0, 0, a.ZPG, a.ZPG, 0, a.IMP, a.ABY, 0, 0, a.ABS, a.ABX, a.ABX, 0,/*5*/
|
||||
/*6*/ a.IMP, a.IDX, a.IMP, 0, 0, a.ZPG, a.ZPG, 0, a.IMP, a.IMM, a.ACC, 0, a.IND, a.ABS, a.ABS, 0,/*6*/
|
||||
/*7*/ a.REL, a.IDY, a.IMP, 0, 0, a.ZPX, a.ZPX, 0, a.IMP, a.ABY, 0, 0, a.ABS, a.ABX, a.ABX, 0,/*7*/
|
||||
/*8*/ 0, a.IDY, 0, a.IDX, a.ZPG, a.ZPG, a.ZPG, a.ZPG, a.IMP, 0, a.IMP, 0, a.ABS, a.ABS, a.ABS, a.ABS,/*8*/
|
||||
/*9*/ a.REL, a.IDY, a.IMP, 0, a.ZPX, a.ZPX, a.ZPY, a.ZPY, a.IMP, a.ABY, a.IMP, 0, a.ABS, a.ABX, 0, 0,/*9*/
|
||||
/*A*/ a.IMM, a.IND, a.IMM, a.IDX, a.ZPG, a.ZPG, a.ZPG, a.ZPX, a.IMP, a.IMM, a.IMP, 0, a.ABS, a.ABS, a.ABS, a.ABS,/*A*/
|
||||
/*B*/ a.REL, a.IDY, a.IMP, a.IDY, a.ZPX, a.ZPX, a.ZPY, a.ZPY, a.IMP, a.ABY, a.IMP, 0, a.ABX, a.ABX, a.ABY, a.ABY,/*B*/
|
||||
/*C*/ a.IMM, a.IDX, 0, 0, a.ZPG, a.ZPG, a.ZPG, 0, a.IMP, a.IMM, a.IMP, 0, a.ABS, a.ABS, a.ABS, 0,/*C*/
|
||||
/*D*/ a.REL, a.IDY, a.IMP, 0, 0, a.ZPX, a.ZPX, 0, a.IMP, a.ABY, 0, 0, a.ABS, a.ABX, a.ABX, 0,/*D*/
|
||||
/*E*/ a.IMM, a.IDX, 0, 0, a.ZPG, a.ZPG, a.ZPG, 0, a.IMP, a.IMM, a.IMP, 0, a.ABS, a.ABS, a.ABS, a.ABS,/*E*/
|
||||
/*F*/ a.REL, a.IDY, a.IMP, 0, 0, a.ZPX, a.ZPX, 0, a.IMP, a.ABY, 0, 0, a.ABS, a.ABX, a.ABX, a.ABX /*F*/
|
||||
};
|
||||
|
||||
public static string GetRegisters(M6502 cpu)
|
||||
{
|
||||
var dSB = new StringBuilder();
|
||||
dSB.Append(String.Format(
|
||||
"PC:{0:x4} A:{1:x2} X:{2:x2} Y:{3:x2} S:{4:x2} P:",
|
||||
cpu.PC, cpu.A, cpu.X, cpu.Y, cpu.S));
|
||||
|
||||
const string flags = "nv0bdizcNV1BDIZC";
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
dSB.Append(((cpu.P & (1 << (7 - i))) == 0) ? flags[i] : flags[i + 8]);
|
||||
}
|
||||
return dSB.ToString();
|
||||
}
|
||||
|
||||
public static string Disassemble(AddressSpace addrSpace, ushort atAddr, ushort untilAddr)
|
||||
{
|
||||
var dSB = new StringBuilder();
|
||||
var dPC = atAddr;
|
||||
while (atAddr < untilAddr)
|
||||
{
|
||||
dSB.AppendFormat("{0:x4}: ", dPC);
|
||||
var len = GetInstructionLength(addrSpace, dPC);
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
if (i < len)
|
||||
{
|
||||
dSB.AppendFormat("{0:x2} ", addrSpace[atAddr++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
dSB.Append(" ");
|
||||
}
|
||||
}
|
||||
dSB.AppendFormat("{0,-15}{1}", RenderOpCode(addrSpace, dPC), Environment.NewLine);
|
||||
dPC += (ushort)len;
|
||||
}
|
||||
if (dSB.Length > 0)
|
||||
{
|
||||
dSB.Length--; // Trim trailing newline
|
||||
}
|
||||
return dSB.ToString();
|
||||
}
|
||||
|
||||
public static string MemDump(AddressSpace addrSpace, ushort atAddr, ushort untilAddr)
|
||||
{
|
||||
var dSB = new StringBuilder();
|
||||
var len = untilAddr - atAddr;
|
||||
while (len-- >= 0)
|
||||
{
|
||||
dSB.AppendFormat("{0:x4}: ", atAddr);
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
dSB.AppendFormat("{0:x2} ", addrSpace[atAddr++]);
|
||||
if (i == 3)
|
||||
{
|
||||
dSB.Append(" ");
|
||||
}
|
||||
}
|
||||
dSB.Append("\n");
|
||||
}
|
||||
if (dSB.Length > 0)
|
||||
{
|
||||
dSB.Length--; // Trim trailing newline
|
||||
}
|
||||
return dSB.ToString();
|
||||
}
|
||||
|
||||
public static string RenderOpCode(AddressSpace addrSpace, ushort PC)
|
||||
{
|
||||
var num_operands = GetInstructionLength(addrSpace, PC) - 1;
|
||||
var PC1 = (ushort)(PC + 1);
|
||||
string addrmodeStr;
|
||||
|
||||
switch (AddressingModeMatrix[addrSpace[PC]])
|
||||
{
|
||||
case a.REL:
|
||||
addrmodeStr = String.Format("${0:x4}", (ushort)(PC + (sbyte)(addrSpace[PC1]) + 2));
|
||||
break;
|
||||
case a.ZPG:
|
||||
case a.ABS:
|
||||
addrmodeStr = RenderEA(addrSpace, PC1, num_operands);
|
||||
break;
|
||||
case a.ZPX:
|
||||
case a.ABX:
|
||||
addrmodeStr = RenderEA(addrSpace, PC1, num_operands) + ",X";
|
||||
break;
|
||||
case a.ZPY:
|
||||
case a.ABY:
|
||||
addrmodeStr = RenderEA(addrSpace, PC1, num_operands) + ",Y";
|
||||
break;
|
||||
case a.IDX:
|
||||
addrmodeStr = "(" + RenderEA(addrSpace, PC1, num_operands) + ",X)";
|
||||
break;
|
||||
case a.IDY:
|
||||
addrmodeStr = "(" + RenderEA(addrSpace, PC1, num_operands) + "),Y";
|
||||
break;
|
||||
case a.IND:
|
||||
addrmodeStr = "(" + RenderEA(addrSpace, PC1, num_operands) + ")";
|
||||
break;
|
||||
case a.IMM:
|
||||
addrmodeStr = "#" + RenderEA(addrSpace, PC1, num_operands);
|
||||
break;
|
||||
default:
|
||||
// a.IMP, a.ACC
|
||||
addrmodeStr = string.Empty;
|
||||
break;
|
||||
}
|
||||
|
||||
return string.Format("{0} {1}", MnemonicMatrix[addrSpace[PC]], addrmodeStr);
|
||||
}
|
||||
|
||||
static int GetInstructionLength(AddressSpace addrSpace, ushort PC)
|
||||
{
|
||||
switch (AddressingModeMatrix[addrSpace[PC]])
|
||||
{
|
||||
case a.ACC:
|
||||
case a.IMP:
|
||||
return 1;
|
||||
case a.REL:
|
||||
case a.ZPG:
|
||||
case a.ZPX:
|
||||
case a.ZPY:
|
||||
case a.IDX:
|
||||
case a.IDY:
|
||||
case a.IMM:
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
static string RenderEA(AddressSpace addrSpace, ushort PC, int bytes)
|
||||
{
|
||||
var lsb = addrSpace[PC];
|
||||
var msb = (bytes == 2) ? addrSpace[(ushort)(PC + 1)] : (byte)0;
|
||||
var ea = (ushort)(lsb | (msb << 8));
|
||||
return string.Format((bytes == 1) ? "${0:x2}" : "${0:x4}", ea);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Machine2600.cs
|
||||
*
|
||||
* The realization of a 2600 machine.
|
||||
*
|
||||
* Copyright © 2003, 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public class Machine2600 : MachineBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
protected TIA TIA { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
TIA.Reset();
|
||||
PIA.Reset();
|
||||
CPU.Reset();
|
||||
}
|
||||
|
||||
public override void ComputeNextFrame(FrameBuffer frameBuffer)
|
||||
{
|
||||
base.ComputeNextFrame(frameBuffer);
|
||||
TIA.StartFrame();
|
||||
CPU.RunClocks = (FrameBuffer.Scanlines + 3) * 76;
|
||||
while (CPU.RunClocks > 0 && !CPU.Jammed)
|
||||
{
|
||||
if (TIA.WSYNCDelayClocks > 0)
|
||||
{
|
||||
CPU.Clock += (ulong)TIA.WSYNCDelayClocks / 3;
|
||||
CPU.RunClocks -= TIA.WSYNCDelayClocks / 3;
|
||||
TIA.WSYNCDelayClocks = 0;
|
||||
}
|
||||
if (TIA.EndOfFrame)
|
||||
{
|
||||
break;
|
||||
}
|
||||
CPU.Execute();
|
||||
}
|
||||
TIA.EndFrame();
|
||||
}
|
||||
|
||||
public Machine2600(Cart cart, ILogger logger, int slines, int startl, int fHZ, int sRate, int[] p)
|
||||
: base(logger, slines, startl, fHZ, sRate, p, 160)
|
||||
{
|
||||
Mem = new AddressSpace(this, 13, 6); // 2600: 13bit, 64byte pages
|
||||
|
||||
CPU = new M6502(this, 1);
|
||||
|
||||
TIA = new TIA(this);
|
||||
for (ushort i = 0; i < 0x1000; i += 0x100)
|
||||
{
|
||||
Mem.Map(i, 0x0080, TIA);
|
||||
}
|
||||
|
||||
PIA = new PIA(this);
|
||||
for (ushort i = 0x0080; i < 0x1000; i += 0x100)
|
||||
{
|
||||
Mem.Map(i, 0x0080, PIA);
|
||||
}
|
||||
|
||||
Cart = cart;
|
||||
Mem.Map(0x1000, 0x1000, Cart);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Machine2600(DeserializationContext input, int[] palette) : base(input, palette)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
|
||||
Mem = input.ReadAddressSpace(this, 13, 6); // 2600: 13bit, 64byte pages
|
||||
|
||||
CPU = input.ReadM6502(this, 1);
|
||||
|
||||
TIA = input.ReadTIA(this);
|
||||
for (ushort i = 0; i < 0x1000; i += 0x100)
|
||||
{
|
||||
Mem.Map(i, 0x0080, TIA);
|
||||
}
|
||||
|
||||
PIA = input.ReadPIA(this);
|
||||
for (ushort i = 0x0080; i < 0x1000; i += 0x100)
|
||||
{
|
||||
Mem.Map(i, 0x0080, PIA);
|
||||
}
|
||||
|
||||
Cart = input.ReadCart(this);
|
||||
Mem.Map(0x1000, 0x1000, Cart);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(Mem);
|
||||
output.Write(CPU);
|
||||
output.Write(TIA);
|
||||
output.Write(PIA);
|
||||
output.Write(Cart);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class Machine2600NTSC : Machine2600
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return GetType().Name;
|
||||
}
|
||||
|
||||
public Machine2600NTSC(Cart cart, ILogger logger)
|
||||
: base(cart, logger, 262, 16, 60, 31440 /* NTSC_SAMPLES_PER_SEC */, TIATables.NTSCPalette)
|
||||
{
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Machine2600NTSC(DeserializationContext input) : base(input, TIATables.NTSCPalette)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
output.WriteVersion(1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class Machine2600PAL : Machine2600
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return GetType().Name;
|
||||
}
|
||||
|
||||
public Machine2600PAL(Cart cart, ILogger logger)
|
||||
: base(cart, logger, 312, 32, 50, 31200 /* PAL_SAMPLES_PER_SEC */, TIATables.PALPalette)
|
||||
{
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Machine2600PAL(DeserializationContext input) : base(input, TIATables.PALPalette)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
output.WriteVersion(1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
* Machine7800.cs
|
||||
*
|
||||
* The realization of a 7800 machine.
|
||||
*
|
||||
* Copyright © 2003-2005 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public class Machine7800 : MachineBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
protected Maria Maria { get; set; }
|
||||
protected RAM6116 RAM1 { get; set; }
|
||||
protected RAM6116 RAM2 { get; set; }
|
||||
protected Bios7800 BIOS { get; private set; }
|
||||
protected HSC7800 HSC { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public void SwapInBIOS()
|
||||
{
|
||||
if (BIOS == null)
|
||||
return;
|
||||
Mem.Map((ushort)(0x10000 - BIOS.Size), BIOS.Size, BIOS);
|
||||
}
|
||||
|
||||
public void SwapOutBIOS()
|
||||
{
|
||||
if (BIOS == null)
|
||||
return;
|
||||
Mem.Map((ushort)(0x10000 - BIOS.Size), BIOS.Size, Cart);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
SwapInBIOS();
|
||||
if (HSC != null)
|
||||
HSC.Reset();
|
||||
Cart.Reset();
|
||||
Maria.Reset();
|
||||
PIA.Reset();
|
||||
CPU.Reset();
|
||||
}
|
||||
|
||||
public override void ComputeNextFrame(FrameBuffer frameBuffer)
|
||||
{
|
||||
base.ComputeNextFrame(frameBuffer);
|
||||
|
||||
AssertDebug(CPU.Jammed || CPU.RunClocks <= 0 && (CPU.RunClocks % CPU.RunClocksMultiple) == 0);
|
||||
AssertDebug(CPU.Jammed || ((CPU.Clock + (ulong)(CPU.RunClocks / CPU.RunClocksMultiple)) % (114 * (ulong)FrameBuffer.Scanlines)) == 0);
|
||||
|
||||
ulong startOfScanlineCpuClock = 0;
|
||||
|
||||
Maria.StartFrame();
|
||||
Cart.StartFrame();
|
||||
for (var i = 0; i < FrameBuffer.Scanlines && !CPU.Jammed; i++)
|
||||
{
|
||||
AssertDebug(CPU.RunClocks <= 0 && (CPU.RunClocks % CPU.RunClocksMultiple) == 0);
|
||||
var newStartOfScanlineCpuClock = CPU.Clock + (ulong)(CPU.RunClocks / CPU.RunClocksMultiple);
|
||||
|
||||
AssertDebug(startOfScanlineCpuClock == 0 || newStartOfScanlineCpuClock == startOfScanlineCpuClock + 114);
|
||||
startOfScanlineCpuClock = newStartOfScanlineCpuClock;
|
||||
|
||||
CPU.RunClocks += (7 * CPU.RunClocksMultiple);
|
||||
var remainingRunClocks = (114 - 7) * CPU.RunClocksMultiple;
|
||||
|
||||
CPU.Execute();
|
||||
if (CPU.Jammed)
|
||||
break;
|
||||
if (CPU.EmulatorPreemptRequest)
|
||||
{
|
||||
Maria.DoDMAProcessing();
|
||||
var remainingCpuClocks = 114 - (CPU.Clock - startOfScanlineCpuClock);
|
||||
CPU.Clock += remainingCpuClocks;
|
||||
CPU.RunClocks = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
var dmaClocks = Maria.DoDMAProcessing();
|
||||
|
||||
// CHEAT: Ace of Aces: Title screen has a single scanline flicker without this. Maria DMA clock counting probably not 100% accurate.
|
||||
if (i == 203 && FrameBuffer.Scanlines == 262 /*NTSC*/ || i == 228 && FrameBuffer.Scanlines == 312 /*PAL*/)
|
||||
if (dmaClocks == 152 && remainingRunClocks == 428 && (CPU.RunClocks == -4 || CPU.RunClocks == -8))
|
||||
dmaClocks -= 4;
|
||||
|
||||
// Unsure exactly what to do if Maria DMA processing extends past the current scanline.
|
||||
// For now, throw away half remaining until we are within the current scanline.
|
||||
// KLAX initialization starts DMA without initializing the DLL data structure.
|
||||
// Maria processing then runs away causing an invalid CPU opcode to be executed that jams the machine.
|
||||
// So Maria must give up at some point, but not clear exactly how.
|
||||
// Anyway, this makes KLAX work without causing breakage elsewhere.
|
||||
while ((CPU.RunClocks + remainingRunClocks) < dmaClocks)
|
||||
{
|
||||
dmaClocks >>= 1;
|
||||
}
|
||||
|
||||
// Assume the CPU waits until the next div4 boundary to proceed after DMA processing.
|
||||
if ((dmaClocks & 3) != 0)
|
||||
{
|
||||
dmaClocks += 4;
|
||||
dmaClocks -= (dmaClocks & 3);
|
||||
}
|
||||
|
||||
CPU.Clock += (ulong)(dmaClocks / CPU.RunClocksMultiple);
|
||||
CPU.RunClocks -= dmaClocks;
|
||||
|
||||
CPU.RunClocks += remainingRunClocks;
|
||||
|
||||
CPU.Execute();
|
||||
if (CPU.Jammed)
|
||||
break;
|
||||
if (CPU.EmulatorPreemptRequest)
|
||||
{
|
||||
var remainingCpuClocks = 114 - (CPU.Clock - startOfScanlineCpuClock);
|
||||
CPU.Clock += remainingCpuClocks;
|
||||
CPU.RunClocks = 0;
|
||||
}
|
||||
}
|
||||
Cart.EndFrame();
|
||||
Maria.EndFrame();
|
||||
}
|
||||
|
||||
public Machine7800(Cart cart, Bios7800 bios, HSC7800 hsc, ILogger logger, int scanlines, int startl, int fHZ, int sRate, int[] p)
|
||||
: base(logger, scanlines, startl, fHZ, sRate, p, 320)
|
||||
{
|
||||
Mem = new AddressSpace(this, 16, 6); // 7800: 16bit, 64byte pages
|
||||
|
||||
CPU = new M6502(this, 4);
|
||||
|
||||
Maria = new Maria(this, scanlines);
|
||||
Mem.Map(0x0000, 0x0040, Maria);
|
||||
Mem.Map(0x0100, 0x0040, Maria);
|
||||
Mem.Map(0x0200, 0x0040, Maria);
|
||||
Mem.Map(0x0300, 0x0040, Maria);
|
||||
|
||||
PIA = new PIA(this);
|
||||
Mem.Map(0x0280, 0x0080, PIA);
|
||||
Mem.Map(0x0480, 0x0080, PIA);
|
||||
Mem.Map(0x0580, 0x0080, PIA);
|
||||
|
||||
RAM1 = new RAM6116();
|
||||
RAM2 = new RAM6116();
|
||||
Mem.Map(0x1800, 0x0800, RAM1);
|
||||
Mem.Map(0x2000, 0x0800, RAM2);
|
||||
|
||||
Mem.Map(0x0040, 0x00c0, RAM2); // page 0 shadow
|
||||
Mem.Map(0x0140, 0x00c0, RAM2); // page 1 shadow
|
||||
Mem.Map(0x2800, 0x0800, RAM2); // shadow1
|
||||
Mem.Map(0x3000, 0x0800, RAM2); // shadow2
|
||||
Mem.Map(0x3800, 0x0800, RAM2); // shadow3
|
||||
|
||||
BIOS = bios;
|
||||
HSC = hsc;
|
||||
|
||||
if (HSC != null)
|
||||
{
|
||||
Mem.Map(0x1000, 0x800, HSC.SRAM);
|
||||
Mem.Map(0x3000, 0x1000, HSC);
|
||||
Logger.WriteLine("7800 Highscore Cartridge Installed");
|
||||
}
|
||||
|
||||
Cart = cart;
|
||||
Mem.Map(0x4000, 0xc000, Cart);
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Machine7800(DeserializationContext input, int[] palette, int scanlines) : base(input, palette)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
|
||||
Mem = input.ReadAddressSpace(this, 16, 6); // 7800: 16bit, 64byte pages
|
||||
|
||||
CPU = input.ReadM6502(this, 4);
|
||||
|
||||
Maria = input.ReadMaria(this, scanlines);
|
||||
Mem.Map(0x0000, 0x0040, Maria);
|
||||
Mem.Map(0x0100, 0x0040, Maria);
|
||||
Mem.Map(0x0200, 0x0040, Maria);
|
||||
Mem.Map(0x0300, 0x0040, Maria);
|
||||
|
||||
PIA = input.ReadPIA(this);
|
||||
Mem.Map(0x0280, 0x0080, PIA);
|
||||
Mem.Map(0x0480, 0x0080, PIA);
|
||||
Mem.Map(0x0580, 0x0080, PIA);
|
||||
|
||||
RAM1 = input.ReadRAM6116();
|
||||
RAM2 = input.ReadRAM6116();
|
||||
Mem.Map(0x1800, 0x0800, RAM1);
|
||||
Mem.Map(0x2000, 0x0800, RAM2);
|
||||
|
||||
Mem.Map(0x0040, 0x00c0, RAM2); // page 0 shadow
|
||||
Mem.Map(0x0140, 0x00c0, RAM2); // page 1 shadow
|
||||
Mem.Map(0x2800, 0x0800, RAM2); // shadow1
|
||||
Mem.Map(0x3000, 0x0800, RAM2); // shadow2
|
||||
Mem.Map(0x3800, 0x0800, RAM2); // shadow3
|
||||
|
||||
BIOS = input.ReadOptionalBios7800();
|
||||
HSC = input.ReadOptionalHSC7800();
|
||||
|
||||
if (HSC != null)
|
||||
{
|
||||
Mem.Map(0x1000, 0x800, HSC.SRAM);
|
||||
Mem.Map(0x3000, 0x1000, HSC);
|
||||
}
|
||||
|
||||
Cart = input.ReadCart(this);
|
||||
Mem.Map(0x4000, 0xc000, Cart);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(Mem);
|
||||
output.Write(CPU);
|
||||
output.Write(Maria);
|
||||
output.Write(PIA);
|
||||
output.Write(RAM1);
|
||||
output.Write(RAM2);
|
||||
output.WriteOptional(BIOS);
|
||||
output.WriteOptional(HSC);
|
||||
output.Write(Cart);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
[System.Diagnostics.Conditional("DEBUG")]
|
||||
void AssertDebug(bool cond)
|
||||
{
|
||||
if (!cond)
|
||||
System.Diagnostics.Debugger.Break();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class Machine7800NTSC : Machine7800
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return GetType().Name;
|
||||
}
|
||||
|
||||
public Machine7800NTSC(Cart cart, Bios7800 bios, HSC7800 hsc, ILogger logger)
|
||||
: base(cart, bios, hsc, logger, 262, 16, 60, 31440 /* NTSC_SAMPLES_PER_SEC */, MariaTables.NTSCPalette)
|
||||
{
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Machine7800NTSC(DeserializationContext input) : base(input, MariaTables.NTSCPalette, 262)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
output.WriteVersion(1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class Machine7800PAL : Machine7800
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return GetType().Name;
|
||||
}
|
||||
|
||||
public Machine7800PAL(Cart cart, Bios7800 bios, HSC7800 hsc, ILogger logger)
|
||||
: base(cart, bios, hsc, logger, 312, 34, 50, 31200 /* PAL_SAMPLES_PER_SEC */, MariaTables.PALPalette)
|
||||
{
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public Machine7800PAL(DeserializationContext input) : base(input, MariaTables.PALPalette, 312)
|
||||
{
|
||||
input.CheckVersion(1);
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationContext output)
|
||||
{
|
||||
base.GetObjectData(output);
|
||||
output.WriteVersion(1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,331 @@
|
|||
/*
|
||||
/*
|
||||
* MachineBase.cs
|
||||
*
|
||||
* Abstraction of an emulated machine.
|
||||
*
|
||||
* Copyright © 2003, 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public abstract class MachineBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
ILogger _Logger;
|
||||
FrameBuffer _FrameBuffer;
|
||||
|
||||
bool _MachineHalt;
|
||||
int _FrameHZ;
|
||||
readonly int _VisiblePitch, _Scanlines;
|
||||
|
||||
protected Cart Cart { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Properties
|
||||
|
||||
internal FrameBuffer FrameBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
AssertDebug(_FrameBuffer != null);
|
||||
return _FrameBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The machine's Central Processing Unit.
|
||||
/// </summary>
|
||||
public M6502 CPU { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The machine's Address Space.
|
||||
/// </summary>
|
||||
public AddressSpace Mem { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The machine's Peripheral Interface Adaptor device.
|
||||
/// </summary>
|
||||
public PIA PIA { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reports whether the machine has been halted due to an internal condition or error.
|
||||
/// </summary>
|
||||
public bool MachineHalt
|
||||
{
|
||||
get { return _MachineHalt; }
|
||||
internal set { if (value) _MachineHalt = true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The machine input state.
|
||||
/// </summary>
|
||||
public InputState InputState { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current frame number.
|
||||
/// </summary>
|
||||
public long FrameNumber { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The first scanline that is visible.
|
||||
/// </summary>
|
||||
public int FirstScanline { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Frame rate.
|
||||
/// </summary>
|
||||
public int FrameHZ
|
||||
{
|
||||
get { return _FrameHZ < 1 ? 1 : _FrameHZ; }
|
||||
set { _FrameHZ = value < 1 ? 1 : value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of sound samples per second.
|
||||
/// </summary>
|
||||
public int SoundSampleFrequency { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The color palette for the configured machine.
|
||||
/// </summary>
|
||||
public int[] Palette { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dumps CPU registers to the log when NOP instructions are encountered.
|
||||
/// </summary>
|
||||
public bool NOPRegisterDumping { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The configured logger sink.
|
||||
/// </summary>
|
||||
public ILogger Logger
|
||||
{
|
||||
get { return _Logger ?? (_Logger = new NullLogger()); }
|
||||
set { _Logger = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the specified machine.
|
||||
/// </summary>
|
||||
/// <param name="machineType"></param>
|
||||
/// <param name="cart"></param>
|
||||
/// <param name="bios">7800 BIOS, optional.</param>
|
||||
/// <param name="hsc">7800 High Score cart, optional.</param>
|
||||
/// <param name="p1">Left controller, optional.</param>
|
||||
/// <param name="p2">Right controller, optional.</param>
|
||||
/// <param name="logger"></param>
|
||||
/// <exception cref="ArgumentNullException">Cart must not be null.</exception>
|
||||
/// <exception cref="Emu7800Exception">Specified MachineType is unexpected.</exception>
|
||||
public static MachineBase Create(MachineType machineType, Cart cart, Bios7800 bios, HSC7800 hsc, Controller p1, Controller p2, ILogger logger)
|
||||
{
|
||||
if (cart == null)
|
||||
throw new ArgumentNullException("cart");
|
||||
|
||||
MachineBase m;
|
||||
switch (machineType)
|
||||
{
|
||||
case MachineType.A2600NTSC:
|
||||
m = new Machine2600NTSC(cart, logger);
|
||||
break;
|
||||
case MachineType.A2600PAL:
|
||||
m = new Machine2600PAL(cart, logger);
|
||||
break;
|
||||
case MachineType.A7800NTSC:
|
||||
m = new Machine7800NTSC(cart, bios, hsc, logger);
|
||||
break;
|
||||
case MachineType.A7800PAL:
|
||||
m = new Machine7800PAL(cart, bios, hsc, logger);
|
||||
break;
|
||||
default:
|
||||
throw new Emu7800Exception("Unexpected MachineType: " + machineType);
|
||||
}
|
||||
|
||||
m.InputState.LeftControllerJack = p1;
|
||||
m.InputState.RightControllerJack = p2;
|
||||
|
||||
m.Reset();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a <see cref="MachineBase"/> from the specified stream.
|
||||
/// </summary>
|
||||
/// <param name="binaryReader"/>
|
||||
/// <exception cref="ArgumentNullException"/>
|
||||
/// <exception cref="Emu7800SerializationException"/>
|
||||
public static MachineBase Deserialize(BinaryReader binaryReader)
|
||||
{
|
||||
var context = new DeserializationContext(binaryReader);
|
||||
MachineBase m;
|
||||
try
|
||||
{
|
||||
m = context.ReadMachine();
|
||||
}
|
||||
catch (Emu7800SerializationException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
// TargetInvocationException wraps exceptions that unwind an Activator.CreateInstance() frame.
|
||||
throw new Emu7800SerializationException("Serialization stream does not describe a valid machine.", ex.InnerException);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Emu7800SerializationException("Serialization stream does not describe a valid machine.", ex);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the state of the machine.
|
||||
/// </summary>
|
||||
public virtual void Reset()
|
||||
{
|
||||
Logger.WriteLine("Machine {0} reset ({1} HZ {2} scanlines)", this, FrameHZ, _Scanlines);
|
||||
FrameNumber = 0;
|
||||
_MachineHalt = false;
|
||||
InputState.ClearAllInput();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the next machine frame, updating contents of the provided <see cref="FrameBuffer"/>.
|
||||
/// </summary>
|
||||
/// <param name="frameBuffer">The framebuffer to contain the computed output.</param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="ArgumentException">frameBuffer is incompatible with machine.</exception>
|
||||
public virtual void ComputeNextFrame(FrameBuffer frameBuffer)
|
||||
{
|
||||
if (MachineHalt)
|
||||
return;
|
||||
|
||||
InputState.CaptureInputState();
|
||||
|
||||
_FrameBuffer = frameBuffer;
|
||||
FrameNumber++;
|
||||
|
||||
for (var i = 0; i < _FrameBuffer.SoundBufferElementLength; i++)
|
||||
_FrameBuffer.SoundBuffer[i].ClearAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="FrameBuffer"/> with compatible dimensions for this machine.
|
||||
/// </summary>
|
||||
public FrameBuffer CreateFrameBuffer()
|
||||
{
|
||||
var fb = new FrameBuffer(_VisiblePitch, _Scanlines);
|
||||
return fb;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize the state of the machine to the specified stream.
|
||||
/// </summary>
|
||||
/// <param name="binaryWriter"/>
|
||||
/// <exception cref="ArgumentNullException"/>
|
||||
/// <exception cref="Emu7800SerializationException"/>
|
||||
public void Serialize(BinaryWriter binaryWriter)
|
||||
{
|
||||
var context = new SerializationContext(binaryWriter);
|
||||
try
|
||||
{
|
||||
context.Write(this);
|
||||
}
|
||||
catch (Emu7800SerializationException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Emu7800SerializationException("Problem serializing specified machine.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
private MachineBase()
|
||||
{
|
||||
}
|
||||
|
||||
protected MachineBase(ILogger logger, int scanLines, int firstScanline, int fHZ, int soundSampleFreq, int[] palette, int vPitch) : this()
|
||||
{
|
||||
InputState = new InputState();
|
||||
Logger = logger;
|
||||
_Scanlines = scanLines;
|
||||
FirstScanline = firstScanline;
|
||||
FrameHZ = fHZ;
|
||||
SoundSampleFrequency = soundSampleFreq;
|
||||
Palette = palette;
|
||||
_VisiblePitch = vPitch;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
protected MachineBase(DeserializationContext input, int[] palette)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
if (palette == null)
|
||||
throw new ArgumentNullException("palette");
|
||||
if (palette.Length != 0x100)
|
||||
throw new ArgumentException("palette incorrect size, must be 256.");
|
||||
|
||||
input.CheckVersion(1);
|
||||
_MachineHalt = input.ReadBoolean();
|
||||
_FrameHZ = input.ReadInt32();
|
||||
_VisiblePitch = input.ReadInt32();
|
||||
_Scanlines = input.ReadInt32();
|
||||
FirstScanline = input.ReadInt32();
|
||||
SoundSampleFrequency = input.ReadInt32();
|
||||
NOPRegisterDumping = input.ReadBoolean();
|
||||
InputState = input.ReadInputState();
|
||||
|
||||
Palette = palette;
|
||||
Logger = null;
|
||||
}
|
||||
|
||||
public virtual void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(_MachineHalt);
|
||||
output.Write(_FrameHZ);
|
||||
output.Write(_VisiblePitch);
|
||||
output.Write(_Scanlines);
|
||||
output.Write(FirstScanline);
|
||||
output.Write(SoundSampleFrequency);
|
||||
output.Write(NOPRegisterDumping);
|
||||
output.Write(InputState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[System.Diagnostics.Conditional("DEBUG")]
|
||||
void AssertDebug(bool cond)
|
||||
{
|
||||
if (!cond)
|
||||
System.Diagnostics.Debugger.Break();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* HostInput.cs
|
||||
*
|
||||
* Copyright © 2009 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public enum MachineInput
|
||||
{
|
||||
End,
|
||||
Pause,
|
||||
Mute,
|
||||
Fire,
|
||||
Fire2,
|
||||
Left,
|
||||
Right,
|
||||
Up,
|
||||
Down,
|
||||
NumPad1, NumPad2, NumPad3,
|
||||
NumPad4, NumPad5, NumPad6,
|
||||
NumPad7, NumPad8, NumPad9,
|
||||
NumPadMult, NumPad0, NumPadHash,
|
||||
Driving0, Driving1, Driving2, Driving3,
|
||||
Reset,
|
||||
Select,
|
||||
Color,
|
||||
LeftDifficulty,
|
||||
RightDifficulty,
|
||||
SetKeyboardToPlayer1,
|
||||
SetKeyboardToPlayer2,
|
||||
SetKeyboardToPlayer3,
|
||||
SetKeyboardToPlayer4,
|
||||
PanLeft, PanRight, PanUp, PanDown,
|
||||
SaveMachine,
|
||||
TakeScreenshot,
|
||||
LeftPaddleSwap,
|
||||
GameControllerSwap,
|
||||
RightPaddleSwap,
|
||||
ShowFrameStats,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* MachineType.cs
|
||||
*
|
||||
* The set of known machines.
|
||||
*
|
||||
* Copyright © 2010 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public enum MachineType
|
||||
{
|
||||
None,
|
||||
A2600NTSC,
|
||||
A2600PAL,
|
||||
A7800NTSC,
|
||||
A7800PAL
|
||||
};
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* MariaTables.cs
|
||||
*
|
||||
* Palette tables for the Maria class.
|
||||
* All derived from Dan Boris' 7800/MAME code.
|
||||
*
|
||||
* Copyright © 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public static class MariaTables
|
||||
{
|
||||
public static readonly int[] NTSCPalette =
|
||||
{
|
||||
0x000000, 0x1c1c1c, 0x393939, 0x595959, // Grey
|
||||
0x797979, 0x929292, 0xababab, 0xbcbcbc,
|
||||
0xcdcdcd, 0xd9d9d9, 0xe6e6e6, 0xececec,
|
||||
0xf2f2f2, 0xf8f8f8, 0xffffff, 0xffffff,
|
||||
|
||||
0x391701, 0x5e2304, 0x833008, 0xa54716, // Gold
|
||||
0xc85f24, 0xe37820, 0xff911d, 0xffab1d,
|
||||
0xffc51d, 0xffce34, 0xffd84c, 0xffe651,
|
||||
0xfff456, 0xfff977, 0xffff98, 0xffff98,
|
||||
|
||||
0x451904, 0x721e11, 0x9f241e, 0xb33a20, // Orange
|
||||
0xc85122, 0xe36920, 0xff811e, 0xff8c25,
|
||||
0xff982c, 0xffae38, 0xffc545, 0xffc559,
|
||||
0xffc66d, 0xffd587, 0xffe4a1, 0xffe4a1,
|
||||
|
||||
0x4a1704, 0x7e1a0d, 0xb21d17, 0xc82119, // Red Orange
|
||||
0xdf251c, 0xec3b38, 0xfa5255, 0xfc6161,
|
||||
0xff706e, 0xff7f7e, 0xff8f8f, 0xff9d9e,
|
||||
0xffabad, 0xffb9bd, 0xffc7ce, 0xffc7ce,
|
||||
|
||||
0x050568, 0x3b136d, 0x712272, 0x8b2a8c, // Pink
|
||||
0xa532a6, 0xb938ba, 0xcd3ecf, 0xdb47dd,
|
||||
0xea51eb, 0xf45ff5, 0xfe6dff, 0xfe7afd,
|
||||
0xff87fb, 0xff95fd, 0xffa4ff, 0xffa4ff,
|
||||
|
||||
0x280479, 0x400984, 0x590f90, 0x70249d, // Purple
|
||||
0x8839aa, 0xa441c3, 0xc04adc, 0xd054ed,
|
||||
0xe05eff, 0xe96dff, 0xf27cff, 0xf88aff,
|
||||
0xff98ff, 0xfea1ff, 0xfeabff, 0xfeabff,
|
||||
|
||||
0x35088a, 0x420aad, 0x500cd0, 0x6428d0, // Purple Blue
|
||||
0x7945d0, 0x8d4bd4, 0xa251d9, 0xb058ec,
|
||||
0xbe60ff, 0xc56bff, 0xcc77ff, 0xd183ff,
|
||||
0xd790ff, 0xdb9dff, 0xdfaaff, 0xdfaaff,
|
||||
|
||||
0x051e81, 0x0626a5, 0x082fca, 0x263dd4, // Blue1
|
||||
0x444cde, 0x4f5aee, 0x5a68ff, 0x6575ff,
|
||||
0x7183ff, 0x8091ff, 0x90a0ff, 0x97a9ff,
|
||||
0x9fb2ff, 0xafbeff, 0xc0cbff, 0xc0cbff,
|
||||
|
||||
0x0c048b, 0x2218a0, 0x382db5, 0x483ec7, // Blue2
|
||||
0x584fda, 0x6159ec, 0x6b64ff, 0x7a74ff,
|
||||
0x8a84ff, 0x918eff, 0x9998ff, 0xa5a3ff,
|
||||
0xb1aeff, 0xb8b8ff, 0xc0c2ff, 0xc0c2ff,
|
||||
|
||||
0x1d295a, 0x1d3876, 0x1d4892, 0x1c5cac, // Light Blue
|
||||
0x1c71c6, 0x3286cf, 0x489bd9, 0x4ea8ec,
|
||||
0x55b6ff, 0x70c7ff, 0x8cd8ff, 0x93dbff,
|
||||
0x9bdfff, 0xafe4ff, 0xc3e9ff, 0xc3e9ff,
|
||||
|
||||
0x2f4302, 0x395202, 0x446103, 0x417a12, // Turquoise
|
||||
0x3e9421, 0x4a9f2e, 0x57ab3b, 0x5cbd55,
|
||||
0x61d070, 0x69e27a, 0x72f584, 0x7cfa8d,
|
||||
0x87ff97, 0x9affa6, 0xadffb6, 0xadffb6,
|
||||
|
||||
0x0a4108, 0x0d540a, 0x10680d, 0x137d0f, // Green Blue
|
||||
0x169212, 0x19a514, 0x1cb917, 0x1ec919,
|
||||
0x21d91b, 0x47e42d, 0x6ef040, 0x78f74d,
|
||||
0x83ff5b, 0x9aff7a, 0xb2ff9a, 0xb2ff9a,
|
||||
|
||||
0x04410b, 0x05530e, 0x066611, 0x077714, // Green
|
||||
0x088817, 0x099b1a, 0x0baf1d, 0x48c41f,
|
||||
0x86d922, 0x8fe924, 0x99f927, 0xa8fc41,
|
||||
0xb7ff5b, 0xc9ff6e, 0xdcff81, 0xdcff81,
|
||||
|
||||
0x02350f, 0x073f15, 0x0c4a1c, 0x2d5f1e, // Yellow Green
|
||||
0x4f7420, 0x598324, 0x649228, 0x82a12e,
|
||||
0xa1b034, 0xa9c13a, 0xb2d241, 0xc4d945,
|
||||
0xd6e149, 0xe4f04e, 0xf2ff53, 0xf2ff53,
|
||||
|
||||
0x263001, 0x243803, 0x234005, 0x51541b, // Orange Green
|
||||
0x806931, 0x978135, 0xaf993a, 0xc2a73e,
|
||||
0xd5b543, 0xdbc03d, 0xe1cb38, 0xe2d836,
|
||||
0xe3e534, 0xeff258, 0xfbff7d, 0xfbff7d,
|
||||
|
||||
0x401a02, 0x581f05, 0x702408, 0x8d3a13, // Light Orange
|
||||
0xab511f, 0xb56427, 0xbf7730, 0xd0853a,
|
||||
0xe19344, 0xeda04e, 0xf9ad58, 0xfcb75c,
|
||||
0xffc160, 0xffc671, 0xffcb83, 0xffcb83
|
||||
};
|
||||
|
||||
public static readonly int[] PALPalette =
|
||||
{
|
||||
0x000000, 0x1c1c1c, 0x393939, 0x595959, // Grey
|
||||
0x797979, 0x929292, 0xababab, 0xbcbcbc,
|
||||
0xcdcdcd, 0xd9d9d9, 0xe6e6e6, 0xececec,
|
||||
0xf2f2f2, 0xf8f8f8, 0xffffff, 0xffffff,
|
||||
|
||||
0x263001, 0x243803, 0x234005, 0x51541b, // Orange Green
|
||||
0x806931, 0x978135, 0xaf993a, 0xc2a73e,
|
||||
0xd5b543, 0xdbc03d, 0xe1cb38, 0xe2d836,
|
||||
0xe3e534, 0xeff258, 0xfbff7d, 0xfbff7d,
|
||||
|
||||
0x263001, 0x243803, 0x234005, 0x51541b, // Orange Green
|
||||
0x806931, 0x978135, 0xaf993a, 0xc2a73e,
|
||||
0xd5b543, 0xdbc03d, 0xe1cb38, 0xe2d836,
|
||||
0xe3e534, 0xeff258, 0xfbff7d, 0xfbff7d,
|
||||
|
||||
0x401a02, 0x581f05, 0x702408, 0x8d3a13, // Light Orange
|
||||
0xab511f, 0xb56427, 0xbf7730, 0xd0853a,
|
||||
0xe19344, 0xeda04e, 0xf9ad58, 0xfcb75c,
|
||||
0xffc160, 0xffc671, 0xffcb83, 0xffcb83,
|
||||
|
||||
0x391701, 0x5e2304, 0x833008, 0xa54716, // Gold
|
||||
0xc85f24, 0xe37820, 0xff911d, 0xffab1d,
|
||||
0xffc51d, 0xffce34, 0xffd84c, 0xffe651,
|
||||
0xfff456, 0xfff977, 0xffff98, 0xffff98,
|
||||
|
||||
0x451904, 0x721e11, 0x9f241e, 0xb33a20, // Orange
|
||||
0xc85122, 0xe36920, 0xff811e, 0xff8c25,
|
||||
0xff982c, 0xffae38, 0xffc545, 0xffc559,
|
||||
0xffc66d, 0xffd587, 0xffe4a1, 0xffe4a1,
|
||||
|
||||
0x4a1704, 0x7e1a0d, 0xb21d17, 0xc82119, // Red Orange
|
||||
0xdf251c, 0xec3b38, 0xfa5255, 0xfc6161,
|
||||
0xff706e, 0xff7f7e, 0xff8f8f, 0xff9d9e,
|
||||
0xffabad, 0xffb9bd, 0xffc7ce, 0xffc7ce,
|
||||
|
||||
0x050568, 0x3b136d, 0x712272, 0x8b2a8c, // Pink
|
||||
0xa532a6, 0xb938ba, 0xcd3ecf, 0xdb47dd,
|
||||
0xea51eb, 0xf45ff5, 0xfe6dff, 0xfe7afd,
|
||||
0xff87fb, 0xff95fd, 0xffa4ff, 0xffa4ff,
|
||||
|
||||
0x280479, 0x400984, 0x590f90, 0x70249d, // Purple
|
||||
0x8839aa, 0xa441c3, 0xc04adc, 0xd054ed,
|
||||
0xe05eff, 0xe96dff, 0xf27cff, 0xf88aff,
|
||||
0xff98ff, 0xfea1ff, 0xfeabff, 0xfeabff,
|
||||
|
||||
0x051e81, 0x0626a5, 0x082fca, 0x263dd4, // Blue1
|
||||
0x444cde, 0x4f5aee, 0x5a68ff, 0x6575ff,
|
||||
0x7183ff, 0x8091ff, 0x90a0ff, 0x97a9ff,
|
||||
0x9fb2ff, 0xafbeff, 0xc0cbff, 0xc0cbff,
|
||||
|
||||
0x0c048b, 0x2218a0, 0x382db5, 0x483ec7, // Blue2
|
||||
0x584fda, 0x6159ec, 0x6b64ff, 0x7a74ff,
|
||||
0x8a84ff, 0x918eff, 0x9998ff, 0xa5a3ff,
|
||||
0xb1aeff, 0xb8b8ff, 0xc0c2ff, 0xc0c2ff,
|
||||
|
||||
0x1d295a, 0x1d3876, 0x1d4892, 0x1c5cac, // Light Blue
|
||||
0x1c71c6, 0x3286cf, 0x489bd9, 0x4ea8ec,
|
||||
0x55b6ff, 0x70c7ff, 0x8cd8ff, 0x93dbff,
|
||||
0x9bdfff, 0xafe4ff, 0xc3e9ff, 0xc3e9ff,
|
||||
|
||||
0x2f4302, 0x395202, 0x446103, 0x417a12, // Turquoise
|
||||
0x3e9421, 0x4a9f2e, 0x57ab3b, 0x5cbd55,
|
||||
0x61d070, 0x69e27a, 0x72f584, 0x7cfa8d,
|
||||
0x87ff97, 0x9affa6, 0xadffb6, 0xadffb6,
|
||||
|
||||
0x0a4108, 0x0d540a, 0x10680d, 0x137d0f, // Green Blue
|
||||
0x169212, 0x19a514, 0x1cb917, 0x1ec919,
|
||||
0x21d91b, 0x47e42d, 0x6ef040, 0x78f74d,
|
||||
0x83ff5b, 0x9aff7a, 0xb2ff9a, 0xb2ff9a,
|
||||
|
||||
0x04410b, 0x05530e, 0x066611, 0x077714, // Green
|
||||
0x088817, 0x099b1a, 0x0baf1d, 0x48c41f,
|
||||
0x86d922, 0x8fe924, 0x99f927, 0xa8fc41,
|
||||
0xb7ff5b, 0xc9ff6e, 0xdcff81, 0xdcff81,
|
||||
|
||||
0x02350f, 0x073f15, 0x0c4a1c, 0x2d5f1e, // Yellow Green
|
||||
0x4f7420, 0x598324, 0x649228, 0x82a12e,
|
||||
0xa1b034, 0xa9c13a, 0xb2d241, 0xc4d945,
|
||||
0xd6e149, 0xe4f04e, 0xf2ff53, 0xf2ff53
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* NullDevice.cs
|
||||
*
|
||||
* Default memory mappable device.
|
||||
*
|
||||
* Copyright © 2003, 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class NullDevice : IDevice
|
||||
{
|
||||
MachineBase M { get; set; }
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Log("{0} reset", this);
|
||||
}
|
||||
|
||||
public byte this[ushort addr]
|
||||
{
|
||||
get
|
||||
{
|
||||
LogDebug("NullDevice: Peek at ${0:x4}, PC=${1:x4}", addr, M.CPU.PC);
|
||||
return 0;
|
||||
}
|
||||
set
|
||||
{
|
||||
LogDebug("NullDevice: Poke at ${0:x4},${1:x2}, PC=${2:x4}", addr, value, M.CPU.PC);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return "NullDevice";
|
||||
}
|
||||
|
||||
#region Constructors
|
||||
|
||||
private NullDevice()
|
||||
{
|
||||
}
|
||||
|
||||
public NullDevice(MachineBase m)
|
||||
{
|
||||
if (m == null)
|
||||
throw new ArgumentNullException("m");
|
||||
M = m;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
void Log(string format, params object[] args)
|
||||
{
|
||||
if (M == null || M.Logger == null)
|
||||
return;
|
||||
M.Logger.WriteLine(format, args);
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("DEBUG")]
|
||||
void LogDebug(string format, params object[] args)
|
||||
{
|
||||
if (M == null || M.Logger == null)
|
||||
return;
|
||||
M.Logger.WriteLine(format, args);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
namespace EMU7800.Core
|
||||
{
|
||||
public class NullLogger : ILogger
|
||||
{
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void WriteLine(object value)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(string format, params object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(object value)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
* PIA.cs
|
||||
*
|
||||
* The Peripheral Interface Adapter (6532) device.
|
||||
* a.k.a. RIOT (RAM I/O Timer?)
|
||||
*
|
||||
* Copyright © 2003, 2004, 2012 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class PIA : IDevice
|
||||
{
|
||||
readonly MachineBase M;
|
||||
|
||||
readonly byte[] RAM = new byte[0x80];
|
||||
|
||||
ulong TimerTarget;
|
||||
int TimerShift;
|
||||
bool IRQEnabled, IRQTriggered;
|
||||
|
||||
public byte DDRA { get; private set; }
|
||||
public byte DDRB { get; private set; }
|
||||
|
||||
public byte WrittenPortA { get; private set; }
|
||||
public byte WrittenPortB { get; private set; }
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
// Some games will loop/hang on $0284 if these are initialized to zero
|
||||
TimerShift = 10;
|
||||
TimerTarget = M.CPU.Clock + (ulong)(0xff << TimerShift);
|
||||
|
||||
IRQEnabled = false;
|
||||
IRQTriggered = false;
|
||||
|
||||
DDRA = 0;
|
||||
|
||||
Log("{0} reset", this);
|
||||
}
|
||||
|
||||
public byte this[ushort addr]
|
||||
{
|
||||
get { return peek(addr); }
|
||||
set { poke(addr, value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "PIA/RIOT M6532";
|
||||
}
|
||||
|
||||
#region Constructors
|
||||
|
||||
private PIA()
|
||||
{
|
||||
}
|
||||
|
||||
public PIA(MachineBase m)
|
||||
{
|
||||
if (m == null)
|
||||
throw new ArgumentNullException("m");
|
||||
M = m;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
byte peek(ushort addr)
|
||||
{
|
||||
if ((addr & 0x200) == 0)
|
||||
{
|
||||
return RAM[addr & 0x7f];
|
||||
}
|
||||
|
||||
switch ((byte)(addr & 7))
|
||||
{
|
||||
case 0: // SWCHA: Controllers
|
||||
return ReadPortA();
|
||||
case 1: // SWCHA DDR: 0=input, 1=output
|
||||
return DDRA;
|
||||
case 2: // SWCHB: Console switches (on 7800, PB2 & PB4 are used)
|
||||
return ReadPortB();
|
||||
case 3: // SWCHB DDR: 0=input, 1=output
|
||||
return 0;
|
||||
case 4: // INTIM
|
||||
case 6:
|
||||
return ReadTimerRegister();
|
||||
case 5: // INTFLG
|
||||
case 7:
|
||||
return ReadInterruptFlag();
|
||||
default:
|
||||
LogDebug("PIA: Unhandled peek ${0:x4}, PC=${1:x4}", addr, M.CPU.PC);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void poke(ushort addr, byte data)
|
||||
{
|
||||
if ((addr & 0x200) == 0)
|
||||
{
|
||||
RAM[addr & 0x7f] = data;
|
||||
return;
|
||||
}
|
||||
|
||||
// A2 Distinguishes I/O registers from the Timer
|
||||
if ((addr & 0x04) != 0)
|
||||
{
|
||||
if ((addr & 0x10) != 0)
|
||||
{
|
||||
IRQEnabled = (addr & 0x08) != 0;
|
||||
SetTimerRegister(data, addr & 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDebug("PIA: Timer: Unhandled poke ${0:x4} w/${1:x2}, PC=${2:x4}", addr, data, M.CPU.PC);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ((byte)(addr & 3))
|
||||
{
|
||||
case 0: // SWCHA: Port A
|
||||
WritePortA(data);
|
||||
break;
|
||||
case 1: // SWACNT: Port A DDR
|
||||
DDRA = data;
|
||||
break;
|
||||
case 2: // SWCHB: Port B
|
||||
WritePortB(data);
|
||||
break;
|
||||
case 3: // SWBCNT: Port B DDR
|
||||
DDRB = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0: TIM1T: set 1 clock interval ( 838 nsec/interval)
|
||||
// 1: TIM8T: set 8 clock interval ( 6.7 usec/interval)
|
||||
// 2: TIM64T: set 64 clock interval ( 53.6 usec/interval)
|
||||
// 3: T1024T: set 1024 clock interval (858.2 usec/interval)
|
||||
void SetTimerRegister(byte data, int interval)
|
||||
{
|
||||
IRQTriggered = false;
|
||||
TimerShift = new[] { 0, 3, 6, 10 }[interval];
|
||||
TimerTarget = M.CPU.Clock + (ulong)(data << TimerShift);
|
||||
}
|
||||
|
||||
byte ReadTimerRegister()
|
||||
{
|
||||
IRQTriggered = false;
|
||||
var delta = (int)(TimerTarget - M.CPU.Clock);
|
||||
if (delta >= 0)
|
||||
{
|
||||
return (byte)(delta >> TimerShift);
|
||||
}
|
||||
if (delta != -1)
|
||||
{
|
||||
IRQTriggered = true;
|
||||
}
|
||||
return (byte)(delta >= -256 ? delta : 0);
|
||||
}
|
||||
|
||||
byte ReadInterruptFlag()
|
||||
{
|
||||
var delta = (int)(TimerTarget - M.CPU.Clock);
|
||||
return (byte)((delta >= 0 || IRQEnabled && IRQTriggered) ? 0x00 : 0x80);
|
||||
}
|
||||
|
||||
// PortA: Controller Jacks
|
||||
//
|
||||
// Left Jack Right Jack
|
||||
// ------------- -------------
|
||||
// \ 1 2 3 4 5 / \ 1 2 3 4 5 /
|
||||
// \ 6 7 8 9 / \ 6 7 8 9 /
|
||||
// --------- ---------
|
||||
//
|
||||
// pin 1 D4 PIA SWCHA D0 PIA SWCHA
|
||||
// pin 2 D5 PIA SWCHA D1 PIA SWCHA
|
||||
// pin 3 D6 PIA SWCHA D2 PIA SWCHA
|
||||
// pin 4 D7 PIA SWCHA D3 PIA SWCHA
|
||||
// pin 5 D7 TIA INPT1 (Dumped) D7 TIA INPT3 (Dumped) 7800: Right Fire
|
||||
// pin 6 D7 TIA INPT4 (Latched) D7 TIA INPT5 (Latched) 2600: Fire
|
||||
// pin 7 +5 +5
|
||||
// pin 8 GND GND
|
||||
// pin 9 D7 TIA INPT0 (Dumped) D7 TIA INPT2 (Dumped) 7800: Left Fire
|
||||
//
|
||||
byte ReadPortA()
|
||||
{
|
||||
var porta = 0;
|
||||
var mi = M.InputState;
|
||||
|
||||
switch (mi.LeftControllerJack)
|
||||
{
|
||||
case Controller.Joystick:
|
||||
case Controller.ProLineJoystick:
|
||||
case Controller.BoosterGrip:
|
||||
porta |= mi.SampleCapturedControllerActionState(0, ControllerAction.Up) ? 0 : (1 << 4);
|
||||
porta |= mi.SampleCapturedControllerActionState(0, ControllerAction.Down) ? 0 : (1 << 5);
|
||||
porta |= mi.SampleCapturedControllerActionState(0, ControllerAction.Left) ? 0 : (1 << 6);
|
||||
porta |= mi.SampleCapturedControllerActionState(0, ControllerAction.Right) ? 0 : (1 << 7);
|
||||
break;
|
||||
case Controller.Driving:
|
||||
porta |= mi.SampleCapturedDrivingState(0) << 4;
|
||||
break;
|
||||
case Controller.Paddles:
|
||||
porta |= mi.SampleCapturedControllerActionState(0, ControllerAction.Trigger) ? 0 : (1 << 7);
|
||||
porta |= mi.SampleCapturedControllerActionState(1, ControllerAction.Trigger) ? 0 : (1 << 6);
|
||||
break;
|
||||
case Controller.Lightgun:
|
||||
porta |= mi.SampleCapturedControllerActionState(0, ControllerAction.Trigger) ? (1 << 4) : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (mi.RightControllerJack)
|
||||
{
|
||||
case Controller.Joystick:
|
||||
case Controller.ProLineJoystick:
|
||||
case Controller.BoosterGrip:
|
||||
porta |= mi.SampleCapturedControllerActionState(1, ControllerAction.Up) ? 0 : (1 << 0);
|
||||
porta |= mi.SampleCapturedControllerActionState(1, ControllerAction.Down) ? 0 : (1 << 1);
|
||||
porta |= mi.SampleCapturedControllerActionState(1, ControllerAction.Left) ? 0 : (1 << 2);
|
||||
porta |= mi.SampleCapturedControllerActionState(1, ControllerAction.Right) ? 0 : (1 << 3);
|
||||
break;
|
||||
case Controller.Driving:
|
||||
porta |= mi.SampleCapturedDrivingState(1);
|
||||
break;
|
||||
case Controller.Paddles:
|
||||
porta |= mi.SampleCapturedControllerActionState(2, ControllerAction.Trigger) ? 0 : (1 << 3);
|
||||
porta |= mi.SampleCapturedControllerActionState(3, ControllerAction.Trigger) ? 0 : (1 << 2);
|
||||
break;
|
||||
case Controller.Lightgun:
|
||||
porta |= mi.SampleCapturedControllerActionState(1, ControllerAction.Trigger) ? (1 << 0) : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return (byte)porta;
|
||||
}
|
||||
|
||||
void WritePortA(byte porta)
|
||||
{
|
||||
WrittenPortA = (byte)((porta & DDRA) | (WrittenPortA & (~DDRA)));
|
||||
}
|
||||
|
||||
void WritePortB(byte portb)
|
||||
{
|
||||
WrittenPortB = (byte)((portb & DDRB) | (WrittenPortB & (~DDRB)));
|
||||
}
|
||||
|
||||
// PortB: Console Switches
|
||||
//
|
||||
// D0 Game Reset 0=on
|
||||
// D1 Game Select 0=on
|
||||
// D2 (used on 7800)
|
||||
// D3 Console Color 1=Color, 0=B/W
|
||||
// D4 (used on 7800)
|
||||
// D5 (unused)
|
||||
// D6 Left Difficulty A 1=A (pro), 0=B (novice)
|
||||
// D7 Right Difficulty A 1=A (pro), 0=B (novice)
|
||||
//
|
||||
byte ReadPortB()
|
||||
{
|
||||
var portb = 0;
|
||||
var mi = M.InputState;
|
||||
|
||||
portb |= mi.SampleCapturedConsoleSwitchState(ConsoleSwitch.GameReset) ? 0 : (1 << 0);
|
||||
portb |= mi.SampleCapturedConsoleSwitchState(ConsoleSwitch.GameSelect) ? 0 : (1 << 1);
|
||||
portb |= mi.SampleCapturedConsoleSwitchState(ConsoleSwitch.GameBW) ? 0 : (1 << 3);
|
||||
portb |= mi.SampleCapturedConsoleSwitchState(ConsoleSwitch.LeftDifficultyA) ? (1 << 6) : 0;
|
||||
portb |= mi.SampleCapturedConsoleSwitchState(ConsoleSwitch.RightDifficultyA) ? (1 << 7) : 0;
|
||||
|
||||
return (byte)portb;
|
||||
}
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public PIA(DeserializationContext input, MachineBase m) : this(m)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
var version = input.CheckVersion(1, 2);
|
||||
RAM = input.ReadExpectedBytes(0x80);
|
||||
TimerTarget = input.ReadUInt64();
|
||||
TimerShift = input.ReadInt32();
|
||||
IRQEnabled = input.ReadBoolean();
|
||||
IRQTriggered = input.ReadBoolean();
|
||||
DDRA = input.ReadByte();
|
||||
WrittenPortA = input.ReadByte();
|
||||
if (version > 1)
|
||||
{
|
||||
DDRB = input.ReadByte();
|
||||
WrittenPortB = input.ReadByte();
|
||||
}
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(2);
|
||||
output.Write(RAM);
|
||||
output.Write(TimerTarget);
|
||||
output.Write(TimerShift);
|
||||
output.Write(IRQEnabled);
|
||||
output.Write(IRQTriggered);
|
||||
output.Write(DDRA);
|
||||
output.Write(WrittenPortA);
|
||||
output.Write(DDRB);
|
||||
output.Write(WrittenPortB);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
void Log(string format, params object[] args)
|
||||
{
|
||||
if (M == null || M.Logger == null)
|
||||
return;
|
||||
M.Logger.WriteLine(format, args);
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("DEBUG")]
|
||||
void LogDebug(string format, params object[] args)
|
||||
{
|
||||
if (M == null || M.Logger == null)
|
||||
return;
|
||||
M.Logger.WriteLine(format, args);
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("DEBUG")]
|
||||
void AssertDebug(bool cond)
|
||||
{
|
||||
if (!cond)
|
||||
System.Diagnostics.Debugger.Break();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,437 @@
|
|||
/*
|
||||
* PokeySound.cs
|
||||
*
|
||||
* Emulation of the audio features of the Atari Pot Keyboard Integrated Circuit (POKEY, C012294).
|
||||
*
|
||||
* Implementation inspired by prior works of Greg Stanton (ProSystem Emulator) and Ron Fries.
|
||||
*
|
||||
* Copyright © 2012 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class PokeySound
|
||||
{
|
||||
#region Constants and Tables
|
||||
|
||||
const int
|
||||
AUDF1 = 0x00, // write reg: channel 1 frequency
|
||||
AUDC1 = 0x01, // write reg: channel 1 generator
|
||||
AUDF2 = 0x02, // write reg: channel 2 frequency
|
||||
AUDC2 = 0x03, // write reg: channel 2 generator
|
||||
AUDF3 = 0x04, // write reg: channel 3 frequency
|
||||
AUDC3 = 0x05, // write reg: channel 3 generator
|
||||
AUDF4 = 0x06, // write reg: channel 4 frequency
|
||||
AUDC4 = 0x07, // write reg: channel 4 generator
|
||||
AUDCTL = 0x08, // write reg: control over audio channels
|
||||
SKCTL = 0x0f, // write reg: control over serial port
|
||||
RANDOM = 0x0a; // read reg: random number generator value
|
||||
|
||||
const int
|
||||
AUDCTL_POLY9 = 0x80, // make 17-bit poly counter into a 9-bit poly counter
|
||||
AUDCTL_CH1_179 = 0x40, // clocks channel 1 with 1.79 MHz, instead of 64 kHz
|
||||
AUDCTL_CH3_179 = 0x20, // clocks channel 3 with 1.79 MHz, instead of 64 kHz
|
||||
AUDCTL_CH1_CH2 = 0x10, // clock channel 2 with channel 1, instead of 64 kHz (16-bit)
|
||||
AUDCTL_CH3_CH4 = 0x08, // clock channel 4 with channel 3, instead of 64 kHz (16-bit)
|
||||
AUDCTL_CH1_FILTER = 0x04, // inserts high-pass filter into channel 1, clocked by channel 3
|
||||
AUDCTL_CH2_FILTER = 0x02, // inserts high-pass filter into channel 2, clocked by channel 4
|
||||
AUDCTL_CLOCK_15 = 0x01; // change normal clock base from 64 kHz to 15 kHz
|
||||
|
||||
const int
|
||||
AUDC_NOTPOLY5 = 0x80,
|
||||
AUDC_POLY4 = 0x40,
|
||||
AUDC_PURE = 0x20,
|
||||
AUDC_VOLUME_ONLY = 0x10,
|
||||
AUDC_VOLUME_MASK = 0x0f;
|
||||
|
||||
const int
|
||||
DIV_64 = 28,
|
||||
DIV_15 = 114,
|
||||
POLY9_SIZE = 0x01ff,
|
||||
POLY17_SIZE = 0x0001ffff,
|
||||
POKEY_FREQ = 1787520,
|
||||
SKCTL_RESET = 3;
|
||||
|
||||
const int CPU_TICKS_PER_AUDIO_SAMPLE = 57;
|
||||
|
||||
readonly byte[] _poly04 = { 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0 };
|
||||
readonly byte[] _poly05 = { 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1 };
|
||||
readonly byte[] _poly17 = new byte[POLY9_SIZE]; // should be POLY17_SIZE, but instead wrapping around to conserve storage
|
||||
|
||||
readonly Random _random = new Random();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Object State
|
||||
|
||||
readonly MachineBase M;
|
||||
|
||||
readonly int _pokeyTicksPerSample;
|
||||
int _pokeyTicks;
|
||||
|
||||
ulong _lastUpdateCpuClock;
|
||||
int _bufferIndex;
|
||||
|
||||
readonly byte[] _audf = new byte[4];
|
||||
readonly byte[] _audc = new byte[4];
|
||||
byte _audctl, _skctl;
|
||||
|
||||
int _baseMultiplier;
|
||||
int _poly04Counter;
|
||||
int _poly05Counter;
|
||||
int _poly17Counter, _poly17Size;
|
||||
|
||||
readonly int[] _divideMax = new int[4];
|
||||
readonly int[] _divideCount = new int[4];
|
||||
readonly byte[] _output = new byte[4];
|
||||
readonly byte[] _outvol = new byte[4];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_poly04Counter = _poly05Counter = _poly17Counter = _audctl = _skctl = 0;
|
||||
|
||||
_baseMultiplier = DIV_64;
|
||||
_poly17Size = POLY17_SIZE;
|
||||
|
||||
_pokeyTicks = 0;
|
||||
|
||||
for (var ch = 0; ch < 4; ch++)
|
||||
{
|
||||
_outvol[ch] = _output[ch] = _audc[ch] = _audf[ch] = 0;
|
||||
_divideCount[ch] = Int32.MaxValue;
|
||||
_divideMax[ch] = Int32.MaxValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void StartFrame()
|
||||
{
|
||||
_lastUpdateCpuClock = M.CPU.Clock;
|
||||
_bufferIndex = 0;
|
||||
}
|
||||
|
||||
public void EndFrame()
|
||||
{
|
||||
RenderSamples(M.FrameBuffer.SoundBufferByteLength - _bufferIndex);
|
||||
}
|
||||
|
||||
public byte Read(ushort addr)
|
||||
{
|
||||
addr &= 0xf;
|
||||
|
||||
switch (addr)
|
||||
{
|
||||
// If the 2 least significant bits of SKCTL are 0, the random number generator is disabled (return all 1s.)
|
||||
// Ballblazer music relies on this.
|
||||
case RANDOM:
|
||||
return (_skctl & SKCTL_RESET) == 0 ? (byte)0xff : (byte)_random.Next(0xff);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(ushort addr, byte data)
|
||||
{
|
||||
if (M.CPU.Clock > _lastUpdateCpuClock)
|
||||
{
|
||||
var updCpuClocks = (int)(M.CPU.Clock - _lastUpdateCpuClock);
|
||||
var samples = updCpuClocks / CPU_TICKS_PER_AUDIO_SAMPLE;
|
||||
RenderSamples(samples);
|
||||
_lastUpdateCpuClock += (ulong)(samples * CPU_TICKS_PER_AUDIO_SAMPLE);
|
||||
}
|
||||
|
||||
addr &= 0xf;
|
||||
|
||||
switch (addr)
|
||||
{
|
||||
case AUDF1:
|
||||
_audf[0] = data;
|
||||
ResetChannel1();
|
||||
if ((_audctl & AUDCTL_CH1_CH2) != 0)
|
||||
ResetChannel2();
|
||||
break;
|
||||
case AUDC1:
|
||||
_audc[0] = data;
|
||||
ResetChannel1();
|
||||
break;
|
||||
case AUDF2:
|
||||
_audf[1] = data;
|
||||
ResetChannel2();
|
||||
break;
|
||||
case AUDC2:
|
||||
_audc[1] = data;
|
||||
ResetChannel2();
|
||||
break;
|
||||
case AUDF3:
|
||||
_audf[2] = data;
|
||||
ResetChannel3();
|
||||
if ((_audctl & AUDCTL_CH3_CH4) != 0)
|
||||
ResetChannel4();
|
||||
break;
|
||||
case AUDC3:
|
||||
_audc[2] = data;
|
||||
ResetChannel3();
|
||||
break;
|
||||
case AUDF4:
|
||||
_audf[3] = data;
|
||||
ResetChannel4();
|
||||
break;
|
||||
case AUDC4:
|
||||
_audc[3] = data;
|
||||
ResetChannel4();
|
||||
break;
|
||||
case AUDCTL:
|
||||
_audctl = data;
|
||||
_poly17Size = ((_audctl & AUDCTL_POLY9) != 0) ? POLY9_SIZE : POLY17_SIZE;
|
||||
_baseMultiplier = ((_audctl & AUDCTL_CLOCK_15) != 0) ? DIV_15 : DIV_64;
|
||||
ResetChannel1();
|
||||
ResetChannel2();
|
||||
ResetChannel3();
|
||||
ResetChannel4();
|
||||
break;
|
||||
case SKCTL:
|
||||
_skctl = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
private PokeySound()
|
||||
{
|
||||
_random.NextBytes(_poly17);
|
||||
for (var i = 0; i < _poly17.Length; i++)
|
||||
_poly17[i] &= 0x01;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
public PokeySound(MachineBase m) : this()
|
||||
{
|
||||
if (m == null)
|
||||
throw new ArgumentNullException("m");
|
||||
|
||||
M = m;
|
||||
|
||||
// Add 8-bits of fractional representation to reduce distortion on output
|
||||
_pokeyTicksPerSample = (POKEY_FREQ << 8) / M.SoundSampleFrequency;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public PokeySound(DeserializationContext input, MachineBase m) : this(m)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
_lastUpdateCpuClock = input.ReadUInt64();
|
||||
_bufferIndex = input.ReadInt32();
|
||||
_audf = input.ReadBytes();
|
||||
_audc = input.ReadBytes();
|
||||
_audctl = input.ReadByte();
|
||||
_skctl = input.ReadByte();
|
||||
_output = input.ReadBytes();
|
||||
_outvol = input.ReadBytes();
|
||||
_divideMax = input.ReadIntegers(4);
|
||||
_divideCount = input.ReadIntegers(4);
|
||||
_pokeyTicks = input.ReadInt32();
|
||||
_pokeyTicksPerSample = input.ReadInt32();
|
||||
_baseMultiplier = input.ReadInt32();
|
||||
_poly04Counter = input.ReadInt32();
|
||||
_poly05Counter = input.ReadInt32();
|
||||
_poly17Counter = input.ReadInt32();
|
||||
_poly17Size = input.ReadInt32();
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(_lastUpdateCpuClock);
|
||||
output.Write(_bufferIndex);
|
||||
output.Write(_audf);
|
||||
output.Write(_audc);
|
||||
output.Write(_audctl);
|
||||
output.Write(_skctl);
|
||||
output.Write(_output);
|
||||
output.Write(_outvol);
|
||||
output.Write(_divideMax);
|
||||
output.Write(_divideCount);
|
||||
output.Write(_pokeyTicks);
|
||||
output.Write(_pokeyTicksPerSample);
|
||||
output.Write(_baseMultiplier);
|
||||
output.Write(_poly04Counter);
|
||||
output.Write(_poly05Counter);
|
||||
output.Write(_poly17Counter);
|
||||
output.Write(_poly17Size);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
void RenderSamples(int count)
|
||||
{
|
||||
const int POKEY_SAMPLE = 4;
|
||||
var poly17Length = (_poly17Size > _poly17.Length ? _poly17.Length : _poly17Size);
|
||||
|
||||
while (count > 0 && _bufferIndex < M.FrameBuffer.SoundBufferByteLength)
|
||||
{
|
||||
var nextEvent = POKEY_SAMPLE;
|
||||
var wholeTicksToConsume = (_pokeyTicks >> 8);
|
||||
|
||||
for (var ch = 0; ch < 4; ch++)
|
||||
{
|
||||
if (_divideCount[ch] <= wholeTicksToConsume)
|
||||
{
|
||||
wholeTicksToConsume = _divideCount[ch];
|
||||
nextEvent = ch;
|
||||
}
|
||||
}
|
||||
|
||||
for (var ch = 0; ch < 4; ch++)
|
||||
_divideCount[ch] -= wholeTicksToConsume;
|
||||
|
||||
_pokeyTicks -= (wholeTicksToConsume << 8);
|
||||
|
||||
if (nextEvent == POKEY_SAMPLE)
|
||||
{
|
||||
_pokeyTicks += _pokeyTicksPerSample;
|
||||
|
||||
byte sample = 0;
|
||||
for (var ch = 0; ch < 4; ch++)
|
||||
sample += _outvol[ch];
|
||||
|
||||
M.FrameBuffer.SoundBuffer[_bufferIndex >> BufferElement.SHIFT][_bufferIndex++] += sample;
|
||||
count--;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
_divideCount[nextEvent] += _divideMax[nextEvent];
|
||||
|
||||
_poly04Counter += wholeTicksToConsume;
|
||||
_poly04Counter %= _poly04.Length;
|
||||
|
||||
_poly05Counter += wholeTicksToConsume;
|
||||
_poly05Counter %= _poly05.Length;
|
||||
|
||||
_poly17Counter += wholeTicksToConsume;
|
||||
_poly17Counter %= poly17Length;
|
||||
|
||||
if ((_audc[nextEvent] & AUDC_NOTPOLY5) != 0 || _poly05[_poly05Counter] != 0)
|
||||
{
|
||||
if ((_audc[nextEvent] & AUDC_PURE) != 0)
|
||||
_output[nextEvent] ^= 1;
|
||||
else if ((_audc[nextEvent] & AUDC_POLY4) != 0)
|
||||
_output[nextEvent] = _poly04[_poly04Counter];
|
||||
else
|
||||
_output[nextEvent] = _poly17[_poly17Counter];
|
||||
}
|
||||
|
||||
_outvol[nextEvent] = (_output[nextEvent] != 0) ? (byte)(_audc[nextEvent] & AUDC_VOLUME_MASK) : (byte)0;
|
||||
}
|
||||
}
|
||||
|
||||
// As defined in the manual, the exact divider values are different depending on the frequency and resolution:
|
||||
// 64 kHz or 15 kHz AUDF + 1
|
||||
// 1 MHz, 8-bit AUDF + 4
|
||||
// 1 MHz, 16-bit AUDF[CHAN1] + 256 * AUDF[CHAN2] + 7
|
||||
|
||||
void ResetChannel1()
|
||||
{
|
||||
var val = ((_audctl & AUDCTL_CH1_179) != 0) ? (_audf[0] + 4) : ((_audf[0] + 1) * _baseMultiplier);
|
||||
if (val != _divideMax[0])
|
||||
{
|
||||
_divideMax[0] = val;
|
||||
if (val < _divideCount[0])
|
||||
_divideCount[0] = val;
|
||||
}
|
||||
UpdateVolumeSettingsForChannel(0);
|
||||
}
|
||||
|
||||
void ResetChannel2()
|
||||
{
|
||||
int val;
|
||||
if ((_audctl & AUDCTL_CH1_CH2) != 0)
|
||||
{
|
||||
val = ((_audctl & AUDCTL_CH1_179) != 0) ? (_audf[1] * 256 + _audf[0] + 7) : ((_audf[1] * 256 + _audf[0] + 1) * _baseMultiplier);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = ((_audf[1] + 1) * _baseMultiplier);
|
||||
}
|
||||
if (val != _divideMax[1])
|
||||
{
|
||||
_divideMax[1] = val;
|
||||
if (val < _divideCount[1])
|
||||
_divideCount[1] = val;
|
||||
}
|
||||
UpdateVolumeSettingsForChannel(1);
|
||||
}
|
||||
|
||||
void ResetChannel3()
|
||||
{
|
||||
var val = ((_audctl & AUDCTL_CH3_179) != 0) ? (_audf[2] + 4) : ((_audf[2] + 1) * _baseMultiplier);
|
||||
if (val != _divideMax[2])
|
||||
{
|
||||
_divideMax[2] = val;
|
||||
if (val < _divideCount[2])
|
||||
_divideCount[2] = val;
|
||||
}
|
||||
UpdateVolumeSettingsForChannel(2);
|
||||
}
|
||||
|
||||
void ResetChannel4()
|
||||
{
|
||||
int val;
|
||||
if ((_audctl & AUDCTL_CH3_CH4) != 0)
|
||||
{
|
||||
val = ((_audctl & AUDCTL_CH3_179) != 0) ? (_audf[3] * 256 + _audf[2] + 7) : ((_audf[3] * 256 + _audf[2] + 1) * _baseMultiplier);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = ((_audf[3] + 1) * _baseMultiplier);
|
||||
}
|
||||
if (val != _divideMax[3])
|
||||
{
|
||||
_divideMax[3] = val;
|
||||
if (val < _divideCount[3])
|
||||
_divideCount[3] = val;
|
||||
}
|
||||
UpdateVolumeSettingsForChannel(3);
|
||||
}
|
||||
|
||||
void UpdateVolumeSettingsForChannel(int ch)
|
||||
{
|
||||
if (((_audc[ch] & AUDC_VOLUME_ONLY) != 0) || ((_audc[ch] & AUDC_VOLUME_MASK) == 0) || (_divideMax[ch] < (_pokeyTicksPerSample >> 8)))
|
||||
{
|
||||
_outvol[ch] = (byte)(_audc[ch] & AUDC_VOLUME_MASK);
|
||||
_divideCount[ch] = Int32.MaxValue;
|
||||
_divideMax[ch] = Int32.MaxValue;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("DEBUG")]
|
||||
void LogDebug(string format, params object[] args)
|
||||
{
|
||||
if (M == null || M.Logger == null)
|
||||
return;
|
||||
M.Logger.WriteLine(format, args);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* RAM6116.cs
|
||||
*
|
||||
* Implements a 6116 RAM device found in the 7800.
|
||||
*
|
||||
* Copyright © 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class RAM6116 : IDevice
|
||||
{
|
||||
readonly byte[] RAM;
|
||||
|
||||
#region IDevice Members
|
||||
|
||||
public void Reset() {}
|
||||
|
||||
public byte this[ushort addr]
|
||||
{
|
||||
get { return RAM[addr & 0x07ff]; }
|
||||
set { RAM[addr & 0x07ff] = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public RAM6116()
|
||||
{
|
||||
RAM = new byte[0x800];
|
||||
}
|
||||
|
||||
public RAM6116(byte[] ram)
|
||||
{
|
||||
RAM = ram;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public RAM6116(DeserializationContext input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
RAM = input.ReadExpectedBytes(0x800);
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(RAM);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,230 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A context for serializing <see cref="MachineBase"/> objects.
|
||||
/// </summary>
|
||||
public class SerializationContext
|
||||
{
|
||||
#region Fields
|
||||
|
||||
readonly BinaryWriter _binaryWriter;
|
||||
|
||||
#endregion
|
||||
|
||||
public void Write(byte value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(ushort value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(int value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(uint value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(long value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(ulong value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(bool value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(double value)
|
||||
{
|
||||
_binaryWriter.Write(value);
|
||||
}
|
||||
|
||||
public void Write(BufferElement bufferElement)
|
||||
{
|
||||
for (var i = 0; i < BufferElement.SIZE; i++)
|
||||
Write(bufferElement[i]);
|
||||
}
|
||||
|
||||
public void Write(byte[] bytes)
|
||||
{
|
||||
_binaryWriter.Write(bytes.Length);
|
||||
if (bytes.Length > 0)
|
||||
_binaryWriter.Write(bytes);
|
||||
}
|
||||
|
||||
public void Write(ushort[] ushorts)
|
||||
{
|
||||
var bytes = new byte[ushorts.Length << 1];
|
||||
Buffer.BlockCopy(ushorts, 0, bytes, 0, bytes.Length);
|
||||
Write(bytes);
|
||||
}
|
||||
|
||||
public void Write(int[] ints)
|
||||
{
|
||||
var bytes = new byte[ints.Length << 2];
|
||||
Buffer.BlockCopy(ints, 0, bytes, 0, bytes.Length);
|
||||
Write(bytes);
|
||||
}
|
||||
|
||||
public void Write(uint[] uints)
|
||||
{
|
||||
var bytes = new byte[uints.Length << 2];
|
||||
Buffer.BlockCopy(uints, 0, bytes, 0, bytes.Length);
|
||||
Write(bytes);
|
||||
}
|
||||
|
||||
public void Write(bool[] booleans)
|
||||
{
|
||||
var bytes = new byte[booleans.Length];
|
||||
for (var i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
bytes[i] = (byte)(booleans[i] ? 0xff : 0x00);
|
||||
}
|
||||
Write(bytes);
|
||||
}
|
||||
|
||||
public void Write(MachineBase m)
|
||||
{
|
||||
WriteTypeName(m);
|
||||
m.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(AddressSpace mem)
|
||||
{
|
||||
mem.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(M6502 cpu)
|
||||
{
|
||||
cpu.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(PIA pia)
|
||||
{
|
||||
pia.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(TIA tia)
|
||||
{
|
||||
tia.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(TIASound tiaSound)
|
||||
{
|
||||
tiaSound.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(Maria maria)
|
||||
{
|
||||
maria.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(Cart cart)
|
||||
{
|
||||
WriteTypeName(cart);
|
||||
cart.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(RAM6116 ram6116)
|
||||
{
|
||||
ram6116.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void Write(InputState inputState)
|
||||
{
|
||||
inputState.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void WriteVersion(int version)
|
||||
{
|
||||
Write(0x78000087);
|
||||
Write(version);
|
||||
}
|
||||
|
||||
public void WriteOptional(byte[] bytes)
|
||||
{
|
||||
var hasBytes = (bytes != null);
|
||||
_binaryWriter.Write(hasBytes);
|
||||
if (!hasBytes)
|
||||
return;
|
||||
_binaryWriter.Write(bytes.Length);
|
||||
if (bytes.Length > 0)
|
||||
_binaryWriter.Write(bytes);
|
||||
}
|
||||
|
||||
public void WriteOptional(HSC7800 hsc7800)
|
||||
{
|
||||
var exist = (hsc7800 != null);
|
||||
Write(exist);
|
||||
if (!exist)
|
||||
return;
|
||||
hsc7800.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void WriteOptional(Bios7800 bios7800)
|
||||
{
|
||||
var exist = (bios7800 != null);
|
||||
Write(exist);
|
||||
if (!exist)
|
||||
return;
|
||||
bios7800.GetObjectData(this);
|
||||
}
|
||||
|
||||
public void WriteOptional(PokeySound pokeySound)
|
||||
{
|
||||
var exist = (pokeySound != null);
|
||||
Write(exist);
|
||||
if (!exist)
|
||||
return;
|
||||
pokeySound.GetObjectData(this);
|
||||
}
|
||||
|
||||
#region Constructors
|
||||
|
||||
private SerializationContext()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new instance of <see cref="SerializationContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="binaryWriter"/>
|
||||
internal SerializationContext(BinaryWriter binaryWriter)
|
||||
{
|
||||
if (binaryWriter == null)
|
||||
throw new ArgumentNullException("binaryWriter");
|
||||
_binaryWriter = binaryWriter;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
void WriteTypeName(object o)
|
||||
{
|
||||
if (o == null)
|
||||
throw new Emu7800SerializationException("Type unexpectedly null.");
|
||||
var typeName = o.GetType().FullName;
|
||||
if (string.IsNullOrWhiteSpace(typeName))
|
||||
throw new Emu7800SerializationException("Unable to discover type name.");
|
||||
_binaryWriter.Write(typeName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,361 @@
|
|||
/*
|
||||
* TIASound.cs
|
||||
*
|
||||
* Sound emulation for the 2600. Based upon TIASound © 1997 by Ron Fries.
|
||||
*
|
||||
* Copyright © 2003, 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* License Information and Copyright Notice */
|
||||
/* ======================================== */
|
||||
/* */
|
||||
/* TiaSound is Copyright(c) 1997 by Ron Fries */
|
||||
/* */
|
||||
/* This library is free software; you can redistribute it and/or modify it */
|
||||
/* under the terms of version 2 of the GNU Library General Public License */
|
||||
/* as published by the Free Software Foundation. */
|
||||
/* */
|
||||
/* This library is distributed in the hope that it will be useful, but */
|
||||
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library */
|
||||
/* General Public License for more details. */
|
||||
/* To obtain a copy of the GNU Library General Public License, write to the */
|
||||
/* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
/* */
|
||||
/* Any permitted reproduction of these routines, in whole or in part, must */
|
||||
/* bear this legend. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public sealed class TIASound
|
||||
{
|
||||
#region Constants and Tables
|
||||
|
||||
// Clock Source Clock Modifier Source Pattern
|
||||
const int
|
||||
SET_TO_1 = 0x00, // 0 0 0 0 3.58 Mhz/114 none (pure) none
|
||||
//POLY4 = 0x01, // 0 0 0 1 3.58 Mhz/114 none (pure) 4-bit poly
|
||||
//DIV31_POLY4 = 0x02, // 0 0 1 0 3.58 Mhz/114 divide by 31 4-bit poly
|
||||
//POLY5_POLY4 = 0x03, // 0 0 1 1 3.58 Mhz/114 5-bit poly 4-bit poly
|
||||
//PURE = 0x04, // 0 1 0 0 3.58 Mhz/114 none (pure) pure (~Q)
|
||||
//PURE2 = 0x05, // 0 1 0 1 3.58 Mhz/114 none (pure) pure (~Q)
|
||||
//DIV31_PURE = 0x06, // 0 1 1 0 3.58 Mhz/114 divide by 31 pure (~Q)
|
||||
//POLY5_2 = 0x07, // 0 1 1 1 3.58 Mhz/114 5-bit poly pure (~Q)
|
||||
POLY9 = 0x08; // 1 0 0 0 3.58 Mhz/114 none (pure) 9-bit poly
|
||||
//POLY5 = 0x09, // 1 0 0 1 3.58 Mhz/114 none (pure) 5-bit poly
|
||||
//DIV31_POLY5 = 0x0a, // 1 0 1 0 3.58 Mhz/114 divide by 31 5-bit poly
|
||||
//POLY5_POLY5 = 0x0b, // 1 0 1 1 3.58 Mhz/114 5-bit poly 5-bit poly
|
||||
//DIV3_PURE = 0x0c, // 1 1 0 0 1.19 Mhz/114 none (pure) pure (~Q)
|
||||
//DIV3_PURE2 = 0x0d, // 1 1 0 1 1.19 Mhz/114 none (pure) pure (~Q)
|
||||
//DIV93_PURE = 0x0e, // 1 1 1 0 1.19 Mhz/114 divide by 31 pure (~Q)
|
||||
//DIV3_POLY5 = 0x0f; // 1 1 1 1 1.19 Mhz/114 5-bit poly pure (~Q)
|
||||
|
||||
const int
|
||||
AUDC0 = 0x15, // audio control 0 (D3-0)
|
||||
AUDC1 = 0x16, // audio control 1 (D4-0)
|
||||
AUDF0 = 0x17, // audio frequency 0 (D4-0)
|
||||
AUDF1 = 0x18, // audio frequency 1 (D3-0)
|
||||
AUDV0 = 0x19, // audio volume 0 (D3-0)
|
||||
AUDV1 = 0x1a; // audio volume 1 (D3-0)
|
||||
|
||||
// The 4bit and 5bit patterns are the identical ones used in the tia chip.
|
||||
readonly byte[] Bit4 = new byte[] { 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0 }; // 2^4 - 1 = 15
|
||||
readonly byte[] Bit5 = new byte[] { 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1 }; // 2^5 - 1 = 31
|
||||
|
||||
// [Ron] treated the 'Div by 31' counter as another polynomial because of
|
||||
// the way it operates. It does not have a 50% duty cycle, but instead
|
||||
// has a 13:18 ratio (of course, 13+18 = 31). This could also be
|
||||
// implemented by using counters.
|
||||
readonly byte[] Div31 = new byte[] { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// Rather than have a table with 511 entries, I use a random number
|
||||
readonly byte[] Bit9 = new byte[511]; // 2^9 - 1 = 511
|
||||
|
||||
readonly int[] P4 = new int[2]; // Position counter for the 4-bit POLY array
|
||||
readonly int[] P5 = new int[2]; // Position counter for the 5-bit POLY array
|
||||
readonly int[] P9 = new int[2]; // Position counter for the 9-bit POLY array
|
||||
|
||||
readonly int[] DivByNCounter = new int[2]; // Divide by n counter, one for each channel
|
||||
readonly int[] DivByNMaximum = new int[2]; // Divide by n maximum, one for each channel
|
||||
|
||||
readonly int _cpuClocksPerSample;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Object State
|
||||
|
||||
readonly MachineBase M;
|
||||
|
||||
// The TIA Sound registers
|
||||
readonly byte[] AUDC = new byte[2];
|
||||
readonly byte[] AUDF = new byte[2];
|
||||
readonly byte[] AUDV = new byte[2];
|
||||
|
||||
// The last output volume for each channel
|
||||
readonly byte[] OutputVol = new byte[2];
|
||||
|
||||
// Used to determine how much sound to render
|
||||
ulong LastUpdateCPUClock;
|
||||
|
||||
int BufferIndex;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
for (var chan = 0; chan < 2; chan++)
|
||||
{
|
||||
OutputVol[chan] = 0;
|
||||
DivByNCounter[chan] = 0;
|
||||
DivByNMaximum[chan] = 0;
|
||||
AUDC[chan] = 0;
|
||||
AUDF[chan] = 0;
|
||||
AUDV[chan] = 0;
|
||||
P4[chan] = 0;
|
||||
P5[chan] = 0;
|
||||
P9[chan] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void StartFrame()
|
||||
{
|
||||
LastUpdateCPUClock = M.CPU.Clock;
|
||||
BufferIndex = 0;
|
||||
}
|
||||
|
||||
public void EndFrame()
|
||||
{
|
||||
RenderSamples(M.FrameBuffer.SoundBufferByteLength - BufferIndex);
|
||||
}
|
||||
|
||||
public void Update(ushort addr, byte data)
|
||||
{
|
||||
if (M.CPU.Clock > LastUpdateCPUClock)
|
||||
{
|
||||
var updCPUClocks = (int)(M.CPU.Clock - LastUpdateCPUClock);
|
||||
var samples = updCPUClocks / _cpuClocksPerSample;
|
||||
RenderSamples(samples);
|
||||
LastUpdateCPUClock += (ulong)(samples * _cpuClocksPerSample);
|
||||
}
|
||||
|
||||
byte chan;
|
||||
|
||||
switch (addr)
|
||||
{
|
||||
case AUDC0:
|
||||
AUDC[0] = (byte)(data & 0x0f);
|
||||
chan = 0;
|
||||
break;
|
||||
case AUDC1:
|
||||
AUDC[1] = (byte)(data & 0x0f);
|
||||
chan = 1;
|
||||
break;
|
||||
case AUDF0:
|
||||
AUDF[0] = (byte)(data & 0x1f);
|
||||
chan = 0;
|
||||
break;
|
||||
case AUDF1:
|
||||
AUDF[1] = (byte)(data & 0x1f);
|
||||
chan = 1;
|
||||
break;
|
||||
case AUDV0:
|
||||
AUDV[0] = (byte)(data & 0x0f);
|
||||
chan = 0;
|
||||
break;
|
||||
case AUDV1:
|
||||
AUDV[1] = (byte)(data & 0x0f);
|
||||
chan = 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
byte new_divn_max;
|
||||
|
||||
if (AUDC[chan] == SET_TO_1)
|
||||
{
|
||||
// indicate the clock is zero so no process will occur
|
||||
new_divn_max = 0;
|
||||
// and set the output to the selected volume
|
||||
OutputVol[chan] = AUDV[chan];
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise calculate the 'divide by N' value
|
||||
new_divn_max = (byte)(AUDF[chan] + 1);
|
||||
// if bits D2 & D3 are set, then multiply the 'div by n' count by 3
|
||||
if ((AUDC[chan] & 0x0c) == 0x0c)
|
||||
{
|
||||
new_divn_max *= 3;
|
||||
}
|
||||
}
|
||||
|
||||
// only reset those channels that have changed
|
||||
if (new_divn_max != DivByNMaximum[chan])
|
||||
{
|
||||
DivByNMaximum[chan] = new_divn_max;
|
||||
|
||||
// if the channel is now volume only or was volume only...
|
||||
if (DivByNCounter[chan] == 0 || new_divn_max == 0)
|
||||
{
|
||||
// reset the counter (otherwise let it complete the previous)
|
||||
DivByNCounter[chan] = new_divn_max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
private TIASound()
|
||||
{
|
||||
var r = new Random();
|
||||
r.NextBytes(Bit9);
|
||||
for (var i = 0; i < Bit9.Length; i++)
|
||||
{
|
||||
Bit9[i] &= 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
public TIASound(MachineBase m, int cpuClocksPerSample) : this()
|
||||
{
|
||||
if (m == null)
|
||||
throw new ArgumentNullException("m");
|
||||
if (cpuClocksPerSample <= 0)
|
||||
throw new ArgumentException("cpuClocksPerSample must be positive.");
|
||||
|
||||
M = m;
|
||||
_cpuClocksPerSample = cpuClocksPerSample;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialization Members
|
||||
|
||||
public TIASound(DeserializationContext input, MachineBase m, int cpuClocksPerSample) : this(m, cpuClocksPerSample)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
input.CheckVersion(1);
|
||||
Bit9 = input.ReadExpectedBytes(511);
|
||||
P4 = input.ReadIntegers(2);
|
||||
P5 = input.ReadIntegers(2);
|
||||
P9 = input.ReadIntegers(2);
|
||||
DivByNCounter = input.ReadIntegers(2);
|
||||
DivByNMaximum = input.ReadIntegers(2);
|
||||
AUDC = input.ReadExpectedBytes(2);
|
||||
AUDF = input.ReadExpectedBytes(2);
|
||||
AUDV = input.ReadExpectedBytes(2);
|
||||
OutputVol = input.ReadExpectedBytes(2);
|
||||
LastUpdateCPUClock = input.ReadUInt64();
|
||||
BufferIndex = input.ReadInt32();
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationContext output)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
output.WriteVersion(1);
|
||||
output.Write(Bit9);
|
||||
output.Write(P4);
|
||||
output.Write(P5);
|
||||
output.Write(P9);
|
||||
output.Write(DivByNCounter);
|
||||
output.Write(DivByNMaximum);
|
||||
output.Write(AUDC);
|
||||
output.Write(AUDF);
|
||||
output.Write(AUDV);
|
||||
output.Write(OutputVol);
|
||||
output.Write(LastUpdateCPUClock);
|
||||
output.Write(BufferIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
void RenderSamples(int count)
|
||||
{
|
||||
for (; BufferIndex < M.FrameBuffer.SoundBufferByteLength && count-- > 0; BufferIndex++)
|
||||
{
|
||||
if (DivByNCounter[0] > 1)
|
||||
{
|
||||
DivByNCounter[0]--;
|
||||
}
|
||||
else if (DivByNCounter[0] == 1)
|
||||
{
|
||||
DivByNCounter[0] = DivByNMaximum[0];
|
||||
ProcessChannel(0);
|
||||
}
|
||||
if (DivByNCounter[1] > 1)
|
||||
{
|
||||
DivByNCounter[1]--;
|
||||
}
|
||||
else if (DivByNCounter[1] == 1)
|
||||
{
|
||||
DivByNCounter[1] = DivByNMaximum[1];
|
||||
ProcessChannel(1);
|
||||
}
|
||||
|
||||
M.FrameBuffer.SoundBuffer[BufferIndex >> BufferElement.SHIFT][BufferIndex] += (byte)(OutputVol[0] + OutputVol[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessChannel(int chan)
|
||||
{
|
||||
// the P5 counter has multiple uses, so we inc it here
|
||||
if (++P5[chan] >= 31)
|
||||
{ // POLY5 size: 2^5 - 1 = 31
|
||||
P5[chan] = 0;
|
||||
}
|
||||
|
||||
// check clock modifier for clock tick
|
||||
if ((AUDC[chan] & 0x02) == 0 ||
|
||||
((AUDC[chan] & 0x01) == 0 && Div31[P5[chan]] == 1) ||
|
||||
((AUDC[chan] & 0x01) == 1 && Bit5[P5[chan]] == 1))
|
||||
{
|
||||
if ((AUDC[chan] & 0x04) != 0)
|
||||
{ // pure modified clock selected
|
||||
OutputVol[chan] = (OutputVol[chan] != 0) ? (byte)0 : AUDV[chan];
|
||||
}
|
||||
else if ((AUDC[chan] & 0x08) != 0)
|
||||
{ // check for poly5/poly9
|
||||
if (AUDC[chan] == POLY9)
|
||||
{ // check for poly9
|
||||
if (++P9[chan] >= 511)
|
||||
{ // poly9 size: 2^9 - 1 = 511
|
||||
P9[chan] = 0;
|
||||
}
|
||||
OutputVol[chan] = (Bit9[P9[chan]] == 1) ? AUDV[chan] : (byte)0;
|
||||
}
|
||||
else
|
||||
{ // must be poly5
|
||||
OutputVol[chan] = (Bit5[P5[chan]] == 1) ? AUDV[chan] : (byte)0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // poly4 is the only remaining possibility
|
||||
if (++P4[chan] >= 15)
|
||||
{ // POLY4 size: 2^4 - 1 = 15
|
||||
P4[chan] = 0;
|
||||
}
|
||||
OutputVol[chan] = (Bit4[P4[chan]] == 1) ? AUDV[chan] : (byte)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,424 @@
|
|||
/*
|
||||
* TIATables.cs
|
||||
*
|
||||
* Mask tables for the Television Interface Adaptor class. All derived from
|
||||
* Bradford Mott's Stella code.
|
||||
*
|
||||
* Copyright © 2003, 2004 Mike Murphy
|
||||
*
|
||||
*/
|
||||
namespace EMU7800.Core
|
||||
{
|
||||
public static class TIATables
|
||||
{
|
||||
public static readonly TIACxPairFlags[] CollisionMask = BuildCollisionMaskTable();
|
||||
public static readonly uint[][] PFMask = BuildPFMaskTable();
|
||||
public static readonly bool[][] BLMask = BuildBLMaskTable();
|
||||
public static readonly bool[][][] MxMask = BuildMxMaskTable();
|
||||
public static readonly byte[][][] PxMask = BuildPxMaskTable();
|
||||
public static readonly byte[] GRPReflect = BuildGRPReflectTable();
|
||||
|
||||
public static readonly int[] NTSCPalette =
|
||||
{
|
||||
0x000000, 0x000000, 0x4a4a4a, 0x4a4a4a,
|
||||
0x6f6f6f, 0x6f6f6f, 0x8e8e8e, 0x8e8e8e,
|
||||
0xaaaaaa, 0xaaaaaa, 0xc0c0c0, 0xc0c0c0,
|
||||
0xd6d6d6, 0xd6d6d6, 0xececec, 0xececec,
|
||||
|
||||
0x484800, 0x484800, 0x69690f, 0x69690f,
|
||||
0x86861d, 0x86861d, 0xa2a22a, 0xa2a22a,
|
||||
0xbbbb35, 0xbbbb35, 0xd2d240, 0xd2d240,
|
||||
0xe8e84a, 0xe8e84a, 0xfcfc54, 0xfcfc54,
|
||||
|
||||
0x7c2c00, 0x7c2c00, 0x904811, 0x904811,
|
||||
0xa26221, 0xa26221, 0xb47a30, 0xb47a30,
|
||||
0xc3903d, 0xc3903d, 0xd2a44a, 0xd2a44a,
|
||||
0xdfb755, 0xdfb755, 0xecc860, 0xecc860,
|
||||
|
||||
0x901c00, 0x901c00, 0xa33915, 0xa33915,
|
||||
0xb55328, 0xb55328, 0xc66c3a, 0xc66c3a,
|
||||
0xd5824a, 0xd5824a, 0xe39759, 0xe39759,
|
||||
0xf0aa67, 0xf0aa67, 0xfcbc74, 0xfcbc74,
|
||||
|
||||
0x940000, 0x940000, 0xa71a1a, 0xa71a1a,
|
||||
0xb83232, 0xb83232, 0xc84848, 0xc84848,
|
||||
0xd65c5c, 0xd65c5c, 0xe46f6f, 0xe46f6f,
|
||||
0xf08080, 0xf08080, 0xfc9090, 0xfc9090,
|
||||
|
||||
0x840064, 0x840064, 0x97197a, 0x97197a,
|
||||
0xa8308f, 0xa8308f, 0xb846a2, 0xb846a2,
|
||||
0xc659b3, 0xc659b3, 0xd46cc3, 0xd46cc3,
|
||||
0xe07cd2, 0xe07cd2, 0xec8ce0, 0xec8ce0,
|
||||
|
||||
0x500084, 0x500084, 0x68199a, 0x68199a,
|
||||
0x7d30ad, 0x7d30ad, 0x9246c0, 0x9246c0,
|
||||
0xa459d0, 0xa459d0, 0xb56ce0, 0xb56ce0,
|
||||
0xc57cee, 0xc57cee, 0xd48cfc, 0xd48cfc,
|
||||
|
||||
0x140090, 0x140090, 0x331aa3, 0x331aa3,
|
||||
0x4e32b5, 0x4e32b5, 0x6848c6, 0x6848c6,
|
||||
0x7f5cd5, 0x7f5cd5, 0x956fe3, 0x956fe3,
|
||||
0xa980f0, 0xa980f0, 0xbc90fc, 0xbc90fc,
|
||||
|
||||
0x000094, 0x000094, 0x181aa7, 0x181aa7,
|
||||
0x2d32b8, 0x2d32b8, 0x4248c8, 0x4248c8,
|
||||
0x545cd6, 0x545cd6, 0x656fe4, 0x656fe4,
|
||||
0x7580f0, 0x7580f0, 0x8490fc, 0x8490fc,
|
||||
|
||||
0x001c88, 0x001c88, 0x183b9d, 0x183b9d,
|
||||
0x2d57b0, 0x2d57b0, 0x4272c2, 0x4272c2,
|
||||
0x548ad2, 0x548ad2, 0x65a0e1, 0x65a0e1,
|
||||
0x75b5ef, 0x75b5ef, 0x84c8fc, 0x84c8fc,
|
||||
|
||||
0x003064, 0x003064, 0x185080, 0x185080,
|
||||
0x2d6d98, 0x2d6d98, 0x4288b0, 0x4288b0,
|
||||
0x54a0c5, 0x54a0c5, 0x65b7d9, 0x65b7d9,
|
||||
0x75cceb, 0x75cceb, 0x84e0fc, 0x84e0fc,
|
||||
|
||||
0x004030, 0x004030, 0x18624e, 0x18624e,
|
||||
0x2d8169, 0x2d8169, 0x429e82, 0x429e82,
|
||||
0x54b899, 0x54b899, 0x65d1ae, 0x65d1ae,
|
||||
0x75e7c2, 0x75e7c2, 0x84fcd4, 0x84fcd4,
|
||||
|
||||
0x004400, 0x004400, 0x1a661a, 0x1a661a,
|
||||
0x328432, 0x328432, 0x48a048, 0x48a048,
|
||||
0x5cba5c, 0x5cba5c, 0x6fd26f, 0x6fd26f,
|
||||
0x80e880, 0x80e880, 0x90fc90, 0x90fc90,
|
||||
|
||||
0x143c00, 0x143c00, 0x355f18, 0x355f18,
|
||||
0x527e2d, 0x527e2d, 0x6e9c42, 0x6e9c42,
|
||||
0x87b754, 0x87b754, 0x9ed065, 0x9ed065,
|
||||
0xb4e775, 0xb4e775, 0xc8fc84, 0xc8fc84,
|
||||
|
||||
0x303800, 0x303800, 0x505916, 0x505916,
|
||||
0x6d762b, 0x6d762b, 0x88923e, 0x88923e,
|
||||
0xa0ab4f, 0xa0ab4f, 0xb7c25f, 0xb7c25f,
|
||||
0xccd86e, 0xccd86e, 0xe0ec7c, 0xe0ec7c,
|
||||
|
||||
0x482c00, 0x482c00, 0x694d14, 0x694d14,
|
||||
0x866a26, 0x866a26, 0xa28638, 0xa28638,
|
||||
0xbb9f47, 0xbb9f47, 0xd2b656, 0xd2b656,
|
||||
0xe8cc63, 0xe8cc63, 0xfce070, 0xfce070
|
||||
};
|
||||
|
||||
public static readonly int[] PALPalette =
|
||||
{
|
||||
0x000000, 0x000000, 0x2b2b2b, 0x2b2b2b,
|
||||
0x525252, 0x525252, 0x767676, 0x767676,
|
||||
0x979797, 0x979797, 0xb6b6b6, 0xb6b6b6,
|
||||
0xd2d2d2, 0xd2d2d2, 0xececec, 0xececec,
|
||||
|
||||
0x000000, 0x000000, 0x2b2b2b, 0x2b2b2b,
|
||||
0x525252, 0x525252, 0x767676, 0x767676,
|
||||
0x979797, 0x979797, 0xb6b6b6, 0xb6b6b6,
|
||||
0xd2d2d2, 0xd2d2d2, 0xececec, 0xececec,
|
||||
|
||||
0x805800, 0x000000, 0x96711a, 0x2b2b2b,
|
||||
0xab8732, 0x525252, 0xbe9c48, 0x767676,
|
||||
0xcfaf5c, 0x979797, 0xdfc06f, 0xb6b6b6,
|
||||
0xeed180, 0xd2d2d2, 0xfce090, 0xececec,
|
||||
|
||||
0x445c00, 0x000000, 0x5e791a, 0x2b2b2b,
|
||||
0x769332, 0x525252, 0x8cac48, 0x767676,
|
||||
0xa0c25c, 0x979797, 0xb3d76f, 0xb6b6b6,
|
||||
0xc4ea80, 0xd2d2d2, 0xd4fc90, 0xececec,
|
||||
|
||||
0x703400, 0x000000, 0x89511a, 0x2b2b2b,
|
||||
0xa06b32, 0x525252, 0xb68448, 0x767676,
|
||||
0xc99a5c, 0x979797, 0xdcaf6f, 0xb6b6b6,
|
||||
0xecc280, 0xd2d2d2, 0xfcd490, 0xececec,
|
||||
|
||||
0x006414, 0x000000, 0x1a8035, 0x2b2b2b,
|
||||
0x329852, 0x525252, 0x48b06e, 0x767676,
|
||||
0x5cc587, 0x979797, 0x6fd99e, 0xb6b6b6,
|
||||
0x80ebb4, 0xd2d2d2, 0x90fcc8, 0xececec,
|
||||
|
||||
0x700014, 0x000000, 0x891a35, 0x2b2b2b,
|
||||
0xa03252, 0x525252, 0xb6486e, 0x767676,
|
||||
0xc95c87, 0x979797, 0xdc6f9e, 0xb6b6b6,
|
||||
0xec80b4, 0xd2d2d2, 0xfc90c8, 0xececec,
|
||||
|
||||
0x005c5c, 0x000000, 0x1a7676, 0x2b2b2b,
|
||||
0x328e8e, 0x525252, 0x48a4a4, 0x767676,
|
||||
0x5cb8b8, 0x979797, 0x6fcbcb, 0xb6b6b6,
|
||||
0x80dcdc, 0xd2d2d2, 0x90ecec, 0xececec,
|
||||
|
||||
0x70005c, 0x000000, 0x841a74, 0x2b2b2b,
|
||||
0x963289, 0x525252, 0xa8489e, 0x767676,
|
||||
0xb75cb0, 0x979797, 0xc66fc1, 0xb6b6b6,
|
||||
0xd380d1, 0xd2d2d2, 0xe090e0, 0xececec,
|
||||
|
||||
0x003c70, 0x000000, 0x195a89, 0x2b2b2b,
|
||||
0x2f75a0, 0x525252, 0x448eb6, 0x767676,
|
||||
0x57a5c9, 0x979797, 0x68badc, 0xb6b6b6,
|
||||
0x79ceec, 0xd2d2d2, 0x88e0fc, 0xececec,
|
||||
|
||||
0x580070, 0x000000, 0x6e1a89, 0x2b2b2b,
|
||||
0x8332a0, 0x525252, 0x9648b6, 0x767676,
|
||||
0xa75cc9, 0x979797, 0xb76fdc, 0xb6b6b6,
|
||||
0xc680ec, 0xd2d2d2, 0xd490fc, 0xececec,
|
||||
|
||||
0x002070, 0x000000, 0x193f89, 0x2b2b2b,
|
||||
0x2f5aa0, 0x525252, 0x4474b6, 0x767676,
|
||||
0x578bc9, 0x979797, 0x68a1dc, 0xb6b6b6,
|
||||
0x79b5ec, 0xd2d2d2, 0x88c8fc, 0xececec,
|
||||
|
||||
0x340080, 0x000000, 0x4a1a96, 0x2b2b2b,
|
||||
0x5f32ab, 0x525252, 0x7248be, 0x767676,
|
||||
0x835ccf, 0x979797, 0x936fdf, 0xb6b6b6,
|
||||
0xa280ee, 0xd2d2d2, 0xb090fc, 0xececec,
|
||||
|
||||
0x000088, 0x000000, 0x1a1a9d, 0x2b2b2b,
|
||||
0x3232b0, 0x525252, 0x4848c2, 0x767676,
|
||||
0x5c5cd2, 0x979797, 0x6f6fe1, 0xb6b6b6,
|
||||
0x8080ef, 0xd2d2d2, 0x9090fc, 0xececec,
|
||||
|
||||
0x000000, 0x000000, 0x2b2b2b, 0x2b2b2b,
|
||||
0x525252, 0x525252, 0x767676, 0x767676,
|
||||
0x979797, 0x979797, 0xb6b6b6, 0xb6b6b6,
|
||||
0xd2d2d2, 0xd2d2d2, 0xececec, 0xececec,
|
||||
|
||||
0x000000, 0x000000, 0x2b2b2b, 0x2b2b2b,
|
||||
0x525252, 0x525252, 0x767676, 0x767676,
|
||||
0x979797, 0x979797, 0xb6b6b6, 0xb6b6b6,
|
||||
0xd2d2d2, 0xd2d2d2, 0xececec, 0xececec
|
||||
};
|
||||
|
||||
static uint[][] BuildPFMaskTable()
|
||||
{
|
||||
var tabl = new uint[2][];
|
||||
tabl[0] = new uint[160];
|
||||
tabl[1] = new uint[160];
|
||||
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
uint mask = 0;
|
||||
if (i < 4)
|
||||
{
|
||||
mask = (uint)(1 << i);
|
||||
}
|
||||
else if (i < 12)
|
||||
{
|
||||
mask = (uint)(1 << (11 + 4 - i));
|
||||
}
|
||||
else if (i < 20)
|
||||
{
|
||||
mask = (uint)(1 << i);
|
||||
}
|
||||
for (var j = 0; j < 4; j++)
|
||||
{
|
||||
// for non-reflected mode
|
||||
tabl[0][4 * i + j] = mask;
|
||||
tabl[0][80 + 4 * i + j] = mask;
|
||||
|
||||
// for reflected mode
|
||||
tabl[1][4 * i + j] = mask;
|
||||
tabl[1][159 - 4 * i - j] = mask;
|
||||
}
|
||||
}
|
||||
return tabl;
|
||||
}
|
||||
|
||||
static bool[][] BuildBLMaskTable()
|
||||
{
|
||||
var tabl = new bool[4][];
|
||||
for (var size = 0; size < 4; size++)
|
||||
{
|
||||
tabl[size] = new bool[160];
|
||||
for (var i = 0; i < 160; i++)
|
||||
{
|
||||
tabl[size][i] = false;
|
||||
}
|
||||
for (var i = 0; i < (1 << size); i++)
|
||||
{
|
||||
tabl[size][i] = true;
|
||||
}
|
||||
}
|
||||
return tabl;
|
||||
}
|
||||
|
||||
static bool[][][] BuildMxMaskTable()
|
||||
{
|
||||
var tabl = new bool[4][][];
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
tabl[i] = new bool[8][];
|
||||
for (var j = 0; j < 8; j++)
|
||||
{
|
||||
tabl[i][j] = new bool[160];
|
||||
for (var k = 0; k < 160; k++)
|
||||
{
|
||||
tabl[i][j][k] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var size = 0; size < 4; size++)
|
||||
{
|
||||
for (var i = 0; i < (1 << size); i++)
|
||||
{
|
||||
tabl[size][0][i] = true;
|
||||
|
||||
tabl[size][1][i] = true;
|
||||
tabl[size][1][i + 16] = true;
|
||||
|
||||
tabl[size][2][i] = true;
|
||||
tabl[size][2][i + 32] = true;
|
||||
|
||||
tabl[size][3][i] = true;
|
||||
tabl[size][3][i + 16] = true;
|
||||
tabl[size][3][i + 32] = true;
|
||||
|
||||
tabl[size][4][i] = true;
|
||||
tabl[size][4][i + 64] = true;
|
||||
|
||||
tabl[size][5][i] = true;
|
||||
|
||||
tabl[size][6][i] = true;
|
||||
tabl[size][6][i + 32] = true;
|
||||
tabl[size][6][i + 64] = true;
|
||||
|
||||
tabl[size][7][i] = true;
|
||||
}
|
||||
}
|
||||
return tabl;
|
||||
}
|
||||
|
||||
static byte[][][] BuildPxMaskTable()
|
||||
{
|
||||
// [suppress mode, nusiz, pixel]
|
||||
// suppress=1: suppress on
|
||||
// suppress=0: suppress off
|
||||
var tabl = new byte[2][][]; //2 8 160
|
||||
tabl[0] = new byte[8][];
|
||||
tabl[1] = new byte[8][];
|
||||
for (var nusiz = 0; nusiz < 8; nusiz++)
|
||||
{
|
||||
tabl[0][nusiz] = new byte[160];
|
||||
tabl[1][nusiz] = new byte[160];
|
||||
for (var hpos = 0; hpos < 160; hpos++)
|
||||
{
|
||||
// nusiz:
|
||||
// 0: one copy
|
||||
// 1: two copies-close
|
||||
// 2: two copies-med
|
||||
// 3: three copies-close
|
||||
// 4: two copies-wide
|
||||
// 5: double size player
|
||||
// 6: 3 copies medium
|
||||
// 7: quad sized player
|
||||
tabl[0][nusiz][hpos] = tabl[1][nusiz][hpos] = 0;
|
||||
if (nusiz >= 0 && nusiz <= 4 || nusiz == 6)
|
||||
{
|
||||
if (hpos >= 0 && hpos < 8)
|
||||
{
|
||||
tabl[0][nusiz][hpos] = (byte)(1 << (7 - hpos));
|
||||
}
|
||||
}
|
||||
if (nusiz == 1 || nusiz == 3)
|
||||
{
|
||||
if (hpos >= 16 && hpos < 24)
|
||||
{
|
||||
tabl[0][nusiz][hpos] = (byte)(1 << (23 - hpos));
|
||||
tabl[1][nusiz][hpos] = (byte)(1 << (23 - hpos));
|
||||
}
|
||||
}
|
||||
if (nusiz == 2 || nusiz == 3 || nusiz == 6)
|
||||
{
|
||||
if (hpos >= 32 && hpos < 40)
|
||||
{
|
||||
tabl[0][nusiz][hpos] = (byte)(1 << (39 - hpos));
|
||||
tabl[1][nusiz][hpos] = (byte)(1 << (39 - hpos));
|
||||
}
|
||||
}
|
||||
if (nusiz == 4 || nusiz == 6)
|
||||
{
|
||||
if (hpos >= 64 && hpos < 72)
|
||||
{
|
||||
tabl[0][nusiz][hpos] = (byte)(1 << (71 - hpos));
|
||||
tabl[1][nusiz][hpos] = (byte)(1 << (71 - hpos));
|
||||
}
|
||||
}
|
||||
if (nusiz == 5)
|
||||
{
|
||||
if (hpos >= 0 && hpos < 16)
|
||||
{
|
||||
tabl[0][nusiz][hpos] = (byte)(1 << ((15 - hpos) >> 1));
|
||||
}
|
||||
}
|
||||
if (nusiz == 7)
|
||||
{
|
||||
if (hpos >= 0 && hpos < 32)
|
||||
{
|
||||
tabl[0][nusiz][hpos] = (byte)(1 << ((31 - hpos) >> 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var shift = nusiz == 5 || nusiz == 7 ? 2 : 1;
|
||||
while (shift-- > 0)
|
||||
{
|
||||
for (var i = 159; i > 0; i--)
|
||||
{
|
||||
tabl[0][nusiz][i] = tabl[0][nusiz][i - 1];
|
||||
tabl[1][nusiz][i] = tabl[1][nusiz][i - 1];
|
||||
}
|
||||
tabl[0][nusiz][0] = tabl[1][nusiz][0] = 0;
|
||||
}
|
||||
}
|
||||
return tabl;
|
||||
}
|
||||
|
||||
static byte[] BuildGRPReflectTable()
|
||||
{
|
||||
var tabl = new byte[256];
|
||||
|
||||
for (var i = 0; i < 256; i++)
|
||||
{
|
||||
var s = (byte)i;
|
||||
var r = (byte)0;
|
||||
for (var j = 0; j < 8; j++)
|
||||
{
|
||||
r <<= 1;
|
||||
r |= (byte)(s & 1);
|
||||
s >>= 1;
|
||||
}
|
||||
tabl[i] = r;
|
||||
}
|
||||
return tabl;
|
||||
}
|
||||
|
||||
static bool tstCx(int i, TIACxFlags cxf1, TIACxFlags cxf2)
|
||||
{
|
||||
var f1 = (int)cxf1;
|
||||
var f2 = (int)cxf2;
|
||||
return ((i & f1) != 0) && ((i & f2) != 0);
|
||||
}
|
||||
|
||||
static TIACxPairFlags[] BuildCollisionMaskTable()
|
||||
{
|
||||
var tabl = new TIACxPairFlags[64];
|
||||
|
||||
for (var i = 0; i < 64; i++)
|
||||
{
|
||||
tabl[i] = 0;
|
||||
if (tstCx(i, TIACxFlags.M0, TIACxFlags.P1)) { tabl[i] |= TIACxPairFlags.M0P1; }
|
||||
if (tstCx(i, TIACxFlags.M0, TIACxFlags.P0)) { tabl[i] |= TIACxPairFlags.M0P0; }
|
||||
if (tstCx(i, TIACxFlags.M1, TIACxFlags.P0)) { tabl[i] |= TIACxPairFlags.M1P0; }
|
||||
if (tstCx(i, TIACxFlags.M1, TIACxFlags.P1)) { tabl[i] |= TIACxPairFlags.M1P1; }
|
||||
if (tstCx(i, TIACxFlags.P0, TIACxFlags.PF)) { tabl[i] |= TIACxPairFlags.P0PF; }
|
||||
if (tstCx(i, TIACxFlags.P0, TIACxFlags.BL)) { tabl[i] |= TIACxPairFlags.P0BL; }
|
||||
if (tstCx(i, TIACxFlags.P1, TIACxFlags.PF)) { tabl[i] |= TIACxPairFlags.P1PF; }
|
||||
if (tstCx(i, TIACxFlags.P1, TIACxFlags.BL)) { tabl[i] |= TIACxPairFlags.P1BL; }
|
||||
if (tstCx(i, TIACxFlags.M0, TIACxFlags.PF)) { tabl[i] |= TIACxPairFlags.M0PF; }
|
||||
if (tstCx(i, TIACxFlags.M0, TIACxFlags.BL)) { tabl[i] |= TIACxPairFlags.M0BL; }
|
||||
if (tstCx(i, TIACxFlags.M1, TIACxFlags.PF)) { tabl[i] |= TIACxPairFlags.M1PF; }
|
||||
if (tstCx(i, TIACxFlags.M1, TIACxFlags.BL)) { tabl[i] |= TIACxPairFlags.M1BL; }
|
||||
if (tstCx(i, TIACxFlags.BL, TIACxFlags.PF)) { tabl[i] |= TIACxPairFlags.BLPF; }
|
||||
if (tstCx(i, TIACxFlags.P0, TIACxFlags.P1)) { tabl[i] |= TIACxPairFlags.P0P1; }
|
||||
if (tstCx(i, TIACxFlags.M0, TIACxFlags.M1)) { tabl[i] |= TIACxPairFlags.M0M1; }
|
||||
}
|
||||
return tabl;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -150,6 +150,7 @@ namespace BizHawk
|
|||
case ".MD":
|
||||
case ".SMD": Game.System = "GEN"; break;
|
||||
case ".A26": Game.System = "A26"; break;
|
||||
case ".A78": Game.System = "A78"; break;
|
||||
case ".COL": Game.System = "COLV"; break;
|
||||
case ".ROM":
|
||||
case ".INT": Game.System = "INTV"; break;
|
||||
|
|
|
@ -155,6 +155,7 @@ namespace BizHawk.MultiClient
|
|||
public string PathINTVGROM = Path.Combine(".", "grom.bin");
|
||||
public string PathINTVEROM = Path.Combine(".", "erom.bin");
|
||||
public string PathFDSBios = Path.Combine(".", "disksys.rom");
|
||||
public string PathAtari7800NTSCBIOS = Path.Combine("C:\\Repos", "7800NTSCBIOS.bin");
|
||||
|
||||
public string FFMpegPath = "%exe%/dll/ffmpeg.exe";
|
||||
|
||||
|
|
|
@ -1303,7 +1303,7 @@ namespace BizHawk.MultiClient
|
|||
if (path == null) return false;
|
||||
using (var file = new HawkFile())
|
||||
{
|
||||
string[] romExtensions = new string[] { "SMS", "SMC", "SFC", "PCE", "SGX", "GG", "SG", "BIN", "GEN", "MD", "SMD", "GB", "NES", "ROM", "INT", "GBC", "UNF" };
|
||||
string[] romExtensions = new string[] { "SMS", "SMC", "SFC", "PCE", "SGX", "GG", "SG", "BIN", "GEN", "MD", "SMD", "GB", "NES", "ROM", "INT", "GBC", "UNF", "A78" };
|
||||
|
||||
//lets not use this unless we need to
|
||||
//file.NonArchiveExtensions = romExtensions;
|
||||
|
@ -1571,6 +1571,13 @@ namespace BizHawk.MultiClient
|
|||
nextEmulator = intv;
|
||||
}
|
||||
break;
|
||||
case "A78":
|
||||
string biospath = Global.Config.PathAtari7800NTSCBIOS; //TODO
|
||||
byte[] BIOS7800 = File.ReadAllBytes(biospath);
|
||||
byte[] HighScoreBIOS = File.ReadAllBytes("C:\\Repos\\7800highscore.bin");
|
||||
Atari7800 a78 = new Atari7800(game, rom.RomData, BIOS7800, HighScoreBIOS);
|
||||
nextEmulator = a78;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue