Skip to content

Commit

Permalink
preparing to optimize monogfx.fill()
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Sep 14, 2024
1 parent c7b1e8d commit b750ee9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
48 changes: 29 additions & 19 deletions compiler/res/prog8lib/cx16/monogfx.p8
Original file line number Diff line number Diff line change
Expand Up @@ -789,31 +789,14 @@ invert:
while cx16.r12L!=0 {
pop_stack()
xx = x1
while xx >= 0 {
if pget(xx as uword, yy as uword) as ubyte != cx16.r11L
break
xx--
}
if x1!=xx
horizontal_line(xx as uword+1, yy as uword, x1-xx as uword, cx16.r10L as bool)
else
goto skip

if fill_scanline_left() goto skip
left = xx + 1
if left < x1
push_stack(left, x1 - 1, yy, -dy)
xx = x1 + 1

do {
cx16.r9s = xx
while xx <= width-1 {
if pget(xx as uword, yy as uword) as ubyte != cx16.r11L
break
xx++
}
if cx16.r9s!=xx
horizontal_line(cx16.r9, yy as uword, xx-cx16.r9s as uword, cx16.r10L as bool)

fill_scanline_right()
push_stack(left, xx - 1, yy, dy)
if xx > x2 + 1
push_stack(x2 + 1, xx - 1, yy, -dy)
Expand All @@ -827,6 +810,33 @@ skip:
left = xx
} until xx>x2
}

sub fill_scanline_left() -> bool {
; TODO optimize this to use vera auto-decrements, but requires masking etc because of 8 pixels per byte...
cx16.r9s = xx
while xx >= 0 {
if pget(xx as uword, yy as uword) as ubyte != cx16.r11L
break
xx--
}
if xx!=cx16.r9s {
horizontal_line(xx+1 as uword, yy as uword, cx16.r9s-xx as uword, cx16.r10L as bool)
return false
}
return true
}

sub fill_scanline_right() {
; TODO optimize this to use vera auto-increments, but requires masking etc because of 8 pixels per byte...
cx16.r9s = xx
while xx <= width-1 {
if pget(xx as uword, yy as uword) as ubyte != cx16.r11L
break
xx++
}
if xx!=cx16.r9s
horizontal_line(cx16.r9, yy as uword, xx-cx16.r9s as uword, cx16.r10L as bool)
}
}

sub position(uword @zp xx, uword yy) {
Expand Down
4 changes: 4 additions & 0 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
TODO
====

Optimize monogfx fill_scanline_left() and fill_scanline_right().



callgraph issue? : if a sub contains another sub and it calls that, the outer sub is never removed even if it doesn't get called?
(diskio, when read4hex is placed back inside internal_f_tell() )

Expand Down
41 changes: 31 additions & 10 deletions examples/test.p8
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
%import conv
%import monogfx
%import textio
%import math

%option no_sysinit
%zeropage basicsafe


main {

sub start() {
read4hex()
monogfx.lores()
demofill()
}

sub read4hex() -> uword {
str hex = "0000"
hex[0] = cbm.CHRIN()
hex[1] = cbm.CHRIN()
hex[2] = cbm.CHRIN()
hex[3] = cbm.CHRIN()
return conv.hex2uword(hex)
}
sub demofill() {
monogfx.circle(160, 120, 110, true)
monogfx.rect(180, 5, 25, 190, true)
monogfx.line(100, 150, 240, 10, true)
monogfx.line(101, 150, 241, 10, true)
monogfx.rect(150, 130, 10, 100, true)

sys.wait(30)

cbm.SETTIM(0,0,0)
monogfx.fill(100,100,true)
monogfx.fill(100,100,false)
uword duration = cbm.RDTIM16()
sys.wait(30)

monogfx.textmode()
txt.nl()
txt.print_uw(duration)
txt.print(" jiffies\n")

; before optimizations: ~166 jiffies

}
}

0 comments on commit b750ee9

Please sign in to comment.