home *** CD-ROM | disk | FTP | other *** search
- ;
- ; co_drive.asm
- ;
- ; Purpose: Console driver primitives.
- ;
- ; Blackstar C Function Libarary
- ; (c) Copyright 1985,1989 Sterling Castle Software
- ;
-
- include model
- include blackstr.mac
-
- extrnf sprintf
- extrnf sscanf
- extrnf kb_gets
- extrnf sc_puts
-
- dseg 'DATA'
-
- save_es dw 00
- save_ds dw 00
- adr1 dw 00
- ifdef asm_386
- adr dd 00
- else
- adr dw 00
- endif
- string_ db 255 dup (0)
-
- enddseg
-
-
- cseg sc_printf_
-
- ;----------------
- ; sc_printf formatted screen output
- ;----------------
- ; Usage: sc_printf("<format>",var1,...,varx);
- ;
- ; int sc_printf("<format>",var1,...,varx);
-
- public sc_printf
-
- sc_printf proc
- ifdef Large_data
- mov ax,ds
- mov bx, seg dgroup
- mov ds,bx
- mov save_ds,ax
- mov ax,es
- mov save_es,ax
- endif
-
- pop eax ;get offset of return address
- ifdef Large_data
- mov dx, seg dgroup
- mov es,dx
- endif
- mov es:adr,eax
-
-
- ifdef Large_code
- pop ebx ;get segment of return address
-
- mov es:adr1,bx
- endif
-
- mpassp string_
- call sprintf ;Use sprintf function
- add esp,Ptr_size
-
- mpassp string_
- call sc_puts
- add esp,Ptr_size ;fix stack for puts call
-
- ifdef Large_code
- mov bx,es:[adr1]
- push bx ;replace segment of return address on stack
- endif
-
- mov eax,es:[adr]
- push eax ;replace offset of return address on stack
-
- ifdef Large_data
- mov ax,save_es
- mov es,ax
- mov ax,save_ds
- mov ds,ax
- ifdef asm_386
- movsx eax,ax
- endif
-
- endif
-
- return
- sc_printf endp
-
-
-
- ;-----------------------
- ; kb_scanf formatted keyboard input routine
- ;-----------------------
- ; Usage: scanf("<string>",var1,...,varN);
- ;
- ; int scanf("<string>",var1,...varN);
-
- public kb_scanf
-
- kb_scanf proc
- ifdef Large_data
- mov ax,ds
- mov bx, seg dgroup
- mov ds,bx
- mov save_ds,ax
- mov ax,es
- mov save_es,ax
- endif
-
- pop eax ;get return address
- ifdef Large_data
- mov cx,seg dgroup
- mov es,cx ;point es to dgroup
- endif
- mov es:adr,eax ;and address
-
- ifdef Large_code
- pop bx ;get far segment
- mov es:adr1,bx ;save segment
- endif
-
- mpassp string_ ;pass pointer to string_ and use kb_gets and scanf
- call kb_gets ;first get input to the string
- add esp,Ptr_size
-
- mpassp string_ ;back to stack for scanf
- call sscanf ;scan it to string_
- add esp,Ptr_size ;fix stack
-
- ifdef Large_code
- ifdef Large_data
- mov cx,seg dgroup
- mov es,cx
- endif
- mov bx,es:[adr1]
- push ebx
- endif
-
- mov eax,es:[adr] ;get return address
- push eax ;return address offset
-
- ifdef Large_data
- mov ax,save_es
- mov es,ax
- mov ax,save_ds
- mov ds,ax
- ifdef asm_386
- movsx eax,ax
- endif
-
- endif
-
- return
- kb_scanf endp
-
- endcseg sc_printf_
- end
-