home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
enterprs
/
c128
/
text
/
examples.arc
/
MOVE.A
< prev
next >
Wrap
Text File
|
1989-12-01
|
14KB
|
318 lines
;move.asm
;==============================================================
; Command: move patternlist [d:]
;==============================================================
; Purpose: MOVE copies files between two separate disk drives.
; No provision is made for single drive users.
; MOVE cannot copy RELative files.
index1 = $0024 ;zero page pointer
strend = $0033 ;pointer to start of bank 1 buffer
fretop = $0035 ;pointer to end+1 of bank 1 buffer
status = $0090
sa = $00b9
dv = $00ba
pntr = $00ec
int01 = $1701
int04 = $1704
int05 = $1705
int08 = $1708
int09 = $1709
int0a = $170a
int0c = $170c
int0d = $170d
int16 = $1716
int17 = $1717
int0e = $170e
primm = $ff7d
tksa = $ff96
second = $ff93
talk = $ffb4
listen = $ffb1
acptr = $ffa5
untlk = $ffab
unlsn = $ffae
close = $ffc3
open = $ffc0
setlfs = $ffba
setnam = $ffbd
clrchn = $ffcc
chrin = $ffcf
chrout = $ffd2
chkin = $ffc6
chkout = $ffc9
cl = $1bf7 ;drive letter accessed by int16
star = $0b00
.wor star
* = star
jmp move
dw Date
move jsr getdes ;get destination drive
ldx #1 ;for parameter=1 to highest one
stx parm
imov jsr int16 ;get 1st match
lda cl ;save the source drive letter
sta cll
bcs nxtprm ;no matches
agin jsr copy ;copy this file
jsr int17 ;any more for this pattern
bcc agin ;yes
nxtprm inc parm ;no...move on to the next one
ldx parm
cpx hiparm
bcc imov ;until no more parameters
beq imov
lda #0 ;all went as expected...return errorlevel zero
jmp int0e
;----------------------------
; Subroutine: Main COPY loop
;----------------------------
doit lda #0 ;st=0
sta stat
jsr getbuf ;fill buffer from source file
jsr putbuf ;flush buffer to destination file
bit stat ;EOF?
bmi movx ;No..error
bvc doit ;still more
movx lda srcla ;done...close source
jsr close
lda desla ;and destination
jsr close
jsr int0c
jmp int0d ;Display DS$ and return
;------------------------------------------
; Subroutine: Fill buffer from source file
;------------------------------------------
getbuf jsr resbuf ;point to start of buffer
sty buflen ;zero # of bytes read
sty buflen+1
sty status
ldx srcla
jsr chkin
gb jsr chrin ;get char
sta $ff02 ;put in bank 1
ldy #0
sta (index1),y
sty $ff00
jsr bindex ;adjust pointer,length
inc buflen
bne gb1
inc buflen+1
gb1 bit status ;still more?
bmi gb2 ;error
bvs gb2 ;EOF
lda index1+1 ;buffer full?
cmp fretop+1
bne gb ;no
lda index1
cmp fretop
bne gb
gb2 lda status ;save ST and RTS
sta stat
jmp clrchn
;-----------------------------------------
; Subroutine: Flush buffer to output file
;-----------------------------------------
putbuf jsr resbuf ;reset buffer pointer
ldx desla
jsr chkout
pb0 lda buflen ;all done?
ora buflen+1
bne pb ;no..still more
jmp clrchn
pb sta $ff02 ;fetch from bank 1
ldy #0
lda (index1),y
sty $ff00
jsr chrout ;write it
jsr bindex ;adjust pointer,length
lda buflen
bne pb1
dec buflen+1
pb1 dec buflen
jmp pb0 ;and loop for more
resbuf lda strend ;reset buffer pointer to start
sta index1
lda strend+1
sta index1+1
ldy #0
rts
bindex inc index1 ;bump buffer pointer
bne bix
inc index1+1
bix rts
;--------------------------------------------------------------------
; Subroutine: Fetch destination drive (highest parameter or default)
;--------------------------------------------------------------------
getdes ldx #21 ;for x=21 to 0 step -1
gd1 jsr int04 ; if parameter(x) is defined use it
bcc gd0 ;otherwise next x
dex
bne gd1
gd0 cpx #0 ;just move?
bne gd2 ;no
jsr primm
.asc 13,"Syntax: move patternlist d:",13
.asc 13,"Purpose: copies files from one drive to another",13, 0
lda #1
jmp int0e
gd2 stx hiparm ;save highest parameter number
sta name ;and destination drive letter assuming its ok
jsr int05 ;check if it was d:
bcs gd9 ;no...it was just one character, use default drive
cmp #":"
bne gd9 ;wasn't d:
sta name+1
jsr int05 ;any more chars?
bcc gd9 ;yes, then its not d:
dec hiparm ;it was d:, adjust last parameter to move
rts
gd9 jsr int01 ;use default drive
sta name
lda #":"
sta name+1
rts
spur .asc "dspu"
cntcpy jsr primm
.asc " Can't copy",13, 0
rts
;-------------------------------------------------------------
; Subroutine: Setup filenames, open them and check for errors
;-------------------------------------------------------------
copy lda cll ;append s: to source filename
sta $1b01
lda #":"
sta $1b02
ldy #0
cp0 lda $1b03,y ;int16/17 puts filename here
cmp #$a0 ;end of name?
beq cp1 ;yep
sta name+2,y ;copy name to destination name
jsr chrout ;and echo to screen
iny
cpy #16
bcc cp0
cp1 lda #"," ;tag on ',type,w' to destination
sta name+2,y ;and ',type,r' to source
sta $1b03,y
iny
jsr tab ;tab(22)
lda $1b00 ;filetype from directory ($81=SEQ etc.)
and #7
cmp #0 ;deleted?
beq cntcpy ;if so, then can't copy
cmp #4 ;is it P,S or U?
bcs cntcpy ;if not, can't copy
tax ;translate to ASCII
lda spur,x
sta name+2,y
sta $1b03,y
iny
lda #","
sta name+2,y
sta $1b03,y
iny
lda #"r"
sta $1b03,y
lda #"w"
sta name+2,y
iny
iny
iny
sty fnl
tya
ldx #<$1b01 ;open source
ldy #>$1b01
jsr setnam
jsr int0a
sta srcla
jsr setlfs
jsr open
jsr int0c ;check DS
cmp #0
beq cp2 ;ok, go on
lda #" " ;otherwise just print DS$
jsr chrout
jsr int0d
lda srcla ;next file
jmp close
cp2 lda fnl ;open destination
ldx #<name
ldy #>name
jsr setnam
jsr int0a
ldy #1
sta desla
jsr setlfs
jsr open
jsr int0c ;check DS
cmp #0
beq cp4 ;OK, go on
lda #" " ;else just print ds$
jsr chrout
jsr int0d
lda desla ;next file
jmp close
cp4 jmp doit ;goto main copy loop & return from there
;---------------------
; Subroutine: TAB(22)
;---------------------
tab pha
tya
pha
txa
pha
tabb lda #" "
jsr chrout
lda pntr
cmp #22
bcc tabb
pla
tax
pla
tay
pla
rts
;------------------------
; Un-Initialized storage
;------------------------
parm *=*+1 ;parameter number (for/next index)
hiparm *=*+1 ;highest parameter to move
cll *=*+1 ;source drive letter
fnl *=*+1 ;destination filename length
name *=*+32 ;destination filename
desla *=*+1 ;save destination la
srcla *=*+1 ;save source la
srctyp *=*+1 ;source filetype
buflen *=*+2 ;number of bytes read into the buffer
stat *=*+1 ;save ST here when input buffer is full or EOF
.end