-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCworld.asm
354 lines (312 loc) · 7.4 KB
/
Cworld.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
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc movAll
call updatePos ;updating positions
call printArr
ret
endp movAll
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc printArr
dopush cx
call indReset
mov cx, 12 ;יש 12 שורות שבהם כביש או מדרכה יודפס
loop2:
call printLine
call rowNext
loop loop2
dopop cx
ret
endp printArr
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc printLine
dopush ax,cx,dx,si
call indUpdate
mov ax,[di] ;keeping Line position
mov [linePos], ax
call incCell
mov ax,[di]
;printing Road/grass in new line
call printRoadlGrass
;checking if grass
cmp ax, 0
jz grass
;checking if top line.
cmp [linePos], 1900h
je contLine
cmp [lastline], 1
jne contLine
;printing lines between roads
call printRoadLines
contLine:
;line is road so lastline =1
mov [lastline], 1
;moving the width and height to their matching variables
mov cx,[car_height] ;height
mov dx,[car_width] ;width
call dimensionsToVars
;updating pointer to point at direction of road
add [cell], 6
call indUpdate
mov dx, [di]
cmp dx, 0
jne printLeft
mov si, offset carRight
jmp contDirection
printLeft:
mov si, offset carLeft
contDirection:
;updating pointer to point at number of cars
call incCell
mov cx, [di]
carPrintLoop:
;car position
call incCell
mov ax, [di]
add ax, [linePos]
add ax, 320*2
mov [pos],ax
;saving car color
call incCell
mov bl, [di]
call carOring
loop carPrintLoop
jmp endLine
grass:
mov [lastline], 0 ;line is grass
endLine:
dopop si,dx,cx,ax
ret
endp printLine
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc carTimers
;enter-
;exit-
dopush cx,ax,bx
;Configuring index to point at timer cell.
call indReset
mov cx, 12
carTimerL:
push cx
call incCell
mov ax, [di]
cmp ax, 0
jz notRoad
;checking if Timer reached 0 (cars needs to move).
add [cell] ,4
call indUpdate
mov ax ,[di]
cmp ax ,0
jnz contCarT
;keeping position of Line.
sub [cell], 6
call indUpdate
mov bx, [di] ; אני עושה את זה כאן כי אני רוצה לעשות את זה רק אם הטיימר שווה 0
mov [linePos], bx
;reseting Timer cell.
add [cell], 4
call indUpdate
mov bx, [di]
call incCell
mov [di], bx
;pointing to Direction of road.
call incCell
mov dx, [di]
;saving number of cars.
call incCell
mov cx, [di]
;checking road Direction
cmp dx, 0
jne movLeft
loopMovRight:
;pointing to car position
call incCell
call movCarRight
loop loopMovRight
jmp contMov
movLeft:
loopMovLeft:
;pointing to car position
call incCell
call movCarLeft
loop loopMovLeft
contMov:
;pointing to timer
mov [cell], 6
call indUpdate
contCarT:
;decreacing timer
mov bx, 1
sub [di], bx
notRoad:
;going to nextRow
call rowNext
pop cx
loop carTimerL
dopop bx,ax,cx
ret
endp carTimers
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc movCarRight
dopush cx,ax,dx
;enter- line position in linePos. row position in bx.
;exit- prints car in new location.
;checking so car position won't pass 320.
mov ax,320
cmp [di],ax
jne range
sub [di],ax
range:
mov dx,1
add [di], dx
;calculating new position.
mov ax, [di]
add ax, [linePos]
add ax, 320*2
mov [pos],ax
;moving the width and height to their matching variables
mov cx,[car_height] ;height
mov dx,[car_width] ;width
call dimensionsToVars
;anding car to delete it.
mov si, offset carMask
call anding
;car color
call incCell
mov bl, [di]
;printing.
mov si, offset carRight ;car photo
call carOring
dopop dx,ax,cx
ret
endp movCarRight
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc movCarLeft
dopush cx,ax,dx
;enter- line position in linePos. row position in bx.
;exit- prints car in new location.
;checking so car position won't pass 0.
mov ax, -22
cmp [di],ax
jne inRange
mov ax,298
mov [di],ax
inRange:
mov dx,1
sub [di], dx
;calculating new position.
mov ax, [di]
add ax, [linePos]
add ax, 320*3
mov [pos],ax
;moving the width and height to their matching variables
mov cx,[car_height] ;height
mov dx,[car_width] ;width
call dimensionsToVars
push [pos] ;saving position
sub [pos], 320
add [height],1
;anding car to delete it.
mov si, offset carMask
call anding
pop [pos] ;returning position
;car color
call incCell
mov bl, [di]
;printing.
mov si, offset carLeft ;car photo
call carOring
dopop dx,ax,cx
ret
endp movCarLeft
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc carOring
;enter- si: the bitmap to print. height and width- bitmap dimensions. carColor- color of car
;exit- prints the bitmap without changing other parameters (excluding memory for screen).
dopush ax,cx,es,si
mov ax,0A000h
mov es,ax
mov di,[pos]
mov cx,[car_height]
CarOr:
push cx
mov cx,[car_width]
CarOr1:
lodsb
cmp al, 1
jne contCarOring
mov al, bl
contCarOring:
or [es:di],al
inc di
loop CarOr1
add di,320
sub di,[car_width]
pop cx
loop CarOr
dopop si,es,cx,ax
ret
endp carOring
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc printRoadLines ;Proc to print lines between roads
dopush ax,cx
mov ax,0A000h
mov es,ax
mov al,0ffh
mov di,[linePos]
mov cx,23 ;how many times
or4:
push cx
mov cx,10 ;length of one line
yy4:
or [es:di],al
inc di
loop yy4
add di,4
pop cx
loop or4
dopop cx,ax
ret
endp printRoadLines
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc printRoadlGrass
;enter-
;exit-
dopush cx,dx,si,ax
;initializing width+length
mov cx,[sr_height] ;height
mov dx,[sr_width] ;width
call dimensionsToVars
mov di, [linePos] ;position to di
mov [pos], di
mov si, offset sr_road ;initializing mask/road.
call anding ;masking/ printing road
;checking if road or grass
cmp ax, 0
jnz sr_ending
mov di, [linePos] ;position to di
mov [pos], di
mov si, offset sr_grass ;initializing grass bitmap.
call oring ;printing grass
sr_ending:
dopop ax,si,dx,cx
ret
endp printRoadlGrass
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc dimensionsToVars
;enter- height in cx. width in dx
;exit moves dimensions to their general used dimensions (widthh, height)
mov [height],cx
mov [widthh],dx
ret
endp dimensionsToVars
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''