home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
clarion
/
share.zip
/
SHARE.ASM
< prev
next >
Wrap
Assembly Source File
|
1985-08-16
|
15KB
|
425 lines
.LALL
PAGE 60,120
;-----------------------------------------------------------------------;
; Written by Craig E. Ransom ;
; of LOGISTICS SYSTEMS ENGINEERING, INC. ;
; ;
; Module: SHARE.ASM ;
; ;
; DOS Language Extension Module ;
; Shared DOS File Handler. For use with PC-MOS/386 ;
; for Pipe File Handling, etc. ;
; ;
; Include: SHAREMOD.CPY - Module Definition Copy ;
; SHARECDS.CPY - Equate Values for Codes ;
; ;
; SHARE_OPEN ;
; Opens Shared DOS file. ;
; Returns LONG File Handle. ;
; ;
; SHARE_READ ;
; Reads Data from Shared DOS File. ;
; Returns LONG count of characters read. ;
; ;
; SHARE_WRITE ;
; Writes Data to Shared DOS File. ;
; ;
; SHARE_CLOSE ;
; Closes Shared DOS File. ;
; ;
;-----------------------------------------------------------------------;
;-----------------------------------------------------------------------;
; L.E.M. equates ;
;-----------------------------------------------------------------------;
TSTRING EQU 0 ;String
TSHORT EQU 1 ;Signed word (16 bits)
TLONG EQU 2 ;Signed double word (32 bits)
TREAL EQU 4 ;Double precision float (8087)
PROCEDURE EQU 0 ;L.E.M. procedure
FUNCTION EQU 1 ;L.E.M. function
NAMELTH = 0 ;Define NAMELTH for macro
;-----------------------------------------------------------------------;
; L.E.M. macro ;
; ROUTINE 'ROUTINE NAME', ROUTINE_PROC_LABEL, ROUTINE_TYPE, ;
; NUMBER_OF_PARAMETERS ;
;-----------------------------------------------------------------------;
ROUTINE MACRO RNAME, RPROC, RTYPE, RPARMS
LOCAL LBLSTRT
LBLSTRT DB &RNAME
NAMELTH = $-LBLSTRT ;;Padd name with nulls to 13 bytes
IF NAMELTH GT 12
.ERR
%OUT routine name too long
ELSE
DB 13-NAMELTH DUP (0) ;;Rest of name area
DW &RPROC ;;Offset within binary module
DB &RTYPE ;;Routine type = PROCEDURE or FUNCTION
DB &RPARMS ;;Number of parameters
ENDIF
ENDM ;;End of macro
;-----------------------------------------------------------------------;
; L.E.M. macro ;
; PARAMETER LABEL_OF_PARAMETER, TYPE_OF_PARAMETER
;-----------------------------------------------------------------------;
PARAMETER MACRO PLBL, PTYPE
DB &PTYPE ;;Type = STRING, SHORT, LONG, or REAL
&PLBL DD 0 ;;Address of PARAMETER data
&PLBL&L DW 0 ;;Length of PARAMETER data
ENDM
;-----------------------------------------------------------------------;
; Start of CODE segment ;
;-----------------------------------------------------------------------;
CODE SEGMENT BYTE PUBLIC 'CODE' ;Will be loaded on a paragraph boundary
ASSUME CS:CODE,DS:CODE
;-----------------------------------------------------------------------;
; Binary module header ;
;-----------------------------------------------------------------------;
DB 'BIO' ;L.E.M Signature - Version 2.0
LIBVEC DD 0 ;Reserved for Runtime Library Vector!
DW BINEND ;Length of binary module
DB 4 ;Four routines in this L.E.M.
;-----------------------------------------------------------------------;
; SHARE_OPEN definition ;
; ;
; SHARE_OPEN ( FILENAME, OPENCODES ) ;
; Open Shared file specified by string FILENAME, ;
; with type of open and sharing specified by ;
; value in SHORT OPENCODES. Returns LONG File Handle ;
; which is used in subsequent SHARE instructions. ;
;-----------------------------------------------------------------------;
ROUTINE 'SHARE_OPEN', SHARE_OPEN, FUNCTION, 2
PARAMETER OPFILENAME, TSTRING
PARAMETER OPENCODES, TSHORT
;-----------------------------------------------------------------------;
; SHARE_READ definition ;
; ;
; SHARE_READ ( FILEHANDLE, BUFFER, MAXSIZE) ;
; Reads up to LONG MAXSIZE characters into STRING/ ;
; GROUP BUFFER from shared file FILEHANDLE. ;
; Returns LONG count of characters actually read. ;
; If return count = 0, file is at end. ;
;-----------------------------------------------------------------------;
ROUTINE 'SHARE_READ', SHARE_READ, FUNCTION, 3
PARAMETER READHANDLE, TLONG ; File handle from SHARE_OPEN
PARAMETER READBUFFER, TSTRING ; Buffer to Read data into
PARAMETER READMAXSIZE, TLONG ; Max characters to read
;-----------------------------------------------------------------------;
; SHARE_WRITE definition ;
; ;
; SHARE_WRITE ( FILEHANDLE, BUFFER, MAXSIZE) ;
; Writes LONG MAXSIZE characters from STRING/GROUP ;
; BUFFER to shared file FILEHANDLE. ;
; Returns LONG count of characters actually written. ;
; If return count = 0, file is at end. ;
;-----------------------------------------------------------------------;
ROUTINE 'SHARE_WRITE', SHARE_WRITE, FUNCTION, 3
PARAMETER WRITEHANDLE, TLONG ; File handle from SHARE_OPEN
PARAMETER WRITEBUFFER, TSTRING ; Buffer to Read data into
PARAMETER WRITEMAXSIZE, TLONG ; Max characters to read
;-----------------------------------------------------------------------;
; SHARE_CLOSE definition ;
; ;
; SHARE_CLOSE ( FILEHANDLE ) ;
; Close Shared file specified by FILEHANDLE. ;
;-----------------------------------------------------------------------;
ROUTINE 'SHARE_CLOSE', SHARE_CLOSE, PROCEDURE, 1
PARAMETER CLOSEHANDLE, TLONG
;-----------------------------------------------------------------------;
; Miscellaneous data area ;
; ;
; Common variables and constants for all routines ;
;-----------------------------------------------------------------------;
FNPTR DD 0 ;Pointer to ASCIIZ filename string
ASCIIZ DB 129 DUP(0) ;Copy name to here (up to 128)
;-----------------------------------------------------------------------;
; SHARE_OPEN ( FILENAME, OPENCODES ) ;
; ;
; Open Shared file specified by string FILENAME, ;
; with type of open and sharing specified by ;
; value in OPENCODES. Returns LONG File Handle, ;
; which is used in subsequent SHARE instructions. ;
;-----------------------------------------------------------------------;
SHARE_OPEN PROC FAR
Sub AX,AX ;Assume no error
Call SETGLOBERR
LES SI,OPFILENAME ; Set up for COPYNAME
Mov BP,ES
Mov CX,OPFILENAMEL
Call COPYNAME ; Copy to ASCIIZ
JC NAME_TOO_LONG ;Error from COPYNAME
LEA DX,ASCIIZ ;DS:DX - pointer to ASCIIZ filename
LES SI,OPENCODES ;FILE OPEN CODES
Mov AL,ES:[SI]
Mov AH,3Dh ;Submit file to OPEN
Int 21h ;Call DOS
JC ERROR_FROM_OPEN ;Error from OPEN
Mov word ptr [FNPTR],AX ;Save Handle
Mov word ptr [FNPTR+2],0
Mov AL,TLONG ;Set up return
LEA BX,FNPTR
Sub CX,CX
RET ;RETURN to Clarion program
ERROR_FROM_OPEN:
CMP AX,8 ;Was the error code less than 8?
JB OPEN_GLOBERR ; Yes, leave error code as is
CMP AX,12 ;Was the error code greater than 12?
JA OPEN_GLOBERR ; Yes, leave error code as is
Mov AX,5 ;If 8,9, or 12 -> 'access denied'
JMP OPEN_GLOBERR
NAME_TOO_LONG:
Mov AX,45 ;BAD FILE NAME
OPEN_GLOBERR:
Call SETGLOBERR ;Set GLOBERR to AX
RET ;Return to Clarion program
SHARE_OPEN ENDP
;-----------------------------------------------------------------------;
; SHARE_READ ( FILEHANDLE, BUFFER, MAXSIZE) ;
; ;
; Reads up to LONG MAXSIZE characters into STRING/ ;
; GROUP BUFFER from shared file FILEHANDLE. ;
; Return s LONG count of characters actually read. ;
; If return count = 0, file is at end. ;
;-----------------------------------------------------------------------;
SHARE_READ PROC FAR
Mov AX,0 ;Assume no error
Call SETGLOBERR
LES SI,READHANDLE ; Get File Handle
Mov BX,ES:[SI]
LES SI,READMAXSIZE ; Get Bytes to read (lo word)
Mov CX,ES:[SI]
Push DS
LDS DX,READBUFFER ; Get Buffer Addres
Mov AH,3Fh ;READ FILE
Int 21h ;Call DOS
Pop DS
JC ERROR_FROM_READ ;Error from READ
Mov word ptr [FNPTR],AX ;Save Bytes Actually Read
Mov word ptr [FNPTR+2],0
Cmp AX,0
JNE READ_EXIT
Mov AX,34 ;END OF FILE
Call SETGLOBERR ;Set GLOBERR to AX
READ_EXIT:
Mov AL,TLONG ;Set up return
LEA BX,FNPTR
RET ;RETURN to Clarion program
ERROR_FROM_READ:
Call SETGLOBERR ;Set GLOBERR to AX
RET ;Return to Clarion program
SHARE_READ ENDP
;-----------------------------------------------------------------------;
; SHARE_WRITE ( FILEHANDLE, BUFFER, MAXSIZE) ;
; ;
; Writes up to LONG MAXSIZE characters from STRING/ ;
; GROUP BUFFER to shared file FILEHANDLE. ;
; Return s LONG count of characters actually written. ;
; If return count = 0, file is at end. ;
;-----------------------------------------------------------------------;
SHARE_WRITE PROC FAR
Mov AX,0 ;Assume no error
Call SETGLOBERR
LES SI,WRITEHANDLE ; Get File Handle
Mov BX,ES:[SI]
LES SI,WRITEMAXSIZE ; Get Bytes to read (lo word)
Mov CX,ES:[SI]
Push DS
LDS DX,WRITEBUFFER ; Get Buffer Addres
Mov AH,40h ;WRITE FILE
Int 21h ;Call DOS
Pop DS
Mov word ptr [FNPTR],AX ;Save Bytes Actually Written
Mov word ptr [FNPTR+2],0
JC ERROR_FROM_WRITE ;Error from WRITE
CMP AX,0 ;CHECK FOR DISK FULL
JE WRITE_DISK_FULL
Mov AL,TLONG ;Set up return
LEA BX,FNPTR
RET ;RETURN to Clarion program
WRITE_DISK_FULL:
Mov AX,14 ;Use 'UNKNOWN DOS ERROR'
ERROR_FROM_WRITE:
Call SETGLOBERR ;Set GLOBERR to AX
RET ;Return to Clarion program
SHARE_WRITE ENDP
;-----------------------------------------------------------------------;
; SHARE_CLOSE ( FILEHANDLE ) ;
; ;
; Close Shared file specified by FILEHANDLE. ;
;-----------------------------------------------------------------------;
SHARE_CLOSE PROC FAR
LES SI,CLOSEHANDLE ; Get File Handle
Mov BX,ES:[SI] ; Low Word Only
Mov AH,3Eh ;Close File
Int 21h ;Call DOS
JC ERROR_FROM_CLOSE ;Error from OPEN
Mov AX,0 ;No error
ERROR_FROM_CLOSE:
Call SETGLOBERR ;Set GLOBERR to AX
RET ;Return to Clarion program
SHARE_CLOSE ENDP
;-----------------------------------------------------------------------;
; COPYNAME ;
; Internal subroutine for the DOS L.E.M. ;
; Copies source to ASCIIZ and clips trailing spaces ;
; Calls COPYSTRING ;
; Returns CARRY set if length longer than size of ASCIIZ - 1 ;
; ;
; CX = length of source ;
; BP:SI = address of source ;
;-----------------------------------------------------------------------;
COPYNAME PROC NEAR
CMP CX,SIZE ASCIIZ - 1
JBE DO_THE_COPY
STC ;Set error
RET ;Return to Caller in L.E.M.
DO_THE_COPY:
Push CX ;Save length
Push DS ;Save data segment
Push DS ;ES:DI = destination
Pop ES ;
LEA DI,ASCIIZ ;destination = ASCIIZ
Mov DS,BP ;BP:SI points to source
Call COPYSTRING
Pop DS
Pop CX
RET ;Return to caller in L.E.M.
COPYNAME ENDP ;End of COPYNAME
;-----------------------------------------------------------------------;
; COPYSTRING ;
; Internal subroutine for the DOS L.E.M. ;
; Copies a string and clips trailing spaces from the destination ;
; ;
; Expects: ;
; CX = length of source ;
; DS:SI = address of source ;
; ES:DI = address of destination ;
; ;
; Returns: ;
; CX = the length of the resultant destination after clipping ;
;-----------------------------------------------------------------------;
COPYSTRING PROC NEAR
Push CX ;Save length
Push SI ;Save source offset
Push DI ;Save dest offset
CLD ;Forward
REP MOVSB ;Move it
Mov BYTE PTR ES:[DI],0 ;Add null at end
Pop DI ;Restore dest offset
Pop SI ;Restore source offset
Pop CX ;Restore length
Push DI ;Save dest offset again
Mov AX,CX ;Set up count register
Dec AX ;Make relative to zero
Add DI,AX ;Point to end
Mov AL,20h ;Look for spaces
STD ;Backwards direction
REPZ SCASB ;Scan while equal to spaces
JNZ NOT_A_SPACE
Mov BYTE PTR ES:1[DI],0 ;String all spaces;put null at begin
JMP SHORT EXIT_COPYSTRING
NOT_A_SPACE:
INC CX ;Fix CX which is 1 too small
Mov BYTE PTR ES:2[DI],0 ;Null terminate after non-space
EXIT_COPYSTRING:
CLD ;Back to forward
CLC ;No error
Pop DI ;Restore dest offset
RET ;Return to caller in L.E.M.
COPYSTRING ENDP ;End of COPYSTRING
;-----------------------------------------------------------------------;
; SETGLOBERR ;
; Internal subroutine for the DOS L.E.M. ;
; Set global error returned by ERROR() and ERRORCODE() ;
; ;
; AX = error code ;
;-----------------------------------------------------------------------;
SETGLOBERR PROC NEAR
Push ES ;Save used registers
Push DI
Push AX ;Save error code
Mov AH,0FFh ;Get address of GLOBERR
Mov AL,29
Call dword ptr LIBVEC
Pop AX ;Get error code
Mov ES:[DI],AX ;Set GLOBERR
Pop DI ;Restore used registers
Pop ES
RET ;Return to caller in L.E.M.
SETGLOBERR ENDP ;End of SETGLOBERR
;-----------------------------------------------------------------------;
; End of L.E.M. ;
;-----------------------------------------------------------------------;
BINEND DB 0 ;Used to provide size of L.E.M.
CODE ENDS ;End of the code segment
END ;End of the DOS L.E.M.