changeset 968:5e0a05c84694

Fix RSID MD5 hash calculation.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 21 Nov 2012 00:14:52 +0200
parents 0233c5fd7d5e
children b9e6f929a617
files src/xs_length.c
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/xs_length.c	Wed Nov 21 00:11:00 2012 +0200
+++ b/src/xs_length.c	Wed Nov 21 00:14:52 2012 +0200
@@ -345,7 +345,7 @@
  */
 typedef struct
 {
-    gchar magicID[4];    /* "PSID" / "RSID" magic identifier */
+    gchar magic[4];    /* "PSID" / "RSID" magic identifier */
     guint16 version,     /* Version number */
         dataOffset,      /* Start of actual c64 data in file */
         loadAddress,     /* Loading address */
@@ -377,13 +377,14 @@
     guint8 *songData = NULL;
     guint8 ib8[2], i8;
     gint index, result;
+    gboolean isRSID;
 
     /* Try to open the file */
     if ((inFile = xs_fopen(filename, "rb")) == NULL)
         goto error;
 
     /* Read PSID header in */
-    if (!xs_fread_str(inFile, psidH.magicID, sizeof(psidH.magicID)) ||
+    if (!xs_fread_str(inFile, psidH.magic, sizeof(psidH.magic)) ||
         !xs_fread_be16(inFile, &psidH.version) ||
         !xs_fread_be16(inFile, &psidH.dataOffset) ||
         !xs_fread_be16(inFile, &psidH.loadAddress) ||
@@ -404,7 +405,9 @@
         xs_error("Not a supported PSID or RSID file '%s'\n", filename);
         goto error;
     }
-        
+
+    isRSID = psidH.magic[0] == 'R';
+
     if (!xs_fread_str(inFile, psidH.sidName, sizeof(psidH.sidName)) ||
         !xs_fread_str(inFile, psidH.sidAuthor, sizeof(psidH.sidAuthor)) ||
         !xs_fread_str(inFile, psidH.sidCopyright, sizeof(psidH.sidCopyright)))
@@ -471,10 +474,14 @@
 #undef XSADDHASH
 
     /* Append song speed data to hash */
-    i8 = 0;
+    i8 = isRSID ? 60 : 0;
     for (index = 0; index < psidH.nSongs && index < 32; index++)
     {
-        i8 = (psidH.speed & (1 << index)) ? 60 : 0;
+        if (isRSID)
+            i8 = 60;
+        else
+            i8 = (psidH.speed & (1 << index)) ? 60 : 0;
+
         xs_md5_append(&inState, &i8, sizeof(i8));
     }