Skip to content

Commit

Permalink
== to === and some fixes for when the processor isn't initialised
Browse files Browse the repository at this point in the history
Overlap disc drive sounds, and fix the lengths of the seeks to be more
appropriate
  • Loading branch information
mattgodbolt committed Feb 10, 2018
1 parent c77e85b commit d8849b5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
25 changes: 12 additions & 13 deletions ddnoise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ define(['./utils', 'underscore', 'promise'], function (utils, _) {
"use strict";

var IDLE = 0, SPIN_UP = 1, SPINNING = 2;
var VOLUME = 0.3;
var VOLUME = 0.25;

function DdNoise(context) {
this.context = context;
Expand Down Expand Up @@ -67,10 +67,10 @@ define(['./utils', 'underscore', 'promise'], function (utils, _) {
source.loop = !!loop;
source.buffer = sound;
source.connect(self.gain);
source.onended = function() {
source.onended = function () {
self.playing = _.without(self.playing, source);
if (!source.loop) resolve();
};
if (!source.loop) resolve();
};
source.start();
self.playing.push(source);
if (source.loop) {
Expand All @@ -80,7 +80,7 @@ define(['./utils', 'underscore', 'promise'], function (utils, _) {
};

DdNoise.prototype.spinUp = function () {
if (this.state == SPINNING || this.state == SPIN_UP) return;
if (this.state === SPINNING || this.state === SPIN_UP) return;
this.state = SPIN_UP;
var self = this;
self.play(self.sounds.motorOn).then(function () {
Expand All @@ -92,7 +92,7 @@ define(['./utils', 'underscore', 'promise'], function (utils, _) {
};

DdNoise.prototype.spinDown = function () {
if (this.state == IDLE) return;
if (this.state === IDLE) return;
this.state = IDLE;
if (this.motor) {
this.motor.stop();
Expand All @@ -102,14 +102,10 @@ define(['./utils', 'underscore', 'promise'], function (utils, _) {
};

DdNoise.prototype.seek = function (diff) {
var dir;
if (diff < 0) {
dir = true;
diff = -diff;
}
if (diff < 0) diff = -diff;
if (diff === 0) return 0;
else if (diff === 1) return this.oneShot(this.sounds.step);
else if (diff < 7) return this.oneShot(this.sounds.seek);
else if (diff < 10) return this.oneShot(this.sounds.seek);
else if (diff < 30) return this.oneShot(this.sounds.seek2);
else return this.oneShot(this.sounds.seek3);
};
Expand All @@ -125,7 +121,10 @@ define(['./utils', 'underscore', 'promise'], function (utils, _) {
}

FakeDdNoise.prototype.spinUp = FakeDdNoise.prototype.spinDown =
FakeDdNoise.prototype.mute = FakeDdNoise.prototype.unmute = FakeDdNoise.prototype.seek = utils.noop;
FakeDdNoise.prototype.mute = FakeDdNoise.prototype.unmute = utils.noop;
FakeDdNoise.prototype.seek = function () {
return 0;
}
FakeDdNoise.prototype.initialize = function () {
return Promise.resolve();
};
Expand Down
5 changes: 3 additions & 2 deletions fdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ define(['./utils'], function (utils) {
spinup();
self.realTrack[self.curDrive] += track - self.curTrack[self.curDrive];
var diff = self.drives[self.curDrive].seek(self.realTrack[self.curDrive]);
var seekLen = (noise.seek(diff) * cpu.peripheralCyclesPerSecond) | 0;
// Let disc noises overlap by ~10%
var seekLen = (noise.seek(diff) * 0.9 * cpu.peripheralCyclesPerSecond) | 0;
self.callbackTask.cancel();
self.callbackTask.schedule(Math.max(200, seekLen));
}
Expand All @@ -449,7 +450,7 @@ define(['./utils'], function (utils) {

function parameter(val) {
if (self.paramNum < 5) self.params[self.paramNum++] = val;
if (self.paramNum != self.paramReq) return;
if (self.paramNum !== self.paramReq) return;
switch (self.command) {
case 0x35: // Specify.
self.status = 0;
Expand Down
7 changes: 4 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require(['jquery', 'utils', 'video', 'soundchip', 'ddnoise', 'debug', '6502', 'c

if (queryString) {
queryString = queryString.substring(1);
if (queryString[queryString.length - 1] == '/') // workaround for shonky python web server
if (queryString[queryString.length - 1] === '/') // workaround for shonky python web server
queryString = queryString.substring(0, queryString.length - 1);
queryString.split("&").forEach(function (keyval) {
var keyAndVal = keyval.split("=");
Expand Down Expand Up @@ -343,12 +343,13 @@ require(['jquery', 'utils', 'video', 'soundchip', 'ddnoise', 'debug', '6502', 'c
var screenOffset = $screen.offset();
var x = (evt.offsetX - cubOffset.left + screenOffset.left) / $screen.width();
var y = (evt.offsetY - cubOffset.top + screenOffset.top) / $screen.height();
processor.touchScreen.onMouse(x, y, evt.buttons);
if (processor.touchScreen)
processor.touchScreen.onMouse(x, y, evt.buttons);
evt.preventDefault();
});

$(window).blur(function () {
processor.sysvia.clearKeys();
if (processor.sysvia) processor.sysvia.clearKeys();
});
document.onkeydown = keyDown;
document.onkeypress = keyPress;
Expand Down
Binary file modified sounds/disc525/seek2.wav
Binary file not shown.
Binary file modified sounds/disc525/seek3.wav
Binary file not shown.
8 changes: 4 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,16 @@ define(['jsunzip', 'promise'], function (jsunzip) {
return "UK";
}
if (localStorage.keyboardLayout) {
return localStorage.keyboardLayout == "US" ? "US" : "UK";
return localStorage.keyboardLayout === "US" ? "US" : "UK";
}
if (navigator.language) {
if (navigator.language.toLowerCase() == "en-gb") return "UK";
if (navigator.language.toLowerCase() == "en-us") return "US";
if (navigator.language.toLowerCase() === "en-gb") return "UK";
if (navigator.language.toLowerCase() === "en-us") return "US";
}
return "UK"; // Default guess of UK
}

var isUKlayout = detectKeyboardLayout() == "UK";
var isUKlayout = detectKeyboardLayout() === "UK";

if (exports.isFirefox()) {
keyCodes.SEMICOLON = 59;
Expand Down

0 comments on commit d8849b5

Please sign in to comment.