Browse code

Progress on orca

neauoire authored on 10/04/2021 03:06:45
Showing 2 changed files
... ...
@@ -32,7 +32,7 @@ else
32 32
 fi
33 33
 
34 34
 echo "Assembling.."
35
-./bin/assembler projects/examples/dev.audio.usm bin/boot.rom
35
+./bin/assembler projects/software/nasu.usm bin/boot.rom
36 36
 
37 37
 echo "Running.."
38 38
 if [ "${2}" = '--cli' ]; 
... ...
@@ -3,7 +3,6 @@
3 3
 	TODO
4 4
 		- Synthax highlight
5 5
 		- B operating doesn't loop around
6
-		- Locking ports
7 6
 		- Detect capitalization
8 7
 		- Comments
9 8
 		- Scale selection
... ...
@@ -17,6 +16,23 @@
17 16
 %8* { #0008 MUL2 } %8/ { #0008 DIV2 }
18 17
 %MOD { DUP2 DIV MUL SUB }
19 18
 
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 )
35
+
20 36
 ( variables )
21 37
 
22 38
 ;timer { byte 1 frame 1 speed 1 }
... ...
@@ -29,7 +45,6 @@
29 45
 |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
30 46
 |0110 ;Console { pad 8 char 1 byte 1 short 2 }
31 47
 |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
32
-|0130 ;Sprite { vector 2 pad 6 x 2 y 2 addr 2 color 1 }
33 48
 |0140 ;Controller { vector 2 button 1 }
34 49
 |0150 ;Keys { vector 2 key 1 }
35 50
 |0160 ;Mouse  { vector 2 x 2 y 2 state 1 chord 1 }
... ...
@@ -71,7 +86,7 @@ BRK
71 86
 	
72 87
 	( skip ) ~Keys.key #00 NEQ ^$continue JNZ BRK $continue
73 88
 
74
-	~selection.x1 ~selection.y1 ~Keys.key ,put-char JSR2
89
+	~selection.x1 ~selection.y1 ~Keys.key SET-CELL
75 90
 
76 91
 	( release ) #00 =Keys.key
77 92
 
... ...
@@ -103,7 +118,7 @@ BRK
103 118
 
104 119
 	~Controller.button #04 NEQ ^$no-backspace JNZ
105 120
 		~Controller.button =Console.byte
106
-		~selection.x1 ~selection.y1 #2e ,put-char JSR2 ( put . char )
121
+		~selection.x1 ~selection.y1 #2e SET-CELL ( put . char )
107 122
 	$no-backspace
108 123
 
109 124
 	,redraw JSR2
... ...
@@ -119,20 +134,20 @@ BRK
119 134
 	$no-touch
120 135
 
121 136
 	( clear last cursor )
122
-	~cursor.x =Sprite.x
123
-	~cursor.y =Sprite.y
124
-	,blank_icn =Sprite.addr
125
-	#10 =Sprite.color
137
+	~cursor.x =Screen.x
138
+	~cursor.y =Screen.y
139
+	,blank_icn =Screen.addr
140
+	#30 =Screen.color
126 141
 
127 142
 	( record cursor positions )
128 143
 	~Mouse.x =cursor.x 
129 144
 	~Mouse.y =cursor.y
130 145
 
131 146
 	( draw new cursor )
132
-	~cursor.x =Sprite.x
133
-	~cursor.y =Sprite.y
134
-	,cursor_icn =Sprite.addr
135
-	#12 ~Mouse.state #01 EQU ADD =Sprite.color
147
+	~cursor.x =Screen.x
148
+	~cursor.y =Screen.y
149
+	,cursor_icn =Screen.addr
150
+	#32 ~Mouse.state #01 EQU ADD =Screen.color
136 151
 	
137 152
 BRK
138 153
 
... ...
@@ -143,7 +158,7 @@ BRK
143 158
 		#00 ~grid.width
144 159
 		$hor
145 160
 			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
146
-			#2e ,put-char JSR2
161
+			#2e SET-CELL
147 162
 			( incr )    SWP #01 ADD SWP
148 163
 			DUP2 LTH ^$hor JNZ
149 164
 		POP2
... ...
@@ -161,25 +176,19 @@ RTN
161 176
 
162 177
 RTN
163 178
 
164
-@put-char (x y char -- )
179
+@set-lock ( x y flag -- )
165 180
 	
166
-	ROT ROT  
167
-
168
-	#00 SWP #00 ~grid.width MUL2
169
-
170
-	ROT #00 SWP ADD2 ,data ADD2 POK2
181
+	ROT ROT GET-OFFSET GRID-LOCKS ADD2 POK2
171 182
 
