2012-03-25 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
2012-05-06 02:48:39 +00:00
|
|
|
|
using BizHawk.Emulation.CPUs.Z80;
|
|
|
|
|
using BizHawk.Emulation.Sound;
|
|
|
|
|
using BizHawk.Emulation.Consoles.Sega;
|
2012-03-25 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Consoles.Coleco
|
|
|
|
|
{
|
|
|
|
|
public partial class ColecoVision : IEmulator, IVideoProvider, ISoundProvider
|
|
|
|
|
{
|
|
|
|
|
public string SystemId { get { return "Coleco"; } }
|
2012-05-06 02:48:39 +00:00
|
|
|
|
public GameInfo game;
|
2012-03-25 01:33:05 +00:00
|
|
|
|
public int[] frameBuffer = new int[256 * 192];
|
|
|
|
|
public CoreInputComm CoreInputComm { get; set; }
|
|
|
|
|
public CoreOutputComm CoreOutputComm { get; private set; }
|
|
|
|
|
public IVideoProvider VideoProvider { get { return this; } }
|
|
|
|
|
public ISoundProvider SoundProvider { get { return this; } }
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
public ISyncSoundProvider SyncSoundProvider { get { return new FakeSyncSound(this, 735); } }
|
|
|
|
|
public bool StartAsyncSound() { return true; }
|
|
|
|
|
public void EndAsyncSound() { }
|
2012-05-18 22:57:05 +00:00
|
|
|
|
public byte[] ram = new byte[2048];
|
2012-03-25 01:33:05 +00:00
|
|
|
|
|
2012-05-06 02:48:39 +00:00
|
|
|
|
public DisplayType DisplayType { get; set; } //TOOD: delete me
|
|
|
|
|
|
2012-03-25 01:33:05 +00:00
|
|
|
|
public ColecoVision(GameInfo game, byte[] rom)
|
|
|
|
|
{
|
2012-05-06 02:48:39 +00:00
|
|
|
|
cpu = new Z80A();
|
|
|
|
|
Vdp = new VDP(this, cpu, VdpMode.SMS, DisplayType);
|
|
|
|
|
|
2012-03-25 01:33:05 +00:00
|
|
|
|
var domains = new List<MemoryDomain>(1);
|
2012-05-06 02:48:39 +00:00
|
|
|
|
domains.Add(new MemoryDomain("Main RAM", 1024, Endian.Little, addr => ram[1023], (addr, value) => ram[addr & 1023] = value));
|
2012-03-25 01:33:05 +00:00
|
|
|
|
memoryDomains = domains.AsReadOnly();
|
|
|
|
|
CoreOutputComm = new CoreOutputComm();
|
|
|
|
|
CoreInputComm = new CoreInputComm();
|
|
|
|
|
this.rom = rom;
|
2012-05-06 02:48:39 +00:00
|
|
|
|
this.game = game;
|
2012-03-25 01:33:05 +00:00
|
|
|
|
HardReset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetFrameCounter() { _frame = 0; }
|
|
|
|
|
|
|
|
|
|
public static readonly ControllerDefinition ColecoVisionControllerDefinition = new ControllerDefinition
|
|
|
|
|
{
|
|
|
|
|
Name = "ColecoVision Basic Controller",
|
|
|
|
|
BoolButtons =
|
|
|
|
|
{
|
|
|
|
|
"P1 Up", "P1 Down", "P1 Left", "P1 Right",
|
2012-05-06 00:54:13 +00:00
|
|
|
|
"P1 L1", "P1 L2", "P1 R1", "P1 R2",
|
2012-03-25 01:33:05 +00:00
|
|
|
|
"P1 Key1", "P1 Key2", "P1 Key3", "P1 Key4", "P1 Key5",
|
2012-05-06 00:54:13 +00:00
|
|
|
|
"P1 Key6", "P1 Key7", "P1 Key8", "P1 Key9", "P1 Star", "P1 Pound" //adelikat: TODO: can there be multiple controllers?
|
2012-03-25 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void SyncState(Serializer ser)
|
|
|
|
|
{
|
|
|
|
|
//cpu.SyncState(ser); //TODO: z80 does not have this, do it the SMS way?
|
|
|
|
|
ser.Sync("ram", ref ram, false);
|
|
|
|
|
ser.Sync("Lag", ref _lagcount);
|
|
|
|
|
ser.Sync("Frame", ref _frame);
|
2012-07-30 14:42:52 +00:00
|
|
|
|
ser.Sync("IsLag", ref _islag);
|
2012-03-25 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ControllerDefinition ControllerDefinition { get { return ColecoVisionControllerDefinition; } }
|
|
|
|
|
public IController Controller { get; set; }
|
|
|
|
|
|
|
|
|
|
public int Frame { get { return _frame; } set { _frame = value; } }
|
|
|
|
|
public int LagCount { get { return _lagcount; } set { _lagcount = value; } }
|
|
|
|
|
public bool IsLagFrame { get { return _islag; } }
|
|
|
|
|
private bool _islag = true;
|
|
|
|
|
private int _lagcount = 0;
|
|
|
|
|
private int _frame = 0;
|
|
|
|
|
|
2012-09-14 22:28:38 +00:00
|
|
|
|
public byte[] ReadSaveRam() { return null; }
|
|
|
|
|
public void StoreSaveRam(byte[] data) { }
|
|
|
|
|
public void ClearSaveRam() { }
|
2012-03-25 01:33:05 +00:00
|
|
|
|
public bool SaveRamModified { get; set; }
|
2012-09-14 22:28:38 +00:00
|
|
|
|
|
2012-10-03 15:31:04 +00:00
|
|
|
|
public bool DeterministicEmulation { get { return true; } }
|
2012-03-25 01:33:05 +00:00
|
|
|
|
public void SaveStateText(TextWriter writer) { SyncState(Serializer.CreateTextWriter(writer)); }
|
|
|
|
|
public void LoadStateText(TextReader reader) { SyncState(Serializer.CreateTextReader(reader)); }
|
|
|
|
|
public void SaveStateBinary(BinaryWriter bw) { SyncState(Serializer.CreateBinaryWriter(bw)); }
|
|
|
|
|
public void LoadStateBinary(BinaryReader br) { SyncState(Serializer.CreateBinaryReader(br)); }
|
|
|
|
|
|
|
|
|
|
public byte[] SaveStateBinary()
|
|
|
|
|
{
|
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
|
|
BinaryWriter bw = new BinaryWriter(ms);
|
|
|
|
|
SaveStateBinary(bw);
|
|
|
|
|
bw.Flush();
|
|
|
|
|
return ms.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int[] GetVideoBuffer() { return frameBuffer; }
|
2012-06-25 02:50:34 +00:00
|
|
|
|
public int VirtualWidth { get { return 256; } }
|
|
|
|
|
public int BufferWidth { get { return 256; } }
|
2012-05-06 01:15:02 +00:00
|
|
|
|
public int BufferHeight { get { return 192; } }
|
2012-03-25 01:33:05 +00:00
|
|
|
|
public int BackgroundColor { get { return 0; } }
|
|
|
|
|
public void GetSamples(short[] samples)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DiscardSamples() { }
|
|
|
|
|
public int MaxVolume { get; set; }
|
|
|
|
|
private IList<MemoryDomain> memoryDomains;
|
|
|
|
|
public IList<MemoryDomain> MemoryDomains { get { return memoryDomains; } }
|
|
|
|
|
public MemoryDomain MainMemory { get { return memoryDomains[0]; } }
|
|
|
|
|
public void Dispose() { }
|
|
|
|
|
}
|
|
|
|
|
}
|