home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ZSYS
/
SIMTEL20
/
SYSLIB
/
SLIB2.LBR
/
SFAPPEND.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
3KB
|
149 lines
;
; SYSLIB Module Name: SFAPPE
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public f$appl,f$append
;
; SEE DOCUMENTATION WITH EACH ROUTINE FOR DETAILS
;
;
; Externals
;
ext initfcb
;
; BDOS Function calls et al
;
BDOS EQU 5 ; BDOS address
OPENF EQU 15 ; Open file function
WRITEF EQU 21 ; Write sequential
RREAD EQU 33 ; Random read function
GETFS EQU 35 ; Get file size function
;
; Macros
;
PUTRG MACRO
PUSH HL
PUSH DE
PUSH BC
ENDM
;
GETRG MACRO
POP BC
POP DE
POP HL
ENDM
;
; F$APPEND OPENS THE INDICATED FILE (WHOSE FCB IS PTED TO BY DE) FOR
; APPENDING, WITH THE NEXT RECORD TO BE APPENDED BEING AFTER THE LAST
; RECORD OF THE FILE. SUBSEQUENT F$WRITE CALLS WILL APPEND TO THE FILE
; AFTER THE LAST RECORD IN THE FILE.
;
; ON INPUT, DE = ADDRESS OF FCB (36 BYTES)
; ON OUTPUT, A = ERROR CODE AND Z IS SET ACCORDINGLY
; A = 0 AND Z IF NO ERROR
; A = 1 AND NZ IF FILE NOT FOUND
; A = 2 AND NZ IF FILE FULL
; A = 3 AND NZ IF FILE EMPTY
; IF SUCCESS, THE TBUFF AREA CONTAINS THE LAST RECORD IN THE FILE
;
; USAGE EXAMPLE:
; ...
; LXI D,FCB
; CALL F$APPEND
; < FILL TBUFF >
; LXI D,FCB
; CALL F$WRITE ; RECORD IS APPENDED AFTER LAST RECORD IN FILE
; ...
;
F$APPEND:
PUTRG
CALL F$APPL ; DO APPEND
JP NZ,DONE
LD C,WRITEF ; WRITE RECORD
CALL BDOS
XOR A ; NO ERROR
JP DONE
;
; F$APPL OPENS THE INDICATED FILE (WHOSE FCB IS PTED TO BY DE) FOR
; APPENDING. SUBSEQUENT F$WRITE CALLS WILL APPEND TO THE FILE STARTING
; AT THE LAST RECORD IN THE FILE.
;
; ON INPUT, DE = ADDRESS OF FCB (36 BYTES)
; ON OUTPUT, A = ERROR CODE AND Z IS SET ACCORDINGLY
; A = 0 AND Z IF NO ERROR
; A = 1 AND NZ IF FILE NOT FOUND
; A = 2 AND NZ IF FILE FULL
; A = 3 AND NZ IF FILE EMPTY
; IF SUCCESS, THE TBUFF AREA CONTAINS THE LAST RECORD IN THE FILE
;
; USAGE EXAMPLE:
; ...
; LXI D,FCB
; CALL F$APPL
; < FILL TBUFF >
; LXI D,FCB
; CALL F$WRITE ; LAST RECORD OF ORIGINAL FILE IS REWRITTEN
; ...
;
F$APPL:
PUTRG
CALL INITFCB ;INIT THE FCB
LD C,OPENF ;OPEN FILE PTED TO BY DE
CALL BDOSE
CP 0FFH ;ERROR?
JP Z,NOFILE
LD C,GETFS ;GET FILE SIZE
CALL BDOSE
LD HL,35 ;CHECK FOR FULL FILE
ADD HL,DE
LD A,(HL) ;GET VALUE
OR A ;MUST BE ZERO
JP NZ,FULLFILE
DEC HL ;GET RECORD NUMBER OF LAST RECORD
LD B,(HL)
DEC HL
LD C,(HL) ;BC = RECORD NUMBER
LD A,B ;CHECK FOR ZERO
OR C
JP Z,EMFILE ;DONE IF NO RECORDS
DEC BC ;DECREMENT TO LAST RECORD
LD (HL),C ;STORE RECORD NUMBER - 1
INC HL
LD (HL),B
LD C,RREAD ;READ LAST RECORD AT RANDOM
CALL BDOSE
XOR A ;NO ERROR
DONE:
GETRG
RET
NOFILE:
LD A,1 ;ERROR CODE FOR NO FILE
JP FILE
FULLFILE:
LD A,2 ;ERROR CODE FOR FULL FILE
JP FILE
EMFILE:
LD A,3 ;ERROR CODE FOR EMPTY FILE
FILE:
GETRG
OR A ;SET NZ
RET
;
; CALL BDOS AND SAVE DE
;
BDOSE:
PUSH DE
CALL BDOS
POP DE
RET
END