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 / BYE5 / FFOR.AQM / FFOR.ASM
Assembly Source File  |  2000-06-30  |  12KB  |  534 lines

  1.  
  2. ; FFOR.ASM - Displays the FFOR text file, describing old files - 12/10/85
  3. ;
  4. ;    This program has been copyrighted (c) by Irvin M. Hoff
  5. ;
  6. ;                FOR.ASM
  7. ;                   by
  8. ;              Irvin M. Hoff
  9. ;             (17 July 1985)
  10. ;
  11.     ASEG            ; For M80 and RMAC, ignore if using MAC
  12. ;
  13. ;
  14. ; This program displays the FFOR text file, showing the description of
  15. ; recently uploaded files.  It should go on A0: area, giving full secur-
  16. ; ity, and allowing it to be called from any drive/user area.  ^S pauses
  17. ; and the following characters will terminate at the end of the current
  18. ; line:
  19. ;
  20. ;    ^C   C     c   ^K   K   k   ^X   X   x
  21. ;
  22. ; It can also show the entire description of any file area that contains
  23. ; a string of characters typed after the FFOR name, in a similar (but
  24. ; more simple) manner to FIND52, etc.  Example:
  25. ;
  26. ;        A>FFOR ?     (displays a help guide)
  27. ;        A>FFOR IBM    (types all files with IBM somewhere)
  28. ;        A>FFOR .A?M    (accepts ? for a wildcard)
  29. ;
  30. ;-----------------------------------------------------------------------
  31. ;
  32. ; 12/10/85  Rewritten (slightly) for FFOR    - Irv Hoff
  33. ; 08/20/85  Redated for KMD04            - Irv Hoff
  34. ; 07/17/85  Initial version            - Irv Hoff
  35. ;
  36. ;-----------------------------------------------------------------------
  37. ;
  38. ; User choices
  39. ;
  40. DRIVE    EQU    'A'        ; FFOR text file location in your system
  41. USER    EQU    5        ; FFOR text file location in your system
  42. ;
  43. ;
  44. ; Equates
  45. ;
  46. CR    EQU    0DH        ; Carriage return
  47. LF    EQU    0AH        ; Line feed
  48. EOF    EQU    1AH        ; End of file character
  49. EOT    EQU    04H        ; End of transmission
  50. ETX    EQU    03H        ; End of text
  51. ;
  52. ;
  53.     ORG    0100H
  54. ;
  55. ;
  56.     JMP    START
  57. ;
  58. ;
  59. STDRIV:    DB    DRIVE        ; Location of FFOR text file
  60. STUSER:    DB    USER        ; Location of FFOR text file
  61. ;
  62. ;
  63. ;=======================================================================
  64. ;
  65. ;            PROGRAM STARTS HERE
  66. ;
  67. ;=======================================================================
  68. ;
  69. ; Save stack, print sign-on, look for file specification
  70. ;
  71. START:    LXI    H,0
  72.     DAD    SP        ; Get 'CCP' stack
  73.     SHLD    STACK        ; Save it for exit
  74.     LXI    SP,STACK    ; Set stack pointer
  75. ;
  76.     LDA    0004H        ; Get current drive/user
  77.     STA    DRUSER        ; Store
  78. ;
  79. ;
  80. ; Set drive/user to the FFOR text file area listed above
  81. ;
  82.     LDA    STUSER        ; Set user to FFOR text file area
  83.     MOV    E,A
  84.     MVI    C,SETUSR
  85.     CALL    BDOS
  86.     LDA    STDRIV        ; Set drive to FFOR text file area
  87.     SUI    41H
  88.     MOV    E,A
  89.     MVI    C,SELDSK
  90.     CALL    BDOS
  91. ;
  92. ;
  93. ; Open source file
  94. ;
  95.     LXI    D,FILE
  96.     MVI    C,OPEN
  97.     CALL    BDOS
  98.     INR    A        ; Check for no open
  99.     JZ    NONE        ; No file, exit
  100. ;
  101.     CALL    ILPRT
  102.     DB    CR,LF
  103.     DB    'FFOR - copyright 1985 by Irvin M. Hoff - 12/10/85'
  104.     DB    CR,LF,'[type ^S to pause, ^C, ^X or ^K to abort, ? for '
  105.     DB    'help]',CR,LF
  106.     DB    'wait a moment...'
  107.     DB    0
  108. ;
  109.     LDA    TBUF        ; Any search string requested?
  110.     ORA    A
  111.     STA    SHOWAL        ; If no strings to find, show everything
  112.     JNZ    CHECK
  113.     CALL    ILPRT        ; Will overwrite "wait" message
  114.     DB    CR,'                  ',CR,LF,0
  115.     JMP    READLP        ; If no strings, exit
  116. ;
  117. ;
  118. ; Want the help guide?
  119. ;
  120. CHECK:    LDA    TBUF+2
  121.     CPI    '?'        ; First chararter typed a '?' for help?
  122.     JNZ    LOOP        ; If not, continue
  123.     LDA    TBUF+3        ; Check next character after '?'
  124.     ORA    A        ; If a zero, they want some help
  125.     JZ    HELP
  126. ;
  127. ;
  128. ; Store the search string in STRING
  129. ;
  130. LOOP:    LXI    H,TBUF
  131.     MOV    B,M        ; Get number of characters in string
  132.     LXI    D,STRING    ; Get and store the requested string(s)
  133.     INX    H
  134. ;
  135. LOOP1:    INX    H
  136.     MOV    A,M
  137.     STAX    D
  138.     INX    D
  139.     DCR    B
  140.     JNZ    LOOP1
  141. ;
  142. ;
  143. ; Address the main buffer, now
  144. ;
  145.     LXI    D,BUFFER    ; Put in buffer
  146. ;
  147. ;
  148. ; Read record from source file
  149. ;
  150. READLP:    PUSH    D        ; Save the line address
  151.     MVI    C,SETDMA
  152.     LXI    D,TBUF
  153.     CALL    BDOS
  154. ;
  155.     MVI    C,READ
  156.     LXI    D,FILE
  157.     CALL    BDOS
  158. ;
  159.     POP    D
  160.     ORA    A        ; Read ok?
  161.     JNZ    RERROR        ; If not, display an error
  162. ;
  163.     LXI    H,TBUF        ; Read buffer address
  164. ;
  165. WRDLOP:    LDA    LFEED        ; Last character a line feed?
  166.     ORA    A
  167.     JZ    WRDL1        ; If not, keep going
  168. ;
  169.     XRA    A
  170.     STA    LFEED        ; Clear the flag
  171.     MOV    A,M
  172.     ANI    7FH        ; Remove any parity
  173.     CPI    '-'        ; Is this a separator line?
  174.     JNZ    WRDL1        ; If not, keep going
  175.     MVI    A,03H        ; If yes, store an "end of text" char.
  176.     STAX    D
  177.     JMP    COMPAR        ; Handle the string
  178. ;
  179. WRDL1:    MOV    A,M        ; Get byte from read buffer
  180.     ANI    7FH        ; Strip parity bit
  181.     CPI    7FH        ; DEL (rubout) ?
  182.     JZ    NEXT        ; Yes, ignore it
  183.     CPI    EOF        ; End of file marker ?
  184.     JZ    TDONE        ; Transfer done, close, exit
  185. ;
  186.     MOV    B,A        ; Store the character temporarily
  187.     LDA    SHOWAL        ; Going to show everything?
  188.     ORA    A
  189.     MOV    A,B        ; Get the character back
  190.     JNZ    WRDL2
  191.     CALL    TYPE
  192.     JMP    WRDL3
  193. ;
  194. ;
  195. ; Store the character in the buffer
  196. ;
  197. WRDL2:    STAX    D        ; Store the character in the buffer
  198.     INX    D        ; Next buffer position
  199. ;
  200. WRDL3:    CPI    LF        ; See if finished with this line
  201.     JNZ    NEXT        ; If not get next character
  202.     LDA    SHOWAL
  203.     STA    LFEED        ; Show we just had a line feed character
  204.     CALL    ABORT        ; Ready to quit?
  205. ;
  206. NEXT:    INR    L        ; Done with sector?
  207.     JZ    READLP        ; If yes get another sector
  208.     JMP    WRDLOP        ; No, get another byte
  209. ;.....
  210. ;
  211. ;
  212. ;=======================================================================
  213. ;
  214. ;             SUBROUTINES
  215. ;
  216. ;=======================================================================
  217. ;
  218. ;
  219. ; Aborts the display when requested, but only at end of line
  220. ;
  221. ABORT:    PUSH    H        ; Save the TBUF address
  222.     PUSH    D
  223.     MVI    C,CONST        ; Check to see if key pressed
  224.     CALL    BDOS
  225.     ORA    A
  226.     JZ    ABORT3        ; If no key pressed, then continue
  227.     MVI    C,RDCON        ; If key pressed, then check for abort
  228.     ANI    5FH        ; Remove parity, insure upper-case
  229.     CALL    BDOS
  230.     CPI    'S'-40H
  231.     JNZ    ABORT1
  232.     MVI    C,RDCON
  233.     CALL    BDOS
  234.     ANI    5FH
  235. ;
  236. ABORT1:    CPI    'C'-40H        ; Is it CTL-C?
  237.     JZ    ABORT2
  238.     CPI    'K'-40H        ; Is it CTL-K?
  239.     JZ    ABORT2        ; If no, then continue
  240.     CPI    'X'-40H        ; Is it CTL-X?
  241.     JZ    ABORT2
  242.     ANI    5FH        ; Cnvert to upper-case
  243.     CPI    'C'
  244.     JZ    ABORT2
  245.     CPI    'K'
  246.     JZ    ABORT2
  247.     CPI    'X'
  248.     JNZ    ABORT3
  249. ;
  250. ABORT2:    CALL    EXIT        ; If yes, then print abort message
  251.     DB    CR,LF,'++ ABORTED ++','$'
  252. ;
  253. ABORT3:    POP    D
  254.     POP    H
  255.     RET
  256. ;.....
  257. ;
  258. ;
  259. ; Print message then exit to CP/M
  260. ;
  261. EXIT:    POP    D        ; Get message address
  262.     MVI    C,PRINT        ; Print message
  263.     CALL    BDOS
  264. ;
  265. EXIT1:    CALL    ILPRT        ; Print CRLF before quitting
  266.     DB    CR,LF,0
  267.     LDA    DRUSER        ; Get original drive/user area back
  268.     RAR
  269.     RAR
  270.     RAR
  271.     RAR
  272.     ANI    0FH        ; Just look at the user area
  273.     MOV    E,A
  274.     MVI    C,SETUSR    ; Restore original user area
  275.     CALL    BDOS
  276.     LDA    DRUSER        ; Get the original drive/user back
  277.     ANI    0FH        ; Just look at the drive for now
  278.     MOV    E,A
  279.     MVI    C,SELDSK    ; Restore original drive
  280.     CALL    BDOS
  281. ;
  282.     LHLD    STACK
  283.     XRA    A
  284.     SPHL
  285.     RET
  286. ;.....
  287. ;
  288. ;
  289. ; Help guide if no search string is included
  290. ;
  291. HELP:    CALL    EXIT
  292.     DB    CR,'   Examples of how to use:',CR,LF
  293.     DB    CR,LF,'   B>FFOR MOD'
  294.     DB    CR,LF,'   B>FFOR MOD|BYE'
  295.     DB    CR,LF,'   B>FFOR M7'
  296.     DB    CR,LF,'   B>FFOR \M7'
  297.     DB    CR,LF,'   B>FFOR SPHL'
  298.     DB    CR,LF,'   B>FFOR .A?M'
  299.     DB    CR,LF,CR,LF,'   If no string is included, all the file '
  300.     DB    'is shown.  A ''|'' allows',CR,LF,'   numerous '
  301.     DB    'strings to be used at the same time.  ''?'' is used '
  302.     DB    'for',CR,LF,'   "any character at this position".  A '
  303.     DB    '''\'' fakes a line feed and',CR,LF,'   looks only at '
  304.     DB    'the start of the filename line.',CR,LF,'$'
  305. ;.....
  306. ;
  307. ;
  308. ; Inline print routine - prints string pointed to by stack until a zero
  309. ; is found.  Returns to caller at the next address after the zero ter-
  310. ; minator.
  311. ;
  312. ILPRT:    XTHL            ; Save HL, get message address
  313. ;
  314. ILPLP:    MOV    A,M        ; Get chararacter
  315.     CALL    TYPE        ; Show on CRT
  316.     INX    H        ; Next character location
  317.     MOV    A,M        ; Get the character
  318.     ORA    A        ; If zero, all done
  319.     JNZ    ILPLP        ; Else keep going
  320.     XTHL            ; Restore HL, ret address
  321.     RET            ; Return past the end of the message
  322. ;.....
  323. ;
  324. ;
  325. NONE:    CALL    EXIT
  326.     DB    CR,LF,'++ No current FFOR text file available ++','$'
  327. ;.....
  328. ;
  329. ;
  330. ; Scan for the string
  331. ;
  332. COMPAR:    PUSH    H        ; Save the TBUF address
  333.     LXI    H,STRING
  334. ;
  335. ORLINE:    SHLD    STRPTR
  336.     LXI    H,BUFFER
  337. ;
  338. NXTSTR:    XCHG            ; Buffer location into DE for now
  339.     LHLD    STRPTR
  340.     XCHG            ; DE=string ponter, HL=buffer address
  341.     PUSH    H        ; Save current buffer position
  342. ;
  343. ;
  344. ; Replace '\' with a line feed character
  345. ;
  346. CLOOP:    LDAX    D        ; Get character from the string
  347.     CPI    '\'
  348.     JNZ    $+5
  349.     MVI    A,LF        ; Call it a line feed
  350. ;
  351. ;
  352. ; Compare the string with characters in the buffer
  353. ;
  354.     INX    D
  355.     ORA    A        ; End of string?
  356.     JZ    MATCHED
  357. ;
  358.     CPI    '|'
  359.     JZ    MATCHED        ; First part
  360. ;
  361.     MOV    B,A        ; Store the string character for now
  362.     MOV    A,M        ; Get the buffer character
  363.     CPI    'a'        ; Test for lower case
  364.     JC    NOTLWR
  365.     CPI    'z'+1
  366.     JNC    NOTLWR
  367.     ANI    5FH
  368. ;
  369. NOTLWR:    MOV    C,A        ; Store temporarily
  370.     INX    H
  371.     MOV    A,B        ; Get the string character back again
  372.     CPI    '?'        ; If wild card, accept any character
  373.     JZ    CLOOP        ; Match so far, keep going
  374.     CMP    C        ; String char. match buffer char?
  375.     JZ    CLOOP        ; Matched, so keep going
  376. ;
  377. ;
  378. ; Not equal
  379. ;
  380.     POP    H        ; Restore the buffer address
  381.     INX    H        ; Next buffer position
  382.     MVI    B,0        ; Zero out temporary "end of file" flag
  383.     MOV    A,M        ; Get the character
  384.     CPI    ETX        ; At end of buffer?
  385.     JZ    NOTEQL        ; If yes, exit
  386. ;
  387.     CPI    EOT
  388.     JNZ    NXTSTR        ; If not, keep going
  389.     INR    B
  390. ;
  391. NOTEQL:    LHLD    STRPTR        ; Reload the string pointer
  392. ;
  393. ;
  394. ; If an 'OR' (|) is in the line, scan for it
  395. ;
  396. FINDOR:    MOV    A,M        ; Get the character from the string
  397.     INX    H        ; Next position in string
  398.     CPI    '|'        ; Divisor between strings
  399.     JZ    ORLINE        ; Was a divisor, so check next string
  400.     ORA    A        ; End of string?
  401.     JNZ    FINDOR        ; If neither, keep checking
  402. ;
  403. ;
  404. ; Start the buffer over again
  405. ;
  406.     MOV    A,B        ; Get our temporary "all done" flag
  407.     ORA    A
  408.     JNZ    TDONE1        ; If not zero, all finished
  409.     LXI    D,BUFFER+1    ; Keep the one '-' from very first line
  410.     POP    H        ; Restore the TBUF address
  411.     JMP    NEXT        ; Get the next character and continue
  412. ;
  413. ;
  414. ; Now print the line itself
  415. ;
  416. MATCHED:POP    H        ; Restore the stack from inner loop
  417.     LDA    FIRSTM
  418.     ORA    A
  419.     JNZ    MATCH0
  420.     INR    A
  421.     STA    FIRSTM
  422.     CALL    ILPRT
  423.     DB    CR,'                  ',CR,LF,0
  424. ;
  425. MATCH0:    LXI    H,BUFFER    ; Start at beginning of buffer
  426. ;
  427. MATCH1:    MOV    A,M        ; Get the character
  428.     CPI    ETX        ; End of Text?
  429.     JZ    MATCH2        ; If yes, start next group
  430.     CPI    EOT        ; End of transmission?
  431.     JZ    TDONE1        ; If yes, all finished now
  432.     CALL    TYPE        ; Show on CRT
  433.     INX    H        ; Next character in buffer
  434.     JMP    MATCH1
  435. ;
  436. MATCH2:    POP    H        ; Restore the TBUF address
  437.     LXI    D,BUFFER+1    ; Keep the original '-' to balance line
  438.     JMP    NEXT        ; Get the next group
  439. ;.....
  440. ;
  441. ;
  442. RERROR:    CPI    1        ; File finished?
  443.     JZ    TDONE        ; Exit, then
  444.     CALL    EXIT
  445.     DB    '++ SOURCE FILE READ ERROR ++$'
  446. ;.....
  447. ;
  448. ;
  449. ; Transfer is done - close destination file
  450. ;
  451. TDONE:    LDA    SHOWAL        ; Showing all text?
  452.     ORA    A
  453.     JZ    TDONE1        ; If yes, exit
  454.     MVI    A,EOT        ; Store ad "end of transmission" char.
  455.     STAX    D
  456.     JMP    COMPAR        ; Make a final comparison
  457. ;
  458. TDONE1:    MVI    C,CLOSE
  459.     LXI    D,FILE
  460.     CALL    BDOS
  461.     CALL    EXIT
  462.     DB    CR,'----'
  463.     DB    CR,LF,'[End of listing]','$'
  464.     JMP    EXIT1
  465. ;.....
  466. ;
  467. ;
  468. ; Send character in A register to console
  469. ;
  470. TYPE:    PUSH    B
  471.     PUSH    D
  472.     PUSH    H
  473.     PUSH    PSW
  474.     MOV    E,A        ; Character to 'E' for CP/M
  475.     MVI    C,WRCON        ; Write to console
  476.     CALL    BDOS
  477.     POP    PSW
  478.     POP    H
  479.     POP    D
  480.     POP    B
  481.     RET
  482. ;.....
  483. ;
  484. ;
  485. ;***********************************************************************
  486. ;
  487. ; Data area
  488. ;
  489. ;***********************************************************************
  490. ;
  491. ;
  492. FILE:    DB    0,'FFOR       '
  493.     DB    0,0,0,0,0,0,0
  494.     DB    0,0,0,0,0,0,0
  495.     DB    0,0,0,0,0,0,0
  496. ;
  497. DRUSER:    DB    0        ; Store original drive/user area
  498. FIRSTM:    DB    0        ; To clear "wait a momemnt....."
  499. LFEED:    DB    0        ; Checks the character after a line feed
  500. SHOWAL:    DB    0        ; Flag to show all text if no strings
  501. STRPTR:    DW    0        ; Pointer for "|" scan
  502. ;
  503. STRING:    DS    128        ; What to search for
  504.     DS    40        ; Room for 20-level stack
  505. ;
  506. ;
  507. ; Set write buffer to even page boundry
  508. ;
  509.     ORG    ($+255)/256*256
  510. ;
  511. BUFFER    EQU    $        ; Write buffer starts here
  512. STACK    EQU    BUFFER-2
  513. ;
  514. ;
  515. ; BDOS equates
  516. ;
  517. RDCON    EQU    1        ; Read console
  518. WRCON    EQU    2        ; Write to console
  519. PRINT    EQU    9        ; Print string
  520. CONST    EQU    11        ; Get console status
  521. SELDSK    EQU    14        ; Select requested disk drive
  522. OPEN    EQU    15        ; Open a file
  523. CLOSE    EQU    16        ; Close a file
  524. READ    EQU    20        ; Read sequential file
  525. SETDMA    EQU    26        ; Set dma address
  526. SETUSR    EQU    32        ; Set requested user area
  527. ;
  528. BDOS    EQU    0005H
  529. TBUF    EQU    0080H
  530. ;.....
  531. ;
  532. ;
  533.     END
  534.