From 6d8f9d29012837c7444188d9ab392e1fa5ef4987 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Fri, 3 Mar 2017 04:05:00 +0900 Subject: [PATCH] still working on vt, still buggy :/ Former-commit-id: 9164ca8ef33917f7254c65f3947903b8a17dd654 Former-commit-id: 3ebf64f00a0b86d11a449c1d399e149f2714839c --- src/net/torvald/terrarum/StateVTTest.kt | 10 --- .../virtualcomputer/assets/lua/ROMLIB.lua | 2 +- .../virtualcomputer/assets/lua/TBASIC.lua | 11 ++- .../virtualcomputer/assets/lua/TBASINCL.lua | 2 +- .../terminal/GraphicsTerminal.kt | 82 +++++++++++-------- .../terminal/SimpleTextTerminal.kt | 31 ------- .../virtualcomputer/terminal/Teletype.kt | 10 --- .../terminal/TeletypeTerminal.kt | 30 ------- .../virtualcomputer/terminal/Terminal.kt | 10 +-- 9 files changed, 61 insertions(+), 127 deletions(-) diff --git a/src/net/torvald/terrarum/StateVTTest.kt b/src/net/torvald/terrarum/StateVTTest.kt index a7c2ec7c3..0dd00dbd2 100644 --- a/src/net/torvald/terrarum/StateVTTest.kt +++ b/src/net/torvald/terrarum/StateVTTest.kt @@ -59,16 +59,6 @@ class StateVTTest : BasicGameState() { } override fun keyPressed(key: Int, c: Char) { - super.keyPressed(key, c) vt.keyPressed(key, c) - - if (!computerInside.isHalted) { - if (key == Key.RETURN && computerInside.luaJ_globals["__scanMode__"].checkjstring() == "line") { - vt.closeInputString() // cut input by pressing Key.RETURN - } - else if (computerInside.luaJ_globals["__scanMode__"].checkjstring() == "a_key") { - vt.closeInputKey(key) // cut input by pressing any key - } - } } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua index bb7ea5666..9f66b2810 100644 --- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua @@ -94,7 +94,7 @@ io.read = function(option) -- RETURN not hit while inkey ~= 13 do inkey = machine.__readFromStdin() - if inkey >= 32 then + if inkey > 0 then io.write(string.char(inkey)) input = input..string.char(inkey) end diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASIC.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASIC.lua index 40e54bb18..23ed8855d 100644 --- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASIC.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASIC.lua @@ -4,6 +4,9 @@ TBASIC shell Synopsis: TBASIC (filename) If no file is specified, interactive mode will be started + +To debug EXEC and/or INCL, there's line ```local debug = false``` on each file; change it to ```true``` manually +and you are all set. ]] @@ -66,10 +69,10 @@ else while not terminate_app do local __read = false - line = io.read() + local line = io.read() -- tokenise line by " " - args = {} + local args = {} -- shadows system args for word in line:gmatch("[^ ]+") do table.insert(args, word:upper()) end @@ -91,7 +94,7 @@ else print(concat_lines(lines)) else if args[2]:match("-") then -- ranged - range = {} + local range = {} for n in args[2]:gmatch("[^-]+") do table.insert(range, n) end @@ -119,7 +122,7 @@ else _TBASIC._ERROR.ILLEGALARG() else if args[2]:match("-") then -- ranged - range = {} + local range = {} for n in args[2]:gmatch("[^-]+") do table.insert(range, n) end diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASINCL.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASINCL.lua index a7446a07b..01e21a52c 100644 --- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASINCL.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASINCL.lua @@ -1329,7 +1329,7 @@ _G._TBASIC.TORPN = function(exprarray) -- stack empty without finding left paren, ERROR! --if not found_left_paren and #stack == 0 then exprerr(token) end -- mismatched parens - elseif isstring(token) then + elseif isstring(token) or isnumber(token) then printdbg("is data") stackpush(outqueue, token) -- arbitrary data else -- a word without '~' or anything; assume it's a variable name diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt index 6a6fceda3..318e68982 100644 --- a/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt @@ -10,6 +10,7 @@ import org.newdawn.slick.Color import org.newdawn.slick.GameContainer import org.newdawn.slick.Graphics import org.newdawn.slick.Image +import java.util.* /** * Printing text using Term API triggers 'compatibility' mode, where you are limited to 16 colours. @@ -93,10 +94,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { cursorY = y } - override fun openInput(echo: Boolean) { - //TODO("not implemented") - } - override fun emitChar(bufferChar: Int, x: Int, y: Int) { videoCard.drawChar( bufferChar.and(0xFF).toChar(), @@ -107,20 +104,32 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { ) } - override fun closeInputKey(keyFromUI: Int): Int { - //TODO("not implemented") - return 0 - } + override fun emitChar(c: Char, xx: Int, yy: Int) { + wrap() // needed + var x = xx + var y = yy + // wrap argument cursor + if (xx < 0 && yy <= 0) { + x = 0 + y = 0 + } + else if (cursorX >= width) { + println("arstenioarstoneirastneo") + x = 0 + y += 1 + } + else if (cursorX < 0) { + x = width - 1 + y -= 1 + } + // auto scroll up + if (cursorY >= height) { + scroll() + y -= 1 + } - override fun closeInputString(): String { - //TODO("not implemented") - return " " - } + println("xx: $xx, yy: $yy") - override var lastStreamInput: String? = null - override var lastKeyPress: Int? = null - - override fun emitChar(c: Char, x: Int, y: Int) { videoCard.drawChar( c, x * PeripheralVideoCard.blockW, @@ -130,22 +139,27 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { } override fun printChar(c: Char) { - wrap() if (c >= ' ' && c.toInt() != 127) { - emitChar(c) + emitChar(c, cursorX, cursorY) cursorX += 1 } else { - when (c) { - ASCII_BEL -> bell(".") - ASCII_BS -> { cursorX -= 1; wrap() } - ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE } - ASCII_LF -> newLine() - ASCII_FF -> clear() - ASCII_CR -> { cursorX = 0 } - ASCII_DEL -> { cursorX -= 1; wrap(); emitChar(colourKey.shl(8)) } - ASCII_DC1, ASCII_DC2, ASCII_DC3, ASCII_DC4 -> { foreColour = c - ASCII_DC1 } - ASCII_DLE -> { foreColour = errorColour } + if (BACKSPACE.contains(c)) { + cursorX -= 1 + //wrap() + emitChar(0.toChar(), cursorX, cursorY) + } + else { + when (c) { + ASCII_BEL -> bell(".") + ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE } + ASCII_LF -> { newLine(); System.err.println("LF ${Random().nextInt(100)}") } + ASCII_FF -> clear() + ASCII_CR -> { cursorX = 0 } + ASCII_DC1, ASCII_DC2, ASCII_DC3, + ASCII_DC4 -> { foreColour = c - ASCII_DC1 } + ASCII_DLE -> { foreColour = errorColour } + } } } } @@ -155,7 +169,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { for (i in 0..s.length - 1) { printChar(s[i]) - wrap() } setCursor(x, y) @@ -171,7 +184,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { for (i in 0..s.length - 1) { printChar(s[i]) - wrap() } } @@ -184,7 +196,8 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { } override fun newLine() { - cursorX = 0; cursorY += 1; wrap() + cursorX = 0; cursorY += 1 + //wrap() } override fun scroll(amount: Int) { @@ -268,12 +281,11 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { val ASCII_NUL = 0.toChar() val ASCII_BEL = 7.toChar() // *BEEP!* - val ASCII_BS = 8.toChar() // x = x - 1 val ASCII_TAB = 9.toChar() // move cursor to next (TABSIZE * yy) pos (5 -> 8, 3- > 4, 4 -> 8) val ASCII_LF = 10.toChar() // new line val ASCII_FF = 12.toChar() // new page val ASCII_CR = 13.toChar() // x <- 0 - val ASCII_DEL = 127.toChar() // backspace and delete char + val BACKSPACE = arrayOf(127.toChar(), 8.toChar()) // backspace and delete char (8 for WIN, 127 for OSX) val ASCII_DC1 = 17.toChar() // foreground colour 0 val ASCII_DC2 = 18.toChar() // foreground colour 1 val ASCII_DC3 = 19.toChar() // foreground colour 2 @@ -283,12 +295,12 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal { val asciiControlInUse = charArrayOf( ASCII_NUL, ASCII_BEL, - ASCII_BS, + 8.toChar(), ASCII_TAB, ASCII_LF, ASCII_FF, ASCII_CR, - ASCII_DEL, + 127.toChar(), ASCII_DC1, ASCII_DC2, ASCII_DC3, diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt index 7b3032af4..aa9e23e7d 100644 --- a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt @@ -343,37 +343,6 @@ open class SimpleTextTerminal( var sb: StringBuilder = StringBuilder() private var inputOpen = false private var keyPressVisible = false - /** - * @param echo if true, keypresses are echoed to the terminal. - */ - override fun openInput(echo: Boolean) { - lastStreamInput = null - lastKeyPress = null - inputOpen = true - keyPressVisible = echo - if (DEBUG) println("[SimpleTextTerminal] openInput()") - } - - override fun closeInputKey(keyFromUI: Int): Int { - inputOpen = false - lastKeyPress = keyFromUI - - if (DEBUG) println("[SimpleTextTerminal] closeInputKey(), $keyFromUI") - return keyFromUI - } - - override var lastStreamInput: String? = null - override var lastKeyPress: Int? = null - - override fun closeInputString(): String { - inputOpen = false - lastStreamInput = sb.toString() - sb = StringBuilder() - - if (DEBUG) - println("[SimpleTextTerminal] closeInputString(), ${if (keyPressVisible) lastStreamInput else "