From 7d68a0b0170e0bd8c7d9deb2fc1caf643bfc44b6 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Thu, 17 Oct 2024 17:47:32 +0100 Subject: [PATCH] Fix DSKIdentifier ModChecksum function This never worked. Will probably fix a whole bunch of core-selection issues (including ones listed here: https://tasvideos.org/HomePages/CloakTheLurker/ZXHawk) --- src/BizHawk.Emulation.Common/DSKIdentifier.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Emulation.Common/DSKIdentifier.cs b/src/BizHawk.Emulation.Common/DSKIdentifier.cs index 5f1499e028d..32b9153211f 100644 --- a/src/BizHawk.Emulation.Common/DSKIdentifier.cs +++ b/src/BizHawk.Emulation.Common/DSKIdentifier.cs @@ -17,7 +17,7 @@ public class DskIdentifier private string _possibleIdent = ""; /// - /// Default fallthrough to AppleII + /// Default fallthrough to AppleII - the AppleII *.dsk format seems to be very simple with no ident strings /// public string IdentifiedSystem { get; set; } = VSystemID.Raw.AppleII; @@ -93,7 +93,7 @@ private void CalculateFormat() // check for bootable status if (trk.Sectors[0].SectorData != null && trk.Sectors[0].SectorData.Length > 0) { - switch (trk.Sectors[0].GetChecksum256()) + switch (trk.Sectors[0].GetModChecksum256()) { case 3: IdentifiedSystem = VSystemID.Raw.ZXSpectrum; @@ -116,13 +116,13 @@ private void CalculateFormat() } // at this point the disk is not standard bootable - // try format analysis + // try format analysis if (trk.Sectors.Length == 9 && trk.Sectors[0].SectorSize == 2) { switch (trk.GetLowestSectorID()) { case 1: - switch (trk.Sectors[0].GetChecksum256()) + switch (trk.Sectors[0].GetModChecksum256()) { case 3: IdentifiedSystem = VSystemID.Raw.ZXSpectrum; @@ -406,7 +406,15 @@ public class Sector public byte[] SectorData { get; set; } public bool ContainsMultipleWeakSectors { get; set; } - public int GetChecksum256() => SectorData.Sum(b => b % 256); + public int GetModChecksum256() + { + int res = 0; + for (int i = 0; i < ActualDataByteLength; i++) + { + res = (res + SectorData[i]) % 256; + } + return res; + } } } }