From d9e72db5ccc7592785c3d5eb6b4c6300c4d12127 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Wed, 25 Nov 2015 10:21:53 -0800 Subject: [PATCH] Rework bell hook --- index.js | 19 ++++++++++++------- tty.js | 11 +++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 9cb87e1..1585f0c 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/tty.js b/tty.js index 62d8965..8858657 100644 --- a/tty.js +++ b/tty.js @@ -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;