-
Notifications
You must be signed in to change notification settings - Fork 0
/
bugio.s
403 lines (302 loc) · 5.65 KB
/
bugio.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
@ Start writing code
.set CLOCK_GETTIME, 0x107
.set CLOCK_REALTIME, 0
.set CLOCK_NANOSLEEP, 0x109
.set TIMER_ABSTIME, 1
.include "mov32.inc"
.include "system_calls.s"
@constant min bound
.set MIN, 0
@constant max bound
.set MAX, 60
.balign 4
.data
playerBody:
.asciz "#"
.set body_len, .-playerBody
clearChar:
.asciz " "
.set clear_body_len, .-clearChar
space:
.ascii " "
gameKey:
.skip 4
player:
.skip 1
.set lenX, .-player
.skip 1
.set lenY, .-lenX-player
spider:
// fourth layer of spider
.byte 27
.ascii "[2C"
.ascii "/"
.byte 27
.ascii "[1C"
.ascii "_"
.byte 27
.ascii "[1C"
.ascii "\\"
.byte 27
.ascii "[1B"
.byte 27
.ascii "[7D"
// third layer of spider
.ascii "\\_\\(_)\/_/"
.byte 27
.ascii "[1B"
.byte 27
.ascii "[9D"
.byte 27
.ascii "[1C"
// second layer of spider
.ascii "_\/\/o\\\\_"
.byte 27
.ascii "[1B"
.byte 27
.ascii "[8D"
.byte 27
.ascii "[2C"
// first layer of spider
.ascii "\/"
.byte 27
.ascii "[3C"
.ascii "\\"
.set spider_Len, .-spider
bullet:
.ascii "*"
.set bullet_Len, .-bullet
timespec:
.word 0
.word 50000000
.balign 4
.text
draw_player:
mov r4, lr
mov r0, r9
mov r1, r10
bl locate
mov r0, #STDOUT
mov32 r1, playerBody
mov r2, #body_len
mov r7, #WRITE
svc #0
mov lr, r4
bx lr
.global gameLoop
gameLoop:
mov r4, lr
bl clear_screen
bl cursor_home
bl cursor_hide
mov lr, r4
bx lr
.global draw_spider
draw_spider:
mov r4, lr
mov r0, #5 @ For color code text
mov r1, #27 @ x pos
bl spider_color
mov r0, #2
bl locate
mov r0, #STDOUT
mov32 r1, spider
mov r2, #spider_Len
mov r7, #WRITE
svc #0
mov r0, #9
bl fore_color
mov lr, r4
bx lr
init_bullet:
mov r0, r9 @ y pos
mov r1, r10 @ x pos
strb r0, [r11, #0]
strb r1, [r11, #1]
b continue_while_loop
clear_bullet:
push {r0, r1, r7, lr}
bl locate
mov r0, #STDOUT
mov32 r1, clearChar
mov r2, #clear_body_len
mov r7, #WRITE
svc #0
pop {r0, r1, r7, pc}
draw_bullet:
mov r4, lr
ldrb r0, [r11, #0] @ y pos
ldrb r1, [r11, #1] @ x pos
cmp r0, #0 @ does this bullet exist?
bxeq lr
cmp r0, r9
blne clear_bullet
sub r0, r0, #1
// Store back on heap
strb r1, [r11, #1]
// Collision detection
cmp r0, #5 @ Where the spider reaches down to
blls check_collision
// don't display the bullet if bullet gets to the top
cmp r0, #1
movle r0, #0
strb r0, [r11, #0]
movle lr, r4
bxle lr
// otherwise display the bullet
bl locate @ This locate is erasing the r0 and r1
mov r0, #STDOUT
mov32 r1, bullet
mov r2, #bullet_Len
mov r7, #WRITE
svc #0
mov lr, r4
bx lr
check_collision:
cmp r1, #26 @ is it less than where the spider starts?
bxls lr @ then do nothing and go back
cmp r1, #35 @ is it greater than where the spider goes to the right?
bxhi lr @ Then do nothing and go back
beq hit_35_27 @ is it equal to 35?
cmp r1, #33
beq hit_33_29
cmp r1, #29
beq hit_33_29
cmp r1, #27
beq hit_35_27
b hit_34_32_31_30_28 @ All these are equal heights
hit_35_27:
cmp r0, #3
bxne lr
// Add to the score
bl hit
mov r0, #0 @ Kill the bullet
strb r0, [r11, #0]
mov lr, r4 @ put the return for the bullet function to lr
bx lr
hit_33_29:
cmp r0, #5
bxne lr
// Add to the score
bl hit
mov r0, #0 @ Kill the bullet
strb r0, [r11, #0]
mov lr, r4 @ put the return for the bullet function to lr
bx lr
hit_34_32_31_30_28:
cmp r0, #4
bxne lr
// Add to the score
bl hit
mov r0, #0 @ Kill the bullet
strb r0, [r11, #0]
mov lr, r4 @ put the return for the bullet function to lr
bx lr
.global reset_cursor
reset_cursor:
mov r4, lr
mov r0, #26 @ y pos
mov r1, #0 @ x pos
bl locate
mov lr, r4
bx lr
.global _start
_start:
mov r9, #21 @ posY - init
mov r10, #31 @ posX - init
bl gameLoop
bl term_init
bl draw_game
bl draw_spider
bl draw_player
sub sp, sp, #1
// Map that crap
mov r0, #0
mov r1, #2000
mov r2, #MAP_PROT
mov r3, #MAP_FLAGS
mov r4, #-1
mov r5, #0
mov r7, #MMAP2
svc #0
mov r11, r0 @ Set r11 as the location of the mapped memory
mov r0, #0
strb r0, [r11]
while_loop:
// get movement from user
mov r7, #READ
mov r0, #STDIN
mov r1, sp
mov r2, #1
svc #0
push {r0, r1}
bl draw_bullet
pop {r0, r1}
// If nothing was read, don't bother writing
cmp r0, #0
beq skip_print
ldrb r0, [sp]
cmp r0, #97 @ a
beq subLeft
cmp r0, #119 @ w
beq subDown
cmp r0, #115 @ s
beq addUp
cmp r0, #100 @ d
beq addRight
cmp r0, #32 @ space
beq init_bullet
continue_while_loop:
bl draw_player
bl draw_spider
skip_print:
ldrb r0, [sp]
push {r0, r1}
mov r0, #CLOCK_REALTIME
mov r1, #0
mov32 r2, timespec
mov r3, #0
movw r7, #CLOCK_NANOSLEEP
svc #0
pop {r0, r1}
cmp r0, #27 @ esc
bne while_loop
add sp, sp, #1
bl term_quit
bl cursor_show
bl highscore
bl reset_cursor
mov r7, #EXIT
svc #0
clear_player:
mov r4, lr
mov r0, r9
mov r1, r10
bl locate
mov r0, #STDOUT
mov32 r1, clearChar
mov r2, #clear_body_len
mov r7, #WRITE
svc #0
mov lr, r4
bx lr
addUp:
bl clear_player
cmp r9, #21 @ Added this to make guy not go past the floor
addlt r9, r9, #1
b continue_while_loop
subLeft:
bl clear_player
cmp r10, #2 @ Added this code to not make guy go past left wall
subgt r10, r10, #1
b continue_while_loop
addRight:
bl clear_player
cmp r10, #61 @ Added this code to not make guy go past Right Wall
addlt r10, r10, #1
b continue_while_loop
subDown:
bl clear_player
cmp r9, #2 @ Added this code to stop guy from going to high
subgt r9, r9, #1
b continue_while_loop