mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 01:54:04 +09:00
still working on vt, still buggy :/
Former-commit-id: 9164ca8ef33917f7254c65f3947903b8a17dd654 Former-commit-id: 3ebf64f00a0b86d11a449c1d399e149f2714839c
This commit is contained in:
@@ -59,16 +59,6 @@ class StateVTTest : BasicGameState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun keyPressed(key: Int, c: Char) {
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
super.keyPressed(key, c)
|
|
||||||
vt.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ io.read = function(option)
|
|||||||
-- RETURN not hit
|
-- RETURN not hit
|
||||||
while inkey ~= 13 do
|
while inkey ~= 13 do
|
||||||
inkey = machine.__readFromStdin()
|
inkey = machine.__readFromStdin()
|
||||||
if inkey >= 32 then
|
if inkey > 0 then
|
||||||
io.write(string.char(inkey))
|
io.write(string.char(inkey))
|
||||||
input = input..string.char(inkey)
|
input = input..string.char(inkey)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ TBASIC shell
|
|||||||
Synopsis: TBASIC (filename)
|
Synopsis: TBASIC (filename)
|
||||||
If no file is specified, interactive mode will be started
|
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
|
while not terminate_app do
|
||||||
local __read = false
|
local __read = false
|
||||||
line = io.read()
|
local line = io.read()
|
||||||
|
|
||||||
-- tokenise line by " "
|
-- tokenise line by " "
|
||||||
args = {}
|
local args = {} -- shadows system args
|
||||||
for word in line:gmatch("[^ ]+") do
|
for word in line:gmatch("[^ ]+") do
|
||||||
table.insert(args, word:upper())
|
table.insert(args, word:upper())
|
||||||
end
|
end
|
||||||
@@ -91,7 +94,7 @@ else
|
|||||||
print(concat_lines(lines))
|
print(concat_lines(lines))
|
||||||
else
|
else
|
||||||
if args[2]:match("-") then -- ranged
|
if args[2]:match("-") then -- ranged
|
||||||
range = {}
|
local range = {}
|
||||||
for n in args[2]:gmatch("[^-]+") do
|
for n in args[2]:gmatch("[^-]+") do
|
||||||
table.insert(range, n)
|
table.insert(range, n)
|
||||||
end
|
end
|
||||||
@@ -119,7 +122,7 @@ else
|
|||||||
_TBASIC._ERROR.ILLEGALARG()
|
_TBASIC._ERROR.ILLEGALARG()
|
||||||
else
|
else
|
||||||
if args[2]:match("-") then -- ranged
|
if args[2]:match("-") then -- ranged
|
||||||
range = {}
|
local range = {}
|
||||||
for n in args[2]:gmatch("[^-]+") do
|
for n in args[2]:gmatch("[^-]+") do
|
||||||
table.insert(range, n)
|
table.insert(range, n)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1329,7 +1329,7 @@ _G._TBASIC.TORPN = function(exprarray)
|
|||||||
|
|
||||||
-- stack empty without finding left paren, ERROR!
|
-- stack empty without finding left paren, ERROR!
|
||||||
--if not found_left_paren and #stack == 0 then exprerr(token) end -- mismatched parens
|
--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")
|
printdbg("is data")
|
||||||
stackpush(outqueue, token) -- arbitrary data
|
stackpush(outqueue, token) -- arbitrary data
|
||||||
else -- a word without '~' or anything; assume it's a variable name
|
else -- a word without '~' or anything; assume it's a variable name
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.newdawn.slick.Color
|
|||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
import org.newdawn.slick.Graphics
|
import org.newdawn.slick.Graphics
|
||||||
import org.newdawn.slick.Image
|
import org.newdawn.slick.Image
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Printing text using Term API triggers 'compatibility' mode, where you are limited to 16 colours.
|
* 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
|
cursorY = y
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openInput(echo: Boolean) {
|
|
||||||
//TODO("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun emitChar(bufferChar: Int, x: Int, y: Int) {
|
override fun emitChar(bufferChar: Int, x: Int, y: Int) {
|
||||||
videoCard.drawChar(
|
videoCard.drawChar(
|
||||||
bufferChar.and(0xFF).toChar(),
|
bufferChar.and(0xFF).toChar(),
|
||||||
@@ -107,20 +104,32 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun closeInputKey(keyFromUI: Int): Int {
|
override fun emitChar(c: Char, xx: Int, yy: Int) {
|
||||||
//TODO("not implemented")
|
wrap() // needed
|
||||||
return 0
|
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 {
|
println("xx: $xx, yy: $yy")
|
||||||
//TODO("not implemented")
|
|
||||||
return " "
|
|
||||||
}
|
|
||||||
|
|
||||||
override var lastStreamInput: String? = null
|
|
||||||
override var lastKeyPress: Int? = null
|
|
||||||
|
|
||||||
override fun emitChar(c: Char, x: Int, y: Int) {
|
|
||||||
videoCard.drawChar(
|
videoCard.drawChar(
|
||||||
c,
|
c,
|
||||||
x * PeripheralVideoCard.blockW,
|
x * PeripheralVideoCard.blockW,
|
||||||
@@ -130,22 +139,27 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun printChar(c: Char) {
|
override fun printChar(c: Char) {
|
||||||
wrap()
|
|
||||||
if (c >= ' ' && c.toInt() != 127) {
|
if (c >= ' ' && c.toInt() != 127) {
|
||||||
emitChar(c)
|
emitChar(c, cursorX, cursorY)
|
||||||
cursorX += 1
|
cursorX += 1
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
when (c) {
|
if (BACKSPACE.contains(c)) {
|
||||||
ASCII_BEL -> bell(".")
|
cursorX -= 1
|
||||||
ASCII_BS -> { cursorX -= 1; wrap() }
|
//wrap()
|
||||||
ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
|
emitChar(0.toChar(), cursorX, cursorY)
|
||||||
ASCII_LF -> newLine()
|
}
|
||||||
ASCII_FF -> clear()
|
else {
|
||||||
ASCII_CR -> { cursorX = 0 }
|
when (c) {
|
||||||
ASCII_DEL -> { cursorX -= 1; wrap(); emitChar(colourKey.shl(8)) }
|
ASCII_BEL -> bell(".")
|
||||||
ASCII_DC1, ASCII_DC2, ASCII_DC3, ASCII_DC4 -> { foreColour = c - ASCII_DC1 }
|
ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
|
||||||
ASCII_DLE -> { foreColour = errorColour }
|
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) {
|
for (i in 0..s.length - 1) {
|
||||||
printChar(s[i])
|
printChar(s[i])
|
||||||
wrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursor(x, y)
|
setCursor(x, y)
|
||||||
@@ -171,7 +184,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
|||||||
|
|
||||||
for (i in 0..s.length - 1) {
|
for (i in 0..s.length - 1) {
|
||||||
printChar(s[i])
|
printChar(s[i])
|
||||||
wrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +196,8 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun newLine() {
|
override fun newLine() {
|
||||||
cursorX = 0; cursorY += 1; wrap()
|
cursorX = 0; cursorY += 1
|
||||||
|
//wrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun scroll(amount: Int) {
|
override fun scroll(amount: Int) {
|
||||||
@@ -268,12 +281,11 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
|||||||
|
|
||||||
val ASCII_NUL = 0.toChar()
|
val ASCII_NUL = 0.toChar()
|
||||||
val ASCII_BEL = 7.toChar() // *BEEP!*
|
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_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_LF = 10.toChar() // new line
|
||||||
val ASCII_FF = 12.toChar() // new page
|
val ASCII_FF = 12.toChar() // new page
|
||||||
val ASCII_CR = 13.toChar() // x <- 0
|
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_DC1 = 17.toChar() // foreground colour 0
|
||||||
val ASCII_DC2 = 18.toChar() // foreground colour 1
|
val ASCII_DC2 = 18.toChar() // foreground colour 1
|
||||||
val ASCII_DC3 = 19.toChar() // foreground colour 2
|
val ASCII_DC3 = 19.toChar() // foreground colour 2
|
||||||
@@ -283,12 +295,12 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
|||||||
val asciiControlInUse = charArrayOf(
|
val asciiControlInUse = charArrayOf(
|
||||||
ASCII_NUL,
|
ASCII_NUL,
|
||||||
ASCII_BEL,
|
ASCII_BEL,
|
||||||
ASCII_BS,
|
8.toChar(),
|
||||||
ASCII_TAB,
|
ASCII_TAB,
|
||||||
ASCII_LF,
|
ASCII_LF,
|
||||||
ASCII_FF,
|
ASCII_FF,
|
||||||
ASCII_CR,
|
ASCII_CR,
|
||||||
ASCII_DEL,
|
127.toChar(),
|
||||||
ASCII_DC1,
|
ASCII_DC1,
|
||||||
ASCII_DC2,
|
ASCII_DC2,
|
||||||
ASCII_DC3,
|
ASCII_DC3,
|
||||||
|
|||||||
@@ -343,37 +343,6 @@ open class SimpleTextTerminal(
|
|||||||
var sb: StringBuilder = StringBuilder()
|
var sb: StringBuilder = StringBuilder()
|
||||||
private var inputOpen = false
|
private var inputOpen = false
|
||||||
private var keyPressVisible = 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) {
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
lastInputByte = c.toInt()
|
lastInputByte = c.toInt()
|
||||||
|
|||||||
@@ -34,15 +34,5 @@ interface Teletype {
|
|||||||
fun newLine()
|
fun newLine()
|
||||||
fun scroll(amount: Int = 1)
|
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 = ".")
|
fun bell(pattern: String = ".")
|
||||||
|
|
||||||
var lastStreamInput: String?
|
|
||||||
var lastKeyPress: Int?
|
|
||||||
}
|
}
|
||||||
@@ -131,36 +131,6 @@ class TeletypeTerminal : Teletype {
|
|||||||
private var inputOpen = false
|
private var inputOpen = false
|
||||||
val DEBUG = true
|
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) {
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
if (inputOpen) {
|
if (inputOpen) {
|
||||||
if (c == SimpleTextTerminal.ASCII_CR)
|
if (c == SimpleTextTerminal.ASCII_CR)
|
||||||
|
|||||||
@@ -39,18 +39,18 @@ interface Terminal : Teletype {
|
|||||||
fun setCursor(x: Int, y: Int)
|
fun setCursor(x: Int, y: Int)
|
||||||
/** Emits a bufferChar. Does not move cursor
|
/** Emits a bufferChar. Does not move cursor
|
||||||
* It is also not affected by the control sequences; just print them out as symbol */
|
* 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
|
/** Emits a char. Does not move cursor
|
||||||
* It is also not affected by the control sequences; just print them out as symbol */
|
* 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. */
|
/** Prints a char and move cursor accordingly. */
|
||||||
override fun printChar(c: Char)
|
override fun printChar(c: Char)
|
||||||
/** Emits a string, does not affected by control sequences. Does not move cursor */
|
/** 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 */
|
/** 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. */
|
/** 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 clear()
|
||||||
fun clearLine()
|
fun clearLine()
|
||||||
override fun newLine()
|
override fun newLine()
|
||||||
|
|||||||
Reference in New Issue
Block a user