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