2012-07-08 04:20:53 +00:00
|
|
|
|
using System;
|
2013-11-04 01:06:36 +00:00
|
|
|
|
|
|
|
|
|
using BizHawk.Emulation.Common;
|
2014-01-22 01:14:36 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Components.CP1610;
|
2012-07-08 04:20:53 +00:00
|
|
|
|
|
2013-11-13 03:32:25 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.Intellivision
|
2012-07-08 04:20:53 +00:00
|
|
|
|
{
|
2014-04-25 01:19:57 +00:00
|
|
|
|
[CoreAttributes(
|
|
|
|
|
"IntelliHawk",
|
2017-02-18 21:01:09 +00:00
|
|
|
|
"BrandonE, Alyosha",
|
2014-04-25 01:19:57 +00:00
|
|
|
|
isPorted: false,
|
2017-02-18 21:01:09 +00:00
|
|
|
|
isReleased: true
|
2014-04-25 01:19:57 +00:00
|
|
|
|
)]
|
2017-04-23 16:10:26 +00:00
|
|
|
|
[ServiceNotApplicable(typeof(ISaveRam), typeof(IDriveLight), typeof(IRegionable))]
|
2017-04-23 17:21:42 +00:00
|
|
|
|
public sealed partial class Intellivision : IEmulator, IStatable, IInputPollable, IDisassemblable,
|
2017-04-23 16:46:37 +00:00
|
|
|
|
IDebuggable, ISettable<Intellivision.IntvSettings, Intellivision.IntvSyncSettings>
|
2012-07-15 08:38:50 +00:00
|
|
|
|
{
|
2015-06-18 16:44:30 +00:00
|
|
|
|
[CoreConstructor("INTV")]
|
2016-12-03 23:44:25 +00:00
|
|
|
|
public Intellivision(CoreComm comm, GameInfo game, byte[] rom, object Settings, object SyncSettings)
|
2015-06-18 16:44:30 +00:00
|
|
|
|
{
|
2017-04-23 16:10:26 +00:00
|
|
|
|
var ser = new BasicServiceProvider(this);
|
|
|
|
|
ServiceProvider = ser;
|
|
|
|
|
|
2015-06-18 16:44:30 +00:00
|
|
|
|
CoreComm = comm;
|
|
|
|
|
|
|
|
|
|
_rom = rom;
|
|
|
|
|
_gameInfo = game;
|
2016-12-03 23:44:25 +00:00
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_settings = (IntvSettings)Settings ?? new IntvSettings();
|
|
|
|
|
_syncSettings = (IntvSyncSettings)SyncSettings ?? new IntvSyncSettings();
|
2016-12-03 23:44:25 +00:00
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
ControllerDeck = new IntellivisionControllerDeck(_syncSettings.Port1, _syncSettings.Port2);
|
2016-12-03 23:44:25 +00:00
|
|
|
|
|
2015-06-18 16:44:30 +00:00
|
|
|
|
_cart = new Intellicart();
|
|
|
|
|
if (_cart.Parse(_rom) == -1)
|
|
|
|
|
{
|
|
|
|
|
_cart = new Cartridge();
|
|
|
|
|
_cart.Parse(_rom);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_cpu = new CP1610
|
|
|
|
|
{
|
|
|
|
|
ReadMemory = ReadMemory,
|
2017-04-23 18:28:40 +00:00
|
|
|
|
WriteMemory = WriteMemory,
|
|
|
|
|
MemoryCallbacks = MemoryCallbacks
|
2017-04-23 16:10:26 +00:00
|
|
|
|
};
|
2015-06-18 16:44:30 +00:00
|
|
|
|
_cpu.Reset();
|
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_stic = new STIC
|
|
|
|
|
{
|
|
|
|
|
ReadMemory = ReadMemory,
|
|
|
|
|
WriteMemory = WriteMemory
|
|
|
|
|
};
|
2015-06-18 16:44:30 +00:00
|
|
|
|
_stic.Reset();
|
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_psg = new PSG
|
|
|
|
|
{
|
|
|
|
|
ReadMemory = ReadMemory,
|
|
|
|
|
WriteMemory = WriteMemory
|
|
|
|
|
};
|
2016-12-10 04:00:40 +00:00
|
|
|
|
_psg.Reset();
|
2017-04-23 16:10:26 +00:00
|
|
|
|
|
|
|
|
|
ser.Register<IVideoProvider>(_stic);
|
|
|
|
|
ser.Register<ISoundProvider>(_psg);
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
Connect();
|
|
|
|
|
|
|
|
|
|
LoadExecutiveRom(CoreComm.CoreFileProvider.GetFirmware("INTV", "EROM", true, "Executive ROM is required."));
|
|
|
|
|
LoadGraphicsRom(CoreComm.CoreFileProvider.GetFirmware("INTV", "GROM", true, "Graphics ROM is required."));
|
2016-11-11 22:17:35 +00:00
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_tracer = new TraceBuffer { Header = _cpu.TraceHeader };
|
|
|
|
|
ser.Register<ITraceable>(_tracer);
|
2016-11-12 20:08:05 +00:00
|
|
|
|
|
|
|
|
|
SetupMemoryDomains();
|
2015-06-18 16:44:30 +00:00
|
|
|
|
}
|
2012-07-15 08:38:50 +00:00
|
|
|
|
|
2016-12-03 23:44:25 +00:00
|
|
|
|
public IntellivisionControllerDeck ControllerDeck { get; private set; }
|
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
private readonly byte[] _rom;
|
|
|
|
|
private readonly GameInfo _gameInfo;
|
|
|
|
|
private readonly ITraceable _tracer;
|
|
|
|
|
private readonly CP1610 _cpu;
|
|
|
|
|
private readonly STIC _stic;
|
|
|
|
|
private readonly PSG _psg;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
private ICart _cart;
|
2017-04-23 15:53:26 +00:00
|
|
|
|
private int _frame;
|
2017-04-23 16:10:26 +00:00
|
|
|
|
private int _sticRow;
|
2017-04-23 15:53:26 +00:00
|
|
|
|
|
2012-08-14 03:58:11 +00:00
|
|
|
|
public void Connect()
|
2012-08-13 08:10:15 +00:00
|
|
|
|
{
|
2015-06-18 16:44:30 +00:00
|
|
|
|
_cpu.SetIntRM(_stic.GetSr1());
|
|
|
|
|
_cpu.SetBusRq(_stic.GetSr2());
|
|
|
|
|
_stic.SetSst(_cpu.GetBusAk());
|
2012-08-13 08:10:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 23:07:48 +00:00
|
|
|
|
public void LoadExecutiveRom(byte[] erom)
|
2012-07-19 00:05:08 +00:00
|
|
|
|
{
|
2012-12-17 04:23:59 +00:00
|
|
|
|
if (erom.Length != 8192)
|
|
|
|
|
{
|
|
|
|
|
throw new ApplicationException("EROM file is wrong size - expected 8192 bytes");
|
|
|
|
|
}
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
2012-07-19 00:05:08 +00:00
|
|
|
|
int index = 0;
|
2017-04-23 16:10:26 +00:00
|
|
|
|
|
2012-07-19 00:05:08 +00:00
|
|
|
|
// Combine every two bytes into a word.
|
|
|
|
|
while (index + 1 < erom.Length)
|
2012-12-17 04:23:59 +00:00
|
|
|
|
{
|
2012-08-10 20:40:34 +00:00
|
|
|
|
ExecutiveRom[index / 2] = (ushort)((erom[index++] << 8) | erom[index++]);
|
2012-12-17 04:23:59 +00:00
|
|
|
|
}
|
2012-07-19 00:05:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 23:07:48 +00:00
|
|
|
|
public void LoadGraphicsRom(byte[] grom)
|
2012-07-19 00:05:08 +00:00
|
|
|
|
{
|
2015-02-05 23:07:48 +00:00
|
|
|
|
if (grom.Length != 2048)
|
2012-12-17 04:23:59 +00:00
|
|
|
|
{
|
|
|
|
|
throw new ApplicationException("GROM file is wrong size - expected 2048 bytes");
|
|
|
|
|
}
|
2012-07-15 08:38:50 +00:00
|
|
|
|
|
2015-06-18 16:44:30 +00:00
|
|
|
|
GraphicsRom = grom;
|
2012-07-15 08:38:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
private void GetControllerState()
|
2016-12-03 23:44:25 +00:00
|
|
|
|
{
|
2016-12-20 01:20:10 +00:00
|
|
|
|
InputCallbacks.Call();
|
|
|
|
|
|
2016-12-03 23:44:25 +00:00
|
|
|
|
ushort port1 = ControllerDeck.ReadPort1(Controller);
|
2016-12-10 23:56:35 +00:00
|
|
|
|
_psg.Register[15] = (ushort)(0xFF - port1);
|
2016-12-03 23:44:25 +00:00
|
|
|
|
|
|
|
|
|
ushort port2 = ControllerDeck.ReadPort2(Controller);
|
2016-12-10 23:56:35 +00:00
|
|
|
|
_psg.Register[14] = (ushort)(0xFF - port2);
|
2016-12-03 23:44:25 +00:00
|
|
|
|
}
|
2017-03-05 23:45:32 +00:00
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
private void HardReset()
|
2017-03-05 23:45:32 +00:00
|
|
|
|
{
|
|
|
|
|
_cpu.Reset();
|
|
|
|
|
_stic.Reset();
|
|
|
|
|
_psg.Reset();
|
|
|
|
|
|
|
|
|
|
Connect();
|
|
|
|
|
|
|
|
|
|
ScratchpadRam = new byte[240];
|
|
|
|
|
SystemRam = new ushort[352];
|
|
|
|
|
|
|
|
|
|
_cart = new Intellicart();
|
|
|
|
|
if (_cart.Parse(_rom) == -1)
|
|
|
|
|
{
|
|
|
|
|
_cart = new Cartridge();
|
|
|
|
|
_cart.Parse(_rom);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
private void SoftReset()
|
2017-03-05 23:45:32 +00:00
|
|
|
|
{
|
|
|
|
|
_cpu.Reset();
|
|
|
|
|
_stic.Reset();
|
|
|
|
|
_psg.Reset();
|
|
|
|
|
|
|
|
|
|
Connect();
|
|
|
|
|
}
|
2012-07-15 08:38:50 +00:00
|
|
|
|
}
|
2016-11-12 21:09:51 +00:00
|
|
|
|
}
|