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
/
MBUG
/
MBUG041.ARC
/
TEXT.MAC
< prev
next >
Wrap
Text File
|
1979-12-31
|
8KB
|
325 lines
;====================================================================
;
; TEXT :- Type all files matching afn1.
;
; PROGRAM
;
;
;====================================================================
;
; Declare macros :-
;
;
INCLUDE MACRO.LIB
;--------------------------------------------------------------------
;
; TXT :- Type all files matching a given FCB.
;
; MACRO
;
; Parameters
; FCBADDR :- Address at which the FCB for which all matching
; files are to be typed is located (only the first 00Ch bytes
; are relevant), default is CCPFCB
; START :- Address from which TXT may use as a buffer, default
; is contents of DE
; LIMIT :- First address after the end of the buffer, default is
; contents of HL
; BUFFER :- Address of start of file buffer, default is CPMBUFF
;
; Returns
; BC :- Number of matching files found
; DE :- START
; HL :- LIMIT
;
; Destroys
; file buffer
; TYPE data region (BUFF2, TYPEFCB)
; DSEARCH data region (BUFF, OFFSET, LENGTH, SCHFCB)
; FSEARCH data region (DSKNO, DEFAULT)
;
; TXT requires the inclusion of the subroutines TYPE, FNAME,
; FSEARCH and DSEARCH.
;
; If insufficient space is available to store all matching entries
; the error is reported and ERREXIT executed.
;
; If the buffer available for displaying the file is to small the
; error is reported and ERREXIT is executed (RECSIZE is the
; minimum space required).
;
; If BDOS reports an error in displaying the file ERREXIT is
; executed after the error is reported.
;
; Bit 7 is masked out.
;
; Control characters other than CR, HT, LF are shown as Eg. ^G.
;
; While the file is being displayed the following keys may be
; used :-
; ctrl-S Pause display (any key to restart)
; ctrl-C Exit program immediately
; ESC Abort display of current file
;
;
TXT MACRO FCBADDR, START, LIMIT, BUFFER
IFNB <BUFFER>
LD BC, BUFFER
ELSE
LD BC, CPMBUFF
ENDIF
LD (BUFF2), BC
IFNB <START>
LD DE, START
ENDIF
PUSH DE
LD (FILE), DE
FILES FCBADDR,, LIMIT, BUFFER
JR NZ, FILESNG ; not enough room to hold files
PUSH HL
PUSH BC
TYPENXT:LD A, B
OR C
JR Z, TXTEXIT
PUSH BC
WRITE 'Displaying file '
LD BC, (FILE) ; set FCB address
CALL TFNAME
WRITELN
CALL TYPE
WRITELN
PUSH HL
LD HL, 00010h
ADD HL, BC
LD (FILE), HL ; update address of filename
POP HL
POP BC
DEC BC ; update number of files remaining
JR TYPENXT
FILESNG:WRITELN 'Too many files found for available memory space.'
JP ERREXIT
TXTEXIT:POP BC
POP HL
POP DE
DSEG
FILE: DS WORD ; address of current filename in buffer
CSEG
ENDM
;====================================================================
;
; Program :-
;
;
ENTRY
LD A, (CPMBUFF)
OR A
JR NZ, DISP ; parameter given
WRITELN 'TEXT :- Type all matching files to the console.'
WRITELN ' ctrl-C Abort program'
WRITELN ' ctrl-S Suspend display'
WRITELN ' ESC Abort display of this file'
RET
DISP: TXT
LD A, B
OR C
RET NZ ; at least one file was found
WRITELN 'No matching files found.'
RET
;====================================================================
;
; Subroutines :-
;
;
; TYPE :- Type a text file to the console.
;
; SUBROUTINE
;
; Parameters
; BC :- Address of the FCB of the file to be typed (only the
; first 00Ch bytes are relevant)
; DE :- Address from which TYPE may use as a buffer
; HL :- First address after the end of the buffer
; BUFF2 :- Address at which address of file buffer is to be
; placed prior to calling
;
; Returns
; Z flag :- Reset if physical end of file reached.
;
; Conserves
; BC
; DE
; HL
;
; Destroys
; file buffer
;
; If the buffer available for displaying the file is to small the
; error is reported and ERREXIT is executed (RECSIZE is the
; minimum space required).
;
; If BDOS reports an error ERREXIT is executed after the error is
; reported.
;
; Bit 7 is masked out.
;
; Control characters other than CR, HT, LF are shown as Eg. ^G.
;
; While the file is being displayed the following keys may be
; used :-
; ctrl-S Pause display (any key to restart)
; ctrl-C Exit program immediately
; ESC Abort display of this file
;
;
TYPE: PUSH BC
PUSH HL
PUSH DE
OR A
SBC HL, DE
JR C, BUFFNG ; buffer of negative size
LD A, L
AND 100h - RECSIZE ; RECSIZE a multiple of 2, hence
LD L, A ; remainder removed from size of
OR H ; buffer
JR Z, BUFFNG ; usable buffer of length zero
ADD HL, DE ; HL contains first byte past end of
PUSH HL ; usable buffer
LD H, B
LD L, C
LD DE, TYPEFCB
LD BC, 00Ch
LDIR
XOR A
LD (TYPEFCB + ex), A
LD (TYPEFCB + s2), A
SERVICE OPEN, TYPEFCB ; Attempt to open file
INC A
JR Z, OPENERR
XOR A
LD (TYPEFCB + cr), A ; set cr to 000h
POP HL
POP DE
PUSH DE
NXTBUFF:CALL FILL
PUSH AF
CALL DISPLAY
JR NZ, LOGICAL
POP AF
JR Z, NXTBUFF
JR PHYSCAL
LOGICAL:POP AF
OR A ; set Z flag
PHYSCAL:LD DE, (BUFF2)
PUSH AF
SERVICE SETBUFF
POP AF ; conserve Z flag
POP DE
POP HL
POP BC
RET
BUFFNG: WRITELN 'Insufficient space available to display file.'
JR QUIT
OPENERR:WRITELN 'BDOS could not open file.'
QUIT: JP ERREXIT
FILL: ; fill buffer, DE contains start
; of buffer address, HL contains
; end of usable buffer address + 1
; (DE conserved, HL returned as top
; of file in buffer + 1 (HL
; conserved except on last fill)).
; Reset Z flag if BDOS unable to
; continue filling buffer
; (generally EOF).
PUSH DE
LD BC, RECSIZE
NXTREC: SERVICE SETBUFF
SERVICE READ, TYPEFCB ; read record in buffer area
OR A
JR NZ, ENDFILE
EX DE, HL
ADD HL, BC ; set address for next read
EX DE, HL
PUSH HL
SBC HL, DE
POP HL
JR NZ, NXTREC ; buffer not full yet
ENDFILE:EX DE, HL ; HL points to top of file in buffer
POP DE
RET
DISPLAY: ; display buffer, DE contains start
; of buffer address, HL contains
; end of buffer address + 1 (DE, HL
; conserved). Reset Z flag if file
; ended logically or was aborted.
; While the file is being displayed
; the following keys may be used :-
; ctrl-S Pause listing
; ctrl-C Terminate program
; ESC Terminate this file
; A = 0FFh if ESC else 000h
PUSH DE
NXTBYTE:PUSH HL
SERVICE DIRCON, 0FFh
CP 'S' - 040h
JR NZ, NOPAUSE
PAUSE: SERVICE DIRCON, 0FFh ; ^S pressed, pause until keypressed
OR A
JR Z, PAUSE
NOPAUSE:CP 'C' - 040h
JP Z, EXIT ; ^C pressed, terminate program
CP ESC
JR Z, QT ; ESC pressed, abort typing file
OR A
SBC HL, DE
POP HL
JR Z, ENDDSP
LD A, (DE)
CP EOF
JR Z, LOGEND
AND 07Fh ; reset bit 7
CP ' '
JR NC, PRNTBLE ; if not a control character
CP RET
JR Z, PRNTBLE ; if a carriage return
CP LF
JR Z, PRNTBLE ; if a line feed
CP HT
JR Z, PRNTBLE ; if a horizontal tab
ADD A, '@' - NUL ; convert to a printable character
PUSH AF
SERVICE CONOB, '^'
POP AF
PRNTBLE:PUSH DE
LD E, A
SERVICE CONOB
POP DE
INC DE
JR NXTBYTE
LOGEND: INC A ; reset Z flag (A contained EOF =
ENDDSP: POP DE ; 01Ah)
LD A, 000h ; file has been typed fully
RET
QT: POP HL
POP DE
LD A, 0FFh ; file was aborted early
OR A ; reset Z flag
RET
DSEG
BUFF2: DS WORD ; address at which I/O buffer resides
TYPEFCB:DS FCBSIZE ; FCB of file to be typed
CSEG
;--------------------------------------------------------------------
TFNAME ; macro declared subroutines
FSEARCH
DSEARCH
;====================================================================
ENDPROG:
END