home *** CD-ROM | disk | FTP | other *** search
-
- ; RCP-CP.Z80
-
- ;=============================================================================
- ;
- ; 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 srcfile
- ; 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 file
- call bdos
- inc a ; Check for error
- jp z,prfnf ; Branch if file not found
-
- ; Make sure destination file does not already exist
-
- call logdest ; Log into destination s user area
- call extest ; Test for existence of file
- jp z,exit ; Branch if it exists
-
- ; Create destination file
-
- 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 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
- 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 of 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
- ld de,fcb1 ; Point to destination FCB
- ld c,16 ; Close file
- call bdos
- 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
-