2012-03-07 00:40:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-04-15 22:10:39 +00:00
|
|
|
|
using System.Linq;
|
2012-03-07 00:40:20 +00:00
|
|
|
|
|
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",
|
2017-05-05 16:56:28 +00:00
|
|
|
|
"Micro500, Alyosha, adelikat, natt",
|
2014-04-25 01:19:57 +00:00
|
|
|
|
isPorted: false,
|
2017-04-24 15:09:17 +00:00
|
|
|
|
isReleased: true)]
|
2014-12-12 01:58:12 +00:00
|
|
|
|
[ServiceNotApplicable(typeof(ISaveRam), typeof(IDriveLight))]
|
2017-05-01 02:01:37 +00:00
|
|
|
|
public partial class Atari2600 : IEmulator, IStatable, IDebuggable, IInputPollable, IBoardInfo,
|
2016-12-15 16:45:20 +00:00
|
|
|
|
IRegionable, ICreateGameDBEntries, ISettable<Atari2600.A2600Settings, Atari2600.A2600SyncSettings>
|
2012-03-07 00:40:20 +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
|
|
|
|
{
|
2015-01-15 15:56:41 +00:00
|
|
|
|
var ser = new BasicServiceProvider(this);
|
|
|
|
|
ServiceProvider = ser;
|
|
|
|
|
|
2017-05-05 17:26:15 +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
|
|
|
|
|
2017-06-27 20:14:41 +00:00
|
|
|
|
_controllerDeck = new Atari2600ControllerDeck(SyncSettings.Port1, SyncSettings.Port2);
|
|
|
|
|
|
2016-11-11 21:28:21 +00:00
|
|
|
|
_leftDifficultySwitchPressed = SyncSettings.LeftDifficulty;
|
|
|
|
|
_rightDifficultySwitchPressed = SyncSettings.RightDifficulty;
|
|
|
|
|
|
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
|
|
|
|
|
2016-11-11 21:28:21 +00:00
|
|
|
|
if (Rom.HashSHA1() == "3A77DB43B6583E8689435F0F14AA04B9E57BDDED" ||
|
|
|
|
|
Rom.HashSHA1() == "E986E1818E747BEB9B33CE4DFF1CDC6B55BDB620")
|
|
|
|
|
{
|
|
|
|
|
game.RemoveOption("m");
|
|
|
|
|
game.AddOption("m", "F8_sega");
|
|
|
|
|
}
|
2016-05-20 13:06:56 +00:00
|
|
|
|
|
2016-11-11 21:28:21 +00:00
|
|
|
|
Console.WriteLine("Game uses mapper " + game.GetOptionsDict()["m"]);
|
|
|
|
|
Console.WriteLine(Rom.HashSHA1());
|
|
|
|
|
RebootCore();
|
2014-09-01 20:12:45 +00:00
|
|
|
|
SetupMemoryDomains();
|
2014-12-15 22:52:22 +00:00
|
|
|
|
|
2016-02-28 14:20:08 +00:00
|
|
|
|
Tracer = new TraceBuffer { Header = Cpu.TraceHeader };
|
|
|
|
|
|
2014-12-15 22:52:22 +00:00
|
|
|
|
ser.Register<IDisassemblable>(Cpu);
|
2014-12-23 01:58:12 +00:00
|
|
|
|
ser.Register<ITraceable>(Tracer);
|
2015-01-14 22:37:37 +00:00
|
|
|
|
ser.Register<IVideoProvider>(_tia);
|
2016-12-11 17:14:42 +00:00
|
|
|
|
ser.Register<ISoundProvider>(_dcfilter);
|
2012-03-07 00:40:20 +00:00
|
|
|
|
}
|
2013-11-11 03:20:33 +00:00
|
|
|
|
|
2017-06-27 20:14:41 +00:00
|
|
|
|
private readonly Atari2600ControllerDeck _controllerDeck;
|
|
|
|
|
|
2017-05-05 16:56:28 +00:00
|
|
|
|
// IRegionable
|
2017-04-24 15:09:17 +00:00
|
|
|
|
public DisplayType Region => _pal ? DisplayType.PAL : DisplayType.NTSC;
|
2015-08-06 00:12:09 +00:00
|
|
|
|
|
2017-05-05 16:56:28 +00:00
|
|
|
|
// ITraceable
|
|
|
|
|
private ITraceable Tracer { get; }
|
2014-04-05 14:13:05 +00:00
|
|
|
|
|
2016-12-15 16:45:20 +00:00
|
|
|
|
// ICreateGameDBEntries
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-01 02:01:37 +00:00
|
|
|
|
// IBoardInfo
|
|
|
|
|
public string BoardName => _mapper.GetType().Name;
|
|
|
|
|
|
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"])
|
2017-05-05 16:56:28 +00:00
|
|
|
|
{
|
2014-05-23 15:47:48 +00:00
|
|
|
|
newgame.RemoveOption("PAL");
|
2017-05-05 16:56:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-23 15:47:48 +00:00
|
|
|
|
if (!newgame["NTSC"])
|
2017-05-05 16:56:28 +00:00
|
|
|
|
{
|
2014-05-23 15:47:48 +00:00
|
|
|
|
newgame.AddOption("NTSC");
|
2017-05-05 16:56:28 +00:00
|
|
|
|
}
|
2014-05-23 15:47:48 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
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
|
2017-05-02 01:09:11 +00:00
|
|
|
|
{
|
|
|
|
|
emu.FrameAdvance(NullController.Instance, false, false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 15:47:18 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|