title	copy	utility
org	100h
wboot	equ	0
bdos	equ	5
cr	equ	13
lf	equ	10
max	equ	3
temp	equ	7fh
start:	lxi	h,stack+32
	lda	5ch
	ora	a
	lxi	d,msg7
	jz	error
	lxi	d,msg18
	cpi	max
	jnc	error
sok:	mov	b,a
	sta	cdisk
	lda	6ch
	ani	5fh
	lxi	d,msg8
	jz	error
	lxi	d,msg19
	cpi	max
	jnc	error
dok:	sta	ddisk
	cmp	b
	lxi	d,msg6
	jz	error
drvok:	lxi	h,80h
	call	admad
	lxi	d,5ch
	mvi	c,11h
	call	bdos
	inr	a
	lxi	d,msg
	jz	error
	lxi	d,fini
	db	0edh,53h
	dw	string
	db	0edh,53h
	dw	store
next:	dcr	a
	add	a
	add	a
	add	a
	add	a
	add	a
	adi	80h
	mvi	h,0
	mov	l,a
	lda	cdisk
	mov	m,a
	db	0edh,5bh
	dw	string
	lxi	b,0ch
	db	0edh,0b0h
	mvi	b,18h
	xra	a
blank:	stax	d
	inx	d
	db	10h,0fch
	db	0edh,53h
	dw	string
	lda	num
	inr	a
	sta	num
	sta	cnum
	mvi	c,12h
	call	bdos
	inr	a
	db	20h,0cbh
	lxi	d,stmsg
	call	pstr
	lxi	d,msgd
	call	pstr
	call	conin
	db	20h,15h
	mvi	a,0ffh
	sta	dup
	lxi	d,msgr
	call	pstr
	call	conin
	db	20h,05h
	mvi	a,0ffh
	sta	ro
reset:	lhld	store
	shld	string
put:	call	sprint
	call	conin
	db	28h,11h
	cpi	cr
	db	28h,23h
	cpi	lf
	db	28h,2fh
	db	0edh,5bh
	dw	store
	mvi	a,0ffh
	stax	d
	db	18h,05h
cok:	mvi	a,0ffh
	sta	trans
get:	lda	num
	dcr	a
	sta	num
	db	28h,18h
	lhld	string
	shld	store
	db	18h,0d1h
nocop:	lda	num
	lhld	store
	mov	b,a
	lxi	d,24h
	mvi	a,0ffh
ncopy:	mov	m,a
	dad	d
	db	10h,0fch
gcopy:	lda	trans
	inr	a
	jnz	boot
	lxi	d,msg9
	call	pstr
	lxi	h,fini
copy:	shld	store
	mov	a,m
	inr	a
	jz	dont
	xra	a
	sta	rdo
	call	print
	lxi	b,20h
	call	tfer
	lda	65h
	ani	7fh
	sta	65h
	call	check
	ora	a
	jz	dont
	lxi	d,5ch
	mvi	c,16h
	call	bdos
	inr	a
	lxi	d,msg2
	jz	error
made:	db	0edh,5bh
	dw	store
	mvi	c,0fh
	call	bdos
	inr	a
	db	20h,09h
	lxi	d,msg14
	call	pstr
	jmp	delt
opened:	db	0edh,5bh
	dw	store
	mvi	c,23h
	call	bdos
	lhld	store
	lxi	b,23h
	dad	b
	mov	a,m
	ora	a
	db	28h,09h
	lxi	d,msg16
	call	pstr
	jmp	delt
fok:	dcx	h
	mov	d,m
	dcx	h
	mov	e,m
	mov	a,d
	ora	e
	db	20h,09h
	lxi	d,msg17
	call	pstr
	jmp	delt
szok:	db	0edh,53h
	dw	records
	xra	a
	ora	d
	db	28h,13h
