(mouse.tal) Improved implementation
This commit is contained in:
parent
6bdb6ca168
commit
d0a521745a
|
@ -1,5 +1,4 @@
|
||||||
( Mouse:
|
( Mouse: Paint with 3 colors with each mouse button. )
|
||||||
Paint with 3 colors with each mouse button. )
|
|
||||||
|
|
||||||
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
|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
|
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||||
|
@ -7,214 +6,181 @@
|
||||||
|
|
||||||
|0000
|
|0000
|
||||||
|
|
||||||
@line &x2 $2 &y2 $2
|
|
||||||
@length $2
|
@length $2
|
||||||
@frame $2
|
@frame $2
|
||||||
@pen &x $2 &y $2 &x2 $2 &y2 $2
|
@pen &x $2 &y $2 &x2 $2 &y2 $2
|
||||||
@pointer &x $2 &y $2 &lastx $2 &lasty $2 &state $1
|
@pointer &x $2 &y $2 &lastx $2 &lasty $2 &state $1
|
||||||
|
|
||||||
|0100 ( -> )
|
|0100
|
||||||
|
|
||||||
( theme )
|
@on-reset ( -> )
|
||||||
#4cfd .System/r DEO2
|
( | theme )
|
||||||
#4cf3 .System/g DEO2
|
#68af .System/r DEO2
|
||||||
#dcf2 .System/b DEO2
|
#79bf .System/g DEO2
|
||||||
|
#8ace .System/b DEO2
|
||||||
( vectors )
|
( | vectors )
|
||||||
;on-mouse .Mouse/vector DEO2
|
;on-mouse .Mouse/vector DEO2
|
||||||
;on-frame .Screen/vector DEO2
|
;on-frame .Screen/vector DEO2
|
||||||
|
<draw-mouse>
|
||||||
draw-mouse
|
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
(
|
(
|
||||||
@|vectors )
|
@|vectors )
|
||||||
|
|
||||||
@on-frame ( -> )
|
@on-frame ( -> )
|
||||||
|
.Mouse/state DEI ?{
|
||||||
.Mouse/state DEI ?&skip
|
;run DUP2 JSR2 JSR2 }
|
||||||
;run DUP2 JSR2 JSR2
|
|
||||||
&skip
|
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@on-mouse ( -> )
|
@on-mouse ( -> )
|
||||||
|
( | clear last cursor )
|
||||||
( clear last cursor )
|
|
||||||
.pointer/x LDZ2 .Screen/x DEO2
|
.pointer/x LDZ2 .Screen/x DEO2
|
||||||
.pointer/y LDZ2 .Screen/y DEO2
|
.pointer/y LDZ2 .Screen/y DEO2
|
||||||
;fill-icn .Screen/addr DEO2
|
;fill-icn .Screen/addr DEO2
|
||||||
[ LIT2 40 -Screen/sprite ] DEO
|
[ LIT2 40 -Screen/sprite ] DEO
|
||||||
draw-mouse
|
<draw-mouse>
|
||||||
( draw new cursor )
|
( | draw new cursor )
|
||||||
;pointer-icn .Screen/addr DEO2
|
;pointer-icn .Screen/addr DEO2
|
||||||
#00 .Screen/auto DEO
|
#00 .Screen/auto DEO
|
||||||
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
|
.Mouse/x DEI2 DUP2 .pointer/x STZ2
|
||||||
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
|
.Screen/x DEO2
|
||||||
|
.Mouse/y DEI2 DUP2 .pointer/y STZ2
|
||||||
|
.Screen/y DEO2
|
||||||
#45 .Mouse/state DEI #00 NEQ #05 MUL ADD .Screen/sprite DEO
|
#45 .Mouse/state DEI #00 NEQ #05 MUL ADD .Screen/sprite DEO
|
||||||
( on down )
|
( | on down )
|
||||||
.Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU AND ?on-mouse-down
|
.Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU AND ?&down
|
||||||
( on drag )
|
( | on drag )
|
||||||
.Mouse/state DEI ?on-mouse-drag
|
.Mouse/state DEI ?&drag
|
||||||
.Mouse/state DEI .pointer/state STZ
|
.Mouse/state DEI .pointer/state STZ
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
&down ( -> )
|
||||||
@on-mouse-down ( -> )
|
#0000 DUP2 .length STZ2
|
||||||
|
.frame STZ2
|
||||||
#0000 DUP2 .length STZ2 .frame STZ2
|
<clear-screen>
|
||||||
clear-screen
|
( | record start position )
|
||||||
( record start position )
|
.Mouse/x DEI2 DUP2 .pointer/x STZ2
|
||||||
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2
|
.pointer/lastx STZ2
|
||||||
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .pointer/lasty STZ2
|
.Mouse/y DEI2 DUP2 .pointer/y STZ2
|
||||||
|
.pointer/lasty STZ2
|
||||||
.Mouse/state DEI .pointer/state STZ
|
.Mouse/state DEI .pointer/state STZ
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
&drag ( -> )
|
||||||
@on-mouse-drag ( -> )
|
( | record )
|
||||||
|
;stroke .length LDZ2 #20 SFT2 ADD2 STH2 .pointer/x LDZ2 .pointer/lastx LDZ2 SUB2 STH2kr STA2
|
||||||
( 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
|
.pointer/y LDZ2 .pointer/lasty LDZ2 SUB2 STH2r INC2 INC2 STA2
|
||||||
( move ptr )
|
( | move ptr )
|
||||||
.length LDZ2 INC2 .length STZ2
|
.length LDZ2 INC2 .length STZ2
|
||||||
( draw line )
|
( | draw line )
|
||||||
.pointer/lastx LDZ2
|
.pointer/lastx LDZ2 .pointer/lasty LDZ2 .pointer/x LDZ2 .pointer/y LDZ2 #01 <draw-line>
|
||||||
.pointer/lasty LDZ2
|
( | record last position )
|
||||||
.pointer/x LDZ2
|
.Mouse/x DEI2 DUP2 .pointer/lastx STZ2
|
||||||
.pointer/y LDZ2
|
|
||||||
#01 draw-line
|
|
||||||
( record last position )
|
|
||||||
.Mouse/x DEI2
|
|
||||||
DUP2 .pointer/lastx STZ2
|
|
||||||
DUP2 .pen/x STZ2
|
DUP2 .pen/x STZ2
|
||||||
.pen/x2 STZ2
|
.pen/x2 STZ2
|
||||||
.Mouse/y DEI2
|
.Mouse/y DEI2 DUP2 .pointer/lasty STZ2
|
||||||
DUP2 .pointer/lasty STZ2
|
|
||||||
DUP2 .pen/y STZ2
|
DUP2 .pen/y STZ2
|
||||||
.pen/y2 STZ2
|
.pen/y2 STZ2
|
||||||
.Mouse/state DEI
|
.Mouse/state DEI DUP #01 NEQ INC ;run/color STA
|
||||||
DUP #01 NEQ INC ;run/color STA
|
|
||||||
.pointer/state STZ
|
.pointer/state STZ
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
(
|
(
|
||||||
@|main )
|
@|main )
|
||||||
|
|
||||||
@run ( -- )
|
@run ( -- )
|
||||||
|
( | read )
|
||||||
( read )
|
;stroke .frame LDZ2 #20 SFT2 ADD2 STH2 .pen/x LDZ2 STH2kr LDA2 ADD2 .pen/x STZ2
|
||||||
;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
|
.pen/y LDZ2 STH2r INC2 INC2 LDA2 ADD2 .pen/y STZ2
|
||||||
( line )
|
( | line )
|
||||||
.pen/x LDZ2 .pen/y LDZ2
|
.pen/x LDZ2 .pen/y LDZ2 .pen/x2 LDZ2 .pen/y2 LDZ2 .frame LDZ2 #01 SFT2 NIP #01 AND [ LIT &color $1 ] ADD INC <draw-line>
|
||||||
.pen/x2 LDZ2 .pen/y2 LDZ2
|
( | history )
|
||||||
.frame LDZ2 #01 SFT2 NIP #01 AND [ LIT &color $1 ] ADD INC draw-line
|
|
||||||
( history )
|
|
||||||
.pen/x LDZ2 .pen/x2 STZ2
|
.pen/x LDZ2 .pen/x2 STZ2
|
||||||
.pen/y LDZ2 .pen/y2 STZ2
|
.pen/y LDZ2 .pen/y2 STZ2
|
||||||
( incr frame )
|
( | incr frame )
|
||||||
.frame LDZ2 INC2 .length LDZ2 INC2 ( mod2 ) DIV2k MUL2 SUB2 .frame STZ2
|
.frame LDZ2 INC2 .length LDZ2 INC2
|
||||||
|
( mod2 ) DIV2k MUL2 SUB2 .frame STZ2
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
@draw-mouse ( -- )
|
@<draw-mouse> ( -- )
|
||||||
|
( | clear )
|
||||||
( clear )
|
#0010 DUP2 .Screen/x DEO2
|
||||||
#0010
|
|
||||||
DUP2 .Screen/x DEO2
|
|
||||||
.Screen/y DEO2
|
.Screen/y DEO2
|
||||||
#16 .Screen/auto DEO
|
#16 .Screen/auto DEO
|
||||||
;fill-icn .Screen/addr DEO2
|
;fill-icn .Screen/addr DEO2
|
||||||
#40 .Screen/sprite DEOk DEO
|
#40 .Screen/sprite DEOk
|
||||||
( buttons )
|
DEO
|
||||||
|
( | buttons )
|
||||||
#0300
|
#0300
|
||||||
&l
|
&l ( -- )
|
||||||
#01 OVR #40 SFT SFT .Mouse/state DEI AND #00 EQU ?&no-draw
|
#01 OVR #40 SFT SFT .Mouse/state DEI AND #00 EQU ?{
|
||||||
#0010 .Screen/y DEO2
|
#0010 .Screen/y DEO2
|
||||||
#00 OVR #40 SFT2 ;button-icn ADD2 .Screen/addr DEO2
|
#00 OVR #40 SFT2 ;button-icn ADD2 .Screen/addr DEO2
|
||||||
#45 .Screen/sprite DEO
|
#45 .Screen/sprite DEO }
|
||||||
&no-draw
|
|
||||||
INC GTHk ?&l
|
INC GTHk ?&l
|
||||||
POP2
|
POP2
|
||||||
( outline )
|
( | outline )
|
||||||
#0010 .Screen/y DEO2
|
#0010 .Screen/y DEO2
|
||||||
;mouse-icn .Screen/addr DEO2
|
;mouse-icn .Screen/addr DEO2
|
||||||
#16 .Screen/auto DEO
|
#16 .Screen/auto DEO
|
||||||
#4a .Screen/sprite DEOk DEO
|
#4a .Screen/sprite DEOk
|
||||||
|
DEO
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
@draw-line ( x1* y1* x2* y2* color -- )
|
@<draw-line> ( x1* y1* x2* y2* color -- )
|
||||||
|
|
||||||
( load )
|
|
||||||
,&color STR
|
,&color STR
|
||||||
,&y STR2
|
,&y STR2
|
||||||
,&x STR2
|
,&x STR2
|
||||||
.line/y2 STZ2
|
,&y2 STR2
|
||||||
.line/x2 STZ2
|
,&x2 STR2
|
||||||
|
,&x LDR2 ,&x2 LDR2 SUB2 abs2 ,&dx STR2
|
||||||
,&x LDR2 .line/x2 LDZ2 SUB2 abs2 ,&dx STR2
|
#0000 ,&y LDR2 ,&y2 LDR2 SUB2 abs2 SUB2 ,&dy STR2
|
||||||
#0000 ,&y LDR2 .line/y2 LDZ2 SUB2 abs2 SUB2 ,&dy STR2
|
#ffff [ LIT2 00 _&x2 ] LDR2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2
|
||||||
|
#ffff [ LIT2 00 _&y2 ] LDR2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2
|
||||||
#ffff #00 .line/x2 LDZ2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2
|
[ LIT2 &dx $2 ] [ LIT2 &dy $2 ] ADD2 STH2
|
||||||
#ffff #00 .line/y2 LDZ2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2
|
&while ( -- )
|
||||||
|
[ LIT2 &x2 $2 ] DUP2 .Screen/x DEO2
|
||||||
[ LIT2 &dx $2 ] [ LIT2 &dy $2 ] ADD2 ,&e1 STR2
|
[ LIT2 &x $2 ] EQU2 [ LIT2 &y2 $2 ] DUP2 .Screen/y DEO2
|
||||||
|
[ LIT2 &y $2 ] EQU2 [ LIT2 &color $1 -Screen/pixel ] DEO
|
||||||
&loop
|
|
||||||
.line/x2 LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
|
|
||||||
.line/y2 LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
|
|
||||||
[ LIT2 &color $1 -Screen/pixel ] DEO
|
|
||||||
AND ?&end
|
AND ?&end
|
||||||
[ LIT2 &e1 $2 ] DUP2 ADD2 DUP2
|
STH2kr DUP2 ADD2 DUP2 ,&dy LDR2 lts2 ?&skipy
|
||||||
,&dy LDR2 lts2 ?&skipy
|
STH2r ,&dy LDR2 ADD2 STH2 ,&x2 LDR2 [ LIT2 &sx $2 ] ADD2 ,&x2 STR2
|
||||||
,&e1 LDR2 ,&dy LDR2 ADD2 ,&e1 STR2
|
&skipy ( -- )
|
||||||
.line/x2 LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x2 STZ2
|
,&dx LDR2 gts2 ?&while
|
||||||
&skipy
|
STH2r ,&dx LDR2 ADD2 STH2 ,&y2 LDR2 [ LIT2 &sy $2 ] ADD2 ,&y2 STR2
|
||||||
,&dx LDR2 gts2 ?&skipx
|
!&while
|
||||||
,&e1 LDR2 ,&dx LDR2 ADD2 ,&e1 STR2
|
&end POP2r JMP2r
|
||||||
.line/y2 LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y2 STZ2
|
|
||||||
&skipx
|
|
||||||
!&loop
|
|
||||||
&end
|
|
||||||
|
|
||||||
|
@abs2 ( a* -- f )
|
||||||
|
DUP2 #0f SFT2 EQU ?{ #0000 SWP2 SUB2 }
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
|
@lts2 ( a* b* -- f )
|
||||||
@lts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 GTH2 JMP2r
|
#8000 STH2k ADD2 SWP2 STH2r ADD2 GTH2 JMP2r
|
||||||
@gts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 LTH2 JMP2r
|
|
||||||
|
|
||||||
@clear-screen ( -- )
|
@gts2 ( a* b* -- f )
|
||||||
|
#8000 STH2k ADD2 SWP2 STH2r ADD2 LTH2 JMP2r
|
||||||
|
|
||||||
#0000 DUP2 .Screen/x DEO2 .Screen/y DEO2
|
@<clear-screen> ( -- )
|
||||||
|
#0000 DUP2 .Screen/x DEO2
|
||||||
|
.Screen/y DEO2
|
||||||
#80 .Screen/pixel DEO
|
#80 .Screen/pixel DEO
|
||||||
|
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
@fill-icn [
|
@fill-icn [ ffff ffff ffff ffff ]
|
||||||
ffff ffff ffff ffff ]
|
|
||||||
@pointer-icn [
|
@pointer-icn [ 80c0 e0f0 f8e0 1000 ]
|
||||||
80c0 e0f0 f8e0 1000 ]
|
|
||||||
@mouse-icn [
|
@mouse-icn [
|
||||||
000d 1212 1212 121d
|
000d 1212 1212 121d 00b0 4848 4848 48b8
|
||||||
00b0 4848 4848 48b8
|
1010 1010 1008 0700 0808 0808 0810 e000 ]
|
||||||
1010 1010 1008 0700
|
|
||||||
0808 0808 0810 e000 ]
|
|
||||||
@button-icn [
|
@button-icn [
|
||||||
000c 1e1e 1e1e 1e0c
|
000c 1e1e 1e1e 1e0c 0000 0000 0000 0000
|
||||||
0000 0000 0000 0000
|
0001 0303 0303 0301 0080 c0c0 c0c0 c080
|
||||||
0001 0303 0303 0301
|
0000 0000 0000 0000 0030 7878 7878 7830 ]
|
||||||
0080 c0c0 c0c0 c080
|
|
||||||
0000 0000 0000 0000
|
|
||||||
0030 7878 7878 7830 ]
|
|
||||||
|
|
||||||
(
|
(
|
||||||
@|memory )
|
@|memory )
|
||||||
|
|
||||||
@stroke
|
@stroke
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,7 @@ uxn_eval(Uxn *u, Uint16 pc)
|
||||||
case 0x60: /* JSI */ SHIFT( 2) rr = ram + pc; pc += 2; T2_(pc); pc += PEEK2(rr); break;
|
case 0x60: /* JSI */ SHIFT( 2) rr = ram + pc; pc += 2; T2_(pc); pc += PEEK2(rr); break;
|
||||||
case 0x80: /* LIT */ case 0xc0: SHIFT( 1) T = ram[pc++]; break;
|
case 0x80: /* LIT */ case 0xc0: SHIFT( 1) T = ram[pc++]; break;
|
||||||
case 0xa0: /* LIT2 */ case 0xe0: SHIFT( 2) N = ram[pc++]; T = ram[pc++]; break;
|
case 0xa0: /* LIT2 */ case 0xe0: SHIFT( 2) N = ram[pc++]; T = ram[pc++]; break;
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
/* ALU */
|
/* ALU */
|
||||||
case 0x01: /* INC */ t=T; SET(1, 0) T = t + 1; break;
|
case 0x01: /* INC */ t=T; SET(1, 0) T = t + 1; break;
|
||||||
case 0x21: /* INC2 */ t=T2; SET(2, 0) T2_(t + 1) break;
|
case 0x21: /* INC2 */ t=T2; SET(2, 0) T2_(t + 1) break;
|
||||||
|
|
|
@ -72,7 +72,7 @@ main(int argc, char **argv)
|
||||||
return system_error("usage", "uxncli [-v] file.rom [args..]");
|
return system_error("usage", "uxncli [-v] file.rom [args..]");
|
||||||
/* Read flags */
|
/* Read flags */
|
||||||
if(argv[i][0] == '-' && argv[i][1] == 'v')
|
if(argv[i][0] == '-' && argv[i][1] == 'v')
|
||||||
return system_version("Uxncli - Console Varvara Emulator", "1 Nov 2023");
|
return system_version("Uxncli - Console Varvara Emulator", "9 Nov 2023");
|
||||||
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
|
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
|
||||||
return system_error("Init", "Failed to initialize uxn.");
|
return system_error("Init", "Failed to initialize uxn.");
|
||||||
/* Game Loop */
|
/* Game Loop */
|
||||||
|
|
|
@ -540,7 +540,7 @@ main(int argc, char **argv)
|
||||||
/* Read flag. Right now, there can be only one. */
|
/* Read flag. Right now, there can be only one. */
|
||||||
if(argv[i][0] == '-') {
|
if(argv[i][0] == '-') {
|
||||||
if(argv[i][1] == 'v')
|
if(argv[i][1] == 'v')
|
||||||
return system_version("Uxnemu - Graphical Varvara Emulator", "1 Nov 2023");
|
return system_version("Uxnemu - Graphical Varvara Emulator", "9 Nov 2023");
|
||||||
if(argv[i][1] == '-')
|
if(argv[i][1] == '-')
|
||||||
i++;
|
i++;
|
||||||
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)
|
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)
|
||||||
|
|
Loading…
Reference in New Issue