From 012bc448456f97a4336fb268dce7b26ce173d0c3 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 24 Sep 2021 11:30:55 +0900 Subject: [PATCH] keyevent reading moved to the tvdos itself --- assets/JS_INIT.js | 45 ------ assets/disk0/home/strobotest.js | 4 +- assets/disk0/tvdos/TVDOS.SYS | 105 +++++++++++- assets/disk0/tvdos/bin/command.js | 20 +-- assets/disk0/tvdos/bin/edit.js | 2 +- assets/disk0/tvdos/bin/hexdump.js | 6 +- assets/disk0/tvdos/bin/touch.js | 6 +- assets/disk0/tvdos/gl.js | 2 +- assets/disk0/tvdos/us_colemak.key | 256 ++++++++++++++++++++++++++++++ assets/disk0/tvdos/us_qwerty.key | 256 ++++++++++++++++++++++++++++++ 10 files changed, 632 insertions(+), 70 deletions(-) create mode 100644 assets/disk0/tvdos/us_colemak.key create mode 100644 assets/disk0/tvdos/us_qwerty.key diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index 176e87d..58577d4 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -427,51 +427,6 @@ con.KEY_DELETE = 211; con.KEY_BACKSPACE = 8; con.KEY_TAB = 9; con.KEY_RETURN = 13; -let _79kfQgystrobocounter = 4294967296*0; // 0L -let _pur82anstrobotime = 4294967296*0; -let _acpgrUzstrobodelays = [0,250000000,0,25000000,0]; // 250ms, 25ms -let _sT9mpKGstrobostatus = 0; // 0: first key, 1: waiting for initial delay, 2: repeating key, 3: waiting for repeat delay -let _9gyFcs7oldkeys = []; -let _qtkf932repeatcnt932repeatcnt = 0; -let _x93paQZshiftin = false; -// basically a multi-key version of con.getch() with GDX keycodes -con.scankeys = function(callback) { - // TODO: char as a first argument of callback, which needs KeyboardLayout(QWERTY, Colemak, Dvorak, etc) - function arrayEq(a,b) { - for (var i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - return true; - } - - sys.poke(-40, 255); - let keys = [sys.peek(-41),sys.peek(-42),sys.peek(-43),sys.peek(-44),sys.peek(-45),sys.peek(-46),sys.peek(-47),sys.peek(-48)]; - if (_sT9mpKGstrobostatus % 2 == 0 && keys[0] != 0) { - _sT9mpKGstrobostatus += 1; - _pur82anstrobotime = sys.nanoTime(); - _qtkf932repeatcnt += 1; - _x93paQZshiftin = keys.includes(59) || keys.includes(60); - - callback('x', keys, _qtkf932repeatcnt); - } - else if (!arrayEq(keys, _9gyFcs7oldkeys) || keys[0] == 0) { - _sT9mpKGstrobostatus = 0; - _qtkf932repeatcnt = 0; - _x93paQZshiftin = keys.includes(59) || keys.includes(60); - } - else if (_sT9mpKGstrobostatus % 2 == 1 && sys.nanoTime() - _pur82anstrobotime < _acpgrUzstrobodelays[_sT9mpKGstrobostatus]) { - sys.spin(); - } - else { - _sT9mpKGstrobostatus += 1; - if (_sT9mpKGstrobostatus >= 4) { - _sT9mpKGstrobostatus = 2; - } - } - - _9gyFcs7oldkeys = keys; -// sys.spin(); -}; con.getch = function() { return sys.readKey(); }; diff --git a/assets/disk0/home/strobotest.js b/assets/disk0/home/strobotest.js index c1c152d..4c45f05 100644 --- a/assets/disk0/home/strobotest.js +++ b/assets/disk0/home/strobotest.js @@ -5,7 +5,7 @@ function hitCtrlQ(keys) { println("Hit Ctrl+Shift+T+R to exit") while (true) { - con.scankeys((char, keys, counter) => { - println(`${keys}\t'${char}' (${counter})`) + input.withEvent(event => { + println(event) }) } \ No newline at end of file diff --git a/assets/disk0/tvdos/TVDOS.SYS b/assets/disk0/tvdos/TVDOS.SYS index 0541e12..086c06e 100644 --- a/assets/disk0/tvdos/TVDOS.SYS +++ b/assets/disk0/tvdos/TVDOS.SYS @@ -32,7 +32,7 @@ function generateRandomHashStr(len) { } // define TVDOS -var _TVDOS = {}; +const _TVDOS = {}; _TVDOS.VERSION = "1.0"; _TVDOS.DRIVES = {}; // Object where key-value pair is : [serial-port, drive-number] // actually figure out the drive letter association @@ -48,6 +48,7 @@ _TVDOS.getPath = function() { _TVDOS.variables = { DOSDIR: "\\tvdos", LANG: "EN", + KEYBOARD: "us_qwerty", PATH: "\\tvdos\\bin;\\tbas;\\home", PATHEXT: ".com;.bat;.js", HELPPATH: "\\tvdos\\help", @@ -58,7 +59,7 @@ Object.freeze(_TVDOS); /////////////////////////////////////////////////////////////////////////////// -var filesystem = {}; +const filesystem = {}; filesystem._toPorts = (driveLetter) => { if (driveLetter.toUpperCase === undefined) { throw Error("'"+driveLetter+"' (type: "+typeof driveLetter+") is not a valid drive letter"); @@ -91,8 +92,7 @@ filesystem.open = (driveLetter, path, operationMode) => { } com.sendMessage(port[0], "OPEN"+mode+'"'+path+'",'+port[1]); - var response = com.getStatusCode(port[0]); - return (response == 0); + return com.getStatusCode(port[0]); }; // @return the entire contents of the file in String filesystem.readAll = (driveLetter) => { @@ -153,9 +153,104 @@ Object.freeze(filesystem); /////////////////////////////////////////////////////////////////////////////// +const input = {}; +const inputwork = {}; + +inputwork.keymap = []; + +input.changeKeyLayout = function(name) { + let res0 = filesystem.open("A",`tvdos/${name.toLowerCase()}.key`,"R"); + if (res0 != 0 && inputwork.keymap.length == 0) throw new Error(`I/O Error ${res0} - A:\\tvdos\\${name.toLowerCase()}.key`); + try { + inputwork.keymap = eval(filesystem.readAll("A")); + } + catch (e) { + printerrln(e); + return -1; + } +} + +// load initial key layout +input.changeKeyLayout(_TVDOS.variables.KEYBOARD || "us_qwerty"); + +// states to run the keyboard input +inputwork.stroboTime = 4294967296*0; +inputwork.stroboDelays = [0,250000000,0,25000000,0]; // 250ms, 25ms +inputwork.stroboStatus = 0; // 0: first key, 1: waiting for initial delay, 2: repeating key, 3: waiting for repeat delay +inputwork.oldKeys = []; +inputwork.oldMouse = []; +inputwork.repeatCount = 0; + +/** + * callback: takes one argument of object which + * [ , args ] + * where: + * "key_down", , , keycode0, keycode1 .. keycode7 + * "key_change", , 0, keycode0, keycode1 .. keycode7 (remaining keys that are held down) + * "mouse_down", pos-x, pos-y, 1 // yes there's only one mouse button :p + * "mouse_up", pos-x, pos-y, 0 + * "mouse_move", pos-x, pos-y,