Rev 485 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 485 | Rev 539 | ||
---|---|---|---|
1 | ; flat assembler |
1 | ; flat assembler |
2 | ; Copyright (c) 1999-2006, Tomasz Grysztar |
2 | ; Copyright (c) 1999-2006, Tomasz Grysztar |
3 | ; All rights reserved. |
3 | ; All rights reserved. |
4 | ; |
4 | ; |
5 | ; MenuetOS system.inc by VT |
5 | ; MenuetOS system.inc by VT |
6 | 6 | ||
7 | struc FILEIO |
7 | struc FILEIO |
8 | { .cmd dd ? |
8 | { .cmd dd ? |
9 | .offset dd ? |
9 | .offset dd ? |
10 | dd ? |
10 | dd ? |
11 | .count dd ? |
11 | .count dd ? |
12 | .buff dd ? |
12 | .buff dd ? |
13 | db ? |
13 | db ? |
14 | .name dd ? |
14 | .name dd ? |
15 | }; |
15 | }; |
16 | 16 | ||
17 | struc FILEINFO |
17 | struc FILEINFO |
18 | { .attr dd ? |
18 | { .attr dd ? |
19 | .flags dd ? |
19 | .flags dd ? |
20 | .cr_time dd ? |
20 | .cr_time dd ? |
21 | .cr_date dd ? |
21 | .cr_date dd ? |
22 | .acc_time dd ? |
22 | .acc_time dd ? |
23 | .acc_date dd ? |
23 | .acc_date dd ? |
24 | .mod_time dd ? |
24 | .mod_time dd ? |
25 | .mod_date dd ? |
25 | .mod_date dd ? |
26 | .size dd ? |
26 | .size dd ? |
27 | } |
27 | } |
28 | 28 | ||
29 | 29 | ||
30 | 30 | ||
31 | ;file_info_open: dd 0,0,0xffffff,0x20000,0xf0000 |
31 | ;file_info_open: dd 0,0,0xffffff,0x20000,0xf0000 |
32 | fullpath_open: ; db '/RD/1/EXAMPLE.ASM' |
32 | fullpath_open: ; db '/RD/1/EXAMPLE.ASM' |
33 | times MAX_PATH db 0 |
33 | times MAX_PATH db 0 |
34 | 34 | ||
35 | 35 | ||
36 | ;file_info_write: dd 1,0,0,0,0xf0000 |
36 | ;file_info_write: dd 1,0,0,0,0xf0000 |
37 | fullpath_write:; db '/RD/1/EXAMPLE' |
37 | fullpath_write:; db '/RD/1/EXAMPLE' |
38 | times MAX_PATH db 0 |
38 | times MAX_PATH db 0 |
39 | 39 | ||
40 | file_info_start: ;this part is already rewrited to 70th function |
40 | file_info_start: ;this part is already rewrited to 70th function |
41 | dd 7 |
41 | dd 7 |
42 | dd 0 |
42 | dd 0 |
43 | dd 0 |
43 | dd 0 |
44 | dd 0 |
44 | dd 0 |
45 | dd 0 |
45 | dd 0 |
46 | fullpath_start: ; db '/RD/1/EXAMPLE' |
46 | fullpath_start: ; db '/RD/1/EXAMPLE' |
47 | times MAX_PATH db 0 |
47 | times MAX_PATH db 0 |
48 | 48 | ||
49 | _ramdisk db '/RD/1/' |
49 | _ramdisk db '/sys/' |
50 | filepos dd 0x0 |
50 | filepos dd 0x0 |
51 | 51 | ||
52 | ; info by Privalov: starting from FASM 1.51 |
52 | ; info by Privalov: starting from FASM 1.51 |
53 | ; ~3/8 - additional memory |
53 | ; ~3/8 - additional memory |
54 | ; ~5/8 - main memory |
54 | ; ~5/8 - main memory |
55 | init_memory: |
55 | init_memory: |
56 | mov [memory_start],0x100000 |
56 | mov [memory_start],0x100000 |
57 | mov [memory_end],0x100000+(APP_MEMORY-0x100000)/8*5 |
57 | mov [memory_end],0x100000+(APP_MEMORY-0x100000)/8*5 |
58 | mov [additional_memory],0x100000+(APP_MEMORY-0x100000)/8*5 |
58 | mov [additional_memory],0x100000+(APP_MEMORY-0x100000)/8*5 |
59 | mov [additional_memory_end],APP_MEMORY |
59 | mov [additional_memory_end],APP_MEMORY |
60 | ret |
60 | ret |
61 | 61 | ||
62 | exit_program: |
62 | exit_program: |
63 | cmp [_mode],NORMAL_MODE |
63 | cmp [_mode],NORMAL_MODE |
64 | je still |
64 | je still |
65 | or eax,-1 |
65 | or eax,-1 |
66 | mcall |
66 | mcall |
67 | 67 | ||
68 | make_timestamp: |
68 | make_timestamp: |
69 | push ebx |
69 | push ebx |
70 | mcall 26,9 |
70 | mcall 26,9 |
71 | imul eax,10 |
71 | imul eax,10 |
72 | pop ebx |
72 | pop ebx |
73 | ret |
73 | ret |
74 | 74 | ||
75 | get_environment_variable: |
75 | get_environment_variable: |
76 | mov ecx,[memory_end] |
76 | mov ecx,[memory_end] |
77 | sub ecx,edi |
77 | sub ecx,edi |
78 | cmp ecx,7 |
78 | cmp ecx,7 |
79 | jb out_of_memory |
79 | jb out_of_memory |
80 | cmp dword[esi],'INCL' |
80 | cmp dword[esi],'INCL' |
81 | jne .finish |
81 | jne .finish |
82 | mov esi,_ramdisk |
82 | mov esi,_ramdisk |
83 | mov ecx,6 |
83 | mov ecx,6 |
84 | cld |
84 | cld |
85 | rep movsb |
85 | rep movsb |
86 | .finish: |
86 | .finish: |
87 | ; stc |
87 | ; stc |
88 | ret |
88 | ret |
89 | 89 | ||
90 | alloc_handle: |
90 | alloc_handle: |
91 | call make_fullpaths |
91 | call make_fullpaths |
92 | mov ebx, fileinfos+4 |
92 | mov ebx, fileinfos+4 |
93 | @@: |
93 | @@: |
94 | cmp dword [ebx], -1 |
94 | cmp dword [ebx], -1 |
95 | jz .found |
95 | jz .found |
96 | add ebx, 4+20+MAX_PATH |
96 | add ebx, 4+20+MAX_PATH |
97 | cmp ebx, fileinfos_end |
97 | cmp ebx, fileinfos_end |
98 | jb @b |
98 | jb @b |
99 | stc |
99 | stc |
100 | ret |
100 | ret |
101 | .found: |
101 | .found: |
102 | and dword [ebx+4], 0 |
102 | and dword [ebx+4], 0 |
103 | and dword [ebx+8], 0 |
103 | and dword [ebx+8], 0 |
104 | push esi edi ecx |
104 | push esi edi ecx |
105 | mov esi, fullpath_open |
105 | mov esi, fullpath_open |
106 | lea edi, [ebx+20] |
106 | lea edi, [ebx+20] |
107 | mov ecx, MAX_PATH |
107 | mov ecx, MAX_PATH |
108 | rep movsb |
108 | rep movsb |
109 | pop ecx edi esi |
109 | pop ecx edi esi |
110 | ret ; CF=0 |
110 | ret ; CF=0 |
111 | 111 | ||
112 | create: |
112 | create: |
113 | call alloc_handle |
113 | call alloc_handle |
114 | jc .ret |
114 | jc .ret |
115 | and dword [ebx-4], 0 |
115 | and dword [ebx-4], 0 |
116 | mov dword [ebx], 2 |
116 | mov dword [ebx], 2 |
117 | .ret: |
117 | .ret: |
118 | ret |
118 | ret |
119 | 119 | ||
120 | 120 | ||
121 | open: |
121 | open: |
122 | ; call make_fullpaths |
122 | ; call make_fullpaths |
123 | 123 | ||
124 | ;; mov eax,fullpath_open |
124 | ;; mov eax,fullpath_open |
125 | ;; DEBUGF '"%s"\n',eax |
125 | ;; DEBUGF '"%s"\n',eax |
126 | 126 | ||
127 | ; mov dword[file_info_open+8],-1 |
127 | ; mov dword[file_info_open+8],-1 |
128 | ; mcall 58,file_info_open |
128 | ; mcall 58,file_info_open |
129 | ; or eax,eax ; found |
129 | ; or eax,eax ; found |
130 | ; jz @f |
130 | ; jz @f |
131 | ; cmp eax,6 |
131 | ; cmp eax,6 |
132 | ; jne file_error |
132 | ; jne file_error |
133 | ;@@: mov [filesize],ebx |
133 | ;@@: mov [filesize],ebx |
134 | ; clc |
134 | ; clc |
135 | ; ret |
135 | ; ret |
136 | ;file_error: |
136 | ;file_error: |
137 | ; stc |
137 | ; stc |
138 | ; ret |
138 | ; ret |
139 | 139 | ||
140 | call alloc_handle |
140 | call alloc_handle |
141 | jc .ret |
141 | jc .ret |
142 | mov dword [ebx], 5 |
142 | mov dword [ebx], 5 |
143 | and dword [ebx+12], 0 |
143 | and dword [ebx+12], 0 |
144 | mov dword [ebx+16], fileinfo |
144 | mov dword [ebx+16], fileinfo |
145 | mov eax, 70 |
145 | mov eax, 70 |
146 | push ebx |
146 | push ebx |
147 | mcall |
147 | mcall |
148 | pop ebx |
148 | pop ebx |
149 | test eax, eax |
149 | test eax, eax |
150 | jnz .fail |
150 | jnz .fail |
151 | mov eax, [fileinfo.size] |
151 | mov eax, [fileinfo.size] |
152 | mov [ebx-4], eax |
152 | mov [ebx-4], eax |
153 | and dword [ebx], 0 |
153 | and dword [ebx], 0 |
154 | .ret: |
154 | .ret: |
155 | ret |
155 | ret |
156 | .fail: |
156 | .fail: |
157 | or dword [ebx], -1 ; close handle |
157 | or dword [ebx], -1 ; close handle |
158 | stc |
158 | stc |
159 | ret |
159 | ret |
160 | 160 | ||
161 | read: |
161 | read: |
162 | ; pusha |
162 | ; pusha |
163 | ; mov edi,edx |
163 | ; mov edi,edx |
164 | ; mov esi,[filepos] |
164 | ; mov esi,[filepos] |
165 | ; add esi,0x20000 |
165 | ; add esi,0x20000 |
166 | ; cld |
166 | ; cld |
167 | ; rep movsb |
167 | ; rep movsb |
168 | ; popa |
168 | ; popa |
169 | ;; ret |
169 | ;; ret |
170 | 170 | ||
171 | mov [ebx+12], ecx |
171 | mov [ebx+12], ecx |
172 | mov [ebx+16], edx |
172 | mov [ebx+16], edx |
173 | push ebx |
173 | push ebx |
174 | mov eax, 70 |
174 | mov eax, 70 |
175 | mcall |
175 | mcall |
176 | xchg eax, [esp] |
176 | xchg eax, [esp] |
177 | add [eax+4], ebx |
177 | add [eax+4], ebx |
178 | adc [eax+8], dword 0 |
178 | adc [eax+8], dword 0 |
179 | mov ebx, eax |
179 | mov ebx, eax |
180 | pop eax |
180 | pop eax |
181 | test eax, eax |
181 | test eax, eax |
182 | jz .ok |
182 | jz .ok |
183 | cmp eax, 6 |
183 | cmp eax, 6 |
184 | jz .ok |
184 | jz .ok |
185 | stc |
185 | stc |
186 | .ok: |
186 | .ok: |
187 | ret |
187 | ret |
188 | 188 | ||
189 | close: |
189 | close: |
190 | or dword [ebx], -1 |
190 | or dword [ebx], -1 |
191 | ret |
191 | ret |
192 | 192 | ||
193 | 193 | ||
194 | ; ebx file handle |
194 | ; ebx file handle |
195 | ; ecx count of bytes to write |
195 | ; ecx count of bytes to write |
196 | ; edx pointer to buffer |
196 | ; edx pointer to buffer |
197 | write: |
197 | write: |
198 | ; pusha |
198 | ; pusha |
199 | ; mov [file_info_write+8],ecx |
199 | ; mov [file_info_write+8],ecx |
200 | ; mov [file_info_write+12],edx |
200 | ; mov [file_info_write+12],edx |
201 | ; mov [filesize],edx |
201 | ; mov [filesize],edx |
202 | ; mov eax,58 |
202 | ; mov eax,58 |
203 | ; mov ebx,file_info_write |
203 | ; mov ebx,file_info_write |
204 | ; mcall |
204 | ; mcall |
205 | ; popa |
205 | ; popa |
206 | ; ret |
206 | ; ret |
207 | 207 | ||
208 | mov [ebx+12], ecx |
208 | mov [ebx+12], ecx |
209 | mov [ebx+16], edx |
209 | mov [ebx+16], edx |
210 | push ebx |
210 | push ebx |
211 | mov eax, 70 |
211 | mov eax, 70 |
212 | mcall |
212 | mcall |
213 | xchg eax, [esp] |
213 | xchg eax, [esp] |
214 | add [eax+4], ebx |
214 | add [eax+4], ebx |
215 | adc [eax+8], dword 0 |
215 | adc [eax+8], dword 0 |
216 | mov ebx, eax |
216 | mov ebx, eax |
217 | pop eax |
217 | pop eax |
218 | mov byte [ebx], 3 |
218 | mov byte [ebx], 3 |
219 | cmp eax, 1 |
219 | cmp eax, 1 |
220 | cmc |
220 | cmc |
221 | ret |
221 | ret |
222 | 222 | ||
223 | make_fullpaths: |
223 | make_fullpaths: |
224 | pusha |
224 | pusha |
225 | push edx |
225 | push edx |
226 | 226 | ||
227 | mov esi,path ; open |
227 | mov esi,path ; open |
228 | ; DEBUGF " '%s'",esi |
228 | ; DEBUGF " '%s'",esi |
229 | mov edi,fullpath_open |
229 | mov edi,fullpath_open |
230 | cld |
230 | cld |
231 | newc1: |
231 | newc1: |
232 | movsb |
232 | movsb |
233 | cmp byte[esi],0;' ' |
233 | cmp byte[esi],0;' ' |
234 | jne newc1 |
234 | jne newc1 |
235 | mov esi,[esp] |
235 | mov esi,[esp] |
236 | 236 | ||
237 | cmp byte[esi],'/' |
237 | cmp byte[esi],'/' |
238 | jne @f |
238 | jne @f |
239 | mov edi,fullpath_open |
239 | mov edi,fullpath_open |
240 | 240 | ||
241 | @@: |
241 | @@: |
242 | lodsb |
242 | lodsb |
243 | stosb |
243 | stosb |
244 | cmp al,0 |
244 | cmp al,0 |
245 | jne @b |
245 | jne @b |
246 | ; mov ecx,12 |
246 | ; mov ecx,12 |
247 | ; cld |
247 | ; cld |
248 | ; rep movsb |
248 | ; rep movsb |
249 | ; mov byte[edi],0 |
249 | ; mov byte[edi],0 |
250 | 250 | ||
251 | mov esi,path ; write |
251 | mov esi,path ; write |
252 | mov edi,fullpath_write |
252 | mov edi,fullpath_write |
253 | cld |
253 | cld |
254 | newc2: |
254 | newc2: |
255 | movsb |
255 | movsb |
256 | cmp byte[esi],0;' ' |
256 | cmp byte[esi],0;' ' |
257 | jne newc2 |
257 | jne newc2 |
258 | mov esi,[esp] |
258 | mov esi,[esp] |
259 | 259 | ||
260 | cmp byte[esi],'/' |
260 | cmp byte[esi],'/' |
261 | jne @f |
261 | jne @f |
262 | mov edi,fullpath_write |
262 | mov edi,fullpath_write |
263 | 263 | ||
264 | @@: |
264 | @@: |
265 | lodsb |
265 | lodsb |
266 | stosb |
266 | stosb |
267 | cmp al,0 |
267 | cmp al,0 |
268 | jne @b |
268 | jne @b |
269 | ; mov ecx,12 |
269 | ; mov ecx,12 |
270 | ; cld |
270 | ; cld |
271 | ; rep movsb |
271 | ; rep movsb |
272 | ; mov byte[edi],0 |
272 | ; mov byte[edi],0 |
273 | 273 | ||
274 | mov esi,path ; start |
274 | mov esi,path ; start |
275 | mov edi,fullpath_start |
275 | mov edi,fullpath_start |
276 | cld |
276 | cld |
277 | newc3: |
277 | newc3: |
278 | movsb |
278 | movsb |
279 | cmp byte[esi],0;' ' |
279 | cmp byte[esi],0;' ' |
280 | jne newc3 |
280 | jne newc3 |
281 | ; mov esi,[esp] |
281 | ; mov esi,[esp] |
282 | pop esi |
282 | pop esi |
283 | 283 | ||
284 | cmp byte[esi],'/' |
284 | cmp byte[esi],'/' |
285 | jne @f |
285 | jne @f |
286 | mov edi,fullpath_start |
286 | mov edi,fullpath_start |
287 | 287 | ||
288 | @@: |
288 | @@: |
289 | lodsb |
289 | lodsb |
290 | stosb |
290 | stosb |
291 | cmp al,0 |
291 | cmp al,0 |
292 | jne @b |
292 | jne @b |
293 | ; mov ecx,12 |
293 | ; mov ecx,12 |
294 | ; cld |
294 | ; cld |
295 | ; rep movsb |
295 | ; rep movsb |
296 | ; mov byte[edi],0 |
296 | ; mov byte[edi],0 |
297 | 297 | ||
298 | ; add esp,4 |
298 | ; add esp,4 |
299 | popa |
299 | popa |
300 | ret |
300 | ret |
301 | 301 | ||
302 | 302 | ||
303 | 303 | ||
304 | lseek: |
304 | lseek: |
305 | cmp al,0 |
305 | cmp al,0 |
306 | jnz @f |
306 | jnz @f |
307 | and dword [ebx+4], 0 |
307 | and dword [ebx+4], 0 |
308 | and dword [ebx+8], 0 |
308 | and dword [ebx+8], 0 |
309 | @@: cmp al,2 |
309 | @@: cmp al,2 |
310 | jnz @f |
310 | jnz @f |
311 | mov eax, [ebx-4] |
311 | mov eax, [ebx-4] |
312 | mov [ebx+4], eax |
312 | mov [ebx+4], eax |
313 | and dword [ebx+8], 0 |
313 | and dword [ebx+8], 0 |
314 | @@: add dword [ebx+4], edx |
314 | @@: add dword [ebx+4], edx |
315 | adc dword [ebx+8], 0 |
315 | adc dword [ebx+8], 0 |
316 | ret |
316 | ret |
317 | 317 | ||
318 | display_character: |
318 | display_character: |
319 | pusha |
319 | pusha |
320 | cmp [_mode],NORMAL_MODE |
320 | cmp [_mode],NORMAL_MODE |
321 | jne @f |
321 | jne @f |
322 | cmp dl,13 |
322 | cmp dl,13 |
323 | jz dc2 |
323 | jz dc2 |
324 | cmp dl,0xa |
324 | cmp dl,0xa |
325 | jnz dc1 |
325 | jnz dc1 |
326 | and [textxy],0x0000FFFF |
326 | and [textxy],0x0000FFFF |
327 | add [textxy], 7 shl 16 +53 and 0xFFFF0000 + 10 |
327 | add [textxy], 7 shl 16 +53 and 0xFFFF0000 + 10 |
328 | dc2: |
328 | dc2: |
329 | popa |
329 | popa |
330 | ret |
330 | ret |
331 | dc1: |
331 | dc1: |
332 | mov eax,[textxy] |
332 | mov eax,[textxy] |
333 | cmp ax,word[bottom_right] |
333 | cmp ax,word[bottom_right] |
334 | ja dc2 |
334 | ja dc2 |
335 | shr eax,16 |
335 | shr eax,16 |
336 | cmp ax,word[bottom_right+2] |
336 | cmp ax,word[bottom_right+2] |
337 | ja dc2 |
337 | ja dc2 |
338 | mov [dc],dl |
338 | mov [dc],dl |
339 | mcall 4,[textxy],[sc.work_text],dc,1 |
339 | mcall 4,[textxy],[sc.work_text],dc,1 |
340 | add [textxy],0x00060000 |
340 | add [textxy],0x00060000 |
341 | popa |
341 | popa |
342 | ret |
342 | ret |
343 | @@: |
343 | @@: |
344 | mov eax,63 |
344 | mov eax,63 |
345 | mov ebx,1 |
345 | mov ebx,1 |
346 | mov cl,dl |
346 | mov cl,dl |
347 | mcall |
347 | mcall |
348 | popa |
348 | popa |
349 | ret |
349 | ret |
350 | 350 | ||
351 | 351 | ||
352 | display_string: |
352 | display_string: |
353 | pusha |
353 | pusha |
354 | @@: |
354 | @@: |
355 | cmp byte[esi],0 |
355 | cmp byte[esi],0 |
356 | je @f |
356 | je @f |
357 | mov dl,[esi] |
357 | mov dl,[esi] |
358 | call display_character |
358 | call display_character |
359 | add esi,1 |
359 | add esi,1 |
360 | jmp @b |
360 | jmp @b |
361 | @@: |
361 | @@: |
362 | popa |
362 | popa |
363 | ret |
363 | ret |
364 | 364 | ||
365 | display_number: |
365 | display_number: |
366 | push ebx |
366 | push ebx |
367 | mov ecx,1000000000 |
367 | mov ecx,1000000000 |
368 | xor edx,edx |
368 | xor edx,edx |
369 | xor bl,bl |
369 | xor bl,bl |
370 | display_loop: |
370 | display_loop: |
371 | div ecx |
371 | div ecx |
372 | push edx |
372 | push edx |
373 | cmp ecx,1 |
373 | cmp ecx,1 |
374 | je display_digit |
374 | je display_digit |
375 | or bl,bl |
375 | or bl,bl |
376 | jnz display_digit |
376 | jnz display_digit |
377 | or al,al |
377 | or al,al |
378 | jz digit_ok |
378 | jz digit_ok |
379 | not bl |
379 | not bl |
380 | display_digit: |
380 | display_digit: |
381 | mov dl,al |
381 | mov dl,al |
382 | add dl,30h |
382 | add dl,30h |
383 | push ebx ecx |
383 | push ebx ecx |
384 | call display_character |
384 | call display_character |
385 | pop ecx ebx |
385 | pop ecx ebx |
386 | digit_ok: |
386 | digit_ok: |
387 | mov eax,ecx |
387 | mov eax,ecx |
388 | xor edx,edx |
388 | xor edx,edx |
389 | mov ecx,10 |
389 | mov ecx,10 |
390 | div ecx |
390 | div ecx |
391 | mov ecx,eax |
391 | mov ecx,eax |
392 | pop eax |
392 | pop eax |
393 | or ecx,ecx |
393 | or ecx,ecx |
394 | jnz display_loop |
394 | jnz display_loop |
395 | pop ebx |
395 | pop ebx |
396 | ret |
396 | ret |
397 | 397 | ||
398 | display_user_messages: |
398 | display_user_messages: |
399 | ; push [skinh] |
399 | ; push [skinh] |
400 | ; pop [textxy] |
400 | ; pop [textxy] |
401 | ; add [textxy], 7 shl 16 +53 |
401 | ; add [textxy], 7 shl 16 +53 |
402 | mov [displayed_count],0 |
402 | mov [displayed_count],0 |
403 | call flush_display_buffer |
403 | call flush_display_buffer |
404 | cmp [displayed_count],1 |
404 | cmp [displayed_count],1 |
405 | jb line_break_ok |
405 | jb line_break_ok |
406 | je make_line_break |
406 | je make_line_break |
407 | mov ax,word[last_displayed] |
407 | mov ax,word[last_displayed] |
408 | cmp ax,0A0Dh |
408 | cmp ax,0A0Dh |
409 | je line_break_ok |
409 | je line_break_ok |
410 | cmp ax,0D0Ah |
410 | cmp ax,0D0Ah |
411 | je line_break_ok |
411 | je line_break_ok |
412 | make_line_break: |
412 | make_line_break: |
413 | mov esi,lf |
413 | mov esi,lf |
414 | call display_string |
414 | call display_string |
415 | line_break_ok: |
415 | line_break_ok: |
416 | ret |
416 | ret |
417 | 417 | ||
418 | display_block: |
418 | display_block: |
419 | pusha |
419 | pusha |
420 | @@: mov dl,[esi] |
420 | @@: mov dl,[esi] |
421 | call display_character |
421 | call display_character |
422 | inc esi |
422 | inc esi |
423 | loop @b |
423 | loop @b |
424 | popa |
424 | popa |
425 | ret |
425 | ret |
426 | 426 | ||
427 | fatal_error: |
427 | fatal_error: |
428 | mov esi,error_prefix |
428 | mov esi,error_prefix |
429 | call display_string |
429 | call display_string |
430 | pop esi |
430 | pop esi |
431 | call display_string |
431 | call display_string |
432 | mov esi,error_suffix |
432 | mov esi,error_suffix |
433 | call display_string |
433 | call display_string |
434 | mov esi,lf |
434 | mov esi,lf |
435 | call display_string |
435 | call display_string |
436 | mov al,0FFh |
436 | mov al,0FFh |
437 | jmp exit_program |
437 | jmp exit_program |
438 | 438 | ||
439 | assembler_error: |
439 | assembler_error: |
440 | call display_user_messages |
440 | call display_user_messages |
441 | push dword 0 |
441 | push dword 0 |
442 | mov ebx,[current_line] |
442 | mov ebx,[current_line] |
443 | get_error_lines: |
443 | get_error_lines: |
444 | push ebx |
444 | push ebx |
445 | test byte [ebx+7],80h |
445 | test byte [ebx+7],80h |
446 | jz display_error_line |
446 | jz display_error_line |
447 | mov edx,ebx |
447 | mov edx,ebx |
448 | find_definition_origin: |
448 | find_definition_origin: |
449 | mov edx,[edx+12] |
449 | mov edx,[edx+12] |
450 | test byte [edx+7],80h |
450 | test byte [edx+7],80h |
451 | jnz find_definition_origin |
451 | jnz find_definition_origin |
452 | push edx |
452 | push edx |
453 | mov ebx,[ebx+8] |
453 | mov ebx,[ebx+8] |
454 | jmp get_error_lines |
454 | jmp get_error_lines |
455 | display_error_line: |
455 | display_error_line: |
456 | mov esi,[ebx] |
456 | mov esi,[ebx] |
457 | call display_string |
457 | call display_string |
458 | mov esi,line_number_start |
458 | mov esi,line_number_start |
459 | call display_string |
459 | call display_string |
460 | mov eax,[ebx+4] |
460 | mov eax,[ebx+4] |
461 | and eax,7FFFFFFFh |
461 | and eax,7FFFFFFFh |
462 | call display_number |
462 | call display_number |
463 | mov dl,']' |
463 | mov dl,']' |
464 | call display_character |
464 | call display_character |
465 | pop esi |
465 | pop esi |
466 | cmp ebx,esi |
466 | cmp ebx,esi |
467 | je line_number_ok |
467 | je line_number_ok |
468 | mov dl,20h |
468 | mov dl,20h |
469 | call display_character |
469 | call display_character |
470 | push esi |
470 | push esi |
471 | mov esi,[esi] |
471 | mov esi,[esi] |
472 | movzx ecx,byte [esi] |
472 | movzx ecx,byte [esi] |
473 | inc esi |
473 | inc esi |
474 | call display_block |
474 | call display_block |
475 | mov esi,line_number_start |
475 | mov esi,line_number_start |
476 | call display_string |
476 | call display_string |
477 | pop esi |
477 | pop esi |
478 | mov eax,[esi+4] |
478 | mov eax,[esi+4] |
479 | and eax,7FFFFFFFh |
479 | and eax,7FFFFFFFh |
480 | call display_number |
480 | call display_number |
481 | mov dl,']' |
481 | mov dl,']' |
482 | call display_character |
482 | call display_character |
483 | line_number_ok: |
483 | line_number_ok: |
484 | mov esi,line_data_start |
484 | mov esi,line_data_start |
485 | call display_string |
485 | call display_string |
486 | mov esi,ebx |
486 | mov esi,ebx |
487 | mov edx,[esi] |
487 | mov edx,[esi] |
488 | call open |
488 | call open |
489 | mov al,2 |
489 | mov al,2 |
490 | xor edx,edx |
490 | xor edx,edx |
491 | call lseek |
491 | call lseek |
492 | mov edx,[esi+8] |
492 | mov edx,[esi+8] |
493 | sub eax,edx |
493 | sub eax,edx |
494 | push eax |
494 | push eax |
495 | xor al,al |
495 | xor al,al |
496 | call lseek |
496 | call lseek |
497 | mov ecx,[esp] |
497 | mov ecx,[esp] |
498 | mov edx,[additional_memory] |
498 | mov edx,[additional_memory] |
499 | lea eax,[edx+ecx] |
499 | lea eax,[edx+ecx] |
500 | cmp eax,[additional_memory_end] |
500 | cmp eax,[additional_memory_end] |
501 | ja out_of_memory |
501 | ja out_of_memory |
502 | call read |
502 | call read |
503 | call close |
503 | call close |
504 | pop ecx |
504 | pop ecx |
505 | mov esi,[additional_memory] |
505 | mov esi,[additional_memory] |
506 | get_line_data: |
506 | get_line_data: |
507 | mov al,[esi] |
507 | mov al,[esi] |
508 | cmp al,0Ah |
508 | cmp al,0Ah |
509 | je display_line_data |
509 | je display_line_data |
510 | cmp al,0Dh |
510 | cmp al,0Dh |
511 | je display_line_data |
511 | je display_line_data |
512 | cmp al,1Ah |
512 | cmp al,1Ah |
513 | je display_line_data |
513 | je display_line_data |
514 | or al,al |
514 | or al,al |
515 | jz display_line_data |
515 | jz display_line_data |
516 | inc esi |
516 | inc esi |
517 | loop get_line_data |
517 | loop get_line_data |
518 | display_line_data: |
518 | display_line_data: |
519 | mov ecx,esi |
519 | mov ecx,esi |
520 | mov esi,[additional_memory] |
520 | mov esi,[additional_memory] |
521 | sub ecx,esi |
521 | sub ecx,esi |
522 | call display_block |
522 | call display_block |
523 | mov esi,cr_lf |
523 | mov esi,cr_lf |
524 | call display_string |
524 | call display_string |
525 | pop ebx |
525 | pop ebx |
526 | or ebx,ebx |
526 | or ebx,ebx |
527 | jnz display_error_line |
527 | jnz display_error_line |
528 | mov esi,error_prefix |
528 | mov esi,error_prefix |
529 | call display_string |
529 | call display_string |
530 | pop esi |
530 | pop esi |
531 | call display_string |
531 | call display_string |
532 | mov esi,error_suffix |
532 | mov esi,error_suffix |
533 | call display_string |
533 | call display_string |
534 | jmp exit_program |
534 | jmp exit_program |
535 | 535 | ||
536 | align 4 |
536 | align 4 |
537 | fileinfo FILEINFO |
537 | fileinfo FILEINFO |
538 | 538 | ||
539 | character db ?,0 |
539 | character db ?,0 |
540 | bytes_count dd ? |
540 | bytes_count dd ? |
541 | 541 | ||
542 | textxy dd 0x000500A0 |
542 | textxy dd 0x000500A0 |
543 | dc db 0x0 |
543 | dc db 0x0 |
544 | filesize dd 0x0 |
544 | filesize dd 0x0 |
545 | 545 | ||
546 | displayed_count dd ? |
546 | displayed_count dd ? |
547 | last_displayed rb 2 |
547 | last_displayed rb 2 |
548 | 548 | ||
549 | error_prefix db 'error: ',0 |
549 | error_prefix db 'error: ',0 |
550 | error_suffix db '.',0 |
550 | error_suffix db '.',0 |
551 | line_data_start db ':' |
551 | line_data_start db ':' |
552 | cr_lf db 0Dh,0Ah,0 |
552 | cr_lf db 0Dh,0Ah,0 |
553 | line_number_start db ' [',0 |
553 | line_number_start db ' [',0 |
554 | 554 | ||
555 | macro dm string { db string,0 } |
555 | macro dm string { db string,0 } |