From 5d9087178928f78ce917e07b8d58eb54d7ad1739 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 30 Aug 2020 00:15:18 +0200 Subject: [PATCH] got floating points working in commanderx16, added txt.color() to set text color --- compiler/res/prog8lib/c64textio.p8 | 12 +++++--- compiler/res/prog8lib/cx16textio.p8 | 48 +++++++++++++++-------------- examples/bdmusic.p8 | 4 +-- examples/cx16/mandelbrot.p8 | 2 +- examples/hello.p8 | 2 +- examples/plasma.p8 | 2 +- examples/tehtriz.p8 | 10 +++--- examples/test.p8 | 1 - 8 files changed, 43 insertions(+), 38 deletions(-) diff --git a/compiler/res/prog8lib/c64textio.p8 b/compiler/res/prog8lib/c64textio.p8 index b96a8bdf6..a8fb1fb31 100644 --- a/compiler/res/prog8lib/c64textio.p8 +++ b/compiler/res/prog8lib/c64textio.p8 @@ -11,7 +11,7 @@ txt { -asmsub clear_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) { +asmsub clear_screen (ubyte char @ A, ubyte charcolor @ Y) clobbers(A) { ; ---- clear the character screen with the given fill character and character color. ; (assumes screen and color matrix are at their default addresses) @@ -41,7 +41,7 @@ _loop sta c64.Screen,y }} } -asmsub clear_screencolors (ubyte color @ A) clobbers(Y) { +asmsub clear_screencolors (ubyte scrcolor @ A) clobbers(Y) { ; ---- clear the character screen colors with the given color (leaves characters). ; (assumes color matrix is at the default address) %asm {{ @@ -56,6 +56,10 @@ _loop sta c64.Colors,y }} } +sub color (ubyte txtcol) { + c64.COLOR = txtcol +} + 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 @@ -504,7 +508,7 @@ _mod lda $ffff ; modified }} } -sub setcc (ubyte column, ubyte row, ubyte char, ubyte color) { +sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { ; ---- set char+color at the given position on the screen %asm {{ lda row @@ -524,7 +528,7 @@ sub setcc (ubyte column, ubyte row, ubyte char, ubyte color) { inc _colormod+2 + lda char _charmod sta $ffff ; modified - lda color + lda charcolor _colormod sta $ffff ; modified rts }} diff --git a/compiler/res/prog8lib/cx16textio.p8 b/compiler/res/prog8lib/cx16textio.p8 index f32084d5e..a161dec8e 100644 --- a/compiler/res/prog8lib/cx16textio.p8 +++ b/compiler/res/prog8lib/cx16textio.p8 @@ -20,6 +20,18 @@ asmsub clear_screen (ubyte char @ A, ubyte txtcolor @ Y) clobbers(A) { } +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) { + c64.CHROUT(color_to_charcode[txtcol & 15]) +} + +sub color2 (ubyte txtcol, ubyte bgcol) { + c64.CHROUT(color_to_charcode[bgcol & 15]) + c64.CHROUT(1) ; switch fg and bg colors + c64.CHROUT(color_to_charcode[txtcol & 15]) +} + asmsub print (str text @ AY) clobbers(A,Y) { ; ---- print null terminated string from A/Y ; note: the compiler contains an optimization that will replace @@ -224,30 +236,20 @@ asmsub print_w (word value @ AY) clobbers(A,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) { - c64.CHROUT(color_to_charcode[txtcol & 15]) -} - -sub color2 (ubyte txtcol, ubyte bgcol) { - c64.CHROUT(color_to_charcode[bgcol & 15]) - c64.CHROUT(1) ; switch fg and bg colors - c64.CHROUT(color_to_charcode[txtcol & 15]) -} - -sub setc (ubyte column, ubyte row, ubyte char) { +sub setchr (ubyte column, ubyte row, ubyte char) { ; ---- set char at the given position on the screen - %asm {{ - phx - ldy column - ldx row - clc - jsr c64.PLOT - plx - lda char - jmp c64.CHROUT - }} + ; plot(column, row) + c64.CHROUT(char) +; %asm {{ +; phx +; ldy column +; ldx row +; clc +; jsr c64.PLOT +; plx +; lda char +; jmp c64.CHROUT +; }} } asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) { diff --git a/examples/bdmusic.p8 b/examples/bdmusic.p8 index ab97c92eb..7e00c5bdf 100644 --- a/examples/bdmusic.p8 +++ b/examples/bdmusic.p8 @@ -47,10 +47,10 @@ sub delay() { sub print_notes(ubyte n1, ubyte n2) { c64.CHROUT('\n') txt.plot(n1/2, 24) - c64.COLOR=7 + txt.color(7) c64.CHROUT('Q') txt.plot(n2/2, 24) - c64.COLOR=4 + txt.color(4) c64.CHROUT('Q') } diff --git a/examples/cx16/mandelbrot.p8 b/examples/cx16/mandelbrot.p8 index 0c00b602b..487b03f0f 100644 --- a/examples/cx16/mandelbrot.p8 +++ b/examples/cx16/mandelbrot.p8 @@ -32,7 +32,7 @@ main { ysquared = y*y iter++ } - + ; txt.setchr(pixelx, pixely, '*') txt.color2(1, max_iter-iter) c64.CHROUT(' ') } diff --git a/examples/hello.p8 b/examples/hello.p8 index df0723b4f..d0d5ab337 100644 --- a/examples/hello.p8 +++ b/examples/hello.p8 @@ -9,7 +9,7 @@ main { sub start() { ; set text color and activate lowercase charset - c64.COLOR = 13 + txt.color(13) c64.VMCSB |= 2 ; use optimized routine to write text diff --git a/examples/plasma.p8 b/examples/plasma.p8 index b4d06648f..e44f4c29c 100644 --- a/examples/plasma.p8 +++ b/examples/plasma.p8 @@ -21,7 +21,7 @@ main { const ubyte PAGE2 = ((SCREEN2 >> 6) & $F0) | ((CHARSET >> 10) & $0E) sub start() { - c64.COLOR = 1 + txt.color(1) txt.print("creating charset...\n") makechar() diff --git a/examples/tehtriz.p8 b/examples/tehtriz.p8 index 5588521cf..45a10371e 100644 --- a/examples/tehtriz.p8 +++ b/examples/tehtriz.p8 @@ -280,12 +280,12 @@ waitkey: sub drawBoard() { c64.CLEARSCR() - c64.COLOR = 7 + txt.color(7) txt.plot(1,1) txt.print("irmen's") txt.plot(2,2) txt.print("teh▁triz") - c64.COLOR = 5 + txt.color(5) txt.plot(6,4) txt.print("hold:") txt.plot(2,22) @@ -296,10 +296,10 @@ waitkey: txt.print("lines:") txt.plot(28,14) txt.print("score:") - c64.COLOR = 12 + txt.color(12) txt.plot(27,18) txt.print("controls:") - c64.COLOR = 11 + txt.color(11) txt.plot(28,19) txt.print(",/ move") txt.plot(28,20) @@ -342,7 +342,7 @@ waitkey: } sub drawScore() { - c64.COLOR=1 + txt.color(1) txt.plot(30,11) txt.print_uw(lines) txt.plot(30,15) diff --git a/examples/test.p8 b/examples/test.p8 index c50aefb97..1e5dfc3ba 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -10,7 +10,6 @@ main { ; sub color(...) {} ; sub other(ubyte color) {} ; TODO don't cause name conflict - byte b1 byte b2 byte b3