From 81930312ffca6e82d2a337e9779de4c94ed8921a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 15 Feb 2021 17:47:48 +0100 Subject: [PATCH] added textio.setcc2() on commanderX16 to enable setting fg+bg colors. --- compiler/res/prog8lib/cx16/textio.p8 | 31 +++++++++++++++++++++ examples/test.p8 | 41 ++++++++++++++-------------- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/compiler/res/prog8lib/cx16/textio.p8 b/compiler/res/prog8lib/cx16/textio.p8 index 944d2d6be..4018aa62a 100644 --- a/compiler/res/prog8lib/cx16/textio.p8 +++ b/compiler/res/prog8lib/cx16/textio.p8 @@ -626,6 +626,8 @@ asmsub getchr (ubyte col @A, ubyte row @Y) -> ubyte @ A { asmsub setclr (ubyte col @X, ubyte row @Y, ubyte color @A) clobbers(A) { ; ---- set the color in A on the screen matrix at the given position + ; note: on the CommanderX16 this allows you to set both Fg and Bg colors; + ; use the high nybble in A to set the Bg color! %asm {{ pha txa @@ -657,6 +659,8 @@ asmsub getclr (ubyte col @A, ubyte row @Y) -> ubyte @ A { sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { ; ---- set char+color at the given position on the screen + ; note: color handling is the same as on the C64: it only sets the foreground color. + ; use setcc2 if you want Cx-16 specific feature of setting both Bg+Fg colors. %asm {{ phx lda column @@ -685,6 +689,33 @@ sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { }} } +sub setcc2 (ubyte column, ubyte row, ubyte char, ubyte colors) { + ; ---- set char+color at the given position on the screen + ; note: on the CommanderX16 this allows you to set both Fg and Bg colors; + ; use the high nybble in A to set the Bg color! + %asm {{ + phx + lda column + asl a + tax + ldy row + stz cx16.VERA_CTRL + stz cx16.VERA_ADDR_H + stx cx16.VERA_ADDR_L + sty cx16.VERA_ADDR_M + lda char + sta cx16.VERA_DATA0 + inx + stz cx16.VERA_ADDR_H + stx cx16.VERA_ADDR_L + sty cx16.VERA_ADDR_M + lda colors + sta cx16.VERA_DATA0 + plx + rts + }} +} + asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) { ; ---- safe wrapper around PLOT kernel routine, to save the X register. %asm {{ diff --git a/examples/test.p8 b/examples/test.p8 index 7aa94d215..4c82c62ee 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,33 +1,32 @@ %import textio %zeropage basicsafe +%option no_sysinit main { sub start() { - - str text = "44" - uword textptr = &text - - ubyte nlen = conv.any2uword(textptr) - ubyte lastchr = text[nlen] - ubyte valid_operand - - valid_operand = nlen>0 and lastchr==0 - txt.print("\nvalidoper? ") - txt.print_ub(valid_operand) txt.nl() - - valid_operand = nlen>0 - valid_operand = valid_operand and lastchr==0 - - txt.print("\nvalidoper? ") - txt.print_ub(valid_operand) + txt.nl() txt.nl() - valid_operand = nlen and lastchr==0 - txt.print("\nvalidoper? ") - txt.print_ub(valid_operand) - txt.nl() + txt.setcc2(0,0, 'a', $0f) + txt.setcc2(1,0, 'a', $1f) + txt.setcc2(2,0, 'a', $2f) + txt.setcc2(3,0, 'a', $3f) + txt.setcc2(4,0, 'a', $4f) + txt.setcc2(5,0, 'a', $5f) + txt.setcc2(6,0, 'a', $6f) + txt.setcc2(7,0, 'a', $7f) + txt.setcc2(8,0, 'a', $8f) + txt.setcc2(9,0, 'a', $9f) + txt.setcc2(10,0, 'a', $af) + txt.setcc2(11,0, 'a', $bf) + txt.setcc2(12,0, 'a', $cf) + txt.setcc2(13,0, 'a', $df) + txt.setcc2(14,0, 'a', $ef) + txt.setcc2(15,0, 'a', $ff) + + } }