home *** CD-ROM | disk | FTP | other *** search
- ; Library: ZSLIB
- ; Version: 3.5
- ; Module: Z2FILE
- ; Version: 1.1
- ; Author: Gene Pizzetta
- ; Date: February 4, 1992
- ; Changes: Changed names of public and external labels.
- ;
- ; Version: 1.0 (beta release)
- ; Author: Gene Pizzetta
- ; Date: December 8, 1991
- ; Changes: Based on the SYSLIB 3.6 S2FILE module by Richard Conn, as
- ; modified by Al Dunsmuir. Now supports inter-directory
- ; I/O.
- ;
- ; FR2OPEN, F2GET, FR2CLOSE, FW2OPEN, F2PUT, FW2CLOSE -- Byte-oriented
- ; file read and write routines.
- ;
- ; FR2OPEN -- Open file for byte-oriented reading.
- ;
- ; Entry: DE = address of file control block
- ; Exit: A = 0, zero flag set (Z) if okay,
- ; A = error code, zero flag reset (NZ) if error.
- ; Uses: AF
- ; Notes: Must be logged into correct directory before calling. Only the
- ; first 12 bytes of the file control block are used and the drive byte
- ; is ignored.
- ;
- ; FW2OPEN -- Open file for byte-oriented writing.
- ;
- ; Entry: DE = address of file control block.
- ; Exit: A = 0, zero flag set (Z) if okay,
- ; A = error code, zero flag reset (NZ) if error.
- ; Uses: AF
- ; Notes: Must be logged into correct directory before calling. Only the
- ; first 12 bytes of the file control block are used and the drive byte
- ; is ignored.
- ;
- ; FR2CLOSE -- Close file after byte-oriented reading.
- ;
- ; Entry: None.
- ; Exit: A = 0, zero flag set (Z) if okay,
- ; A = error code, zero flag reset (NZ) if error.
- ; Uses: AF
- ; Notes: Read files should always be closed. Closing the file properly
- ; prepares the data blocks for using this routine to open another file,
- ; which will fail otherwise. In addition, it is required if the program
- ; will be re-executed with the ZCPR3 GO command.
- ;
- ; FW2CLOSE -- Close file after byte-oriented writing.
- ;
- ; Entry: None.
- ; Exit: A = 0, zero flag set (Z) if okay,
- ; A = error code, zero flag reset (NZ) if error.
- ; Uses: AF
- ; Notes: Write files must always be closed, otherwise the buffers will
- ; not be flushed to disk.
- ;
- ; F2GET -- Get next byte from read file.
- ;
- ; Entry: None.
- ; Exit: A = byte, zero flag set (Z) if okay,
- ; A = error code, zero flag reset (NZ) if error.
- ; Uses: AF
- ; Notes: Returns error code 4 on end of file.
- ;
- ; F2PUT -- Put a byte into write file.
- ;
- ; Entry: A = byte to put.
- ; Exit: A = byte that was put, zero flag set (Z) if okay,
- ; A = error code, zero flag reset (NZ) if error.
- ; Uses: AF
- ; Notes: Except on error, A returns the byte that was put into the write
- ; file.
- ;
- ; General Notes: Program must log into correct directory when calling
- ; corresponding open routine. After opening file, no further attention
- ; need be paid to the drive/user. Only the first 12 bytes of the user's
- ; file control block are significant (filename and filetype--the drive
- ; byte is ignored) by the open routines, so an abbreviated FCB may be
- ; used and re-used to open multiple files.
- ;
- ; The returned error codes are:
- ; 1 GET or PUT attempted on an unopened file.
- ; 2 Write file disk full (PUT).
- ; 3 Read file not found (OPEN).
- ; 4 End of read file (GET) or empty read file (OPEN).
- ; 5 Write file directory full (OPEN).
- ; 6 Error closing file (CLOSE).
- ; 7 File is already open (OPEN).
- ;
- PUBLIC FR2OPEN,F2GET,FR2CLOSE,FW2OPEN,F2PUT,FW2CLOSE
- ;
- EXTRN FR@OPEN,FW@OPEN,FR@CLOSE,FW@CLOSE,F@GET,F@PUT ; ZSLIB
- ;
- FR2OPEN:
- push hl ; save HL
- call ckrflg ; check open flag
- call FR@OPEN
- pop hl
- ret nz ; (error)
- dec a ; set open flag
- ld (R2Flg),a
- inc a
- ret
- ;
- FW2OPEN:
- push hl ; save HL
- call ckwflg ; check open flag
- call FW@OPEN
- pop hl
- ret nz ; (error)
- dec a ; set open flag
- ld (W2Flg),a
- inc a
- ret
- ;
- F2GET: push hl ; save HL
- call ckrflg ; check open flag
- jr z,gperr1 ; (file not open)
- jp F@GET ; jump and return to caller
- ;
- F2PUT: push hl ; save HL
- push af
- call ckwflg ; check open flag
- jr z,gperr ; (file not open)
- pop af
- jp F@PUT ; jump and return to caller
- ;
- gperr: pop hl ; adjust stack
- gperr1: pop hl ; restore HL
- inc a ; error code (file not open)
- ret
- ;
- FR2CLOSE:
- push hl ; save HL
- call ckrflg ; check open flag
- call nz,FR@CLOSE ; if open, close it
- pop hl
- ret nz ; (error)
- ld (R2Flg),a ; reset open flag
- ret
- ;
- FW2CLOSE:
- push hl ; save HL
- call ckwflg ; check open flag
- call nz,FW@CLOSE ; if open, close it
- pop hl
- ret nz ; (error)
- ld (W2Flg),a ; reset open flag
- ret
- ;
- ckrflg: ld hl,R2Tbl ; point to read table
- ld a,(R2Flg) ; check flag
- or a
- ret
- ;
- ckwflg: ld hl,W2Tbl ; point to write table
- ld a,(W2Flg) ; check flag
- or a
- ret
- ;
- ; Initialized flags
- ;
- R2Flg: db 0 ; read file opened flag (0=no)
- W2Flg: db 0 ; write file opened flag (0=no)
- ;
- ; Uninitialized tables and buffers (initialized by file open routines)
- ;
- DSEG
- ;
- R2Tbl:
- R2du: ds 2 ; read file drive and user
- R2cnt: ds 1 ; read file character count
- R2ptr: ds 2 ; read file character pointer
- R2fcb: ds 36 ; read file fcb
- R2buf: ds 128 ; read file buffer
- ;
- W2Tbl:
- W2du: ds 2 ; write file drive and user
- W2cnt: ds 1 ; write file character count
- W2ptr: ds 2 ; write file character pointer
- W2fcb: ds 36 ; write file fcb
- W2buf: ds 128 ; write file buffer
- ;
- end