From a374f9f4b8138cbbf976d7f0fa81c5888a25e72d Mon Sep 17 00:00:00 2001 From: Asnivor Date: Thu, 3 May 2018 15:33:30 +0100 Subject: [PATCH] ZXHawk: Some UPD ReadID improvements --- .../Hardware/Disk/NECUPD765.FDC.cs | 32 +++++++++++++++++-- .../SinclairSpectrum/Machine/SpectrumBase.cs | 4 +-- .../SinclairSpectrum/ZXSpectrum.Messaging.cs | 7 +++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDC.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDC.cs index 60582674a8..4ab2c2d133 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDC.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDC.cs @@ -598,7 +598,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ActiveCommandParams.Cylinder++; // reset sector - ActiveCommandParams.Sector = 1; + ActiveCommandParams.Sector = sector.SectorID; // 1; ActiveDrive.SectorIndex = 0; } else @@ -1598,6 +1598,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ActiveDrive.SectorIndex = 0; } + if (ActiveDrive.SectorIndex == 0 && ActiveDrive.Disk.DiskTracks[ActiveDrive.CurrentTrackID].Sectors.Length > 1) + { + // looks like readid always skips the first sector on a track + ActiveDrive.SectorIndex++; + } + // read the sector data var data = track.Sectors[ActiveDrive.SectorIndex]; //.GetCHRN(); ResBuffer[RS_C] = data.TrackNumber; @@ -2710,8 +2716,24 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // set seek flag ActiveDrive.SeekStatus = SEEK_SEEK; - // immediate seek - ActiveDrive.CurrentTrackID = CommBuffer[CM_C]; + if (ActiveDrive.CurrentTrackID == CommBuffer[CM_C]) + { + // we are already on the correct track + ActiveDrive.SectorIndex = 0; + } + else + { + // immediate seek + ActiveDrive.CurrentTrackID = CommBuffer[CM_C]; + + ActiveDrive.SectorIndex = 0; + + if (ActiveDrive.Disk.DiskTracks[ActiveDrive.CurrentTrackID].Sectors.Length > 1) + { + // always read the first sector + //ActiveDrive.SectorIndex++; + } + } // skip execution mode and go directly to idle // result is determined by SIS command @@ -2773,6 +2795,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ActiveDrive.TrackIndex = 0; ActiveDrive.SectorIndex = 0; + // recalibrate appears to always skip the first sector + //if (ActiveDrive.Disk.DiskTracks[ActiveDrive.TrackIndex].Sectors.Length > 1) + //ActiveDrive.SectorIndex++; + // set seek flag ActiveDrive.SeekStatus = SEEK_RECALIBRATE; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs index 9d52641d6f..f2766502a7 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs @@ -204,14 +204,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum Spectrum.IsLagFrame = !InputRead; // FDC debug - /* + if (UPDDiskDevice != null && UPDDiskDevice.writeDebug) { // only write UPD log every second if (FrameCount % 10 == 0) System.IO.File.WriteAllText(UPDDiskDevice.outputfile, UPDDiskDevice.outputString); } - */ + } #endregion diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs index 737829434a..8c7f6baf14 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Messaging.cs @@ -129,7 +129,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); sb.Clear(); - sb.Append("Detected Protection: " + Enum.GetName(typeof(ProtectionType), _machine.UPDDiskDevice.DiskPointer.Protection)); + string protection = "None"; + protection = Enum.GetName(typeof(ProtectionType), _machine.UPDDiskDevice.DiskPointer.Protection); + if (protection == "None") + protection += " (OR UNKNOWN)"; + + sb.Append("Detected Protection: " + protection); SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Disk); sb.Clear();