-
Notifications
You must be signed in to change notification settings - Fork 0
/
APong.asm
1463 lines (1195 loc) · 33.8 KB
/
APong.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
processor 6502
include vcs.i
include macro.i
;-------------------------Constants Below---------------------------------
PADDLEHEIGHT = 15; 20
BALLHEIGHT = 3
DIGITHEIGHT = 16
PLAYHEIGHT = 200 ;184
DIGITY = 84
SERVECOUNT = 102
; Ball goes from 0 to 182
; Paddle goes from 01 to 169 (184 - PADDLEHEIGHT)
; Ball speeds should be .5 .75 and 1 or $80 $C0 and $100
; or new calc came in at .5 1.0 1.5 or $80 $100 and $180
;-------------------------COLOR CONSTANTS (NTSC)--------------------------
GRAY = $00
GOLD = $10
ORANGE = $20
BURNTORANGE = $30
RED = $40
PURPLE = $50
PURPLEBLUE = $60
BLUE = $70
BLUE2 = $80
LIGHTBLUE = $90
TURQUOISE = $A0
GREEN = $B0
BROWNGREEN = $C0
TANGREEN = $D0
TAN = $E0
BROWN = $F0
;--------------------------TIA CONSTANTS----------------------------------
;--NUSIZx CONSTANTS
; player:
ONECOPYNORMAL = $00
TWOCOPIESCLOSE = $01
TWOCOPIESMED = $02
THREECOPIESCLOSE = $03
TWOCOPIESWIDE = $04
ONECOPYDOUBLE = $05
THREECOPIESMED = $06
ONECOPYQUAD = $07
; missile:
SINGLEWIDTHMISSILE = $00
DOUBLEWIDTHMISSILE = $10
QUADWIDTHMISSILE = $20
OCTWIDTHMISSILE = $30
;---CTRLPF CONSTANTS
; playfield:
REFLECTEDPF = %00000001
SCOREPF = %00000010
PRIORITYPF = %00000100
; ball:
SINGLEWIDTHBALL = SINGLEWIDTHMISSILE
DOUBLEWIDTHBALL = DOUBLEWIDTHMISSILE
QUADWIDTHBALL = QUADWIDTHMISSILE
OCTWIDTHBALL = OCTWIDTHMISSILE
;---HMxx CONSTANTS
LEFTSEVEN = $70
LEFTSIX = $60
LEFTFIVE = $50
LEFTFOUR = $40
LEFTTHREE = $30
LEFTTWO = $20
LEFTONE = $10
NOMOVEMENT = $00
RIGHTONE = $F0
RIGHTTWO = $E0
RIGHTTHREE = $D0
RIGHTFOUR = $C0
RIGHTFIVE = $B0
RIGHTSIX = $A0
RIGHTSEVEN = $90
RIGHTEIGHT = $80
;---AUDCx CONSTANTS (P Slocum's naming convention)
SAWSOUND = 1
ENGINESOUND = 3
SQUARESOUND = 4
BASSSOUND = 6
PITFALLSOUND = 7
NOISESOUND = 8
LEADSOUND = 12
BUZZSOUND = 15
;---SWCHA CONSTANTS (JOYSTICK)
J0RIGHT = %10000000
J0LEFT = %01000000
J0DOWN = %00100000
J0UP = %00010000
J1RIGHT = %00001000
J1LEFT = %00000100
J1DOWN = %00000010
J1UP = %00000001
;---SWCHB CONSTANTS (CONSOLE SWITCHES)
P1DIFF = %10000000
P0DIFF = %01000000
BWCOLOR = %00001000
SELECT = %00000010
RESET = %00000001
;-------------------------End Constants-----------------------------------
;-----------------------------Macros--------------------------------------
MAC FILLER
REPEAT {1}
.byte {2}
REPEND
ENDM
MAC DEBUG_BRK
IF DEBUG
brk ;
ENDIF
ENDM
MAC CHECKPAGE
IF >. != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ")"
ECHO ""
ERR
ENDIF
ENDM
MAC BIT_B
.byte opBIT_B
ENDM
MAC BIT_W
.byte opBIT_W
ENDM
;------------------------------Variables----------------------------------
SEG.U Variables
org $80
Counter ds 1
PaddleBase ds 1
DigitLPtr ds 2
DigitRPtr ds 2
DigitLTemp ds 1
DigitRTemp ds 1
PaddleLTemp ds 1
PaddleRTemp ds 1
PaddleLY ds 1
PaddleRY ds 1
PaddleValue ds 1
BallTemp ds 1
BallXfrac ds 1
BallX ds 1
BallYfrac ds 1
BallY ds 1
BallVelXfrac ds 1
BallVelX ds 1
BallVelYfrac ds 1
BallVelY ds 1
ScoreL ds 1
ScoreR ds 1
soundPointer ds 2
sfxPlay ds 1
sfxLast ds 1
gameState ds 1 ; 0 - Attract - 1 Game
attractLockout ds 1
serveDelay ds 1 ; 1.7 seconds is needed for this counter for a count of 102
volleyCounter ds 1 ; 0-3 slow 4-11 med 12-15 fast
winScore ds 1 ; 11 or 15 depending on difficulty switch
;-------------------------End Variables-----------------------------------
SEG Bank0
org $F000
Start
CLEAN_START
;--any initial setup
lda #REFLECTEDPF|SINGLEWIDTHBALL
sta CTRLPF
lda #ONECOPYDOUBLE|DOUBLEWIDTHMISSILE
sta NUSIZ0
lda #ONECOPYDOUBLE
sta NUSIZ1
lda #GRAY+14 ;white
sta COLUPF
sta COLUP0
sta COLUP1
lda #1
sta VDELBL
sta VDELP0
; net ranges from 1 to 160
lda #79 ;net
ldx #4
jsr PositionASprite
lda #38 ;L digit
ldx #0
jsr PositionASprite
;lda #90 ;R digit
lda #120
ldx #1
jsr PositionASprite
lda #78
sta BallX
lda #80
sta BallY
lda #$80
sta BallYfrac
sta BallVelXfrac
lda #1
sta BallVelY
lda #0
sta ScoreL
lda #1
sta ScoreR
lda #20
sta attractLockout
lda #0
sta serveDelay
jmp MainGameLoop
Serve
lda #0
sta volleyCounter
lda #1
sta gameState
lda #SERVECOUNT
sta serveDelay
; reset ball position
lda #(261/2)
sta BallXfrac
; start at slow speed
lda #$80
sta BallVelXfrac
lda BallVelX
bmi .neg
lda #0
beq .pos
.neg lda #$FF
.pos sta BallVelX
lda #80
sta BallX
rts
;-------------------------------------------------------------------------
;--------------GAME MAIN LOOP---------------------------------------------
;-------------------------------------------------------------------------
MainGameLoop
jsr VBLANKRoutine
lda sfxPlay ; NB - this is here to keep the display in check
bne .nofill ; if sfxPlay is not true we need to burn a line of the display
sta WSYNC ; hence this WSYNC. I stole a line from the start of the Kernel Routine
.nofill ; TODO - fix this so it doesn't rely on side effects
jsr SFXTick
jsr KernelRoutine
jsr SFXTick
jsr OverscanRoutine ; checks paddles and sets new paddle velocity Y
jmp MainGameLoop
;-------------------------------------------------------------------------
;-------------------VBLANK Routine----------------------------------------
;-------------------------------------------------------------------------
VBLANKRoutine
lda #$82
sta VBLANK ;for paddles
lda #%00001111
VSYNCLoop
sta WSYNC
sta VSYNC
lsr
bcs VSYNCLoop
lda #43
sta TIM64T
lda SWCHB
lsr
bcs .noreset
lda #0
sta ScoreL
sta ScoreR
jsr Serve
.noreset
ldx serveDelay
beq .served
dex
stx serveDelay
bne .serving
.
.served
jsr MoveBall
.serving
jsr UpdateCounters
jsr SetupDisplayVariables
sta CXCLR
WaitForVblankEnd
lda INTIM
bne WaitForVblankEnd
sta WSYNC
sta VBLANK ;turn off VBLANK - it was turned on by overscan
rts
;-------------------------------------------------------------------------
;----------------------Kernel Routine-------------------------------------
;-------------------------------------------------------------------------
;--Notes on kernel:
; left and right "paddles" are drawn with PF0!
; left and right score digits are drawn with P0 (VDELed) and P1
; center "net" is drawn with BL (VDELed)
; ball is drawn with M0
;
; Two-line kernel
; Every line:
; ball is drawn
; "paddles" are drawn
; paddle (INPT0 or INPT1, alternating frames,
; indexed with X) is read
; Every other line:
; "net" is drawn
; left and right score digits are drawn
align 256
KernelRoutine
sta WSYNC
lda #$00
sta PF0
sta PF1
sta PF2 ;+11 11 draw horizontal line at top of screen
sta WSYNC
; sta WSYNC ; NB - this line was stolen for the main game loop to process an extra SFX tick
ldy #PLAYHEIGHT ;+2 2
lda Counter ;3
and #1 ;2
clc ;2
adc PaddleBase ;3
tax ;2 +12 14
lda #255
sta PaddleValue ;+5 19 necessary to preload PaddleValue
SLEEP 40 ;+40 59
lda #BALLHEIGHT
dcp BallTemp ; dec BallTemp cmp BallTemp
sbc #BALLHEIGHT-2
sta ENAM0 ;+12 71 draw ball - a little early here. Oh well. Quick hack.
lda #0 ;+2 73
sta PF2 ;+3 76
; sta WSYNC
sta PF0
sta PF1 ;+6 6 erase horizontal line at top of screen
KernelLoop
lda #PADDLEHEIGHT
dcp PaddleLTemp ; dec PaddleLTemp cmp PaddleLTemp (5 cycles)
sbc #<(PADDLEHEIGHT-64)
and #$40
sta PF0 ;+14 20 draw L "paddle"
lda #DIGITHEIGHT-1 ; 2
dcp DigitLTemp ; 6 dec DigitLTemp cmp DigitLTemp
bcs DoDrawDigitL ; 2/3
lda #0 ;
.byte $2C ; 4 (but covers the next five)
DoDrawDigitL
lda (DigitLPtr),Y ; 5
sta GRP0 ;+18 38 draw L score. VDELed. Could use SkipDraw here
; and save 1 cycle.
lda INPT0,X ; 4
bpl ReadPaddle1 ; 2/3
.byte $2C ; 4
ReadPaddle1
sty PaddleValue ; 3 (4+3+3) or (4+2+4) = +10 48 read paddle
lda #PADDLEHEIGHT
dcp PaddleRTemp ; dec PaddleRTemp cmp PaddleRTemp
sbc #<(PADDLEHEIGHT-64)
and #$40
sta PF0 ;+14 62 draw right "paddle"
dey ;+2 64
lda #BALLHEIGHT
dcp BallTemp ; dec BallTemp cmp BallTemp
sbc #BALLHEIGHT-2
sta ENAM0 ;+12 76 draw ball
lda #PADDLEHEIGHT
dcp PaddleLTemp ;dec PaddleLTemp cmp PaddleLTemp
sbc #<(PADDLEHEIGHT-64)
and #$40
sta PF0 ;+14 14 draw left "paddle"
lda #DIGITHEIGHT-1
dcp DigitRTemp ; dec DigitRtemp cmp DigitRTemp
bcs DoDrawDigitR
lda #0
.byte $2C
DoDrawDigitR
lda (DigitRPtr),Y
sta GRP1 ;+18 32 draw right score digit
; necessary to use DoDraw (or similar)
; here - because of VDEL GRP1 must be
; written to every time.
lda INPT0,X
bpl ReadPaddle2
.byte $2C
ReadPaddle2
sty PaddleValue ;+10 42 read paddle
lda #PADDLEHEIGHT
dcp PaddleRTemp ; dec PaddleRTemp cmp PaddleRTemp
sbc #<(PADDLEHEIGHT-64)
and #$40
sta PF0 ;+14 56 draw right "paddle"
tya
lsr
sta ENABL ;+7 63 VDELed - this is the 'net'
nop ;+2 65 Two free cycles
lda #BALLHEIGHT
dcp BallTemp ; dec BallTemp cmp BallTemp
sbc #BALLHEIGHT-2
sta ENAM0 ;+12 1 draw ball
dey
bne KernelLoop ;+5 6
CheckPage KernelRoutine
lda #$00
sta PF0
sta PF1
sta PF2 ; draw horizontal line at bottom of screen
sta WSYNC
lda #0
sta ENAM0
sta ENABL
sta GRP0
sta GRP1 ;+14 14 erase all objects (remember that BL and P0 are VDELed)
sta WSYNC
sta WSYNC
lda #0
sta PF0
sta PF1
sta PF2 ; erase horizontal line at bottom of screen
sta WSYNC
rts
;-------------------------------------------------------------------------
;------------------------Overscan Routine---------------------------------
;-------------------------------------------------------------------------
OverscanRoutine subroutine
lda #2
sta WSYNC
sta VBLANK ;turn on VBLANK
lda #34
sta TIM64T
ldx #0
lda SWCHB
and #P1DIFF
bne .setPaddleBase
ldx #2
.setPaddleBase
stx PaddleBase
; Set the winning score to be 11 or 15 depending on Player 0 difficulty switch.
ldx #11
lda SWCHB
and #P0DIFF
beq .setWinScore
ldx #15
.setWinScore
stx winScore
stx winScore
; check collisions first because paddle value will be correct
jsr CheckCollisions
lda gameState
beq .attractMode
jsr SetPaddleY
jmp WaitForOverscanEnd
.attractMode
ldx #201
stx PaddleLY
stx PaddleRY
WaitForOverscanEnd
lda INTIM
bne WaitForOverscanEnd
rts
;-------------------------------------------------------------------------
;----------------------------End Main Routines----------------------------
;-------------------------------------------------------------------------
;*************************************************************************
;-------------------------------------------------------------------------
;----------------------Begin Subroutines----------------------------------
;-------------------------------------------------------------------------
CheckCollisions subroutine
;--ball to paddle collision is actually a M0-to-PF collision. Will have to look at ball X
; position to determine which paddle is hit.
lda CXM0FB ;M0 to PF in bit 7
asl
bcc NoBallToPaddleCollision
;--so maybe we hit a paddle
lda BallX
cmp #80
bcs .rightSide
lda BallVelX
bpl .exit ; ball already heading correct direction (prevent double trigger)
ldx #00 ; left paddle
beq .checkbounce
.rightSide:
lda BallVelX
bmi .exit ; ball already heading correct direction (prevent double trigger)
ldx #01 ; right paddle
.checkbounce
lda BallY
clc
adc #2
sec
sbc PaddleLY,X
bmi .exit
.goodl cmp #16
bcs .exit
.goodh tax
;lsr
;sta ScoreR
;sta ScoreL
lda newvelYl,x
sta BallVelYfrac
lda newvelYh,x
sta BallVelY
sec ; 0-velX -> velX
lda #$00
sbc BallVelXfrac
sta BallVelXfrac
lda #$00
sbc BallVelX
sta BallVelX
lda #<PADDLE_HIT
sta soundPointer
lda #>PADDLE_HIT
sta soundPointer+1
sta sfxPlay ; starts the SFX
ldx volleyCounter
cpx #4
beq .med
cpx #12
beq .fast
bcs .2
bcc .1
.fast lda #$0
ldy #$1
bne .updateVel
.med lda #$c0
ldy #$0
.updateVel
sta BallVelXfrac
sty BallVelX
.1 inx
stx volleyCounter
.2
.exit
NoBallToPaddleCollision
rts
;There are 245 visible lines on the screen in Arcade Pong
; ball is 4 pixels high
; The vertical motion of the ball is influenced by two things, hitting the top or bottom of the screen, or
; hitting one of the paddles. When the ball hits the top or bottom of the screen, it will reverse direction,
; but keep the same speed. When the ball hits the paddle the effect on the vertical motion is determined by
; where on the paddle it hits. The paddle is 16 pixels high which is divided up into 8 regions,
; a hit on these regions affects the vertical position as follows:
; 1 - Up fast
; 2 - Up medium
; 3 - Up slow
; 4 - No vertical motion
; 5 - No vertical motion
; 6 - Down slow
; 7 - Down medium
; 8 - Down fast
; 8 2 pixel high segments
; Hit counter for ball speed increase. Counter determines horizontal ball speed. Counter caps at 15.
; Counter resets when point scored
;
; HitCounter H1(11) H1(3)
; 0-3 0 0
; 4-11 0 1
; 12-15 1 1;
;
;
newvelYl: .byte $00,$00, $00,$00, $80,$80, $00,$00, $00,$00, $00,$00, $80,$80, $00,$00
newvelYh: .byte $fe,$fe, $ff,$ff, $ff,$ff, $00,$00, $00,$00, $01,$01, $01,$01, $02,$02
;newvelYl: .byte $80,$80,$80, $80,$80,$80, $00,$00,$00, $00, $00,$00,$00, $80,$80,$80, $80,$80,$80, $80
;newvelYh: .byte $fd,$fd,$fd, $fe,$fe,$fe, $ff,$ff,$ff, $00, $01,$01,$01, $01,$01,$01, $02,$02,$02, $02
;-------------------------------------------------------------------------
SetPaddleY subroutine
lda Counter
and #1
tax
lda PaddleValue
cmp #PLAYHEIGHT-PADDLEHEIGHT
bcc PaddleNotTooHigh
lda #PLAYHEIGHT-PADDLEHEIGHT
; clc
PaddleNotTooHigh
; adc PaddleLY,X
; ror
sta PaddleLY,X
rts
;-------------------------------------------------------------------------
MoveBall subroutine
lda BallVelXfrac
clc
adc BallXfrac
sta BallXfrac
lda BallX
adc BallVelX
sta BallX
lda BallVelYfrac
clc
adc BallYfrac
sta BallYfrac
lda BallY
adc BallVelY
sta BallY
;--check boundaries
;--if hit any edge, reverse that direction
;--if hit left/right edge, increase score of other player
lda BallX
sec
sbc #01
cmp #(160-1)
bcc .ballOnScreenX
lda gameState
bne .gameplay
;--if attract mode just bounce off left/right side of screen
; invert X velocity (2s complement)
lda BallVelXfrac
eor #$FF
clc
adc #$01
sta BallVelXfrac
lda BallVelX
eor #$FF
adc #$00
sta BallVelX
lda BallVelXfrac
clc
adc BallXfrac
sta BallXfrac
lda BallX
adc BallVelX
sta BallX
jmp .ballOnScreenX
.gameplay
;--regular gameplay
; play off screen sound effect
lda #<MISSED_BALL
sta soundPointer
lda #>MISSED_BALL
sta soundPointer+1
sta sfxPlay ; starts the SFX
jsr Serve
lda BallVelX
bpl .ballOffRightEdge
;--ball off left edge
;--increase right score
lda ScoreR
clc
adc #$01
cmp winScore
bcc .goodscr
ldx #00
stx gameState
.goodscr
sta ScoreR
jmp .ballOnScreenX
.ballOffRightEdge
;--ball off right edge
;--increase left score
lda ScoreL
clc
adc #$01
cmp winScore
bcc .goodscl
ldx #00
stx gameState
.goodscl
sta ScoreL
.ballOnScreenX
;--now check top and bottom bounds
lda BallY
cmp #PLAYHEIGHT-2
bcc .ballOnScreenY
;--ball hit top or bottom
lda gameState
beq .nosound ; attract mode has no sound
; play wall hit sound effect
lda #<WALL_HIT
sta soundPointer
lda #>WALL_HIT
sta soundPointer+1
sta sfxPlay ; starts the SFX
.nosound
; invert Y velocity (2s complement)
lda BallVelYfrac
eor #$FF
clc
adc #$01
sta BallVelYfrac
lda BallVelY
eor #$FF
adc #$00
sta BallVelY
; this should make sure that ball is back in bounds
lda BallVelYfrac
clc
adc BallYfrac
sta BallYfrac
lda BallY
adc BallVelY
sta BallY
.ballOnScreenY
lda BallX
ldx #2
jsr PositionASprite
rts
;-------------------------------------------------------------------------
SetupDisplayVariables subroutine
lda #PLAYHEIGHT+1
sec
sbc PaddleLY
sta PaddleLTemp
lda #PLAYHEIGHT+1
sec
sbc PaddleRY
sta PaddleRTemp
lda #0
ldx serveDelay
bne .serving
lda #PLAYHEIGHT
sec
sbc BallY
.serving
sta BallTemp
lda #PLAYHEIGHT
lsr
sec
sbc #DIGITY
clc
adc #DIGITHEIGHT
sta DigitLTemp
lda #PLAYHEIGHT
lsr
sec
sbc #DIGITY
clc
adc #DIGITHEIGHT
sta DigitRTemp
lda ScoreL
and #$0F
asl
tay
lda DigitTable,Y
sec
sbc #1
; lda #<Digit3-1
sec
sbc #DIGITY*2
clc
adc #DIGITHEIGHT*2
sta DigitLPtr
lda DigitTable+1,Y
sta DigitLPtr+1
lda ScoreR
and #$0F
asl
tay
lda DigitTable,Y
; lda #<Digit3
sec
sbc #DIGITY*2
clc
adc #DIGITHEIGHT*2
sta DigitRPtr
lda DigitTable+1,Y
sta DigitRPtr+1
rts
;-------------------------------------------------------------------------
UpdateCounters subroutine
dec Counter
rts
;-------------------------------------------------------------------------
;align 256
PositionASprite ;call this function with A == horizontal position (0-159)
;and X == the object to be positioned (0=P0, 1=P1, 2=M0, etc.)
;This function will change A, which
;will be the value put into HMxx when returned.
;Call this function with at least 14 cycles left in the scanline
;(jsr + sec + sta WSYNC + sta HMCLR = 14); it will return 9 cycles
;into the second scanline
sec
sta HMCLR
sta WSYNC ;begin line 1
.divideLoop
sbc #15
bcs .divideLoop ;+4/5 4/ 9.../54
eor #7 ;+2 6/11.../56
asl
asl
asl
asl ;+8 14/19.../64
sta.wx HMP0,X ;+5 19/24.../69
sta RESP0,X ;+4 23/28/33/38/43/48/53/58/63/68/73
sta WSYNC ;+3 0 begin line 2
sta HMOVE ;+3
Return ;label for time-wasting 'jsr's
rts
CHECKPAGE PositionASprite
;----------------------------------------------------------------------------
;;;;;;;;;; SFX code ;;;;;;;;;;