-
Notifications
You must be signed in to change notification settings - Fork 0
/
tet.tal
1254 lines (1106 loc) · 24.5 KB
/
tet.tal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
( fourtette, a block game by [email protected] )
( macros )
%MOD { DIVk MUL SUB }
%debug { #f4 .System/debug DEO }
%halt { #81 .System/halt DEO }
( devices )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|60 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|c0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
( variables )
|0000
|0010
( the piece controlled by the player )
@cur &type $1 &rot $1 &x $1 &y $1
( a virtual piece used to cur piece movement )
@test &type $1 &rot $1 &x $1 &y $1
( a virtual piece that sits where cur would drop )
@ghost &type $1 &rot $1 &x $1 &y $1
( the next pieces to enter the field )
@next $5
( the hold piece )
@hold &type $1 &ok $1
@score
&level $1
&lines $2
&points $2
@music-player
&which $1
&counter $1
&delay $1
&position $2
&length $2
&update $2
&treble1 $2
&treble2 $2
&bass $2
&drums $2
&drums-off $1
( program )
|0100 ( -> )
init-prng
;button/vector .Controller/vector DEO2
#0100 .Screen/width DEO2
#0100 .Screen/height DEO2
;theme/mono theme/set
init-title
BRK
@init-title ( -- )
;on-frame-title .Screen/vector DEO2
#00 ;on-frame-title/n STA
#00 .music-player/drums-off STZ
#01 .music-player/which STZ
music/init
JMP2r
@on-frame-title ( -> )
[ LIT &n $1 ] #84 EQU
?&anim-done
;costab #00 ,&n LDR ADD2 LDA ,&yoffs STR
,&n LDR INC ,&n STR
( clear )
#0000 .Screen/x DEO2 #0000 .Screen/y DEO2 #83 .Screen/pixel DEO
( draw image )
;title-image #0010 #0020 #00 [ LIT &yoffs $1 ] SUB2 draw-image
!&draw-done
&anim-done
( play music )
music/on-screen-audio
( draw "press start" )
#0054 #00e8 ;strings/start
#0d [ LIT &blink $1 ] #b0 LTH #03 MUL SUB draw-str
,&blink LDR INC ,&blink STR
&draw-done
#0c button/pressed ?&start
BRK
&start
menu
BRK
@menu
;&on-frame .Screen/vector DEO2
#00 ;&selected STA
#00 ;&start-level STA
#00 .music-player/drums-off STZ
.music-player/which LDZ ;&music-selection STA
( clear )
#0000 .Screen/x DEO2
#0000 .Screen/y DEO2
#c0 .Screen/pixel DEO
( boxes and bg )
;bg/grid-dot .Screen/addr DEO2
#0000 .Screen/x DEO2
#0000 .Screen/y DEO2
#20 #20 #03 draw-sprite-rect
;&level-x LDA2 .Screen/x DEO2
;&level-y LDA2 .Screen/y DEO2
;&level-w LDA ;&level-h LDA
#8a draw-box
;zero .Screen/addr DEO2
;&level-x LDA2 .Screen/x DEO2
;&level-y LDA2 .Screen/y DEO2
;&level-w LDA ;&level-h LDA
#01 draw-sprite-rect
;&music-x LDA2 .Screen/x DEO2
;&music-y LDA2 .Screen/y DEO2
;&music-w LDA ;&music-h LDA
#8a draw-box
;zero .Screen/addr DEO2
;&music-x LDA2 .Screen/x DEO2
;&music-y LDA2 .Screen/y DEO2
;&music-w LDA ;&music-h LDA
#01 draw-sprite-rect
JMP2r
&on-frame ( -> )
( play music )
music/on-screen-audio
( draw text )
#42 ;&selected LDA ADD ;&level-color STA
#43 ;&selected LDA SUB ;&music-color STA
;&level-x LDA2 #0008 ADD2
;&level-y LDA2 #0008 ADD2
;strings/level [ LIT &level-color 42 ] draw-str
;&level-x LDA2 #0040 ADD2
;&level-y LDA2 #0008 ADD2
#00 [ LIT &start-level $1 ] ,&level-color LDR draw-num
;&music-x LDA2 #0008 ADD2
;&music-y LDA2 #0008 ADD2
;strings/music [ LIT &music-color 43 ] draw-str
;&music-x LDA2 #0050 ADD2
;&music-y LDA2 #0008 ADD2
;&music-str #00 [ LIT &music-selection $1 ] #02 MUL ADD2 LDA2 ,&music-color LDR draw-str
( interaction )
#30 button/pressed ?&swap
#40 button/pressed ?&dec
#80 button/pressed ?&inc
#0c button/pressed ?&start
BRK
&swap
[ LIT &selected $1 ] INC #02 MOD ,&selected STR
BRK
&inc
,&selected LDR ?&inc-music
;&start-level LDA INC #15 MOD ;&start-level STA
BRK
&inc-music
;&music-selection LDA INC #04 MOD DUP
;&music-selection STA
.music-player/which STZ
music/init
BRK
&dec
,&selected LDR ?&dec-music
;&start-level LDA #14 ADD #15 MOD ;&start-level STA
BRK
&dec-music
;&music-selection LDA #03 ADD #04 MOD DUP
;&music-selection STA
.music-player/which STZ
music/init
BRK
&start
;&start-level LDA init-game
BRK
&level-x 0048
&level-y 0060
&level-w 0e
&level-h 03
&music-x 0048
&music-y 0090
&music-w 0e
&music-h 03
&music-str
=strings/off
=strings/a
=strings/b
=strings/c
@init-game ( level -- )
.score/level STZ
;on-frame-game .Screen/vector DEO2
#0000 .score/lines STZ2
#0000 .score/points STZ2
#01 .music-player/drums-off STZ
init-well
init-level
init-pieces
!draw-bg
@on-frame-game ( -> )
( press start to pause )
#08 button/pressed #00 EQU
?&no-pause
,&is-paused LDR #01 EOR ,&is-paused STR
&no-pause
[ LIT &is-paused $1 ]
?&draw
( play music )
music/on-screen-audio
.ghost clear-piece
.cur clear-piece
[ LIT &is-compact $1 ]
?&no-compact
compact-well ,&is-compact STR
!&update
&no-compact
( swap hold piece )
#04 button/pressed #00 EQU
?&no-hold
( only allow one swap per freeze )
[ LIT &hold-swapped $1 ]
?&no-hold
( put cur piece in hold )
#01 ,&hold-swapped STR
[ LIT ¬-held 01 ]
?&first-hold
( swap hold and cur )
;sfx-vol/hold LDA ;sfx/hold play-sample
init-cur-pos
.cur/type LDZ .hold/type LDZ .cur/type STZ .hold/type STZ
#00 ;&freeze-timer STA
!&update
( no piece held yet )
&first-hold
;sfx-vol/hold LDA ;sfx/hold play-sample
#00 ,¬-held STR
.cur/type LDZ .hold/type STZ
#01 .hold/ok STZ
#00 ;&freeze-timer STA
!&make-new-piece
&no-hold
.test .cur copy-piece
( handle rot change )
.cur/type LDZ #03 EQU ( b can't rotate )
?&rot-done
#01 button/pressed #03 MUL
#02 button/pressed
ADD
DUP #03 EQU ,&rot-anti STR
.cur/rot LDZ ADD #04 MOD
DUP .test/rot STZ .cur/rot LDZ EQU
?&rot-done
( try in place )
.test try-piece #00 EQU
?&rot-ok
( try kicks )
[ LIT &rot-anti $1 ] try-kick
?&rot-done
( rot changed )
&rot-ok
;sfx-vol/rot LDA ;sfx/rot play-sample
.cur .test copy-piece
#00 ;&freeze-timer STA
&rot-done
( handle x change )
#80 button/pressed ( right )
#40 button/pressed SUB ( left )
DUP .cur/x LDZ ADD .test/x STZ #00 EQU
?&no-x
.test try-piece
?&no-x
( x changed )
;sfx-vol/x LDA ;sfx/x play-sample
.cur .test copy-piece
#00 ;&freeze-timer STA
&no-x
( up button - hard drop )
#10 button/pressed #00 EQU
?&no-up
update-ghost
.cur .ghost copy-piece
!&freeze
&no-up
( gravity )
[ LIT &speed $1 ]
?&gravity-tick
( instant drop - like hard drop but don't freeze immediately )
update-ghost
.cur .ghost copy-piece
!&run-freeze-timer
( normal drop - descend 1 row every &speed frames )
&gravity-tick
[ LIT &tick $1 ] INC ,&speed LDR MOD DUP ,&tick STR #00 EQU
?&inc-y
( down button - soft drop )
#20 button/held
?&inc-y
[ LIT &freeze-timer $1 ]
?&run-freeze-timer
!&update
( try to increment y )
&inc-y
.test .cur copy-piece
.test/y LDZ INC .test/y STZ
.test try-piece
?&run-freeze-timer ( blocked )
( y changed )
.cur .test copy-piece
( ghost is unchanged )
!&update
( check if the freeze timer has expired )
&run-freeze-timer
,&freeze-timer LDR #1e GTH
?&freeze
,&freeze-timer LDR INC ,&freeze-timer STR
!&update
( freeze the current piece )
&freeze
;sfx-vol/freeze LDA ;sfx/freeze play-sample
freeze-cur-piece
#00 ,&freeze-timer STR
( create a new piece )
&make-new-piece
#00 ;&hold-swapped STA
new-piece
( if the new piece doesn't fit, die )
.cur try-piece
?&die
#00 ;&is-compact STA ( compact next frame )
( update the current piece and ghost )
&update
update-ghost
set-ghost-piece
set-cur-piece
!&draw
&die
init-game-over
&draw
draw-fg
BRK
@init-game-over
;on-frame-game-over .Screen/vector DEO2
#0280 ;on-frame-game-over/n STA2
;sfx-vol/game-over LDA ;sfx/tetris #28
!play-sample-note
@on-frame-game-over
[ LIT2 &n $2 ] #0140 LTH2
?&draw
,&n LDR2 #0002 SUB2 ,&n STR2
,&n LDR2 ;well ADD2
DUP #07 MOD #10 ORA
OVR INC #07 MOD #10 ORA
#00
,&n LDR2 #01d0 LTH2
,&n LDR2 #01f0 GTH2
EOR MUL2
SWP2 STA2
&draw
draw-fg
,&n LDR2 #01d0 GTH2
?&done
;pos/well-x LDA2 #0004 ADD2
;pos/well-y LDA2 #004d ADD2
;strings/game-over #41 draw-str
#0c button/pressed #00 EQU
?&done
music/init
menu
&done
BRK
@button
[ LIT &state $1 ]
&vector ( -> )
.Controller/button DEI DUP
,&state STR
[ LIT &debounce $1 ] AND ,&debounce STR
BRK
&held ( code -- held )
DUP ,&state LDR AND EOR #00 EQU
JMP2r
&pressed ( code -- pressed )
DUP ,&state LDR AND
?&pressed-debounce
¬-pressed
POP #00
JMP2r
&pressed-debounce
DUP
,&debounce LDR AND
?¬-pressed
,&debounce LDR ORA ,&debounce STR
#01
JMP2r
@init-pieces ( -- )
#00 &loop new-piece INC DUP #06 LTH ?&loop POP
JMP2r
@init-level ( -- )
#00 .score/level LDZ ;level-speeds ADD2 LDA
;on-frame-game/speed STA
JMP2r
@init-well ( -- )
;well &loop
DUP2 #0fff AND2 #027f GTH2
?&block
DUP #0f AND #03 LTH
?&block
DUP #0f AND #0c GTH
?&block
&space #00
!&store
&block #80
&store ROT ROT STAk ROT POP
INC2 DUP2 #0fff AND2 #0300 LTH2
?&loop
POP2
JMP2r
@compact-well ( -- noop )
#00 ;&lines STA
#00 ,&line-sum STR
;well INC2 INC2 &loop
INC2
DUP2 #0fff AND2 #027f GTH2
?&done
DUP #0f AND #0c GTH
?&eol
( sum block high nibble )
LDAk #04 SFT [ LIT &line-sum $1 ] ADD ,&line-sum STR
!&loop
&eol
,&line-sum LDR #14 EQU
?&hl-line
,&line-sum LDR #28 EQU
?&rem-line
!&cont
&hl-line
DUP2 #000a SUB2
&hl-block
DUP2 LDAk #8f AND #40 ORA ROT ROT STA
INC2 GTH2k
?&hl-block
,&lines LDR INC ,&lines STR
POP2
!&cont
&rem-line
remove-well-line
#00
JMP2r
&cont
#00 ,&line-sum STR
#0005 ADD2
!&loop
&done POP2
,&lines LDR
?&inc-score
#01
JMP2r
&inc-score
,&lines LDR #04 EQU
?&tetris
;sfx-vol/line LDA ;sfx/line play-sample
!&sfx-done
&tetris
;sfx-vol/tetris LDA ;sfx/tetris play-sample
&sfx-done
.score/lines LDZ2 ,&before-lines STR2
#00 [ LIT &lines $1 ] .score/lines LDZ2 ADD2 .score/lines STZ2
#00 ,&lines LDR DUP MUL .score/points LDZ2 ADD2 .score/points STZ2
.score/level LDZ #1e EQU
?&score-done
[ LIT2 &before-lines $2 ] #000a DIV2 .score/lines LDZ2 #000a DIV2 EQU2
?&score-done
.score/level LDZ INC .score/level STZ
init-level
&score-done
#00
JMP2r
@remove-well-line ( well-addr-on-line -- )
#fff0 AND2 #0010 ADD2 ( go to end of this line )
&loop
#0001 SUB2
( read block from line above )
DUP2k #0010 SUB2 LDA
( store block in current line )
ROT ROT STA
( see if we're done )
DUP2 #0fff AND2 #0010 GTH2
?&loop
POP2
JMP2r
@copy-piece ( dst src -- )
SWPk INC SWP INC
SWPk INC SWP INC
SWPk INC SWP INC
LDZ SWP STZ
LDZ SWP STZ
LDZ SWP STZ
LDZ SWP STZ
JMP2r
@init-cur-pos ( -- )
#06 .cur/x STZ
#11 .cur/y STZ
#00 .cur/rot STZ
JMP2r
@new-piece ( -- )
init-cur-pos
.next LDZ .cur/type STZ
#00 &loop
INCk .next ADD LDZ
OVR .next ADD STZ
INC DUP #04 LTH
?&loop
.next ADD
next-piece-type SWP STZ
JMP2r
@next-piece-type
[ LIT &len $1 ]
?&pop
( fill bag 0-6 )
;&bag #00 &fill
ROT ROT STAk
INC2 ROT INC DUP #07 LTH
?&fill
,&len STR POP2
( shuffle bag )
;&bag #07 shuffle
( pop type from bag )
&pop
,&len LDR #01 SUB DUP ,&len STR
#00 SWP ;&bag ADD2 LDA
JMP2r
[ &bag $7 ]
@set-piece ( piece val -- )
,&val STR
;&each !each-piece-block
&each ( well-offset -- )
;well ADD2 [ LIT &val $1 ] ROT ROT STA
JMP2r
@set-cur-piece ( -- )
.cur DUP LDZ #10 ORA !set-piece
@freeze-cur-piece ( -- )
.cur DUP LDZ #20 ORA !set-piece
@set-ghost-piece ( -- )
.ghost #07 !set-piece
@clear-piece ( -- )
#00 !set-piece
( tries to move cur to test, reports whether it failed )
@try-piece ( piece -- blocked )
#00 ,&blocked STR
;&each each-piece-block
,&blocked LDR
JMP2r
&each ( well-offset -- )
;well ADD2 LDA #e0 AND
[ LIT &blocked $1 ] ORA ,&blocked STR
JMP2r
( set ghost to cur, but at the bottom-most y point that fits )
@update-ghost
.ghost .cur copy-piece
&loop
.ghost/y LDZ INC .ghost/y STZ
.ghost try-piece #00 EQU
?&loop
.ghost/y LDZ #01 SUB .ghost/y STZ
JMP2r
( try all the kicks for the test piece for the given rotation,
leaves the test piece in a slot that fits )
@try-kick ( anti-clockwise -- blocked )
#00 SWP #30 SFT
#00 .test/type LDZ #00 EQU #60 SFT
#00 .test/rot LDZ #40 SFT
;kicks ADD2 ADD2 ADD2 ,&addr STR2
#00 ,&offs STR
&loop
[ LIT2 &addr $2 ] #00 [ LIT &offs $1 ] ADD2 INCk2
LDA .test/y LDZ ADD .test/y STZ
LDA .test/x LDZ ADD .test/x STZ
.test try-piece
?&next
#00 ( kick succeeded )
JMP2r
&next ( reset and try next kick, if any left )
.cur/x LDZ .test/x STZ
.cur/y LDZ .test/y STZ
,&offs LDR INC INC DUP ,&offs STR #08 LTH
?&loop
#01 ( all kicks blocked )
JMP2r
( return the bits that define a 4x4 piece
of the given type and rotation )
@piece-bits ( rot type -- piece-bits* )
#30 SFT ( type )
SWP DUP ADD ( rot )
ADD #00 SWP
;pieces ADD2 LDA2 ( piece16 )
JMP2r
@each-piece-block ( piece each-func* -- )
,&each-func STR2
LDZk ( type ) SWP INC LDZk ( rot )
SWP INC LDZk ( x ) SWP INC LDZ ( y )
#00 SWP #40 SFT2 ROT #00 SWP ADD2 ,&offset STR2
SWP piece-bits ;&each !each-piece-bits-block
&each
DUP #0c AND #02 SFT #40 SFT
SWP #03 AND ADD
#00 SWP [ LIT2 &offset $2 ] ADD2
[ LIT2 &each-func $2 ] JMP2
@each-piece-bits-block ( piece-bits* each-func* -- )
,&each-func STR2 ,&piece-bits STR2
( go backward from bottom-right, as we
consume piece-bits least-to-most significant )
#0f &loop
( test whether a piece block is at woffs )
[ LIT2 &piece-bits $2 ] NIP #01 AND #01 NEQ ?&no
DUP [ LIT2 &each-func $2 ] JSR2
&no
#01 SUB
( shift piece-bits right )
,&piece-bits LDR2 #01 SFT2 DUP2 ,&piece-bits STR2
( continue if there are more blocks )
ORA
?&loop
POP
JMP2r
( draw game state )
@pos
&well-x 0058
&well-y 0030
&well-w 0a
&well-h 14
&next-x 00b0
&next-y 0030
&next-w 06
&next-h 0f
&hold-x 00b0
&hold-y 00b0
&hold-w 06
&hold-h 04
&score-x 0020
&score-y 0030
&score-w 06
&score-h 08
@draw-fg
( clear )
#0000 .Screen/x DEO2
#0000 .Screen/y DEO2
#c0 .Screen/pixel DEO
draw-next
draw-hold
draw-score
;on-frame-game/is-paused LDA
?draw-pause
( clear well background here,
because draw-pause may have painted it )
;zero .Screen/addr DEO2
;pos/well-x LDA2 .Screen/x DEO2
;pos/well-y LDA2 .Screen/y DEO2
;pos/well-w LDA
;pos/well-h LDA
#01 draw-sprite-rect
!draw-well
@draw-pause
;bg/stripes .Screen/addr DEO2
;pos/well-x LDA2 .Screen/x DEO2
;pos/well-y LDA2 .Screen/y DEO2
;pos/well-w LDA
;pos/well-h LDA
#01 draw-sprite-rect
#006a #0080 ;strings/pause #41
!draw-str
@draw-next
#00 ,&n STR
&loop
;pos/next-x LDA2 #0008 ADD2
;pos/next-y LDA2 #000b ADD2 #0015 #00 ,&n LDR MUL2 ADD2
.next ,&n LDR ADD LDZ
draw-piece
[ LIT &n $1 ] INC DUP ,&n STR #05 LTH
?&loop
JMP2r
@draw-hold
.hold/ok LDZ #00 EQU
?&done
;pos/hold-x LDA2 #0008 ADD2
;pos/hold-y LDA2 #0009 ADD2
.hold/type LDZ
draw-piece
&done
JMP2r
( draw piece centered )
@draw-piece ( screen-x* screen-y* type -- )
,&type STR
#00 ,&type LDR #00 NEQ #20 SFT2 ADD2 ,&screen-y STR2
#00 ,&type LDR DUP #00 NEQ SWP #03 NEQ AND #20 SFT2 ADD2 ,&screen-x STR2
#00 ,&type LDR piece-bits ;&each !each-piece-bits-block
&each
DUP
#03 AND #30 SFT #00 SWP [ LIT2 &screen-x $2 ] ADD2 .Screen/x DEO2
#02 SFT #30 SFT #00 SWP [ LIT2 &screen-y $2 ] ADD2 .Screen/y DEO2
[ LIT &type $1 ] #10 ORA !draw-block
@draw-well ( -- )
;pos/well-x LDA2 .Screen/x DEO2
;pos/well-y LDA2 .Screen/y DEO2
#01 .Screen/auto DEO
;well #0142 ADD2 &loop
INC2
DUP2 #0fff AND2 #027f GTH2
?&done
DUP #0f AND #0c GTH
?&eol
LDAk draw-block
!&loop
&eol
.Screen/x DEI2 #0050 SUB2 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
#0005 ADD2
!&loop
&done POP2
JMP2r
@draw-block ( block-type -- )
DUP #77 AND
?&block
POP
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
JMP2r
&block
#07 AND #03 MUL #00 SWP ;piece-sprites ADD2
INC2k INC2 LDA ROT ROT LDA2
.Screen/addr DEO2
.Screen/sprite DEO
JMP2r
@draw-score ( -- )
;pos/score-x LDA2 #0004 ADD2
;pos/score-y LDA2 #000e ADD2
#00 .score/level LDZ
#41
draw-num
;pos/score-x LDA2 #0004 ADD2
;pos/score-y LDA2 #0022 ADD2
.score/lines LDZ2
#41
draw-num
;pos/score-x LDA2 #0004 ADD2
;pos/score-y LDA2 #0036 ADD2
.score/points LDZ2
#41
!draw-num
( backgrounds )
@draw-bg ( -- )
( background )
;bg/grid-dot .Screen/addr DEO2
#0000 .Screen/x DEO2
#0000 .Screen/y DEO2
#20 #20 #03 draw-sprite-rect
( main field )
;pos/well-x LDA2 .Screen/x DEO2
;pos/well-y LDA2 .Screen/y DEO2
;pos/well-w LDA
;pos/well-h LDA
#8a draw-box
( next piece )
;pos/next-x LDA2 .Screen/x DEO2
;pos/next-y LDA2 .Screen/y DEO2
;pos/next-w LDA
;pos/next-h LDA
#8a draw-box
;zero .Screen/addr DEO2
;pos/next-x LDA2 .Screen/x DEO2
;pos/next-y LDA2 .Screen/y DEO2
;pos/next-w LDA
;pos/next-h LDA
#01 draw-sprite-rect
;pos/next-x LDA2 #0008 ADD2
;pos/next-y LDA2 #0003 ADD2
;strings/next #02 draw-str
( hold piece )
;pos/hold-x LDA2 .Screen/x DEO2
;pos/hold-y LDA2 .Screen/y DEO2
;pos/hold-w LDA
;pos/hold-h LDA
#8a draw-box
;zero .Screen/addr DEO2
;pos/hold-x LDA2 .Screen/x DEO2
;pos/hold-y LDA2 .Screen/y DEO2
;pos/hold-w LDA
;pos/hold-h LDA
#01 draw-sprite-rect
;pos/hold-x LDA2 #0008 ADD2
;pos/hold-y LDA2 #0003 ADD2
;strings/hold #02 draw-str
( score )
;pos/score-x LDA2 .Screen/x DEO2
;pos/score-y LDA2 .Screen/y DEO2
;pos/score-w LDA
;pos/score-h LDA
#8a draw-box
;zero .Screen/addr DEO2
;pos/score-x LDA2 .Screen/x DEO2
;pos/score-y LDA2 .Screen/y DEO2
;pos/score-w LDA
;pos/score-h LDA
#01 draw-sprite-rect
;pos/score-x LDA2 #0004 ADD2
;pos/score-y LDA2 #0004 ADD2
;strings/level #02 draw-str
;pos/score-x LDA2 #0004 ADD2
;pos/score-y LDA2 #0018 ADD2
;strings/lines #02 draw-str
;pos/score-x LDA2 #0004 ADD2
;pos/score-y LDA2 #002c ADD2
;strings/score #02
!draw-str
@draw-box ( w h col -- )
;&col STA #30 SFT ;&h STA #30 SFT ;&w STA
.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
.Screen/y DEI2 #0008 SUB2 .Screen/y DEO2
( tl )
#01 .Screen/auto DEO
;border-chr/corner .Screen/addr DEO2
#00 draw-box/put
( top )
;border-chr/edge-hor .Screen/addr DEO2
#00 [ LIT &w $1 ] draw-box/putn
( tr )
#02 .Screen/auto DEO
;border-chr/corner .Screen/addr DEO2
#10 draw-box/put
( right )
;border-chr/edge-ver .Screen/addr DEO2
#10 [ LIT &h $1 ] draw-box/putn
( br )
;border-chr/corner .Screen/addr DEO2
#30 draw-box/put
( left )
.Screen/x DEI2 #00 ;&w LDA #08 ADD SUB2 .Screen/x DEO2
.Screen/y DEI2 #00 ;&h LDA #08 SUB SUB2 .Screen/y DEO2
;border-chr/edge-ver .Screen/addr DEO2
#00 ;&h LDA draw-box/putn
( bl )
#01 .Screen/auto DEO
;border-chr/corner .Screen/addr DEO2
#20 draw-box/put
( bottom )
;border-chr/edge-hor .Screen/addr DEO2
#20 ;&w LDA !draw-box/putn
&put ( flags -- )
[ LIT &col $1 ] ORA .Screen/sprite DEO
JMP2r
&putn ( n flags -- )
&wloop OVR ,&put JSR #08 SUB DUP ?&wloop
POP2
JMP2r
@draw-sprite-rect ( w h col -- )
;&col STA
SWP DUP ,&w STR
#00 SWP ROT #00 SWP MUL2
#01 .Screen/auto DEO
&loop
#0001 SUB2
[ LIT &col $1 ] .Screen/sprite DEO
DUP2 #0000 EQU2
?&done
DUP2 #00 [ LIT &w $1 ] DIV2k MUL2 SUB2 NIP
?&loop
&line
.Screen/x DEI2 #0008 #00 ;&w LDA MUL2 SUB2 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
!&loop
&done POP2
JMP2r
@draw-image ( addr* x* y* -- )
,&y STR2 ,&x STR2
LDAk ,&w STR INC LDAk ,&h STR INC
.Screen/addr DEO2
#05 .Screen/auto DEO
[ LIT2 &y $2 ] .Screen/y DEO2
[ LIT &h $1 ] &yloop
[ LIT2 &x $2 ] .Screen/x DEO2
[ LIT &w $1 ] &xloop
#81 .Screen/sprite DEO
#01 SUB DUP
?&xloop
POP
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
#01 SUB DUP
?&yloop
POP
JMP2r
( text )
@draw-str ( x* y* text* color -- )