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 / BEEHIVE / OS / Z8D24SUP.ARC / RCPCP.LIÂ < prev    next >
Text File  |  1991-02-10  |  7KB  |  267 lines

  1. ; Z80DOS - Z80 Disk Operating System
  2. ;
  3. ; Version 1.0 - 05 Sept. 87 by Carson Wilson
  4. ;
  5.  
  6. ; RCP-CP.Z80 (from Z33RCP01.LBR, for ZCPR version 3.3)
  7.  
  8. ; Modified for Z80DOS date stamping by Carson Wilson, Sept. 1, 1987.
  9.  
  10. ; This version of CP copies Z80DOS's Get Stamp (54) and Use Stamp (55)
  11. ; functions to copy the source file's Z80DOS or DOS+25 format
  12. ; create date and modify time/date to the destination file.  The
  13. ; last access time on both files is set to the current system time when
  14. ; the copy was made.
  15.  
  16. ; Z80DOS' Get Stamp function saves the time stamp, if present, of a
  17. ; successfully opened file.  The Use Stamp function can then be used
  18. ; to set the date and time for the next file write or close command.
  19.  
  20. ; Only sections marked <crw> have been altered.
  21.  
  22. Z80DOS    equ    true        ; Copy Z80DOS stamps (costs 26 bytes)
  23.  
  24. GetStp    equ    54        ; Store file's date and time stamp
  25.  
  26. UseStp    equ    55        ; Use stored stamp for write/close
  27.  
  28. ;=============================================================================
  29. ;
  30. ;    F I L E    C O P Y    C O M M A N D
  31. ;
  32. ;=============================================================================
  33.  
  34. ; Command:    CP
  35. ; Function:    Copy a file from one place to another
  36. ; Syntax:    CP destfile srcfile, CP destfile=srcfile <crw>
  37. ;        CP : srcfile, CP =srcfile <crw>
  38. ;        CP . srcfile (if '.' = current dir. in CCP) <crw>
  39. ; Comments:    Both file specifications can include a directory specification.
  40. ;        If only one file name is given, then the current directory and
  41. ;        the source file name are assumed for the destination.
  42.  
  43. copy:
  44.     call    retsave
  45.  
  46. ; If new is blank, make it the same name and type as old
  47.  
  48.     ld    de,fcb1+1    ; Point to destination file name
  49.     ld    a,(de)        ; Get first character
  50.     cp    ' '        ; If not blank (no name)
  51.     jr    nz,copy0    ; ..then branch to copy
  52.  
  53.     ld    hl,fcb2+1    ; Copy source name into destination FCB
  54.     ld    b,11        ; Name and type are 11 bytes
  55.     call    blkmov
  56.  
  57. ; See if destination is same as source, and abort if so
  58.  
  59. copy0:
  60.     ld    hl,fcb1        ; Set up pointers to two files
  61.     ld    de,fcb2
  62.     push    hl
  63.     push    de
  64.     inc    hl        ; Point to names of files
  65.     inc    de
  66.     ld    b,13        ; Compare 13 bytes (name, type, and user #)
  67. copy1:
  68.     call    comp
  69.     jr    nz,copy2    ; If they differ, go on with copy
  70.  
  71.     ld    c,25        ; Get-current-disk BDOS function
  72.     call    bdos        ; Get it in case no drive given explicitly
  73.     inc    a        ; Shift to range 1..16
  74.     ld    b,a        ; ..and keep value in B
  75.     pop    de        ; Restore pointers to FCBs
  76.     pop    hl
  77.     ld    a,(de)        ; Get drive of source file
  78.     ld    c,a        ; ..and save it in C
  79.     or    a        ; Is it default drive?
  80.     jr    nz,copy1a    ; Branch if drive made explicit
  81.     ld    c,b        ; Otherwise, copy default drive into C
  82. copy1a:
  83.     ld    a,(hl)        ; Get drive of destination file
  84.     or    a        ; Is it default drive?
  85.     jr    nz,copy1b    ; Branch if drive made explicit
  86.     ld    a,b        ; Otherwise, get current drive
  87. copy1b:
  88.     cp    c        ; Compare the two drives specified
  89.     jr    nz,copy3    ; Branch if they are different
  90.     jr    cperr        ; Branch to error code if they are the same
  91.  
  92. copy2:
  93.     pop    de        ; Clean up the stack
  94.     pop    hl
  95.  
  96. ; Make note of the user numbers of the two files
  97.  
  98. copy3:
  99.     ld    a,(fcb1+13)    ; Get destination user number
  100.     ld    (usrdest),a
  101.     ld    a,(fcb2+13)    ; Get source user number
  102.     ld    (usrsrc),a
  103.  
  104. ; Set up new FCB for source file and open the source
  105.  
  106.     call    define        ; Define buffer addresses dynamically
  107.     ld    hl,(srcfcb)    ; Get address to use for new source FCB
  108.     push    hl
  109.     ex    de,hl        ; Copy file data to new FCB
  110.     ld    b,12
  111.     call    blkmov
  112.     call    logsrc        ; Log in user number of source file
  113.     pop    hl        ; Initialize the source file FCB
  114.     call    initfcb2
  115.     ld    c,15        ; Open source file
  116.     call    bdos
  117.     inc    a        ; Check for error
  118.     jp    z,prfnf        ; Branch if file not found
  119.  
  120.      if Z80DOS
  121.     ld    c,GetStp    ; Save source's stamp <crw>
  122.     call    bdos
  123.      endif
  124.  
  125. ; Make sure destination file does not already exist
  126.  
  127.     call    logdest        ; Log into destination user area
  128.     call    extest        ; Test for existence of file in fcb1
  129.     jp    z,exit        ; Branch if it exists
  130.  
  131. ; Create destination file
  132.  
  133.      if Z80DOS
  134.     ld    c,UseStp    ; Use stored stamp <crw>
  135.     call    bdos
  136.      endif
  137.  
  138.     ld    de,fcb1        ; Point to destination FCB
  139.     ld    c,22        ; BDOS make-file function
  140.     call    bdos
  141.     inc    a        ; Test for error (no directory space)
  142.     jr    nz,copy5    ; Branch if OK
  143.  
  144. ; Report file error
  145.  
  146. cperr:
  147.     call    print
  148.     db    ' Copy','?'+80h
  149.     jp    exit
  150.  
  151. ; Copy source to destination with buffering
  152.  
  153. ;++++++++++ this should be done by changing DMA address to save all the
  154. ;        buffer swapping
  155.  
  156. copy5:
  157.     call    logsrc        ; Log in source user area
  158.     ld    b,0        ; Initialize counter
  159.     ld    hl,(cbuff)    ; Initialize buffer pointer
  160.  
  161. copy5a:
  162.     push    hl        ; Save address and counter
  163.     push    bc
  164. ;    ld    hl,(srcfcb)    ; Point to source file FCB
  165. ;    ex    de,hl        ; Put it in DE for BDOS call
  166.     ld    de,(srcfcb)    ; <crw>
  167.     ld    c,20        ; BDOS read-sequential function
  168.     call    bdos
  169.     pop    bc        ; Get counter and address
  170.     pop    de
  171.     or    a        ; Read Ok?
  172.     jr    nz,copy5b    ; Branch if end of file
  173.  
  174.     push    bc        ; Save counter
  175.     ld    hl,tbuff    ; Copy from 80h to buffer
  176.     ld    b,128        ; 128 bytes
  177.     call    blkmov
  178.     ex    de,hl        ; HL points to next buffer address
  179.     pop    bc        ; Get counter back
  180.     inc    b        ; Increment it
  181.     ld    a,b        ; See if buffer full
  182.     cp    cpblocks
  183.     jr    nz,copy5a    ; If not, go back for more
  184.  
  185. copy5b:
  186.     ld    a,b        ; Get count of blocks loaded into buffer
  187.     or    a        ; Are there any?
  188.     jr    z,copy6        ; Branch if not (we are done)
  189.     push    bc        ; Save count
  190.     call    logdest        ; Log into destination user number
  191. cbuff    equ    $+1        ; Pointer for in-the-code modification
  192.     ld    hl,0        ; Point to beginning of copy buffer
  193. copy5c:
  194.     ld    de,tbuff    ; Copy into tbuff
  195.     ld    b,128        ; 128 bytes
  196.     call    blkmov
  197.     push    hl        ; Save pointer to next block
  198.  
  199.      if Z80DOS
  200.     ld    c,UseStp    ; Use store stamp <crw>
  201.     call    bdos
  202.      endif
  203.  
  204.     ld    de,fcb1        ; Point to destination file FCB
  205.     ld    c,21        ; Write the block
  206.     call    bdos
  207.     or    a
  208.     jr    nz,cperr    ; Branch on error (disk full or write error)
  209.     pop    hl        ; Get back pointer to next block
  210.     pop    bc        ; Get count
  211. ;<rjj>    djnz    copy5        ; Work through the blocks
  212.     dec    b        ; <rjj>
  213.     jr    z,copy5        ; <rjj>
  214.     push    bc        ; Save count
  215.     jr    copy5c        ; Back for another bufferful
  216.  
  217. ; Close the destination file
  218.  
  219. copy6:
  220.     call    logdest        ; Log into destination user number
  221.  
  222.      if Z80DOS
  223.     ld    c,UseStp    ; Use stored stamp for close <crw>
  224.     call    bdos
  225.      endif
  226.  
  227.     ld    de,fcb1        ; Point to destination FCB
  228.  
  229.      if Z80DOS
  230.     push    de
  231.     pop    ix        ; point to s2 byte of FCB
  232.     ld    (ix+14),0    ; zero it to force close & stamp
  233.      endif            ; ..of 0-length file <crw>
  234.  
  235.     ld    c,16        ; Close file
  236.     call    bdos
  237.  
  238.     inc    a        ; 0ffh --> 0 if error <crw>
  239.     jr    z,cperr        ; close file error <crw>
  240.  
  241.     call    print
  242.     db    ' Don','e'+80h
  243.  
  244.      if    cpsp and spaceon
  245.     jp    spaexit        ; Report space remaining on destination drive
  246.      else
  247.     jp    exit
  248.      endif    ;cpsp and spaceon
  249.  
  250. ; Log into user number of source file
  251.  
  252. logsrc:
  253. usrsrc    equ    $+1        ; Pointer for in-the-code modification
  254.     ld    a,0        ; Get user number
  255.     jr    setusrrel    ; Local jump to save code
  256.  
  257. ; Log into user number of destination file
  258.  
  259. logdest:
  260. usrdest    equ    $+1        ; Pointer for in-the-code modification
  261.     ld    a,0        ; Get user number
  262. setusrrel:
  263.     jp    setusr
  264. ;
  265. ; End RCP-CP.Z80
  266. ;
  267.