Expose more TTY CALL shims

This commit is contained in:
Joshua Bell 2014-11-08 16:36:31 -08:00
parent e1d01b3706
commit b1fb46a5fa
3 changed files with 70 additions and 32 deletions

View File

@ -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(); }
}

View File

@ -215,6 +215,12 @@ can be literals (unquoted strings), strings, or numbers
<li><code>CALL -3086</code> - clear current hi-res page to black
<li><code>CALL -3082</code> - clear current hi-res page to current color
<li><code>CALL 54951</code> - clear stack (cancel pending <code>FOR</code>-<code>NEXT</code> loops and <code>GOSUB</code>s)
<li><code>CALL -1036</code> - move cursor right
<li><code>CALL -1008</code> - move cursor left
<li><code>CALL -998</code> - move cursor up
<li><code>CALL -958</code> - clear text from cursor to bottom of window
<li><code>CALL -922</code> - move cursor down
<li><code>CALL -868</code> - clear text from cursor to end of line
</ul>
<dt>PR# <var>aexpr</var><dd>Direct output to slot

79
tty.js
View File

@ -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();
};
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();
};
// Internal
function advanceCursor() {
// Advance the cursor
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;
}
};