]> hydra-www.ietfng.org Git - acmetensortoys-chiptunes/commitdiff
NPF: two 5-bit cmds in track
authorNathaniel Wesley Filardo <nwf@smaug.priv.ietfng.org>
Sun, 11 Apr 2010 08:35:59 +0000 (04:35 -0400)
committerNathaniel Wesley Filardo <nwf@smaug.priv.ietfng.org>
Sun, 11 Apr 2010 08:35:59 +0000 (04:35 -0400)
progenv/tracker_optimize.pl
progenv/trackerfmt.h
target/main.c

index c4a4fe83c122ac79ac85951df3cd50ada08b9efa..357f7f6a88d9610fcea0e7e38aafb400b90e7c05 100644 (file)
@@ -51,7 +51,7 @@ my @OVERPAR = (
     , 'PACKSIZE_RESOURCE' => '13'
     , 'PACKSIZE_SONGTRACK' => '6'
     , 'PACKSIZE_SONGTRANS' => '4'
-    , 'PACKSIZE_TRACKCMD' => '4'
+    , 'PACKSIZE_TRACKCMD' => '5'
     , 'PACKSIZE_TRACKINST' => '4'
     , 'PACKSIZE_TRACKPAR' => '8'
     , 'PACKSIZE_TRACKNOTE' => '7'
@@ -446,7 +446,6 @@ sub pack_song($$$) {
 sub pack_tracks($$$) {
     my ($v, $format, $trackrows) = @_;
 
-    die if $$v{'version'} != 1;   # XXX cmd 1
 
     return [map {
         my $pi = new_pack();
@@ -455,22 +454,37 @@ sub pack_tracks($$$) {
 
             my $hasnote = (defined $note  and $note  != 0);
             my $hasinst = (defined $instr and $instr != 0);
-            my $hascmd  = (defined $c0    and $c0    != 0);
+            my $hascmd0 = (defined $c0    and $c0    != 0);
+            my $hascmd1 = (defined $c1    and $c1    != 0);
+
+            if ($hascmd1 and not $hascmd0) {
+                $hascmd0 = 1;
+                $hascmd1 = 0;
+                $c0 = $c1;
+                $p0 = $p1;
+            }
 
             my $flags = 0;
             $flags += 1 if $hasnote;
             $flags += 2 if $hasinst;
-            $flags += 4 if $hascmd;
+            $flags += 4 if $hascmd0 or $hascmd1;
 
             append_pack($pi, 3, $flags);
+            append_pack($pi, 1, $hascmd1) if $hascmd0;
             append_pack($pi, $$format{'PACKSIZE_TRACKNOTE'}, $note)
                 if $hasnote;
             append_pack($pi, $$format{'PACKSIZE_TRACKINST'}, $instr)
                 if $hasinst;
-            append_pack($pi, $$format{'PACKSIZE_TRACKCMD'}, $c0)
-                if $hascmd;
-            append_pack($pi, $$format{'PACKSIZE_TRACKPAR'}, $p0)
-                if $hascmd;
+            if($hascmd0) {
+                append_pack($pi, $$format{'PACKSIZE_TRACKCMD'}, $c0);
+                append_pack($pi, $$format{'PACKSIZE_TRACKPAR'}, $p0);
+            }
+            if($hascmd1) {
+                die "Unable to encode multiple commands in track line!" if $$v{'version'} < 2;
+                append_pack($pi, $$format{'PACKSIZE_TRACKCMD'}, $c1);
+                append_pack($pi, $$format{'PACKSIZE_TRACKPAR'}, $p1);
+            }
+
         }
         ${finish_pack($pi)}[0];
     } @$trackrows];
index 5ad379a62e0dd4300a0ac73590e837ab20655b21..4d1d98015ed287155f8c0417c29de1044953d031 100644 (file)
@@ -12,7 +12,7 @@
 #define PACKSIZE_INSTRPAR      8
 #define PACKSIZE_TRACKNOTE     7
 #define PACKSIZE_TRACKINST     4
-#define PACKSIZE_TRACKCMD      4
+#define PACKSIZE_TRACKCMD      5
 #define PACKSIZE_TRACKPAR      8
 
 #define NR_CHAN         4   /**< Number of channels active in the system */
index 9d54c95375ad8c82a4e18f8b2e8574e40c6d82d6..258a3e36da0ac116f6d79e92b19d4d6864cc62f0 100644 (file)
@@ -214,20 +214,17 @@ static void playroutine() {
                        if(playsong) {
                                for(ch = 0; ch < NR_CHAN; ch++) {
                                        if(channel[ch].tnum) {
-                                               u8 note, instr, cmd, param;
+                                               u8 note, instr;
                                                u8 fields;
 
                                                fields = readchunk(&channel[ch].trackup, 3);
                                                note = 0;
                                                instr = 0;
-                                               cmd = 0;
-                                               param = 0;
+                                               if((fields & 4) && readchunk(&channel[ch].trackup, 1)) {
+                                                       fields |= 8;
+                                               }
                                                if(fields & 1) note = readchunk(&channel[ch].trackup, PACKSIZE_TRACKNOTE);
                                                if(fields & 2) instr = readchunk(&channel[ch].trackup, PACKSIZE_TRACKINST);
-                                               if(fields & 4) {
-                                                       cmd = readchunk(&channel[ch].trackup, PACKSIZE_TRACKCMD);
-                                                       param = readchunk(&channel[ch].trackup, PACKSIZE_TRACKPAR);
-                                               }
                                                if(note) {
                                                        channel[ch].tnote = note + channel[ch].transp;
                                                        if(!instr) instr = channel[ch].lastinstr;
@@ -253,7 +250,17 @@ static void playroutine() {
                                                        channel[ch].dutyd = 0;
                                                        channel[ch].vdepth = 0;
                                                }
-                                               if(cmd) runcmd(ch, cmd, param);
+                                               if(fields & 4) {
+                                                       u8 cmd = readchunk(&channel[ch].trackup, PACKSIZE_TRACKCMD);
+                                                       u8 param = readchunk(&channel[ch].trackup, PACKSIZE_TRACKPAR);
+                                                       runcmd(ch, cmd, param);
+                                               }
+                                               if(fields & 8) {
+                                                       u8 cmd = readchunk(&channel[ch].trackup, PACKSIZE_TRACKCMD);
+                                                       u8 param = readchunk(&channel[ch].trackup, PACKSIZE_TRACKPAR);
+                                                       runcmd(ch, cmd, param);
+                                               }
+
                                        }
                                }