-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadFile.asm
370 lines (277 loc) · 7.7 KB
/
readFile.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
INCLUDE macros.inc
EXTRN filename:BYTE
EXTRN flag_direction_temp:BYTE ;0->up 1->down 2->left 3->right
EXTRN xc_Car:WORD
EXTRN yc_Car:WORD
;times of reduce the blue car image is 11, times of reduce the red car image is 11
public CAR
; public Screen
;---------------------------------------
.MODEL SMALL
;---------------------------------------
.DATA
; backGround db 'Grass.bin',0
; BackGround_size equ 320*200
; backGround_buffer db BackGround_size dup(?)
; GROUND_HEIGHT equ 200
; GROUND_WIDTH equ 320
buffer_size equ 35
buffer db buffer_size dup(?)
errtext db "YOUR ERROR MESSAGE", 10, "$"
start_Xtemp dw 155
start_Ytemp dw 100
CAR_HEIGHT equ 3;YOUR HEIGHT
CAR_WIDTH equ 2;YOUR WIDTH
SCREEN_WIDTH equ 320
SCREEN_HEIGHT equ 200
;---------------------------------------
.code
;description
; Screen proc far
; mov ah, 03Dh
; mov al, 0 ; open attribute: 0 - read-only, 1 - write-only, 2 -read&write
; mov dx, offset backGround ; ASCIIZ filename to open
; int 21h
; ;jc error_exit ; Jump if carry flag set (error)
; mov bx, AX
; mov ah, 03Fh
; mov cx, BackGround_size ; number of bytes to read
; mov dx, offset backGround_buffer ; were to put read data
; int 21h
; ; Check for errors
; ;jc error_exit ; Jump if carry flag set (error)
; mov ah, 3Eh ; DOS function: close file
; INT 21H
; MOV AX, 0A000h
; MOV ES, AX
; mov si,offset backGround_buffer
; mov di,0
; call drawScreen
; ret
; Screen endp
; ;description
; drawScreen PROC
; MOV DX,GROUND_HEIGHT
; REPEAT_BACK:
; MOV CX,GROUND_WIDTH
; DRAW_PIXELS_BACK:
; ; Check if the byte at [SI] is 250 TO SKIP IT
; mov AH,BYTE PTR [SI]
; CMP BYTE PTR [SI], 250
; JE SKIP_DRAW_BACK
; ; Draw the pixel
; MOVSB ;increment di after moving car pixel from si to di(screen) and point (x,y) is top left in BACK movement
; JMP DECC_BACK
; SKIP_DRAW_BACK:
; INC DI
; INC SI
; DECC_BACK:
; DEC CX
; JNZ DRAW_PIXELS_BACK
; ADD DI,SCREEN_WIDTH - GROUND_WIDTH
; DEC DX
; JNZ REPEAT_BACK
; RET
; drawScreen ENDP
CAR PROC FAR
;call Clear_old
push ax
push bx
push cx
push dx
push si
push di
mov ah, 03Dh
mov al, 0 ; open attribute: 0 - read-only, 1 - write-only, 2 -read&write
mov dx, offset filename ; ASCIIZ filename to open
int 21h
;jc error_exit ; Jump if carry flag set (error)
mov bx, AX
mov ah, 03Fh
mov cx, buffer_size ; number of bytes to read
mov dx, offset buffer ; were to put read data
int 21h
; Check for errors
;jc error_exit ; Jump if carry flag set (error)
mov ah, 3Eh ; DOS function: close file
INT 21H
cmp flag_direction_temp,0
jnz not_Up
;dec word ptr yc_Car
mov bx,word ptr xc_Car
sub bx,CAR_WIDTH
mov start_Xtemp,bx
mov bx,word ptr yc_Car
sub bx,CAR_HEIGHT
mov start_ytemp,bx
not_Up:
cmp flag_direction_temp,1
jnz not_Down
;inc word ptr yc_Car
mov bx,word ptr xc_Car
add bx,CAR_WIDTH
mov start_Xtemp,bx
mov bx,word ptr yc_Car
add bx,CAR_HEIGHT
mov start_ytemp,bx
not_down:
cmp flag_direction_temp,3
jnz not_Left
;dec word ptr xc_Car
mov bx,word ptr xc_Car
sub bx,CAR_HEIGHT
mov start_Xtemp,bx
mov bx,word ptr yc_Car
add bx,CAR_WIDTH
mov start_ytemp,bx
add start_Xtemp,6
sub start_Ytemp,4
not_Left:
cmp flag_direction_temp,2
jnz not_Right
;inc word ptr xc_Car
mov bx,word ptr xc_Car
add bx,CAR_HEIGHT
mov start_Xtemp,bx
mov bx,word ptr yc_Car
sub bx,CAR_WIDTH
mov start_ytemp,bx
sub start_Xtemp,6
add start_Ytemp,4
not_Right:
mov bx,320
mov ax,start_Ytemp
mul bx
add ax,start_Xtemp
MOV DI,ax
MOV AX, 0A000h
MOV ES, AX
;dec X2_temp
;dec Y2_temp
;drawCar X1_temp,Y1_temp,X2_temp,Y2_temp,01h
MOV SI,offset buffer
cmp flag_direction_temp,0
jnz not_Drawup
CALL drawImageUP
jmp exit
not_Drawup:
cmp flag_direction_temp,1
jnz not_Drawdown
CALL drawImageDown
jmp exit
not_Drawdown:
cmp flag_direction_temp,2
jnz not_Drawleft
CALL drawImageLeft
jmp exit
not_Drawleft:
CALL drawImageRight
exit:
pop di
pop si
pop dx
pop cx
pop bx
pop ax
RET
CAR ENDP
drawImageUP PROC
;MOV SI,offset buffer
MOV DX,2*CAR_HEIGHT+1
REPEAT_UP:
MOV CX,2*CAR_WIDTH+1
DRAW_PIXELS_UP:
; Check if the byte at [SI] is 250 TO SKIP IT
mov AH,BYTE PTR [SI]
CMP BYTE PTR [SI], 250
JE SKIP_DRAW_UP
; Draw the pixel
MOVSB ;increment di after moving car pixel from si to di(screen) and point (x,y) is top left in up movement
JMP DECC_UP
SKIP_DRAW_UP:
INC DI
INC SI
DECC_UP:
DEC CX
JNZ DRAW_PIXELS_UP
ADD DI,SCREEN_WIDTH - (2*CAR_WIDTH+1)
DEC DX
JNZ REPEAT_UP
RET
drawImageUP ENDP
drawImageDown PROC
;MOV SI,offset buffer
MOV DX,2*CAR_HEIGHT+1
REPEAT_DOWN:
MOV CX,2*CAR_WIDTH+1
DRAW_PIXELS_DOWN:
; Check if the byte at [SI] is 250 TO SKIP IT
mov AH,BYTE PTR [SI]
CMP BYTE PTR [SI], 250
JE SKIP_DRAW_DOWN
; Draw the pixel
MOVSB ;increment di after moving car pixel from si to di(screen)
sub di,2 ;as in down movement the point (x,y) in bottom right and subtract two (one for increment due to MOVSB and one for move to The place before it)
JMP DECC_DOWN
SKIP_DRAW_DOWN:
DEC DI
INC SI
DECC_DOWN:
DEC CX
JNZ DRAW_PIXELS_DOWN
SUB DI,SCREEN_WIDTH - (2*CAR_WIDTH+1)
DEC DX
JNZ REPEAT_DOWN
RET
drawImageDown ENDP
drawImageRight PROC
;MOV SI,offset buffer
MOV DX, 2*CAR_HEIGHT+1
REPEAT_RIGHT:
MOV CX, 2*CAR_WIDTH+1
DRAW_PIXELS_RIGHT:
; Check if the byte at [SI] is 250 TO SKIP IT
mov AH,BYTE PTR [SI]
CMP BYTE PTR [SI], 250
JE SKIP_DRAW_RIGHT
; Draw the pixel
MOVSB ;increment di after moving car pixel from si to di(screen) and ponit (x,y) is top right in right movement
add di,SCREEN_WIDTH-1
JMP DECC_RIGHT
SKIP_DRAW_RIGHT:
add di,SCREEN_WIDTH
INC SI
DECC_RIGHT:
DEC CX
JNZ DRAW_PIXELS_RIGHT
SUB DI,SCREEN_WIDTH * (2*CAR_WIDTH+1) +1
DEC DX
JNZ REPEAT_RIGHT
RET
drawImageRight ENDP
drawImageLeft PROC
;MOV SI,offset buffer
MOV DX, 2*CAR_HEIGHT+1
REPEAT_LEFT:
MOV CX, 2*CAR_WIDTH+1
DRAW_PIXELS_LEFT:
; Check if the byte at [SI] is 250 TO SKIP IT
mov AH,BYTE PTR [SI]
CMP BYTE PTR [SI], 250
JE SKIP_DRAW_LEFT
; Draw the pixel
MOVSB ;increment di after moving car pixel from si to di(screen) and ponit (x,y) is bottom left in left movement
sub di,SCREEN_WIDTH +1
JMP DECC_LEFT
SKIP_DRAW_LEFT:
sub di,SCREEN_WIDTH
INC SI
DECC_LEFT:
DEC CX
JNZ DRAW_PIXELS_LEFT
add DI,SCREEN_WIDTH * (2*CAR_WIDTH+1) +1
DEC DX
JNZ REPEAT_LEFT
RET
drawImageLeft ENDP
END