From 2deb18beb2b73cac53995517a05597e29b3628cc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 19 Sep 2020 22:37:24 +0200 Subject: [PATCH] tweaks to c64 txtio. Fixed expression evaluation of bitwise invert. --- compiler/res/prog8lib/c64textio.p8 | 8 +++ compiler/res/prog8lib/cx16lib.p8 | 7 ++- compiler/res/prog8lib/cx16textio.p8 | 9 ++- .../optimizer/ConstantFoldingOptimizer.kt | 19 +++++- examples/cx16/datetime.p8 | 2 +- examples/hello.p8 | 4 +- examples/numbergame.p8 | 2 +- examples/screencodes.p8 | 2 +- examples/test.p8 | 63 ++++++++++--------- 9 files changed, 76 insertions(+), 40 deletions(-) diff --git a/compiler/res/prog8lib/c64textio.p8 b/compiler/res/prog8lib/c64textio.p8 index f860a3643..70a799b1f 100644 --- a/compiler/res/prog8lib/c64textio.p8 +++ b/compiler/res/prog8lib/c64textio.p8 @@ -68,6 +68,14 @@ sub color (ubyte txtcol) { c64.COLOR = txtcol } +sub lowercase() { + c64.VMCSB |= 2 +} + +sub uppercase() { + c64.VMCSB &= ~2 +} + asmsub scroll_left_full (ubyte alsocolors @ Pc) clobbers(A, Y) { ; ---- scroll the whole screen 1 character to the left ; contents of the rightmost column are unchanged, you should clear/refill this yourself diff --git a/compiler/res/prog8lib/cx16lib.p8 b/compiler/res/prog8lib/cx16lib.p8 index 256f833db..2e742ec00 100644 --- a/compiler/res/prog8lib/cx16lib.p8 +++ b/compiler/res/prog8lib/cx16lib.p8 @@ -259,9 +259,14 @@ asmsub init_system() { jsr c64.IOINIT jsr c64.RESTOR jsr c64.CINT + lda #$90 ; black + jsr c64.CHROUT + lda #1 ; swap fg/bg + jsr c64.CHROUT lda #$9e ; yellow jsr c64.CHROUT - ; TODO select black background color + lda #147 ; clear screen + jsr c64.CHROUT lda #0 tax tay diff --git a/compiler/res/prog8lib/cx16textio.p8 b/compiler/res/prog8lib/cx16textio.p8 index ee521e301..e52f081d5 100644 --- a/compiler/res/prog8lib/cx16textio.p8 +++ b/compiler/res/prog8lib/cx16textio.p8 @@ -83,7 +83,6 @@ asmsub clear_screenchars (ubyte char @ A) clobbers(Y) { }} } - ubyte[16] color_to_charcode = [$90,$05,$1c,$9f,$9c,$1e,$1f,$9e,$81,$95,$96,$97,$98,$99,$9a,$9b] sub color (ubyte txtcol) { @@ -96,6 +95,14 @@ sub color2 (ubyte txtcol, ubyte bgcol) { c64.CHROUT(color_to_charcode[txtcol & 15]) } +sub lowercase() { + cx16.screen_set_charset(3, 0) ; lowercase charset +} + +sub uppercase() { + cx16.screen_set_charset(2, 0) ; uppercase charset +} + romsub $FFD2 = chrout(ubyte char @ A) ; for consistency. You can also use c64.CHROUT directly ofcourse. asmsub print (str text @ AY) clobbers(A,Y) { diff --git a/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt b/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt index 933574b38..b8668421e 100644 --- a/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt +++ b/compiler/src/prog8/optimizer/ConstantFoldingOptimizer.kt @@ -216,9 +216,24 @@ internal class ConstantFoldingOptimizer(private val program: Program) : AstWalke else -> throw ExpressionError("can only take negative of int or float", subexpr.position) } "~" -> when (subexpr.type) { - in IntegerDatatypes -> { + DataType.BYTE -> { listOf(IAstModification.ReplaceNode(expr, - NumericLiteralValue.optimalInteger(subexpr.number.toInt().inv(), subexpr.position), + NumericLiteralValue(DataType.BYTE, subexpr.number.toInt().inv(), subexpr.position), + parent)) + } + DataType.UBYTE -> { + listOf(IAstModification.ReplaceNode(expr, + NumericLiteralValue(DataType.UBYTE, subexpr.number.toInt().inv() and 255, subexpr.position), + parent)) + } + DataType.WORD -> { + listOf(IAstModification.ReplaceNode(expr, + NumericLiteralValue(DataType.WORD, subexpr.number.toInt().inv(), subexpr.position), + parent)) + } + DataType.UWORD -> { + listOf(IAstModification.ReplaceNode(expr, + NumericLiteralValue(DataType.UWORD, subexpr.number.toInt().inv() and 65535, subexpr.position), parent)) } else -> throw ExpressionError("can only take bitwise inversion of int", subexpr.position) diff --git a/examples/cx16/datetime.p8 b/examples/cx16/datetime.p8 index 7202cad2e..a10d9af87 100644 --- a/examples/cx16/datetime.p8 +++ b/examples/cx16/datetime.p8 @@ -14,7 +14,7 @@ main { cx16.r2 = mkword(0, 16) cx16.r3 = 0 cx16.clock_set_date_time() - cx16.screen_set_charset(3, 0) ; lowercase charset + txt.lowercase() repeat { c64.CHROUT(19) ; HOME diff --git a/examples/hello.p8 b/examples/hello.p8 index d0d5ab337..13b7571ac 100644 --- a/examples/hello.p8 +++ b/examples/hello.p8 @@ -8,9 +8,7 @@ main { sub start() { - ; set text color and activate lowercase charset - txt.color(13) - c64.VMCSB |= 2 + txt.lowercase() ; use optimized routine to write text txt.print("Hello!\n") diff --git a/examples/numbergame.p8 b/examples/numbergame.p8 index 8c828a82a..6d572802b 100644 --- a/examples/numbergame.p8 +++ b/examples/numbergame.p8 @@ -13,7 +13,7 @@ main { ubyte secretnumber = rnd() % 99 + 1 ; random number 1..100 ubyte attempts_left - c64.VMCSB |= 2 ; switch lowercase chars + txt.lowercase() txt.print("Please introduce yourself: ") void txt.input_chars(name) txt.print("\n\nHello, ") diff --git a/examples/screencodes.p8 b/examples/screencodes.p8 index c24b55911..987b4e614 100644 --- a/examples/screencodes.p8 +++ b/examples/screencodes.p8 @@ -7,7 +7,7 @@ main { sub start() { - c64.VMCSB |= 2 ; switch to lowercase charset + txt.lowercase() str s1 = "HELLO hello 1234 @[/]" ; regular strings have default encoding (petscii on c64) str s2 = @"HELLO hello 1234 @[/]" ; alternative encoding (screencodes on c64) diff --git a/examples/test.p8 b/examples/test.p8 index 03f23cdd8..e4118107a 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,10 +1,10 @@ ;%import c64lib ;%import c64graphics -%import c64textio +; %import c64textio ;%import c64flt ;%option enable_floats -;%target cx16 -;%import cx16textio +%target cx16 +%import cx16textio %zeropage basicsafe @@ -12,41 +12,44 @@ main { sub start() { + txt.lowercase() + txt.print("Hello there") + txt.setchr(5, 5, '*') txt.setchr(6, 5, '*') txt.setchr(7, 5, '*') txt.setchr(7, 6, '+') txt.setchr(7, 7, '+') - txt.setclr(5, 5, 1) - txt.setclr(6, 5, 2) - txt.setclr(7, 5, 3) - txt.setclr(7, 6, 4) - txt.setclr(7, 7, 5) - +; txt.setclr(5, 5, 1) +; txt.setclr(6, 5, 2) +; txt.setclr(7, 5, 3) +; txt.setclr(7, 6, 4) +; txt.setclr(7, 7, 5) +; txt.plot(15,10) txt.chrout('!') - - txt.print_ub(txt.getchr(4,5)) - txt.chrout(',') - txt.print_ub(txt.getchr(5,5)) - txt.chrout(',') - txt.print_ub(txt.getchr(6,5)) - txt.chrout(',') - txt.print_ub(txt.getchr(7,5)) - txt.chrout(',') - txt.print_ub(txt.getchr(8,5)) - txt.chrout('\n') - txt.print_ub(txt.getclr(4,5)) - txt.chrout(',') - txt.print_ub(txt.getclr(5,5)) - txt.chrout(',') - txt.print_ub(txt.getclr(6,5)) - txt.chrout(',') - txt.print_ub(txt.getclr(7,5)) - txt.chrout(',') - txt.print_ub(txt.getclr(8,5)) - txt.chrout('\n') +; +; txt.print_ub(txt.getchr(4,5)) +; txt.chrout(',') +; txt.print_ub(txt.getchr(5,5)) +; txt.chrout(',') +; txt.print_ub(txt.getchr(6,5)) +; txt.chrout(',') +; txt.print_ub(txt.getchr(7,5)) +; txt.chrout(',') +; txt.print_ub(txt.getchr(8,5)) +; txt.chrout('\n') +; txt.print_ub(txt.getclr(4,5)) +; txt.chrout(',') +; txt.print_ub(txt.getclr(5,5)) +; txt.chrout(',') +; txt.print_ub(txt.getclr(6,5)) +; txt.chrout(',') +; txt.print_ub(txt.getclr(7,5)) +; txt.chrout(',') +; txt.print_ub(txt.getclr(8,5)) +; txt.chrout('\n') } }