, 'PACKSIZE_RESOURCE' => '13'
, 'PACKSIZE_SONGTRACK' => '6'
, 'PACKSIZE_SONGTRANS' => '4'
- , 'PACKSIZE_TRACKCMD' => '4'
+ , 'PACKSIZE_TRACKCMD' => '5'
, 'PACKSIZE_TRACKINST' => '4'
, 'PACKSIZE_TRACKPAR' => '8'
, 'PACKSIZE_TRACKNOTE' => '7'
sub pack_tracks($$$) {
my ($v, $format, $trackrows) = @_;
- die if $$v{'version'} != 1; # XXX cmd 1
return [map {
my $pi = new_pack();
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];
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;
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);
+ }
+
}
}