-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame over screen.asm
More file actions
589 lines (516 loc) · 14.5 KB
/
Copy pathgame over screen.asm
File metadata and controls
589 lines (516 loc) · 14.5 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
# 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)
#
# WARNING: THERE WILL BE CONFLICT AS THE DRAW ENEMY IS DIFF THAN FOR THE MOVE ENEMY'S VERSION OF DRAW ENEMY
#
.eqv lightBrown 0xa0522d
.eqv darkBrown 0x654321
.eqv red 0xff0000
.eqv green 0x00ff00
.eqv baseAddress 0x10008000
.eqv yellow 0xffff00
.data
ggsMessage: .word 0,0
obstacle: .word 0, 0 #x, y coordinates of the obstacle
game: .word 18, 4 # x,y coordinates of the top right of the word "game"
over: .word 28, 10 # x,y coordinates of the top right of the word "end"
score: .word 23, 16 # x,y coordinates of the top right of the word "score"
symbol_1: .word 6, 23 # x, y coordinates for the score
symbol_2: .word 12, 23
symbol_3: .word 18, 23
symbol_4: .word 24, 23
symbol_5: .word 30, 23
.text
gameOverPhase:
# redraw screen to be black
# draw background obstacles
#jal allEnemies
# draw the game over message
#jal drawGameOver
# draw score
#jal drawScore
#draw symbols
addi $s6, $zero, 16
addi $s7, $zero, 15
ble $s6, $s7, end
jal drawSymbol_1
addi $s7, $zero, 30
ble $s6, $s7, end
jal drawSymbol_2
bye:
j end
addi $0, $0, 0
# draw reset
drawGameOver:
la $s0, red # load the red colour into $s0
la $s1, baseAddress # $s1 has the base address
la $s2, game # $s2 holds the top right corner of the word "game"
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds displayAddress + 4*(32*y + x)
sw $s0, 0($s5)#first row of the word game
sw $s0, -4($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
sw $s0, -24($s5)
sw $s0, -40($s5)
sw $s0, -52($s5)
sw $s0, -56($s5)
sw $s0, -60($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, -4($s5) #second row
sw $s0, -12($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -60($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, -0($s5) #third row
sw $s0, -4($s5)
sw $s0, -12($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -40($s5)
sw $s0, -44($s5)
sw $s0, -52($s5)
sw $s0, -60($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, -4($s5) #fourth row
sw $s0, -12($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -52($s5)
sw $s0, -60($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, -0($s5) #fifth row
sw $s0, -4($s5)
sw $s0, -12($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -52($s5)
sw $s0, -56($s5)
sw $s0, -60($s5)
la $t1, baseAddress # $t1 has the base address
la $t2, over # $t2 holds the top right corner of the word "over"
lw $t2, 4($t2) # $t2 holds the y coordinate
sll $s5, $t2, 5 # $s5 holds y coordinate * 32
la $t2, over # $t2 holds the top right corner of the word "over"
lw $t2, 0($t2) # $t2 holds the x coordinate
add $s5, $s5, $t2 # $s5 holds 32*y + x
sll $s5, $s5, 2 # $s5 holds 4*(32*y + x)
add $s5, $s5, $t1 # $s5 holds 4*(32*y + x) + baseAddress
sw $s0, 0($s5)#first row of the word over
sw $s0, -4($s5)
sw $s0, -8($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -48($s5)
sw $s0, -52($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, 0($s5)# second row
sw $s0, -8($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -52($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, 0($s5)# third row
sw $s0, -4($s5)
sw $s0, -8($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -52($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, -4($s5) # fourth row
sw $s0, -8($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -52($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, 0($s5)#fifth row
sw $s0, -8($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
sw $s0, -32($s5)
sw $s0, -44($s5)
sw $s0, -48($s5)
sw $s0, -52($s5)
jr $ra
drawScore:
la $s0, green # $s0 has the green colour
la $s1, baseAddress # $t1 has the base address
la $s2, score # $t2 holds the top right corner of the word "score"
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds displayAddress + 4*(32*y + x)
sw $s0, 0($s5)#first row of the word score
sw $s0, -4($s5)
sw $s0, -12($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -32($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -48($s5)
sw $s0, -52($s5)
sw $s0, -60($s5)
sw $s0, -64($s5)
sw $s0, -68($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, 8($s5)# second row
sw $s0, -4($s5)
sw $s0, -12($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -52($s5)
sw $s0, -68($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, 0($s5)# third row
sw $s0, -4($s5)
sw $s0, -12($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -52($s5)
sw $s0, -60($s5)
sw $s0, -64($s5)
sw $s0, -68($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, 8($s5)# fourth row
sw $s0, -4($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -36($s5)
sw $s0, -52($s5)
sw $s0, -60($s5)
addi $s5, $s5, 128 #set to next row, rightmost pixel
sw $s0, 0($s5)#fifth row
sw $s0, -4($s5)
sw $s0, -12($s5)
sw $s0, -20($s5)
sw $s0, -28($s5)
sw $s0, -32($s5)
sw $s0, -36($s5)
sw $s0, -44($s5)
sw $s0, -48($s5)
sw $s0, -52($s5)
sw $s0, -60($s5)
sw $s0, -64($s5)
sw $s0, -68($s5)
jr $ra
#################################################################################################################################################
# New Stuff
#################################################################################################################################################
drawOk:
#################################################################################################################################################
# Obstacles
#################################################################################################################################################
allEnemies:
addi $sp, $sp, -4 # move the stack up
sw $ra, 0($sp) # store the return address
jal enemyLocation
jal enemyLocation
jal enemyLocation
jal enemyLocation
jal enemyLocation
jal enemyLocation
jal enemyLocation
lw $ra, 0($sp) # load the return address
addi $sp, $sp, 4 # move the stack down
jr $ra
enemyLocation:
addi $sp, $sp, -4 # move stack up
sw $ra, 0($sp) # save the return address
li $v0, 42 # Service 42, random int range
li $a0, 0 # Select random generator 0
li $a1, 26 # Upper bound of random number generator is 30
syscall # Generate random int (returns in $a0)
la $t0, obstacle #$t0 holds the address of the enemy's top right corner
sw $a0, 4($t0) #save random y coordinate into enemy array
li $v0, 42 # Service 42, random int range
li $a0, 0 # Select random generator 0
li $a1, 31 # Upper bound of random number generator is 16
syscall # Generate random int (returns in $a0)
sw $a0, 0($t0) #save random x coordinate (between 16 and 32) into the enemy array
la $t0, darkBrown # $t0 stores the dark brown colour
addi $sp, $sp, -4 # move up stack
sw $t0, 0($sp) #store the rdark brown colour into the stack
la $t0, lightBrown # t0 stores the light brown colour
addi $sp, $sp, -4 # move up stack
sw $t0, 0($sp) #store the light brown colour into the stack
jal drawEnemy
lw $ra, 0($sp) # restor this function's return adress
addi $sp, $sp, 4 # move the stack down
jr $ra
drawEnemy:
lw $s0, 0($sp) # $s0 holds colour popped off from the stack
addi $sp, $sp, 4 # update stack down
lw $s1, 0($sp) # $s1 holds colour popped off from the stack
addi $sp, $sp, 4 # update stack down
la $s2, obstacle # $s2 holds the top right corner of the obstacle
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds baseAddress + 4*(32*y + x)
# first row
#sw $s0, 0($s5)
sw $s0, -4($s5)
sw $s0, -8($s5)
sw $t0, -12($s5)
#sw $s0, -16($s5)
#sw $s0, -20($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
# second row
sw $s0, 0($s5)
sw $s0, -4($s5)
sw $s1, -8($s5)
sw $s1, -12($s5)
sw $s0, -16($s5)
#sw $s0, -20($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
# third row
sw $s0, 0($s5)
sw $s0, -4($s5)
sw $s0, -8($s5)
sw $s1, -12($s5)
sw $s1, -16($s5)
sw $s0, -20($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
# fourth row
sw $s0, 0($s5)
sw $s1, -4($s5)
sw $s0, -8($s5)
sw $s0, -12($s5)
sw $s1, -16($s5)
sw $s0, -20($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
# fifth row
sw $s0, 0($s5)
sw $s0, -4($s5)
sw $s1, -8($s5)
sw $s0, -12($s5)
sw $s0, -16($s5)
sw $s0, -20($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
# sixth row
#sw $s0, 0($s5)
sw $s0, -4($s5)
sw $s0, -8($s5)
sw $s0, -12($s5)
sw $s0, -16($s5)
#sw $s0, -20($s5)
#return to line after function call
jr $ra
drawSymbol_1:
la $s0, red # $s0 has the green colour
la $s6, yellow
la $s1, baseAddress # $t1 has the base address
la $s2, symbol_1 # $t2 holds the top right corner of the word "score"
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds displayAddress + 4*(32*y + x)
sw $s0, -8($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, 0($s5)
sw $s6, -4($s5)
sw $s0, -8($s5)
sw $s6, -12($s5)
sw $s0, -16($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -8($s5)
jr $ra
drawSymbol_2:
la $s0, red # $s0 has the green colour
la $s6, yellow
la $s1, baseAddress # $t1 has the base address
la $s2, symbol_2 # $t2 holds the top right corner of the word "score"
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds displayAddress + 4*(32*y + x)
sw $s0, -8($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, 0($s5)
sw $s6, -4($s5)
sw $s0, -8($s5)
sw $s6, -12($s5)
sw $s0, -16($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -8($s5)
jr $ra
drawSymbol_3:
la $s0, red # $s0 has the green colour
la $s6, yellow
la $s1, baseAddress # $t1 has the base address
la $s2, symbol_3 # $t2 holds the top right corner of the word "score"
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds displayAddress + 4*(32*y + x)
sw $s0, -8($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, 0($s5)
sw $s6, -4($s5)
sw $s0, -8($s5)
sw $s6, -12($s5)
sw $s0, -16($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -8($s5)
jr $ra
drawSymbol_4:
la $s0, red # $s0 has the green colour
la $s6, yellow
la $s1, baseAddress # $t1 has the base address
la $s2, symbol_4 # $t2 holds the top right corner of the word "score"
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds displayAddress + 4*(32*y + x)
sw $s0, -8($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, 0($s5)
sw $s6, -4($s5)
sw $s0, -8($s5)
sw $s6, -12($s5)
sw $s0, -16($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -8($s5)
jr $ra
drawSymbol_5:
la $s0, red # $s0 has the green colour
la $s6, yellow
la $s1, baseAddress # $t1 has the base address
la $s2, symbol_5 # $t2 holds the top right corner of the word "score"
lw $s3, 0($s2) # $s3 holds the x coordinate
lw $s4, 4($s2) # $s4 holds the y coordinate
sll $s4, $s4, 5 # $s4 holds y coordinate * 32
add $s4, $s4, $s3 # $s4 holds 32*y + x
sll $s4, $s4, 2 # $s4 holds 4*(32*y + x)
la $s5, baseAddress # $s5 has the base address
add $s5, $s5, $s4 # $s5 holds displayAddress + 4*(32*y + x)
sw $s0, -8($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, 0($s5)
sw $s6, -4($s5)
sw $s0, -8($s5)
sw $s6, -12($s5)
sw $s0, -16($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -4($s5)
sw $s6, -8($s5)
sw $s0, -12($s5)
#set to next row, rightmost pixel
addi $s5, $s5, 128
sw $s0, -8($s5)
jr $ra
end:
# gracefully terminate the program
li $v0, 10
syscall