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

  1. ;
  2. ;  dv_drive.asm
  3. ;
  4. ;  Purpose: Device handling 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.  
  14.     ;---------------------------------------------
  15.     ; the interrupt and codes for the interface.
  16.     ;--------------------------------------------
  17.     keyboard        equ     16h     ;interrupt 16 to deal with keyboard
  18.     msdosf          equ     21h     ;msdos function call
  19.     video           equ     10h     ;interrupt for screen
  20.  
  21.  
  22.     cseg    dv_op__
  23.  
  24. ;---------------
  25. ;   dv_op_                      open a device
  26. ;---------------
  27. ;                               Usage:  fd = dv_op_(name,mode);
  28. ;
  29. ;                               int dv_op_(char *dname, int mode);
  30.  
  31.     public dv_op_
  32.  
  33. dv_op_  proc
  34.     parm386 <<dname,ptr>,<mode,dword>>
  35.     parm86  <<dname,ptr>,<mode,word>>
  36.     prolog
  37.  
  38.     loadptr lds,edx,dname
  39.     mov     eax,mode        ;mode 0-read,1-write,2-read/write
  40.     mov     ah,3dh          ;MS-DOS open function
  41.     int     msdosf          ;function call
  42.     jnc     dv_opb          ;carry flag is error
  43.     mov     eax,-1          ;return error code
  44.     jmp     dv_opx
  45.  
  46. dv_opb:
  47.     mov     ebx,mode
  48.     and     ebx,8000h       ;see if binary set
  49.     jz      dv_opx
  50.     push    eax             ;device fd #
  51.  
  52.     ifdef   Large_code
  53.     push    cs
  54.     endif
  55.  
  56.     call    dv_stat_        ;get status of device
  57.     or      eax,0020h       ;set for binary mode
  58.     and     eax,00ffh       ;need high byte zero
  59.     push    eax             ;com byte on stack
  60.  
  61.     ifdef   Large_code
  62.     push    cs
  63.     endif
  64.  
  65.     call    dv_com_         ;set to binary mode
  66.     add     esp,Word_size
  67.     pop     eax             ;restore fd #
  68.  
  69. dv_opx: epilog
  70. dv_op_  endp
  71.  
  72.  
  73. ;----------------
  74. ;   dv_com_                     set device parameters
  75. ;-----------------
  76. ;                               Usage: dv_com_(control,fd);
  77. ;
  78. ;                               int dv_com_(int control, int fd);
  79.  
  80.     public  dv_com_
  81.  
  82. dv_com_ proc
  83.     parm386 <<control,dword>, <fd,dword>>
  84.     parm86 <<control,word>, <fd,word>>
  85.     prolog
  86.  
  87.     mov     eax,4401h       ;set command
  88.     mov     ebx,fd          ;file handle
  89.     mov     edx,control     ;get command byte
  90.     int     msdosf          ;function call
  91.  
  92.     ifdef    asm_386
  93.     movsx    eax,ax
  94.     endif
  95.  
  96.     epilog
  97. dv_com_ endp
  98.  
  99.  
  100. ;-------------
  101. ;   _dv_stat_                   get device parms
  102. ;-------------
  103. ;                               Usage status = dv_stat_(fd);
  104. ;
  105. ;                               int dv_stat_(int fd);
  106.  
  107.     public  dv_stat_
  108.  
  109. dv_stat_ proc
  110.     parm386 <<fd2,dword>>
  111.     parm86 <<fd2,word>>
  112.     prolog
  113.  
  114.     mov     eax,4400h       ;get status byte
  115.     mov     ebx,fd2         ;device number
  116.     int     msdosf          ;function call
  117.     mov     ax,dx
  118.  
  119.     ifdef    asm_386
  120.     movsx    eax,ax
  121.     endif
  122.  
  123.     epilog
  124. dv_stat_ endp
  125.  
  126.  
  127. ;----------------
  128. ;   dv_rd_              device read
  129. ;----------------
  130. ;                       Usage:  status = dv_rd_(fd,buff,bytes)
  131. ;
  132. ;                       int dv_read_(int fd, char *buff, int cnt)
  133.  
  134.     public  dv_rd_
  135.  
  136. dv_rd_  proc    near
  137.     parm386 <<fd3,dword>,<buff,ptr>,<cnt,dword>>
  138.     parm86 <<fd3,word>,<buff,ptr>,<cnt,word>>
  139.     prolog
  140.  
  141.     loadptr lds,edx,buff    ;buffer to read into
  142.     mov     ecx,cnt         ;# bytes to read
  143.     mov     ebx,fd3         ;file handle
  144.     mov     ah,3fh          ;read command
  145.     int     msdosf          ;function call
  146.  
  147.     ifdef    asm_386
  148.     movsx    eax,ax
  149.     endif
  150.  
  151.     epilog
  152. dv_rd_ endp
  153.  
  154.  
  155. ;-----------------
  156. ;   dv_wr_              device write
  157. ;-----------------
  158. ;                       Usage: #bytes = dv_wr_(fd,buff,bytes)
  159. ;
  160. ;                       int dv_wr_(int fd, char *buff, int bytes);
  161.  
  162.     public  dv_wr_
  163.  
  164. dv_wr_  proc
  165.     parm386 <<fd4,dword>,<buff2,ptr>,<bytes,dword>>
  166.     parm86 <<fd4,word>,<buff2,ptr>,<bytes,word>>
  167.     prolog
  168.  
  169.     mov     ebx,fd4         ;file handle number
  170.     loadptr lds,edx,buff2   ;buffer to write from
  171.     mov     ecx,bytes       ;# bytes to write
  172.     mov     ah,40h          ;command to write
  173.     int     msdosf          ;function call
  174.  
  175.     ifdef    asm_386
  176.     movsx    eax,ax
  177.     endif
  178.  
  179.     epilog
  180. dv_wr_  endp
  181.  
  182.  
  183. ;------------------
  184. ;   dv_cl_                      close a device
  185. ;------------------
  186. ;                               Usage: status = dv_cl_(fd)
  187. ;
  188. ;                               int dv_cl_(int fd);
  189.  
  190.     public  dv_cl_
  191.  
  192. dv_cl_  proc
  193.     parm386 <<fd5,dword>>
  194.     parm86 <<fd5,word>>
  195.     prolog
  196.  
  197.     mov     ebx,fd5         ;file handle number
  198.     mov     ah,3eh          ;command to close it
  199.     int     msdosf          ;function call
  200.  
  201.     ifdef    asm_386
  202.     movsx    eax,ax
  203.     endif
  204.  
  205.     epilog
  206. dv_cl_  endp
  207.  
  208.  
  209. ;----------------
  210. ;   dv_ctrd_                    control channel read
  211. ;----------------
  212. ;                               Usage:  dv_ctrd_(fd,&data,count);
  213. ;
  214. ;                               int dv_ctrd_(int fd, char *data, int count);
  215.  
  216.     public  dv_ctrd_
  217.  
  218. dv_ctrd_ proc
  219.     parm386 <<fd6,dword>,<datap,ptr>,<count,dword>>
  220.     parm86 <<fd6,word>,<datap,ptr>,<count,word>>
  221.     prolog
  222.  
  223.     mov     ebx,fd6         ;file handle
  224.     loadptr lds,edx,datap   ;
  225.     mov     ecx,count       ;# of bytes to read
  226.     mov     ax,4402h        ;ioctl read command
  227.     int     msdosf          ;function call
  228.  
  229.     ifdef    asm_386
  230.     movsx    eax,ax
  231.     endif
  232.  
  233.     epilog
  234. dv_ctrd_ endp
  235.  
  236.  
  237. ;------------------
  238. ;   dv_ctwr_                    write to control channel of device
  239. ;------------------
  240. ;                               Usage:  cnt = dv_ctwr_(fd,buff,count);
  241. ;
  242. ;                               int dv_ctwr_(int fd, char *buff, int count);
  243.  
  244.     public  dv_ctwr_
  245.  
  246. dv_ctwr_ proc
  247.     parm386 <<fd7,dword>,<buff3,ptr>,<count2,dword>>
  248.     parm86 <<fd7,word>,<buff3,ptr>,<count2,word>>
  249.     prolog
  250.  
  251.     mov     ebx,fd7         ;file handle
  252.     loadptr lds,edx,buff3   ;buffer to write from
  253.     mov     ecx,count2      ;number of bytes to write
  254.     mov     ax,4403h        ;ioctl command to write
  255.     int     msdosf          ;function call
  256.  
  257.     ifdef    asm_386
  258.     movsx    eax,ax
  259.     endif
  260.  
  261.     epilog
  262. dv_ctwr_ endp
  263.  
  264.     endcseg dv_op__
  265.     end
  266.