-
Notifications
You must be signed in to change notification settings - Fork 1
/
astroblast.asm
2322 lines (1927 loc) · 67.7 KB
/
astroblast.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
//////////////////////////////////////////////////////////////////////////////
// astroblast.asm
// Copyright(c) 2021 Neal Smith.
// License: MIT. See LICENSE file in root directory.
//
// AstroBlaster Main program
//////////////////////////////////////////////////////////////////////////////
#import "../nv_c64_util/nv_c64_util_macs_and_data.asm"
#import "astro_sound_macs.asm"
*=$0800 "BASIC Start" // location to put a 1 line basic program so we can just
// type run to execute the assembled program.
// will just call assembled program at correct location
// 10 SYS (4096)
// These bytes are a one line basic program that will
// do a sys call to assembly language portion of
// of the program which will be at $1000 or 4096 decimal
// basic line is:
// 10 SYS (4096)
.byte $00 // first byte of basic area should be 0
.byte $0E, $08 // Forward address to next basic line
.byte $0A, $00 // this will be line 10 ($0A)
.byte $9E // basic token for SYS
.byte $20, $28, $34, $30, $39, $36, $29 // ASCII for " (4096)"
.byte $00, $00, $00 // end of basic program (addr $080E from above)
*=$0820 "Main Program Vars"
#import "astro_keyboard_macs.asm"
#import "astro_vars_data.asm"
#import "astro_wind_data.asm"
#import "astro_ship_death_data.asm"
#import "astro_ship_shield_data.asm"
#import "astro_blackhole_data.asm"
.const KEY_COOL_DURATION = $08
.const ASTRO_GAME_SECONDS_ROW = 0
.const ASTRO_GAME_SECONDS_COL = 17
.const DEBUG_KEYS_ON = false
.const HOLE_SOUND_FRAMES = 31
ship1_collision_sprite_label: .text @"ship1 coll sprite: \$00"
nv_b8_label: .text @"nv b8 coll sprite: \$00"
// the data for the sprites.
// the file specifies where it assembles to ($0900)
#import "astro_sprite_data.asm"
// our assembly code will goto this address
// it will go from $1000-$2FFF
*=$1000 "Main Start"
jmp RealStart
#import "../nv_c64_util/nv_screen_code.asm"
#import "../nv_c64_util/nv_sprite_raw_collisions_code.asm"
#import "../nv_c64_util/nv_sprite_raw_code.asm"
#import "../nv_c64_util/nv_sprite_extra_code.asm"
#import "astro_ships_code.asm"
#import "astro_ship_death_code.asm"
#import "astro_ship_shield_code.asm"
//////////////////////////////////////////////////////////////////////////////
// charset is expected to be at $3000
*=$3000 "charset start"
.import binary "astro_charset.bin"
// end charset
//////////////////////////////////////////////////////////////////////////////
#import "astro_starfield_code.asm"
#import "astro_turret_armer_code.asm"
#import "../nv_c64_util/nv_joystick_code.asm"
#import "astro_blackhole_code.asm"
#import "astro_turret_code.asm"
.const ASTRO_CHANGE_UP_MASK = $03
RealStart:
jsr DoPreTitleInit
DoTitle:
jsr TitleStart // show title screen
bne RunGame // make sure non zero in accum and run game
jmp ProgramDone // if zero in accum then user quit
RunGame:
// standard initialization
jsr DoPostTitleInit
.var showTiming = false
.var showFrameCounters = false
.var showSecondCounter = false
jsr StarStart
// display timer with initial value if time based game
lda astro_end_on_seconds
beq MainLoop
nv_screen_poke_hex_word_mem(ASTRO_GAME_SECONDS_ROW, ASTRO_GAME_SECONDS_COL, astro_game_seconds, false)
MainLoop:
nv_adc16x_mem_immed(frame_counter, 1, frame_counter)
nv_adc16x_mem_immed(second_partial_counter, 1, second_partial_counter)
// check if a full second has elapsed
nv_bge16_immed(second_partial_counter, ASTRO_FPS, FullSecond)
// not a full second (or time to change up) so do the regular frame stuff
jmp RegularFrame
FullSecond:
// a full second has elapsed, do the stuff that we do once per second
// add one to the second counter and display second counter
nv_adc16x_mem_immed(second_counter, 1, second_counter)
.if (showFrameCounters)
{
nv_screen_poke_hex_word_mem(0, 7, second_counter, true)
}
// check the quit flag which is set if user presses quit key
lda quit_flag
beq CheckEndOnSeconds
// quit flag is set, program done
jmp ProgramDone
CheckEndOnSeconds:
lda astro_end_on_seconds
beq DoneEndOnSeconds
// playing until some number of seconds elapses
nv_bcd_sbc16_mem_immed(astro_game_seconds, $0001, astro_game_seconds)
nv_screen_poke_hex_word_mem(ASTRO_GAME_SECONDS_ROW, ASTRO_GAME_SECONDS_COL, astro_game_seconds, false)
lda astro_game_seconds
bne DoneEndOnSeconds
// game is over
jsr DoWinner
jmp DoTitle
DoneEndOnSeconds:
// clear partial second counter which counts frame up to a
// full second then back to zero
nv_store16_immed(second_partial_counter, $0000)
// now check the "change up" stuff that happens once per x seconds
lda #ASTRO_CHANGE_UP_MASK
and second_counter //set flag every 4 secs when bits 0 and 1 clear
bne RegularFrame
// if here its time to changeup
jsr ChangeUp
.if (showFrameCounters)
{
nv_screen_poke_hex_word_mem(0, 14, change_up_counter, true)
}
RegularFrame:
// its a new frame, but not a new second and not time to change up
.if (showFrameCounters)
{
nv_screen_poke_hex_word_mem(0, 0, frame_counter, true)
}
//// call function to move sprites around based on X and Y velocity
// but only modify the position in their extra data block not on screen
.if (showTiming)
{
nv_screen_set_border_color_immed(NV_COLOR_LITE_GREEN)
}
// check if its time to start some wind
jsr WindCheck
// read keyboard and take action before other effects incase
// other effects will override keyboard action
jsr DoKeyboard
jsr DoJoystick
// step through the effects
jsr StarStep
jsr WindStep
jsr DoHoleStep
jsr TurretStep
jsr TurretArmStep
jsr ShipDeathStep
jsr ShipShieldStep
// fire the turret automatically if its time.
jsr TurretAutoStart
// move the sprites based on velocities set above.
jsr ship_1.MoveInExtraData
jsr ship_2.MoveInExtraData
jsr asteroid_1.MoveInExtraData
jsr asteroid_2.MoveInExtraData
jsr asteroid_3.MoveInExtraData
jsr asteroid_4.MoveInExtraData
jsr asteroid_5.MoveInExtraData
.if (showTiming)
{
//lda #NV_COLOR_LITE_BLUE // change border color back to
//sta BORDER_COLOR_REG_ADDR // visualize timing
nv_screen_set_border_color_mem(border_color)
}
nv_sprite_wait_last_scanline() // wait for particular scanline.
lda astro_slow_motion
beq AstroSkipSlowMo
nv_sprite_wait_specific_scanline(240)
AstroSkipSlowMo:
.if (showTiming)
{
nv_screen_set_border_color_immed(NV_COLOR_GREEN)
//lda #NV_COLOR_GREEN // change border color to
//sta BORDER_COLOR_REG_ADDR // visualize timing
}
SoundDoStep()
jsr SlowMoStep
jsr StepShipExhaust
//// call routine to update sprite x and y positions on screen
jsr ship_1.SetLocationFromExtraData
jsr ship_2.SetLocationFromExtraData
jsr asteroid_1.SetLocationFromExtraData
jsr asteroid_2.SetLocationFromExtraData
jsr asteroid_3.SetLocationFromExtraData
jsr asteroid_4.SetLocationFromExtraData
jsr asteroid_5.SetLocationFromExtraData
nv_sprite_raw_get_sprite_collisions_in_a()
sta sprite_collision_reg_value
//////////////////////////////////////////////////////////////////////
//// check for ship1 collisions
jsr CheckCollisionsUpdateScoreShip1
beq NoWinShip1
// if get here then ship 1 has winning score
// update ship 2 in case it also has winning score
jsr CheckCollisionsUpdateScoreShip2
jsr DoWinner
jmp DoTitle
NoWinShip1:
NoCollisionShip1:
//////////////////////////////////
//// check for ship2 collisions
jsr CheckCollisionsUpdateScoreShip2
beq NoWinShip2
jsr DoWinner
jmp DoTitle
NoWinShip2:
jsr TurretHitCheck
jsr ScoreToScreen
jmp MainLoop
ProgramDone:
// Done moving sprites, move cursor out of the way
// and return, but leave the sprites on the screen
// also set border color to normal
nv_screen_set_border_color_immed(NV_COLOR_LITE_BLUE)
nv_screen_set_background_color_immed(NV_COLOR_BLUE)
jsr StarCleanup
jsr TurretArmCleanup
jsr TurretCleanup
jsr WindCleanup
jsr HoleCleanup
jsr ShipDeathCleanup
jsr ShipShieldCleanup
jsr JoyCleanup
jsr SoundMuteOn
jsr SoundDone
jsr AllSpritesDisable
nv_key_done()
nv_rand_done()
nv_screen_custom_charset_done()
nv_screen_plot_cursor(5, 24)
nv_screen_clear()
rts // program done, return
// end main program
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to step the hole
DoHoleStep:
{
jsr HoleActive
bne HoleIsActive // its active
HoleNotActive:
//jsr SoundPlaySilenceFX
rts
HoleIsActive:
jsr HoleStep
nv_ble16(frame_counter, astro_hole_restart_sound_frame, DoneDoHoleStep)
jsr SoundPlayHoleFX
nv_adc16x_mem_immed(frame_counter, HOLE_SOUND_FRAMES, astro_hole_restart_sound_frame)
DoneDoHoleStep:
rts
}
// DoHoleStep - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to flash the ship's exhaust different colors
StepShipExhaust:
{
lda frame_counter
and #$07
bne NoToggle
IsToggle:
lda astro_multi_color1
cmp #NV_COLOR_LITE_GREEN
beq GoYellow
GoGreen:
lda #NV_COLOR_LITE_GREEN
sta astro_multi_color1
nv_sprite_raw_set_multicolors(NV_COLOR_LITE_GREEN, NV_COLOR_LITE_GREY)
jmp NoToggle
GoYellow:
lda #NV_COLOR_YELLOW
sta astro_multi_color1
nv_sprite_raw_set_multicolors(NV_COLOR_YELLOW, NV_COLOR_LITE_GREY)
NoToggle:
rts
}
// StepShipExhaust - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to check collisions for ship 1 and update score accordingly
// return value:
// Accum: will be non zero if ship has a winning score, or zero if
// it does not
CheckCollisionsUpdateScoreShip1:
check_collisions_update_score_sr(ship_1, ship_1_death_count, 1, ship_1_next_possible_bounce_frame, SoundPlayShip1AsteroidFX)
// CheckCollisionsUpdateScoreShip1 end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to check if ship 2 hit asteroid and update score accordingly
// return values:
// Accum: will have 0 if ship didn't win, or non zero if ship won
CheckCollisionsUpdateScoreShip2:
check_collisions_update_score_sr(ship_2, ship_2_death_count, 2, ship_2_next_possible_bounce_frame, SoundPlayShip2AsteroidFX)
// CheckCollisionsUpdateScoreShip2 end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// macro subroutine to check if ship hit asteroid and update score
// accordingly
// macro params:
// ship: is ship_1 or ship_2
// ship_death_count: is the address of the byte that holds the ships
// death count. it will be non zero if dead
// ship_num: is 1 for ship_1 or 2 for ship_2
// next_possible_bounce_frame: is the address of the word that
// holds the next frame at which this
// ship will be able to bounce.
// sound_fx_ship_hit_asteroid: is the address to jsr to play the ship
// hit asteroid sound fx
.macro check_collisions_update_score_sr(ship, ship_death_count, ship_num, next_possible_bounce_frame, sound_fx_ship_hit_asteroid)
{
jsr ship.CheckShipCollision // sets ship.collision_sprite
lda ship.collision_sprite // closest_sprite, will be $FF
bpl HandleCollisionShip // if no collisions so check minus
jmp NoCollisionShip
HandleCollisionShip:
lda ship_death_count // if ship is dead then ignore collisions
beq NoDeath
jmp NoCollisionShip
NoDeath:
// get extra pointer for the sprite that ship1 collided with loaded
// so that we can then disable it
ldy ship.collision_sprite
cpy blackhole.sprite_num
bne CollisionNotHole
jsr HoleForceStop
jsr SlowMoStart
jsr SoundPlaySilenceFX
lda #0
rts
CollisionNotHole:
lda #ship_num
jsr ShipShieldIsActive // will not change Y Reg
bne ShipShieldUp
jsr AstroSpriteExtraPtrToRegs // Y Reg still has sprite number in it
jsr NvSpriteExtraDisable
jsr sound_fx_ship_hit_asteroid
// add one to ship score
nv_bcd_adc16_mem_immed(ship.score, $0001, ship.score)
// check if playing time based or score based end
lda astro_end_on_seconds
beq WinShip
jmp NoWinShip
WinShip:
// check if that is the winning score
nv_blt16_far(ship.score, astro_score_to_win, NoWinShip)
// if we get here then ship won
lda #1
rts
ShipShieldUp:
// Y Reg should still have the sprite number.
sty temp // store sprite number in temp
nv_blt16_far(frame_counter, next_possible_bounce_frame, NoBounce)
// here so we need to bounce the ship/asteroid.
ldy temp // sprite number back in Y
jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg
jsr NvSpriteGetHitboxCenter // get asteroid's center x/y screen coords
nv_xfer16_mem_mem(nv_sprite_hitbox_center_x, asteroid_center_x)
nv_xfer16_mem_mem(nv_sprite_hitbox_center_y, asteroid_center_y)
jsr ship.LoadExtraPtrToRegs
jsr NvSpriteGetHitboxCenter // get asteroid's center x/y screen coords
nv_xfer16_mem_mem(nv_sprite_hitbox_center_x, ship_center_x)
nv_xfer16_mem_mem(nv_sprite_hitbox_center_y, ship_center_y)
BounceY:
nv_blt16(asteroid_center_y, ship_center_y, BounceAsteroidAbove)
BounceAsteroidBelow:
ldy temp // sprite number back in Y
jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg
jsr NvSpriteAssureVelPosY
jsr ship.LoadExtraPtrToRegs
jsr NvSpriteAssureVelNegY
jmp BounceX
BounceAsteroidAbove:
ldy temp // sprite number back in Y
jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg
jsr NvSpriteAssureVelNegY
jsr ship.LoadExtraPtrToRegs
jsr NvSpriteAssureVelPosY
BounceX:
nv_blt16(asteroid_center_x, ship_center_x, BounceAsteroidLeft)
BounceAsteroidRight:
ldy temp // sprite number back in Y
jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg
jsr NvSpriteAssureVelPosX
jsr ship.LoadExtraPtrToRegs
jsr NvSpriteAssureVelNegX
jmp BounceDone
BounceAsteroidLeft:
ldy temp // sprite number back in Y
jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg
jsr NvSpriteAssureVelNegX
jsr ship.LoadExtraPtrToRegs
jsr NvSpriteAssureVelPosX
BounceDone:
nv_adc16x_mem_immed(frame_counter, 3, next_possible_bounce_frame)
NoBounce:
NoWinShip:
NoCollisionShip:
lda #0
rts
temp: .byte $00
asteroid_center_x: .word $00
asteroid_center_y: .word $00
ship_center_x: .word $00
ship_center_y: .word $00
}
// check_collisions_update_score_sr end
//////////////////////////////////////////////////////////////////////////////
SlowMoStart:
{
lda #255
sta astro_slow_motion
rts
}
SlowMoForceStop:
{
lda #0
sta astro_slow_motion
rts
}
SlowMoStep:
{
lda astro_slow_motion
beq Done
dec astro_slow_motion
Done:
rts
}
//////////////////////////////////////////////////////////////////////////////
// subroutine to initialize the things that must be initialized before
// screen is started
DoPreTitleInit:
{
nv_screen_custom_charset_init(6, false)
nv_screen_set_border_color_mem(border_color)
nv_screen_set_background_color_mem(background_color)
// initialize joystick
jsr JoyInit
// initialize random numbers, needs to be before soundstarts
nv_rand_init(true) // do before SoundInit
// initialized keyboard routine so user can use keyboard
// in title screen for changing options etc.
nv_key_init()
// initialize song 0 so we can hear music during title
// so user can adjust volume
//lda #ASTRO_SOUND_MAIN_TUNE
lda #ASTRO_SOUND_TITLE_TUNE
jsr SoundInit
// start at volumen 2
lda #$02
jsr SoundVolumeSet
// clear quit flag since it can be set in title screen
lda #$00
sta quit_flag
sta astro_slow_motion
// start out in easy mode, user can adjust in title screen
lda #ASTRO_DIFF_EASY
sta astro_diff_mode
// set the default game seconds
nv_store16_immed(astro_game_seconds, ASTRO_GAME_SECONDS_DEFAULT)
// set default, play to reach seconds or to reach score
lda #0
sta astro_end_on_seconds
// set the global sprite multi colors
nv_sprite_raw_set_multicolors(NV_COLOR_LITE_GREEN, NV_COLOR_LITE_GREY)
// setup the score required to win to default value
nv_store16_immed(astro_score_to_win, ASTRO_DEFAULT_SCORE_TO_WIN)
nv_xfer8x_immed_mem(1, astro_single_player_flag)
// setup everything for the sprite_ship so its ready to enable
jsr ship_1.Setup
jsr ship_2.Setup
jsr ship_1.SetColorAlive
jsr ship_2.SetColorAlive
// setup everything for the sprite_asteroid so its ready to enable
jsr asteroid_1.Setup
jsr asteroid_2.Setup
jsr asteroid_3.Setup
jsr asteroid_4.Setup
jsr asteroid_5.Setup
// initialize sprite locations from their extra data blocks
jsr ship_1.SetLocationFromExtraData
jsr ship_2.SetLocationFromExtraData
jsr asteroid_1.SetLocationFromExtraData
jsr asteroid_2.SetLocationFromExtraData
jsr asteroid_3.SetLocationFromExtraData
jsr asteroid_4.SetLocationFromExtraData
jsr asteroid_5.SetLocationFromExtraData
rts
}
// DoPreTitleInit - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to initialize the things that must be initialized after the
// title screen is started
DoPostTitleInit:
{
nv_store16_immed(second_counter, $0000)
nv_store16_immed(second_partial_counter, $0000)
nv_store16_immed(frame_counter, $0000)
nv_store16_immed(ship_1.score, $0000)
nv_store16_immed(ship_2.score, $0000)
nv_store16_immed(ship_1_next_possible_bounce_frame, $0000)
nv_store16_immed(ship_2_next_possible_bounce_frame, $0000)
lda #$00
sta sprite_collision_reg_value
sta astro_slow_motion
// initialize based on difficulty (must be after standard init)
jsr AstroSetDiffParams
// clear the screen just to have an empty canvas
nv_screen_clear()
jsr StarInit
jsr WindInit
jsr TurretInit
// initialize song 0 so we can hear music during title
// so user can adjust volume
lda #ASTRO_SOUND_MAIN_TUNE
jsr SoundInit
// pass the diff mode to TurretArmInit. Note that we are
// assuming that TURRET_ARM_EASY = ASTRO_DIFF_EASY, etc.
// which is a convienent coincidence and why we are asserting it.
.assert "Turret Arm Diff Check", TURRET_ARM_EASY == ASTRO_DIFF_EASY, true
.assert "Turret Arm Diff Check", TURRET_ARM_MED == ASTRO_DIFF_MED, true
.assert "Turret Arm Diff Check", TURRET_ARM_HARD == ASTRO_DIFF_HARD, true
lda astro_diff_mode
jsr TurretArmInit
jsr TurretArmStart
jsr ShipDeathInit
jsr ShipShieldInit
jsr HoleInit
// initialize sprite locations to locations to start game
.const SHIP1_INIT_X_LOC = 22
.const SHIP1_INIT_Y_LOC = 50
.const SHIP1_INIT_X_VEL = 1
.const SHIP1_INIT_Y_VEL = 1
.const SHIP2_INIT_X_LOC = 22
.const SHIP2_INIT_Y_LOC = 210
.const SHIP2_INIT_X_VEL = 1
.const SHIP2_INIT_Y_VEL = 1
// init ship 1
nv_store16_immed(ship_1.x_loc, SHIP1_INIT_X_LOC)
lda #SHIP1_INIT_Y_LOC
sta ship_1.y_loc
lda #SHIP1_INIT_X_VEL
sta ship_1.x_vel
lda #SHIP1_INIT_Y_VEL
sta ship_1.y_vel
jsr ship_1.SetLocationFromExtraData
jsr ship_1.SetColorAlive
// init ship 2
nv_store16_immed(ship_2.x_loc, 0)
lda #SHIP2_INIT_Y_LOC
sta ship_2.y_loc
lda #SHIP2_INIT_X_VEL
sta ship_2.x_vel
lda #SHIP2_INIT_Y_VEL
sta ship_2.y_vel
jsr ship_2.SetLocationFromExtraData
// set color for ship 2
jsr ship_2.SetColorAlive
jsr asteroid_1.SetLocationFromExtraData
jsr asteroid_2.SetLocationFromExtraData
jsr asteroid_3.SetLocationFromExtraData
jsr asteroid_4.SetLocationFromExtraData
jsr asteroid_5.SetLocationFromExtraData
jsr AllSpritesEnable
rts
}
// DoPosttitleInit - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to enable all sprites
AllSpritesEnable:
{
// enable sprites
jsr ship_1.Enable
jsr ship_2.Enable
jsr asteroid_1.Enable
jsr asteroid_2.Enable
jsr asteroid_3.Enable
jsr asteroid_4.Enable
jsr asteroid_5.Enable
rts
}
// AllSpritesEnable
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to disable all sprites
AllSpritesDisable:
{
// enable sprites
jsr ship_1.Disable
jsr ship_2.Disable
jsr asteroid_1.Disable
jsr asteroid_2.Disable
jsr asteroid_3.Disable
jsr asteroid_4.Disable
jsr asteroid_5.Disable
rts
}
// AllSpritesDisable
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call when there is a winner detected
DoWinner:
{
.const WINNER_SHIP_X_LOC = 69
.const WINNER_SHIP_Y_LOC = 131
.const WINNER_TIE_SHIP_X_LOC = WINNER_SHIP_X_LOC - 30
.const WINNER_TIE_SHIP_Y_LOC = WINNER_SHIP_Y_LOC
.const WINNER_TEXT_ROW = 11
.const WINNER_TEXT_COL = 10
.const WINNER_CONTINUE_ROW = 23
.const WINNER_CONTINUE_COL = 10
jsr SoundMuteOn
jsr HoleForceStop
jsr AllSpritesDisable
nv_screen_clear()
// show the score
jsr ScoreToScreen
// force sheilds off for both ships
lda #$03
jsr ShipShieldForceStop
// check for a tie
nv_beq16(ship_1.score, ship_2.score, WinnerTie)
// not a tie, there was a winner
nv_screen_poke_color_str(WINNER_TEXT_ROW, WINNER_TEXT_COL, NV_COLOR_WHITE, winner_str)
nv_bge16(ship_1.score, ship_2.score, WinnerShip1)
WinnerShip2:
nv_store16_immed(ship_2.x_loc, WINNER_SHIP_X_LOC)
lda #WINNER_SHIP_Y_LOC
sta ship_2.y_loc
jsr ship_2.SetLocationFromExtraData
jsr ship_2.SetColorAlive
jsr ship_2.Enable
jmp WinnerWaitForKey
WinnerShip1:
nv_store16_immed(ship_1.x_loc, WINNER_SHIP_X_LOC)
lda #WINNER_SHIP_Y_LOC
sta ship_1.y_loc
jsr ship_1.SetLocationFromExtraData
jsr ship_1.SetColorAlive
jsr ship_1.Enable
jmp WinnerWaitForKey
WinnerTie:
nv_screen_poke_color_str(WINNER_TEXT_ROW, WINNER_TEXT_COL, NV_COLOR_WHITE, winner_tie_str)
// display ship 1
nv_store16_immed(ship_1.x_loc, WINNER_SHIP_X_LOC)
lda #WINNER_SHIP_Y_LOC
sta ship_1.y_loc
jsr ship_1.SetLocationFromExtraData
jsr ship_1.SetColorAlive
jsr ship_1.Enable
// display ship 2
nv_store16_immed(ship_2.x_loc, WINNER_TIE_SHIP_X_LOC)
lda #WINNER_TIE_SHIP_Y_LOC
sta ship_2.y_loc
jsr ship_2.SetLocationFromExtraData
jsr ship_2.SetColorAlive
jsr ship_2.Enable
WinnerWaitForKey:
// fall through to wait for key
nv_screen_poke_color_str(WINNER_CONTINUE_ROW, WINNER_CONTINUE_COL, NV_COLOR_WHITE, winner_continue_str)
nv_screen_poke_color_str(WINNER_CONTINUE_ROW+1, WINNER_CONTINUE_COL, NV_COLOR_WHITE, winner_quit_str)
nv_key_wait_no_key()
// initialize song 0 so we can hear music during title
// so user can adjust volume
lda #ASTRO_SOUND_WIN_TUNE
jsr SoundInit
jsr SoundMuteOff
WinnerWaitForKeyLoop:
nv_sprite_wait_last_scanline()
SoundDoStep()
nv_key_scan()
nv_key_get_last_pressed_a() // get key pressed in accum
WinnerTryContinueKey:
cmp #KEY_WINNER_CONTINUE
bne WinnerTryQuitKey
WinnerGotContinueKey:
beq WinnerGotKey
WinnerTryQuitKey:
cmp #KEY_QUIT
bne WinnerKeyCheckEnd
WinnerGotQuitKey:
lda #1
sta quit_flag
jmp WinnerGotKey
WinnerKeyCheckEnd:
jmp WinnerWaitForKeyLoop
WinnerGotKey:
jsr SoundMuteOff
jsr AllSpritesDisable
// clear collsions so replaying won't use value from last
// frame of this game
lda #$00
sta sprite_collision_reg_value
rts
//winner_key_count: .byte 0
//winner_temp_key: .byte 0
winner_str: .text @"the winner!\$00"
winner_tie_str: .text @"tie game!\$00"
winner_continue_str: .text @"press p to play more\$00"
winner_quit_str: .text @"press q to quit now\$00"
}
// DoWinner End
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to set the program parameters based on the difficulty
// option specified on title screen
// NPS single player
AstroSetDiffParams:
{
lda astro_diff_mode
TryEasy:
cmp #ASTRO_DIFF_EASY
bne TryMed
IsEasy:
// Set easy mode params here
nv_store16_immed(astro_auto_turret_wait_frames, ASTRO_AUTO_TURRET_WAIT_FRAMES_EASY)
nv_store16_immed(astro_ai_turret_frames_before_auto, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_EASY)
nv_store16_immed(astro_ai_turret_frames_before_auto_base, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_EASY)
jmp DoneDiffParams
TryMed:
cmp #ASTRO_DIFF_MED
bne TryHard
IsMed:
// Set medium mode params here
nv_store16_immed(astro_auto_turret_wait_frames, ASTRO_AUTO_TURRET_WAIT_FRAMES_MED)
nv_store16_immed(astro_ai_turret_frames_before_auto, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_MED)
nv_store16_immed(astro_ai_turret_frames_before_auto_base, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_MED)
jmp DoneDiffParams
TryHard:
// if wasn't easy or medium, assume hard
// set hard mode params here
nv_store16_immed(astro_auto_turret_wait_frames, ASTRO_AUTO_TURRET_WAIT_FRAMES_HARD)
nv_store16_immed(astro_ai_turret_frames_before_auto, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_HARD)
nv_store16_immed(astro_ai_turret_frames_before_auto_base, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_HARD)
// fall through to done
DoneDiffParams:
nv_adc16x(frame_counter, astro_auto_turret_wait_frames,
astro_auto_turret_next_shot_frame)
nv_sbc16(astro_auto_turret_next_shot_frame, astro_ai_turret_frames_before_auto,
astro_ai_turret_next_shot_frame)
rts
}
//////////////////////////////////////////////////////////////////////////////
// subroutine to put the score onto the screen
ScoreToScreen:
{
nv_screen_poke_bcd_word_mem(0, 0, ship_1.score)
nv_screen_poke_bcd_word_mem(24, 0, ship_2.score)
rts
}
//////////////////////////////////////////////////////////////////////////////
// subroutine to change things up every x seconds.
ChangeUp:
{
.const COLOR_MASK = $0F
// increment the changeup counter.
nv_adc16x_mem_immed(change_up_counter, 1, change_up_counter)
inc cycling_color
lda cycling_color
and #COLOR_MASK
sta cycling_color
lda background_color
and #COLOR_MASK
cmp cycling_color
bne NotBG
IsBG:
inc cycling_color
lda cycling_color
and #COLOR_MASK
sta cycling_color
NotBG:
nv_sprite_raw_set_color_from_memory(1, cycling_color)
// change some speeds
SkipShipMax:
inc asteroid_1.y_vel // increment asteroid Y velocity
lda asteroid_1.y_vel // load new speed just incremented
cmp #SHIP_MAX_SPEED+1 // compare new spead with max +1
bne SkipAsteroidMin // if we haven't reached max + 1 then skip setting to min
lda #SHIP_MIN_SPEED // else, we have reached max+1 so need to reset it back min
sta asteroid_1.y_vel
SkipAsteroidMin:
// check if its time for a black hole
lda change_up_counter
and #$07
bne NoHole
jsr HoleStart
jsr SoundPlayHoleFX
nv_adc16x_mem_immed(frame_counter, HOLE_SOUND_FRAMES, astro_hole_restart_sound_frame)
NoHole:
// revive all the disabled astroids
CheckDisabled:
jsr asteroid_1.LoadEnabledToA
bne CheckAster2
lda #130
sta asteroid_1.y_loc
jsr asteroid_1.Enable
CheckAster2:
jsr asteroid_2.LoadEnabledToA
bne CheckAster3
lda #130
sta asteroid_2.y_loc
jsr asteroid_2.Enable
CheckAster3:
jsr asteroid_3.LoadEnabledToA
bne CheckAster4
lda #130
sta asteroid_3.y_loc
jsr asteroid_3.Enable
CheckAster4:
jsr asteroid_4.LoadEnabledToA
bne CheckAster5
lda #130
sta asteroid_4.y_loc
jsr asteroid_4.Enable
CheckAster5:
jsr asteroid_5.LoadEnabledToA
bne DoneCheckingDisabledAsteroids
lda #130
sta asteroid_5.y_loc
jsr asteroid_5.Enable
DoneCheckingDisabledAsteroids:
rts