only allow drawing on canvas

This commit is contained in:
Travis Shears 2025-06-30 10:19:18 +02:00
parent ddf4abf52e
commit 47e07b4e28

View file

@ -8,39 +8,66 @@
|58 @canvas-width
|1f @canvas-height
( zero page vars )
|00
@x $2
@y $2
(to run gui: `./run_ui.sh one_line_canvas.tal`)
(to run debugger: `../uxn/bin/uxnasm one_line_canvas.tal one_line_canvas.rom && ../uxn/bin/uxnemu ../beetbug.rom ./one_line_canvas.rom`)
%dbug { #01 .System/debug DEO }
%PX { #01 .Screen/pixel DEO }
%ADD1 { #01 ADD }
|0100
@on-reset
setup-gui
( draw canvas bounds )
.canvas-width ADD1 .canvas-width ADD1 .canvas-height ADD1 draw-h-line
.canvas-width ADD1 .canvas-width ADD1 .canvas-height ADD1 #02 MUL draw-h-line
.canvas-height ADD1 .canvas-width ADD1 .canvas-height ADD1 draw-v-line
.canvas-height ADD1 .canvas-width ADD1 #02 MUL .canvas-height ADD1 draw-v-line
( top line )
.canvas-width #01 ADD .canvas-width .canvas-height #01 SUB draw-h-line
( bot line )
.canvas-width #01 ADD .canvas-width .canvas-height #02 MUL #01 ADD draw-h-line
( left line )
.canvas-height #01 ADD .canvas-width #01 SUB .canvas-height draw-v-line
( right line )
.canvas-height #01 ADD .canvas-width #02 MUL #01 ADD .canvas-height draw-v-line
;on-mouse .Mouse/vector DEO2
BRK
@add-px-to-drawing
( figure out if px on on canvas )
( x too small )
LIT2 =canvas-width .x LDZ2 GTH2 ?/end
( x too big )
LIT2 =canvas-width #0002 MUL2 .x LDZ2 LTH2 ?/end
( y too small )
LIT2 =canvas-height .y LDZ2 GTH2 ?/end
( y too big )
LIT2 =canvas-height #0002 MUL2 .y LDZ2 LTH2 ?/end
( draw px to screen )
.x LDZ2 .Screen/x DEO2
.y LDZ2 .Screen/y DEO2
#01 .Screen/pixel DEO
&end
JMP2r
@on-mouse ( -> )
.Mouse/x DEI2
.Mouse/y DEI2
.Mouse/x DEI2 .x STZ2
.Mouse/y DEI2 .y STZ2
draw-cursor
add-px-to-drawing
BRK
@draw-cursor ( x* y* )
@draw-cursor
( clear fg )
LIT2 0000 .Screen/x DEO2
LIT2 0000 .Screen/y DEO2
#c0 .Screen/pixel DEO
( draw cursor sprite to fg )
.Screen/y DEO2 ( x* )
.Screen/x DEO2 ( )
.x LDZ2 .Screen/x DEO2
.y LDZ2 .Screen/y DEO2
;cursor-sprite .Screen/addr DEO2
#41 .Screen/sprite DEO
JMP2r
@draw-v-line ( l x y )
SWP ( l y x )