-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacLinePanic.asm
More file actions
3366 lines (3160 loc) · 93.8 KB
/
Copy pathPacLinePanic.asm
File metadata and controls
3366 lines (3160 loc) · 93.8 KB
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
; Pac-Line Panic
;
; (C)2025 - Thomas Jentzsch
processor 6502
LIST OFF
include vcs.h
LIST ON
; Legend:
; - open
; o partially done
; + done
; x cancelled
; ? maybe
; BUGs:
; - #6 why is extra WSYNC required for Stella? (Stella bug?)
; TODOs:
; - AI has problems with 1st pellet left of center
; - PAL color checks
; - update version number
; - ...
; Ideas:
; x alternative theme (for cart release)
; ? robots (cute, bad)
; - collecting tools: screw, screwdriver, screw nut, wrench,
; batteries, pliers, multi meter, drilling machine
; ? Jawbreaker jaws and smilies + Fruits
; ? animals
; ? spaceships
; ? cars (police?)
; ? abstract
; ? ZPH: Cats, Toys, Treats
; ? ...
; ? pellets, wafers, dots...?
; x wider enemies?
; x deadly bonuses (mushrooms)
; x countdown with player graphics eating pellets
; x high score screen (787 cycles per line?)
; x 16-bit random
; DONEs:
; + difficulty ramp up
; + speeds
; + enemies and players seperately
; + by value
; + enemies slower than players at start
; + enemies accelerate faster than players
; + maximum speed for players and enemies
; + players reach maximum speed earlier than enemies
; + different start lines (e.g. 1, 5, 9; displayed with starting line)
; x globally
; x individually
; + mixed (lines individual, speed global)
; + speed defined by
; x time
; x individual line
; + global line (human players only)
; + AI
; + enemies (following player)
; + hunting: move to player (no wrapping)
; + running: move to side away from player
; + dead : move to far away side
; + follow further to the left
; + display
; + score
; + color gradients
; + line
; + displayed player number
; x hex score stored, converted to BCD (up to 65,535 instead 9,999)
; + display top score
; x display score of player which changed line last
; x display score of player which set new maximum line
; + do not display "Ln. 0"
; + display player number alterating with rank number (solves close colors problem)
; + bonus items
; + based on current individual line
; + when should they appear?
; + either at start of new line (delayed?)
; x or when power-up gets collected (disapear at next line)
; + when shoud bonuses disappear?
; x disappear at border
; x when power-up gets eaten
; + when line is finished
; x never (when eaten or new bonus appears)
; + running enemies graphics/colors
; + align collecting animation with pellets (sync animation with position)
; + delay ghost/bonus collisions (at least 50% overlapping)
; + in AI row, dark/grey...
; + ghost, blink, eyes
; + bonus
; + lines
; x pellets & power pill
; + controls
; + dectect QuadTari
; + start game
; + active player
; + reverse direction
; + RESET, SELECT
; + game variations (2x4)
; + game states
; + %00, select (before start and at end of game)
; + %10, start
; + %11, running
; + %01, over (all human players killed)
; + controls
; + press/release to switch directions
; + hold = left, release = right
; + diffiulty switch changes controls
; + replace "lvl" with "ln."
; + #2 sometimes sound after game over
; - #1 powerLst might be able to become $ff
; + demo mode
; + when no player got activated during start
; x stop with button press
; + AI computer players
; x reverse direction if ghost comes too close:
; dist to border opposite of enemy/player speed < dist of ghost/enemy speed
; (dP/sP < dE/sE => dP*sE < dE*sP)
; x simplyfied: reverse at 8 - dist enemy from its border
; + move to middle pellets after power pill
; + better player animation
; + alive, based on pos
; + dead, based on power timer
; + remove ghost at death
; + 1st select after game over must not change variation
; + fire after game over should directly start new game (like RESET)
; + start with bonus game variations
; + display high score during game select
; + high score
; + score and line
; + determine
; + play sound for new high score (when reached and was not zero before)
; + reset
; + when game variation changes
; + keep for same variation as high score
; + save (PlusROM only)
; + #3 timer overflows
; + caused by high score display
; + caused by too many player/enemy collisions in the same frame
; + caused by too much AI logic in the same frame
; Ideas:
; + move code into VSYNC
; + do not calc from scratch every frame (.maxLine , firstPlayer)
; + optimize code
; + check timer and abandon early
; + sound
; + only human players
; + prios:
; + channel 0: death, bonus, waka-waka (alternating "wa" and "ka")
; + channel 1: enemy eaten, eyes, scared, siren (pitch based on game speed)
; + countdown
; x start
; x game over sound
; + new high score (player sound, 10x ding)
; + #4 game starts with line not score
; + #5 AI players are not dying completely at end of game
; x larger power-up pellet
; + debounce uses only 1 bit, saves 6 bytes
; + extend score display intervals
; + different font (Pac-Man)
; + fire buttun aborts demo and resets game
; + support old and new controls (left difficulty)
; + demo mode
; + repeating after score loop
; + sound
; x automatic start
; + increased scores for later lines (must not overflow!)
; + line div 4 is OK (up to 8976 points at line 44)
; + multiply with BCD is slow, reduce CPU time in overscan:
; + pellet collision check for only 50% players
; x hiscore check only for 1 or 2 players/frame (??? cycles at game start)
; x powertim counter variable (for SCARED sound) (~200 cylces)
; + merge Left- and RightDigitPtr
; + flicker
; x all 3 objects
; + Enemy and Bonus?
; x Player and Enemies when Bonus arrives (player is never over a pellet)
; x ghost color value boost
; x check both (enemy & bonus) collisions every frame
; + add powerTim counter (optional)
; + only highest bonus from line 32 on
; + #7 score display after demo mode starts wrong
; + PlusCart tests
; x replace top fruits with original Pac-Man items: Galaxian, Bell, Key
; + load high score from PlusROM backend:
; x check and set request active flag
; + work if no PlusROM
; + initial loading (variation 0)
; + load high scores
; + #8 fix high scores loading, use delay (wait 1s after SELECT)
; + sent each high score
;---------------------------------------------------------------
; *** Code Structure ***
; OverScan
; - determine maximum human player line
; - handle player/pellet collisions
; - handle player/enemy collisions
; - update audio
;---------------------------------------
; DrawScreen
; - score kernel
; - 8 x game kernel
;---------------------------------------
; VerticalBlank
; - check console switches
; - setup player, enemy & bonus speeds
; - move players, enemies and bonuses
; - update player directions
; - prepare display
; Note: This means that collisions are checked after display and before players
; get moved
;===============================================================================
; A S S E M B L E R - S W I T C H E S
;===============================================================================
GAME_NAME = "Pac-Line Panic"
VERSION = $0120
BASE_ADR = $f000 ; 4K
IFNCONST TV_MODE ; manually defined here
NTSC = 1
PAL60 = 0
PAL50 = 0 ; not supported!
ENDIF
include tv_modes.h
ILLEGAL = 1
DEBUG = 1
SAVEKEY = 0 ; (-~220) support high scores on SaveKey (too many bytes)
PLUSROM = 1 ; (-34) save current variation's high score to PlusStore HSC backend
PLUSROM_LOAD = 1 ; (-52) load current variation's high score from PlusStore HSC backend
COPYRIGHT = 0 ; (-40/41) add copyright notice into code
COPYRIGHT_SHORT = 0 ; (-21/22) add short copyright notice into code
RAND16 = 0 ; (-3, -1 RAM) 16-bit random values
FRAME_LINES = 1 ; (-12) draw white lines at top and bottom
SWITCH_DIR = 1 ; (-28, -1 RAM)
BUTTON_DIR = 1 ; (-4) button press directly determines direction
; (-5, if both enabled
BIG_MOUTH = 1 ; (0) bigger mouth for player
HISCORE_DING = 1 ; (-99) 10 dings at new high score
EXTEND_COUNTDOWN= 1 ; (-12) extends countdown with each new activated player
LONG_DEATH = 1 ; (-??) = 0 is still TODO
LIMIT_LINE = 0 ; (-9) limit line to 99 (doubtful that this can ever be reached)
DEMO_SOUND = 1 ; (-12/15) play sounds during demo mode
MULT_SCORE = 1 ; (-25) multiply scores by line/4
POWER_CNT = 0 ; (-6) count active power-ups (saves some cycles if required)
MAX_BONUS = 1 ; (-12) only highest bonus item(s) after line 32
ALL_HISCORES = 1 ; (-4) send all high scores
THEME_ORG = 1
THEME_ALT_1 = 0 ; TODO
THEME_ALT_2 = 0 ; TODO
THEME_ALT_3 = 0 ; TODO
;===============================================================================
; C O L O R - C O N S T A N T S
;===============================================================================
FRAME_COL = WHITE
AI_LUM = 4
;===============================================================================
; G A M E - C O N S T A N T S
;===============================================================================
EOR_RND = $bd ; %10110100 ($9c, $b4, $bd, $ca, $eb, $fc)
SCW = 160
PELLET_H = 2
POWER_H = 6
SPRITE_W = 8
NUM_PLAYERS = 8
NUM_VARIATIONS = 8 ; TODO (8|4... saves 7 bytes)
POWER_TIM = 140
NUM_BONUS = 8 ; enough for 32 lines
X_BONUS_OFF = $ff
BONUS_SHIFT = 2 ; 2 = every 4th line
BONUS_MASK = (1<<BONUS_SHIFT)-1
; Note: player has to be able to reach a most centered power-up. That's the 8th
; spot from left or right. Meanwhile the enemy has to move 12 spots, which is
; 50% more. So the speed difference should be a bit below 50%.
; | o o o o o o o O . . . . O o o o o o o o|
DELTA_SPEED = 140 ; 40% delta; start: player d% faster, end: enemy d% faster
INIT_EN_SPEED = 48
DIFF_EN_SPEED = 6
MAX_EN_SPEED = 255 ; reached after 35 lines
INIT_PL_SPEED = (INIT_EN_SPEED * DELTA_SPEED + 50) / 100 ; -> equal speed after ~9 lines
DIFF_PL_SPEED = DIFF_EN_SPEED - 2 ; = 4
MAX_PL_SPEED = (MAX_EN_SPEED * 100 + DELTA_SPEED / 2) / DELTA_SPEED ; reached after 29 lines
; ECHO " player vs enemy"
; ECHO "Speeds: ", [MAX_PL_SPEED]d, "vs", [MAX_EN_SPEED]d
; ECHO "Ranges:", [MAX_PL_SPEED*100/8]d, "vs", [MAX_EN_SPEED*100/12]d
; ECHO ""
PELLET_PTS = 1
POWER_PTS = 5
ENEMY_PTS = 10
SCORE_TIM = FPS * 3 / 2
; gameState constants:
DIFF_MASK = $03 ; game variation
NO_BONUS_GAME = $04 ; no bonus game flag
VAR_MASK = DIFF_MASK|NO_BONUS_GAME
IF HISCORE_DING
HISCORE_DINGED = $08
ENDIF
QT_RIGHT = $10 ; bit 5==0: left QuadTari; bit 4==1: right QuadTari
QT_LEFT = $20
QT_MASK = QT_LEFT|QT_RIGHT
;GAME_SELECT = $00
GAME_START = $80
GAME_RUNNING = $c0
GAME_OVER = $40
GAME_MASK = $c0
;Select -> press & release -> Start -> 5s -> Run -> Over -> 2s -> press & release -> Select
; 00 = select?
; 10 = game start, select active players
; 11 = game running
; 01 = Game over, display scores of human players
DEBOUNCE = $80
NUM_TMPS = 6
STACK_SIZE = 6 ; used in score & kernel row setup
;===============================================================================
; Z P - V A R I A B L E S
;===============================================================================
SEG.U variables
ORG $80
frameCnt .byte ; even: enemy drawn, odd: bonus drawn
;frameCntHi .byte ; TODO: enable demo mode after (demo?) game over, in select mode (5 minutes? = 24000 frames)
randomLo .byte
IF RAND16 ;{
randomHi .byte
ENDIF ;}
debounce .byte ; D....... Debounce ; TODO: = powerTimLst?
;---------------------------------------
lineLst ds NUM_PLAYERS
;---------------------------------------
xPlayerLst ds NUM_PLAYERS ; 32 bytes
xEnemyLst ds NUM_PLAYERS
xBonusLst ds NUM_PLAYERS
xPowerLst ds NUM_PLAYERS
;---------------------------------------
playerAI .byte ; 0 = human, 1 = AI
hiScoreVar = playerAI
;---------------------------------------
resetLst = .
pfLst ds NUM_PLAYERS*3 ; 24 bytes
pf01LeftLst = pfLst
pf20MiddleLst = pfLst+NUM_PLAYERS
pf12RightLst = pfLst+NUM_PLAYERS*2
;---------------------------------------
; only used during GAME_RUNNING:
playerSpeed .byte
xPlayerFract .byte
enemySpeed .byte
xEnemyFract .byte
bonusSpeed = enemySpeed
xBonusFract .byte
maxLine .byte ; permanent value instead of calculated from scratch
firstPlayer .byte ; used if Get1stPlayerScore takes too long
; reused:
lastButtons = playerSpeed ; BBBBBBBB reused during GAME_SELECT & GAME_OVER
waitedOver = xPlayerFract ; ......WW reused during GAME_OVER
playerIdx = enemySpeed ; ....PPPP reused during GAME_OVER (score displayed when game is over)
ignoredScores = xEnemyFract ; IIIIIIII reused for displaying alternating scores
nxtIgnoredScores= xBonusFract
;---------------------------------------
; row bits:
IF SWITCH_DIR
buttonBits .byte ; 1 = pressed
ENDIF
playerLeft .byte ; 1 = left, 0 = right
enemyLeft .byte ; 1 = left, 0 = right
bonusLeft .byte ; 1 = left, 0 = right
playerDone .byte ; 0 = alive, 1 = dead/score rolled
enemyEyes .byte ; 0 = alive, 1 = eyes
;---------------------------------------
powerTimLst ds NUM_PLAYERS ; 8 bytes
IF POWER_CNT ;{
powerTimCnt .byte
ENDIF ;}
;---------------------------------------
audIdxLst ds 2
audIdx0 = audIdxLst
audIdx1 = audIdxLst+1
;---------------------------------------
scoreLst ds NUM_PLAYERS*2 ; 16 bytes
scoreLoLst = scoreLst
scoreHiLst = scoreLst+NUM_PLAYERS
NUM_RESETS = . - resetLst
;---------------------------------------
HISCORE_BYTES = 3
hiScoreLst ds HISCORE_BYTES ; must be followed by gameState for PlusROM HSC
hiScoreLo = hiScoreLst
hiScoreHi = hiScoreLst+1
hiScoreLine = hiScoreLst+2
gameState .byte ; MMrLDBVV Mode, Right/Left QuadTari, Dinged, Bonus, Variation
;---------------------------------------
countDown = scoreLoLst ; reused during GAME_START
;---------------------------------------
IF PLUSROM_LOAD
delayRequest .byte ; wait before loading high score
ENDIF
cxPelletBits .byte ; temporary
cxSpriteBits .byte ; temporary
RAM_END = .
; temp vars and stack form a consecutive area:
tmpVars = $100 - STACK_SIZE - NUM_TMPS
IF PLUSROM
WriteToBuffer = $1ff0 ; MUST be $1xxx (used for detection)!
WriteSendBuffer = $1ff1
ReceiveBuffer = $1ff2
ReceiveBufferSize = $1ff3
ENDIF
;===============================================================================
; M A C R O S
;===============================================================================
DEBUG_BYTES SET 0
MAC DEBUG_BRK
IF DEBUG
DEBUG_BYTES SET DEBUG_BYTES + 1
brk
ENDIF
ENDM
MAC NOP_IMM ; skip 1 byte, 2 cycles
.byte $82
ENDM
MAC NOP_B ; skip 1 byte, 3 cycles
.byte $04
ENDM
MAC NOP_W ; skip 2 bytes, 4 cycles
.byte $0c
ENDM
MAC SLEEP
IF {1} = 1
ECHO "ERROR: SLEEP 1 not allowed !"
END
ENDIF
IF {1} & 1
nop $00
REPEAT ({1}-3)/2
nop
REPEND
ELSE
REPEAT ({1})/2
nop
REPEND
ENDIF
ENDM
MAC _CHECKPAGE ; internal, do not use directly
IF (PASS > 0) && (>{1} != >{2})
LIST ON
ECHO ""
IF {3} != ""
ECHO "ERROR: different pages! (", {3}, "=", {2}, ",", {1}, ")"
ELSE
ECHO "ERROR: different pages! (", {2}, ",", {1}, ")"
ENDIF
ECHO ""
ERR
ENDIF
LIST ON
ENDM
MAC CHECKPAGE_LBL
LIST OFF
_CHECKPAGE ., {1}, {2}
ENDM
MAC CHECKPAGE
LIST OFF
CHECKPAGE_LBL {1}, ""
ENDM
MAC CHECKPAGE_DATA_LBL
LIST OFF
_ADDR SET . - 1 ; hack to convince DASM
_CHECKPAGE _ADDR, {1}, {2}
ENDM
MAC CHECKPAGE_DATA
LIST OFF
CHECKPAGE_DATA_LBL {1}, ""
ENDM
MAC VERSION_STR
.byte ((VERSION & $f00) >> 8) + 48
.byte "."
.byte ((VERSION & $0f0) >> 4) + 48
IF VERSION < $100 | (VERSION & $00f) != 0
; IF (VERSION & $00f) != 0
.byte ((VERSION & $00f) >> 0) + 48
ENDIF
ENDM
;---------------------------------------------------------------
; Free space macros
;---------------------------------------------------------------
ECHO_FREE SET 1 ; 1 = echo free space enabled
FREE_TOTAL SET 0 ; use only once
MAC OUT_FREE
FREE_GAP$ SET - .
{1} {2}
FREE_GAP$ SET FREE_GAP$ + .
FREE_TOTAL SET FREE_TOTAL + FREE_GAP$
IF ECHO_FREE && FREE_GAP$ > 0
ECHO "@", ., ": Gap:", [FREE_GAP$]d, "; Total:", [FREE_TOTAL]d, ";", {3}, {2}, {4}
ENDIF
ENDM
MAC ALIGN_FREE_LBL
LIST OFF
OUT_FREE ALIGN, {1}, "ALIGN", {2}
LIST ON
ENDM
MAC ALIGN_FREE
LIST OFF
ALIGN_FREE_LBL {1}, ""
ENDM
MAC COND_ALIGN_FREE_LBL ; space required, alignement, "label"
LIST OFF
IF (>(. + {1} - 1)) > (>.)
ALIGN_FREE_LBL {2}, {3}
ENDIF
LIST ON
ENDM
MAC COND_ALIGN_FREE ; space required, alignement
LIST OFF
COND_ALIGN_FREE_LBL {1}, {2}, ""
ENDM
MAC ORG_FREE_LBL
LIST OFF
OUT_FREE ORG, {1}, "ORG", {2}
LIST ON
ENDM
MAC ORG_FREE
LIST OFF
ORG_FREE_LBL {1}, ""
ENDM
MAC NEXT_PASS
IFNCONST PASS
PASS SET 0
ELSE
PASS SET PASS + 1
ECHO "Pass:", [PASS]d
ENDIF
ENDM
NEXT_PASS
MAC HEX2BCD ; hex value
; Hex2Bcd (good 0-99), 22 bytes, 26 cycles:
tax ; 2 0..$63
lsr ; 2
lsr ; 2
lsr ; 2
lsr ; 2
tay ; 2 0..3
txa ; 2
sed ; 2
clc ; 2
adc #0 ; 2
adc BcdTbl,y ; 4
cld ; 2 = 26
ENDM
IF PLUSROM
PLUSROM_ID = 84 ; Pac-Line Panic game id in Highscore DB
MAC COMMIT_PLUSROM_SEND
lda #PLUSROM_ID
sta WriteSendBuffer ; send request to backend...
ENDM
ENDIF ; /PLUSROM
;===============================================================================
; R O M - C O D E
;===============================================================================
SEG Bank0
ORG BASE_ADR
COPYRIGHT_LEN SET 0
;---------------------------------------------------------------
GameInit SUBROUTINE
;---------------------------------------------------------------
ldx #NUM_RESETS-1
lda #0
.loopReset
sta resetLst,x
dex
bpl .loopReset
sta AUDV0
sta AUDV1
stx frameCnt ; required for alternating from scratch in select mode
; setup initial board:
ldx #NUM_PLAYERS-1
.loopPf
jsr SetupPowerPellets
IF BIG_MOUTH = 0
lda #SCW*1/2-16 ; at right of left power-ups
ELSE
lda #SCW*1/2-16-1 ; at right of left power-ups
ENDIF
sta xPlayerLst,x
lda #SCW-8-1 ; right border-1
sta xEnemyLst,x
lda #X_BONUS_OFF ; no bonus
sta xBonusLst,x
lda #1
sta lineLst,x
dex
bpl .loopPf
stx VDELP0
stx VDELBL
rts
; /GameInit
; ds 10, 0 ; line kernel alignment (tight contraints!)
;---------------------------------------------------------------
DrawScreen SUBROUTINE
;---------------------------------------------------------------
.scorePtrLst = tmpVars
.scorePtr0 = .scorePtrLst ; lowest digit
.scorePtr1 = .scorePtrLst+2
.scorePtr2 = .scorePtrLst+4
.scorePtr3 = .scorePtrLst+6
.scorePtr4 = .scorePtrLst+8
.scorePtr5 = .scorePtrLst+10 ; highest digit
.scoreCol = cxPelletBits
.waitTim
lda INTIM
bne .waitTim
sta WSYNC
;---------------------------------------
sta HMOVE ; 3
sta VBLANK ; 3
ldy #FONT_H-1 ; 2 = 8
.loopScore ; @60
lda .scoreCol ; 3
and ScoreLums,y ; 4
sta COLUP0 ; 3
sta COLUP1 ; 3
sta WSYNC ; 3 = 16 zero cycles free!
;---------------------------------------
lda (.scorePtr5),y ; 5
sta GRP0 ; 3
lda (.scorePtr4),y ; 5
sta GRP1 ; 3
lda (.scorePtr3),y ; 5
sta GRP0 ; 3 = 24
lax (.scorePtr0),y ; 5
txs ; 2
lax (.scorePtr2),y ; 5
lda (.scorePtr1),y ; 5
stx GRP1 ; 3 = 20 @44
sta GRP0 ; 3 @47
tsx ; 2
stx GRP1 ; 3 @52
sta GRP0 ; 3 = 11
dey ; 2
bpl .loopScore ; 3/2= 5/4
iny ; 2
sty ENABL ; 3
sty GRP1 ; 3
sty GRP0 ; 3
sty GRP1 ; 3
sty NUSIZ0 ; 3 = 17
;---------------------------------------
sty NUSIZ1 ; 3
sty VDELP1 ; 3
sty GRP1 ; 3
ldx #$ff ; 2
txs ; 2
lda #%010000 ; 2
sta CTRLPF ; 3 = 20
;---------------------------------------------------------------
.loopCnt = tmpVars
.color0 = .loopCnt
.bonusFlag = tmpVars+1
.lineCol = tmpVars+2
.ptrCol0 = tmpVars+3
.ptrCol1 = tmpVars+5
.ptr0 = tmpVars+7 ; used as stack by lines drawing
.ptr1 = tmpVars+9 ; same
.enaBl = tmpVars+11 ; same
lda frameCnt ; 3
lsr ; 2
lda #$ff ; 2
adc #0 ; 2
sta .bonusFlag ; 3 = 10 0 = (potential) bonus frame, $ff = enemy frame
; TODO?: use for lineLst,x >> 2, and #$07
lda #>ColorTbls
sta .ptrCol0+1
IF FRAME_LINES
lda #FRAME_COL
ELSE
lda #0
ENDIF
sta .lineCol
ldx #NUM_PLAYERS-1
.loopKernels ; @65
stx .loopCnt ; 3 = 3
IF THEME_ORG
lda Pot2Bit,x ; 4
sta WSYNC ; 3 = 7 @71
;---------------------------------------
sty GRP1 ; 3 Y == 0!
; *** draw lines between players ***
; setup player sprite direction:
ldy #8 ; 2
and playerLeft ; 3
beq .right0 ; 2/3
NOP_B ; 1
.right0
dey ; 2
sty REFP0 ; 3 = 13
ELSE ;{THEME_ALT_1|THEME_ALT_2|THEME_ALT_3
sta WSYNC ; 3 = 3
;---------------------------------------
sty GRP1 ; 3 Y == 0!
SLEEP 13
ENDIF ;}
SLEEP 16-13
X_OFS = 48
; prepare player: ; 3 @20!
lda xPlayerLst,x ; 4
clc ; 2
adc #X_OFS ; 2
pha ; 3 x-pos
lda #0 ; 2
pha ; 3 index
; lda #0 ; 2
pha ; 3 = 19 color
; prepare enemy/bonus:
lda xBonusLst,x ; 4
ora .bonusFlag ; 3 0|$ff
cmp #X_BONUS_OFF ; 2 if xBonus = OFF, draw enemy
LinesBranches
bne .positionBonus ; 2/3
; position enemy:
lda xEnemyLst,x ; 4
adc #X_OFS-1 ; 2
.contBonus ; = 17 @56!
pha ; 3 x-pos
lda #1 ; 2
pha ; 3 index
lda .lineCol ; 3
pha ; 3 = 14 color
; prepare power-up (not drawn from stack):
lda xPowerLst,x ; 4 x-pos
ldx #4 ; 2 = 6 index
;---------------------------------------
ldy #0 ; 2 color @01
; clc ; 2
adc #X_OFS ; 2
sec ; 2
bcs .enterLoop ; 3 = 9! @08!
.positionBonus ;12
adc #X_OFS ; 2
bcc .contBonus ; 3 = 17
;---------------------------------------------------------------
.rightPos ; @14
sbc #X_OFS+15*5 ; 2
.waitRight
sbc #$0f ; 2
bcs .waitRight ; 3/2 @34
tay ; 2
lda HMoveTbl-$f1,y ; 5!
sta HMP0,x ; 4
pla ; 4 color
tay ; 2
pla ; 4 index
cpx #1 ; 2
sta.wx RESP0,x ; 5 = 34.. @48..73!
sta WSYNC ; 3
;---------------------------------------
bcc .exit ; 2/4!
tax ; 2
.next
pla ; 4 = 8 @08 x-pos 48..208
.enterLoop ;
sty COLUBK ; 3
bmi .rightPos ; 2/3= 5/6 @13/14
sbc #X_OFS ; 2 CF == 1! BUG#1: this can become $ff!
.waitLeft
sbc #$0f ; 2
bcs .waitLeft ; 3/2
CHECKPAGE LinesBranches
sta RESP0,x ; 4 = 10 @23..48!
tay ; 2
lda HMoveTbl-$f1,y ; 5!
sta HMP0,x ; 4
pla ; 4 color
tay ; 2
pla ; 4 index
cpx #1 ; 2
tax ; 2
sta WSYNC ; 3 = 28
;---------------------------------------
IF >. = >.next
ECHO ""
ECHO "ERROR: Must be in different pages!"
ERR
ENDIF
bcs .next ; 4/2= 4/2 we need 4 cycles here!
.exit ; @02/04, CF == 0
TIM_0a
ldx .loopCnt ; 3
txs ; 2 store .loopCnt in SP
; setup player color pointer:
ldy #<HumanColMask ; 2
lda gameState ; 3 display colors in demo mode
and #GAME_MASK ; 2
eor #GAME_START ; 2 GAME_START?
bne .startMode ; 2/3 no, color all sprites
lda playerAI ; 3
and Pot2Bit,x ; 4
cmp #1 ; 2 also sets AI state
.startMode
lda LineCols,x ; 4
bcc .brightLine ; 2/3
ldy #<AIColMask ; 2
eor #(LINE_LUM ^ AI_LUM); 2 -> lum == 2
.brightLine ;
sta .lineCol ; = ..35
sty .ptrCol0 ; 3 = 3
TIM_0b
sta WSYNC
;---------------------------------------
sta COLUBK ; 3 = 3
TIM_1a ; timers have problems with preceding WSYNCs!
; setup player sprite pointer:
lda PlayerCol,x ; 4
sta .color0 ; 3
lda playerDone ; 3
and Pot2Bit,x ; 4
beq .playerAlive ; 2/3=16/17
; death animation:
lda powerTimLst,x ; 4
lsr ; 2
lsr ; 2
lsr ; 2
clc ; 2
adc #NUM_ALIVE_PTR ; 2
tay ; 2
bpl .playerLeft ; 3 = 19+7
.playerAlive
lda xPlayerLst,x ; 4 animate in sync with position (= speed based)
and #7 ; 2
tay ; 2
lda playerLeft ; 3
and Pot2Bit,x ; 4
bne .playerLeft ; 2/3
iny ; 2 adjust animation when going right
.playerLeft
lda PlayerPtr,y ; 4
sta .ptr0 ; 3 = 25/26
; setup power-up pointer:
ldy #2 ; 2
lda #0 ; 2
TIM_1b ; 46..47 (+6) cycles
sta WSYNC ; 3 = 7
;---------------------------------------
sta HMOVE ; 3
TIM_2a
sta COLUBK ; 3
lda xPowerLst,x ; 4
bne .showPower ; 2/3
dey ; 2
.showPower ; = 9/10
sty .enaBl ; 3 = 9
; draw enemy or bonus:
bit .bonusFlag ; 3 bonus frame?
bmi .drawEnemy ; 2/3 no, flicker draw enemy
lda xBonusLst,x ; 4
eor #X_BONUS_OFF ; 2
beq .drawEnemy ; 2/3=13/14
; draw bonus:
lda lineLst,x ; 4
REPEAT BONUS_SHIFT
lsr ; 2/4/6 every 4th line
REPEND ; = 6..10
IF MAX_BONUS
cmp #NUM_BONUS ;
bcc .lowerLine
lda #0 ; show top bonus
.lowerLine
ENDIF
and #NUM_BONUS-1 ; 2
tay ; 2
lda BonusPtr,y ; 4
sta .ptr1 ; 3
lda BonusColPtr,y ; 4
ldy .ptrCol0 ; 3
cpy #<AIColMask ; 2 AI row?
bne .setColPtr1B ; 2/3 no
lda #<GreyCol ; 2
.setColPtr1B
sta .ptrCol1 ; 3
ldy #0 ; 2 = 20
beq .setRefP1 ; 3 = 3
.drawEyes ; @45
ldy #<GreyCol ; 2
bcs .setColPtr1Eyes ; 2/3 AI row
ldy #<EnemyEyesCol ; 2
.setColPtr1Eyes
sty .ptrCol1 ; 3
ldy #<EnemyEyesGfx ; 2
bne .setPtr1 ; 3
.powerOff
ldy #<GreyCol ; 2
bcs .setPtrCol1 ; 2/3 AI row
ldy EnemyColPtr,x ; 4
.setPtrCol1
sty .ptrCol1 ; 3 = 8/11
ldy #<EnemyGfx0 ; 2
lda xEnemyLst,x ; 4
and #$04 ; 2
bne .setPtr1 ; 2/3
ldy #<EnemyGfx1 ; 2
NOP_W ; 2
.hideEnemy
ldy #<NoEnemyGfx ; 2
bne .setPtr1 ; 3
.drawEnemy ;
lda Pot2Bit,x ; 4
bit playerDone ; 3
bne .hideEnemy ; 2/3
bit enemyEyes ; 3
bne .drawEyes ; 2/3= 9/10
; setup colors:
lda powerTimLst,x ; 4
beq .powerOff ; 2/3= 6/7
; power on:
ldy #<GreyCol ; 2
bcs .setColPtr1x ; 2/3 AI row
ldy #<EnemyColDark ; 2
cmp #$50 ; 2
bcs .setColPtr1x ; 2/3