mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 22:30:46 +00:00
implemented difference between printing and writing text in vm screen
This commit is contained in:
parent
d9d83248fe
commit
bc9d00922e
@ -60,53 +60,50 @@ class BitmapScreenPanel : KeyListener, JPanel() {
|
||||
g2d.color = palette[color and 15]
|
||||
g2d.drawLine(x1, y1, x2, y2)
|
||||
}
|
||||
fun writeText(x: Int, y: Int, text: String, color: Int, lowercase: Boolean) {
|
||||
var xx=x
|
||||
var yy=y
|
||||
fun printText(text: String, color: Int, lowercase: Boolean) {
|
||||
val lines = text.split('\n')
|
||||
for(line in lines.withIndex()) {
|
||||
writeTextSingleLine(xx, yy, line.value, color, lowercase)
|
||||
xx = cursorX
|
||||
yy = cursorY
|
||||
printTextSingleLine(line.value, color, lowercase)
|
||||
if(line.index<lines.size-1) {
|
||||
xx=0
|
||||
yy++
|
||||
cursorX=0
|
||||
cursorY++
|
||||
}
|
||||
}
|
||||
}
|
||||
fun writeTextSingleLine(x: Int, y: Int, text: String, color: Int, lowercase: Boolean) {
|
||||
private fun printTextSingleLine(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) {
|
||||
for(clearx in cursorX until cursorX+text.length) {
|
||||
g2d.clearRect(8*clearx, 8*y, 8, 8)
|
||||
}
|
||||
var xx=x
|
||||
var yy=y
|
||||
for(sc in Petscii.encodeScreencode(text, lowercase)) {
|
||||
setChar(xx, yy, sc)
|
||||
xx++
|
||||
if(xx>=(SCREENWIDTH/8)) {
|
||||
yy++
|
||||
xx=0
|
||||
setChar(cursorX, cursorY, sc)
|
||||
cursorX++
|
||||
if(cursorX>=(SCREENWIDTH/8)) {
|
||||
cursorY++
|
||||
cursorX=0
|
||||
}
|
||||
}
|
||||
cursorX = x + text.length
|
||||
cursorY = y
|
||||
if(cursorX>=(SCREENWIDTH/8)) {
|
||||
}
|
||||
|
||||
fun printChar(char: Short) {
|
||||
if(char==13.toShort() || char==141.toShort()) {
|
||||
cursorX=0
|
||||
cursorY++
|
||||
} else {
|
||||
setChar(cursorX, cursorY, char)
|
||||
cursorX++
|
||||
if (cursorX >= (SCREENWIDTH / 8)) {
|
||||
cursorY++
|
||||
cursorX = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -118,6 +115,19 @@ class BitmapScreenPanel : KeyListener, JPanel() {
|
||||
return Pair(cursorX, cursorY)
|
||||
}
|
||||
|
||||
fun writeText(x: Int, y: Int, text: String, color: Int, lowercase: Boolean) {
|
||||
var xx=x
|
||||
if(color!=1) {
|
||||
TODO("text can only be white for now")
|
||||
}
|
||||
for(clearx in xx until xx+text.length) {
|
||||
g2d.clearRect(8*clearx, 8*y, 8, 8)
|
||||
}
|
||||
for(sc in Petscii.encodeScreencode(text, lowercase)) {
|
||||
setChar(xx++, y, sc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
const val SCREENWIDTH = 320
|
||||
|
@ -1886,8 +1886,7 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
}
|
||||
"c64.CHROUT" -> {
|
||||
val sc=variables.getValue("A").integerValue()
|
||||
val (x, y) = canvas?.getCursorPos()!!
|
||||
canvas?.setChar(x, y, sc.toShort())
|
||||
canvas?.printChar(sc.toShort())
|
||||
callstack.pop()
|
||||
}
|
||||
"c64.GETIN" -> {
|
||||
@ -2208,27 +2207,23 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
canvas?.setCursorPos(x, y)
|
||||
}
|
||||
Syscall.SYSASM_c64scr_print -> {
|
||||
val (x, y) = canvas!!.getCursorPos()
|
||||
val straddr = variables.getValue("A").integerValue() + 256*variables.getValue("Y").integerValue()
|
||||
val str = heap.get(straddr).str!!
|
||||
canvas?.writeText(x, y, str, 1, true)
|
||||
canvas?.printText(str, 1, true)
|
||||
}
|
||||
Syscall.SYSASM_c64scr_print_ub -> {
|
||||
val (x, y) = canvas!!.getCursorPos()
|
||||
val num = variables.getValue("A").integerValue()
|
||||
canvas?.writeText(x, y, num.toString(), 1, true)
|
||||
canvas?.printText(num.toString(), 1, true)
|
||||
}
|
||||
Syscall.SYSASM_c64scr_print_uw -> {
|
||||
val (x, y) = canvas!!.getCursorPos()
|
||||
val lo = variables.getValue("A").integerValue()
|
||||
val hi = variables.getValue("Y").integerValue()
|
||||
val number = lo+256*hi
|
||||
canvas?.writeText(x, y, number.toString(), 1, true)
|
||||
canvas?.printText(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)
|
||||
canvas?.printText(number.toString(), 1, true)
|
||||
}
|
||||
Syscall.SYSASM_c64scr_setcc -> {
|
||||
val x = variables.getValue("c64scr.setcc.column").integerValue()
|
||||
|
Loading…
x
Reference in New Issue
Block a user