-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.s
executable file
·1688 lines (1386 loc) · 51 KB
/
game.s
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
AREA lib, CODE, READWRITE
EXTERN BOARD_WIDTH
EXTERN BOARD_HEIGHT
EXTERN rand
EXTERN div_and_mod
EXTERN set_cursor_pos
EXPORT keystroke
EXPORT board
EXPORT prev_board
EXPORT initialize_game
EXPORT update_game
EXPORT game_over
EXPORT life_lost_flag
EXPORT clear_board
EXPORT reset_game
EXPORT score
EXPORT time_left
EXPORT level
EXPORT calculate_bonus
EXPORT num_lives
EXPORT bomb_detonated
EXPORT game_active
EXPORT blink_timer
EXTERN game_loop
EXTERN T0MR0
BRICK_WALL EQU '#'
BOMBERMAN EQU 'B'
ENEMY_SLOW EQU 'x'
ENEMY_FAST EQU '+'
BOMB EQU 'ð'
BOMB_EXPLODED EQU 'o'
BLAST_VERTICAL EQU '|'
BLAST_HORIZONTAL EQU '-'
BARRIER EQU 'Z'
FREE EQU ' '
UP_KEY EQU 'w'
LEFT_KEY EQU 'a'
DOWN_KEY EQU 's'
RIGHT_KEY EQU 'd'
PLACE_BOMB_KEY EQU 'x'
MOVE_UP EQU 1
MOVE_RIGHT EQU 2
MOVE_DOWN EQU 3
MOVE_LEFT EQU 4
ENEMY_MULTIPLIER EQU 10 ; Score multiplier when enemy is killed (score += level * multiplier)
LEVEL_CLEARED_BONUS EQU 100 ; Score bonus when level is completed (score += 100)
LIFE_REMAINING_BONUS EQU 25 ; Score bonus awarded for each life remaining when game is over (score += num_lives * life_remaining_bonus)
MAX_LEVEL EQU 4 ; Maximum level user can reach. After the player passes this level,
; the game no longer increases in speed.
BOMBERMAN_X_START EQU 1 ; Bomberman starting x-position.
BOMBERMAN_Y_START EQU 1 ; Bomberman starting y-position.
ENEMY1_X_START EQU 23 ; Enemy 1 starting x-position.
ENEMY1_Y_START EQU 1 ; Enemy 1 starting y-position.
ENEMY2_X_START EQU 1 ; Enemy 2 starting x-position.
ENEMY2_Y_START EQU 11 ; Enemy 2 starting y-position.
ENEMY3_X_START EQU 23 ; Enemy 3 (FAST) starting x-position.
ENEMY3_Y_START EQU 11 ; Enemy 3 (FAST) starting y-position.
BOMB_TIMEOUT EQU 10 ; After many refreshes the bomb should detonate.
BLAST_X_RADIUS EQU 4 ; Horizontal blast radius.
BLAST_Y_RADIUS EQU 2 ; Vertical blast radius.
BLINK_REFRESHES EQU 6 ; Number of refreshes RGB LED should blink for after detonation.
num_bricks DCD 0x00000014 ; Number of bricks to start game with.
BRICK_INCREMENT EQU 3 ; Number of bricks to add after each level.
time_left DCD 120 ; Time left in the game.
bomb_placed DCD 0x00000000 ; Has a bomb been placed?
bomb_detonated DCD 0x00000000 ; Has the placed bomb been detonated?
blink_timer DCD 0xFFFFFFFF ; Counter for blinking LED.
bomb_timer DCD 0x00000000 ; Bomb detonation timer.
bomb_radius DCD 0x00000001 ; Bomb blast radius.
bomb_x_pos DCD 0x00000000 ; Placed bomb x-position.
bomb_y_pos DCD 0x00000000 ; Placed bomb y-position.
bomberman_x_pos DCD 0x00000001 ; Bomberman's current x-position.
bomberman_y_pos DCD 0x00000001 ; Bomberman's current y-position.
enemy1_x_pos DCD 0x00000017 ; Enemy #1's current x-position.
enemy1_y_pos DCD 0x00000001 ; Enemy #1's current y-position.
enemy1_killed DCD 0x00000000 ; Is enemy #1 killed?
enemy2_x_pos DCD 0x00000001 ; Enemy #2's current x-position.
enemy2_y_pos DCD 0x0000000B ; Enemy #2's current y-position.
enemy2_killed DCD 0x00000000 ; Is enemy #2 killed?
enemy3_x_pos DCD 0x00000017 ; Enemy #3's current x-position.
enemy3_y_pos DCD 0x0000000B ; Enemy #3's current y-position.
enemy3_killed DCD 0x00000000 ; Is enemy #3 killed?
enemy_slow_moved DCD 0x00000000 ; Did the slow enemies move last frame?
num_enemies DCD 0x00000003 ; Number of enemies. Initialized to 3.
num_lives DCD 0x00000004 ; Number of lives Bomberman has. Initialized to 3.
life_lost_flag DCD 0x00000000 ; Did Bomberman lose a life last frame?
level DCD 0x00000001 ; Current level. Initialized to 1.
score DCD 0x00000000 ; Current score.
game_over DCD 0x00000000 ; Is the game over?
game_active DCD 0x00000000 ; Is the game not paused and currently being played?
keystroke DCD 0x00000000 ; Player's keystroke.
board_clean = "ZZZZZZZZZZZZZZZZZZZZZZZZZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZZZZZZZZZZZZZZZZZZZZZZZZZ",0
board = "ZZZZZZZZZZZZZZZZZZZZZZZZZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZZZZZZZZZZZZZZZZZZZZZZZZZ",0
prev_board = "ZZZZZZZZZZZZZZZZZZZZZZZZZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZ Z Z Z Z Z Z Z Z Z Z Z ZZ ZZZZZZZZZZZZZZZZZZZZZZZZZZ",0
ALIGN
;-------------------------------------------------------;
; @NAME ;
; reset_game ;
; ;
; @DESCRIPTION ;
; Reset game parameters. ;
;-------------------------------------------------------;
reset_game
STMFD sp!, {lr}
LDR a1, =level ; Reset level back to 1.
MOV a2, #1
STR a2, [a1]
LDR a1, =score
MOV a2, #0
STR a2, [a1] ; Reset score back to 0.
LDR a1, =game_over
MOV a2, #0
STR a2, [a1] ; Set game state to active.
LDR a1, =num_bricks
MOV a2, #20
STR a2, [a1] ; Reset initial number of bricks back to 20.
LDR a1, =num_lives
MOV a2, #4
STR a2, [a1] ; Reset number of bomberman lives back to 4.
LDR a1, =blink_timer
MOV a2, #0xFFFFFFFF
STR a2, [a1] ; Reset blink timer to negative value.
LDR a1, =time_left
MOV a2, #120
STR a2, [a1] ; Reset game timer
LDMFD sp!, {lr}
BX lr
;-------------------------------------------------------;
; @NAME ;
; calculate_bonus ;
; ;
; @DESCRIPTION ;
; Calculate bonus points to be awarded after game ends. ;
;-------------------------------------------------------;
calculate_bonus
STMFD sp!, {lr}
LDR a1, =score ; If the game is over, award a 25 bonus for each life remaining.
LDR a2, =num_lives ; Note that if the number of lives left is zero, this does nothing.
LDR a2, [a2] ; a2 = num_lives
MOV a3, #LIFE_REMAINING_BONUS ; a3 = life_remaining_bonus
MUL a4, a2, a3 ; a4 = num_lives * life_remaining_bonus
LDR a3, [a1] ; a3 = score
ADD a3, a3, a4 ; score = score + a4
STR a3, [a1] ; Update the score in memory after awarding the life remaining bonus.
LDMFD sp!, {lr}
BX lr
;-------------------------------------------------------;
; @NAME ;
; initialize_game ;
; ;
; @DESCRIPTION ;
; Initialize the game. Add enemies and generate brick ;
; walls. Reset positions and flags for gameplay ;
;-------------------------------------------------------;
initialize_game
STMFD sp!, {lr, v1}
BL clear_bomb_detonation ; Clear the bomb blast if it exists
BL clear_board ; Clear the board of extra characters
LDR a1, =game_active ; Assert game_active flag.
MOV a2, #1
STR a2, [a1]
MOV a1, #0 ; Reset bomb placement (Let you place a bomb right away)
LDR v1, =bomb_placed
STR a1, [v1]
MOV a1, #3 ; Reset enemy count to 3
LDR v1, =num_enemies
STR a1, [v1]
MOV a1, #0 ; Reset the enemy delay flag
LDR v1, =enemy_slow_moved
STR a1, [v1]
MOV a1, #0 ; Reset the life lost flag
LDR v1, =life_lost_flag
STR a1, [v1]
MOV a1, #BOMBERMAN_X_START
MOV a2, #BOMBERMAN_Y_START
MOV a3, #BOMBERMAN
BL update_pos
LDR v1, =bomberman_x_pos ; Reset bomberman position
STR a1, [v1]
LDR v1, =bomberman_y_pos
STR a2, [v1]
MOV a1, #ENEMY1_X_START
MOV a2, #ENEMY1_Y_START
MOV a3, #ENEMY_SLOW
BL update_pos
LDR v1, =enemy1_x_pos ; Reset enemy1 position
STR a1, [v1]
LDR v1, =enemy1_y_pos
STR a2, [v1]
LDR v1, =enemy1_killed ; Set enemy1 not killed
MOV a1, #0
STR a1, [v1]
MOV a1, #ENEMY2_X_START
MOV a2, #ENEMY2_Y_START
MOV a3, #ENEMY_SLOW
BL update_pos
LDR v1, =enemy2_x_pos ; Reset enemy2 position
STR a1, [v1]
LDR v1, =enemy2_y_pos
STR a2, [v1]
LDR v1, =enemy2_killed ; Set enemy1 not killed
MOV a1, #0
STR a1, [v1]
MOV a1, #ENEMY3_X_START
MOV a2, #ENEMY3_Y_START
MOV a3, #ENEMY_FAST
BL update_pos
LDR v1, =enemy3_x_pos ; Reset enemy3 position
STR a1, [v1]
LDR v1, =enemy3_y_pos
STR a2, [v1]
LDR v1, =enemy3_killed ; Set enemy1 not killed
MOV a1, #0
STR a1, [v1]
BL generate_brick_walls
LDMFD sp!, {lr, v1}
BX lr
;-------------------------------------------------------;
; @NAME ;
; clear_board ;
; ;
; @DESCRIPTION ;
; Cleans the board string of all characters except 'Z' ;
;-------------------------------------------------------;
clear_board
STMFD SP!, {lr}
LDR a1, =board_clean
LDR a2, =board
clear_board_loop
LDRB a3, [a1], #1 ; Load the clean string character
CMP a3, #0 ; Is it null? If so, we're done. Exit loop
BEQ clear_board_exit
STRB a3, [a2], #1 ; Store the clean board character in the dirty board
B clear_board_loop
clear_board_exit
LDMFD SP!, {lr}
BX lr
;-------------------------------------------------------;
; @NAME ;
; update_game ;
; ;
; @DESCRIPTION ;
; Advances games simulation one step. ;
;-------------------------------------------------------;
update_game
STMFD sp!, {lr}
LDR a1, =blink_timer
LDR a2, [a1]
SUB a2, a2, #1
STR a2, [a1] ; Decrement blink timer.
LDR a1, =bomb_detonated
LDR a3, [a1]
CMP a3, #1
BLEQ clear_bomb_detonation ; Remove remnants from bomb blast.
LDR a1, =keystroke
LDR a1, [a1]
LDR a2, =enemy_slow_moved ; Is this an odd frame?
LDR a2, [a2]
CMP a2, #0
BLEQ move_bomberman ; Move bomberman.
LDR a1, =life_lost_flag
LDR a1, [a1]
CMP a1, #1
BEQ update_game_exit
BL move_enemies ; Move all enemies
LDR a1, =keystroke
LDR a1, [a1]
CMP a1, #PLACE_BOMB_KEY
BLEQ place_bomb ; Place bomb if keystroke is 'x'
; and a bomb is not already placed.
LDR a1, =bomb_timer
LDR a1, [a1]
LDR a2, =bomb_placed ; Is the bomb placed and has it timed out?
LDR a2, [a2] ; If so, detonate it.
CMP a2, #1
MOVEQ a2, #BOMB_TIMEOUT
CMP a1, a2
BLEQ detonate_bomb
LDR a1, =bomb_timer
LDR a2, [a1]
ADD a2, a2, #1
STR a2, [a1] ; Increment bomb timer.
update_game_exit
LDR a1, =enemy_slow_moved
LDR a1, [a1]
CMP a1, #1
LDREQ v1, =keystroke
MOVEQ a1, #0 ; Reset keystroke.
STREQ a1, [v1]
LDMFD sp!, {lr}
BX lr
;-------------------------------------------------------;
; @NAME ;
; detonate_bomb ;
; ;
; @DESCRIPTION ;
; Detonate the placed bomb. ;
;-------------------------------------------------------;
detonate_bomb
STMFD sp!, {lr, v1-v8}
LDR a1, =blink_timer
MOV a2, #BLINK_REFRESHES ; Number of refreshes RGB LED indicating an explosion should blink for.
LDR a3, =bomb_placed
LDR a3, [a3]
CMP a3, #1
STREQ a2, [a1]
LDR a1, =bomb_placed
LDR a1, [a1]
CMP a1, #0
BEQ detonate_bomb_exit ; Is a bomb placed? If not, exit.
LDR a1, =bomb_detonated
MOV a2, #1
STR a2, [a1] ; Assert bomb detonated flag.
LDR a1, =bomb_placed
MOV a2, #0
STR a2, [a1] ; De-assert bomb placed flag.
LDR a1, =bomb_x_pos
LDR a1, [a1]
MOV v1, a1
LDR a2, =bomb_y_pos
LDR a2, [a2]
MOV v2, a2
MOV v3, #-1 ; Check if bomberman is in same position as the bomb that is detonating.
MOV v4, #-2 ; If so, kill bomberman.
LDR a1, =bomberman_x_pos
LDR a1, [a1]
LDR a2, =bomberman_y_pos
LDR a2, [a2]
LDR a3, =bomb_x_pos
LDR a3, [a3]
LDR a4, =bomb_y_pos
LDR a4, [a4]
CMP a1, a3 ; Do X-positions match?
MOVEQ v3, #1
CMP a2, a4 ; Do Y-positions match?
MOVEQ v4, #1
CMP v3, v4
BLEQ kill_bomberman ; Do both X-positions AND Y-positions match? If so, kill bomberman.
SUB v3, v1, #BLAST_X_RADIUS ; Lower bound x-position for blast.
ADD v4, v1, #BLAST_X_RADIUS ; Upper bound x-position for blast.
SUB v5, v2, #BLAST_Y_RADIUS ; Lower bound y-position for blast.
ADD v6, v2, #BLAST_Y_RADIUS ; Upper bound y-position for blast.
MOV v8, #0 ; Keep track of number of bricks destroyed.
;-------------------------------------------------------;
; Destroy everything to the left of the placed bomb. ;
; i.e. ----o ;
;-------------------------------------------------------;
detonate_bomb_west
MOV v7, v1 ; Initialize X-detonation loop counter.
detonate_bomb_west_loop
; Add '-' and '|' characters, making sure
; to not blow up any indestructible stuff. Also need to
; check if the blast kills an enemy or bomberman.
MOV a1, v7 ; Current X-position (decremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BOMBERMAN ; Is it bomberman? If so, call kill_bomberman.
BLEQ kill_bomberman
MOV a1, v7 ; Current X-position (decremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BARRIER ; Is it a barrier? If so, break out of loop.
BEQ detonate_bomb_east
MOV a1, v7 ; Current X-position (decremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BRICK_WALL ; Is it a brick wall? If so, increment brick wall destroyed counter.
ADDEQ v8, v8, #1
MOV a1, v7 ; Current X-position (decremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #ENEMY_SLOW ; Is it a slow enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v7 ; Current X-position (decremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #ENEMY_FAST ; Is it a fast enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v7 ; Current X-position (decremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BOMB ; Is it a bomb? If so, do nothing.
BEQ detonate_bomb_west_next
MOV a1, v7
MOV a2, v2
MOV a3, #BLAST_HORIZONTAL
BL update_pos ; Otherwise, draw a '-'. (this is the default case of our "switch statement").
detonate_bomb_west_next
SUB v7, v7, #1 ; Decrement X-position.
CMP v7, v3
BGE detonate_bomb_west_loop
;-------------------------------------------------------;
; Destroy everything to the right of the placed bomb. ;
; i.e. o---- ;
;-------------------------------------------------------;
detonate_bomb_east
MOV v7, v1 ; Initialize X-detonation loop counter.
detonate_bomb_east_loop
; Add '-' and '|' characters, making sure
; to not blow up any indestructible stuff. Also need to
; check if the blast kills an enemy or bomberman.
MOV a1, v7 ; Current X-position (incremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BOMBERMAN ; Is it bomberman? If so, call kill_bomberman.
BLEQ kill_bomberman
MOV a1, v7 ; Current X-position (incremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BARRIER ; Is it a barrier? If so, break out of loop.
BEQ detonate_bomb_south
MOV a1, v7 ; Current X-position (decremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BRICK_WALL ; Is it a brick wall? If so, increment brick wall destroyed counter.
ADDEQ v8, v8, #1
MOV a1, v7 ; Current X-position (incremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #ENEMY_SLOW ; Is it a slow enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v7 ; Current X-position (incremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #ENEMY_FAST ; Is it a fast enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v7 ; Current X-position (incremented after each loop iteration).
MOV a2, v2 ; Y-position (fixed).
BL check_pos_char
CMP a1, #BOMB ; Is it a bomb? If so, do nothing.
BEQ detonate_bomb_east_next
MOV a1, v7
MOV a2, v2
MOV a3, #BLAST_HORIZONTAL
BL update_pos ; Otherwise, draw a '-'. (this is the default case of our "switch statement").
detonate_bomb_east_next
ADD v7, v7, #1 ; Increment X-position.
CMP v7, v4
BLE detonate_bomb_east_loop
;-------------------------------------------------------;
; Destroy everything below the placed bomb. ;
;-------------------------------------------------------;
detonate_bomb_south
MOV v7, v2 ; Initialize Y-detonation loop counter.
detonate_bomb_south_loop
; Add '-' and '|' characters, making sure
; to not blow up any indestructible stuff. Also need to
; check if the blast kills an enemy or bomberman.
MOV a1, v1 ; X-position (fixed).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BOMBERMAN ; Is it bomberman? If so, call kill_bomberman.
BLEQ kill_bomberman
MOV a1, v1 ; Current X-position (fixed).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BARRIER ; Is it a barrier? If so, break out of loop.
BEQ detonate_bomb_north
MOV a1, v1 ; Current X-position (fixed).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BRICK_WALL ; Is it a brick wall? If so, increment brick wall destroyed counter.
ADDEQ v8, v8, #1
MOV a1, v1 ; Current X-position (incremented after each loop iteration).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
MOV a2, v1
MOV a3, v2
CMP a1, #ENEMY_SLOW ; Is it a slow enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v1 ; Current X-position (incremented after each loop iteration).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #ENEMY_FAST ; Is it a fast enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v1 ; Current X-position (incremented after each loop iteration).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BOMB ; Is it a bomb? If so, do nothing.
BEQ detonate_bomb_south_next
MOV a1, v1
MOV a2, v7
MOV a3, #BLAST_VERTICAL
BL update_pos ; Otherwise, draw a '-'. (this is the default case of our "switch statement").
detonate_bomb_south_next
ADD v7, v7, #1 ; Increment Y-position.
CMP v7, v6
BLE detonate_bomb_south_loop
;-------------------------------------------------------;
; Destroy everything above the placed bomb. ;
;-------------------------------------------------------;
detonate_bomb_north
MOV v7, v2 ; Initialize Y-detonation loop counter.
detonate_bomb_north_loop
; Add '-' and '|' characters, making sure
; to not blow up any indestructible stuff. Also need to
; check if the blast kills an enemy or bomberman.
MOV a1, v1 ; X-position (fixed).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BOMBERMAN ; Is it bomberman? If so, call kill_bomberman.
BLEQ kill_bomberman
MOV a1, v1 ; Current X-position (incremented after each loop iteration).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BARRIER ; Is it a barrier? If so, break out of loop.
BEQ detonate_bomb_north_exit
MOV a1, v1 ; Current X-position (fixed).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BRICK_WALL ; Is it a brick wall? If so, increment brick wall destroyed counter.
ADDEQ v8, v8, #1
MOV a1, v1 ; Current X-position (incremented after each loop iteration).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #ENEMY_SLOW ; Is it a slow enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v1 ; Current X-position (incremented after each loop iteration).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #ENEMY_FAST ; Is it a fast enemy? If so, call kill_enemy.
BLEQ kill_enemy
MOV a1, v1 ; Current X-position (incremented after each loop iteration).
MOV a2, v7 ; Y-position (incremented after each loop iteration).
BL check_pos_char
CMP a1, #BOMB ; Is it a bomb? If so, do nothing.
BEQ detonate_bomb_north_next
MOV a1, v1
MOV a2, v7
MOV a3, #BLAST_VERTICAL
BL update_pos ; Otherwise, draw a '-'. (this is the default case of our "switch statement").
detonate_bomb_north_next
SUB v7, v7, #1 ; Decrement Y-position.
CMP v7, v5
BGE detonate_bomb_north_loop
detonate_bomb_north_exit
LDR a1, =bomb_x_pos
LDR a1, [a1]
LDR a2, =bomb_y_pos
LDR a2, [a2]
MOV a3, #BOMB_EXPLODED
BL update_pos
LDR a1, =score ; Update score.
LDR a2, [a1] ; score += Number of bricks destroyed * current level.
LDR a3, =level
LDR a3, [a3]
MUL a4, v8, a3
ADD a2, a2, a4
STR a2, [a1]
detonate_bomb_exit
LDMFD sp!, {lr, v1-v8}
BX lr
;-------------------------------------------------------;
; @NAME ;
; kill_enemy ;
; ;
; @DESCRIPTION ;
; Kill the specified enemy. Enemy X-cord passed in a2. ;
; Enemy Y-cord passed in a3. No return. ;
;-------------------------------------------------------;
kill_enemy
STMFD sp!, {lr, v1-v8}
LDR a1, =bomb_x_pos
LDR a1, [a1]
LDR a2, =bomb_y_pos
LDR a2, [a2]
MOV a1, v1
MOV a2, v1
SUB v3, v1, #BLAST_X_RADIUS ; Lower bound x-position for blast.
ADD v4, v1, #BLAST_X_RADIUS ; Upper bound x-position for blast.
SUB v5, v2, #BLAST_Y_RADIUS ; Lower bound y-position for blast.
ADD v6, v2, #BLAST_Y_RADIUS ; Upper bound y-position for blast.
kill_enemy1
LDR a1, =enemy1_killed
LDR a1, [a1]
CMP a1, #1
BEQ kill_enemy2 ; Is enemy already dead? If so, skip check.
LDR a1, =enemy1_x_pos
LDR a1, [a1]
LDR a2, =enemy1_y_pos
LDR a2, [a2]
MOV v1, #-1 ; Initialize variables for pairwise comparison.
MOV v2, #-2
MOV v7, #-3
MOV v8, #-4
CMP a1, v3 ; Check if enemy is within x-range of blast.
MOVGE v1, #1
CMP a1, v4
MOVLE v2, #1
CMP v1, v2
MOVEQ v7, #1
MOV v1, #-1 ; Re-initialize variables to non equal values for pairwise comparison.
MOV v2, #-2
CMP a2, v5 ; Check if enemy is within y-range of blast.
MOVGE v1, #1
CMP a2, v6
MOVLE v2, #1
CMP v1, v2
MOVEQ v8, #1
CMP v7, v8 ; If enemy is within x-range and y-range, we have a hit.
BNE kill_enemy2
LDR a1, =enemy1_killed ; Kill enemy #1
MOV a2, #1
STR a2, [a1]
LDR a1, =level
LDR a1, [a1]
LDR a2, =score
LDR a3, [a2]
MOV v1, #ENEMY_MULTIPLIER
MUL a4, a1, v1
ADD a3, a3, a4 ; Update total score.
STR a3, [a2] ; score += (level_number * 10)
LDR a1, =enemy1_x_pos
LDR a2, =enemy1_y_pos
MOV a3, #-100
STR a3, [a1]
STR a3, [a2] ; Move enemy off board.
LDR a1, =num_enemies ; Decrement enemy count.
LDR a2, [a1]
SUB a2, a2, #1
CMP a2, #0 ; Is there no enemies left? If so, go to the next level.
BEQ kill_enemy_exit_level_up
STR a2, [a1]
kill_enemy2
LDR a1, =enemy2_killed
LDR a1, [a1]
CMP a1, #1
BEQ kill_enemy3 ; Is enemy already dead? If so, skip check.
LDR a1, =enemy2_x_pos
LDR a1, [a1]
LDR a2, =enemy2_y_pos
LDR a2, [a2]
MOV v1, #-1 ; Initialize variables for pairwise comparison.
MOV v2, #-2
MOV v7, #-3
MOV v8, #-4
CMP a1, v3 ; Check if enemy is within x-range of blast.
MOVGE v1, #1
CMP a1, v4
MOVLE v2, #1
CMP v1, v2
MOVEQ v7, #1
MOV v1, #-1
MOV v2, #-2
CMP a2, v5 ; Check if enemy is within y-range of blast.
MOVGE v1, #1
CMP a2, v6
MOVLE v2, #1 ; Re-initialize variables to non equal values for pairwise comparison.
CMP v1, v2
MOVEQ v8, #1
CMP v7, v8 ; If enemy is within x-range and y-range, we have a hit.
BNE kill_enemy3
LDR a1, =enemy2_killed ; Kill enemy #2.
MOV a2, #1
STR a2, [a1]
LDR a1, =level
LDR a1, [a1]
LDR a2, =score
LDR a3, [a2]
MOV v1, #ENEMY_MULTIPLIER
MUL a4, a1, v1
ADD a3, a3, a4 ; Update total score.
STR a3, [a2] ; score += (level_number * 10)
LDR a1, =enemy2_x_pos
LDR a2, =enemy2_y_pos
MOV a3, #-100
STR a3, [a1]
STR a3, [a2] ; Move enemy off board.
LDR a1, =num_enemies ; Decrement enemy count.
LDR a2, [a1]
SUB a2, a2, #1
CMP a2, #0 ; Is there no enemies left? If so, go to the next level.
BEQ kill_enemy_exit_level_up
STR a2, [a1]
kill_enemy3
LDR a1, =enemy3_killed
LDR a1, [a1]
CMP a1, #1
BEQ kill_enemy_exit ; Is enemy already dead? If so, skip check.
LDR a1, =enemy3_x_pos
LDR a1, [a1]
LDR a2, =enemy3_y_pos
LDR a2, [a2]
MOV v1, #-1 ; Initialize variables for pairwise comparison.
MOV v2, #-2
MOV v7, #-3
MOV v8, #-4
CMP a1, v3 ; Check if enemy is within x-range of blast.
MOVGE v1, #1
CMP a1, v4
MOVLE v2, #1
CMP v1, v2
MOVEQ v7, #1
MOV v1, #-1 ; Re-initialize variables to non equal values for pairwise comparison.
MOV v2, #-2
CMP a2, v5 ; Check if enemy is within y-range of blast.
MOVGE v1, #1
CMP a2, v6
MOVLE v2, #1
CMP v1, v2
MOVEQ v8, #1
CMP v7, v8 ; If enemy is within x-range and y-range, we have a hit.
BNE kill_enemy_exit
LDR a1, =enemy3_killed ; Kill enemy #3.
MOV a2, #1
STR a2, [a1]
LDR a1, =level
LDR a1, [a1]
LDR a2, =score
LDR a3, [a2]
MOV v1, #ENEMY_MULTIPLIER
MUL a4, a1, v1
ADD a3, a3, a4 ; Update total score.
STR a3, [a2] ; score += (level_number * 10)
LDR a1, =enemy3_x_pos
LDR a2, =enemy3_y_pos
MOV a3, #-100
STR a3, [a1]
STR a3, [a2] ; Move enemy off board.
LDR a1, =num_enemies ; Decrement enemy count.
LDR a2, [a1]
SUB a2, a2, #1
CMP a2, #0 ; Is there no enemies left? If so, go to the next level.
BEQ kill_enemy_exit_level_up
STR a2, [a1]
kill_enemy_exit
LDMFD sp!, {lr, v1-v8}
BX lr
kill_enemy_exit_level_up
LDMFD sp!, {lr, v1-v8}
B level_up
;-------------------------------------------------------;
; @NAME ;
; level_up ;
; ;
; @DESCRIPTION ;
; Re-initialize board and increase game diffulculty by ;
; increasing speed ;
;-------------------------------------------------------;
level_up
BL clear_bomb_detonation
LDR a1, =bomberman_x_pos
LDR a1, [a1]
LDR a2, =bomberman_y_pos
LDR a2, [a2]
MOV a3, #FREE
BL update_pos
LDR a1, =level
LDR a2, [a1]
ADD a2, a2, #1
STR a2, [a1]
CMP a2, #MAX_LEVEL
BGT begin_next_level
increase_speed
LDR a1, =T0MR0
LDR a2, [a1]
;LSR a2, a2, #1
SUB a2, a2, #0xE1000 ; Decrease timer period by 0.1s
STR a2, [a1] ; Increse the speed of the game.
begin_next_level
LDR a1, =score
LDR a2, [a1]
ADD a2, a2, #LEVEL_CLEARED_BONUS ; Update total score.
STR a2, [a1] ; score += LEVEL_CLEARED_BONUS
LDR a1, =num_bricks
LDR a2, [a1]
ADD a2, a2, #BRICK_INCREMENT
STR a2, [a1]
BL initialize_game
B game_loop
;-------------------------------------------------------;
; @NAME ;
; clear_bomb_detonation ;
; ;
; @DESCRIPTION ;
; Detonate the placed bomb. ;
;-------------------------------------------------------;
clear_bomb_detonation
STMFD sp!, {lr, v1-v8}
LDR a1, =bomb_detonated
LDR a2, [a1]
CMP a2, #0
BEQ clear_bomb_detonation_exit ; Has the bomb detonated? If not, exit.
MOV a2, #0
STR a2, [a1] ; De-assert bomb detonated flag.
LDR a1, =bomb_x_pos
LDR a1, [a1]
MOV v1, a1
LDR a2, =bomb_y_pos
LDR a2, [a2]
MOV v2, a2
SUB v3, v1, #BLAST_X_RADIUS ; Lower bound x-position for blast.
CMP v3, #0
MOVLT v3, #0
ADD v4, v1, #BLAST_X_RADIUS ; Upper bound x-position for blast.
CMP v4, #0
MOVLT v4, #0
SUB v5, v2, #BLAST_Y_RADIUS ; Lower bound y-position for blast.
CMP v5, #0
MOVLT v5, #0
ADD v6, v2, #BLAST_Y_RADIUS ; Upper bound y-position for blast.
CMP v6, #0
MOVLT v6, #0
clear_bomb_detonation_west
MOV v7, v1
clear_bomb_detonation_west_loop
MOV a1, v7
MOV a2, v2
BL check_pos_char
CMP a1, #BARRIER
BEQ clear_bomb_detonation_east
MOV a1, v7
MOV a2, v2
MOV a3, #FREE
BL update_pos
ADD v7, v7, #1
CMP v7, v4
BLE clear_bomb_detonation_west_loop
clear_bomb_detonation_east