172 183
 RTN
173 184
 
174
-@get-char ( x y -- char )
185
+@get-lock ( x y -- flag )
175 186
 	
176
-	#00 SWP #00 ~grid.width MUL2
177
-
178
-	ROT #00 SWP ADD2 ,data ADD2 PEK2
187
+	GET-OFFSET GRID-LOCKS ADD2 PEK2
179 188
 
180 189
 RTN
181 190
 
182
-@get-char-value ( char -- value )
191
+@get-cell-value ( char -- value )
183 192
 	
184 193
 	#00 SWP ,values ADD2 PEK2
185 194
 
... ...
@@ -193,13 +202,13 @@ RTN
193 202
 
194 203
 @get-value ( x y -- value )
195 204
 	
196
-	,get-char JSR2 #20 SUB ,get-char-value JSR2
205
+	GET-CELL #20 SUB ,get-cell-value JSR2
197 206
 
198 207
 RTN
199 208
 
200
-@get-char-sprite ( x y -- addr )
209
+@get-cell-sprite ( x y -- addr )
201 210
 	
202
-	DUP2 ,get-char JSR2 
211
+	DUP2 GET-CELL 
203 212
 	( if character is dot )
204 213
 	DUP #2e NEQ ^$no-bar JNZ
205 214
 		( check if x,y is grid )
... ...
@@ -223,7 +232,7 @@ RTN
223 232
 	( incr y ) #01 ADD 
224 233
 	( get result ) ADDr STHr
225 234
 	,get-value-char JSR2 
226
-	,put-char JSR2
235
+	SET-CELL
227 236
 
228 237
 RTN
229 238
 
... ...
@@ -235,7 +244,7 @@ RTN
235 244
 	( incr y ) #01 ADD 
236 245
 	( get result ) SUBr STHr 
237 246
 	,get-value-char JSR2 
238
-	,put-char JSR2
247
+	SET-CELL
239 248
 
240 249
 RTN
241 250
 
... ...
@@ -243,7 +252,7 @@ RTN
243 252
 	
244 253
 	POP
245 254
 	#01 ADD
246
-	#30 ~timer.frame #08 MOD ADD ,put-char JSR2
255
+	#30 ~timer.frame #08 MOD ADD SET-CELL
247 256
 
248 257
 RTN
249 258
 
... ...
@@ -312,19 +321,16 @@ RTN
312 321
 	STH
313 322
 	( limit )
314 323
 	DUP #00 NEQ ^$not-edge JNZ
315
-		#2a ,put-char JSR2
316
-		POP STHr
317
-		RTN
324
+		#2a SET-CELL POP STHr RTN 
318 325
 	$not-edge
319 326
 	( collide )
320
-	DUP2 #01 SUB ,get-char JSR2 #2e EQU ^$not-collide JNZ
321
-		#2a ,put-char JSR2
322
-		POP STHr
323
-		RTN
327
+	DUP2 #01 SUB GET-CELL #2e EQU ^$not-collide JNZ
328
+		#2a SET-CELL POP STHr RTN
324 329
 	$not-collide
330
+	( move )
325 331
 	DUP2 STHr
326
-	SWP #01 SUB SWP ,put-char JSR2	
327
-	#2e ,put-char JSR2
332
+	SWP #01 SUB SWP SET-CELL	
333
+	#2e SET-CELL
328 334
 	
329 335
 RTN
330 336
 
... ...
@@ -354,10 +360,10 @@ RTN
354 360
 
355 361
 @op-s ( x y char -- )
356 362
 	
357
-	STH DUP2 STHr
358
-	SWP #01 ADD SWP ,put-char JSR2	
359
-	#2e ,put-char JSR2
360
-	( TODO: Lock )
363
+	STH 
364
+	( clear ) DUP2 #2e SET-CELL
365
+	( move ) #01 ADD DUP2 #01 ,set-lock JSR2
366
+	STHr SET-CELL
361 367
 	
362 368
 RTN
363 369
 
... ...
@@ -381,7 +387,19 @@ RTN
381 387
 
382 388
 @op-w ( x y char -- )
383 389
 
