"Fossies" - the Fresh Open Source Software Archive 
Member "fasm/source/DOS/system.inc" (21 Feb 2022, 8863 Bytes) of package /linux/misc/fasm-1.73.30.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "system.inc":
1.73.29_vs_1.73.30.
1
2 ; flat assembler interface for DOS
3 ; Copyright (c) 1999-2022, Tomasz Grysztar.
4 ; All rights reserved.
5
6 go32:
7 use16
8 call modes:real32
9 use32
10 retw
11
12 program_base dd ?
13 buffer_address dd ?
14 psp_segment dw ?
15 environment_segment dw ?
16
17 if UNREAL_ENABLED>0
18
19 init_memory:
20 mov [stack_limit],0
21 cmp [mode],dpmi
22 je init_dpmi_memory
23 call modes:init_real32_memory
24 ret
25 dos_int:
26 cmp [mode],dpmi
27 je dpmi_dos_int
28 stc
29 int 21h
30 ret
31 dos_int_with_buffer:
32 cmp [mode],dpmi
33 je dpmi_dos_int_with_buffer
34 push ds buffer
35 pop ds
36 stc
37 int 21h
38 pop ds
39 ret
40 exit_program:
41 cmp [mode],dpmi
42 je exit_state_ok
43 push eax
44 call modes:free_real32_memory
45 pop eax
46 exit_state_ok:
47 mov ah,4Ch
48 int 21h
49
50 else
51
52 init_memory:
53 mov [stack_limit],0
54 jmp init_dpmi_memory
55 dos_int:
56 jmp dpmi_dos_int
57 dos_int_with_buffer:
58 jmp dpmi_dos_int_with_buffer
59 exit_program:
60 mov ah,4Ch
61 int 21h
62
63 end if
64
65 get_environment_variable:
66 mov ebx,esi
67 push ds
68 mov ds,[environment_segment]
69 xor esi,esi
70 compare_variable_names:
71 mov edx,ebx
72 compare_character:
73 lodsb
74 mov ah,[es:edx]
75 inc edx
76 cmp al,'='
77 je end_of_variable_name
78 or ah,ah
79 jz next_variable
80 sub ah,al
81 jz compare_character
82 cmp ah,20h
83 jne next_variable
84 cmp al,41h
85 jb next_variable
86 cmp al,5Ah
87 jna compare_character
88 next_variable:
89 lodsb
90 or al,al
91 jnz next_variable
92 cmp byte [esi],0
93 jne compare_variable_names
94 pop ds
95 ret
96 end_of_variable_name:
97 or ah,ah
98 jnz next_variable
99 copy_variable_value:
100 lodsb
101 cmp edi,[es:memory_end]
102 jae out_of_memory
103 stosb
104 or al,al
105 jnz copy_variable_value
106 dec edi
107 pop ds
108 ret
109
110 open:
111 push esi edi
112 call adapt_path
113 mov ax,716Ch
114 mov bx,100000b
115 mov dx,1
116 xor cx,cx
117 xor si,si
118 call dos_int_with_buffer
119 jnc open_done
120 cmp ax,7100h
121 je old_open
122 stc
123 jmp open_done
124 old_open:
125 mov ax,3D00h
126 xor dx,dx
127 call dos_int_with_buffer
128 open_done:
129 mov bx,ax
130 pop edi esi
131 ret
132 adapt_path:
133 mov esi,edx
134 mov edi,[buffer_address]
135 copy_path:
136 lodsb
137 cmp al,'/'
138 jne path_char_ok
139 mov al,'\'
140 path_char_ok:
141 stosb
142 or al,al
143 jnz copy_path
144 ret
145 create:
146 push esi edi
147 call adapt_path
148 mov ax,716Ch
149 mov bx,100001b
150 mov dx,10010b
151 xor cx,cx
152 xor si,si
153 xor di,di
154 call dos_int_with_buffer
155 jnc create_done
156 cmp ax,7100h
157 je old_create
158 stc
159 jmp create_done
160 old_create:
161 mov ah,3Ch
162 xor cx,cx
163 xor dx,dx
164 call dos_int_with_buffer
165 create_done:
166 mov bx,ax
167 pop edi esi
168 ret
169 write:
170 push edx esi edi ebp
171 mov ebp,ecx
172 mov esi,edx
173 .loop:
174 mov ecx,1000h
175 sub ebp,1000h
176 jnc .write
177 add ebp,1000h
178 mov ecx,ebp
179 xor ebp,ebp
180 .write:
181 push ecx
182 mov edi,[buffer_address]
183 shr ecx,2
184 rep movsd
185 mov ecx,[esp]
186 and ecx,11b
187 rep movsb
188 pop ecx
189 mov ah,40h
190 xor dx,dx
191 call dos_int_with_buffer
192 or ebp,ebp
193 jnz .loop
194 pop ebp edi esi edx
195 ret
196 read:
197 push edx esi edi ebp
198 mov ebp,ecx
199 mov edi,edx
200 .loop:
201 mov ecx,1000h
202 sub ebp,1000h
203 jnc .read
204 add ebp,1000h
205 mov ecx,ebp
206 xor ebp,ebp
207 .read:
208 push ecx
209 mov ah,3Fh
210 xor dx,dx
211 call dos_int_with_buffer
212 cmp ax,cx
213 jne .eof
214 mov esi,[buffer_address]
215 mov ecx,[esp]
216 shr ecx,2
217 rep movsd
218 pop ecx
219 and ecx,11b
220 rep movsb
221 or ebp,ebp
222 jnz .loop
223 .exit:
224 pop ebp edi esi edx
225 ret
226 .eof:
227 pop ecx
228 stc
229 jmp .exit
230 close:
231 mov ah,3Eh
232 int 21h
233 ret
234 lseek:
235 mov ah,42h
236 mov ecx,edx
237 shr ecx,16
238 int 21h
239 pushf
240 shl edx,16
241 popf
242 mov dx,ax
243 mov eax,edx
244 ret
245
246 display_string:
247 lods byte [esi]
248 or al,al
249 jz string_end
250 mov dl,al
251 mov ah,2
252 int 21h
253 jmp display_string
254 string_end:
255 ret
256 display_number:
257 push ebx
258 mov ecx,1000000000
259 xor edx,edx
260 xor bl,bl
261 display_loop:
262 div ecx
263 push edx
264 cmp ecx,1
265 je display_digit
266 or bl,bl
267 jnz display_digit
268 or al,al
269 jz digit_ok
270 not bl
271 display_digit:
272 mov dl,al
273 add dl,30h
274 mov ah,2
275 int 21h
276 digit_ok:
277 mov eax,ecx
278 xor edx,edx
279 mov ecx,10
280 div ecx
281 mov ecx,eax
282 pop eax
283 or ecx,ecx
284 jnz display_loop
285 pop ebx
286 ret
287
288 display_user_messages:
289 mov [displayed_count],0
290 call show_display_buffer
291 cmp [displayed_count],1
292 jb line_break_ok
293 je make_line_break
294 mov ax,word [last_displayed]
295 cmp ax,0A0Dh
296 je line_break_ok
297 cmp ax,0D0Ah
298 je line_break_ok
299 make_line_break:
300 mov ah,2
301 mov dl,0Dh
302 int 21h
303 mov dl,0Ah
304 int 21h
305 line_break_ok:
306 ret
307 display_block:
308 add [displayed_count],ecx
309 cmp ecx,1
310 ja take_last_two_characters
311 jb display_character
312 mov al,[last_displayed+1]
313 mov ah,[esi]
314 mov word [last_displayed],ax
315 jmp display_character
316 take_last_two_characters:
317 mov ax,[esi+ecx-2]
318 mov word [last_displayed],ax
319 display_character:
320 lods byte [esi]
321 mov dl,al
322 mov ah,2
323 int 21h
324 loopd display_character
325 ret
326
327 fatal_error:
328 mov esi,error_prefix
329 call display_string
330 pop esi
331 call display_string
332 mov esi,error_suffix
333 call display_string
334 mov al,0FFh
335 jmp exit_program
336 assembler_error:
337 call display_user_messages
338 mov ebx,[current_line]
339 test ebx,ebx
340 jz display_error_message
341 pushd 0
342 get_error_lines:
343 mov eax,[ebx]
344 cmp byte [eax],0
345 je get_next_error_line
346 push ebx
347 test byte [ebx+7],80h
348 jz display_error_line
349 mov edx,ebx
350 find_definition_origin:
351 mov edx,[edx+12]
352 test byte [edx+7],80h
353 jnz find_definition_origin
354 push edx
355 get_next_error_line:
356 mov ebx,[ebx+8]
357 jmp get_error_lines
358 display_error_line:
359 mov esi,[ebx]
360 call display_string
361 mov esi,line_number_start
362 call display_string
363 mov eax,[ebx+4]
364 and eax,7FFFFFFFh
365 call display_number
366 mov dl,']'
367 mov ah,2
368 int 21h
369 pop esi
370 cmp ebx,esi
371 je line_number_ok
372 mov dl,20h
373 mov ah,2
374 int 21h
375 push esi
376 mov esi,[esi]
377 movzx ecx,byte [esi]
378 inc esi
379 call display_block
380 mov esi,line_number_start
381 call display_string
382 pop esi
383 mov eax,[esi+4]
384 and eax,7FFFFFFFh
385 call display_number
386 mov dl,']'
387 mov ah,2
388 int 21h
389 line_number_ok:
390 mov esi,line_data_start
391 call display_string
392 mov esi,ebx
393 mov edx,[esi]
394 call open
395 mov al,2
396 xor edx,edx
397 call lseek
398 mov edx,[esi+8]
399 sub eax,edx
400 jz line_data_displayed
401 mov [counter],eax
402 xor al,al
403 call lseek
404 mov esi,[additional_memory]
405 read_line_data:
406 mov ecx,100h
407 cmp ecx,[counter]
408 jbe bytes_count_ok
409 mov ecx,[counter]
410 bytes_count_ok:
411 sub [counter],ecx
412 lea eax,[esi+ecx]
413 cmp eax,[additional_memory_end]
414 ja out_of_memory
415 push ecx
416 mov edx,esi
417 call read
418 pop ecx
419 get_line_data:
420 mov al,[esi]
421 cmp al,0Ah
422 je display_line_data
423 cmp al,0Dh
424 je display_line_data
425 cmp al,1Ah
426 je display_line_data
427 or al,al
428 jz display_line_data
429 inc esi
430 loop get_line_data
431 cmp [counter],0
432 ja read_line_data
433 display_line_data:
434 call close
435 mov ecx,esi
436 mov esi,[additional_memory]
437 sub ecx,esi
438 call display_block
439 line_data_displayed:
440 mov esi,cr_lf
441 call display_string
442 pop ebx
443 or ebx,ebx
444 jnz display_error_line
445 cmp [preprocessing_done],0
446 je display_error_message
447 mov esi,preprocessed_instruction_prefix
448 call display_string
449 mov esi,[current_line]
450 add esi,16
451 mov edi,[additional_memory]
452 xor dl,dl
453 convert_instruction:
454 lodsb
455 cmp al,1Ah
456 je copy_symbol
457 cmp al,22h
458 je copy_symbol
459 cmp al,3Bh
460 je instruction_converted
461 stosb
462 or al,al
463 jz instruction_converted
464 xor dl,dl
465 jmp convert_instruction
466 copy_symbol:
467 or dl,dl
468 jz space_ok
469 mov byte [edi],20h
470 inc edi
471 space_ok:
472 cmp al,22h
473 je quoted
474 lodsb
475 movzx ecx,al
476 rep movsb
477 or dl,-1
478 jmp convert_instruction
479 quoted:
480 mov al,27h
481 stosb
482 lodsd
483 mov ecx,eax
484 jecxz quoted_copied
485 copy_quoted:
486 lodsb
487 stosb
488 cmp al,27h
489 jne quote_ok
490 stosb
491 quote_ok:
492 loop copy_quoted
493 quoted_copied:
494 mov al,27h
495 stosb
496 or dl,-1
497 jmp convert_instruction
498 instruction_converted:
499 xor al,al
500 stosb
501 mov esi,[additional_memory]
502 call display_string
503 mov esi,cr_lf
504 call display_string
505 display_error_message:
506 mov esi,error_prefix
507 call display_string
508 pop esi
509 call display_string
510 mov esi,error_suffix
511 call display_string
512 mov al,2
513 jmp exit_program
514
515 make_timestamp:
516 mov ah,2Ah
517 int 21h
518 push dx cx
519 movzx ecx,cx
520 mov eax,ecx
521 sub eax,1970
522 mov ebx,365
523 mul ebx
524 mov ebp,eax
525 mov eax,ecx
526 sub eax,1969
527 shr eax,2
528 add ebp,eax
529 mov eax,ecx
530 sub eax,1901
531 mov ebx,100
532 div ebx
533 sub ebp,eax
534 mov eax,ecx
535 xor edx,edx
536 sub eax,1601
537 mov ebx,400
538 div ebx
539 add ebp,eax
540 movzx ecx,byte [esp+3]
541 mov eax,ecx
542 dec eax
543 mov ebx,30
544 mul ebx
545 add ebp,eax
546 cmp ecx,8
547 jbe months_correction
548 mov eax,ecx
549 sub eax,7
550 shr eax,1
551 add ebp,eax
552 mov ecx,8
553 months_correction:
554 mov eax,ecx
555 shr eax,1
556 add ebp,eax
557 cmp ecx,2
558 pop cx
559 jbe day_correction_ok
560 sub ebp,2
561 test ecx,11b
562 jnz day_correction_ok
563 xor edx,edx
564 mov eax,ecx
565 mov ebx,100
566 div ebx
567 or edx,edx
568 jnz day_correction
569 mov eax,ecx
570 mov ebx,400
571 div ebx
572 or edx,edx
573 jnz day_correction_ok
574 day_correction:
575 inc ebp
576 day_correction_ok:
577 pop dx
578 movzx eax,dl
579 dec eax
580 add eax,ebp
581 mov ebx,24
582 mul ebx
583 push eax
584 mov ah,2Ch
585 int 21h
586 pop eax
587 push dx
588 movzx ebx,ch
589 add eax,ebx
590 mov ebx,60
591 mul ebx
592 movzx ebx,cl
593 add eax,ebx
594 mov ebx,60
595 mul ebx
596 pop bx
597 movzx ebx,bh
598 add eax,ebx
599 adc edx,0
600 ret