From 282c3533b43a79474b31aea1191609087ada1544 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Wed, 2 May 2018 11:11:40 +0100 Subject: [PATCH] ZXHawk: Multi-disks are now supported for +3 disk drive --- .../Hardware/Disk/NECUPD765.FDD.cs | 10 ++- .../Machine/SpectrumBase.Input.cs | 58 +++++++++++++++++ .../SinclairSpectrum/Media/Disk/FloppyDisk.cs | 33 ++++++++++ .../ZXSpectrum.Controllers.cs | 15 ++++- .../SinclairSpectrum/ZXSpectrum.Messaging.cs | 62 ++++++++++++++++++- 5 files changed, 174 insertions(+), 4 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs index 2b60c5bc52..44cd6dd9ab 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDD.cs @@ -170,7 +170,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public void FDD_EjectDisk() { - DriveStates[DiskDriveIndex].FDD_EjectDisk(); + DriveStates[0].FDD_EjectDisk(); } /// @@ -181,6 +181,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum get { return DriveStates[DiskDriveIndex].FDD_IsDiskLoaded; } } + /// + /// Returns the disk object from drive 0 + /// + public FloppyDisk DiskPointer + { + get { return DriveStates[0].Disk; } + } + public FloppyDisk Disk { get; set; } #endregion diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs index 978d815c52..cb80c28bd4 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs @@ -19,6 +19,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum string PrevBlock = "Prev Tape Block"; string TapeStatus = "Get Tape Status"; + string NextDisk = "Insert Next Disk"; + string PrevDisk = "Insert Previous Disk"; + string EjectDisk = "Eject Current Disk"; + string DiskStatus = "Get Disk Status"; + string HardResetStr = "Hard Reset"; string SoftResetStr = "Soft Reset"; @@ -30,6 +35,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum bool pressed_NextBlock = false; bool pressed_PrevBlock = false; bool pressed_TapeStatus = false; + bool pressed_NextDisk = false; + bool pressed_PrevDisk = false; + bool pressed_EjectDisk = false; + bool pressed_DiskStatus = false; bool pressed_HardReset = false; bool pressed_SoftReset = false; @@ -218,6 +227,55 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } else pressed_SoftReset = false; + + // disk control + if (Spectrum._controller.IsPressed(NextDisk)) + { + if (!pressed_NextDisk) + { + Spectrum.OSD_FireInputMessage(NextDisk); + DiskMediaIndex++; + pressed_NextDisk = true; + } + } + else + pressed_NextDisk = false; + + if (Spectrum._controller.IsPressed(PrevDisk)) + { + if (!pressed_PrevDisk) + { + Spectrum.OSD_FireInputMessage(PrevDisk); + DiskMediaIndex--; + pressed_PrevDisk = true; + } + } + else + pressed_PrevDisk = false; + + if (Spectrum._controller.IsPressed(EjectDisk)) + { + if (!pressed_EjectDisk) + { + Spectrum.OSD_FireInputMessage(EjectDisk); + if (UPDDiskDevice != null) + UPDDiskDevice.FDD_EjectDisk(); + } + } + else + pressed_EjectDisk = false; + + if (Spectrum._controller.IsPressed(DiskStatus)) + { + if (!pressed_DiskStatus) + { + //Spectrum.OSD_FireInputMessage(TapeStatus); + Spectrum.OSD_ShowDiskStatus(); + pressed_DiskStatus = true; + } + } + else + pressed_DiskStatus = false; } /// diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs index 60627fc01b..e9b5252a9d 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs @@ -249,6 +249,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public bool DetectAlkatraz(ref int[] weak) { + try + { + var data1 = DiskTracks[0].Sectors[0].SectorData; + var data2 = DiskTracks[0].Sectors[0].SectorData.Length; + } + catch (Exception) + { + return false; + } + // check for ALKATRAZ ident in sector 0 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); if (!ident.ToUpper().Contains("ALKATRAZ PROTECTION SYSTEM")) @@ -282,6 +292,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public bool DetectPaulOwens(ref int[] weak) { + try + { + var data1 = DiskTracks[0].Sectors[2].SectorData; + var data2 = DiskTracks[0].Sectors[2].SectorData.Length; + } + catch (Exception) + { + return false; + } + // check for PAUL OWENS ident in sector 2 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[2].SectorData, 0, DiskTracks[0].Sectors[2].SectorData.Length); if (!ident.ToUpper().Contains("PAUL OWENS")) @@ -310,6 +330,19 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public bool DetectHexagon(ref int[] weak) { + try + { + var data1 = DiskTracks[0].Sectors.Length; + var data2 = DiskTracks[0].Sectors[8].ActualDataByteLength; + var data3 = DiskTracks[0].Sectors[8].SectorData; + var data4 = DiskTracks[0].Sectors[8].SectorData.Length; + var data5 = DiskTracks[1].Sectors[0]; + } + catch (Exception) + { + return false; + } + if (DiskTracks[0].Sectors.Length != 10 || DiskTracks[0].Sectors[8].ActualDataByteLength != 512) return false; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs index 38a281ecca..fa69c5164f 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs @@ -82,7 +82,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum definition.CategoryLabels[s] = "Keyboard"; } - // Datacorder (tape device) + // Power functions List power = new List { // Tape functions @@ -109,6 +109,19 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum definition.CategoryLabels[s] = "Datacorder"; } + // Datacorder (tape device) + List disk = new List + { + // Tape functions + "Insert Next Disk", "Insert Previous Disk", /*"Eject Current Disk",*/ "Get Disk Status" + }; + + foreach (var s in disk) + { + definition.BoolButtons.Add(s); + definition.CategoryLabels[s] = "+3 Disk Drive"; + } + return definition; } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs index 43724f8ee2..737829434a 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs @@ -70,7 +70,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public void OSD_DiskInit() { StringBuilder sb = new StringBuilder(); - if (_machine.diskImages != null) + if (_machine.diskImages != null && _machine.UPDDiskDevice != null) { sb.Append("Disk Media Imported (count: " + _machine.diskImages.Count() + ")"); SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Emulator); @@ -83,8 +83,66 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public void OSD_DiskInserted() { StringBuilder sb = new StringBuilder(); + + if (_machine.UPDDiskDevice == null) + { + sb.Append("No Drive Present"); + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + return; + } + sb.Append("DISK INSERTED (" + _machine.DiskMediaIndex + ": " + _diskInfo[_machine.DiskMediaIndex].Name + ")"); - SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape); + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + } + + /// + /// Tape message that prints the current status of the tape device + /// + public void OSD_ShowDiskStatus() + { + StringBuilder sb = new StringBuilder(); + + if (_machine.UPDDiskDevice == null) + { + sb.Append("No Drive Present"); + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + return; + } + + if (_diskInfo.Count == 0) + { + sb.Append("No Disk Loaded"); + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + return; + } + + if (_machine.UPDDiskDevice != null) + { + if (_machine.UPDDiskDevice.DiskPointer == null) + { + sb.Append("No Disk Loaded"); + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + return; + } + + sb.Append("Disk: " + _machine.DiskMediaIndex + ": " + _diskInfo[_machine.DiskMediaIndex].Name); + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + sb.Clear(); + + sb.Append("Detected Protection: " + Enum.GetName(typeof(ProtectionType), _machine.UPDDiskDevice.DiskPointer.Protection)); + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + sb.Clear(); + + sb.Append("Status: "); + + if (_machine.UPDDiskDevice.DriveLight) + sb.Append("READING/WRITING DATA"); + else + sb.Append("UNKNOWN"); + + SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); + sb.Clear(); + } } #endregion