diff --git a/compiler/res/prog8lib/cx16textio.p8 b/compiler/res/prog8lib/cx16textio.p8 index ccbf80e3f..fddf0bfb8 100644 --- a/compiler/res/prog8lib/cx16textio.p8 +++ b/compiler/res/prog8lib/cx16textio.p8 @@ -268,20 +268,35 @@ asmsub print_w (word value @ AY) clobbers(A,Y) { }} } -sub setchr (ubyte column, ubyte row, ubyte char) { - ; ---- set char at the given position on the screen - ; plot(column, row) - c64.CHROUT(char) -; %asm {{ -; phx -; ldy column -; ldx row -; clc -; jsr c64.PLOT -; plx -; lda char -; jmp c64.CHROUT -; }} +; TODO implement the "missing" txtio subroutines + +sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { + ; ---- set char+color at the given position on the screen + %asm {{ + phx + lda column + asl a + tax + ldy row + lda charcolor + and #$0f + sta P8ZP_SCRATCH_B1 + 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 cx16.VERA_DATA0 + and #$f0 + ora P8ZP_SCRATCH_B1 + sta cx16.VERA_DATA0 + plx + rts + }} } asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) { diff --git a/examples/cx16/swirl-float.p8 b/examples/cx16/swirl-float.p8 new file mode 100644 index 000000000..1f7eb799f --- /dev/null +++ b/examples/cx16/swirl-float.p8 @@ -0,0 +1,27 @@ +%import cx16textio +%import cx16flt +%zeropage basicsafe + +main { + + const uword width = 80 + const uword height = 60 + + struct Ball { + float t + ubyte color + } + + sub start() { + + Ball ball + + repeat { + ubyte xx=(sin(ball.t) * width/2.1) + width/2.0 as ubyte + ubyte yy=(cos(ball.t*1.1356) * height/2.1) + height/2.0 as ubyte + txt.setcc(xx, yy, 81, ball.color) + ball.t += 0.05 + ball.color++ + } + } +} diff --git a/examples/cx16/swirl.p8 b/examples/cx16/swirl.p8 new file mode 100644 index 000000000..981792fde --- /dev/null +++ b/examples/cx16/swirl.p8 @@ -0,0 +1,30 @@ +%import cx16lib +%import cx16textio +%zeropage basicsafe + +main { + + const uword width = 79 + const uword height = 59 + + struct Ball { + uword anglex + uword angley + ubyte color + } + + sub start() { + + Ball ball + + repeat { + ubyte x = msb(sin8u(msb(ball.anglex)) as uword * width) + ubyte y = msb(cos8u(msb(ball.angley)) as uword * height) + txt.setcc(x, y, 81, ball.color) + + ball.anglex+=266 + ball.angley+=215 + ball.color++ + } + } +} diff --git a/examples/swirl-float.p8 b/examples/swirl-float.p8 index 1ccdb9963..cb4740442 100644 --- a/examples/swirl-float.p8 +++ b/examples/swirl-float.p8 @@ -6,17 +6,21 @@ main { const uword width = 40 const uword height = 25 - sub start() { - + struct Ball { float t ubyte color + } + + sub start() { + + Ball ball repeat { - ubyte xx=(sin(t) * width/2.2) + width/2.0 as ubyte - ubyte yy=(cos(t*1.1356) * height/2.2) + height/2.0 as ubyte - txt.setcc(xx, yy, 81, color) - t += 0.08 - color++ + ubyte xx=(sin(ball.t) * width/2.1) + width/2.0 as ubyte + ubyte yy=(cos(ball.t*1.1356) * height/2.1) + height/2.0 as ubyte + txt.setcc(xx, yy, 81, ball.color) + ball.t += 0.08 + ball.color++ } } }