home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / zslsrc36.lbr / Z2FILE.ZZ0 / Z2FILE.Z80
Encoding:
Text File  |  1992-02-04  |  5.1 KB  |  187 lines

  1. ; Library:    ZSLIB
  2. ; Version:    3.5
  3. ; Module:    Z2FILE
  4. ; Version:    1.1
  5. ; Author:    Gene Pizzetta
  6. ; Date:        February 4, 1992
  7. ; Changes:    Changed names of public and external labels.
  8. ;
  9. ; Version:    1.0 (beta release)
  10. ; Author:    Gene Pizzetta
  11. ; Date:        December 8, 1991
  12. ; Changes:    Based on the SYSLIB 3.6 S2FILE module by Richard Conn, as
  13. ;        modified by Al Dunsmuir.  Now supports inter-directory
  14. ;        I/O.
  15. ;
  16. ; FR2OPEN, F2GET, FR2CLOSE, FW2OPEN, F2PUT, FW2CLOSE -- Byte-oriented
  17. ; file read and write routines.
  18. ;
  19. ; FR2OPEN -- Open file for byte-oriented reading.
  20. ;
  21. ; Entry: DE = address of file control block
  22. ; Exit:  A = 0, zero flag set (Z) if okay,
  23. ;     A = error code, zero flag reset (NZ) if error.
  24. ; Uses:  AF
  25. ; Notes: Must be logged into correct directory before calling.  Only the
  26. ; first 12 bytes of the file control block are used and the drive byte
  27. ; is ignored.
  28. ;
  29. ; FW2OPEN -- Open file for byte-oriented writing.
  30. ;
  31. ; Entry: DE = address of file control block.
  32. ; Exit:  A = 0, zero flag set (Z) if okay,
  33. ;     A = error code, zero flag reset (NZ) if error.
  34. ; Uses:     AF
  35. ; Notes: Must be logged into correct directory before calling.  Only the
  36. ; first 12 bytes of the file control block are used and the drive byte
  37. ; is ignored.
  38. ;
  39. ; FR2CLOSE -- Close file after byte-oriented reading.
  40. ;
  41. ; Entry: None.
  42. ; Exit:     A = 0, zero flag set (Z) if okay,
  43. ;     A = error code, zero flag reset (NZ) if error.
  44. ; Uses:     AF
  45. ; Notes: Read files should always be closed.  Closing the file properly
  46. ; prepares the data blocks for using this routine to open another file,
  47. ; which will fail otherwise.  In addition, it is required if the program
  48. ; will be re-executed with the ZCPR3 GO command.
  49. ;
  50. ; FW2CLOSE -- Close file after byte-oriented writing.
  51. ;
  52. ; Entry: None.
  53. ; Exit:     A = 0, zero flag set (Z) if okay,
  54. ;     A = error code, zero flag reset (NZ) if error.
  55. ; Uses:     AF
  56. ; Notes: Write files must always be closed, otherwise the buffers will
  57. ; not be flushed to disk.
  58. ;
  59. ; F2GET -- Get next byte from read file.
  60. ;
  61. ; Entry: None.
  62. ; Exit:     A = byte, zero flag set (Z) if okay,
  63. ;     A = error code, zero flag reset (NZ) if error.
  64. ; Uses:     AF
  65. ; Notes: Returns error code 4 on end of file.
  66. ;
  67. ; F2PUT -- Put a byte into write file.
  68. ;
  69. ; Entry: A = byte to put.
  70. ; Exit:     A = byte that was put, zero flag set (Z) if okay,
  71. ;     A = error code, zero flag reset (NZ) if error.
  72. ; Uses:     AF
  73. ; Notes: Except on error, A returns the byte that was put into the write
  74. ; file.
  75. ;
  76. ; General Notes:  Program must log into correct directory when calling
  77. ; corresponding open routine.  After opening file, no further attention
  78. ; need be paid to the drive/user.  Only the first 12 bytes of the user's
  79. ; file control block are significant (filename and filetype--the drive
  80. ; byte is ignored) by the open routines, so an abbreviated FCB may be
  81. ; used and re-used to open multiple files.
  82. ;
  83. ; The returned error codes are:
  84. ;    1    GET or PUT attempted on an unopened file.
  85. ;    2    Write file disk full (PUT).
  86. ;    3    Read file not found (OPEN).
  87. ;    4    End of read file (GET) or empty read file (OPEN).
  88. ;    5    Write file directory full (OPEN).
  89. ;    6    Error closing file (CLOSE).
  90. ;    7    File is already open (OPEN).
  91. ;
  92.     PUBLIC    FR2OPEN,F2GET,FR2CLOSE,FW2OPEN,F2PUT,FW2CLOSE
  93. ;
  94.     EXTRN    FR@OPEN,FW@OPEN,FR@CLOSE,FW@CLOSE,F@GET,F@PUT    ; ZSLIB
  95. ;
  96. FR2OPEN:
  97.     push    hl        ; save HL
  98.     call    ckrflg        ; check open flag
  99.     call    FR@OPEN
  100.     pop    hl
  101.     ret    nz        ; (error)
  102.     dec    a        ; set open flag
  103.     ld    (R2Flg),a
  104.     inc    a
  105.     ret
  106. ;
  107. FW2OPEN:
  108.     push    hl        ; save HL
  109.     call    ckwflg        ; check open flag
  110.     call    FW@OPEN
  111.     pop    hl
  112.     ret    nz        ; (error)
  113.     dec    a        ; set open flag
  114.     ld    (W2Flg),a
  115.     inc    a
  116.     ret
  117. ;
  118. F2GET:    push    hl        ; save HL
  119.     call    ckrflg        ; check open flag
  120.     jr    z,gperr1    ; (file not open)
  121.     jp    F@GET        ; jump and return to caller
  122. ;
  123. F2PUT:    push    hl        ; save HL
  124.     push    af
  125.     call    ckwflg        ; check open flag
  126.     jr    z,gperr        ; (file not open)
  127.     pop    af
  128.     jp    F@PUT        ; jump and return to caller
  129. ;
  130. gperr:    pop    hl        ; adjust stack
  131. gperr1:    pop    hl        ; restore HL
  132.     inc    a        ; error code (file not open)
  133.     ret
  134. ;
  135. FR2CLOSE:
  136.     push    hl        ; save HL
  137.     call    ckrflg        ; check open flag
  138.     call    nz,FR@CLOSE    ; if open, close it
  139.     pop    hl
  140.     ret    nz        ; (error)
  141.     ld    (R2Flg),a    ; reset open flag
  142.     ret
  143. ;
  144. FW2CLOSE:
  145.     push    hl        ; save HL
  146.     call    ckwflg        ; check open flag
  147.     call    nz,FW@CLOSE    ; if open, close it
  148.     pop    hl
  149.     ret    nz        ; (error)
  150.     ld    (W2Flg),a    ; reset open flag
  151.     ret
  152. ;
  153. ckrflg:    ld    hl,R2Tbl    ; point to read table
  154.     ld    a,(R2Flg)    ; check flag
  155.     or    a
  156.     ret
  157. ;
  158. ckwflg:    ld    hl,W2Tbl    ; point to write table
  159.     ld    a,(W2Flg)    ; check flag
  160.     or    a
  161.     ret
  162. ;
  163. ; Initialized flags
  164. ;
  165. R2Flg:    db    0        ; read file opened flag (0=no)
  166. W2Flg:    db    0        ; write file opened flag (0=no)
  167. ;
  168. ; Uninitialized tables and buffers (initialized by file open routines)
  169. ;
  170.     DSEG
  171. ;
  172. R2Tbl:
  173. R2du:    ds    2        ; read file drive and user
  174. R2cnt:    ds    1        ; read file character count
  175. R2ptr:    ds    2        ; read file character pointer
  176. R2fcb:    ds    36        ; read file fcb
  177. R2buf:    ds    128        ; read file buffer
  178. ;
  179. W2Tbl:
  180. W2du:    ds    2        ; write file drive and user
  181. W2cnt:    ds    1        ; write file character count
  182. W2ptr:    ds    2        ; write file character pointer
  183. W2fcb:    ds    36        ; write file fcb
  184. W2buf:    ds    128        ; write file buffer
  185. ;
  186.     end
  187.