diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index 0ae04c9..f7e9ab1 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -376,6 +376,18 @@ String.prototype.trimNull = function() { } // ncurses-like terminal control var con = {}; +con.KEY_HOME = 199; +con.KEY_UP = 200; +con.KEY_PAGE_UP = 201; +con.KEY_LEFT = 203; +con.KEY_RIGHT = 205 +con.KEY_END = 207; +con.KEY_DOWN = 208 +con.KEY_PAGE_DOWN = 209; +con.KEY_INSERT = 210; +con.KEY_DELETE = 211; +con.KEY_BACKSPACE = 8; +con.KEY_RETURN = 13; con.getch = function() { return sys.readKey(); }; @@ -458,7 +470,7 @@ con.poll_keys = function() { return [-41,-42,-43,-44,-45,-46,-47,-48].map(it => sys.peek(it)); }; Object.freeze(con); -// system management function +// system management function var system = {}; system.maxmem = function() { return sys.peek(-65) | (sys.peek(-66) << 8) | (sys.peek(-67) << 16) | (sys.peek(-68) << 24); diff --git a/assets/disk0/home/keypolltest.js b/assets/disk0/home/keypolltest.js new file mode 100644 index 0000000..16fdc3d --- /dev/null +++ b/assets/disk0/home/keypolltest.js @@ -0,0 +1,6 @@ +println("Hit Ctrl-C or Ctrl-D to exit"); +while (true) { + let keys = con.poll_keys() + println(keys); + if (keys[1] == 129 && (keys[0] == 31 || keys[0] == 32)) break; +} \ No newline at end of file diff --git a/assets/disk0/tvdos/bin/command.js b/assets/disk0/tvdos/bin/command.js index 5a3ac82..4ec2c19 100644 --- a/assets/disk0/tvdos/bin/command.js +++ b/assets/disk0/tvdos/bin/command.js @@ -98,6 +98,7 @@ shell.replaceVarCall = function(value) { return replaceMap.map(it => (it.r) ? _TVDOS.variables[it.s] : it.s).join(''); } shell.getPwd = function() { return shell_pwd; } +shell.getPwdString = function() { return "\\" + (shell_pwd.concat([""])).join("\\"); } shell.getCurrentDrive = function() { return CURRENT_DRIVE; } // example input: echo "the string" > subdir\test.txt shell.parse = function(input) { @@ -422,12 +423,12 @@ if (goInteractive) { print(s); } // backspace - else if (key === 8 && cmdbuf.length > 0) { + else if (key === con.KEY_BACKSPACE && cmdbuf.length > 0) { cmdbuf = cmdbuf.substring(0, cmdbuf.length - 1); print(String.fromCharCode(key)); } // enter - else if (key === 10 || key === 13) { + else if (key === 10 || key === con.KEY_RETURN) { println(); try { errorlevel = 0; // reset the number @@ -451,7 +452,7 @@ if (goInteractive) { } } // up arrow - else if (key === 19 && cmdHistory.length > 0 && cmdHistoryScroll < cmdHistory.length) { + else if (key === con.KEY_UP && cmdHistory.length > 0 && cmdHistoryScroll < cmdHistory.length) { cmdHistoryScroll += 1; // back the cursor in order to type new cmd @@ -463,7 +464,7 @@ if (goInteractive) { } // down arrow - else if (key === 20) { + else if (key === con.KEY_DOWN) { if (cmdHistoryScroll > 0) { // back the cursor in order to type new cmd var x = 0; diff --git a/assets/disk0/tvdos/bin/edit.js b/assets/disk0/tvdos/bin/edit.js index 6cb070b..4e222f8 100644 --- a/assets/disk0/tvdos/bin/edit.js +++ b/assets/disk0/tvdos/bin/edit.js @@ -7,15 +7,24 @@ else { println("File to edit?"); filename = read(); } +let driveLetter = _G.shell.getCurrentDrive(); +let filePath = _G.shell.getPwdString() + filename; let scroll = 0; -//let textbuffer = ["The quick brown fox","jumps over a lazy dog 12345678901234567890", "Pack my box with", "five dozen liquor jugs", "The quick brown fox","jumps over a lazy dog 12345678901234567890", "Pack my box with", "five dozen liquor jugs"]; let textbuffer = [""]; let cursorRow = 0; let cursorCol = 0; let exit = false; let scene = -1; // -1: main, 0: filemenu, 1: editmenu , ... +// load existing file if it's there +let editingExistingFile = filesystem.open(driveLetter, filePath, "R"); +if (editingExistingFile) { + textbuffer = filesystem.readAll(driveLetter).split("\n"); + serial.println(textbuffer); +} + + let windowWidth = con.getmaxyx()[1]; let windowHeight = con.getmaxyx()[0]; let paintWidth = windowWidth - 4; @@ -189,8 +198,7 @@ function gotoText() { // FUNCTIONING FUNCTIONS (LOL) // function writeout() { - var driveLetter = _G.shell.getCurrentDrive(); - filesystem.open(driveLetter, filename, "W"); + filesystem.open(driveLetter, filePath, "W"); filesystem.write(driveLetter, textbuffer.join('\n')); } @@ -236,15 +244,19 @@ function appendLine() { gotoText(); } -reset_status(); +/////////////////////////////////////////////////////////////////////////////////////////////////// + drawMain(); drawTextbuffer(); let bulletinShown = false; -// TODO for existing file, show [ Read $n Lines ] -// TODO for new file, show [ New File ] -displayBulletin(`Wrote ${textbuffer.length} Lines`); +// show "welcome" message +if (!editingExistingFile) + displayBulletin(`New File`); +else + displayBulletin(`Read ${textbuffer.length} Lines`); + while (!exit) { let key = con.getch(); @@ -257,9 +269,9 @@ while (!exit) { writeout(); displayBulletin(`Wrote ${textbuffer.length} lines`); } - else if (key == 8) { // Bksp + else if (key == con.KEY_BACKSPACE) { // Bksp } - else if (key == 13) { // Return / ^M + else if (key == con.KEY_RETURN) { // Return appendLine(); } else if (key >= 32) { // printables (excludes \n) diff --git a/assets/disk0/tvdos/bin/less.js b/assets/disk0/tvdos/bin/less.js index 4123695..8eacd50 100644 --- a/assets/disk0/tvdos/bin/less.js +++ b/assets/disk0/tvdos/bin/less.js @@ -88,24 +88,27 @@ con.move(termH + 1, 2); while (true) { // read a key key = con.getch(); + + //serial.println("key = "+key); + // do something with key read /*Q*/if (key == 113 || key == 81) break; /*R*/else if (key == 114 || key == 82) repaint(); - /*up*/else if (key == 19) { + /*up*/else if (key == con.KEY_UP) { scroll -= scrollSize; if (scroll < 0) scroll = 0; repaint(); } - /*down*/else if (key == 20) { + /*down*/else if (key == con.KEY_DOWN) { scroll += scrollSize; if (scroll > lineToBytes.length - termH) scroll = lineToBytes.length - termH; repaint(); } - /*left*/else if (key == 21 && pan > 0) { + /*left*/else if (key == con.KEY_LEFT && pan > 0) { pan -= panSize; repaint(); } - /*right*/else if (key == 22 && pan < maxPan - termW) { + /*right*/else if (key == con.KEY_RIGHT && pan < maxPan - termW) { pan += panSize; repaint(); } @@ -113,7 +116,7 @@ while (true) { print(String.fromCharCode(key)); numbuf = (numbuf * 10) + (key - 48); } - /*bksp*/else if (key == 8) { + /*bksp*/else if (key == con.KEY_BACKSPACE) { if (numbuf > 0) print(String.fromCharCode(key)); numbuf = (numbuf / 10)|0; } @@ -129,14 +132,14 @@ while (true) { } - if (!(key >= 48 && key <= 57 || key == 8)) { + if (!(key >= 48 && key <= 57 || key == con.KEY_BACKSPACE)) { resetKeyReadStatus(); con.move(termH + 1, 1); print(":"+" ".repeat(termW - 2)); con.move(termH + 1, 2); } - serial.println("numbuf = "+numbuf); + //serial.println("numbuf = "+numbuf); } con.move(termH + 1, 1); diff --git a/src/net/torvald/tsvm/VMJSR223Delegate.kt b/src/net/torvald/tsvm/VMJSR223Delegate.kt index 7e2041e..4cc6095 100644 --- a/src/net/torvald/tsvm/VMJSR223Delegate.kt +++ b/src/net/torvald/tsvm/VMJSR223Delegate.kt @@ -52,6 +52,22 @@ class VMJSR223Delegate(val vm: VM) { /** * @return key being hit, of which: * a-zA-Z1-9: corresponding ASCII code + * + * Up: 200 + * Left: 203 + * Down: 208 + * Right: 205 + * + * PgUp: 201 + * PgDn: 209 + * Home: 199 + * End: 207 + * Ins: 201 + * Del: 211 + * + * Return: 13 (^M) + * Bksp: 8 (^H) + * * ^A-^Z: 1 through 26 */ fun readKey(): Int { diff --git a/src/net/torvald/tsvm/peripheral/IOSpace.kt b/src/net/torvald/tsvm/peripheral/IOSpace.kt index 97742c9..bb990da 100644 --- a/src/net/torvald/tsvm/peripheral/IOSpace.kt +++ b/src/net/torvald/tsvm/peripheral/IOSpace.kt @@ -1,6 +1,7 @@ package net.torvald.tsvm.peripheral import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Input import com.badlogic.gdx.InputProcessor import net.torvald.UnsafeHelper import net.torvald.tsvm.VM @@ -252,8 +253,8 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor { } override fun keyTyped(p0: Char): Boolean { - if (keyboardInputRequested && !ttySpecialKeyLatched && p0.toInt() > 0) { - //println("[IO] Key typed: ${p0.toInt()}") + if (keyboardInputRequested && p0.toInt() > 0) { + //println("[IO] key typed = ${p0.toInt()}") keyboardBuffer.appendHead(p0.toByte()) return true } @@ -267,7 +268,7 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor { } override fun keyUp(p0: Int): Boolean { - ttySpecialKeyLatched = false + //ttySpecialKeyLatched = false return true } @@ -279,16 +280,29 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor { private var uptimeCounterLatched = false private var RTClatched = false private var rawInputFunctionLatched = false - private var ttySpecialKeyLatched = false - // UP DN LE RI - private var specialKey = listOf(19,20,21,22).toSortedSet() + private var specialKeys = hashMapOf( + Input.Keys.HOME to 199.toByte(), + Input.Keys.UP to 200.toByte(), + Input.Keys.PAGE_UP to 201.toByte(), + Input.Keys.LEFT to 203.toByte(), + Input.Keys.RIGHT to 205.toByte(), + Input.Keys.END to 207.toByte(), + Input.Keys.DOWN to 208.toByte(), + Input.Keys.PAGE_DOWN to 209.toByte(), + Input.Keys.INSERT to 210.toByte(), + Input.Keys.FORWARD_DEL to 211.toByte() + ) override fun keyDown(p0: Int): Boolean { - if (keyboardInputRequested && !ttySpecialKeyLatched && p0 in specialKey) { - //println("[IO] Key down: $p0") - keyboardBuffer.appendHead(p0.toByte()) + if (keyboardInputRequested) { + specialKeys[p0]?.let { + //println("[IO] key special = ${it.toUInt()}") + keyboardBuffer.appendHead(it) + } + return true + } + else { + return false } - - return true } override fun touchDown(p0: Int, p1: Int, p2: Int, p3: Int): Boolean { diff --git a/terranmon.txt b/terranmon.txt index 5be625b..a2930f1 100644 --- a/terranmon.txt +++ b/terranmon.txt @@ -96,6 +96,7 @@ MMIO 90 RO: BMS calculated battery percentage where 255 is 100% 91 RO: BMS battery voltage multiplied by 10 (127 = "12.7 V") +1024..2047 RW: Reserved for integrated peripherals (e.g. built-in status display) 4076..4079 RW: 8-bit status code for the port 4080..4083 RO: 8-bit status code for connected device