2012-03-07 00:40:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2014-04-15 22:10:39 +00:00
|
|
|
|
using System.Linq;
|
2012-03-07 00:40:20 +00:00
|
|
|
|
|
2013-11-04 00:36:15 +00:00
|
|
|
|
using BizHawk.Common;
|
2014-07-03 19:20:34 +00:00
|
|
|
|
using BizHawk.Common.BufferExtensions;
|
2013-11-04 01:06:36 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2013-11-04 00:36:15 +00:00
|
|
|
|
|
2013-11-13 03:32:25 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
2012-03-07 00:40:20 +00:00
|
|
|
|
{
|
2014-04-25 01:19:57 +00:00
|
|
|
|
[CoreAttributes(
|
|
|
|
|
"Atari2600Hawk",
|
2014-06-04 19:06:36 +00:00
|
|
|
|
"Micro500, adelikat, natt",
|
2014-04-25 01:19:57 +00:00
|
|
|
|
isPorted: false,
|
|
|
|
|
isReleased: true
|
|
|
|
|
)]
|
2014-11-30 23:41:54 +00:00
|
|
|
|
[ServiceNotApplicable(typeof(ISaveRam))]
|
2014-11-30 20:29:30 +00:00
|
|
|
|
public partial class Atari2600 : IEmulator, IMemoryDomains, IStatable, IDebuggable, IInputPollable, ISettable<Atari2600.A2600Settings, Atari2600.A2600SyncSettings>
|
2012-03-07 00:40:20 +00:00
|
|
|
|
{
|
2014-04-05 14:13:05 +00:00
|
|
|
|
private readonly GameInfo _game;
|
|
|
|
|
private int _frame;
|
2012-03-30 00:35:15 +00:00
|
|
|
|
|
2014-08-23 19:06:37 +00:00
|
|
|
|
[CoreConstructor("A26")]
|
2014-04-05 14:13:05 +00:00
|
|
|
|
public Atari2600(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings)
|
2012-03-07 00:40:20 +00:00
|
|
|
|
{
|
2014-12-04 03:38:30 +00:00
|
|
|
|
ServiceProvider = new BasicServiceProvider(this);
|
2014-12-05 01:56:45 +00:00
|
|
|
|
Tracer = new TraceBuffer();
|
|
|
|
|
MemoryCallbacks = new MemoryCallbackSystem();
|
2014-12-04 00:43:12 +00:00
|
|
|
|
InputCallbacks = new InputCallbackSystem();
|
2014-12-05 01:56:45 +00:00
|
|
|
|
|
2014-04-05 14:13:05 +00:00
|
|
|
|
Ram = new byte[128];
|
2012-12-10 00:43:43 +00:00
|
|
|
|
CoreComm = comm;
|
2014-07-14 16:10:45 +00:00
|
|
|
|
Settings = (A2600Settings)settings ?? new A2600Settings();
|
|
|
|
|
SyncSettings = (A2600SyncSettings)syncSettings ?? new A2600SyncSettings();
|
2013-12-24 20:50:53 +00:00
|
|
|
|
|
2014-04-05 14:13:05 +00:00
|
|
|
|
Rom = rom;
|
|
|
|
|
_game = game;
|
2014-02-08 04:59:45 +00:00
|
|
|
|
|
|
|
|
|
if (!game.GetOptionsDict().ContainsKey("m"))
|
2014-04-02 21:07:55 +00:00
|
|
|
|
{
|
2014-04-04 19:46:41 +00:00
|
|
|
|
game.AddOption("m", DetectMapper(rom));
|
2014-04-02 21:07:55 +00:00
|
|
|
|
}
|
2014-02-08 04:59:45 +00:00
|
|
|
|
|
2012-03-30 00:35:15 +00:00
|
|
|
|
Console.WriteLine("Game uses mapper " + game.GetOptionsDict()["m"]);
|
2014-04-06 22:40:10 +00:00
|
|
|
|
RebootCore();
|
2014-09-01 20:12:45 +00:00
|
|
|
|
SetupMemoryDomains();
|
2012-03-07 00:40:20 +00:00
|
|
|
|
}
|
2013-11-11 03:20:33 +00:00
|
|
|
|
|
2014-12-04 03:38:30 +00:00
|
|
|
|
public IEmulatorServiceProvider ServiceProvider { get; private set; }
|
|
|
|
|
|
2014-04-05 14:13:05 +00:00
|
|
|
|
public string SystemId { get { return "A26"; } }
|
|
|
|
|
|
|
|
|
|
public string BoardName { get { return _mapper.GetType().Name; } }
|
|
|
|
|
|
|
|
|
|
public CoreComm CoreComm { get; private set; }
|
|
|
|
|
|
|
|
|
|
public IVideoProvider VideoProvider { get { return _tia; } }
|
|
|
|
|
|
|
|
|
|
public ISoundProvider SoundProvider { get { return _dcfilter; } }
|
|
|
|
|
|
2014-05-23 16:37:49 +00:00
|
|
|
|
// todo: make this not so ugly
|
|
|
|
|
public ISyncSoundProvider SyncSoundProvider
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new FakeSyncSound(_dcfilter, CoreComm.VsyncRate > 55.0 ? 735 : 882);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-05 14:13:05 +00:00
|
|
|
|
|
|
|
|
|
public ControllerDefinition ControllerDefinition { get { return Atari2600ControllerDefinition; } }
|
|
|
|
|
|
|
|
|
|
public IController Controller { get; set; }
|
|
|
|
|
|
|
|
|
|
public int Frame { get { return _frame; } set { _frame = value; } }
|
|
|
|
|
|
|
|
|
|
public bool DeterministicEmulation { get; set; }
|
|
|
|
|
|
|
|
|
|
public A2600Settings Settings { get; private set; }
|
|
|
|
|
|
|
|
|
|
public A2600SyncSettings SyncSettings { get; private set; }
|
|
|
|
|
|
|
|
|
|
public static readonly ControllerDefinition Atari2600ControllerDefinition = new ControllerDefinition
|
|
|
|
|
{
|
|
|
|
|
Name = "Atari 2600 Basic Controller",
|
|
|
|
|
BoolButtons =
|
|
|
|
|
{
|
|
|
|
|
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button",
|
|
|
|
|
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button",
|
2014-04-06 22:40:10 +00:00
|
|
|
|
"Reset", "Select", "Power"
|
2014-04-05 14:13:05 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-20 01:19:33 +00:00
|
|
|
|
public int CurrentScanLine
|
|
|
|
|
{
|
2014-05-27 02:45:05 +00:00
|
|
|
|
get { return _tia.LineCount; }
|
2014-04-20 01:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsVsync
|
|
|
|
|
{
|
|
|
|
|
get { return _tia.IsVSync; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsVBlank
|
|
|
|
|
{
|
|
|
|
|
get { return _tia.IsVBlank; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-15 22:10:39 +00:00
|
|
|
|
public CompactGameInfo GenerateGameDbEntry()
|
|
|
|
|
{
|
|
|
|
|
return new CompactGameInfo
|
|
|
|
|
{
|
|
|
|
|
Name = _game.Name,
|
|
|
|
|
System = "A26",
|
|
|
|
|
MetaData = "m=" + _mapper.GetType().ToString().Split('.').ToList().Last(),
|
2014-07-03 19:20:34 +00:00
|
|
|
|
Hash = Rom.HashSHA1(),
|
2014-04-15 22:10:39 +00:00
|
|
|
|
Region = _game.Region,
|
|
|
|
|
Status = RomStatus.Unknown
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 14:13:05 +00:00
|
|
|
|
public bool StartAsyncSound() { return true; }
|
|
|
|
|
|
|
|
|
|
public void EndAsyncSound() { }
|
|
|
|
|
|
2013-11-03 16:29:51 +00:00
|
|
|
|
public void ResetCounters()
|
2012-03-07 00:40:20 +00:00
|
|
|
|
{
|
2012-03-23 02:55:46 +00:00
|
|
|
|
_frame = 0;
|
2012-11-25 15:41:40 +00:00
|
|
|
|
_lagcount = 0;
|
|
|
|
|
_islag = false;
|
2012-03-07 00:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() { }
|
2014-05-21 14:32:41 +00:00
|
|
|
|
|
|
|
|
|
private static bool DetectPal(GameInfo game, byte[] rom)
|
|
|
|
|
{
|
2014-05-23 15:47:48 +00:00
|
|
|
|
// force NTSC mode for the new core we instantiate
|
|
|
|
|
var newgame = game.Clone();
|
|
|
|
|
if (newgame["PAL"])
|
|
|
|
|
newgame.RemoveOption("PAL");
|
|
|
|
|
if (!newgame["NTSC"])
|
|
|
|
|
newgame.AddOption("NTSC");
|
|
|
|
|
|
2014-05-21 15:47:18 +00:00
|
|
|
|
// give the emu a minimal of input\output connections so it doesn't crash
|
2014-05-21 14:32:41 +00:00
|
|
|
|
var comm = new CoreComm(null, null);
|
2014-12-04 00:43:12 +00:00
|
|
|
|
|
2014-05-23 15:47:48 +00:00
|
|
|
|
using (Atari2600 emu = new Atari2600(new CoreComm(null, null), newgame, rom, null, null))
|
2014-05-21 15:47:18 +00:00
|
|
|
|
{
|
|
|
|
|
emu.Controller = new NullController();
|
|
|
|
|
|
|
|
|
|
List<int> framecounts = new List<int>();
|
|
|
|
|
emu._tia.FrameEndCallBack = (i) => framecounts.Add(i);
|
|
|
|
|
for (int i = 0; i < 71; i++) // run for 71 * 262 lines, since we're in NTSC mode
|
|
|
|
|
emu.FrameAdvance(false, false);
|
|
|
|
|
int numpal = framecounts.Count((i) => i > 287);
|
2014-05-23 15:47:48 +00:00
|
|
|
|
bool pal = numpal >= 25;
|
|
|
|
|
Console.WriteLine("PAL Detection: {0} lines, {1}", numpal, pal);
|
|
|
|
|
return pal;
|
2014-05-21 15:47:18 +00:00
|
|
|
|
}
|
2014-05-21 14:32:41 +00:00
|
|
|
|
}
|
2012-03-07 00:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|