diff --git a/src/net/torvald/tsvm/peripheral/GlassTty.kt b/src/net/torvald/tsvm/peripheral/GlassTty.kt index a061594..fe82d5c 100644 --- a/src/net/torvald/tsvm/peripheral/GlassTty.kt +++ b/src/net/torvald/tsvm/peripheral/GlassTty.kt @@ -50,8 +50,6 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { ttyEscArguments.push(ttyEscArguments.pop() * 10 + (newnum.toInt() - 0x30)) } - //TODO() - when (ttyEscState) { TTY_ESC_STATE.INITIAL -> { if (char == ESC) { @@ -117,6 +115,11 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { val arg1 = ttyEscArguments.pop() cursorXY(arg1, arg2) } + 'm' -> return accept { + val arg2 = ttyEscArguments.pop() + val arg1 = ttyEscArguments.pop() + sgrTwoArg(arg1, arg2) + } ';' -> ttyEscState = TTY_ESC_STATE.SEP2 else -> return reject() } @@ -140,6 +143,10 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { val arg1 = ttyEscArguments.pop() cursorXY(arg1, 0) } + 'm' -> return accept { + val arg1 = ttyEscArguments.pop() + sgrTwoArg(arg1, 0) + } ';' -> { ttyEscArguments.push(0) ttyEscState = TTY_ESC_STATE.SEP2 @@ -176,15 +183,14 @@ abstract class GlassTty(val TEXT_ROWS: Int, val TEXT_COLS: Int) { abstract fun scrollUp(arg: Int = 1) abstract fun scrollDown(arg: Int = 1) abstract fun sgrOneArg(arg: Int = 0) + abstract fun sgrTwoArg(arg1: Int, arg2: Int) abstract fun sgrThreeArg(arg1: Int, arg2: Int, arg3: Int) abstract fun cursorXY(arg1: Int, arg2: Int) + abstract fun ringBell() + abstract fun insertTab() private val ESC = 0x1B.toByte() - private val FORE_DEFAULT = 254 - private val BACK_DEFAULT = 255 - - private enum class TTY_ESC_STATE { INITIAL, ESC, CSI, NUM1, SEP1, NUM2, SEP2, NUM3 } @@ -234,16 +240,18 @@ digraph G { separator1 -> numeral2 [label="0..9"] separator1 -> separator2 [label="; (zero)"] separator1 -> CursorPos [label="H (zero)"] + separator1 -> SGR2 [label="m (zero)"] numeral2 -> numeral2 [label="0..9"] numeral2 -> CursorPos [label="H"] - numeral2 -> separator2 [label=";"] + numeral2 -> SGR2 [label="m"] + numeral2 -> separator2 [label="; (zero)"] separator2 -> numeral3 [label="0..9"] numeral3 -> numeral3 [label="0..9"] - separator2 -> "SGR-Colour" [label="m (zero)"] - numeral3 -> "SGR-Colour" [label="m"] + separator2 -> SGR3 [label="m (zero)"] + numeral3 -> SGR3 [label="m"] ESC [shape=Mdiamond] Reset -> end @@ -260,7 +268,8 @@ digraph G { ScrollDown -> end CursorPos -> end SGR -> end - "SGR-Colour" -> end + SGR2 -> end + SGR3 -> end end [shape=Msquare] } diff --git a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt index a6642ca..d210e9b 100644 --- a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt +++ b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt @@ -37,8 +37,8 @@ class GraphicsAdapter(val lcdMode: Boolean = false) : GlassTty(Companion.TEXT_RO private var chrWidth = 7f private var chrHeight = 14f - override var ttyFore: Int = 254 // cannot be Byte - override var ttyBack: Int = 255 // cannot be Byte + override var ttyFore: Int = TTY_FORE_DEFAULT // cannot be Byte + override var ttyBack: Int = TTY_BACK_DEFAULT // cannot be Byte private val textForePixmap = Pixmap(TEXT_COLS, TEXT_ROWS, Pixmap.Format.RGBA8888) private val textBackPixmap = Pixmap(TEXT_COLS, TEXT_ROWS, Pixmap.Format.RGBA8888) @@ -182,14 +182,10 @@ class GraphicsAdapter(val lcdMode: Boolean = false) : GlassTty(Companion.TEXT_RO } } - /** - * @param from memory address (pointer) on the VM's user memory. Because of how the VM is coded, only the user space is eligible for move. - * @param to memory "offset" in Graphics Adapter's memory space, starts from zero. - * @param length how many bytes should be moved - */ - /*fun bulkLoad(vm: VM, from: Long, to: Long, length: Long) { - UnsafeHelper.unsafe.copyMemory(null, vm.usermem.ptr + from, (framebuffer.pixels as DirectBuffer).address(), to, length) - }*/ + override fun resetTtyStatus() { + ttyFore = TTY_FORE_DEFAULT + ttyBack = TTY_BACK_DEFAULT + } override fun putChar(x: Int, y: Int, text: Byte, foreColour: Byte, backColour: Byte) { val textOff = toTtyTextOffset(x, y) @@ -364,6 +360,9 @@ class GraphicsAdapter(val lcdMode: Boolean = false) : GlassTty(Companion.TEXT_RO const val TEXT_ROWS = 32 val VRAM_SIZE = 256.kB() + const val TTY_FORE_DEFAULT = 254 + const val TTY_BACK_DEFAULT = 255 + private val LCD_BASE_COL = Color(0xa1a99cff.toInt()) val DRAW_SHADER_FRAG = """