changeset 1192:8841c7f8c608

Some work on the 0x0102 pattern loader.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 13:32:11 +0200
parents 1f1225b509fb
children b52905e2788e
files minijss/jloadxm.c
diffstat 1 files changed, 79 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/minijss/jloadxm.c	Thu Mar 05 13:10:36 2015 +0200
+++ b/minijss/jloadxm.c	Thu Mar 05 13:32:11 2015 +0200
@@ -220,6 +220,85 @@
 
 static int jssXMUnpackPattern102(DMResource *inFile, int size, JSSPattern *pattern)
 {
+    JSSNote *pnote;
+    int row, channel;
+    int orig = size;
+    assert(pattern != NULL);
+
+    pnote = pattern->data;
+
+    for (row = 0; row < pattern->nrows && size > 0; row++)
+    for (channel = 0; channel < pattern->nchannels && size > 0; channel++)
+    {
+        int packb, tmp;
+        JSGETBYTE(packb);
+        if (packb & 0x80)
+        {
+            if (packb & 0x01)
+            {
+                // PACK 0x01: Read note
+                JSGETBYTE(tmp);
+                pnote->note = jssXMConvertNote(tmp);
+            }
+
+            if (packb & 0x02)
+            {
+                // PACK 0x02: Read instrument
+                JSGETBYTE(tmp);
+                pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
+            }
+
+            if (packb & 0x04)
+            {
+                // PACK 0x04: Read volume
+                JSGETBYTE(tmp);
+                pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet;
+            }
+
+            if (packb & 0x08)
+            {
+                // PACK 0x08: Read effect
+                JSGETBYTE(pnote->effect);
+                pnote->param = 0;
+            }
+
+            if (packb & 0x10)
+            {
+                // PACK 0x10: Read effect parameter
+                JSGETBYTE(pnote->param);
+                if (pnote->effect == jsetNotSet && pnote->param != 0)
+                    pnote->effect = 0;
+            }
+        }
+        else
+        {
+            // All data available
+            pnote->note = jssXMConvertNote(packb & 0x7f);
+
+            // Get instrument
+            JSGETBYTE(tmp);
+            pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
+
+            // Get volume
+            JSGETBYTE(tmp);
+            pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet;
+
+            if (tmp & 0xc0)
+            {
+                JSGETBYTE(pnote->effect);
+                JSGETBYTE(pnote->param);
+            }
+            else
+            {
+                JSGETBYTE(pnote->param);
+                pnote->effect = tmp & 0xf;
+            }
+
+            if (pnote->effect == 0 && pnote->param == 0)
+                pnote->effect = pnote->param = jsetNotSet;
+        }
+        pnote++;
+    }
 
     // Check the state
     if (size > 0)