From a7bf8e4ca380b9025ec72ed8224568e109d3074d Mon Sep 17 00:00:00 2001 From: Asnivor Date: Mon, 30 Apr 2018 17:36:16 +0100 Subject: [PATCH] ZXHawk: +3 Paul Owens Disk Protection games now loading --- .../Hardware/Disk/NECUPD765.FDC.cs | 4 + .../SinclairSpectrum/Media/Disk/FloppyDisk.cs | 80 ++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) 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 ec52e5cb1e..83269135d3 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDC.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Disk/NECUPD765.FDC.cs @@ -394,6 +394,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // temp sector index byte secIdx = ActiveCommandParams.Sector; + // hack for when another drive (non-existent) is being called + if (ActiveDrive.ID != 0) + DiskDriveIndex = 0; + // do we have a valid disk inserted? if (!ActiveDrive.FLAG_READY) { diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs index f9a6d947ca..8f14e4bb82 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs @@ -163,6 +163,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum sec.ContainsMultipleWeakSectors = true; } } + else if (DetectAlkatraz(ref weakArr)) + { + Protection = ProtectionType.Alkatraz; + } + else if (DetectPaulOwens(ref weakArr)) + { + Protection = ProtectionType.PaulOwens; + } } /// @@ -223,6 +231,72 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum return true; } + /// + /// Detect speedlock weak sector + /// + /// + /// + public bool DetectAlkatraz(ref int[] weak) + { + // 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")) + return false; + + // Alkatraz protection appears to revolve around a track on the disk with 18 sectors, + // (track position is not consistent) with the sector ID info being incorrect: + // TrackID is consistent between the sectors although is usually high (233, 237 etc) + // SideID is fairly random looking but with all IDs being even + // SectorID is also fairly random looking but contains both odd and even numbers + // + // There doesnt appear to be any CRC errors in this track, but the sector size is always 1 (256 bytes) + // Each sector contains different filler byte + // Presumably all of this weird data needs to be read correctly for decryption to succeed and the game to load + + // Immediately following this track are a number of tracks and sectors with a DAM set. + // This presumably has something to do with the protection scheme + + // Finally, when the 18 sector track is read, the CPU supplies a strange GAP3 value (10). + // Perhaps the alkatraz protection scheme is reading the ID marks as sector data because of this? + + + foreach (var t in DiskTracks) + { + foreach (var s in t.Sectors) + { + if (s.Status1 > 0 || s.Status2 > 0) + { + string tvcv = ""; + } + } + } + + return true; + } + + /// + /// Detect speedlock weak sector + /// + /// + /// + public bool DetectPaulOwens(ref int[] weak) + { + // 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")) + return false; + + /* Paul Owens protection appears to exibit the following things: + * + * * There are more than 10 cylinders + * * Cylinder 1 has no sector data + * * The sector ID infomation in most cases contains incorrect track IDs + * * Track 0 is pretty much the only track that appears to be standard (assume this is the boot track) + * */ + + return true; + } + /// /// Should be run at the end of the ParseDisk process /// If speedlock is detected the flag is set in the disk image @@ -528,7 +602,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public enum ProtectionType { None, - Speedlock + Speedlock, + Alkatraz, + Hexagon, + Frontier, + PaulOwens } }