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 / KFORZ.ZZ0 / KFORZ.Z80
Text File  |  2000-06-30  |  9KB  |  628 lines

  1. ; Program:    KFORZ
  2. ; Version:    1.0
  3. ; Assembly:    Z80ASM.COM 
  4. ; Date:        5 Aug 87    
  5. ; Author:    Carson Wilson
  6. ;
  7. ; Purpose:    This is an enhanced version Irv Hoff's KFOR.COM for ZCPR33.
  8. ;
  9. ; Features:    The bug of a dollar sign in the file name or description
  10. ;         not showing up on the "repeating to verify" display 
  11. ;         was fixed.
  12. ;        MAIN FEATURE: now takes a command line tail of up to 32 
  13. ;         characters as the name of the file to be described.
  14. ;        Loads at 1000 hex so that FORZ can be rerun with ZCPR's GO
  15. ;         command after running KFORZ.
  16. ;        Reinitializes its internal FCB so that KFORZ can be rerun
  17. ;         with ZCPR's JUMP command. 
  18. ;        Apologies for the parts of the source whose function remains
  19. ;         unknown.  This file was built from a disassembly.
  20.  
  21. Version    equ    10
  22.  
  23. ;
  24. CR    equ    0dh
  25. LF    equ    0ah
  26. BDOS    equ    5
  27.  
  28. DMA    equ    80h
  29.  
  30.     org    1000h
  31.  
  32. Entry:    jp    Start
  33.     db    'Z3ENV'
  34.     db    3
  35. Z3EAdr:    dw    0        ; address ZCPR ENV descriptor 
  36.                 ;  to be filled in by CCP
  37.     dw    Entry        ; Type 3 environment points to itself
  38. ;
  39.     db    '[CONFIG>'
  40. FORDrv:    db    'A'        ; drive of FOR file (not used)
  41. FORUsr:    db    14        ; user # of FOR file
  42. ;
  43. Start:    ld    hl,0
  44.     add    hl,sp
  45.     ld    (StkSav),hl
  46.     ld    sp,StkSav
  47. ;
  48.     ld    hl,FORFCB1        ; Initialize FORZ's FCB so can use
  49.                     ;  ZCPR's GO command.
  50.     ld    b,21            ; Length to fill
  51.     xor    a            ; Zero it out
  52. InitFCBa:
  53.     ld    (hl),a
  54.     inc    hl
  55.     djnz    InitFCBa
  56. ;
  57. ReStart:    
  58.     ld    hl,0
  59.     ld    (l069d),hl
  60.     xor    a
  61.     ld    (l069a),a
  62.     ld    a,'!'
  63.     ld    (l0422),a
  64.     ld    (l069c),a
  65. ;
  66.     call    print
  67.     db    CR,LF
  68.     db    'KFORZ ',version/10 + '0','.',version mod 10 + '0'
  69.     db    ' (c) 1987 by C. Wilson',CR,LF
  70.     db    'SysOp can easily add a new file description.'
  71.     db    CR,LF,0
  72. ;
  73.     ld    a,(DMA)
  74.     or    a
  75.     jr    z,getname        ; no command line tail
  76. ;
  77.     call    print
  78.     db    CR,LF,0
  79.     ld    a,(DMA)            ; get tail length
  80. ;
  81.     ld    de,Buf1            ; pt. to buffer
  82.     ld    hl,DMA+2        ; begin parameter 1
  83. ;
  84.     sub    1            ; minus 1 for leading space
  85.     cp    33
  86.     jr    c,NoTrunc
  87.     ld    a,32            ; limit to 32 chars for 
  88.                     ;  name/typ/category
  89. NoTrunc:
  90.     ld    b,a            ; get command line tail length
  91.  
  92. KillSp:    ld    a,(hl)            ; kill leading spaces, tabs
  93.     cp    ' '
  94.     jr    z,Kill1
  95.     cp    9
  96.     jr    nz,copy
  97. Kill1:    inc    hl
  98.     djnz    KillSp
  99.     ld    a,b
  100.     or    a
  101.     jr    z,getname        ; CL held nothing but spaces 
  102. ;
  103. copy:    ld    a,(hl)            ; get char from dma buffer
  104.     ld    (de),a            ; save in our buffer
  105.     inc    de
  106.     inc    hl
  107.     call    PChar            ; echo it
  108.     djnz    copy            ; up to b characters
  109. ;    
  110.     ld    a,CR            ; tail it with cr, lf
  111.     ld    (de),a
  112.     inc    de    
  113.     ld    a,LF
  114.     ld    (de),a
  115.     ld    hl,l06a3
  116.     call    l048a        ; transfer '----',etc. to high buffer
  117.     call    print
  118.     db    CR,LF,0
  119.     jr    transnam    
  120.  
  121. getname:call    print
  122.     db    'What is the filename/extent/category?'
  123.     db    CR,LF,CR,LF,0
  124.     ld    hl,l06a3        ; pt to "'----',CR,LF"
  125.     call    l048a            ; transfer it
  126.     call    l03f2            ; get name
  127. transnam:
  128.     call    l0487            ; transfer name to buffer
  129. ;
  130.     call    print
  131.     db    CR,LF
  132.     db    'Please describe this file (7 lines or less).  '
  133.     db    'Tell what equipment can use'
  134.     db    CR,LF,
  135.     db    'it and what the program does.  Extra RET to quit.',0
  136.     call    print
  137.     db    CR,LF,CR,LF
  138.     db    '0: ---------1---------2---------3---------4---------'
  139.     db    '5---------6---------',CR,LF,0
  140. ;
  141.     xor    a
  142.     ld    (l069a),a
  143.     ld    (l069c),a
  144.     ld    a,70            ; Max. line length
  145.     ld    (l0422),a
  146.     ld    c,48
  147. l029a:    
  148.     inc    c
  149.     ld    a,c
  150.     cp    56
  151.     jp    nc,l02be
  152.     call    PChar
  153.     ld    a,' '
  154.     call    l0547
  155.     call    l0547
  156.     call    l0547
  157.     call    print
  158.     db    ': ',0
  159.     call    l03f2
  160.     call    l0487
  161.     jp    l029a
  162. l02be:                ; tail the entry with CR,LF,'$' 
  163.     ld    a,CR
  164.     call    l0547
  165.     ld    a,LF
  166.     call    l0547
  167. ;    ld    a,'$'
  168.     XOR    A
  169.     call    l0547
  170.     call    print
  171.     db    CR,LF
  172.     db    '   Repeating to verify:'
  173.     db    CR,LF,CR,LF,0
  174. ;
  175.     ld    hl,(FreeMem)
  176. DISP:
  177.     LD    A,(HL)
  178.     OR    A
  179.     JR    Z,DONE
  180.     CALL    PCHAR
  181.     INC    HL
  182.     JR    DISP
  183. DONE:
  184.  
  185. ;    ex    de,hl
  186. ;    ld    c,9            ; Print string
  187. ;    call    BDOS            ;  had bug which didn't display '$'
  188. ;
  189.     ld    hl,(l069d)
  190.     dec    hl
  191.     ld    (l069d),hl
  192. l02fe:    
  193.     call    print
  194.     db    'Is this ok (Y/N)? ',0
  195.     call    l04eb
  196.     call    PChar
  197.     and    5fh
  198.     cp    'Y'
  199.     jp    z,l032f
  200.     cp    'N'
  201.     jp    nz,l02fe
  202.     call    print
  203.     db    CR,LF,0
  204.     jp    ReStart
  205. l032f:    
  206.     ld    a,(4)        ; get current default drive
  207.     ld    (DefDU),a
  208.  
  209.     ld    a,(FORUsr)    ; get stored user
  210.     ld    e,a
  211.     ld    c,32        ; set user code
  212.     call    BDOS
  213. ;
  214.     ld    a,(FORDrv)    ; get FOR drive letter
  215.     sub    'A'        ; translate to 0, 1, ...
  216.     ld    e,a
  217.     ld    c,0eh        ; select disk
  218.     call    BDOS
  219. ;
  220.     call    print
  221.     db    CR,LF,0
  222. ;
  223.     ld    de,l0658
  224.     ld    c,0fh        ; Open file
  225.     call    BDOS
  226. ;
  227.     inc    a
  228.     jp    nz,l0367
  229. ;
  230.     ld    c,16h        ; Make file
  231.     ld    de,l0658
  232.     call    BDOS
  233. ;
  234.     inc    a
  235.     jp    z,l0514
  236. l0367:    
  237.     ld    hl,l0658
  238.     ld    de,TempFCB
  239.     ld    b,9
  240.     call    BLDIR
  241.     xor    a
  242.     ld    (l0685),a
  243.     ld    (l0699),a
  244.     ld    hl,8000h
  245.     ld    (MYSTERY),hl
  246. ;
  247.     ld    c,13h                ; Delete file
  248.     ld    de,TempFCB
  249.     call    BDOS
  250. ;
  251.     ld    c,16h                ; Make file
  252.     ld    de,TempFCB
  253.     call    BDOS
  254. ;
  255.     inc    a
  256.     jp    z,l0514
  257.     call    print
  258.     db    CR,LF,'Wait a moment...',0
  259. l03a9:    
  260.     ld    de,DMA
  261.     ld    c,1ah                ; Set DMA
  262.     call    BDOS
  263. ;
  264.     ld    de,l0658
  265.     ld    c,14h                ; Read seq.
  266.     call    BDOS
  267. ;
  268.     or    a
  269.     jp    nz,l05aa
  270.     ld    hl,DMA
  271. l03c0:    
  272.     ld    a,(hl)
  273.     and    7fh
  274.     cp    7fh            ; DEL
  275.     jp    z,l03d0
  276.     cp    1ah            ; ^Z 
  277.     jp    z,l05f8
  278.     call    l0547
  279. l03d0:    
  280.     inc    l
  281.     jp    z,l03a9
  282.     jp    l03c0
  283. l03d7:    
  284.     call    PChar
  285.     ld    a,b
  286.     or    a
  287.     jp    nz,l03e4
  288.     ld    a,' '
  289.     jp    l03ee
  290. l03e4:    
  291.     dec    b
  292.     dec    hl
  293.     ld    a,' '
  294.     ld    (hl),a
  295.     call    PChar
  296. l03ec:    
  297.     ld    a,8        ; BackSp
  298. l03ee:    
  299.     call    PChar
  300.     ret
  301. ;
  302. l03f2:    
  303.     ld    b,0
  304.     ld    hl,Buf1
  305. l03f7:    
  306.     call    l04eb
  307.     cp    CR
  308.     jp    z,l042f
  309.     cp    9        ; Tab
  310.     jp    z,l0470
  311.     cp    7fh        ; delete same as BS - C.W.
  312.     jp    z,BackSp
  313.     cp    8        ; BackSp
  314.     jp    nz,l040f
  315. BackSp:    
  316.     ld    a,8
  317.     call    l03d7
  318.     jp    l03f7
  319. ;
  320. l040f:    
  321.     cp    ' '        ; char?
  322.     jp    c,l03f7        ; no
  323.     jp    z,l041a        ; yes, it was <space>
  324.     ld    (l069a),a    ; yes, but NOT space
  325. l041a:    
  326.     ld    (hl),a
  327.     call    PChar
  328.     inc    hl
  329.     inc    b
  330.     ld    a,b
  331.     db    0feh        ; 'cp n'
  332. l0422:    db    70
  333.     jp    c,l03f7
  334.     call    l03ec
  335.     call    l03e4
  336.     jp    l03f7
  337. l042f:    
  338.     ld    a,(l069a)
  339.     or    a
  340.     jp    nz,l045b
  341.     pop    hl
  342.     call    PrnExit
  343.     db    CR,LF,'++ Aborting with no changes ++$'
  344. l045b:    
  345.     ld    (hl),CR
  346.     ld    a,(hl)
  347.     call    PChar
  348.     inc    hl
  349.     ld    (hl),LF
  350.     ld    a,(hl)
  351.     call    PChar
  352.     inc    hl
  353.     ld    a,b
  354.     or    a
  355.     ret    nz
  356.     pop    hl
  357.     jp    l02be
  358. l0470:    
  359.     ld    a,b
  360.     cp    68
  361.     jp    nc,l03f7
  362.     ld    (hl),' '
  363.     ld    a,(hl)
  364.     call    PChar
  365.     inc    hl
  366.     inc    b
  367.     ld    a,b
  368.     and    7
  369.     jp    nz,l0470
  370.     jp    l03f7
  371. l0487:    
  372.     ld    hl,Buf1    ; pt to input buffer
  373. l048a:    
  374.     ld    a,(hl)
  375.     call    l0547
  376.     cp    LF        ; test input string (empty?)
  377.     ret    z
  378.     inc    hl
  379.     jp    l048a
  380. PrnExit:    
  381.     pop    de
  382.     ld    c,9
  383.     call    BDOS
  384. l049b:    
  385.     call    Restore
  386.     ld    hl,(StkSav)
  387.     ld    sp,hl
  388.     xor    a
  389.     ret
  390. ;
  391. print:                ; print string up to 0
  392.     ex    (sp),hl
  393. print1:    ld    a,(hl)
  394.     call    PChar
  395.     inc    hl
  396.     ld    a,(hl)
  397.     or    a
  398.     jp    nz,print1
  399.     ex    (sp),hl
  400.     ret
  401. ;
  402. l04b1:    
  403.     ld    c,13h        ; Delete file
  404.     ld    de,TempFCB
  405.     call    BDOS
  406.     jp    PrnExit
  407.     db    CR,LF,'++ Disk full, aborting, saving original file$'
  408. ;
  409. l04eb:    
  410.     push    hl
  411.     push    de
  412.     push    bc
  413. l04ee:    
  414.     ld    e,0ffh
  415.     ld    c,6        ; Direct Console Input
  416.     call    BDOS
  417.     and    7fh        ; mask
  418.     or    a
  419.     jp    z,l04ee
  420.     cp    'a'        ; lower case?
  421.     jp    c,l0510
  422.     cp    '{'
  423.     jp    nc,l0510
  424.     ld    b,a
  425.     ld    a,(l069c)
  426.     or    a
  427.     ld    a,b
  428.     jp    z,l0510
  429.     and    5fh
  430. l0510:    
  431.     pop    bc
  432.     pop    de
  433.     pop    hl
  434.     ret
  435. ;
  436. l0514:    
  437.     call    PrnExit
  438.     db    CR,LF,'No dir space: output$'
  439. l052e:    
  440.     jp    PrnExit
  441.     db    CR,LF,'Cannot close output$'
  442. l0547:    
  443.     push    hl
  444.     push    af
  445.     ld    hl,(MYSTERY)
  446.     ex    de,hl
  447.     ld    hl,(l069d)
  448.     ld    a,l
  449.     sub    e
  450.     ld    a,h
  451.     sbc    a,d
  452.     jp    c,l0599            ; DMA buffer full? (?)
  453.     ld    hl,0
  454.     ld    (l069d),hl
  455. l055d:    
  456.     ex    de,hl
  457.     ld    hl,(MYSTERY)
  458.     ld    a,e
  459.     sub    l
  460.     ld    a,d
  461.     sbc    a,h
  462.     jp    nc,l058b
  463.     ld    hl,(FreeMem)
  464.     add    hl,de
  465. ;
  466.     ex    de,hl
  467.     ld    c,1ah                ; Set DMA
  468.     call    BDOS
  469. ;
  470.     ld    de,TempFCB
  471.     ld    c,15h
  472.     call    BDOS                ; Write seq.
  473. ;
  474.     or    a
  475.     jp    nz,l04b1
  476.     ld    de,DMA
  477.     ld    hl,(l069d)
  478.     add    hl,de
  479.     ld    (l069d),hl
  480.     jp    l055d
  481. l058b:    
  482.     ld    de,DMA
  483.     ld    c,1ah                ; Set DMA
  484.     call    BDOS
  485. ;
  486.     ld    hl,0
  487.     ld    (l069d),hl
  488. l0599:    
  489.     ex    de,hl
  490.     ld    hl,(FreeMem)
  491.     add    hl,de
  492.     ex    de,hl
  493.     pop    af
  494.     ld    (de),a
  495.     ld    hl,(l069d)
  496.     inc    hl
  497.     ld    (l069d),hl
  498.     pop    hl
  499.     ret
  500. l05aa:    
  501.     cp    1            ; ^A
  502.     jp    z,l05f8
  503. ;
  504.     ld    c,13h            ; Delete file
  505.     ld    de,TempFCB
  506.     call    BDOS
  507. ;
  508.     call    PrnExit
  509.     db    '++ SOURCE FILE READ ERROR ++$'
  510.  
  511. Restore:    
  512.     ld    a,(DefDU)
  513.     rra
  514.     rra
  515.     rra
  516.     rra
  517.     and    0fh
  518.     ld    e,a
  519.     ld    c,' '        ; reset user
  520.     call    BDOS
  521.     ld    a,(DefDU)
  522.     and    0fh
  523.     ld    e,a
  524.     ld    c,0eh        ; select default disk
  525.     call    BDOS
  526.     call    print
  527.     db    CR,LF,0
  528.     ret
  529.  
  530. l05f8:    
  531.     ld    hl,(l069d)
  532.     ld    a,l
  533.     and    7fh
  534.     jp    nz,l0604
  535.     ld    (MYSTERY),hl
  536. l0604:    
  537.     ld    a,1ah            ; ^Z
  538.     push    af
  539.     call    l0547
  540.     pop    af
  541.     jp    nz,l05f8
  542.  
  543.     ld    c,10h            ; Close file
  544.     ld    de,l0658
  545.     call    BDOS
  546.  
  547.     ld    c,10h            ; Close file
  548.     ld    de,TempFCB
  549.     call    BDOS
  550.  
  551.     inc    a
  552.     jp    z,l052e
  553.     ld    hl,l0659
  554.     ld    de,l068a
  555.     ld    b,10h
  556.     call    BLDIR
  557.  
  558.     ld    c,13h            ; Delete file
  559.     ld    de,l0658
  560.     call    BDOS
  561.  
  562.     ld    de,TempFCB
  563.     ld    c,17h            ; Rename file
  564.     call    BDOS
  565.     jp    l049b
  566. ;
  567. PChar:                ; print char
  568.     push    bc
  569.     push    de
  570.     push    hl
  571.     push    af
  572.     ld    e,a
  573.     ld    c,2
  574.     call    BDOS
  575.     pop    af
  576.     pop    hl
  577.     pop    de
  578.     pop    bc
  579.     ret
  580. ;
  581. BLDIR:                ; Repeating block load with dec. of B
  582.     ld    a,(hl)
  583.     ld    (de),a
  584.     inc    hl
  585.     inc    de
  586.     dec    b
  587.     jp    nz,BLDIR
  588.     ret
  589. ;
  590. l0658:                ; drive byte of FCB
  591.     ds    1
  592. l0659:    
  593.     db    'FOR        '        ; file name
  594. FORFCB1:
  595.     ds    21            ; rest of FCB
  596. ;
  597. TempFCB:    
  598.     db    0,'        $$$'        ; temporary file
  599. l0685:    
  600.     ds    5
  601. l068a:    
  602.     ds    15
  603. ;
  604. l0699:    
  605.     db    0
  606. l069a:    
  607.     db    0
  608. DefDU:                    ; store defaults
  609.     ds    1
  610. l069c:    
  611.     db    0
  612. l069d:    
  613.     dw    0
  614. FreeMem:    
  615.     dw    FOREnd
  616. MYSTERY:            ; purpose unknown 8/1/87
  617.     dw    8000h
  618. l06a3:    
  619.     db    '----',CR,LF
  620. Buf1:    
  621.     ds    86
  622. StkSav:    
  623.     ds    2
  624.  
  625. FOREnd    equ    $
  626.  
  627.     end
  628.