first:	xra	a
	sta	num
	sta	num+1
	call	rdwrt
	lda	records+1
	dcr	a
	sta	records+1
	db	20h,0edh
last:	lda	records
	ora	a
	db	28h,09h
	sta	num
	sta	num+1
	call	rdwrt
even:	lxi	h,1000h
	call	admad
	db	0edh,5bh
	dw	store
	mvi	c,14h
	call	bdos
	ora	a
	db	20h,09h
	lxi	d,msg3
	call	pstr
	jmp	delt
eof:	lxi	d,5ch
	mvi	c,10h
	call	bdos
	inr	a
	db	20h,4dh
	lxi	d,msg5
	call	pstr
delt:	lxi	d,5ch
	mvi	c,13h
	call	bdos
reren:	lda	rdo
	ora	a
	db	28h,25h
	db	0edh,5bh
	dw	string
	lhld	string
	lxi	b,10h
	dad	b
	xchg
	xra	a
	sta	rdo
	db	0edh,42h
	push	h
	xchg
	db	0edh,0b0h
	pop	d
	mvi	c,17h
	call	bdos
	inr	a
	db	28h,06h
	lxi	d,msg13
	call	pstr
dont:	lhld	store
	lxi	b,24h
	dad	b
	lda	cnum
	dcr	a
	sta	cnum
	jnz	copy
	jmp	boot
end1:	lxi	b,0bh
	call	tfer
	lda	65h
	ani	80h
	db	20h,08h
	lxi	d,5ch
	mvi	c,1eh
	call	bdos
notro:	lda	rdo
	ora	a
	db	28h,1dh
	lxi	h,65h
	mvi	a,temp
	mov	m,a
	inx	h
	mov	m,a
	inx	h
	mov	m,a
	lxi	d,5ch
	mvi	c,13h
	call	bdos
	inr	a
	db	20h,08h
	lxi	d,msg10
	call	pstr
	db	18h,0b4h
comp:	lxi	d,msg4
	call	pstr
	jmp	dont
rdwrt:	lxi	h,1000h
	call	admad
read:	db	0edh,5bh
	dw	store
	mvi	c,14h
	call	bdos
	ora	a
	db	28h,0ah
	pop	psw
	lxi	d,msg15
	call	pstr
	jmp	delt
okin:	call	addma
	lda	num
	dcr	a
	sta	num
	db	20h,0deh
	lxi	h,1000h
	call	admad
write:	lxi	d,5ch
	mvi	c,15h
	call	bdos
	ora	a
	db	28h,0ah
	pop	psw
	lxi	d,msg1
	call	pstr
	jmp	delt
okout:	call	addma
	lda	num+1
	dcr	a
	sta	num+1
	db	20h,0dfh
	ret
check:	lxi	h,80h
	call	admad
	lxi	d,5ch
	mvi	c,11h
	call	bdos
	mov	b,a
	inr	a
	mvi	a,0ffh
	rz
	lda	dup
	ora	a
	jz	notfer
	mov	a,b
	add	a
	add	a
	add	a
	add	a
	add	a
	adi	80h
	mvi	h,0
	mov	l,a
	lda	ddisk
	mov	m,a
	shld	string
	lxi	b,9h
	dad	b
	mov	a,m
	ani	80h
	db	28h,1fh
	lda	ro
	ora	a
	mov	a,m
	jz	rdonly
	ani	7fh
	mov	m,a
	db	0edh,5bh
	dw	string
	mvi	c,1eh
	call	bdos
	inr	a
	db	20h,08h
	lxi	d,msg10
	call	pstr
	xra	a
	ret
ren:	db	0edh,5bh
	dw	string
	lhld	string
	lxi	b,10h
	dad	b
	xchg
	db	0edh,0b0h
	lxi	b,9
	dad	b
	mvi	a,temp
	mov	m,a
	inx	h
	mov	m,a
	inx	h
	mov	m,a
	db	0edh,5bh
	dw	string
	mvi	c,17h
	call	bdos
	inr	a
	sta	rdo
	rnz
	lxi	d,msg13
	call	pstr
	xra	a
	ret
