Browse code

(clock.tal) Minor optimizations

Devine Lu Linvega authored on 16/11/2021 17:10:48
Showing 1 changed files
... ...
@@ -1,8 +1,8 @@
1 1
 ( Dev/Time )
2 2
 
3
-%+  { ADD } %-   { SUB }              %/   { DIV }  
3
+%+  { ADD } %-   { SUB }  %*  { MUL } %/   { DIV }  
4 4
 %<  { LTH } %>   { GTH }  %=  { EQU } %!   { NEQ } 
5
-%++ { ADD2 } %-- { SUB2 }              %// { DIV2 } 
5
+%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } 
6 6
 %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } 
7 7
 
8 8
 %8* { #30 SFT }
... ...
@@ -17,8 +17,8 @@
17 17
 %RTN     { JMP2r }
18 18
 %MOD     { DUP2 DIV MUL SUB }
19 19
 %ABS2    { DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 -- }
20
-%SCALEX  { 2// .Screen/width DEI2 2// ++ RADIUS -- }
21
-%SCALEY  { 2// .Screen/height DEI2 2// ++ RADIUS -- }
20
+%SCALEX  { 2// .center/x LDZ2 ++ RADIUS -- }
21
+%SCALEY  { 2// .center/y LDZ2 ++ RADIUS -- }
22 22
 %12HOURS { DUP #0c GTH #0c MUL SUB }
23 23
 %LTS2    { #8000 ++ SWP2 #8000 ++ GTH2 }
24 24
 %GTS2    { #8000 ++ SWP2 #8000 ++ LTH2 }
... ...
@@ -39,27 +39,29 @@
39 39
 @current $1
40 40
 @center
41 41
 	&x $2 &y $2
42
-@needles [ &hx $2 &hy $2 &mx $2 &my $2 &sx $2 &sy $2 ]
43
-@line    [ &x0 $2 &y0 $2 &x $2 &y $2 &sx $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2 ]
42
+@needles
43
+	&hx $2 &hy $2 &mx $2 &my $2 &sx $2 &sy $2
44
+@line
45
+	&x0 $2 &y0 $2 &x $2 &y $2 &sx $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2
44 46
 
45 47
 ( program )
46 48
 
47 49
 |0100 ( -> )
48 50
 	
49 51
 	( theme ) 
50
-	#e0f8 .System/r DEO2 
51
-	#e008 .System/g DEO2 
52
-	#e008 .System/b DEO2
52
+	#0ff8 .System/r DEO2 
53
+	#0f08 .System/g DEO2 
54
+	#0f08 .System/b DEO2
53 55
 
54 56
 	#00f0 .Screen/width DEO2
55
-	#00f0 .Screen/height DEO2
57
+	#0120 .Screen/height DEO2
56 58
 
57 59
 	( vectors ) 
58 60
 	;on-frame .Screen/vector DEO2
59 61
 
60
-	DIAMETER SCALEX .center/x STZ2
61
-	DIAMETER SCALEY .center/y STZ2
62
-
62
+	( center )
63
+	.Screen/width DEI2 2// .center/x STZ2
64
+	.Screen/height DEI2 2// .center/y STZ2
63 65
 
64 66
 BRK
65 67
 
... ...
@@ -77,12 +79,8 @@ BRK
77 79
 
78 80
 @draw-clock ( -- )
79 81
 
80
-	( clear )
81
-	.center/x LDZ2 .center/y LDZ2 .needles/sx LDZ2 .needles/sy LDZ2 #00 ;draw-line JSR2
82
-	.center/x LDZ2 .center/y LDZ2 .needles/mx LDZ2 .needles/my LDZ2 #00 ;draw-line JSR2
83
-	.center/x LDZ2 .center/y LDZ2 .needles/hx LDZ2 .needles/hy LDZ2 #00 ;draw-line JSR2
82
+	( clear ) #00 ;draw-needles JSR2
84 83
 
85
-	( place )
86 84
 	#00 .DateTime/second DEI 2** ;table ++ LDA2
87 85
 		TOS SCALEY .needles/sy STZ2
88 86
 		TOS SCALEX .needles/sx STZ2
... ...
@@ -93,10 +91,7 @@ BRK
93 91
 		TOS 2// RADIUS ++ SCALEY .needles/hy STZ2
94 92
 		TOS 2// RADIUS ++ SCALEX .needles/hx STZ2
95 93
 
96
-	( needles )
97
-	.center/x LDZ2 .center/y LDZ2 .needles/sx LDZ2 .needles/sy LDZ2 #02 ;draw-line JSR2
98
-	.center/x LDZ2 .center/y LDZ2 .needles/mx LDZ2 .needles/my LDZ2 #01 ;draw-line JSR2
99
-	.center/x LDZ2 .center/y LDZ2 .needles/hx LDZ2 .needles/hy LDZ2 #03 ;draw-line JSR2
94
+	( draw ) #01 ;draw-needles JSR2
100 95
 
101 96
 	( circle )
102 97
 	#3c #00 
... ...
@@ -110,13 +105,22 @@ BRK
110 105
 
111 106
 RTN
112 107
 
108
+@draw-needles ( mul -- )
109
+
110
+	STH
111
+	.center/x LDZ2 .center/y LDZ2 .needles/sx LDZ2 .needles/sy LDZ2 #02 STHkr * ;draw-line JSR2
112
+	.center/x LDZ2 .center/y LDZ2 .needles/mx LDZ2 .needles/my LDZ2 #01 STHkr * ;draw-line JSR2
113
+	.center/x LDZ2 .center/y LDZ2 .needles/hx LDZ2 .needles/hy LDZ2 #01 STHr * ;draw-line JSR2
114
+
115
+RTN
116
+
113 117
 @draw-display ( -- )
114 118
 
115 119
 	( auto x ) #01 .Screen/auto DEO
116 120
 
117 121
 	( date )
118
-	.Screen/height DEI2 2// #0058 -- .Screen/y DEO2
119
-	.Screen/width DEI2 2// #0014 -- .Screen/x DEO2
122
+	.center/y LDZ2 #0058 -- .Screen/y DEO2
123
+	.center/x LDZ2 #0014 -- .Screen/x DEO2
120 124
 		.DateTime/month DEI INC
121 125
 		DUP #0a DIV GET-CHAR-SPRITE .Screen/addr DEO2
122 126
 			#03 .Screen/sprite DEO
... ...
@@ -130,8 +134,8 @@ RTN
130 134
 			#03 .Screen/sprite DEO
131 135
 
132 136
 	( time )
133
-	.Screen/height DEI2 2// #0050 ++ .Screen/y DEO2
134
-	.Screen/width DEI2 2// #0020 -- .Screen/x DEO2
137
+	.center/y LDZ2 #0050 ++ .Screen/y DEO2
138
+	.center/x LDZ2 #0020 -- .Screen/x DEO2
135 139
 		.DateTime/hour DEI
136 140
 		DUP #0a DIV GET-CHAR-SPRITE .Screen/addr DEO2
137 141
 			#01 .Screen/sprite DEO
... ...
@@ -169,7 +173,7 @@ RTN
169 173
 		.line/y LDZ2 .Screen/y DEO2 
170 174
 		.color LDZ .Screen/pixel DEO
171 175
 		[ .line/x LDZ2 .line/x0 LDZ2 == ] 
172
-		[ .line/y LDZ2 .line/y0 LDZ2 == ] #0101 == ,&end JCN
176
+		[ .line/y LDZ2 .line/y0 LDZ2 == ] AND ,&end JCN
173 177
 		.line/e1 LDZ2 2** .line/e2 STZ2
174 178
 		.line/e2 LDZ2 .line/dy LDZ2 LTS2 ,&skipy JCN
175 179
 			.line/e1 LDZ2 .line/dy LDZ2 ++ .line/e1 STZ2
... ...
@@ -184,7 +188,7 @@ RTN
184 188
 
185 189
 RTN
186 190
 
187
-@table ( 60 positions on a circle in bytes )
191
+@table ( 60 positions on a circle )
188 192
 	8000 8d00 9a02 a706 b40b c011 cb18 d520
189 193
 	df2a e734 ee40 f44b f958 fd65 ff72 ff80
190 194
 	ff8d fd9a f9a7 f4b4 eec0 e7cb dfd5 d5df