added CX16 txt.setcc and swirl examples that use it

This commit is contained in:
Irmen de Jong 2020-08-31 21:01:18 +02:00
parent f45eabdd9e
commit 2b35498370
4 changed files with 97 additions and 21 deletions

View File

@ -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) {

View File

@ -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++
}
}
}

30
examples/cx16/swirl.p8 Normal file
View File

@ -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++
}
}
}

View File

@ -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++
}
}
}