-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharena.asm
381 lines (286 loc) · 7.48 KB
/
arena.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
makeArena:
;takes no paramters and makes the arena of the game depending upon level.
call initializeHurdlePositions
call makeBoundary
call makeSurface
cmp word[level], 1
jne noDisplayLevel1Hurdles
call makeHurdleLevel1
noDisplayLevel1Hurdles:
cmp word[level], 2
jne noDisplayLevel2Hurdles
call makeHurdleLevel2
noDisplayLevel2Hurdles:
ret
surfaceCell: dw 0x3700
makeSurface:
pusha
push es
push word 0xb800
pop es
mov ax, [surfaceCell]
mov bx, 23 ;23 rows to clear.
mov si, 162 ;second row second column
whileSurfacing:
mov di, si ;es:di
mov cx, 78 ;78 columns to clear.
cld
rep stosw
add si, 160 ;move to next row.
dec bx
jnz whileSurfacing
pop es
popa
ret
boundaryUpDownCell: dw 0x04cd
boundaryRightLeftCell: dw 0x04ba
makeBoundary:
;creates the boundary around the snake
pusha
push es
push word 0xb800
pop es
;draw upper boundary
mov di, 0 ;es:di = b800: 0
mov ax, [boundaryUpDownCell]
mov cx, 80
rep stosw
;draw lower boundary
mov di, 4000 - 160 ;es:di = b800:start of last row.
mov cx, 80
rep stosw
mov ax, [boundaryRightLeftCell]
;draw left boundary
mov bx, 0
mov cx, 25
whileDrawLeftBoundary:
mov [es:bx], ax
add bx, 160
loop whileDrawLeftBoundary
;draw right boundary
mov bx, 158 ;end of first row.
mov cx, 25
whileDrawRightBoundary:
mov [es:bx], ax
add bx, 160
loop whileDrawRightBoundary
popa
pop es
ret
collisionCheckBoundary:
;checks if the snake has collided with the boundary, if so, then it print a spot at that point else does nothing.
pusha
push es
push word 0
push word 0
push word[snake]
call calRowAndColumn
pop ax ;col
pop bx ;row
cmp ax, 0
je collisionWithBoundary
cmp ax, 79
je collisionWithBoundary
cmp bx, 0
je collisionWithBoundary
cmp bx, 24
jne noCollisionWithBoundary
collisionWithBoundary:
mov ax, 0xb800
mov es, ax
mov bx, [snake]
mov word[es:bx], 0x0720
call updateLives
noCollisionWithBoundary:
pop es
popa
ret
;check logic of initializeHurdlePositions for reasons of these memory declarations.
level1hurdle1: dw 0
level1hurdle2: dw 0
level1hurdle1row: dw 5
level1hurdle1col: dw 9
level1hurdle2row: dw 19
level1hurdle2col: dw 9
initializeHurdlePositions:
;initalizes the values of hurdles and portals that are used by the functions of level 1 and level2. The reason for not hardcoding
;these values was to be flexible. The reason for not having the level1 and level2 calculate these themselves was optimization.
push ax
push word 0
push word [level1hurdle1row]
push word [level1hurdle1col]
call calLocation
pop ax ;address of 10th row, 10th column
mov [level1hurdle1], ax
push word 0
push word [level1hurdle2row]
push word [level1hurdle2col]
call calLocation
pop ax ;address of 20th row 10th column.
mov [level1hurdle2], ax
push word 0
push word[level2hurlderow]
push word[level2hurldecol]
call calLocation
pop ax
mov [level2hurdle], ax
push word 0
push word 4
push word 4 ;row 2 col 2
call calLocation
pop ax
mov [portalLE], ax
push word 0
push word 19
push word 4 ;row 24 col 2
call calLocation
pop ax
mov [portalLL], ax
push word 0
push word 4
push word 67 ;row 2 col 79
call calLocation
pop ax
mov [portalRE], ax
push word 0
push word 19
push word 67 ;row 24, col 79
call calLocation
pop ax
mov [portalRL], ax
pop ax
ret
makeHurdleLevel1:
;makes hurdles for level1. It has two horizontal bars.
pusha
push es
push word 0xb800
pop es
cld
mov ax, [boundaryUpDownCell] ;blank color.
mov di, [level1hurdle1] ;es:di
mov cx, 60
rep stosw
mov di, [level1hurdle2]
mov cx, 60
rep stosw
pop es
popa
ret
level2hurdle: dw 0
level2hurldecol: dw 39
level2hurlderow: dw 0
portals: ;extra label for iteration.
portalLE: dw 0
portalLL: dw 0
portalRE: dw 0
portalRL: dw 0
portalEnterCell: dw 0x040a
portalLeaveCell: dw 0x020a
makeHurdleLevel2:
pusha
push es
push word 0xb800
pop es
mov bx, [level2hurdle]
mov cx, 25
mov ax, [boundaryRightLeftCell]
whilePrintingHurdleLevel2
mov word[es:bx], ax
add bx, 160
loop whilePrintingHurdleLevel2
mov bx, [portalLE]
mov ax, [portalEnterCell]
mov word[es:bx], ax
mov bx, [portalLL]
mov ax, [portalLeaveCell]
mov word[es:bx], ax
mov bx, [portalRE]
mov ax, [portalEnterCell]
mov word[es:bx], ax
mov bx, [portalRL]
mov ax, [portalLeaveCell]
mov word[es:bx], ax
pop es
popa
ret
generalCollisionWithLevel1Hurdles:
;takes an address on video memory in stack, and returns 1 if it collides with any of level1 hurdles.
;returns 0 otherwise
push bp
mov bp, sp
pusha
mov word[bp + 6], 0 ;return spot.
push word 0
push word 0
push word[bp + 4]
call calRowAndColumn ;gets the rows and column corresponding to the position of food on screen for easy comparison with boundary.
pop ax ;col
pop bx ;row
mov cx, [level1hurdle1col]
add cx, 59
cmp bx, [level1hurdle1row]
jne generalCollisionL1H2Check
cmp ax, [level1hurdle1col]
jl generalCollisionL1H2Check
cmp ax, cx
jg generalCollisionL1H2Check
mov word[bp + 6], 1 ;in case it has collided with hurdle 1 of level 1.
jmp generalCollisionWithLevel1HurdlesEnd
generalCollisionL1H2Check:
mov cx, [level1hurdle1col]
add cx, 59
cmp bx, [level1hurdle2row]
jne generalCollisionWithLevel1HurdlesEnd
cmp ax, [level1hurdle2col]
jl generalCollisionWithLevel1HurdlesEnd
cmp ax, cx
jg generalCollisionWithLevel1HurdlesEnd
mov word[bp + 6], 1 ;collided with hurdle 2 of level 1
generalCollisionWithLevel1HurdlesEnd:
popa
mov sp, bp
pop bp
ret 2
generalCollisionWithLevel2Hurdles:
;takes address of a memory as its input paramter. returns 1 if i collides with the center bar, 0 otherwise.
push bp
mov bp, sp
pusha
mov word[bp + 6], 0 ;return spot.
push word 0
push word 0
push word[bp + 4]
call calRowAndColumn ;gets the rows and column corresponding to the position of food on screen for easy comparison with boundary.
pop ax ;col
pop bx ;row
cmp ax, [level2hurldecol]
jne generalCollisionWithLevel2HurdlesEnd
mov word[bp + 6], 1
generalCollisionWithLevel2HurdlesEnd:
popa
mov sp, bp
pop bp
ret 2
generalCollisionWithPortals:
;takes an address on video memory as input. returns 0 if no collision with portal has occured otherwise returns the word present
;at the portal with which it collided.
push bp
mov bp, sp
pusha
mov word[bp + 6], 0 ;return value.
mov ax, [bp + 4] ;input address.
mov cx, 4
mov bx, portals
whileCheckingPortals:
cmp ax, [bx]
jne portalNotCollided
mov dx, [bx]
mov [bp + 6], dx
portalNotCollided:
add bx, 2
loop whileCheckingPortals
popa
mov sp, bp
pop bp
ret 2