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 / BEEHIVE / UTILITYS / RPEEP12.ARC / RPEEP.LIB next >
Text File  |  1991-08-11  |  20KB  |  988 lines

  1. ; RPEEP.LIB - Resident PEEP
  2. ;=============================================================================
  3. ;
  4. ;        P E E P    C O M M A N D
  5. ;
  6. ;============================================================================
  7.  
  8. ; +++++++    NOT an official RCP segment.
  9. ;        This is a hacker's module intended to work with Z33RCP.
  10.  
  11. ; Command:    PEEP
  12. ; Function:    Text File Browser and Lister
  13. ; Version:    1.2   4 Nov 1987
  14. ; Author:     Rob Friefeld, 4607 Colorado St., Long Beach, CA 213-434-7338
  15. ; Comments:    The CRT protocol has to be hard coded into this module.
  16. ;          If the TCAP were used, PEEP would not be practical.
  17. ;          See below for installation
  18. ;    Version 1.2:
  19. ;        - LF's stripped from file
  20. ;        - Bug fix, now can read file which doesn't end with 1Ah (EOF)
  21. ;        - Adds about 1100 bytes + printer init string to RCP
  22. ;          Assembly without printer code saves about 180 bytes
  23. ;----------------------------------------------------------------------------
  24. ; USAGE:    Hands rest on the home row of keys.  Left hand moves ahead,
  25. ;        right hand moves back through file. 
  26. ;                                                            ---
  27. ;                                              Go To Marker | 0 |
  28. ;                                                            ---
  29. ;                      Read More                     Init    Set    Print
  30. ;                  (if memory full)                 Printer Marker (from mark)
  31. ;                         ---                         ---    ---    ---
  32. ;                        | R |                       | I |  | O |  | P |
  33. ;                         ---                         ---    ---    ---
  34. ;    ---    ---    ---    ---    ---    ---    ---    ---    ---    ---
  35. ;   | A |  | S |  | D |  | F |  | G |  | H |  | J |  | K |  | L |  | ; |
  36. ;    ---    ---    ---    ---    ---    ---    ---    ---    ---    ---
  37. ;    End   Scan   Next   Next    Find   Rpt    Prev   Prev  R/Scan  Top
  38. ;  Screen         Line  Screen         Find   Screen  Line         Screen
  39. ;
  40. ;
  41. ;  X - Exit   <sp> - Hop 10 lines   <cr> - Next Screen (F)  </,?> - File Name
  42. ;----------------------------------------------------------------------------
  43.  
  44. ;
  45. ; PEEP EQUATES
  46. ;
  47.  
  48. ; GET WIDTH FROM ENV
  49. envwidth    equ    no    ; T = use ENV, F = use crtwid below
  50.  
  51. ; INCLUDE PRINTER CODE
  52. PEEP$LST    EQU    yes    ; Include printer related code
  53.  
  54. ;bell    equ    07h        ; If not already added to SYSDEF.LIB
  55.  
  56. ccpsz    equ    800h        ; Top mem assumes 800h CCP size
  57. textloc    equ    tpa        ; File will be read in to TPA
  58. crtrows    equ    24        ; 24 line screen
  59. scrlns    equ    crtrows-1    ; Need one line for prompts
  60. crtcols    equ    80
  61. crtwid    equ    crtcols-1    ; May be optionally taken from ENV
  62.  
  63. tabsize    equ    8        ; Tab expansion size
  64. scanspd    equ    2000h        ; Scroll rate - smaller number goes faster
  65. ovrlap    equ    1        ; Number of lines to overlap scroll (0 is OK)
  66.  
  67. ;
  68. ; STRING SEARCH BUFFER
  69. ; Set size of string to match buffer.
  70. ;     The TBUF at 80h is not used because it would prevent
  71. ;     doing a repeat FIND after reading in more of file.
  72.  
  73. findsz    equ    12        ; Size of FIND string buffer
  74.  
  75. ;
  76. ; PRINITER INITIALIZATION STRING
  77. ; If you wish to send an initialization string with the 'I' command, install
  78. ; it here.  First byte must be char count.
  79.      if    peep$lst
  80. init$str:
  81.     db    1    ; char count
  82.     db    cr
  83.      endif    ; peep$lst
  84.  
  85. ;
  86. ; CRT PROTOCOL INSTALLATION SECTION
  87. ;
  88. ; The defaults are standard for Televideo, Wyse, et al.
  89.  
  90.  
  91. ; CLEAR SCREEN, HOME CURSOR
  92. clr_scr        macro
  93.     db    1ah+80h        ; Not used if CLSON is true.
  94.         endm
  95.  
  96. ; CLEAR TO END OF LINE
  97. cl_to_eol    macro
  98.     db    esc,'T'+80h
  99.         endm
  100.  
  101. ; HOME CURSOR, DO NOT CLEAR SCREEN
  102. hom_crs        macro
  103.     db    1eh+80h
  104.         endm
  105.  
  106. ; INSERT LINE
  107. ins_line    macro
  108.     db    esc,'E'+80h
  109.         endm
  110.  
  111. ; RETURN CURSOR TO START OF BOTTOM LINE OF CRT
  112. ret_crs        macro
  113.     db    esc,'=',scrlns+32,0+32+80h
  114.         endm
  115.  
  116. ; STANDOUT MODE.  MUST NOT TAKE SCREEN SPACE.  USE 0 IF NOT AVAILABLE.
  117. dim_on        macro
  118.     db    esc,')'+80h
  119.         endm
  120.  
  121. ; STANDEND
  122. dim_off        macro
  123.     db    esc,'('+80h
  124.         endm
  125.  
  126. ;
  127. ;  END OF CRT PROTOCOL INSTALLATION SECTION
  128. ;
  129.  
  130.  
  131. ;
  132. ; CRT ROUTINES USING ABOVE MACROS
  133. ;
  134.  
  135. ; INSERT BLANK LINE AT TOP OF SCREEN
  136. inslin:    call    homcrs
  137.     call    print
  138.     ins_line
  139.  
  140. ; PRINT CR AND CLREOL
  141. cr$clr:
  142. clreol:    call    print
  143.     db    cr
  144.     cl_to_eol
  145.     ret
  146.  
  147. ; HOME CURSOR
  148. homcrs:    call    print
  149.     hom_crs
  150.     ret
  151.  
  152.  
  153. ; RETURN CURSOR TO LAST LINE OF SCREEN
  154. retcrs:    call    print
  155.     ret_crs
  156.     ret
  157.  
  158. ; CLEAR SCREEN
  159.      if    [ not CLSON ]
  160. cls:    call    print
  161.     clr_scr
  162.     ret
  163.      endif
  164.  
  165. ; START STANDOUT MODE
  166. stndout:
  167.     call    print
  168.     dim_on
  169.     ret
  170.  
  171. ; END STANDOUT MODE
  172. stndend:
  173.     call    print
  174.     dim_off
  175.     ret
  176.  
  177. ;
  178. ; SWITCHING CONOUT
  179. ;
  180.      if    peep$lst
  181. plcon:    ld    a,listf        ; Switch to lst: output
  182. plcon1:    ld    (conout+8),a    ; Poke list byte at  ld  c,bdosf
  183.     ret
  184.  
  185. plcoff:    ld    a,wrconf    ; Switch to con: output
  186.     jr    plcon1
  187.      endif    ; peep$lst
  188.  
  189. ;
  190. ; SLOW DOWN SCAN FUNCTIONS
  191. ;
  192. wait:    ld    hl,scanspd
  193. wait0:    dec    hl        ; Down count to 0
  194.     ld    a,h
  195.     or    l
  196.     ret    z
  197.     jr    wait0
  198.  
  199. ;
  200. ;  UPCASE CHAR IN A
  201. ;
  202. mkupper:
  203.     cp    'a'
  204.     ret    c
  205.     cp    'z'+1
  206.     ret    nc
  207.     and    5fh
  208.     ret
  209.  
  210. ;
  211. ; MAIN PROGRAM
  212. ;
  213.  
  214. peep:    call    retsave        ; Save zcpr return
  215.  
  216. ; LOAD THE SCREEN WIDTH
  217.      if    envwidth
  218.     ld    hl,z3env+2fh    ; Offset to CRT in use
  219.     xor    a
  220.     cp    (hl)
  221.     jr    z,pinit1    ; Using CRT 0
  222.     inc    hl
  223.     inc    hl
  224.     inc    hl
  225. pinit1:    inc    hl
  226.     inc    hl
  227. pinit2:    ld    a,(hl)
  228.     dec    a
  229.     ld    (width),a
  230.      endif    ;envwidth
  231.  
  232. ; READ IN THE FILE
  233.  
  234.     call    getfil        ; Read the file into memory
  235.     call    cls
  236.  
  237. ; RESTART ENTRY FOR READING IN MORE TEXT ON "MEMORY FULL" MESSAGE
  238.  
  239. resrt:    ld    hl,textloc    ; Set Start Pointer to beginning of file
  240.     ld    (srtptr),hl
  241.     ld    (mrkptr),hl    ; Set place marker to start of text
  242.  
  243.  
  244. ;
  245. ; PRINT ONE SCREEN OF TEXT
  246. ;
  247. prnscr:    call    homcrs        ; Move cursor
  248.     call    geteos        ; Set end of screen pointer
  249.     ex    de,hl        ; Compute position relative to last screen
  250.     ld    hl,(srtptr)
  251.     push    hl        ; If near end then print entire last screen
  252.     xor    a
  253.     sbc    hl,de
  254.     pop    hl
  255.     jr    z,prn1        ; We are at or before last screen so go ahead
  256.     jp    nc,last        ; We are past last screen so back up
  257.  
  258. prn1:    ld    b,scrlns    ; Line count in B
  259. prnlp1:    call    clreol
  260.     call    prnline
  261.     djnz    prnlp1        ; Print SCRLNS lines
  262.     ld    (nxtptr),hl    ; And set Next Pointer
  263.     call    retcrs        ; Cursor to prompt line
  264.  
  265. ;
  266. ; COMMAND INPUT ROUTINE
  267. ;
  268. command:
  269.     call    getchr        ; Get command
  270.     call    case        ; Scan list of commands
  271.  
  272. ;
  273. ; COMMAND LIST: CHAR TO MATCH FOLLOWED BY ADDRESS
  274. ;
  275.     db    'A'        ; Last screen of file
  276.     dw    last
  277.     db    'D'        ; Forward a line
  278.     dw    down
  279.     db    'F'        ; Next screen
  280.     dw    next
  281.     db    'G'        ; Find string
  282.     dw    find
  283.     db    'H'        ; Find string again
  284.     dw    find0
  285.      if    peep$lst
  286.     db    'I'        ; Init printer
  287.     dw    init$prt
  288.      endif    ; peep$lst
  289.     db    'J'        ; Previous screen
  290.     dw    prev
  291.     db    'K'        ; Back a line
  292.     dw    up
  293.     db    'L'        ; Scan backward
  294.     dw    back
  295.     db    'O'        ; Set place marker
  296.     dw    mark
  297.      if    peep$lst
  298.     db    'P'        ; Print from marker
  299.     dw    list
  300.      endif
  301.     db    'R'        ; Read in more text
  302.     dw    read
  303.     db    'S'        ; Scan forward
  304.     dw    scan
  305.     db    'X'        ; Exit to CPR
  306.     dw    exit
  307.     db    ';'        ; Top of file
  308.     dw    top
  309.     db    '0'        ; Go to marker
  310.     dw    gomark0
  311.     db    20h        ; <sp> jump ahead 10 lines
  312.     dw    hop
  313.     db    cr        ; <cr> next screen
  314.     dw    next
  315.     db    '/'
  316.     dw    what        ; Show filename
  317.     db    '?'
  318.     dw    what
  319.     db    0        ; table delimiter
  320.  
  321.     jr    command        ; Loop back on invalid input
  322.  
  323. ;
  324. ; CASE - JUMP TABLE SCANNER
  325. ; FORMAT:  CALL CASE    ;CALL WITH VALUE TO MATCH IN A
  326. ;       DB    VAL1    ;FIRST VAL TO MATCH
  327. ;       DW    ADDR1    ;JUMP ADDRESS
  328. ;       ...
  329. ;       DB    0    ;END TABLE
  330. ;       ELSE NEXT INSTUCTION EXECUTES IF NO MATCH
  331. ;
  332. case:
  333.     ex    (sp),hl        ;hl -> next addr after call
  334.     ex    af,af'        ;save char
  335.     xor    a
  336. case1:
  337.     ex    af,af'        ;restore char
  338.     cp    (hl)        ;match?
  339.     inc    hl
  340.     jr    z,case0        ;if match, jump
  341.     inc    hl        ;point to next val
  342.     inc    hl
  343.     ex    af,af'        ;check for list terminator
  344.     cp    (hl)
  345.     jr    nz,case1    ;keep looking
  346.  
  347.     inc    hl        ;execute next instruction
  348. casex:    ex    (sp),hl
  349.     ret
  350.  
  351. case0:    ld    e,(hl)        ;load address
  352.     inc    hl
  353.     ld    d,(hl)
  354.     ex    de,hl
  355.     jr    casex
  356. ;
  357. ;  PRINT ONE LINE OF TEXT
  358. ;  HL -> first char on entry, next char on exit
  359. ;
  360. prnline:
  361.     push    bc        ; Preserve possible loop counter on entry
  362.     xor    a
  363.     ld    c,a        ; Char counter for CRT width and tabs
  364.     ld    d,a        ; OVFL flag
  365. prnl1:
  366.     ld    a,(hl)        ; Get char
  367.     cp    eof        ; At end?
  368.     jr    z,prnl2        ; Can occur on text smaller than one screen
  369.     inc    hl        ; Bump pointer
  370.     cp    cr        ; Are we at end of line?
  371.     jr    z,prnl2
  372.     call    prnl3        ; Print the character
  373.     jr    prnl1
  374. prnl2:    pop    bc
  375.     call    print
  376.     db    cr,lf+80h
  377.     ret            ; Exit routine
  378.  
  379. ; PRINT THE CHAR IF THE LINE IS NOT FULL
  380.  
  381. prnl3:    cp    tab
  382.     jr    nz,prnl5    ; No tab
  383.  
  384. ; TAB EXPANSION
  385.  
  386. prnl4:    ld    a,c        ; Compute char count MOD tabsize
  387.     sub    tabsize
  388.     jr    nc,$-2
  389.     neg            ; Spaces to next tab in A
  390.     ld    b,a        ; Use as loop counter
  391.     ld    a,' '        ; Print space
  392. prnl41:    call    prnl5        ; Send it out, if room, and update char count
  393.     djnz    prnl41
  394.     ret
  395.  
  396. prnl5:
  397.     ld    e,a        ; Save char
  398.     ld    a,d        ; OVFL flag
  399.     or    a
  400.     ret    nz        ; Already OVFL
  401.     inc    c        ; Bump char counter
  402.  
  403.  
  404. ; DISPLAY CONTROL CHARACTERS AS ^n
  405. ; Char in E
  406. outchr:
  407.     ld    a,7fh        ; Don't print DEL
  408.     cp    e
  409.     ret    z
  410.  
  411.      if    peep$lst
  412.     ld    a,(conout+8)    ; Listing?
  413.     cp    wrconf
  414.     jr    z,outc1        ; No, check line width before printing
  415.     ld    a,e        ; Restore char
  416.     cp    20h
  417.     jp    nc,conout    ; Not a control
  418.     call    print
  419.     db    '^'+80h
  420.     ld    a,e
  421.     add    40h        ; Make char printable
  422.     jp    conout    
  423.      endif    ;peep$lst
  424.  
  425. outc1:
  426.     ld    a,(width)    ; OVFL?
  427.     cp    c
  428.     jr    nc,outc2    ; No
  429. outc01:
  430.     dec    d        ; Now have OVFL, make d NZ
  431.     call    stndout
  432.     call    print        ; Display OVFL indicator
  433.     db    '>',bs+80h
  434.     jp    stndend        ; And quit
  435.  
  436. outc2:
  437.     ld    a,e        ; Restore char
  438.     cp    20h
  439.     jp    nc,conout    ; Not a control
  440.  
  441.     call    stndout
  442.     call    print
  443.     db    '^'+80h
  444.  
  445.     inc    c        ; Bump tab expansion count for '^' char
  446.     ld    a,(width)    ; CRT, is there still room?
  447.     cp    c
  448.     jr    c,outc01    ; OVFL
  449.     ld    a,e        ; Restore char
  450.     add    40h
  451.     call    conout
  452. outx:    jp    stndend
  453.  
  454.  
  455. ;
  456. ; PRINT NEXT SCREEN
  457. ;
  458. next:    ld    hl,(nxtptr)
  459.     ld    a,eof        ; Is there a next screen?
  460.     cp    (hl)
  461.     jr    z,hop0        ; No
  462.     ld    a,ovrlap
  463.     or    a
  464.     jr    z,next1
  465.     ld    b,a        ; Back up scroll overlap lines
  466.     call    pvline
  467.     djnz    $-3
  468. next1:    ld    (srtptr),hl    ; Next screen is new start pointer
  469.     jr    top0        ; Print the screen
  470.  
  471. ;
  472. ; PRINT FIRST SCREEN
  473. ;
  474.  
  475. top:    ld    hl,textloc    ; Start of text
  476.     ld    (srtptr),hl    ; To start pointer
  477. top0:    jp    prnscr
  478.  
  479. ;
  480. ; PRINT LAST SCREEN
  481. ;
  482. last:    call    geteos        ; Top of last screen
  483.     ld    (srtptr),hl    ; Start there
  484.     jr    top0        ; Print the screen
  485.  
  486. ;
  487. ; PRINT NEXT LINE
  488. ;
  489. down:    ld    b,1        ; Loop counter = 1 line
  490.     jr    hop1        ; Print the line
  491.  
  492. ;
  493. ; HOP FORWARD 10 LINES
  494. ;
  495. hop:    ld    b,10        ; Loop counter = 10 lines
  496. hop1:    push    bc        ; Save it
  497.     call    dnline        ; Print next line
  498.     pop    bc
  499.     djnz    hop1
  500. hop0:    jp    command
  501.  
  502. ;
  503. ; SCROLL CONTINUOUSLY AHEAD UNTIL A KEY PRESSED
  504. ;
  505. scan:    call    dnline        ; Print next line
  506.     jr    z,hop0        ; Routine returns 0 on EOF
  507.     call    scstop        ; Check for key press
  508.     jr    scan
  509.  
  510. ;
  511. ;  WAIT, THEN CHECK FOR BREAK
  512. ;
  513. scstop:
  514.     call    wait        ; Pause a few msec
  515.     ld    c,CONSTF
  516.     call    bdos
  517.     or    a
  518.     ret    z        ; No character, continue
  519.     pop    af        ; Dispose of return address
  520.     call    getchr        ; Erase screen echo and dispose of char
  521.     jr    hop0        ; Back to command list
  522.  
  523. ;
  524. ; PRINT NEXT LINE
  525. ;
  526. dnline:    ld    hl,(nxtptr)    ; Look at start of next line
  527.     ld    a,eof        ; Is it EOF?
  528.     cp    (hl)
  529.     ret    z        ; There is no next line
  530.     call    prnline        ; Print the line
  531.     ld    (nxtptr),hl    ; Advance Next Pointer
  532.     ld    hl,(srtptr)    ; Advance Start Pointer
  533.     call    nxline        ; Find start of next line
  534.     ld    (srtptr),hl    
  535.     xor    a        ; A NZ flag on successful return
  536.     dec    a
  537.     ret
  538.  
  539. ;
  540. ;  SEARCH FOR NEXT LINE OF TEXT
  541. ;  HL -> starting point
  542. ;
  543. nxline:    ld    a,(hl)        ; Look at char
  544.     cp    eof
  545.     ret    z        ; No more text
  546.     inc    hl        ; Bump pointer
  547.     cp    cr
  548.     jr    nz,nxline
  549.     ret            ; Returns HL at character after LF
  550.  
  551. ;
  552. ; PRINT PREVIOUS SCREEN
  553. ;
  554. prev:    ld    hl,(srtptr)    ; HL-> char at top of screen
  555.     ld    a,scrlns
  556.     sub    ovrlap
  557.     ld    b,a        ; Loop counter SCRLNS lines
  558. prev0:    call    pvline        ; Find start of previous line
  559.     djnz    prev0
  560.     ld    (srtptr),hl    ; Set Start Pointer
  561.     jp    prnscr        ; Print the screen
  562.  
  563. ;
  564. ;  SEARCH FOR START OF PREVIOUS LINE OF TEXT
  565. ;
  566. pvline:    push    bc        ; Save possible loop counter on entry
  567.     ld    de,textloc    ; Are we already at beginning of file?
  568.     ld    b,2
  569. prvlp:    dec    hl
  570.     xor    a
  571.     push    hl
  572.     sbc    hl,de
  573.     pop    hl
  574.     jr    c,prv0        ; Yes, so we are done
  575.     ld    a,(hl)        ; Look for last cr
  576.     cp    cr
  577.     jr    nz,prvlp    ; Haven't found cr yet
  578.     djnz    prvlp
  579. prv0:    inc    hl
  580.     pop    bc
  581.     ret
  582.  
  583. ;
  584. ;  PRINT PREVIOUS LINE
  585. ;
  586. up:    call    upline
  587. up0:    jp    command
  588.  
  589. ;
  590. ; SCAN BACKWARDS UNTIL KEY PRESS
  591. ;
  592. back:    call    upline        ; Move up a line
  593.     jr    z,up0        ; Returns Z if no more lines
  594.     call    scstop        ; Check for break
  595.     jr    back
  596.  
  597. ;
  598. ; MOVE DISPLAY UP A LINE
  599. ;
  600. upline:    ld    de,textloc    ; Are we already at start of text?
  601.     ld    hl,(srtptr)
  602.     xor    a
  603.     sbc    hl,de
  604.     ret    z        ; Yes, quit and return Z
  605.  
  606.     call    inslin        ; Home cursor and insert a blank line
  607.     ld    hl,(srtptr)    ; Back up a line
  608.     call    pvline
  609.     ld    (srtptr),hl    ; Set pointer
  610.     call    prnline        ; Print the line
  611.     ld    hl,(nxtptr)    ; Set Next Pointer
  612.     call    pvline
  613.     ld    (nxtptr),hl
  614.     call    retcrs        ; Return cursor to bottom of screen
  615.     call    cr$clr        ; Erase dead line
  616.     xor    a        ; Return NZ
  617.     dec    a
  618.     ret
  619.  
  620. ;
  621. ; FIND A STRING
  622. ;
  623. find:
  624.     call    STNDOUT
  625.     call    print        ; Find string in following pages
  626.     db    'Find ->',' '+80h
  627.     ld    de,fbuf        ; Read string to find
  628.     ld    c,RDBUFF
  629.     call    bdos
  630.     call    clrend
  631.  
  632. find0:    ld    a,(fbuf+1)    ; String length
  633.     or    a
  634.     jp    z,command    ; 0 length string ... abort
  635.     ex    af,af'        ; Save it
  636.  
  637. ; START SEARCH AT NEXT LINE
  638.  
  639.     ld    hl,(srtptr)
  640.     call    nxline        ; HL now -> next line
  641. finlp0:
  642.     ld    de,fbuf+2    ; First char
  643. finlp1:
  644.     call    fmatch        ; Compare upcase of (hl) and (de)
  645.     inc    hl        ; Bump text pointer
  646.     jr    nz,finlp1    ; No match, keep moving through text
  647.  
  648. ; AT THIS POINT, FIRST CHAR IS MATCHED
  649.  
  650.     ex    af,af'        ; Recover string length
  651.     ld    b,a
  652.     ex    af,af'
  653.     dec    b        ; We have already found 1
  654.     jr    z,findex    ; Done if only 1 char to match
  655. finlp2:
  656.     inc    de
  657.     call    fmatch
  658.     jr    nz,finlp0    ; No match ... start looking again
  659.     inc    hl        ; So far, so good
  660.     djnz    finlp2        ; Match next chars
  661.  
  662.  
  663. ; THE STRING IS IN THE CURRENT LINE, MOVE IT TO TOP OF SCREEN
  664.  
  665. findex:    call    pvline        ; Find previous line
  666.     call    nxline        ; Go to beginning of this line
  667.     ld    (srtptr),hl
  668.     jp    prnscr        ; Show the screen
  669.  
  670. ; MATCH ROUTINE
  671.  
  672. fmatch:
  673.     ld    a,(hl)
  674.     cp    eof
  675.     jr    z,finot
  676.     call    mkupper
  677.     ld    c,a
  678.     ld    a,(de)
  679.     call    mkupper
  680.     cp    c
  681.     ret
  682.  
  683. ; NO LUCK ON FIND
  684.  
  685. finot:    pop    af        ; Lift stack
  686.     call    cr$clr        ; String not found - print message
  687.     call    stndout
  688.     call    print
  689.     db    '???',' '+80h
  690. finot0:    call    stndend
  691.     jp    command
  692.  
  693.  
  694. ;
  695. ;  SHOW FILE NAME COMMAND
  696. ;
  697. what:    call    stndout
  698.     ld    hl,fcb1+1
  699.     call    prfn        ; ROUTINE ELSEWHERE IN RCP
  700.     jr    finot0        ; Finish up display
  701.  
  702. ;
  703. ; SET PLACE MARKER
  704. ;
  705. mark:
  706.     ld    hl,(srtptr)    ; Top of screen pointer is marker pointer
  707.     ld    (mrkptr),hl
  708.     call    stndout
  709.     call    print
  710.     db    'Mark',bell+80h
  711.     jr    finot0        ; Finish up display
  712.  
  713.  
  714. ;
  715. ; GO TO MARKER
  716. ;
  717. gomark0:
  718.     ld    hl,(mrkptr)
  719.     ld    (srtptr),hl
  720.     jp    prnscr
  721.  
  722.  
  723. ;
  724. ;  LIST MARKED PORTION OF FILE
  725. ;
  726.      if    peep$lst
  727. list:
  728.     ld    hl,lstmsg
  729.     call    qprompt        ; Are we serious?  (And is printer on?)
  730.     jr    z,listx        ; Abort
  731.     call    stndout
  732.     call    print
  733.     db    'Printing',' '+80h
  734. ; Compute print block size
  735.  
  736.     ld    de,(mrkptr)    ; Beginning of block
  737.     ld    hl,(nxtptr)    ; End of block
  738.     xor    a
  739.     sbc    hl,de        ; Block size now in HL
  740.     jr    c,lsterr    ; If beginning at or after end then no go
  741.     jr    z,lsterr
  742.  
  743. ; Set up pointers
  744.  
  745.     ex    de,hl        ; Block size in DE, start in HL
  746.     push    de
  747.     pop    bc        ; Block size in BC
  748.     ld    de,0        ; Count # lines in DE
  749.     ld    a,cr
  750. list1:    cpir            ; Count line feeds
  751.     inc    de
  752.     jp    po,list2    ; Loop expired at last cr
  753.     jr    list1
  754.  
  755. list2:
  756.     call    plcon        ; Switch output to list
  757.     push    de
  758.     pop    bc        ; Count to BC
  759.     ld    hl,(mrkptr)    ; Source of block
  760.  
  761. list3:    call    break        ; Exit on ^C (routine in rcpsubs.lib)
  762.     call    prnline        ; Output switched to list:
  763.     dec    bc
  764.     ld    a,b
  765.     or    c
  766.     jr    nz,list3
  767.  
  768.     call    plcoff        ; Switch output to con:
  769.  
  770. lsterr:    call    print        ; Beep on marker error or finish print
  771.     db    bell+80h
  772.     call    clrend
  773. listx:    jp    command
  774.  
  775.  
  776.  
  777. lstmsg:    db    'Print from MAR','K'+80h
  778.  
  779. ;
  780. ;  SEND INIT STRING TO PRINTER
  781. ;
  782. init$prt:
  783.     ld    hl,initmsg
  784.     call    qprompt
  785.     jr    z,listx
  786.     call    plcon        ; Switch conout to list
  787.     ld    hl,init$str    ; Send string
  788.     ld    b,(hl)        ; Char count
  789. ip1:    inc    hl
  790.     ld    a,(hl)
  791.     call    conout
  792.     djnz    ip1
  793.     call    plcoff        ; Switch conout to con
  794.     jr    listx
  795.  
  796. initmsg:
  797.     db    'Init LST',':'+80h 
  798.  
  799.       endif    ; peep$lst
  800. ;
  801. ;  READ FILE INTO TPA UNTIL FULL OR EOF
  802. ;
  803. getfil:
  804.     
  805. ; SET UP TOP OF MEMORY POINTER
  806.  
  807.     ld    hl,(bdos+1)    ; BDOS location
  808.     ld    de,-ccpsz-88h    ; CCP size + offset + cr,eof + 1 record
  809.     add    hl,de
  810.     ld    (topmem),hl    ; Store as top of memory
  811.  
  812. ; REJECT BLANK FILE SPEC
  813.  
  814. getfil1:
  815.     call    filcheck
  816.  
  817.     CALL    LOGUSR        ; ROUTINE IS IN RCPSUBS.LIB
  818.  
  819. ; OPEN THE FILE
  820.     call    opensource
  821.  
  822. ; RESET EOF FLAG (EOF NOT ENCOUNTERED)
  823.     xor    a
  824.     ld    (eoflag),a
  825.  
  826. ; FILE READ LOOP
  827. ; File read into tbuf, MSB mask, lf strip, transfer to text buffer
  828.  
  829.     ld    de,textloc    ; Start of text pointer
  830. getlp1:
  831.     ld    hl,(topmem)    ; Check memory full
  832.     xor    a
  833.     sbc    hl,de
  834.     jr    c,toobig    ; Yes
  835.  
  836.     push    de
  837.     ld    de,fcb1        ; Read a record
  838.     ld    c,readf
  839.     call    bdos
  840.     pop    de
  841.     call    loadfil        ; Load it into text buffer
  842.     jr    z,getlp1    ; Keep reading, eof not encountered
  843.  
  844. geteof:    ld    (eoflag),a    ; Set EOF flag
  845.     ret
  846.  
  847. ; MOVE RECORD INTO TEXT BUFFER
  848. loadfil:
  849.     or    a        ; Enter with BDOS read return code
  850.     jr    nz,ldfil03    ; No more to read, but no EOF char
  851.     ld    hl,tbuf
  852.     ld    b,80h
  853. ldfil01:
  854.     ld    a,(hl)
  855.     inc    hl
  856.     and    7fh        ; Mask MSB
  857.     cp    lf
  858.     jr    z,ldfil02    ; Skip lf
  859.     cp    eof
  860.     jr    z,ldfil03    ; Done, set up EOF pointers
  861.     ld    (de),a
  862.     inc    de
  863. ldfil02:
  864.     djnz    ldfil01
  865.     xor    a        ; Z = not done
  866.     ret
  867.  
  868. ldfil03:
  869.     ex    de,hl
  870.     ld    (hl),cr        ; Add a cr to the end
  871.     inc    hl
  872.     ld    (hl),eof    ; Mark end with eof
  873.     ld    (eofptr),hl    ; Save location
  874.     or    -1        ; NZ = done
  875.     ret
  876.  
  877. ; FILE HAS FILLED AVAILABLE MEMORY, PRINT WARNING
  878.  
  879. toobig:
  880.     call    print
  881.     db    'Mem',bell+80h
  882.     call    getchr        ; Wait for key press
  883.     jr    ldfil03        ; Read no more
  884.  
  885.  
  886. ;
  887. ; READ MORE TEXT COMMAND
  888. ;
  889. read:    ld    a,(eoflag)    ; Has EOF been encountered?
  890.     or    a
  891.     jr    nz,rdprompt    ; If so, send message
  892.     ld    de,textloc    ; Else, preserve some text and read more
  893.     call    geteos
  894.     ld    a,eof
  895. rdlp1:    ldi            ; Move last page to beginning of buffer
  896.     cp    (hl)        ; Check for end of file marker
  897.     jr    nz,rdlp1    ; Loop until it is reached
  898.     dec    de        ; Back up over last CR
  899.     call    getlp1        ; Fill memory with more of file
  900.     jr    readx        ; Re-initialize pointers and start
  901.  
  902.  
  903. ; PROMPT IF NO MORE TO READ
  904.  
  905. rdmsg:    db    'Restar','t'+80h
  906. rdprompt:
  907.     ld    hl,rdmsg
  908.     call    qprompt
  909.     jp    z,command    ; No
  910.  
  911.  
  912. ; STARTING OVER, ZERO FCB POSITION POINTERS
  913.  
  914. read1:
  915.     CALL    INITFCB1    ; IN RCPSUBS.LIB
  916.     ld    a,(ppusr)    ; Restore user #
  917.     ld    (fcb1+13),a
  918.     call    getfil1        ; Read the file
  919. readx:    jp    resrt        ; Restart PEEP
  920.  
  921.  
  922. ; EXAMINE COMMAND LINE FOR FILE SPEC
  923.  
  924. filcheck:
  925.     ld    a,(fcb1+13)
  926.     ld    (ppusr),a
  927.     ld    hl,fcb1+1
  928.     ld    a,' '
  929.     cp    (hl)
  930. filcx:    ret    nz
  931.     call    prfnf        ; ROUNTINE IS ELSEWHERE IN RCP
  932.     jp    exit        ; NO FILE SPEC
  933.  
  934. ; OPEN SOURCE FILE
  935.  
  936. opensource:
  937.     ld    de,fcb1
  938.     ld    c,openf
  939.     call    bdos
  940.     inc    a
  941.     jr    filcx
  942.  
  943.  
  944. ; Enter with HL -> message.  Return Z if answer = N.
  945. qprompt:
  946.     call    stndout
  947.     call    printhl
  948.     call    print
  949.     db    '? (Y/n)',' '+80h
  950. getchr:
  951.     call    conin
  952.     cp    'N'
  953. clrend:
  954.     push    af
  955.     call    stndend
  956.     call    cr$clr
  957.     pop    af
  958.     ret
  959.  
  960. ; Get pointer to start of last screen in HL
  961. geteos:
  962.     ld    hl,(eofptr)    ; Set End of Screen Pointer to beginning
  963.     ld    b,scrlns    ;   of last screen
  964.     call    pvline        ; Back up one screen from end
  965.     djnz    $-3
  966.     ret
  967.  
  968. ;
  969. ; STORAGE
  970. ;
  971. fbuf:    db    findsz        ; Find string buffer
  972.     ds    1        ; Returned char count
  973.     ds    findsz        ; Buffer
  974.  
  975. width    db    crtwid        ; Useable screen width
  976. ppusr    ds    1        ; User number
  977. eoflag    ds    1        ; EOF encountered flag
  978. srtptr    ds    2        ; Start Pointer -> top of screen
  979. nxtptr    ds    2        ; Next Pointer -> next screen
  980. eofptr    ds    2        ; End of File Pointer -> end of text
  981. topmem    ds    2        ; Top of memory pointer
  982. mrkptr:    ds    2        ; Place marker
  983.  
  984. ; End RPEEP.LIB
  985.  
  986. ; End of File Pointer -> end of text
  987. topmem    ds    2        ; Top