Fix indentation in `SpectrumBase.Media.cs`
This commit is contained in:
parent
45581b2370
commit
5f29b50940
|
@ -5,314 +5,314 @@ using BizHawk.Common.StringExtensions;
|
|||
|
||||
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
||||
{
|
||||
/// <summary>
|
||||
/// The abstract class that all emulated models will inherit from
|
||||
/// * Imported media *
|
||||
/// </summary>
|
||||
public abstract partial class SpectrumBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The abstract class that all emulated models will inherit from
|
||||
/// * Imported media *
|
||||
/// </summary>
|
||||
public abstract partial class SpectrumBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The tape or disk image(s) that are passed in from the main ZXSpectrum class
|
||||
/// </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>
|
||||
/// Tape images
|
||||
/// </summary>
|
||||
public List<byte[]> tapeImages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Disk images
|
||||
/// </summary>
|
||||
/// Disk images
|
||||
/// </summary>
|
||||
public List<byte[]> diskImages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set when a savestate is loaded
|
||||
/// (Used to cancel any tape/disk load messages after a loadstate)
|
||||
/// </summary>
|
||||
public bool IsLoadState;
|
||||
/// <summary>
|
||||
/// Set when a savestate is loaded
|
||||
/// (Used to cancel any tape/disk load messages after a loadstate)
|
||||
/// </summary>
|
||||
public bool IsLoadState;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the currently 'loaded' tape image
|
||||
/// </summary>
|
||||
protected int tapeMediaIndex;
|
||||
public int TapeMediaIndex
|
||||
{
|
||||
get => tapeMediaIndex;
|
||||
set
|
||||
{
|
||||
int tmp = value;
|
||||
int result = value;
|
||||
/// The index of the currently 'loaded' tape image
|
||||
/// </summary>
|
||||
protected int tapeMediaIndex;
|
||||
public int TapeMediaIndex
|
||||
{
|
||||
get => tapeMediaIndex;
|
||||
set
|
||||
{
|
||||
int tmp = value;
|
||||
int result = value;
|
||||
|
||||
if (tapeImages == null || tapeImages.Count == 0)
|
||||
{
|
||||
// no tape images found
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
{
|
||||
// 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;
|
||||
{
|
||||
// negative index not allowed - move to last item in the collection
|
||||
result = tapeImages.Count - 1;
|
||||
}
|
||||
|
||||
// fire osd message
|
||||
if (!IsLoadState)
|
||||
Spectrum.OSD_TapeInserted();
|
||||
// load the media into the tape device
|
||||
tapeMediaIndex = result;
|
||||
|
||||
LoadTapeMedia();
|
||||
}
|
||||
}
|
||||
// fire osd message
|
||||
if (!IsLoadState)
|
||||
Spectrum.OSD_TapeInserted();
|
||||
|
||||
/// <summary>
|
||||
/// The index of the currently 'loaded' disk image
|
||||
/// </summary>
|
||||
protected int diskMediaIndex;
|
||||
public int DiskMediaIndex
|
||||
{
|
||||
get => 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;
|
||||
|
||||
// fire osd message
|
||||
if (!IsLoadState)
|
||||
Spectrum.OSD_DiskInserted();
|
||||
|
||||
LoadDiskMedia();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on first instantiation (and subsequent core reboots)
|
||||
/// </summary>
|
||||
protected void InitializeMedia(List<byte[]> files)
|
||||
{
|
||||
mediaImages = files;
|
||||
LoadAllMedia();
|
||||
}
|
||||
LoadTapeMedia();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to load all media into the relevant structures
|
||||
/// </summary>
|
||||
/// The index of the currently 'loaded' disk image
|
||||
/// </summary>
|
||||
protected int diskMediaIndex;
|
||||
public int DiskMediaIndex
|
||||
{
|
||||
get => 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;
|
||||
|
||||
// fire osd message
|
||||
if (!IsLoadState)
|
||||
Spectrum.OSD_DiskInserted();
|
||||
|
||||
LoadDiskMedia();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on first instantiation (and subsequent core reboots)
|
||||
/// </summary>
|
||||
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[]>();
|
||||
{
|
||||
tapeImages = new List<byte[]>();
|
||||
diskImages = new List<byte[]>();
|
||||
|
||||
int cnt = 0;
|
||||
foreach (var m in mediaImages)
|
||||
{
|
||||
switch (IdentifyMedia(m))
|
||||
{
|
||||
case SpectrumMediaType.Tape:
|
||||
tapeImages.Add(m);
|
||||
Spectrum._tapeInfo.Add(Spectrum._gameInfo[cnt]);
|
||||
break;
|
||||
case SpectrumMediaType.Disk:
|
||||
diskImages.Add(m);
|
||||
Spectrum._diskInfo.Add(Spectrum._gameInfo[cnt]);
|
||||
break;
|
||||
case SpectrumMediaType.DiskDoubleSided:
|
||||
// this is a bit tricky. we will attempt to parse the double sided disk image byte array,
|
||||
// then output two separate image byte arrays
|
||||
List<byte[]> working = new List<byte[]>();
|
||||
foreach (DiskType type in Enum.GetValues(typeof(DiskType)))
|
||||
{
|
||||
bool found = false;
|
||||
int cnt = 0;
|
||||
foreach (var m in mediaImages)
|
||||
{
|
||||
switch (IdentifyMedia(m))
|
||||
{
|
||||
case SpectrumMediaType.Tape:
|
||||
tapeImages.Add(m);
|
||||
Spectrum._tapeInfo.Add(Spectrum._gameInfo[cnt]);
|
||||
break;
|
||||
case SpectrumMediaType.Disk:
|
||||
diskImages.Add(m);
|
||||
Spectrum._diskInfo.Add(Spectrum._gameInfo[cnt]);
|
||||
break;
|
||||
case SpectrumMediaType.DiskDoubleSided:
|
||||
// this is a bit tricky. we will attempt to parse the double sided disk image byte array,
|
||||
// then output two separate image byte arrays
|
||||
List<byte[]> working = new List<byte[]>();
|
||||
foreach (DiskType type in Enum.GetValues(typeof(DiskType)))
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DiskType.CPCExtended:
|
||||
found = CPCExtendedFloppyDisk.SplitDoubleSided(m, working);
|
||||
break;
|
||||
case DiskType.CPC:
|
||||
found = CPCFloppyDisk.SplitDoubleSided(m, working);
|
||||
break;
|
||||
case DiskType.UDI:
|
||||
found = UDI1_0FloppyDisk.SplitDoubleSided(m, working);
|
||||
break;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case DiskType.CPCExtended:
|
||||
found = CPCExtendedFloppyDisk.SplitDoubleSided(m, working);
|
||||
break;
|
||||
case DiskType.CPC:
|
||||
found = CPCFloppyDisk.SplitDoubleSided(m, working);
|
||||
break;
|
||||
case DiskType.UDI:
|
||||
found = UDI1_0FloppyDisk.SplitDoubleSided(m, working);
|
||||
break;
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
// add side 1
|
||||
diskImages.Add(working[0]);
|
||||
// add side 2
|
||||
diskImages.Add(working[1]);
|
||||
if (found)
|
||||
{
|
||||
// add side 1
|
||||
diskImages.Add(working[0]);
|
||||
// add side 2
|
||||
diskImages.Add(working[1]);
|
||||
|
||||
Common.GameInfo one = new Common.GameInfo();
|
||||
Common.GameInfo two = new Common.GameInfo();
|
||||
var gi = Spectrum._gameInfo[cnt];
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Common.GameInfo work = new Common.GameInfo();
|
||||
if (i == 0)
|
||||
{
|
||||
work = one;
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
work = two;
|
||||
}
|
||||
Common.GameInfo one = new Common.GameInfo();
|
||||
Common.GameInfo two = new Common.GameInfo();
|
||||
var gi = Spectrum._gameInfo[cnt];
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Common.GameInfo work = new Common.GameInfo();
|
||||
if (i == 0)
|
||||
{
|
||||
work = one;
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
work = two;
|
||||
}
|
||||
|
||||
work.FirmwareHash = gi.FirmwareHash;
|
||||
work.Hash = gi.Hash;
|
||||
work.Name = gi.Name + " (Parsed Side " + (i + 1) + ")";
|
||||
work.Region = gi.Region;
|
||||
work.NotInDatabase = gi.NotInDatabase;
|
||||
work.Status = gi.Status;
|
||||
work.System = gi.System;
|
||||
work.FirmwareHash = gi.FirmwareHash;
|
||||
work.Hash = gi.Hash;
|
||||
work.Name = gi.Name + " (Parsed Side " + (i + 1) + ")";
|
||||
work.Region = gi.Region;
|
||||
work.NotInDatabase = gi.NotInDatabase;
|
||||
work.Status = gi.Status;
|
||||
work.System = gi.System;
|
||||
|
||||
Spectrum._diskInfo.Add(work);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Spectrum._diskInfo.Add(work);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
cnt++;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (tapeImages.Count > 0)
|
||||
LoadTapeMedia();
|
||||
if (tapeImages.Count > 0)
|
||||
LoadTapeMedia();
|
||||
|
||||
if (diskImages.Count > 0)
|
||||
LoadDiskMedia();
|
||||
}
|
||||
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 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()
|
||||
{
|
||||
if (this is not ZX128Plus3)
|
||||
{
|
||||
Spectrum.CoreComm.ShowMessage("You are trying to load one of more disk images.\n\n Please select ZX Spectrum +3 emulation immediately and reboot the core");
|
||||
return;
|
||||
}
|
||||
/// <summary>
|
||||
/// Attempts to load a disk into the disk device based on diskMediaIndex
|
||||
/// </summary>
|
||||
protected void LoadDiskMedia()
|
||||
{
|
||||
if (this is not ZX128Plus3)
|
||||
{
|
||||
Spectrum.CoreComm.ShowMessage("You are trying to load one of more disk images.\n\n Please select ZX Spectrum +3 emulation immediately and reboot the core");
|
||||
return;
|
||||
}
|
||||
|
||||
UPDDiskDevice.FDD_LoadDisk(diskImages[diskMediaIndex]);
|
||||
}
|
||||
UPDDiskDevice.FDD_LoadDisk(diskImages[diskMediaIndex]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Identifies and sorts the various media types
|
||||
/// </summary>
|
||||
private SpectrumMediaType IdentifyMedia(byte[] data)
|
||||
{
|
||||
// get first 16 bytes as a string
|
||||
string hdr = Encoding.ASCII.GetString(data.Take(16).ToArray());
|
||||
/// <summary>
|
||||
/// Identifies and sorts the various media types
|
||||
/// </summary>
|
||||
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.Contains("EXTENDED CPC DSK", StringComparison.OrdinalIgnoreCase) || hdr.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .dsk disk file
|
||||
// check for number of sides
|
||||
var sides = data[0x31];
|
||||
if (sides == 1)
|
||||
return SpectrumMediaType.Disk;
|
||||
else
|
||||
return SpectrumMediaType.DiskDoubleSided;
|
||||
}
|
||||
{
|
||||
// spectrum .dsk disk file
|
||||
// check for number of sides
|
||||
var sides = data[0x31];
|
||||
if (sides == 1)
|
||||
return SpectrumMediaType.Disk;
|
||||
else
|
||||
return SpectrumMediaType.DiskDoubleSided;
|
||||
}
|
||||
if (hdr.StartsWith("FDI", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .fdi disk file
|
||||
return SpectrumMediaType.Disk;
|
||||
}
|
||||
if (hdr.StartsWith("CAPS", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// IPF format file
|
||||
return SpectrumMediaType.Disk;
|
||||
}
|
||||
if (hdr.StartsWith("UDI!", StringComparison.OrdinalIgnoreCase) && data[0x08] == 0)
|
||||
{
|
||||
// UDI v1.0
|
||||
if (hdr.StartsWithOrdinal("udi!"))
|
||||
{
|
||||
throw new NotSupportedException("ZXHawk currently does not supported UDIv1.0 with compression.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data[0x0A] == 0x01)
|
||||
return SpectrumMediaType.DiskDoubleSided;
|
||||
else
|
||||
return SpectrumMediaType.Disk;
|
||||
}
|
||||
}
|
||||
{
|
||||
// spectrum .fdi disk file
|
||||
return SpectrumMediaType.Disk;
|
||||
}
|
||||
if (hdr.StartsWith("CAPS", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// IPF format file
|
||||
return SpectrumMediaType.Disk;
|
||||
}
|
||||
if (hdr.StartsWith("UDI!", StringComparison.OrdinalIgnoreCase) && data[0x08] == 0)
|
||||
{
|
||||
// UDI v1.0
|
||||
if (hdr.StartsWithOrdinal("udi!"))
|
||||
{
|
||||
throw new NotSupportedException("ZXHawk currently does not supported UDIv1.0 with compression.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data[0x0A] == 0x01)
|
||||
return SpectrumMediaType.DiskDoubleSided;
|
||||
else
|
||||
return SpectrumMediaType.Disk;
|
||||
}
|
||||
}
|
||||
|
||||
// tape checking
|
||||
if (hdr.StartsWith("ZXTAPE!", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
if (hdr.StartsWith("PZXT", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
if (hdr.StartsWith("COMPRESSED SQ", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
if (hdr.Contains("WAVE", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
// tape checking
|
||||
if (hdr.StartsWith("ZXTAPE!", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
if (hdr.StartsWith("PZXT", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
if (hdr.StartsWith("COMPRESSED SQ", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
if (hdr.Contains("WAVE", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// spectrum .tzx tape file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
|
||||
// if we get this far, assume a .tap file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
}
|
||||
// if we get this far, assume a .tap file
|
||||
return SpectrumMediaType.Tape;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SpectrumMediaType
|
||||
{
|
||||
{
|
||||
None,
|
||||
Tape,
|
||||
Disk,
|
||||
DiskDoubleSided
|
||||
}
|
||||
DiskDoubleSided
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue