-
Notifications
You must be signed in to change notification settings - Fork 3
/
PAC3.ASM
822 lines (822 loc) · 10.2 KB
/
PAC3.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
;
; PAC-MAN GAME SUBROUTINES
;
; INITIALIZE PLAYER/MISSILE MEMORY
;
; THIS SUBR CLEARS P/M AREA
;
INITPM LDX #0
TXA
JSR INITPL
LDA #$FE
LDX #$F0
JSR INITPL
TXA
RTS
INITPL STA PMADDR+$300,X
STA PMADDR+$400,X
STA PMADDR+$500,X
STA PMADDR+$600,X
STA PMADDR+$700,X
INX
BNE INITPL
RTS
;
; SETCOLOR SUBROUTINE WILL
; INITIALIZE $2C0 - $2C7
; (COLOR REGISTERS)
;
SETCLR LDX #7
SETCLL LDA COLORS,X
STA PCOLR0,X
DEX
BPL SETCLL
RTS
;
;
P1INIT LDX #0
P1INIL LDA DATMAZ,X
STA PACMAZ,X
LDA DATMAZ+$100,X
STA PACMAZ+$100,X
LDA DATMAZ+$200,X
STA PACMAZ+$200,X
LDA DATMAZ+$300,X
STA PACMAZ+$300,X
INX
BNE P1INIL
RTS
;
SAVEP1 LDX #0
SAVP1L LDA PACMAZ,X
STA P1SAVE,X
LDA PACMAZ+$100,X
STA P1SAVE+$100,X
LDA PACMAZ+$200,X
STA P1SAVE+$200,X
LDA PACMAZ+$300,X
STA P1SAVE+$300,X
INX
BNE SAVP1L
RTS
;
SAVEP2 LDX #0
SAVP2L LDA PACMAZ,X
STA P2SAVE,X
LDA PACMAZ+$100,X
STA P2SAVE+$100,X
LDA PACMAZ+$200,X
STA P2SAVE+$200,X
LDA PACMAZ+$300,X
STA P2SAVE+$300,X
INX
BNE SAVP2L
SAV2PX RTS
;
; PMSTIK SUBROUTINE WILL TEST
; JOYTICK INPUT AND DETERMINE
; IF DIRECTION CHOSEN IS VALID.
; THE PACMAN WILL THEN MOVE
; IN THE PROPER DIRECTION WITH
; IT'S MOUTH OPENING AND CLOSING.
;
; THIS CODE IS CALLED DURING
; VBLANK AND INITIATES MOTION
; DURING ALTERNATE OCCURANCES
; OF VBLANK. MOUTH ANIMATION
; IS PERFORMED EVERY VBLANK.
;
;
PMSTIK LDA PMSTAT
BMI SAV2PX
PUDSTK LDX #4
JSR MAZHND
CLC
LDA PMNDIR;SEE IF WE CHANGE DIR.
BIT TEMLOC;IS IT VALID ?
BEQ PMUDST;NO
CMP PMODIR
BEQ PUDSAM
ORA PMODIR
TAY
AND #3
BEQ PUDSAM
TYA
AND #$0C
BEQ PUDSAM
STY PACADV
PUDSAM LDA PMNDIR
STA PMODIR
PMUDST LDX PLYNUM
LDA STICK0,X
EOR #$0F
BEQ PMSAME
PHA
LDX #3
LDY #0
PMTST2 CLC
LSR A
BCC NXPTS2
INY
NXPTS2 DEX
BPL PMTST2
PLA
CPY #2
BEQ PMSAME
PDRTST STA ATRACT
STA PMNDIR
BIT TEMLOC
BEQ PMSAME
STA PMODIR
PMSAME LDA PMODIR
BIT TEMLOC
BNE PACTST
JMP PACOPN
PACTST CMP #1
BEQ PACUP
CMP #2
BEQ PACDN
CMP #4
BNE PACRTV
JMP PACLF
PACRTV CMP #8
BEQ PACRT
JMP PACSTP
PACUP LDA PACCNT
BNE PACUPS
DEC PMVPOS
DEC PMVPOS
LDA PACMAP
BNE DECPMP
LDA #3
STA PACMAP
BNE PACUPS
DECPMP DEC PACMAP
BNE PACUPS
LDA PMVPOS
CMP PVSAVE
BEQ PACUPS
SEC
LDA PACSCN
SBC #$28
STA PACSCN
LDA PACSCN+1
SBC #0
STA PACSCN+1
PACUPS LDY #6;POINT TO PACTOP
JMP MOVPAC
PACDN LDA PACCNT
BNE PACDNS
INC PMVPOS
INC PMVPOS
LDA PACMAP
CMP #3
BNE INCPMP
LDA #0
STA PACMAP
LDA PMVPOS
CMP PVSAVE
BEQ PACDNS
CLC
LDA PACSCN
ADC #$28
STA PACSCN
LDA PACSCN+1
ADC #0
STA PACSCN+1
BNE PACDNS
INCPMP INC PACMAP
PACDNS LDY #8;POINT TO PACBOT
JMP MOVPAC
PACRT LDA PACCNT
BNE PACRTS
;
LDA PMHPOS
CMP #$CA
BNE NORTTN
LDA #$2A
STA PMHPOS
LDA #$8F
STA PACSCN
;
NORTTN INC PMHPOS
LDA PACBYT
CMP #3
BNE INCPBY
LDA #0
STA PACBYT
LDA PMHPOS
CMP PHSAVE
BEQ PACRTS
INC PACSCN
BNE PACRTS
INC PACSCN+1
BNE PACRTS
INCPBY INC PACBYT
PACRTS LDY #2;POINT TO PACRGT
BNE MOVPAC
PACLF LDA PACCNT
BNE PACLFS
;
LDA PMHPOS
CMP #$2A
BNE NOLFTN
LDA #$CA
STA PMHPOS
LDA #$B7
STA PACSCN
;
NOLFTN DEC PMHPOS
LDA PACBYT
BNE DECPBY
LDA #3
STA PACBYT
BNE PACLFS
DECPBY DEC PACBYT
BNE PACLFS
LDA PMHPOS
CMP PHSAVE
BEQ PACLFS
SEC
LDA PACSCN
SBC #1
STA PACSCN
LDA PACSCN+1
SBC #0
STA PACSCN+1
PACLFS LDY #4;POINT TO PACLFT
BNE MOVPAC
PACOPN LDA PMODIR
CMP #1
BNE POPNDN
LDY #6; UP
BNE SETOPN
POPNDN CMP #2
BNE POPNLF
LDY #8; DOWN
BNE SETOPN
POPNLF CMP #4
BNE POPNRT
LDY #4; LEFT
BNE SETOPN
POPNRT CMP #8
BNE PACSTP
LDY #2
SETOPN LDA #$0A
BNE STRPAC
PACSTP LDY #0;POINT TO PACDOT
TYA
BEQ STRPAC
MOVPAC LDX PMSEQU
BNE PACSID
INC PMSEQU
BNE PACSTP
PACSID DEX
LDA PACIDX,X
CPX #2
BNE INCPSQ
LDX #$FF
STX PMSEQU
INCPSQ INC PMSEQU
STRPAC TAX
LDA PACADD,Y
STA PIXGET
INY
LDA PACADD,Y
STA PIXGET+1
TXA
CLC
ADC PIXGET
STA PIXGET
LDA #0
ADC PIXGET+1
STA PIXGET+1
LDY #9
PMBFLP LDA (PIXGET),Y
STA PACBUF+3,Y
DEY
BPL PMBFLP
LDA #LOW PACBUF
STA PIXGET
LDA #HIGH PACBUF
STA PIXGET+1
LDA PMVPOS
STA PIXPUT
LDA #HIGH PMADDR+3
STA PIXPUT+1
CLC
LDA PMHPOS
STA HPOSM3
ADC #2
STA HPOSM2
ADC #2
STA HPOSM1
ADC #2
STA HPOSM0
LDY #$0F
PPLOOP LDA (PIXGET),Y
STA (PIXPUT),Y
DEY
BPL PPLOOP
PMSIXX RTS
;
; MUNCHY SUBROUTINE EATS DOTS
;
MUNCHY LDA PACBYT
BNE MUNCHX
LDA PACMAP
BNE MUNCHX
LDA PMHPOS
CMP PHSAVE
BNE NWPREF
LDA PMVPOS
CMP PVSAVE
BEQ PMSIXX
NWPREF LDA PMVPOS
STA PVSAVE
LDA PMHPOS
STA PHSAVE
LDY #0
LDA (PACSCN),Y
CMP #1
BEQ EATSML
CMP #2
BNE MUNCHX
TYA
STA (PACSCN),Y
RTS
EATSML STA SCOREX+4
JSR PSCORE
LDA #1
STA EATERF
STA PACDLY
LDA #0
STA EATERC
LDA EATERT
BNE ZEATER
LDA #1
BNE SEATER
ZEATER LDA #0
SEATER STA EATERT
LDA #0
TAY
STA (PACSCN),Y
INCDOT LDX PLYNUM
INC DTCTL1,X
BNE CHKMAX
INC DTCTM1,X
CHKMAX LDX PLYNUM
LDA DTCTM1,X
BEQ MUNCHX
LDA DTCTL1,X
CMP #4
BNE MUNCHX
LDA #1
STA RRFLAG
MUNCHX RTS
;
DOTTST LDX PLYNUM
LDA BIGDT1,X
STA TEMLOC
LDX PMVPOS
LDY PMHPOS
LDA #1
BIT TEMLOC
BEQ DT2TST
CPX #$3C
BNE DT2TST
CPY #$3A
BEQ DOTFND
DT2TST ASL A
BIT TEMLOC
BEQ DT3TST
CPX #$3C
BNE DT3TST
CPY #$BE
BEQ DOTFND
DT3TST ASL A
BIT TEMLOC
BEQ DT4TST
CPX #$A4
BNE DT4TST
CPY #$3A
BEQ DOTFND
DT4TST ASL A
BIT TEMLOC
BEQ MUNCHX
CPX #$A4
BNE MUNCHX
CPY #$BE
BNE MUNCHX
DOTFND EOR #$0F
AND TEMLOC
LDX PLYNUM
STA BIGDT1,X
LDA #5
STA SCOREX+4
JSR PSCORE
LDA #1; SET UP FOR BLUE MONSTERS
STA FLASHC
LDA #$FF
STA GLPCNT
LDX PLYNUM
LDA MAZCT1,X
TAX
LDA BLUTIM,X
STA FLITMR
LDX #3
SETFLL LDA M1STAT,X
ASL A
BMI NXTFLL
LDA M1STAT,X
ORA #$80; SET STATUS = FLIGHT
STA M1STAT,X
LSR A
LSR A
LSR A
BCS NXTFLL
;
AND #$3B
BEQ NXTFLL
LDA M1DIRT,X
TAY
LDA BLUREV,Y
STA M1DIRT,X
;
NXTFLL DEX
BPL SETFLL
JMP INCDOT
;
; PSCORE WILL ADD ANY POINTS
; SCORED TO THE PLAYERS' SCORE
;
PSCORE LDA #0;PSCORE SUBR
STA CARRYB
SED
LDA PLYNUM
BEQ PSCOR1
LDX #$4C
BNE PSCORX
PSCOR1 LDX #$2F
PSCORX LDY #5
KSCORE CLC
LDA TEXT,X
AND #$0F
ADC CARRYB
ADC SCOREX,Y
PHA
AND #$10
BEQ NOCARY
LDA #1
NOCARY STA CARRYB
PLA
ORA #$10
CMP #$10
BNE STRSCR
CPY #0
BNE TESLED
TYA
BEQ STRSCR
TESLED LDA TEXT-1,X
BNE NOLEAD
LDA CARRYB
BEQ STRSCR
NOLEAD LDA #$10
STRSCR STA TEXT,X
DEX
DEY
BPL KSCORE
CLD
LDX #5
LDA #0
CLRSCR STA SCOREX,X
DEX
BPL CLRSCR
CKBONS LDX PLYNUM
LDA BPACP1,X
BNE NOBONS
CPX #0
BNE CKBON2
LDA TEXT+$2B
BNE BONUSP
NOBONS RTS
CKBON2 LDA TEXT+$48
BEQ NOBONS
BONUSP INC BPACP1,X
INC XPACP1,X
JMP UDXPACS
;
; MAZE HANDLER SUBROUTINE
;
; ENTRY:
; A REG VALUE EQUALS VPOS
; Y REG VALUE EQUALS HPOS
;
; EXIT:
; A REG VALUE EQUALS PERMISSIBLE
; DIRECTIONS FOR ANY OBJECT FROM
; ANY POSITION
;
; BIT 0 SET - UP OK
; BIT 1 SET - DN OK
; BIT 2 SET - RT OK
; BIT 3 SET - LF OK
;
; CARRY BIT IS SET IF
; DECISION POINT WAS REACHED
; OTHERWISE IT IS CLEARED.
;
MAZHND LDA M1HPOS,X
STA HSAVER
LDA M1VPOS,X
STX TEMLOC
LDX #9
MHORLP CMP VTABLE,X;SEARCH VPOS
BEQ VRTFND;MATCH FOUND
DEX
BPL MHORLP;KEEP LOOKING
LDA HSAVER;NONE FOUND SO TRY HPOS
LDY #9
MVRTLP CMP HTABLE,Y;SEARCH HPOS
BEQ HORFND;MATCH FOUND
DEY
BPL MVRTLP
VRTFND LDY #9;NOW WE CHECK HPOS TABLE
LDA HSAVER; TO SEE IF DECISION PT.
VRTFNL CMP HTABLE,Y
BEQ CHOICE;YES - MAKE CHOICE
DEY
BPL VRTFNL
LDA #$0C;NO - KEEP GOING
CLC
BCC MAZHNX
HORFND LDA #3; ONLY ONE MATCH FOUND
CLC
BCC MAZHNX
CHOICE TXA;NOW INDEX INTO TABLE
ASL A
TAX
LDA HTBADD,X
STA PIXGET
INX
LDA HTBADD,X
STA PIXGET+1
LDA (PIXGET),Y
SEC
MAZHNX LDX TEMLOC
STA TEMLOC
PHP
CPX #4
BEQ MAZHX1
LDA M1DIRT,X
TAY
LDA TEMLOC
AND REVTAB,Y
STA TEMLOC
LDA M1VPOS,X
CMP #$64
BNE MAZHX1
LDA M1HPOS,X
CMP #$76
BEQ MASKIT
NEXTMU CMP #$82
BNE MAZHX1
MASKIT LDA M1STAT,X
BMI MASKSD
LDA TEMLOC
AND #$0E
BNE MASKUP
MASKSD LDA #1
MASKUP STA TEMLOC
MAZHX1 LDA TEMLOC
PLP
RTS
;
VCHASE LDA #0
STA VFLITS
LDA VCHASS
BNE VCHDIR
LDA #$28
STA VCHASF
LDA #1
STA VCHASS
STA VCHASD
VCHDIR LDA VCHASD
CMP #1
BNE VCHADN
LDA VCHASF
CMP #$40
BCC VCUPOK
LDA #2
STA VCHASD
BNE VCDNOK
VCUPOK LDA WHINEY
CLC
ADC VCHASF
BNE STRVCH
VCHADN LDA VCHASF
CMP #$28
BCS VCDNOK
LDA #1
STA VCHASD
BNE VCUPOK
VCDNOK SEC
LDA VCHASF
SBC WHINEY
STRVCH STA VCHASF
STA AUDF2
LDA #$A1
STA AUDC2
VCHASX RTS
;
BLINKR LDA RTCLOK+2
AND #$0F
BEQ BLNKON
CMP #8
BEQ BLNKOF
RTS
BLNKON LDY #2
LDX PLYNUM
LDA BIGDT1,X
STA TEMLOC
LDA #1
BIT TEMLOC
BEQ BKOND2
STY PACMAZ+$7B
BKOND2 ASL A
BIT TEMLOC
BEQ BKOND3
STY PACMAZ+$9C
BKOND3 ASL A
BIT TEMLOC
BEQ BKOND4
STY PACMAZ+$283
BKOND4 ASL A
BIT TEMLOC
BNE BKONX1
BKONXX RTS
;
BLNKOF LDY #0
STY PACMAZ+$7B
STY PACMAZ+$9C
STY PACMAZ+$283
BKONX1 STY PACMAZ+$2A4
RTS
;
;
; SPEED SEQUENCING FOR OBJECTS
;
; X REG = INDEX VALUE FOR OBJECT
;
; X=0 TO 3 FOR MONSTERS 1 - 4
; X=4 FOR PACMAN
;
; ON EXIT:
; A REG = 0 INDICATES UPDATE TIME
;
SPDSEQ DEC M1SPCT,X
BEQ NXSPSQ
LDA #$FF
RTS
NXSPSQ LDA M1SPSQ,X
CMP #3
BNE INCSPS
LDA #$FF
STA M1SPSQ,X
INCSPS INC M1SPSQ,X
LDY PLYNUM
LDA MAZCT1,Y
CMP #6
BCC LOWSPD
LDA #6
LOWSPD TAY
CPX #4
BNE MXSPSQ
LDA PACSPD,Y
BPL LDSPSQ
MXSPSQ LDA MONSPD,Y
LDSPSQ CLC
ADC M1SPSQ,X
TAY
LDA SPEED1,Y
STA M1SPCT,X
LDA #0
RTS
;
; CHASE SEQUENCING
;
CHSSEQ LDA RTCLOK+2
AND #7
BNE CHSSQ1
LDA CHASET
BEQ CHSSQ1
DEC CHASET
CHSSQ1 LDX PLYNUM
LDA DTCTM1,X
BEQ CHMAD1
VRYMAD LDX #3
JSR SETMAD
LDA #5
BNE STWHIN
CHMAD1 LDA DTCTL1,X
CMP #$F0
BCS VRYMAD
CMP #$E0
BCC SMLMAD
LDX #2
JSR SETMAD
LDA #4
BNE STWHIN
SMLMAD CMP #$B0
BCC NOTMAD
LDA #3
BNE STWHIN
NOTMAD LDA #2
STWHIN STA WHINEY
CHSSQ2 LDX #3
CHSSQL LDA M1STAT,X
CMP #8
BEQ TSTCHS
CMP #$10
BEQ TSTCHS
BNE NXCHSQ
TSTCHS JSR SEEPAC
NXCHSQ DEX
BPL CHSSQL
RTS
;
SETMAD LDA M1STAT,X
CMP #8
BEQ YESMAD
CMP #$10
BEQ YESMAD
CMP #$20
BNE NXSTMD
YESMAD LDA #2
STA M1STAT,X
NXSTMD DEX
BPL SETMAD
STX CHASET
RTS
;
FRUITY LDA FRSCRF
BEQ TSTFRT
LDA FRSCRT
BNE DCFRST
LDA #0
STA FRSCRF
LDX #4
CLFRSL STA PACMAZ+$1F1,X
DEX
BPL CLFRSL
RTS
DCFRST DEC FRSCRT
DCFRSX RTS
TSTFRT LDA FRUFLG
BNE DFRTMR
LDX PLYNUM
LDA DTCTL1,X
TAY
LDA FRUTP1,X
BEQ FRTST1
CMP #1
BEQ FRTST2
RTS
FRTST1 CPY #$50
BEQ SETFRT
FRTST2 CPY #$A0
BNE DCFRSX
SETFRT INC FRUTP1,X
LDA MAZCT1,X
CMP #$0C
BCC LOWFRC
LDA #$0C
LOWFRC TAX
LDA FRUCHR,X
STA PACMAZ+$1F3
CLC
ADC #1
STA PACMAZ+$1F4
LDA #1
STA FRUFLG
LDA #FDELAY
STA FRUTMR
LDA #2
STA FRUTMR+1
RTS
DFRTMR LDA FRUTMR+1
BNE DCFRTM
LDA FRUTMR
BNE DCFRTM
LDA #0
STA PACMAZ+$1F3
STA PACMAZ+$1F4
STA FRUFLG
RTS
DCFRTM DEC FRUTMR
BNE FRUITX
DEC FRUTMR+1
FRUITX RTS
;
STA FR