-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev notes.txt
155 lines (119 loc) · 2.86 KB
/
dev notes.txt
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
displayAddress: starting index of display
$v0 return var (use for syscalls)
$v1 return var 2
== store variables in s# ==
s0: lives
s1: dartData
s2: bugBlasterPosition
s3: centipedeLives
s4: centipedeDirection
s5: playerScore
s6: fleaData
direction constants: 0 North, 1 East, 2 South, 3 West
# Get Centipedes
get_centipedes:
# save caller
addi $sp, $sp, -4
sw $ra, 0($sp)
move $t0, $zero
sll $t1, $t0, 2
add $t2, $s3, $t1
empty_loop:
lw $t3, 0($t2)
beq $t3, $zero, empty_end
addi $t0, $t0, 1
sll $t1, $t0, 2
add $t2, $s3, $t1
j empty_loop
empty_end:
move $v0, $t0
# return to caller
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
# MAIN TESTING
#move $s0, $zero
#li $s1, 56
#test_loop:
#beq $s0, $s1, test_end
#jal delay
#jal handle_centipede
#addi $s0, $s0, 1
#j test_loop
#test_end:
#lw $s0, screenWidth
#lw $s1, screenHeight
# Testing
#move $t6, $s6
#lw $t8, mushroomAmount
#move $t9, $zero # i = 0
#test_loop:
#beq $t9, $t8, test_end
#sll $t7, $t9, 2 # $t7 = i * 4 = offset
#add $t7, $t6, $t7 # $t7 = addr(A) + i*4 = addr(A[i])
#lw $a0, 0($t7)
#li $v0,1
#syscall
#li $v0,4
#la $a0,newLine
#syscall
#addi $t9, $t9, 1
#j test_loop
#test_end:
# ALLOCATE MEMORY
# read n from console
li $v0 5
syscall
move $t0 $v0
# allocate dynamic memory
sll $a0 $v0 2 # sll performs $a0 = $v0 x 2^2
li $v0 9 #9 is the system code for service(sbrk) whoes work is
syscall #to allocate dynamic memory
move $t1 $zero
move $t2 $v0
loop:
bge $t1 $t0 end
# read in and store int
li $v0 5
syscall
sw $v0 0($t2)
addi $t1 $t1 1
addi $t2 $t2 4
j loop
end:
# CENTIPEDE
move $t8, $zero # $t8: check collision
beq $t9, $zero, find_cmove_skip # if direction east/west
beq $t7, $zero, find_cmove_skip_down # if at edge
addi $v0, $t6, 256 # move down
li $v1, 2
find_cmove_skip_down:
bne $t7, $zero, find_cmove_skip # continue moving in same direction
li $t5, 1
bne $s4, $t5, find_cmove_skip_east # moving east
addi $v0, $t6, 4 # move right
find_cmove_skip_east:
beq $s4, $t5, find_cmove_skip # moving west
addi $v0, $t6, -4
find_cmove_skip:
bne $t9, $zero, find_cmove_end # if direction north/south
beq $t7, $zero, find_cmove_skip_2 # if at edge
li $t5, 1
bne $t7, $t5, find_cmove_skip_east_2 # at left wall
addi $v0, $t6, 4 # move left
li $v1, 1
find_cmove_skip_east_2:
beq $t7, $t5, find_cmove_skip_2 # at right wall
addi $v0, $t6, -4
li $v1, 3
find_cmove_skip_2:
bne $t7, $zero, find_cmove_end # move in old direction
li $t5, 1
bne $s4, $t5, find_cmove_skip_east_3 # oldDirection is east
addi $v0, $t6, 4
li $v1, 1
find_cmove_skip_east_3:
beq $s4, $t5, find_cmove_end # oldDirection is west
addi $v0, $t6, -4
li $v1, 3
find_cmove_end: