commit be12a3ff69e1946fa3e3084b057eb6177f3466a1
parent 896237d28f2d5048ff32445bd1e535831ead5756
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Mon, 2 Jan 2023 20:47:42 -0500
gr/plane: add bounds to :pos!
to avoid writing outside the buffer.
Diffstat:
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/fs/emul/uxn/gui.fs b/fs/emul/uxn/gui.fs
@@ -29,7 +29,7 @@ create _fgmask FGMASKSZ allot
swap 1+ 1+ short@ r> _extract ( r8 g8 b8 ) r8g8b8>rgb24 ;
: _drawpixel ( x y pixel -- )
3 and screencolor to screen color ( x y )
- to screen ty to screen tx screen :pixel! ;
+ screen :pos! 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/plane.fs b/fs/gr/plane.fs
@@ -37,13 +37,17 @@ extends Rect struct[ Plane
: :pixel! ( self -- ) >r \ V1=self
r@ color r@ _addr 16b !+ r> color 16 rshift swap c! ;
- : :pos! ( x y self -- ) tuck to ty to tx ;
+ : _boundsx ( x self -- x ) width mod ;
+ : _boundsy ( y self -- y ) height mod ;
+
+ : :pos! ( x y self -- ) >r \ V1=self
+ r@ _boundsy r@ to ty r@ _boundsx r> to tx ;
: :ty+ ( n self -- ) >r \ V1=self
- r@ ty + dup r@ height >= if r@ height - then r> to ty ;
+ r@ ty + r@ _boundsy r> to ty ;
: :tx+ ( n self -- ) >r \ V1=self
- r@ tx + dup r@ width >= if r@ width - then r> to tx ;
+ r@ tx + r@ _boundsx r> to tx ;
: :fill ( width height self -- ) >r \ V1=self
>r V1 tx begin ( w x )
diff --git a/fs/tests/manual/uxn/mouse.tal b/fs/tests/manual/uxn/mouse.tal
@@ -28,7 +28,11 @@
( vectors )
;on-mouse .Mouse/vector DEO2
- ;on-frame .Screen/vector DEO2
+ ( TODO: when Dusk will have better timer capability and actually run the
+ Screen vector at about 60 frames per second, then we can enable this line
+ below. Otherwise, this "doodle replayer" goes way too fast and monopolizes
+ system ressources. )
+ ( ;on-frame .Screen/vector DEO2 )
BRK
@@ -43,6 +47,8 @@ BRK
@on-mouse ( -> )
;pointer-icn .Screen/addr DEO2
+ ( TODO: clearing the cursor erases the doodling below. It doesn't do it on
+ the regular uxnemu. )
( clear last cursor )
.pointer/x LDZ2 .Screen/x DEO2
.pointer/y LDZ2 .Screen/y DEO2
@@ -116,11 +122,7 @@ BRK
JMP2r
-( TODO: fix uxn or varvara or something. When this is executed, the computer
- spins into a loop that sends it crashing. I tried replacing .Screen/pixel
- below with a dummy .Mouse/pad, but clicking still crashes the machine. I'm
- thinking that the bug might be in uxn rather than varvara... )
-@draw-line ( x1* y1* x2* y2* color -- ) POP POP2 POP2 POP2 POP2 JMP2r
+@draw-line ( x1* y1* x2* y2* color -- )
( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
,&x LDR2 .line/x LDZ2 SUB2 ;abs2 JSR2 .line/dx STZ2