-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.s
More file actions
2500 lines (2217 loc) · 54.1 KB
/
main.s
File metadata and controls
2500 lines (2217 loc) · 54.1 KB
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
#########################################################
# #
# Universidade de Brasilia #
# Instituto de Ciencias Exatas #
# Departamento de Ciencia da Computacao #
# Introducao aos Sistemas Computacionais - 2023.2 #
# Professor Marcus Vinicius Lamar #
# Alunos Nirva Neves, Rodrigo Rafik e Mariana Simion #
# Projeto Final #
# Nome do jogo: RadIceCream #
# #
#########################################################
#
# Notes:
# 1 - Registers are used rather liberally, with only argument registers really being used for their intended purposes.
# Since memory is used so extensively, we delegated the function of saved registers mostly to memory. In other words,
# temporary and saved registers are pretty much used interchangeably.
#
# 2 - Register s11 is exclusively used as a tick counter.
# good luck lol
.data
###############
### globals ###
###############
# map width and height are fixed for every level
mapwidth:
.word 20
mapheight:
.word 15
# how many levels are unlocked
unlockedLevels:
.word 1
#####################
### external data ###
#####################
.include "level_information/menu_screens/title_screen.data"
.include "level_information/menu_screens/level_select.data"
.include "level_information/menu_screens/padlockoverlay.data"
.include "level_information/menu_screens/pause_overlay.data"
.include "level_information/menu_screens/death_overlay.data"
.include "level_information/menu_screens/gameover.data"
.include "level_information/menu_screens/victoryscreen.data"
.include "level_information/menu_screens/storyscreen1.data"
.include "level_information/menu_screens/storyscreen2.data"
.include "level_information/menu_screens/victory_screen_final0.data"
.include "level_information/menu_screens/victory_screen_final1.data"
.include "sprites/numbers.data"
.include "level_information/level_1/level1.data"
.include "level_information/level_1/level1_bg.data"
.include "level_information/level_1/level1_info.data"
.include "level_information/level_1/level1_colupdates.data"
.include "level_information/level_1/level1_music.data"
.include "level_information/level_2/level2.data"
.include "level_information/level_2/level2_bg.data"
.include "level_information/level_2/level2_info.data"
.include "level_information/level_2/level2_colupdates.data"
.include "level_information/level_2/level2_music.data"
.include "level_information/level_3/level3.data"
.include "level_information/level_3/level3_bg.data"
.include "level_information/level_3/level3_info.data"
.include "level_information/level_3/level3_colupdates.data"
.include "level_information/level_3/level3_music.data"
.include "sprites/empty.data"
.include "sprites/breakable.data"
.include "sprites/collectibles.data"
.include "sprites/breakable_c.data"
.include "sprites/enemy_dudu.data"
.include "sprites/enemy_tonho.data"
.include "sprites/char.data"
.include "sprites/building0.data"
.include "sprites/breaking0.data"
.include "sprites/explosion.data"
# levelLoader data
currentLevel:
.space 308 # 20 * 15 bytes + 2 words
levelBackground:
.space 76808 # 320 * 240 bytes + 2 words
enemyAmount:
.word 0
enemyPositions:
.space 24
enemyTypes:
.space 8
enemyStates:
.byte
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0
playerPosition:
.space 8
collectibleCount:
.word 0
collectibleUpdates:
.word 0
updateCounter:
.word 0
# Enough space for three updates, could be expanded but I can't be bothered since the max is 3 anyway
# Like why would anyone in their right mind put four collectibles in a level
collectibleTypes:
.word 0, 0, 0
collectibleMatrices:
.space 900
collectibleDecrement:
.word 0
currentCollectible:
.word 0
levelNumber:
.word 0
# song data
songLength:
.word 0
# songNotes and notesDuration work in pairs, so they use the same pointer (currentNote)
songNotes: # array that contains the pitch value of each note
.space 4096
notesDuration: # array that contains the duration of each note
.space 4096
currentNote: # pointer to the current note (and its duration)
.word 0
currentEndTime: # when last note ends
.word 0
# explosion variables
explosionMatrix:
.space 300
explosionFlag:
.word 0
explosionState:
.word 0
# states up, down, left and right are 0, 1, 2 and 3 respectively
playerState:
.word 0
# boolean value - is the player pressing space?
playerBreaking:
.word 0
# position
playerPosX:
.word 0
playerPosY:
.word 0
# movement limiters
playerEnergy:
.word 0
maxPlayerEnergy:
.word 8
# How much each collectible is worth
collectibleValue:
.word 0
points:
.word 0
# frameswitch variables
currentframeaddress:
.word 0xff100000
displayedframeaddress:
.word 0xff200604
# input variables
currentInput:
.word 0x0
keyboardAddress:
.word 0xff200000
# used by doSpecial
lookAheadPointer:
.word 20
# time variables
levelTimer:
.word 0
levelPaused:
.word 0
currentTime:
.word 0
# game flags
victoryFlag:
.word 0
gameOverFlag:
.word 0
# mapRender variables
tempwidth:
.word 0x0
tempheight:
.word 0x0
######################################
######### End of data segment ########
######################################
.text
# MAIN MENU
mainMenuRender:
# render title screen
mv a0, zero
mv a1, zero
la a2, title_screen
li a3, 0
jal displayPrint
jal frameSwitch
mainMenuSelect:
# get input from the keyboard for menu options
lw t0, keyboardAddress
lw t1, 0(t0)
andi t1, t1, 1
# check first bit at keyboard address to see if input has been pressed
beq t1, zero, mainMenuSelect
lb t1, 4(t0)
li t2, 0x031
beq t1, t2, storyScreen
li t2, 0x032
# this slight madness below has to be done because exitProgram is out of the branch's range (+- 512 words)
bne t1, t2, continueMMSelect
j exitProgram
continueMMSelect:
j mainMenuSelect
# STORY SCREEN
storyScreen:
# render story part 1
mv a0, zero
mv a1, zero
la a2, storyscreen1
li a3, 0
jal displayPrint
jal frameSwitch
storyPrompt1:
# get input from the keyboard
lw t0, keyboardAddress
lw t1, 0(t0)
andi t1, t1, 1
# check first bit at keyboard address to see if input has been pressed
beq t1, zero, storyPrompt1
lb t1, 4(t0)
# next part if input is 1
li t2, 0x031
bne t1, t2, storyPrompt1
# render story part 2
mv a0, zero
mv a1, zero
la a2, storyscreen2
li a3, 0
jal displayPrint
jal frameSwitch
storyPrompt2:
# get input from the keyboard
lw t0, keyboardAddress
lw t1, 0(t0)
andi t1, t1, 1
# check first bit at keyboard address to see if input has been pressed
beq t1, zero, storyPrompt2
lb t1, 4(t0)
# level Select if input is 1
li t2, 0x031
bne t1, t2, storyPrompt2
# LEVEL SELECT
levelSelect:
# render level select screen
mv a0, zero
mv a1, zero
la a2, level_select
li a3, 0
jal displayPrint
# padlocks rendering
lw s0, unlockedLevels
la s1, padlockoverlay
padlock2:
li t0, 2
bge s0, t0, padlock3
li a0, 144
li a1, 112
mv a2, s1
mv a3, zero
jal displayPrint
padlock3:
li t0, 3
bge s0, t0, finishPadlocks
li a0, 208
li a1, 112
mv a2, s1
mv a3, zero
jal displayPrint
finishPadlocks:
jal frameSwitch
levelInput:
# get input from the keyboard numbers and loads the corresponding level.
lw t0, keyboardAddress
lw t1, 0(t0)
andi t1, t1, 1
# check first bit at keyboard address to see if input has been pressed
beq t1, zero, levelInput
lb t1, 4(t0)
# pressing 0 is a cheat to unlock all levels
li t2, 0x30
beq t1, t2, unlockLevels
# pressing [-] is a cheat to lock levels
li t2, 0x2D
beq t1, t2, lockLevels
# load level according to keyboard numbers
li t2, 0x031
beq t1, t2, load1
li t2, 0x032
beq t1, t2, load2
li t2, 0x033
beq t1, t2, load3
# p returns to main menu
li t2, 0x70
beq t1, t2, mainMenuRender
j levelInput
unlockLevels:
# unlock levels and go back to level prompt
li t0, 9
sw t0, unlockedLevels, t1
j levelSelect
lockLevels:
# lock levels and go back to level prompt
li t0, 1
sw t0, unlockedLevels, t1
j levelSelect
# LEVEL LOADING
load1:
li t0, 1
sw t0, levelNumber, t1
la a0, level1
la a1, level1_bg
la a2, level1_info
la a3, level1_colupdates
la a4, level1_music
j levelLoader
load2:
# only loadable if unlocked
lw t0, unlockedLevels
li t1, 2
blt t0, t1, levelInput
li t0, 2
sw t0, levelNumber, t1
la a0, level2
la a1, level2_bg
la a2, level2_info
la a3, level2_colupdates
la a4, level2_music
j levelLoader
load3:
# equally
lw t0, unlockedLevels
li t1, 3
blt t0, t1, levelInput
li t0, 3
sw t0, levelNumber, t1
la a0, level3
la a1, level3_bg
la a2, level3_info
la a3, level3_colupdates
la a4, level3_music
j levelLoader
# ENDGAME STORY SCREEN
finalVictoryScreen:
# render vicstory part 1
mv a0, zero
mv a1, zero
la a2, victory_screen_final0
li a3, 0
jal displayPrint
jal frameSwitch
victoryPrompt1:
# get input from the keyboard
lw t0, keyboardAddress
lw t1, 0(t0)
andi t1, t1, 1
# check first bit at keyboard address to see if input has been pressed
beq t1, zero, victoryPrompt1
lb t1, 4(t0)
# next part if input is 1
li t2, 0x031
bne t1, t2, victoryPrompt1
# render vicstory part 2
mv a0, zero
mv a1, zero
la a2, victory_screen_final1
li a3, 0
jal displayPrint
jal frameSwitch
victoryPrompt2:
# get input from the keyboard
lw t0, keyboardAddress
lw t1, 0(t0)
andi t1, t1, 1
# check first bit at keyboard address to see if input has been pressed
beq t1, zero, victoryPrompt2
lb t1, 4(t0)
# level Select if input is 1
li t2, 0x031
bne t1, t2, victoryPrompt2
j mainMenuRender
# DYNAMIC LEVEL SELECTOR
# (Used for restarts and next levels)
dynamicLoader:
# loads a level based on the current levelNumber
# useful for restarting and loading the next level after victory
lw t0, levelNumber
li t1, 1
beq t0, t1, load1
li t1, 2
beq t0, t1, load2
li t1, 3
beq t0, t1, load3
li t1, 4
beq t0, t1, finalVictoryScreen
j mainMenuRender
# LEVEL LOADER
levelLoader:
# a0 = level matrix
# a1 = level background image
# a2 = level information file
# a3 = level collectible update matrix
# a4 = level music information
# reset collectible values
li t0, 100
sw t0, collectibleValue, t1
# reset victory flag
li t0, 0
sw t0, victoryFlag, t1
# reset collectible update counter
li t0, 0
sw t0, updateCounter, t1
# reset pause flag
li t0, 0
sw t0, levelPaused, t1
# reset playerState
li t0, 1
sw t0, playerState, t1
# reset lookAheadPointer
li t0, 20
sw t0, lookAheadPointer, t1
# reset points
li t0, 0
sw t0, points, t1
# reset ticker
li s11, 0
# reset player energy
li t0, 10
sw t0, playerEnergy, t1
# reset explosionState
li t0, 0
sw t0, explosionState, t1
# reset explosionFlag
li t0, 0
sw t0, explosionFlag, t1
# reset current note
li t0, 0
sw t0, currentNote, t1
# reset explosionMatrix
la s0, explosionMatrix
li t2, 75
li t0, 0
explosionMatrixReset:
bge t0, t2, outExplosionMatrixReset
li t1, 0
sw t1, 0(s0)
addi t0, t0, 1
addi s0, s0, 4
j explosionMatrixReset
outExplosionMatrixReset:
# reset enemy states
la s0, enemyStates
li t0, 4
li t1, 0
# the reason for this number is that it alternates between bytes 0 and 1
# we want all enemies to start facing down and not performing specials
li t2, 0x00010001
enemyStateReset:
bge t1, t0, endEnemyStateReset
sw t2, 0(s0)
addi t1, t1, 1
addi s0, s0, 4
j enemyStateReset
endEnemyStateReset:
# copy from level data to currentLevel
la s0, currentLevel
lw t0, 0(a0)
sw t0, 0(s0)
# t0 = width
lw t1, 4(a0)
sw t1, 4(s0)
# t1 = height
li t2, 0
li t3, 0
# t2 = current x
# t3 = current y
addi s0, s0, 8
addi a0, a0, 8
# s0 is currentLevel saver pointer and a0 is level data loader pointer
levelYloop:
# iterate through matrix lines
bge t3, t1, levelYloopEnd
li t2, 0
levelXloop:
# iterate through matrix columns
bge t2, t0, levelXloopEnd
# copy from level data pointer to currentLevel data pointer
lw t4, 0(a0)
sw t4, 0(s0)
# increments
addi a0, a0, 4
addi s0, s0, 4
addi t2, t2, 4
j levelXloop
levelXloopEnd:
addi t3, t3, 1
j levelYloop
levelYloopEnd:
getBackground:
# copy background data to levelBackground
la s0, levelBackground
lw t0, 0(a1)
sw t0, 0(s0)
# t0 = width
lw t1, 4(a1)
sw t1, 4(s0)
# t1 = height
li t2, 0
li t3, 0
# t2 = current x
# t3 = current y
addi s0, s0, 8
addi a1, a1, 8
# very similar to the procedure above (It's almost the same code.)
bgYloop:
bge t3, t1, bgYloopEnd
li t2, 0
bgXloop:
bge t2, t0, bgXloopEnd
# copy 4 pixels from background pointer to levelBackground pointer
lw t4, 0(a1)
sw t4, 0(s0)
# increments
addi a1, a1, 4
addi s0, s0, 4
addi t2, t2, 4
j bgXloop
bgXloopEnd:
addi t3, t3, 1
j bgYloop
bgYloopEnd:
# now using argument a2 for accessing level information
getInfo:
# collect enemy amount
lw s0, 0(a2)
sw s0, enemyAmount, t0
# move a2 to enemy positions
addi a2, a2, 4
li t0, 24
# enemy position is 6 words long (allows for 8 enemies total)
li t1, 0
la s0, enemyPositions
# counter
# collect enemy positions
# deja vu
loadEnemyPos:
bge t1, t0, loadEnemyPosEnd
lw s1, 0(a2)
sw s1, 0(s0)
addi a2, a2, 4
addi s0, s0, 4
addi t1, t1, 4
j loadEnemyPos
loadEnemyPosEnd:
# collect enemy types (could've been iterative but why iterate through only two words?)
la s0, enemyTypes
lw s1, 0(a2)
sw s1, 0(s0)
addi s0, s0, 4
addi a2, a2, 4
lw s1, 0(a2)
sw s1, 0(s0)
# move a2 to player positions
addi a2, a2, 4
# collect player positions
la s0, playerPosX
lw s1, 0(a2)
sw s1, 0(s0)
addi a2, a2, 4
la s0, playerPosY
lw s1, 0(a2)
sw s1, 0(s0)
# move a2 to collectible amount
addi a2, a2, 4
# init collectible amount
la s0, collectibleCount
lw s1, 0(a2)
sw s1, 0(s0)
# move a2 to collectible updates
addi a2, a2, 4
# init collectible Update amount
la s0, collectibleUpdates
lw s1, 0(a2)
sw s1, 0(s0)
# move a2 to collectible types
addi a2, a2, 4
# init collectible types (iterative because 2 words is too little and 3 is enough apparently)
la s0, collectibleTypes
li s1, 3
li t1, 0
initCollectibleTypes:
beq t1, s1, outICT
lw s2, 0(a2)
sw s2, 0(s0)
addi a2, a2, 4
addi s0, s0, 4
addi t1, t1, 1
j initCollectibleTypes
outICT:
# load timer
lw s2, 0(a2)
sw s2, levelTimer, t0
# move to cdpm
addi a2, a2, 4
# load collectible decrement per minute
lw s2, 0(a2)
sw s2, collectibleDecrement, t0
# now using a3 to collect the update matrices
# init collectible matrices
la s0, collectibleMatrices
lw s1, collectibleUpdates
li t0, 0
# these matrices are self-contained so there is no need to count x and y
initCollectibleMatrices:
bge t0, s1, outICM
li t1, 0
# all matrices are 300 bytes long (20 * 15)
li t2, 300
ICMLoop:
bge t1, t2, outICMLoop
lb t3, 0(a3)
sb t3, 0(s0)
addi t1, t1, 1
addi a3, a3, 1
addi s0, s0, 1
j ICMLoop
outICMLoop:
addi t0, t0, 1
j initCollectibleMatrices
outICM:
loadMusic:
# music loading isn't much different from the other loader loops
lw s0, 0(a4)
sw s0, songLength, t0
addi a4, a4, 4
la s2, songNotes
li s1, 0
loadNotes:
bge s1, s0, outLoadNotes
lw t0, 0(a4)
sw t0, 0(s2)
addi a4, a4, 4
addi s2, s2, 4
addi s1, s1, 1
j loadNotes
outLoadNotes:
li s1, 0
la s2, notesDuration
loadDurations:
bge s1, s0, outLoadDurations
lw t0, 0(a4)
sw t0, 0(s2)
addi a4, a4, 4
addi s2, s2, 4
addi s1, s1, 1
j loadDurations
outLoadDurations:
# init currentCollectible
la s0, collectibleTypes
lw s1, 0(s0)
sw s1, currentCollectible, s0
# init currentTime and currentEndTime
li a7, 30
ecall
sw a0, currentTime, t0
sw a0, currentEndTime, t0
# MAIN INGAME LOOPS
runtimeLoop:
# This small sleep is necessary, otherwise some note don't play at all
# This is because runtimeLoop would run EXTREMELY fast without this sleep
li a7, 32
li a0, 1
ecall
# MUSIC
musicRunner:
# Checks if note is over playing:
endNoteChecker:
li a7, 30
ecall # a0 holds current time
lw t5, currentEndTime # (refurbishing t5 here) t5 holds currentEndTime
blt a0, t5, notOverYet # checks if current time is less than the previously set end time.
playNote:
# Get memory info
lw t4, songLength # load song length in notes
lw t0, currentNote # load pointer
la t1, songNotes # Load notes array address into t1
la t2, notesDuration # Load durations array address into t2
li t3, 4
mul t0, t0, t3
# Set up pointers
add t1, t1, t0 # t1 holds the current pitch's address
lw t1, 0(t1) # t1 is now the current note
add t2, t2, t0 # t2 holds the current duration's address
lw t2, 0(t2) # t2 is now the current duration
# Midi Output
li a7, 31 # MidiOut syscall
mv a0, t1 # move pitch from t1 to a0
mv a1, t2 # move duration from t2 to a1
li a2, 30 # guitar instrument
li a3, 85 # volume
ecall
# Get current time
li a7, 30
ecall
# Setting up end time for the current note being played
add t6, a0, t2 # t6 is startTime + duration
sw t6, currentEndTime, s2
lw s0, currentNote # s0 acts like a current note counter
addi s0, s0, 1 # increment counter
bge s0, t4, loopSong # if song ended, loop it
j outLoopSong
loopSong:
li s0, 0 # reset counter
outLoopSong:
sw s0, currentNote, s1 # set new pointer value to memory
notOverYet:
# MAIN GAME LOOP
# check if it's time to run the next game tick
lw t0, currentTime
# 44 miliseconds because time in the runtime simulator is weird
# The game runs at ~ 20 fps (it varies a little bit, sadly)
addi t0, t0, 44
li a7, 30
ecall
bge a0, t0, gameLoop
j runtimeLoop
gameLoop:
# save the time at which this tick is being run
li a7, 30
ecall
sw a0, currentTime, t0
# INITIAL GAMELOOP PROCEDURES
# LEVEL PAUSING
lw t0, levelPaused
beq t0, zero, outPauseLevel
pauseLevel:
# display pause screen
li a0, 0
li a1, 0
la a2, pause_overlay
li a3, 0
jal displayPrint
jal frameSwitch
pauseInput:
# get input from the keyboard numbers and perform the relevant action
lw t0, keyboardAddress
lw t1, 0(t0)
andi t1, t1, 1
# check first bit at keyboard address to see if input has been pressed
# again, if no input it just keeps checking
beq t1, zero, pauseInput
lb t1, 4(t0)
# 1 for unpause
li t2, 0x031
beq t1, t2, outPauseLevel
# 2 for restart (dynamicLoader loads current level)
li t2, 0x032
beq t1, t2, dynamicLoader
# 3 for main menu
li t2, 0x33
beq t1, t2, mainMenuRender
# other inputs are invalid
j pauseInput
outPauseLevel:
# remove pause flag
sw zero, levelPaused, t0
# TIMER
# decrement timer every second (approximate)
li t0, 20
# since s11 is only divisible by 20 once per second, the code runs as intended.
remu t0, s11, t0
beq t0, zero, timerDecrement
j outTimerDecrement
timerDecrement:
lw t0, levelTimer
addi t0, t0, -1
sw t0, levelTimer, t1
# game ends if player runs out of time
bne t0, zero, outTimerDecrement
timerGameOver:
li t0, 2
sw t0, gameOverFlag, t1
outTimerDecrement:
# COLLECTIBLE VALUE
# Collectibles will lose value every minute; value lost is specified on level information file
# 1200 ticks = one minute
li t1, 1200
remu t1, s11, t1
beq s11, zero, noLower
beq t1, zero, lowerCollectibleValue
j noLower
lowerCollectibleValue:
lw s0, collectibleValue
lw t1, collectibleDecrement
sub s0, s0, t1
sw s0, collectibleValue, s1
noLower:
# PLAYER "STAMINA"
# player stamina system core
# used in move and special functions
# energy capped at 10, regenerates 1 point every tick. player may only
# move or perform a special when it is equal to 10
lw s0, playerEnergy
lw t1, maxPlayerEnergy
blt s0, t1, addEnergy
j outAddEnergy
addEnergy:
addi s0, s0, 1
sw s0, playerEnergy, s1
outAddEnergy:
# PLAYER ANIMATION
# maintain breaking state while energy hasn't yet recovered
lw t0, playerEnergy
bge t0, t1, resetPlayerBreaking
j outResetPlayerBreaking
resetPlayerBreaking:
lw s0, playerBreaking
li s0, 0
sw s0, playerBreaking, s1
outResetPlayerBreaking:
# ENEMY AI
# enemy ai for movement should be run every 0.8s (16 ticks)
# enemy ai should never be run at the very start of the match
li t3, 16
blt s11, t3, outEnemyAI
li t0, 0
# t0 will hold the current enemy ID
li t3, 16
rem t3, s11, t3
beq t3, zero, flagEnMov
li t3, 160
li t2, 8
sub t2, s11, t2
rem t3, t2, t3
beq t3, zero, flagEnExp
j outEnemyAI
flagEnMov:
li t3, 0
sw t3, explosionFlag, t2
j enemyAI
flagEnExp:
li t3, 1
sw t3, explosionFlag, t2
li t3, 0
sw t3, explosionState, t2
j enemyAI
enemyAI:
# once there are no more enemies to verify, continue
lw t3, enemyAmount
bge t0, t3, outEnemyAI
# gathering enemy information
# position (s0 and s1)
la t1, enemyPositions
li t3, 3
mul t3, t0, t3
add t1, t3, t1
lb s0, 0(t1)
lb s1, 1(t1)
# type (s3)
la t1, enemyTypes
add t1, t0, t1
lb s3, 0(t1)
# states (s4 and s5)
la t1, enemyStates
li t3, 2
mul t3, t0, t3
add t1, t3, t1
lb s4, 0(t1)
lb s5, 1(t1)
lw t3, explosionFlag
beq t3, zero, enemyMovement