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
Text File  |  2000-06-30  |  26KB  |  1,221 lines

  1. ;
  2. ;  PROGRAM:  PAGE
  3. ;  VERSION:  2.0
  4. ;  DATE:  18 May 84
  5. ;  AUTHOR:  RICHARD CONN
  6. ;  PREVIOUS VERSIONS:  1.2 (26 Apr 83), 1.1 (25 Apr 83), 1.0 (22 Apr 83)
  7. ;
  8. vers    equ    21
  9. z3env    defl    0fe00h
  10.  
  11. ; Version 2.1 modifications by Bruce Morgen, September 9, 1988
  12. ;
  13. ;    v2.1 is basically a maintenance update to catch up with Z33/Z34
  14. ; and get PAGE down to a sensible 4K via Z80 opcodes, implementation of
  15. ; a DSEG and linkage with the beta v4 Z3LIB and SYSLIB.  Z33LIB is also
  16. ; required for re-building the program.  The only visible functional
  17. ; changes are a correction and "intelligence" added to the help screen.
  18. ; Translated code to Zilog mnemonics - the Z80 is almost 10 years old,
  19. ; after all.  This is one of Rick's nicer tools, worth a second look.
  20. ; More subtle changes include wheel-controlled access to SYS files and
  21. ; an inter-character delay variable based on the CPU speed byte in ENV.
  22. ;
  23. ;    PAGE is THE file screen print utility for ZCPR3.  Installable by
  24. ; Z3INS, PAGE provides a wide range of options for the user.  First, PAGE
  25. ; allows the user to employ wild cards and file name lists (lists of files
  26. ; separated by commas, like: file1,file2,file3,...).  Second, PAGE provides
  27. ; the following options:
  28. ;        0-9    Set Character Print Speed Delay
  29. ;        I    Inspect Files
  30. ;                The user approves each file to be printed
  31. ;                before the printing process begins
  32. ;        L    Toggle Line Numbering
  33. ;                Each line may or may not begin with a line
  34. ;                number
  35. ;        P    Toggle Screen Paging
  36. ;        Snnnn    Skip to Specified Page
  37. ;                Printing begins on the indicated page
  38. ;
  39. ;    During paged output, various parameters can be changed dynamically.
  40. ; In particular, the letter P toggles screen paging and the digits 0-9
  41. ; vary the speed WHILE the output is being presented.  The effect is immediate.
  42. ; Control characters may be used to perform additional control functions:
  43. ; ^S pauses the output, ^X aborts paging of current file and advances to
  44. ; the next file, and ^C aborts to the operating system.
  45. ;
  46.  
  47. false    equ    0
  48. true    equ    not false
  49.  
  50. ;
  51. ;  BASIC SYSLIB ROUTINES NEEDED BY TEMPLATE
  52. ;
  53. esize    equ    16        ; SIZE OF DIR ENTRY (FROM SYSLIB DIRF ROUTINE)
  54.  
  55.     extrn    dirq        ; DIRECTORY PROCESSOR
  56.  
  57.     extrn    z33chk,z33fname    ; Z33LIB stuff, for parsing
  58.  
  59.     extrn    z3init        ; INIT BUFFERS
  60.     extrn    zfname        ; FILE NAME PROCESSOR
  61.     extrn    getcrt        ; GET CRT PARAMETERS
  62.     extrn    z3log        ; LOG INTO DIR
  63.     extrn    getefcb
  64.     extrn    getwhl
  65.     extrn    getspeed
  66.  
  67.     extrn    initfcb        ; INIT FCB
  68.     extrn    retud        ; RETURN CURRENT USER/DISK
  69.     extrn    putud        ; SAVE CURRENT USER/DISK
  70.     extrn    getud        ; RESTORE CURRENT USER/DISK
  71.     extrn    eprint        ; PRINT STRING PTED TO BY RET ADR
  72.     extrn    padc        ; PRINT A IN DEC
  73.     extrn    cout        ; CONSOLE OUTPUT ROUTINE
  74.     extrn    cst        ; CONSOLE STATUS ROUTINE
  75.     extrn    cin        ; CONSOLE INPUT ROUTINE
  76.     extrn    caps        ; CAPITALIZE ROUTINE
  77.     extrn    crlf        ; NEW LINE ROUTINE
  78.     extrn    codend        ; CODE END COMPUTATION ROUTINE
  79.  
  80.     extrn    f$open        ; FILE OPEN
  81.     extrn    f$read        ; BLOCK READ
  82.     extrn    f$close        ; FILE CLOSE
  83.  
  84.     extrn    eval10        ; STRING TO BINARY CONVERSION
  85.     extrn    phldc        ; PRINT HL IN DECIMAL ROUTINE
  86.     extrn    moveb        ; MOVEB ROUTINE
  87.  
  88. ;
  89. ;  CP/M EQUATES
  90. ;
  91. cpm    equ    0        ; WARM BOOT
  92. bdose    equ    cpm+5        ; BDOS ENTRY
  93. fcb    equ    cpm+5ch        ; FCB
  94. tbuff    equ    cpm+80h        ; INPUT LINE BUFFER
  95. del    equ    7fh        ; <DEL>
  96. cr    equ    13        ; <CR>
  97. ff    equ    12        ; <FF>
  98. lf    equ    10        ; <LF>
  99. ctrlc    equ    'C'-'@'        ; ^C
  100. ctrlg    equ    'G'-'@'
  101. ctrlh    equ    'H'-'@'
  102. ctrli    equ    'I'-'@'
  103. ctrls    equ    'S'-'@'
  104. ctrlx    equ    'X'-'@'
  105. ctrlz    equ    'Z'-'@'
  106.  
  107. ;
  108. ;  OTHER EQUATES
  109. ;
  110. eold    equ    0ffh        ; END OF LOAD DELIMITER
  111.  
  112.     cseg
  113. ;
  114. ; Environment Definition
  115. ;
  116.      if    z3env ne 0
  117. ;
  118. ; External ZCPR3 Environment Descriptor
  119. ;
  120.     jp    start
  121.     db    'Z3ENV'        ; This is a ZCPR3 Utility
  122.     db    1        ; External Environment Descriptor
  123. z3eadr:
  124.     dw    z3env
  125. start:
  126.     ld    hl,(z3eadr)    ; Pt to ZCPR3 environment
  127. ;
  128.      else
  129. ;
  130. ; Internal ZCPR3 Environment Descriptor
  131. ;
  132.     maclib    z3base.lib
  133.     maclib    sysenv.lib
  134. z3eadr:
  135.     jp    start
  136.     sysenv
  137. start:
  138.     ld    hl,z3eadr    ; Pt to ZCPR3 environment
  139.      endif
  140.  
  141. ;
  142. ; Start of Program -- Initialize ZCPR3 Environment
  143. ;
  144.     call    z3init        ; Initialize the ZCPR3 Env and the VLIB Env
  145.     jr    startx
  146.  
  147. ;
  148. ;  **** Special Initial Value Area
  149. ;
  150. cspp:
  151.     db    1        ; LINES TO SKIP PER SCREEN
  152. ;
  153. ;  NOTE:  CTPP + CSPP + 1 (FOOTER SIZE) = TOTAL LINES PER SCREEN ON CONSOLE
  154. ;
  155. dlnumfl:
  156.     db    0        ; LINE NUMBER FLAG (DEFAULT TO NO)
  157. dpagefl:
  158.     db    0ffh        ; PAGE NUMBER FLAG (DEFAULT TO YES)
  159. dinspect:
  160.     db    0        ; INSPECT FILES (DEFAULT TO NO)
  161. ddelay:
  162.     db    0        ; DELAY COUNT (DEFAULT TO 0)
  163. ;
  164. ;  OTHER BUFFERS
  165. ;
  166. skipfl:
  167.     db    0        ; SKIP FLAG (DEFAULT TO NO)
  168. lnumfl:
  169.     db    0        ; LINE NUMBER FLAG (DEFAULT TO NO)
  170. pagefl:
  171.     db    0ffh        ; PAGE NUMBER FLAG (DEFAULT TO YES)
  172. inspect:
  173.     db    0        ; INSPECT FILES (DEFAULT TO NO)
  174. delay:
  175.     db    0        ; DELAY COUNT (DEFAULT TO 0)
  176.  
  177. ;
  178. ;  Start of Program
  179. ;
  180. startx:
  181.     ld    (stack),sp    ; GET STACK PTR & SAVE IT
  182.     call    codend        ; DETERMINE FREE SPACE
  183.     ld    (cmdlne),hl    ; COMMAND LINE BUFFER
  184.     inc    h        ; BUFFER SIZE IS 100H
  185.     ld    (dirbuf),hl    ; ADDRESS OF DIRECTORY BUFFER (TOP OF LOCAL STACK)
  186.     ld    sp,hl        ; SET NEW STACK
  187.     call    putud        ; SAVE CURRENT USER/DISK AWAY
  188.  
  189.     call    getcrt        ; GET CRT PARAMETERS
  190.     ld    a,(hl)
  191.     ld    (cwidth),a
  192.     inc    hl
  193.     inc    hl
  194.     ld    a,(hl)        ; GET NUMBER OF TEXT LINES
  195.     ld    (ctpp),a
  196.     ld    b,a        ; IN B
  197.     dec    hl
  198.     ld    a,(hl)        ; GET TOTAL NUMBER OF LINES
  199.     sub    b        ; COMPUTE NUMBER OF LINES TO SKIP/SCREEN
  200.     dec    a        ; 1 LINE FOR PROMPT
  201.     ld    (cspp),a
  202.  
  203.     ld    hl,tbuff+1    ; SAVE COMMAND LINE
  204.     ld    de,(cmdlne)    ; GET PTR TO COMMAND LINE SAVE BUFFER
  205.     ld    b,80h        ; SIZE OF LINE
  206.     call    moveb        ; COPY COMMAND LINE
  207.  
  208. ;
  209. ;  **** Banner of Program
  210. ;
  211.     call    eprint
  212.     db    'PAGE,  Version '
  213.     db    vers/10+'0','.',(vers mod 10)+'0',0
  214.  
  215. ;
  216. ;  Check for Help Request
  217. ;
  218.     ld    a,(fcb+1)    ; GET FIRST CHAR OF FILE NAME
  219.     cp    ' '        ; NO FILE SPEC?
  220.     jr    z,help
  221.     cp    '/'        ; OPTION CAUGHT?
  222.     jp    nz,econt
  223.  
  224. ;
  225. ;  **** Print Help Information
  226. ;
  227. help:
  228.     call    eprint
  229.     db    cr,lf,'Syntax:'
  230.     db    cr,lf,'  ',0
  231.     call    comnam
  232.     call    eprint
  233.     db    ' file1,file2,...,filen o...'
  234.     db    cr,lf,'Options:'
  235.     db    cr,lf,' 0-9 Select Delay Constant'
  236.     db    cr,lf,' I Inspect and Select Files First'
  237.     db    cr,lf,' L Toggle Numbering of Each Line'
  238.     db    cr,lf,' P Toggle Paging'
  239.     db    cr,lf,' Snnnn Skip to Specified Page before Printing'
  240.     db    cr,lf
  241.     db    cr,lf,'Examples:'
  242.     db    cr,lf,'   ',0
  243.     call    comnam
  244.     call    eprint
  245.     db    ' MYFILE.TXT,*.MAC LI'
  246.     db    cr,lf,'    -- Number Lines, Inspect Files'
  247.     db    cr,lf,'   ',0
  248.     call    comnam
  249.     call    eprint
  250.     db    ' MYFILE.* S25'
  251.     db    cr,lf,'    -- Skip to Page 25'
  252.     db    cr,lf
  253.     db    cr,lf,'Commands during printout:'
  254.     db    cr,lf,' ^C  - abort program   ^X  - skip to next file'
  255.     db    cr,lf,' ^S  - suspend output   P  - toggle paging'
  256.     db    cr,lf,'       0-9 - change scrolling speed'
  257.     db    0
  258.  
  259. ;
  260. ;  RETURN TO OS
  261. ;
  262. return:
  263.     ld    sp,(stack)    ; GET OLD STACK
  264.     ret
  265.  
  266. ;
  267. ;  PROGRAM'S INIT ROUTINE
  268. ;
  269. econt:
  270.     call    init        ; PROG INIT ROUTINE
  271. ;
  272. ;  EXTRACT FLAGS IF PRESENT
  273. ;
  274.     ld    hl,0        ; SET FILE COUNT
  275.     ld    (filecnt),hl
  276.     ld    hl,(cmdlne)    ; PT TO BUFFER
  277. ;
  278. ;  SKIP TO FILE NAME STRING
  279. ;
  280.     call    sblank        ; SKIP OVER BLANKS
  281. ;
  282. ;  SKIP TO END OF FILE NAME STRING
  283. ;
  284.     call    snblank        ; SKIP OVER NON-BLANKS
  285. ;
  286. ;  CHECK FOR LEADING SLASH ON OPTION AND SKIP IT IF SO
  287. ;
  288. opt:
  289.     cp    '/'        ; OPTION CHAR?
  290.     jr    nz,option
  291.     inc    hl        ; SKIP SLASH
  292. ;
  293. ;  PROCESS LIST OF OPTIONS
  294. ;
  295. option:
  296.     ld    a,(hl)        ; GET BYTE
  297.     or    a        ; DONE?
  298.     jp    z,dspec
  299.     inc    hl        ; PT TO NEXT CHAR
  300.     cp    ' '        ; SKIP OVER SPACES
  301.     jr    z,option
  302.     ld    c,a        ; COMMAND IN C
  303.     ld    de,optab    ; PT TO OPTION TABLE
  304. optl:
  305.     ld    a,(de)        ; GET OPTION LETTER
  306.     or    a        ; END OF TABLE?
  307.     jp    z,help        ; HELP IF SO
  308.     cp    c        ; MATCH?
  309.     jr    z,optm        ; PROCESS IF SO
  310.     inc    de        ; PT TO NEXT ENTRY
  311.     inc    de
  312.     inc    de
  313.     jr    optl
  314. ;
  315. ;  PROCESS OPTION
  316. ;
  317. optm:
  318.     push    hl        ; SAVE HL ON STACK
  319.     ld    hl,option    ; GET RETURN ADDRESS
  320.     ex    (sp),hl        ; ON STACK AND RESTORE HL
  321.     inc    de        ; PT TO ADDRESS
  322.     ld    a,(de)        ; GET ADDRESS LOW
  323.     ld    b,a        ; IN B
  324.     inc    de
  325.     ld    a,(de)        ; GET ADDRESS HIGH
  326.     ld    d,a        ; IN D
  327.     ld    e,b        ; LOW IN E
  328.     push    de        ; PUT ADDRESS ON STACK
  329.     ld    a,c        ; COMMAND IN A
  330.     ret            ; "CALL" OPTION ROUTINE
  331.  
  332. ;
  333. ;  **** PROGRAM INIT ROUTINE
  334. ;    THIS ROUTINE IS USED BY THE PROGRAM TO PERFORM ANY INITS
  335. ;
  336. init:
  337.     ld    hl,dlnumfl    ; Copy defaults into buffers
  338.     ld    de,lnumfl
  339.     ld    b,4        ; 4 bytes
  340.     call    moveb        ; Do copy
  341.     xor    a        ; A=0
  342.     ld    (skipfl),a    ; Set no skip
  343.     ret
  344.  
  345. ;
  346. ;  **** OPTION TABLE
  347. ;    EACH OPTION IS A CAPITAL LETTER OR SPECIAL CHAR FOLLOWED BY
  348. ;        AN ADDRESS; THE TABLE IS TERMINATED BY A BINARY ZERO
  349. ;
  350. optab:
  351.     db    '0'
  352.     dw    optnum
  353.     db    '1'
  354.     dw    optnum
  355.     db    '2'
  356.     dw    optnum
  357.     db    '3'
  358.     dw    optnum
  359.     db    '4'
  360.     dw    optnum
  361.     db    '5'
  362.     dw    optnum
  363.     db    '6'
  364.     dw    optnum
  365.     db    '7'
  366.     dw    optnum
  367.     db    '8'
  368.     dw    optnum
  369.     db    '9'
  370.     dw    optnum
  371.     db    'I'
  372.     dw    optinsp
  373.     db    'L'
  374.     dw    optln
  375.     db    'P'
  376.     dw    optpage
  377.     db    'S'
  378.     dw    optskip
  379.     db    0        ; END OF TABLE
  380. ;
  381. ;  Set Delay Constant
  382. ;
  383. optnum:
  384.     sub    '0'        ; Set constant
  385.     ld    (delay),a
  386.     ret
  387. ;
  388. ;  Toggle Inspect Option
  389. ;
  390. optinsp:
  391.     ld    a,(inspect)    ; Flip flag
  392.     cpl
  393.     ld    (inspect),a
  394.     ret
  395. ;
  396. ;  Set Line Number Flag
  397. ;
  398. optln:
  399.     ld    a,(lnumfl)    ; Flip flag
  400.     cpl
  401.     ld    (lnumfl),a
  402.     ret
  403. ;
  404. ;  Toggle Paging
  405. ;
  406. optpage:
  407.     ld    a,(pagefl)    ; Flip flag
  408.     cpl
  409.     ld    (pagefl),a
  410.     ret
  411. ;
  412. ;  Set Skip Flag and get number
  413. ;
  414. optskip:
  415.     ld    a,0ffh        ; Set flag
  416.     ld    (skipfl),a
  417.     call    eval10        ; Get number in DE (A = E)
  418.     ld    (skipnum),de    ; Set page number to skip to
  419.     or    d        ; See if page number was zero
  420.     jp    nz,option
  421.     ld    (skipfl),a    ; If zero, just turn off skip flag
  422.     ret
  423. ;
  424. ;  BEGIN MOVING THROUGH FILE NAMES, SEPARATED BY COMMAS
  425. ;
  426. dspec:
  427.     ld    hl,(cmdlne)    ; PT TO FIRST BYTE
  428.     call    sblank        ; SKIP TO NON-BLANK
  429. ;
  430. ;  MAJOR REENTRY POINT WHEN FILE SPECS ARE SEPARATED BY COMMAS
  431. ;    HL PTS TO FIRST BYTE OF NEXT FILE SPEC
  432. ;
  433. dspec1:
  434.     ld    sp,(dirbuf)    ; RESET STACK
  435.     call    getud        ; RESET USER IF NECESSARY
  436.     call    z33chk
  437.     ld    de,fcb        ; PT TO FCB IN DE, PT TO FIRST CHAR OF FILE NAME IN HL
  438.     jr    z,gotz33
  439.     xor    a        ; DIR BEFORE DU
  440.     call    zfname        ; EXTRACT FILE NAME INTO FCB, AND GET DISK AND USER
  441.     jr    parsed
  442. gotz33:    call    z33fname
  443. parsed:    ld    (nextch),hl    ; SAVE PTR TO DELIMITER WHICH ENDED SCAN
  444.     ld    de,fcb        ; PT TO FCB
  445.     call    z3log        ; LOG INTO DU FOR FILE
  446.  
  447. ;
  448. ;  LOAD DIRECTORY AND PERFORM FUNCTION
  449. ;
  450. fct:
  451.     ld    de,fcb        ; PT TO FCB
  452.     call    initfcb        ; INIT THE FCB
  453.     call    getwhl
  454.     ld    hl,(dirbuf)    ; PT TO DIR BUFFER
  455.     ld    a,11000000b    ; SELECT SYS AND NON-SYS FILES
  456.     jr    nz,dodirq    ; GO DO IT IF WHEEL BYTE SET
  457.     ld    a,10000000b    ; SELECT NON-SYS FILES ONLY
  458. dodirq:    call    dirq        ; LOAD DIR, SELECT FILES, PACK, AND ALPHABETIZE
  459. ;
  460. ;  DETERMINE BEGINNING OF SCRATCH AREA (SCRATCH) AND SIZE IN PAGES (BCNT)
  461. ;
  462.     push    hl        ; SAVE PTR AND COUNT
  463.     push    bc
  464.     ld    de,esize    ; SET PTR TO NEXT FREE BLOCK
  465. fctfre:
  466.     ld    a,b        ; DONE?
  467.     or    c
  468.     jr    z,fctfr1
  469.     add    hl,de        ; PT TO NEXT
  470.     dec    bc        ; COUNT DOWN
  471.     jr    fctfre
  472. fctfr1:
  473.     inc    h        ; NEXT PAGE
  474.     ld    l,0
  475.     ld    (scratch),hl    ; SET PTR TO SCRATCH AREA
  476.     ex    de,hl        ; PTR IN DE
  477.     ld    hl,(bdose+1)    ; COMPUTE BLOCK BUFFER SIZE
  478.     ld    a,h        ; ADJUST FOR ZCPR3
  479.     sub    10
  480.     sub    d        ; A=SIZE IN BLOCKS
  481.     ld    (bcnt),a    ; SET BLOCK COUNT
  482.     pop    bc        ; RESTORE AND SAVE REGS
  483.     pop    hl
  484. ;
  485. ;  ALLOW USER TO INSPECT FILES
  486. ;
  487.     push    hl
  488.     push    bc
  489.     call    icheck        ; CHECK FOR INSPECT OPTION AND INSPECT IF SET
  490.     pop    bc        ; RESTORE COUNT AND PTR
  491.     pop    hl
  492.  
  493. ;
  494. ;  PERFORM FUNCTION; HL PTS TO FILE AND BC CONTAINS NUMBER OF FILES
  495. ;
  496. fctl:
  497.     ld    a,b        ; CHECK FOR COMPLETION (COUNT = 0)
  498.     or    c
  499.     jr    z,fctl1
  500.     dec    bc        ; COUNT DOWN
  501.     ld    sp,(dirbuf)    ; SET STACK
  502.     push    bc        ; SAVE COUNT AND PTR
  503.     push    hl
  504.     call    function    ; PERFORM FUNCTION
  505. fctlnxt:
  506.     ld    sp,(dirbuf)    ; RESTORE STACK
  507.     dec    sp
  508.     dec    sp
  509.     dec    sp
  510.     dec    sp        ; SET STACK
  511.     pop    hl        ; RESTORE PTR
  512.     pop    bc        ; RESTORE COUNT
  513.     ld    de,esize    ; PT TO NEXT ENTRY
  514.     add    hl,de
  515.     jr    fctl
  516.  
  517. ;
  518. ;  CHECK FOR NEXT FILE SPEC
  519. ;
  520. fctl1:
  521.     call    getud        ; RETURN TO BASE USER/DISK
  522.     ld    hl,(nextch)    ; GET PTR
  523.     ld    a,(hl)        ; GET DELIM
  524.     cp    ','        ; ANOTHER FILE?
  525.     jr    nz,dreturn
  526.     inc    hl        ; PT TO CHAR AFTER COMMA
  527.     jp    dspec1        ; CONTINUE PROCESSING
  528.  
  529. ;
  530. ;  **** EMERGENCY ABORT
  531. ;
  532. abort:
  533.     call    eprint
  534.     db    cr,lf,'** ',0
  535.     call    comnam
  536.     call    eprint
  537.     db    ' Abort **',cr,lf,0
  538.     call    getud        ; RETURN HOME AND FALL THRU TO DRETURN
  539. ;
  540. ;  **** FUNCTION COMPLETE -- CLEANUP AND EXIT
  541. ;    FILL THIS IN WITH CLEANUP CODE FOR EXIT
  542. ;
  543. dreturn:
  544.     jp    return
  545.  
  546. ;
  547. ;  **** INSPECT FILES -- THIS ROUTINE IS TO PERFORM A FILE INSPECTION
  548. ;    ON INPUT, HL PTS TO FIRST 16-BYTE ENTRY AND BC=NUMBER OF ENTRIES
  549. ;
  550. icheck:
  551.     ld    a,b        ; Any files?
  552.     or    c
  553.     ret    z
  554.     push    hl        ; Save ptrs
  555.     push    bc
  556.     ld    de,esize    ; Size of entry
  557. ichk1:
  558.     ld    (hl),0        ; Clear MSBytes
  559.     add    hl,de        ; Pt to next
  560.     dec    bc        ; Count down
  561.     ld    a,b        ; Done?
  562.     or    c
  563.     jr    nz,ichk1
  564.     pop    bc        ; Restore ptrs
  565.     pop    hl
  566.     ld    a,(inspect)    ; Inspect?
  567.     or    a        ; 0=no
  568.     ret    z
  569.     call    eprint
  570.     db    cr,lf,'PAGE File Inspect Mode'
  571.     db    cr,lf,' Y (def) = Select File      N = Don''t Select File'
  572.     db    cr,lf,' Q = Select Rest of Files   S = Skip Rest of Files'
  573.     db    cr,lf,0
  574. ichk2:
  575.     call    eprint
  576.     db    cr,lf,'Select ',0
  577.     call    prfn        ; Print file name
  578.     call    eprint
  579.     db    ' -- (Y/N/Q/S)? ',0
  580.     call    cin        ; Get response
  581.     call    caps        ; Capitalize
  582.     call    cout        ; Echo
  583.     cp    'Q'        ; Select rest?
  584.     jr    z,ichkyr
  585.     cp    'S'        ; Skip rest
  586.     jr    z,ichknr
  587.     cp    'N'        ; No to this one?
  588.     jr    nz,ichk3
  589.     ld    (hl),0ffh    ; Set NO flag in file FCB
  590. ichk3:
  591.     add    hl,de        ; Pt to next one
  592.     dec    bc        ; Count down
  593.     ld    a,b        ; Done?
  594.     or    c
  595.     jr    nz,ichk2
  596.     ret
  597. ;  Check Rest of Files as Selected
  598. ichkyr:
  599.     call    eprint
  600.     db    cr,lf,' Rest of Files Selected',0
  601.     ret
  602. ;  Check Rest of Files as NOT Selected
  603. ichknr:
  604.     ld    (hl),0ffh    ; Set NO flag
  605.     add    hl,de        ; Pt to next
  606.     dec    bc        ; Count down
  607.     ld    a,b        ; Done?
  608.     or    c
  609.     jr    nz,ichknr
  610.     call    eprint
  611.     db    cr,lf,' Rest of Files NOT Selected',0
  612.     ret
  613. ;
  614. ;  **** FUNCTION -- MAIN FUNCTION OF TEMPLATE
  615. ;    ON ENTRY, HL PTS TO NAME OF FILE (16 BYTES) AND USER IS LOGGED INTO
  616. ;        DIRECTORY CONTAINING INDICATED FILE
  617. ;
  618. function:
  619. ;
  620. ;  FILE PAGE Routine -- Page the File Whose Name is Pointed to by
  621. ;    HL; we are already logged into the correct directory
  622. ;
  623.     ld    a,(hl)        ; File selected?
  624.     or    a        ; 0=yes
  625.     ret    nz
  626.     call    prinit        ; Init print buffers
  627.     call    fload        ; Load buffer initially
  628.     ld    hl,(scratch)    ; Pt to first char in file
  629.     ld    (nxtln),hl    ; Set pointer to next line
  630. fprloop:
  631.     call    prline        ; Print line of file
  632.     jr    nz,fprloop    ; Done if EOF
  633.     call    page        ; Advance to top of next page
  634.     jp    prfoot        ; Print footer & return to caller
  635. ;
  636. ;  Init Print Buffers and Print File Name
  637. ;
  638. prinit:
  639.     ld    de,tfcb        ; Set up FCB
  640.     ld    b,12        ; 12 bytes
  641.     call    moveb
  642.     ld    hl,0        ; HL=0
  643.     ld    (pnum),hl    ; Set page number
  644.     ld    (lnum),hl    ; Set line number
  645.     ld    a,(ctpp)    ; Set line count
  646.     dec    a        ; 1 less for first line
  647.     ld    (lcount),a
  648.     call    crlf
  649.     call    comnam
  650.     call    eprint
  651.     db    ' File: ',0
  652.     ld    hl,tfcb        ; Print file name
  653.     call    prfn
  654.     jp    crlf
  655. ;
  656. ;  FILE LOAD (FLOAD) Routine -- Initial Load of memory buffer
  657. ;
  658. fload:
  659.     ld    de,tfcb        ; Pt to file fcb
  660.     call    initfcb        ; Init file's fcb
  661.     call    f$open        ; Open file for input
  662.     jr    z,fload1    ; Open was OK
  663.     call    eprint
  664.     db    cr,lf,'File ',0
  665.     ex    de,hl        ; HL pts to FCB
  666.     call    prfn        ; Print file name
  667.     call    eprint
  668.     db    ' NOT Found',0
  669.     pop    de        ; Clear return address
  670.     ret            ; Abort printout of this file
  671. ;
  672. ;  This is an entry point for further memory loads of the file
  673. ;
  674. fload1:
  675.     ld    a,(bcnt)    ; Get number of blocks to load
  676.     ld    c,a        ; In C
  677.     ld    hl,(scratch)    ; Get address of first block to load into
  678.     ld    (nxtblk),hl    ; Set pointer to next block to load
  679. fload2:
  680.     call    rdblk        ; Read a block (128 bytes)
  681.     jr    nz,eof        ; Eof encountered?
  682.     call    rdblk        ; Read another block (128 bytes)
  683.     jr    nz,eof        ; Eof encountered?
  684.     dec    c        ; Count down
  685.     jr    nz,fload2
  686.     ld    hl,(nxtblk)    ; Pt to next byte to load
  687.     ld    (hl),eold    ; Mark end of load
  688.     ret
  689. eof:
  690.     ld    de,tfcb        ; Close file
  691.     call    f$close
  692.     ld    hl,(nxtblk)    ; Ensure ^Z
  693.     ld    (hl),ctrlz
  694.     ret
  695. rdblk:
  696.     ld    de,tfcb        ; Pt to FCB
  697.     call    f$read        ; Read next block
  698.     or    a        ; Error?
  699.     ret    nz
  700.     ld    de,(nxtblk)    ; Get ptr to next block
  701.     ld    hl,tbuff    ; Ptr to DMA address
  702.     ld    b,128        ; Copy 128 bytes
  703. rdblk1:
  704.     ld    a,(hl)        ; Get byte
  705.     and    7fh        ; Mask out msb
  706.     ld    (de),a        ; Put byte
  707.     inc    hl        ; Pt to next
  708.     inc    de
  709.     djnz    rdblk1        ; Count down
  710.     xor    a
  711.     ex    de,hl        ; New nxtblock
  712.     ld    (nxtblk),hl
  713.     ret
  714.  
  715. ;
  716. ;  Line Print Routine
  717. ;    Print Next Line with Optional Disk Load
  718. ;    Input Parameter is NXTLN, which is the address of the first char
  719. ; on the next line
  720. ;    Output Parameter is Zero Flag, with Z meaning done with print, NZ
  721. ; meaning more yet to print
  722. ;
  723. prline:
  724.     ld    hl,(lnum)    ; Increment line number
  725.     inc    hl
  726.     ld    (lnum),hl
  727.     ld    hl,(nxtln)    ; Pt to first char of next line
  728.     ld    c,0        ; Init char count
  729.     ld    a,(hl)        ; Get first char of line
  730.     cp    ctrlz        ; EOF?
  731.     call    nz,prlnum    ; Print line number (optional)
  732. prl1:
  733.     ld    a,(hl)        ; Get char
  734.     cp    eold        ; End of load?
  735.     jr    z,prload
  736.     cp    ctrlz        ; Eof?
  737.     jr    z,prexit
  738.     inc    hl        ; Pt to next char
  739.     cp    ctrli        ; Tab?
  740.     jr    z,prtab
  741.     cp    cr        ; <CR>?
  742.     jr    z,prcr
  743.     cp    ff        ; Form feed?
  744.     jr    z,prff
  745.     cp    lf        ; End of line?
  746.     jr    z,prldn
  747.     cp    ctrlh        ; Back space?
  748.     jr    z,prbs
  749.     cp    ctrlg        ; Ring bell?
  750.     jr    z,prbell
  751.     cp    del        ; Delete char?
  752.     jr    z,prl1        ; Skip it
  753.     cp    ' '        ; Other control char?
  754.     jr    c,prl1        ; Skip if other control char
  755.     call    prout        ; Print char
  756.     inc    c        ; Increment char count
  757.     call    eoltest        ; Check to see if at end of line and newline if so
  758.     jr    prl1
  759. ;
  760. ;  End of Load Reached -- Load More of File from Disk
  761. ;
  762. prload:
  763.     push    bc        ; Save char count
  764.     call    fload1        ; Use load routine
  765.     pop    bc        ; Get char count
  766.     ld    hl,(scratch)    ; Next byte is here
  767.     jr    prl1        ; Continue processing
  768. ;
  769. ;  Tabulate
  770. ;
  771. prtab:
  772.     ld    a,' '        ; Space
  773.     call    prout
  774.     inc    c        ; New char
  775.     call    eoltest        ; Process EOL
  776.     ld    a,c        ; Done?
  777.     and    7
  778.     jr    nz,prtab    ; Continue tabulation
  779.     jr    prl1        ; Continue processing
  780. ;
  781. ;  Exit with Zero Flag Set if Done
  782. ;
  783. prexit:
  784.     xor    a        ; Set zero flag
  785.     ret
  786. ;
  787. ;  Carriage Return -- Reset Character Count and Continue
  788. ;
  789. prcr:
  790.     call    prout        ; Send CR to printer
  791.     ld    c,0        ; Reset char count
  792.     jr    prl1        ; Continue processing
  793. ;
  794. ;  Form Feed -- Advance to Top of Next Page
  795. ;
  796. prff:
  797.     call    page        ; Page eject with heading
  798.     ld    c,0        ; Reset char count
  799.     jr    prl1        ; Continue processing
  800. ;
  801. ;  Line Feed -- End of Routine
  802. ;
  803. prldn:
  804.     call    prout        ; Echo LF to printer
  805.     ld    (nxtln),hl    ; Set ptr to first char of next line
  806.     ld    a,0ffh        ; Set not done
  807.     or    a        ; Set flags
  808.     ret
  809. ;
  810. ;  Backspace on Printer
  811. ;
  812. prbs:
  813.     ld    a,c        ; Check for beginning of line
  814.     or    a
  815.     jr    z,prl1        ; Continue if at BOL
  816.     ld    a,ctrlh        ; Backspace
  817.     call    prout
  818.     dec    c        ; Back up char position
  819.     jr    prl1        ; Continue
  820. ;
  821. ;  Ring Bell on Printer
  822. ;
  823. prbell:
  824.     call    prout        ; Ring the bell
  825.     jr    prl1        ; Continue without advancing char position
  826. ;
  827. ;  Test for End of Line and Process if so
  828. ;
  829. eoltest:
  830.     ld    a,(cwidth)    ; Get line width
  831.     sub    4        ; 4 chars less for continuation mark
  832.     ld    b,a        ; Result in B
  833.     ld    a,(lnumfl)    ; Line numbering (lines are 7 chars shorter if so)
  834.     or    a        ; 0=no
  835.     jr    z,eolt1
  836.     ld    a,b        ; Reduce by 7 for line numbers
  837.     sub    7
  838.     ld    b,a
  839. eolt1:
  840.     ld    a,b        ; Get line width
  841.     cp    c        ; There?
  842.     ret    nz        ; Continue if not
  843.     ld    a,(hl)        ; Get next char
  844.     cp    cr        ; New line next?
  845.     ret    z        ; Continue if so
  846.     cp    ctrlh        ; Backspace next?
  847.     ret    z        ; Continue if so
  848.     push    hl
  849.     ld    b,3        ; See if a new line in next 3 chars
  850. eolt2:
  851.     inc    hl
  852.     ld    a,(hl)        ; Look for CR
  853.     cp    cr
  854.     jr    z,eolt3
  855.     djnz    eolt2
  856.     jr    eolt4
  857. eolt3:
  858.     pop    hl        ; Restore ptr
  859.     ret
  860. eolt4:
  861.     pop    hl        ; Restore ptr
  862.     ld    a,' '        ; Print continuation chars
  863.     call    prout
  864.     ld    a,'<'
  865.     call    prout
  866.     ld    a,'<'
  867.     call    prout
  868.     ld    a,cr        ; New line
  869.     call    prout
  870.     ld    a,lf
  871.     call    prout
  872.     ld    c,0        ; Reset char position
  873.     ld    a,(skipfl)    ; Skipping?
  874.     or    a        ; 0=no
  875.     ret    nz
  876.     ld    a,(lnumfl)    ; Printing line numbers?
  877.     or    a        ; 0=no
  878.     ret    z
  879.     call    eprint
  880.     db    '     : ',0
  881.     ret
  882. ;
  883. ;  Output a character to the console
  884. ;    A = Character
  885. ;
  886. prout:
  887.     ld    b,a        ; Char in B
  888.     call    cst        ; Check for abort
  889.     jr    nz,prout1
  890.     call    ctrlin        ; Get control input
  891. prout1:
  892.     ld    a,(skipfl)    ; Skipping?
  893.     or    a        ; Set flags (Z=no skip=print char)
  894.     ld    a,b        ; Restore char
  895.     call    z,ctrlout    ; Send character to printer
  896.     cp    lf        ; Special tests if it is a line feed
  897.     ret    nz        ; Done if non-LF char
  898.     ld    a,(lcount)    ; Decrement line counter
  899.     dec    a
  900.     ld    (lcount),a
  901.     ret    nz
  902. ;
  903. ;  Paging Required
  904. ;    Skip to top of next page; reset LCOUNT (Lines Left on Page Count);
  905. ;    increment PNUM (Screen Number); test for skip stop; print header
  906. ;
  907. prout0:
  908.     ld    a,(ctpp)    ; Get number of text lines per page
  909.     ld    (lcount),a    ; Set as new line count
  910.     push    hl        ; Save ptr
  911.     ld    hl,(pnum)    ; Increment page number
  912.     inc    hl
  913.     ld    (pnum),hl
  914.     ld    a,(cspp)    ; Number of lines to skip
  915.     call    lineskp        ; Skip lines
  916.     pop    hl        ; Restore ptr
  917.     call    prfoot        ; Print 1-line footer
  918.     ld    a,(hl)        ; Check next char
  919.     cp    ctrlz        ; EOF?
  920.     jp    z,fctlnxt    ; Skip to next file
  921.     ld    a,(skipfl)    ; Skipping?
  922.     or    a        ; 0=no
  923.     push    hl
  924.     call    nz,skiptst    ; Affects HL
  925.     pop    hl
  926.     ret
  927. ;
  928. ;  Skip out rest of page
  929. ;    Form Feed Function
  930. ;
  931. page:
  932.     ld    a,(lcount)    ; Get count of remaining lines
  933.     call    lineskp        ; Skip lines
  934.     jr    prout0        ; Process top of new page
  935. ;
  936. ;  Skip out lines on page
  937. ;
  938. lineskp:
  939.     ld    b,a        ; Line count in B
  940.     or    a        ; Any?
  941.     ret    z
  942.     ld    a,(skipfl)    ; Skipping?
  943.     or    a
  944.     ret    nz
  945.     ld    a,(pagefl)    ; Paging?
  946.     or    a
  947.     ret    z
  948. lines1:
  949.     ld    a,cr        ; Output new line to printer
  950.     call    cout
  951.     ld    a,lf
  952.     call    cout
  953.     djnz    lines1        ; Count down
  954.     ret
  955. ;
  956. ;  Control Input
  957. ;    CTRLIN -- Main Routine Entry Point; Implements Dynamic Commands,
  958. ;        including P, 0-9, ^S, ^X, and ^C
  959. ;    CTRLCS -- ^S Reentry Point; Implements all Dyanamic Commands except ^S
  960. ;
  961. ctrlcs:
  962.     call    cin        ; Get input
  963.     jr    ctrlns
  964. ctrlin:
  965.     call    cin        ; Get input
  966.     cp    ctrls        ; Pause?
  967.     jr    z,ctrlcs
  968. ctrlns:
  969.     call    caps        ; Capitalize
  970.     cp    ctrlc        ; Abort?
  971.     jp    z,abort
  972.     cp    ctrlx        ; Skip to next
  973.     jp    z,fctlnxt
  974.     cp    'P'        ; Page now?
  975.     jr    z,ctrlip
  976.     cp    '0'        ; Delay?
  977.     ret    c
  978.     cp    '9'+1
  979.     ret    nc
  980.     sub    '0'        ; Convert to binary
  981.     ld    (delay),a    ; Set delay count
  982.     ret
  983. ctrlip:
  984.     ld    a,(pagefl)    ; Toggle paging
  985.     cpl
  986.     ld    (pagefl),a
  987.     ret
  988. ;
  989. ;  Control Output
  990. ;
  991. ctrlout:
  992.     push    af        ; Save char
  993.     call    cout        ; Output char
  994.     ld    a,(delay)    ; Pause?
  995.     or    a        ; Any delay?
  996.     jr    z,ctrloz
  997.     push    hl        ; Delay
  998.     push    bc
  999.     ld    b,a        ; Delay count
  1000. del1:
  1001.     call    getspeed
  1002.     ld    hl,0
  1003.     push    de
  1004.     ld    de,500/4    ; Delay constant
  1005. del1a:    add    hl,de
  1006.     dec    a
  1007.     jr    nz,del1a
  1008.     pop    de
  1009. del2:
  1010.     ex    (sp),hl        ; Long NOP
  1011.     ex    (sp),hl
  1012.     dec    hl        ; Count down
  1013.     ld    a,h        ; Done?
  1014.     or    l
  1015.     jr    nz,del2
  1016.     djnz    del1        ; Count down
  1017.     pop    bc        ; Restore regs
  1018.     pop    hl
  1019. ctrloz:
  1020.     pop    af        ; Restore A
  1021.     ret
  1022. ;
  1023. ;  Print Line Number (optional)
  1024. ;
  1025. prlnum:
  1026.     ld    a,(skipfl)    ; Skipping?
  1027.     or    a        ; 0=no
  1028.     ret    nz
  1029.     ld    a,(lnumfl)    ; Get flag
  1030.     or    a        ; 0=don't number lines
  1031.     ret    z
  1032.     push    hl        ; Save ptr
  1033.     ld    hl,(lnum)    ; Get line number
  1034.     call    phldc        ; Print line number
  1035.     call    eprint        ; Print separator
  1036.     db    ': ',0
  1037.     pop    hl        ; Restore ptr
  1038.     ret
  1039. ;
  1040. ;  Print 1-line footer
  1041. ;
  1042. prfoot:
  1043.     ld    a,(skipfl)    ; Skipping?
  1044.     or    a        ; 0=no
  1045.     ret    nz
  1046.     ld    a,(pagefl)    ; Paging?
  1047.     or    a
  1048.     ret    z
  1049.     push    hl        ; Save ptr
  1050.     call    prpnum        ; Print page heading and number
  1051.     call    prdash        ; Print dash
  1052.     ld    hl,tfcb        ; Pt to file FCB
  1053.     call    prfn        ; Print file name
  1054.     pop    hl        ; Restore ptr
  1055.     call    eprint
  1056.     db    ' -- Strike Any Key ',0
  1057.     call    ctrlin        ; Get control response
  1058.     jp    crlf        ; New line
  1059. ;
  1060. ;  Test for completion of skipping
  1061. ;
  1062. skiptst:
  1063.     ld    hl,(pnum)    ; Get page number
  1064.     inc    hl        ; Increment for test
  1065.     ex    de,hl        ; In DE
  1066.     ld    hl,(skipnum)    ; Get page to skip to
  1067.     ld    a,h        ; Compare them
  1068.     cp    d
  1069.     ret    nz
  1070.     ld    a,l
  1071.     cp    e
  1072.     ret    nz
  1073.     xor    a        ; A=0 to stop skipping
  1074.     ld    (skipfl),a    ; Set flag
  1075.     ret
  1076. ;
  1077. ;  Print Page Number
  1078. ;
  1079. prpnum:
  1080.     call    eprint        ; Print header
  1081.     db    'Screen ',0
  1082.     ld    hl,(pnum)    ; Print current page number
  1083.     jp    phldc        ; Print as decimal, return to caller
  1084. ;
  1085. ;  Print Separator
  1086. ;
  1087. prdash:
  1088.     call    eprint
  1089.     db    ' -- ',0
  1090.     ret
  1091. ;
  1092. ;  UTILITIES
  1093. ;    SBLANK    -- SKIP BLANKS PTED TO BY HL UNTIL NON-BLANK ENCOUNTERED; HL
  1094. ;    SNBLANK -- SKIP NON-BLANKS PTED TO BY HL UNTIL BLANK OR EOL; HL
  1095. ;    PRFN    -- PRINT FILE NAME PTED TO BY HL; AFFECT NOTHING
  1096. ;
  1097.  
  1098. ;
  1099. ;  SKIP UNTIL NON-BLANK
  1100. ;
  1101. sblank:
  1102.     ld    a,(hl)        ; LOOK FOR BLANK
  1103.     inc    hl        ; PT TO NEXT
  1104.     cp    ' '        ; BLANK?
  1105.     jr    z,sblank
  1106.     dec    hl        ; BACK UP
  1107.     ret
  1108.  
  1109. ;
  1110. ;  SKIP UNTIL BLANK OR EOL
  1111. ;
  1112. snblank:
  1113.     ld    a,(hl)        ; GET CHAR
  1114.     inc    hl        ; PT TO NEXT
  1115.     cp    ' '        ; BLANK?
  1116.     jr    z,snb1
  1117.     or    a        ; EOL?
  1118.     jr    nz,snblank
  1119. snb1:
  1120.     dec    hl        ; BACK UP
  1121.     ret
  1122.  
  1123. ;
  1124. ;  PRINT FILE NAME PTED TO BY HL
  1125. ;    OUTPUT TO CON:
  1126. ;
  1127. prfn:
  1128.     push    hl        ; SAVE REGS
  1129.     push    bc
  1130.     call    retud        ; GET CURRENT USER/DISK
  1131.     ld    a,b        ; PRINT DISK
  1132.     add    a,'A'        ; LETTER
  1133.     call    cout
  1134.     ld    a,c        ; PRINT USER
  1135.     call    padc
  1136.     call    eprint
  1137.     db    ': ',0
  1138.     inc    hl        ; PT TO FILE NAME
  1139.     ld    b,8        ; PRINT NAME
  1140.     call    prnt
  1141.     ld    a,'.'        ; DECIMAL
  1142.     call    cout
  1143.     ld    b,3        ; PRINT TYPE
  1144.     call    prnt
  1145.     pop    bc        ; GET REGS
  1146.     pop    hl
  1147.     ret
  1148.  
  1149. ;
  1150. ;  PRINT CHARS PTED TO BY HL FOR B BYTES
  1151. ;    OUTPUT TO CON:
  1152. ;
  1153. prnt:
  1154.     ld    a,(hl)        ; GET CHAR
  1155.     call    cout
  1156.     inc    hl        ; PT TO NEXT
  1157.     djnz    prnt        ; COUNT DOWN
  1158.     ret
  1159.  
  1160. ; Print our name if ZCPR3 knows it, otherwise print "PAGE"
  1161. ;
  1162. comnam:    call    getefcb
  1163.     jr    z,noefcb
  1164.     ld    b,8
  1165. cmnmlp:    inc    hl
  1166.     ld    a,(hl)
  1167.     and    7fh
  1168.     cp    ' '
  1169.     call    nz,cout
  1170.     djnz    cmnmlp
  1171.     ret
  1172. ;
  1173. noefcb:    call    eprint
  1174.     db    'PAGE',0
  1175.     ret
  1176.  
  1177. ;
  1178. ;  BUFFERS
  1179. ;
  1180.     dseg
  1181. cwidth:
  1182.     ds    1        ; WIDTH OF SCREEN
  1183. ctpp:
  1184.     ds    1        ; LINES OF TEXT PER SCREEN
  1185. skipnum:
  1186.     ds    2        ; PAGE NUMBER TO SKIP TO
  1187. lnum:
  1188.     ds    2        ; CURRENT LINE NUMBER
  1189. pnum:
  1190.     ds    2        ; CURRENT PAGE NUMBER
  1191. cmdlne:
  1192.     ds    2        ; PTR TO COMMAND LINE STRING
  1193. dirbuf:
  1194.     ds    2        ; PTR TO DIRECTORY BUFFER
  1195. nextch:
  1196.     ds    2        ; PTR TO NEXT CHAR IN MULTIFILE COMMAND LINE
  1197. filecnt:
  1198.     ds    2        ; COUNT OF NUMBER OF FILES RENAMED
  1199. scratch:
  1200.     ds    2        ; ADDRESS OF FIRST BYTE OF SCRATCH AREA
  1201. bcnt:
  1202.     ds    1        ; NUMBER OF PAGES IN SCRATCH AREA
  1203. ;
  1204. ;  PAGE Buffers
  1205. ;
  1206. tfcb:
  1207.     ds    36        ; FCB for current file
  1208. nxtblk:
  1209.     ds    2        ; Pointer to next block to load
  1210. nxtln:
  1211.     ds    2        ; Pointer to next line to read
  1212. lcount:
  1213.     ds    1        ; Count of text lines left on page
  1214. ;
  1215. ;  Stack
  1216. ;
  1217. stack:
  1218.     ds    2        ; OLD STACK PTR
  1219.  
  1220.     end
  1221.