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