home *** CD-ROM | disk | FTP | other *** search
- page 58,132
-
- ; dos2fun.asm
- ; contains: dos2append(),dos2create(),dos2delete(),dos2open(),dos2close(),
- ; contains: dos2read(),dos2write(),dosrename(),dosseek(),
- ;
-
- include model.h
- include prologue.h
- include equ.h
-
- name dos2fun
- pseg dos2appe
-
- ;==>-- long dos2append(table)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ;
- ;; DESCRIPTION:
- ; The file pointer is moved to the end of the file plus one byte
- ; such that subsequent write operations will append the file. The
- ; file size may be determined by checking the return value.
- ;
- ;; RETURNS:
- ; 0 == Error, else long integer location of file pointer following
- ; the seek.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dos2append,,dos2appe
- if _LDATA
- push ds
- lds si,parm1_
- else
- mov si,parm1_
- endif
- mov bx,[si+handle] ;get handle to BX
- xor cx,cx ;hi-order offset = 0
- xor dx,dx ;lo-order offset
- mov ax,4202h ;lseek EOF + (CX:DX)
- int 21h
- jc dos2a2 ;if error, leave now
- mov [si+fcbrec],ax ;hi-order part
- mov [si+_fcbr2],dx ;lo-order
- ifdef AXBX32
- mov bx,ax
- mov ax,dx
- endif
- jmp short dos2xit
- dos2a2: xor ax,ax ;indicate error to user
- ifdef AXBX32
- mov bx,ax
- else
- mov dx,ax
- endif
- dos2xit:
- if _LDATA
- pop ds
- endif
- cproce
-
- ;==>-- int dos2create(table)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ;
- ;; DESCRIPTION:
- ; Create a file, table->string must point to a string with drive,path
- ; and filename. table->dskfcb.dskattr.dattr.xxx must contain
- ; the attribute(s) to set.
- ;
- ;; RETURNS:
- ; file handle or -1 if error.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc dos2create,,dos2crea
- if _LDATA
- push ds
- lds si,parm1_ ;ds:si points to table
- else
- mov si,parm1_ ;ds:si points to table
- endif
- mov cl,[si+fattr]
- xor ch,ch ;cx = attribute
- if _LDATA
- push ds
- lds dx,[si+string] ;ds:dx = filename
- else
- mov dx,[si+string] ;ds:dx = filename
- endif
- mov ah,3ch ;dos file create function
- int 21h
- if _LDATA
- pop ds
- endif
- jnc d2cre2 ;hop if no error
- mov [si+status],ax ;error to status word
- mov ax,-1 ;error so return -1
- jmp short d2crexit
- d2cre2: mov [si+handle],ax ;save file handle.
- mov [si+status],0 ;set status to 0
- d2crexit:
- if _LDATA
- pop ds
- endif
- cproce
-
- ;==>-- unsigned dos2delete(table)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ;
- ;; DESCRIPTION:
- ; Deletes file specified in table->string
- ;
- ;; RETURNS:
- ; 1 if successful, 0 if unsuccessful
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dos2delete,,dos2dele
- if _LDATA
- push ds
- lds bx,parm1_ ;ds:bx points to DISKTABLE
- push ds
- lds dx,[bx+string] ;ds:dx points to string
- else
- mov bx,parm1_ ;ds:bx points to DISKTABLE
- mov dx,[bx+string] ;ds:dx points to string
- endif
- mov ah,41h ;function to delete
- int 21h
- if _LDATA
- pop ds
- endif
- jnc d2del2 ;hop no error
- mov [bx+status],ax ;indicate error code
- xor ax,ax
- jmp short d2delxit
- d2del2:
- mov [bx+status],0
- mov ax,1 ;indicate success
- d2delxit:
- if _LDATA
- pop ds
- endif
- cproce
-
- ;==>-- int dos2open(table,mode)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ; (int) mode - open mode:
- ; 0=Read,1=Write,2=Read/Write
- ;
- ;; DESCRIPTION:
- ; Open file, a drive,path and file name are specified by
- ; table->string. The mode parameter specifies the file mode.
- ;
- ;; RETURNS:
- ; dos file handle or -1 if error
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc dos2open
- if _LDATA
- push ds
- lds si,parm1_ ;ds:si=structure
- push ds
- lds dx,[si+string] ;ds:dx point to filename
- mov al,parm3_ ;al = mode
- mov ah,3dh ;open a file function
- int 21h
- pop ds ;ds:si point to structure
- else
- mov si,parm1_ ;ds:si=structure
- mov dx,[si+string] ;ds:dx point to filename
- mov al,parm2_ ;al=mode
- mov ah,3dh
- int 21h
- endif
- jnc d2opn2 ;if no error AX=file handle
- mov [si+status],ax ;else save error code
- mov ax,-1 ;indicate error
- jmp short d2opex
- d2opn2: mov [si+handle],ax ;save handle in structure
- mov [si+status],0 ;zero status byte
- d2opex:
- if _LDATA
- pop ds
- endif
- cproce
-
- ;==>-- int dos2close(table)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ;
- ;; DESCRIPTION:
- ; Close file, use handle stored in DISKTABLE
- ;
- ;; RETURNS:
- ; 1=success, 0=error, error code in table->status
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dos2close,,dos2clos
- if _LDATA
- push ds
- lds si,parm1_ ;DS:SI -> struc
- else
- mov si,parm1_
- endif
- mov bx,[si+handle] ;get handle to close
- mov ah,3Eh
- int 21h
- jnc d2clo2 ;hop no error
- mov [si+status],ax ;else store status
- xor ax,ax ;indicate error
- jmp short d2cloxit
- d2clo2: mov [si+status],0
- mov ax,1 ;indicate success
- d2cloxit:
- if _LDATA
- pop ds
- endif
- cproce
-
- ;==>-- unsigned dos2read(table)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ;
- ;; DESCRIPTION:
- ; Write to file, table->handle - handle to use, table->rbytes -
- ; number of bytes to read, table->buffer points to address
- ; to read to.
- ;
- ;; RETURNS:
- ; Number of bytes read, if 0 an error code is placed in
- ; table->status.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc dos2read
- if _LDATA
- push ds
- lds si,parm1_ ;ds:si points to parameter
- else
- mov si,parm1_ ;ds:si points to parameter
- endif
- mov [si+abytes],0
- mov [si+status],0
- mov bx,[si+handle] ;ax=files handle
- mov cx,[si+rbytes] ;cx=number of bytes
- if _LDATA
- push ds
- lds dx,[si+buffer] ;ds:dx points to buffer
- else
- mov dx,[si+buffer] ;ds:dx points to buffer
- endif
- mov ah,3fh ;3f=read function
- int 21h ;call ms. dos
- if _LDATA
- pop ds ;ds:si points to parameter
- endif
- jnc rdok
- mov [si+status],ax
- xor ax,ax ;indicate 0 bytes
- jmp short rdex ;and exit
- rdok: mov [si+abytes],ax ;store number of bytes read
- rdex:
- if _LDATA
- pop ds
- endif
- cproce
-
- ;==>-- unsigned dos2write(table)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ;
- ;; DESCRIPTION:
- ; Read from file, table->handle - handle to use, table->rbytes -
- ; number of bytes to write, table->buffer points to address
- ; to write from.
- ;
- ;; RETURNS:
- ; Number of bytes written, if 0 an error code is placed in
- ; table->status.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc dos2write,,dos2writ
- if _LDATA
- push ds
- lds si,parm1_ ;ds:si points to parameter
- else
- mov si,parm1_ ;ds:si points to parameter
- endif
- mov [si+abytes],0
- mov [si+status],0
- mov bx,[si+handle] ;bx=files handle
- mov cx,[si+rbytes] ;cx=number of bytes
- if _LDATA
- push ds
- lds dx,[si+buffer] ;ds:dx points to buffer
- else
- mov dx,[si+buffer] ;ds:dx points to buffer
- endif
- mov ah,40h ;40=write function
- int 21h ;call ms. dos
- if _LDATA
- pop ds ;ds:si points to parameter
- endif
- jnc wtok
- mov [si+status],ax
- xor ax,ax ;indicate 0 bytes
- jmp short wtex ;and exit
- wtok: mov [si+abytes],ax ;store number of bytes read
- wtex:
- if _LDATA
- pop ds
- endif
- cproce
-
-
- ;==>-- int dosrename(from,to)
- ;
- ;; ARGUMENTS:
- ; (char *) from - Existing filename
- ; (char *) to - New filename
- ;
- ;; DESCRIPTION:
- ; Rename file
- ;
- ;; RETURNS:
- ; 0 if successful, else dos error code
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dosrename,,dosrenam
- mov ah,30h ;get DOS version
- int 21h
- cmp al,0
- mov ax,-1
- jz dosrenxit
- if _LDATA
- push ds
- push es
- lds dx,parm1_ ;ds:dx points to existing name
- les di,parm3_ ;es:di points to new name
- else
- push es
- mov ax,ds
- mov es,ax ;es==ds
- mov dx,parm1_ ;ds:dx points to existing name
- mov di,parm2_ ;es:di points to new name
- endif
- mov ah,56h ; function number in AH
- int 21h
- if _LDATA
- pop es
- pop ds
- else
- pop es
- endif
- jc dosrenxit ;if error return value
- xor ax,ax ;else indicate success with 0
- dosrenxit: ;Return 0
- cproce
-
- ;==>-- long dosseek(table,offset,mode)
- ;
- ;; ARGUMENTS:
- ; (struct DISKTABLE *) table - points to DISKTABLE
- ; (long) offset - offset to seek
- ; (int) mode - seek mode:
- ; 0=move pointer to offset bytes
- ; from the beginning of the
- ; file.
- ; 1=move to current offset plus
- ; offset bytes.
- ; 2=move to end of file plus
- ; offset bytes.
- ;
- ;; DESCRIPTION:
- ; Seek (Move file pointer)
- ;
- ;; RETURNS:
- ; New location of file pointer in bytes. If unsuccessful, returns
- ; (long) -1, with error code in tbl->status.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dosseek
- if _LDATA
- push ds
- lds bx,parm1_ ;ds:bx points to DISKTABLE
- mov dx,parm3_ ;dx = low order part of offset
- mov cx,parm4_ ;cx = high order part of offset
- mov al,parm5_ ;al = mode
- else
- mov bx,parm1_ ;ds:bx points to DISKTABLE
- mov dx,parm2_ ;dx = low order part of offset
- mov cx,parm3_ ;cx = high order part of offset
- mov al,parm4_ ;al = mode
- endif
- push bx
- mov bx,[bx+handle] ;bx=handle
- mov ah,42h
- int 21h
- pop bx
- jc seeker
- mov [bx+status],0
- mov [bx+fcbrec],dx ;new offset
- mov [bx+_fcbr2],ax
- ifdef AXBX32
- mov bx,ax
- mov ax,dx
- endif
- jmp short seekxit
- seeker: mov [bx+status],ax
- mov ax,-1
- mov bx,ax
- mov dx,ax ;all returns are -1
- seekxit:
- if _LDATA
- pop ds
- endif
- cproce
- endps
- end
-