Skip to content

Commit

Permalink
Restrict compilaton for unfinished players
Browse files Browse the repository at this point in the history
(temporary solution within #28)
  • Loading branch information
mborik committed Jan 7, 2023
1 parent 6360e5e commit 74e8410
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
37 changes: 26 additions & 11 deletions src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,37 @@ export default class Compiler extends CompilerRender implements CompilerOptions
}

private async preparePlayer() {
const playerTypeResult =
let playerTypeResult =
(this.playerType < 0) ?
this.playerTypeByData :
Math.max(this.playerType, this.playerTypeByData);

if (this.songData != null) {
this.log(`Song data length: ${this.songData.length} bytes`);
this.log(`Minimal player version by song data: ${constants.CURRENT_PLAYER_MAJOR_VERSION}.${this.playerTypeByData}`);
}

if (this.playerType >= 0 && playerTypeResult !== this.playerType) {
this.log(`Requested player type (${this.playerType}) is ${
this.log(`WARNING: Requested player version (1.${this.playerType}) is ${
(this.playerType > playerTypeResult) ? 'higher' : 'lower'
} than is needed for song data (${playerTypeResult})`, true);
} than is needed for song data (1.${playerTypeResult})!`);

if (this.verbose && this.playerType < playerTypeResult) {
this.log('All unsupported commands by selected version of player will be ignored.');
}
}

/*
* FIXME Temporary solution for unfinished player versions 2 and 3
* (https://github.com/mborik/SAA1099Tracker/issues/28)
*/
if (playerTypeResult > 1) {
if (this.playerType >= 0 && this.playerType < 2) {
playerTypeResult = this.playerType;
}
else {
throw 'Players of version 1.2 and 1.3 are not yet supported!';
}
}

const resourceFileName = `assets/data/saa-player-${
Expand Down Expand Up @@ -527,14 +549,7 @@ export default class Compiler extends CompilerRender implements CompilerOptions
}

private finalizeOutputBinary() {
let totalLen = 0;

if (this.songData != null) {
totalLen += this.songData.length;

this.log(`Song data length: ${this.songData.length} bytes`);
this.log(`Minimal player type by song data: ${constants.CURRENT_PLAYER_MAJOR_VERSION}.${this.playerTypeByData}`);
}
let totalLen = this.songData?.length ?? 0;

if (this.playerData != null) {
totalLen += this.playerData.length;
Expand Down
15 changes: 8 additions & 7 deletions src/compiler/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,9 @@ export default class CompilerRender extends CompilerOptimizer {
case 0x1 : // PORTAMENTO UP
case 0x2 : // PORTAMENTO DOWN
case 0x3 : // GLISSANDO TO GIVEN NOTE
case 0xA : // VOLUME SLIDE
if (
(dat & 0x0F) === 0 || (dat & 0xF0) === 0 || // `period` nor `pitch` cannot be 0
(cmd === 0xA && (dat & 0x0F) === 0x08) || // value change for VOLUME SLIDE cannot be 8
(cmd === 0x3 && ton === 0) // missing tone for GLISSANDO
(cmd === 0x3 && ton === 0) // missing tone for GLISSANDO
) {
removedCmd.add(cmdStr);
cmd = 0;
Expand All @@ -197,6 +195,9 @@ export default class CompilerRender extends CompilerOptimizer {
}
break;

case 0xA : // VOLUME SLIDE
break;

case 0xB : // BREAK CURRENT CHANNEL-PATTERN AND LOOP FROM LINE
if (dat < 0 || dat >= i) { // line number cannot be >= actual line number
removedCmd.add(cmdStr);
Expand Down Expand Up @@ -349,12 +350,12 @@ export default class CompilerRender extends CompilerOptimizer {
// vX.3 - 123+45+6789ABCDEF
this.playerTypeByData = 3;
}
else if (usedCmdId.has(6) || usedCmdId.has(7) || usedCmdId.has(8) || usedCmdId.has(9)) {
// vX.2 - 123+6789+ABCDEF
else if (usedCmdId.has(3) || usedCmdId.has(6) || usedCmdId.has(7) || usedCmdId.has(8) || usedCmdId.has(9)) {
// vX.2 - 12+36789+ABCDEF
this.playerTypeByData = 2;
}
else if (usedCmdId.has(1) || usedCmdId.has(2) || usedCmdId.has(3) || usedCmdId.has(10)) {
// vX.1 - 123A+BCDEF
else if (usedCmdId.has(1) || usedCmdId.has(2) || usedCmdId.has(10)) {
// vX.1 - 12A+BCDEF
this.playerTypeByData = 1;
}
else {
Expand Down
4 changes: 2 additions & 2 deletions templates/dlg-compiler.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ <h4 class="modal-title">Binary compilation</h4>
<div class="col-sm-14">
<div class="radio"><label class="control-label"><input id="rdPlayerTypeAuto" name="rdPlayerType" type="radio" value="-1" tabindex="5"><b>Autodetect</b></label></div>
<div class="radio"><label class="control-label"><input id="rdPlayerTypeV0" name="rdPlayerType" type="radio" value="0" tabindex="6"><b>v0</b> - supported commands: <code>BCDEF</code></label></div>
<div class="radio"><label class="control-label"><input id="rdPlayerTypeV1" name="rdPlayerType" type="radio" value="1" tabindex="7"><b>v1</b> - supported commands: <code>123A+BCDEF</code></label></div>
<div class="radio"><label class="control-label text-muted"><input id="rdPlayerTypeV2" name="rdPlayerType" type="radio" value="2" disabled="disabled" tabindex="8"><b>v2</b> - supported commands: <code>123+6789+ABCDEF</code></label></div>
<div class="radio"><label class="control-label"><input id="rdPlayerTypeV1" name="rdPlayerType" type="radio" value="1" tabindex="7"><b>v1</b> - supported commands: <code>12A+BCDEF</code></label></div>
<div class="radio"><label class="control-label text-muted"><input id="rdPlayerTypeV2" name="rdPlayerType" type="radio" value="2" disabled="disabled" tabindex="8"><b>v2</b> - supported commands: <code>12+36789+ABCDEF</code></label></div>
<div class="radio"><label class="control-label text-muted"><input id="rdPlayerTypeV3" name="rdPlayerType" type="radio" value="3" disabled="disabled" tabindex="9"><b>v3</b> - supported commands: <code>123+45+6789ABCDEF</code></label></div>
</div>
</div>
Expand Down

0 comments on commit 74e8410

Please sign in to comment.