introduced graphics module wrapper for cx16 to make even more programs compatible

This commit is contained in:
Irmen de Jong 2020-09-22 02:12:01 +02:00
parent e8679ae03b
commit 0d5c78e875
6 changed files with 93 additions and 29 deletions

View File

@ -2,7 +2,7 @@
%import textio
; bitmap pixel graphics module for the C64
; only black/white monchrome for now
; only black/white monchrome 320x200 for now
; assumes bitmap screen memory is $2000-$3fff
graphics {
@ -135,33 +135,33 @@ graphics {
}
}
sub disc(uword cx, ubyte cy, ubyte radius) {
sub disc(uword xcenter, ubyte ycenter, ubyte radius) {
; Midpoint algorithm, filled
ubyte xx = radius
ubyte yy = 0
byte decisionOver2 = 1-xx as byte
while xx>=yy {
ubyte cy_plus_yy = cy + yy
ubyte cy_min_yy = cy - yy
ubyte cy_plus_xx = cy + xx
ubyte cy_min_xx = cy - xx
ubyte ycenter_plus_yy = ycenter + yy
ubyte ycenter_min_yy = ycenter - yy
ubyte ycenter_plus_xx = ycenter + xx
ubyte ycenter_min_xx = ycenter - xx
for internal_plotx in cx to cx+xx {
internal_plot(cy_plus_yy)
internal_plot(cy_min_yy)
for internal_plotx in xcenter to xcenter+xx {
internal_plot(ycenter_plus_yy)
internal_plot(ycenter_min_yy)
}
for internal_plotx in cx-xx to cx-1 {
internal_plot(cy_plus_yy)
internal_plot(cy_min_yy)
for internal_plotx in xcenter-xx to xcenter-1 {
internal_plot(ycenter_plus_yy)
internal_plot(ycenter_min_yy)
}
for internal_plotx in cx to cx+yy {
internal_plot(cy_plus_xx)
internal_plot(cy_min_xx)
for internal_plotx in xcenter to xcenter+yy {
internal_plot(ycenter_plus_xx)
internal_plot(ycenter_min_xx)
}
for internal_plotx in cx-yy to cx {
internal_plot(cy_plus_xx)
internal_plot(cy_min_xx)
for internal_plotx in xcenter-yy to xcenter {
internal_plot(ycenter_plus_xx)
internal_plot(ycenter_min_xx)
}
yy++
if decisionOver2<=0

View File

@ -0,0 +1,56 @@
%target cx16
%import syslib
; bitmap pixel graphics module for the CommanderX16
; wraps the graphics functions that are in ROM.
; only black/white monchrome 320x200 for now.
graphics {
sub enable_bitmap_mode() {
; enable bitmap screen, erase it and set colors to black/white.
void cx16.screen_set_mode($80)
cx16.r0 = 0
cx16.GRAPH_init()
clear_screen(1, 0)
}
sub clear_screen(ubyte pixelcolor, ubyte bgcolor) {
cx16.GRAPH_set_colors(pixelcolor, pixelcolor, bgcolor)
cx16.GRAPH_clear()
}
sub line(uword @zp x1, ubyte @zp y1, uword @zp x2, ubyte @zp y2) {
cx16.r0 = x1
cx16.r1 = y1
cx16.r2 = x2
cx16.r3 = y2
cx16.GRAPH_draw_line()
}
sub circle(uword xcenter, ubyte ycenter, ubyte radius) {
cx16.r0 = xcenter - radius/2
cx16.r1 = ycenter - radius/2
cx16.r2 = radius
cx16.r3 = radius
cx16.GRAPH_draw_oval(false) ; TODO currently seems to crash
}
sub disc(uword xcenter, ubyte ycenter, ubyte radius) {
cx16.r0 = xcenter - radius/2
cx16.r1 = ycenter - radius/2
cx16.r2 = radius
cx16.r3 = radius
cx16.GRAPH_draw_oval(true) ; TODO currently seems to crash
}
sub plot(uword plotx, ubyte ploty) {
cx16.r0 = plotx
cx16.r1 = ploty
cx16.FB_cursor_position()
cx16.FB_cursor_position()
cx16.FB_set_pixel(1)
}
}

View File

@ -1,9 +1,7 @@
%target c64
%import graphics
%import syslib
%import graphics
; TODO make the graphics library not C64 specific
; Note: this program is compatible with C64 and CX16.
main {
@ -38,13 +36,23 @@ main {
angley+=217
anglez+=452
while c64.RASTER!=255 {
}
while c64.RASTER!=254 {
}
wait_a_little_bit()
}
}
sub wait_a_little_bit() {
%asm {{
stx P8ZP_SCRATCH_REG
lda #0
jsr c64.SETTIM
- jsr c64.RDTIM
cmp #1
bne -
ldx P8ZP_SCRATCH_REG
rts
}}
}
sub rotate_vertices(ubyte ax, ubyte ay, ubyte az) {
; rotate around origin (0,0,0)

View File

@ -1,6 +1,6 @@
%import graphics
; TODO make graphics lib cross-system
; Note: this program is compatible with C64 and CX16.
main {

View File

@ -3,10 +3,10 @@
%zeropage floatsafe
; Draw a mandelbrot in graphics mode (the image will be 256 x 200 pixels).
; NOTE: this will take an eternity to draw on a real c64.
; NOTE: this will take an eternity to draw on a real c64. A CommanderX16 is a bit faster.
; even in Vice in warp mode (700% speed on my machine) it's slow, but you can see progress
; TODO make graphics lib cross-system
; Note: this program is compatible with C64 and CX16.
main {
const ubyte width = 255