home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm68k / msutils.lbr / COPY.SQ / COPY.S
Encoding:
Text File  |  1988-02-18  |  8.1 KB  |  284 lines

  1. *#######################################################################
  2. *          PROGRAM COPY...File Copy Utility
  3. *
  4. *            Dr. David C. Wilcox
  5. *            DCW Industries, Inc.
  6. *         5354 Palm Dr., La Canada, CA  91011
  7. *               818/790-3844
  8. *
  9. *               June 4, 1986
  10. *#####################################################################
  11. boot    equ    00        *warm boot
  12. print    equ    09        *print string
  13. curdsk    equ    25        *return current disk
  14. chain    equ    47        *chain to program
  15. lf    equ    10        *line feed
  16. cr    equ    13        *carriage return
  17. space    equ    32        *ascii space
  18. bdos    equ    $0002        *BDOS entry point
  19. *#####################################################################
  20. *  Special registers:
  21. *
  22. *    a5 = address of DMA buffer
  23. *    a6 = address of 1st parsed FCB
  24. *    d4 = number of characters in the destination file
  25. *    d5 = number of characters in the source file
  26. *    d6 = adjusted number of characters in the DMA
  27. *#####################################################################
  28. *
  29. *  Locate FCB and DMA (for portability)
  30. *
  31.     link    a6,#0        *mark stack frame
  32.     move.l    8(a6),a0    *get base page address
  33.     lea    $80(a0),a5    *get address of DMA buffer
  34.     lea    $5c(a0),a6    *get address of 1st parsed file name
  35.     clr.l    d2        *make sure d2 is empty
  36. *
  37. *  Check for no files specified
  38. *
  39.     cmpi.b    #space,$1(a6)
  40.     bne    start
  41.     move.l    #usage,d1    *if no parameters...
  42.     move.w    #print,d0    *display instructions
  43.     trap    #bdos
  44.     jsr    quit        *and exit to CP/M
  45. *
  46. start:    movea.l    a5,a1        *point to DMA
  47.     move.b    (a1)+,d6    *put total characters in d6
  48.     move.b    d6,d2        *transfer to d2 which will be counter
  49.     addq    #8,d6        *adjust for 'PIP ' and '[RV]'
  50. *
  51.     move.l    #0,d5        *get the source file name
  52.     movea.l    #source,a0
  53. sfile1:    move.b    (a1)+,(a0)+
  54.     addq    #1,d5
  55.     subq    #1,d2        *no destination given...use
  56.     beq    msdos        *the current disk and user
  57.     cmpi.b    #space,(a1)
  58.     bne    sfile1
  59.     move.b    #'[',(a0)    *append the option separator
  60.     addq    #1,d5
  61.     adda.l    #1,a1        *skip over the space
  62. *
  63.     move.l    #0,d4        *now get the destination file name
  64.     movea.l    #dest,a0
  65. dfile1:    move.b    (a1)+,(a0)+
  66.     addq    #1,d4
  67.     subq    #1,d2        *make sure we're not out of characters
  68.     blt    error        *before we find the null
  69.     cmpi.b    #0,(a1)
  70.     bne    dfile1
  71.     bra    parse
  72. *
  73. msdos:    move.b    #'[',(a0)    *append the option separator
  74.     addq    #1,d5
  75.     move.w    #curdsk,d0    *get current disk
  76.     trap    #bdos
  77.     add.b    #65,d0        *make it ascii
  78.     movea.l    #dest,a0
  79.     move.b    d0,(a0)+    *save drive designator in dest
  80.     move.b    #':',(a0)    *conclude with a ':'
  81.     move.b    #2,d4        *save character count in d4
  82.     addq.b    #2,d6        *adjust total character count
  83. *
  84. parse:    jsr    usrchk        *check for copy across user areas
  85. *
  86.     movea.l    a5,a0        *point to the dma
  87.     move.b    d6,(a0)+    *put character count in first byte
  88. *
  89.     movea.l    #cmnd,a1    *now put 'PIP ' in next four bytes
  90.     move.w    #4,d2
  91.     jsr    movmem
  92. *
  93.     movea.l    #dest,a1    *destination file goes first
  94.     move.b    d4,d2
  95.     jsr    movmem
  96. *
  97.     move.b    #'=',(a0)+    *insert the '='
  98. *
  99.     movea.l    #source,a1    *source file goes last
  100.     move.b    d5,d2
  101.     jsr    movmem
  102. *
  103.     movea.l    #option,a1    *and finally we add 'RV]'
  104.     move.w    #3,d2
  105.     jsr    movmem
  106. *
  107.     move.b    #0,(a0)        *and conclude with a null
  108. *
  109.     move.w    #chain,d0    *now let pip do the rest
  110.     trap    #bdos
  111. *#######################################################################
  112. *                           Subroutines
  113. *#######################################################################
  114. *
  115. *  Display error message and quit
  116. *
  117. error:    
  118.     move.l    #errmsg,d1
  119.     move.w    #print,d0
  120.     trap    #bdos
  121. *
  122. *  Quit to CP/M
  123. *
  124. quit:    
  125.     move.w    #boot,d0
  126.     trap    #bdos
  127. *
  128. *  Copy d2 bytes from a1 to a0
  129. movmem:    
  130.     move.b    (a1)+,(a0)+
  131.     subq    #1,d2
  132.     bne    movmem
  133.     rts
  134. *
  135. *  Check for source file user area
  136. *
  137. usrchk:    
  138.     movea.l    #source,a1
  139.     move.b    d5,d2
  140.     move.w    #1,d1
  141. schek:    cmpi.b    #':',(a1)
  142.     beq    sdrv
  143.     adda    #1,a1
  144.     addq    #1,d1
  145.     subq    #1,d2
  146.     bne    schek
  147.     bra    dchek0        *no user specified...check destination
  148. sdrv:    cmpi.b    #2,d1        *is it the logged user?
  149.     bne    sdig1        *no...check number of digits
  150.     bra    dchek0        *yes...further action not required
  151. sdig1:    cmpi.b    #3,d1        *is it a single digit user?
  152.     bne    sdig2        *no...check for two digit user
  153.     movea.l    #source+1,a1    *get the user number
  154.     move.b    (a1),suser+1    *and store it in proper location
  155.     move.b    d5,d2
  156.     subq    #2,d2
  157.     movea.l    #source+2,a1    *rearrange source file syntax
  158.     movea.l    #source+1,a0
  159.     jsr    movmem
  160.     move.w    #2,d2        *now tag on the user specification
  161.     movea.l    #suser,a1
  162.     jsr    movmem
  163.     addq    #1,d5        *and adjust the character count
  164.     addq    #1,d6
  165.     bra    dchek0
  166. sdig2:    cmpi.b    #4,d1        *is it a two digit user?
  167.     bne    error        *no...incorrect user number
  168.     movea.l    #source+1,a1    *get the two digit user number
  169.     move.b    (a1)+,suser+1    *and store it in proper location
  170.     move.b    (a1),suser+2
  171.     move.b    d5,d2
  172.     subq    #3,d2
  173.     movea.l    #source+3,a1    *rearrange source file syntax
  174.     movea.l    #source+1,a0
  175.     jsr    movmem
  176.     move.w    #3,d2        *now tag on the user specification
  177.     movea.l    #suser,a1
  178.     jsr    movmem
  179.     addq    #1,d5        *and adjust the character count
  180.     addq    #1,d6
  181. dchek0:    movea.l    #dest,a1    *check for destination file user area
  182.     move.b    d4,d2
  183.     move.w    #1,d1
  184. dchek:    cmpi.b    #':',(a1)
  185.     beq    ddrv
  186.     adda    #1,a1
  187.     addq    #1,d1
  188.     subq    #1,d2
  189.     bne    dchek
  190.     rts            *no user specified...we're all done
  191. ddrv:    cmpi.b    #2,d1        *is it the logged user?
  192.     bne    ddig1        *no...check number of digits
  193.     rts            *yes...further action not required
  194. ddig1:    cmpi.b    #3,d1        *is it a single digit user?
  195.     bne    ddig2        *no...check for two digit user
  196.     movea.l    #dest+1,a1    *get the user number
  197.     move.b    (a1),duser+2    *and store it in proper location
  198.     move.b    d4,d2
  199.     subq    #2,d2
  200.     movea.l    #dest+2,a1    *rearrange source file syntax
  201.     movea.l    #dest+1,a0
  202.     jsr    movmem
  203.     move.w    #3,d2        *now tag on the user specification
  204.     movea.l    #duser,a1
  205.     jsr    movmem
  206.     move.b    #']',(a0)    *and add a left bracket
  207.     addq    #3,d4        *and adjust the character count
  208.     addq    #3,d6
  209.     rts
  210. ddig2:    cmpi.b    #4,d1        *is it a two digit user?
  211.     bne    error        *no...incorrect user number
  212.     movea.l    #dest+1,a1    *get the two digit user number
  213.     move.b    (a1)+,duser+2    *and store it in proper location
  214.     move.b    (a1),duser+3
  215.     move.b    d4,d2
  216.     subq    #3,d2
  217.     movea.l    #dest+3,a1    *rearrange source file syntax
  218.     movea.l    #dest+1,a0
  219.     jsr    movmem
  220.     move.w    #4,d2        *now tag on the user specification
  221.     movea.l    #duser,a1
  222.     jsr    movmem
  223.     move.b    #']',(a0)    *and add a left bracket
  224.     addq    #3,d4        *and adjust the character count
  225.     addq    #3,d6
  226.     rts
  227. *#####################################################################
  228. *                          Console Messages
  229. *#####################################################################
  230. cmnd:    dc.b    'PIP '
  231. dest:    ds.b    32
  232. source:    ds.b    32
  233. duser:    dc.b    '[G',0,0
  234. suser:    dc.b    'G',0,0
  235.     even
  236. option:    dc.b    'RV]'
  237.     even
  238. usage:    dc.b    lf,cr
  239.     dc.b    '---------------------------------------'
  240.     dc.b    '---------------------------------------'
  241.     dc.b    lf,cr
  242.     dc.b    '|       Correct usage:                 '
  243.     dc.b    '                                      |'
  244.     dc.b    lf,cr
  245.     dc.b    '|                                      '
  246.     dc.b    '                                      |'
  247.     dc.b    lf,cr
  248.     dc.b    '|           COPY  {ds[us]:}source file '
  249.     dc.b    ' <{dd[ud]:}destination file>          |'
  250.     dc.b    lf,cr
  251.     dc.b    '|                                      '
  252.     dc.b    '                                      |'
  253.     dc.b    lf,cr
  254.     dc.b    '|                        ds = source drive           '
  255.     dc.b    '                        |'
  256.     dc.b    lf,cr
  257.     dc.b    '|                        us = source user number     '
  258.     dc.b    '                        |'
  259.     dc.b    lf,cr
  260.     dc.b    '|                        dd = destination drive      '
  261.     dc.b    '                        |'
  262.     dc.b    lf,cr
  263.     dc.b    '|                        ud = destination user number'
  264.     dc.b    '                        |'
  265.     dc.b    lf,cr
  266.     dc.b    '|                                      '
  267.     dc.b    '                                      |'
  268.     dc.b    lf,cr
  269.     dc.b    '|       All PIP wildcard options are supported'
  270.     dc.b    '...the copy is verified        |'
  271.     dc.b    lf,cr
  272.     dc.b    '|                                      '
  273.     dc.b    '                                      |'
  274.     dc.b    lf,cr
  275.     dc.b    '|       If destination is omitted, current drive '
  276.     dc.b    'and user are assumed        |',lf,cr
  277.     dc.b    '---------------------------------------'
  278.     dc.b    '---------------------------------------'
  279.     dc.b    lf,cr,'$'
  280.     even
  281. errmsg:    dc.b    'File name error...COPY aborted',cr,lf,'$'
  282. *#####################################################################
  283.     end
  284.