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

144 lines
2.9 KiB
C#

using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Intellivision
{
public sealed partial class Intellivision : IEmulator
{
public IEmulatorServiceProvider ServiceProvider { get; }
public ControllerDefinition ControllerDefinition => ControllerDeck.Definition;
public IController Controller { get; set; }
public void FrameAdvance(bool render, bool rendersound)
{
if (_tracer.Enabled)
{
_cpu.TraceCallback = (s) => _tracer.Put(s);
}
else
{
_cpu.TraceCallback = null;
}
_frame++;
_sticRow = -1;
// read the controller state here for now
GetControllerState();
// this timer tracks cycles stolen by the STIC during the visible part of the frame, quite a large number of them actually
int delay_cycles = 700;
int delay_timer = -1;
_cpu.PendingCycles = 14934 - 3791 + _cpu.GetPendingCycles();
_stic.Sr1 = true;
_islag = true;
bool active_display = _stic.active_display;
// also at the start of every frame the color stack is reset
_stic.ColorSP = 0x0028;
while (_cpu.GetPendingCycles() > 0)
{
int cycles = _cpu.Execute();
_psg.generate_sound(cycles);
if (delay_cycles>=0 && active_display)
delay_cycles += cycles;
if (delay_timer> 0 && active_display)
{
delay_timer -= cycles;
if (delay_timer<=0)
{
_stic.ToggleSr2();
delay_cycles = 0;
}
}
if (delay_cycles >= 750 && active_display)
{
delay_cycles = -1;
delay_timer = 110;
_stic.ToggleSr2();
if (_sticRow >= 0)
{
_stic.in_vb_2 = true;
_stic.Background(_sticRow);
_stic.in_vb_2 = false;
}
_sticRow++;
}
Connect();
}
// set up VBlank variables
_stic.in_vb_1 = true;
_stic.in_vb_2 = true;
if (_stic.active_display)
{
_stic.Mobs();
}
_stic.active_display = false;
_stic.Sr1 = false;
_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;
while (_cpu.GetPendingCycles() > 0)
{
int cycles = _cpu.Execute();
_psg.generate_sound(cycles);
Connect();
}
_stic.in_vb_2 = false;
if (_islag)
_lagcount++;
if (Controller.IsPressed("Power"))
HardReset();
if (Controller.IsPressed("Reset"))
SoftReset();
}
public int Frame => _frame;
public string SystemId => "INTV";
public bool DeterministicEmulation => true;
[FeatureNotImplemented]
public string BoardName => null;
public void ResetCounters()
{
_frame = 0;
_lagcount = 0;
}
public CoreComm CoreComm { get; }
public void Dispose()
{
}
}
}