improved text output in stackvm

This commit is contained in:
Irmen de Jong 2019-03-13 22:45:12 +01:00
parent bf3caaefe1
commit f2397527f1
3 changed files with 41 additions and 4 deletions

View File

@ -50,6 +50,8 @@ class BitmapScreenPanel : KeyListener, JPanel() {
fun clearScreen(color: Int) {
g2d.background = palette[color and 15]
g2d.clearRect(0, 0, BitmapScreenPanel.SCREENWIDTH, BitmapScreenPanel.SCREENHEIGHT)
cursorX = 0
cursorY = 0
}
fun setPixel(x: Int, y: Int, color: Int) {
image.setRGB(x, y, palette[color and 15].rgb)
@ -59,9 +61,26 @@ class BitmapScreenPanel : KeyListener, JPanel() {
g2d.drawLine(x1, y1, x2, y2)
}
fun writeText(x: Int, y: Int, text: String, color: Int, lowercase: Boolean) {
var xx=x
var yy=y
val lines = text.split('\n')
for(line in lines.withIndex()) {
writeTextSingleLine(xx, yy, line.value, color, lowercase)
xx = cursorX
yy = cursorY
if(line.index<lines.size-1) {
xx=0
yy++
}
}
}
fun writeTextSingleLine(x: Int, y: Int, text: String, color: Int, lowercase: Boolean) {
if(color!=1) {
TODO("text can only be white for now")
}
for(clearx in x until x+text.length) {
g2d.clearRect(8*clearx, 8*y, 8, 8)
}
var xx=x
var yy=y
for(sc in Petscii.encodeScreencode(text, lowercase)) {
@ -72,9 +91,22 @@ class BitmapScreenPanel : KeyListener, JPanel() {
xx=0
}
}
cursorX = x + text.length
cursorY = y
if(cursorX>=(SCREENWIDTH/8)) {
cursorX=0
cursorY++
}
}
fun setChar(x: Int, y: Int, screenCode: Short) {
g2d.clearRect(8*x, 8*y, 8, 8)
g2d.drawImage(Charset.shiftedChars[screenCode.toInt()], 8*x, 8*y , null)
cursorX = x + 1
cursorY = y
if(cursorX>=(SCREENWIDTH/8)) {
cursorX=0
cursorY++
}
}
fun setCursorPos(x: Int, y: Int) {

View File

@ -100,6 +100,7 @@ enum class Syscall(val callNr: Short) {
SYSASM_c64scr_print_uw(211),
SYSASM_c64scr_print_w(212),
SYSASM_c64scr_setcc(213),
SYSASM_c64flt_print_f(214),
}
@ -1879,7 +1880,6 @@ class StackVm(private var traceOutputFile: String?) {
callstack.pop()
}
"c64.CHROUT" -> {
// TODO sometimes the character ends up on the wrong screen position because the text-output routines don't update the cursorpos!
val sc=variables.getValue("A").integerValue()
val (x, y) = canvas?.getCursorPos()!!
canvas?.setChar(x, y, sc.toShort())
@ -2058,13 +2058,13 @@ class StackVm(private var traceOutputFile: String?) {
Syscall.FUNC_FLOOR -> {
val value = evalstack.pop()
if (value.type in NumericDatatypes)
evalstack.push(Value(DataType.WORD, floor(value.numericValue().toDouble()).toInt()))
evalstack.push(Value(DataType.FLOAT, floor(value.numericValue().toDouble())))
else throw VmExecutionException("cannot get floor of $value")
}
Syscall.FUNC_CEIL -> {
val value = evalstack.pop()
if (value.type in NumericDatatypes)
evalstack.push(Value(DataType.WORD, ceil(value.numericValue().toDouble()).toInt()))
evalstack.push(Value(DataType.FLOAT, ceil(value.numericValue().toDouble())))
else throw VmExecutionException("cannot get ceil of $value")
}
Syscall.FUNC_MAX_UB -> {
@ -2213,6 +2213,11 @@ class StackVm(private var traceOutputFile: String?) {
val number = lo+256*hi
canvas?.writeText(x, y, number.toString(), 1, true)
}
Syscall.SYSASM_c64flt_print_f -> {
val (x, y) = canvas!!.getCursorPos()
val number = variables.getValue("c64flt.print_f.value").numericValue()
canvas?.writeText(x, y, number.toString(), 1, true)
}
Syscall.SYSASM_c64scr_setcc -> {
val x = variables.getValue("c64scr.setcc.column").integerValue()
val y = variables.getValue("c64scr.setcc.row").integerValue()

View File

@ -10,7 +10,7 @@
const ubyte max_iter = 16
sub start() {
c64scr.print("calculating mandelbrot fractal...\n")
c64scr.print("calculating mandelbrot fractal...")
c64.TIME_HI=0
c64.TIME_MID=0