-
Notifications
You must be signed in to change notification settings - Fork 0
/
breakout.asm
1475 lines (1371 loc) · 31 KB
/
breakout.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
; Used DASM to compile
; see https://github.com/Julio-Rats/dasm
;
; Command to compile:
; dasm breakout.asm -obreakout.bin -f3
;
PROCESSOR 6502
INCLUDE "vcs.h"
INCLUDE "macro.h"
;===================================================================
; TV SYSTEM DEFINITION
;===================================================================
SYSTEM_TV = "NTSC" ; (NTSC, PAL)
;===================================================================
; NTSC 60 FPS
IF SYSTEM_TV == "NTSC"
KERNEL_SCANLINE = 192
SCAN_START_BORDER = 16
HEIGHT_LINES = 8
VBLANK_TIMER = 43
OVERSCAN_TIMER = 37
BORDER_COLOR = $04
PLAYER_COLOR = $F4
LINE_COLOR1 = $46
LINE_COLOR2 = $36
LINE_COLOR3 = $26
LINE_COLOR4 = $16
LINE_COLOR5 = $C6
LINE_COLOR6 = $86
;===================================================================
; PAL 50 FPS
ELSE
IF SYSTEM_TV == "PAL"
KERNEL_SCANLINE = 228
SCAN_START_BORDER = 24
HEIGHT_LINES = 8
VBLANK_TIMER = 52
OVERSCAN_TIMER = 44
BORDER_COLOR = $08
PLAYER_COLOR = $44
LINE_COLOR1 = $62
LINE_COLOR2 = $64
LINE_COLOR3 = $46
LINE_COLOR4 = $26
LINE_COLOR5 = $56
LINE_COLOR6 = $D6
;===================================================================
; OTHERS
ELSE
ECHO "TV SYSTEM NOT SUPPORTED!"
ENDIF
ENDIF
;===================================================================
;===================================================================
; Global Constants
;===================================================================
PLAYER_LIFE = 4
NUMBER_LINES = 6
NUMBER_SOUNDS = 4
HEIGHT_BORDER = 16
HEIGHT_PLAYER = 4
HEIGHT_BALL = 3
LAST_SCANLINE = (KERNEL_SCANLINE-3)
SPEED_LEFT = 3
SPEED_LEFT_HEX = $30
SPEED_RIGHT = 3
SPEED_RIGHT_HEX = $D0
SCAN_START_SCORE = (SCAN_START_BORDER-12)
SCAN_POS_PLAYER = (LAST_SCANLINE - HEIGHT_PLAYER)
SCAN_START_LINES = (SCAN_START_BORDER + HEIGHT_BORDER + 21)
SOUND_FRAME = 5
SOUND_VOLUME = $0E
SOUND_CTRL = $0C
TAPS = $B8
;===================================================================
;===================================================================
; VARIABLES RAM ($0080-$00FF)(128B RAM)
SEG.U VARIABLES
ORG $80
RANDOM_NUMBER ds 1
SCORE_MASK ds 1
COUNT_SCANLINES ds 1
COUNT_LIFE ds 1
LINES_PFS0 ds NUMBER_LINES
LINES_PFS1 ds NUMBER_LINES
LINES_PFS2 ds NUMBER_LINES
LINES_PFS3 ds NUMBER_LINES
DESTROY_LINE ds 2
DESTROY_MASK ds 1
PLAYER_POS ds 1
BALL_PHORZ ds 1
BALL_PVERT ds 1
BALL_STATUS ds 1
; BALL_STATUS DECODER
; BIT ACTION
; 0 Live?
; 1 Move up?
; 2 Move Right?
; 4-7 SPEED BALL
SCORE ds 2
POINTER_SCORE ds 8
POINTER_LIFE ds 2
SOUND_FCTRL ds 1
SOUND_MCTRL ds 1
;===================================================================
;===================================================================
; CODE SEGMENT
SEG CODE
ORG $F000 ; Start of "Cart Area" (See Atari Memory Map)
;===================================================================
; CPU ENTRYPOINT
;===================================================================
BootGame:
SEI
CLD
LDA #$00
TAY
LDX #$FF
TXS
INX
ClearMemory:
DEX
STA $CC,X
BNE ClearMemory
; Get seed for random generation
LDA INTIM
BNE NoNULLSeed
LDA #1
NoNULLSeed:
STA RANDOM_NUMBER
LDY #$08
; Set Position of P1 and M1 (Plataform)
STA WSYNC
DEY
; Delay PosP1 and PosM1
PosPlayer1:
DEY
BPL PosPlayer1
STA RESP1
STA RESM1
; Set Pos P1 and M1(ball) (H,V) in Memory
LDA #68
STA PLAYER_POS
LDA #75
STA BALL_PHORZ
LDA #(KERNEL_SCANLINE-10)
STA BALL_PVERT
LDA #$16
STA BALL_STATUS
; Apply move if exists in buffer
LDA #$20
STA HMP1
STA HMM1
STA WSYNC
STA WSYNC
STA HMOVE
STA WSYNC
STA HMCLR
; Reset Game and Set Pointers
JSR ResetGame
; Sound Control
LDA #$0C
STA AUDC0
; Sound Freq
LDA #1
STA SOUND_MCTRL
LDA #%01000010 ; Starting Vblank
STA VBLANK
;===================================================================
; NEW FRAME CYCLE
;===================================================================
StartFrame:
LDA #%00001110 ; Vertical sync is signaled by VSYNC's bit 1...
WsynWait:
STA WSYNC ; (WSYNC write => wait for end of scanline)
STA VSYNC
LSR
BNE WsynWait
LDA #VBLANK_TIMER ; Timing Vblank Scanlines
STA TIM64T
;===================================================================
;===================================================================
; Vblank code area
;===================================================================
;===================================================================
;Check Stop Sound
JSR CheckSound
; Set Size and Graph type
LDA #$30
STA NUSIZ0
LDA #$15
STA NUSIZ1
; Control Mode Playfield to Score (No PlayField Reflect)
LDA #0
STA CTRLPF
; Input Controls Set Mode Read
STA SWACNT
STA SWBCNT
; Reset Vertical Delay
STA VDELP0
STA VDELP1
STA VDELBL
; Set Color
STA COLUBK
LDA #BORDER_COLOR
STA COLUP0
LDA #PLAYER_COLOR
STA COLUP1
; Set Position of P0 and M0 (Side Borders)
LDY #$04
;Delay PosP0
STA WSYNC
DEY
PosPlayer0:
DEY
BPL PosPlayer0
NOP
STA RESP0
;Delay PosM0
LDY #$05
PosMissile0:
DEY
BPL PosMissile0
NOP
NOP
STA RESM0
LDA #$F0
STA HMP0
;===================================================================
; INPUT CONTROL PROCESSING AREA
;===================================================================
; Reset Switches
LDA SWCHB
AND #$01
BNE P_Control
JSR ResetGame
P_Control:
; Start Ball if ball is dead (button control)
LDA BALL_STATUS
AND #1
BNE Controllers
; Get Input Button (Both Controls)
LDA #$80
AND INPT4
BEQ Fire
AND INPT5
BEQ Fire
JMP Controllers
; Ball is dead and button is push
Fire:
; Verify Count Life
LDA COUNT_LIFE
BEQ Controllers
; "Use" life
DEC COUNT_LIFE
; Ball Parameter Defaults
LDA RANDOM_NUMBER
AND #$04 ; Random Horz Start (Left or Right)
ORA #$13
STA BALL_STATUS
LDA #(SCAN_POS_PLAYER-HEIGHT_BALL)
STA BALL_PVERT
; Get input controls to move the player (platform)
Controllers:
LDX SWCHA
; Control(s) press Left
TXA
AND #$40
BEQ MovePlayerLeft
TXA
AND #$04
BEQ MovePlayerLeft
; Control(s) press Right
TXA
AND #$80
BEQ MovePlayerRight
TXA
AND #$08
BEQ MovePlayerRight
; no press
JMP NoMove
; Move Player to Left
MovePlayerLeft:
; Get current position, verify bounds, apply move based on movement of Player
LDA PLAYER_POS
CMP #26
BCC NoMove
LDX #SPEED_LEFT_HEX
SEC
SBC #SPEED_LEFT
JMP SetMovemtMemory
MovePlayerRight:
; Get current position, verify bounds, apply move based on movement of Player
LDA PLAYER_POS
CMP #111
BCS NoMove
LDX #SPEED_RIGHT_HEX
CLC
ADC #SPEED_RIGHT
SetMovemtMemory: ; efficient ROM Space
STA PLAYER_POS
STX HMP1
NoMove:
; Ball Movement
; Check Dead Ball
LDA BALL_STATUS
TAY
AND #1
BEQ NoMoveBall
; Move
; Shift Speed Ball in 4 High Bits of BALL_STATUS
LDX #4
TYA
ShiftSpeedBall:
LSR
DEX
BNE ShiftSpeedBall
; Save in Register X
TAX
; Move Vertical
TYA
AND #2
BEQ MoveBallUP
; MoveBallDown:
; two's complement
TXA
EOR #$FF
SEC
ADC BALL_PVERT
JMP MoveHorz
MoveBallUP:
TXA
CLC
ADC BALL_PVERT
MoveHorz: ; efficient ROM Space
; Save in Memory Vertical movement of Ball
STA BALL_PVERT
; Move Horizontal
TYA
AND #4
BEQ MoveBallLeft
; MoveBallRight:
TXA
CLC
ADC BALL_PHORZ
STA BALL_PHORZ
TYA
AND #$F0
EOR #$F0
CLC
ADC #$10
JMP BallMoved
MoveBallLeft:
TXA
; two's complement
EOR #$FF
SEC
ADC BALL_PHORZ
STA BALL_PHORZ
TYA
AND #$F0
BallMoved:
STA HMM1
NoMoveBall:
; Life and Score Set Graph
JSR SetInfoDigitPointers
; PreparePlayfield: ; Preparing graph registers to start hot scanlines
LDA #BORDER_COLOR
STA COLUPF
; Wait Rest of Existing Vblank (Async Clock)
WaitVblankEnd:
LDA INTIM
BNE WaitVblankEnd
; Register Y for Count Hot Scanlines
TAY ; A:=0
STA WSYNC
; Apply Moves in Buffers
STA HMOVE
; Clear Collisions (New Frame)
STA CXCLR
STA WSYNC
; Clear Buffer of Moves
STA HMCLR
; Out VBlank (Magic Starts Here)
STA VBLANK ; Stop Vblank
;=============================================================================================
;=============================================================================================
;=============================================================================================
; KERNEL
;=============================================================================================
;=============================================================================================
;=============================================================================================
;
; PRINT SCREEN MOMENT (HOT SCANLINES)
;
; Start Visible Scanlines
; Waiting for the Correct Scanline to Start Graphics
WaitPrintScore:
; Increment Y-ScanLine Count
INY
STA WSYNC
CPY #(SCAN_START_SCORE-1)
BCC WaitPrintScore
; Start Print Score and Life Counter
STY COUNT_SCANLINES
LDY #0
StartScore:
;D0-1
; Get bitmap for the nº line of the Digit 0 (Most Significant Digit)
LDA (POINTER_SCORE),Y
; Take the Left Mirror
AND #$F0
; Save for Join
STA SCORE_MASK
; Get Bitmap for the nº Line of the Digit 1
LDA (POINTER_SCORE+2),Y
STA WSYNC
; Take the Right Mirror
AND #$0F
; Merge the Bitmaps to the Playfield 1 Register
ORA SCORE_MASK
STA PF1
;D2-3
; Get bitmap for the nº line of the Digit 2
LDA (POINTER_SCORE+6),Y
; Take the Left Mirror
AND #$F0
; Save for Join
STA SCORE_MASK
; Get Bitmap for the nº Line of the Digit 3
LDA (POINTER_SCORE+4),Y
; Take the Right Mirror
AND #$0F
; Merge the Bitmaps to the Playfield 2 Register
ORA SCORE_MASK
STA PF2
; Get Bitmap for the nº Line of the Digit of Life Counter
LDA (POINTER_LIFE),Y
; Take only the Right Mirror
AND #$0F
; Set in Playfild tile of digit
STA PF1
LDA #0
NOP
INY
STA PF2
CPY #10 ; Length Bitmap (tile) of Digits (10 rows)
BCC StartScore
; After Score Area
; Increment Y-ScanLine Count
INY
STA WSYNC
STA PF1
TYA
CLC
; Adds to the Counter Lines How Many Lines Used in the Scoreboard
ADC COUNT_SCANLINES
STA COUNT_SCANLINES
TAY
; Control Reflect Playfield for the Color Lines (No Reflection)
LDA #$01
STA CTRLPF
; Wait to Print Borders
WaitPrintBord:
; Increment Y-ScanLine Count
INY
STA WSYNC
CPY #(SCAN_START_BORDER-1)
BCC WaitPrintBord
; Start Print Borders
LDA #$FF
LDX #$3F
INY
STA WSYNC
; Use Player to Make Left Border
STA GRP0
; Not use the Left Part of the Playfild 1
STX PF1
STA PF2
; Make UP border
StartBorder:
; Increment Y-ScanLine Count
INY
STA WSYNC
CPY #(SCAN_START_BORDER+HEIGHT_BORDER-1)
BCC StartBorder
;***********************************************************
; Start Stack Call Danger Zone (Don't use JSR)
;***********************************************************
; Do not use stack or JSR inside danger zone,
; use stack only for print ball
; Trick Using Stack Pointer To Print "Ball" (Missile P1)
LDX #ENAM1
TXS
; StopBord:
; Increment Y-ScanLine Count
INY
STA WSYNC
; Use Missile P0 to Make Right Border
STA ENAM0
LDX #0
STX PF1
STX PF2
STX CTRLPF ; Control Mode Playfield to Lines
; Check Print Ball
TYA
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
PLA
WaitStartLines:
STA WSYNC
; Increment Y-ScanLine Count
INY
; Check Print Ball
TYA
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
PLA
CPY #(SCAN_START_LINES-1)
BCC WaitStartLines
; Start Print Lines
STY COUNT_SCANLINES
LDX #(NUMBER_LINES-1)
LDY #(HEIGHT_LINES-1)
PrintLines:
; Increment Memory ScanLine Count
INC COUNT_SCANLINES
STA WSYNC
LDA COUNT_SCANLINES
; Check Print Ball
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
; Set Line Color
LDA LineColors,X
STA COLUPF
; Get PF of lines
LDA LINES_PFS0,X
STA PF1
LDA LINES_PFS1,X
STA PF2
LDA LINES_PFS2,X
STA PF0
LDA LINES_PFS3,X
STA PF1
PLA
; Reset For New ScanLine
LDA #0
STA PF2
STA PF0
; Check Height of Current Color Line
DEY
BPL PrintLines
; Transition Between Different Color Lines
; Increment Memory ScanLine Count
INC COUNT_SCANLINES
LDY #(HEIGHT_LINES-1)
STA WSYNC
LDA COUNT_SCANLINES
; Check Print Ball
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
; Set Line Color
LDA LineColors,X
STA COLUPF
; Get PF of lines
LDA LINES_PFS0,X
STA PF1
LDA LINES_PFS1,X
STA PF2
LDA LINES_PFS2,X
STA PF0
LDA LINES_PFS3,X
STA PF1
PLA
; Reset For New ScanLine
LDA #0
STA PF2
STA PF0
DEX
BPL PrintLines
; End of Color Lines
; Get Current ScanLine Count
LDY COUNT_SCANLINES
STA WSYNC
STA PF1
STA PF2
; Increment Y-ScanLine Count
INY
TYA
; Check Print Ball
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
PLA
WaitStartPlayer:
STA WSYNC
; Increment Y-ScanLine Count
INY
TYA
; Check Print Ball
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
PLA
CPY #SCAN_POS_PLAYER
BNE WaitStartPlayer
STA WSYNC
; Enable Print Player
LDA #$FF
STA GRP1
LDX #HEIGHT_PLAYER
; Print Player (Missile 1)
PrintPlay:
; Increment Y-ScanLine Count
INY
TYA
; Check Print Ball
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
PLA
; Decrease Player Height
DEX
STA WSYNC
BNE PrintPlay
; Increment Y-ScanLine Count
INY
TYA
; Check Print Ball
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
PLA
; Stop to Draw Borders and Player
; X:=0
STX GRP0
STX GRP1
STX ENAM0
STX ENABL
;=============================================================================================
; OVERSCAN
;=============================================================================================
; Wait hot Scanlines over
ScanlineEnd:
TYA
; Check Print Ball
SEC
SBC BALL_PVERT
AND #($FF-HEIGHT_BALL)
PHP
PLA
STA WSYNC
; Increment Y-ScanLine Count
INY
CPY #(KERNEL_SCANLINE-1)
BNE ScanlineEnd
; Restore Stack Pointer
LDX #$FF
TXS
;***********************************************************
; End Stack Danger Zone (JSR available)
;***********************************************************
;=============================================================================================
;=============================================================================================
;=============================================================================================
; END OF KERNEL
;=============================================================================================
;=============================================================================================
;=============================================================================================
Overscan:
LDA #%01000010 ; "Turn Off Cathodic Ray"
STA VBLANK
LDA #OVERSCAN_TIMER ; Timing OverScanlines
STA TIM64T
INX ; X:=0
STX ENAM1 ; "Ball" below the screen (stop ball draw )
;===================================================================
;===================================================================
; Overscan Code Area
;===================================================================
;===================================================================
; Random Number Generation
JSR RandNumber
;===================================================================
; COLLISION PROCESSING AREA
;===================================================================
; Collision Ball with wall or dead
; Ball Alive? (BALL_STATUS:0 == 1)
LDA BALL_STATUS
AND #1
BEQ NoBallCollision
; Dead ball? (Ball BALL_PVERT > KERNEL_SCANLINE)
LDA BALL_PVERT
CMP #KERNEL_SCANLINE
BCC BallCollPlayer
LDA #$16
STA BALL_STATUS
; Collision Ball With Player
BallCollPlayer:
LDA CXM1P
AND #$40
BEQ BallCollVert
; Player Collision set ball vertical move to up
LDA #$02
ORA BALL_STATUS
STA BALL_STATUS
JSR MakeSound
JSR CheckEndLines
; Collision Ball With Top Bord
BallCollVert:
LDY BALL_PVERT
CPY #(SCAN_START_BORDER+HEIGHT_BORDER+1)
BCS BallCollHoriz
; Top collision set ball vertical move to down
LDA #$FD
AND BALL_STATUS
STA BALL_STATUS
JSR MakeSound
; Collision Ball With Lateral Bords
; Check Left Border
BallCollHoriz:
LDY BALL_PHORZ
; Left
CPY #25
BCS BallCollCheckRight
; Left collision set ball horizon move to right
LDA #$04
ORA BALL_STATUS
STA BALL_STATUS
JSR MakeSound
JMP BallLinesCollision ; If you collided on the left, you won't need to check on the right.
; Check Right Border
BallCollCheckRight:
; Right
CPY #126
BCC BallLinesCollision
; Right collision set ball horizon move to left
LDA #$FB
AND BALL_STATUS
STA BALL_STATUS
JSR MakeSound
; Check ball collision with playfield (Color lines)
BallLinesCollision:
LDA CXM1FB
AND #$80
BEQ NoBallCollision
JSR DestroyLine
NoBallCollision:
;=============================================================================================
; END OVERSCAN
;=============================================================================================
; Wait Rest of Existing OverScan (Async Clock)
WaintOverscanEnd: ; Timing OverScanlines
LDA INTIM
BNE WaintOverscanEnd
JMP StartFrame ; Back to Start
;=============================================================================================
;=============================================================================================
; FUNCTION DECLARATION
;=============================================================================================
;=============================================================================================
; FUNCTION AjustPointerDigit (A:=A+20*X):
; Apply n sums of 20 in to register A
; where n is the value in register x
; If sum generate carry, Y incremented
AjustPointerDigit:
CPX #0
BEQ OutAjust
NoCheckZero:
CLC
ADC #20
BCC NoCarryPointer
INY
NoCarryPointer:
DEX
BNE NoCheckZero
OutAjust:
RTS
; FUNCTION ResetLines (None):
ResetLines:
LDX #(NUMBER_LINES-1)
LDA #$3F
LDY #$FF
SetPFColorLines:
STA LINES_PFS0,X
STY LINES_PFS1,X
LDY #$F0
STY LINES_PFS2,X
LDY #$FF
STY LINES_PFS3,X
DEX
BPL SetPFColorLines
RTS
; FUNCTION CheckEndLines (None):
CheckEndLines:
LDY #0
CheckLinesLoop:
LDA LINES_PFS0,Y
BNE CheckOut
INY
CPY #(NUMBER_LINES*4)
BNE CheckLinesLoop
JMP ResetLines
CheckOut:
RTS
; FUNCTION ResetGame (None):
; Restore Ball, Life, Color Lines and Score
ResetGame:
; Set PF Color Lines (Reset Lines)
JSR ResetLines
INX ;X:=0
; Reset Score
STX SCORE
STX SCORE+1
; Reset Ball
STX BALL_STATUS
LDA #KERNEL_SCANLINE
STA BALL_PVERT
; Reset Life
LDA #PLAYER_LIFE
STA COUNT_LIFE
RTS
; FUNCTION SetInfoDigitPointers (None):
; Set Score Graph Bitmap Pointers to Current Score and Count Life
SetInfoDigitPointers:
; Score Pointer
; Get BCD of Digit 0 (Most Significant Digit)
LDA SCORE
AND #$F0
; Shift for memory pointer
LDX #4
ShiftScoreDigit0:
LSR
DEX
BNE ShiftScoreDigit0
; Adjusts the pointer to the digit, using the function 'AjustPointerDigit'
TAX
CPX #0
BEQ DigitBlank
LDA #<Data0
LDY #>Data0
JMP DigitAjust
; Invisible Digit if Score is Less than 1000.
DigitBlank:
LDA #<DataEmpty
LDY #>DataEmpty
DigitAjust:
JSR AjustPointerDigit
STA POINTER_SCORE
STY POINTER_SCORE+1
; Get BCD of Digit 2
LDA SCORE+1
AND #$F0
; Shift for memory pointer
LDX #4
ShiftScoreDigit2:
LSR
DEX
BNE ShiftScoreDigit2
; Adjusts the pointer to the digit, using the function 'AjustPointerDigit'
TAX
LDA #<Data0R
LDY #>Data0R
JSR AjustPointerDigit
STA POINTER_SCORE+4
STY POINTER_SCORE+5
; Get BCD of Digit 1
LDA SCORE
AND #$0F
TAX
LDA #<Data0
LDY #>Data0
JSR AjustPointerDigit
STA POINTER_SCORE+2
STY POINTER_SCORE+3
; Get BCD of Digit 3
LDA SCORE+1
AND #$0F
; Adjusts the pointer to the digit, using the function 'AjustPointerDigit'
TAX
LDA #<Data0R
LDY #>Data0R
JSR AjustPointerDigit
STA POINTER_SCORE+6
STY POINTER_SCORE+7
; Ajust Pointer for Count Life
LDX COUNT_LIFE
LDA #<Data0
LDY #>Data0
JSR AjustPointerDigit
STA POINTER_LIFE
STY POINTER_LIFE+1
RTS
; FUNCTION AddScore (None):
; Increment one in Score (2 bytes in BCD mode)
AddScore:
SED
LDA SCORE+1
CLC
ADC #1
STA SCORE+1
BCC NoCarryADD
LDA SCORE
ADC #0
STA SCORE
NoCarryADD:
CLD
RTS
; FUNCTION DestroyLine (None):
; Removes bit from the playfield referring to the colidade line
DestroyLine:
; Check which horizontal playfield bank collided
LDY BALL_PHORZ
DEY
LDA BALL_STATUS
AND #$04