rdonly:	lxi	d,msg11
	call	pstr
	xra	a
	ret
notfer:	lxi	d,msg12
	call	pstr
	xra	a
	ret
addma:	lhld	dmadd
	lxi	b,80h
	dad	b
admad:	shld	dmadd
	xchg
	mvi	c,1ah
	jmp	bdos
pstr:	mvi	c,9
	jmp	bdos
error:	call	pstr
boot:	jmp	wboot
print:	mvi	e,cr
	call	conout
	mvi	e,lf
	call	conout
	push	h
	mov	a,m
	adi	40h
	mov	e,a
	call	conout
	mvi	e,':'
	call	conout
	mvi	b,8
pout8:	inx	h
	mov	e,m
	call	conout
	db	10h,0f9h
	mvi	e,'.'
	call	conout
	mvi	b,3
pout3:	inx	h
	mov	e,m
	call	conout
	db	10h,0f9h
	pop	h
	ret
sprint:	call	print
	mvi	e,'?'
	call	conout
	mvi	e,' '
	call	conout
	mvi	a,24h
	add	l
	mov	l,a
	db	30h,01h
	inr	h
plus1:	shld	string
	ret
tfer:	lhld	store
	inx	h
	lxi	d,5dh
	db	0edh,0b0h
	lda	ddisk
	sta	5ch
	ret
conout:	push	h
	push	b
	mvi	c,2
	call	bdos
	pop	b
	pop	h
	ret
conin:	mvi	c,1
	call	bdos
	ani	5fh
	cpi	3
	db	20h,04h
	pop	psw
	jmp	boot
isity:	cpi	'Y'
	ret
stmsg:	db	cr,lf,lf,'CP/M 2.2 Copy Utility (no verification).'
	db	cr,lf,lf,'Options:-',cr,lf,'Y or y to copy displayed file.'
	db	cr,lf,'* or (LINE FEED) to copy all files from displayed point'
	db	cr,lf,'- or (RETURN) to skip over all other files'
	db	cr,lf,'^C to reboot, no copying takes place'
	db	cr,lf,'Any other key, do not displayed file.',cr,lf,'$'
msg:	db	cr,lf,'File not found$'
msgd:	db	cr,lf,'Do you wish duplicated files deleted? Y or N $'
msgr:	db	cr,lf,'Do you wish read-only files deleted? Y or N $'
msg1:	db	cr,lf,'No more file space$'
msg2:	db	cr,lf,'No more directory space$'
msg3:	db	cr,lf,'        Read past EOF$'
msg4:	db	cr,lf,'        Transfer complete$'
msg5:	db	cr,lf,'        Fault in closing file$'
msg6:	db	cr,lf,'Same drive specified$'
msg7:	db	cr,lf,'Source drive not specified$'
msg8:	db	cr,lf,'Destination drive not specified$'
msg9:	db	cr,lf,lf,'  COPYING:-$'
msg10:	db	'        Cannot delete existing file$'
msg11:	db	'        Duplicate file is read-only$'
msg12:	db	'        File exists. No transfer$'
msg13:	db	'        Fault in duplicate file$'
msg14:	db	'        Fault in openning source$'
msg15:	db	'        Premature eof$'
msg16:	db	'        File too large$'
msg17:	db	'        Empty file$'
msg18:	db	cr,lf,'Source drive does not exist$'
msg19:	db	cr,lf,'Destination drive does not exist$'
dup:	ds	1
rdo:	ds	1
ro:	ds	1
cdisk:	ds	1
ddisk:	ds	1
trans:	ds	1
cnum:	ds	1
num:	ds	2
dmadd:	ds	2
string:	ds	2
store:	ds	2
records: ds	2
stack:	ds	3
fini:
	end
 