monogfx and gfx2: flood fill uses optimized horizontal line drawing

This commit is contained in:
Irmen de Jong 2023-10-15 22:44:34 +02:00
parent daca87c6d0
commit 1fb94e7a7b
4 changed files with 59 additions and 60 deletions

View File

@ -17,7 +17,7 @@
; mode 2 = bitmap 640 x 480 x 4c (2 bpp. there's not enough vram for more colors in hires mode.)
; mode 3 = bitmap 320 x 240 x 16c (not yet implemented: just use 256c, there's enough vram for that)
; mode 4 = bitmap 320 x 240 x 4c (not yet implemented: just use 256c, there's enough vram for that)
; higher color dephts in highres are not supported due to lack of VRAM
; higher color depths in highres are not supported due to lack of VRAM
gfx2 {
@ -481,11 +481,20 @@ gfx2 {
lda cx16.r0L
sta cx16.VERA_ADDR_L
lda cx16.VERA_DATA0
sta cx16.r0L
pha
lda xx
and #3
tay
lda gfx2.plot.shift4c,y
tay
pla
cpy #0
beq +
- lsr a
dey
bne -
+ and #3
}}
cx16.r1L = lsb(xx) & 3
cx16.r0L >>= gfx2.plot.shift4c[cx16.r1L]
return cx16.r0L & 3
}
else -> return 0
}
@ -574,10 +583,12 @@ gfx2 {
while cx16.r12L {
pop_stack()
xx = x1
while xx >= 0 and pget(xx as uword, yy as uword) == cx16.r11L {
plot(xx as uword, yy as uword, cx16.r10L) ; TODO use vera auto decrement
cx16.r9 = xx
while xx >= 0 and pget(xx as uword, yy as uword) == cx16.r11L
xx--
}
if cx16.r9!=xx
horizontal_line(xx as uword+1, yy as uword, cx16.r9-(xx as uword), cx16.r10L)
if xx >= x1
goto skip
@ -587,10 +598,12 @@ gfx2 {
xx = x1 + 1
do {
while xx <= width-1 and pget(xx as uword, yy as uword) == cx16.r11L {
plot(xx as uword, yy as uword, cx16.r10L) ; TODO use vera auto increment
cx16.r9 = xx
while xx <= width-1 and pget(xx as uword, yy as uword) == cx16.r11L
xx++
}
if cx16.r9!=xx
horizontal_line(cx16.r9, yy as uword, (xx as uword)-cx16.r9, cx16.r10L)
push_stack(left, xx - 1, yy, dy)
if xx > x2 + 1
push_stack(x2 + 1, xx - 1, yy, -dy)

View File

@ -608,10 +608,13 @@ _done
while cx16.r12L {
pop_stack()
xx = x1
while xx >= 0 and pget(xx as uword, yy as uword) == cx16.r11L {
plot(xx as uword, yy as uword, cx16.r10L)
cx16.r9 = xx
while xx >= 0 and pget(xx as uword, yy as uword) == cx16.r11L
xx--
}
if cx16.r9!=xx
horizontal_line(xx as uword+1, yy as uword, cx16.r9-(xx as uword), cx16.r10L)
if xx >= x1
goto skip
@ -621,10 +624,12 @@ _done
xx = x1 + 1
do {
while xx <= width-1 and pget(xx as uword, yy as uword) == cx16.r11L {
plot(xx as uword, yy as uword, cx16.r10L)
cx16.r9 = xx
while xx <= width-1 and pget(xx as uword, yy as uword) == cx16.r11L
xx++
}
if cx16.r9!=xx
horizontal_line(cx16.r9, yy as uword, (xx as uword)-cx16.r9, cx16.r10L)
push_stack(left, xx - 1, yy, dy)
if xx > x2 + 1
push_stack(x2 + 1, xx - 1, yy, -dy)

View File

@ -1,8 +1,11 @@
TODO
====
- gfx2: use vera auto in/decrement in the flood fill routine
- add an option to inject an actual instruction (STP on 65c02, BRK on 6502) for breakpoints, instead of only listing them in the vice symbol file.
- codegen for cx16.r2L >>= gfx2.plot.shift4c[cx16.r1L] is wrong (gfx2.p8 older version fill hires 4c)
- why does cx16.r1L = lsb(xx) & 3 generate 5 asm instructions? (noopt)
- optimize asm: sta VAR / <something with A> / sta VAR
- gfx2/monogfx: use vera auto in/decrement in the flood fill routine (getpixels)
- gfx2: use vera fx fill for horizontal_line of sufficient length?
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
- [on branch: ir-less-branch-opcodes] IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction

View File

@ -1,49 +1,27 @@
%import gfx2
%import textio
%import math
%option no_sysinit
%zeropage basicsafe
main {
sub start() {
ubyte[] b_array = [11,22,33,44]
uword[] w_array = [1111,2222,3333,4444]
uword[] @split split_array = [1111,2222,3333,4444]
ubyte index = 2
uword value = 9999
w_array[index] = value
split_array[index] = value
uword pstep = w_array[index]
uword psteps = split_array[index]
txt.print_uw(pstep)
txt.nl()
txt.print_uw(psteps)
txt.nl()
uword @zp ptr = &w_array[index]
txt.print_uw(peekw(ptr))
txt.nl()
txt.print_uwhex(&w_array, true)
txt.spc()
txt.print_uwhex(ptr, true)
txt.nl()
%breakpoint
ptr = &split_array
txt.print_uw(peekw(ptr))
txt.nl()
txt.print_uwhex(&w_array, true)
txt.spc()
txt.print_uwhex(ptr, true)
txt.nl()
ptr = &b_array[index]
txt.print_ub(peek(ptr))
txt.nl()
txt.print_uwhex(&b_array, true)
txt.spc()
txt.print_uwhex(ptr, true)
txt.nl()
gfx2.screen_mode(2)
demofill()
repeat {
}
}
sub demofill() {
gfx2.circle(160, 120, 110, 1)
gfx2.rect(180, 5, 25, 190, 1)
gfx2.line(100, 150, 240, 10, 1)
gfx2.line(101, 150, 241, 10, 1)
gfx2.fill(100,100,2)
gfx2.fill(182,140,3)
gfx2.fill(182,40,1)
}
}