-
Notifications
You must be signed in to change notification settings - Fork 0
/
frogger.asm
1717 lines (1091 loc) · 34.4 KB
/
frogger.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
# =============================== Project Information ===============================
# ---------------------- CSC258H1S Fall 2021 Assembly Final Project ----------------------
# University of Toronto, St. George
# --- Student Info ----
# Student: Name: Zhonghan CHEN
# Student Number: 1005770541
# --- Bitmap Display Configuration ---:
# - Unit width in pixels: 8
# - Unit height in pixels: 8
# - Display width in pixels: 256
# - Display height in pixels: 256
# - Base Address for Display: 0x10008000 ($gp)
# --- Bitmap Display Configuration Ends ---:
# Which milestone is reached in this submission?
# ------ Milestone 5 has been reached.
# Which approved additional features have been implemented?
# EASY FEATURE:
# ---- 1. Display the number of lives remaining
# ---- 2. Have objects in different rows move at different speeds
# ---- 3. Add a third row in each of the water and road sections
# ---- 4. Display a death/respawn animation each time the player loses a frog.
# HARD FEATURE:
# ---- 5. Have some of the floating objects sink and reappear (like arcade version)
# ---- 6. Add extra random hazards (alligators in the goal areas, spiders on the logs, etc)
# ---- 7. Two-player mode (two sets of inputs controlling two frogs at the same time)
# =============================== Project Information Ends ===============================
.data
displayAddress: .word 0x10008000
RED: .word 0xff0000
GREEN: .word 0x00ff00
LAKE_BLUE: .word 0x33FFFF
BLACK: .word 0x000000
GREY: .word 0x7a7a7a
YELLOW: .word 0xffff00
WOOD: .word 0x663300
WHITE: .word 0xE0E0E0
PINK: .word 0xFFCCFF
WATER_BLUE: .word 0x0000CC
FROG_BLOOD: .word 0xFF3333
CAR_COLOR: .word 0x6600CC
Alligator_Color: .word 0x006633
Spider_Color: .word 0xFFCCE5
LivesRemain: .word 3 # A global info stores the life remaining (mutable)
# X and Y are the top-left coordinate of the
frogX: .word 24
frogY: .word 28
frogX2: .word 64
frogY2: .word 28
carShift: .word 2840
termination: .word 128
frog: .word 3608
logShape: .word 1028, 1032, 1036, 1040, 1044, 1048, # LOG1 - 1
1156, 1160, 1164, 1168, 1172, 1176, # LOG1 - 2
1284, 1288, 1292, 1296, 1300, 1304, # LOG1 - 3
1412, 1416, 1420, 1424, 1428, 1432, # LOG1 - 4
1080, 1084, 1088, 1092, 1096, 1100, 1104 # LOG2 - 1
1208, 1212, 1216, 1220, 1224, 1228, 1232 # LOG2 - 2
1336, 1340, 1344, 1348, 1352, 1356, 1360 # LOG2 - 3
1464, 1468, 1472, 1476, 1480, 1484, 1488 # LOG2 - 4
1552, 1556, 1560, 1564, 1568, 1572, # LOG3 - 1
1680, 1684, 1688, 1692, 1696, 1700, # LOG3 - 2
1808, 1812, 1816, 1820, 1824, 1828, # LOG3 - 3
1936, 1940, 1944, 1948, 1952, 1956, # LOG3 - 4
1508, 1512, 1516, 1520,
1724, 1728, 1732, 1736, 1740 # LOG4 - 2
1852, 1856, 1860, 1864, 1868 # LOG4 - 3
1980, 1984, 1988, 1992, 1996 # LOG4 - 4
1544, 1548, # Complemets for LOG3
1672, 1676,
1800, 1804,
1928, 1932,
log: .space 412
CarShapeRow0: .word 2664, 2668, 2672, 2588, 2592, 2596
car0: .space 24
CarShapeRow1: .word 3076, 3080, 3084, 3088, # the first log in ROW1
3124, 3128, 3132, 3136 # the second log in ROW1
car1: .space 32
CarShapeRow2: .word 3464, 3468, 3472
car2: .space 12
AlligatorShape: .word 528, 536, 660, 672, 784, 792, 796, 800, 924, 932, 936
Alligator: .space 44
SpiderShape: .word 2856, 2860, 2864, 2732, 2988, 2900, 3024, 3032
Spider: .space 1212
.text
lw $t0, displayAddress
main:
jal DRAW_BACKGROUND
jal DRAW_FROG
jal DRAW_FROG2
jal DrawSpider
jal CarDrawingRow0
jal CarDrawingRow1
jal CarDrawingRow2
jal LogDrawing
jal refresh
addi $sp, $sp, -4
sw $ra, 0($sp)
jal frogMovement
jal frogMovement2
lw $ra, 0($sp)
addi $sp, $sp, 4
refresh:
addi $sp, $sp, -4
sw $ra, 0($sp)
jal DrawAlligator
jal DrawSpider
jal LogShift
jal CarShiftRow0
jal CarShiftRow1
jal CarShiftRow2
jal DRAW_START_AREA
jal DRAW_SAFE_ZONE
jal DRAW_GOAL_AREA
jal DRAW_INFO_AREA
# === Here we start the part for collision ===
jal reachGoalArea
jal reachGoalArea2
jal carCollision
jal carCollision2
jal WaterDropIn
jal WaterDropIn2
jal DRAW_FROG
jal DRAW_FROG2
jal displayLifeRemain
jal displayDeathScreen
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# ================================= Movement of the Frog =================================
frogMovement:
lw $t5, 0xffff0000
beq $t5, 1, KeyboardStroke #Check for keyboard Input
j refresh
KeyboardStroke:
lw $t4, 0xffff0004
beq $t4, 0x61, key_A
beq $t4, 0x77, key_W
beq $t4, 0x73, key_S
beq $t4, 0x64, key_D
# ================================= Movement of the Frog Ends =================================
# ================================= Movement of the Frog2 =================================
frogMovement2:
lw $t5, 0xffff0000
beq $t5, 1, KeyboardStroke2 #Check for keyboard Input
j refresh
KeyboardStroke2:
lw $t4, 0xffff0004
beq $t4, 0x6a, key_J
beq $t4, 0x69, key_I
beq $t4, 0x6b, key_K
beq $t4, 0x6c, key_L
# ================================= Movement of the Frog2 Ends =================================
# ============================================ Drawing the Frog ===========================================================
# Here we start to draw the Frog
# the frog consists of 12 pixels
DRAW_FROG:
la $t8, frogX # fetch the address of X coordinate of frog
la $t9, frogY # fetch the address of Y coordinate of frog
lw $t6, 0($t8) # get the X value of the frog
lw $t7, 0($t9) # get the Y value of the frog
# lw $t1, BLACK
# Declare again the address of $t0
lw $t0, displayAddress
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
lw $t1, BLACK
sw $t1, 0($t0) # DRAW left-leg of the frog
sub $t0, $t0, $t6
sub $t0, $t0, $t5
sw $t0, displayAddress
jr $ra
# ============================================ Drawing the Frog Ends ===========================================================
# ============================================ Drawing the Frog2 ===========================================================
# Here we start to draw the Frog
# the frog consists of 12 pixels
DRAW_FROG2:
la $t8, frogX2 # fetch the address of X coordinate of frog
la $t9, frogY2 # fetch the address of Y coordinate of frog
lw $t6, 0($t8) # get the X value of the frog
lw $t7, 0($t9) # get the Y value of the frog
# lw $t1, BLACK
# Declare again the address of $t0
lw $t0, displayAddress
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
lw $t1, RED
sw $t1, 0($t0) # DRAW left-leg of the frog
sub $t0, $t0, $t6
sub $t0, $t0, $t5
sw $t0, displayAddress
jr $ra
# ============================================ Drawing the Frog Ends ===========================================================
# =========================================== Draw the Spider ===========================================
DrawSpider:
SpiderDraw:
lw $t1, Spider_Color
la $t2, SpiderShape
add $t3, $zero, $zero # Counter
add $t4, $zero, $zero # Position
SpiderDrawLoop:
lw $t0, displayAddress
beq $t3, 8, SpiderDrawEnd
lw $t5, SpiderShape($t4)
add $t5, $t5, $t0
sw $t1, 0($t5)
addi $t3, $t3, 1
addi $t4, $t4, 4
j SpiderDrawLoop
SpiderDrawEnd:
# ==== About the update of the paint =====
li $v0, 32
li $a0, 800
syscall
# === Update ends here ====
jr $ra
# =========================================== Draw the Spider Ends ===========================================
# =========================================== Car Collision Starts ===========================================
# The Action when collide with the Car in Red.
carCollision:
# << REGISTER USED >>: t0, t1, t8, t9, t6, t7, t5, t1, t2
addi $sp, $sp, -4
sw $ra, 0($sp)
# == Loading ===
lw $t0, displayAddress # Guarantee the correctness of the base.
lw $t1, CAR_COLOR # Store the determination condition for Car-Collision
# == Calculate address for the frog ==
la $t8, frogX # fetch the address of X coordinate of frog
la $t9, frogY # fetch the address of Y coordinate of frog
lw $t6, 0($t8) # get the X value of the frog
lw $t7, 0($t9) # get the Y value of the frog
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# == Calculation for address finished ==
lw $t2, 0($t0) # Load what color is at this location now
beq $t2, $t1, carCollisionReaction
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# Describe how the frog would react when collide with the car
carCollisionReaction:
addi $sp, $sp, -4
sw $ra, 0($sp)
# ======= change the life first =====
lw $t3, LivesRemain
addi $t3, $t3, -1
sw $t3, LivesRemain
# ======= change the life finished =====
# ======= Add some animation here =========
sub $t0, $t0, $t5 # the updated address (Y updated)
sub $t0, $t0, $t6
sw $t0, displayAddress
lw $t0, displayAddress
lw $t1, FROG_BLOOD
# -------- calculate frog's current position ------------
lw $t6, frogX
lw $t7, frogY
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# -------- calculate frog's current position ------------
addi $t0, $t0, -128
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, 8
sw $t1, 0($t0)
addi $t0, $t0, 128
sw $t1, 0($t0)
addi $t0, $t0, 128
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, -128
sw $t1, 0($t0)
addi $t0, $t0, -128
sw $t1, 0($t0)
# ==== About the update of the paint =====
li $v0, 32
li $a0, 800
syscall
# === Update ends here ====
# ======= Add some animation here =========
addi $t3, $zero, 24 # X-coordinate of the frog and re-initialize the $t3
addi $t4, $zero, 28 # Y-coordinate of the frog
sw $t3, frogX
sw $t4, frogY
jal DRAW_FROG
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# =========================================== Car Collision Ends ===========================================
# =========================================== Car2 Collision Starts ===========================================
# The Action when collide with the Car in Red.
carCollision2:
# << REGISTER USED >>: t0, t1, t8, t9, t6, t7, t5, t1, t2
addi $sp, $sp, -4
sw $ra, 0($sp)
# == Loading ===
lw $t0, displayAddress # Guarantee the correctness of the base.
lw $t1, CAR_COLOR # Store the determination condition for Car-Collision
# == Calculate address for the frog ==
la $t8, frogX2 # fetch the address of X coordinate of frog
la $t9, frogY2 # fetch the address of Y coordinate of frog
lw $t6, 0($t8) # get the X value of the frog
lw $t7, 0($t9) # get the Y value of the frog
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# == Calculation for address finished ==
lw $t2, 0($t0) # Load what color is at this location now
beq $t2, $t1, carCollisionReaction2
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# Describe how the frog would react when collide with the car
carCollisionReaction2:
addi $sp, $sp, -4
sw $ra, 0($sp)
# ======= change the life first =====
lw $t3, LivesRemain
addi $t3, $t3, -1
sw $t3, LivesRemain
# ======= change the life finished =====
# ======= Add some animation here =========
sub $t0, $t0, $t5 # the updated address (Y updated)
sub $t0, $t0, $t6
sw $t0, displayAddress
lw $t0, displayAddress
lw $t1, FROG_BLOOD
# -------- calculate frog's current position ------------
lw $t6, frogX2
lw $t7, frogY2
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# -------- calculate frog's current position ------------
addi $t0, $t0, -128
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, 8
sw $t1, 0($t0)
addi $t0, $t0, 128
sw $t1, 0($t0)
addi $t0, $t0, 128
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, -4
sw $t1, 0($t0)
addi $t0, $t0, -128
sw $t1, 0($t0)
addi $t0, $t0, -128
sw $t1, 0($t0)
# ==== About the update of the paint =====
li $v0, 32
li $a0, 800
syscall
# === Update ends here ====
# ======= Add some animation here =========
addi $t3, $zero, 64 # X-coordinate of the frog and re-initialize the $t3
addi $t4, $zero, 28 # Y-coordinate of the frog
sw $t3, frogX2
sw $t4, frogY2
jal DRAW_FROG2
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# =========================================== Car2 Collision Ends ===========================================
# =========================================== Drop In Water Starts ===========================================
# The Action when collide with the Car in Red.
WaterDropIn:
# << REGISTER USED >>: t0, t1, t8, t9, t6, t7, t5
addi $sp, $sp, -4
sw $ra, 0($sp)
# == Loading ===
lw $t0, displayAddress # Guarantee the correctness of the base.
lw $t1, LAKE_BLUE # Store the determination condition for Car-Collision
# == Calculate address for the frog ==
la $t8, frogX # fetch the address of X coordinate of frog
la $t9, frogY # fetch the address of Y coordinate of frog
lw $t6, 0($t8) # get the X value of the frog
lw $t7, 0($t9) # get the Y value of the frog
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# == Calculation for address finished ==
lw $t2, 0($t0) # Load what color is at this location now
beq $t2, $t1, WaterDropInReaction
jal DRAW_FROG
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# Describe how the frog would react when collide with the car
WaterDropInReaction:
addi $sp, $sp, -4
sw $ra, 0($sp)
# ======= change the life first =====
lw $t3, LivesRemain
addi $t3, $t3, -1
sw $t3, LivesRemain
# ======= change the life finished =====
# ======= Add some animation here =========
sub $t0, $t0, $t5 # the updated address (Y updated)
sub $t0, $t0, $t6
sw $t0, displayAddress
lw $t0, displayAddress
lw $t1, WATER_BLUE
# -------- calculate frog's current position ------------
lw $t6, frogX
lw $t7, frogY
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# -------- calculate frog's current position ------------
addi $t0, $t0, -128
sw $t1, 0($t0)
addi $t0, $t0, 132
sw $t1, 0($t0)
addi $t0, $t0, -8
sw $t1, 0($t0)
addi $t0, $t0, 132
sw $t1, 0($t0)
# ==== About the update of the paint =====
li $v0, 32
li $a0, 800
syscall
# === Update ends here ====
# ======= Add some animation here =========
addi $t3, $zero, 24 # X-coordinate of the frog
addi $t4, $zero, 28 # Y-coordinate of the frog
sw $t3, frogX
sw $t4, frogY
jal DRAW_FROG
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# =========================================== Drop In Water Ends ===========================================
# =========================================== Drop In Water Starts ===========================================
# The Action when collide with the Car in Red.
WaterDropIn2:
# << REGISTER USED >>: t0, t1, t8, t9, t6, t7, t5
addi $sp, $sp, -4
sw $ra, 0($sp)
# == Loading ===
lw $t0, displayAddress # Guarantee the correctness of the base.
lw $t1, LAKE_BLUE # Store the determination condition for Car-Collision
# == Calculate address for the frog ==
la $t8, frogX2 # fetch the address of X coordinate of frog
la $t9, frogY2 # fetch the address of Y coordinate of frog
lw $t6, 0($t8) # get the X value of the frog
lw $t7, 0($t9) # get the Y value of the frog
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# == Calculation for address finished ==
lw $t2, 0($t0) # Load what color is at this location now
beq $t2, $t1, WaterDropInReaction2
jal DRAW_FROG2
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# Describe how the frog would react when collide with the car
WaterDropInReaction2:
addi $sp, $sp, -4
sw $ra, 0($sp)
# ======= change the life first =====
lw $t3, LivesRemain
addi $t3, $t3, -1
sw $t3, LivesRemain
# ======= change the life finished =====
# ======= Add some animation here =========
sub $t0, $t0, $t5 # the updated address (Y updated)
sub $t0, $t0, $t6
sw $t0, displayAddress
lw $t0, displayAddress
lw $t1, WATER_BLUE
# -------- calculate frog's current position ------------
lw $t6, frogX2
lw $t7, frogY2
addi $t5, $zero, 128 # set the unit to multiply
mult $t7, $t5 # the operation is 128 * Y
mflo $t5 # like to store the value of 128*Y
add $t0, $t0, $t5 # the updated address (Y updated)
add $t0, $t0, $t6
# -------- calculate frog's current position ------------
addi $t0, $t0, -128
sw $t1, 0($t0)
addi $t0, $t0, 132
sw $t1, 0($t0)
addi $t0, $t0, -8
sw $t1, 0($t0)
addi $t0, $t0, 132
sw $t1, 0($t0)
# ==== About the update of the paint =====
li $v0, 32
li $a0, 800
syscall
# === Update ends here ====
# ======= Add some animation here =========
addi $t3, $zero, 64 # X-coordinate of the frog
addi $t4, $zero, 28 # Y-coordinate of the frog
sw $t3, frogX2
sw $t4, frogY2
jal DRAW_FROG2
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# =========================================== Drop In Water Ends ===========================================
# ================================== Log Drawing and Shifting ============================================
LogDrawing:
LogDraw:
lw $t0, displayAddress
lw $t1, WOOD
la $t2, logShape
add $t3, $zero, $zero # Counter
add $t4, $zero, $zero # Position
logDrawLoop:
beq $t3, 103, logDrawEnd
lw $t5, logShape($t4)
add $t5, $t5, $t0
sw $t1, 0($t5)
addi $t3, $t3, 1
addi $t4, $t4, 4
j logDrawLoop
logDrawEnd:
jr $ra
LogShift:
LogShiftLoad:
add $t1, $zero, $zero # Position in the array
add $t3, $zero, $zero # Counter
lw $t5, WOOD
LogShiftLoop:
addi $sp, $sp, -4
sw $ra, 0($sp)
lw $t2, termination
beq $t3, 103, EndShift
lw $t4, logShape($t1)
rem $t2, $t4, $t2
addi $t4, $t4, -4
beq $t2, $zero, WrapHandler
new_label:
sw $t4, logShape ($t1)
addi $t2, $zero, 128
sw $t2, termination
addi $t1, $t1, 4
addi $t3, $t3, 1
lw $ra, 0 ($sp)
addi $sp, $sp, 4
j LogShiftLoop
WrapHandler:
addi $t4, $t4, 128
j new_label
EndShift:
addi $sp, $sp, -4
sw $ra, 0($sp)
# ==== About the update of the paint =====
li $v0, 32
li $a0, 1
syscall
# === Update ends here ====
jal DRAW_WATER_AREA
jal LogDrawing
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# ================================== Log Drawing and Shifting Ends ============================================
# =================================== Car0 Drawing and Shifting =========================================
CarDrawingRow0:
carDraw0:
lw $t0, displayAddress
lw $t1, CAR_COLOR
la $t2, CarShapeRow0
add $t3, $zero, $zero # Counter
add $t4, $zero, $zero # Position
carDrawLoop0:
beq $t3, 6, carDrawEnd0
lw $t5, CarShapeRow0($t4)
add $t5, $t5, $t0
sw $t1, 0($t5)
addi $t3, $t3, 1
addi $t4, $t4, 4
j carDrawLoop0
carDrawEnd0:
jr $ra
CarShiftRow0:
carShiftLoadRow0:
add $t1, $zero, $zero # Position in the array
add $t3, $zero, $zero # Counter
lw $t5, CAR_COLOR
carShiftLoopRow0:
addi $sp, $sp, -4
sw $ra, 0($sp)
lw $t2, termination
beq $t3, 6, EndShiftRow0
lw $t4, CarShapeRow0($t1)
rem $t2, $t4, $t2
addi $t4, $t4, -4
beq $t2, $zero, WrapHandlerRow0
new_label0:
sw $t4, CarShapeRow0($t1)
addi $t2, $zero, 128
sw $t2, termination
addi $t1, $t1, 4
addi $t3, $t3, 1
lw $ra, 0 ($sp)
addi $sp, $sp, 4
j carShiftLoopRow0
WrapHandlerRow0:
addi $t4, $t4, 128
j new_label0
EndShiftRow0:
addi $sp, $sp, -4
sw $ra, 0($sp)