Skip to content

Commit

Permalink
Fix DSKIdentifier ModChecksum function
Browse files Browse the repository at this point in the history
This never worked. Will probably fix a whole bunch of core-selection issues (including ones listed here: https://tasvideos.org/HomePages/CloakTheLurker/ZXHawk)
  • Loading branch information
Asnivor committed Oct 17, 2024
1 parent ce3af37 commit 7d68a0b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/BizHawk.Emulation.Common/DSKIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DskIdentifier
private string _possibleIdent = "";

/// <summary>
/// Default fallthrough to AppleII
/// Default fallthrough to AppleII - the AppleII *.dsk format seems to be very simple with no ident strings
/// </summary>
public string IdentifiedSystem { get; set; } = VSystemID.Raw.AppleII;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
}

0 comments on commit 7d68a0b

Please sign in to comment.