2015-06-18 16:44:30 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2016-11-11 21:47:55 +00:00
|
|
|
|
using System;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Cores.Intellivision
|
|
|
|
|
{
|
|
|
|
|
public sealed partial class Intellivision : IEmulator
|
|
|
|
|
{
|
|
|
|
|
public IEmulatorServiceProvider ServiceProvider { get; private set; }
|
|
|
|
|
|
|
|
|
|
public ControllerDefinition ControllerDefinition
|
|
|
|
|
{
|
2016-12-03 23:44:25 +00:00
|
|
|
|
get { return ControllerDeck.Definition; }
|
2015-06-18 16:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IController Controller { get; set; }
|
|
|
|
|
|
|
|
|
|
public void FrameAdvance(bool render, bool rendersound)
|
|
|
|
|
{
|
2016-11-11 22:17:35 +00:00
|
|
|
|
if (Tracer.Enabled)
|
|
|
|
|
_cpu.TraceCallback = (s) => Tracer.Put(s);
|
|
|
|
|
else
|
|
|
|
|
_cpu.TraceCallback = null;
|
|
|
|
|
|
2016-12-10 04:00:40 +00:00
|
|
|
|
//reset the count of audio samples
|
|
|
|
|
_psg.sample_count = 0;
|
|
|
|
|
|
2016-12-06 03:00:47 +00:00
|
|
|
|
_frame++;
|
2016-12-24 01:07:12 +00:00
|
|
|
|
stic_row = -1;
|
2016-11-11 21:47:55 +00:00
|
|
|
|
// read the controller state here for now
|
|
|
|
|
get_controller_state();
|
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
|
2016-12-24 20:01:41 +00:00
|
|
|
|
int delay_cycles = 700;
|
2016-12-13 21:45:30 +00:00
|
|
|
|
int delay_timer = -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;
|
2016-12-27 21:31:33 +00:00
|
|
|
|
islag = true;
|
2016-11-15 15:28:09 +00:00
|
|
|
|
|
2016-12-24 14:14:24 +00:00
|
|
|
|
bool active_display = _stic.active_display;
|
|
|
|
|
|
2016-12-24 20:01:41 +00:00
|
|
|
|
//also at the start of every frame the color stack is reset
|
|
|
|
|
_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
|
|
|
|
|
2016-12-24 14:14:24 +00:00
|
|
|
|
if (delay_cycles>=0 && active_display)
|
2016-12-13 21:45:30 +00:00
|
|
|
|
delay_cycles += cycles;
|
|
|
|
|
|
2016-12-24 14:14:24 +00:00
|
|
|
|
if (delay_timer> 0 && active_display)
|
2016-12-13 21:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
delay_timer -= cycles;
|
|
|
|
|
if (delay_timer<=0)
|
|
|
|
|
{
|
|
|
|
|
_stic.ToggleSr2();
|
|
|
|
|
delay_cycles = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-24 14:14:24 +00:00
|
|
|
|
if (delay_cycles>= 750 && active_display)
|
2016-12-13 21:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
delay_cycles = -1;
|
|
|
|
|
delay_timer = 110;
|
|
|
|
|
_stic.ToggleSr2();
|
2016-12-24 01:07:12 +00:00
|
|
|
|
if (stic_row >= 0)
|
|
|
|
|
{
|
|
|
|
|
_stic.in_vb_2 = true;
|
|
|
|
|
_stic.Background(stic_row);
|
|
|
|
|
_stic.in_vb_2 = false;
|
|
|
|
|
}
|
|
|
|
|
stic_row++;
|
2016-12-13 21:45:30 +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
|
|
|
|
|
2016-12-26 15:51:45 +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
|
2016-12-26 15:51:45 +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();
|
|
|
|
|
}
|
2016-12-23 02:07:31 +00:00
|
|
|
|
_stic.in_vb_2 = false;
|
2016-11-15 15:28:09 +00:00
|
|
|
|
|
2016-12-27 21:31:33 +00:00
|
|
|
|
if (islag)
|
|
|
|
|
lagcount++;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-04 14:25:17 +00:00
|
|
|
|
private int _frame;
|
2016-12-27 21:31:33 +00:00
|
|
|
|
public bool islag;
|
|
|
|
|
public int lagcount;
|
2016-12-24 01:07:12 +00:00
|
|
|
|
private int stic_row;
|
2016-12-04 14:25:17 +00:00
|
|
|
|
public int Frame { get { return _frame; } }
|
2015-06-18 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
public string SystemId
|
|
|
|
|
{
|
|
|
|
|
get { return "INTV"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeterministicEmulation { get { return true; } }
|
|
|
|
|
|
|
|
|
|
[FeatureNotImplemented]
|
|
|
|
|
public string BoardName { get { return null; } }
|
|
|
|
|
|
|
|
|
|
public void ResetCounters()
|
|
|
|
|
{
|
2016-12-04 14:25:17 +00:00
|
|
|
|
_frame = 0;
|
2016-12-27 21:31:33 +00:00
|
|
|
|
lagcount = 0;
|
2015-06-18 16:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CoreComm CoreComm { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-03 23:44:25 +00:00
|
|
|
|
}
|