Implemented multi bundler functionlity and multiple tape controls

This commit is contained in:
Asnivor 2018-03-05 11:17:22 +00:00
parent 50d28c9627
commit 90c1e293bf
15 changed files with 266 additions and 37 deletions

View File

@ -661,7 +661,8 @@ namespace BizHawk.Client.Common
case "ZXSpectrum":
nextEmulator = new ZXSpectrum(
nextComm,
xmlGame.Assets.Select(a => a.Value).First(),
xmlGame.Assets.Select(a => a.Value), //.First(),
GameInfo.NullInstance,
(ZXSpectrum.ZXSpectrumSettings)GetCoreSettings<ZXSpectrum>(),
(ZXSpectrum.ZXSpectrumSyncSettings)GetCoreSyncSettings<ZXSpectrum>());
break;
@ -999,7 +1000,7 @@ namespace BizHawk.Client.Common
nextEmulator = c64;
break;
case "ZXSpectrum":
var zx = new ZXSpectrum(nextComm, rom.FileData, GetCoreSettings<ZXSpectrum>(), GetCoreSyncSettings<ZXSpectrum>());
var zx = new ZXSpectrum(nextComm, Enumerable.Repeat(rom.RomData, 1), rom.GameInfo, GetCoreSettings<ZXSpectrum>(), GetCoreSyncSettings<ZXSpectrum>());
nextEmulator = zx;
break;
case "GBA":

View File

@ -143,7 +143,8 @@
"GB",
"PCFX",
"PSX",
"SAT"});
"SAT",
"ZXSpectrum"});
this.SystemDropDown.Location = new System.Drawing.Point(425, 75);
this.SystemDropDown.Name = "SystemDropDown";
this.SystemDropDown.Size = new System.Drawing.Size(69, 21);

View File

@ -233,7 +233,24 @@ namespace BizHawk.Client.EmuHawk
Icon = Properties.Resources.BackMore,
Location = new Point(83, 22),
Type = PadSchema.PadInputType.Boolean
}
},
new PadSchema.ButtonSchema
{
Name = "Insert Next Tape",
DisplayName = "NEXT TAPE",
//Icon = Properties.Resources.MoveRight,
Location = new Point(23, 52),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "Insert Previous Tape",
DisplayName = "PREV TAPE",
//Icon = Properties.Resources.MoveLeft,
Location = new Point(100, 52),
Type = PadSchema.PadInputType.Boolean
},
}
};
}

View File

@ -1378,6 +1378,7 @@
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Keyboard.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Port.cs" />
<None Include="Computers\SinclairSpectrum\readme.md" />
<Compile Include="Computers\SinclairSpectrum\Machine\SpectrumBase.Media.cs" />
<None Include="Consoles\Atari\docs\stella.pdf" />
<None Include="Consoles\Coleco\docs\colecovision tech1.pdf" />
<None Include="Consoles\Coleco\docs\colecovision tech2.pdf" />

View File

@ -401,6 +401,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
ser.Sync("currentState", ref currentState);
//_dataBlocks
/*
ser.BeginSection("Datablocks");
if (ser.IsWriter)
@ -417,11 +418,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
ser.Sync("_tempBlockCount", ref _tempBlockCount);
}
ser.EndSection();
*/
ser.EndSection();
}

View File

@ -10,6 +10,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
string Stop = "Stop Tape";
string RTZ = "RTZ Tape";
string Record = "Record Tape";
string NextTape = "Insert Next Tape";
string PrevTape = "Insert Previous Tape";
public void PollInput()
{
@ -69,6 +71,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
}
if (Spectrum._controller.IsPressed(NextTape))
{
TapeMediaIndex++;
}
if (Spectrum._controller.IsPressed(PrevTape))
{
TapeMediaIndex--;
}
}
}
}

View File

