home *** CD-ROM | disk | FTP | other *** search
- ; Z80DOS - Z80 Disk Operating System
- ;
- ; Version 1.0 - 05 Sept. 87 by Carson Wilson
- ;
-
- ; RCP-CP.Z80 (from Z33RCP01.LBR, for ZCPR version 3.3)
-
- ; Modified for Z80DOS date stamping by Carson Wilson, Sept. 1, 1987.
-
- ; This version of CP copies Z80DOS's Get Stamp (54) and Use Stamp (55)
- ; functions to copy the source file's Z80DOS or DOS+25 format
- ; create date and modify time/date to the destination file. The
- ; last access time on both files is set to the current system time when
- ; the copy was made.
-
- ; Z80DOS' Get Stamp function saves the time stamp, if present, of a
- ; successfully opened file. The Use Stamp function can then be used
- ; to set the date and time for the next file write or close command.
-
- ; Only sections marked <crw> have been altered.
-
- Z80DOS equ true ; Copy Z80DOS stamps (costs 26 bytes)
-
- GetStp equ 54 ; Store file's date and time stamp
-
- UseStp equ 55 ; Use stored stamp for write/close
-
- ;=============================================================================
- ;
- ; F I L E C O P Y C O M M A N D
- ;
- ;=============================================================================
-
- ; Command: CP
- ; Function: Copy a file from one place to another
- ; Syntax: CP destfile srcfile, CP destfile=srcfile <crw>
- ; CP : srcfile, CP =srcfile <crw>
- ; CP . srcfile (if '.' = current dir. in CCP) <crw>
- ; Comments: Both file specifications can include a directory specification.
- ; If only one file name is given, then the current directory and
- ; the source file name are assumed for the destination.
-
- copy:
- call retsave
-
- ; If new is blank, make it the same name and type as old
-
- ld de,fcb1+1 ; Point to destination file name
- ld a,(de) ; Get first character
- cp ' ' ; If not blank (no name)
- jr nz,copy0 ; ..then branch to copy
-
- ld hl,fcb2+1 ; Copy source name into destination FCB
- ld b,11 ; Name and type are 11 bytes
- call blkmov
-
- ; See if destination is same as source, and abort if so
-
- copy0:
- ld hl,fcb1 ; Set up pointers to two files
- ld de,fcb2
- push hl
- push de
- inc hl ; Point to names of files
- inc de
- ld b,13 ; Compare 13 bytes (name, type, and user #)
- copy1:
- call comp
- jr nz,copy2 ; If they differ, go on with copy
-
- ld c,25 ; Get-current-disk BDOS function
- call bdos ; Get it in case no drive given explicitly
- inc a ; Shift to range 1..16
- ld b,a ; ..and keep value in B
- pop de ; Restore pointers to FCBs
- pop hl
- ld a,(de) ; Get drive of source file
- ld c,a ; ..and save it in C
- or a ; Is it default drive?
- jr nz,copy1a ; Branch if drive made explicit
- ld c,b ; Otherwise, copy default drive into C
- copy1a:
- ld a,(hl) ; Get drive of destination file
- or a ; Is it default drive?
- jr nz,copy1b ; Branch if drive made explicit
- ld a,b ; Otherwise, get current drive
- copy1b:
- cp c ; Compare the two drives specified
- jr nz,copy3 ; Branch if they are different
- jr cperr ; Branch to error code if they are the same
-
- copy2:
- pop de ; Clean up the stack
- pop hl
-
- ; Make note of the user numbers of the two files
-
- copy3:
- ld a,(fcb1+13) ; Get destination user number
- ld (usrdest),a
- ld a,(fcb2+13) ; Get source user number
- ld (usrsrc),a
-
- ; Set up new FCB for source file and open the source
-
- call define ; Define buffer addresses dynamically
- ld hl,(srcfcb) ; Get address to use for new source FCB
- push hl
- ex de,hl ; Copy file data to new FCB
- ld b,12
- call blkmov
- call logsrc ; Log in user number of source file
- pop hl ; Initialize the source file FCB
- call initfcb2
- ld c,15 ; Open source file
- call bdos
- inc a ; Check for error
- jp z,prfnf ; Branch if file not found
-
- if Z80DOS
- ld c,GetStp ; Save source's stamp <crw>
- call bdos
- endif
-
- ; Make sure destination file does not already exist
-
- call logdest ; Log into destination user area
- call extest ; Test for existence of file in fcb1
- jp z,exit ; Branch if it exists
-
- ; Create destination file
-
- if Z80DOS
- ld c,UseStp ; Use stored stamp <crw>
- call bdos
- endif
-
- ld de,fcb1 ; Point to destination FCB
- ld c,22 ; BDOS make-file function
- call bdos
- inc a ; Test for error (no directory space)
- jr nz,copy5 ; Branch if OK
-
- ; Report file error
-
- cperr:
- call print
- db ' Copy','?'+80h
- jp exit
-
- ; Copy source to destination with buffering
-
- ;++++++++++ this should be done by changing DMA address to save all the
- ; buffer swapping
-
- copy5:
- call logsrc ; Log in source user area
- ld b,0 ; Initialize counter
- ld hl,(cbuff) ; Initialize buffer pointer
-
- copy5a:
- push hl ; Save address and counter
- push bc
- ; ld hl,(srcfcb) ; Point to source file FCB
- ; ex de,hl ; Put it in DE for BDOS call
- ld de,(srcfcb) ; <crw>
- ld c,20 ; BDOS read-sequential function
- call bdos
- pop bc ; Get counter and address
- pop de
- or a ; Read Ok?
- jr nz,copy5b ; Branch if end of file
-
- push bc ; Save counter
- ld hl,tbuff ; Copy from 80h to buffer
- ld b,128 ; 128 bytes
- call blkmov
- ex de,hl ; HL points to next buffer address
- pop bc ; Get counter back
- inc b ; Increment it
- ld a,b ; See if buffer full
- cp cpblocks
- jr nz,copy5a ; If not, go back for more
-
- copy5b:
- ld a,b ; Get count of blocks loaded into buffer
- or a ; Are there any?
- jr z,copy6 ; Branch if not (we are done)
- push bc ; Save count
- call logdest ; Log into destination user number
- cbuff equ $+1 ; Pointer for in-the-code modification
- ld hl,0 ; Point to beginning of copy buffer
- copy5c:
- ld de,tbuff ; Copy into tbuff
- ld b,128 ; 128 bytes
- call blkmov
- push hl ; Save pointer to next block
-
- if Z80DOS
- ld c,UseStp ; Use store stamp <crw>
- call bdos
- endif
-
- ld de,fcb1 ; Point to destination file FCB
- ld c,21 ; Write the block
- call bdos
- or a
- jr nz,cperr ; Branch on error (disk full or write error)
- pop hl ; Get back pointer to next block
- pop bc ; Get count
- ;<rjj> djnz copy5 ; Work through the blocks
- dec b ; <rjj>
- jr z,copy5 ; <rjj>
- push bc ; Save count
- jr copy5c ; Back for another bufferful
-
- ; Close the destination file
-
- copy6:
- call logdest ; Log into destination user number
-
- if Z80DOS
- ld c,UseStp ; Use stored stamp for close <crw>
- call bdos
- endif
-
- ld de,fcb1 ; Point to destination FCB
-
- if Z80DOS
- push de
- pop ix ; point to s2 byte of FCB
- ld (ix+14),0 ; zero it to force close & stamp
- endif ; ..of 0-length file <crw>
-
- ld c,16 ; Close file
- call bdos
-
- inc a ; 0ffh --> 0 if error <crw>
- jr z,cperr ; close file error <crw>
-
- call print
- db ' Don','e'+80h
-
- if cpsp and spaceon
- jp spaexit ; Report space remaining on destination drive
- else
- jp exit
- endif ;cpsp and spaceon
-
- ; Log into user number of source file
-
- logsrc:
- usrsrc equ $+1 ; Pointer for in-the-code modification
- ld a,0 ; Get user number
- jr setusrrel ; Local jump to save code
-
- ; Log into user number of destination file
-
- logdest:
- usrdest equ $+1 ; Pointer for in-the-code modification
- ld a,0 ; Get user number
- setusrrel:
- jp setusr
- ;
- ; End RCP-CP.Z80
- ;