home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / clarion / share.zip / SHARE.ASM < prev    next >
Assembly Source File  |  1985-08-16  |  15KB  |  425 lines

  1.     .LALL
  2.     PAGE    60,120
  3. ;-----------------------------------------------------------------------;
  4. ;    Written by Craig E. Ransom                    ;
  5. ;    of LOGISTICS SYSTEMS ENGINEERING, INC.                ;
  6. ;                                    ;
  7. ;    Module: SHARE.ASM                        ;
  8. ;                                    ;
  9. ;         DOS Language Extension Module                ;
  10. ;         Shared DOS File Handler.    For use with PC-MOS/386        ;
  11. ;           for Pipe File Handling, etc.                ;
  12. ;                                    ;
  13. ;         Include:  SHAREMOD.CPY - Module Definition Copy        ;
  14. ;               SHARECDS.CPY - Equate Values for Codes        ;
  15. ;                                    ;
  16. ;         SHARE_OPEN                            ;
  17. ;             Opens Shared DOS file.                ;
  18. ;             Returns LONG File Handle.                ;
  19. ;                                    ;
  20. ;         SHARE_READ                            ;
  21. ;             Reads Data from Shared DOS File.            ;
  22. ;             Returns LONG count of characters read.        ;
  23. ;                                    ;
  24. ;         SHARE_WRITE                        ;
  25. ;             Writes Data to Shared DOS File.            ;
  26. ;                                    ;
  27. ;         SHARE_CLOSE                        ;
  28. ;             Closes Shared DOS File.                ;
  29. ;                                    ;
  30. ;-----------------------------------------------------------------------;
  31.  
  32. ;-----------------------------------------------------------------------;
  33. ; L.E.M.  equates                            ;
  34. ;-----------------------------------------------------------------------;
  35. TSTRING EQU    0            ;String
  36. TSHORT    EQU    1            ;Signed word (16 bits)
  37. TLONG    EQU    2            ;Signed double word (32 bits)
  38. TREAL    EQU    4            ;Double precision float (8087)
  39.  
  40. PROCEDURE    EQU    0        ;L.E.M. procedure
  41. FUNCTION    EQU    1        ;L.E.M. function
  42.  
  43. NAMELTH = 0                ;Define NAMELTH for macro
  44.  
  45. ;-----------------------------------------------------------------------;
  46. ; L.E.M.  macro                                ;
  47. ;    ROUTINE 'ROUTINE NAME', ROUTINE_PROC_LABEL, ROUTINE_TYPE,    ;
  48. ;            NUMBER_OF_PARAMETERS                ;
  49. ;-----------------------------------------------------------------------;
  50. ROUTINE MACRO    RNAME, RPROC, RTYPE, RPARMS
  51.     LOCAL    LBLSTRT
  52. LBLSTRT DB    &RNAME
  53. NAMELTH =    $-LBLSTRT        ;;Padd name with nulls to 13 bytes
  54.     IF NAMELTH GT 12
  55.       .ERR
  56.       %OUT routine name too long
  57.     ELSE
  58.       DB    13-NAMELTH DUP (0)    ;;Rest of name area
  59.       DW    &RPROC            ;;Offset within binary module
  60.       DB    &RTYPE            ;;Routine type = PROCEDURE or FUNCTION
  61.       DB    &RPARMS            ;;Number of parameters
  62.     ENDIF
  63.     ENDM                ;;End of macro
  64.  
  65. ;-----------------------------------------------------------------------;
  66. ; L.E.M.  macro                                ;
  67. ;    PARAMETER LABEL_OF_PARAMETER, TYPE_OF_PARAMETER
  68. ;-----------------------------------------------------------------------;
  69. PARAMETER    MACRO    PLBL, PTYPE
  70.     DB    &PTYPE            ;;Type = STRING, SHORT, LONG, or REAL
  71. &PLBL    DD    0            ;;Address of PARAMETER data
  72. &PLBL&L DW    0            ;;Length of PARAMETER data
  73.     ENDM
  74.  
  75. ;-----------------------------------------------------------------------;
  76. ; Start of CODE segment                            ;
  77. ;-----------------------------------------------------------------------;
  78. CODE    SEGMENT BYTE PUBLIC 'CODE'    ;Will be loaded on a paragraph boundary
  79.     ASSUME    CS:CODE,DS:CODE
  80.  
  81. ;-----------------------------------------------------------------------;
  82. ; Binary module header                            ;
  83. ;-----------------------------------------------------------------------;
  84.     DB    'BIO'            ;L.E.M Signature - Version 2.0
  85. LIBVEC    DD    0            ;Reserved for Runtime Library Vector!
  86.     DW    BINEND            ;Length of binary module
  87.     DB    4            ;Four routines in this L.E.M.
  88.  
  89. ;-----------------------------------------------------------------------;
  90. ; SHARE_OPEN definition                            ;
  91. ;                                    ;
  92. ;         SHARE_OPEN ( FILENAME, OPENCODES )                ;
  93. ;             Open Shared file specified by string FILENAME,    ;
  94. ;             with type of open and sharing specified by        ;
  95. ;             value in SHORT OPENCODES. Returns LONG File Handle ;
  96. ;             which is used in subsequent SHARE instructions.    ;
  97. ;-----------------------------------------------------------------------;
  98.     ROUTINE        'SHARE_OPEN', SHARE_OPEN, FUNCTION, 2
  99.     PARAMETER    OPFILENAME, TSTRING
  100.     PARAMETER    OPENCODES,  TSHORT
  101.  
  102. ;-----------------------------------------------------------------------;
  103. ; SHARE_READ definition                            ;
  104. ;                                    ;
  105. ;         SHARE_READ ( FILEHANDLE, BUFFER, MAXSIZE)            ;
  106. ;             Reads up to LONG MAXSIZE characters into STRING/    ;
  107. ;             GROUP BUFFER from shared file FILEHANDLE.        ;
  108. ;             Returns LONG count of characters actually read.    ;
  109. ;             If return count = 0, file is at end.        ;
  110. ;-----------------------------------------------------------------------;
  111.     ROUTINE         'SHARE_READ', SHARE_READ, FUNCTION, 3
  112.     PARAMETER    READHANDLE, TLONG         ; File handle from SHARE_OPEN
  113.     PARAMETER    READBUFFER, TSTRING     ; Buffer to Read data into
  114.     PARAMETER    READMAXSIZE, TLONG         ; Max characters to read
  115.  
  116. ;-----------------------------------------------------------------------;
  117. ; SHARE_WRITE definition                        ;
  118. ;                                    ;
  119. ;         SHARE_WRITE ( FILEHANDLE, BUFFER, MAXSIZE)            ;
  120. ;             Writes LONG MAXSIZE characters from STRING/GROUP    ;
  121. ;             BUFFER to shared file FILEHANDLE.            ;
  122. ;             Returns LONG count of characters actually written. ;
  123. ;             If return count = 0, file is at end.        ;
  124. ;-----------------------------------------------------------------------;
  125.     ROUTINE         'SHARE_WRITE', SHARE_WRITE, FUNCTION, 3
  126.     PARAMETER    WRITEHANDLE, TLONG         ; File handle from SHARE_OPEN
  127.     PARAMETER    WRITEBUFFER, TSTRING    ; Buffer to Read data into
  128.     PARAMETER    WRITEMAXSIZE, TLONG     ; Max characters to read
  129.  
  130. ;-----------------------------------------------------------------------;
  131. ; SHARE_CLOSE definition                        ;
  132. ;                                    ;
  133. ;         SHARE_CLOSE ( FILEHANDLE )                    ;
  134. ;             Close Shared file specified by FILEHANDLE.        ;
  135. ;-----------------------------------------------------------------------;
  136.     ROUTINE        'SHARE_CLOSE', SHARE_CLOSE, PROCEDURE, 1
  137.     PARAMETER    CLOSEHANDLE, TLONG
  138.  
  139. ;-----------------------------------------------------------------------;
  140. ; Miscellaneous data area                        ;
  141. ;                                    ;
  142. ; Common variables and constants for all routines            ;
  143. ;-----------------------------------------------------------------------;
  144. FNPTR    DD    0            ;Pointer to ASCIIZ filename string
  145.  
  146. ASCIIZ    DB    129 DUP(0)        ;Copy name to here (up to 128)
  147.  
  148. ;-----------------------------------------------------------------------;
  149. ; SHARE_OPEN ( FILENAME, OPENCODES )                    ;
  150. ;                                    ;
  151. ;      Open Shared file specified by string FILENAME,        ;
  152. ;      with type of open and sharing specified by            ;
  153. ;      value in OPENCODES.  Returns LONG File Handle,        ;
  154. ;      which is used in subsequent SHARE instructions.        ;
  155. ;-----------------------------------------------------------------------;
  156. SHARE_OPEN   PROC    FAR
  157.  
  158.          Sub     AX,AX             ;Assume no error
  159.          Call    SETGLOBERR
  160.  
  161.          LES     SI,OPFILENAME         ; Set up for COPYNAME
  162.          Mov     BP,ES
  163.          Mov     CX,OPFILENAMEL
  164.  
  165.          Call    COPYNAME             ; Copy to ASCIIZ
  166.          JC         NAME_TOO_LONG         ;Error from COPYNAME
  167.  
  168.          LEA     DX,ASCIIZ             ;DS:DX - pointer to ASCIIZ filename
  169.          LES     SI,OPENCODES         ;FILE OPEN CODES
  170.          Mov     AL,ES:[SI]
  171.  
  172.          Mov     AH,3Dh             ;Submit file to OPEN
  173.          Int     21h             ;Call DOS
  174.          JC         ERROR_FROM_OPEN         ;Error from OPEN
  175.  
  176.          Mov     word ptr [FNPTR],AX     ;Save Handle
  177.          Mov     word ptr [FNPTR+2],0
  178.  
  179.          Mov     AL,TLONG             ;Set up return
  180.          LEA     BX,FNPTR
  181.          Sub     CX,CX
  182.  
  183.          RET                 ;RETURN to Clarion program
  184.  
  185. ERROR_FROM_OPEN:
  186.          CMP     AX,8             ;Was the error code less than 8?
  187.          JB         OPEN_GLOBERR         ;    Yes, leave error code as is
  188.          CMP     AX,12             ;Was the error code greater than 12?
  189.          JA         OPEN_GLOBERR         ;    Yes, leave error code as is
  190.  
  191.          Mov     AX,5             ;If 8,9, or 12 -> 'access denied'
  192.          JMP     OPEN_GLOBERR
  193.  
  194. NAME_TOO_LONG:
  195.          Mov     AX,45             ;BAD FILE NAME
  196.  
  197. OPEN_GLOBERR:
  198.          Call    SETGLOBERR             ;Set GLOBERR to AX
  199.          RET                 ;Return to Clarion program
  200.  
  201. SHARE_OPEN   ENDP
  202.  
  203. ;-----------------------------------------------------------------------;
  204. ; SHARE_READ ( FILEHANDLE, BUFFER, MAXSIZE)                ;
  205. ;                                    ;
  206. ;      Reads up to LONG MAXSIZE characters into STRING/        ;
  207. ;      GROUP BUFFER from shared file FILEHANDLE.            ;
  208. ;      Return s LONG count of characters actually read.        ;
  209. ;      If return count = 0, file is at end.                ;
  210. ;-----------------------------------------------------------------------;
  211. SHARE_READ   PROC    FAR
  212.  
  213.          Mov     AX,0             ;Assume no error
  214.          Call    SETGLOBERR
  215.  
  216.          LES     SI,READHANDLE         ; Get File Handle
  217.          Mov     BX,ES:[SI]
  218.  
  219.          LES     SI,READMAXSIZE         ; Get Bytes to read (lo word)
  220.          Mov     CX,ES:[SI]
  221.  
  222.          Push    DS
  223.          LDS     DX,READBUFFER         ; Get Buffer Addres
  224.  
  225.          Mov     AH,3Fh             ;READ FILE
  226.          Int     21h             ;Call DOS
  227.  
  228.          Pop     DS
  229.  
  230.          JC         ERROR_FROM_READ         ;Error from READ
  231.  
  232.          Mov     word ptr [FNPTR],AX     ;Save Bytes Actually Read
  233.          Mov     word ptr [FNPTR+2],0
  234.  
  235.          Cmp     AX,0
  236.          JNE     READ_EXIT
  237.  
  238.          Mov     AX,34             ;END OF FILE
  239.          Call    SETGLOBERR             ;Set GLOBERR to AX
  240.  
  241. READ_EXIT:
  242.  
  243.          Mov     AL,TLONG             ;Set up return
  244.          LEA     BX,FNPTR
  245.  
  246.          RET                 ;RETURN to Clarion program
  247.  
  248. ERROR_FROM_READ:
  249.  
  250.          Call    SETGLOBERR             ;Set GLOBERR to AX
  251.          RET                 ;Return to Clarion program
  252.  
  253. SHARE_READ   ENDP
  254.  
  255. ;-----------------------------------------------------------------------;
  256. ; SHARE_WRITE ( FILEHANDLE, BUFFER, MAXSIZE)                ;
  257. ;                                    ;
  258. ;      Writes up to LONG MAXSIZE characters from STRING/        ;
  259. ;      GROUP BUFFER to shared file FILEHANDLE.            ;
  260. ;      Return s LONG count of characters actually written.        ;
  261. ;      If return count = 0, file is at end.                ;
  262. ;-----------------------------------------------------------------------;
  263. SHARE_WRITE  PROC    FAR
  264.  
  265.          Mov     AX,0             ;Assume no error
  266.          Call    SETGLOBERR
  267.  
  268.          LES     SI,WRITEHANDLE         ; Get File Handle
  269.          Mov     BX,ES:[SI]
  270.  
  271.          LES     SI,WRITEMAXSIZE         ; Get Bytes to read (lo word)
  272.          Mov     CX,ES:[SI]
  273.  
  274.          Push    DS
  275.          LDS     DX,WRITEBUFFER         ; Get Buffer Addres
  276.  
  277.          Mov     AH,40h             ;WRITE FILE
  278.          Int     21h             ;Call DOS
  279.  
  280.          Pop     DS
  281.  
  282.          Mov     word ptr [FNPTR],AX     ;Save Bytes Actually Written
  283.          Mov     word ptr [FNPTR+2],0
  284.  
  285.          JC         ERROR_FROM_WRITE         ;Error from WRITE
  286.  
  287.          CMP     AX,0             ;CHECK FOR DISK FULL
  288.          JE         WRITE_DISK_FULL
  289.  
  290.          Mov     AL,TLONG             ;Set up return
  291.          LEA     BX,FNPTR
  292.  
  293.          RET                 ;RETURN to Clarion program
  294.  
  295. WRITE_DISK_FULL:
  296.          Mov     AX,14             ;Use 'UNKNOWN DOS ERROR'
  297.  
  298. ERROR_FROM_WRITE:
  299.          Call    SETGLOBERR             ;Set GLOBERR to AX
  300.          RET                 ;Return to Clarion program
  301.  
  302. SHARE_WRITE  ENDP
  303.  
  304. ;-----------------------------------------------------------------------;
  305. ; SHARE_CLOSE ( FILEHANDLE )                        ;
  306. ;                                    ;
  307. ;      Close Shared file specified by FILEHANDLE.            ;
  308. ;-----------------------------------------------------------------------;
  309. SHARE_CLOSE  PROC    FAR
  310.  
  311.          LES     SI,CLOSEHANDLE         ; Get File Handle
  312.          Mov     BX,ES:[SI]             ; Low Word Only
  313.  
  314.          Mov     AH,3Eh             ;Close File
  315.          Int     21h             ;Call DOS
  316.          JC         ERROR_FROM_CLOSE         ;Error from OPEN
  317.  
  318.          Mov     AX,0             ;No error
  319.  
  320. ERROR_FROM_CLOSE:
  321.  
  322.          Call    SETGLOBERR             ;Set GLOBERR to AX
  323.          RET                 ;Return to Clarion program
  324.  
  325. SHARE_CLOSE  ENDP
  326.  
  327. ;-----------------------------------------------------------------------;
  328. ; COPYNAME                                ;
  329. ;    Internal subroutine for the DOS L.E.M.                ;
  330. ;    Copies source to ASCIIZ and clips trailing spaces        ;
  331. ;    Calls COPYSTRING                        ;
  332. ;    Returns CARRY set if length longer than size of ASCIIZ - 1    ;
  333. ;                                    ;
  334. ;    CX    = length of source                    ;
  335. ;    BP:SI = address of source                    ;
  336. ;-----------------------------------------------------------------------;
  337. COPYNAME    PROC    NEAR
  338.     CMP    CX,SIZE ASCIIZ - 1
  339.     JBE    DO_THE_COPY
  340.     STC                ;Set error
  341.     RET                ;Return to Caller in L.E.M.
  342. DO_THE_COPY:
  343.     Push    CX            ;Save length
  344.     Push    DS            ;Save data segment
  345.     Push    DS            ;ES:DI = destination
  346.     Pop    ES            ;
  347.     LEA    DI,ASCIIZ        ;destination = ASCIIZ
  348.     Mov    DS,BP            ;BP:SI points to source
  349.     Call    COPYSTRING
  350.     Pop    DS
  351.     Pop    CX
  352.     RET                ;Return to caller in L.E.M.
  353. COPYNAME    ENDP            ;End of COPYNAME
  354.  
  355. ;-----------------------------------------------------------------------;
  356. ; COPYSTRING                                ;
  357. ;    Internal subroutine for the DOS L.E.M.                ;
  358. ;    Copies a string and clips trailing spaces from the destination    ;
  359. ;                                    ;
  360. ; Expects:                                ;
  361. ;    CX    = length of source                    ;
  362. ;    DS:SI = address of source                    ;
  363. ;    ES:DI = address of destination                    ;
  364. ;                                    ;
  365. ; Returns:                                ;
  366. ;    CX = the length of the resultant destination after clipping    ;
  367. ;-----------------------------------------------------------------------;
  368. COPYSTRING    PROC    NEAR
  369.     Push    CX            ;Save length
  370.     Push    SI            ;Save source offset
  371.     Push    DI            ;Save dest offset
  372.     CLD                ;Forward
  373.     REP    MOVSB            ;Move it
  374.     Mov    BYTE PTR ES:[DI],0    ;Add null at end
  375.     Pop    DI            ;Restore dest offset
  376.     Pop    SI            ;Restore source offset
  377.     Pop    CX            ;Restore length
  378.     Push    DI            ;Save dest offset again
  379.     Mov    AX,CX            ;Set up count register
  380.     Dec    AX            ;Make relative to zero
  381.     Add    DI,AX            ;Point to end
  382.     Mov    AL,20h            ;Look for spaces
  383.     STD                ;Backwards direction
  384.     REPZ    SCASB            ;Scan while equal to spaces
  385.     JNZ    NOT_A_SPACE
  386.     Mov    BYTE PTR ES:1[DI],0    ;String all spaces;put null at begin
  387.     JMP    SHORT EXIT_COPYSTRING
  388. NOT_A_SPACE:
  389.     INC    CX            ;Fix CX which is 1 too small
  390.     Mov    BYTE PTR ES:2[DI],0    ;Null terminate after non-space
  391. EXIT_COPYSTRING:
  392.     CLD                ;Back to forward
  393.     CLC                ;No error
  394.     Pop    DI            ;Restore dest offset
  395.     RET                ;Return to caller in L.E.M.
  396. COPYSTRING    ENDP            ;End of COPYSTRING
  397.  
  398. ;-----------------------------------------------------------------------;
  399. ; SETGLOBERR                                ;
  400. ;    Internal subroutine for the DOS L.E.M.                ;
  401. ;    Set global error returned by ERROR() and ERRORCODE()        ;
  402. ;                                    ;
  403. ;    AX = error code                            ;
  404. ;-----------------------------------------------------------------------;
  405. SETGLOBERR    PROC    NEAR
  406.     Push    ES            ;Save used registers
  407.     Push    DI
  408.     Push    AX            ;Save error code
  409.     Mov    AH,0FFh            ;Get address of GLOBERR
  410.     Mov    AL,29
  411.     Call    dword ptr LIBVEC
  412.     Pop    AX            ;Get error code
  413.     Mov    ES:[DI],AX        ;Set GLOBERR
  414.     Pop    DI            ;Restore used registers
  415.     Pop    ES
  416.     RET                ;Return to caller in L.E.M.
  417. SETGLOBERR    ENDP            ;End of SETGLOBERR
  418.  
  419. ;-----------------------------------------------------------------------;
  420. ; End of L.E.M.                                ;
  421. ;-----------------------------------------------------------------------;
  422. BINEND    DB    0            ;Used to provide size of L.E.M.
  423. CODE    ENDS                ;End of the code segment
  424.     END                ;End of the DOS L.E.M.
  425.