Browse code

Add RLE text import to life.tal

Andrew Alderwick authored on 26/11/2021 22:29:20
Showing 1 changed files
... ...
@@ -22,6 +22,7 @@
22 22
 
23 23
 %WIDTH { #40 }   %HEIGHT { #40 }
24 24
 %WIDTH-MOD { #3f AND }   %HEIGHT-MOD { #3f AND }
25
+%IN-RANGE { INCk SWP SUB2 GTH }
25 26
 
26 27
 %BANK1 { #8000 } %BANK2 { #a000 }
27 28
 
... ...
@@ -32,6 +33,7 @@
32 33
 ( devices )
33 34
 
34 35
 |00 @System     [ &vector $2 &wst      $1 &rst    $1 &pad   $4 &r      $2 &g     $2 &b      $2 ]
36
+|10 @Console    [ &vector $2 &read $1 &pad    $5 &write $1 &error  $1 ]
35 37
 |20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y      $2 &addr  $2 &pixel $1 &sprite $1 ]
36 38
 |30 @Audio0     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
37 39
 |80 @Controller [ &vector $2 &button   $1 &key    $1 ]
... ...
@@ -44,6 +46,7 @@
44 46
 @world   [ &frame $1 &count $2 ]
45 47
 @anchor  [ &x $2 &y $2 ]
46 48
 @pointer [ &x $2 &y $2 ]
49
+@rle     [ &x $1 &y $1 &n $1 ]
47 50
 
48 51
 ( program )
49 52
 
... ...
@@ -55,6 +58,7 @@
55 58
 	#024f .System/b DEO2
56 59
 
57 60
 	( vectors )
61
+	;on-input   .Console/vector DEO2
58 62
 	;on-frame   .Screen/vector DEO2
59 63
 	;on-mouse   .Mouse/vector DEO2
60 64
 	;on-control .Controller/vector DEO2
... ...
@@ -229,6 +233,15 @@ RTN
229 233
 
230 234
 RTN
231 235
 
236
+@unset-cell ( x y -- )
237
+	
238
+	DUP2 ,get-index JSR STH2
239
+	POP 8MOD #01 SWP SFL #ff EOR
240
+	LDAkr STHr SWP AND
241
+	STH2r STA
242
+
243
+RTN
244
+
232 245
 @get-cell ( x y -- cell )
233 246
 	
234 247
 	DUP2 ,get-index JSR LDA 
... ...
@@ -269,6 +282,67 @@ RTN
269 282
 
270 283
 RTN
271 284
 
285
+@on-input ( -> )
286
+	,&main JSR
287
+	BRK
288
+
289
+	&main
290
+	.Console/read DEI #20 GTH JMP JMP2r ( ignore whitespace )
291
+	.Console/read DEI LIT 'b EQU ,unset-run JCN
292
+	.Console/read DEI LIT 'o EQU ,set-run JCN
293
+	.Console/read DEI LIT '$ EQU ,input-eol JCN
294
+	.Console/read DEI LIT '! EQU ,input-eop JCN
295
+	LIT2 '0 '9 .Console/read DEI IN-RANGE ,input-number JCN
296
+	#44 .Console/write DEO
297
+	;on-ignore-until-eol .Console/vector DEO2
298
+	JMP2r
299
+
300
+@unset-run ( -- )
301
+	;unset-cell ,run JMP ( tail call )
302
+
303
+@set-run ( -- )
304
+	;set-cell ( fall through )
305
+
306
+@run ( cell-fn* -- )
307
+	STH2
308
+	;on-frame-paused .Screen/vector DEO2
309
+	.rle/n LDZk #00 ROT STZ
310
+	DUP #00 NEQ JMP INC
311
+	&loop ( count / cell-fn* )
312
+		DUP #00 EQU ,&end JCN
313
+		.rle/x LDZ .rle/y LDZ STH2kr JSR2
314
+		.rle/x LDZk INC SWP STZ
315
+		#01 SUB
316
+		,&loop JMP
317
+	&end
318
+	POP POP2r
319
+	JMP2r
320
+
321
+@input-number ( -- )
322
+	.rle/n LDZk #0a MUL
323
+		.Console/read DEI LIT '0 SUB
324
+		ADD SWP STZ
325
+	JMP2r
326
+
327
+@input-eol ( -- )
328
+	WIDTH .rle/x LDZ SUB .rle/n STZ
329
+	,unset-run JSR
330
+	#00 .rle/x STZ
331
+	.rle/y LDZk INC SWP STZ
332
+	JMP2r
333
+
334
+@input-eop ( -- )
335
+	,input-eol JSR
336
+	HEIGHT .rle/y LDZ GTH ,input-eop JCN
337
+	;on-frame .Screen/vector DEO2
338
+	#00 .rle/y STZ
339
+	BRK
340
+
341
+@on-ignore-until-eol ( -> )
342
+	.Console/read DEI #0a EQU JMP BRK
343
+	;on-input .Console/vector DEO2
344
+	BRK
345
+
272 346
 @cursor 
273 347
 	80c0 e0f0 f8e0 1000
274 348