commit bc37867cd095f942b7f204c41e2ab24d1ad48a53
parent dc9ccd8c0dd5f702edb2059b88140b36cbe659ac
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 31 Dec 2022 12:51:28 -0500
sys/screen: simplify API
The idea with :pixel! taking "a" as a parameter was to make drawing to adjacent
pixels faster, but it's overcomplicated to use this way. This optimization will
come back in another form.
Diffstat:
4 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/fs/doc/sys/screen.fs b/fs/doc/sys/screen.fs
@@ -34,8 +34,9 @@ Fields:
width Screen width
height Screen height
bpp Screen bits per plane
+color Color (from gr/color) that will be drawn
Methods:
-:pixel! ( color a self -- )
- Set a pixel at address "a" (from ":pixel'") to "color" (from gr/color).
+:pixel! ( x y self -- )
+ Set a pixel at x,y to the value of field "color".
diff --git a/fs/emul/uxn/gui.fs b/fs/emul/uxn/gui.fs
@@ -29,8 +29,7 @@ create _fgmask FGMASKSZ allot
swap 1+ 1+ dup short@ r@ _extract ( r8 'g g8 )
swap 1+ 1+ short@ r> _extract ( r8 g8 b8 ) r8g8b8>rgb24 ;
: _drawpixel ( x y pixel -- )
- 3 and screencolor ( x y color )
- rot> screen :pixel' screen :pixel! ;
+ 3 and screencolor to screen color ( x y ) screen :pixel! ;
: _drawlayer ( x y pixel fg? -- )
if >r 2dup r@ _fg! r> _drawpixel
else >r 2dup _fg? if 2drop rdrop else r> _drawpixel then then ;
diff --git a/fs/gr/draw.fs b/fs/gr/draw.fs
@@ -1,18 +1,15 @@
require /sys/screen.fs
?f<< /gr/color.fs
-\ TODO: "pixelbytes" is specific to drv/pc/vesa and is the wrong approach
-\ anyways.
-: drawrect ( color w h x y -- )
- >r >r rot> >r >r \ V1=y V2=x V3=w V4=color
- ( h ) >r begin ( )
- V2 V1 screen :pixel' ( a ) V3 >r begin ( a )
- V4 over screen :pixel! pixelbytes + next ( a ) drop
- 1 to+ V1 next
- rfree ;
+: drawrect ( w h x y -- )
+ >r >r \ V1=y V2=x
+ ( h ) >r begin ( w ) dup >r begin ( w )
+ V2 r@ + 1- V1 screen :pixel! next
+ 1 to+ V1 next ( w )
+ drop rfree ;
: recttest
- 255 0 0 r8g8b8>rgb24 ( color )
- 42 42 ( color w h )
+ 255 0 0 r8g8b8>rgb24 to screen color
+ 42 42 ( w h )
screen width >> 21 -
- screen height >> 21 - ( color w h x y ) drawrect ;
+ screen height >> 21 - ( w h x y ) drawrect ;
diff --git a/fs/sys/screen.fs b/fs/sys/screen.fs
@@ -2,17 +2,18 @@ struct[ Screen
sfield width
sfield height
sfield bpp
+ \ TODO: support more than 24bpp
+ sfield color
smethod :activate ( self -- )
smethod :deactivate ( self -- )
smethod :pixel' ( x y self -- a )
\ Creates the first part of the screen structure, but leaves the method fields
\ to the caller.
- : :newbase ( -- partial-screen ) here 0 , 0 , 0 , ;
+ : :newbase ( -- partial-screen ) here 0 , 0 , 0 , 0 , ;
- \ TODO: support more than 24bpp
- : :pixel! ( color a self -- )
- drop over >r 16b !+ r> 16 rshift swap c! ;
+ : :pixel! ( x y self -- ) >r \ V1=self
+ r@ :pixel' r@ color swap 16b !+ r> color 16 rshift swap c! ;
]struct
0 structbind Screen screen