changeset 1185:cdba23d3fd0d

Version 0x0102 has slightly different pattern header than 0x0104.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 11:36:00 +0200
parents d144ebb1cdea
children eca2784bff75
files minijss/jloadxm.c
diffstat 1 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/minijss/jloadxm.c	Thu Mar 05 11:35:02 2015 +0200
+++ b/minijss/jloadxm.c	Thu Mar 05 11:36:00 2015 +0200
@@ -244,14 +244,41 @@
         // Get the pattern header
         off_t remainder, pos = dmftell(inFile);
 
-        if (!dmf_read_le32(inFile, &xmP.headSize) ||
-            !dmf_read_byte(inFile, &xmP.packing) ||
-            !dmf_read_le16(inFile, &xmP.nrows) ||
-            !dmf_read_le16(inFile, &xmP.size))
+        if (!dmf_read_le32(inFile, &xmP.headSize))
             JSSERROR(DMERR_FREAD, DMERR_FREAD,
-            "Could not read pattern header data #%d.\n",
+            "Could not read pattern header size #%d.\n",
             index);
 
+        if (module->intVersion == 0x0102)
+        {
+            Uint8 tmp;
+            if (xmP.headSize != 4 + 1 + 1 + 2)
+                JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
+                "Invalid pattern #%d header size %d, expected %d bytes.\n",
+                index, xmP.headSize, 4 + 1 + 1 + 2);
+
+            if (!dmf_read_byte(inFile, &xmP.packing) ||
+                !dmf_read_byte(inFile, &tmp) ||
+                !dmf_read_le16(inFile, &xmP.size))
+                JSSERROR(DMERR_FREAD, DMERR_FREAD,
+                "Could not read pattern header data #%d.\n",
+                index);
+            xmP.nrows = tmp;
+        }
+        else
+        {
+            if (xmP.headSize != 4 + 1 + 2 + 2)
+                JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
+                "Invalid pattern #%d header size %d, expected %d bytes.\n",
+                index, xmP.headSize, 4 + 1 + 2 + 2);
+
+            if (!dmf_read_byte(inFile, &xmP.packing) ||
+                !dmf_read_le16(inFile, &xmP.nrows) ||
+                !dmf_read_le16(inFile, &xmP.size))
+                JSSERROR(DMERR_FREAD, DMERR_FREAD,
+                "Could not read pattern header data #%d.\n",
+                index);
+        }
 
         // Check the header
         if (xmP.packing != 0)