2022-03-27 14:53:24 -04:00
|
|
|
( Mouse:
|
|
|
|
Paint with 3 colors with each mouse button. )
|
2021-04-21 12:48:04 -04:00
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
|
|
|
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
|
|
|
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &modx $2 &mody $2
|
2021-04-21 12:48:04 -04:00
|
|
|
|
|
|
|
|0000
|
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
@line
|
|
|
|
&x $2 &y $2 &dx $2 &dy $2 &e1 $2
|
2022-07-16 14:54:16 -04:00
|
|
|
@length $2
|
|
|
|
@frame $2
|
|
|
|
@pen
|
|
|
|
&x $2 &y $2 &x2 $2 &y2 $2
|
2022-03-27 12:43:24 -04:00
|
|
|
@pointer
|
|
|
|
&x $2 &y $2 &lastx $2 &lasty $2 &state $1
|
2021-04-21 12:48:04 -04:00
|
|
|
|
|
|
|
|0100 ( -> )
|
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
( theme )
|
2022-07-16 14:54:16 -04:00
|
|
|
#4cfd .System/r DEO2
|
|
|
|
#4cf3 .System/g DEO2
|
|
|
|
#dcf2 .System/b DEO2
|
2021-04-29 00:00:39 -04:00
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
( vectors )
|
2021-04-22 23:44:38 -04:00
|
|
|
;on-mouse .Mouse/vector DEO2
|
2022-07-16 14:54:16 -04:00
|
|
|
;on-frame .Screen/vector DEO2
|
|
|
|
|
|
|
|
BRK
|
|
|
|
|
|
|
|
@on-frame ( -> )
|
|
|
|
|
|
|
|
.Mouse/state DEI ,&skip JCN
|
|
|
|
;run DUP2 JSR2 JSR2
|
|
|
|
&skip
|
2021-04-21 12:48:04 -04:00
|
|
|
|
|
|
|
BRK
|
|
|
|
|
|
|
|
@on-mouse ( -> )
|
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
;pointer-icn .Screen/addr DEO2
|
|
|
|
( clear last cursor )
|
|
|
|
.pointer/x LDZ2 .Screen/x DEO2
|
|
|
|
.pointer/y LDZ2 .Screen/y DEO2
|
|
|
|
#40 .Screen/sprite DEO
|
|
|
|
( draw new cursor )
|
|
|
|
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
|
|
|
|
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
|
2022-07-16 14:54:16 -04:00
|
|
|
#42 .Mouse/state DEI #00 NEQ ADD .Screen/sprite DEO
|
2021-04-22 14:08:06 -04:00
|
|
|
( on down )
|
2022-05-31 16:25:41 -04:00
|
|
|
.Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU AND ,on-mouse-down JCN
|
2021-04-22 14:08:06 -04:00
|
|
|
( on drag )
|
2021-05-13 02:31:42 -04:00
|
|
|
.Mouse/state DEI ,on-mouse-drag JCN
|
2021-05-11 14:14:52 -04:00
|
|
|
.Mouse/state DEI .pointer/state STZ
|
2021-04-22 14:08:06 -04:00
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
BRK
|
2021-04-21 12:48:04 -04:00
|
|
|
|
2021-04-22 14:08:06 -04:00
|
|
|
@on-mouse-down ( -> )
|
|
|
|
|
2022-07-16 14:54:16 -04:00
|
|
|
#0000 DUP2 .length STZ2 .frame STZ2
|
|
|
|
;clear-screen JSR2
|
2021-04-22 17:29:48 -04:00
|
|
|
( record start position )
|
2022-03-27 12:43:24 -04:00
|
|
|
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2
|
2021-05-11 14:14:52 -04:00
|
|
|
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .pointer/lasty STZ2
|
|
|
|
.Mouse/state DEI .pointer/state STZ
|
2021-04-22 14:08:06 -04:00
|
|
|
|
|
|
|
BRK
|
|
|
|
|
|
|
|
@on-mouse-drag ( -> )
|
2022-07-16 14:54:16 -04:00
|
|
|
|
|
|
|
( record )
|
|
|
|
;stroke .length LDZ2 #20 SFT2 ADD2 STH2
|
|
|
|
.pointer/x LDZ2 .pointer/lastx LDZ2 SUB2 STH2kr STA2
|
|
|
|
.pointer/y LDZ2 .pointer/lasty LDZ2 SUB2 STH2r INC2 INC2 STA2
|
|
|
|
( move ptr )
|
|
|
|
.length LDZ2 INC2 .length STZ2
|
2021-04-22 17:29:48 -04:00
|
|
|
( draw line )
|
2022-03-27 12:43:24 -04:00
|
|
|
.pointer/lastx LDZ2
|
|
|
|
.pointer/lasty LDZ2
|
|
|
|
.pointer/x LDZ2
|
|
|
|
.pointer/y LDZ2
|
2022-07-16 14:54:16 -04:00
|
|
|
#01
|
|
|
|
;draw-line JSR2
|
2021-04-22 14:08:06 -04:00
|
|
|
( record last position )
|
2022-07-16 14:54:16 -04:00
|
|
|
.Mouse/x DEI2
|
|
|
|
DUP2 .pointer/lastx STZ2
|
|
|
|
DUP2 .pen/x STZ2
|
|
|
|
.pen/x2 STZ2
|
|
|
|
.Mouse/y DEI2
|
|
|
|
DUP2 .pointer/lasty STZ2
|
|
|
|
DUP2 .pen/y STZ2
|
|
|
|
.pen/y2 STZ2
|
2021-05-11 14:14:52 -04:00
|
|
|
.Mouse/state DEI .pointer/state STZ
|
2021-04-22 14:08:06 -04:00
|
|
|
|
|
|
|
BRK
|
|
|
|
|
2022-07-16 14:54:16 -04:00
|
|
|
@run ( -- )
|
|
|
|
|
|
|
|
( read )
|
|
|
|
;stroke .frame LDZ2 #20 SFT2 ADD2 STH2
|
|
|
|
.pen/x LDZ2 STH2kr LDA2 ADD2 .pen/x STZ2
|
|
|
|
.pen/y LDZ2 STH2r INC2 INC2 LDA2 ADD2 .pen/y STZ2
|
|
|
|
( line )
|
|
|
|
.pen/x LDZ2 .pen/y LDZ2
|
|
|
|
.pen/x2 LDZ2 .pen/y2 LDZ2
|
|
|
|
.frame LDZ2 #01 SFT2 NIP #01 AND INC ;draw-line JSR2
|
|
|
|
( history )
|
|
|
|
.pen/x LDZ2 .pen/x2 STZ2
|
|
|
|
.pen/y LDZ2 .pen/y2 STZ2
|
|
|
|
( incr frame )
|
|
|
|
.frame LDZ2 INC2 .length LDZ2 INC2 ( mod2 ) DIV2k MUL2 SUB2 .frame STZ2
|
|
|
|
|
|
|
|
JMP2r
|
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
@draw-line ( x1* y1* x2* y2* color -- )
|
2021-04-29 00:00:39 -04:00
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
|
|
|
|
,&x LDR2 .line/x LDZ2 SUB2 ;abs2 JSR2 .line/dx STZ2
|
|
|
|
#0000 ,&y LDR2 .line/y LDZ2 SUB2 ;abs2 JSR2 SUB2 .line/dy STZ2
|
2022-07-16 14:54:16 -04:00
|
|
|
#ffff #00 .line/x LDZ2 ,&x LDR2 ;lts2 JSR2 DUP2 ADD2 ADD2 ,&sx STR2
|
|
|
|
#ffff #00 .line/y LDZ2 ,&y LDR2 ;lts2 JSR2 DUP2 ADD2 ADD2 ,&sy STR2
|
2021-05-11 14:14:52 -04:00
|
|
|
.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
|
2021-04-22 14:08:06 -04:00
|
|
|
&loop
|
2022-03-27 12:43:24 -04:00
|
|
|
.line/x LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
|
|
|
|
.line/y LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
|
|
|
|
STHkr .Screen/pixel DEO
|
|
|
|
AND ,&end JCN
|
2022-07-16 14:54:16 -04:00
|
|
|
.line/e1 LDZ2 DUP2 ADD2 DUP2
|
2022-03-27 12:43:24 -04:00
|
|
|
.line/dy LDZ2 ;lts2 JSR2 ,&skipy JCN
|
2021-05-11 14:14:52 -04:00
|
|
|
.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
|
2022-03-27 12:43:24 -04:00
|
|
|
.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2
|
2021-04-22 14:08:06 -04:00
|
|
|
&skipy
|
2022-03-27 12:43:24 -04:00
|
|
|
.line/dx LDZ2 ;gts2 JSR2 ,&skipx JCN
|
2021-05-11 14:14:52 -04:00
|
|
|
.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2
|
2022-03-27 12:43:24 -04:00
|
|
|
.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2
|
2021-04-22 14:08:06 -04:00
|
|
|
&skipx
|
2022-03-27 12:43:24 -04:00
|
|
|
,&loop JMP
|
2021-04-22 14:08:06 -04:00
|
|
|
&end
|
2022-03-27 12:43:24 -04:00
|
|
|
POPr
|
|
|
|
|
|
|
|
JMP2r
|
2021-04-22 14:08:06 -04:00
|
|
|
|
2022-03-27 12:43:24 -04:00
|
|
|
@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
|
2022-04-05 19:41:49 -04:00
|
|
|
@lts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 GTH2 JMP2r
|
|
|
|
@gts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 LTH2 JMP2r
|
2021-04-22 14:08:06 -04:00
|
|
|
|
2022-07-16 14:54:16 -04:00
|
|
|
@clear-screen ( -- )
|
|
|
|
|
|
|
|
.Screen/height DEI2 #03 SFT2 NIP #00
|
|
|
|
&y
|
|
|
|
#00 OVR #30 SFT2 .Screen/y DEO2
|
|
|
|
.Screen/width DEI2 #03 SFT2 NIP #00
|
|
|
|
&x
|
|
|
|
#00 OVR #30 SFT2 .Screen/x DEO2
|
|
|
|
#00 .Screen/sprite DEO
|
|
|
|
INC GTHk ,&x JCN
|
|
|
|
POP2
|
|
|
|
INC GTHk ,&y JCN
|
|
|
|
POP2
|
|
|
|
|
|
|
|
JMP2r
|
|
|
|
|
|
|
|
@pointer-icn
|
|
|
|
80c0 e0f0 f8e0 1000
|
|
|
|
|
|
|
|
@stroke
|
|
|
|
|