home *** CD-ROM | disk | FTP | other *** search
- ;
- ; dv_drive.asm
- ;
- ; Purpose: Device handling primitives.
- ;
- ; Blackstar C Function Libarary
- ; (c) Copyright 1985,1989 Sterling Castle Software
- ;
-
- include model
- include blackstr.mac
-
-
- ;---------------------------------------------
- ; the interrupt and codes for the interface.
- ;--------------------------------------------
- keyboard equ 16h ;interrupt 16 to deal with keyboard
- msdosf equ 21h ;msdos function call
- video equ 10h ;interrupt for screen
-
-
- cseg dv_op__
-
- ;---------------
- ; dv_op_ open a device
- ;---------------
- ; Usage: fd = dv_op_(name,mode);
- ;
- ; int dv_op_(char *dname, int mode);
-
- public dv_op_
-
- dv_op_ proc
- parm386 <<dname,ptr>,<mode,dword>>
- parm86 <<dname,ptr>,<mode,word>>
- prolog
-
- loadptr lds,edx,dname
- mov eax,mode ;mode 0-read,1-write,2-read/write
- mov ah,3dh ;MS-DOS open function
- int msdosf ;function call
- jnc dv_opb ;carry flag is error
- mov eax,-1 ;return error code
- jmp dv_opx
-
- dv_opb:
- mov ebx,mode
- and ebx,8000h ;see if binary set
- jz dv_opx
- push eax ;device fd #
-
- ifdef Large_code
- push cs
- endif
-
- call dv_stat_ ;get status of device
- or eax,0020h ;set for binary mode
- and eax,00ffh ;need high byte zero
- push eax ;com byte on stack
-
- ifdef Large_code
- push cs
- endif
-
- call dv_com_ ;set to binary mode
- add esp,Word_size
- pop eax ;restore fd #
-
- dv_opx: epilog
- dv_op_ endp
-
-
- ;----------------
- ; dv_com_ set device parameters
- ;-----------------
- ; Usage: dv_com_(control,fd);
- ;
- ; int dv_com_(int control, int fd);
-
- public dv_com_
-
- dv_com_ proc
- parm386 <<control,dword>, <fd,dword>>
- parm86 <<control,word>, <fd,word>>
- prolog
-
- mov eax,4401h ;set command
- mov ebx,fd ;file handle
- mov edx,control ;get command byte
- int msdosf ;function call
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- dv_com_ endp
-
-
- ;-------------
- ; _dv_stat_ get device parms
- ;-------------
- ; Usage status = dv_stat_(fd);
- ;
- ; int dv_stat_(int fd);
-
- public dv_stat_
-
- dv_stat_ proc
- parm386 <<fd2,dword>>
- parm86 <<fd2,word>>
- prolog
-
- mov eax,4400h ;get status byte
- mov ebx,fd2 ;device number
- int msdosf ;function call
- mov ax,dx
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- dv_stat_ endp
-
-
- ;----------------
- ; dv_rd_ device read
- ;----------------
- ; Usage: status = dv_rd_(fd,buff,bytes)
- ;
- ; int dv_read_(int fd, char *buff, int cnt)
-
- public dv_rd_
-
- dv_rd_ proc near
- parm386 <<fd3,dword>,<buff,ptr>,<cnt,dword>>
- parm86 <<fd3,word>,<buff,ptr>,<cnt,word>>
- prolog
-
- loadptr lds,edx,buff ;buffer to read into
- mov ecx,cnt ;# bytes to read
- mov ebx,fd3 ;file handle
- mov ah,3fh ;read command
- int msdosf ;function call
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- dv_rd_ endp
-
-
- ;-----------------
- ; dv_wr_ device write
- ;-----------------
- ; Usage: #bytes = dv_wr_(fd,buff,bytes)
- ;
- ; int dv_wr_(int fd, char *buff, int bytes);
-
- public dv_wr_
-
- dv_wr_ proc
- parm386 <<fd4,dword>,<buff2,ptr>,<bytes,dword>>
- parm86 <<fd4,word>,<buff2,ptr>,<bytes,word>>
- prolog
-
- mov ebx,fd4 ;file handle number
- loadptr lds,edx,buff2 ;buffer to write from
- mov ecx,bytes ;# bytes to write
- mov ah,40h ;command to write
- int msdosf ;function call
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- dv_wr_ endp
-
-
- ;------------------
- ; dv_cl_ close a device
- ;------------------
- ; Usage: status = dv_cl_(fd)
- ;
- ; int dv_cl_(int fd);
-
- public dv_cl_
-
- dv_cl_ proc
- parm386 <<fd5,dword>>
- parm86 <<fd5,word>>
- prolog
-
- mov ebx,fd5 ;file handle number
- mov ah,3eh ;command to close it
- int msdosf ;function call
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- dv_cl_ endp
-
-
- ;----------------
- ; dv_ctrd_ control channel read
- ;----------------
- ; Usage: dv_ctrd_(fd,&data,count);
- ;
- ; int dv_ctrd_(int fd, char *data, int count);
-
- public dv_ctrd_
-
- dv_ctrd_ proc
- parm386 <<fd6,dword>,<datap,ptr>,<count,dword>>
- parm86 <<fd6,word>,<datap,ptr>,<count,word>>
- prolog
-
- mov ebx,fd6 ;file handle
- loadptr lds,edx,datap ;
- mov ecx,count ;# of bytes to read
- mov ax,4402h ;ioctl read command
- int msdosf ;function call
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- dv_ctrd_ endp
-
-
- ;------------------
- ; dv_ctwr_ write to control channel of device
- ;------------------
- ; Usage: cnt = dv_ctwr_(fd,buff,count);
- ;
- ; int dv_ctwr_(int fd, char *buff, int count);
-
- public dv_ctwr_
-
- dv_ctwr_ proc
- parm386 <<fd7,dword>,<buff3,ptr>,<count2,dword>>
- parm86 <<fd7,word>,<buff3,ptr>,<count2,word>>
- prolog
-
- mov ebx,fd7 ;file handle
- loadptr lds,edx,buff3 ;buffer to write from
- mov ecx,count2 ;number of bytes to write
- mov ax,4403h ;ioctl command to write
- int msdosf ;function call
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- dv_ctwr_ endp
-
- endcseg dv_op__
- end
-