home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / croutes.zip / IOS1-20.ASM < prev    next >
Assembly Source File  |  1984-07-29  |  7KB  |  309 lines

  1. title    Level 1 I/O Functions for Lattice 'c' Version 1.04
  2. page    64,132
  3. name    IOS1_20 ;DOS function calls 3DH, 3EH, 3FH, 40H, AND 42H.
  4. comment |
  5.    These functions take advantage of DOS 2.0 and will directly
  6. replace the original level 1 I/O except that 'text mode' is
  7. not supported.    DOS error numbers are saved at ERRNO and may be
  8. checked by including: "extern short errno;" in your source files.
  9. Note that the pmode parameter in creat is forced to zero, due to
  10. a problem with Lattice's freopen which passes a 1A4H to creat.
  11.  
  12.          Ted Reuss       c/o South Texas Software, Inc.
  13.     Home: 713/961-3926    4544 Post Oak Place, Suite 176
  14.     Offi: 713/877-8205    Houston, Tx 77027
  15.     |
  16.     public    CREAT, OPEN, CLOSE, READ, WRITE, LSEEK
  17. dgroup    group    data
  18. data    segment word public 'data'
  19.     assume    ds:dgroup
  20.  
  21.     public    ERRNO
  22. ERRNO    dw    0    ; DOS error number (DOS Manual page D-14)
  23. data    ends
  24.  
  25. pgroup    group    prog
  26. prog    segment byte public 'prog'
  27.     assume    cs:pgroup
  28.  
  29.     subttl    CREAT -- create a new file
  30.     page
  31. ;
  32. ; NAME
  33. ;    creat -- create a new file
  34. ;
  35. ; SYNOPSIS
  36. ;
  37. ;    file = creat(name, pmode);
  38. ;    int file;    file number or error code
  39. ;    char *name;    file name (valid drive\path\filespec)
  40. ;    int pmode;    access privilege mode bits, DOS attribute
  41. ;            NOTE: forced to zero in current version.
  42. ;
  43. ; DESCRIPTION
  44. ;
  45. ;    Creates a new file with the specified name and prepares is
  46. ;    for access via the level 1 I/O functions.  The file name
  47. ;    may consist of a valid drive and path name.  All I/O is
  48. ;    done via DOS calls 3fh (READ) and 40h (WRITE).    If the file
  49. ;    already exists, it's contents are discarded.  The current file
  50. ;    position and the end of file are both zero. (indicating an
  51. ;    empty file) if the function is successful. ERRNO is set to
  52. ;    the error number returned by DOS in the event of an error.
  53. ;
  54. ; RETURNS
  55. ;    file = file number to access file, if successful
  56. ;         = -1 if error  (ERRNO get DOS error number)
  57. ;
  58.  
  59.     public    CREAT
  60. CREAT    proc    near
  61.     push    bp
  62.     mov    bp,sp
  63.     mov    dx,[bp+4]    ;get ptr to drive\path\filespec
  64.     xor    cx,cx
  65.     mov    ah,3CH        ;DOS create function
  66.     int    21H
  67.     jnc    cre10
  68.     mov    dgroup:errno,ax
  69.     mov    ax,-1
  70. cre10:    mov    sp,bp
  71.     pop    bp
  72.     ret
  73. CREAT    endp
  74.  
  75.     subttl    OPEN -- open a file
  76.     page
  77. ;
  78. ; NAME
  79. ;    open -- open a file
  80. ;
  81. ; SYNOPSIS
  82. ;
  83. ;    file = open(name, rwmode);
  84. ;    int file;    file number or error code
  85. ;    char *name;    file name (valid drive\path\filespec)
  86. ;    int rwmode;    read/write mode, where 0=read, 1=write,
  87. ;            2=read/write
  88. ;
  89. ; DESCRIPTION
  90. ;
  91. ;    Opens a file for access using the level 1 I/O functions.
  92. ;    The file name may contain a valid drive and path name.    All
  93. ;    I/O is done via DOS functions 3fh (READ) and 40h (WRITE).
  94. ;    The mode word determines the type of I/O which will be
  95. ;    performed on the file.    The low order bits specify whether
  96. ;    read or write operations (or both) are to be allowed.
  97. ;    In the event of an error the error code passed by DOS is
  98. ;    saved at ERRNO.
  99. ;
  100. ; RETURNS
  101. ;
  102. ;    file = file number to access file, if successful
  103. ;         = -1 if error  (ERRNO get DOS error number)
  104. ;
  105.  
  106.     public    OPEN
  107. OPEN    proc    near
  108.     push    bp
  109.     mov    bp,sp
  110.     mov    dx,[bp+4]    ;get ptr to drive\path\filespec
  111.     mov    ax,[bp+6]    ;get mode
  112.     mov    ah,3DH        ;DOS open function
  113.     int    21H
  114.     jnc    opn10
  115.     mov    dgroup:errno,ax
  116.     mov    ax,-1
  117. opn10:    mov    sp,bp
  118.     pop    bp
  119.     ret
  120. OPEN    endp
  121.  
  122.     subttl    CLOSE -- close a file
  123.     page
  124. ;
  125. ; NAME
  126. ;
  127. ;    close -- close a file
  128. ;
  129. ; SYNOPSIS
  130. ;
  131. ;    status = close(file);
  132. ;    int status;    status code: 0 if successful
  133. ;    int file;    file number for file
  134. ;
  135. ; DESCRIPTION
  136. ;
  137. ;    Close a file and frees the file number for use in accessing
  138. ;    another file.  Any buffers allocated when the file was
  139. ;    opened are released.
  140. ;
  141. ; RETURNS
  142. ;
  143. ;    status = 0 if successful
  144. ;           = -1 if error  (ERRNO get DOS error number)
  145. ;
  146.  
  147.     public    CLOSE
  148. CLOSE    proc    near
  149.     push    bp
  150.     mov    bp,sp
  151.     mov    bx,[bp+4]    ;get file handle
  152.     mov    ah,3EH        ;DOS close function
  153.     int    21H
  154.     jc     clo10
  155.     xor    ax,ax
  156.     jmp    short clo20
  157. clo10:    mov    dgroup:errno,ax
  158.     mov    ax,-1
  159. clo20:    mov    sp,bp
  160.     pop    bp
  161.     ret
  162. CLOSE    endp
  163.  
  164.     subttl    READ -- read data from file
  165.     page
  166. ;
  167. ; NAME
  168. ;
  169. ;    read -- read data from file
  170. ;
  171. ; SYNOPSIS
  172. ;
  173. ;    status = read(file, buffer, length);
  174. ;    int status;    status code or actual length
  175. ;    int file;    file number for file
  176. ;    char *buffer;    input buffer
  177. ;    int length;    number of bytes requested
  178. ;
  179. ; DESCRIPTION
  180. ;
  181. ;    Reads next set of bytes from a file.  The return count
  182. ;    is always equal to the number of bytes placed in the buffer
  183. ;    and will never exceed the "length" parameter, except in the
  184. ;    case of an error, where -1 is returned.  The file position
  185. ;    is advanced accordingly.
  186. ;
  187. ; RETURNS
  188. ;
  189. ;    status = 0 if end of file
  190. ;           = -1 if error  (ERRNO get DOS error number)
  191. ;           = else number of bytes actually read
  192. ;
  193.  
  194.     public    READ
  195. READ    proc    near
  196.     push    bp
  197.     mov    bp,sp
  198.     mov    bx,[bp+4]    ;get file handle
  199.     mov    dx,[bp+6]    ;get buffer address
  200.     mov    cx,[bp+8]    ;get byte count
  201.     mov    ah,3FH        ;DOS read function
  202.     int    21H
  203.     jnc    red10
  204.     mov    dgroup:errno,ax
  205.     mov    ax,-1
  206. red10:    mov    sp,bp
  207.     pop    bp
  208.     ret
  209. READ    endp
  210.  
  211.     subttl    WRITE -- write data to file
  212.     page
  213. ;
  214. ; NAME
  215. ;
  216. ;    write -- write data to file
  217. ;
  218. ; SYNOPSIS
  219. ;
  220. ;    status = write(file, buffer, length);
  221. ;    int status;    status code or actual length
  222. ;    int file;    file number for file
  223. ;    char *buffer;    output buffer
  224. ;    int length;    number of bytes in buffer
  225. ;
  226. ; DESCRIPTION
  227. ;
  228. ;    Writes next set of bytes to a file.  The return count is
  229. ;    equal to the number of bytes written, unless an error
  230. ;    occurred.  The file position is advanced accordingly.
  231. ;
  232. ; RETURNS
  233. ;
  234. ;    status = -1 if error  (ERRNO get DOS error number)
  235. ;           = else number of bytes actually written
  236. ;
  237.  
  238.     public    WRITE
  239. WRITE    proc    near
  240.     push    bp
  241.     mov    bp,sp
  242.     mov    bx,[bp+4]    ;get file handle
  243.     mov    dx,[bp+6]    ;get buffer address
  244.     mov    cx,[bp+8]    ;get byte count
  245.     mov    ah,40H        ;DOS write function
  246.     int    21H
  247.     jnc    wrt10
  248.     mov    dgroup:errno,ax
  249.     mov    ax,-1
  250. wrt10:    mov    sp,bp
  251.     pop    bp
  252.     ret
  253. WRITE    endp
  254.  
  255.     subttl    LSEEK -- seek to specified file position
  256.     page
  257. ;
  258. ; NAME
  259. ;
  260. ;    lseek -- seek to specified file position
  261. ;
  262. ; SYNOPSIS
  263. ;
  264. ;    pos = lseek(file, offset, mode);
  265. ;    long pos;    returned file position or error code
  266. ;    int file;    file number for file
  267. ;    long offset;    desired position
  268. ;    int mode;    offset mode relative to:
  269. ;            0 = beginning of file        BOFM
  270. ;            1 = current file position   CURM
  271. ;            2 = end of file         EOFM
  272. ;
  273. ; DESCRIPTION
  274. ;
  275. ;    Changes the current file position to a new position in the
  276. ;    file.  The offset is specified as a long int and is added to
  277. ;    the current position (mode 1) or to the logical end of file
  278. ;    (mode 2).  Use DOS function 42h (LSEEK).
  279. ;
  280. ; RETURNS
  281. ;
  282. ;    pos = -1L if error occurred (ERRNO get DOS error number)
  283. ;    = new file position if successful
  284. ;
  285.  
  286.     public    LSEEK
  287. LSEEK    proc    near
  288.     push    bp
  289.     mov    bp,sp
  290.     mov    bx,[bp+4]    ;get file handle
  291.     mov    dx,[bp+6]    ;get low word of pos
  292.     mov    cx,[bp+8]    ;get high word of pos
  293.     mov    ax,[bp+10]    ;get seek mode
  294.     mov    ah,42H        ;DOS lseek function
  295.     int    21H
  296.     jnc    lsk10
  297.     mov    dgroup:errno,ax
  298.     mov    ax,-1
  299.     mov    dx,ax
  300. lsk10:    mov    bx,ax
  301.     mov    ax,dx
  302.     mov    sp,bp
  303.     pop    bp
  304.     ret
  305. LSEEK    endp
  306.  
  307. prog    ends
  308.     end
  309.