diff --git a/compiler/res/prog8lib/cx16/monogfx.p8 b/compiler/res/prog8lib/cx16/monogfx.p8 index 52d675e90..c49639cbc 100644 --- a/compiler/res/prog8lib/cx16/monogfx.p8 +++ b/compiler/res/prog8lib/cx16/monogfx.p8 @@ -819,31 +819,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) @@ -857,6 +840,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) { diff --git a/examples/test.p8 b/examples/test.p8 index 10a85aec4..9ffd45632 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,37 +1,39 @@ -%import palette +%import monogfx %import textio +%import math + %option no_sysinit +%zeropage basicsafe + main { + sub start() { - repeat 4 { - for cx16.r0L in 0 to 15 { - txt.color2(cx16.r0L, cx16.r0L) - txt.spc() - txt.spc() - txt.spc() - txt.spc() - } - txt.nl() - } - bool changed - uword[] colors = [ - $f00, $800, $200, $000, - $f0f, $80f, $20f, $00f - ] - do { - sys.waitvsync() - sys.waitvsync() - changed = palette.fade_step_colors(0, 8, colors) - } until not changed - - sys.wait(60) - changed = false - do { - sys.waitvsync() - sys.waitvsync() - changed = palette.fade_step_multi(0, 8, $fff) - } until not changed - sys.wait(60) + monogfx.lores() + demofill() + } + + 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 + } }