-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.asm
2852 lines (2593 loc) · 71.5 KB
/
main.asm
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
; Disassembly of Temple of ROM by William Astle
; (February 20-25, 2018)
; 16 character tabs
; General memory map:
; 0000-00FF direct page variables
; 0100-03FF stack
; 0400-0FFF graphics screen #1
; 1000-1BFF graphics screen #2
; 1C00 explosion sprite queue
; 3000 code
IFDEF MCUSTOM
include map/constants.asm
ELSE
include constants.asm
ENDC
PIA0.DA equ $ff00
PIA0.CA equ $ff01
PIA0.DB equ $ff02
PIA0.CB equ $ff03
PIA1.DA equ $ff20
PIA1.CA equ $ff21
PIA1.DB equ $ff22
PIA1.CB equ $ff23
SAM equ $ffc0
* References to Color Basic ROM APIs
RSTFLG equ $71
RSTVEC equ $72
*** SEGMENT 1 ***
setdp 0
; start right after RSTFLG and RSTVEC so we don't overlay them
org $74
monsterptr rmb 2 ; pointer to current player's monster locations
portaloff rmb 1 ; nonzero means portals are currently disabled
V03 rmb 1 ; attract mode flag
* Used by music routine
V05 rmb 2 ; note 1 value
V07 rmb 2 ; note 2 value
V09 rmb 2 ; note 3 value
V0B rmb 2 ; note 4 value
V0D rmb 2 ; note 1 pitch delta
V0F rmb 2 ; note 2 pitch delta
V11 rmb 2 ; note 3 pitch delta
V13 rmb 2 ; note 4 pitch delta
V15 rmb 1 ; note duration
V18 rmb 1 ; crown active timer ($FF, counts down)
V19 rmb 1 ; crystal ball active timer ($FF, counts down)
V1A rmb 1 ; player walk animation index
V4F rmb 1 ; score digit value
V50 rmb 2 ; bat x position
V52 rmb 2 ; bat y position
V5C rmb 1 ; bat creation timer
V5D rmb 2 ; target coord x
V5F rmb 2 ; target coord y
V68 rmb 2 ; object coord x
V8D rmb 1 ; object coord y
randseed rmb 2 ; the "random seed"
mazeoffx rmb 2 ; horizontal offset in maze of top left of screen
mazeoffy rmb 2 ; vertical offset in maze of top left of screen
curposx rmb 2 ; current player horizontal screen position
curposy rmb 2 ; current player vertical screen position
tcoord rmb 1 ; temporary coordinate storage
renderscr rmb 2 ; current render screen location
endclear rmb 2 ; lowest address (highest location on screen) to clear
color rmb 1 ; pset color
VBF rmb 2 ; attract mode mute flag
* player position
VC1 rmb 2 ; screen pointer (unused)
VC3 rmb 1 ; signed joystick x delta
VC4 rmb 1 ; signed joystick y delta
VC5 rmb 1 ; last nonzero signed joystick x delta (used for laser and walk animation direction)
VC6 rmb 1 ; last nonzero signed joystick y delta (used for laser direction)
* line drawing
VC7 rmb 1
VC8 rmb 1
VC9 rmb 1
VCA rmb 1
VCB rmb 2
VCD rmb 2
VCF rmb 1 ; laser y position
VD0 rmb 1 ; laser x position
VD1 rmb 1 ; fire button timer (0: not depressed, >0: depressed, counts up to FF while still depressed)
scorep1 rmb 3 ; player one's score
dead rmb 1 ; player dead flag
VD6 rmb 1 ; zero suppress flag
VD7 rmb 1 ; laser sound value
VD8 rmb 1 ; render location Y
VD9 rmb 1 ; render location X
VDA rmb 1 ; treasure count
collision rmb 1 ; collision detection flag
VDC rmb 1 ; number of treasures remaining
* hitbox
hity1 rmb 1 ; miny
hity2 rmb 1 ; maxy
hitx1 rmb 1 ; minx
hitx2 rmb 1 ; maxx
numplayers rmb 1 ; number of players in the game
scrollstep rmb 2 ; step/direction for maze scrolling
plr1state rmb 6 ; player two game state (6 bytes)
plr2state rmb 6 ; player one game state (6 bytes)
scorep2 rmb 3 ; player two's score
scoreptr rmb 2 ; pointer to current player's score
texttty rmb 1 ; whether the "tty" effect is enabled for text
objlistptr rmb 2 ; pointer to current player's treasure list
curplayer rmb 1 ; current player number (oddly, 2 = player 1, 1 = player 2)
VF9 rmb 2 ; bat sprite (or zero if bat inactive)
VFA rmb 1 ; bat wing flap state
POTVAL rmb 4 ; joystick values
temp rmb 1 ; temporary pixel mask storage
tick rmb 1 ; IRQ countdown timer
tock rmb 1 ; IRQ countup timer
aggro rmb 1 ; aggro flag
STACK equ $3ff
* SCREEN 1
*
* 128 x 96, 4 color
*
SCREEN1 equ $400 ; SCREEN 1 (3072 bytes)
* SCREEN 2
*
* 128 x 96, 4 color
*
SCREEN2 equ $1000 ; SCREEN 2 (3072 bytes)
org $1c00
* EXPLOSION SPRITE QUEUE
*
* 8 items of 4 bytes each
*
* Each list item is 4 bytes:
* sprite 2 bytes (address of pointer to current sprite)
* X 1 byte (X coordinate divided by 4)
* Y 1 byte (Y coordinate divided by 4)
XQUEUE rmb 8*4
* MASTER MONSTER LIST
*
* Each list entry is 9 bytes:
* X1 2 bytes
* X2 2 bytes
* Y1 2 bytes
* Y2 2 bytes
* ID 1 byte ($00 = spider, $20 = fireball, $40 = ghost, $60 = skull)
*
* The box defined by (X1, Y1, X2, Y2) is the monster's aggro area, with the monster's initial position
* 25% down from the left and top edges
*
* list ends with $0000
monsters rmb NMONSTERS*9+2
* PLAYER 1 TREASURE LIST
*
* Each list item is 4 bytes:
* X 1 byte (X coordinate divided by 4)
* Y 1 byte (Y coordinate divided by 4)
* sprite 2 bytes (address of treasure sprite)
plr1objlist rmb NTREASURES*4
* PLAYER 1 MONSTER LIST
*
* Each list entry is 4 bytes:
* X 2 bytes
* Y 2 bytes
plr1monsters rmb NMONSTERS*4
* PLAYER 2 TREASURE LIST
*
* Each list item is 4 bytes:
* X 1 byte (X coordinate divided by 4)
* Y 1 byte (Y coordinate divided by 4)
* sprite 2 bytes (address of treasure sprite)
plr2objlist rmb NTREASURES*4
* PLAYER 2 MONSTER LIST
*
* Each list entry is 4 bytes:
* X 2 bytes
* Y 2 bytes
plr2monsters rmb NMONSTERS*4
IFGT *-$3000
ERROR Overlay error
ENDC
zdata equ *
org $3000
START orcc #$50 ; make sure interrupts are disabled
clr $ff40 ; make sure all FDC drive motors and selects are off
lbra LCD46 ; launch main initialization sequence
include sound.asm ; fetch sound handling routines
include joystick.asm ; fetch joystick handling routines
; Render the vertical lines of the map
drawvert leau LC34A,pcr ; point to short circuit offset table for vertical lines
ldd mazeoffx ; fetch screen display offset for maze
bge LC013 ; brif screen X offset is positive
ldd #0 ; minimize to 0
LC013 lslb ; shift upper 2 bits of position into A
rola
lslb
rola
lsla ; two bytes per offset
ldd a,u ; get offset from start of offset table to the actual data to start rendering
leau d,u ; point to actual render data
LC01C clra ; zero extend next read
pulu b ; fetch column number
tstb ; end of data?
beq LC06F ; brif so
lslb ; multiply by 4
rola
lslb
rola
subd mazeoffx ; compare to maze offset
blt LC06B ; brif off the left of the screen
cmpd #$7f ; are we off the right side of the screen?
bgt LC06F ; brif so - don't render anything
tfr d,x ; save offset from left of the screen
clra ; zero extend next read
pulu b ; get top coordinate of line
lslb ; times 4
rola
lslb
rola
subd mazeoffy ; compare to screen offset (vertical)
cmpd #8 ; is it in the header or off the screen?
bge LC043 ; brif not
ldb #8 ; force to start at top of visible area
LC043 cmpd #$5f ; are we at the bottom of the screen?
ble LC04B ; brif not
ldb #$5f ; force to end at the bottom of the screen
LC04B pshs b ; save first Y coordinate
clra ; zero extend next read
pulu b ; fetch bottom Y coordinate (offset from top of screen)
lslb ; times 4
rola
lslb
rola
subd mazeoffy ; compare to screen offset (vertical)
bge LC059 ; brif below top of screen
clrb ; normalize into screen
LC059 cmpd #$5f ; are we off the bottom of the screen
ble LC061 ; brif not
ldb #$5f ; normalize into screen
LC061 lda ,s ; get adjusted top coordinate back
cmpb ,s+ ; is the bottom coordinate below the top coordinate?
bls LC01C ; brif so - we don't need to render anything
bsr vline ; draw line
bra LC01C ; go check next line to render
LC06B leau 2,u ; move to next line to consider
bra LC01C ; go render it if necessary
LC06F rts
* Draw vertical line
* A: beginning Y coordinate
* B: ending Y coordinate
* X: X coordinate
vline pshs a ; save top coordinate
pshs b ; save bottom coordinate
tfr x,d ; stuff the horizontal coordinate into an accumulator
andb #3 ; figure out which pixel in the byte we're at
leay LC09A,pcr ; point to pixel bit masks
lda b,y ; get the proper pixel bit mask
ldb ,s+ ; get bottom coordinate
subb ,s ; subtract out top coordinate (number of pixels to do)
exg d,x ; get back horizontal coordinate and save count and pixel mask
lda ,s+ ; get top coordinate
rolb ; calcuate screen offset
lsra
rorb
lsra
rorb
lsra
rorb
addd renderscr ; add to base screen address
exg d,x ; put into pointer and get back pixel mask and counter
LC091 sta ,x ; set pixel for line
leax $20,x ; move to next row
decb ; done last pixel?
;bne LC091 ; brif not FIXED BUG!
bpl LC091
rts
LC09A fcb $40,$10,$04,$01 ; pixel masks for maze walls (color #1)
; Render the horizontal lines of the map
drawhoriz leau LC36A,pcr ; point to short circuit offsets for horizontal drawing
ldd mazeoffy ; get vertical offset of screen
bge LC0A9 ; brif valid coordinate
ldd #0 ; minimize to 0
LC0A9 lslb ; get upper 4 bits of offset into A
rola
lslb
rola
lsla ; two bytes per offset entry
ldd a,u ; get offset from start of offset table
leau d,u ; point to data to render
LC0B2 clra ; zero extend for next read
pulu b ; get horizontal coordinate
tstb ; end of data?
beq LC104 ; brif so
lslb ; times 4
rola
lslb
rola
subd mazeoffy ; get offset relative to screen position
cmpd #8 ; are we above the screen or in the header?
blt LC100 ; brif so
cmpd #$5f ; are we below the bottom of the screen?
bgt LC100 ; brif so
tfr d,x ; save vertical offset for later
clra ; zero extend for next read
pulu b ; get left coordinate for line
lslb ; times 4
rola
lslb
rola
subd mazeoffx ; offset relative to the screen position
bge LC0D8 ; brif not off the left side
clrb ; normalize to left side
LC0D8 cmpd #$7f ; off the right of the screen?
ble LC0E0 ; brif not
ldb #$7f ; normalize to right side
LC0E0 pshs b ; save left coordinate
clra ; zero extend next read
pulu b ; fetch right coordinate
lslb ; times 4
rola
lslb
rola
subd mazeoffx ; offset according to the screen position
bge LC0EE ; brif not off left side of screen
clrb ; normalize to left side of screen
LC0EE cmpd #$7f ; are we off the right side of the screen?
ble LC0F6 ; brif not
ldb #$7f ; normalize to right side of screen
LC0F6 lda ,s ; get left coordinate back
cmpb ,s+ ; is right coordinate left of left coordinate?
bls LC0B2 ; brif so (or same as)
bsr hline ; go draw line
bra LC0B2 ; go handle next line
LC100 leau 2,u ; move to next set of line data
bra LC0B2 ; go render it if needed
LC104 rts
* Draw horizontal line
* A: beginning X coordinate
* B: ending X coordinate
* X: Y coordinate
hline pshs a ; save left coordinate
exg x,d ; save coordinates and get vertical offset
tfr b,a ; put vertical coordinate in A
ldb ,s ; get left coordinate
rolb ; calcuate screen offset
lsra
rorb
lsra
rorb
lsra
rorb
addd renderscr ; add screen base
exg d,x ; save pointer and get back coordinates
subb ,s+ ; calculate number of pixels
incb ; add one (compensate for decb below)
leay LC09A,pcr ; point to pixel masks
anda #3 ; get pixel number in byte
lda a,y ; get pixel mask
sta temp
LC125 decb ; are we done yet?
blt LC148 ; brif so
lda temp
ora ,x ; merge with screen data
sta ,x ; save on screen
lsr temp
lsr temp
bne LC125 ; brif we haven't got to the end of the byte
leax 1,x ; move to next byte
lda #$55 ; set up to do whole bytes
LC138 subb #4 ; do we have a whole byte worth?
blt LC140 ; brif not
sta ,x+ ; do a whole byte
bra LC138 ; try again
LC140 addb #4 ; reset for subb above
lda #$40 ; set up for leftmost pixel in byte
sta temp ; set pixel masks
bra LC125 ; go complete the line
LC148 rts
; 00 black
; 01 blue
; 10 red
; 11 white
; explosion sprites
explosion
fcb explosion1-*
fcb explosion2-*
fcb explosion3-*
fcb explosion4-*
fcb $00 ; end of table marker
explosion1
fcb $00,$00 ; ........
fcb $00,$00 ; ........
fcb $03,$00 ; ...W....
fcb $0f,$c0 ; ..WWW...
fcb $03,$00 ; ...W....
fcb $00,$00 ; ........
fcb $00,$00 ; ........
fcb $00,$00 ; ........
explosion2
fcb $c0,$0c ; W.....W.
fcb $30,$30 ; .W...W..
fcb $0e,$c0 ; ..WRW...
fcb $0a,$80 ; ..RRR...
fcb $0e,$c0 ; ..WRW...
fcb $30,$30 ; .W...W..
fcb $c0,$0c ; W.....W.
fcb $00,$00 ; ........
explosion3
fcb $00,$20 ; .....R..
fcb $20,$c0 ; .R..W...
fcb $08,$80 ; ..R.R...
fcb $ca,$00 ; W.RR....
fcb $0c,$80 ; ..W.R...
fcb $00,$00 ; ........
fcb $80,$30 ; R....W..
fcb $00,$00 ; ........
explosion4
fcb $00,$00 ; ........
fcb $0c,$00 ; ..W.....
fcb $00,$20 ; .....R..
fcb $03,$00 ; ...W....
fcb $08,$00 ; ..R.....
fcb $00,$00 ; ........
fcb $00,$00 ; ........
fcb $00,$00 ; ........
; digit glyphs; this is used as a pointer to digit #2 simply because
; the A,r indexing mode is signed and digits 8 and 9 wouldn't be
; contiguous otherwise
digits fcb $3c,$00,$c3,$00,$c3,$00,$c3,$00 ; 0
fcb $3c,$00,$00,$00,$00,$00,$00,$00
fcb $0c,$00,$3c,$00,$0c,$00,$0c,$00 ; 1
fcb $3f,$00,$00,$00,$00,$00,$00,$00
fcb $fc,$00,$03,$00,$3c,$00,$c0,$00 ; 2
fcb $ff,$00,$00,$00,$00,$00,$00,$00
fcb $fc,$00,$03,$00,$3c,$00,$03,$00 ; 3
fcb $fc,$00,$00,$00,$00,$00,$00,$00
fcb $0f,$00,$33,$00,$c3,$00,$ff,$00 ; 4
fcb $03,$00,$00,$00,$00,$00,$00,$00
fcb $ff,$00,$c0,$00,$fc,$00,$03,$00 ; 5
fcb $fc,$00,$00,$00,$00,$00,$00,$00
fcb $3f,$00,$c0,$00,$fc,$00,$c3,$00 ; 6
fcb $3c,$00,$00,$00,$00,$00,$00,$00
fcb $ff,$00,$03,$00,$0c,$00,$30,$00 ; 7
fcb $30,$00,$00,$00,$00,$00,$00,$00
fcb $3c,$00,$c3,$00,$3c,$00,$c3,$00 ; 8
fcb $3c,$00,$00,$00,$00,$00,$00,$00
fcb $3c,$00,$c3,$00,$3f,$00,$03,$00 ; 9
fcb $fc,$00,$00,$00,$00,$00,$00,$00
plr1mess fcb 10
fcc 'PLAYER ONE'
plr2mess fcb 10
fcc 'PLAYER TWO'
ToRmess fcb 16
fcc 'TEMPLE OF ROM !!'
gameovermess fcb 9
fcc 'GAME OVER'
oneplrmess fcb 10
fcc 'ONE PLAYER'
twoplrmess fcb 11
fcc 'TWO PLAYERS'
copyrmess fcb 14
fcc 'COPYRIGHT 2020 '
authmess fcb 13
fcc 'BY RICK ADAMS '
;fest1 fcb 10
; fcc "WELCOME TO"
;fest2 fcb 13
; fcc "COCOFEST 2023"
;licmess fcb 11
; fcc 'LICENSED TO '
;tandymess fcb 17
; fcc 'TANDY CORPORATION '
;rightsmess fcb 19
; fcc 'ALL RIGHTS RESERVED'
fontidx fcc 'ABCDEFGHI1KLMNOP9RST8VW4Y235JQXZU6790 !' ; font index character list
; Font data. Each character is encoded as 32 bits. The character matrix is 5x6 with
; the bits packed left to right and top down starting at the msb of each byte.
fontdata fcb $f0,$5f,$17,$80 ; A
fcb $f4,$7d,$1f,$00 ; B
fcb $74,$61,$17,$00 ; C
fcb $f4,$63,$1f,$00 ; D
fcb $74,$7d,$07,$80 ; E
fcb $74,$79,$08,$00 ; F
fcb $7c,$27,$17,$00 ; G
fcb $85,$b3,$18,$80 ; H
fcb $42,$10,$83,$00 ; I
fcb $23,$08,$47,$00 ; 1
fcb $8c,$b9,$28,$80 ; K
fcb $84,$21,$0f,$80 ; L
fcb $55,$6b,$58,$80 ; M
fcb $b6,$63,$18,$80 ; N
fcb $74,$63,$17,$00 ; O
fcb $f4,$63,$e8,$00 ; P
fcb $74,$5e,$1f,$00 ; 9
fcb $be,$21,$08,$00 ; R
fcb $7c,$1c,$1f,$00 ; S
fcb $f9,$10,$83,$80 ; T
fcb $74,$5d,$17,$00 ; 8
fcb $8c,$62,$a2,$00 ; V
fcb $8c,$6b,$55,$00 ; W
fcb $32,$a5,$f1,$00 ; 4
fcb $8c,$54,$42,$00 ; Y
* ADDED GLYPHS NOW THAT WE HAVE MORE RAM
fqb %11110000010111010000111110000000 ; 2
fqb %11110000010111000001111100000000 ; 3
fqb %11111100001111000001111100000000 ; 5
fqb %00001000010000110001011100000000 ; J
fqb %01110100011000101001101100000000 ; Q
fqb %10001010100010001010100010000000 ; X
fqb %11111000100010001000111110000000 ; Z
fqb %10001100011000110001011100000000 ; U
fqb %01110100001111010001011100000000 ; 6
fqb %11111000010001000100001000000000 ; 7
fqb %01110100010111100001011100000000 ; 9
fcb $74,$63,$17,$00 ; 0
fcb $00,$00,$00,$00 ; space
fcb $71,$08,$47,$00 ; I
IFDEF MCUSTOM
include map/lines.asm
ELSE
include lines.asm
ENDC
*** SEGMENT 2 ***
LCD46 lbra LCF50
include music.asm
; This generates a pseudo random sequence with period 128 in B
random pshs a ; save registers
lda randseed ; get current random seed
ldb #123 ; get fudge factor
mul ; multiply
addb #9 ; add something for fun
stb randseed ; save new random seed (and result)
puls a ; restore registers
rts
* Better random routine from Steve Bjork
lrandom
clr ,-s ; clear holder of LFSB
lda randseed ; get high byte of 16-bit random seed
anda #%10110100 ; get the bits check in shifting
ldb #6 ; use the top 6 bits for xoring
loop@
lsla ; move top bit into the carry flag
bcc no@ ; skip incing the LFSB if no carry
inc ,s ; add one to the LFSB test holder
no@
decb ; count down loop counter
bne loop@ ; loop if all bits are not done
lda ,s+ ; get LFSB off of stack
inca ; invert lower bit by adding one
rora ; move bit 0 into carry
rol randseed+1 ; shift carry into bit 0
rol randseed ; one more shift to complete the 16 bit shift
ldd randseed ; load up a and b with the new random seed
rts
* Generate random number between zero and A
rand
pshs d
lbsr lrandom
puls a
mul
puls b,pc
; Wait for VSYNC -- wait for every fifth vertical sync
WaitVSYNC
pshs a
loop@ lda tick
bne loop@
lda #5
sta tick
sync
puls a,pc
; Clear screen one header (to white)
clrheader pshs y,x,b,a ; save registers
ldx #SCREEN1 ; point to start of screen #1
ldy #$80 ; set up to clear 256 bytes (2 bytes at a time)
ldd #$ffff ; set up to use color #3
clrheader0 std ,x++ ; clear out two bytes
leay -1,y ; done yet?
bne clrheader0 ; brif not
puls y,x,b,a ; restore registers
rts
; Copy screen one header to screen two
dupheader pshs y,x,b,a ; save registers
ldx #$500 ; point to end of 8th row on screen #1
ldy #$1100 ; point to end of 8th row on screen #2
dupheader0 ldd ,--x ; copy two bytes from screen #1 to screen #2
std ,--y
cmpy #SCREEN2 ; at start of screen?
bgt dupheader0 ; brif not
puls y,x,b,a ; restore registers
rts
* Is player inside aggro area?
; D: player coord
; X: aggro box left/top
; Y: aggro box right/bottom
LCF3C pshs b,a
cmpx ,s
bhi LCF4B
cmpy ,s
blo LCF4B
orcc #4
bra LCF4D
LCF4B andcc #$fb
LCF4D puls b,a
rts
*** SEGMENT 3 ***
LCF50 nop ; flag for valid warm start routine
orcc #$50 ; make sure interrupts are disabled
clrb ; set direct page to page 0
tfr b,dp
leau LCF50,pcr ; install reset handler
stu RSTVEC
lda #$55 ; flag for reset vector as valid
lds #STACK ; put stack somewhere safe
sta RSTFLG ; mark reset vector as valid
lbsr LEDoff ; turn off Boomerang LED
* Default to composite unless it's a Coco3
lda #$f8
* "Hey, you got your CoCo 3 yet?"
ldx $FFFE
cmpx #$8C1B
bne notcoco3
* Special Coco 3 palette setup
clrb ; black
stb $FFB4
ldb #9 ; blue
stb $FFB5
ldb #36 ; red
stb $FFB6
ldb #63 ; white
stb $FFB7
ldb #$20 ; flip the phase bit
stb $ff98
lda #$c8 ; default to RGB rather than composite
notcoco3
sta PIA1.DB
sta SAM+5 ; set SAM V2 (32 bytes per row, 96 rows)
* init VSYNC interrupt
initvsync
clr tick
leau IRQ,pcr ; IRQ interrupt vector
stu $10d
lda PIA0.CA ; turn off HSYNC
anda #$fe
sta PIA0.CA
lda PIA0.CB ; turn on VSYNC
ora #$01
sta PIA0.CB
andcc #%11101111 ; start VSYNC interrupt on IRQ
* Seed random number routine
addd $112 ; throw in the BASIC timer
bne no@ ; can't be zero
ldd #123
no@ std randseed
ldd #SCREEN2 ; set render screen to screen #2
std renderscr
ldd #SCREEN1 ; set bottom of screen to clear to start of screen #1
std endclear
lbsr LD3B9 ; clear both screens
lbsr clearscores ; reset both players scores
clr numplayers ; set to no players
leax LDD23,pcr ; point to monster data table
ldy #monsters ; point to unpacked location for monster data table
LCF85 ldd ,x ; are we at the end of the table?
beq LCF92 ; brif so
lbsr LD0C1 ; expand the base/offset pairs for the monster
lda ,x+
sta ,y+
bra LCF85 ; go handle another
LCF92 std ,y ; save end of table flag
LCF94 lbsr LD531
clr V03 ; no longer in attract mode
ldu #plr1objlist ; point to player one's treasure list
lbsr buildobjlist ; build treasure list
ldu #plr2objlist ; point to player two's treasure list
lbsr buildobjlist ; build treasure list
ldu #plr1monsters ; point to player one's monster locations
lbsr LDCE6 ; set default locations
ldu #plr2monsters ; point to player two's monster locations
lbsr LDCE6 ; set default locations
lbsr setstartpos ; set default attract mode scrolling start
pshs d
ldd #MINX+((MAXX-MINX)/2)-(128/2)
std mazeoffx
ldd #MINY+((MAXY-MINY)/2)-(96/2)
std mazeoffy
puls d
clr VD7 ; silence tikkatikka sound
lbsr LEDoff ; turn off the Boomerang LED
ldd #1 ; set scroll direction to down-right
std scrollstep
clr texttty ; enable "tty" effect
LCFBD tst numplayers ; did we have a game running?
beq LCFDF ; brif not
leau gameovermess+1,pcr ; point to game over message
lbsr showmess ; show it
lbeq LD05E ; brif button pressed
lda #20 ; 20 scroll iterations
lbsr scrollmaze ; go scroll the maze
lbne LD05E ; brif button pressed
lbsr showscore ; show the scores
lda #$ff ; do a really long maze scroll (255 iterations)
lbsr scrollmaze ; actually do the scrolling
bne LD05E ; brif button pressed
LCFDF leau ToRmess+1,pcr ; point to "TEMPLE OF ROM" message
lda texttty ; get the current "tty" state
sta VBF ; save it for later
beq LCFF1 ; brif enabled
inc V5C ; bump counter
ldb V5C ; fetch counter
andb #3 ; wrap at 3
stb texttty ; save result as "tty" state (will do the "tty" thing every fourth time)
LCFF1 lbsr showmess ; show the "TEMPLE OF ROM" message
beq LD05E ; brif button pressed
lda VBF ; get saved "tty" state
sta texttty ; restore "tty" state
lbsr scrolllong ; go scroll for a while
bne LD05E ; brif button pressed
leau vermess+1,pcr ; point to version string
lbsr showmess ; show it
beq LD05E ; brif button pressed
lda #20 ; scroll for 20 steps
lbsr scrollmaze ; do the scrolling
leau copyrmess+1,pcr ; point to copyright message
lbsr showmess ; show it
beq LD05E ; brif button pressed
lda #20 ; scroll for 20 steps
lbsr scrollmaze ; do the scrolling
leau authmess+1,pcr ; point to author message
lbsr showmess ; show it
beq LD05E ; brif button pressed
lbsr scrolllong ; do a long scroll
bne LD05E ; brif button pressed
;leau cocot+1,pcr
;lbsr showmess
;beq LD05E ; brif button pressed
;lda #20 ; scroll for 20 steps
;lbsr scrollmaze ; do the scrolling
; leau fest1+1,pcr ; "Welcome to"
; lbsr showmess ; show it
; beq LD05E ; brif button pressed
; lda #20 ; scroll for 20 steps
; lbsr scrollmaze ; do the scrolling
; leau fest2+1,pcr ; "CocoFEST 20XX"
; lbsr showmess ; show it
; beq LD05E ; brif button pressed
; lbsr scrolllong ; do a long scroll
; bne LD05E ; brif button pressed
;leau licmess+1,pcr ; point to licensing message
;lbsr showmess ; show it
;beq LD05E ; brif button pressed
;lda #20 ; scroll for 20 steps
;lbsr scrollmaze ; do the scrolling
;bne LD05E ; brif button pressed
;leau tandymess+1,pcr ; point to tandy message
;lbsr showmess ; show message
;beq LD05E ; brif button pressed
;lda #20 ; scroll for 20 steps
;lbsr scrollmaze ; do the scrolling
;bne LD05E ; brif button pressed
;leau rightsmess+1,pcr ; point to rights message
;lbsr showmess ; show messages
;beq LD05E ; brif button pressed
;lbsr scrolllong ; do a long scroll
;bne LD05E ; brif button pressed
lda #$ff ; disable the "tty" effect
sta texttty
lbra LCFBD ; restart the intro loop
LD05E lbsr setstartpos ; set default start position
lbsr drawmazeboth ; draw maze on both screens
clr texttty ; enable the "tty" effect
lda #$ff
sta VD1 ; disable laser
sta V03 ; set attract mode flag
lbsr LD144
lbsr LD1AC
LD072 ldb PIA0.DA ; read keyboard rows/buttons
andb #3 ; keep joystick buttons
eorb #3 ; set nonzero if pressed
bne LD072 ; brif button pressed - we're waiting until the button is released
clr numplayers ; set to no players
LD07D jsr GETJOY ; read joysticks
lda POTVAL+2 ; get X coordinate for first player
cmpa #$20 ; is it to the left?
bgt LD09B ; brif not
lda numplayers ; get number of players
cmpa #1 ; already set to one?
beq LD0AC ; brif so
leau oneplrmess+1,pcr ; point to one player message
lbsr showmess ; display it
lda #1 ; set to one player
sta numplayers
bra LD0AC
LD09B lda numplayers ; get number of players
cmpa #2 ; set for two?
beq LD0AC ; brif so
leau twoplrmess+1,pcr ; point to two player message
lbsr showmess ; display it
lda #2 ; set to two players
sta numplayers
LD0AC ldb PIA0.DA ; read keyboard rows (buttons)
andb #3 ; keep joystick buttons
eorb #3 ; now pressed is 1
beq LD07D ; brif not buttons pressed
lbsr clearscores ; reset both players scores
bsr LD0CD ; run game loop for first life
bsr LD0CD ; run game loop for second life
bsr LD0CD ; run game loop for third life
lbra LCF94 ; go back to main intro screen
; Take two 8 bit coordinate pairs which have been divided by four and expand them
; to their full value. Store the resulting coordinates at Y and move Y
; forward.
LD0C1 bsr LD0C3 ; handle first pair
LD0C3 bsr LD0C5 ; handle first value in pair
LD0C5 lda ,x+ ; fetch value
ldb #4 ; muliply by 4 (gives 16 bit value)
mul
std ,y++ ; save resulting value
rts
LD0CD bsr LD0EE ; run game loop for player one
lda numplayers ; get number of players
cmpa #1 ; only one player?
beq LD0D8 ; brif so
lbsr LD156 ; run game loop for player two
LD0D8 rts
setstartpos pshs a,b ; save registers
ldd #62*256+46 ; starting player position (62, 46) (center of screen minus 2)
sta curposx ; set horizontal position
stb curposy ; set vertical position
ldd #STARTX ; set player position (X) entry point
std mazeoffx
ldd #STARTY ; set player position (Y) entry point
std mazeoffy
puls a,b,pc ; restore registers and return
; Game loop for player one
LD0EE ldu #plr1state ; point to player one state
ldd ,u++ ; get saved screen coordinates
sta curposx ; save horizontal screen position
stb curposy ; save vertical screen position
ldd ,u++ ; fetch saved maze offset (X)
std mazeoffx ; activate it
ldd ,u ; fetch saved maze offset (Y)
std mazeoffy ; activate it
lda #2 ; switch active player to player one
sta curplayer
lbsr LD9EA
lbsr LD531
clr portaloff ; mark all portals as active
clr V18 ; crown inactive
clr V19 ; crystal ball inactive
clr VD1 ; clear fire button timer
ldu #plr1monsters ; point to player one's monster locations
stu monsterptr ; save as monster location pointer
ldu #scorep1 ; point to player one's score
stu scoreptr ; set as current score pointer
ldu #plr1objlist ; point to player one's treasure list
stu objlistptr ; set as current treasure list pointer
leau plr1mess+1,pcr ; point to player one header message
lbsr showmess ; show it
clra ; stop maze scroll
clrb
std scrollstep
clr dead ; player dead flag
lbsr drawmazeboth ; draw maze on both screens
leau LCE2B,pcr ; opening tune
lbsr LCD49 ; 4 part music routine
lbsr showscore ; update scores
LD13A lbsr LD1BE ; common play loop
tst dead ; dead yet?
beq LD13A ; keep going
lbsr LDB82 ; player death
LD144 ldu #plr1state ; point to player one's state data
lda curposx ; fetch current horizontal screen position
ldb curposy ; fetch current vertical screen position
std ,u++ ; save in state
ldd mazeoffx ; fetch current maze offset (X)
std ,u++ ; save in state
ldd mazeoffy ; fetch current maze offset (Y)
std ,U ; save in state
rts
; Game loop for player two
LD156 ldu #plr2state ; point to player two's state data
ldd ,u++ ; get saved screen position
sta curposx ; save horizontal screen position
stb curposy ; save vertical screen position
ldd ,u++ ; fetch saved maze offset (X)
std mazeoffx ; activate it
ldd ,u ; fetch saved maze offset (Y)
std mazeoffy ; activate it
lda #1 ; set player two active