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