@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
public abstract partial class SpectrumBase
{
// until +3 disk drive is emulated, we assume that incoming files are tape images
/// <summary>
/// The tape or disk image(s) that are passed in from the main ZXSpectrum class
/// </summary>
protected List<byte[]> mediaImages { get; set; }
/// <summary>
/// Tape images
/// </summary>
protected List<byte[]> tapeImages { get; set; }
/// <summary>
/// Disk images
/// </summary>
protected List<byte[]> diskImages { get; set; }
/// <summary>
/// The index of the currently 'loaded' tape or disk image
/// </summary>
protected int tapeMediaIndex;
public int TapeMediaIndex
{
get { return tapeMediaIndex; }
set
{
int tmp = value;
int result = value;
if (tapeImages == null || tapeImages.Count() == 0)
{
// no tape images found
return;
}
if (value >= tapeImages.Count())
{
// media at this index does not exist - loop back to 0
result = 0;
}
else if (value < 0)
{
// negative index not allowed - move to last item in the collection
result = tapeImages.Count() - 1;
}
// load the media into the tape device
tapeMediaIndex = result;
LoadTapeMedia();
}
}
/// <summary>
/// The index of the currently 'loaded' tape or disk image
/// </summary>
protected int diskMediaIndex;
public int DiskMediaIndex
{
get { return diskMediaIndex; }
set
{
int tmp = value;
int result = value;
if (diskImages == null || diskImages.Count() == 0)
{
// no tape images found
return;
}
if (value >= diskImages.Count())
{
// media at this index does not exist - loop back to 0
result = 0;
}
else if (value < 0)
{
// negative index not allowed - move to last item in the collection
result = diskImages.Count() - 1;
}
// load the media into the disk device
diskMediaIndex = result;
LoadDiskMedia();
}
}
/// <summary>
/// Called on first instantiation (and subsequent core reboots)
/// </summary>
/// <param name="files"></param>
protected void InitializeMedia(List<byte[]> files)
{
mediaImages = files;
LoadAllMedia();
}
/// <summary>
/// Attempts to load all media into the relevant structures
/// </summary>
protected void LoadAllMedia()
{
tapeImages = new List<byte[]>();
diskImages = new List<byte[]>();
foreach (var m in mediaImages)
{
switch (IdentifyMedia(m))
{
case SpectrumMediaType.Tape:
tapeImages.Add(m);
break;
case SpectrumMediaType.Disk:
diskImages.Add(m);
break;
}
}
if (tapeImages.Count > 0)
LoadTapeMedia();
if (diskImages.Count > 0)
LoadDiskMedia();
}
/// <summary>
/// Attempts to load a tape into the tape device based on tapeMediaIndex
/// </summary>
protected void LoadTapeMedia()
{
TapeDevice.LoadTape(tapeImages[tapeMediaIndex]);
}
/// <summary>
/// Attempts to load a disk into the disk device based on diskMediaIndex
/// </summary>
protected void LoadDiskMedia()
{
throw new NotImplementedException("+3 disk drive device not yet implemented");
}
/// <summary>
/// Identifies and sorts the various media types
/// </summary>
/// <returns></returns>
private SpectrumMediaType IdentifyMedia(byte[] data)
{
// get first 16 bytes as a string
string hdr = Encoding.ASCII.GetString(data.Take(16).ToArray());
// disk checking first
if (hdr.ToUpper().Contains("EXTENDED CPC DSK"))
{
// spectrum .dsk disk file
return SpectrumMediaType.Disk;
}
if (hdr.ToUpper().StartsWith("FDI"))
{
// spectrum .fdi disk file
return SpectrumMediaType.Disk;
}
// tape checking
if (hdr.ToUpper().StartsWith("ZXTAPE!"))
{
// spectrum .tzx tape file
return SpectrumMediaType.Tape;
}
// if we get this far, assume a .tap file
return SpectrumMediaType.Tape;
}
}
public enum SpectrumMediaType
{
None,
Tape,
Disk
}
}

View File

