From 04d77b16dcb2017557d85f87a5127d9d155e5310 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 26 Dec 2021 10:00:07 +0900 Subject: [PATCH] more robust multilingual print --- assets/JS_INIT.js | 21 +++++++++++-------- assets/disk0/tvdos/TVDOS.SYS | 9 +++----- .../torvald/tsvm/GraphicsJSR223Delegate.kt | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index 3a0e22a..8e427a3 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -431,7 +431,10 @@ con.getch = function() { return sys.readKey(); }; con.move = function(y, x) { - print("\x1B["+(y|0)+";"+(x|0)+"H"); + //print("\x1B["+(y|0)+";"+(x|0)+"H"); + // NOT using ANSI escape sequence as it conflicts with some multilingual drive which redefines PRINT function + // and obviously this method is faster albeit less genuine :p + graphics.setCursorYX(y|0, x|0); }; con.addch = function(c) { graphics.putSymbol(c|0); @@ -446,20 +449,20 @@ con.getyx = function() { return graphics.getCursorYX(); }; con.curs_up = function() { - let c = graphics.getCursorYX(); - con.move(c[0]-1,c[1]); + let [y,x] = graphics.getCursorYX(); + con.move(y-1,x); }; con.curs_down = function() { - let c = graphics.getCursorYX(); - con.move(c[0]+1,c[1]); + let [y,x] = graphics.getCursorYX(); + con.move(y+1,x); }; con.curs_left = function() { - let c = graphics.getCursorYX(); - con.move(c[0],c[1]-1); + let [y,x] = graphics.getCursorYX(); + con.move(y,x-1); }; con.curs_right = function() { - let c = graphics.getCursorYX(); - con.move(c[0],c[1]+1); + let [y,x] = graphics.getCursorYX(); + con.move(y,x+1); }; con.hitterminate = function() { // ^C sys.poke(-40, 1); diff --git a/assets/disk0/tvdos/TVDOS.SYS b/assets/disk0/tvdos/TVDOS.SYS index dc5d54e..7d69c11 100644 --- a/assets/disk0/tvdos/TVDOS.SYS +++ b/assets/disk0/tvdos/TVDOS.SYS @@ -330,17 +330,14 @@ unicode.getUniprint = (c) => { print = function(str) { if ((typeof str === 'string' || str instanceof String) && str.length > 0) { let cp = unicode.utf8toCodepoints(str) - let q = unicode.getUniprint(cp[0]) cp.forEach(c => { - if (q == undefined) { + let q = unicode.getUniprint(c) + + if (q == undefined || !q[0](c)) { con.addch(4) con.curs_right() } - else if (q[0](c)) { - q[1](c) - } else { - q = unicode.getUniprint(c) q[1](c) } }) diff --git a/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt b/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt index 31a87c7..32d6eb4 100644 --- a/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt +++ b/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt @@ -97,7 +97,7 @@ class GraphicsJSR223Delegate(val vm: VM) { fun setCursorYX(cy: Int, cx: Int) { getFirstGPU()?.let { - it.setCursorPos(cy - 1, cx - 1) + it.setCursorPos(cx - 1, cy - 1) } }