diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index 21bd7ee..ba060ee 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -17,13 +17,13 @@ con.getch = function() { return sys.readKey(); }; con.move = function(y, x) { - print(String.fromCharCode(27,91)+y+";"+x+"H"); + print(String.fromCharCode(27,91)+(y|0)+";"+(x|0)+"H"); }; con.addch = function(c) { - graphics.putSymbol(c); + graphics.putSymbol(c|0); }; con.mvaddch = function(y, x, c) { - move(y, x); addch(c); + con.move(y, x); con.addch(c); }; con.getmaxyx = function() { return graphics.getTermDimension(); @@ -48,13 +48,13 @@ con.color_fore = function(n) { // 0..7; -1 for transparent if (n < 0) print(String.fromCharCode(27,91)+"38;5;255m"); else - print(String.fromCharCode(27,91)+((n % 8)+30)+"m"); + print(String.fromCharCode(27,91)+(((n|0) % 8)+30)+"m"); }; con.color_back = function(n) { // 0..7; -1 for transparent if (n < 0) print(String.fromCharCode(27,91)+"48;5;255m"); else - print(String.fromCharCode(27,91)+((n % 8)+40)+"m"); + print(String.fromCharCode(27,91)+(((n|0) % 8)+40)+"m"); }; con.color_pair = function(fore, back) { // 0..255 print(String.fromCharCode(27,91)+"38;5;"+fore+"m"); @@ -64,7 +64,7 @@ con.clear = function() { print(String.fromCharCode(27,91)+"2J"); }; con.curs_set = function(arg) { - print(String.fromCharCode(27,91)+"?25"+((arg == 0) ? "l" : "h")); + print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h")); }; Object.freeze(con); // system management function diff --git a/assets/tvdos/fsh.js b/assets/tvdos/fsh.js index e21abf5..a8a3155 100644 --- a/assets/tvdos/fsh.js +++ b/assets/tvdos/fsh.js @@ -1,10 +1,32 @@ graphics.setBackground(3,3,3); var _fsh = {}; -_fsh.titlebartex = new GL.Tex(2, 14, [254, 239, 254, 254, 253, 254, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 252, 253, 253, 252, 252, 252, 252, 251, 251, 251]); +_fsh.titlebarTex = new GL.Tex(2, 14, base64.atobarr("/u/+/v3+/f39/f39/f39/f39/P39/Pz8/Pv7+w==")); +_fsh.scrdim = con.getmaxyx(); +_fsh.scrwidth = _fsh.scrdim[1]; +_fsh.scrheight = _fsh.scrdim[0]; +_fsh.brandName = "f\xb3Sh"; +_fsh.brandLogoTexSmall = new GL.Tex(24, 14, base64.atobarr("///////////////////////////////////////////z///////////////////////////////z///////////////////////z8/Pz///z////8/Pz8/Pz8/P///////Pz///////z///z8///////8/P///////Pz///////z///z8///////8/Pz8/P/8/Pz8/Pz///z////8/Pz////8/P///Pz//Pz///////z///////z8///8/P///Pz//Pz///////z////////8/P/8/P///Pz//Pz///////z////////8/P/8/P///Pz//Pz///////z///z8/Pz8///8/P///Pz///////////z///////////////////////////////z////////////////////////////////////////////////////")); -GL.drawTexPattern(_fsh.titlebartex, 0, 0, 560, 14); +_fsh.drawTitlebar = function(titletext) { + GL.drawTexPattern(_fsh.titlebarTex, 0, 0, 560, 14); + if (titletext === undefined || titletext.length == 0) { + con.move(1,1); + print(" ".repeat(_fsh.scrwidth)); + GL.drawTexImageOver(_fsh.brandLogoTexSmall, 268, 0); + } + else { + con.color_pair(240, 255);// vvv this number must be even + GL.drawTexPattern(_fsh.titlebarTex, 268, 0, 24, 14); + con.move(1, 1 + (_fsh.scrwidth - titletext.length) / 2); + print(titletext); + } + con.color_pair(254, 255); +}; + +// screen init con.color_pair(254, 255); con.clear(); con.curs_set(0); +_fsh.drawTitlebar(); diff --git a/assets/tvdos/gl.js b/assets/tvdos/gl.js index bd23bdf..8255872 100644 --- a/assets/tvdos/gl.js +++ b/assets/tvdos/gl.js @@ -20,7 +20,23 @@ GL.drawTexPattern = function(tex, x, y, width, height) { } } }; +/* + * Draws a texture verbatim - color of 255 will be written to the screen buffer + */ GL.drawTexImage = function(tex, x, y) { GL.drawTexPattern(tex, x, y, tex.width, tex.height); }; +/* + * Draws texture with blitting - color of 255 will pass-thru what's already on the screen buffer + */ +GL.drawTexImageOver = function(tex, x, y) { + for (var ty = 0; ty < tex.height; ty++) { + for (var tx = 0; tx < tex.width; tx++) { + var c = tex.texData[ty * tex.width + tx]; + if (c != 255) { + graphics.plotPixel(x + tx, y + ty, c); + } + } + } +}; Object.freeze(GL); diff --git a/fsh_logo.png b/fsh_logo.png new file mode 100644 index 0000000..b3e8039 Binary files /dev/null and b/fsh_logo.png differ diff --git a/shell_mockup.kra b/shell_mockup.kra index c1b55fd..e730e2b 100644 --- a/shell_mockup.kra +++ b/shell_mockup.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec7d818b19632a258a312d26a2a9cb35a2bd47a1a3f25650972d03c2e574f436 -size 293378 +oid sha256:a3a7a205d0d1a396931186a8caf10ac9a250ed931495e2a8cf8847c80c6cb54d +size 313863 diff --git a/src/net/torvald/tsvm/Memvwr.kt b/src/net/torvald/tsvm/Memvwr.kt index 1be1efe..cf5fe57 100644 --- a/src/net/torvald/tsvm/Memvwr.kt +++ b/src/net/torvald/tsvm/Memvwr.kt @@ -100,7 +100,7 @@ class Memvwr(val vm: VM) : JFrame() { } if (x + 15 in intArrayOf(3, 7, 11)) - sb.append('|') + sb.append(' ') } sb.append("|\n") diff --git a/src/net/torvald/tsvm/VMJSR223Delegate.kt b/src/net/torvald/tsvm/VMJSR223Delegate.kt index 22f1202..5e0d271 100644 --- a/src/net/torvald/tsvm/VMJSR223Delegate.kt +++ b/src/net/torvald/tsvm/VMJSR223Delegate.kt @@ -1,12 +1,15 @@ package net.torvald.tsvm import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong +import java.nio.charset.Charset /** * Pass the instance of the class to the ScriptEngine's binding, preferably under the namespace of "vm" */ class VMJSR223Delegate(val vm: VM) { + private val SYSTEM_CHARSET = Charsets.ISO_8859_1 + fun poke(addr: Int, value: Int) = vm.poke(addr.toLong(), value.toByte()) fun peek(addr: Int) = vm.peek(addr.toLong())!!.toInt().and(255) fun nanoTime() = System.nanoTime() @@ -32,11 +35,11 @@ class VMJSR223Delegate(val vm: VM) { fun print(s: String) { //System.out.print("[Nashorn] $s") - vm.getPrintStream().write(s.toByteArray()) + vm.getPrintStream().write(s.toByteArray(SYSTEM_CHARSET)) } fun println(s: String) { System.out.println("[Nashorn] $s") - vm.getPrintStream().write((s + '\n').toByteArray()) + vm.getPrintStream().write((s + '\n').toByteArray(SYSTEM_CHARSET)) } fun println() = print('\n') diff --git a/src/net/torvald/tsvm/VMRunnerFactory.kt b/src/net/torvald/tsvm/VMRunnerFactory.kt index 8abe738..a6374be 100644 --- a/src/net/torvald/tsvm/VMRunnerFactory.kt +++ b/src/net/torvald/tsvm/VMRunnerFactory.kt @@ -80,12 +80,19 @@ object VMRunnerFactory { val fr = FileReader("./assets/JS_INIT.js") val prg = fr.readText() fr.close() - engine.eval(toSingleLine(prg), context) + engine.eval(sanitiseJS(prg), context) } } override suspend fun executeCommand(command: String) { - engine.eval("\"use strict\";" + encapsulateJS(sanitiseJS(command)), context) + try { + engine.eval("\"use strict\";" + encapsulateJS(sanitiseJS(command)), context) + } + catch (e: javax.script.ScriptException) { + System.err.println("ScriptException from the script:") + System.err.println(command.substring(0, minOf(1024, command.length))) + System.err.println(e) + } } override suspend fun evalGlobal(command: String) { @@ -98,8 +105,7 @@ object VMRunnerFactory { } - private fun toSingleLine(code: String) = code.replace(Regex("//[^\\n]*"), "").replace('\n', ' ') - private fun sanitiseJS(code: String) = toSingleLine(code).replace("\\", "\\\\") - private fun encapsulateJS(code: String) = "eval('$code')" + private fun sanitiseJS(code: String) = code//.replace("\\", "\\\\") + private fun encapsulateJS(code: String) = "(function(){$code})()" }