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 3, 2024
1 parent ad22cf0 commit d274fe9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 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
3 changes: 3 additions & 0 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
TODO
====

Optimize monogfx fill_scanline_left() and fill_scanline_right().


Improve register load order in subroutine call args assignments:
in certain situations, the "wrong" order of evaluation of function call arguments is done which results
in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!)
Expand Down
22 changes: 11 additions & 11 deletions examples/test.p8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%import gfx2
%import monogfx
%import textio
%import math

Expand All @@ -9,31 +9,31 @@
main {

sub start() {
gfx2.screen_mode(2)
monogfx.lores()
demofill()
}

sub demofill() {
gfx2.circle(160, 120, 110, 1)
gfx2.rect(180, 5, 25, 190, 2)
gfx2.line(100, 150, 240, 10, 2)
gfx2.rect(150, 130, 10, 100, 3)
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)
gfx2.fill(100,100,3)
gfx2.fill(100,100,2)
gfx2.fill(100,100,0)
monogfx.fill(100,100,true)
monogfx.fill(100,100,false)
uword duration = cbm.RDTIM16()
sys.wait(30)

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

; hires 4c before optimizations: ~345 jiffies
; before optimizations: ~166 jiffies

}
}

0 comments on commit d274fe9

Please sign in to comment.