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
/
CPM
/
ZCPR33
/
A-R
/
PAGE21.LBR
/
PAGE21.ZZ0
/
PAGE21.Z80
Wrap
Text File
|
2000-06-30
|
26KB
|
1,221 lines
;
; PROGRAM: PAGE
; VERSION: 2.0
; DATE: 18 May 84
; AUTHOR: RICHARD CONN
; PREVIOUS VERSIONS: 1.2 (26 Apr 83), 1.1 (25 Apr 83), 1.0 (22 Apr 83)
;
vers equ 21
z3env defl 0fe00h
; Version 2.1 modifications by Bruce Morgen, September 9, 1988
;
; v2.1 is basically a maintenance update to catch up with Z33/Z34
; and get PAGE down to a sensible 4K via Z80 opcodes, implementation of
; a DSEG and linkage with the beta v4 Z3LIB and SYSLIB. Z33LIB is also
; required for re-building the program. The only visible functional
; changes are a correction and "intelligence" added to the help screen.
; Translated code to Zilog mnemonics - the Z80 is almost 10 years old,
; after all. This is one of Rick's nicer tools, worth a second look.
; More subtle changes include wheel-controlled access to SYS files and
; an inter-character delay variable based on the CPU speed byte in ENV.
;
; PAGE is THE file screen print utility for ZCPR3. Installable by
; Z3INS, PAGE provides a wide range of options for the user. First, PAGE
; allows the user to employ wild cards and file name lists (lists of files
; separated by commas, like: file1,file2,file3,...). Second, PAGE provides
; the following options:
; 0-9 Set Character Print Speed Delay
; I Inspect Files
; The user approves each file to be printed
; before the printing process begins
; L Toggle Line Numbering
; Each line may or may not begin with a line
; number
; P Toggle Screen Paging
; Snnnn Skip to Specified Page
; Printing begins on the indicated page
;
; During paged output, various parameters can be changed dynamically.
; In particular, the letter P toggles screen paging and the digits 0-9
; vary the speed WHILE the output is being presented. The effect is immediate.
; Control characters may be used to perform additional control functions:
; ^S pauses the output, ^X aborts paging of current file and advances to
; the next file, and ^C aborts to the operating system.
;
false equ 0
true equ not false
;
; BASIC SYSLIB ROUTINES NEEDED BY TEMPLATE
;
esize equ 16 ; SIZE OF DIR ENTRY (FROM SYSLIB DIRF ROUTINE)
extrn dirq ; DIRECTORY PROCESSOR
extrn z33chk,z33fname ; Z33LIB stuff, for parsing
extrn z3init ; INIT BUFFERS
extrn zfname ; FILE NAME PROCESSOR
extrn getcrt ; GET CRT PARAMETERS
extrn z3log ; LOG INTO DIR
extrn getefcb
extrn getwhl
extrn getspeed
extrn initfcb ; INIT FCB
extrn retud ; RETURN CURRENT USER/DISK
extrn putud ; SAVE CURRENT USER/DISK
extrn getud ; RESTORE CURRENT USER/DISK
extrn eprint ; PRINT STRING PTED TO BY RET ADR
extrn padc ; PRINT A IN DEC
extrn cout ; CONSOLE OUTPUT ROUTINE
extrn cst ; CONSOLE STATUS ROUTINE
extrn cin ; CONSOLE INPUT ROUTINE
extrn caps ; CAPITALIZE ROUTINE
extrn crlf ; NEW LINE ROUTINE
extrn codend ; CODE END COMPUTATION ROUTINE
extrn f$open ; FILE OPEN
extrn f$read ; BLOCK READ
extrn f$close ; FILE CLOSE
extrn eval10 ; STRING TO BINARY CONVERSION
extrn phldc ; PRINT HL IN DECIMAL ROUTINE
extrn moveb ; MOVEB ROUTINE
;
; CP/M EQUATES
;
cpm equ 0 ; WARM BOOT
bdose equ cpm+5 ; BDOS ENTRY
fcb equ cpm+5ch ; FCB
tbuff equ cpm+80h ; INPUT LINE BUFFER
del equ 7fh ; <DEL>
cr equ 13 ; <CR>
ff equ 12 ; <FF>
lf equ 10 ; <LF>
ctrlc equ 'C'-'@' ; ^C
ctrlg equ 'G'-'@'
ctrlh equ 'H'-'@'
ctrli equ 'I'-'@'
ctrls equ 'S'-'@'
ctrlx equ 'X'-'@'
ctrlz equ 'Z'-'@'
;
; OTHER EQUATES
;
eold equ 0ffh ; END OF LOAD DELIMITER
cseg
;
; Environment Definition
;
if z3env ne 0
;
; External ZCPR3 Environment Descriptor
;
jp start
db 'Z3ENV' ; This is a ZCPR3 Utility
db 1 ; External Environment Descriptor
z3eadr:
dw z3env
start:
ld hl,(z3eadr) ; Pt to ZCPR3 environment
;
else
;
; Internal ZCPR3 Environment Descriptor
;
maclib z3base.lib
maclib sysenv.lib
z3eadr:
jp start
sysenv
start:
ld hl,z3eadr ; Pt to ZCPR3 environment
endif
;
; Start of Program -- Initialize ZCPR3 Environment
;
call z3init ; Initialize the ZCPR3 Env and the VLIB Env
jr startx
;
; **** Special Initial Value Area
;
cspp:
db 1 ; LINES TO SKIP PER SCREEN
;
; NOTE: CTPP + CSPP + 1 (FOOTER SIZE) = TOTAL LINES PER SCREEN ON CONSOLE
;
dlnumfl:
db 0 ; LINE NUMBER FLAG (DEFAULT TO NO)
dpagefl:
db 0ffh ; PAGE NUMBER FLAG (DEFAULT TO YES)
dinspect:
db 0 ; INSPECT FILES (DEFAULT TO NO)
ddelay:
db 0 ; DELAY COUNT (DEFAULT TO 0)
;
; OTHER BUFFERS
;
skipfl:
db 0 ; SKIP FLAG (DEFAULT TO NO)
lnumfl:
db 0 ; LINE NUMBER FLAG (DEFAULT TO NO)
pagefl:
db 0ffh ; PAGE NUMBER FLAG (DEFAULT TO YES)
inspect:
db 0 ; INSPECT FILES (DEFAULT TO NO)
delay:
db 0 ; DELAY COUNT (DEFAULT TO 0)
;
; Start of Program
;
startx:
ld (stack),sp ; GET STACK PTR & SAVE IT
call codend ; DETERMINE FREE SPACE
ld (cmdlne),hl ; COMMAND LINE BUFFER
inc h ; BUFFER SIZE IS 100H
ld (dirbuf),hl ; ADDRESS OF DIRECTORY BUFFER (TOP OF LOCAL STACK)
ld sp,hl ; SET NEW STACK
call putud ; SAVE CURRENT USER/DISK AWAY
call getcrt ; GET CRT PARAMETERS
ld a,(hl)
ld (cwidth),a
inc hl
inc hl
ld a,(hl) ; GET NUMBER OF TEXT LINES
ld (ctpp),a
ld b,a ; IN B
dec hl
ld a,(hl) ; GET TOTAL NUMBER OF LINES
sub b ; COMPUTE NUMBER OF LINES TO SKIP/SCREEN
dec a ; 1 LINE FOR PROMPT
ld (cspp),a
ld hl,tbuff+1 ; SAVE COMMAND LINE
ld de,(cmdlne) ; GET PTR TO COMMAND LINE SAVE BUFFER
ld b,80h ; SIZE OF LINE
call moveb ; COPY COMMAND LINE
;
; **** Banner of Program
;
call eprint
db 'PAGE, Version '
db vers/10+'0','.',(vers mod 10)+'0',0
;
; Check for Help Request
;
ld a,(fcb+1) ; GET FIRST CHAR OF FILE NAME
cp ' ' ; NO FILE SPEC?
jr z,help
cp '/' ; OPTION CAUGHT?
jp nz,econt
;
; **** Print Help Information
;
help:
call eprint
db cr,lf,'Syntax:'
db cr,lf,' ',0
call comnam
call eprint
db ' file1,file2,...,filen o...'
db cr,lf,'Options:'
db cr,lf,' 0-9 Select Delay Constant'
db cr,lf,' I Inspect and Select Files First'
db cr,lf,' L Toggle Numbering of Each Line'
db cr,lf,' P Toggle Paging'
db cr,lf,' Snnnn Skip to Specified Page before Printing'
db cr,lf
db cr,lf,'Examples:'
db cr,lf,' ',0
call comnam
call eprint
db ' MYFILE.TXT,*.MAC LI'
db cr,lf,' -- Number Lines, Inspect Files'
db cr,lf,' ',0
call comnam
call eprint
db ' MYFILE.* S25'
db cr,lf,' -- Skip to Page 25'
db cr,lf
db cr,lf,'Commands during printout:'
db cr,lf,' ^C - abort program ^X - skip to next file'
db cr,lf,' ^S - suspend output P - toggle paging'
db cr,lf,' 0-9 - change scrolling speed'
db 0
;
; RETURN TO OS
;
return:
ld sp,(stack) ; GET OLD STACK
ret
;
; PROGRAM'S INIT ROUTINE
;
econt:
call init ; PROG INIT ROUTINE
;
; EXTRACT FLAGS IF PRESENT
;
ld hl,0 ; SET FILE COUNT
ld (filecnt),hl
ld hl,(cmdlne) ; PT TO BUFFER
;
; SKIP TO FILE NAME STRING
;
call sblank ; SKIP OVER BLANKS
;
; SKIP TO END OF FILE NAME STRING
;
call snblank ; SKIP OVER NON-BLANKS
;
; CHECK FOR LEADING SLASH ON OPTION AND SKIP IT IF SO
;
opt:
cp '/' ; OPTION CHAR?
jr nz,option
inc hl ; SKIP SLASH
;
; PROCESS LIST OF OPTIONS
;
option:
ld a,(hl) ; GET BYTE
or a ; DONE?
jp z,dspec
inc hl ; PT TO NEXT CHAR
cp ' ' ; SKIP OVER SPACES
jr z,option
ld c,a ; COMMAND IN C
ld de,optab ; PT TO OPTION TABLE
optl:
ld a,(de) ; GET OPTION LETTER
or a ; END OF TABLE?
jp z,help ; HELP IF SO
cp c ; MATCH?
jr z,optm ; PROCESS IF SO
inc de ; PT TO NEXT ENTRY
inc de
inc de
jr optl
;
; PROCESS OPTION
;
optm:
push hl ; SAVE HL ON STACK
ld hl,option ; GET RETURN ADDRESS
ex (sp),hl ; ON STACK AND RESTORE HL
inc de ; PT TO ADDRESS
ld a,(de) ; GET ADDRESS LOW
ld b,a ; IN B
inc de
ld a,(de) ; GET ADDRESS HIGH
ld d,a ; IN D
ld e,b ; LOW IN E
push de ; PUT ADDRESS ON STACK
ld a,c ; COMMAND IN A
ret ; "CALL" OPTION ROUTINE
;
; **** PROGRAM INIT ROUTINE
; THIS ROUTINE IS USED BY THE PROGRAM TO PERFORM ANY INITS
;
init:
ld hl,dlnumfl ; Copy defaults into buffers
ld de,lnumfl
ld b,4 ; 4 bytes
call moveb ; Do copy
xor a ; A=0
ld (skipfl),a ; Set no skip
ret
;
; **** OPTION TABLE
; EACH OPTION IS A CAPITAL LETTER OR SPECIAL CHAR FOLLOWED BY
; AN ADDRESS; THE TABLE IS TERMINATED BY A BINARY ZERO
;
optab:
db '0'
dw optnum
db '1'
dw optnum
db '2'
dw optnum
db '3'
dw optnum
db '4'
dw optnum
db '5'
dw optnum
db '6'
dw optnum
db '7'
dw optnum
db '8'
dw optnum
db '9'
dw optnum
db 'I'
dw optinsp
db 'L'
dw optln
db 'P'
dw optpage
db 'S'
dw optskip
db 0 ; END OF TABLE
;
; Set Delay Constant
;
optnum:
sub '0' ; Set constant
ld (delay),a
ret
;
; Toggle Inspect Option
;
optinsp:
ld a,(inspect) ; Flip flag
cpl
ld (inspect),a
ret
;
; Set Line Number Flag
;
optln:
ld a,(lnumfl) ; Flip flag
cpl
ld (lnumfl),a
ret
;
; Toggle Paging
;
optpage:
ld a,(pagefl) ; Flip flag
cpl
ld (pagefl),a
ret
;
; Set Skip Flag and get number
;
optskip:
ld a,0ffh ; Set flag
ld (skipfl),a
call eval10 ; Get number in DE (A = E)
ld (skipnum),de ; Set page number to skip to
or d ; See if page number was zero
jp nz,option
ld (skipfl),a ; If zero, just turn off skip flag
ret
;
; BEGIN MOVING THROUGH FILE NAMES, SEPARATED BY COMMAS
;
dspec:
ld hl,(cmdlne) ; PT TO FIRST BYTE
call sblank ; SKIP TO NON-BLANK
;
; MAJOR REENTRY POINT WHEN FILE SPECS ARE SEPARATED BY COMMAS
; HL PTS TO FIRST BYTE OF NEXT FILE SPEC
;
dspec1:
ld sp,(dirbuf) ; RESET STACK
call getud ; RESET USER IF NECESSARY
call z33chk
ld de,fcb ; PT TO FCB IN DE, PT TO FIRST CHAR OF FILE NAME IN HL
jr z,gotz33
xor a ; DIR BEFORE DU
call zfname ; EXTRACT FILE NAME INTO FCB, AND GET DISK AND USER
jr parsed
gotz33: call z33fname
parsed: ld (nextch),hl ; SAVE PTR TO DELIMITER WHICH ENDED SCAN
ld de,fcb ; PT TO FCB
call z3log ; LOG INTO DU FOR FILE
;
; LOAD DIRECTORY AND PERFORM FUNCTION
;
fct:
ld de,fcb ; PT TO FCB
call initfcb ; INIT THE FCB
call getwhl
ld hl,(dirbuf) ; PT TO DIR BUFFER
ld a,11000000b ; SELECT SYS AND NON-SYS FILES
jr nz,dodirq ; GO DO IT IF WHEEL BYTE SET
ld a,10000000b ; SELECT NON-SYS FILES ONLY
dodirq: call dirq ; LOAD DIR, SELECT FILES, PACK, AND ALPHABETIZE
;
; DETERMINE BEGINNING OF SCRATCH AREA (SCRATCH) AND SIZE IN PAGES (BCNT)
;
push hl ; SAVE PTR AND COUNT
push bc
ld de,esize ; SET PTR TO NEXT FREE BLOCK
fctfre:
ld a,b ; DONE?
or c
jr z,fctfr1
add hl,de ; PT TO NEXT
dec bc ; COUNT DOWN
jr fctfre
fctfr1:
inc h ; NEXT PAGE
ld l,0
ld (scratch),hl ; SET PTR TO SCRATCH AREA
ex de,hl ; PTR IN DE
ld hl,(bdose+1) ; COMPUTE BLOCK BUFFER SIZE
ld a,h ; ADJUST FOR ZCPR3
sub 10
sub d ; A=SIZE IN BLOCKS
ld (bcnt),a ; SET BLOCK COUNT
pop bc ; RESTORE AND SAVE REGS
pop hl
;
; ALLOW USER TO INSPECT FILES
;
push hl
push bc
call icheck ; CHECK FOR INSPECT OPTION AND INSPECT IF SET
pop bc ; RESTORE COUNT AND PTR
pop hl
;
; PERFORM FUNCTION; HL PTS TO FILE AND BC CONTAINS NUMBER OF FILES
;
fctl:
ld a,b ; CHECK FOR COMPLETION (COUNT = 0)
or c
jr z,fctl1
dec bc ; COUNT DOWN
ld sp,(dirbuf) ; SET STACK
push bc ; SAVE COUNT AND PTR
push hl
call function ; PERFORM FUNCTION
fctlnxt:
ld sp,(dirbuf) ; RESTORE STACK
dec sp
dec sp
dec sp
dec sp ; SET STACK
pop hl ; RESTORE PTR
pop bc ; RESTORE COUNT
ld de,esize ; PT TO NEXT ENTRY
add hl,de
jr fctl
;
; CHECK FOR NEXT FILE SPEC
;
fctl1:
call getud ; RETURN TO BASE USER/DISK
ld hl,(nextch) ; GET PTR
ld a,(hl) ; GET DELIM
cp ',' ; ANOTHER FILE?
jr nz,dreturn
inc hl ; PT TO CHAR AFTER COMMA
jp dspec1 ; CONTINUE PROCESSING
;
; **** EMERGENCY ABORT
;
abort:
call eprint
db cr,lf,'** ',0
call comnam
call eprint
db ' Abort **',cr,lf,0
call getud ; RETURN HOME AND FALL THRU TO DRETURN
;
; **** FUNCTION COMPLETE -- CLEANUP AND EXIT
; FILL THIS IN WITH CLEANUP CODE FOR EXIT
;
dreturn:
jp return
;
; **** INSPECT FILES -- THIS ROUTINE IS TO PERFORM A FILE INSPECTION
; ON INPUT, HL PTS TO FIRST 16-BYTE ENTRY AND BC=NUMBER OF ENTRIES
;
icheck:
ld a,b ; Any files?
or c
ret z
push hl ; Save ptrs
push bc
ld de,esize ; Size of entry
ichk1:
ld (hl),0 ; Clear MSBytes
add hl,de ; Pt to next
dec bc ; Count down
ld a,b ; Done?
or c
jr nz,ichk1
pop bc ; Restore ptrs
pop hl
ld a,(inspect) ; Inspect?
or a ; 0=no
ret z
call eprint
db cr,lf,'PAGE File Inspect Mode'
db cr,lf,' Y (def) = Select File N = Don''t Select File'
db cr,lf,' Q = Select Rest of Files S = Skip Rest of Files'
db cr,lf,0
ichk2:
call eprint
db cr,lf,'Select ',0
call prfn ; Print file name
call eprint
db ' -- (Y/N/Q/S)? ',0
call cin ; Get response
call caps ; Capitalize
call cout ; Echo
cp 'Q' ; Select rest?
jr z,ichkyr
cp 'S' ; Skip rest
jr z,ichknr
cp 'N' ; No to this one?
jr nz,ichk3
ld (hl),0ffh ; Set NO flag in file FCB
ichk3:
add hl,de ; Pt to next one
dec bc ; Count down
ld a,b ; Done?
or c
jr nz,ichk2
ret
; Check Rest of Files as Selected
ichkyr:
call eprint
db cr,lf,' Rest of Files Selected',0
ret
; Check Rest of Files as NOT Selected
ichknr:
ld (hl),0ffh ; Set NO flag
add hl,de ; Pt to next
dec bc ; Count down
ld a,b ; Done?
or c
jr nz,ichknr
call eprint
db cr,lf,' Rest of Files NOT Selected',0
ret
;
; **** FUNCTION -- MAIN FUNCTION OF TEMPLATE
; ON ENTRY, HL PTS TO NAME OF FILE (16 BYTES) AND USER IS LOGGED INTO
; DIRECTORY CONTAINING INDICATED FILE
;
function:
;
; FILE PAGE Routine -- Page the File Whose Name is Pointed to by
; HL; we are already logged into the correct directory
;
ld a,(hl) ; File selected?
or a ; 0=yes
ret nz
call prinit ; Init print buffers
call fload ; Load buffer initially
ld hl,(scratch) ; Pt to first char in file
ld (nxtln),hl ; Set pointer to next line
fprloop:
call prline ; Print line of file
jr nz,fprloop ; Done if EOF
call page ; Advance to top of next page
jp prfoot ; Print footer & return to caller
;
; Init Print Buffers and Print File Name
;
prinit:
ld de,tfcb ; Set up FCB
ld b,12 ; 12 bytes
call moveb
ld hl,0 ; HL=0
ld (pnum),hl ; Set page number
ld (lnum),hl ; Set line number
ld a,(ctpp) ; Set line count
dec a ; 1 less for first line
ld (lcount),a
call crlf
call comnam
call eprint
db ' File: ',0
ld hl,tfcb ; Print file name
call prfn
jp crlf
;
; FILE LOAD (FLOAD) Routine -- Initial Load of memory buffer
;
fload:
ld de,tfcb ; Pt to file fcb
call initfcb ; Init file's fcb
call f$open ; Open file for input
jr z,fload1 ; Open was OK
call eprint
db cr,lf,'File ',0
ex de,hl ; HL pts to FCB
call prfn ; Print file name
call eprint
db ' NOT Found',0
pop de ; Clear return address
ret ; Abort printout of this file
;
; This is an entry point for further memory loads of the file
;
fload1:
ld a,(bcnt) ; Get number of blocks to load
ld c,a ; In C
ld hl,(scratch) ; Get address of first block to load into
ld (nxtblk),hl ; Set pointer to next block to load
fload2:
call rdblk ; Read a block (128 bytes)
jr nz,eof ; Eof encountered?
call rdblk ; Read another block (128 bytes)
jr nz,eof ; Eof encountered?
dec c ; Count down
jr nz,fload2
ld hl,(nxtblk) ; Pt to next byte to load
ld (hl),eold ; Mark end of load
ret
eof:
ld de,tfcb ; Close file
call f$close
ld hl,(nxtblk) ; Ensure ^Z
ld (hl),ctrlz
ret
rdblk:
ld de,tfcb ; Pt to FCB
call f$read ; Read next block
or a ; Error?
ret nz
ld de,(nxtblk) ; Get ptr to next block
ld hl,tbuff ; Ptr to DMA address
ld b,128 ; Copy 128 bytes
rdblk1:
ld a,(hl) ; Get byte
and 7fh ; Mask out msb
ld (de),a ; Put byte
inc hl ; Pt to next
inc de
djnz rdblk1 ; Count down
xor a
ex de,hl ; New nxtblock
ld (nxtblk),hl
ret
;
; Line Print Routine
; Print Next Line with Optional Disk Load
; Input Parameter is NXTLN, which is the address of the first char
; on the next line
; Output Parameter is Zero Flag, with Z meaning done with print, NZ
; meaning more yet to print
;
prline:
ld hl,(lnum) ; Increment line number
inc hl
ld (lnum),hl
ld hl,(nxtln) ; Pt to first char of next line
ld c,0 ; Init char count
ld a,(hl) ; Get first char of line
cp ctrlz ; EOF?
call nz,prlnum ; Print line number (optional)
prl1:
ld a,(hl) ; Get char
cp eold ; End of load?
jr z,prload
cp ctrlz ; Eof?
jr z,prexit
inc hl ; Pt to next char
cp ctrli ; Tab?
jr z,prtab
cp cr ; <CR>?
jr z,prcr
cp ff ; Form feed?
jr z,prff
cp lf ; End of line?
jr z,prldn
cp ctrlh ; Back space?
jr z,prbs
cp ctrlg ; Ring bell?
jr z,prbell
cp del ; Delete char?
jr z,prl1 ; Skip it
cp ' ' ; Other control char?
jr c,prl1 ; Skip if other control char
call prout ; Print char
inc c ; Increment char count
call eoltest ; Check to see if at end of line and newline if so
jr prl1
;
; End of Load Reached -- Load More of File from Disk
;
prload:
push bc ; Save char count
call fload1 ; Use load routine
pop bc ; Get char count
ld hl,(scratch) ; Next byte is here
jr prl1 ; Continue processing
;
; Tabulate
;
prtab:
ld a,' ' ; Space
call prout
inc c ; New char
call eoltest ; Process EOL
ld a,c ; Done?
and 7
jr nz,prtab ; Continue tabulation
jr prl1 ; Continue processing
;
; Exit with Zero Flag Set if Done
;
prexit:
xor a ; Set zero flag
ret
;
; Carriage Return -- Reset Character Count and Continue
;
prcr:
call prout ; Send CR to printer
ld c,0 ; Reset char count
jr prl1 ; Continue processing
;
; Form Feed -- Advance to Top of Next Page
;
prff:
call page ; Page eject with heading
ld c,0 ; Reset char count
jr prl1 ; Continue processing
;
; Line Feed -- End of Routine
;
prldn:
call prout ; Echo LF to printer
ld (nxtln),hl ; Set ptr to first char of next line
ld a,0ffh ; Set not done
or a ; Set flags
ret
;
; Backspace on Printer
;
prbs:
ld a,c ; Check for beginning of line
or a
jr z,prl1 ; Continue if at BOL
ld a,ctrlh ; Backspace
call prout
dec c ; Back up char position
jr prl1 ; Continue
;
; Ring Bell on Printer
;
prbell:
call prout ; Ring the bell
jr prl1 ; Continue without advancing char position
;
; Test for End of Line and Process if so
;
eoltest:
ld a,(cwidth) ; Get line width
sub 4 ; 4 chars less for continuation mark
ld b,a ; Result in B
ld a,(lnumfl) ; Line numbering (lines are 7 chars shorter if so)
or a ; 0=no
jr z,eolt1
ld a,b ; Reduce by 7 for line numbers
sub 7
ld b,a
eolt1:
ld a,b ; Get line width
cp c ; There?
ret nz ; Continue if not
ld a,(hl) ; Get next char
cp cr ; New line next?
ret z ; Continue if so
cp ctrlh ; Backspace next?
ret z ; Continue if so
push hl
ld b,3 ; See if a new line in next 3 chars
eolt2:
inc hl
ld a,(hl) ; Look for CR
cp cr
jr z,eolt3
djnz eolt2
jr eolt4
eolt3:
pop hl ; Restore ptr
ret
eolt4:
pop hl ; Restore ptr
ld a,' ' ; Print continuation chars
call prout
ld a,'<'
call prout
ld a,'<'
call prout
ld a,cr ; New line
call prout
ld a,lf
call prout
ld c,0 ; Reset char position
ld a,(skipfl) ; Skipping?
or a ; 0=no
ret nz
ld a,(lnumfl) ; Printing line numbers?
or a ; 0=no
ret z
call eprint
db ' : ',0
ret
;
; Output a character to the console
; A = Character
;
prout:
ld b,a ; Char in B
call cst ; Check for abort
jr nz,prout1
call ctrlin ; Get control input
prout1:
ld a,(skipfl) ; Skipping?
or a ; Set flags (Z=no skip=print char)
ld a,b ; Restore char
call z,ctrlout ; Send character to printer
cp lf ; Special tests if it is a line feed
ret nz ; Done if non-LF char
ld a,(lcount) ; Decrement line counter
dec a
ld (lcount),a
ret nz
;
; Paging Required
; Skip to top of next page; reset LCOUNT (Lines Left on Page Count);
; increment PNUM (Screen Number); test for skip stop; print header
;
prout0:
ld a,(ctpp) ; Get number of text lines per page
ld (lcount),a ; Set as new line count
push hl ; Save ptr
ld hl,(pnum) ; Increment page number
inc hl
ld (pnum),hl
ld a,(cspp) ; Number of lines to skip
call lineskp ; Skip lines
pop hl ; Restore ptr
call prfoot ; Print 1-line footer
ld a,(hl) ; Check next char
cp ctrlz ; EOF?
jp z,fctlnxt ; Skip to next file
ld a,(skipfl) ; Skipping?
or a ; 0=no
push hl
call nz,skiptst ; Affects HL
pop hl
ret
;
; Skip out rest of page
; Form Feed Function
;
page:
ld a,(lcount) ; Get count of remaining lines
call lineskp ; Skip lines
jr prout0 ; Process top of new page
;
; Skip out lines on page
;
lineskp:
ld b,a ; Line count in B
or a ; Any?
ret z
ld a,(skipfl) ; Skipping?
or a
ret nz
ld a,(pagefl) ; Paging?
or a
ret z
lines1:
ld a,cr ; Output new line to printer
call cout
ld a,lf
call cout
djnz lines1 ; Count down
ret
;
; Control Input
; CTRLIN -- Main Routine Entry Point; Implements Dynamic Commands,
; including P, 0-9, ^S, ^X, and ^C
; CTRLCS -- ^S Reentry Point; Implements all Dyanamic Commands except ^S
;
ctrlcs:
call cin ; Get input
jr ctrlns
ctrlin:
call cin ; Get input
cp ctrls ; Pause?
jr z,ctrlcs
ctrlns:
call caps ; Capitalize
cp ctrlc ; Abort?
jp z,abort
cp ctrlx ; Skip to next
jp z,fctlnxt
cp 'P' ; Page now?
jr z,ctrlip
cp '0' ; Delay?
ret c
cp '9'+1
ret nc
sub '0' ; Convert to binary
ld (delay),a ; Set delay count
ret
ctrlip:
ld a,(pagefl) ; Toggle paging
cpl
ld (pagefl),a
ret
;
; Control Output
;
ctrlout:
push af ; Save char
call cout ; Output char
ld a,(delay) ; Pause?
or a ; Any delay?
jr z,ctrloz
push hl ; Delay
push bc
ld b,a ; Delay count
del1:
call getspeed
ld hl,0
push de
ld de,500/4 ; Delay constant
del1a: add hl,de
dec a
jr nz,del1a
pop de
del2:
ex (sp),hl ; Long NOP
ex (sp),hl
dec hl ; Count down
ld a,h ; Done?
or l
jr nz,del2
djnz del1 ; Count down
pop bc ; Restore regs
pop hl
ctrloz:
pop af ; Restore A
ret
;
; Print Line Number (optional)
;
prlnum:
ld a,(skipfl) ; Skipping?
or a ; 0=no
ret nz
ld a,(lnumfl) ; Get flag
or a ; 0=don't number lines
ret z
push hl ; Save ptr
ld hl,(lnum) ; Get line number
call phldc ; Print line number
call eprint ; Print separator
db ': ',0
pop hl ; Restore ptr
ret
;
; Print 1-line footer
;
prfoot:
ld a,(skipfl) ; Skipping?
or a ; 0=no
ret nz
ld a,(pagefl) ; Paging?
or a
ret z
push hl ; Save ptr
call prpnum ; Print page heading and number
call prdash ; Print dash
ld hl,tfcb ; Pt to file FCB
call prfn ; Print file name
pop hl ; Restore ptr
call eprint
db ' -- Strike Any Key ',0
call ctrlin ; Get control response
jp crlf ; New line
;
; Test for completion of skipping
;
skiptst:
ld hl,(pnum) ; Get page number
inc hl ; Increment for test
ex de,hl ; In DE
ld hl,(skipnum) ; Get page to skip to
ld a,h ; Compare them
cp d
ret nz
ld a,l
cp e
ret nz
xor a ; A=0 to stop skipping
ld (skipfl),a ; Set flag
ret
;
; Print Page Number
;
prpnum:
call eprint ; Print header
db 'Screen ',0
ld hl,(pnum) ; Print current page number
jp phldc ; Print as decimal, return to caller
;
; Print Separator
;
prdash:
call eprint
db ' -- ',0
ret
;
; UTILITIES
; SBLANK -- SKIP BLANKS PTED TO BY HL UNTIL NON-BLANK ENCOUNTERED; HL
; SNBLANK -- SKIP NON-BLANKS PTED TO BY HL UNTIL BLANK OR EOL; HL
; PRFN -- PRINT FILE NAME PTED TO BY HL; AFFECT NOTHING
;
;
; SKIP UNTIL NON-BLANK
;
sblank:
ld a,(hl) ; LOOK FOR BLANK
inc hl ; PT TO NEXT
cp ' ' ; BLANK?
jr z,sblank
dec hl ; BACK UP
ret
;
; SKIP UNTIL BLANK OR EOL
;
snblank:
ld a,(hl) ; GET CHAR
inc hl ; PT TO NEXT
cp ' ' ; BLANK?
jr z,snb1
or a ; EOL?
jr nz,snblank
snb1:
dec hl ; BACK UP
ret
;
; PRINT FILE NAME PTED TO BY HL
; OUTPUT TO CON:
;
prfn:
push hl ; SAVE REGS
push bc
call retud ; GET CURRENT USER/DISK
ld a,b ; PRINT DISK
add a,'A' ; LETTER
call cout
ld a,c ; PRINT USER
call padc
call eprint
db ': ',0
inc hl ; PT TO FILE NAME
ld b,8 ; PRINT NAME
call prnt
ld a,'.' ; DECIMAL
call cout
ld b,3 ; PRINT TYPE
call prnt
pop bc ; GET REGS
pop hl
ret
;
; PRINT CHARS PTED TO BY HL FOR B BYTES
; OUTPUT TO CON:
;
prnt:
ld a,(hl) ; GET CHAR
call cout
inc hl ; PT TO NEXT
djnz prnt ; COUNT DOWN
ret
; Print our name if ZCPR3 knows it, otherwise print "PAGE"
;
comnam: call getefcb
jr z,noefcb
ld b,8
cmnmlp: inc hl
ld a,(hl)
and 7fh
cp ' '
call nz,cout
djnz cmnmlp
ret
;
noefcb: call eprint
db 'PAGE',0
ret
;
; BUFFERS
;
dseg
cwidth:
ds 1 ; WIDTH OF SCREEN
ctpp:
ds 1 ; LINES OF TEXT PER SCREEN
skipnum:
ds 2 ; PAGE NUMBER TO SKIP TO
lnum:
ds 2 ; CURRENT LINE NUMBER
pnum:
ds 2 ; CURRENT PAGE NUMBER
cmdlne:
ds 2 ; PTR TO COMMAND LINE STRING
dirbuf:
ds 2 ; PTR TO DIRECTORY BUFFER
nextch:
ds 2 ; PTR TO NEXT CHAR IN MULTIFILE COMMAND LINE
filecnt:
ds 2 ; COUNT OF NUMBER OF FILES RENAMED
scratch:
ds 2 ; ADDRESS OF FIRST BYTE OF SCRATCH AREA
bcnt:
ds 1 ; NUMBER OF PAGES IN SCRATCH AREA
;
; PAGE Buffers
;
tfcb:
ds 36 ; FCB for current file
nxtblk:
ds 2 ; Pointer to next block to load
nxtln:
ds 2 ; Pointer to next line to read
lcount:
ds 1 ; Count of text lines left on page
;
; Stack
;
stack:
ds 2 ; OLD STACK PTR
end