2021-02-01 21:18:00 +00:00
|
|
|
; Bitmap pixel graphics routines for the CommanderX16
|
2020-12-25 01:59:19 +00:00
|
|
|
; Custom routines to use the full-screen 640x480 and 320x240 screen modes.
|
2021-02-21 21:48:06 +00:00
|
|
|
; (These modes are not supported by the documented GRAPH_xxxx kernal routines)
|
2021-02-01 21:18:00 +00:00
|
|
|
;
|
2021-02-01 19:56:04 +00:00
|
|
|
; No text layer is currently shown, text can be drawn as part of the bitmap itself.
|
|
|
|
; Note: for similar graphics routines that also work on the C-64, use the "graphics" module instead.
|
2023-10-04 21:01:00 +00:00
|
|
|
; Note: for identical routines for a monochrome 1 bpp screen, use the "monogfx" module instead.
|
2021-02-01 19:56:04 +00:00
|
|
|
; Note: for color palette manipulation, use the "palette" module or write Vera registers yourself.
|
2021-02-01 21:18:00 +00:00
|
|
|
; Note: this library implements code for various resolutions and color depths. This takes up memory.
|
|
|
|
; If you're memory constrained you should probably not use this built-in library,
|
|
|
|
; but make a copy in your project only containing the code for the required resolution.
|
2021-02-01 19:56:04 +00:00
|
|
|
;
|
2023-11-05 15:39:36 +00:00
|
|
|
; NOTE: For sake of speed, NO BOUNDS CHECKING is performed in most routines!
|
|
|
|
; You'll have to make sure yourself that you're not writing outside of bitmap boundaries!
|
|
|
|
;
|
2021-02-01 19:56:04 +00:00
|
|
|
;
|
2021-01-26 17:17:20 +00:00
|
|
|
; SCREEN MODE LIST:
|
|
|
|
; mode 0 = reset back to default text mode
|
2023-10-04 21:01:00 +00:00
|
|
|
; mode 1 = bitmap 320 x 240 x 256c (8 bpp)
|
2023-11-01 20:55:42 +00:00
|
|
|
; mode 2 = bitmap 640 x 480 x 4c (2 bpp)
|
|
|
|
; mode 3 = bitmap 320 x 240 x 4c (not yet implemented: just use 256c, there's enough vram for that)
|
|
|
|
; mode 4 = bitmap 320 x 240 x 16c (not yet implemented: just use 256c, there's enough vram for that)
|
|
|
|
; mode 5 = bitmap 640 x 400 x 16c (not yet implemented)
|
2021-01-26 17:17:20 +00:00
|
|
|
|
2020-12-23 00:55:15 +00:00
|
|
|
gfx2 {
|
|
|
|
|
2023-12-29 21:21:44 +00:00
|
|
|
%option ignore_unused
|
2023-06-29 22:29:50 +00:00
|
|
|
|
2020-12-23 01:30:46 +00:00
|
|
|
; read-only control variables:
|
2021-01-26 17:17:20 +00:00
|
|
|
ubyte active_mode = 0
|
2020-12-23 00:55:15 +00:00
|
|
|
uword width = 0
|
|
|
|
uword height = 0
|
|
|
|
ubyte bpp = 0
|
|
|
|
|
2020-12-26 00:25:52 +00:00
|
|
|
sub screen_mode(ubyte mode) {
|
2023-10-01 22:12:48 +00:00
|
|
|
cx16.VERA_CTRL=0
|
2020-12-23 00:55:15 +00:00
|
|
|
when mode {
|
2021-01-26 17:17:20 +00:00
|
|
|
1 -> {
|
|
|
|
; lores 256c
|
2020-12-23 00:55:15 +00:00
|
|
|
cx16.VERA_DC_VIDEO = (cx16.VERA_DC_VIDEO & %11001111) | %00100000 ; enable only layer 1
|
|
|
|
cx16.VERA_DC_HSCALE = 64
|
|
|
|
cx16.VERA_DC_VSCALE = 64
|
|
|
|
cx16.VERA_L1_CONFIG = %00000111
|
|
|
|
cx16.VERA_L1_MAPBASE = 0
|
|
|
|
cx16.VERA_L1_TILEBASE = 0
|
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; highres 4c
|
|
|
|
cx16.VERA_DC_VIDEO = (cx16.VERA_DC_VIDEO & %11001111) | %00100000 ; enable only layer 1
|
|
|
|
cx16.VERA_DC_HSCALE = 128
|
|
|
|
cx16.VERA_DC_VSCALE = 128
|
|
|
|
cx16.VERA_L1_CONFIG = %00000101
|
|
|
|
cx16.VERA_L1_MAPBASE = 0
|
|
|
|
cx16.VERA_L1_TILEBASE = %00000001
|
|
|
|
}
|
2021-01-26 17:17:20 +00:00
|
|
|
else -> {
|
2022-11-20 18:19:01 +00:00
|
|
|
; back to default text mode
|
2024-03-19 00:21:56 +00:00
|
|
|
if active_mode!=0 {
|
|
|
|
cx16.r15L = cx16.VERA_DC_VIDEO & %00000111 ; retain chroma + output mode
|
|
|
|
cbm.CINT()
|
|
|
|
cx16.VERA_DC_VIDEO = (cx16.VERA_DC_VIDEO & %11111000) | cx16.r15L
|
|
|
|
}
|
2023-11-04 13:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init_mode(mode)
|
2024-02-04 22:22:43 +00:00
|
|
|
if active_mode!=0
|
2023-11-04 13:51:25 +00:00
|
|
|
clear_screen(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
sub init_mode(ubyte mode) {
|
|
|
|
; set the internal configuration variables corresponding to the given screenmode
|
|
|
|
; doesn't manipulate Vera / the actual display mode
|
|
|
|
active_mode = mode
|
|
|
|
when mode {
|
|
|
|
1 -> {
|
|
|
|
width = 320
|
|
|
|
height = 240
|
|
|
|
bpp = 8
|
|
|
|
}
|
|
|
|
2 -> {
|
|
|
|
width = 640
|
|
|
|
height = 480
|
|
|
|
bpp = 2
|
|
|
|
}
|
|
|
|
else -> {
|
2020-12-25 16:00:11 +00:00
|
|
|
width = 0
|
|
|
|
height = 0
|
|
|
|
bpp = 0
|
2023-11-04 13:51:25 +00:00
|
|
|
active_mode = 0
|
2020-12-25 16:00:11 +00:00
|
|
|
}
|
2020-12-23 00:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-05 19:00:39 +00:00
|
|
|
sub clear_screen(ubyte color) {
|
2020-12-25 16:00:11 +00:00
|
|
|
position(0, 0)
|
2020-12-23 00:55:15 +00:00
|
|
|
when active_mode {
|
2021-01-26 17:17:20 +00:00
|
|
|
1 -> {
|
|
|
|
; lores 256c
|
2020-12-23 00:55:15 +00:00
|
|
|
repeat 240/2
|
2023-10-05 19:00:39 +00:00
|
|
|
cs_innerloop640(color)
|
2020-12-23 00:55:15 +00:00
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; highres 4c
|
2023-10-05 19:00:39 +00:00
|
|
|
ubyte[] colors = [%00000000, %01010101, %10101010, %11111111]
|
|
|
|
color = colors[color&3]
|
2021-01-27 01:31:20 +00:00
|
|
|
repeat 480/4
|
2023-10-05 19:00:39 +00:00
|
|
|
cs_innerloop640(color)
|
2021-01-27 01:31:20 +00:00
|
|
|
}
|
2020-12-23 00:55:15 +00:00
|
|
|
}
|
2020-12-25 16:00:11 +00:00
|
|
|
position(0, 0)
|
2020-12-23 00:55:15 +00:00
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub rect(uword xx, uword yy, uword rwidth, uword rheight, ubyte color) {
|
2022-05-22 15:34:08 +00:00
|
|
|
if rwidth==0 or rheight==0
|
2020-12-27 16:34:25 +00:00
|
|
|
return
|
2023-08-28 15:35:53 +00:00
|
|
|
horizontal_line(xx, yy, rwidth, color)
|
2022-05-22 15:34:08 +00:00
|
|
|
if rheight==1
|
2020-12-27 16:34:25 +00:00
|
|
|
return
|
2023-08-28 15:35:53 +00:00
|
|
|
horizontal_line(xx, yy+rheight-1, rwidth, color)
|
|
|
|
vertical_line(xx, yy+1, rheight-2, color)
|
2022-05-22 15:34:08 +00:00
|
|
|
if rwidth==1
|
2020-12-27 16:34:25 +00:00
|
|
|
return
|
2023-08-28 15:35:53 +00:00
|
|
|
vertical_line(xx+rwidth-1, yy+1, rheight-2, color)
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub fillrect(uword xx, uword yy, uword rwidth, uword rheight, ubyte color) {
|
2023-10-05 19:00:39 +00:00
|
|
|
; Draw a filled rectangle of the given size and color.
|
|
|
|
; To fill the whole screen, use clear_screen(color) instead - it is much faster.
|
2022-05-22 15:34:08 +00:00
|
|
|
if rwidth==0
|
2020-12-27 16:34:25 +00:00
|
|
|
return
|
2022-05-22 15:34:08 +00:00
|
|
|
repeat rheight {
|
2023-08-28 15:35:53 +00:00
|
|
|
horizontal_line(xx, yy, rwidth, color)
|
|
|
|
yy++
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub horizontal_line(uword xx, uword yy, uword length, ubyte color) {
|
2020-12-27 16:34:25 +00:00
|
|
|
if length==0
|
|
|
|
return
|
2020-12-27 14:14:44 +00:00
|
|
|
when active_mode {
|
2023-10-04 21:01:00 +00:00
|
|
|
1 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; lores 256c
|
2023-08-28 15:35:53 +00:00
|
|
|
position(xx, yy)
|
2021-01-27 01:31:20 +00:00
|
|
|
%asm {{
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_color
|
|
|
|
ldx p8v_length+1
|
2021-01-27 01:31:20 +00:00
|
|
|
beq +
|
|
|
|
ldy #0
|
|
|
|
- sta cx16.VERA_DATA0
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
dex
|
|
|
|
bne -
|
2023-12-29 21:21:44 +00:00
|
|
|
+ ldy p8v_length ; remaining
|
2021-01-27 01:31:20 +00:00
|
|
|
beq +
|
|
|
|
- sta cx16.VERA_DATA0
|
|
|
|
dey
|
|
|
|
bne -
|
2023-07-15 13:18:26 +00:00
|
|
|
+
|
2021-01-27 01:31:20 +00:00
|
|
|
}}
|
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
|
|
|
; highres 4c ....also mostly usable for lores 4c?
|
2021-02-01 19:56:04 +00:00
|
|
|
color &= 3
|
|
|
|
ubyte[4] colorbits
|
|
|
|
ubyte ii
|
|
|
|
for ii in 3 downto 0 {
|
|
|
|
colorbits[ii] = color
|
|
|
|
color <<= 2
|
|
|
|
}
|
2023-08-28 15:35:53 +00:00
|
|
|
void addr_mul_24_for_highres_4c(yy, xx) ; 24 bits result is in r0 and r1L (highest byte)
|
2021-02-01 19:56:04 +00:00
|
|
|
%asm {{
|
|
|
|
lda cx16.VERA_ADDR_H
|
|
|
|
and #%00000111 ; no auto advance
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
stz cx16.VERA_CTRL ; setup vera addr 0
|
|
|
|
lda cx16.r1
|
|
|
|
and #1
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
lda cx16.r0
|
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
lda cx16.r0+1
|
|
|
|
sta cx16.VERA_ADDR_M
|
2023-12-29 21:21:44 +00:00
|
|
|
ldx p8v_xx
|
2021-02-01 19:56:04 +00:00
|
|
|
}}
|
2021-01-29 22:52:29 +00:00
|
|
|
|
2021-02-01 19:56:04 +00:00
|
|
|
repeat length {
|
|
|
|
%asm {{
|
|
|
|
txa
|
|
|
|
and #3
|
|
|
|
tay
|
|
|
|
lda cx16.VERA_DATA0
|
2023-12-29 21:21:44 +00:00
|
|
|
and p8b_gfx2.p8s_plot.p8v_mask4c,y
|
|
|
|
ora p8v_colorbits,y
|
2021-02-01 19:56:04 +00:00
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
cpy #%00000011 ; next vera byte?
|
2021-04-28 00:55:49 +00:00
|
|
|
bne ++
|
2021-02-01 19:56:04 +00:00
|
|
|
inc cx16.VERA_ADDR_L
|
2021-04-28 00:55:49 +00:00
|
|
|
bne ++
|
2021-02-01 19:56:04 +00:00
|
|
|
inc cx16.VERA_ADDR_M
|
2021-02-04 16:47:52 +00:00
|
|
|
+ bne +
|
|
|
|
inc cx16.VERA_ADDR_H
|
2021-02-01 19:56:04 +00:00
|
|
|
+ inx ; next pixel
|
|
|
|
}}
|
|
|
|
}
|
2021-01-27 01:31:20 +00:00
|
|
|
}
|
2020-12-27 14:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-10 00:08:13 +00:00
|
|
|
sub safe_horizontal_line(uword xx, uword yy, uword length, ubyte color) {
|
2023-11-05 15:39:36 +00:00
|
|
|
; does bounds checking and clipping
|
|
|
|
if msb(yy)&$80!=0 or yy>=height
|
|
|
|
return
|
|
|
|
if msb(xx)&$80!=0 {
|
|
|
|
length += xx
|
|
|
|
xx = 0
|
|
|
|
}
|
|
|
|
if xx>=width
|
|
|
|
return
|
|
|
|
if xx+length>width
|
|
|
|
length = width-xx
|
|
|
|
if length>width
|
|
|
|
return
|
|
|
|
|
2023-11-10 00:08:13 +00:00
|
|
|
horizontal_line(xx, yy, length, color)
|
2023-11-05 15:39:36 +00:00
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub vertical_line(uword xx, uword yy, uword lheight, ubyte color) {
|
2021-01-27 01:31:20 +00:00
|
|
|
when active_mode {
|
2023-10-04 21:01:00 +00:00
|
|
|
1 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; lores 256c
|
|
|
|
; set vera auto-increment to 320 pixel increment (=next line)
|
2023-08-28 15:35:53 +00:00
|
|
|
position(xx,yy)
|
2021-01-29 22:52:29 +00:00
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & %00000111 | (14<<4)
|
2020-12-29 01:13:38 +00:00
|
|
|
%asm {{
|
2023-12-29 21:21:44 +00:00
|
|
|
ldy p8v_lheight
|
2020-12-29 21:53:53 +00:00
|
|
|
beq +
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_color
|
2021-01-27 01:31:20 +00:00
|
|
|
- sta cx16.VERA_DATA0
|
2020-12-29 01:13:38 +00:00
|
|
|
dey
|
|
|
|
bne -
|
2020-12-29 21:53:53 +00:00
|
|
|
+
|
2020-12-29 01:13:38 +00:00
|
|
|
}}
|
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; highres 4c
|
2021-04-27 22:29:21 +00:00
|
|
|
; use TWO vera adress pointers simultaneously one for reading, one for writing, so auto-increment is possible
|
2022-05-22 15:34:08 +00:00
|
|
|
if lheight==0
|
2021-04-27 22:29:21 +00:00
|
|
|
return
|
2023-08-28 15:35:53 +00:00
|
|
|
position2(xx,yy,true)
|
2021-04-27 23:19:10 +00:00
|
|
|
set_both_strides(13) ; 160 increment = 1 line in 640 px 4c mode
|
2023-05-23 18:10:01 +00:00
|
|
|
;; color &= 3
|
2023-08-28 15:35:53 +00:00
|
|
|
;; color <<= gfx2.plot.shift4c[lsb(xx) & 3]
|
|
|
|
cx16.r2L = lsb(xx) & 3
|
2023-05-23 18:10:01 +00:00
|
|
|
when color & 3 {
|
|
|
|
1 -> color = gfx2.plot.shiftedleft_4c_1[cx16.r2L]
|
|
|
|
2 -> color = gfx2.plot.shiftedleft_4c_2[cx16.r2L]
|
|
|
|
3 -> color = gfx2.plot.shiftedleft_4c_3[cx16.r2L]
|
|
|
|
}
|
2023-08-28 15:35:53 +00:00
|
|
|
ubyte @shared mask = gfx2.plot.mask4c[lsb(xx) & 3]
|
2022-05-22 15:34:08 +00:00
|
|
|
repeat lheight {
|
2021-02-05 17:09:21 +00:00
|
|
|
%asm {{
|
2021-04-27 22:29:21 +00:00
|
|
|
lda cx16.VERA_DATA0
|
2023-12-29 21:21:44 +00:00
|
|
|
and p8v_mask
|
|
|
|
ora p8v_color
|
2021-04-27 22:29:21 +00:00
|
|
|
sta cx16.VERA_DATA1
|
2021-02-05 17:09:21 +00:00
|
|
|
}}
|
2021-01-27 01:31:20 +00:00
|
|
|
}
|
2020-12-29 01:13:38 +00:00
|
|
|
}
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
2021-01-27 01:31:20 +00:00
|
|
|
|
2021-04-27 23:19:10 +00:00
|
|
|
sub set_both_strides(ubyte stride) {
|
|
|
|
stride <<= 4
|
|
|
|
cx16.VERA_CTRL = 0
|
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & %00000111 | stride
|
|
|
|
cx16.VERA_CTRL = 1
|
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & %00000111 | stride
|
|
|
|
}
|
|
|
|
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub line(uword @zp x1, uword @zp y1, uword @zp x2, uword @zp y2, ubyte color) {
|
|
|
|
; Bresenham algorithm.
|
|
|
|
; This code special-cases various quadrant loops to allow simple ++ and -- operations.
|
|
|
|
if y1>y2 {
|
|
|
|
; make sure dy is always positive to have only 4 instead of 8 special cases
|
2022-06-06 14:01:11 +00:00
|
|
|
cx16.r0 = x1
|
|
|
|
x1 = x2
|
|
|
|
x2 = cx16.r0
|
|
|
|
cx16.r0 = y1
|
|
|
|
y1 = y2
|
|
|
|
y2 = cx16.r0
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
2021-03-10 17:49:40 +00:00
|
|
|
word @zp dx = (x2 as word)-x1
|
|
|
|
word @zp dy = (y2 as word)-y1
|
2020-12-27 16:34:25 +00:00
|
|
|
|
|
|
|
if dx==0 {
|
2021-03-10 17:49:40 +00:00
|
|
|
vertical_line(x1, y1, abs(dy) as uword +1, color)
|
2020-12-27 16:34:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if dy==0 {
|
|
|
|
if x1>x2
|
|
|
|
x1=x2
|
2021-03-10 17:49:40 +00:00
|
|
|
horizontal_line(x1, y1, abs(dx) as uword +1, color)
|
2020-12-27 16:34:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
word @zp d = 0
|
2024-02-04 22:22:43 +00:00
|
|
|
cx16.r1L = 1 ;; true ; 'positive_ix'
|
2020-12-27 16:34:25 +00:00
|
|
|
if dx < 0 {
|
|
|
|
dx = -dx
|
2024-02-04 22:22:43 +00:00
|
|
|
cx16.r1L = 0 ;; false
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
2021-03-09 20:54:31 +00:00
|
|
|
word @zp dx2 = dx*2
|
|
|
|
word @zp dy2 = dy*2
|
2020-12-27 16:34:25 +00:00
|
|
|
cx16.r14 = x1 ; internal plot X
|
|
|
|
|
|
|
|
if dx >= dy {
|
2024-02-04 22:22:43 +00:00
|
|
|
if cx16.r1L!=0 {
|
2020-12-27 16:34:25 +00:00
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, color)
|
|
|
|
if cx16.r14==x2
|
|
|
|
return
|
|
|
|
cx16.r14++
|
2021-03-09 20:54:31 +00:00
|
|
|
d += dy2
|
2020-12-27 16:34:25 +00:00
|
|
|
if d > dx {
|
|
|
|
y1++
|
2021-03-09 20:54:31 +00:00
|
|
|
d -= dx2
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, color)
|
|
|
|
if cx16.r14==x2
|
|
|
|
return
|
|
|
|
cx16.r14--
|
2021-03-09 20:54:31 +00:00
|
|
|
d += dy2
|
2020-12-27 16:34:25 +00:00
|
|
|
if d > dx {
|
|
|
|
y1++
|
2021-03-09 20:54:31 +00:00
|
|
|
d -= dx2
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2024-02-04 22:22:43 +00:00
|
|
|
if cx16.r1L!=0 {
|
2020-12-27 16:34:25 +00:00
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, color)
|
|
|
|
if y1 == y2
|
|
|
|
return
|
|
|
|
y1++
|
2021-03-09 20:54:31 +00:00
|
|
|
d += dx2
|
2020-12-27 16:34:25 +00:00
|
|
|
if d > dy {
|
|
|
|
cx16.r14++
|
2021-03-09 20:54:31 +00:00
|
|
|
d -= dy2
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, color)
|
|
|
|
if y1 == y2
|
|
|
|
return
|
|
|
|
y1++
|
2021-03-09 20:54:31 +00:00
|
|
|
d += dx2
|
2020-12-27 16:34:25 +00:00
|
|
|
if d > dy {
|
|
|
|
cx16.r14--
|
2021-03-09 20:54:31 +00:00
|
|
|
d -= dy2
|
2020-12-27 16:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub circle(uword @zp xcenter, uword @zp ycenter, ubyte radius, ubyte color) {
|
2023-11-05 15:39:36 +00:00
|
|
|
; Warning: NO BOUNDS CHECKS. Make sure circle fits in the screen.
|
2020-12-27 14:14:44 +00:00
|
|
|
; Midpoint algorithm.
|
2020-12-27 16:34:25 +00:00
|
|
|
if radius==0
|
|
|
|
return
|
|
|
|
|
2020-12-27 14:14:44 +00:00
|
|
|
ubyte @zp xx = radius
|
|
|
|
ubyte @zp yy = 0
|
|
|
|
word @zp decisionOver2 = (1 as word)-xx
|
|
|
|
; R14 = internal plot X
|
|
|
|
; R15 = internal plot Y
|
|
|
|
|
|
|
|
while xx>=yy {
|
|
|
|
cx16.r14 = xcenter + xx
|
|
|
|
cx16.r15 = ycenter + yy
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
cx16.r14 = xcenter - xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
cx16.r14 = xcenter + xx
|
|
|
|
cx16.r15 = ycenter - yy
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
cx16.r14 = xcenter - xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
cx16.r14 = xcenter + yy
|
|
|
|
cx16.r15 = ycenter + xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
cx16.r14 = xcenter - yy
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
cx16.r14 = xcenter + yy
|
|
|
|
cx16.r15 = ycenter - xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
cx16.r14 = xcenter - yy
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
|
|
|
|
|
|
|
yy++
|
|
|
|
if decisionOver2>=0 {
|
|
|
|
xx--
|
|
|
|
decisionOver2 -= xx*$0002
|
|
|
|
}
|
|
|
|
decisionOver2 += yy*$0002
|
|
|
|
decisionOver2++
|
|
|
|
}
|
|
|
|
|
|
|
|
sub plotq() {
|
|
|
|
; cx16.r14 = x, cx16.r15 = y, color=color.
|
2020-12-27 14:14:44 +00:00
|
|
|
plot(cx16.r14, cx16.r15, color)
|
2023-11-05 15:39:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub safe_circle(uword @zp xcenter, uword @zp ycenter, ubyte radius, ubyte color) {
|
|
|
|
; This version does bounds checks and clipping, but is a lot slower.
|
|
|
|
; Midpoint algorithm.
|
|
|
|
if radius==0
|
|
|
|
return
|
|
|
|
|
|
|
|
ubyte @zp xx = radius
|
|
|
|
ubyte @zp yy = 0
|
|
|
|
word @zp decisionOver2 = (1 as word)-xx
|
|
|
|
; R14 = internal plot X
|
|
|
|
; R15 = internal plot Y
|
|
|
|
|
|
|
|
while xx>=yy {
|
|
|
|
cx16.r14 = xcenter + xx
|
|
|
|
cx16.r15 = ycenter + yy
|
|
|
|
plotq()
|
|
|
|
cx16.r14 = xcenter - xx
|
|
|
|
plotq()
|
|
|
|
cx16.r14 = xcenter + xx
|
|
|
|
cx16.r15 = ycenter - yy
|
|
|
|
plotq()
|
|
|
|
cx16.r14 = xcenter - xx
|
|
|
|
plotq()
|
|
|
|
cx16.r14 = xcenter + yy
|
|
|
|
cx16.r15 = ycenter + xx
|
|
|
|
plotq()
|
|
|
|
cx16.r14 = xcenter - yy
|
|
|
|
plotq()
|
|
|
|
cx16.r14 = xcenter + yy
|
|
|
|
cx16.r15 = ycenter - xx
|
|
|
|
plotq()
|
|
|
|
cx16.r14 = xcenter - yy
|
|
|
|
plotq()
|
2020-12-27 14:14:44 +00:00
|
|
|
|
|
|
|
yy++
|
2023-11-05 15:39:36 +00:00
|
|
|
if decisionOver2>=0 {
|
2020-12-27 14:14:44 +00:00
|
|
|
xx--
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 -= xx*$0002
|
2020-12-27 14:14:44 +00:00
|
|
|
}
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 += yy*$0002
|
|
|
|
decisionOver2++
|
|
|
|
}
|
|
|
|
|
|
|
|
sub plotq() {
|
|
|
|
; cx16.r14 = x, cx16.r15 = y, color=color.
|
|
|
|
safe_plot(cx16.r14, cx16.r15, color)
|
2020-12-27 14:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-27 16:34:25 +00:00
|
|
|
sub disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, ubyte color) {
|
2023-11-05 15:39:36 +00:00
|
|
|
; Warning: NO BOUNDS CHECKS. Make sure circle fits in the screen.
|
2020-12-27 14:14:44 +00:00
|
|
|
; Midpoint algorithm, filled
|
2020-12-27 16:34:25 +00:00
|
|
|
if radius==0
|
|
|
|
return
|
2020-12-27 14:14:44 +00:00
|
|
|
ubyte @zp yy = 0
|
2020-12-27 16:34:25 +00:00
|
|
|
word @zp decisionOver2 = (1 as word)-radius
|
2020-12-27 14:14:44 +00:00
|
|
|
|
2020-12-27 16:34:25 +00:00
|
|
|
while radius>=yy {
|
2020-12-27 22:57:13 +00:00
|
|
|
horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, color)
|
|
|
|
horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, color)
|
2020-12-28 21:15:16 +00:00
|
|
|
horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, color)
|
|
|
|
horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, color)
|
2020-12-27 14:14:44 +00:00
|
|
|
yy++
|
2023-11-05 15:39:36 +00:00
|
|
|
if decisionOver2>=0 {
|
2020-12-27 16:34:25 +00:00
|
|
|
radius--
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 -= radius*$0002
|
2020-12-27 14:14:44 +00:00
|
|
|
}
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 += yy*$0002
|
|
|
|
decisionOver2++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, ubyte color) {
|
|
|
|
; This version does bounds checks and clipping, but is a lot slower.
|
|
|
|
; Midpoint algorithm, filled
|
|
|
|
if radius==0
|
|
|
|
return
|
|
|
|
ubyte @zp yy = 0
|
|
|
|
word @zp decisionOver2 = (1 as word)-radius
|
|
|
|
|
|
|
|
while radius>=yy {
|
|
|
|
safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, color)
|
|
|
|
safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, color)
|
|
|
|
safe_horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, color)
|
|
|
|
safe_horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, color)
|
|
|
|
yy++
|
|
|
|
if decisionOver2>=0 {
|
|
|
|
radius--
|
|
|
|
decisionOver2 -= radius*$0002
|
|
|
|
}
|
|
|
|
decisionOver2 += yy*$0002
|
|
|
|
decisionOver2++
|
2020-12-27 14:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub plot(uword @zp xx, uword @zp yy, ubyte @zp color) {
|
2022-02-10 02:10:47 +00:00
|
|
|
ubyte[4] @shared mask4c = [%00111111, %11001111, %11110011, %11111100]
|
|
|
|
ubyte[4] @shared shift4c = [6,4,2,0]
|
2023-05-23 18:10:01 +00:00
|
|
|
ubyte[4] shiftedleft_4c_1 = [1<<6, 1<<4, 1<<2, 1<<0]
|
|
|
|
ubyte[4] shiftedleft_4c_2 = [2<<6, 2<<4, 2<<2, 2<<0]
|
|
|
|
ubyte[4] shiftedleft_4c_3 = [3<<6, 3<<4, 3<<2, 3<<0]
|
2020-12-27 22:57:13 +00:00
|
|
|
|
2020-12-23 00:55:15 +00:00
|
|
|
when active_mode {
|
2021-01-26 17:17:20 +00:00
|
|
|
1 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; lores 256c
|
2023-08-28 15:35:53 +00:00
|
|
|
void addr_mul_24_for_lores_256c(yy, xx) ; 24 bits result is in r0 and r1L (highest byte)
|
2021-04-28 00:22:21 +00:00
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
lda cx16.r1
|
|
|
|
ora #%00010000 ; enable auto-increment so next_pixel() can be used after this
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
lda cx16.r0+1
|
|
|
|
sta cx16.VERA_ADDR_M
|
|
|
|
lda cx16.r0
|
|
|
|
sta cx16.VERA_ADDR_L
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_color
|
2021-04-28 00:22:21 +00:00
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
}}
|
2021-01-27 01:31:20 +00:00
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
|
|
|
; highres 4c ....also mostly usable for lores 4c?
|
2023-08-28 15:35:53 +00:00
|
|
|
void addr_mul_24_for_highres_4c(yy, xx) ; 24 bits result is in r0 and r1L (highest byte)
|
|
|
|
cx16.r2L = lsb(xx) & 3 ; xbits
|
2023-05-23 18:10:01 +00:00
|
|
|
; color &= 3
|
|
|
|
; color <<= shift4c[cx16.r2L]
|
|
|
|
when color & 3 {
|
|
|
|
1 -> color = shiftedleft_4c_1[cx16.r2L]
|
|
|
|
2 -> color = shiftedleft_4c_2[cx16.r2L]
|
|
|
|
3 -> color = shiftedleft_4c_3[cx16.r2L]
|
|
|
|
}
|
2021-04-28 00:39:35 +00:00
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
lda cx16.r1L
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
lda cx16.r0H
|
|
|
|
sta cx16.VERA_ADDR_M
|
|
|
|
lda cx16.r0L
|
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
ldy cx16.r2L ; xbits
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_mask4c,y
|
2021-04-28 00:39:35 +00:00
|
|
|
and cx16.VERA_DATA0
|
2023-12-29 21:21:44 +00:00
|
|
|
ora p8v_color
|
2021-04-28 00:39:35 +00:00
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
}}
|
2020-12-23 00:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-06 12:40:55 +00:00
|
|
|
}
|
|
|
|
|
2023-11-05 15:39:36 +00:00
|
|
|
sub safe_plot(uword xx, uword yy, ubyte color) {
|
|
|
|
; A plot that does bounds checks to see if the pixel is inside the screen.
|
|
|
|
if msb(xx)&$80!=0 or msb(yy)&$80!=0
|
|
|
|
return
|
|
|
|
if xx >= width or yy >= height
|
|
|
|
return
|
|
|
|
plot(xx, yy, color)
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub pget(uword @zp xx, uword yy) -> ubyte {
|
2022-11-06 12:40:55 +00:00
|
|
|
when active_mode {
|
|
|
|
1 -> {
|
|
|
|
; lores 256c
|
2023-08-28 15:35:53 +00:00
|
|
|
void addr_mul_24_for_lores_256c(yy, xx) ; 24 bits result is in r0 and r1L (highest byte)
|
2022-11-06 12:40:55 +00:00
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
lda cx16.r1
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
lda cx16.r0+1
|
|
|
|
sta cx16.VERA_ADDR_M
|
|
|
|
lda cx16.r0
|
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
lda cx16.VERA_DATA0
|
|
|
|
}}
|
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
2022-11-06 12:40:55 +00:00
|
|
|
; hires 4c
|
2023-08-28 15:35:53 +00:00
|
|
|
void addr_mul_24_for_highres_4c(yy, xx) ; 24 bits result is in r0 and r1L (highest byte)
|
2022-11-06 12:40:55 +00:00
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
lda cx16.r1L
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
lda cx16.r0H
|
|
|
|
sta cx16.VERA_ADDR_M
|
|
|
|
lda cx16.r0L
|
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
lda cx16.VERA_DATA0
|
2023-10-15 20:44:34 +00:00
|
|
|
pha
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx
|
2023-10-15 20:44:34 +00:00
|
|
|
and #3
|
|
|
|
tay
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8b_gfx2.p8s_plot.p8v_shift4c,y
|
2023-10-15 20:44:34 +00:00
|
|
|
tay
|
|
|
|
pla
|
|
|
|
cpy #0
|
|
|
|
beq +
|
|
|
|
- lsr a
|
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
+ and #3
|
2022-11-06 12:40:55 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
else -> return 0
|
|
|
|
}
|
2020-12-23 04:04:19 +00:00
|
|
|
}
|
2023-05-22 22:27:42 +00:00
|
|
|
|
2023-11-04 12:51:18 +00:00
|
|
|
sub fill(uword x, uword y, ubyte new_color) {
|
2023-05-22 22:27:42 +00:00
|
|
|
; Non-recursive scanline flood fill.
|
|
|
|
; based loosely on code found here https://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm
|
|
|
|
; with the fixes applied to the seedfill_4 routine as mentioned in the comments.
|
2023-11-11 20:59:12 +00:00
|
|
|
const ubyte MAXDEPTH = 64
|
2023-11-04 12:51:18 +00:00
|
|
|
word @zp xx = x as word
|
|
|
|
word @zp yy = y as word
|
2023-05-28 12:53:53 +00:00
|
|
|
word[MAXDEPTH] @split @shared stack_xl
|
|
|
|
word[MAXDEPTH] @split @shared stack_xr
|
|
|
|
word[MAXDEPTH] @split @shared stack_y
|
2023-05-22 22:27:42 +00:00
|
|
|
byte[MAXDEPTH] @shared stack_dy
|
|
|
|
cx16.r12L = 0 ; stack pointer
|
|
|
|
word x1
|
|
|
|
word x2
|
|
|
|
byte dy
|
|
|
|
cx16.r10L = new_color
|
|
|
|
sub push_stack(word sxl, word sxr, word sy, byte sdy) {
|
|
|
|
if cx16.r12L==MAXDEPTH
|
|
|
|
return
|
|
|
|
cx16.r0s = sy+sdy
|
|
|
|
if cx16.r0s>=0 and cx16.r0s<=height-1 {
|
|
|
|
;; stack_xl[cx16.r12L] = sxl
|
|
|
|
;; stack_xr[cx16.r12L] = sxr
|
|
|
|
;; stack_y[cx16.r12L] = sy
|
|
|
|
;; stack_dy[cx16.r12L] = sdy
|
|
|
|
;; cx16.r12L++
|
|
|
|
%asm {{
|
2023-05-28 12:53:53 +00:00
|
|
|
ldy cx16.r12L
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_sxl
|
|
|
|
sta p8v_stack_xl_lsb,y
|
|
|
|
lda p8v_sxl+1
|
|
|
|
sta p8v_stack_xl_msb,y
|
|
|
|
lda p8v_sxr
|
|
|
|
sta p8v_stack_xr_lsb,y
|
|
|
|
lda p8v_sxr+1
|
|
|
|
sta p8v_stack_xr_msb,y
|
|
|
|
lda p8v_sy
|
|
|
|
sta p8v_stack_y_lsb,y
|
|
|
|
lda p8v_sy+1
|
|
|
|
sta p8v_stack_y_msb,y
|
2023-05-22 22:27:42 +00:00
|
|
|
ldy cx16.r12L
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_sdy
|
|
|
|
sta p8v_stack_dy,y
|
2023-05-22 22:27:42 +00:00
|
|
|
inc cx16.r12L
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sub pop_stack() {
|
|
|
|
;; cx16.r12L--
|
|
|
|
;; x1 = stack_xl[cx16.r12L]
|
|
|
|
;; x2 = stack_xr[cx16.r12L]
|
|
|
|
;; y = stack_y[cx16.r12L]
|
|
|
|
;; dy = stack_dy[cx16.r12L]
|
|
|
|
%asm {{
|
|
|
|
dec cx16.r12L
|
2023-05-28 12:53:53 +00:00
|
|
|
ldy cx16.r12L
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_stack_xl_lsb,y
|
|
|
|
sta p8v_x1
|
|
|
|
lda p8v_stack_xl_msb,y
|
|
|
|
sta p8v_x1+1
|
|
|
|
lda p8v_stack_xr_lsb,y
|
|
|
|
sta p8v_x2
|
|
|
|
lda p8v_stack_xr_msb,y
|
|
|
|
sta p8v_x2+1
|
|
|
|
lda p8v_stack_y_lsb,y
|
|
|
|
sta p8v_yy
|
|
|
|
lda p8v_stack_y_msb,y
|
|
|
|
sta p8v_yy+1
|
2023-05-22 22:27:42 +00:00
|
|
|
ldy cx16.r12L
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_stack_dy,y
|
|
|
|
sta p8v_dy
|
2023-05-22 22:27:42 +00:00
|
|
|
}}
|
2023-08-28 15:35:53 +00:00
|
|
|
yy+=dy
|
2023-05-22 22:27:42 +00:00
|
|
|
}
|
2023-08-28 15:35:53 +00:00
|
|
|
cx16.r11L = pget(xx as uword, yy as uword) ; old_color
|
2023-05-22 22:27:42 +00:00
|
|
|
if cx16.r11L == cx16.r10L
|
|
|
|
return
|
2023-08-28 15:35:53 +00:00
|
|
|
if xx<0 or xx>width-1 or yy<0 or yy>height-1
|
2023-05-22 22:27:42 +00:00
|
|
|
return
|
2023-08-28 15:35:53 +00:00
|
|
|
push_stack(xx, xx, yy, 1)
|
|
|
|
push_stack(xx, xx, yy + 1, -1)
|
2023-05-22 22:27:42 +00:00
|
|
|
word left = 0
|
2024-02-04 22:22:43 +00:00
|
|
|
while cx16.r12L!=0 {
|
2023-05-22 22:27:42 +00:00
|
|
|
pop_stack()
|
2023-08-28 15:35:53 +00:00
|
|
|
xx = x1
|
2024-01-14 12:20:12 +00:00
|
|
|
; possible speed optimization: if mode==1 (256c) use vera autodecrement instead of pget(), but code bloat not worth it?
|
2023-11-04 12:51:18 +00:00
|
|
|
while xx >= 0 {
|
|
|
|
if pget(xx as uword, yy as uword) != cx16.r11L
|
|
|
|
break
|
2023-08-28 15:35:53 +00:00
|
|
|
xx--
|
2023-11-04 12:51:18 +00:00
|
|
|
}
|
2023-10-18 21:04:11 +00:00
|
|
|
if x1!=xx
|
|
|
|
horizontal_line(xx as uword+1, yy as uword, x1-xx as uword, cx16.r10L)
|
|
|
|
else
|
2023-05-22 22:27:42 +00:00
|
|
|
goto skip
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
left = xx + 1
|
2023-05-22 22:27:42 +00:00
|
|
|
if left < x1
|
2023-08-28 15:35:53 +00:00
|
|
|
push_stack(left, x1 - 1, yy, -dy)
|
|
|
|
xx = x1 + 1
|
2023-05-22 22:27:42 +00:00
|
|
|
|
|
|
|
do {
|
2024-02-04 22:22:43 +00:00
|
|
|
cx16.r9s = xx
|
2024-01-14 12:20:12 +00:00
|
|
|
; possible speed optimization: if mode==1 (256c) use vera autoincrement instead of pget(), but code bloat not worth it?
|
2023-11-04 12:51:18 +00:00
|
|
|
while xx <= width-1 {
|
|
|
|
if pget(xx as uword, yy as uword) != cx16.r11L
|
|
|
|
break
|
2023-08-28 15:35:53 +00:00
|
|
|
xx++
|
2023-11-04 12:51:18 +00:00
|
|
|
}
|
2024-02-04 22:22:43 +00:00
|
|
|
if cx16.r9s!=xx
|
|
|
|
horizontal_line(cx16.r9, yy as uword, xx-cx16.r9s as uword, cx16.r10L)
|
2023-10-15 20:44:34 +00:00
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
push_stack(left, xx - 1, yy, dy)
|
|
|
|
if xx > x2 + 1
|
|
|
|
push_stack(x2 + 1, xx - 1, yy, -dy)
|
2023-05-22 22:27:42 +00:00
|
|
|
skip:
|
2023-08-28 15:35:53 +00:00
|
|
|
xx++
|
2023-11-04 12:51:18 +00:00
|
|
|
while xx <= x2 {
|
|
|
|
if pget(xx as uword, yy as uword) == cx16.r11L
|
|
|
|
break
|
2023-08-28 15:35:53 +00:00
|
|
|
xx++
|
2023-11-04 12:51:18 +00:00
|
|
|
}
|
2023-08-28 15:35:53 +00:00
|
|
|
left = xx
|
|
|
|
} until xx>x2
|
2023-05-22 22:27:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-23 04:04:19 +00:00
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub position(uword @zp xx, uword yy) {
|
2020-12-23 04:04:19 +00:00
|
|
|
when active_mode {
|
2021-01-26 17:17:20 +00:00
|
|
|
1 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; lores 256c
|
2023-08-28 15:35:53 +00:00
|
|
|
void addr_mul_24_for_lores_256c(yy, xx) ; 24 bits result is in r0 and r1L (highest byte)
|
2021-01-27 01:31:20 +00:00
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
2021-01-27 01:31:20 +00:00
|
|
|
; highres 4c
|
2023-08-28 15:35:53 +00:00
|
|
|
void addr_mul_24_for_highres_4c(yy, xx) ; 24 bits result is in r0 and r1L (highest byte)
|
2020-12-23 04:04:19 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
cx16.r2L = cx16.r1L
|
|
|
|
cx16.vaddr(cx16.r2L, cx16.r0, 0, 1)
|
2020-12-23 04:04:19 +00:00
|
|
|
}
|
2020-12-23 00:55:15 +00:00
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub position2(uword @zp xx, uword yy, bool also_port_1) {
|
|
|
|
position(xx, yy)
|
2023-07-23 21:29:09 +00:00
|
|
|
if also_port_1
|
|
|
|
cx16.vaddr_clone(0)
|
2021-04-27 22:29:21 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 04:33:00 +00:00
|
|
|
inline asmsub next_pixel(ubyte color @A) {
|
2020-12-23 04:04:19 +00:00
|
|
|
; -- sets the next pixel byte to the graphics chip.
|
2020-12-28 21:15:16 +00:00
|
|
|
; for 8 bpp screens this will plot 1 pixel.
|
2021-01-27 01:56:25 +00:00
|
|
|
; for 2 bpp screens it will plot 4 pixels at once (color = bit pattern).
|
2020-12-23 04:04:19 +00:00
|
|
|
%asm {{
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub next_pixels(uword pixels @AY, uword amount @R0) clobbers(A, X, Y) {
|
2020-12-26 02:10:53 +00:00
|
|
|
; -- sets the next bunch of pixels from a prepared array of bytes.
|
2020-12-28 21:15:16 +00:00
|
|
|
; for 8 bpp screens this will plot 1 pixel per byte.
|
2021-01-27 01:56:25 +00:00
|
|
|
; for 2 bpp screens it will plot 4 pixels at once (colors are the bit patterns per byte).
|
2020-12-28 21:15:16 +00:00
|
|
|
%asm {{
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
ldx cx16.r0+1
|
|
|
|
beq +
|
|
|
|
ldy #0
|
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
inc P8ZP_SCRATCH_W1+1 ; next page of 256 pixels
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
|
|
|
|
+ ldx cx16.r0 ; remaining pixels
|
|
|
|
beq +
|
|
|
|
ldy #0
|
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne -
|
2023-07-15 13:18:26 +00:00
|
|
|
+ rts
|
2020-12-28 21:15:16 +00:00
|
|
|
}}
|
2020-12-23 04:04:19 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub set_8_pixels_from_bits(ubyte bits @R0, ubyte oncolor @A, ubyte offcolor @Y) clobbers(X) {
|
2020-12-26 02:10:53 +00:00
|
|
|
; this is only useful in 256 color mode where one pixel equals one byte value.
|
2020-12-25 16:00:11 +00:00
|
|
|
%asm {{
|
|
|
|
ldx #8
|
|
|
|
- asl cx16.r0
|
|
|
|
bcc +
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
bra ++
|
|
|
|
+ sty cx16.VERA_DATA0
|
|
|
|
+ dex
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-12-26 02:10:53 +00:00
|
|
|
const ubyte charset_bank = $1
|
|
|
|
const uword charset_addr = $f000 ; in bank 1, so $1f000
|
|
|
|
|
|
|
|
sub text_charset(ubyte charset) {
|
2022-03-31 16:51:54 +00:00
|
|
|
; -- select the text charset to use with the text() routine
|
2020-12-26 02:10:53 +00:00
|
|
|
; the charset number is the same as for the cx16.screen_set_charset() ROM function.
|
|
|
|
; 1 = ISO charset, 2 = PETSCII uppercase+graphs, 3= PETSCII uppercase+lowercase.
|
|
|
|
cx16.screen_set_charset(charset, 0)
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub text(uword @zp xx, uword yy, ubyte color, uword sctextptr) {
|
2020-12-26 02:10:53 +00:00
|
|
|
; -- Write some text at the given pixel position. The text string must be in screencode encoding (not petscii!).
|
|
|
|
; You must also have called text_charset() first to select and prepare the character set to use.
|
2020-12-26 00:25:52 +00:00
|
|
|
uword chardataptr
|
2023-07-24 22:43:45 +00:00
|
|
|
ubyte[8] @shared char_bitmap_bytes_left
|
|
|
|
ubyte[8] @shared char_bitmap_bytes_right
|
|
|
|
|
2020-12-26 00:25:52 +00:00
|
|
|
when active_mode {
|
2023-10-04 21:01:00 +00:00
|
|
|
1 -> {
|
2021-01-26 17:17:20 +00:00
|
|
|
; lores 256c
|
2024-02-04 22:22:43 +00:00
|
|
|
while @(sctextptr)!=0 {
|
2020-12-26 00:25:52 +00:00
|
|
|
chardataptr = charset_addr + (@(sctextptr) as uword)*8
|
|
|
|
cx16.vaddr(charset_bank, chardataptr, 1, 1)
|
|
|
|
repeat 8 {
|
2023-08-28 15:35:53 +00:00
|
|
|
position(xx,yy)
|
|
|
|
yy++
|
2020-12-26 00:25:52 +00:00
|
|
|
%asm {{
|
2023-12-29 21:21:44 +00:00
|
|
|
ldx p8v_color
|
2020-12-26 00:25:52 +00:00
|
|
|
lda cx16.VERA_DATA1
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
ldy #8
|
2020-12-26 02:10:53 +00:00
|
|
|
- asl P8ZP_SCRATCH_B1
|
|
|
|
bcc +
|
|
|
|
stx cx16.VERA_DATA0 ; write a pixel
|
|
|
|
bra ++
|
|
|
|
+ lda cx16.VERA_DATA0 ; don't write a pixel, but do advance to the next address
|
|
|
|
+ dey
|
2020-12-26 00:25:52 +00:00
|
|
|
bne -
|
|
|
|
}}
|
|
|
|
}
|
2023-08-28 15:35:53 +00:00
|
|
|
xx+=8
|
|
|
|
yy-=8
|
2020-12-26 00:25:52 +00:00
|
|
|
sctextptr++
|
|
|
|
}
|
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
2 -> {
|
2021-02-01 21:18:00 +00:00
|
|
|
; hires 4c
|
2022-08-16 01:50:36 +00:00
|
|
|
; we're going to use a few cx16 registers to make sure every variable is in zeropage in the inner loop.
|
|
|
|
cx16.r11L = color
|
2024-02-04 22:22:43 +00:00
|
|
|
while @(sctextptr)!=0 {
|
2021-02-01 21:18:00 +00:00
|
|
|
chardataptr = charset_addr + (@(sctextptr) as uword)*8
|
2024-02-04 22:22:43 +00:00
|
|
|
cx16.vaddr(charset_bank, chardataptr, 1, 1) ; for reading the chardata from Vera data channel 1
|
2023-08-28 15:35:53 +00:00
|
|
|
position(xx, yy) ; only calculated once, we update vera address in the loop instead
|
2023-07-26 02:17:44 +00:00
|
|
|
cx16.VERA_ADDR_H &= $0f ; no auto increment
|
2021-02-01 21:18:00 +00:00
|
|
|
repeat 8 {
|
2023-07-26 02:17:44 +00:00
|
|
|
cx16.r10L = cx16.VERA_DATA1 ; get the next 8 horizontal character bits
|
2023-08-28 15:35:53 +00:00
|
|
|
cx16.r7 = xx
|
2021-02-01 21:18:00 +00:00
|
|
|
repeat 8 {
|
2023-07-26 02:17:44 +00:00
|
|
|
cx16.r10L <<= 1
|
|
|
|
if_cs {
|
|
|
|
cx16.r2L = cx16.r7L & 3 ; xbits
|
|
|
|
when cx16.r11L & 3 {
|
|
|
|
1 -> cx16.r12L = gfx2.plot.shiftedleft_4c_1[cx16.r2L]
|
|
|
|
2 -> cx16.r12L = gfx2.plot.shiftedleft_4c_2[cx16.r2L]
|
|
|
|
3 -> cx16.r12L = gfx2.plot.shiftedleft_4c_3[cx16.r2L]
|
|
|
|
else -> cx16.r12L = 0
|
|
|
|
}
|
|
|
|
cx16.VERA_DATA0 = cx16.VERA_DATA0 & gfx2.plot.mask4c[cx16.r2L] | cx16.r12L
|
|
|
|
}
|
2022-08-16 01:50:36 +00:00
|
|
|
cx16.r7++
|
2023-07-26 02:17:44 +00:00
|
|
|
if (cx16.r7 & 3) == 0 {
|
|
|
|
; increment the pixel address by one
|
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
clc
|
|
|
|
lda cx16.VERA_ADDR_L
|
|
|
|
adc #1
|
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
lda cx16.VERA_ADDR_M
|
|
|
|
adc #0
|
|
|
|
sta cx16.VERA_ADDR_M
|
|
|
|
lda cx16.VERA_ADDR_H
|
|
|
|
adc #0
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
}}
|
|
|
|
}
|
2021-02-01 21:18:00 +00:00
|
|
|
}
|
2023-07-26 02:17:44 +00:00
|
|
|
|
|
|
|
; increment pixel address to the next line
|
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
clc
|
|
|
|
lda cx16.VERA_ADDR_L
|
|
|
|
adc #(640-8)/4
|
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
lda cx16.VERA_ADDR_M
|
|
|
|
adc #0
|
|
|
|
sta cx16.VERA_ADDR_M
|
|
|
|
lda cx16.VERA_ADDR_H
|
|
|
|
adc #0
|
|
|
|
sta cx16.VERA_ADDR_H
|
|
|
|
}}
|
2021-02-01 21:18:00 +00:00
|
|
|
}
|
2023-08-28 15:35:53 +00:00
|
|
|
xx+=8
|
2021-02-01 21:18:00 +00:00
|
|
|
sctextptr++
|
|
|
|
}
|
|
|
|
}
|
2020-12-26 00:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-05 19:00:39 +00:00
|
|
|
asmsub cs_innerloop640(ubyte color @A) clobbers(Y) {
|
2023-11-30 23:33:17 +00:00
|
|
|
; using verafx 32 bits writes here would make this faster but it's safer to
|
|
|
|
; use verafx only explicitly when you know what you're doing.
|
2020-12-23 04:04:19 +00:00
|
|
|
%asm {{
|
|
|
|
ldy #80
|
2023-10-05 19:00:39 +00:00
|
|
|
- sta cx16.VERA_DATA0
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
sta cx16.VERA_DATA0
|
2020-12-23 04:04:19 +00:00
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
2020-12-23 00:55:15 +00:00
|
|
|
|
2021-02-25 23:43:51 +00:00
|
|
|
asmsub addr_mul_24_for_highres_4c(uword yy @R2, uword xx @R3) clobbers(A, Y) -> uword @R0, uword @R1 {
|
|
|
|
; yy * 160 + xx/4 (24 bits calculation)
|
2021-01-27 01:31:20 +00:00
|
|
|
; 24 bits result is in r0 and r1L (highest byte)
|
2021-02-04 16:47:52 +00:00
|
|
|
%asm {{
|
2021-02-25 23:43:51 +00:00
|
|
|
ldy #5
|
|
|
|
- asl cx16.r2
|
|
|
|
rol cx16.r2+1
|
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
lda cx16.r2
|
|
|
|
sta cx16.r0
|
|
|
|
lda cx16.r2+1
|
|
|
|
sta cx16.r0+1
|
|
|
|
asl cx16.r0
|
|
|
|
rol cx16.r0+1
|
|
|
|
asl cx16.r0
|
|
|
|
rol cx16.r0+1
|
|
|
|
|
|
|
|
; xx >>= 2 (xx=R3)
|
|
|
|
lsr cx16.r3+1
|
|
|
|
ror cx16.r3
|
|
|
|
lsr cx16.r3+1
|
|
|
|
ror cx16.r3
|
|
|
|
|
|
|
|
; add r2 and xx (r3) to r0 (24-bits)
|
2021-02-04 16:47:52 +00:00
|
|
|
stz cx16.r1
|
|
|
|
clc
|
|
|
|
lda cx16.r0
|
|
|
|
adc cx16.r2
|
|
|
|
sta cx16.r0
|
|
|
|
lda cx16.r0+1
|
|
|
|
adc cx16.r2+1
|
|
|
|
sta cx16.r0+1
|
|
|
|
bcc +
|
|
|
|
inc cx16.r1
|
|
|
|
+ clc
|
|
|
|
lda cx16.r0
|
2021-02-25 23:43:51 +00:00
|
|
|
adc cx16.r3
|
2021-02-04 16:47:52 +00:00
|
|
|
sta cx16.r0
|
|
|
|
lda cx16.r0+1
|
2021-02-25 23:43:51 +00:00
|
|
|
adc cx16.r3+1
|
2021-02-04 16:47:52 +00:00
|
|
|
sta cx16.r0+1
|
|
|
|
bcc +
|
|
|
|
inc cx16.r1
|
|
|
|
+
|
2021-02-25 23:43:51 +00:00
|
|
|
rts
|
2021-02-04 16:47:52 +00:00
|
|
|
}}
|
2021-01-27 01:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
asmsub addr_mul_24_for_lores_256c(uword yy @R0, uword xx @AY) clobbers(A) -> uword @R0, ubyte @R1 {
|
2021-02-27 02:30:21 +00:00
|
|
|
; yy * 320 + xx (24 bits calculation)
|
|
|
|
%asm {{
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
lda cx16.r0
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
lda cx16.r0+1
|
|
|
|
sta cx16.r1
|
|
|
|
sta P8ZP_SCRATCH_REG
|
|
|
|
lda cx16.r0
|
|
|
|
asl a
|
|
|
|
rol P8ZP_SCRATCH_REG
|
|
|
|
asl a
|
|
|
|
rol P8ZP_SCRATCH_REG
|
|
|
|
asl a
|
|
|
|
rol P8ZP_SCRATCH_REG
|
|
|
|
asl a
|
|
|
|
rol P8ZP_SCRATCH_REG
|
|
|
|
asl a
|
|
|
|
rol P8ZP_SCRATCH_REG
|
|
|
|
asl a
|
|
|
|
rol P8ZP_SCRATCH_REG
|
|
|
|
sta cx16.r0
|
|
|
|
lda P8ZP_SCRATCH_B1
|
|
|
|
clc
|
|
|
|
adc P8ZP_SCRATCH_REG
|
|
|
|
sta cx16.r0+1
|
|
|
|
bcc +
|
|
|
|
inc cx16.r1
|
|
|
|
+ ; now add the value to this 24-bits number
|
|
|
|
lda cx16.r0
|
|
|
|
clc
|
|
|
|
adc P8ZP_SCRATCH_W1
|
|
|
|
sta cx16.r0
|
|
|
|
lda cx16.r0+1
|
|
|
|
adc P8ZP_SCRATCH_W1+1
|
|
|
|
sta cx16.r0+1
|
|
|
|
bcc +
|
|
|
|
inc cx16.r1
|
|
|
|
+ lda cx16.r1
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
2020-12-23 00:55:15 +00:00
|
|
|
|
|
|
|
}
|