diff --git a/modules/pc6502/lib/debugger.js b/modules/pc6502/lib/debugger.js index 6e0d040e1..caa769039 100644 --- a/modules/pc6502/lib/debugger.js +++ b/modules/pc6502/lib/debugger.js @@ -180,7 +180,7 @@ if (DEBUGGER) { Component.subclass(Debugger6502, Debugger); /* - * NOTE: Every Debugger property from here to the first prototype function definition (initBus()) is a + * NOTE: Every Debugger property from here to the first prototype function definition (initBus()) is * considered a "class constant"; most of them use our "all-caps" convention (and all of them SHOULD, but * that wouldn't help us catch any bugs). * @@ -718,36 +718,29 @@ if (DEBUGGER) { * control.focus(); */ control.onkeydown = function onKeyDownDebugInput(event) { - var sCmds; + var sCmd; if (event.keyCode == Keyboard.KEYCODE.CR) { - sCmds = control.value; + sCmd = control.value; control.value = ""; - dbg.doCommands(sCmds, true); + dbg.doCommands(sCmd, true); } else if (event.keyCode == Keyboard.KEYCODE.ESC) { - control.value = sCmds = ""; + control.value = sCmd = ""; } else { if (event.keyCode == Keyboard.KEYCODE.UP) { - if (dbg.iPrevCmd < dbg.aPrevCmds.length - 1) { - sCmds = dbg.aPrevCmds[++dbg.iPrevCmd]; - } + sCmd = dbg.getPrevCommand(); } else if (event.keyCode == Keyboard.KEYCODE.DOWN) { - if (dbg.iPrevCmd > 0) { - sCmds = dbg.aPrevCmds[--dbg.iPrevCmd]; - } else { - sCmds = ""; - dbg.iPrevCmd = -1; - } + sCmd = dbg.getNextCommand(); } - if (sCmds != null) { - var cch = sCmds.length; - control.value = sCmds; + if (sCmd != null) { + var cch = sCmd.length; + control.value = sCmd; control.setSelectionRange(cch, cch); } } - if (sCmds != null && event.preventDefault) event.preventDefault(); + if (sCmd != null && event.preventDefault) event.preventDefault(); }; return true; diff --git a/modules/pc8080/lib/debugger.js b/modules/pc8080/lib/debugger.js index 8c67ca23b..e38de2fcf 100644 --- a/modules/pc8080/lib/debugger.js +++ b/modules/pc8080/lib/debugger.js @@ -180,7 +180,7 @@ if (DEBUGGER) { Component.subclass(Debugger8080, Debugger); /* - * NOTE: Every Debugger8080 property from here to the first prototype function definition (initBus()) is a + * NOTE: Every Debugger8080 property from here to the first prototype function definition (initBus()) is * considered a "class constant"; most of them use our "all-caps" convention (and all of them SHOULD, but * that wouldn't help us catch any bugs). * @@ -682,36 +682,29 @@ if (DEBUGGER) { * control.focus(); */ control.onkeydown = function onKeyDownDebugInput(event) { - var sCmds; + var sCmd; if (event.keyCode == Keyboard8080.KEYCODE.CR) { - sCmds = control.value; + sCmd = control.value; control.value = ""; - dbg.doCommands(sCmds, true); + dbg.doCommands(sCmd, true); } else if (event.keyCode == Keyboard8080.KEYCODE.ESC) { - control.value = sCmds = ""; + control.value = sCmd = ""; } else { if (event.keyCode == Keyboard8080.KEYCODE.UP) { - if (dbg.iPrevCmd < dbg.aPrevCmds.length - 1) { - sCmds = dbg.aPrevCmds[++dbg.iPrevCmd]; - } + sCmd = dbg.getPrevCommand(); } else if (event.keyCode == Keyboard8080.KEYCODE.DOWN) { - if (dbg.iPrevCmd > 0) { - sCmds = dbg.aPrevCmds[--dbg.iPrevCmd]; - } else { - sCmds = ""; - dbg.iPrevCmd = -1; - } + sCmd = dbg.getNextCommand(); } - if (sCmds != null) { - var cch = sCmds.length; - control.value = sCmds; + if (sCmd != null) { + var cch = sCmd.length; + control.value = sCmd; control.setSelectionRange(cch, cch); } } - if (sCmds != null && event.preventDefault) event.preventDefault(); + if (sCmd != null && event.preventDefault) event.preventDefault(); }; return true; diff --git a/modules/pcx86/lib/debugger.js b/modules/pcx86/lib/debugger.js index 0ea56ad51..567c60b2e 100644 --- a/modules/pcx86/lib/debugger.js +++ b/modules/pcx86/lib/debugger.js @@ -38,6 +38,7 @@ if (DEBUGGER) { var web = require("../../shared/lib/weblib"); var Component = require("../../shared/lib/component"); var Debugger = require("../../shared/lib/debugger"); + var Keys = require("../../shared/lib/keys"); var State = require("../../shared/lib/state"); var PCX86 = require("./defines"); var CPU = require("./cpu"); @@ -247,7 +248,7 @@ if (DEBUGGER) { Component.subclass(DebuggerX86, Debugger); /* - * NOTE: Every Debugger property from here to the first prototype function definition (initBus()) is a + * NOTE: Every Debugger property from here to the first prototype function definition (initBus()) is * considered a "class constant"; most of them use our "all-caps" convention (and all of them SHOULD, but * that wouldn't help us catch any bugs). * @@ -2018,36 +2019,29 @@ if (DEBUGGER) { * control.focus(); */ control.onkeydown = function onKeyDownDebugInput(event) { - var sCmds; - if (event.keyCode == Keyboard.KEYCODE.CR) { - sCmds = control.value; + var sCmd; + if (event.keyCode == Keys.KEYCODE.CR) { + sCmd = control.value; control.value = ""; - dbg.doCommands(sCmds, true); + dbg.doCommands(sCmd, true); } - else if (event.keyCode == Keyboard.KEYCODE.ESC) { - control.value = sCmds = ""; + else if (event.keyCode == Keys.KEYCODE.ESC) { + control.value = sCmd = ""; } else { - if (event.keyCode == Keyboard.KEYCODE.UP) { - if (dbg.iPrevCmd < dbg.aPrevCmds.length - 1) { - sCmds = dbg.aPrevCmds[++dbg.iPrevCmd]; - } + if (event.keyCode == Keys.KEYCODE.UP) { + sCmd = dbg.getPrevCommand(); } - else if (event.keyCode == Keyboard.KEYCODE.DOWN) { - if (dbg.iPrevCmd > 0) { - sCmds = dbg.aPrevCmds[--dbg.iPrevCmd]; - } else { - sCmds = ""; - dbg.iPrevCmd = -1; - } + else if (event.keyCode == Keys.KEYCODE.DOWN) { + sCmd = dbg.getNextCommand(); } - if (sCmds != null) { - var cch = sCmds.length; - control.value = sCmds; + if (sCmd != null) { + var cch = sCmd.length; + control.value = sCmd; control.setSelectionRange(cch, cch); } } - if (sCmds != null && event.preventDefault) event.preventDefault(); + if (sCmd != null && event.preventDefault) event.preventDefault(); }; return true; diff --git a/modules/pcx86/lib/keyboard.js b/modules/pcx86/lib/keyboard.js index 185d2ebf7..e6fefd767 100644 --- a/modules/pcx86/lib/keyboard.js +++ b/modules/pcx86/lib/keyboard.js @@ -35,6 +35,7 @@ if (NODE) { var str = require("../../shared/lib/strlib"); var web = require("../../shared/lib/weblib"); var Component = require("../../shared/lib/component"); + var Keys = require("../../shared/lib/keys"); var State = require("../../shared/lib/state"); var PCX86 = require("./defines"); var Messages = require("./messages"); @@ -153,198 +154,15 @@ Component.subclass(Keyboard); */ Keyboard.MODELS = ["US83", "US84", "US101"]; -/** - * Alphanumeric and other common (printable) ASCII codes. - * - * TODO: Determine what we can do to get ALL constants like these inlined (enum doesn't seem to - * get the job done); the problem seems to be limited to property references that use quotes, which - * is why I've 'unquoted' as many of them as possible. - * - * @enum {number} - */ -Keyboard.ASCII = { - CTRL_A: 1, CTRL_C: 3, CTRL_Z: 26, - ' ': 32, '!': 33, '"': 34, '#': 35, '$': 36, '%': 37, '&': 38, "'": 39, - '(': 40, ')': 41, '*': 42, '+': 43, ',': 44, '-': 45, '.': 46, '/': 47, - '0': 48, '1': 49, '2': 50, '3': 51, '4': 52, '5': 53, '6': 54, '7': 55, - '8': 56, '9': 57, ':': 58, ';': 59, '<': 60, '=': 61, '>': 62, '?': 63, - '@': 64, A: 65, B: 66, C: 67, D: 68, E: 69, F: 70, G: 71, - H: 72, I: 73, J: 74, K: 75, L: 76, M: 77, N: 78, O: 79, - P: 80, Q: 81, R: 82, S: 83, T: 84, U: 85, V: 86, W: 87, - X: 88, Y: 89, Z: 90, '[': 91, '\\':92, ']': 93, '^': 94, '_': 95, - '`': 96, a: 97, b: 98, c: 99, d: 100, e: 101, f: 102, g: 103, - h: 104, i: 105, j: 106, k: 107, l: 108, m: 109, n: 110, o: 111, - p: 112, q: 113, r: 114, s: 115, t: 116, u: 117, v: 118, w: 119, - x: 120, y: 121, z: 122, '{':123, '|':124, '}':125, '~':126 -}; - -/** - * Browser keyCodes we must pay particular attention to. For the most part, these are non-alphanumeric - * or function keys, some which may require special treatment (eg, preventDefault() if returning false on - * the initial keyDown event is insufficient). - * - * keyCodes for most common ASCII keys can simply use the appropriate ASCII code above. - * - * Most of these represent non-ASCII keys (eg, the LEFT arrow key), yet for some reason, browsers defined - * them using ASCII codes (eg, the LEFT arrow key uses the ASCII code for '%' or 37). This conflict is - * discussed further in the definition of CLICKCODE below. - * - * @enum {number} - */ -Keyboard.KEYCODE = { - /* 0x08 */ BS: 8, - /* 0x09 */ TAB: 9, - /* 0x0A */ LF: 10, - /* 0x0D */ CR: 13, - /* 0x10 */ SHIFT: 16, - /* 0x11 */ CTRL: 17, - /* 0x12 */ ALT: 18, - /* 0x13 */ PAUSE: 19, // PAUSE/BREAK - /* 0x14 */ CAPS_LOCK: 20, - /* 0x1B */ ESC: 27, - /* 0x20 */ SPACE: 32, - /* 0x21 */ PGUP: 33, - /* 0x22 */ PGDN: 34, - /* 0x23 */ END: 35, - /* 0x24 */ HOME: 36, - /* 0x25 */ LEFT: 37, - /* 0x26 */ UP: 38, - /* 0x27 */ RIGHT: 39, - /* 0x27 */ FF_QUOTE: 39, - /* 0x28 */ DOWN: 40, - /* 0x2C */ FF_COMMA: 44, - /* 0x2C */ PRTSC: 44, - /* 0x2D */ INS: 45, - /* 0x2E */ DEL: 46, - /* 0x2E */ FF_PERIOD: 46, - /* 0x2F */ FF_SLASH: 47, - /* 0x3B */ FF_SEMI: 59, - /* 0x3D */ FF_EQUALS: 61, - /* 0x5B */ CMD: 91, // aka WIN - /* 0x5B */ FF_LBRACK: 91, - /* 0x5C */ FF_BSLASH: 92, - /* 0x5D */ RCMD: 93, // aka MENU - /* 0x5D */ FF_RBRACK: 93, - /* 0x60 */ NUM_INS: 96, // 0 - /* 0x60 */ FF_BQUOTE: 96, - /* 0x61 */ NUM_END: 97, // 1 - /* 0x62 */ NUM_DOWN: 98, // 2 - /* 0x63 */ NUM_PGDN: 99, // 3 - /* 0x64 */ NUM_LEFT: 100, // 4 - /* 0x65 */ NUM_CENTER: 101, // 5 - /* 0x66 */ NUM_RIGHT: 102, // 6 - /* 0x67 */ NUM_HOME: 103, // 7 - /* 0x68 */ NUM_UP: 104, // 8 - /* 0x69 */ NUM_PGUP: 105, // 9 - /* 0x6A */ NUM_MUL: 106, - /* 0x6B */ NUM_ADD: 107, - /* 0x6D */ NUM_SUB: 109, - /* 0x6E */ NUM_DEL: 110, // . - /* 0x6F */ NUM_DIV: 111, - /* 0x70 */ F1: 112, - /* 0x71 */ F2: 113, - /* 0x72 */ F3: 114, - /* 0x73 */ F4: 115, - /* 0x74 */ F5: 116, - /* 0x75 */ F6: 117, - /* 0x76 */ F7: 118, - /* 0x77 */ F8: 119, - /* 0x78 */ F9: 120, - /* 0x79 */ F10: 121, - /* 0x7A */ F11: 122, - /* 0x7B */ F12: 123, - /* 0x90 */ NUM_LOCK: 144, - /* 0x91 */ SCROLL_LOCK: 145, - /* 0xAD */ FF_DASH: 173, - /* 0xBA */ SEMI: 186, // Firefox: 59 - /* 0xBB */ EQUALS: 187, // Firefox: 61 - /* 0xBC */ COMMA: 188, // Firefox: 44 - /* 0xBD */ DASH: 189, // Firefox: 173 - /* 0xBE */ PERIOD: 190, // Firefox: 46 - /* 0xBF */ SLASH: 191, // Firefox: 47 - /* 0xC0 */ BQUOTE: 192, // Firefox: 96 - /* 0xDB */ LBRACK: 219, // Firefox: 91 - /* 0xDC */ BSLASH: 220, // Firefox: 92 - /* 0xDD */ RBRACK: 221, // Firefox: 93 - /* 0xDE */ QUOTE: 222, // Firefox: 39 - /* 0xE0 */ FF_CMD: 224, // Firefox only (used for both CMD and RCMD) - // - // The following biases use what I'll call Decimal Coded Binary or DCB (the opposite of BCD), - // where the thousands digit is used to store the sum of "binary" digits 1 and/or 2 and/or 4. - // - // Technically, that makes it DCO (Decimal Coded Octal), but then again, BCD should have really - // been called HCD (Hexadecimal Coded Decimal), so if "they" can take liberties, so can I. - // - // ONDOWN is a bias we add to browser keyCodes that we want to handle on "down" rather than on "press". - // - ONDOWN: 1000, - // - // ONRIGHT is a bias we add to browser keyCodes that need to check for a "right" location (default is "left") - // - ONRIGHT: 2000, - // - // FAKE is a bias we add to signal these are fake keyCodes corresponding to internal keystroke combinations. - // The actual values are for internal use only and merely need to be unique and used consistently. - // - FAKE: 4000 -}; - -/* - * Maps "stupid" keyCodes to their "non-stupid" counterparts - */ -Keyboard.STUPID_KEYCODES = {}; -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.SEMI] = Keyboard.ASCII[';']; // 186 -> 59 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.EQUALS] = Keyboard.ASCII['=']; // 187 -> 61 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.COMMA] = Keyboard.ASCII[',']; // 188 -> 44 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.DASH] = Keyboard.ASCII['-']; // 189 -> 45 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.PERIOD] = Keyboard.ASCII['.']; // 190 -> 46 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.SLASH] = Keyboard.ASCII['/']; // 191 -> 47 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.BQUOTE] = Keyboard.ASCII['`']; // 192 -> 96 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.LBRACK] = Keyboard.ASCII['[']; // 219 -> 91 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.BSLASH] = Keyboard.ASCII['\\']; // 220 -> 92 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.RBRACK] = Keyboard.ASCII[']']; // 221 -> 93 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.QUOTE] = Keyboard.ASCII["'"]; // 222 -> 39 -Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.FF_DASH] = Keyboard.ASCII['-']; - -/* - * Maps unshifted keyCodes to their shifted counterparts; to be used when a shift-key is down. - * Alphabetic characters are handled in code, since they must also take CAPS_LOCK into consideration. - */ -Keyboard.SHIFTED_KEYCODES = {}; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['1']] = Keyboard.ASCII['!']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['2']] = Keyboard.ASCII['@']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['3']] = Keyboard.ASCII['#']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['4']] = Keyboard.ASCII['$']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['5']] = Keyboard.ASCII['%']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['6']] = Keyboard.ASCII['^']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['7']] = Keyboard.ASCII['&']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['8']] = Keyboard.ASCII['*']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['9']] = Keyboard.ASCII['(']; -Keyboard.SHIFTED_KEYCODES[Keyboard.ASCII['0']] = Keyboard.ASCII[')']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.SEMI] = Keyboard.ASCII[':']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.EQUALS] = Keyboard.ASCII['+']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.COMMA] = Keyboard.ASCII['<']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.DASH] = Keyboard.ASCII['_']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.PERIOD] = Keyboard.ASCII['>']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.SLASH] = Keyboard.ASCII['?']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.BQUOTE] = Keyboard.ASCII['~']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.LBRACK] = Keyboard.ASCII['{']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.BSLASH] = Keyboard.ASCII['|']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.RBRACK] = Keyboard.ASCII['}']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.QUOTE] = Keyboard.ASCII['"']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.FF_DASH] = Keyboard.ASCII['_']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.FF_EQUALS] = Keyboard.ASCII['+']; -Keyboard.SHIFTED_KEYCODES[Keyboard.KEYCODE.FF_SEMI] = Keyboard.ASCII[':']; - Keyboard.SIMCODE = { - BS: Keyboard.KEYCODE.BS + Keyboard.KEYCODE.ONDOWN, - TAB: Keyboard.KEYCODE.TAB + Keyboard.KEYCODE.ONDOWN, - SHIFT: Keyboard.KEYCODE.SHIFT + Keyboard.KEYCODE.ONDOWN, - RSHIFT: Keyboard.KEYCODE.SHIFT + Keyboard.KEYCODE.ONDOWN + Keyboard.KEYCODE.ONRIGHT, - CTRL: Keyboard.KEYCODE.CTRL + Keyboard.KEYCODE.ONDOWN, - ALT: Keyboard.KEYCODE.ALT + Keyboard.KEYCODE.ONDOWN, - CAPS_LOCK: Keyboard.KEYCODE.CAPS_LOCK + Keyboard.KEYCODE.ONDOWN, - ESC: Keyboard.KEYCODE.ESC + Keyboard.KEYCODE.ONDOWN, + BS: Keys.KEYCODE.BS + Keys.KEYCODE.ONDOWN, + TAB: Keys.KEYCODE.TAB + Keys.KEYCODE.ONDOWN, + SHIFT: Keys.KEYCODE.SHIFT + Keys.KEYCODE.ONDOWN, + RSHIFT: Keys.KEYCODE.SHIFT + Keys.KEYCODE.ONDOWN + Keys.KEYCODE.ONRIGHT, + CTRL: Keys.KEYCODE.CTRL + Keys.KEYCODE.ONDOWN, + ALT: Keys.KEYCODE.ALT + Keys.KEYCODE.ONDOWN, + CAPS_LOCK: Keys.KEYCODE.CAPS_LOCK + Keys.KEYCODE.ONDOWN, + ESC: Keys.KEYCODE.ESC + Keys.KEYCODE.ONDOWN, /* * It seems that a recent change to Safari on iOS (first noticed in iOS 9.1) treats SPACE * differently now, at least with regard to