home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / CO_DRIVE.ASM next >
Encoding:
Assembly Source File  |  1990-09-25  |  3.2 KB  |  167 lines

  1. ;
  2. ;  co_drive.asm
  3. ;
  4. ;  Purpose: Console driver primitives.
  5. ;
  6. ;  Blackstar C Function Libarary
  7. ;  (c) Copyright 1985,1989 Sterling Castle Software
  8. ;
  9.  
  10.     include model
  11.     include blackstr.mac
  12.  
  13.     extrnf sprintf
  14.     extrnf sscanf
  15.     extrnf kb_gets
  16.     extrnf sc_puts
  17.  
  18.     dseg    'DATA'
  19.  
  20.     save_es         dw      00
  21.     save_ds         dw      00
  22.     adr1            dw      00
  23.     ifdef   asm_386
  24.     adr             dd      00
  25.     else
  26.     adr             dw      00
  27.     endif
  28.     string_         db      255 dup (0)
  29.  
  30.     enddseg
  31.  
  32.  
  33.     cseg    sc_printf_
  34.  
  35. ;----------------
  36. ;   sc_printf                   formatted screen output
  37. ;----------------
  38. ;                               Usage: sc_printf("<format>",var1,...,varx);
  39. ;
  40. ;                               int sc_printf("<format>",var1,...,varx);
  41.  
  42.     public  sc_printf
  43.  
  44. sc_printf proc
  45.     ifdef   Large_data
  46.     mov     ax,ds
  47.     mov     bx, seg dgroup
  48.     mov     ds,bx
  49.     mov     save_ds,ax
  50.     mov     ax,es
  51.     mov     save_es,ax
  52.     endif
  53.  
  54.     pop     eax             ;get offset of return address
  55.     ifdef   Large_data
  56.     mov     dx, seg dgroup
  57.     mov     es,dx
  58.     endif
  59.     mov     es:adr,eax
  60.  
  61.  
  62.     ifdef   Large_code
  63.     pop     ebx             ;get segment of return address
  64.  
  65.     mov     es:adr1,bx
  66.         endif
  67.  
  68.     mpassp  string_
  69.     call    sprintf     ;Use sprintf function
  70.     add     esp,Ptr_size
  71.  
  72.     mpassp  string_
  73.     call    sc_puts
  74.     add     esp,Ptr_size    ;fix stack for puts call
  75.  
  76.     ifdef    Large_code
  77.     mov     bx,es:[adr1]
  78.     push    bx              ;replace segment of return address on stack
  79.     endif
  80.  
  81.     mov     eax,es:[adr]
  82.     push    eax             ;replace offset of return address on stack
  83.  
  84.     ifdef   Large_data
  85.     mov     ax,save_es
  86.     mov     es,ax
  87.     mov     ax,save_ds
  88.     mov     ds,ax
  89.     ifdef    asm_386
  90.     movsx    eax,ax
  91.     endif
  92.  
  93.     endif
  94.  
  95.     return
  96. sc_printf endp
  97.  
  98.  
  99.  
  100. ;-----------------------
  101. ;    kb_scanf            formatted keyboard input routine
  102. ;-----------------------
  103. ;                               Usage: scanf("<string>",var1,...,varN);
  104. ;
  105. ;                               int scanf("<string>",var1,...varN);
  106.  
  107.     public  kb_scanf
  108.  
  109. kb_scanf proc
  110.     ifdef   Large_data
  111.     mov     ax,ds
  112.     mov     bx, seg dgroup
  113.     mov     ds,bx
  114.     mov     save_ds,ax
  115.     mov     ax,es
  116.     mov     save_es,ax
  117.     endif
  118.  
  119.     pop     eax             ;get return address
  120.     ifdef   Large_data
  121.     mov     cx,seg dgroup
  122.     mov     es,cx           ;point es to dgroup
  123.     endif
  124.     mov     es:adr,eax      ;and address
  125.  
  126.     ifdef   Large_code
  127.     pop     bx              ;get far segment
  128.     mov     es:adr1,bx      ;save segment
  129.     endif
  130.  
  131.     mpassp  string_         ;pass pointer to string_ and use kb_gets and scanf
  132.     call    kb_gets     ;first get input to the string
  133.     add     esp,Ptr_size
  134.  
  135.     mpassp  string_         ;back to stack for scanf
  136.     call    sscanf        ;scan it to string_
  137.     add     esp,Ptr_size    ;fix stack
  138.  
  139.     ifdef   Large_code
  140.     ifdef   Large_data
  141.     mov     cx,seg dgroup
  142.     mov     es,cx
  143.     endif
  144.     mov     bx,es:[adr1]
  145.     push    ebx
  146.     endif
  147.  
  148.     mov     eax,es:[adr]    ;get return address
  149.     push    eax             ;return address offset
  150.  
  151.     ifdef   Large_data
  152.     mov     ax,save_es
  153.     mov     es,ax
  154.     mov     ax,save_ds
  155.     mov     ds,ax
  156.     ifdef    asm_386
  157.     movsx    eax,ax
  158.     endif
  159.  
  160.     endif
  161.  
  162.     return
  163. kb_scanf endp
  164.  
  165.     endcseg sc_printf_
  166.     end
  167.