2023-10-04 20:32:13 +00:00
|
|
|
; Monochrome Bitmap pixel graphics routines for the CommanderX16
|
|
|
|
; Using the full-screen 640x480 and 320x240 screen modes, in 1 bpp mode (black/white).
|
|
|
|
;
|
|
|
|
; No text layer is currently shown, but text can be drawn as part of the bitmap itself.
|
2024-11-12 16:48:35 +00:00
|
|
|
; For color bitmap graphics, see the gfx_lores or gfx_hires libraries.
|
2023-10-04 20:32:13 +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!
|
2023-10-04 20:32:13 +00:00
|
|
|
|
2024-11-29 19:57:40 +00:00
|
|
|
%import buffers
|
|
|
|
|
2023-10-04 20:32:13 +00:00
|
|
|
monogfx {
|
|
|
|
|
2023-12-29 21:21:44 +00:00
|
|
|
%option ignore_unused
|
2023-10-04 20:32:13 +00:00
|
|
|
|
|
|
|
; read-only control variables:
|
|
|
|
uword width = 0
|
|
|
|
uword height = 0
|
2024-03-03 21:35:54 +00:00
|
|
|
ubyte mode
|
|
|
|
const ubyte MODE_NORMAL = %00000000
|
|
|
|
const ubyte MODE_STIPPLE = %00000001
|
|
|
|
const ubyte MODE_INVERT = %00000010
|
2023-10-04 20:32:13 +00:00
|
|
|
|
|
|
|
sub lores() {
|
|
|
|
; enable 320*240 bitmap mode
|
|
|
|
cx16.VERA_CTRL=0
|
|
|
|
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 = %00000100
|
|
|
|
cx16.VERA_L1_MAPBASE = 0
|
|
|
|
cx16.VERA_L1_TILEBASE = 0
|
|
|
|
width = 320
|
|
|
|
height = 240
|
2024-03-03 21:35:54 +00:00
|
|
|
mode = MODE_NORMAL
|
2024-09-17 19:01:01 +00:00
|
|
|
clear_screen(false)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub hires() {
|
|
|
|
; enable 640*480 bitmap mode
|
|
|
|
cx16.VERA_CTRL=0
|
|
|
|
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 = %00000100
|
|
|
|
cx16.VERA_L1_MAPBASE = 0
|
|
|
|
cx16.VERA_L1_TILEBASE = %00000001
|
|
|
|
width = 640
|
|
|
|
height = 480
|
2024-03-03 21:35:54 +00:00
|
|
|
mode = MODE_NORMAL
|
2024-09-17 19:01:01 +00:00
|
|
|
clear_screen(false)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub textmode() {
|
|
|
|
; back to normal text mode
|
|
|
|
cx16.r15L = cx16.VERA_DC_VIDEO & %00000111 ; retain chroma + output mode
|
|
|
|
cbm.CINT()
|
|
|
|
cx16.VERA_DC_VIDEO = (cx16.VERA_DC_VIDEO & %11111000) | cx16.r15L
|
|
|
|
}
|
|
|
|
|
2024-03-03 21:35:54 +00:00
|
|
|
sub drawmode(ubyte dm) {
|
|
|
|
mode = dm
|
|
|
|
}
|
|
|
|
|
2024-09-17 19:01:01 +00:00
|
|
|
sub clear_screen(bool draw) {
|
2023-10-04 20:32:13 +00:00
|
|
|
position(0, 0)
|
|
|
|
when width {
|
|
|
|
320 -> {
|
|
|
|
repeat 240/2/8
|
2024-09-17 19:01:01 +00:00
|
|
|
cs_innerloop640(draw)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
640 -> {
|
|
|
|
repeat 480/8
|
2024-09-17 19:01:01 +00:00
|
|
|
cs_innerloop640(draw)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
position(0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
sub rect(uword xx, uword yy, uword rwidth, uword rheight, bool draw) {
|
|
|
|
if rwidth==0 or rheight==0
|
|
|
|
return
|
|
|
|
horizontal_line(xx, yy, rwidth, draw)
|
|
|
|
if rheight==1
|
|
|
|
return
|
|
|
|
horizontal_line(xx, yy+rheight-1, rwidth, draw)
|
|
|
|
vertical_line(xx, yy+1, rheight-2, draw)
|
|
|
|
if rwidth==1
|
|
|
|
return
|
|
|
|
vertical_line(xx+rwidth-1, yy+1, rheight-2, draw)
|
|
|
|
}
|
|
|
|
|
|
|
|
sub fillrect(uword xx, uword yy, uword rwidth, uword rheight, bool draw) {
|
2024-09-17 19:01:01 +00:00
|
|
|
; Draw a filled rectangle of the given size.
|
|
|
|
; To fill the whole screen, use clear_screen(draw) instead - it is much faster.
|
2023-10-04 20:32:13 +00:00
|
|
|
if rwidth==0
|
|
|
|
return
|
|
|
|
repeat rheight {
|
|
|
|
horizontal_line(xx, yy, rwidth, draw)
|
|
|
|
yy++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub horizontal_line(uword xx, uword yy, uword length, bool draw) {
|
|
|
|
ubyte[9] masked_starts = [ 0, %00000001, %00000011, %00000111, %00001111, %00011111, %00111111, %01111111, %11111111]
|
|
|
|
ubyte[9] masked_ends = [ 0, %10000000, %11000000, %11100000, %11110000, %11111000, %11111100, %11111110, %11111111]
|
|
|
|
|
|
|
|
if length==0
|
|
|
|
return
|
2023-10-04 21:01:00 +00:00
|
|
|
if length<=8 {
|
|
|
|
; just use 2 byte writes with shifted mask
|
|
|
|
position2(xx,yy,true)
|
|
|
|
%asm {{
|
2023-12-29 21:21:44 +00:00
|
|
|
ldy p8v_length
|
|
|
|
lda p8v_masked_ends,y
|
2023-10-04 21:01:00 +00:00
|
|
|
sta cx16.r0L ; save left byte
|
|
|
|
stz P8ZP_SCRATCH_B1
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx
|
2023-10-04 21:01:00 +00:00
|
|
|
and #7
|
|
|
|
beq +
|
|
|
|
tay
|
|
|
|
lda cx16.r0L
|
|
|
|
- lsr a
|
|
|
|
ror P8ZP_SCRATCH_B1
|
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
sta cx16.r0L ; new left byte
|
|
|
|
+
|
2024-03-03 21:35:54 +00:00
|
|
|
lda p8v_mode
|
|
|
|
lsr a
|
|
|
|
bcc _dontstipple
|
2023-10-04 21:01:00 +00:00
|
|
|
; determine stipple pattern
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_yy
|
2023-10-04 21:01:00 +00:00
|
|
|
and #1
|
|
|
|
beq +
|
|
|
|
lda #%10101010
|
|
|
|
bne ++
|
|
|
|
+ lda #%01010101
|
|
|
|
+ sta P8ZP_SCRATCH_REG
|
|
|
|
lda cx16.r0L
|
|
|
|
and P8ZP_SCRATCH_REG
|
|
|
|
sta cx16.r0L
|
|
|
|
lda P8ZP_SCRATCH_B1
|
|
|
|
and P8ZP_SCRATCH_REG
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
_dontstipple
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_draw
|
2023-10-04 21:01:00 +00:00
|
|
|
beq _clear
|
|
|
|
lda cx16.r0L ; left byte
|
|
|
|
ora cx16.VERA_DATA1
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
lda P8ZP_SCRATCH_B1 ; right byte
|
|
|
|
ora cx16.VERA_DATA1
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
rts
|
|
|
|
_clear
|
|
|
|
lda cx16.r0L ; left byte
|
|
|
|
eor #255
|
|
|
|
and cx16.VERA_DATA1
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
lda P8ZP_SCRATCH_B1 ; right byte
|
|
|
|
eor #255
|
|
|
|
and cx16.VERA_DATA1
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-10-04 20:32:13 +00:00
|
|
|
ubyte separate_pixels = (8-lsb(xx)) & 7
|
2024-02-04 22:22:43 +00:00
|
|
|
if separate_pixels!=0 {
|
2024-03-05 21:38:34 +00:00
|
|
|
when mode {
|
|
|
|
MODE_NORMAL -> {
|
|
|
|
position(xx,yy)
|
|
|
|
cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off
|
|
|
|
if draw
|
|
|
|
cx16.VERA_DATA0 |= masked_starts[separate_pixels]
|
|
|
|
else
|
|
|
|
cx16.VERA_DATA0 &= ~masked_starts[separate_pixels]
|
|
|
|
xx += separate_pixels
|
|
|
|
}
|
|
|
|
MODE_STIPPLE -> {
|
|
|
|
repeat separate_pixels {
|
|
|
|
plot(xx, yy, draw)
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MODE_INVERT -> {
|
|
|
|
position(xx,yy)
|
|
|
|
cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off
|
|
|
|
if draw
|
|
|
|
cx16.VERA_DATA0 ^= masked_starts[separate_pixels]
|
|
|
|
else
|
|
|
|
cx16.VERA_DATA0 &= masked_starts[separate_pixels]
|
|
|
|
xx += separate_pixels
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
length -= separate_pixels
|
|
|
|
}
|
2024-02-04 22:22:43 +00:00
|
|
|
if length!=0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
position(xx, yy)
|
|
|
|
separate_pixels = lsb(length) & 7
|
|
|
|
xx += length & $fff8
|
|
|
|
%asm {{
|
2023-12-29 21:21:44 +00:00
|
|
|
lsr p8v_length+1
|
|
|
|
ror p8v_length
|
|
|
|
lsr p8v_length+1
|
|
|
|
ror p8v_length
|
|
|
|
lsr p8v_length+1
|
|
|
|
ror p8v_length
|
|
|
|
lda p8v_draw
|
2023-10-04 20:32:13 +00:00
|
|
|
bne +
|
|
|
|
ldy #0 ; black
|
|
|
|
bra _loop
|
2024-03-03 21:35:54 +00:00
|
|
|
+ lda p8v_mode
|
|
|
|
lsr a
|
|
|
|
bcs _stipple
|
2024-03-05 21:38:34 +00:00
|
|
|
lsr a
|
|
|
|
bcs _inverted
|
|
|
|
ldy #255 ; normal drawing mode
|
2023-10-04 20:32:13 +00:00
|
|
|
bra _loop
|
2024-03-05 21:38:34 +00:00
|
|
|
|
|
|
|
_inverted lda #0
|
|
|
|
jsr cx16.vaddr_clone
|
|
|
|
_invertedloop lda p8v_length
|
|
|
|
ora p8v_length+1
|
|
|
|
beq _done
|
|
|
|
lda cx16.VERA_DATA1
|
|
|
|
eor #255
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
lda p8v_length
|
|
|
|
bne +
|
|
|
|
dec p8v_length+1
|
|
|
|
+ dec p8v_length
|
|
|
|
bra _invertedloop
|
|
|
|
|
2023-12-29 21:21:44 +00:00
|
|
|
_stipple lda p8v_yy
|
2023-10-04 20:32:13 +00:00
|
|
|
and #1 ; determine stipple pattern to use
|
|
|
|
bne +
|
|
|
|
ldy #%01010101
|
|
|
|
bra _loop
|
|
|
|
+ ldy #%10101010
|
2023-12-29 21:21:44 +00:00
|
|
|
_loop lda p8v_length
|
|
|
|
ora p8v_length+1
|
2023-10-04 20:32:13 +00:00
|
|
|
beq _done
|
|
|
|
sty cx16.VERA_DATA0
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_length
|
2023-10-04 20:32:13 +00:00
|
|
|
bne +
|
2023-12-29 21:21:44 +00:00
|
|
|
dec p8v_length+1
|
|
|
|
+ dec p8v_length
|
2023-10-04 20:32:13 +00:00
|
|
|
bra _loop
|
|
|
|
_done
|
|
|
|
}}
|
|
|
|
|
2024-03-05 21:38:34 +00:00
|
|
|
when mode {
|
|
|
|
MODE_NORMAL -> {
|
|
|
|
cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off
|
|
|
|
if draw
|
|
|
|
cx16.VERA_DATA0 |= masked_ends[separate_pixels]
|
|
|
|
else
|
|
|
|
cx16.VERA_DATA0 &= ~masked_ends[separate_pixels]
|
|
|
|
}
|
|
|
|
MODE_STIPPLE -> {
|
|
|
|
repeat separate_pixels {
|
|
|
|
plot(xx, yy, draw)
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MODE_INVERT -> {
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off
|
|
|
|
if draw
|
2024-03-05 21:38:34 +00:00
|
|
|
cx16.VERA_DATA0 ^= masked_ends[separate_pixels]
|
2023-10-04 20:32:13 +00:00
|
|
|
else
|
2024-03-05 21:38:34 +00:00
|
|
|
cx16.VERA_DATA0 &= masked_ends[separate_pixels]
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cx16.VERA_ADDR_H &= %00000111 ; vera auto-increment off again
|
|
|
|
}
|
|
|
|
|
2023-11-05 15:39:36 +00:00
|
|
|
sub safe_horizontal_line(uword xx, uword yy, uword length, bool draw) {
|
|
|
|
; 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
|
|
|
|
|
|
|
|
horizontal_line(xx, yy, length, draw)
|
|
|
|
}
|
|
|
|
|
2023-10-04 20:32:13 +00:00
|
|
|
sub vertical_line(uword xx, uword yy, uword lheight, bool draw) {
|
|
|
|
cx16.r15L = monogfx.plot.maskbits[xx as ubyte & 7] ; bitmask
|
|
|
|
if draw {
|
2024-03-03 21:35:54 +00:00
|
|
|
%asm {{
|
|
|
|
lda p8v_mode
|
|
|
|
and #p8c_MODE_INVERT
|
|
|
|
beq +
|
2024-03-05 21:38:34 +00:00
|
|
|
lda #$45 ; eor ZP modifying code
|
|
|
|
bne ++
|
|
|
|
+ lda #$05 ; ora ZP modifying code
|
|
|
|
+ sta drawmode
|
2024-03-03 21:35:54 +00:00
|
|
|
}}
|
|
|
|
if mode!=MODE_STIPPLE {
|
2023-10-04 20:32:13 +00:00
|
|
|
; draw continuous line.
|
|
|
|
position2(xx,yy,true)
|
|
|
|
if width==320
|
|
|
|
set_both_strides(11) ; 40 increment = 1 line in 320 px monochrome
|
|
|
|
else
|
|
|
|
set_both_strides(12) ; 80 increment = 1 line in 640 px monochrome
|
|
|
|
repeat lheight {
|
|
|
|
%asm {{
|
|
|
|
lda cx16.VERA_DATA0
|
2024-03-03 21:35:54 +00:00
|
|
|
drawmode: ora cx16.r15L
|
2023-10-04 20:32:13 +00:00
|
|
|
sta cx16.VERA_DATA1
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
; draw stippled line.
|
2023-10-04 21:01:00 +00:00
|
|
|
if (xx ^ yy)&1==0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
yy++
|
|
|
|
lheight--
|
|
|
|
}
|
2023-10-04 21:01:00 +00:00
|
|
|
lheight++ ; because it is divided by 2 later, don't round off the last pixel
|
2023-10-04 20:32:13 +00:00
|
|
|
position2(xx,yy,true)
|
|
|
|
if width==320
|
|
|
|
set_both_strides(12) ; 80 increment = 2 line in 320 px monochrome
|
|
|
|
else
|
|
|
|
set_both_strides(13) ; 160 increment = 2 line in 640 px monochrome
|
|
|
|
repeat lheight/2 {
|
|
|
|
%asm {{
|
|
|
|
lda cx16.VERA_DATA0
|
|
|
|
ora cx16.r15L
|
|
|
|
sta cx16.VERA_DATA1
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
position2(xx,yy,true)
|
|
|
|
cx16.r15 = ~cx16.r15 ; erase pixels
|
|
|
|
if width==320
|
|
|
|
set_both_strides(11) ; 40 increment = 1 line in 320 px monochrome
|
|
|
|
else
|
|
|
|
set_both_strides(12) ; 80 increment = 1 line in 640 px monochrome
|
|
|
|
repeat lheight {
|
|
|
|
%asm {{
|
|
|
|
lda cx16.VERA_DATA0
|
|
|
|
and cx16.r15L
|
|
|
|
sta cx16.VERA_DATA1
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_both_strides(ubyte stride) {
|
|
|
|
stride <<= 4
|
|
|
|
cx16.VERA_CTRL = 1
|
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & %00000111 | stride
|
2024-07-02 21:36:36 +00:00
|
|
|
cx16.VERA_CTRL = 0
|
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & %00000111 | stride
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub line(uword @zp x1, uword @zp y1, uword @zp x2, uword @zp y2, bool draw) {
|
|
|
|
; 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
|
|
|
|
cx16.r0 = x1
|
|
|
|
x1 = x2
|
|
|
|
x2 = cx16.r0
|
|
|
|
cx16.r0 = y1
|
|
|
|
y1 = y2
|
|
|
|
y2 = cx16.r0
|
|
|
|
}
|
|
|
|
word @zp dx = (x2 as word)-x1
|
|
|
|
word @zp dy = (y2 as word)-y1
|
|
|
|
|
|
|
|
if dx==0 {
|
|
|
|
vertical_line(x1, y1, abs(dy) as uword +1, draw)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if dy==0 {
|
|
|
|
if x1>x2
|
|
|
|
x1=x2
|
|
|
|
horizontal_line(x1, y1, abs(dx) as uword +1, draw)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
word @zp d = 0
|
2024-02-04 22:22:43 +00:00
|
|
|
cx16.r1L = 1 ;; true ; 'positive_ix'
|
2023-10-04 20:32:13 +00:00
|
|
|
if dx < 0 {
|
|
|
|
dx = -dx
|
2024-02-04 22:22:43 +00:00
|
|
|
cx16.r1L = 0 ;; false
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
word @zp dx2 = dx*2
|
|
|
|
word @zp dy2 = dy*2
|
|
|
|
cx16.r14 = x1 ; internal plot X
|
|
|
|
|
|
|
|
if dx >= dy {
|
2024-02-04 22:22:43 +00:00
|
|
|
if cx16.r1L!=0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, draw)
|
|
|
|
if cx16.r14==x2
|
|
|
|
return
|
|
|
|
cx16.r14++
|
|
|
|
d += dy2
|
|
|
|
if d > dx {
|
|
|
|
y1++
|
|
|
|
d -= dx2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, draw)
|
|
|
|
if cx16.r14==x2
|
|
|
|
return
|
|
|
|
cx16.r14--
|
|
|
|
d += dy2
|
|
|
|
if d > dx {
|
|
|
|
y1++
|
|
|
|
d -= dx2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2024-02-04 22:22:43 +00:00
|
|
|
if cx16.r1L!=0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, draw)
|
|
|
|
if y1 == y2
|
|
|
|
return
|
|
|
|
y1++
|
|
|
|
d += dx2
|
|
|
|
if d > dy {
|
|
|
|
cx16.r14++
|
|
|
|
d -= dy2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
repeat {
|
|
|
|
plot(cx16.r14, y1, draw)
|
|
|
|
if y1 == y2
|
|
|
|
return
|
|
|
|
y1++
|
|
|
|
d += dx2
|
|
|
|
if d > dy {
|
|
|
|
cx16.r14--
|
|
|
|
d -= dy2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub circle(uword @zp xcenter, uword @zp ycenter, ubyte radius, bool draw) {
|
2023-11-05 15:39:36 +00:00
|
|
|
; Warning: NO BOUNDS CHECKS. Make sure circle fits in the screen.
|
2023-10-04 20:32:13 +00:00
|
|
|
; 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
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.r14 = xcenter - xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.r14 = xcenter + xx
|
|
|
|
cx16.r15 = ycenter - yy
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.r14 = xcenter - xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.r14 = xcenter + yy
|
|
|
|
cx16.r15 = ycenter + xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.r14 = xcenter - yy
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.r14 = xcenter + yy
|
|
|
|
cx16.r15 = ycenter - xx
|
2023-11-05 15:39:36 +00:00
|
|
|
plotq()
|
2023-10-04 20:32:13 +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, draw=draw
|
2023-10-04 20:32:13 +00:00
|
|
|
plot(cx16.r14, cx16.r15, draw)
|
2023-11-05 15:39:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub safe_circle(uword @zp xcenter, uword @zp ycenter, ubyte radius, bool draw) {
|
|
|
|
; Does bounds checking and clipping.
|
|
|
|
; 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()
|
2023-10-04 20:32:13 +00:00
|
|
|
|
|
|
|
yy++
|
2023-11-05 15:39:36 +00:00
|
|
|
if decisionOver2>=0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
xx--
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 -= xx*$0002
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 += yy*$0002
|
|
|
|
decisionOver2++
|
|
|
|
}
|
|
|
|
|
|
|
|
sub plotq() {
|
|
|
|
; cx16.r14 = x, cx16.r15 = y, draw=draw
|
|
|
|
safe_plot(cx16.r14, cx16.r15, draw)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) {
|
2023-11-05 15:39:36 +00:00
|
|
|
; Warning: NO BOUNDS CHECKS. Make sure circle fits in the screen.
|
2023-10-04 20:32:13 +00:00
|
|
|
; Midpoint algorithm, filled
|
|
|
|
if radius==0
|
|
|
|
return
|
|
|
|
ubyte @zp yy = 0
|
|
|
|
word @zp decisionOver2 = (1 as word)-radius
|
2024-09-15 13:38:33 +00:00
|
|
|
uword last_y3 = ycenter+radius
|
|
|
|
uword last_y4 = ycenter-radius
|
|
|
|
uword new_y3, new_y4
|
2023-10-04 20:32:13 +00:00
|
|
|
|
|
|
|
while radius>=yy {
|
|
|
|
horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
|
|
|
|
horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
|
2024-09-15 13:38:33 +00:00
|
|
|
new_y3 = ycenter+radius
|
|
|
|
if new_y3 != last_y3 {
|
|
|
|
horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
|
|
|
|
last_y3 = new_y3
|
|
|
|
}
|
|
|
|
new_y4 = ycenter-radius
|
|
|
|
if new_y4 != last_y4 {
|
|
|
|
horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
|
|
|
|
last_y4 = new_y4
|
|
|
|
}
|
2023-10-04 20:32:13 +00:00
|
|
|
yy++
|
2023-11-05 15:39:36 +00:00
|
|
|
if decisionOver2>=0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
radius--
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 -= radius*$0002
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 += yy*$0002
|
|
|
|
decisionOver2++
|
|
|
|
}
|
2024-09-15 13:38:33 +00:00
|
|
|
; draw the final two spans
|
|
|
|
yy--
|
|
|
|
horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
|
|
|
|
horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
|
2023-11-05 15:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) {
|
|
|
|
; Does bounds checking and clipping.
|
|
|
|
; Midpoint algorithm, filled
|
|
|
|
if radius==0
|
|
|
|
return
|
|
|
|
ubyte @zp yy = 0
|
|
|
|
word @zp decisionOver2 = (1 as word)-radius
|
2024-09-15 13:38:33 +00:00
|
|
|
uword last_y3 = ycenter+radius
|
|
|
|
uword last_y4 = ycenter-radius
|
|
|
|
uword new_y3, new_y4
|
2023-11-05 15:39:36 +00:00
|
|
|
|
|
|
|
while radius>=yy {
|
|
|
|
safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
|
|
|
|
safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
|
2024-09-15 13:38:33 +00:00
|
|
|
new_y3 = ycenter+radius
|
|
|
|
if new_y3 != last_y3 {
|
|
|
|
safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
|
|
|
|
last_y3 = new_y3
|
|
|
|
}
|
|
|
|
new_y4 = ycenter-radius
|
|
|
|
if new_y4 != last_y4 {
|
|
|
|
safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
|
|
|
|
last_y4 = new_y4
|
|
|
|
}
|
2023-11-05 15:39:36 +00:00
|
|
|
yy++
|
|
|
|
if decisionOver2>=0 {
|
|
|
|
radius--
|
|
|
|
decisionOver2 -= radius*$0002
|
|
|
|
}
|
|
|
|
decisionOver2 += yy*$0002
|
|
|
|
decisionOver2++
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
2024-09-15 13:38:33 +00:00
|
|
|
; draw the final two spans
|
|
|
|
yy--
|
|
|
|
safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
|
|
|
|
safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub plot(uword @zp xx, uword @zp yy, bool @zp draw) {
|
|
|
|
ubyte[8] @shared maskbits = [128, 64, 32, 16, 8, 4, 2, 1]
|
|
|
|
if draw {
|
|
|
|
; solid color or perhaps stipple
|
|
|
|
%asm {{
|
2024-03-03 21:35:54 +00:00
|
|
|
lda p8v_mode
|
|
|
|
lsr a
|
|
|
|
bcs +
|
|
|
|
lsr a
|
|
|
|
bcs p8l_invert
|
|
|
|
bra p8l_nostipple
|
|
|
|
+ ; stipple mode
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx
|
|
|
|
eor p8v_yy
|
2023-10-04 20:32:13 +00:00
|
|
|
and #1
|
|
|
|
}}
|
|
|
|
if_nz {
|
2024-03-03 20:47:42 +00:00
|
|
|
nostipple:
|
2023-10-04 20:32:13 +00:00
|
|
|
prepare()
|
|
|
|
%asm {{
|
|
|
|
tsb cx16.VERA_DATA0
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
; only erase
|
|
|
|
prepare()
|
|
|
|
%asm {{
|
|
|
|
trb cx16.VERA_DATA0
|
|
|
|
}}
|
|
|
|
}
|
2024-03-03 21:35:54 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
invert:
|
|
|
|
prepare()
|
|
|
|
%asm {{
|
|
|
|
lda cx16.VERA_DATA0
|
|
|
|
eor p8v_maskbits,y
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
}}
|
|
|
|
return
|
2023-10-04 20:32:13 +00:00
|
|
|
|
|
|
|
sub prepare() {
|
|
|
|
%asm {{
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx
|
2023-10-04 20:32:13 +00:00
|
|
|
and #7
|
|
|
|
pha ; xbits
|
|
|
|
}}
|
|
|
|
xx /= 8
|
|
|
|
if width==320
|
|
|
|
xx += yy*(320/8)
|
|
|
|
else
|
|
|
|
xx += yy*(640/8)
|
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
stz cx16.VERA_ADDR_H
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx+1
|
2023-10-04 20:32:13 +00:00
|
|
|
sta cx16.VERA_ADDR_M
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx
|
2023-10-04 20:32:13 +00:00
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
ply ; xbits
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_maskbits,y
|
2023-10-04 20:32:13 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 15:39:36 +00:00
|
|
|
sub safe_plot(uword xx, uword yy, bool draw) {
|
|
|
|
; 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, draw)
|
|
|
|
}
|
|
|
|
|
2024-02-27 23:34:35 +00:00
|
|
|
sub pget(uword @zp xx, uword yy) -> bool {
|
2023-10-04 20:32:13 +00:00
|
|
|
%asm {{
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx
|
2023-10-04 20:32:13 +00:00
|
|
|
and #7
|
|
|
|
pha ; xbits
|
|
|
|
}}
|
|
|
|
xx /= 8
|
|
|
|
if width==320
|
|
|
|
xx += yy*(320/8)
|
|
|
|
else
|
|
|
|
xx += yy*(640/8)
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
stz cx16.VERA_ADDR_H
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx+1
|
2023-10-04 20:32:13 +00:00
|
|
|
sta cx16.VERA_ADDR_M
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8v_xx
|
2023-10-04 20:32:13 +00:00
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
ply ; xbits
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8s_plot.p8v_maskbits,y
|
2023-10-04 20:32:13 +00:00
|
|
|
and cx16.VERA_DATA0
|
|
|
|
beq +
|
|
|
|
lda #1
|
|
|
|
+ rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2024-11-29 19:57:40 +00:00
|
|
|
sub fill(uword x, uword y, bool draw, ubyte stack_rambank) {
|
2023-10-04 20:32:13 +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-04 12:51:18 +00:00
|
|
|
word @zp xx = x as word
|
|
|
|
word @zp yy = y as word
|
2023-10-04 20:32:13 +00:00
|
|
|
word x1
|
|
|
|
word x2
|
|
|
|
byte dy
|
2024-11-29 19:57:40 +00:00
|
|
|
stack.init(stack_rambank)
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.r10L = draw as ubyte
|
|
|
|
sub push_stack(word sxl, word sxr, word sy, byte sdy) {
|
|
|
|
cx16.r0s = sy+sdy
|
|
|
|
if cx16.r0s>=0 and cx16.r0s<=height-1 {
|
2024-11-29 19:57:40 +00:00
|
|
|
stack.pushw(sxl as uword)
|
|
|
|
stack.pushw(sxr as uword)
|
|
|
|
stack.pushw(sy as uword)
|
|
|
|
stack.push(sdy as ubyte)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sub pop_stack() {
|
2024-11-29 19:57:40 +00:00
|
|
|
dy = stack.pop() as byte
|
|
|
|
yy = stack.popw() as word
|
|
|
|
x2 = stack.popw() as word
|
|
|
|
x1 = stack.popw() as word
|
2023-10-04 20:32:13 +00:00
|
|
|
yy+=dy
|
|
|
|
}
|
2024-02-27 23:34:35 +00:00
|
|
|
cx16.r11L = pget(xx as uword, yy as uword) as ubyte ; old_color
|
2023-10-04 20:32:13 +00:00
|
|
|
if cx16.r11L == cx16.r10L
|
|
|
|
return
|
|
|
|
if xx<0 or xx>width-1 or yy<0 or yy>height-1
|
|
|
|
return
|
|
|
|
push_stack(xx, xx, yy, 1)
|
|
|
|
push_stack(xx, xx, yy + 1, -1)
|
|
|
|
word left = 0
|
2024-11-29 19:57:40 +00:00
|
|
|
while not stack.isempty() {
|
2023-10-04 20:32:13 +00:00
|
|
|
pop_stack()
|
|
|
|
xx = x1
|
2024-08-23 17:00:12 +00:00
|
|
|
if fill_scanline_left() goto skip
|
2023-10-04 20:32:13 +00:00
|
|
|
left = xx + 1
|
|
|
|
if left < x1
|
|
|
|
push_stack(left, x1 - 1, yy, -dy)
|
|
|
|
xx = x1 + 1
|
|
|
|
|
|
|
|
do {
|
2024-08-23 17:00:12 +00:00
|
|
|
fill_scanline_right()
|
2023-10-04 20:32:13 +00:00
|
|
|
push_stack(left, xx - 1, yy, dy)
|
|
|
|
if xx > x2 + 1
|
|
|
|
push_stack(x2 + 1, xx - 1, yy, -dy)
|
|
|
|
skip:
|
|
|
|
xx++
|
2023-11-04 12:51:18 +00:00
|
|
|
while xx <= x2 {
|
2024-02-27 23:34:35 +00:00
|
|
|
if pget(xx as uword, yy as uword) as ubyte == cx16.r11L
|
2023-11-04 12:51:18 +00:00
|
|
|
break
|
2023-10-04 20:32:13 +00:00
|
|
|
xx++
|
2023-11-04 12:51:18 +00:00
|
|
|
}
|
2023-10-04 20:32:13 +00:00
|
|
|
left = xx
|
|
|
|
} until xx>x2
|
|
|
|
}
|
2024-08-23 17:00:12 +00:00
|
|
|
|
|
|
|
sub fill_scanline_left() -> bool {
|
2024-12-05 02:59:39 +00:00
|
|
|
; TODO maybe this could use vera auto decrement, but that requires some clever masking calculations
|
2024-08-23 17:00:12 +00:00
|
|
|
cx16.r9s = xx
|
|
|
|
while xx >= 0 {
|
|
|
|
if pgetset()
|
|
|
|
break
|
|
|
|
xx--
|
|
|
|
}
|
|
|
|
return xx==cx16.r9s
|
|
|
|
}
|
|
|
|
|
|
|
|
sub fill_scanline_right() {
|
2024-12-05 02:59:39 +00:00
|
|
|
; TODO maybe this could use vera auto increment, but that requires some clever masking calculations
|
2024-08-23 17:00:12 +00:00
|
|
|
cx16.r9s = xx
|
|
|
|
while xx <= width-1 {
|
|
|
|
if pgetset()
|
|
|
|
break
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub pgetset() -> bool {
|
|
|
|
; test and optionally set a pixel
|
|
|
|
word @zp xpos = xx
|
|
|
|
%asm {{
|
|
|
|
lda p8v_xpos
|
|
|
|
and #7
|
|
|
|
pha ; xbits
|
|
|
|
}}
|
|
|
|
xpos /= 8
|
|
|
|
if width==320
|
|
|
|
xpos += yy*(320/8) as uword
|
|
|
|
else
|
|
|
|
xpos += yy*(640/8) as uword
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
stz cx16.VERA_CTRL
|
|
|
|
stz cx16.VERA_ADDR_H
|
|
|
|
lda p8v_xpos+1
|
|
|
|
sta cx16.VERA_ADDR_M
|
|
|
|
lda p8v_xpos
|
|
|
|
sta cx16.VERA_ADDR_L
|
|
|
|
ply ; xbits
|
|
|
|
lda p8s_plot.p8v_maskbits,y
|
|
|
|
and cx16.VERA_DATA0
|
|
|
|
beq +
|
|
|
|
lda #1
|
|
|
|
+
|
|
|
|
; cx16.r11L = seed color to check against
|
|
|
|
eor cx16.r11L
|
|
|
|
beq +
|
|
|
|
rts
|
|
|
|
+ ; cx16.r10L = new color to set
|
|
|
|
lda p8s_plot.p8v_maskbits,y
|
|
|
|
ldx cx16.r10L
|
|
|
|
beq +
|
|
|
|
tsb cx16.VERA_DATA0
|
|
|
|
bra ++
|
|
|
|
+ trb cx16.VERA_DATA0
|
|
|
|
+ lda #0
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub position(uword @zp xx, uword yy) {
|
|
|
|
if width==320
|
|
|
|
cx16.r0 = yy*(320/8)
|
|
|
|
else
|
|
|
|
cx16.r0 = yy*(640/8)
|
2023-10-04 21:01:00 +00:00
|
|
|
cx16.vaddr(0, cx16.r0+(xx/8), 0, 1)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub position2(uword @zp xx, uword yy, bool also_port_1) {
|
|
|
|
position(xx, yy)
|
|
|
|
if also_port_1
|
|
|
|
cx16.vaddr_clone(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
const ubyte charset_bank = $1
|
|
|
|
const uword charset_addr = $f000 ; in bank 1, so $1f000
|
|
|
|
|
|
|
|
sub text_charset(ubyte charset) {
|
|
|
|
; -- select the text charset to use with the text() routine
|
|
|
|
; 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)
|
|
|
|
}
|
|
|
|
|
2024-03-05 21:38:34 +00:00
|
|
|
sub text(uword @zp xx, uword yy, bool draw, str sctextptr) {
|
2023-10-04 20:32:13 +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.
|
|
|
|
uword chardataptr
|
|
|
|
ubyte[8] @shared char_bitmap_bytes_left
|
|
|
|
ubyte[8] @shared char_bitmap_bytes_right
|
|
|
|
|
|
|
|
cx16.r3 = sctextptr
|
2024-03-05 21:38:34 +00:00
|
|
|
%asm {{
|
|
|
|
lda p8v_mode
|
|
|
|
cmp #p8c_MODE_INVERT
|
|
|
|
beq +
|
|
|
|
lda #$0d ; ORA abs modifying code
|
|
|
|
bne ++
|
|
|
|
+ lda #$4d ; EOR abs modifying code
|
|
|
|
+ sta cdraw_mod1
|
|
|
|
sta cdraw_mod2
|
|
|
|
}}
|
|
|
|
|
2024-02-04 22:22:43 +00:00
|
|
|
while @(cx16.r3)!=0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
chardataptr = charset_addr + @(cx16.r3) * $0008
|
|
|
|
; copy the character bitmap into RAM
|
|
|
|
cx16.vaddr_autoincr(charset_bank, chardataptr, 0, 1)
|
|
|
|
%asm {{
|
|
|
|
; pre-shift the bits
|
2023-12-29 21:21:44 +00:00
|
|
|
lda p8s_text.p8v_xx
|
2023-10-04 20:32:13 +00:00
|
|
|
and #7
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
ldy #0
|
|
|
|
- lda cx16.VERA_DATA0
|
|
|
|
stz P8ZP_SCRATCH_REG
|
|
|
|
ldx P8ZP_SCRATCH_B1
|
|
|
|
cpx #0
|
|
|
|
beq +
|
|
|
|
- lsr a
|
|
|
|
ror P8ZP_SCRATCH_REG
|
|
|
|
dex
|
|
|
|
bne -
|
2023-12-29 21:21:44 +00:00
|
|
|
+ sta p8v_char_bitmap_bytes_left,y
|
2023-10-04 20:32:13 +00:00
|
|
|
lda P8ZP_SCRATCH_REG
|
2023-12-29 21:21:44 +00:00
|
|
|
sta p8v_char_bitmap_bytes_right,y
|
2023-10-04 20:32:13 +00:00
|
|
|
iny
|
|
|
|
cpy #8
|
|
|
|
bne --
|
|
|
|
}}
|
|
|
|
; left part of shifted char
|
|
|
|
position2(xx, yy, true)
|
|
|
|
set_autoincrs()
|
|
|
|
if draw {
|
|
|
|
%asm {{
|
|
|
|
ldy #0
|
2023-12-29 21:21:44 +00:00
|
|
|
- lda p8v_char_bitmap_bytes_left,y
|
2024-03-05 21:38:34 +00:00
|
|
|
cdraw_mod1 ora cx16.VERA_DATA1
|
2023-10-04 20:32:13 +00:00
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
iny
|
|
|
|
cpy #8
|
|
|
|
bne -
|
|
|
|
}}
|
|
|
|
} else {
|
|
|
|
%asm {{
|
|
|
|
ldy #0
|
2023-12-29 21:21:44 +00:00
|
|
|
- lda p8v_char_bitmap_bytes_left,y
|
2023-10-04 20:32:13 +00:00
|
|
|
eor #255
|
|
|
|
and cx16.VERA_DATA1
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
iny
|
|
|
|
cpy #8
|
|
|
|
bne -
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
; right part of shifted char
|
2024-02-04 22:22:43 +00:00
|
|
|
if lsb(xx) & 7 !=0 {
|
2023-10-04 20:32:13 +00:00
|
|
|
position2(xx+8, yy, true)
|
|
|
|
set_autoincrs()
|
|
|
|
if draw {
|
|
|
|
%asm {{
|
|
|
|
ldy #0
|
2023-12-29 21:21:44 +00:00
|
|
|
- lda p8v_char_bitmap_bytes_right,y
|
2024-03-05 21:38:34 +00:00
|
|
|
cdraw_mod2 ora cx16.VERA_DATA1
|
2023-10-04 20:32:13 +00:00
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
iny
|
|
|
|
cpy #8
|
|
|
|
bne -
|
|
|
|
}}
|
|
|
|
} else {
|
|
|
|
%asm {{
|
|
|
|
ldy #0
|
2023-12-29 21:21:44 +00:00
|
|
|
- lda p8v_char_bitmap_bytes_right,y
|
2023-10-04 20:32:13 +00:00
|
|
|
eor #255
|
|
|
|
and cx16.VERA_DATA1
|
|
|
|
sta cx16.VERA_DATA0
|
|
|
|
iny
|
|
|
|
cpy #8
|
|
|
|
bne -
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cx16.r3++
|
|
|
|
xx += 8
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_autoincrs() {
|
|
|
|
; set autoincrements to go to next pixel row (40 or 80 increment)
|
|
|
|
if width==320 {
|
|
|
|
cx16.VERA_CTRL = 1
|
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & $0f | (11<<4)
|
|
|
|
cx16.VERA_CTRL = 0
|
2024-07-02 21:36:36 +00:00
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & $0f | (11<<4)
|
|
|
|
} else {
|
2023-10-04 20:32:13 +00:00
|
|
|
cx16.VERA_CTRL = 1
|
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & $0f | (12<<4)
|
2024-07-02 21:36:36 +00:00
|
|
|
cx16.VERA_CTRL = 0
|
|
|
|
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & $0f | (12<<4)
|
2023-10-04 20:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-17 19:01:01 +00:00
|
|
|
asmsub cs_innerloop640(bool draw @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.
|
2023-10-04 20:32:13 +00:00
|
|
|
%asm {{
|
2023-10-05 19:00:39 +00:00
|
|
|
cmp #0
|
|
|
|
beq +
|
|
|
|
lda #255
|
|
|
|
+ ldy #80
|
|
|
|
- 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
|
2023-10-04 20:32:13 +00:00
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|