duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit eba4bd8efdde8a6310e24ed2160e2e1836623977
parent 6fcd3551b997e331c8adad8de3b8371e377dbbb0
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Thu, 15 Dec 2022 09:31:58 -0500

emul/uxn/screen: implement fg/bg logic for pixels

Diffstat:
Mfs/emul/uxn/screen.fs | 28+++++++++++++++++++++++++---
Mfs/tests/manual/uxn/rect.tal | 28+++++++++++++++++++++-------
2 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/fs/emul/uxn/screen.fs b/fs/emul/uxn/screen.fs @@ -1,7 +1,23 @@ \ Varvara screen implementation require /sys/draw.fs +?f<< /lib/bit.fs ?f<< /emul/uxn/varvara.fs +\ FG Mask: to properly handle FG/BG logic, we need to know which pixels are +\ "filled" on the FG layer, that is, have a non-zero color. When it is, a draw +\ operation on the BG layer will have no effect. +\ Let's say, for now, that maximum supported resolution is 1024x768 +1024 768 * 8 / const FGMASKSZ +create _fgmask FGMASKSZ allot + +: _fg' ( x y -- bit a ) + scrwidth * + 8 /mod ( bit a ) _fgmask + ; +: _fg! ( x y id -- ) + >r _fg' dup c@ ( bit a n ) + rot r> if bit1! else bit0! then ( a n ) + swap c! ; +: _fg? ( x y -- f ) _fg' c@ swap bit? ; + \ example: $5678 for "r" means ID0=5 ID1=6 ID2=7 ID3=8 : _extract ( systemrgb id -- rgb8 ) 3 -^ << << rshift $f and ( rgb4 ) 4 lshift ; @@ -11,17 +27,23 @@ require /sys/draw.fs dup short@ r@ _extract ( 'r r8 ) swap 1+ 1+ dup short@ r@ _extract ( r8 'g g8 ) swap 1+ 1+ short@ r> _extract ( r8 g8 b8 ) rgbcolor ; +: _drawpixel ( x y pixel -- ) + 3 and screencolor ( x y color ) + rot> pixel' pixel! ; : screendei ( dev port -- c ) 2drop 0 ; : screendeo ( dev port -- ) case ( dev ) \ V1=case $e of = >r \ V2=dev - $8 r@ devshort@ ( x ) $a r@ devshort@ ( x y ) pixel' ( a ) - $e r> Device dat + c@ 3 and screencolor ( a color ) - swap pixel! + $8 r@ devshort@ ( x ) $a r@ devshort@ ( x y ) + $e r> Device dat + c@ ( x y pixel ) + dup $40 and if \ fg + >r 2dup r@ _fg! r> _drawpixel + else >r 2dup _fg? if 2drop rdrop else r> _drawpixel then then endof drop endcase ; : screen_init + _fgmask FGMASKSZ 0 fill $2 ['] screendei ['] screendeo uxn_set_dev $112 vesamode! ; diff --git a/fs/tests/manual/uxn/rect.tal b/fs/tests/manual/uxn/rect.tal @@ -4,20 +4,34 @@ %WIDTH { #42 } %HEIGHT { #54 } +|0000 ( zero-page ) + +@maxx $1 +@maxy $1 +@pixel $1 + |0100 ( -> ) ( theme ) #0f0f .System/r DEO2 #0ff0 .System/g DEO2 #00ff .System/b DEO2 - #00 ( y ) + #00 #00 #42 ;draw-rect JSR2 + WIDTH #01 SFT HEIGHT #01 SFT #01 ;draw-rect JSR2 + BRK + +@draw-rect ( x y pixel -- ) + + .pixel STZ + DUP HEIGHT ADD .maxy STZ ( xbase y ) + OVR WIDTH ADD .maxx STZ ( xbase y ) &loopy #00 OVR .Screen/y DEO2 INC - #00 ( y x ) + OVR ( xbase y x ) &loopx #00 OVR .Screen/x DEO2 INC - #41 .Screen/pixel DEO - DUP WIDTH LTH ,&loopx JCN - POP DUP HEIGHT LTH ,&loopy JCN - POP - BRK + .pixel LDZ .Screen/pixel DEO + DUP .maxx LDZ LTH ,&loopx JCN ( xbase y x ) + POP DUP .maxy LDZ LTH ,&loopy JCN ( xbase y ) + POP2 +JMP2r