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 0xD683: function() { // Clear stack
state.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 0xFC9C: function() { // Clear from cursor to right
if (env.tty.clearEOL) { env.tty.clearEOL(); } 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 -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 -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 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> </ul>
<dt>PR# <var>aexpr</var><dd>Direct output to slot <dt>PR# <var>aexpr</var><dd>Direct output to slot

81
tty.js
View File

@ -6,6 +6,12 @@
// //
// tty = new TTY( screen_element, keyboard_element, bell ); // tty = new TTY( screen_element, keyboard_element, bell );
// tty.clearScreen() // tty.clearScreen()
// tty.clearEOL()
// tty.clearEOS()
// tty.cursorLeft()
// tty.cursorRight()
// tty.cursorUp()
// tty.cursorDown()
// tty.scrollScreen() // tty.scrollScreen()
// tty.setTextStyle( textStyle ) // tty.setTextStyle( textStyle )
// { width: w, height: h } = tty.getScreenSize() // { 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) { this.setFirmwareActive = function setFirmwareActive(active) {
init(active, 24, active ? 80 : 40); init(active, 24, active ? 80 : 40);
@ -276,32 +294,46 @@ function TTY(screenElement, keyboardElement, bell) {
} }
} }
// Internal this.cursorDown = function cursorDown() {
function lineFeed() {
cursorY += 1; cursorY += 1;
if (cursorY >= self.textWindow.top + self.textWindow.height) { if (cursorY >= self.textWindow.top + self.textWindow.height) {
cursorY = self.textWindow.top + self.textWindow.height - 1; cursorY = self.textWindow.top + self.textWindow.height - 1;
if (self.autoScroll) { if (self.autoScroll) {
self.scrollScreen(); self.scrollScreen();
} }
} }
updateCursor(); updateCursor();
} };
// Internal this.cursorLeft = function cursorLeft() {
function advanceCursor() { cursorX -= 1;
// Advance the cursor 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; cursorX += 1;
if (cursorX >= self.textWindow.left + self.textWindow.width) { if (cursorX >= self.textWindow.left + self.textWindow.width) {
cursorX = self.textWindow.left; cursorX = self.textWindow.left;
lineFeed(); self.cursorDown();
} }
updateCursor(); updateCursor();
} };
// Hookable // Hookable
this.writeChar = function writeChar(c) { this.writeChar = function writeChar(c) {
@ -326,34 +358,19 @@ function TTY(screenElement, keyboardElement, bell) {
break; break;
case 8: // (BS) backspace case 8: // (BS) backspace
cursorX -= 1; self.cursorLeft();
if (cursorX < self.textWindow.left) {
cursorX += self.textWindow.width;
cursorY -= 1;
if (cursorY < self.textWindow.top) {
cursorY = self.textWindow.top;
}
}
break; break;
case 9: case 9:
break; break;
case 10: // (LF) line feed case 10: // (LF) line feed
lineFeed(); self.cursorDown();
break; break;
case 11: // (VT) clear EOS case 11: // (VT) clear EOS
if (firmwareActive) { if (firmwareActive) {
// Clears from the cursor position to the end of the window self.clearEOS();
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);
}
}
} }
break; break;
@ -366,7 +383,7 @@ function TTY(screenElement, keyboardElement, bell) {
case 13: // (CR) return case 13: // (CR) return
cursorX = self.textWindow.left; cursorX = self.textWindow.left;
lineFeed(); self.cursorDown();
break; break;
case 14: // (SO) normal case 14: // (SO) normal
@ -482,7 +499,7 @@ function TTY(screenElement, keyboardElement, bell) {
default: default:
setCellChar(cursorX, cursorY, code); setCellChar(cursorX, cursorY, code);
advanceCursor(); self.cursorRight();
break; break;
} }
}; };