From 370f920745144891db2e55e7e0aae472a70e346a Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sun, 11 Apr 2010 04:35:59 -0400 Subject: [PATCH] NPF: two 5-bit cmds in track --- progenv/tracker_optimize.pl | 30 ++++++++++++++++++++++-------- progenv/trackerfmt.h | 2 +- target/main.c | 23 +++++++++++++++-------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/progenv/tracker_optimize.pl b/progenv/tracker_optimize.pl index c4a4fe8..357f7f6 100644 --- a/progenv/tracker_optimize.pl +++ b/progenv/tracker_optimize.pl @@ -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]; diff --git a/progenv/trackerfmt.h b/progenv/trackerfmt.h index 5ad379a..4d1d980 100644 --- a/progenv/trackerfmt.h +++ b/progenv/trackerfmt.h @@ -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 */ diff --git a/target/main.c b/target/main.c index 9d54c95..258a3e3 100644 --- a/target/main.c +++ b/target/main.c @@ -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); + } + } } -- 2.50.1