#ifndef ASSEMBLER
#endif
+ /* Packed format sizes */
+#define PACKSIZE_RESOURCE 13
+#define PACKSIZE_SONGTRACK 6
+#define PACKSIZE_SONGTRANS 4
+#define PACKSIZE_INSTRCMD 8
+#define PACKSIZE_INSTRPAR 8
+#define PACKSIZE_TRACKNOTE 7
+#define PACKSIZE_TRACKINST 4
+#define PACKSIZE_TRACKCMD 4
+#define PACKSIZE_TRACKPAR 8
+
#define NR_CHAN 4 /**< Number of channels active in the system */
#define TRACKLEN 32 /**< Rows in a track */
u8 transp;
gottransp = readchunk(&songup, 1);
- channel[ch].tnum = readchunk(&songup, 6);
+ channel[ch].tnum = readchunk(&songup, PACKSIZE_SONGTRACK);
if(gottransp) {
- transp = readchunk(&songup, 4);
+ transp = readchunk(&songup, PACKSIZE_SONGTRANS);
if(transp & 0x8) transp |= 0xf0;
} else {
transp = 0;
instr = 0;
cmd = 0;
param = 0;
- if(fields & 1) note = readchunk(&channel[ch].trackup, 7);
- if(fields & 2) instr = readchunk(&channel[ch].trackup, 4);
+ 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, 4);
- param = readchunk(&channel[ch].trackup, 8);
+ cmd = readchunk(&channel[ch].trackup, PACKSIZE_TRACKCMD);
+ param = readchunk(&channel[ch].trackup, PACKSIZE_TRACKPAR);
}
if(note) {
channel[ch].tnote = note + channel[ch].transp;
}
trackpos++;
- trackpos &= 31;
+ trackpos &= (TRACKLEN-1);
}
}
}
initup(&up, 0);
for(i = 0; i < 16 + MAXTRACK; i++) {
- resources[i] = readchunk(&up, 13);
+ resources[i] = readchunk(&up, PACKSIZE_RESOURCE);
}
initup(&songup, resources[0]);
for(i = 0; i < 16 + maxtrack; i++) {
// if(exportfile) fprintf(exportfile, "songdata_resources%d:\n", i);
- exportchunk(resources[i], 13);
+ exportchunk(resources[i], PACKSIZE_RESOURCE);
}
resources[nres++] = alignbyte();
- // if(exportfile) fprintf(exportfile, "songdata_song:\n");
+ if(exportfile) fprintf(exportfile, "songdata_song:\n");
for(i = 0; i < songlen; i++) {
- for(j = 0; j < 4; j++) {
+ for(j = 0; j < NR_CHAN; j++) {
if(song[i].transp[j]) {
exportchunk(1, 1);
- exportchunk(song[i].track[j], 6);
- exportchunk(song[i].transp[j], 4);
+ exportchunk(song[i].track[j], PACKSIZE_SONGTRACK);
+ exportchunk(song[i].transp[j], PACKSIZE_SONGTRANS);
} else {
exportchunk(0, 1);
- exportchunk(song[i].track[j], 6);
+ exportchunk(song[i].track[j], PACKSIZE_SONGTRACK);
}
}
}
// if(exportfile) fprintf(exportfile, "songdata_instrument%d:\n", i);
if(instrument[i].length > 1) {
for(j = 0; j < instrument[i].length; j++) {
- exportchunk(packcmd(instrument[i].line[j].cmd), 8);
- exportchunk(instrument[i].line[j].param, 8);
+ exportchunk(packcmd(instrument[i].line[j].cmd), PACKSIZE_INSTRCMD);
+ exportchunk(instrument[i].line[j].param, PACKSIZE_INSTRPAR);
}
}
- exportchunk(0, 8);
+ exportchunk(0, PACKSIZE_INSTRCMD);
}
for(i = 1; i <= maxtrack; i++) {
exportchunk(!!cmd, 1);
if(track[i].line[j].note) {
- exportchunk(track[i].line[j].note, 7);
+ exportchunk(track[i].line[j].note, PACKSIZE_TRACKNOTE);
}
if(track[i].line[j].instr) {
- exportchunk(track[i].line[j].instr, 4);
+ exportchunk(track[i].line[j].instr, PACKSIZE_TRACKINST);
}
if(cmd) {
- exportchunk(cmd, 4);
- exportchunk(track[i].line[j].param[0], 8);
+ exportchunk(cmd, PACKSIZE_TRACKCMD);
+ exportchunk(track[i].line[j].param[0], PACKSIZE_TRACKPAR);
}
}
}