Browse code

Progress on orca

neauoire authored on 13/04/2021 04:16:31
Showing 2 changed files
... ...
@@ -12,26 +12,29 @@
12 12
 )
13 13
 
14 14
 %RTN { JMP2r }
15
+%++ { #01 ADD } %-- { #01 SUB }
15 16
 %8+ { #0008 ADD2 }
16 17
 %8* { #0008 MUL2 } %8/ { #0008 DIV2 }
17 18
 %MOD { DUP2 DIV MUL SUB }
18 19
 
19
-%GRID-CELLS { #2000 }
20
-%GRID-LOCKS { #3000 }
21
-%GRID-TYPES { #4000 }
22
-
23
-%GET-OFFSET {
24
-	#00 SWP #00 ~grid.width MUL2 ROT #00 SWP ADD2
25
-} ( x y -- offset* )
26
-%GET-INDEX { 
27
-	GET-OFFSET GRID-CELLS ADD2 
28
-} ( x y -- index* )
29
-%SET-CELL { 
30
-	ROT ROT GET-INDEX POK2 
31
-} ( x y char -- )
32
-%GET-CELL { 
33
-	GET-INDEX PEK2 
34
-} ( x y -- char )
20
+%DATA-CELLS { #2000 }
21
+%DATA-LOCKS { #3000 }
22
+%DATA-TYPES { #4000 }
23
+
24
+%GET-CHAR { #24 MOD #00 SWP ,b36clc ADD2 PEK2 } ( b36 -- char )
25
+%GET-VALUE { #20 SUB #00 SWP ,values ADD2 PEK2 } ( char -- b36 )
26
+
27
+%GET-INDEX { #00 SWP #00 ~grid.width MUL2 ROT #00 SWP ADD2 } ( x y -- index )
28
+%GET-CELL { GET-INDEX DATA-CELLS ADD2 PEK2 } ( x y -- char )
29
+%SET-CELL { ROT ROT GET-INDEX DATA-CELLS ADD2 POK2 } ( x y char -- )
30
+%GET-TYPE { GET-INDEX DATA-TYPES ADD2 PEK2 } ( x y -- type )
31
+%SET-TYPE { ROT ROT GET-INDEX DATA-TYPES ADD2 POK2 } ( x y type -- )
32
+%GET-LOCK { GET-INDEX DATA-TYPES ADD2 PEK2 } ( x y -- type )
33
+%SET-LOCK { ROT ROT GET-INDEX DATA-TYPES ADD2 POK2 } ( x y type -- )
34
+%GET-PORT { } ( x y lock -- char )
35
+%SET-PORT { } ( x y char -- )
36
+
37
+%GET-CELL-VALUE { GET-CELL GET-VALUE } ( x y -- b36 )
35 38
 
36 39
 ( variables )
37 40
 
... ...
@@ -68,11 +71,11 @@ BRK
68 71
 
69 72
 @on-frame
70 73
 
71
-	~timer #01 ADD DUP =timer
74
+	~timer ++ DUP =timer
72 75
 
73 76
 	( skip ) #08 EQU ^$tick JNZ BRK $tick
74 77
 
75
-	~timer.frame #01 ADD =timer.frame
78
+	~timer.frame ++ =timer.frame
76 79
 
77 80
 	,run JSR2
78 81
 
... ...
@@ -91,20 +94,20 @@ BRK
91 94
 	~Controller.button #f0 AND
92 95
 		DUP #04 SFT #01 AND #01 NEQ ^$no-up JNZ 
93 96
 			~selection.y1 #00 EQU ^$no-up JNZ
94
-			~selection.y1 #01 SUB =selection.y1 
95
-			~selection.y2 #01 SUB =selection.y2 $no-up
97
+			~selection.y1 -- =selection.y1 
98
+			~selection.y2 -- =selection.y2 $no-up
96 99
 		DUP #05 SFT #01 AND #01 NEQ ^$no-down JNZ 
97
-			~selection.y1 ~grid.height #01 SUB EQU ^$no-down JNZ
98
-			~selection.y1 #01 ADD =selection.y1 
99
-			~selection.y2 #01 ADD =selection.y2 $no-down
100
+			~selection.y1 ~grid.height -- EQU ^$no-down JNZ
101
+			~selection.y1 ++ =selection.y1 
102
+			~selection.y2 ++ =selection.y2 $no-down
100 103
 		DUP #06 SFT #01 AND #01 NEQ ^$no-left JNZ 
101 104
 			~selection.x1 #00 EQU ^$no-left JNZ
102
-			~selection.x1 #01 SUB =selection.x1 
103
-			~selection.x2 #01 SUB =selection.x2 $no-left
105
+			~selection.x1 -- =selection.x1 
106
+			~selection.x2 -- =selection.x2 $no-left
104 107
 		DUP #07 SFT #01 AND #01 NEQ ^$no-right JNZ 
105
-			~selection.x1 ~grid.width #01 SUB EQU ^$no-right JNZ
106
-			~selection.x1 #01 ADD =selection.x1 
107
-			~selection.x2 #01 ADD =selection.x2 $no-right
108
+			~selection.x1 ~grid.width -- EQU ^$no-right JNZ
109
+			~selection.x1 ++ =selection.x1 
110
+			~selection.x2 ++ =selection.x2 $no-right
108 111
 	POP
109 112
 
110 113
 	~Controller.key #08 NEQ ^$no-backspace JNZ
... ...
@@ -149,10 +152,10 @@ BRK
149 152
 		$hor
150 153
 			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
151 154
 			#2e SET-CELL
152
-			( incr )    SWP #01 ADD SWP
155
+			( incr )    SWP ++ SWP
153 156
 			DUP2 LTH ^$hor JNZ
154 157
 		POP2
155
-		( incr ) SWP #01 ADD SWP
158
+		( incr ) SWP ++ SWP
156 159
 		DUP2 LTH ^$ver JNZ
157 160
 	POP2
158 161
 
... ...
@@ -160,39 +163,28 @@ BRK
160 163
 
161 164
 RTN
162 165
 
163
-@is-selected ( x y -- flag )
164
-	
165
-	~selection.x1 ~selection.y1 EQU2
166
+( operations )
166 167
 
168
+@get-bang ( x y -- bang )
167 169
 RTN
168 170
 
169
-@set-lock ( x y flag -- )
170
-	
171
-	ROT ROT GET-OFFSET GRID-LOCKS ADD2 POK2
171
+( old )
172 172
 
173
-RTN
174
-
175
-@get-lock ( x y -- flag )
176
-	
177
-	GET-OFFSET GRID-LOCKS ADD2 PEK2
178
-
179
-RTN
180
-
181
-@get-cell-value ( char -- value )
173
+@is-selected ( x y -- flag )
182 174
 	
183
-	#00 SWP ,values ADD2 PEK2
184
-
185
-RTN
175
+	~selection.x1 ~selection.y1 EQU2
186 176
 
187
-@get-value-char ( value -- char )
188
-	
189
-	#24 MOD #00 SWP ,b36clc ADD2 PEK2
190
-	
191 177
 RTN
192 178
 
193
-@get-value ( x y -- value )
179
+@get-port ( x y lock -- value )
194 180
 	
195
-	GET-CELL #20 SUB ,get-cell-value JSR2
181
+	(
182
+	DUP #01 NEQ ^$no-lock JNZ
183
+		DUP2 #01 SET-LOCK
184
+	$no-lock
185
+	STH DUP2 #02 #02 STHr MUL ADD ,set-type JSR2
186
+	GET-CELL
187
+	)
196 188
 
197 189
 RTN
198 190
 
... ...
@@ -217,11 +209,11 @@ RTN
217 209
 @op-a ( x y char -- )
218 210
 
219 211
 	POP
220
-	( get left ) DUP2 SWP #01 SUB SWP ,get-value JSR2 STH
221
-	( get right ) DUP2 SWP #01 ADD SWP ,get-value JSR2 STH
222
-	( incr y ) #01 ADD 
212
+	( get left ) DUP2 SWP -- SWP GET-CELL-VALUE STH
213
+	( get right ) DUP2 SWP ++ SWP GET-CELL-VALUE STH
214
+	( incr y ) ++ 
223 215
 	( get result ) ADDr STHr
224
-	,get-value-char JSR2 
216
+	GET-CHAR 
225 217
 	SET-CELL
226 218
 
227 219
 RTN
... ...
@@ -229,11 +221,12 @@ RTN
229 221
 @op-b ( x y char -- )
230 222
 	
231 223
 	POP
232
-	( get left ) DUP2 SWP #01 SUB SWP ,get-value JSR2 STH
233
-	( get right ) DUP2 SWP #01 ADD SWP ,get-value JSR2 STH
234
-	( incr y ) #01 ADD 
224
+	( get left ) DUP2 SWP -- SWP GET-CELL-VALUE STH
225
+	( get right ) DUP2 SWP ++ SWP GET-CELL-VALUE STH
226
+	( incr y ) ++ 
235 227
 	( get result ) SUBr STHr 
236
-	,get-value-char JSR2 
228
+	DUP =Console.byte
229
+	GET-CHAR 
237 230
 	SET-CELL
238 231
 
239 232
 RTN
... ...
@@ -241,7 +234,7 @@ RTN
241 234
 @op-c ( x y char -- )
242 235
 	
243 236
 	POP
244
-	#01 ADD
237
+	++
245 238
 	#30 ~timer.frame #08 MOD ADD SET-CELL
246 239
 
247 240
 RTN
... ...
@@ -314,12 +307,12 @@ RTN
314 307
 		#2a SET-CELL POP STHr RTN 
315 308
 	$not-edge
316 309
 	( collide )
317
-	DUP2 #01 SUB GET-CELL #2e EQU ^$not-collide JNZ
310
+	DUP2 -- GET-CELL #2e EQU ^$not-collide JNZ
318 311
 		#2a SET-CELL POP STHr RTN
319 312
 	$not-collide
320 313
 	( move )
321 314
 	DUP2 STHr
322
-	SWP #01 SUB SWP SET-CELL	
315
+	SWP -- SWP SET-CELL	
323 316
 	#2e SET-CELL
324 317
 	
325 318
 RTN
... ...
@@ -352,7 +345,7 @@ RTN
352 345
 	
353 346
 	STH 
354 347
 	( clear ) DUP2 #2e SET-CELL
355
-	( move ) #01 ADD DUP2 #01 ,set-lock JSR2
348
+	( move ) ++ DUP2 #01 SET-LOCK
356 349
 	STHr SET-CELL
357 350
 	
358 351
 RTN
... ...
@@ -383,12 +376,12 @@ RTN
383 376
 		#2a SET-CELL POP STHr RTN 
384 377
 	$not-edge
385 378
 	( collide )
386
-	DUP2 SWP #01 SUB SWP GET-CELL #2e EQU ^$not-collide JNZ
379
+	DUP2 SWP -- SWP GET-CELL #2e EQU ^$not-collide JNZ
387 380
 		#2a SET-CELL POP STHr RTN
388 381
 	$not-collide
389 382
 	( move )
390 383
 	DUP2 
391
-	SWP #01 SUB SWP STHr SET-CELL	
384
+	SWP -- SWP STHr SET-CELL	
392 385
 	#2e SET-CELL
393 386
 	
394 387
 RTN
... ...
@@ -426,37 +419,24 @@ RTN
426 419
 	$not-dot
427 420
 
428 421
 	( skip locked )
429
-	ROT ROT DUP2 ,get-lock JSR2 #00 EQU ^$not-locked JNZ
422
+	ROT ROT DUP2 GET-LOCK #00 EQU ^$not-locked JNZ
430 423
 		POP POP2 RTN 
431 424
 	$not-locked
432 425
 	ROT
433 426
 
434
-	( A ) DUP #41 EQU ,op-a JNZ2
435
-	( B ) DUP #42 EQU ,op-b JNZ2
436
-	( C ) DUP #43 EQU ,op-c JNZ2
437
-	( D ) DUP #44 EQU ,op-d JNZ2
438
-	( E ) DUP #45 EQU ,op-e JNZ2
439
-	( F ) DUP #46 EQU ,op-f JNZ2
440
-	( G ) DUP #47 EQU ,op-g JNZ2
441
-	( H ) DUP #48 EQU ,op-h JNZ2
442
-	( I ) DUP #49 EQU ,op-i JNZ2
443
-	( J ) DUP #4a EQU ,op-j JNZ2
444
-	( K ) DUP #4b EQU ,op-k JNZ2
445
-	( L ) DUP #4c EQU ,op-l JNZ2
446
-	( M ) DUP #4d EQU ,op-m JNZ2
447
-	( N ) DUP #4e EQU ,op-n JNZ2 ( done. )
448
-	( O ) DUP #4f EQU ,op-o JNZ2
449
-	( P ) DUP #50 EQU ,op-p JNZ2
450
-	( Q ) DUP #51 EQU ,op-q JNZ2
451
-	( R ) DUP #52 EQU ,op-r JNZ2
452
-	( S ) DUP #53 EQU ,op-s JNZ2
453
-	( T ) DUP #54 EQU ,op-t JNZ2
454
-	( U ) DUP #55 EQU ,op-u JNZ2
455
-	( V ) DUP #56 EQU ,op-v JNZ2
456
-	( W ) DUP #57 EQU ,op-w JNZ2 ( done. )
457
-	( X ) DUP #58 EQU ,op-x JNZ2
458
-	( Y ) DUP #59 EQU ,op-y JNZ2
459
-	( Z ) DUP #5a EQU ,op-z JNZ2
427
+	( A ) DUP #41 EQU ,op-a JNZ2 ( B ) DUP #42 EQU ,op-b JNZ2
428
+	( C ) DUP #43 EQU ,op-c JNZ2 ( D ) DUP #44 EQU ,op-d JNZ2
429
+	( E ) DUP #45 EQU ,op-e JNZ2 ( F ) DUP #46 EQU ,op-f JNZ2
430
+	( G ) DUP #47 EQU ,op-g JNZ2 ( H ) DUP #48 EQU ,op-h JNZ2
431
+	( I ) DUP #49 EQU ,op-i JNZ2 ( J ) DUP #4a EQU ,op-j JNZ2
432
+	( K ) DUP #4b EQU ,op-k JNZ2 ( L ) DUP #4c EQU ,op-l JNZ2
433
+	( M ) DUP #4d EQU ,op-m JNZ2 ( N ) DUP #4e EQU ,op-n JNZ2 
434
+	( O ) DUP #4f EQU ,op-o JNZ2 ( P ) DUP #50 EQU ,op-p JNZ2
435
+	( Q ) DUP #51 EQU ,op-q JNZ2 ( R ) DUP #52 EQU ,op-r JNZ2
436
+	( S ) DUP #53 EQU ,op-s JNZ2 ( T ) DUP #54 EQU ,op-t JNZ2
437
+	( U ) DUP #55 EQU ,op-u JNZ2 ( V ) DUP #56 EQU ,op-v JNZ2
438
+	( W ) DUP #57 EQU ,op-w JNZ2 ( X ) DUP #58 EQU ,op-x JNZ2
439
+	( Y ) DUP #59 EQU ,op-y JNZ2 ( Z ) DUP #5a EQU ,op-z JNZ2
460 440
 	( * ) DUP #2a EQU ,op-bang JNZ2
461 441
 	POP POP2
462 442
 
... ...
@@ -469,11 +449,11 @@ RTN
469 449
 		#00 ~grid.width
470 450
 		$hor
471 451
 			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
472
-			( unlock ) #00 ,set-lock JSR2
473
-			( incr ) SWP #01 ADD SWP
452
+			( unlock ) #00 SET-LOCK
453
+			( incr ) SWP ++ SWP
474 454
 			DUP2 LTH ^$hor JNZ
475 455
 		POP2
476
-		( incr ) SWP #01 ADD SWP
456
+		( incr ) SWP ++ SWP
477 457
 		DUP2 LTH ^$ver JNZ
478 458
 	POP2
479 459
 
... ...
@@ -489,10 +469,10 @@ RTN
489 469
 		$hor
490 470
 			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
491 471
 			DUP2 GET-CELL ,run-char JSR2
492
-			( incr )    SWP #01 ADD SWP
472
+			( incr )    SWP ++ SWP
493 473
 			DUP2 LTH ^$hor JNZ
494 474
 		POP2
495
-		( incr ) SWP #01 ADD SWP
475
+		( incr ) SWP ++ SWP
496 476
 		DUP2 LTH ^$ver JNZ
497 477
 	POP2
498 478
 	,redraw JSR2
... ...
@@ -506,19 +486,19 @@ RTN
506 486
 	( Positionx )
507 487
 	#0000 =Screen.x
508 488
 	~selection.x1 
509
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
489
+		DUP #04 SFT GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
510 490
 	#22 =Screen.color
511 491
 	#0008 =Screen.x
512
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
492
+		#0f AND GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
513 493
 	#22 =Screen.color
514 494
 
515 495
 	( Positiony )
516 496
 	#0010 =Screen.x
517 497
 	~selection.y1 
518
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
498
+		DUP #04 SFT GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
519 499
 	#22 =Screen.color
520 500
 	#0018 =Screen.x
521
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
501
+		#0f AND GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
522 502
 	#22 =Screen.color
523 503
 
524 504
 	#0020 =Screen.x
... ...
@@ -528,10 +508,10 @@ RTN
528 508
 	( Frame )
529 509
 	#0030 =Screen.x
530 510
 	~timer.frame 
531
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
511
+		DUP #04 SFT GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
532 512
 	#22 =Screen.color
533 513
 	#0038 =Screen.x
534
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
514
+		#0f AND GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
535 515
 	#22 =Screen.color
536 516
 
537 517
 	#0040 =Screen.x
... ...
@@ -541,10 +521,10 @@ RTN
541 521
 	( Speed )
542 522
 	#0050 =Screen.x
543 523
 	~timer.speed 
544
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
524
+		DUP #04 SFT GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
545 525
 	#22 =Screen.color
546 526
 	#0058 =Screen.x
547
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
527
+		#0f AND GET-CHAR #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
548 528
 	#22 =Screen.color
549 529
 
550 530
 	( TODO: Signal VU )
... ...
@@ -569,10 +549,10 @@ RTN
569 549
 			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
570 550
 			( sprite )  DUP2 ,get-cell-sprite JSR2 =Screen.addr
571 551
 			( draw )    ,is-selected JSR2 #0d MUL #21 ADD =Screen.color
572
-			( incr )    SWP #01 ADD SWP
552
+			( incr )    SWP ++ SWP
573 553
 			DUP2 LTH ^$hor JNZ
574 554
 		POP2
575
-		( incr ) SWP #01 ADD SWP
555
+		( incr ) SWP ++ SWP
576 556
 		DUP2 LTH ^$ver JNZ
577 557
 	POP2
578 558
 
... ...
@@ -270,7 +270,7 @@ walktoken(char *w)
270 270
 	case ',': return 3;                                                       /* lit2 addr-hb addr-lb */
271 271
 	case '.': return 2;                                                       /* addr-hb addr-lb */
272 272
 	case '^': return 2;                                                       /* Relative jump: lit addr-offset */
273
-	case '#': return (slen(w + 1) == 2 ? 2 : 3);
273
+	case '#': return (slen(w + 1) == 4 ? 3 : 2);
274 274
 	}
275 275
 	if((m = findmacro(w))) {
276 276
 		int i, res = 0;
... ...
@@ -332,10 +332,12 @@ parsetoken(char *w)
332 332
 		pushshort(findlabeladdr(w + 1), 1);
333 333
 		l->refs++;
334 334
 		return 1;
335
-	} else if(w[0] == '#' && sihx(w + 1)) {
336
-		if(slen(w + 1) == 2)
335
+	} else if(w[0] == '#') {
336
+		if(slen(w + 1) == 1)
337
+			pushbyte((Uint8)w[1], 1);
338
+		if(sihx(w + 1) && slen(w + 1) == 2)
337 339
 			pushbyte(shex(w + 1), 1);
338
-		else if(slen(w + 1) == 4)
340
+		else if(sihx(w + 1) && slen(w + 1) == 4)
339 341
 			pushshort(shex(w + 1), 1);
340 342
 		else
341 343
 			return 0;