-
Notifications
You must be signed in to change notification settings - Fork 16
/
Worms.forth
2118 lines (1772 loc) · 134 KB
/
Worms.forth
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
\ WORMS? COPYRIGHT (C) 1983 BY DAVID S. MAYNARD
( MASTER OCT. 9, 1983. COMMODORE 64 FINAL ) HEX
C000 CONSTANT HIMEM HIMEM 1000 - CONSTANT APMAREA
0 VARIABLE FNCUR 0 VARIABLE CHCUR
CODE (?CH)
C6 LDA, 0= NOT IF, 277 LDA, THEN, PUSH0A JMP, END-CODE
HERE 0 C, 8 C, 4 C, 2 C, 1 C, 0 C, 84 - CONSTANT CV84-
: ?CH BEGIN (?CH)
DUP IF DUP 84 MAX 89 MIN CV84- + C@
-DUP IF FNCUR ! ELSE DUP CHCUR ! THEN
FLKBD THEN
DROP (?CH) 0= UNTIL CHCUR @ ;
: KEY BEGIN CHCUR @ 0= WHILE ?CH DROP REPEAT
CHCUR @ 0 CHCUR ! ;
: =KEY SWAP OVER = IF KEY = ELSE DROP 0 THEN ;
: ?TERMINAL ?CH DROP FNCUR @ 0 FNCUR ! DUP 8 = IF QUIT THEN ; ;S
( WORM GAME START ) HEX
: <-> CONSTANT ; : < U< ;
: VAR VARIABLE ;
14 <-> #H 16 <-> #V 12 <-> #DH 12 <-> #DV 1 <-> H0 1 <-> V0
#DH 2 / <-> STX
#DV 2 / <-> STY
0 <-> W# 0 <-> 2*W#
0 VAR QFLG
: STOP ?TERMINAL QFLG @ OR
DUP QFLG ! ;
: CONT STOP 0= ;
400 <-> C64SCR
( WORM GAME CONSTANTS )
4 <-> MAX#W #H 1 - <-> #H-1
#V 1 - <-> #V-1 FF <-> UNDFMOVE
#DH 1 - <-> #DH-1
#DV 1 - <-> #DV-1
F1 <-> GETNEW# F2 <-> DOAI# F3 <-> DIE#
6 <-> NOMOVE
3 VAR DEN ( DENSITY )
0 VAR #WORMS
0 VAR WORMV 1 VAR GPR
C VAR MXLUM 07 VAR STO
1 <-> PWDTH
0 VAR HCSHI
0 VAR LOCK ( INTERLOCK FOR FORTH VBI ! IN UPDMAP )
( LOCKED IN UPDMAP CHECKED IN CDEST2 )
( WORM GAME CONSTANTS CONT. ATARI HDW )
( FIRST 1 + 800 / 800 * 800 - )
( 02E5 @ C1F - ) APMAREA \ DUP <-> PMA
200 - DUP <-> WCHSET ( FITS! )
#H #V * - <-> WDATA
( D40A <-> WSYNC ) E4 <-> MAXPOT
\ 022F <-> DMACTL D01D <-> GRACTL
\ D407 <-> PMBASE
\ 2C8 <-> COLBK 2C4 <-> COLPF0
\ 2C5 <-> COLPF1 2C6 <-> COLPF2
\ 2C7 <-> COLPF3 2C0 <-> COLPM0
\ 2C1 <-> COLPM1 2C2 <-> COLPM2
\ 2C3 <-> COLPM3 26F <-> GPRIOR
\ D300 <-> PORTA 0270 <-> POT0
\ D40E <-> NMIEN ;S
;S
( MOVE COUNT DOWN TIMERS )
\ D201 <-> AUDC D200 <-> AUDF
\ D208 <-> AUDCTL 1 VAR VBION
\ HERE
\ 0 , 0 , 0 , 0 ,
\ <-> FRQT ( FREQ. TABLE )
HERE
0 , 0 , 0 , 0 ,
<-> CDT ( COUNT DOWN TIMERS )
CODE DECCDT ( DECREMENT CDT )
0 # LDA,
CDT ,X CMP, 0= NOT
IF, CDT ,X DEC, THEN,
RTS, END-CODE
;S
( MAP VBI TABLES AND CONTS )
\ HERE
\ 7 , 7 , 7 , 7 ,
\ <-> CDT ( MOVE CDTIMERS )
HERE
0 , 0 , 0 , 0 ,
<-> MAPCDT ( MAP CD TIMER )
HERE
0 , 0 , 0 , 0 ,
<-> MAPMOVE ( MOVE ARRY )
CODE DECMAP ( DECREMENT CDT )
0 # LDA,
MAPCDT ,X CMP, 0= NOT
IF, MAPCDT ,X DEC, THEN,
RTS, END-CODE
;S
;S ( INTERRUPT ROUTINES UPDHS)
0 VAR HPSHAD 4 ALLOT
CODE UPDHS ( UPD HRZ POS )
HPSHAD LDA, D000 STA,
HPSHAD 1 + LDA, D001 STA,
HPSHAD 2 + LDA, D002 STA,
HPSHAD 3 + LDA, D003 STA,
RTS, END-CODE
( : CTABLE <BUILDS !CSP 3 HERE )
( 0 , DOES> 2+ ; )
( : ENDTAB HERE OVER - 2 - SWAP ! )
( 3 ?PAIRS ?CSP ; )
( : TAB# 2 - @ ; )
( : WTABLE <BUILDS !CSP 3 HERE )
( 0 , DOES> 2+ ; )
;S
;S ( INTERRUPT ROUTINES SETVOL )
HERE
A5 C, A7 C, A6 C, A6 C, A5 C, A5 C, A5 C, A4 C,
A4 C, A3 C, A2 C, A1 C, A0 C, A0 C, A0 C, A0 C,
A8 C, A7 C, A6 C, A6 C, A5 C, A4 C, A3 C, A3 C,
A4 C, A3 C, A2 C, A1 C, A0 C, A0 C, A0 C, A0 C,
A6 C, A8 C, A7 C, A6 C, A5 C, A4 C, A3 C, A2 C,
A2 C, A1 C, A0 C, A0 C, A0 C, A0 C, A0 C, A0 C,
A6 C, A8 C, A6 C, A4 C, A3 C, A2 C, A1 C, A0 C,
A0 C, A0 C, A0 C, A0 C, A0 C, A0 C, A0 C, A0 C,
<-> ENV
;S
;S ( PMXTAB SETVOL )
CODE SETVOL ( SETVOLUME )
CDT ,X LDA, 0= IF, 0 # LDA,
AUDC ,X STA, FRQT ,X STA,
ELSE, STO LDA, SEC,
CDT ,X SBC, F # AND, F8 STA, TXA,
.A ASL, .A ASL, .A ASL, CLC, F8 ADC, CLC,
TAY, ENV ,Y LDA,
( F # AND, A0 # ORA, )
AUDC ,X STA,
( FRQT ,X LDA, AUDF ,X STA, )
( 0 # LDA, AUDCTL STA, )
THEN, CLC, RTS, END-CODE ;S
CTABLE PMXTAB 3C C, 64 C, 8C C, B4 C,
ENDTAB
;S
;S ( INTERRUPT DAMPPOT )
0 VAR CPOT 4 ALLOT
CODE DAMPPOT ( DAMP POT )
CPOT ,X LDA, SEC,
POT0 ,X CMP,
CS IF, SEC, POT0 ,X SBC,
.A LSR, .A LSR, SEC,
FF # EOR, CLC, CPOT ,X ADC,
CPOT ,X STA, ELSE,
POT0 ,X LDA, SEC,
CPOT ,X SBC, .A LSR, .A LSR, .A LSR,
CLC, CPOT ,X ADC,
CPOT ,X STA,
THEN,
CLC, RTS, END-CODE
;S
;S ( INTERRUPT ROUTINES RPOTS )
0 VAR WPOT 2 ALLOT 0 VAR PSCAN
( CODE RPOT ( READ POT )
( ' DAMPPOT JSR, )
( E6 # LDA, SEC, CPOT ,X SBC, )
( .A LSR, .A LSR, .A LSR, )
( 7 # AND, 6 # CMP, BCS, )
( IF, 5 # LDA, THEN, )
( WPOT ,X STA, CLC, RTS, END-CODE )
CODE RPOTS ( READ POTS )
PSCAN LDA, 0= NOT IF,
0 # LDX, BEGIN,
' DAMPPOT JSR,
INX, 4 # CPX, 0=
UNTIL, CLC, THEN, RTS, END-CODE
;S
( WORM PRIMITIVES .XPOS ETC )
CODE .XPOS ' C@ JMP, END-CODE
CODE SET1 1 # LDA, SETUP JSR, RTS, END-CODE
CODE .YPOS ' SET1 JSR, 01 # LDY, N )Y LDA, PUSH0A JMP, END-CODE
CODE N)Y@ N )Y LDA, PHA, INY, N )Y LDA, PUSH JMP, END-CODE
CODE .LOC ' SET1 JSR, 02 # LDY, ' N)Y@ JMP, END-CODE
CODE .#MOVES ' SET1 JSR, 04 # LDY, ' N)Y@ JMP, END-CODE
CODE .STATUS ' SET1 JSR, 06 # LDY, ' .YPOS 5 + JMP, END-CODE
CODE .WRM# ' SET1 JSR, 07 # LDY, ' .YPOS 5 + JMP, END-CODE
CODE .MOVE 0B # LDA, ' A0+ JSR, BOT LDA, BOT 1+ LDY, INX, INX,
' AY+ JSR, ' C@ JMP, END-CODE
CODE +C! BOT LDA, INX, INX, ' A0+ JSR, ' C! JMP, END-CODE
: !XPOS ( WORM XPOS ) SWAP C! ;
: !YPOS SWAP 1+ C! ;
: !LOC SWAP 2+ ! ;
: !#MOVES SWAP 4 + ! ; ;S
( WORM PRIMITIVES CONT )
CODE .HPOS ' SET1 JSR, 08 # LDY, ' .YPOS 5 + JMP, END-CODE
: !HPOS ( WORM HPOS )
SWAP 8 +C! ;
CODE .VPOS ' SET1 JSR, 09 # LDY, ' .YPOS 5 + JMP, END-CODE
: !VPOS SWAP 9 +C! ;
CODE .CRIX ' SET1 JSR, 0A # LDY, ' .YPOS 5 + JMP, END-CODE
: !CRIX SWAP A +C! ;
: .TMO 4C + @ ;
: !TMO SWAP 4C + ! ;
;S
( #BITS WAIT )
\ : ENDIF [COMPILE] THEN ; IMMEDIATE
: #BITS ( BYTE -> #BITS )
0 OVER 1 AND IF 1+ ENDIF
OVER 2 AND IF 1+ ENDIF
OVER 4 AND IF 1+ ENDIF
OVER 8 AND IF 1+ ENDIF
OVER 10 AND IF 1+ ENDIF
OVER 20 AND IF 1+ ENDIF SWAP
DROP ;
: WAIT ( TICKS -> ) JIFFYS ;
\ DECIMAL 89 92 HEX THRU DECIMAL 138 140 HEX THRU
\ 0 220 ! FF 22E C! 1 MAX
\ 220 ! BEGIN 22E C@ 0= UNTIL
\ ;
;S
( WORM PRIMITIVES CNT WAITTAB )
: !STATUS SWAP 6 + C! ;
: !WORM# SWAP 7 + C! ;
: !MOVE ( WORM N MOVE )
SWAP ROT B + + C! ;
: .VAL .LOC C@ ;
: !VAL ( W VAL ) 2DUP SWAP .LOC C! 64!VAL ;
: [.VAL] .VAL 3F AND ; \ MASK OFF COLOR
( : CWAITTAB <BUILDS )
( 2 C, 2 C, 2 C, 2 C, 2 C, )
( 2 C, 2 C, DOES> ; )
( CWAITTAB WAITTAB )
;S
( WORM PRIMITIVES CONT )
: .KIND 4B + C@ ;
: !KIND SWAP 4B + C! ;
: .SCORE 4C + @ ;
: !SCORE SWAP 4C + ! ;
: .NAME 4E + ;
\ : 2* DUP + ; EAFORTH 2* IS FASTER
: 3* DUP 2* + ;
: 4* 2* 2* ;
: 8* 4* 2* ; ( : 28* DUP 4* + 8* ; )
D3 <-> COLCRS D6 <-> ROWCRS
: X! COLCRS C! ; : X@ COLCRS @ ;
: Y! DUP ROWCRS C! 28* C64SCR + D1 ! ; : Y@ ROWCRS C@ ;
: XY! Y! X! ; : ^ 1 0 XY! ;
: P" 0 14 XY! 1 286 C! ( WHITE ) ; ;S
;S
( WORM TABLE BUILDERS )
HERE
3 C, 4 C, 5 C, 0 C, 1 C, 2 C,
<-> NMOVE
HERE
1 , 0 , -1 , -1 , -1 , 0 ,
<-> XINCE
HERE
1 , 1 , 0 , -1 , 0 , 1 ,
<-> XINCO
HERE
0 , 1 , 1 , 0 , -1 , -1 ,
<-> YINC
;S
( ZERO PAGE DEFS )
0A <-> ZF 0C <-> ZT 0E <-> ZM
04 <-> ZA 06 <-> ZB 08 <-> ZC
;S
HERE 0 C, 0 C, 00 C, 0 C, 0 C, 00 C,
0 C, 0 C, 00 C, 3 C, C0 C, 00 C,
3 C, C0 C, 00 C, 0 C, 0 C, 00 C,
0 C, 0 C, 00 C, 0 C, 0 C, 00 C,
0 C, 0 C, 00 C, 0 C, 0 C, 00 C,
F C, F0 C, 00 C, F C, F0 C, 00 C,
F C, F0 C, 00 C, F C, F0 C, 00 C,
0 C, 0 C, 00 C, 0 C, 0 C, 00 C,
0 C, 0 C, 00 C, 3F C, FC C, 00 C,
3F C, FC C, 00 C, 3F C, FC C, 00 C,
3F C, FC C, 00 C, 3F C, FC C, 00 C,
3F C, FC C, 00 C, 0 C, 0 C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, FC C, 3F C, 00 C,
FC C, 3F C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
F0 C, F C, 00 C, F0 C, F C, 00 C,
F0 C, F C, 00 C, F0 C, F C, 00 C,
FF C, FF C, 00 C, FF C, FF C, 00 C,
FF C, FF C, 00 C, C0 C, 3 C, 00 C,
C0 C, 3 C, 00 C, C0 C, 3 C, 00 C,
C0 C, 3 C, 00 C, C0 C, 3 C, 00 C,
C0 C, 3 C, 00 C, FF C, FF C, 00 C,
0 C, 0 C, 00 C, 0 C, 0 C, 00 C,
0 C, 0 C, 00 C, 0 C, 0 C, 00 C,
0 C, 0 C, 00 C, 0 C, 0 C, 00 C,
0 C, 0 C, 00 C, 0 C, 0 C, 00 C, <-> MAPMASK
( ANONB CR*24 )
0 VAR ANONB ( ANIMATION ON )
: ANON 1 ANONB ! ;
HERE CRMAP 00 + , CRMAP 18 + , CRMAP 30 + ,
CRMAP 48 + , CRMAP 60 + , CRMAP 78 + ,
CRMAP 90 + , CRMAP A8 + ,
<-> CR*24
( INTERRUPT CRMAP ROUTINES )
CRMAP VAR CRMADDR
CODE CSOURCE ( FIND ZF ADDR )
MAPMOVE ,X LDA,
.A ASL, TAY,
CR*24 ,Y LDA, ZF STA, INY,
CR*24 ,Y LDA, ZF 1+ STA, INY,
RTS, END-CODE
: GCMD WCHSET 3 + @ IF 0 WCHSET 3 + C! ELSE
8 WCHSET 3 + C! THEN ;
HERE MAPMASK 00 + , MAPMASK 18 + , MAPMASK 30 + ,
MAPMASK 48 + , MAPMASK 60 + , MAPMASK 78 + ,
MAPMASK 90 + , MAPMASK A8 + , <-> MM*24 ;S
( CDEST CCANDM VBISMASK VBIMASKTAB )
MAPMASK VAR MMADDR 0 VAR VBISMASK 1 VAR VBIMAPMASK
HERE ( PAIRS: MASKVAL , STOVAL )
0 C, 2 C, 0 C, 04 C, 0 C, 06 C,
0 C, 8 C, 0 C, 0C C, 0 C, 10 C,
1 C, 10 C, 3 C, C C, 7 C, 10 C, F C, 10 C, <-> VBIMASKT
CODE CDEST2
SPMEM ,X LDA, ZT STA,
SPMEM 1+ ,X LDA, ZT 1+ STA,
RTS, END-CODE
CODE CANDM ( AND MASK ADDR )
8 # LDA, SEC, MAPCDT ,X SBC,
.A ASL, TAY,
MM*24 ,Y LDA, ZM STA, INY,
MM*24 ,Y LDA, ZM 1+ STA, INY,
CLC, RTS, END-CODE ;S
( INTRPT CODE CHAR ANIMATION )
CRMAP 7 8 * + <-> SRCBASE 14 <-> CLKLO
WCHSET 3F 8 * + <-> DESTBAS
: ANOFF 0 ANONB ! ; ;S 8 0 DO
SRCBASE I + C@ DESTBAS I +
C! LOOP ;
;S CODE ANIM
ANONB LDA, 0= NOT IF, CLKLO LDA, 3 # AND, 0= IF,
CLKLO LDA, 1C # AND,
.A ASL, TAY,
7 # LDX, BEGIN,
SRCBASE ,X LDA,
MAPMASK ,Y AND, DESTBAS ,X
STA, DEX, INY, FF # CPX,
0= UNTIL, THEN,
THEN, CLC, RTS, END-CODE ;S
( WRTP )
CODE WRTP ( WRITE PLAYERS ) LOCK LDA, 0= IF,
17 # LDY, BEGIN,
ZF )Y LDA, ZM )Y AND,
ZT )Y STA,
DEY, FF # CPY, 0=
UNTIL, THEN, CLC, RTS, END-CODE ;S
( INTERRUPT ROUTINES VBI )
CODE VBI ( VERTICAL BLANK )
( CLKLO LDA, VBISMASK AND, 0= IF, ' VBISND JSR, THEN, )
( ' ANIM JSR, )
( ' RPOTS JSR, ) CLKLO LDA,
VBIMAPMASK AND, 0= IF,
0 # LDX, BEGIN,
MAPCDT ,X LDA, 0= NOT IF,
' CSOURCE JSR, ' CDEST2 JSR,
' CANDM JSR, ' WRTP JSR,
' DECMAP JSR, THEN,
' DECCDT JSR, INX, INX,
8 # CPX, 0= UNTIL,
THEN, ( ' UPDHS JSR, ) CLC,
RTS, END-CODE ( SYS VBI RETURN)
;S
( ?SPEED ?SPEED2 CNFRM )
: RANGE 1+ >R OVER R> < >R 1- > R> AND ;
: ACMD ANONB @ IF ANOFF ELSE ANON THEN ;
: (?SPEED2)
KEY 39 SWAP - 2* VBIMASKT + DUP C@ DUP VBISMASK C!
1 MAX VBIMAPMASK C! 1+ C@ STO ! ;
: ?SPEED
?CH -DUP IF
30 39 RANGE
IF (?SPEED2) THEN THEN ;
: PROMPT2 P" C64SCR 14 28* + 28 20 FILL ;
: CNFRM KEY D = DUP IF ELSE PROMPT2 THEN ; ;S
( TRIG AND FREQ TABLES CRMAP .GWADR MOVE8 )
HERE
04 C, 08 C, 40 C, 80 C,
<-> TRIGMASK
: ?START \ 0 4 0 DO I TRIGMASK +
\ C@ PORTA C@ AND 0= OR LOOP
?TERMINAL 7 AND ( OR ) ;
: ?CLEAR BEGIN ?START 0= UNTIL
;
: MOVE18 ( FROM TO )
18 CMOVE ;
;S
( UPDCRLOC )
: UPDCRLOC ( WORM )
DUP .XPOS 8* 4 +
OVER
.YPOS 1 AND IF 4 + ENDIF
2DUP !HPOS
( W# HPSHAD + C! ) DROP
DUP .YPOS 8* 2E + !VPOS ;
;S
( UPDMAP UPDMV ZRMAP ZMAP )
: ZRMAP ( 2*W# -> )
0 OVER MAPCDT + !
SPMEM + @ 18 0 FILL ;
: ZMAP ( W ) DROP 2*W# ZRMAP ;
: UPDMAP ( W ) 2*W# ZRMAP
DUP .VPOS SWAP .HPOS 2* W#
YXSPRITE 7 MAPCDT 2*W# + !
STO C@ CDT 2*W# + ! ;
: UPDMV ( W )
2*W#
( DUP MAPCDT + 4 SWAP ! )
MAPMOVE +
SWAP .CRIX SWAP ! ; ;S
( WORM BUILDERS CWORM GWORM )
HERE 0 , 0 , 0 , 0 , <-> WORMS
: GWORM ( N -> WORM ) DUP + WORMS + @ ;
: INITWORM ( ADDR --> )
>R R #WORMS @ DUP + WORMS + !
R STX !XPOS R STY !YPOS R 0 !LOC R 0 !#MOVES
R 1 !STATUS R #WORMS @ !WORM# R 0 !HPOS R 0 !VPOS R 6 !CRIX
R 40 0 DO DUP I GETNEW# !MOVE LOOP DROP
R 0 !KIND R 0 !SCORE R> .NAME >R
53 R C! 41 R 1+ C! 4D R 2+ C! 45 R 3 + C!
R 8 4 DO DUP I + 20 SWAP C! LOOP DROP
R> DROP 1 #WORMS +! ;
( KILLW ) HEX 97 97 THRU
: KILLW ( WORM -> ) DROP TKILLW ; ;S
( 0 VBION ! ) A !CRIX
XSND \ .WRM# COLPF0 +
FF 50 DO A 0 DO NOOP LOOP
\ 120 I - 10 / OVER C@ F0 AND OR
\ OVER C!
I I 50 - 0 MAX DO
5 F FFFF I >< - ROVR SOUND 8 +LOOP
STOP IF LEAVE ENDIF
8 +LOOP
\ 5 OVER C@ F0 AND OR SWAP C!
XSND ( 1 VBION ! ) ;
;S
( UPDSTATUS )
: UPDSTATUS ( WORM )
DUP .STATUS
IF DUP [.VAL] 3F =
IF DUP KILLW 0 !STATUS
ELSE 1 !STATUS ENDIF
ELSE DROP ENDIF ;
;S
( UPDLOC UPDCOL TRIGCLR )
: UPDLOC ( WORM )
DUP .XPOS OVER .YPOS #H * +
WDATA + !LOC ;
CODE 40* BOT LDA, CLC, .A ROR, .A ROR, .A ROR,
BOT STA, CLC, NEXT JMP, END-CODE
: UPDCOL ( WORM )
DUP [.VAL] W# 40* + !VAL ;
: INITAUTO ( WORM )
40 0 DO
DUP I DOAI# !MOVE LOOP
DUP 3E 0 !MOVE ( FORCED )
DUP 3D 1 !MOVE DUP 3B 2 !MOVE DUP 37 3 !MOVE
DUP 2F 4 !MOVE DUP 3F DIE# !MOVE
1F 5 !MOVE ; ;S
( WORM INITIALIZATION )
: INITPOS ( WORM )
DUP STX !XPOS DUP STY !YPOS
DUP NOMOVE !CRIX DUP UPDLOC
DUP UPDCRLOC ( DUP UPDMV )
( DUP UPDMAP )
DUP 258 !TMO UPDSTATUS ;
: INITMOVES ( WORM )
40 0 DO
DUP I GETNEW# !MOVE LOOP
DUP 3E 0 !MOVE ( FORCED )
DUP 3D 1 !MOVE
DUP 3B 2 !MOVE
DUP 37 3 !MOVE
DUP 2F 4 !MOVE DUP 3F DIE# !MOVE
1F 5 !MOVE ; ;S
C64SCR 14 28 * + <-> SCRMEM
;S ( DLH SAVELIST BUILDER ) HEX
230 CONSTANT DLH
D404 CONSTANT HSCROL
DLH @ CONSTANT SAVDLH
: RESTORE SAVDLH DLH !
22 DMACTL C! 0 GRACTL C!
E0 2F4 C! 28 COLPF0 C! 0 COLPF1 C!
C COLPF2 C! 46 COLPF3 C!
\ 5 0 DO ( CLEAR PM REGISTRS )
\ 0 D00D I + C! LOOP ;
;
;S
;S ( DISPLAY LIST BUILDER ) HEX
70 ALLOT 14 , HERE HERE 70 C, 70 C,
56 C, WDATA 0 #H * + , 46 C, WDATA 1 #H * + ,
56 C, WDATA 2 #H * + , 46 C, WDATA 3 #H * + ,
56 C, WDATA 4 #H * + , 46 C, WDATA 5 #H * + ,
56 C, WDATA 6 #H * + , 46 C, WDATA 7 #H * + ,
56 C, WDATA 8 #H * + , 46 C, WDATA 9 #H * + ,
56 C, WDATA A #H * + , 46 C, WDATA B #H * + ,
56 C, WDATA C #H * + , 46 C, WDATA D #H * + ,
56 C, WDATA E #H * + , 46 C, WDATA F #H * + ,
56 C, WDATA 10 #H * + , 46 C, WDATA 11 #H * + ,
56 C, WDATA 12 #H * + , 46 C, WDATA 13 #H * + ,
80 C, 60 C, 46 C, SCRMEM 50 + , 00 C, 40 C,
46 C, SCRMEM , 00 C, 00 C, 46 C, SCRMEM 28 + ,
41 C, , <-> WDL
;S
( WDL SETHSCRL CHARACTER SET DEF. )
HERE
1 C, 2 C, 4 C, 8 C, 10 C, 20 C,
<-> TMASK
;S
( HEX #DV 2+ CDL WDL
( : SETHSCRL )
( DUP 2 - @ 1 DO )
( DUP I 3 * + 1 - DUP C@ 10 OR )
( SWAP C! 2 +LOOP DROP )
( C HSCROL C! ; )
( WDL SETHSCRL )
2F4 <-> CHBAS D409 <-> CHBASE
WCHSET 100 / FF AND <-> WCHSETH
WCHSETH VAR CHNOW C VAR SCRLVAL
( CHSET BUILDING TVEC DEFS )
HERE
00 C, 00 C, 00 C, 0F C, ( 0 )
00 C, 00 C, 00 C, 00 C,
00 C, 00 C, 00 C, 00 C, ( 1 )
08 C, 08 C, 04 C, 04 C,
00 C, 00 C, 00 C, 00 C, ( 2 )
10 C, 10 C, 20 C, 20 C,
00 C, 00 C, 00 C, F0 C, ( 3 )
00 C, 00 C, 00 C, 00 C,
20 C, 20 C, 10 C, 10 C, ( 4 )
00 C, 00 C, 00 C, 00 C,
04 C, 04 C, 08 C, 08 C, ( 5 )
00 C, 00 C, 00 C, 00 C,
<-> TVEC
;S
( CHSET BUILDING )
: DALLY FF 0 DO I DROP LOOP ;
37A7 VARIABLE SEED
\ : RAND SEED @ FB * 3D + DUP SEED ! 4* MSB ;
: RAND D012 C@ SEED +! SEED C@ ;
;S : ORCHARVEC ( CHARADDR VECADR )
8 0 DO 2DUP I + C@
OVER I + C@ OR SWAP
I + C! LOOP DROP DROP ;
: ORCHAR ( CHB CINDX -> CHB )
6 0 DO 2DUP TMASK I + C@
AND IF
OVER 8 * +
TVEC I 8 * + ORCHARVEC
ELSE DROP ENDIF LOOP
DROP ;
( CHSET BUILD WDISPLAY )
: HI MSB ; : LO LSB ;
: CLEARF WDATA #H #V * 0 FILL
CLEAR64PF ;
;S : BUILDCHSET ( CHBASE ) DUP 200 0 FILL
40 0 DO
I ORCHAR LOOP DROP 8 WCHSET 3 + C! ;
: IWDISPLAY ( 2A ) 22 DMACTL C!
( 02 ) 00 GRACTL C! WDL DLH !
C0 NMIEN C! \ GPR C@ GPRIOR C!
\ PMA HI PMBASE C!
\ C 0 DO 0 I D000 + C! LOOP ( PLAYER H POS )
4 0 DO ( PWDTH D008 I + C! ) ( PLAYER WIDTHS )
COLPFT I + C@ COLPF0 I + C!
\ COLPMT I + C@ COLPM0 I + C!
LOOP WCHSETH CHBAS C! ; ;S
( [X] [Y] SCALE )
: [X] ( X -> X CLIPS )
DUP #DH-1 H0 + > IF #DH - ELSE
DUP H0 < IF #DH + ENDIF ENDIF ;
: [Y] ( Y -> Y CLIPS )
DUP #DV-1 V0 + > IF #DV - ELSE
DUP V0 < IF #DV + ENDIF
ENDIF ;
HERE ( C D F G A ... )
( NEED 18 ONLY )
892 , 99F , B71 , CD8 , E6B ,
1125 , 133F , 16E3 , 19B0 , 1CD6 ,
224B , 267E , 2DC6 , 3361 , 39AC ,
4495 , 4CFC , 5B8C , 66C2 , 7358 ,
892B , 99F7 , B719 , CD85 , E6B0 ,
<-> SCALE ;S
( SOUND BSND MSND PWORM )
\ : BSND ( WORM --> ) DROP ;
\ 2*W# DUP FRQT + FF SWAP !
\ CDT + 10 SWAP ! ;
\ C VAR FV 4 VAR BV ( FOR,BK VOL)
: MSND ( W M )
SWAP .STATUS
IF W# 3* + 2* SCALE + @ >R WV SR AR R> ROVR C64SOUND
ELSE DROP THEN ;
;S : PWORM 1 VBION !
3F 0 DO DUP DUP I
.MOVE MSND 8 WAIT LOOP
DROP XSND 0 VBION ! ; ;S
( [MOVE] DECTMO GXINC XY! X! Y! ^ )
: [MOVE] ( WORM M -> WORM M )
DUP 5 > IF ( OVER BSND ) ELSE
OVER .VAL OVER TMASK + C@
AND IF DROP GETNEW#
ENDIF ENDIF ;
: DECTMO ( W -> )
DUP .TMO 13 - 50 MAX !TMO ;
: GXINC ( WORM -> XINCV )
.YPOS 1 AND IF XINCO ELSE
XINCE ENDIF ;
;S
( ?SPACE ?CR MOVEOK DETRACT TIMEOUT )
: ?SPACE ?CH 20 =KEY ;
: ?NOTSP ?CH DUP 0= SWAP 20 = OR
IF 0 ELSE KEY THEN ;
: ?CR ?CH 0D =KEY ;
: MOVEOK ( WORM M -> FLAG )
TMASK + C@ SWAP .VAL AND 0= ;
: DETRACT ( 0 4D C! ) ;
: PAUSEP P" ." PAUSED: HIT RUN " ;
: ?PAUSE ?CH 03 = IF PAUSEP KEY DROP
BEGIN ?CH IF 0 ELSE KEY 03 = THEN
?TERMINAL OR UNTIL PROMPT2 THEN ;
: TIMEOUT ( MOVE --> MOVE F ) ?PAUSE
( W# ) ( DUP BLINK ) ?SPEED
( TRIGMASK + C@ PORTA C@ AND 0= ) ?NOTSP ( OR) STOP OR ; ;S
( SETTIME NXTMOVE CLRKBD )
0 VAR KEYPOT
: SETTIME ( WORM ) DROP ;
\ 0 KEYPOT !
\ 0 21E ! FF 22C C! DUP .TMO
\ 21E ! DROP 2*W# >R
\ R R + SCALE + C@
\ R FRQT + !
\ STO @ R> CDT + ! ;
: NXTMOVE ( MOVE -> MOVE )
NMOVE + C@ 5 MIN 0 MAX ;
: CLRKBD BEGIN ?CH WHILE KEY DROP REPEAT ;
;S
;S : =OR ROT >R R = SWAP R> = OR ; ;S ( CASES )
: CASES ?COMP CSP @ !CSP 4 ; IMMEDIATE
: >OF 4 ?PAIRS COMPILE OVER COMPILE < COMPILE 0BRANCH
HERE 0 , COMPILE DROP 5 ; IMMEDIATE
: <OF 4 ?PAIRS COMPILE OVER COMPILE > COMPILE 0BRANCH
HERE 0 , COMPILE DROP 5 ; IMMEDIATE
: =OF 4 ?PAIRS COMPILE OVER COMPILE = COMPILE 0BRANCH
HERE 0 , COMPILE DROP 5 ; IMMEDIATE
: INOF 4 ?PAIRS COMPILE ROT COMPILE >R COMPILE R COMPILE >=
COMPILE SWAP COMPILE R COMPILE <= COMPILE AND
COMPILE R> COMPILE SWAP COMPILE 0BRANCH
HERE 0 , COMPILE DROP 5 ; IMMEDIATE
: ENDOF 5 ?PAIRS COMPILE BRANCH HERE 0 , SWAP 2 [COMPILE] THEN
4 ; IMMEDIATE
: ENDCASES 4 ?PAIRS COMPILE DROP BEGIN SP@ CSP @ = 0= WHILE 2
[COMPILE] THEN REPEAT CSP ! ; IMMEDIATE ;S
( FIXL0 FIXL1 )
\ : FIXL2 ( W# ) MAPCLR + C@ COLRMEM 14 28* + 28 ROT FILL ;
;S
: FIXL0 ( W# ) ( SCORE LINE )
DUP 40* ( W# MASK )
SWAP 5 * SCRMEM +
DUP 5 + SWAP
DO I C@ 3F AND OVER OR I C!
LOOP DROP ;
: FIXL1 ( W# ) ( NAME LINE )
DUP 40* ( W# MASK )
SWAP 5 * SCRMEM 28 + +
DUP 5 + SWAP
DO I C@ 3F AND OVER OR I C!
LOOP DROP ; ;S
( ADDONE )
\ : ADDONE ( ADDR )
\ >R BEGIN
\ R C@ 3F AND DUP 2F 38 RANGE
\ IF 1+ R C! 1 ELSE
\ DUP 39 = IF DROP 30 R C! R> 1- >R 0 ELSE
\ DROP 31 R C! 1 THEN THEN
\ UNTIL R> DROP ;
: PUTSCORE ( N A )
>R BEGIN 0A /MOD SWAP
2* A0 + DUP R 1- C! 1+ R C!
R> 2- >R DUP 0= UNTIL R> 2DROP ;
;S
( KEYPOT GKEYPOT X! Y! XY! )
0 VARIABLE TBUF 10 ALLOT 0 VAR CCNT
HEX 0 VAR SEL ( SELECTED WORM )
: HIL2 ( SEL @ FIXL2 ) ; : FIXL2 DROP ;
: GKEYPOT ( -> N )
?SPACE KEYPOT +! KEYPOT @ ;
: PROMPTM P" ." PADDLE/SPACE&RETURN" ;
;S
( LEGAL CHKMOVES )
0 VAR LEGAL 4 ALLOT
0 VAR #LEGAL
HERE 1 C, 2 C, 4 C,
8 C, 10 C, 20 C, <-> MMASK
: CHKMOVES ( WORM )
0 #LEGAL !
[.VAL] 6 0 DO
DUP I MMASK + C@ AND 0= IF
#LEGAL @ LEGAL + I SWAP C!
1 #LEGAL +! ENDIF
LOOP DROP ;
;S
( GPOT ) HEX
: GPOT ( WORM --> INDX ) DROP GKEYPOT
\ .WRM# DUP POT0 + C@ MAXPOT = IF DROP GKEYPOT ELSE
\ CPOT + C@ E6 SWAP -
\ E6 #LEGAL @ 2 * /
\ / GKEYPOT + THEN
#LEGAL @ 1 MAX MOD
LEGAL + C@ 0 MAX 5 MIN ;
: TRIGCLR ( MV WORM - MOVE ) DROP JSCLR ; ;S
\ >R W# TRIGMASK + C@
\ BEGIN DUP PORTA C@ AND
\ R DUP GPOT !CRIX ( R UPDMV )
\ W# DUP + MAPCDT + >R
\ R C@ 0= IF 7 R C! ENDIF R>
\ DROP UNTIL
\ DROP DROP R> .CRIX ; ;S
( PEEKMAP HOME? SAMEDIR? )
: XY->V #H * + WDATA + C@ ;
: PEEKMAP ( W M -> COUNT ) 2DUP
SWAP >R 2 * R GXINC + @ R>
.XPOS + [X] ROT ROT
SWAP >R 2 * YINC + @ R> .YPOS
+ [Y]
XY->V #BITS ;
: HOME? ( W M --> F )
DROP DROP 0 ( NOT IMPL. ) ;
: SAMEDIR? ( W M --> NO/?/YES )
SWAP [.VAL] DUP #BITS 1 = IF
SWAP NXTMOVE TMASK + C@ = 2 *
ELSE SWAP NXTMOVE TMASK + C@
AND IF 1 ELSE 0 ENDIF ENDIF ;
;S
( EVAL )
HERE 5 C, 7 C, 7 C,
9 C, B C, 2 C, <-> SIX
HERE 5 C, 7 C, 7 C,
9 C, 5 C, 2 C, <-> VALFN
: EVAL ( W M --> )
OVER .VAL OVER TMASK + C@
AND IF SIX + 0 SWAP C! DROP
ELSE ( W LEGALMOVE )
2DUP PEEKMAP VALFN + C@ >R
2DUP HOME? R> + >R
SWAP OVER SAMEDIR? R> SWAP -
SWAP SIX + C!
ENDIF ;
;S
( DOAI )
: CK6 ( W --> )
6 0 DO DUP I EVAL LOOP DROP ;
0 VAR TEMP
: 6T SIX + C@ TEMP @ ;
: PICKBEST ( --> M ) 0 TEMP !
6 0 DO
I 6T MAX TEMP ! LOOP 0
6 0 DO I 6T = IF 1+ ENDIF
LOOP RAND SWAP MOD 1+
6 0 DO I 6T = IF 1 - -DUP
0= IF I LEAVE ENDIF ENDIF
LOOP ;
: DOAI ( W --> M )
( 300 0 DO I DROP LOOP )
CK6 PICKBEST ; ;S
( DOS EMULATION )
1 VAR CMDOK : CHKST ;
\ 80 CONSTANT SECSZ
\ 0 VARIABLE FBUF SECSZ ALLOT
: IOBUF PAD ;
: VDOSDISK 1 ;
;S
: GETNEWMOVE DUP 7 !CRIX CLRKBD
XSND DUP SETTIME 2*W#
>R DUP UPDCRLOC
DUP CHKMOVES ( 1 PSCAN C! )
DUP UPDMAP
6 BEGIN DROP DUP GPOT
OVER .CRIX OVER = IF ELSE
2DUP !CRIX
OVER UPDMV ENDIF R MAPCDT +
C@ 0= IF 7 MAPCDT R + ! ENDIF
TIMEOUT UNTIL OVER TRIGCLR
( 0 COLBK C! DETRACT ) [MOVE]
SWAP OVER SWAP
DUP [.VAL] ROT !MOVE ( 0 PSCAN C! )
( 1 VBION ! ) R> DROP ; ;S
( HILITE DELITE )
HERE 38 C, 60 C, 88 C, B0 C, <-> MHP
: MVHILTE ( W# )
DUP 0A * DM 28 17 * + + 0A F7 FILL
MAPCLR OVER + C@ SWAP D027 + C! ;
: MVDELITE ( )
DM 28 17 * + 28 20 FILL W# SPCOLR + C@ W# D027 + C! ;
: HILITE ( WORM ) DROP ;
\ WRM# DUP COLPF0 + SWAP
\ COLPFT + C@ F0 AND 8 OR SWAP C! ;
: DELITE ( ) ;
\ 4 0 DO COLPFT I + C@ F0
\ AND 4 OR COLPF0 I +
\ C! LOOP ;
: XLITE ( ALL COLORS OFF ) ; ;S
\ 4 0 DO 0 COLPF0 I + C! LOOP ; ;S
( GETMOVE )
: GETMOVE ( WORM -> MOVE )
DUP [.VAL] OVER SWAP .MOVE
DUP
6 < IF ELSE DUP ( W M )
GETNEW# = IF DROP W# MVHILTE
DUP GETNEWMOVE MVDELITE DELITE ELSE DUP
DOAI# = IF DROP DUP DOAI
>R DUP DUP [.VAL] R !MOVE R> ELSE DUP
DIE# = IF DROP DUP UPDSTATUS UNDFMOVE ELSE
( ." ????? " S. )
THEN THEN THEN THEN SWAP DROP ;
;S
( INC#MOVES NXTMOVE UPDXPOS )
: INC#MOVES ( WORM )
DUP 4 + @ 1+
SWAP 4 + ! ;
: UPDXPOS ( WORM MOVE )
SWAP >R 2* R GXINC + @ R
.XPOS + [X] R> SWAP !XPOS ;
: UPDYPOS ( WORM MOVE )
SWAP >R 2* YINC + @ R .YPOS
+ [Y] R> SWAP !YPOS ;
0 VAR WSCR 6 ALLOT
: UPDSCR ( WORM )
.WRM# DUP 0A * SCRMEM + 2E +
>R ( ADDONE ) ( DUP FIXL0 ) DUP +
WSCR + DUP >R 1 SWAP +! R> @ R> PUTSCORE ;
;S
( UPDCNODE INSTALLVBI INSTALLHBI INITMEM )
: UPDCNODE ( WORM MOVE )
2DUP !CRIX
OVER .VAL SWAP TMASK + C@
OR DUP 3F AND 3F = IF
OVER 7 !CRIX OVER UPDSCR
ENDIF !VAL ; ;S
: INSTALLVBI ( ADDR -> )
7 SET-INT ;
: INSTALLHBI ( ADDR -> )
40 D40E C! 200 ! C0 D40E C! ;
: INITMEM DLH @ [ ' SAVDLH ] LITERAL !
58 @ [ ' SCRMEM ] LITERAL !
SCRMEM 50 + WDL 41 + ! SCRMEM WDL 46 + !
SCRMEM 28 + WDL 4B + ! ;
;S
( MAKEMOVE )
: MAKEMOVE ( WORM -> STATUS )
DUP UPDSTATUS DUP .STATUS
IF DUP GETMOVE
DUP 6 < IF OVER ZMAP
OVER UPDCRLOC
2DUP MSND 2DUP UPDCNODE
OVER UPDMV OVER UPDMAP
( OVER PAUSE ) OVER UPDCOL
2DUP UPDXPOS 2DUP UPDYPOS
OVER UPDLOC OVER UPDCOL
( OVER ZCRMAP OVER UPDCRLOC )
( OVER INC#MOVES ) 2DUP NXTMOVE
UPDCNODE OVER UPDSTATUS
ENDIF DROP ENDIF DUP UPDSTATUS
.STATUS ; ;S
( GAME ENDGAME CSOUND )
0 VARIABLE MVCNT 4 VAR WTICKS
4 VARIABLE PERIOD
: SETW# DUP ' W# ! DUP + ' 2*W# ! ;
: GAME ( #PLAYERS )
( 1 VBION ! ) 0 QFLG !
DUP 0 DO I GWORM UPDCRLOC LOOP
BEGIN 0 OVER 0 DO ( XSND ) ?PAUSE I SETW#