home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / a / cpswld.asm < prev    next >
Assembly Source File  |  2020-01-01  |  7KB  |  223 lines

  1. ; CPSWLD.ASM
  2. ;       KERMIT - (Celtic for "FREE")
  3. ;
  4. ;       This is the CP/M-80 implementation of the Columbia University
  5. ;       KERMIT file transfer protocol.
  6. ;
  7. ;       Version 4.0
  8. ;
  9. ;       Copyright June 1981,1982,1983,1984
  10. ;       Columbia University
  11. ;
  12. ; Originally written by Bill Catchings of the Columbia University Center for
  13. ; Computing Activities, 612 W. 115th St., New York, NY 10025.
  14. ;
  15. ; Contributions by Frank da Cruz, Daphne Tzoar, Bernie Eiben,
  16. ; Bruce Tanner, Nick Bush, Greg Small, Kimmo Laaksonen, Jeff Damens, and many
  17. ; others. 
  18. ;
  19. ;       Multi-file access subroutine.  Allows processing of multiple files
  20. ;       (i.e., *.ASM) from disk.  This routine builds the proper name in the
  21. ;       FCB each time it is called.  This command would be used in such pro-
  22. ;       grams such as modem transfer, tape save, etc. in which you want to
  23. ;       process single or multiple files.
  24. ;       Note that it will fail if more than 256 entries match the wildcard.
  25. ;
  26. ; revision history:
  27. ; edit 4: June 20, 1986, by OBSchou.  Added stuff at top and tail of routine
  28. ;       to support multiple FCBs.  If the routine get to mfn01 (Search for next)
  29. ;       then the next file found gets its fcb added to the buffer.  Once no 
  30. ;       more files have been found, the mfflg3 flag is set non-zero. 
  31. ;       The first thing to test on entry is whether a disk access
  32. ;       is needed.  Either way, the routine should return the next file name
  33. ;       in the fcb, or return with the carry flag set if there are no more
  34. ;       files to do.  Once there is a carry flag set for the return, all 
  35. ;       temporary flags are reset. Get all that?
  36. ;
  37. ; edit 3: July 27, 1984
  38. ;       support LASM: remove exclamation points, link to CP4CMD.
  39. ;
  40. ; edit 2: June 7, 1984 (CJC)
  41. ;       formatting and documentation; add module version string; redo movfcb,
  42. ;       in preparation for moving DMA buffer (later...).
  43. ;
  44. ; edit 1: May, 1984 (CJC)
  45. ;       extracted from CPMBASE.M80 version 3.9; modifications are described
  46. ;       in the accompanying .UPD file.
  47. ;
  48. wldver:    db    'CPSWLD.ASM (4)  20-Jun-86$'
  49.  
  50. ;       The FCB will be set up with the next name, ready to do normal 
  51. ;       processing (OPEN, READ, etc.) when routine is called.
  52. ;
  53. ;       Carry is set if no more names can be found
  54. ;
  55. ;       MFFLG1 is count/switch [0 for first time thru, pos for all others]
  56. ;       MFFLG2 is counted down for each successive GETNEXT file call
  57. ;       MFFLG3 is set to the last remaining FCBs buffered once Search for next
  58. ;               file fails with files in the buffer.
  59. ;
  60. ;       Technique used is to repeat SFIRST/SNEXT sequence N+1 times for each
  61. ;       successive call, till sequence fails. CP/M does NOT allow disk-handling
  62. ;       between SFIRST and SNEXT.
  63. ;       called by: send, seof, dir
  64.  
  65. mfname:    ora    a        ; clear carry
  66.     push    b        ;Save registers
  67.     push    d
  68.     push    h
  69.     jmp    mfnam0        ; skip over the next bit (which is entered from elsewhere)
  70.  
  71. ;[4] Get the FCB counter and see if we have any fcbs already.
  72. mfnam1:    lxi    h,fcb0
  73.     shld    xfcbptr        ; reset the pointer if we are to return an FCB
  74.  
  75. mfnam0:    lda    fcbcnt
  76.     ana    a        ; if none, then we may have to get some from disk
  77.     jz    mfn00        ; see later on
  78.     lhld    xfcbptr        ; we have some, so give the next one to the user
  79.     lxi    d,fcb        ; move from (hl) to (de) for length bc
  80.     lxi    b,12
  81.     call    mover
  82.     xra    a
  83.     sta    fcbext        ; clear fcb extents and such
  84.     sta    fcbrno        ; like record number
  85.     lhld    xfcbptr        ; point to next fcb
  86.     lxi    d,fcblen
  87.     dad    d        ; yup
  88.     shld    xfcbptr
  89.     lda    fcbcnt
  90.     dcr    a
  91.     sta    fcbcnt        ; decrease the number of fcbs we have
  92.     xra    a        ; clear carry
  93.     jmp    mffix1        ; and exit as if were all done
  94.  
  95. mfn00:    lda    mfflg3        ; no more FCBs for the user, any more on disk?
  96.     ana    a
  97.     jnz    mffix2        ; no, then set the carry flag to say so.
  98.     lxi    h,fcb0        ; now reset the fcb pointers and counter
  99.     shld    xfcbptr
  100.     xra    a
  101.     sta    fcbcnt
  102. ;[4] end of this addition.  See below as well.
  103.  
  104.  
  105.     mvi    c,setdma    ;Init DMA addr, FCB
  106.     lxi    d,80H
  107.     call    bdos
  108.     xra    a        ;A = 0
  109.     sta    fcbext        ;clear extension
  110.     lda    mfflg1        ;find out if "second" call in row
  111.     ora    a
  112.     jnz    mfn01        ;Were here before
  113.     sta    mfflg2
  114.     lxi    h,fcb
  115.     lxi    d,mfreq
  116.     lxi    b,12
  117.     call    mover        ;.from FCB to MFREQ
  118.     mvi    c,SFIRST    ;Search first
  119.     lxi    d,fcb
  120.     call    bdos
  121.     jmp    mfn02        ;and check results
  122.  
  123. mfn01:    dcr    a
  124.     sta    mfflg2        ;store down-counter
  125.     lxi    h,mfreq        ;SFIRST REQ name
  126.     lxi    d,fcb
  127.     lxi    b,12
  128.     call    mover        ;.from MFREQ to FCB
  129.     mvi    c,sfirst    ;Search first old one,we got it before
  130.     lxi    d,fcb
  131.     call    bdos        ;no error's expected -we got that before
  132. mfn01a:
  133.     mvi    c,snext        ;Search next
  134.     call    bdos
  135. mfn02:    push    psw
  136.     lda    mfflg2        ;get "repeat file counter"
  137.     ora    a
  138.     jz    mfn02a        ;if zero, check if SNEXT had ERROR
  139.     dcr    a        ;count down
  140.     sta    mfflg2        ;store back
  141.     pop    psw        ;no error-check, we got it before
  142.     jmp    mfn01a        ;next SNEXT
  143.  
  144. mfn02a:    pop    psw
  145.     ora    a
  146.     jm    mffi2a        ;No (more) found
  147.     call    movfcb        ;move data to fcb
  148.     lda    mfreq        ;the original disk-designator
  149.     sta    fcb        ;back into fcb
  150.     lda    mfflg1        ;get file-flag
  151.     inr    a        ;increment
  152.     sta    mfflg1        ;and store for next go-around
  153.     mvi    a,0        ;Setup FCB
  154.     sta    fcbext        ;clean up FCB for OPEN etc
  155.     sta    fcbrno
  156.     lhld    xfcbptr        ;[4] like here 
  157.     xchg
  158.     lxi    h,fcb        ;[4] from fcb space
  159.     lxi    b,12
  160.     call    mover
  161.     lhld    xfcbptr        ;[4] now lets update the pointers
  162.     lxi    d,fcblen
  163.     dad    d
  164.     shld    xfcbptr        ;[4] new pointer
  165.     lda    fcbcnt        ;[4] now the fcb counter
  166.     inr    a
  167.     sta    fcbcnt
  168.     cpi    maxfcb        ;[4] any more spare space?
  169.     jp    mfnam1        ;[4] nope, so get first fcb and return
  170.     lxi    d,fcb        ; else restore the file to serach for
  171.     lxi    h,mfreq
  172.     lxi    b,12        ; copy the original fcb to fcb
  173.     call    mover
  174.     jmp    mfn01a        ; and look for next match.
  175.  
  176. mffix1:    pop    h        ;restore registers
  177.     pop    d
  178.     pop    b
  179.     ret            ;and return
  180.  
  181. mffi2a:
  182.     sta    mfflg3        ;[4] no more FCBs from disks to be had, but
  183.     lda    fcbcnt        ;[4]we have some in the buffer, havet we?
  184.     ana    a
  185.     jnz    mfnam1        ;[4] yes, so all's ok.  Get an fcb and return,
  186.  
  187. mffix2:    xra    a
  188.     sta    mfflg3        ;[4] clear the new flag (=no more fcbs at all)
  189.     sta    mfflg2        ;[4] may as well do the others, as we're not comming again
  190.     sta    mfflg1        ;[4]
  191.     stc            ;set carry
  192.     jmp    mffix1        ;return with CARRY set
  193.  
  194. ;       copy directory entry to FCB
  195. ;       called with A/ entry number in directory (0-3)
  196. ;                   directory block in DMA buffer (buff)
  197.  
  198. movfcb:    add    a
  199.     add    a
  200.     add    a
  201.     add    a
  202.     add    a        ;* 32
  203.     mov    c,a        ; copy offset to bc
  204.     mvi    b,0        ; (high byte is zero)
  205.     lxi    h,buff        ; get start of disk buffer
  206.     dad    b        ; calculate start of directory entry
  207.     lxi    d,fcb
  208.     lxi    b,12
  209.     call    mover
  210.     ret
  211.  
  212. ;       Data storage for MFNAME (multi-file access)
  213. mfreq:    DS    12        ;Requested name
  214. mfflg1:    DB    0        ;First time thru flag for MFNAME
  215. mfflg2:    DB    0        ;Down counter for MFNAME
  216. mfflg3:    DB    0        ;[4] Non zero if no more FCBs from disk,
  217.                 ;[4] but we still have some in buffer
  218. ;
  219. IF lasm
  220.     LINK    CPSCMD
  221. ENDIF;lasm
  222.  
  223.