BizHawk/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs

152 lines
2.9 KiB
C#
Raw Normal View History

2015-06-18 16:44:30 +00:00
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Intellivision
{
public sealed partial class Intellivision : IEmulator
{
public IEmulatorServiceProvider ServiceProvider { get; }
2015-06-18 16:44:30 +00:00
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
2015-06-18 16:44:30 +00:00
public IController Controller { private get; set; }
2015-06-18 16:44:30 +00:00
public void FrameAdvance(bool render, bool rendersound)
{
2017-04-23 16:10:26 +00:00
if (_tracer.Enabled)
{
_cpu.TraceCallback = s => _tracer.Put(s);
}
else
{
_cpu.TraceCallback = null;
}
2016-12-06 03:00:47 +00:00
_frame++;
2017-04-23 16:10:26 +00:00
_sticRow = -1;
// read the controller state here for now
2017-04-23 16:10:26 +00:00
GetControllerState();
// this timer tracks cycles stolen by the STIC during the visible part of the frame, quite a large number of them actually
int delayCycles = 700;
int delayTimer = -1;
2016-12-22 02:43:33 +00:00
_cpu.PendingCycles = 14934 - 3791 + _cpu.GetPendingCycles();
2016-11-15 15:28:09 +00:00
_stic.Sr1 = true;
_islag = true;
2016-11-15 15:28:09 +00:00
bool activeDisplay = _stic.active_display;
2016-12-24 14:14:24 +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();
_psg.generate_sound(cycles);
if (delayCycles >= 0 && activeDisplay)
{
delayCycles += cycles;
}
if (delayTimer > 0 && activeDisplay)
{
delayTimer -= cycles;
if (delayTimer <= 0)
{
_stic.ToggleSr2();
delayCycles = 0;
}
}
if (delayCycles >= 750 && activeDisplay)
{
delayCycles = -1;
delayTimer = 110;
_stic.ToggleSr2();
2017-04-23 16:10:26 +00:00
if (_sticRow >= 0)
{
_stic.in_vb_2 = true;
2017-04-23 16:10:26 +00:00
_stic.Background(_sticRow);
_stic.in_vb_2 = false;
}
2017-04-23 16:10:26 +00:00
_sticRow++;
}
2015-06-18 16:44:30 +00:00
Connect();
}
// set up VBlank variables
_stic.in_vb_1 = true;
_stic.in_vb_2 = true;
2016-11-15 15:28:09 +00:00
if (_stic.active_display)
{
_stic.Mobs();
}
_stic.active_display = false;
_stic.Sr1 = false;
2016-12-22 02:43:33 +00:00
_cpu.PendingCycles = 3000 + _cpu.GetPendingCycles();
while (_cpu.GetPendingCycles() > 0)
{
int cycles = _cpu.Execute();
_psg.generate_sound(cycles);
Connect();
}
// vblank phase 2
_cpu.PendingCycles = 791 + _cpu.GetPendingCycles();
_stic.in_vb_1 = false;
2016-11-15 15:28:09 +00:00
while (_cpu.GetPendingCycles() > 0)
{
int cycles = _cpu.Execute();
_psg.generate_sound(cycles);
2016-11-15 15:28:09 +00:00
Connect();
}
_stic.in_vb_2 = false;
2016-11-15 15:28:09 +00:00
if (_islag)
{
_lagcount++;
}
if (Controller.IsPressed("Power"))
{
HardReset();
}
if (Controller.IsPressed("Reset"))
{
SoftReset();
}
2015-06-18 16:44:30 +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
public string BoardName => _cart.BoardName;
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
{
_frame = 0;
_lagcount = 0;
2015-06-18 16:44:30 +00:00
}
public CoreComm CoreComm { get; }
2015-06-18 16:44:30 +00:00
public void Dispose()
{
}
}
}