Browse code

(mouse.tal) Optimized

neauoire authored on 27/03/2022 16:43:24
Showing 2 changed files
... ...
@@ -1,56 +1,51 @@
1
-( dev/mouse )
1
+( Mouse )
2 2
 
3
-%RTN   { JMP2r }
4
-%ABS2  { DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 }
5
-%LTS2  { #8000 ADD2 SWP2 #8000 ADD2 GTH2 }
6
-%GTS2  { #8000 ADD2 SWP2 #8000 ADD2 LTH2 }
7
-%2** { #10 SFT2 }
8
-
9
-( devices )
10
-
11
-|00 @System     &vector $2 &wst      $1 &rst    $1 &pad    $4 &r      $2 &g      $2 &b      $2 &debug  $1 &halt $1
12
-|20 @Screen     &vector $2 &width    $2 &height $2 &pad    $2 &x      $2 &y      $2 &addr   $2 &pixel  $1 &sprite $1
13
-|90 @Mouse      &vector $2 &x        $2 &y      $2 &state  $1 &pad    $3 &modx   $2 &mody   $2
3
+|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
4
+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
5
+|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &modx $2 &mody $2
14 6
 
15 7
 |0000
16 8
 
17
-@color $1
18
-@line    
19
-	&x0 $2 &y0 $2 &x     $2 &y     $2 &sx    $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2
20
-@pointer 
21
-	&x  $2 &y  $2 &lastx $2 &lasty $2 &state $1
22
-
23
-( program )
9
+@line
10
+	&x $2 &y $2 &dx $2 &dy $2 &e1 $2
11
+@pointer
12
+	&x $2 &y $2 &lastx $2 &lasty $2 &state $1
24 13
 
25 14
 |0100 ( -> )
26 15
 
27
-	( theme ) 
28
-	#f030 .System/r DEO2 
29
-	#f04f .System/g DEO2 
30
-	#f050 .System/b DEO2
16
+	( theme )
17
+	#a0f0 .System/r DEO2
18
+	#40ff .System/g DEO2
19
+	#60ff .System/b DEO2
31 20
 
32
-	( vectors ) 
21
+	( vectors )
33 22
 	;on-mouse .Mouse/vector DEO2
34 23
 
35 24
 BRK
36 25
 
37 26
 @on-mouse ( -> )
38 27
 
39
-	;draw-cursor JSR2
40
-
28
+	;pointer-icn .Screen/addr DEO2
29
+	( clear last cursor )
30
+	.pointer/x LDZ2 .Screen/x DEO2
31
+	.pointer/y LDZ2 .Screen/y DEO2
32
+	#40 .Screen/sprite DEO
33
+	( draw new cursor )
34
+	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
35
+	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
36
+	#43 .Mouse/state DEI #00 NEQ DUP ADD SUB .Screen/sprite DEO
41 37
 	( on down )
42 38
 	.Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU #0101 EQU2 ,on-mouse-down JCN
43
-
44 39
 	( on drag )
45 40
 	.Mouse/state DEI ,on-mouse-drag JCN
46 41
 	.Mouse/state DEI .pointer/state STZ
47 42
 
48
-BRK 
43
+BRK
49 44
 
50 45
 @on-mouse-down ( -> )
51 46
 
52 47
 	( record start position )
53
-	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2 
48
+	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2
54 49
 	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .pointer/lasty STZ2
55 50
 	.Mouse/state DEI .pointer/state STZ
56 51
 
... ...
@@ -59,62 +54,50 @@ BRK
59 54
 @on-mouse-drag ( -> )
60 55
 	
61 56
 	( draw line )
62
-	.pointer/lastx LDZ2 
63
-	.pointer/lasty LDZ2 
64
-	.pointer/x LDZ2 
65
-	.pointer/y LDZ2 
66
-	#01 [ .Mouse/state DEI #10 EQU DUP ADD ADD ] 
57
+	.pointer/lastx LDZ2
58
+	.pointer/lasty LDZ2
59
+	.pointer/x LDZ2
60
+	.pointer/y LDZ2
61
+	.Mouse/state DEI INC
67 62
 	;draw-line JSR2
68 63
 
69 64
 	( record last position )
70
-	.Mouse/x DEI2 .pointer/lastx STZ2 
65
+	.Mouse/x DEI2 .pointer/lastx STZ2
71 66
 	.Mouse/y DEI2 .pointer/lasty STZ2
72 67
 	.Mouse/state DEI .pointer/state STZ
73 68
 
74 69
 BRK
75 70
 
76
-@draw-cursor ( -- )
77
-	
78
-	;pointer-icn .Screen/addr DEO2
79
-
80
-	( clear last cursor )
81
-	.pointer/x LDZ2 .Screen/x DEO2
82
-	.pointer/y LDZ2 .Screen/y DEO2
83
-	#40 .Screen/sprite DEO
71
+@draw-line ( x1* y1* x2* y2* color -- )
84 72
 
85
-	( draw new cursor )
86
-	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 
87
-	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
88
-	#43 .Mouse/state DEI #00 NEQ DUP ADD SUB .Screen/sprite DEO
89
-
90
-RTN
91
-
92
-@draw-line ( x1 y1 x2 y2 color -- )
93
-	
94
-	( load ) .color STZ .line/y0 STZ2 .line/x0 STZ2 .line/y STZ2 .line/x STZ2
95
-	.line/x0 LDZ2 .line/x LDZ2 SUB2 ABS2 .line/dx STZ2
96
-	.line/y0 LDZ2 .line/y LDZ2 SUB2 ABS2 #0000 SWP2 SUB2 .line/dy STZ2
97
-	#ffff #00 .line/x LDZ2 .line/x0 LDZ2 LTS2 2** ADD2 .line/sx STZ2
98
-	#ffff #00 .line/y LDZ2 .line/y0 LDZ2 LTS2 2** ADD2 .line/sy STZ2
73
+	( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
74
+	,&x LDR2 .line/x LDZ2 SUB2 ;abs2 JSR2 .line/dx STZ2
75
+	#0000 ,&y LDR2 .line/y LDZ2 SUB2 ;abs2 JSR2 SUB2 .line/dy STZ2
76
+	#ffff #00 .line/x LDZ2 ,&x LDR2 ;lts2 JSR2 #10 SFT2 ADD2 ,&sx STR2
77
+	#ffff #00 .line/y LDZ2 ,&y LDR2 ;lts2 JSR2 #10 SFT2 ADD2 ,&sy STR2
99 78
 	.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
100 79
 	&loop
101
-		.line/x LDZ2 .Screen/x DEO2 
102
-		.line/y LDZ2 .Screen/y DEO2 
103
-		.color LDZ .Screen/pixel DEO
104
-		[ .line/x LDZ2 .line/x0 LDZ2 EQU2 ] 
105
-		[ .line/y LDZ2 .line/y0 LDZ2 EQU2 ] #0101 EQU2 ,&end JCN
106
-		.line/e1 LDZ2 2** .line/e2 STZ2
107
-		.line/e2 LDZ2 .line/dy LDZ2 LTS2 ,&skipy JCN
80
+		.line/x LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
81
+		.line/y LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
82
+			STHkr .Screen/pixel DEO
83
+			AND ,&end JCN
84
+		.line/e1 LDZ2 #10 SFT2 DUP2
85
+		.line/dy LDZ2 ;lts2 JSR2 ,&skipy JCN
108 86
 			.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
109
-			.line/x LDZ2 .line/sx LDZ2 ADD2 .line/x STZ2
87
+			.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2
110 88
 		&skipy
111
-		.line/e2 LDZ2 .line/dx LDZ2 GTS2 ,&skipx JCN
89
+		.line/dx LDZ2 ;gts2 JSR2 ,&skipx JCN
112 90
 			.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2
113
-			.line/y LDZ2 .line/sy LDZ2 ADD2 .line/y STZ2
91
+			.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2
114 92
 		&skipx
115
-		;&loop JMP2
93
+		,&loop JMP
116 94
 	&end
95
+	POPr
96
+
97
+JMP2r
117 98
 
118
-RTN
99
+@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
100
+@lts2 #8000 ADD2 SWP2 #8000 ADD2 GTH2 JMP2r
101
+@gts2 #8000 ADD2 SWP2 #8000 ADD2 LTH2 JMP2r
119 102
 
120 103
 @pointer-icn 80c0 e0f0 f8e0 1000
121 104
deleted file mode 100644
... ...
@@ -1,30 +0,0 @@
1
-( devices )
2
-
3
-|00 @System     &vector $2 &wst      $1 &rst    $1 &swsz   $1 &swap   $1 &pad     $2 &r       $2 &g      $2 &b     $2 &debug  $1 &halt $1
4
-|20 @Screen     &vector $2 &width    $2 &height $2 &auto   $1 &pad    $1 &x       $2 &y       $2 &addr   $2 &pixel $1 &sprite $1
5
-
6
-( variables )
7
-
8
-|0000
9
-
10
-( program )
11
-
12
-|0100 ( -> )
13
-	( theme ) 
14
-	#0fe5 .System/r DEO2 
15
-	#0fc5 .System/g DEO2 
16
-	#0f25 .System/b DEO2
17
-
18
-	#35 .Screen/auto DEO
19
-
20
-	;font #0210 ADD2 .Screen/addr DEO2
21
-	#0d00 &loop
22
-		#04 .Screen/sprite DEO
23
-		INC
24
-		GTHk ,&loop JCN
25
-
26
-BRK
27
-
28
-~projects/assets/msx01x02.tal
29
-
30
-