still working on vt, still buggy :/

Former-commit-id: 9164ca8ef33917f7254c65f3947903b8a17dd654
Former-commit-id: 3ebf64f00a0b86d11a449c1d399e149f2714839c
This commit is contained in:
Song Minjae
2017-03-03 04:05:00 +09:00
parent efd3284e30
commit 6d8f9d2901
9 changed files with 61 additions and 127 deletions

View File

@@ -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
}
}
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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 "<keypress hidden>"}")
return lastStreamInput!!
}
override fun keyPressed(key: Int, c: Char) {
lastInputByte = c.toInt()

View File

@@ -34,15 +34,5 @@ interface Teletype {
fun newLine()
fun scroll(amount: Int = 1)
/**
* @param echo if true, keypresses are echoed to the terminal.
*/
fun openInput(echo: Boolean = true)
fun closeInputKey(keyFromUI: Int): Int
fun closeInputString(): String
fun bell(pattern: String = ".")
var lastStreamInput: String?
var lastKeyPress: Int?
}

View File

@@ -131,36 +131,6 @@ class TeletypeTerminal : Teletype {
private var inputOpen = false
val DEBUG = true
/**
* @param echo if true, keypresses are echoed to the terminal.
*/
override fun openInput(echo: Boolean) {
lastStreamInput = null
lastKeyPress = null
inputOpen = true
if (DEBUG) println("[TeletypeTerminal] openInput()")
}
override fun closeInputKey(keyFromUI: Int): Int {
inputOpen = false
lastKeyPress = keyFromUI
if (DEBUG) println("[TeletypeTerminal] 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("[TeletypeTerminal] closeInputString(), $lastStreamInput")
return lastStreamInput!!
}
override fun keyPressed(key: Int, c: Char) {
if (inputOpen) {
if (c == SimpleTextTerminal.ASCII_CR)

View File

@@ -39,18 +39,18 @@ interface Terminal : Teletype {
fun setCursor(x: Int, y: Int)
/** Emits a bufferChar. Does not move cursor
* It is also not affected by the control sequences; just print them out as symbol */
fun emitChar(bufferChar: Int, x: Int = cursorX, y: Int = cursorY)
fun emitChar(bufferChar: Int, x: Int, y: Int)
/** Emits a char. Does not move cursor
* It is also not affected by the control sequences; just print them out as symbol */
fun emitChar(c: Char, x: Int = cursorX, y: Int = cursorY)
fun emitChar(c: Char, x: Int, y: Int)
/** Prints a char and move cursor accordingly. */
override fun printChar(c: Char)
/** Emits a string, does not affected by control sequences. Does not move cursor */
fun emitString(s: String, x: Int = cursorX, y: Int = cursorY)
fun emitString(s: String, x: Int, y: Int)
/** Emits a string and move cursor accordingly, then do LF */
fun printString(s: String, x: Int = cursorX, y: Int = cursorY)
fun printString(s: String, x: Int, y: Int)
/** Emits a string and move cursor accordingly. */
fun writeString(s: String, x: Int = cursorX, y: Int = cursorY)
fun writeString(s: String, x: Int, y: Int)
fun clear()
fun clearLine()
override fun newLine()