2015-06-18 16:44:30 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Cores.Intellivision
|
|
|
|
|
{
|
2017-05-01 02:01:37 +00:00
|
|
|
|
public sealed partial class Intellivision : IEmulator, IBoardInfo
|
2015-06-18 16:44:30 +00:00
|
|
|
|
{
|
2017-04-10 16:24:53 +00:00
|
|
|
|
public IEmulatorServiceProvider ServiceProvider { get; }
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
2017-04-24 17:24:56 +00:00
|
|
|
|
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
2019-01-06 20:05:29 +00:00
|
|
|
|
public bool FrameAdvance(IController controller, bool render, bool rendersound)
|
2015-06-18 16:44:30 +00:00
|
|
|
|
{
|
2017-04-23 16:10:26 +00:00
|
|
|
|
if (_tracer.Enabled)
|
2017-04-10 16:24:53 +00:00
|
|
|
|
{
|
2017-04-24 17:24:56 +00:00
|
|
|
|
_cpu.TraceCallback = s => _tracer.Put(s);
|
2017-04-10 16:24:53 +00:00
|
|
|
|
}
|
2016-11-11 22:17:35 +00:00
|
|
|
|
else
|
2017-04-10 16:24:53 +00:00
|
|
|
|
{
|
2016-11-11 22:17:35 +00:00
|
|
|
|
_cpu.TraceCallback = null;
|
2017-04-10 16:24:53 +00:00
|
|
|
|
}
|
2016-11-11 22:17:35 +00:00
|
|
|
|
|
2016-12-06 03:00:47 +00:00
|
|
|
|
_frame++;
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_sticRow = -1;
|
2017-04-10 16:24:53 +00:00
|
|
|
|
|
2016-11-11 21:47:55 +00:00
|
|
|
|
// read the controller state here for now
|
2017-05-02 01:09:11 +00:00
|
|
|
|
GetControllerState(controller);
|
2016-12-06 02:51:12 +00:00
|
|
|
|
|
2016-12-13 21:45:30 +00:00
|
|
|
|
// this timer tracks cycles stolen by the STIC during the visible part of the frame, quite a large number of them actually
|
2017-04-24 17:24:56 +00:00
|
|
|
|
int delayCycles = 700;
|
|
|
|
|
int delayTimer = -1;
|
2016-12-22 02:43:33 +00:00
|
|
|
|
|
2017-04-10 16:24:53 +00:00
|
|
|
|
_cpu.PendingCycles = 14934 - 3791 + _cpu.GetPendingCycles();
|
2016-11-15 15:28:09 +00:00
|
|
|
|
_stic.Sr1 = true;
|
2017-04-23 15:53:26 +00:00
|
|
|
|
_islag = true;
|
2016-11-15 15:28:09 +00:00
|
|
|
|
|
2017-04-24 17:24:56 +00:00
|
|
|
|
bool activeDisplay = _stic.active_display;
|
2016-12-24 14:14:24 +00:00
|
|
|
|
|
2017-04-10 16:24:53 +00:00
|
|
|
|
// also at the start of every frame the color stack is reset
|
2016-12-24 20:01:41 +00:00
|
|
|
|
_stic.ColorSP = 0x0028;
|
|
|
|
|
|
2015-06-18 16:44:30 +00:00
|
|
|
|
while (_cpu.GetPendingCycles() > 0)
|
|
|
|
|
{
|
|
|
|
|
int cycles = _cpu.Execute();
|
2016-12-06 02:51:12 +00:00
|
|
|
|
_psg.generate_sound(cycles);
|
2016-12-13 21:45:30 +00:00
|
|
|
|
|
2017-04-24 17:24:56 +00:00
|
|
|
|
if (delayCycles >= 0 && activeDisplay)
|
|
|
|
|
{
|
|
|
|
|
delayCycles += cycles;
|
|
|
|
|
}
|
2016-12-13 21:45:30 +00:00
|
|
|
|
|
2017-04-24 17:24:56 +00:00
|
|
|
|
if (delayTimer > 0 && activeDisplay)
|
2016-12-13 21:45:30 +00:00
|
|
|
|
{
|
2017-04-24 17:24:56 +00:00
|
|
|
|
delayTimer -= cycles;
|
|
|
|
|
if (delayTimer <= 0)
|
2016-12-13 21:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
_stic.ToggleSr2();
|
2017-04-24 17:24:56 +00:00
|
|
|
|
delayCycles = 0;
|
2016-12-13 21:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 17:24:56 +00:00
|
|
|
|
if (delayCycles >= 750 && activeDisplay)
|
2016-12-13 21:45:30 +00:00
|
|
|
|
{
|
2017-04-24 17:24:56 +00:00
|
|
|
|
delayCycles = -1;
|
|
|
|
|
delayTimer = 110;
|
2016-12-13 21:45:30 +00:00
|
|
|
|
_stic.ToggleSr2();
|
2017-04-23 16:10:26 +00:00
|
|
|
|
if (_sticRow >= 0)
|
2016-12-24 01:07:12 +00:00
|
|
|
|
{
|
|
|
|
|
_stic.in_vb_2 = true;
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_stic.Background(_sticRow);
|
2016-12-24 01:07:12 +00:00
|
|
|
|
_stic.in_vb_2 = false;
|
2017-04-10 16:24:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 16:10:26 +00:00
|
|
|
|
_sticRow++;
|
2016-12-13 21:45:30 +00:00
|
|
|
|
}
|
2017-04-24 17:24:56 +00:00
|
|
|
|
|
2015-06-18 16:44:30 +00:00
|
|
|
|
Connect();
|
|
|
|
|
}
|
2016-11-11 21:47:55 +00:00
|
|
|
|
|
2016-12-23 02:07:31 +00:00
|
|
|
|
// set up VBlank variables
|
|
|
|
|
_stic.in_vb_1 = true;
|
|
|
|
|
_stic.in_vb_2 = true;
|
2016-11-15 15:28:09 +00:00
|
|
|
|
|
2016-12-23 02:07:31 +00:00
|
|
|
|
if (_stic.active_display)
|
|
|
|
|
{
|
|
|
|
|
_stic.Mobs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_stic.active_display = false;
|
2016-12-06 02:51:12 +00:00
|
|
|
|
_stic.Sr1 = false;
|
2016-12-22 02:43:33 +00:00
|
|
|
|
|
2017-04-10 16:24:53 +00:00
|
|
|
|
_cpu.PendingCycles = 3000 + _cpu.GetPendingCycles();
|
2016-12-23 02:07:31 +00:00
|
|
|
|
|
|
|
|
|
while (_cpu.GetPendingCycles() > 0)
|
|
|
|
|
{
|
|
|
|
|
int cycles = _cpu.Execute();
|
2017-02-07 16:31:05 +00:00
|
|
|
|
_psg.generate_sound(cycles);
|
2016-12-23 02:07:31 +00:00
|
|
|
|
Connect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// vblank phase 2
|
2017-04-10 16:24:53 +00:00
|
|
|
|
_cpu.PendingCycles = 791 + _cpu.GetPendingCycles();
|
2016-12-23 02:07:31 +00:00
|
|
|
|
_stic.in_vb_1 = false;
|
2016-12-06 02:51:12 +00:00
|
|
|
|
|
2016-11-15 15:28:09 +00:00
|
|
|
|
while (_cpu.GetPendingCycles() > 0)
|
|
|
|
|
{
|
|
|
|
|
int cycles = _cpu.Execute();
|
2017-02-07 16:31:05 +00:00
|
|
|
|
_psg.generate_sound(cycles);
|
2016-11-15 15:28:09 +00:00
|
|
|
|
Connect();
|
|
|
|
|
}
|
2017-04-24 17:24:56 +00:00
|
|
|
|
|
2016-12-23 02:07:31 +00:00
|
|
|
|
_stic.in_vb_2 = false;
|
2016-11-15 15:28:09 +00:00
|
|
|
|
|
2017-04-23 15:53:26 +00:00
|
|
|
|
if (_islag)
|
2017-04-24 17:24:56 +00:00
|
|
|
|
{
|
2017-04-23 15:53:26 +00:00
|
|
|
|
_lagcount++;
|
2017-04-24 17:24:56 +00:00
|
|
|
|
}
|
2017-03-05 23:45:32 +00:00
|
|
|
|
|
2017-05-02 01:09:11 +00:00
|
|
|
|
if (controller.IsPressed("Power"))
|
2017-04-24 17:24:56 +00:00
|
|
|
|
{
|
2017-03-05 23:45:32 +00:00
|
|
|
|
HardReset();
|
2017-04-24 17:24:56 +00:00
|
|
|
|
}
|
2017-03-05 23:45:32 +00:00
|
|
|
|
|
2017-05-02 01:09:11 +00:00
|
|
|
|
if (controller.IsPressed("Reset"))
|
2017-04-24 17:24:56 +00:00
|
|
|
|
{
|
2017-03-05 23:45:32 +00:00
|
|
|
|
SoftReset();
|
2017-04-24 17:24:56 +00:00
|
|
|
|
}
|
2019-01-06 20:05:29 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 16:24:53 +00:00
|
|
|
|
public int Frame => _frame;
|
|
|
|
|
|
2017-04-15 20:37:30 +00:00
|
|
|
|
public string SystemId => "INTV";
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
2017-04-15 20:37:30 +00:00
|
|
|
|
public bool DeterministicEmulation => true;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
2017-04-15 20:37:30 +00:00
|
|
|
|
public void ResetCounters()
|
2015-06-18 16:44:30 +00:00
|
|
|
|
{
|
2016-12-04 14:25:17 +00:00
|
|
|
|
_frame = 0;
|
2017-04-23 15:53:26 +00:00
|
|
|
|
_lagcount = 0;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 16:24:53 +00:00
|
|
|
|
public CoreComm CoreComm { get; }
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-05-01 02:01:37 +00:00
|
|
|
|
|
|
|
|
|
// IBoardInfo
|
|
|
|
|
public string BoardName => _cart.BoardName;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
}
|
2016-12-03 23:44:25 +00:00
|
|
|
|
}
|