return of the cursor blink

This commit is contained in:
minjaesong
2020-05-14 00:09:31 +09:00
parent b87afc4a51
commit ffe314bd61
5 changed files with 40 additions and 12 deletions

View File

@@ -25,7 +25,7 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
override fun create() { override fun create() {
super.create() super.create()
gpu = GraphicsAdapter(lcdMode = false) gpu = GraphicsAdapter(lcdMode = true)
vm.peripheralTable[1] = PeripheralEntry( vm.peripheralTable[1] = PeripheralEntry(
VM.PERITYPE_TERM, VM.PERITYPE_TERM,
@@ -49,7 +49,7 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
// TEST PRG // TEST PRG
vmRunner = VMRunnerFactory(vm, "js") vmRunner = VMRunnerFactory(vm, "js")
coroutineJob = GlobalScope.launch { coroutineJob = GlobalScope.launch {
vmRunner.executeCommand(gpuTestPaletteJs) vmRunner.executeCommand(sanitiseJS(gpuTestPaletteJs))
} }
} }
@@ -212,7 +212,7 @@ while true do
end end
""".trimIndent() """.trimIndent()
private val jscode = """ private val gpuTestPaletteJs = """
var w = 560; var w = 560;
var h = 448; var h = 448;
var hwoff = 1048576; var hwoff = 1048576;
@@ -254,12 +254,18 @@ while (true) {
var tend = vm.nanoTime(); var tend = vm.nanoTime();
print("Apparent FPS: " + (1000000000 / (tend - tstart))); println("Apparent FPS: " + (1000000000 / (tend - tstart)));
} }
""".trimIndent() """.trimIndent()
private val gpuTestPaletteJs = "function print(s){vm.print(s)}eval('${jscode.replace(Regex("//[^\\n]*"), "").replace('\n', ' ')}')" private val shitcode = """
println("064 KB OK");
println("");
println("Starting TVDOS...");
println("TSVM Disk Operating System, version 1.20");
println("");
print("C:\\\\>");
""".trimIndent()
private val gpuTestPaletteJava = """ private val gpuTestPaletteJava = """
int w = 560; int w = 560;

View File

@@ -14,6 +14,10 @@ class VMJSR223Delegate(val vm: VM) {
fun free(ptr: Int) = vm.free(ptr) fun free(ptr: Int) = vm.free(ptr)
fun print(s: String) { fun print(s: String) {
//print("[Nashorn] $s")
vm.printStream.write(s.toByteArray())
}
fun println(s: String) {
//println("[Nashorn] $s") //println("[Nashorn] $s")
vm.printStream.write((s + '\n').toByteArray()) vm.printStream.write((s + '\n').toByteArray())
} }

View File

@@ -1,5 +1,6 @@
package net.torvald.tsvm package net.torvald.tsvm
import java.io.FileReader
import javax.script.Compilable import javax.script.Compilable
import javax.script.ScriptContext import javax.script.ScriptContext
import javax.script.ScriptEngineManager import javax.script.ScriptEngineManager
@@ -53,6 +54,10 @@ object VMRunnerFactory {
//bind.put("poke", { a: Long, b: Byte -> vm.poke(a, b) }) // kts: lambda does not work... //bind.put("poke", { a: Long, b: Byte -> vm.poke(a, b) }) // kts: lambda does not work...
//bind.put("nanotime", { System.nanoTime() }) //bind.put("nanotime", { System.nanoTime() })
bind.put("serial", VMSerialDebugger(vm)) bind.put("serial", VMSerialDebugger(vm))
if (extension == "js") {
engine.eval(toSingleLine(JS_INIT), context)
}
} }
override suspend fun executeCommand(command: String) { override suspend fun executeCommand(command: String) {
@@ -64,4 +69,16 @@ object VMRunnerFactory {
//else -> throw UnsupportedOperationException("Unsupported script extension: $extension") //else -> throw UnsupportedOperationException("Unsupported script extension: $extension")
} }
} }
}
private val JS_INIT = """
function print(s) {
vm.print(s)
}
function println(s) {
vm.println(s)
}
"""
}
fun toSingleLine(code: String) = code.replace(Regex("//[^\\n]*"), "").replace('\n', ' ')
fun sanitiseJS(code: String) = "eval('${toSingleLine(code)}')"

View File

@@ -464,14 +464,16 @@ class GraphicsAdapter(val lcdMode: Boolean = false) : GlassTty(Companion.TEXT_RO
if (!graphicsUseSprites) { if (!graphicsUseSprites) {
// draw texts // draw texts
val (cx, cy) = getCursorPos()
// prepare char buffer texture // prepare char buffer texture
for (y in 0 until TEXT_ROWS) { for (y in 0 until TEXT_ROWS) {
for (x in 0 until TEXT_COLS) { for (x in 0 until TEXT_COLS) {
val drawCursor = textCursorIsOn && cx == x && cy == y
val addr = y.toLong() * TEXT_COLS + x val addr = y.toLong() * TEXT_COLS + x
val char = spriteAndTextArea[memTextOffset + addr].toInt().and(255) val char = if (drawCursor) 0xDB else spriteAndTextArea[memTextOffset + addr].toInt().and(255)
val back = spriteAndTextArea[memTextBackOffset + addr].toInt().and(255) val back = if (drawCursor) ttyBack else spriteAndTextArea[memTextBackOffset + addr].toInt().and(255)
val fore = spriteAndTextArea[memTextForeOffset + addr].toInt().and(255) val fore = if (drawCursor) ttyFore else spriteAndTextArea[memTextForeOffset + addr].toInt().and(255)
textPixmap.setColor(Color(0f, 0f, char / 255f, 1f)) textPixmap.setColor(Color(0f, 0f, char / 255f, 1f))
textPixmap.drawPixel(x, y) textPixmap.drawPixel(x, y)
@@ -519,7 +521,7 @@ class GraphicsAdapter(val lcdMode: Boolean = false) : GlassTty(Companion.TEXT_RO
paletteOfFloats[4 * ttyFore + 2], paletteOfFloats[4 * ttyFore + 2],
paletteOfFloats[4 * ttyFore + 3] paletteOfFloats[4 * ttyFore + 3]
) )
val (cursorx, cursory) = getTtyCursorPos() val (cursorx, cursory) = getCursorPos()
batch.draw(faketex, cursorx * chrWidth, (TEXT_ROWS - cursory - 1) * chrHeight, chrWidth, chrHeight) batch.draw(faketex, cursorx * chrWidth, (TEXT_ROWS - cursory - 1) * chrHeight, chrWidth, chrHeight)
}*/ }*/
} }

View File

@@ -18,6 +18,5 @@ class IOSpace : PeriBase {
} }
override fun dispose() { override fun dispose() {
TODO("Not yet implemented")
} }
} }