mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-09 22:54:03 +09:00
edit.js: can read existing files; change on tty key read that arrow keys are now distinguished from ctrl-S or something
This commit is contained in:
@@ -376,6 +376,18 @@ String.prototype.trimNull = function() {
|
|||||||
}
|
}
|
||||||
// ncurses-like terminal control
|
// ncurses-like terminal control
|
||||||
var con = {};
|
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() {
|
con.getch = function() {
|
||||||
return sys.readKey();
|
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));
|
return [-41,-42,-43,-44,-45,-46,-47,-48].map(it => sys.peek(it));
|
||||||
};
|
};
|
||||||
Object.freeze(con);
|
Object.freeze(con);
|
||||||
// system management function
|
// system management function
|
||||||
var system = {};
|
var system = {};
|
||||||
system.maxmem = function() {
|
system.maxmem = function() {
|
||||||
return sys.peek(-65) | (sys.peek(-66) << 8) | (sys.peek(-67) << 16) | (sys.peek(-68) << 24);
|
return sys.peek(-65) | (sys.peek(-66) << 8) | (sys.peek(-67) << 16) | (sys.peek(-68) << 24);
|
||||||
|
|||||||
6
assets/disk0/home/keypolltest.js
Normal file
6
assets/disk0/home/keypolltest.js
Normal file
@@ -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;
|
||||||
|
}
|
||||||
@@ -98,6 +98,7 @@ shell.replaceVarCall = function(value) {
|
|||||||
return replaceMap.map(it => (it.r) ? _TVDOS.variables[it.s] : it.s).join('');
|
return replaceMap.map(it => (it.r) ? _TVDOS.variables[it.s] : it.s).join('');
|
||||||
}
|
}
|
||||||
shell.getPwd = function() { return shell_pwd; }
|
shell.getPwd = function() { return shell_pwd; }
|
||||||
|
shell.getPwdString = function() { return "\\" + (shell_pwd.concat([""])).join("\\"); }
|
||||||
shell.getCurrentDrive = function() { return CURRENT_DRIVE; }
|
shell.getCurrentDrive = function() { return CURRENT_DRIVE; }
|
||||||
// example input: echo "the string" > subdir\test.txt
|
// example input: echo "the string" > subdir\test.txt
|
||||||
shell.parse = function(input) {
|
shell.parse = function(input) {
|
||||||
@@ -422,12 +423,12 @@ if (goInteractive) {
|
|||||||
print(s);
|
print(s);
|
||||||
}
|
}
|
||||||
// backspace
|
// backspace
|
||||||
else if (key === 8 && cmdbuf.length > 0) {
|
else if (key === con.KEY_BACKSPACE && cmdbuf.length > 0) {
|
||||||
cmdbuf = cmdbuf.substring(0, cmdbuf.length - 1);
|
cmdbuf = cmdbuf.substring(0, cmdbuf.length - 1);
|
||||||
print(String.fromCharCode(key));
|
print(String.fromCharCode(key));
|
||||||
}
|
}
|
||||||
// enter
|
// enter
|
||||||
else if (key === 10 || key === 13) {
|
else if (key === 10 || key === con.KEY_RETURN) {
|
||||||
println();
|
println();
|
||||||
try {
|
try {
|
||||||
errorlevel = 0; // reset the number
|
errorlevel = 0; // reset the number
|
||||||
@@ -451,7 +452,7 @@ if (goInteractive) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// up arrow
|
// 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;
|
cmdHistoryScroll += 1;
|
||||||
|
|
||||||
// back the cursor in order to type new cmd
|
// back the cursor in order to type new cmd
|
||||||
@@ -463,7 +464,7 @@ if (goInteractive) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
// down arrow
|
// down arrow
|
||||||
else if (key === 20) {
|
else if (key === con.KEY_DOWN) {
|
||||||
if (cmdHistoryScroll > 0) {
|
if (cmdHistoryScroll > 0) {
|
||||||
// back the cursor in order to type new cmd
|
// back the cursor in order to type new cmd
|
||||||
var x = 0;
|
var x = 0;
|
||||||
|
|||||||
@@ -7,15 +7,24 @@ else {
|
|||||||
println("File to edit?");
|
println("File to edit?");
|
||||||
filename = read();
|
filename = read();
|
||||||
}
|
}
|
||||||
|
let driveLetter = _G.shell.getCurrentDrive();
|
||||||
|
let filePath = _G.shell.getPwdString() + filename;
|
||||||
|
|
||||||
let scroll = 0;
|
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 textbuffer = [""];
|
||||||
let cursorRow = 0;
|
let cursorRow = 0;
|
||||||
let cursorCol = 0;
|
let cursorCol = 0;
|
||||||
let exit = false;
|
let exit = false;
|
||||||
let scene = -1; // -1: main, 0: filemenu, 1: editmenu , ...
|
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 windowWidth = con.getmaxyx()[1];
|
||||||
let windowHeight = con.getmaxyx()[0];
|
let windowHeight = con.getmaxyx()[0];
|
||||||
let paintWidth = windowWidth - 4;
|
let paintWidth = windowWidth - 4;
|
||||||
@@ -189,8 +198,7 @@ function gotoText() {
|
|||||||
// FUNCTIONING FUNCTIONS (LOL) //
|
// FUNCTIONING FUNCTIONS (LOL) //
|
||||||
|
|
||||||
function writeout() {
|
function writeout() {
|
||||||
var driveLetter = _G.shell.getCurrentDrive();
|
filesystem.open(driveLetter, filePath, "W");
|
||||||
filesystem.open(driveLetter, filename, "W");
|
|
||||||
filesystem.write(driveLetter, textbuffer.join('\n'));
|
filesystem.write(driveLetter, textbuffer.join('\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,15 +244,19 @@ function appendLine() {
|
|||||||
gotoText();
|
gotoText();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_status();
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
drawMain();
|
drawMain();
|
||||||
drawTextbuffer();
|
drawTextbuffer();
|
||||||
|
|
||||||
let bulletinShown = false;
|
let bulletinShown = false;
|
||||||
|
|
||||||
// TODO for existing file, show [ Read $n Lines ]
|
// show "welcome" message
|
||||||
// TODO for new file, show [ New File ]
|
if (!editingExistingFile)
|
||||||
displayBulletin(`Wrote ${textbuffer.length} Lines`);
|
displayBulletin(`New File`);
|
||||||
|
else
|
||||||
|
displayBulletin(`Read ${textbuffer.length} Lines`);
|
||||||
|
|
||||||
|
|
||||||
while (!exit) {
|
while (!exit) {
|
||||||
let key = con.getch();
|
let key = con.getch();
|
||||||
@@ -257,9 +269,9 @@ while (!exit) {
|
|||||||
writeout();
|
writeout();
|
||||||
displayBulletin(`Wrote ${textbuffer.length} lines`);
|
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();
|
appendLine();
|
||||||
}
|
}
|
||||||
else if (key >= 32) { // printables (excludes \n)
|
else if (key >= 32) { // printables (excludes \n)
|
||||||
|
|||||||
@@ -88,24 +88,27 @@ con.move(termH + 1, 2);
|
|||||||
while (true) {
|
while (true) {
|
||||||
// read a key
|
// read a key
|
||||||
key = con.getch();
|
key = con.getch();
|
||||||
|
|
||||||
|
//serial.println("key = "+key);
|
||||||
|
|
||||||
// do something with key read
|
// do something with key read
|
||||||
/*Q*/if (key == 113 || key == 81) break;
|
/*Q*/if (key == 113 || key == 81) break;
|
||||||
/*R*/else if (key == 114 || key == 82) repaint();
|
/*R*/else if (key == 114 || key == 82) repaint();
|
||||||
/*up*/else if (key == 19) {
|
/*up*/else if (key == con.KEY_UP) {
|
||||||
scroll -= scrollSize;
|
scroll -= scrollSize;
|
||||||
if (scroll < 0) scroll = 0;
|
if (scroll < 0) scroll = 0;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
/*down*/else if (key == 20) {
|
/*down*/else if (key == con.KEY_DOWN) {
|
||||||
scroll += scrollSize;
|
scroll += scrollSize;
|
||||||
if (scroll > lineToBytes.length - termH) scroll = lineToBytes.length - termH;
|
if (scroll > lineToBytes.length - termH) scroll = lineToBytes.length - termH;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
/*left*/else if (key == 21 && pan > 0) {
|
/*left*/else if (key == con.KEY_LEFT && pan > 0) {
|
||||||
pan -= panSize;
|
pan -= panSize;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
/*right*/else if (key == 22 && pan < maxPan - termW) {
|
/*right*/else if (key == con.KEY_RIGHT && pan < maxPan - termW) {
|
||||||
pan += panSize;
|
pan += panSize;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
@@ -113,7 +116,7 @@ while (true) {
|
|||||||
print(String.fromCharCode(key));
|
print(String.fromCharCode(key));
|
||||||
numbuf = (numbuf * 10) + (key - 48);
|
numbuf = (numbuf * 10) + (key - 48);
|
||||||
}
|
}
|
||||||
/*bksp*/else if (key == 8) {
|
/*bksp*/else if (key == con.KEY_BACKSPACE) {
|
||||||
if (numbuf > 0) print(String.fromCharCode(key));
|
if (numbuf > 0) print(String.fromCharCode(key));
|
||||||
numbuf = (numbuf / 10)|0;
|
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();
|
resetKeyReadStatus();
|
||||||
con.move(termH + 1, 1);
|
con.move(termH + 1, 1);
|
||||||
print(":"+" ".repeat(termW - 2));
|
print(":"+" ".repeat(termW - 2));
|
||||||
con.move(termH + 1, 2);
|
con.move(termH + 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
serial.println("numbuf = "+numbuf);
|
//serial.println("numbuf = "+numbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
con.move(termH + 1, 1);
|
con.move(termH + 1, 1);
|
||||||
|
|||||||
@@ -52,6 +52,22 @@ class VMJSR223Delegate(val vm: VM) {
|
|||||||
/**
|
/**
|
||||||
* @return key being hit, of which:
|
* @return key being hit, of which:
|
||||||
* a-zA-Z1-9: corresponding ASCII code
|
* 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
|
* ^A-^Z: 1 through 26
|
||||||
*/
|
*/
|
||||||
fun readKey(): Int {
|
fun readKey(): Int {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.tsvm.peripheral
|
package net.torvald.tsvm.peripheral
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.Input
|
||||||
import com.badlogic.gdx.InputProcessor
|
import com.badlogic.gdx.InputProcessor
|
||||||
import net.torvald.UnsafeHelper
|
import net.torvald.UnsafeHelper
|
||||||
import net.torvald.tsvm.VM
|
import net.torvald.tsvm.VM
|
||||||
@@ -252,8 +253,8 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun keyTyped(p0: Char): Boolean {
|
override fun keyTyped(p0: Char): Boolean {
|
||||||
if (keyboardInputRequested && !ttySpecialKeyLatched && p0.toInt() > 0) {
|
if (keyboardInputRequested && p0.toInt() > 0) {
|
||||||
//println("[IO] Key typed: ${p0.toInt()}")
|
//println("[IO] key typed = ${p0.toInt()}")
|
||||||
keyboardBuffer.appendHead(p0.toByte())
|
keyboardBuffer.appendHead(p0.toByte())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -267,7 +268,7 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun keyUp(p0: Int): Boolean {
|
override fun keyUp(p0: Int): Boolean {
|
||||||
ttySpecialKeyLatched = false
|
//ttySpecialKeyLatched = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,16 +280,29 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
private var uptimeCounterLatched = false
|
private var uptimeCounterLatched = false
|
||||||
private var RTClatched = false
|
private var RTClatched = false
|
||||||
private var rawInputFunctionLatched = false
|
private var rawInputFunctionLatched = false
|
||||||
private var ttySpecialKeyLatched = false
|
private var specialKeys = hashMapOf(
|
||||||
// UP DN LE RI
|
Input.Keys.HOME to 199.toByte(),
|
||||||
private var specialKey = listOf(19,20,21,22).toSortedSet()
|
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 {
|
override fun keyDown(p0: Int): Boolean {
|
||||||
if (keyboardInputRequested && !ttySpecialKeyLatched && p0 in specialKey) {
|
if (keyboardInputRequested) {
|
||||||
//println("[IO] Key down: $p0")
|
specialKeys[p0]?.let {
|
||||||
keyboardBuffer.appendHead(p0.toByte())
|
//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 {
|
override fun touchDown(p0: Int, p1: Int, p2: Int, p3: Int): Boolean {
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ MMIO
|
|||||||
90 RO: BMS calculated battery percentage where 255 is 100%
|
90 RO: BMS calculated battery percentage where 255 is 100%
|
||||||
91 RO: BMS battery voltage multiplied by 10 (127 = "12.7 V")
|
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
|
4076..4079 RW: 8-bit status code for the port
|
||||||
4080..4083 RO: 8-bit status code for connected device
|
4080..4083 RO: 8-bit status code for connected device
|
||||||
|
|||||||
Reference in New Issue
Block a user