Browse code

(life.tal) Minor cleanup

neauoire authored on 09/02/2022 04:04:18
Showing 1 changed files
... ...
@@ -4,9 +4,9 @@
4 4
 	Any live cell with more than three live neighbours dies, as if by overpopulation.
5 5
 	Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. )
6 6
 
7
-%+  { ADD } %-   { SUB } 
7
+%+  { ADD } %-   { SUB }
8 8
 %<  { LTH } %>   { GTH }  %=  { EQU } %!   { NEQ }
9
-%++ { ADD2 } %-- { SUB2 } 
9
+%++ { ADD2 } %-- { SUB2 }
10 10
 %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
11 11
 
12 12
 %2/  { #01 SFT }
... ...
@@ -16,17 +16,19 @@
16 16
 %40** { #60 SFT2 }
17 17
 %8MOD { #07 AND } %2MOD { #01 AND }
18 18
 
19
-%TOS  { #00 SWP } 
20
-%RTN  { JMP2r }   
19
+%TOS  { #00 SWP }
20
+%RTN  { JMP2r }
21 21
 %SFL  { #40 SFT SFT }
22 22
 
23
-%WIDTH { #40 }   %HEIGHT { #40 }
24
-%WIDTH-MOD { #3f AND }   %HEIGHT-MOD { #3f AND }
23
+%WIDTH { #40 }
24
+%HEIGHT { #40 }
25
+%LENGTH { #0200 }
26
+%WIDTH-MOD { #3f AND }
27
+%HEIGHT-MOD { #3f AND }
25 28
 %IN-RANGE { INCk SWP SUB2 GTH }
26 29
 
27 30
 %BANK1 { #8000 } %BANK2 { #a000 }
28 31
 
29
-%GET-SIZE { WIDTH TOS 8// 40** }
30 32
 %GET-ITERATORS { SWP2k POP NIP }
31 33
 %GET-ITER { OVR2 NIP OVR SWP }
32 34
 
... ...
@@ -37,7 +39,7 @@
37 39
 
38 40
 |00 @System     [ &vector $2 &wst      $1 &rst    $1 &pad   $4 &r      $2 &g     $2 &b      $2 ]
39 41
 |10 @Console    [ &vector $2 &read $1 &pad    $5 &write $1 &error  $1 ]
40
-|20 @Screen     &vector $2 &width    $2 &height $2 &auto   $1 &pad    $1 &x       $2 &y       $2 &addr   $2 &pixel $1 &sprite $1
42
+|20 @Screen     &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
41 43
 |30 @Audio0     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
42 44
 |80 @Controller [ &vector $2 &button   $1 &key    $1 ]
43 45
 |90 @Mouse      [ &vector $2 &x        $2 &y      $2 &state $1 &wheel $1 ]
... ...
@@ -55,9 +57,9 @@
55 57
 
56 58
 |0100 ( -> )
57 59
 
58
-	( theme ) 
59
-	#02cf .System/r DEO2 
60
-	#02ff .System/g DEO2 
60
+	( theme )
61
+	#02cf .System/r DEO2
62
+	#02ff .System/g DEO2
61 63
 	#024f .System/b DEO2
62 64
 
63 65
 	( vectors )
... ...
@@ -89,14 +91,10 @@ BRK
89 91
 	( incr frame ) .world/frame LDZ INC [ DUP ] .world/frame STZ
90 92
 	( reset count ) #0000 .world/count STZ2
91 93
 
92
-	#03 AND #00 = #01 JCN [ BRK ] 
94
+	#03 AND #00 = #01 JCN [ BRK ]
93 95
 
94 96
 	( clear buffer )
95
-	BANK2 STH2k GET-SIZE ++ STH2r
96
-	&clear-loop
97
-		DUP2 #0000 SWP2 STA2
98
-		INC2 INC2 GTH2k ,&clear-loop JCN
99
-	POP2 POP2
97
+	BANK2 LENGTH ;mclr JSR2
100 98
 
101 99
 	( run grid )
102 100
 	#00 HEIGHT
... ...
@@ -116,12 +114,7 @@ BRK
116 114
 	POP2
117 115
 
118 116
 	( move buffer )
119
-	BANK2 DUP2 GET-SIZE ++ SWP2
120
-	&copy-loop
121
-		DUP2 LDA2k
122
-		SWP2 #2000 -- STA2
123
-		INC2 INC2 GTH2k ,&copy-loop JCN
124
-	POP2 POP2
117
+	BANK2 BANK1 LENGTH ;mcpy JSR2
125 118
 
126 119
 	;draw-grid JSR2
127 120
 
... ...
@@ -150,7 +143,7 @@ RTN
150 143
 	.world/count LDZ2 INC2 .world/count STZ2
151 144
 	( save in buffer )
152 145
 	STH2
153
-	DUP2 POP 8MOD #01 SWP SFL 
146
+	DUP2 POP 8MOD #01 SWP SFL
154 147
 	LDAkr STHr SWP ORA
155 148
 	STH2r STA
156 149
 
... ...
@@ -159,14 +152,14 @@ RTN
159 152
 @on-mouse ( -> )
160 153
 	
161 154
 	( clear last cursor )
162
-	;cursor .Screen/addr DEO2 
163
-	.pointer/x LDZ2 .Screen/x DEO2 
164
-	.pointer/y LDZ2 .Screen/y DEO2 
155
+	;cursor .Screen/addr DEO2
156
+	.pointer/x LDZ2 .Screen/x DEO2
157
+	.pointer/y LDZ2 .Screen/y DEO2
165 158
 	#40 .Screen/sprite DEO
166 159
 
167 160
 	( record pointer positions )
168 161
 	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
169
-	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 
162
+	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
170 163
 
171 164
 	( colorize on state )
172 165
 	#42 [ .Mouse/state DEI #00 ! ] + .Screen/sprite DEO
... ...
@@ -187,8 +180,6 @@ BRK
187 180
 
188 181
 @on-control ( -> )
189 182
 
190
-	.Controller/key DEI #00 ! #01 JCN [ BRK ]
191
-
192 183
 	.Controller/key DEI #20 ! ,&no-toggle JCN
193 184
 		;on-frame
194 185
 		.Screen/vector DEI2 ;on-frame-paused == ,&swap JCN
... ...
@@ -197,6 +188,11 @@ BRK
197 188
 		.Screen/vector DEO2
198 189
 		&no-toggle
199 190
 
191
+	.Controller/button DEI #08 ! ,&no-reset JCN
192
+		BANK1 #1000 ;mclr JSR2
193
+		BANK2 #1000 ;mclr JSR2
194
+		&no-reset
195
+
200 196
 BRK
201 197
 
202 198
 @draw-grid ( -- )
... ...
@@ -210,10 +206,10 @@ BRK
210 206
 
211 207
 	HEIGHT #00
212 208
 	&ver
213
-		#00 OVR 2** .anchor/y LDZ2 ++ .Screen/y DEO2
209
+		DUP TOS 2** .anchor/y LDZ2 ++ .Screen/y DEO2
214 210
 		WIDTH #00
215 211
 		&hor
216
-			#00 OVR 2** .anchor/x LDZ2 ++ .Screen/x DEO2
212
+			DUP TOS 2** .anchor/x LDZ2 ++ .Screen/x DEO2
217 213
 			GET-ITER ,get-cell JSR INC .Screen/pixel DEO
218 214
 			INC GTHk ,&hor JCN
219 215
 		POP2
... ...
@@ -232,7 +228,7 @@ RTN
232 228
 @set-cell ( x y -- )
233 229
 	
234 230
 	DUP2 ,get-index JSR STH2
235
-	POP 8MOD #01 SWP SFL 
231
+	POP 8MOD #01 SWP SFL
236 232
 	LDAkr STHr SWP ORA
237 233
 	STH2r STA
238 234
 
... ...
@@ -249,12 +245,12 @@ RTN
249 245
 
250 246
 @get-cell ( x y -- cell )
251 247
 	
252
-	DUP2 ,get-index JSR LDA 
248
+	DUP2 ,get-index JSR LDA
253 249
 	NIP SWP
254 250
 	8MOD
255 251
 	SFT 2MOD
256 252
 
257
-RTN 
253
+RTN
258 254
 
259 255
 @get-neighbours ( x y -- neighbours )
260 256
 	
... ...
@@ -272,21 +268,47 @@ RTN
272 268
 
273 269
 @draw-short ( short* color -- )
274 270
 
275
-	;draw-char/color STA
276
-	SWP ,draw-byte JSR
271
+	STH
272
+	SWP STHkr ,draw-byte JSR
273
+	STHr
277 274
 
278
-@draw-byte ( byte -- )
275
+@draw-byte ( byte color -- )
279 276
 
280
-	DUP #04 SFT ,draw-char JSR
281
-	#0f AND
277
+	STH
278
+	DUP #04 SFT STHkr ,draw-hex JSR #0f AND
279
+	STHr
282 280
 
283
-@draw-char ( char -- )
281
+@draw-hex ( char color -- )
284 282
 
285
-	TOS 8** ;font-hex ++ .Screen/addr DEO2
286
-	[ LIT &color $1 ] .Screen/sprite DEO
283
+	SWP TOS 8** ;font-hex ++ .Screen/addr DEO2
284
+	.Screen/sprite DEO
287 285
 
288 286
 RTN
289 287
 
288
+@mclr ( addr* len* -- )
289
+
290
+	OVR2 ++ SWP2
291
+	&loop
292
+		STH2k #00 STH2r STA
293
+		INC2 GTH2k ,&loop JCN
294
+	POP2 POP2
295
+
296
+JMP2r
297
+
298
+@mcpy ( src* dst* len* -- )
299
+
300
+	SWP2 STH2
301
+	OVR2 ++ SWP2
302
+	&loop
303
+		LDAk STH2kr STA INC2r
304
+		INC2 GTH2k ,&loop JCN
305
+	POP2 POP2
306
+	POP2r
307
+
308
+JMP2r
309
+
310
+( input )
311
+
290 312
 @on-input ( -> )
291 313
 	,&main JSR
292 314
 	BRK
... ...
@@ -347,7 +369,7 @@ RTN
347 369
 	;on-input .Console/vector DEO2
348 370
 	BRK
349 371
 
350
-@cursor 
372
+@cursor
351 373
 	80c0 e0f0 f8e0 1000
352 374
 
353 375
 @font-hex