384
-	POP POP2
390
+	STH
391
+	( limit )
392
+	OVR #00 NEQ ^$not-edge JNZ
393
+		#2a SET-CELL POP STHr RTN 
394
+	$not-edge
395
+	( collide )
396
+	DUP2 SWP #01 SUB SWP GET-CELL #2e EQU ^$not-collide JNZ
397
+		#2a SET-CELL POP STHr RTN
398
+	$not-collide
399
+	( move )
400
+	DUP2 
401
+	SWP #01 SUB SWP STHr SET-CELL	
402
+	#2e SET-CELL
385 403
 	
386 404
 RTN
387 405
 
... ...
@@ -403,8 +421,26 @@ RTN
403 421
 	
404 422
 RTN
405 423
 
424
+@op-bang ( x y char -- )
425
+
426
+	POP
427
+	#2e SET-CELL
428
+
429
+RTN
430
+
406 431
 @run-char ( x y char -- )
407 432
 	
433
+	( skip dot )
434
+	DUP #2e NEQ ^$not-dot JNZ
435
+		POP POP2 RTN
436
+	$not-dot
437
+
438
+	( skip locked )
439
+	ROT ROT DUP2 ,get-lock JSR2 #00 EQU ^$not-locked JNZ
440
+		POP POP2 RTN 
441
+	$not-locked
442
+	ROT
443
+
408 444
 	( A ) DUP #41 EQU ,op-a JNZ2
409 445
 	( B ) DUP #42 EQU ,op-b JNZ2
410 446
 	( C ) DUP #43 EQU ,op-c JNZ2
... ...
@@ -418,7 +454,7 @@ RTN
418 454
 	( K ) DUP #4b EQU ,op-k JNZ2
419 455
 	( L ) DUP #4c EQU ,op-l JNZ2
420 456
 	( M ) DUP #4d EQU ,op-m JNZ2
421
-	( N ) DUP #4e EQU ,op-n JNZ2
457
+	( N ) DUP #4e EQU ,op-n JNZ2 ( done. )
422 458
 	( O ) DUP #4f EQU ,op-o JNZ2
423 459
 	( P ) DUP #50 EQU ,op-p JNZ2
424 460
 	( Q ) DUP #51 EQU ,op-q JNZ2
... ...
@@ -427,23 +463,42 @@ RTN
427 463
 	( T ) DUP #54 EQU ,op-t JNZ2
428 464
 	( U ) DUP #55 EQU ,op-u JNZ2
429 465
 	( V ) DUP #56 EQU ,op-v JNZ2
430
-	( W ) DUP #57 EQU ,op-w JNZ2
466
+	( W ) DUP #57 EQU ,op-w JNZ2 ( done. )
431 467
 	( X ) DUP #58 EQU ,op-x JNZ2
432 468
 	( Y ) DUP #59 EQU ,op-y JNZ2
433 469
 	( Z ) DUP #5a EQU ,op-z JNZ2
470
+	( * ) DUP #2a EQU ,op-bang JNZ2
434 471
 	POP POP2
435 472
 
436 473
 RTN
437 474
 
438
-@run
475
+@init ( -- )
439 476
 	
440 477
 	#00 ~grid.height
441 478
 	$ver
442 479
 		#00 ~grid.width
443 480
 		$hor
444
-			( get x,y ) SWP2 OVR STH SWP2 OVR STHr DUP2 
445
-			,get-char JSR2 
446
-			,run-char JSR2 
481
+			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
482
+			( unlock ) #00 ,set-lock JSR2
483
+			( incr ) SWP #01 ADD SWP
484
+			DUP2 LTH ^$hor JNZ
485
+		POP2
486
+		( incr ) SWP #01 ADD SWP
487
+		DUP2 LTH ^$ver JNZ
488
+	POP2
489
+
490
+RTN
491
+
492
+@run ( -- )
493
+	
494
+	,init JSR2
495
+
496
+	#00 ~grid.height
497
+	$ver
498
+		#00 ~grid.width
499
+		$hor
500
+			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
501
+			DUP2 GET-CELL ,run-char JSR2
447 502
 			( incr )    SWP #01 ADD SWP
448 503
 			DUP2 LTH ^$hor JNZ
449 504
 		POP2
... ...
@@ -456,60 +511,60 @@ RTN
456 511
 
457 512
 @draw-interface ( -- )
458 513
 	
459
-	~Screen.height #0008 SUB2 =Sprite.y
514
+	~Screen.height #0008 SUB2 =Screen.y
460 515
 
461 516
 	( Positionx )
462
-	#0000 =Sprite.x
517
+	#0000 =Screen.x
463 518
 	~selection.x1 
