null argument to support print w/o newline|new EMIT fn for BASIC

This commit is contained in:
minjaesong
2020-06-16 10:02:04 +09:00
parent 4e9dcf71e0
commit 8b9a16bbd1
4 changed files with 41 additions and 22 deletions

View File

@@ -123,12 +123,12 @@ function parseSigil(s) {
function resolve(variable) { function resolve(variable) {
if (variable.type == "string" || variable.type == "number") if (variable.type == "string" || variable.type == "number")
return variable.value; return variable.value;
else if (variable.type == "literal") { else if (variable.type == "literal")
return basicInterpreterStatus.variables[parseSigil(variable.value).name].literal; return basicInterpreterStatus.variables[parseSigil(variable.value).name].literal;
} else if (variable.type == "null")
else { return undefined;
else
throw "InternalError: unknown variable with type "+variable.type+", with value "+variable.value throw "InternalError: unknown variable with type "+variable.type+", with value "+variable.value
}
} }
var basicInterpreterStatus = {}; var basicInterpreterStatus = {};
basicInterpreterStatus.gosubStack = []; basicInterpreterStatus.gosubStack = [];
@@ -237,11 +237,33 @@ basicInterpreterStatus.builtin = {
if (args.length == 0) if (args.length == 0)
println(); println();
else else {
println(args.map(function(it) { if (args[args.length - 1].type == "null") {
var it2 = resolve(it); print(args.slice(0, args.length - 1).map(function(it) {
return ((!isNaN(it2)) ? " " : "") + it2; // BASIC always put a space before a number var it2 = resolve(it);
}).join("\t")); return ((!isNaN(it2)) ? " " : "") + it2; // BASIC always put a space before a number
}).join("\t"));
}
else {
println(args.map(function(it) {
var it2 = resolve(it);
return ((!isNaN(it2)) ? " " : "") + it2; // BASIC always put a space before a number
}).join("\t"));
}
}
},
"EMIT" : function(lnum, args) {
if (args.length > 0) {
for (var llll = 0; llll < args.length; llll++) {
var lvalll = resolve(args[llll]);
if (isNaN(lvalll)) {
print(lvalll);
}
else {
con.addch(lvalll);
}
}
}
}, },
"POKE" : function(lnum, args) { "POKE" : function(lnum, args) {
if (args.length != 2) throw lang.syntaxfehler(lnum); if (args.length != 2) throw lang.syntaxfehler(lnum);
@@ -1040,7 +1062,7 @@ basicFunctions._executeSyntaxTree = function(lnum, syntaxTree, recDepth) {
if (_debugExec) serial.println(recWedge+"@@ EXECUTE @@"); if (_debugExec) serial.println(recWedge+"@@ EXECUTE @@");
if (syntaxTree === undefined) if (syntaxTree === undefined)
throw "InternalError: tree is undefined"; return new SyntaxTreeReturnObj("null", undefined, lnum + 1);
else if (syntaxTree.type == "function" || syntaxTree.type == "operator") { else if (syntaxTree.type == "function" || syntaxTree.type == "operator") {
if (_debugExec) serial.println(recWedge+"function|operator"); if (_debugExec) serial.println(recWedge+"function|operator");
if (_debugExec) serial.println(recWedge+syntaxTree.toString()); if (_debugExec) serial.println(recWedge+syntaxTree.toString());

View File

@@ -71,6 +71,8 @@ class GraphicsJSR223Delegate(val vm: VM) {
fun putSymbol(char: Byte) { fun putSymbol(char: Byte) {
getFirstGPU()?.let { getFirstGPU()?.let {
val (cx, cy) = it.getCursorPos() val (cx, cy) = it.getCursorPos()
it.putChar(cx, cy, char) it.putChar(cx, cy, char)
it.setCursorPos(cx + 1, cy) it.setCursorPos(cx + 1, cy)
} }

View File

@@ -34,13 +34,7 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) {
abstract fun putChar(x: Int, y: Int, text: Byte, foreColour: Byte = ttyFore.toByte(), backColour: Byte = ttyBack.toByte()) abstract fun putChar(x: Int, y: Int, text: Byte, foreColour: Byte = ttyFore.toByte(), backColour: Byte = ttyBack.toByte())
fun writeOut(char: Byte) { fun writeOut(char: Byte) {
// deal with y-axis out-of-bounds val (cx, cy) = getCursorPos()
var (cx, cy) = getCursorPos()
if (cy >= TEXT_ROWS) {
scrollUp(cy - TEXT_ROWS + 1)
setCursorPos(cx, TEXT_ROWS - 1)
cy = TEXT_ROWS - 1
}
val printable = acceptChar(char) // this function processes the escape codes and CRLFs val printable = acceptChar(char) // this function processes the escape codes and CRLFs

View File

@@ -69,11 +69,7 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false, lcdInvert: Boole
set(value) { spriteAndTextArea.setShort(memTextCursorPosOffset, value.toShort()) } set(value) { spriteAndTextArea.setShort(memTextCursorPosOffset, value.toShort()) }
override fun getCursorPos() = rawCursorPos % TEXT_COLS to rawCursorPos / TEXT_COLS override fun getCursorPos() = rawCursorPos % TEXT_COLS to rawCursorPos / TEXT_COLS
/**
* Think of it as a real paper tty;
* setCursorPos must "wrap" the cursor properly when x-value goes out of screen bound.
* For y-value, only when y < 0, set y to zero and don't care about the y-value goes out of bound.
*/
override fun setCursorPos(x: Int, y: Int) { override fun setCursorPos(x: Int, y: Int) {
var newx = x var newx = x
var newy = y var newy = y
@@ -89,6 +85,11 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false, lcdInvert: Boole
if (newy < 0) { if (newy < 0) {
newy = 0 // DON'T SCROLL when cursor goes ABOVE the screen newy = 0 // DON'T SCROLL when cursor goes ABOVE the screen
} }
else if (newy >= TEXT_ROWS) {
scrollUp(newy - TEXT_ROWS + 1)
setCursorPos(newy, TEXT_ROWS - 1)
newy = TEXT_ROWS - 1
}
rawCursorPos = toTtyTextOffset(newx, newy) rawCursorPos = toTtyTextOffset(newx, newy)
} }