diff --git a/basic.js b/basic.js index 62c2da0..2b168b2 100644 --- a/basic.js +++ b/basic.js @@ -468,6 +468,21 @@ this.basic = (function() { 0xD683: function() { // Clear stack state.stack = []; }, + 0xFBF4: function() { // Move cursor right + if (env.tty.cursorRight) { env.tty.cursorRight(); } + }, + 0xFC10: function() { // Move cursor left + if (env.tty.cursorLeft) { env.tty.cursorLeft(); } + }, + 0xFC1A: function() { // Move cursor up + if (env.tty.cursorUp) { env.tty.cursorUp(); } + }, + 0xFC42: function() { // Clear text from cursor to bottom + if (env.tty.clearEOS) { env.tty.clearEOS(); } + }, + 0xFC66: function() { // Move cursor down + if (env.tty.cursorDown) { env.tty.cursorDown(); } + }, 0xFC9C: function() { // Clear from cursor to right if (env.tty.clearEOL) { env.tty.clearEOL(); } } diff --git a/reference.htm b/reference.htm index 5854d88..a5f1ac0 100644 --- a/reference.htm +++ b/reference.htm @@ -215,6 +215,12 @@ can be literals (unquoted strings), strings, or numbers
  • CALL -3086 - clear current hi-res page to black
  • CALL -3082 - clear current hi-res page to current color
  • CALL 54951 - clear stack (cancel pending FOR-NEXT loops and GOSUBs) +
  • CALL -1036 - move cursor right +
  • CALL -1008 - move cursor left +
  • CALL -998 - move cursor up +
  • CALL -958 - clear text from cursor to bottom of window +
  • CALL -922 - move cursor down +
  • CALL -868 - clear text from cursor to end of line
    PR# aexpr
    Direct output to slot diff --git a/tty.js b/tty.js index e449dd2..62d8965 100644 --- a/tty.js +++ b/tty.js @@ -6,6 +6,12 @@ // // tty = new TTY( screen_element, keyboard_element, bell ); // tty.clearScreen() +// tty.clearEOL() +// tty.clearEOS() +// tty.cursorLeft() +// tty.cursorRight() +// tty.cursorUp() +// tty.cursorDown() // tty.scrollScreen() // tty.setTextStyle( textStyle ) // { width: w, height: h } = tty.getScreenSize() @@ -216,6 +222,18 @@ function TTY(screenElement, keyboardElement, bell) { } }; + // Clears from the cursor position to the end of the window + this.clearEOS = function clearEOS() { + var x, y; + for (x = cursorX; x < self.textWindow.left + self.textWindow.width; x += 1) { + setCellChar(x, cursorY, 0x20); + } + for (y = cursorY + 1; y < self.textWindow.top + self.textWindow.height; y += 1) { + for (x = self.textWindow.left; x < self.textWindow.left + self.textWindow.width; x += 1) { + setCellChar(x, y, 0x20); + } + } + }; this.setFirmwareActive = function setFirmwareActive(active) { init(active, 24, active ? 80 : 40); @@ -276,32 +294,46 @@ function TTY(screenElement, keyboardElement, bell) { } } - // Internal - function lineFeed() { + this.cursorDown = function cursorDown() { cursorY += 1; if (cursorY >= self.textWindow.top + self.textWindow.height) { cursorY = self.textWindow.top + self.textWindow.height - 1; - if (self.autoScroll) { self.scrollScreen(); } } - updateCursor(); - } + }; - // Internal - function advanceCursor() { - // Advance the cursor + this.cursorLeft = function cursorLeft() { + cursorX -= 1; + if (cursorX < self.textWindow.left) { + cursorX += self.textWindow.width; + cursorY -= 1; + if (cursorY < self.textWindow.top) { + cursorY = self.textWindow.top; + } + } + updateCursor(); + }; + + this.cursorUp = function cursorUp() { + cursorY -= 1; + if (cursorY < self.textWindow.top) { + cursorY = self.textWindow.top; + } + updateCursor(); + }; + + + this.cursorRight = function cursorRight() { cursorX += 1; - if (cursorX >= self.textWindow.left + self.textWindow.width) { cursorX = self.textWindow.left; - lineFeed(); + self.cursorDown(); } - updateCursor(); - } + }; // Hookable this.writeChar = function writeChar(c) { @@ -326,34 +358,19 @@ function TTY(screenElement, keyboardElement, bell) { break; case 8: // (BS) backspace - cursorX -= 1; - if (cursorX < self.textWindow.left) { - cursorX += self.textWindow.width; - cursorY -= 1; - if (cursorY < self.textWindow.top) { - cursorY = self.textWindow.top; - } - } + self.cursorLeft(); break; case 9: break; case 10: // (LF) line feed - lineFeed(); + self.cursorDown(); break; case 11: // (VT) clear EOS if (firmwareActive) { - // Clears from the cursor position to the end of the window - for (x = cursorX; x < self.textWindow.left + self.textWindow.width; x += 1) { - setCellChar(x, cursorY, 0x20); - } - for (y = cursorY + 1; y < self.textWindow.top + self.textWindow.height; y += 1) { - for (x = self.textWindow.left; x < self.textWindow.left + self.textWindow.width; x += 1) { - setCellChar(x, y, 0x20); - } - } + self.clearEOS(); } break; @@ -366,7 +383,7 @@ function TTY(screenElement, keyboardElement, bell) { case 13: // (CR) return cursorX = self.textWindow.left; - lineFeed(); + self.cursorDown(); break; case 14: // (SO) normal @@ -482,7 +499,7 @@ function TTY(screenElement, keyboardElement, bell) { default: setCellChar(cursorX, cursorY, code); - advanceCursor(); + self.cursorRight(); break; } };