464
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
465
-	#02 =Sprite.color
466
-	#0008 =Sprite.x
467
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
468
-	#02 =Sprite.color
519
+		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
520
+	#22 =Screen.color
521
+	#0008 =Screen.x
522
+		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
523
+	#22 =Screen.color
469 524
 
470 525
 	( Positiony )
471
-	#0010 =Sprite.x
526
+	#0010 =Screen.x
472 527
 	~selection.y1 
473
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
474
-	#02 =Sprite.color
475
-	#0018 =Sprite.x
476
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
477
-	#02 =Sprite.color
528
+		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
529
+	#22 =Screen.color
530
+	#0018 =Screen.x
531
+		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
532
+	#22 =Screen.color
478 533
 
479
-	#0020 =Sprite.x
480
-	,position_icn =Sprite.addr
481
-	#03 =Sprite.color
534
+	#0020 =Screen.x
535
+	,position_icn =Screen.addr
536
+	#23 =Screen.color
482 537
 
483 538
 	( Frame )
484
-	#0030 =Sprite.x
539
+	#0030 =Screen.x
485 540
 	~timer.frame 
486
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
487
-	#02 =Sprite.color
488
-	#0038 =Sprite.x
489
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
490
-	#02 =Sprite.color
541
+		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
542
+	#22 =Screen.color
543
+	#0038 =Screen.x
544
+		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
545
+	#22 =Screen.color
491 546
 
492
-	#0040 =Sprite.x
493
-	,beat_icn =Sprite.addr
494
-	#01 ~timer.frame #08 MOD #00 EQU #02 MUL ADD =Sprite.color
547
+	#0040 =Screen.x
548
+	,beat_icn =Screen.addr
549
+	#21 ~timer.frame #08 MOD #00 EQU #02 MUL ADD =Screen.color
495 550
 
496 551
 	( Speed )
497
-	#0050 =Sprite.x
552
+	#0050 =Screen.x
498 553
 	~timer.speed 
499
-		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
500
-	#02 =Sprite.color
501
-	#0058 =Sprite.x
502
-		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr
503
-	#02 =Sprite.color
554
+		DUP #04 SFT ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
555
+	#22 =Screen.color
556
+	#0058 =Screen.x
557
+		#0f AND ,get-value-char JSR2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
558
+	#22 =Screen.color
504 559
 
505 560
 	( TODO: Signal VU )
506 561
 
507 562
 	( File )
508
-	~Screen.width #0028 SUB2 =Sprite.x
509
-	~Sprite.x 8+ =Sprite.x ,eye_icns =Sprite.addr #01 =Sprite.color
510
-	~Sprite.x 8+ =Sprite.x ,filestate_icn =Sprite.addr #01 =Sprite.color
511
-	~Sprite.x 8+ =Sprite.x ,load_icn =Sprite.addr #01 =Sprite.color
512
-	~Sprite.x 8+ =Sprite.x ,save_icn =Sprite.addr #01 =Sprite.color
563
+	~Screen.width #0028 SUB2 =Screen.x
564
+	~Screen.x 8+ =Screen.x ,eye_icns =Screen.addr #21 =Screen.color
565
+	~Screen.x 8+ =Screen.x ,filestate_icn =Screen.addr #21 =Screen.color
566
+	~Screen.x 8+ =Screen.x ,load_icn =Screen.addr #21 =Screen.color
567
+	~Screen.x 8+ =Screen.x ,save_icn =Screen.addr #21 =Screen.color
513 568
 
514 569
 RTN
515 570
 
... ...
@@ -517,13 +572,13 @@ RTN
517 572
 	
518 573
 	#00 ~grid.height
519 574
 	$ver
520
-		( pos-y ) OVR #00 SWP #0008 MUL2 =Sprite.y
575
+		( pos-y ) OVR #00 SWP #0008 MUL2 =Screen.y
521 576
 		#00 ~grid.width
522 577
 		$hor
523
-			( pos-x )   OVR #00 SWP #0008 MUL2 =Sprite.x 
578
+			( pos-x )   OVR #00 SWP #0008 MUL2 =Screen.x 
524 579
 			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
525
-			( sprite )  DUP2 ,get-char-sprite JSR2 =Sprite.addr
526
-			( draw )    ,is-selected JSR2 #0d MUL #01 ADD =Sprite.color
580
+			( sprite )  DUP2 ,get-cell-sprite JSR2 =Screen.addr
581
+			( draw )    ,is-selected JSR2 #0d MUL #21 ADD =Screen.color
527 582
 			( incr )    SWP #01 ADD SWP
528 583
 			DUP2 LTH ^$hor JNZ
529 584
 		POP2