@ -208,6 +208,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (AYDevice != null)
AYDevice.SyncState(ser);
ser.Sync("tapeMediaIndex", ref tapeMediaIndex);
TapeMediaIndex = tapeMediaIndex;
ser.Sync("diskMediaIndex", ref diskMediaIndex);
DiskMediaIndex = diskMediaIndex;
TapeDevice.SyncState(ser);
ser.EndSection();

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX128(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, byte[] file)
public ZX128(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
{
Spectrum = spectrum;
CPU = cpu;
@ -40,11 +40,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
KeyboardDevice = new Keyboard48(this);
KempstonDevice = new KempstonJoystick(this);
//TapeProvider = new DefaultTapeProvider(file);
TapeDevice = new DatacorderDevice();
TapeDevice.Init(this);
TapeDevice.LoadTape(file);
InitializeMedia(files);
}
#endregion

View File

@ -20,8 +20,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX128Plus2(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, byte[] file)
: base(spectrum, cpu, borderType, file)
public ZX128Plus2(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
: base(spectrum, cpu, borderType, files)
{
}

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX128Plus3(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, byte[] file)
public ZX128Plus3(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
{
Spectrum = spectrum;
CPU = cpu;
@ -40,11 +40,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
KeyboardDevice = new Keyboard48(this);
KempstonDevice = new KempstonJoystick(this);
//TapeProvider = new DefaultTapeProvider(file);
TapeDevice = new DatacorderDevice();
TapeDevice.Init(this);
TapeDevice.LoadTape(file);
InitializeMedia(files);
}
#endregion

View File

@ -16,8 +16,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX16(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, byte[] file)
: base(spectrum, cpu, borderType, file)
public ZX16(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
: base(spectrum, cpu, borderType, files)
{
}

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="spectrum"></param>
/// <param name="cpu"></param>
public ZX48(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, byte[] file)
public ZX48(ZXSpectrum spectrum, Z80A cpu, ZXSpectrum.BorderType borderType, List<byte[]> files)
{
Spectrum = spectrum;
CPU = cpu;
@ -31,11 +31,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
KeyboardDevice = new Keyboard48(this);
KempstonDevice = new KempstonJoystick(this);
//TapeProvider = new DefaultTapeProvider(file);
TapeDevice = new DatacorderDevice();
TapeDevice.Init(this);
TapeDevice.LoadTape(file);
InitializeMedia(files);
//TapeDevice.LoadTape(file);
}
#endregion

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// Keyboard - row 5
"Key Symbol Shift", "Key Semi-Colon", "Key Quote", "Key Left Cursor", "Key Right Cursor", "Key Space", "Key Up Cursor", "Key Down Cursor", "Key Comma",
// Tape functions
"Play Tape", "Stop Tape", "RTZ Tape", "Record Tape"
"Play Tape", "Stop Tape", "RTZ Tape", "Record Tape", "Insert Next Tape", "Insert Previous Tape"
}
};
}

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public partial class ZXSpectrum : IDebuggable, IInputPollable, IStatable, IRegionable
{
[CoreConstructor("ZXSpectrum")]
public ZXSpectrum(CoreComm comm, byte[] file, object settings, object syncSettings)
public ZXSpectrum(CoreComm comm, IEnumerable<byte[]> files, GameInfo game, object settings, object syncSettings)
{
PutSyncSettings((ZXSpectrumSyncSettings)syncSettings ?? new ZXSpectrumSyncSettings());
PutSettings((ZXSpectrumSettings)settings ?? new ZXSpectrumSettings());
@ -34,29 +34,30 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
_tracer = new TraceBuffer { Header = _cpu.TraceHeader };
_file = file;
//_file = file;
_files = files?.ToList() ?? new List<byte[]>();
switch (SyncSettings.MachineType)
{
case MachineType.ZXSpectrum16:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum16, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _file);
Init(MachineType.ZXSpectrum16, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
break;
case MachineType.ZXSpectrum48:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum48, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _file);
Init(MachineType.ZXSpectrum48, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
break;
case MachineType.ZXSpectrum128:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum128, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _file);
Init(MachineType.ZXSpectrum128, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
break;
case MachineType.ZXSpectrum128Plus2:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum128Plus2, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _file);
Init(MachineType.ZXSpectrum128Plus2, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
break;
case MachineType.ZXSpectrum128Plus3:
ControllerDefinition = ZXSpectrumControllerDefinition;
Init(MachineType.ZXSpectrum128Plus3, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _file);
Init(MachineType.ZXSpectrum128Plus3, SyncSettings.BorderType, SyncSettings.TapeLoadSpeed, _files);
break;
default:
throw new InvalidOperationException("Machine not yet emulated");
@ -104,7 +105,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
private DCFilter dcf;
private byte[] _file;
//private byte[] _file;
private readonly List<byte[]> _files;
public bool DiagRom = false;
@ -152,37 +154,37 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
}
private void Init(MachineType machineType, BorderType borderType, TapeLoadSpeed tapeLoadSpeed, byte[] file)
private void Init(MachineType machineType, BorderType borderType, TapeLoadSpeed tapeLoadSpeed, List<byte[]> files)
{
// setup the emulated model based on the MachineType
switch (machineType)
{
case MachineType.ZXSpectrum16:
_machine = new ZX16(this, _cpu, borderType, file);
_machine = new ZX16(this, _cpu, borderType, files);
var _systemRom16 = GetFirmware(0x4000, "48ROM");
var romData16 = RomData.InitROM(machineType, _systemRom16);
_machine.InitROM(romData16);
break;
case MachineType.ZXSpectrum48:
_machine = new ZX48(this, _cpu, borderType, file);
_machine = new ZX48(this, _cpu, borderType, files);
var _systemRom = GetFirmware(0x4000, "48ROM");
var romData = RomData.InitROM(machineType, _systemRom);
_machine.InitROM(romData);
break;
case MachineType.ZXSpectrum128:
_machine = new ZX128(this, _cpu, borderType, file);
_machine = new ZX128(this, _cpu, borderType, files);
var _systemRom128 = GetFirmware(0x8000, "128ROM");
var romData128 = RomData.InitROM(machineType, _systemRom128);
_machine.InitROM(romData128);
break;
case MachineType.ZXSpectrum128Plus2:
_machine = new ZX128Plus2(this, _cpu, borderType, file);
_machine = new ZX128Plus2(this, _cpu, borderType, files);
var _systemRomP2 = GetFirmware(0x8000, "PLUS2ROM");
var romDataP2 = RomData.InitROM(machineType, _systemRomP2);
_machine.InitROM(romDataP2);
break;
case MachineType.ZXSpectrum128Plus3:
_machine = new ZX128Plus3(this, _cpu, borderType, file);
_machine = new ZX128Plus3(this, _cpu, borderType, files);
var _systemRomP3 = GetFirmware(0x10000, "PLUS3ROM");
var romDataP3 = RomData.InitROM(machineType, _systemRomP3);
_machine.InitROM(romDataP3);