2012-03-25 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2013-10-27 22:07:40 +00:00
|
|
|
|
|
|
|
|
|
using BizHawk.Common;
|
2014-07-03 17:23:03 +00:00
|
|
|
|
using BizHawk.Common.NumberExtensions;
|
|
|
|
|
|
2013-11-04 01:06:36 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2013-11-14 19:33:13 +00:00
|
|
|
|
using BizHawk.Emulation.Common.Components;
|
2014-01-22 01:14:36 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Components.Z80;
|
2012-03-25 01:33:05 +00:00
|
|
|
|
|
2013-11-13 03:32:25 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.ColecoVision
|
2012-03-25 01:33:05 +00:00
|
|
|
|
{
|
2014-04-25 01:19:57 +00:00
|
|
|
|
[CoreAttributes(
|
|
|
|
|
"ColecoHawk",
|
|
|
|
|
"Vecna",
|
|
|
|
|
isPorted: false,
|
|
|
|
|
isReleased: true
|
|
|
|
|
)]
|
2014-12-12 01:58:12 +00:00
|
|
|
|
[ServiceNotApplicable(typeof(ISaveRam), typeof(IDriveLight))]
|
2015-01-14 21:55:48 +00:00
|
|
|
|
public sealed partial class ColecoVision : IEmulator, IDebuggable, IInputPollable, IStatable, ISettable<object, ColecoVision.ColecoSyncSettings>
|
2012-03-25 01:33:05 +00:00
|
|
|
|
{
|
2012-11-17 21:12:51 +00:00
|
|
|
|
// ROM
|
|
|
|
|
public byte[] RomData;
|
|
|
|
|
public int RomLength;
|
2012-11-17 17:39:33 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
public byte[] BiosRom;
|
2012-11-17 17:39:33 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
// Machine
|
|
|
|
|
public Z80A Cpu;
|
|
|
|
|
public TMS9918A VDP;
|
|
|
|
|
public SN76489 PSG;
|
|
|
|
|
public byte[] Ram = new byte[1024];
|
2012-05-06 02:48:39 +00:00
|
|
|
|
|
2014-08-23 19:06:37 +00:00
|
|
|
|
[CoreConstructor("Coleco")]
|
2013-12-24 23:32:43 +00:00
|
|
|
|
public ColecoVision(CoreComm comm, GameInfo game, byte[] rom, object SyncSettings)
|
2012-03-25 01:33:05 +00:00
|
|
|
|
{
|
2014-12-04 03:38:30 +00:00
|
|
|
|
ServiceProvider = new BasicServiceProvider(this);
|
2015-01-24 21:08:20 +00:00
|
|
|
|
MemoryCallbacks = new MemoryCallbackSystem();
|
2012-12-10 00:43:43 +00:00
|
|
|
|
CoreComm = comm;
|
2014-12-05 03:16:08 +00:00
|
|
|
|
_syncSettings = (ColecoSyncSettings)SyncSettings ?? new ColecoSyncSettings();
|
|
|
|
|
bool skipbios = this._syncSettings.SkipBiosIntro;
|
2012-12-10 00:43:43 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
Cpu = new Z80A();
|
|
|
|
|
Cpu.ReadMemory = ReadMemory;
|
|
|
|
|
Cpu.WriteMemory = WriteMemory;
|
|
|
|
|
Cpu.ReadHardware = ReadPort;
|
|
|
|
|
Cpu.WriteHardware = WritePort;
|
2015-01-24 21:08:20 +00:00
|
|
|
|
Cpu.MemoryCallbacks = MemoryCallbacks;
|
2012-11-17 17:39:33 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
VDP = new TMS9918A(Cpu);
|
2015-01-14 22:37:37 +00:00
|
|
|
|
(ServiceProvider as BasicServiceProvider).Register<IVideoProvider>(VDP);
|
2012-11-17 21:12:51 +00:00
|
|
|
|
PSG = new SN76489();
|
2012-11-17 17:39:33 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
// TODO: hack to allow bios-less operation would be nice, no idea if its feasible
|
2015-03-05 01:17:43 +00:00
|
|
|
|
BiosRom = CoreComm.CoreFileProvider.GetFirmware("Coleco", "Bios", true, "Coleco BIOS file is required.");
|
2012-05-06 02:48:39 +00:00
|
|
|
|
|
2013-12-24 23:32:43 +00:00
|
|
|
|
// gamedb can overwrite the syncsettings; this is ok
|
2012-12-10 00:43:43 +00:00
|
|
|
|
if (game["NoSkip"])
|
|
|
|
|
skipbios = false;
|
2012-11-22 02:01:15 +00:00
|
|
|
|
LoadRom(rom, skipbios);
|
2012-11-17 21:12:51 +00:00
|
|
|
|
this.game = game;
|
2012-11-20 00:35:22 +00:00
|
|
|
|
SetupMemoryDomains();
|
2015-01-24 21:08:20 +00:00
|
|
|
|
(ServiceProvider as BasicServiceProvider).Register<IDisassemblable>(new Disassembler());
|
2012-03-25 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-04 03:38:30 +00:00
|
|
|
|
public IEmulatorServiceProvider ServiceProvider { get; private set; }
|
|
|
|
|
|
2012-11-20 00:35:22 +00:00
|
|
|
|
const ushort RamSizeMask = 0x03FF;
|
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
public void FrameAdvance(bool render, bool renderSound)
|
|
|
|
|
{
|
2012-11-18 05:22:13 +00:00
|
|
|
|
Frame++;
|
2014-12-05 03:16:08 +00:00
|
|
|
|
_isLag = true;
|
2012-11-17 21:12:51 +00:00
|
|
|
|
PSG.BeginFrame(Cpu.TotalExecutedCycles);
|
|
|
|
|
VDP.ExecuteFrame();
|
|
|
|
|
PSG.EndFrame(Cpu.TotalExecutedCycles);
|
2012-11-18 05:22:13 +00:00
|
|
|
|
|
2014-12-05 03:16:08 +00:00
|
|
|
|
if (_isLag)
|
|
|
|
|
{
|
2012-11-18 05:22:13 +00:00
|
|
|
|
LagCount++;
|
2014-12-05 03:16:08 +00:00
|
|
|
|
}
|
2012-11-17 21:12:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 16:45:45 +00:00
|
|
|
|
void LoadRom(byte[] rom, bool skipbios)
|
|
|
|
|
{
|
|
|
|
|
RomData = new byte[0x8000];
|
|
|
|
|
for (int i = 0; i < 0x8000; i++)
|
|
|
|
|
RomData[i] = rom[i % rom.Length];
|
2012-11-18 00:40:22 +00:00
|
|
|
|
|
2012-11-22 02:01:15 +00:00
|
|
|
|
// hack to skip colecovision title screen
|
|
|
|
|
if (skipbios)
|
|
|
|
|
{
|
|
|
|
|
RomData[0] = 0x55;
|
|
|
|
|
RomData[1] = 0xAA;
|
|
|
|
|
}
|
2013-11-11 16:45:45 +00:00
|
|
|
|
}
|
2012-11-17 21:12:51 +00:00
|
|
|
|
|
|
|
|
|
byte ReadPort(ushort port)
|
|
|
|
|
{
|
|
|
|
|
port &= 0xFF;
|
|
|
|
|
|
|
|
|
|
if (port >= 0xA0 && port < 0xC0)
|
|
|
|
|
{
|
|
|
|
|
if ((port & 1) == 0)
|
|
|
|
|
return VDP.ReadData();
|
|
|
|
|
return VDP.ReadVdpStatus();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 16:45:45 +00:00
|
|
|
|
if (port >= 0xE0)
|
|
|
|
|
{
|
|
|
|
|
if ((port & 1) == 0)
|
|
|
|
|
return ReadController1();
|
|
|
|
|
return ReadController2();
|
|
|
|
|
}
|
2012-11-18 00:40:22 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
return 0xFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WritePort(ushort port, byte value)
|
|
|
|
|
{
|
|
|
|
|
port &= 0xFF;
|
|
|
|
|
|
2013-11-11 16:45:45 +00:00
|
|
|
|
if (port >= 0xA0 && port <= 0xBF)
|
2012-11-17 21:12:51 +00:00
|
|
|
|
{
|
|
|
|
|
if ((port & 1) == 0)
|
|
|
|
|
VDP.WriteVdpData(value);
|
|
|
|
|
else
|
|
|
|
|
VDP.WriteVdpControl(value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 16:45:45 +00:00
|
|
|
|
if (port >= 0x80 && port <= 0x9F)
|
|
|
|
|
{
|
|
|
|
|
InputPortSelection = InputPortMode.Right;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (port >= 0xC0 && port <= 0xDF)
|
|
|
|
|
{
|
|
|
|
|
InputPortSelection = InputPortMode.Left;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (port >= 0xE0)
|
|
|
|
|
{
|
|
|
|
|
PSG.WritePsgData(value, Cpu.TotalExecutedCycles);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-11-17 21:12:51 +00:00
|
|
|
|
}
|
2012-03-25 01:33:05 +00:00
|
|
|
|
|
2012-10-03 15:31:04 +00:00
|
|
|
|
public bool DeterministicEmulation { get { return true; } }
|
2013-11-11 16:45:45 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
public void Dispose() { }
|
2013-11-03 16:29:51 +00:00
|
|
|
|
public void ResetCounters()
|
2012-11-25 15:41:40 +00:00
|
|
|
|
{
|
|
|
|
|
Frame = 0;
|
2014-12-05 03:16:08 +00:00
|
|
|
|
_lagCount = 0;
|
|
|
|
|
_isLag = false;
|
2012-11-25 15:41:40 +00:00
|
|
|
|
}
|
2012-11-17 17:39:33 +00:00
|
|
|
|
|
2012-11-17 21:12:51 +00:00
|
|
|
|
public string SystemId { get { return "Coleco"; } }
|
|
|
|
|
public GameInfo game;
|
2012-12-10 00:43:43 +00:00
|
|
|
|
public CoreComm CoreComm { get; private set; }
|
2012-11-17 21:12:51 +00:00
|
|
|
|
public ISoundProvider SoundProvider { get { return PSG; } }
|
2012-11-17 17:39:33 +00:00
|
|
|
|
|
2013-08-24 16:54:22 +00:00
|
|
|
|
public string BoardName { get { return null; } }
|
|
|
|
|
|
2015-04-12 05:52:40 +00:00
|
|
|
|
public ISyncSoundProvider SyncSoundProvider { get { return new FakeSyncSound(SoundProvider, 735); } }
|
2012-11-17 21:12:51 +00:00
|
|
|
|
public bool StartAsyncSound() { return true; }
|
|
|
|
|
public void EndAsyncSound() { }
|
2012-03-25 01:33:05 +00:00
|
|
|
|
}
|
2012-11-23 05:51:16 +00:00
|
|
|
|
}
|