2012-03-07 00:40:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk
|
|
|
|
|
{
|
|
|
|
|
public partial class Atari2600 : IEmulator, IVideoProvider, ISoundProvider
|
|
|
|
|
{
|
|
|
|
|
public string SystemId { get { return "A26"; } }
|
2012-03-30 00:35:15 +00:00
|
|
|
|
public GameInfo game;
|
2012-03-07 00:40:20 +00:00
|
|
|
|
|
2012-03-16 07:24:00 +00:00
|
|
|
|
public int[] frameBuffer = new int[320 * 262];
|
2012-03-07 00:40:20 +00:00
|
|
|
|
public CoreInputComm CoreInputComm { get; set; }
|
|
|
|
|
public CoreOutputComm CoreOutputComm { get; private set; }
|
|
|
|
|
public IVideoProvider VideoProvider { get { return this; } }
|
|
|
|
|
public ISoundProvider SoundProvider { get { return this; } }
|
2012-03-30 00:35:15 +00:00
|
|
|
|
|
2012-03-07 00:40:20 +00:00
|
|
|
|
public Atari2600(GameInfo game, byte[] rom)
|
|
|
|
|
{
|
|
|
|
|
var domains = new List<MemoryDomain>(1);
|
2012-03-21 02:57:26 +00:00
|
|
|
|
domains.Add(new MemoryDomain("Main RAM", 128, Endian.Little, addr => ram[addr & 127], (addr, value) => ram[addr & 127] = value));
|
2012-03-07 00:40:20 +00:00
|
|
|
|
memoryDomains = domains.AsReadOnly();
|
|
|
|
|
CoreOutputComm = new CoreOutputComm();
|
|
|
|
|
CoreInputComm = new CoreInputComm();
|
|
|
|
|
this.rom = rom;
|
2012-03-30 00:35:15 +00:00
|
|
|
|
this.game = game;
|
|
|
|
|
Console.WriteLine("Game uses mapper " + game.GetOptionsDict()["m"]);
|
2012-03-07 00:40:20 +00:00
|
|
|
|
HardReset();
|
|
|
|
|
}
|
|
|
|
|
public void ResetFrameCounter()
|
|
|
|
|
{
|
2012-03-23 02:55:46 +00:00
|
|
|
|
_frame = 0;
|
2012-03-07 00:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly ControllerDefinition Atari2600ControllerDefinition = new ControllerDefinition
|
|
|
|
|
{
|
|
|
|
|
Name = "Atari 2600 Basic Controller",
|
|
|
|
|
BoolButtons =
|
|
|
|
|
{
|
2012-03-22 06:33:28 +00:00
|
|
|
|
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button",
|
|
|
|
|
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button",
|
|
|
|
|
"Reset",
|
2012-03-07 00:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void SyncState(Serializer ser)
|
|
|
|
|
{
|
|
|
|
|
cpu.SyncState(ser);
|
|
|
|
|
ser.Sync("ram", ref ram, false);
|
2012-03-23 02:55:46 +00:00
|
|
|
|
ser.Sync("Lag", ref _lagcount);
|
|
|
|
|
ser.Sync("Frame", ref _frame);
|
2012-03-30 02:34:47 +00:00
|
|
|
|
tia.SyncState(ser);
|
|
|
|
|
m6532.SyncState(ser);
|
2012-03-30 00:35:15 +00:00
|
|
|
|
mapper.SyncState(ser);
|
2012-03-07 00:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ControllerDefinition ControllerDefinition { get { return Atari2600ControllerDefinition; } }
|
|
|
|
|
public IController Controller { get; set; }
|
|
|
|
|
|
2012-03-23 02:55:46 +00:00
|
|
|
|
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;
|
2012-03-07 00:40:20 +00:00
|
|
|
|
|
|
|
|
|
public byte[] SaveRam { get { return new byte[0]; } }
|
|
|
|
|
public bool DeterministicEmulation { get; set; }
|
|
|
|
|
public bool SaveRamModified { get; set; }
|
|
|
|
|
public void SaveStateText(TextWriter writer) { SyncState(Serializer.CreateTextWriter(writer)); }
|
|
|
|
|
public void LoadStateText(TextReader reader) { SyncState(Serializer.CreateTextReader(reader)); }
|
|
|
|
|
public void SaveStateBinary(BinaryWriter bw) { SyncState(Serializer.CreateBinaryWriter(bw)); }
|
|
|
|
|
public void LoadStateBinary(BinaryReader br) { SyncState(Serializer.CreateBinaryReader(br)); }
|
|
|
|
|
|
|
|
|
|
public byte[] SaveStateBinary()
|
|
|
|
|
{
|
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
|
|
BinaryWriter bw = new BinaryWriter(ms);
|
|
|
|
|
SaveStateBinary(bw);
|
|
|
|
|
bw.Flush();
|
|
|
|
|
return ms.ToArray();
|
|
|
|
|
}
|
|
|
|
|
public int[] GetVideoBuffer() { return frameBuffer; }
|
2012-03-10 00:26:54 +00:00
|
|
|
|
public int BufferWidth { get { return 320; } }
|
2012-03-10 04:53:23 +00:00
|
|
|
|
public int BufferHeight { get { return 262; } }
|
2012-03-07 00:40:20 +00:00
|
|
|
|
public int BackgroundColor { get { return 0; } }
|
2012-03-15 20:34:14 +00:00
|
|
|
|
public void GetSamples(short[] samples)
|
|
|
|
|
{
|
2012-03-16 07:24:00 +00:00
|
|
|
|
/*
|
2012-03-15 20:34:14 +00:00
|
|
|
|
int freqDiv = 0;
|
|
|
|
|
byte myP4 = 0x00;
|
|
|
|
|
|
|
|
|
|
short[] moreSamples = new short[1000];
|
|
|
|
|
for (int i = 0; i < 1000; i++)
|
|
|
|
|
{
|
|
|
|
|
if (++freqDiv == (tia.audioFreqDiv * 2))
|
|
|
|
|
{
|
|
|
|
|
freqDiv = 0;
|
|
|
|
|
myP4 = (byte)(((myP4 & 0x0f) != 0) ? ((myP4 << 1) | ((((myP4 & 0x08) != 0) ? 1 : 0) ^ (((myP4 & 0x04) != 0) ? 1 : 0))) : 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moreSamples[i] = (short)(((myP4 & 0x08) != 0) ? 32767 : 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < samples.Length/2; i++)
|
|
|
|
|
{
|
|
|
|
|
//samples[i] = 0;
|
|
|
|
|
if (tia.audioEnabled)
|
|
|
|
|
{
|
|
|
|
|
samples[i*2] = moreSamples[(int)(((double)moreSamples.Length / (double)(samples.Length/2)) * i)];
|
|
|
|
|
//samples[i * 2 + 1] = moreSamples[(int)((moreSamples.Length / (samples.Length / 2)) * i)];
|
|
|
|
|
//samples[i] = (short)(Math.Sin(((((32000.0 / (tia.audioFreqDiv+1)) / 60.0) * Math.PI) / samples.Length) * i) * MaxVolume + MaxVolume);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
samples[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//samples = tia.samples;
|
2012-03-16 07:24:00 +00:00
|
|
|
|
* */
|
2012-03-15 20:34:14 +00:00
|
|
|
|
}
|
2012-03-07 00:40:20 +00:00
|
|
|
|
public void DiscardSamples() { }
|
|
|
|
|
public int MaxVolume { get; set; }
|
|
|
|
|
private IList<MemoryDomain> memoryDomains;
|
|
|
|
|
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
|
|
|
|
|
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
|
|
|
|
|
public void Dispose() { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|