-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab7.s
3170 lines (3016 loc) · 78 KB
/
lab7.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 interrupts, CODE, READWRITE
EXPORT lab7
EXPORT FIQ_Handler
EXTERN pin_connect_block_setup_for_uart0
EXTERN uart_init
EXTERN read_character
EXTERN output_character
EXTERN read_string
EXTERN output_string
EXTERN div_and_mod
EXTERN illuminateLEDs
EXTERN illuminate_RGB_LED
EXTERN display_digit_on_7_seg
GAME_BOARD = " SCORE 000",10,10,10,13,\
" _____",10,13," ////Q/|",10,13,\
" /____/ |____",10,13," | | /////|",10,13,\
" |____|/___/ |____",10,13," /////| | //////|",\
10,13," /___/ |___|/____/ |_____",10,13," | | /////",\
"| | //////|",10,13," |___|/___/ |____|/____/ |____",10,13,\
" /////| | //////| | /////|",10,13," /___/ |___|/",\
"____/ |____|/___/ |____",10,13," | | /////| | //////|",\
" | /////|",10,13," |___|/___/ |____|/____/ |___|/___/ |",10,13,\
" /////| | //////| | /////| | /",10,13," /___/ |___|/",\
"____/ |____|/___/ |____|/",10,13," | | /////| |//////| | /",\
10,13," |____|/___/ |____/____/ |____|/",10,13," //////| | ///",\
"//| | /",10,13," /____/ |____|/___/ |____|/",10,13," | | /////",\
"| | /",10,13," |____|/___/ |____|/",10,13," //////| | /",10,13,\
"/____/ |____|/",10,13,"| | /",10,13,"|____|/",10,13,0
INTRO = " Welcome to ARM QBERT",10,10,10,13,"Instructions:",10,13,\
"Qbert is represented by a Q, balls are represented by a O, ",10,13,\
"the snake ball is a C, and the snake is an S.",10,10,13,\
"Use the w, a, s, d keys to move up, left, down, and right ",10,13,\
"respectively.",10,10,13,\
"Qbert starts the game with four lives. Getting hit by a ",10,13,\
"ball, or snake removes a life. Jumping off the side of the ",10,13,\
"pyramid also costs one one life.",10,10,13,\
"Unexplored squares are shaded with ////. Explore all squares",10,13,\
"to advance to the next level.",10,10,13,\
"The game is over after 2 minutes, or all four lives have ",10,13,\
"been lost.",10,10,13,\
"Press the space bar at anytime to exit the game.",10,10,13,\
"Press the ARM push button at anytime to pause the game.",10,13,\
"No inputs will be accepted until the game is unpaused by ",10,13,\
"pushing the ARM push button again.",10,10,13,\
"Press g at anytime to start a new game.",10,10,13,\
"Press g now to start...",10,13,0
GAME_OVER = " Game Over Score: 000",10,10,10,10,13,\
" Press g to play again",10,13,\
" Press space bar to exit",0
TEST_TIMER1 = " timer 1 ",10,13,0
ALIGN
Q_X_POSITION DCD 15 ; Starting x=15
Q_Y_POSITION DCD 5 ; Starting y=5
Q_DIRECTION DCD 0 ;0=none, 1=up, 2=left, 3=down, 4=right
Q_SQUARE DCD 1
BALL1_X_POSITION DCD 0
BALL1_Y_POSITION DCD 0
BALL1_DIRECTION DCD 0
BALL1_SQUARE DCD 0
BALL2_X_POSITION DCD 0
BALL2_Y_POSITION DCD 0
BALL2_DIRECTION DCD 0
BALL2_SQUARE DCD 0
SNAKEBALL_X_POSITION DCD 0
SNAKEBALL_Y_POSITION DCD 0
SNAKEBALL_DIRECTION DCD 0
SNAKEBALL_SQUARE DCD 0
SNAKE_X_POSITION DCD 0
SNAKE_Y_POSITION DCD 0
SNAKE_DIRECTION DCD 0
SNAKE_SQUARE DCD 0
LEVEL DCD 1
LIVES DCD 4
SQUARE
DCD 0 ; 0
DCD 0 ; 1
DCD 0 ; 2
DCD 0 ; 3
DCD 0 ; 4
DCD 0 ; 5
DCD 0 ; 6
DCD 0 ; 7
DCD 0 ; 8
DCD 0 ; 9
DCD 0 ; 10
DCD 0 ; 11
DCD 0 ; 12
DCD 0 ; 13
DCD 0 ; 14
DCD 0 ; 15
DCD 0 ; 16
DCD 0 ; 17
DCD 0 ; 18
DCD 0 ; 29
DCD 0 ; 20
DCD 0 ; 21
SCORE DCD 0
BLINK DCD 0
Q_MOVES DCD 1
INC_TIMER_FLAG DCD 0 ; 0=up to date, 1=needs to be updated
NUM_BALLS DCD 0
NUM_HALF_SECS DCD 0
IS_PAUSED DCD 0 ; 0=running, 1=paused
BALL1_FELL_OFF DCD 0 ; Set if falls off
BALL2_FELL_OFF DCD 0 ; Set if falls off
SNAKEBALL_FELL_OFF DCD 0 ; Set if falls off
IS_GAMEOVER_SCREEN DCD 0 ; Set when at game over screen
DISPLAY_CURSE DCD 0
Q_RECENTLY_HIT = 0 ; Set when Q has been hit
ALIGN
lab7
STMFD sp!, {lr}
;;;;;; TODO hide cursor????
BL uart_init
BL pin_connect_block_setup_for_uart0
BL interrupt_init
MOV r2, #0x0C ; ASCII 0x0C is for new page
BL output_character ; Clear the screen
; Seven-seg starts with a 0
MOV r4, #0
BL display_digit_on_7_seg
; RGB LED starts as white
MOV r4, #5
BL illuminate_RGB_LED ; Set RGB LCD to white
; Display intro/instructions
LDR r3, =INTRO
BL output_string
; Loop at intro screen until player starts a new game or quits
endlessLoop
ADD r0, r0, #0 ; NOP
B endlessLoop
newGame
STMFD SP!, {r0-r5, r9, lr} ; Save registers
MOV r2, #0x0C ; ASCII 0x0C is for new page
BL output_character ; Clear the screen
; is no longer at the game over screen
LDR r0, =IS_GAMEOVER_SCREEN ; clear variable
MOV r1, #0
STRB r1, [r0]
; set ball 1 and 2, snakeball and snake to no square
LDR r0, =BALL1_SQUARE
MOV r1, #0
STR r1, [r0]
; set ball2 to no square
LDR r0, =BALL2_SQUARE
STR r1, [r0]
; set snakeball to no square
LDR r0, =SNAKEBALL_SQUARE
STR r1, [r0]
; set snake to no square
LDR r0, =SNAKE_SQUARE
STR r1, [r0]
; Do not continue to blink after a new game is started
LDR r0, =BLINK
MOV r1, #0
STR r1, [r0]
; Reset 2s spawn timer to 0
LDR r4, =NUM_HALF_SECS
MOV r5, #0
STR r5, [r4]
; Reset SCORE to 0
LDR r4, =SCORE
MOV r5, #0
STR r5, [r4]
; Reset NUM_BALLS to 0
LDR r4, =NUM_BALLS
MOV r5, #0
STR r5, [r4]
; Reset all SQUAREs to 0
BL resetAllSquares
; Reset LEVEL to 1
LDR r4, =LEVEL
MOV r5, #1
STR r5, [r4]
; Reset LIVES to 4
LDR r4, =LIVES ; Set the LIVES to 4
MOV r5, #4
STR r5, [r4]
MOV r4, #1
BL display_digit_on_7_seg ; Display current level (1)
MOV r4, #1
BL illuminate_RGB_LED ; Set RGB LCD to green when game running
; turn all four leds on
MOV r4, #0x00
BL illuminateLEDs ; Set all 4 LCDs to on
; Reset Q to starting position
LDR r4, =Q_X_POSITION
MOV r5, #15
STR r5, [r4] ; store new xPos
LDR r4, =Q_Y_POSITION
MOV r5, #5
STR r5, [r4] ; store new yPos
; Reset Q_DIRECTION to 0 = none
LDR r4, =Q_DIRECTION
MOV r5, #0
STR r5, [r4] ; store new direction
; Display the game board
LDR r3, =GAME_BOARD
BL output_string
; Enable timer0
LDR r2, =0xE000401C ; Address of Match Register 0 (MR0)
;LDR r0, =36864000 ; timeout period of the timer (2s)
;LDR r0, =18432000 ; timeout period of the timer (1s)
LDR r0, =9216000 ; timeout period of the timer (0.5s)
;LDR r0, =8755200 ; timeout period of the timer (0.45s)
STR r0, [r2]
LDR r0, =0xE0004004 ; (T0TCR) Timer 0 timer control reg
LDR r1, [r0]
ORR r1, r1, #1 ; set bit 0 to 1 to enable, or 0 to disable
STR r1, [r0]
; Enable timer1
LDR r2, =0xE000801C ; Address of Match Register 1 (MR1)
;LDR r0, =36864000 ; timeout period of the timer (2s)
;LDR r0, =92160000 ; timeout period of the timer (5s)
LDR r0, =2211840000 ; timeout period of the timer (120s)
STR r0, [r2]
LDR r0, =0xE0008004 ; (T1TCR) Timer 1 timer control reg
LDR r1, [r0]
ORR r1, r1, #1 ; set bit 0 to 1 to enable, or 0 to disable
STR r1, [r0]
BL interrupt_init
LDMFD SP!, {r0-r5, r9, lr} ; Restore registers
BX lr
resetAllSquares
STMFD SP!, {r0-r5, lr} ; Save registers
; Reset all SQUAREs to 0
LDR r3, =SQUARE
MOV r5, #0
resetNextSquare
; Clear SQUARE to reset
MOV r2, #0
STR r2, [r3, r5, LSL #2 ]
ADD r5, r5, #1
CMP r5, #22
BLT resetNextSquare
LDMFD SP!, {r0-r5, lr} ; Restore registers
BX lr
;;;;; TODO PURPLE AT GAME OVER
gameOver
STMFD SP!, {r0-r3, lr} ; Save registers
MOV r2, #0x0C ; ASCII 0x0C is for new page
BL output_character ; Clear the screen
; Display Game Over screen
LDR r3, =GAME_OVER
BL output_string
; Update score += lives left * 25
LDR r0, =LIVES
LDR r1, [r0]
MOV r2, #25
MUL r2, r1, r2
LDR r0, =SCORE
LDR r1, [r0]
ADD r1, r2, r1
STR r1, [r0]
BL updateScore
;BL interrupt_init
; Disable timer0
LDR r0, =0xE0004004 ; (T0TCR) Timer 0 timer control reg
LDR r1, [r0]
AND r1, r1, #0 ; set bit 0 to 1 to enable, or 0 to disable
STRB r1, [r0]
; Disable timer1
LDR r0, =0xE0008004 ; (T1TCR) Timer 1 timer control reg
LDR r1, [r0]
AND r1, r1, #0 ; set bit 0 to 1 to enable, or 0 to disable
STRB r1, [r0]
LDR r0, =IS_GAMEOVER_SCREEN ; set for game over screen
MOV r1, #1
STRB r1, [r0]
LDMFD SP!, {r0-r3, lr} ; Restore registers
BX lr
increaseLevel
STMFD SP!, {r0-r5, lr} ; Save registers
; THIS DOESNT WORK
; pause the game while increaseing the level
LDR r0, =IS_GAMEOVER_SCREEN
MOV r1, #1
STRB r1, [r0]
; Increase level by one and update 7-seg display
LDR r0, =LEVEL
LDR r4, [r0]
ADD r4, r4, #1
STR r4, [r0]
BL display_digit_on_7_seg ; Display current level (takes arg in r4)
; Update score +100
LDR r3, =SCORE
LDR r2, [r3]
ADD r2, r2, #100 ; Player gets 100 points for completing a level
STR r2, [r3]
; Reset Q to starting position
LDR r4, =Q_X_POSITION
MOV r5, #15
STR r5, [r4] ; store new xPos
LDR r4, =Q_Y_POSITION
MOV r5, #5
STR r5, [r4] ; store new yPos
; Reset Q_DIRECTION to 0 = none
LDR r4, =Q_DIRECTION
MOV r5, #0
STR r5, [r4] ; store new direction
; set ball1 to no square
LDR r0, =BALL1_SQUARE
MOV r1, #0
STR r1, [r0]
; set ball2 to no square
LDR r0, =BALL2_SQUARE
STR r1, [r0]
; Display the game board
MOV r2, #0x0C ; ASCII 0x0C is for new page
BL output_character ; Clear the screen
LDR r3, =GAME_BOARD
BL output_string
; Set flag to increase speed
LDR r4, =INC_TIMER_FLAG
MOV r5, #1
STR r5, [r4]
; TODO clear balls and snakes and rest spawns
; Reset 2s spawn timer to 0
LDR r4, =NUM_HALF_SECS
MOV r5, #0
STR r5, [r4]
; Number of balls -= 1
LDR r4, =NUM_BALLS
LDR r5, [r4]
SUB r5, r5, #1
STR r5, [r4]
; Reset all SQUAREs to 0
BL resetAllSquares
; THIS DOESNT WORK
; unpause the game after increasing level
LDR r0, =IS_GAMEOVER_SCREEN
MOV r1, #0
STRB r1, [r0]
LDMFD SP!, {r0-r5, lr} ; Restore registers
BX lr
removeQ
STMFD SP!, {r0-r5, lr} ; Save registers
LDR r4, =Q_X_POSITION
LDR r5, =Q_Y_POSITION
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r1, #10 ; divisor
LDR r0, [r5] ; dividend
BL div_and_mod
MOV r2, r0 ; quotient = xPos tens digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, r1 ; remiander = xPos ones digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, #0x3B ; ;
BL output_character
MOV r1, #10 ; divisor
LDR r0, [r4] ; dividend
BL div_and_mod
MOV r2, r0 ; quotient = yPos tens digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, r1 ; remiander = yPos ones digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, #0x66 ; f
BL output_character
MOV r2, #0x20 ; space
BL output_character
BL interrupt_init
LDMFD SP!, {r0-r5, lr} ; Restore registers
BX lr ; Return
redrawQ
STMFD SP!, {r0-r8, lr} ; Save registers
LDR r3, =Q_DIRECTION
LDR r8, [r3]
LDR r4, =Q_X_POSITION
LDR r6, [r4]
LDR r5, =Q_Y_POSITION
LDR r7, [r5]
CMP r8, #0 ; direction = none
BEQ savePosition
CMP r8, #1 ; direction = up
ADDEQ r6, r6, #2 ; new x = x+2
SUBEQ r7, r7, #4 ; new y = y-4
BEQ savePosition
CMP r8, #2 ; direction = left
SUBEQ r6, r6, #5 ; new x = x-5
SUBEQ r7, r7, #2 ; new y = y-2
BEQ savePosition
CMP r8, #3 ; direction = down
SUBEQ r6, r6, #2 ; new x = x-2
ADDEQ r7, r7, #4 ; new y = y+4
BEQ savePosition
CMP r8, #4 ; direction = right
ADDEQ r6, r6, #5 ; new x = x+5
ADDEQ r7, r7, #2 ; new y = y+2
savePosition
STR r6, [r4] ; store new xPos
STR r7, [r5] ; store new yPos
; draw a Q
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r1, #10 ; divisor
MOV r0, r7 ; dividend
BL div_and_mod
MOV r2, r0 ; quotient = xPos tens digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, r1 ; remiander = xPos ones digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, #0x3B ; ;
BL output_character
MOV r1, #10 ; divisor
MOV r0, r6 ; dividend
BL div_and_mod
MOV r2, r0 ; quotient = yPos tens digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, r1 ; remiander = yPos ones digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, #0x66 ; f
BL output_character
MOV r2, #0x51 ; Q
BL output_character
LDR r0, =Q_X_POSITION
LDR r2, =Q_SQUARE
BL updateSquare
; Only clear the square if player has lives left
; this is to prevent spaces in game over screen
LDR r3, =LIVES
LDR r4, [r3]
CMP r4, #0
BLNE clearSquare
; Check if all spaces cleared to see if player reached next level
LDR r3, =SQUARE
MOV r5, #1 ;2
nextSquare
LDR r4, [r3, r5, LSL #2]
CMP r4, #0 ; 0 if not cleared
BEQ notClear
ADD r5, r5, #1
CMP r5, #22
BLT nextSquare
BL increaseLevel
notClear
BL interrupt_init
LDMFD SP!, {r0-r8, lr} ; Restore registers
BX lr ; Return
;r0=objects x position
;r2=objects square
updateSquare
STMFD SP!, {r5, lr} ; Save registers
LDR r5, [r0]
CMP r5, #15
MOVEQ r1, #1
BEQ doneSquare
CMP r5, #13
MOVEQ r1, #2
BEQ doneSquare
CMP r5, #20
MOVEQ r1, #3
BEQ doneSquare
CMP r5, #11
MOVEQ r1, #4
BEQ doneSquare
CMP r5, #18
MOVEQ r1, #5
BEQ doneSquare
CMP r5, #25
MOVEQ r1, #6
BEQ doneSquare
CMP r5, #9
MOVEQ r1, #7
BEQ doneSquare
CMP r5, #16
MOVEQ r1, #8
BEQ doneSquare
CMP r5, #23
MOVEQ r1, #9
BEQ doneSquare
CMP r5, #30
MOVEQ r1, #10
BEQ doneSquare
CMP r5, #7
MOVEQ r1, #11
BEQ doneSquare
CMP r5, #14
MOVEQ r1, #12
BEQ doneSquare
CMP r5, #21
MOVEQ r1, #13
BEQ doneSquare
CMP r5, #28
MOVEQ r1, #14
BEQ doneSquare
CMP r5, #35
MOVEQ r1, #15
BEQ doneSquare
CMP r5, #5
MOVEQ r1, #16
BEQ doneSquare
CMP r5, #12
MOVEQ r1, #17
BEQ doneSquare
CMP r5, #19
MOVEQ r1, #18
BEQ doneSquare
CMP r5, #26
MOVEQ r1, #19
BEQ doneSquare
CMP r5, #33
MOVEQ r1, #20
BEQ doneSquare
CMP r5, #40
MOVEQ r1, #21
BEQ doneSquare
BL fallOff ; Q/enemy is off pyramid if not on a square
B offSquare
doneSquare
STR r1, [r2] ; Store the new square
offSquare
LDMFD SP!, {r5, lr} ; Restore registers
BX lr
;r0=objects x position
;r2=objects square
fallOff
STMFD SP!, {r4-r5, lr} ; Save registers
; Check if Q, or ball fell off pyramid
LDR r1, =Q_X_POSITION
CMP r0, r1
BEQ qFell
LDR r1, =SNAKEBALL_X_POSITION
CMP r0, r1
BEQ snakeBallFell
LDR r1, =BALL2_X_POSITION
CMP r0, r1
BEQ ball2Fell
LDR r4, =BALL1_FELL_OFF ; set O_FELL_OFF
MOV r5, #1
STR r5, [r4]
BL removeBall1
B oFell
snakeBallFell
LDR r4, =SNAKEBALL_FELL_OFF ; set SANKEBALL_FELL_OFF
MOV r5, #1
STR r5, [r4]
BL removeSnakeBall
B oFell
ball2Fell
LDR r4, =BALL2_FELL_OFF ; set O_FELL_OFF
MOV r5, #1
STR r5, [r4]
BL removeBall2
B oFell
qFell
BL removeQ
; Reset Q to starting position
LDR r4, =Q_X_POSITION
MOV r5, #15
STR r5, [r4] ; store new xPos
LDR r4, =Q_Y_POSITION
MOV r5, #5
STR r5, [r4] ; store new yPos
; Reset Q_DIRECTION to 0 = none
LDR r4, =Q_DIRECTION
MOV r5, #0
STR r5, [r4] ; store new direction
BL removeLife
oFell
LDMFD SP!, {r4-r5, lr} ; Restore registers
BX lr
removeLife
STMFD SP!, {r3-r5, lr} ; Save registers
; Blink RGB LED red 5 times
; Set BLINK to 10 which will be decremented 10 times and
; blink each time
LDR r3, =BLINK
MOV r5, #10
STR r5, [r3] ; store new BLINK
BL blinkOnDeath
; Remove a life
LDR r3, =LIVES
LDR r5, [r3]
SUB r5, #1
STR r5, [r3]
; Update lives LEDs
CMP r5, #3
LDREQ r4, =0x10000 ;turn 3 leds on
CMP r5, #2
LDREQ r4, =0x30000 ;turn 2 leds on
CMP r5, #1
LDREQ r4, =0x70000 ;turn 1 leds on
CMP r5, #0
LDREQ r4, =0xF0000 ;turn 0 leds on
BL illuminateLEDs
CMP r5, #0
BLEQ gameOver
CMP r5, #0
BEQ qDead ; Do not need to update new Q position if game over
BL redrawQ
qDead
LDMFD SP!, {r3-r5, lr} ; Restore registers
BX lr
blinkOnDeath
STMFD SP!, {r0-r5, lr} ; Save registers
LDR r3, =BLINK ; check if BLINK is 0
LDR r5, [r3]
CMP r5, #0
MOVEQ r4, #1 ; Set RGB back to green when zero
BEQ noBlinks ; if BLINK is 0 do not blink
; If BLINK is non-zero check if even or odd
MOV r1, #2 ; divisor
MOV r0, r5 ; dividend
BL div_and_mod
CMP r1, #0 ; even if remainder = 0
MOVEQ r4, #0 ; SET RGB LED to red when even
MOVGT r4, #6 ; Set RGB LED to off when odd
; Decrement BLINK
SUB r5, r5, #1
STR r5, [r3]
noBlinks
BL illuminate_RGB_LED
LDMFD SP!, {r0-r5, lr} ; Restore registers
BX lr
clearSquare
STMFD SP!, {r3-r5, lr} ; Save registers
LDR r3, =Q_SQUARE
LDR r4, [r3]
CMP r4, #1
BLEQ clearLLL
CMP r4, #2
BLEQ clearLL
CMP r4, #3
BLEQ clearLL
CMP r4, #5
BLEQ clearLL
CMP r4, #4
BLEQ clearLR
CMP r4, #7
BLEQ clearLR
CMP r4, #8
BLEQ clearLR
CMP r4, #12
BLEQ clearLR
CMP r4, #15
BLEQ clearLR
CMP r4, #17
BLEQ clearLR
CMP r4, #18
BLEQ clearLR
CMP r4, #20
BLEQ clearLR
CMP r4, #21
BLEQ clearLR
CMP r4, #9
BLEQ clearLLR
CMP r4, #10
BLEQ clearLLR
CMP r4, #11
BLEQ clearLLR
CMP r4, #13
BLEQ clearLLR
CMP r4, #16
BLEQ clearLLR
CMP r4, #19
BLEQ clearLLR
CMP r4, #6
BLEQ clearLLL
CMP r4, #14
BLEQ clearLRR
LDMFD SP!, {r3-r5, lr} ; Restore registers
BX lr
LTORG ; Literal poop too distant
clearLL
STMFD SP!, {r2-r6, lr} ; Save registers
; Check if space is already clear
LDR r3, =SQUARE
LDR r4, =Q_SQUARE
LDR r5, [r4]
MOV r5, r5, LSL #2
LDR r6, [r3, r5]
CMP r6, #0 ; 0 if not cleared
BNE alreadyClrLL
; Move curosr left 3, and write 2 spaces
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x33 ; 3
BL output_character
MOV r2, #0x44 ; D
BL output_character
MOV r2, #0x20 ; space
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Set SQUARE to show its already been cleared
MOV r2, #1
STR r2, [r3, r5]
; Update SCORE
LDR r3, =SCORE
LDR r2, [r3]
ADD r2, r2, #10 ; Player gets 10 point for unexplored square
STR r2, [r3]
alreadyClrLL
LDMFD SP!, {r2-r6, lr} ; Restore registers
BX lr
clearLR
STMFD SP!, {r2-r6, lr} ; Save registers
; Check if space is already clear
LDR r3, =SQUARE
LDR r4, =Q_SQUARE
LDR r5, [r4]
MOV r5, r5, LSL #2
LDR r6, [r3, r5]
CMP r6, #0 ; 0 if not cleared
BNE alreadyClrLR
; Move curosr left 2, and write 1 space
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x32 ; 2
BL output_character
MOV r2, #0x44 ; D
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Move cursor right 1, and write 1 space
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x31 ; 1
BL output_character
MOV r2, #0x43 ; C
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Set SQUARE to show its already been cleared
MOV r2, #1
STR r2, [r3, r5]
; Update SCORE
LDR r3, =SCORE
LDR r2, [r3]
ADD r2, r2, #10 ; Player gets 10 point for unexplored square
STR r2, [r3]
alreadyClrLR
LDMFD SP!, {r2-r6, lr} ; Restore registers
BX lr
clearLLR
STMFD SP!, {r2-r6, lr} ; Save registers
LDR r3, =SQUARE
LDR r4, =Q_SQUARE
LDR r5, [r4]
MOV r5, r5, LSL #2
LDR r6, [r3, r5]
CMP r6, #0 ; 0 if not cleared
BNE alreadyClrLLR
; Move curosr left 3, and write 2 spaces
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x33 ; 3
BL output_character
MOV r2, #0x44 ; D
BL output_character
MOV r2, #0x20 ; space
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Move cursor right 1, and write 1 space
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x31 ; 1
BL output_character
MOV r2, #0x43 ; C
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Set SQUARE to show its already been cleared
MOV r2, #1
STR r2, [r3, r5]
; Update SCORE
LDR r3, =SCORE
LDR r2, [r3]
ADD r2, r2, #10 ; Player gets 10 point for unexplored square
STR r2, [r3]
alreadyClrLLR
LDMFD SP!, {r2-r6, lr} ; Restore registers
BX lr
clearLLL
STMFD SP!, {r2-r6, lr} ; Save registers
LDR r3, =SQUARE
LDR r4, =Q_SQUARE
LDR r5, [r4]
MOV r5, r5, LSL #2
LDR r6, [r3, r5]
CMP r6, #0 ; 0 if not cleared
BNE alreadyClrLLL
; Move curosr left 4, and write 3 spaces
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x34 ; 4
BL output_character
MOV r2, #0x44 ; D
BL output_character
MOV r2, #0x20 ; space
BL output_character
MOV r2, #0x20 ; space
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Set SQUARE to show its already been cleared
MOV r2, #1
STR r2, [r3, r5]
; Update SCORE
LDR r3, =SCORE
LDR r2, [r3]
ADD r2, r2, #10 ; Player gets 10 point for unexplored square
STR r2, [r3]
alreadyClrLLL
LDMFD SP!, {r2-r6, lr} ; Restore registers
BX lr
clearLRR
STMFD SP!, {r2-r6, lr} ; Save registers
LDR r3, =SQUARE
LDR r4, =Q_SQUARE
LDR r5, [r4]
MOV r5, r5, LSL #2
LDR r6, [r3, r5]
CMP r6, #0 ; 0 if not cleared
BNE alreadyClrLRR
; Move curosr left 2, and write 1 spaces
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x32 ; 2
BL output_character
MOV r2, #0x44 ; D
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Move cursor right 1, and write 2 space
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #0x31 ; 1
BL output_character
MOV r2, #0x43 ; C
BL output_character
MOV r2, #0x20 ; space
BL output_character
MOV r2, #0x20 ; space
BL output_character
; Set SQUARE to show its already been cleared
MOV r2, #1
STR r2, [r3, r5]
; Update SCORE
LDR r3, =SCORE
LDR r2, [r3]
ADD r2, r2, #10 ; Player gets 10 point for unexplored square
STR r2, [r3]
alreadyClrLRR
LDMFD SP!, {r2-r6, lr} ; Restore registers
BX lr
updateScore
STMFD SP!, {r2-r4, lr} ; Save registers
MOV r2, #0x1B ; ESC
BL output_character
MOV r2, #0x5B ; [
BL output_character
MOV r2, #1 ; move to line 1
BL output_character
MOV r2, #0x3B ; ;
BL output_character
MOV r2, #0x33 ; move to column 39
BL output_character
MOV r2, #0x39
BL output_character
MOV r2, #0x66 ; f
BL output_character
; Redraw SCORE
LDR r3, =SCORE
LDR r4, [r3]
MOV r1, #1000 ; divisor
MOV r0, r4 ; dividend
BL div_and_mod
MOV r2, r0 ; quotient = thousands digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r0, r1 ; Move remainder to dividend
MOV r1, #100 ; divisor
BL div_and_mod
MOV r2, r0 ; quotient = hundreds digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r0, r1 ; Move remainder to dividend
MOV r1, #10 ; divisor
BL div_and_mod
MOV r2, r0 ; quotient = tens digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
MOV r2, r1 ; remiander = ones digit
ADD r2, r2, #0x30 ; convert to ascii
BL output_character
LDMFD SP!, {r2-r4, lr} ; Restore registers
BX lr
spawnEnemy
STMFD SP!, {r2-r4, lr} ; Save registers
; dont spawn an enemy if one is currently at square 2 or 3
LDR r2, =BALL1_SQUARE
LDR r1, [r2]
CMP r1, #2
BEQ noSpawn
CMP r1, #3
BEQ noSpawn
LDR r2, =BALL2_SQUARE
LDR r1, [r2]
CMP r1, #2
BEQ noSpawn
CMP r1, #3
BEQ noSpawn
LDR r2, =SNAKEBALL_SQUARE
LDR r1, [r2]
CMP r1, #2
BEQ noSpawn
CMP r1, #3