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 / FOR-SUPP.LBR / FORZ.ZZ0 / FORZ.Z80
Text File  |  2000-06-30  |  8KB  |  474 lines

  1. ; Program:    FORZ
  2. ; Version:    1.0
  3. ; Assembly:    Z80ASM.COM, PDLN.COM, Z3LIB
  4. ; Date:        5 Aug 87    
  5. ; Author:    Carson Wilson
  6. ;
  7. ; Purpose:    This is an enhanced version Irv Hoff's FOR.COM for ZCPR33.
  8. ;
  9. ; Features:    Sets the ZCPR program error flag if a string was given at
  10. ;         the command line and no match was found
  11. ;        Resets ZCPR program error flag if a string was given at the 
  12. ;         command line and a match WAS found.
  13. ;        Operates quietly (no informative messages) if ZCPR quiet
  14. ;         flag is set (useful for running under ZFILER).
  15. ;        Responds to ZCPR '/' or '//' help commands.
  16. ;        Reinitializes its internal FCB so that FORZ can be rerun
  17. ;         with ZCPR's GO command. 
  18. ;        Apologies for parts of this source which remain unclear;
  19. ;         this file was adapted from a disassembly.
  20.  
  21. Version    equ    10
  22.  
  23. ;
  24. BDOS    equ    5
  25. CR    equ    0dh
  26. LF    equ    0ah
  27. DMA    equ    80h
  28. ;
  29.     .request    z3lib
  30.     ext        z3init, puter2, getquiet
  31. ;
  32. entry:
  33.     jp    Start
  34.     db    'Z3ENV'
  35.     db    3
  36. z3eadr:    dw    0        ; address ZCPR ENV descriptor 
  37.                 ;  to be filled in by CCP
  38.     dw    entry        ; Type 3 environment points to itself
  39. ;
  40.     db    '[CONFIG>'
  41. FORdrv:    db    'A'        ; drive of FOR file (not used)
  42. FORusr:    db    14        ; user # of FOR file
  43. ;
  44. Start:    
  45.     ld    hl,0
  46.     add    hl,sp
  47.     ld    (StkSav),hl        ; save sp
  48.     ld    sp,StkSav
  49.     ld    a,(4)
  50.     ld    (DefDU),a
  51. ;
  52.     ld    hl,(z3eadr)        ; Initialize Z environment
  53.     call    z3init
  54. ;
  55.     ld    hl,FORFCB1        ; Initialize FCB so we can use
  56.                     ; ZCPR's GO command on FORZ
  57.     ld    b,21            ; Length to fill
  58.     xor    a            ; Zero out
  59. InitFCBa:
  60.     ld    (hl),a
  61.     inc    hl
  62.     djnz    InitFCBa
  63. ;
  64.  
  65.     ld    a,(FORusr)
  66.     ld    e,a
  67.     ld    c,' '            ; select FOR. user
  68.     call    BDOS
  69. ;
  70.     ld    a,(FORdrv)
  71.     sub    'A'
  72.     ld    e,a
  73.     ld    c,0eh
  74.     call    5            ; select FOR. drive 
  75.                     ;  (as returned by getmsg)
  76. ;    
  77.     ld    de,ForFCB
  78.     ld    c,0fh
  79.     call    BDOS            ; search first
  80.     inc    a
  81.     jp    z,NoFOR            ; FOR file not found
  82. ;
  83.     call    getquiet
  84.     jr    nz,ChkLen        ; No messages if Quiet on    
  85.     call    InlPrnt
  86.     db    CR,LF
  87.     db    'FORZ ',version/10+'0','.',version mod 10+'0',
  88.     db    ' (c) 1987 by C. Wilson',CR,LF
  89.     db    '[type ^S to pause, ^C, ^X or ^K to abort]'
  90.     db    CR,LF,CR,LF,0
  91. ;
  92. ;
  93. ChkLen:    ld    a,(DMA)            ; # of chars in command tail
  94.     or    a
  95.     ld    (TailLen),a        ; save length
  96.     jp    nz,ChkTail        ; had tail
  97.     ld    a,CR            ; no CL tail
  98.     call    PCharA
  99.     jp    Read
  100. ;
  101. ; ChkTail: '?', '/', or '//' gives help message.
  102. ;
  103. ChkTail:
  104.     ld    a,(82h)            ; 1st char of CL tail
  105.     cp    '/'
  106.     jp    nz,ChkT2
  107.     ld    a,(83h)            ; 2nd char
  108.     or    a
  109.     jp    z,Help            ; no 2nd char
  110.     cp    '/'            ; 2nd char '/'
  111.     jp    z,Help
  112. ;
  113. ChkT2:    ld    a,(82h)
  114.     cp    '?'
  115.     jp    nz,CopyTail        ; No help
  116.     ld    a,(83h)            ; 2nd CL char detected?
  117.     or    a
  118.     jp    nz,CopyTail        ; Yes, no help.
  119.     jp    Help            ; Lone '?' gives help
  120.  
  121. CopyTail:
  122.     call    SetZerr            ; set ZCPR error flag as default
  123.                     ;  until match for CL string found
  124.     ld    hl,DMA
  125.     ld    b,(hl)            ; # of chars in command line buffer
  126.     ld    de,FORBuf
  127.     inc    hl
  128. CopyT1:    
  129.     inc    hl
  130.     ld    a,(hl)
  131.     ld    (de),a
  132.     inc    de
  133.     dec    b
  134.     jp    nz,CopyT1        ; copy tail to our buffer
  135. ;
  136.     ld    de,FORDMA
  137. Read:    
  138.     push    de
  139.     ld    c,1ah            ; set DMA 80h
  140.     ld    de,DMA
  141.     call    BDOS
  142.     ld    c,14h            ; read seq.
  143.     ld    de,ForFCB
  144.     call    BDOS
  145.     pop    de
  146.     or    a
  147.     jp    nz,l04fb        ; read error / EOF
  148.     ld    hl,DMA
  149. ;
  150. TestCh:    
  151.     ld    a,(First)        ; flag
  152.     or    a            ; = 0?
  153.     jp    z,l020c            ; yes, first char.
  154.     xor    a            ; set flag to 0
  155.     ld    (First),a
  156.     ld    a,(hl)            ; get next char from file
  157.     and    7fh            ; mask 
  158.     cp    '-'
  159.     jp    nz,l020c
  160.     ld    a,3
  161.     ld    (de),a
  162.     jp    l0473
  163. l020c:    
  164.     ld    a,(hl)
  165.     and    7fh
  166.     cp    7fh            ; delete mark?
  167.     jp    z,ReadChk
  168.     cp    1ah            ; end of file?
  169.     jp    z,l0520
  170.     ld    b,a
  171.     ld    a,(TailLen)
  172.     or    a
  173.     ld    a,b
  174.     jp    nz,l0228
  175.     call    PCharA
  176.     jp    l022a
  177. l0228:    
  178.     ld    (de),a
  179.     inc    de
  180. l022a:    
  181.     cp    LF
  182.     jp    nz,ReadChk
  183.     ld    a,(TailLen)
  184.     ld    (First),a
  185.     call    ChkCon
  186. ReadChk:                ; time to read again?
  187.     inc    l
  188.     jp    z,Read            ; yes
  189.     jp    TestCh            ; no, test next char.
  190. ;
  191. ;
  192. ChkCon:                    ; Test for user interrupt
  193.     push    hl
  194.     push    de
  195.     ld    c,0bh            ; get console status
  196.     call    BDOS
  197.     or    a
  198.     jp    z,ChkConX        ; no input waiting
  199.     ld    c,1            ; get input
  200.     and    5fh
  201.     call    BDOS
  202.     cp    13h            ; ^S?
  203.     jp    nz,ChkCon1        ; no
  204.     ld    c,1            ; yes, await input
  205.     call    BDOS
  206.     and    5fh
  207. ChkCon1:    
  208.     cp    3            ; ^C?
  209.     jp    z,Abort
  210.     cp    0bh            ; ^K?
  211.     jp    z,Abort
  212.     cp    18h            ; ^X?
  213.     jp    z,Abort
  214.     and    5fh            ; capitalize
  215.     cp    'C'
  216.     jp    z,Abort
  217.     cp    'K'
  218.     jp    z,Abort
  219.     cp    'X'
  220.     jp    nz,ChkConX
  221. Abort:    
  222.     call    getquiet
  223.     jp    nz,Exit
  224.     call    PrnExit
  225.     db    CR,LF,'++ ABORTED ++$'
  226. ChkConX:    
  227.     pop    de
  228.     pop    hl
  229.     ret
  230. ;
  231. ;
  232. PrnExit:            ; print string & exit 
  233.     pop    de
  234.     ld    c,9        ; print following '$' terminated string
  235.     call    BDOS
  236.     call    InlPrnt
  237.     db    CR,LF,0
  238. ;
  239. Exit:
  240.     ld    a,(DefDU)
  241.     rra
  242.     rra
  243.     rra
  244.     rra
  245.     and    0fh
  246.     ld    e,a         ; set user code to original
  247.     ld    c,' '
  248.     call    BDOS
  249. ;
  250.     ld    a,(DefDU)
  251.     and    0fh
  252.     ld    e,a
  253.     ld    c,0eh
  254.     call    5        ; restore drive
  255. ;
  256.     ld    hl,(StkSav)
  257.     xor    a
  258.     ld    sp,hl
  259.     ret            ; exit FOR.COM
  260. ;
  261. ;
  262. Help:    
  263.      call    PrnExit
  264.     db    CR,'   Examples of how to use:',CR,LF,CR,LF
  265.     db    '   B>FORZ MOD',CR,LF
  266.     db    '   B>FORZ MOD|BYE',CR,LF
  267.     db    '   B>FORZ M7',CR,LF
  268.     db    '   B>FORZ \M7',CR,LF
  269.     db    '   B>FORZ SPHL',CR,LF
  270.     db    '   B>FORZ .A?M',CR,LF,CR,LF
  271.     db    '   If no string is included, all the file '
  272.     db    'is shown.  A ''|'' allows',CR,LF
  273.     db    '   numerous strings to be used at the same time. '
  274.     db    ' ''?'' is used for',CR,LF
  275.     db    '   "any character at this position".  A ''\'' fakes a '
  276.     db    'line feed and',CR,LF,'  '
  277.     db    ' looks only at the start of the filename line.',CR,LF
  278.     db    '$'
  279. ;
  280. ;
  281. InlPrnt:            ; Print inline chars up to 0
  282.     ex    (sp),hl
  283. Prnt1:    
  284.     ld    a,(hl)
  285.     call    PCharA
  286.     inc    hl
  287.     ld    a,(hl)
  288.     or    a
  289.     jp    nz,Prnt1
  290.     ex    (sp),hl
  291.     ret
  292. ;
  293. NoFOR:    call    SetZerr
  294.     call    getquiet
  295.     jp    nz,Exit
  296.     call    PrnExit
  297.     db    CR,LF,'++ No current FOR text file available ++$'
  298. ;
  299. ;
  300. l0473:    
  301.     push    hl
  302.     ld    hl,FORBuf
  303. l0477:                ; Point to start of CL buffer
  304.     ld    (BufPt),hl    ; save at BUfPt
  305.     ld    hl,FORDMA    ; Point to start of DMABuf
  306. l047d:    
  307.     ex    de,hl        ; DE --> start of DMABuf
  308.     ld    hl,(BufPt)    ; HL --> start of CL
  309.     ex    de,hl        ; DE --> CL
  310.     push    hl        ; HL --> DMABuf
  311. l0483:    
  312.     ld    a,(de)        ; get first char of CL
  313.     cp    '\'
  314.     jp    nz,l048b
  315.     ld    a,LF        ; Look only at start of filename line
  316. l048b:    
  317.     inc    de        ; next CL char
  318.     or    a
  319.     jp    z,l04d9        ; First char is zero
  320.     cp    '|'
  321.     jp    z,l04d9        ; Start search for next CL string (| = or)
  322.     ld    b,a
  323.     ld    a,(hl)
  324.     cp    'a'
  325.     jp    c,l04a3
  326.     cp    '{'
  327.     jp    nc,l04a3
  328.     and    5fh
  329. l04a3:    
  330.     ld    c,a
  331.     inc    hl
  332.     ld    a,b
  333.     cp    '?'
  334.     jp    z,l0483
  335.     cp    c
  336.     jp    z,l0483
  337.     pop    hl
  338.     inc    hl
  339.     ld    b,0
  340.     ld    a,(hl)
  341.     cp    3
  342.     jp    z,l04bf
  343.     cp    4
  344.     jp    nz,l047d
  345.     inc    b
  346. l04bf:    
  347.     ld    hl,(BufPt)
  348. l04c2:    
  349.     ld    a,(hl)
  350.     inc    hl
  351.     cp    7ch
  352.     jp    z,l0477
  353.     or    a
  354.     jp    nz,l04c2
  355.     ld    a,b
  356.     or    a
  357.     jp    nz,Close
  358.     ld    de,FORDMA1
  359.     pop    hl
  360.     jp    ReadChk
  361. ;
  362. ;
  363. l04d9:    
  364.     pop    hl        ; HL --> DMABuf
  365.     ld    a,CR
  366.     call    PCharA
  367.     ld    hl,FORDMA
  368. ;
  369. PrintBuf:                ; Print DMABuf until terminator
  370.     ld    a,(hl)
  371.     cp    3        ; ^C
  372.     jp    z,l04f4
  373.     cp    4        ; ^D
  374.     jp    z,Success
  375.     call    PCharA
  376.     inc    hl
  377.     jp    PrintBuf
  378. ;
  379. Success:
  380.     call    ResZerr        ; Found match, so reset ZCPR error flag
  381.     jp    Close
  382. ;
  383. l04f4:    
  384.     call    ResZerr
  385.     pop    hl
  386.     ld    de,FORDMA1
  387.     jp    ReadChk
  388. ;
  389. ;
  390. l04fb:    
  391.     cp    1
  392.     jp    z,l0520
  393.     call    getquiet
  394.     jp    nz,Exit
  395.     call    PrnExit
  396.     db    '++ SOURCE FILE READ ERROR ++$'
  397. l0520:    
  398.     ld    a,(TailLen)
  399.     or    a
  400.     jp    z,Close
  401.     ld    a,4
  402.     ld    (de),a
  403.     jp    l0473
  404. Close:    
  405.     ld    c,10h        ; close file
  406.     ld    de,ForFCB
  407.     call    BDOS
  408.     call    getquiet
  409.     jp    nz,Exit
  410.     call    PrnExit
  411.     db    CR,'----',CR,LF,'[end of listing]$'
  412. ;
  413. PCharA:                ; print char in A
  414.     push    bc
  415.     push    de
  416.     push    hl
  417.     push    af
  418.     ld    e,a
  419.     ld    c,2
  420.     call    BDOS
  421.     pop    af
  422.     pop    hl
  423.     pop    de
  424.     pop    bc
  425.     ret
  426. ;
  427. ; Set ZCPR program error flag
  428. ;
  429. SetZerr:
  430.     ld    a,0ffh
  431.     call    puter2        ; set error flag to non-zero
  432.     ret
  433. ;
  434. ; Reset ZCPR error flag (clear it) 
  435. ;
  436. ResZerr:
  437.     ld    a,0
  438.     call    puter2        ; set error flag to 0
  439.     ret
  440. ;
  441. ;
  442. ForFCB:    db    0,'FOR        '
  443. ForFCB1:
  444.     ds    21
  445. DefDU:            ; default drive/user 
  446.     ds    1
  447. ;
  448. First:            ; flag
  449.     db    0
  450. ;
  451. TailLen:        ; length of comand line tail
  452.     ds    1
  453. ;
  454. OurStk:
  455.     ds    32
  456. StkSav:    
  457.     ds    2
  458. ;
  459. BufPt:    
  460.     ds    2
  461. ;
  462. FORBuf:    
  463.     ds    128
  464. ;
  465.  
  466.     DSEG
  467.  
  468. FORDMA:    
  469.     ds    1
  470.  
  471. FORDMA1    equ    $
  472.  
  473.     end
  474.