Rework bell hook

This commit is contained in:
Joshua Bell 2015-11-25 10:21:53 -08:00
parent 4d46a4317d
commit d9e72db5cc
2 changed files with 15 additions and 15 deletions

View File

@ -5,12 +5,6 @@ window.addEventListener('DOMContentLoaded', function () {
$('#lb_files').selectedIndex = 0;
var bell = (function () {
var b = new Bell(/^.*\/|/.exec(window.location)[0]);
return function () { b.play(); };
} ());
var frame = $('#frame');
var keyboard = frame;
@ -26,7 +20,18 @@ window.addEventListener('DOMContentLoaded', function () {
frame.parentNode.insertBefore(keyboard, frame);
}
var tty = new TTY($('#screen'), keyboard, bell);
var tty = new TTY($('#screen'), keyboard);
(function() {
// Install output hook for bell
var b = new Bell(/^.*\/|/.exec(window.location)[0]);
var orig = tty.writeChar;
tty.writeChar = function index_writeChar(c) {
if (c.charCodeAt(0) === 7)
b.play();
else
orig(c);
};
}());
var dos = new DOS(tty);
var lores = new LoRes($('#lores'), 40, 48);

11
tty.js
View File

@ -4,7 +4,7 @@
// Usage:
//
// tty = new TTY( screen_element, keyboard_element, bell );
// tty = new TTY( screen_element, keyboard_element );
// tty.clearScreen()
// tty.clearEOL()
// tty.clearEOS()
@ -34,7 +34,7 @@
// tty.TEXT_STYLE_INVERSE = 1
// tty.TEXT_STYLE_FLASH = 2
function TTY(screenElement, keyboardElement, bell) {
function TTY(screenElement, keyboardElement) {
// Constants
@ -348,15 +348,10 @@ function TTY(screenElement, keyboardElement, bell) {
case 4: // DOS hook takes care of CHR$(4)
case 5:
case 6:
case 7: // (BEL) bell - handled by index hook
// no-op
break;
case 7: // (BEL) bell
if (bell) {
bell();
}
break;
case 8: // (BS) backspace
self.cursorLeft();
break;