-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.asm
3726 lines (3099 loc) · 62.8 KB
/
game.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
; asmsyntax=ca65
.include "game_ram.asm"
.importzp child_NUMBER_OF_MAPS
; Word value. Frames active.
PU_GRAVITY_DURATION = 600
Death_Height = 200
Death_Offset = 4 ; negative offset from ball center
BALL_UP = $80
BALL_DOWN = $00
BALL_LEFT = $00
BALL_RIGHT = $40
BOUNCE_STEP = $18
SPRITE_ID_BALL = $0A
SPRITE_ID_PADDLE_MID = $09
SPRITE_ID_PADDLE_SIDE = $08
BOOST_VALUE = $F0
MAX_BOOST_POOL = 3
Initial_Ball_Speed_WHOLE = 1
Initial_Ball_Speed_FRACT = 0
Initial_Ball_Direction = BALL_UP | BALL_RIGHT
Initial_Paddle_Speed_WHOLE = 2
Initial_Paddle_Speed_FRACT = 0
Initial_Ball_X = 50 ; 200
Initial_Ball_Y = 154 ; $C0
Paddle_Speed_Slow_WHOLE = 1
Paddle_Speed_Slow_FRACT = 0
Paddle_Speed_Fast_WHOLE = 3
Paddle_Speed_Fast_FRACT = 128
Initial_Paddle_X = 128
Initial_Paddle_Y = 208
Child_Paddle_Y = 184
WALL_RIGHT = $F5
WALL_LEFT = $0A
WALL_TOP = $11
WALL_BOTTOM = $EA
CHILD_WALL_RIGHT = WALL_RIGHT - (8 * 5)
CHILD_WALL_LEFT = WALL_LEFT + (8 * 5)
CHILD_WALL_TOP = WALL_TOP + (8 * 2)
CHILD_WALL_BOTTOM = WALL_BOTTOM - (8 * 4)
BALL_SPRITE_OFFSET_X = 2
BALL_SPRITE_OFFSET_Y = 3
EDGE_COLLIDE_OFFSET = 3
POINT_COLLIDE_OFFSET = 1
;START_MAP = 4
GRAVITY_VALUE = $04
; For collision
PADDLE_VERT_OFFSET = 3
PADDLE_VERT_COLLIDE_OFFSET = EDGE_COLLIDE_OFFSET + PADDLE_VERT_OFFSET
PADDLE_CENTER_WIDTH = 11
; For drawing
PADDLE_SPRITE_OFFSET_X = 3
PADDLE_SPRITE_OFFSET_Y = 3
PADDLE_WALL_LEFT = WALL_LEFT + 10 ;$14
PADDLE_WALL_RIGHT = WALL_RIGHT - 9 ;$EC
CHILD_PADDLE_WALL_LEFT = CHILD_WALL_LEFT + 10 ;$14
CHILD_PADDLE_WALL_RIGHT = CHILD_WALL_RIGHT - 9 ;$EC
; These are RAM addresses
Paddle_Sprite_Start = $0208
Paddle_Sprite_X = Paddle_Sprite_Start + 3
Paddle_Sprite_Y = Paddle_Sprite_Start + 0
Paddle_Sprite_Tile = Paddle_Sprite_Start + 1
Paddle_Sprite_Attr = Paddle_Sprite_Start + 2
Pal_Game:
.byte $0F, $01, $11, $38
Pal_GameSprites:
.byte $0F, $00, $10, $20
.byte $0F, $16, $16, $2A
Init_Game:
.NMI_Disable
; Disable drawing BG and sprites
.Disable_Drawing
bit $2002
lda #$3F
sta $2006
lda #$00
sta $2006
; Load up a palette
.repeat 4, i
lda Pal_Game+i
sta PaletteBuffer+i
.endrepeat
lda #$3F
sta $2006
lda #$10
sta $2006
; Load up another palette
.repeat 8, i
lda Pal_GameSprites+i
sta PaletteBufferSprites+i
.endrepeat
lda #0
;jsr FillNametable1
jsr ClearAttrTable0
lda #ChrData::Game
jsr LoadChrData
lda #ChrData::Game2
jsr LoadChrData
jsr ClearSprites
jsr Clear_GameRam
jsr Clear_ExtendedRam
jsr DrawBackground_Main
;jsr DrawBackground_Child
; Tile
lda #SPRITE_ID_BALL
sta Sprites+5
lda #16
sta Sprites+(4*6)
sta Sprites+(4*6)+3
lda #1
sta Sprites+(4*6)+2
; Attributes
lda #0
sta Sprites+6
sta Paddle_Sprite_Attr
sta Paddle_Sprite_Attr+4
lda #$40
sta Paddle_Sprite_Attr+8
lda #SPRITE_ID_PADDLE_MID
sta Paddle_Sprite_Tile
lda #SPRITE_ID_PADDLE_SIDE
sta Paddle_Sprite_Tile+4
sta Paddle_Sprite_Tile+8
lda #MAX_BOOST_POOL
sta BoostPool
; Boost count sprite
lda #16
sta Sprites+(4*5)+0
lda #24
sta Sprites+(4*5)+3
lda #$0D
sta Sprites+(4*5)+1
lda #0
sta Sprites+(4*5)+2
jsr WriteSprites
jsr game_DrawWalls
; Sprite zero
; TODO: Try to change the background color
; during H-Blank with this as the trigger
;lda #0
;sta Sprites+3
;lda #120
;sta Sprites+0
;lda #1
;sta Sprites+1
;lda #1
;sta Sprites+2
jsr ResetBall
lda #0
sta PaddleX
sta PaddleY
sta ChildId
lda #<Row_Coord_Top
sta Address_RowCoordTop
lda #>Row_Coord_Top
sta Address_RowCoordTop+1
lda #<Row_Coord_Bot
sta Address_RowCoordBot
lda #>Row_Coord_Bot
sta Address_RowCoordBot+1
lda #<Row_Coord_Left
sta Address_RowCoordLeft
lda #>Row_Coord_Left
sta Address_RowCoordLeft+1
lda #<Row_Coord_Right
sta Address_RowCoordRight
lda #>Row_Coord_Right
sta Address_RowCoordRight+1
lda #BOARD_OFFSET_Y
sta game_BoardOffsetY
lda #BOARD_OFFSET_X
sta game_BoardOffsetX
lda #BOARD_WIDTH
sta game_BoardWidth
lda #BOARD_HEIGHT
sta game_BoardHeight
lda #PADDLE_WALL_LEFT
sta game_PaddleWallLeft
lda #PADDLE_WALL_RIGHT
sta game_PaddleWallRight
lda #Initial_Paddle_X
sta PaddleX+1
lda #Initial_Paddle_Y
sta PaddleY+1
lda #Initial_Paddle_Speed_FRACT
sta PaddleSpeed
lda #Initial_Paddle_Speed_WHOLE
sta PaddleSpeed+1
lda #WALL_TOP
sta game_WallTop
lda #WALL_BOTTOM
sta game_WallBot
lda #WALL_LEFT
sta game_WallLeft
lda #WALL_RIGHT
sta game_WallRight
jsr UpdatePaddleSprite
lda CurrentBoard
jsr LoadMap
jsr DrawCurrentMap
.Update_PpuControl PPU_CTRL_NMI | PPU_CTRL_VERTICAL
; Draw two columns of wall on the second nametable
; to scroll onto with a the screen shake
lda #$24
sta $2006
lda #$00
sta $2006
ldx #30
lda #$01
:
sta $2007
dex
bne :-
lda #$24
sta $2006
lda #$1F
sta $2006
ldx #30
lda #$01
:
sta $2007
dex
bne :-
.ifdef DEBUG
jmp @afterRowCol ; skip but keep code, lol
; Add row numbers
lda #$20
sta $2006
lda #$82
sta $2006
ldx #12
ldy #$10
:
sty $2007
iny
dex
bne :-
.endif
.Update_PpuControl PPU_CTRL_NMI
.ifdef DEBUG
lda #1
sta TmpX
; add column numbers
lda #$20
sta $2006
lda #$44
sta $2006
ldx #16
ldy #$10
:
sty $2007
iny
dex
bne :-
ldx #8
ldy #$10
:
sty $2007
iny
dex
bne :-
@afterRowCol:
.endif
lda Gravity_MainMap
sta game_currentGravity
lda #%10001000
sta PpuControl
lda #$00
sta $2005
sta $2005
Frame_Game:
.NMI_Set NMI_Game
jsr ReadControllers
; TODO: put this in a routine
lda LivesCount
clc
adc #$0A ; offset to sprite
sta Sprites+(4*6)+1
; TODO: Make this a proper sprite / UI element
; wtf is this doing? lmao
bit powerup_ActiveItems
bvc :+
lda #$1F
sta Sprites+(4*6)+1
:
.ifdef DEBUG
lda #BUTTON_SELECT
jsr ButtonPressedP1
beq :++
lda #BUTTON_START
jsr ButtonPressedP1
beq :+
jsr ResetBall
jmp :++
:
; toggle debug mode
lda game_debug
eor #$FF
sta game_debug
:
.endif
lda BallDirection
and #BALL_STATE_INIT
bne @Init
lda #BUTTON_A
jsr ButtonPressedP1
beq :+
jsr BoostTheBall
:
@Init:
.ifdef DEBUG
lda game_debug
beq :+
jmp @debug_input
:
.endif
jsr UpdateBallCoords
jsr UpdatePaddleCoords
@afterCoordUpdate:
jsr CheckWallCollide
beq :+
jmp Frame_Game
:
.ifdef DEBUG
; Disable collision detection in debug mode
; unless B is held
lda game_debug
beq :+
lda #BUTTON_B
and controller1
beq :++
:
.endif
jsr CheckBrickCollide
; Check for remaining bricks
bit CurrentBoard
bpl @checkMain
lda ChildBrickCount
bne @doneCountCheck
; Child board finished
; - Redraw the main board
; - Set the NMI pointer
; - Wait for NMI
; - NMI will turn on drawing
; - Wait for NMI again to draw a full screen
; - Go to frame loop top
jsr game_ReturnToMain
.NMI_Set NMI_Game
jsr WaitForNMI ; wait for non-drawn frame to finish
jsr WaitForNMI ; draw a frame
jmp Frame_Game
@checkMain:
lda MainBrickCount+0
bne @doneCountCheck
lda MainBrickCount+1
bne @doneCountCheck
jmp EndLevel
@doneCountCheck:
bit CurrentBoard
bmi :+
; Skip these on child boards
jsr powerup_CollideCheck
jsr powerup_DoFrameAction
jsr powerup_Animate
:
jsr CheckPaddleCollide
jsr UpdateBallSprite
jsr UpdatePaddleSprite
jsr UpdateBoostSprite
.ifdef DEBUG
jsr game_DebugData
.endif
lda #BUTTON_START
jsr ButtonPressedP1
beq :+
lda controller1
and #BUTTON_A
beq @pause
jmp EndLevel
@pause:
nop
:
.ifdef DEBUG
; Set the ball direction sprite
lda #17
sta Sprites+252
lda #24
sta Sprites+255
lda #$1E
sta Sprites+253
lda BallDirection
sta Sprites+254
.endif
jsr WaitForNMI
jmp Frame_Game
.ifdef DEBUG
@debug_input:
lda #BUTTON_A
and controller1
beq @dbgMove
; change ball direction
lda #BUTTON_LEFT
and controller1
beq :+
lda BallDirection
and #BALL_DIR_UP
sta BallDirection
jmp :++
:
lda #BUTTON_RIGHT
and controller1
beq :+
lda BallDirection
ora #BALL_DIR_RIGHT
sta BallDirection
:
lda #BUTTON_UP
and controller1
beq :+
lda BallDirection
ora #BALL_DIR_UP
sta BallDirection
:
lda #BUTTON_DOWN
and controller1
beq :+
lda BallDirection
and #BALL_DIR_RIGHT
sta BallDirection
:
jmp @afterCoordUpdate
@dbgMove:
lda #BUTTON_LEFT
and controller1
beq :+
dec BallX+1
:
lda #BUTTON_RIGHT
and controller1
beq :+
inc BallX+1
:
lda #BUTTON_UP
and controller1
beq :+
dec BallY+1
:
lda #BUTTON_DOWN
and controller1
beq :+
inc BallY+1
:
jmp @afterCoordUpdate
.endif ; ifdef DEBUG
; starting positions for sprites
DEBUG_DATA_Y = 20
DEBUG_DATA_X = 216
DEBUG_SPRITES = Sprites + (4 * 8) ; 8th sprite
DEBUG_HEX = $50 ; Tile row for hex values
game_DebugData:
lda #DEBUG_DATA_Y
sta DEBUG_SPRITES + (4 * 0)
sta DEBUG_SPRITES + (4 * 1)
lda #DEBUG_DATA_Y + 8
sta DEBUG_SPRITES + (4 * 2)
sta DEBUG_SPRITES + (4 * 3)
lda #DEBUG_DATA_Y + 16
sta DEBUG_SPRITES + (4 * 4)
sta DEBUG_SPRITES + (4 * 5)
sta DEBUG_SPRITES + (4 * 6)
sta DEBUG_SPRITES + (4 * 7)
lda #DEBUG_DATA_Y + 24
sta DEBUG_SPRITES + (4 * 8)
sta DEBUG_SPRITES + (4 * 9)
sta DEBUG_SPRITES + (4 * 10)
sta DEBUG_SPRITES + (4 * 11)
lda #DEBUG_DATA_X
sta DEBUG_SPRITES + 3 + (4 * 0)
sta DEBUG_SPRITES + 3 + (4 * 2)
sta DEBUG_SPRITES + 3 + (4 * 4)
sta DEBUG_SPRITES + 3 + (4 * 8)
lda #DEBUG_DATA_X + 8
sta DEBUG_SPRITES + 3 + (4 * 1)
sta DEBUG_SPRITES + 3 + (4 * 3)
sta DEBUG_SPRITES + 3 + (4 * 5)
sta DEBUG_SPRITES + 3 + (4 * 9)
lda #DEBUG_DATA_X + 16
sta DEBUG_SPRITES + 3 + (4 * 6)
sta DEBUG_SPRITES + 3 + (4 * 10)
lda #DEBUG_DATA_X + 24
sta DEBUG_SPRITES + 3 + (4 * 7)
sta DEBUG_SPRITES + 3 + (4 * 11)
; Attributes
lda #0
sta DEBUG_SPRITES + 2 + (4 * 0)
sta DEBUG_SPRITES + 2 + (4 * 1)
sta DEBUG_SPRITES + 2 + (4 * 2)
sta DEBUG_SPRITES + 2 + (4 * 3)
sta DEBUG_SPRITES + 2 + (4 * 4)
sta DEBUG_SPRITES + 2 + (4 * 5)
sta DEBUG_SPRITES + 2 + (4 * 6)
sta DEBUG_SPRITES + 2 + (4 * 7)
sta DEBUG_SPRITES + 2 + (4 * 8)
sta DEBUG_SPRITES + 2 + (4 * 9)
sta DEBUG_SPRITES + 2 + (4 * 10)
sta DEBUG_SPRITES + 2 + (4 * 11)
; BallX+1
lda BallX+1
jsr BinToHex
lda TmpY
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 0)
lda TmpX
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 1)
; BallY+1
lda BallY+1
jsr BinToHex
lda TmpY
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 2)
lda TmpX
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 3)
; BallSeedX+1
lda BallSpeedX+1
jsr BinToHex
lda TmpY
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 4)
lda TmpX
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 5)
; BallSeedX+0
lda BallSpeedX+0
jsr BinToHex
lda TmpY
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 6)
lda TmpX
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 7)
; BallSeedY+1
lda BallSpeedY+1
jsr BinToHex
lda TmpY
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 8)
lda TmpX
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 9)
; BallSeedY+0
lda BallSpeedY+0
jsr BinToHex
lda TmpY
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 10)
lda TmpX
ora #DEBUG_HEX
sta DEBUG_SPRITES + 1 + (4 * 11)
rts
NMI_Game:
pha
txa
pha
tya
pha
jsr WriteSprites
jsr WritePalettes
lda #%10001000
sta PpuControl
; Destroy any bricks that need destroying
lda BrickDestroyA+1 ;check high byte for value
beq :+
bit $2002
sta $2006
lda BrickDestroyA
sta $2006
lda #0
sta $2007
bit BrickDestroyHalf
bmi :+
sta $2007
:
lda BrickDestroyB+1 ;check high byte for value
beq :+
bit $2002
sta $2006
lda BrickDestroyB
sta $2006
lda #0
sta $2007
bit BrickDestroyHalf
bvs :+
sta $2007
:
lda #0
sta BrickDestroyA
sta BrickDestroyA+1
sta BrickDestroyB
sta BrickDestroyB+1
sta BrickDestroyHalf
bit $2002
lda game_ScrollX
sta $2005
lda game_ScrollY
sta $2005
.Update_PpuMask PPU_MASK_ON | PPU_MASK_LEFTSPRITES | PPU_MASK_LEFTBACKGROUND
lda PpuControl
ora game_Nametable
sta $2000
dec Sleeping
pla
tay
pla
tax
pla
rti
game_DrawWalls:
bit CurrentBoard
bmi @childBoard
; Right wall
lda #$20
sta AddressPointer0+1
lda #$1F
sta AddressPointer0+0
; bottom wall
lda #$23
sta AddressPointer1+1
lda #$80
sta AddressPointer1+0
lda #2
sta TmpX ; top row count
lda #1
sta TmpY ; column count for left/right
jmp @loops
@childBoard:
; Right wall
lda #$20
sta AddressPointer0+1
lda #$1A
sta AddressPointer0+0
; bottom wall
lda #$23
sta AddressPointer1+1
lda #$00
sta AddressPointer1+0
lda #4
sta TmpX ; top row count
lda #6
sta TmpY ; column count for left/right
@loops:
; Draw top two rows
lda #$20
sta $2006
lda #$00
sta $2006
lda #$01
ldx TmpX
:
.repeat 32
sta $2007
.endrepeat
dex
bne :-
; draw bottom two rows
lda AddressPointer1+1
sta $2006
lda AddressPointer1+0
sta $2006
lda #$0F
ldx TmpX
:
.repeat 32
sta $2007
.endrepeat
dex
bne :-
; Draw Left (left after top to use address)
lda #%10011100
sta $2000
ldy #$00
sty TmpZ
lda #$01
ldx TmpY
:
ldy #$20
sty $2006
ldy TmpZ
sty $2006
inc TmpZ
.repeat 30
sta $2007
.endrepeat
dex
bne :-
; Draw Right
lda #$01
ldx TmpY
:
ldy #$20
sty $2006
ldy AddressPointer0
sty $2006
inc AddressPointer0
.repeat 30
sta $2007
.endrepeat
dex
bne :-
rts
BoostTheBall:
lda game_currentGravity
bne :+
rts
:
lda BoostPool
bne :+
rts
: dec BoostPool
bit BallDirection
bpl @down
; going up
lda BallSpeedY
clc
adc #BOOST_VALUE
sta BallSpeedY
lda BallSpeedY+1
adc #0
sta BallSpeedY+1
rts
@down:
lda BallSpeedY
sec
sbc #BOOST_VALUE
sta BallSpeedY
lda BallSpeedY+1
sbc #0
sta BallSpeedY+1
bmi :+
rts
:
; handle underflow
lda #0
sec
sbc BallSpeedY+0
sta BallSpeedY+0
lda #0
sbc BallSpeedY+1
sta BallSpeedY+1
lda BallDirection
and #$40
sta BallDirection
rts
UpdateBoostSprite:
lda game_currentGravity
bne :+
lda #$FF
sta Sprites+(4*5)
sta Sprites+(4*5)+3
rts
:
lda #16
sta Sprites+(4*5)
lda #24
sta Sprites+(4*5)+3
lda BoostPool
beq @empty
clc
adc #$0A
sta Sprites+(4*5)+1
rts
@empty:
lda #0
sta Sprites+(4*5)+1
rts
ResetBall:
lda #Initial_Ball_Direction
ora #BALL_STATE_INIT
sta BallDirection
lda PaddleX
sta BallX
lda PaddleY
sta BallY
lda PaddleX+1
sta BallX+1
lda PaddleY+1
sta BallY+1
;lda #Initial_Ball_Speed_FRACT
lda #0
sta BallSpeedY
sta BallSpeedX
;lda #Initial_Ball_Speed_WHOLE
sta BallSpeedY+1
sta BallSpeedX+1
; Reset gravity powerup
lda Gravity_MainMap
bne :+
; Turn off the gravity if you die
lda #0
sta game_currentGravity
sta pu_Gravity+0
sta pu_Gravity+1
:
rts
; Read the button inputs and update the paddle coords accordingly
UpdatePaddleCoords:
lda #Initial_Paddle_Speed_FRACT
sta PaddleSpeed
lda #Initial_Paddle_Speed_WHOLE
sta PaddleSpeed+1
lda BallDirection
and #BALL_STATE_INIT
beq @notInit
; When in the init state launch ball
; when A is pressed.
lda #BUTTON_A
jsr ButtonPressedP1
beq :+
lda BallDirection
eor #BALL_STATE_INIT
sta BallDirection
jsr UpdateBallAngle
: