Minor optimizations to noodle

This commit is contained in:
neauoire 2021-03-24 20:00:34 -07:00
parent b345ec7b84
commit 11a299778a
1 changed files with 79 additions and 84 deletions

View File

@ -6,20 +6,15 @@
arrows - move zoom
space - toogle zoom
backspace - blank canvas
m - toggle mirror mode
1-8 - select brush size
TODO
- Only draw-canvas when mouse has changed
- Only draw-canvas target tile
- Resize buttons
- Limit size
- Pixel cleanup brush
- Drag canvas content
- [tool] fill rect
- [tool] spray
- [tool] pen
- [tool] line
BUGS
- Zoom drawing with other tools
)
%RTN { JMP2r }
@ -35,18 +30,23 @@
( variables )
;cursor { x 2 y 2 x0 2 y0 2 dx 2 dy 2 }
;brush { tool 1 size 1 patt 1 drag 1 last 1 oper 2 }
;zoom { active 1 x 2 y 2 }
;center { x 2 y 2 }
( interface )
;toolpane { x1 2 y1 2 x2 2 y2 2 }
;pattpane { x1 2 y1 2 x2 2 y2 2 }
;sizepane { x1 2 y1 2 x2 2 y2 2 }
;cursor { x 2 y 2 x0 2 y0 2 dx 2 dy 2 tool 1 size 1 patt 1 drag 1 last 1 mirror 1 oper 2 }
;zoom { active 1 x 2 y 2 }
;canvas { x1 2 y1 2 x2 2 y2 2 w 2 h 2 }
;rect { x1 2 y1 2 x2 2 y2 2 }
;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
;origin { x1 2 y1 2 x2 2 y2 2 }
;color { byte 1 }
;pt0 { x 2 y 2 }
;pt1 { x 2 y 2 }
;pt2 { x 2 y 2 } ( paint-rect )
;px { x 1 y 1 }
( devices )
@ -59,7 +59,7 @@
|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|01F0 .RESET .FRAME .ERROR ( vectors )
|01F8 [ f07c f0e2 f0c2 ] ( palette )
|01F8 [ c0ef c07f c05f ] ( palette )
( program )
@ -69,9 +69,9 @@
#002a =canvas.w #001a =canvas.h
( default brush )
#04 =cursor.size
#00 =cursor.patt
#00 =cursor.tool
#04 =brush.size
#00 =brush.patt
#00 =brush.tool
( load file )
,filepath ,load-file JSR2
@ -111,7 +111,7 @@ BRK
,draw-cursor JSR2
( release drag )
,$no-release ~Mouse.state #00 EQU ~cursor.drag #01 EQU #0101 NEQ2 JMP2?
,$no-release ~Mouse.state #00 EQU ~brush.drag #01 EQU #0101 NEQ2 JMP2?
~origin.x1 #0002 SUB2 ~origin.y1 #0002 SUB2 ~origin.x2 #0002 ADD2 ~origin.y2 #0002 ADD2 #00 ,fill-rect JSR2
~canvas.x1 -- ~canvas.y1 -- ~canvas.x2 ~canvas.y2 #10 ,line-rect JSR2
,draw-background JSR2
@ -119,11 +119,11 @@ BRK
,draw-toolpane JSR2
,draw-pattpane JSR2
,draw-sizepane JSR2
#00 =cursor.drag
#00 =brush.drag
$no-release
( operations on release line/rect )
,$no-touch-change ~Mouse.state ~cursor.last EQU JMP2?
,$no-touch-change ~Mouse.state ~brush.last EQU JMP2?
,$no-touch-change ~Mouse.x CLN2r ~canvas.x1 GTS2 STH2r ~canvas.x2 LTS2 #0101 NEQ2 JMP2?
,$no-touch-change ~Mouse.y CLN2r ~canvas.y1 GTS2 STH2r ~canvas.y2 LTS2 #0101 NEQ2 JMP2?
,$no-touch-ondown ~Mouse.state #00 EQU JMP2?
@ -133,12 +133,12 @@ BRK
$no-touch-ondown
,$no-touch-onup ~Mouse.state #00 NEQ JMP2?
( on up )
,$no-touch-line ~cursor.tool #02 NEQ JMP2?
~cursor.dx ~canvas.x1 SUB2 ~cursor.dy ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 #01 ,paint-line JSR2
,$no-touch-line ~brush.tool #02 NEQ JMP2?
~cursor.dx ~canvas.x1 SUB2 ~cursor.dy ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint-line JSR2
,$touch-end JMP2
$no-touch-line
,$no-touch-rect ~cursor.tool #03 NEQ JMP2?
~cursor.dx ~canvas.x1 SUB2 ~cursor.dy ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 #01 ,paint-rect JSR2
,$no-touch-rect ~brush.tool #03 NEQ JMP2?
~cursor.dx ~canvas.x1 SUB2 ~cursor.dy ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint-rect JSR2
,$touch-end JMP2
$no-touch-rect
$no-touch-onup
@ -148,7 +148,7 @@ BRK
( drag )
,$no-drag ~Controller #02 NEQ JMP2?
,$no-drag-start ~cursor.drag #00 NEQ JMP2?
,$no-drag-start ~brush.drag #00 NEQ JMP2?
~canvas.x1 =origin.x1
~canvas.y1 =origin.y1
~canvas.x2 =origin.x2
@ -160,7 +160,7 @@ BRK
~canvas.w 8* ~canvas.x1 ADD2 =canvas.x2
~canvas.h 8* ~canvas.y1 ADD2 =canvas.y2
~canvas.x1 -- ~canvas.y1 -- ~canvas.x2 ~canvas.y2 #13 ,line-rect JSR2
#01 =cursor.drag
#01 =brush.drag
,$touch-end JMP2
$no-drag
@ -168,8 +168,8 @@ BRK
,$no-touch-sizepane ~Mouse.x CLN2r ~sizepane.x1 GTH2 STH2r ~sizepane.x2 LTH2 #0101 NEQ2 JMP2?
,$no-touch-sizepane ~Mouse.y CLN2r ~sizepane.y1 GTH2 STH2r ~sizepane.y2 LTH2 #0101 NEQ2 JMP2?
( release ) #00 =Mouse.state
#01 =cursor.tool
~Mouse.x ~sizepane.x1 SUB2 8/ SWP POP =cursor.size
#01 =brush.tool
~Mouse.x ~sizepane.x1 SUB2 8/ SWP POP =brush.size
( draw ) ,draw-sizepane JSR2
( draw ) ,draw-toolpane JSR2
,$touch-end JMP2
@ -179,7 +179,7 @@ BRK
,$no-touch-pattpane ~Mouse.x CLN2r ~pattpane.x1 GTH2 STH2r ~pattpane.x2 LTH2 #0101 NEQ2 JMP2?
,$no-touch-pattpane ~Mouse.y CLN2r ~pattpane.y1 GTH2 STH2r ~pattpane.y2 LTH2 #0101 NEQ2 JMP2?
( release ) #00 =Mouse.state
~Mouse.x ~pattpane.x1 SUB2 8/ SWP POP =cursor.patt
~Mouse.x ~pattpane.x1 SUB2 8/ SWP POP =brush.patt
( draw ) ,draw-pattpane JSR2
,$touch-end JMP2
$no-touch-pattpane
@ -188,7 +188,7 @@ BRK
,$no-touch-toolpane ~Mouse.x CLN2r ~toolpane.x1 GTH2 STH2r ~toolpane.x2 LTH2 #0101 NEQ2 JMP2?
,$no-touch-toolpane ~Mouse.y CLN2r ~toolpane.y1 GTH2 STH2r ~toolpane.y2 LTH2 #0101 NEQ2 JMP2?
( release ) #00 =Mouse.state
~Mouse.x ~toolpane.x1 SUB2 8/ SWP POP =cursor.tool
~Mouse.x ~toolpane.x1 SUB2 8/ SWP POP =brush.tool
( draw ) ,draw-toolpane JSR2
,$touch-end JMP2
$no-touch-toolpane
@ -198,14 +198,14 @@ BRK
,$no-touch-canvas ~Mouse.y CLN2r ~canvas.y1 GTS2 STH2r ~canvas.y2 LTS2 #0101 NEQ2 JMP2?
( set cursor operation )
,add-pixel ,$no-oper ~Mouse.state #01 EQU JMP2? POP2 ,remove-pixel $no-oper =cursor.oper
,add-pixel ,$no-oper ~Mouse.state #01 EQU JMP2? POP2 ,remove-pixel $no-oper =brush.oper
,$no-touch-pen ~cursor.tool #00 NEQ JMP2?
~cursor.x0 ~canvas.x1 SUB2 ~cursor.y0 ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 #01 ,paint-line JSR2
,$no-touch-pen ~brush.tool #00 NEQ JMP2?
~cursor.x0 ~canvas.x1 SUB2 ~cursor.y0 ~canvas.y1 SUB2 ~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint-line JSR2
,$touch-end JMP2
$no-touch-pen
,$no-touch-brush ~cursor.tool #01 NEQ JMP2?
,$no-touch-brush ~brush.tool #01 NEQ JMP2?
~Mouse.x ~canvas.x1 SUB2 ~Mouse.y ~canvas.y1 SUB2 ,paint-brush JSR2
,$touch-end JMP2
$no-touch-brush
@ -215,20 +215,17 @@ BRK
( background interface )
,$no-touch-background ~Mouse.y STEP8 ~Screen.height #0010 SUB2 NEQ2 JMP2?
~Mouse.x ~Screen.width #0020 SUB2 SUB2 8/
DUP2
#0000 NEQ2 ,$no-toggle-zoom ROT JMP2?
DUP2 #0000 NEQ2 ,$no-toggle-zoom ROT JMP2?
~zoom.active #00 EQU =zoom.active
( release ) #00 =Mouse.state
,redraw JSR2
$no-toggle-zoom
DUP2
#0001 NEQ2 ,$no-load-button ROT JMP2?
DUP2 #0001 NEQ2 ,$no-load-button ROT JMP2?
,filepath ,load-file JSR2
,draw-canvas JSR2
( release ) #00 =Mouse.state
$no-load-button
DUP2
#0002 NEQ2 ,$no-save-button ROT JMP2?
DUP2 #0002 NEQ2 ,$no-save-button ROT JMP2?
,filepath ,save-file JSR2
( release ) #00 =Mouse.state
$no-save-button
@ -257,19 +254,24 @@ BRK
( toggle zoom ) ~zoom.active #00 EQU =zoom.active ,redraw JSR2 $no-space
DUP #08 NEQ ,$no-backspace ROT JMP2?
( erase ) ,clear JSR2 $no-backspace
DUP #6d NEQ ,$no-mkey ROT JMP2?
( mirror ) ~cursor.mirror #00 EQU =cursor.mirror $no-mkey
DUP #71 NEQ ,$no-qkey ROT JMP2?
( tool0 ) #00 =brush.tool ,draw-toolpane JSR2 $no-qkey
DUP #77 NEQ ,$no-wkey ROT JMP2?
( tool0 ) #01 =brush.tool ,draw-toolpane JSR2 $no-wkey
DUP #65 NEQ ,$no-ekey ROT JMP2?
( tool0 ) #02 =brush.tool ,draw-toolpane JSR2 $no-ekey
DUP #72 NEQ ,$no-rkey ROT JMP2?
( tool0 ) #03 =brush.tool ,draw-toolpane JSR2 $no-rkey
DUP
DUP #30 GTH SWP #39 LTH #0101 NEQ2 ,$no-numkey ROT JMP2?
( size ) ~Keys #31 SUB =cursor.size ,draw-sizepane JSR2 $no-numkey
( size ) ~Keys #31 SUB =brush.size ,draw-sizepane JSR2 $no-numkey
POP
( release ) #00 =Keys
$no-keys
~Mouse.x =cursor.x0
~Mouse.y =cursor.y0
~Mouse.state =cursor.last
~Mouse.state =brush.last
BRK
@ -307,16 +309,16 @@ RTN
RTN
@paint-line ( x1 y1 x2 y2 color )
@paint-line ( x1 y1 x2 y2 )
( load ) =color =line.y0 =line.x0 =line.y =line.x
( load ) =line.y0 =line.x0 =line.y =line.x
~line.x0 ~line.x SUB2 ABS2 =line.dx
~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy
#ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx
#ffff #00 ~line.y ~line.y0 LTS2 #0002 MUL2 ADD2 =line.sy
~line.dx ~line.dy ADD2 =line.e1
$loop
( paint ) ~line.x ~line.y ~cursor.oper JSR2
( paint ) ~line.x ~line.y ~brush.oper JSR2
,$end ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 JMP2?
~line.e1 #0002 MUL2 =line.e2
,$skipy ~line.e2 ~line.dy LTS2 JMP2?
@ -338,22 +340,20 @@ RTN
RTN
;rpt { x 2 y 2 }
@paint-rect ( x1 y1 x2 y2 )
@paint-rect ( x1 y1 x2 y2 color )
( load ) =color =rect.y2 =rect.x2 DUP2 =rpt.y =rect.y1 DUP2 =rpt.x =rect.x1
( load ) =rect.y2 =rect.x2 DUP2 =pt2.y =rect.y1 DUP2 =pt2.x =rect.x1
$ver
~rect.x1 =rpt.x
~rect.x1 =pt2.x
$hor
~rpt.x SWP POP =px.x ~rpt.y SWP POP =px.y
~pt2.x SWP POP =px.x ~pt2.y SWP POP =px.y
,$no-pixel ,patternize JSR2 #00 EQU JMP2?
( draw ) ~rpt.x ~rpt.y ~cursor.oper JSR2
( draw ) ~pt2.x ~pt2.y ~brush.oper JSR2
$no-pixel
( incr ) ~rpt.x ++ =rpt.x
,$hor ~rpt.x ~rect.x2 LTH2 JMP2?
~rpt.y ++ =rpt.y
,$ver ~rpt.y ~rect.y2 LTH2 JMP2?
( incr ) ~pt2.x ++ =pt2.x
,$hor ~pt2.x ~rect.x2 LTH2 JMP2?
~pt2.y ++ =pt2.y
,$ver ~pt2.y ~rect.y2 LTH2 JMP2?
,draw-canvas JSR2
,draw-toolpane JSR2
@ -382,11 +382,11 @@ RTN
$ver
#00 =px.x
$hor
( addr ) ,size_icn #00 ~cursor.size 8* ADD2
( addr ) ,size_icn #00 ~brush.size 8* ADD2
( byte ) #00 ~px.y ADD2 PEK2 #07 ~px.x SUB SFT #01 AND
#00 EQU ,$no-pixel ROT JMP2?
,$no-pixel ,patternize JSR2 #00 EQU JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ~cursor.oper JSR2
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ~brush.oper JSR2
$no-pixel
( incr ) ~px.x #01 ADD =px.x
,$hor ~px.x #08 LTH JMP2?
@ -402,46 +402,44 @@ RTN
@patternize
,$noplain ~cursor.patt #00 NEQ JMP2?
,$noplain ~brush.patt #00 NEQ JMP2?
#01 RTN
$noplain
,$notone1 ~cursor.patt #01 NEQ JMP2?
,$notone1 ~brush.patt #01 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0001 AND2 #0000 EQU2
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0001 AND2 #0000 EQU2
#0101 EQU2
RTN
$notone1
,$notone2 ~cursor.patt #02 NEQ JMP2?
,$notone2 ~brush.patt #02 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0003 AND2 #0000 EQU2
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0003 AND2 #0000 EQU2
#0101 EQU2
RTN
$notone2
,$notone3 ~cursor.patt #03 NEQ JMP2?
,$notone3 ~brush.patt #03 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0005 AND2 #0000 EQU2
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0005 AND2 #0000 EQU2
#0101 EQU2
RTN
$notone3
,$notone4 ~cursor.patt #04 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0003 AND2 #0000 EQU2
RTN
,$notone4 ~brush.patt #04 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0003 AND2 #0000 EQU2 RTN
$notone4
,$notone5 ~cursor.patt #05 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0003 AND2 #0000 EQU2
RTN
,$notone5 ~brush.patt #05 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0003 AND2 #0000 EQU2 RTN
$notone5
,$notone6 ~cursor.patt #06 NEQ JMP2?
,$notone6 ~brush.patt #06 NEQ JMP2?
~pt0.x #00 ~px.x ADD2 #0001 AND2 SWP POP RTN
$notone6
,$notone7 ~cursor.patt #07 NEQ JMP2?
,$notone7 ~brush.patt #07 NEQ JMP2?
~pt0.y #00 ~px.y ADD2 #0001 AND2 SWP POP RTN
$notone7
@ -449,7 +447,7 @@ RTN
RTN
@get-pixel ( x y )
@get-pixel ( x y -- b )
SWP POP #07 AND =px.y
SWP POP #07 AND =px.x
@ -555,19 +553,18 @@ RTN
~Mouse.y =cursor.y
( draw size cursor )
,$outside-canvas ~cursor.tool #01 NEQ JMP2?
,$outside-canvas ~brush.tool #01 NEQ JMP2?
,$outside-canvas ~Mouse.x CLN2r ~canvas.x1 GTH2 STH2r ~canvas.x2 LTH2 #0101 NEQ2 JMP2?
,$outside-canvas ~Mouse.y CLN2r ~canvas.y1 GTH2 STH2r ~canvas.y2 LTH2 #0101 NEQ2 JMP2?
( do not draw size in toolpane )
,$outside-canvas
~Mouse.x CLN2r ~toolpane.x1 GTH2 STH2r ~toolpane.x2 LTH2 #0101 EQU2
~Mouse.y CLN2r ~toolpane.y1 GTH2 STH2r ~toolpane.y2 LTH2 #0101 EQU2
#0101 EQU2 JMP2?
,$outside-canvas ~Mouse.x CLN2r ~toolpane.x1 GTH2 STH2r ~toolpane.x2 LTH2 #0101 EQU2 ~Mouse.y CLN2r ~toolpane.y1 GTH2 STH2r ~toolpane.y2 LTH2 #0101 EQU2 #0101 EQU2 JMP2?
,$outside-canvas ~Mouse.x CLN2r ~sizepane.x1 GTH2 STH2r ~sizepane.x2 LTH2 #0101 EQU2 ~Mouse.y CLN2r ~sizepane.y1 GTH2 STH2r ~sizepane.y2 LTH2 #0101 EQU2 #0101 EQU2 JMP2?
,$outside-canvas ~Mouse.x CLN2r ~pattpane.x1 GTH2 STH2r ~pattpane.x2 LTH2 #0101 EQU2 ~Mouse.y CLN2r ~pattpane.y1 GTH2 STH2r ~pattpane.y2 LTH2 #0101 EQU2 #0101 EQU2 JMP2?
( do not draw size when holding alt )
,$outside-canvas ~Controller #02 EQU JMP2?
~cursor.x #0003 SUB2 =Sprite.x
~cursor.y #0003 SUB2 =Sprite.y
,brush_view #00 ~cursor.size 8* ADD2 =Sprite.addr
,brush_view #00 ~brush.size 8* ADD2 =Sprite.addr
#11 ~Mouse.state #02 MUL ADD =Sprite.color
,$outside-canvas ~Mouse.state #00 EQU JMP2?
RTN
@ -590,7 +587,7 @@ RTN
,tool_icn =Sprite.addr
$tools
( draw ) #01 ~Sprite.x ~pattpane.x1 SUB2 8/ SWP POP ~cursor.tool EQU #02 MUL ADD =Sprite.color
( draw ) #01 ~Sprite.x ~pattpane.x1 SUB2 8/ SWP POP ~brush.tool EQU #02 MUL ADD =Sprite.color
( incr ) ~Sprite.x 8+ =Sprite.x
( incr ) ~Sprite.addr 8+ =Sprite.addr
,$tools ~Sprite.x ~toolpane.x2 LTH2 JMP2?
@ -607,7 +604,7 @@ RTN
,patt_icn =Sprite.addr
$patterns
( draw ) #01 ~Sprite.x ~pattpane.x1 SUB2 8/ SWP POP ~cursor.patt EQU #02 MUL ADD =Sprite.color
( draw ) #01 ~Sprite.x ~pattpane.x1 SUB2 8/ SWP POP ~brush.patt EQU #02 MUL ADD =Sprite.color
( incr ) ~Sprite.x 8+ =Sprite.x
( incr ) ~Sprite.addr 8+ =Sprite.addr
,$patterns ~Sprite.x ~pattpane.x2 LTH2 JMP2?
@ -624,7 +621,7 @@ RTN
,size_icn =Sprite.addr
$patterns
( draw ) #01 ~Sprite.x ~sizepane.x1 SUB2 8/ SWP POP ~cursor.size EQU #02 MUL ADD =Sprite.color
( draw ) #01 ~Sprite.x ~sizepane.x1 SUB2 8/ SWP POP ~brush.size EQU #02 MUL ADD =Sprite.color
( incr ) ~Sprite.x 8+ =Sprite.x
( incr ) ~Sprite.addr 8+ =Sprite.addr
,$patterns ~Sprite.x ~sizepane.x2 LTH2 JMP2?
@ -787,6 +784,4 @@ RTN
@ERROR BRK
;canvas { w 2 h 2 x1 2 y1 2 x2 2 y2 2 }
@data [ ]