	title	Convert ASCII file to upper/lower case
	name	('CONVERT')

; Program converts a text file to upper/lower case until ';'
; found. This is the delimiter for assembler comments.
; So only assembler mnemonics and labels  will  be set
; to upper/lower case, comments will stay intact. Of course
; constant text, enclosed in apostrophes, will also
; not be changed

; The default extension of the file is .MAC
; Copyright (c)	Werner Cirsovius
;		Hohe Weide 44
;		D-20253 Hamburg
;		Germany
;		Phone: +49-40-4223247
;		Version 3.4, August 1995

; To get program running use :

;		CONVERT filespec{.ext} [option]
; or		CONVERT file1=file2 [option]

; The first form may contain wildcards in filename.
; The name of the converted file(s) will not be changed.

; The options are:
;	L - to convert upper to lower case
;	U - to convert lower to upper case

NO	equ	0
YES	equ	NOT NO

@SYSL	equ	YES		; Select SYSLIB support
;@SYSL	equ	NO		; Don't select SYSLIB support

IF	@SYSL
	maclib	base80

	entry	$memry

	ext	getver,indexa,string,crlf,seterr
	ext	wrbuf,wrfcb,wrbfp,rdbfp
	ext	fparse,wcard,uppcon,curdrv,seldrv,open,create
	ext	conout,delete,rename,break,conind,conino,condir
	ext	dirmax,files,decout,fillin,closef,dskput

ELSE

	.z80
	aseg
	org	0100h

FALSE	equ	0
TRUE	equ	NOT FALSE

OS	equ	0000h
BDOS	equ	0005h
FCB	equ	005ch
CCPlen	equ	0080h
CCP	equ	CCPlen+1
DMA	equ	0080h

.string	equ	9

.fdrv	equ	 1
.fname	equ	 8
.fext	equ	 3

dirlen	equ	 16
fcblen	equ	 36
reclng	equ	128

bs	equ	08h
tab	equ	09h
lf	equ	0ah
cr	equ	0dh
eot	equ	'$'
ENDIF	;@SYSL

_exterr	equ	-1

_INVDR	equ	 0
_NOF	equ	 1
_DIFF	equ	 2
_INVCMD	equ	 3
_WILD	equ	 4
_OS	equ	 5
_HELP	equ	 6
_PARM	equ	 7
_NOPF	equ	 8
_RENER	equ	 9
_NOCR	equ	10
_DSKFUL	equ	11

U.MSK	equ	11011111b	; Upper mask
L.MSK	equ	11111111b	; Lower mask

U.BIT	equ	00000000b	; Upper bit
L.BIT	equ	00100000b	; Lower bit

_SING	equ	 1
_MULT	equ	-2

LINLEN	equ	255

	sub	a		; Test correct CPU
	jp	po,CPU.ok	; .. yeap
	ld	de,$ILL.CPU
	ld	c,.string
	call	BDOS		; Give error message
	jp	OS		; .. and exit
CPU.ok:
	ld	ix,ms.idx
	ld	(ix+0),_OS	; Set OS required
	call	getver		; Get version number
	jp	c,_error	; .. invalid
	ld	a,_exterr
	call	seterr		; Set extended error
	ld	hl,O$DMA
	ld	(wrbuf),hl	; Set write buffer
	ld	hl,O$FCB
	ld	(wrfcb),hl	; .. and file
	ld	sp,LocStk	; Get local stack
	ld	(ix+0),_HELP
	ld	a,(CCPlen)	; Test any command givven
	or	a
	jp	z,_error	; Give help if not
	call	cmd.parse	; Parse first file
	ld	(nxt.chr),a	; Save character
	cp	'='		; Test single file
	jp	nz,sing.file	; .. yeap
;
; Process different files
;
	inc	hl		; Skip assign
	ld	($PB),hl	; .. save parameter pointer
	call	log.dsk		; Log disk
	ld	(ix+0),_WILD
	bit	0,c
	jp	nz,_error	; Wildcards not allowed
	call	set.def		; Set default file extension
	ld	hl,FCB
	ld	de,O$FCB
	ld	bc,fcblen
	ldir			; Set destination file
	call	cmd.parse	; Parse source file
	call	log.dsk		; Log disk
	push	bc
	call	get.opt		; Get option
	call	set.def		; Set default file extension
	ld	(ix+0),_DIFF
	ld	de,FCB
	ld	hl,O$FCB+.fdrv
	ld	a,(hl)
	dec	hl
	cp	' '		; Test name given
	jr	nz,got.FN	; .. yeap
	ld	a,(de)
	cp	(hl)		; Verify different drives
	jp	z,_error	; Files must be different
	inc	hl
	inc	de
	ld	bc,.fname+.fext
	ex	de,hl
	ldir			; Unpack name and extension
	pop	bc
	bit	0,c		; Test wildcard
	jr	z,??files	; .. nope
	ld	a,_MULT
	call	prc.files	; Process wildcard files
	jp	OS
;
; Found second file name
;
got.FN:
	ld	bc,.fdrv+.fname+.fext
diff..:
	ld	a,(de)
	inc	de
	cpi			; Compare file names
	jr	nz,diff.fn
	jp	pe,diff..	; .. loop thru name
	jp	_error		; No file found
diff.fn:
	pop	bc		; Get back flag
	ld	(ix+0),_WILD
	bit	0,c
	jp	nz,_error	; Wildcard not allowed
??files:
	ld	(ix+0),_NOPF
	ld	de,FCB
	call	open		; Open file
	jp	c,_error	; .. not present
	ld	de,O$FCB
	call	isnew?		; Check destination file
	ld	(ix+0),_NOCR
	call	create		; Create destination file
	jp	c,_error	; Cannot create file
	ld	hl,FCB+.fdrv
	call	one.file	; Process one file
	jp	OS
;
; Process single file
;
sing.file:
	call	get.opt		; Get option
	call	set.def		; Set default file extension
	ld	a,_SING
	call	prc.files	; Process wildcard files
	jp	OS
;
; Process error pointed to by ^IX
;
_error:
	ld	a,(ix+0)	; Get message index
	ld	hl,MES$TAB
	call	indexa		; .. to table
	push	de
	pop	ix
	ld	e,(ix+0)	; Fetch message
	ld	d,(ix+1)
	call	string		; .. print it
	ld	a,(ix+2)	; Get print control
	ld	hl,PR$TAB
	call	exe.idx
	ld	a,(ix+3)	; Get action control
	ld	hl,ACT$TAB
	call	exe.idx
	call	crlf		; Give new line
	jp	OS		; .. and stop
;
; Execute routine thru index in Accu, table in ^HL
;
exe.idx:
	or	a		; Zero means no action
	ret	z
	dec	a		; .. fix index
	call	indexa		; Get table address
	ex	de,hl
	jp	(hl)
;
; Print mode 1 : Print drive
;
pr$drv:
	ld	a,(log.drv)	; Get logged drive
	add	a,'A'-1		; .. make ASCII
	call	conout		; .. print
	ld	a,':'
	call	conout		; .. delimiter follows
	ret
;
; Print mode 2 : Print source file name
;
pr$fi:
	ld	hl,FCB+.fdrv
	jr	pr$fx
;
; Print mode 3 : Print source file name
;
pr$fo:
	ld	hl,O$FCB+.fdrv
pr$fx:
	call	pr.blnk		; Give blank
	res	0,c		; Enable blanks
	call	pr$fn		; Print file name
	ret
;
; Action mode 1 : Delete and rename backup file
;
act$del:
	ld	de,O$FCB
	call	delete		; Delete file
;
; Action mode 2 : Rename backup file
;
act$ren:
	ld	a,(nxt.chr)	; Get next character
	cp	'='		; Test single file
	ret	z		; .. nope
	call	mv.FCB		; Unpack file name
	ld	hl,O$FCB+.fdrv+.fname
	ld	de,FCB+.fdrv+.fname
	ld	bc,.fext
	ldir			; .. unpack again
	ld	de,FCB
	call	rename		; Rename file
	ret
;
; Test user break
;
isbrk?:
	call	break		; Test key
	ret	nc		; .. nope
	call	conind		; Get it
	cp	'C'-'@'		; Test abort
	ret	nz		; .. nope
	ld	de,$BREAK
	call	string		; Tell user break
	jp	OS		; .. and stop
;
; Parse file and return next character
;
cmd.parse:
	ld	(ix+0),_INVCMD
	ld	de,$PB
	call	fparse		; Parse file
	jp	c,_error	; Invalid command
	ld	($PB),hl	; .. save pointer
	ld	(dot?),a	; Save dot in name
	ld	a,l
	or	h
	jp	z,_error	; .. dtto.
	ld	de,($PB+2)	; Get FCB
	call	wcard		; Test wildcard
	ld	a,(hl)		; Get next character
	res	0,c
	ret	nz		; .. no wildcard
	set	0,c		; Indicate it
	ret
;
; Set default file extension
;
set.def:
	ld	a,(dot?)	; Test dot in name
	or	a
	ret	nz		; .. yeap, skip setting
	ld	de,FCB+.fdrv+.fname
	ld	a,(de)
	cp	' '
	ret	nz
	ld	hl,$DEF
	ld	bc,.fext
	ldir			; Set default
	ret
;
; Process option from ^HL
;
get.opt:
	ld	(ix+0),_PARM
	ld	a,(hl)		; Fetch character
	cp	'['		; Verify start
	jp	nz,_error	; .. parameter error if not
	inc	hl
	ld	a,(hl)		; Get option
	call	uppcon		; .. as upper case
	ld	de,'a'*256+'z'+1
	ld	bc,U.MSK*256+U.BIT
	cp	'U'		; Verify corect option
	jr	z,got.opt
	ld	de,'A'*256+'Z'+1
	ld	bc,L.MSK*256+L.BIT
	cp	'L'
	jp	nz,_error	; Parameter error
got.opt:
	inc	hl		; Skip option
	ld	a,(hl)
	cp	']'		; Verify close
	jp	nz,_error	; Parameter error
	ld	(_MASK_),bc	; Save mask
	ld	(_RANGE_),de	; .. and range
	ret
;
; Init conversion with FCB in ^HL
;
init.conv:
	push	hl
	ld	hl,-1
	ld	(LIN.CNT),hl	; Init line count
	ld	a,FALSE
	ld	(_eof),a	; Clear EOF flag
	ld	a,0
	ld	(wrbfp),a	; Init output pointer
	ld	a,reclng
	ld	(rdbfp),a	; .. and input pointer
	ld	de,$CONV
	call	string		; Tell converting
	pop	hl
	set	0,c		; Disable blanks
	call	pr$fn		; Print file name
	ret
;
; Print file name in ^DE
; Bit 0 in reg C controls blank printing
;
pr$fn:
	call	pr$drv		; Print drive
	ld	b,.fname
	call	pr$f..		; .. name
	ld	a,'.'
	call	conout		; .. delimiter
	ld	b,.fext
	call	pr$f..		; .. and extension
;
; Print blank on console
;
pr.blnk:
	ld	a,' '
	call	conout		; Give final blank
	ret
;
; Print part of FCB in ^HL, length in reg B
;
pr$f..:
	ld	a,(hl)		; Get from FCB
	call	pr.noblank	; .. print
	inc	hl
	djnz	pr$f..
	ret
;
; Print character, blank on request only
;
pr.noblank:
	cp	' '
	jp	nz,conout	; Print if no blank
	bit	0,c
	ret	z
	jp	conout		; .. or blank on request
;
; Create file in ^DE - Check for presence
;
isnew?:
	call	open		; Test file exists
	ret	c		; .. not found
	push	de
	ex	de,hl
	inc	hl
	res	0,c		; Enable blanks
	call	pr$fn		; Print file name
	ld	de,$EXIST
	call	string		; Tell file exists
	pop	de
wt.YN:
	call	conino		; Get response
	call	uppcon		; .. as upper case
	cp	'N'		; Test character expected
	jr	z,got.YN
	cp	'Y'
	jr	nz,wt.YN
got.YN:
	ld	c,a
	call	condir		; Echo character
	call	crlf		; Give new line
	ld	a,c
	cp	'N'		; Test delete
	jp	z,OS		; .. nope, hard stop
	call	delete		; Delete file
	ret
;
; Process wildcard files
; Accu holds
;	 1 on  single  file mode
;	-2 on multiple file mode
;
prc.files:
	ld	(fn.mode),a	; .. save mode
	call	get.files	; Sample file
prc.loop:
	call	isbrk?		; Test abort
	call	nxt.file	; Get next file into FCB
	ld	(ix+0),_NOPF
	ld	de,FCB
	call	open		; Open file
	jp	c,_error	; .. not present
	ld	a,(fn.mode)
	cp	_SING		; Test single file
	jr	nz,prep.mult	; .. nope
	call	mv.FCB		; Unpack file name
	ld	hl,$BAK
	ld	de,FCB+dirlen+.fdrv+.fname
	ld	bc,.fext
	ldir			; Set $$$
	ld	hl,FCB
	ld	de,O$FCB
	ld	bc,.fdrv+.fname+.fext
	ldir
	ld	(ix+0),_RENER
	ld	de,FCB
	call	rename		; Rename file
	jp	c,_error	; .. cannot rename
	ld	hl,$BAK
	ld	de,FCB+.fdrv+.fname
	ld	bc,.fext
	ldir			; Set $$$
	ld	de,FCB
	call	open		; Open file
	jr	prep.files
prep.mult:
	ld	hl,FCB+.fdrv
	ld	de,O$FCB+.fdrv
	ld	bc,.fname+.fext
	ldir			; Unpack file
	ld	de,O$FCB
	call	delete		; Delete old file
prep.files:
	ld	(ix+0),_NOCR
	ld	de,O$FCB
	call	create		; Create file
	jp	c,_error	; Cannot create file
	ld	hl,O$FCB+.fdrv
	call	one.file	; Process one file
	ld	a,(fn.mode)
	cp	_SING		; Test single file
	ld	de,FCB
	call	z,delete	; .. delete if so
	ld	hl,(fn.cnt)
	dec	hl		; Coount down files
	ld	(fn.cnt),hl
	ld	a,l
	or	h
	jp	nz,prc.loop	; Loop on thru files
;
; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; %%% Main conversion routine %%%
; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
_CONVERT_:
	ld	a,FALSE		; Disable ..
	ld	(_CMNT),a	; .. comments
	ld	(_STRG1),a	; .. strings
	ld	(_STRG2),a
	ld	(ix+0),_DSKFUL
	call	rd.line		; Read line from file
	jp	c,eof.fnd	; .. end of file
	ld	de,(_RANGE_)	; Get range
	ld	hl,(_MASK_)	; .. and mask
	ld	bc,$LINE+1	; Point to line start
CNV.line:
	ld	a,(bc)		; Get character
	cp	''''		; Test string delimiter
	jr	z,CONV.str1
	cp	'"'
	jr	z,CONV.str2
	cp	';'		; .. comment delimiter
	jr	z,CONV.cmnt
	cp	d		; Test range
	jr	c,skp.CONV
	cp	e
	jr	nc,skp.CONV
	and	h		; .. mask out bit
	or	l		; .. insert case bit
skp.CONV:
	call	dskput		; Put to file
	jp	c,_error	; .. disk full
	ld	a,(bc)
	cp	lf		; Test new line
	jr	z,_CONVERT_	; .. try next if so
	inc	bc		; .. bump pointer
	jr	CNV.line
CONV.cmnt:
	push	af
	ld	a,(_CMNT)	; Test comment in progress
	cp	FALSE
	jr	nz,fputc	; .. yeap, put to file
dmy.mask:
	ld	hl,L.MSK*256+U.BIT	; No action mask
fputc:
	pop	af		; Get back character
	jr	skp.CONV	; .. and write it
CONV.str1:
	push	af
	ld	a,(_STRG2)	; Test in progress
	cp	TRUE
	jr	z,fputc		; .. yeap, put to file
	ld	a,(_STRG1)	; .. 2nd
	cp	FALSE
	jr	nz,chg.msk1	; .. yeap
	ld	a,h
	add	a,l
	cp	L.MSK		; Test dummy mask
	jr	z,fputc		; .. put to file if so
	ld	a,TRUE		; Set ..
	ld	(_STRG1),a	; .. string
	ld	(_CMNT),a	; .. comments
	jr	dmy.mask	; Set dummy mask
chg.msk1:
	ld	a,FALSE		; Clear ..
	ld	(_STRG1),a	; .. string
	ld	(_CMNT),a	; .. comments
	ld	hl,(_MASK_)	; Get mask
	jr	fputc		; .. then put to file
CONV.str2:
	push	af
	ld	a,(_STRG1)	; Test in progress
	cp	TRUE
	jr	z,fputc		; .. yeap, put to file
	ld	a,(_STRG2)	; Test 2nd in progress
	cp	FALSE
	jr	nz,chg.msk2	; .. yeap
	ld	a,h
	add	a,l
	cp	L.MSK		; Test dummy mask
	jr	z,fputc		; .. put to file if so
	ld	a,TRUE		; Set ..
	ld	(_STRG2),a	; .. string
	ld	(_CMNT),a	; .. comments
	jr	dmy.mask	; Set dummy mask
chg.msk2:
	ld	a,FALSE		; Clear ..
	ld	(_STRG2),a	; .. string
	ld	(_CMNT),a	; .. comments
	ld	hl,(_MASK_)	; Get mask
	jr	fputc		; .. put to file
eof.fnd:
	call	closef		; Close file
	jp	c,_error	; Disk full
	ret
;
; Log disk
;
log.dsk:
	call	ret.dsk		; Get current disk
	call	seldrv		; .. log it
	jp	c,_error	; Give help on error
	ret
;
; Return current disk, map if default
;
ret.dsk:
	ld	(ix+0),_INVDR
	ld	a,(FCB)		; Get parsed drive
	dec	a
	call	m,curdrv	; .. get current if default
	inc	a
	ld	(log.drv),a	; .. save
	dec	a
	ret
;
; Map wildcard files to normal ones into memory
;
get.files:
	call	ret.dsk		; Get current disk
	call	dirmax		; Get max directories of drive
	jp	c,_error	; Invalid drive
	ld	(ix+0),_NOF
	ld	c,l		; Unpack max count
	ld	b,h
	ld	hl,($memry)	; Fetch base memory
	ld	de,FCB
	call	files		; Sample files
	jp	c,_error	; No file
	ld	(fn.ptr),hl	; Save base address
	ld	(fn.cnt),bc	; .. and file count
	ret
;
; Get next file from memory into FCB
;
nxt.file:
	ld	hl,(fn.ptr)	; Get current pointer
	inc	hl
	ld	de,FCB
	ld	a,(log.drv)	; Get logged drive
	ld	(de),a
	inc	de
	ld	bc,.fname+.fext
	ldir
	ld	(fn.ptr),hl	; .. save new pointer
	ret
;
; Process one file with FCB in ^HL
;
one.file:
	call	init.conv	; Init conversion
	call	_CONVERT_	; Do the conversion
	ld	hl,(LIN.CNT)
	ld	de,DMA
	ld	b,eot
	call	decout		; Convert line count
	ld	de,$LIN.PRCD
	call	string		; Tell # lines processed
	ld	de,DMA
	call	string		; .. tell amount
	call	crlf		; Give new line
	ret
;
; Unpack primary file name to secondary one
;
mv.FCB:
	ld	hl,FCB
	ld	de,FCB+dirlen
	ld	bc,dirlen
	ldir			; .. just do it
	ret
;
; Read line from file, process display
; Carry set indicates end of file
;
rd.line:
	ld	a,(_eof)	; Test EOF encountered
	or	a
	jr	nz,end.file	; .. yeap, return state
	ld	hl,(LIN.CNT)
	inc	hl		; Bump line count
	ld	(LIN.CNT),hl
	ld	a,l
	and	00000011b	; .. modulo 4
	ld	c,a
	ld	b,0
	ld	hl,$DISP
	add	hl,bc
	ld	a,(hl)		; Get from table
	call	conout		; .. print
	ld	a,bs
	call	conout		; .. position cursor
	ld	de,$LINE
	ld	b,lf
	call	fillin		; Fill line from file
	ret	nc		; .. more on file
	ld	a,TRUE
	ld	(_eof),a	; Set EOF
	ret	nz
end.file:
	scf			; Mark end of file
	ret
IF	NOT	@SYSL
;
; %%SYSLIB SUPPORT STARTS
;
fillin:
	push	de
	push	hl
	push	bc
	ld	l,0
	ld	h,0
	ld	a,(de)
	ld	b,a
	inc	b
l055e:
	inc	de
	call	l0588
	jr	c,l057b
	ld	(de),a
	inc	h
	dec	b
	jr	z,l0576
	cp	0dh
	jr	z,l055e
	cp	0ah
	jr	z,l0575
	ld	l,0ffh
	jr	l055e
l0575:
	inc	de
l0576:
	ld	c,a
	ld	a,l
	or	a
	jr	l057f
l057b:
	ld	c,a
	ld	a,l
	or	a
	scf
l057f:
	ld	c,a
	pop	bc
	ld	c,a
	ex	de,hl
	ld	(hl),b
	ld	a,d
	pop	hl
	pop	de
	ret
l0588:
	jp	l0596
closef:
	call	l05a0
	ld	de,(wrfcb)
	call	nc,l0656
	ret
l0596:
	call	l05b0
	ret	c
	cp	1ah
	scf
	ret	z
	ccf
	ret
l05a0:
	ld	a,1ah
	call	dskput
	ret	c
	ld	a,(wrbfp)
	cp	80h
	jr	nz,l05a0
	jp	l05e6
l05b0:
	ld	a,(rdbfp)
	cp	80h
	jr	nz,l05d4
	push	de
	push	hl
	call	l07ea
	push	hl
	ld	de,(l0ef2)
	call	l08a3
	ld	de,(l0ef5)
	call	l067e
	pop	de
	push	af
	call	l08a3
	pop	af
	pop	hl
	pop	de
	ret	c
l05d4:
	push	de
	push	hl
	ld	d,0
	ld	e,a
	ld	hl,(l0ef2)
	add	hl,de
	inc	a
	ld	(rdbfp),a
	ld	a,(hl)
	pop	hl
	pop	de
	or	a
	ret
l05e6:
	push	bc
	push	de
	push	hl
	call	l07ea
	push	hl
	ld	de,(wrbuf)
	call	l08a3
	ld	de,(wrfcb)
	call	l0686
	pop	de
	push	af
	call	l08a3
	pop	af
	pop	hl
	pop	de
	pop	bc
	ret
dskput:
	push	bc
	ld	c,a
	ld	a,(wrbfp)
	cp	80h
	jr	nz,l0613
	call	l05e6
	jr	c,l0624
l0613:
	push	de
	push	hl
	ld	d,0
	ld	e,a
	ld	hl,(wrbuf)
	add	hl,de
	inc	a
	ld	(wrbfp),a
	ld	(hl),c
	or	a
	pop	hl
	pop	de
l0624:
	pop	bc
	ret
files:
	push	hl
	ld	hl,0
	ld	(l0efc),hl
	call	l0693
	pop	de
	ret	c
	push	de
	call	l063d
	pop	hl
	ld	bc,(l0efc)
	or	a
	ret
l063d:
	ld	a,b
	or	c
	ret	z
	dec	bc
	push	bc
	dec	hl
	ld	bc,.fdrv+.fname+.fext
	ldir
	pop	bc
	ld	hl,(l0efc)
	inc	hl
	ld	(l0efc),hl
	call	l068e
	jr	nc,l063d
	ret
l0656:
	ld	a,10h
	call	l06cc
	jp	l077e
create:
	ld	a,16h
	call	l06d4
	jp	l077e
delete:
	ld	a,13h
	call	l06cc
	jp	l077e
open:
	ld	a,0fh
	call	l06d4
	jp	l077e
rename:
	ld	a,17h
	call	l06cc
	jp	l077e
l067e:
	ld	a,14h
	call	l0722
	jp	l077e
l0686:
	ld	a,15h
	call	l0722
	jp	l077e
l068e:
	push	bc
	ld	c,12h
	jr	l0696
l0693:
	push	bc
	ld	c,11h
l0696:
	push	de
	push	bc
	ld	hl,(l0efe)
	ld	a,h
	or	l
	jr	nz,l06a7
	call	l07ea
	ld	(l0f00),hl
	jr	l06ae
l06a7:
	ld	(l0f00),hl
	ex	de,hl
	call	l08a3
l06ae:
	pop	bc
	pop	de
	push	de
	call	5
	cp	0ffh
	scf
	jr	z,l06c7
	ld	hl,(l0f00)
	ld	de,32
	inc	hl
l06c0:
	or	a
	jr	z,l06c7
	add	hl,de
	dec	a
	jr	l06c0
l06c7:
	pop	de
	pop	bc
	jp	l077e
l06cc:
	push	hl
	call	l07d8
	rla
	ld	a,h
	pop	hl
	ret
l06d4:
	push	hl
	push	ix
	push	de
	pop	ix
	ld	(ix+12),0
	ld	(ix+32),0
	call	l07d8
	rla
	ld	a,h
	pop	ix
	pop	hl
	ret
seterr:
	push	bc
	push	de
	push	hl
	ld	(l0f18),a
	ld	c,'-'
	ld	e,a
	call	5
	pop	hl
	pop	de
	pop	bc
	ret
dirmax:
	push	bc
	push	de
	push	af
	call	curdrv		; Get current drive
	ld	b,a
	pop	af
	push	bc
	call	seldrv
	jr	c,l0718
	ld	c,1fh
	call	5
	ld	de,7
	add	hl,de
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ex	de,hl
	inc	hl
	or	a
l0718:
	pop	bc
	push	af
	ld	a,b
	call	seldrv
	pop	af
	pop	de
	pop	bc
	ret
l0722:
	push	hl
	call	l07d8
	or	a
	ld	a,h
	pop	hl
	ret	z
	scf
	ret
conino:
	call	break
	jr	nc,conino
conind:
	push	bc
	push	de
	push	hl
	ld	c,6
	ld	e,0ffh
	call	5
	pop	hl
	pop	de
	pop	bc
	ret
crlf:
	push	de
	ld	de,l0f03
	call	string
	pop	de
	ret
fparse:
	call	l07f9
	ret	c
	push	bc
	push	de
	push	hl
	push	af
	jr	nz,l075f
	ld	hl,(l07f9-2)
	dec	hl
l0756:
	inc	hl
	ld	a,(hl)
	or	a
	jr	z,l075f
	cp	0dh
	jr	nz,l0756
l075f:
	ld	de,(l07f9-2)
	call	l076c
	pop	af
	ld	a,b
	pop	hl
	pop	de
	pop	bc
	ret
l076c:
	ld	b,0
	or	a
	sbc	hl,de
	ret	z
	ld	c,l
	ld	b,h
	ex	de,hl
	ld	a,'.'
	cpir
	ld	b,1
	ret	z
	dec	b
	ret
l077e:
	ret	nc
	ld	(l0f02),a
	ld	a,(l0f18)
	cp	0feh
	ld	a,(l0f02)
	ret	c
	push	hl
	ld	hl,(l0f16)
	ld	a,l
	or	h
	ld	a,(l0f02)
	jr	z,l07a2
	cp	7
	jr	c,l079c
	sub	2
l079c:
	pop	bc
	pop	bc
	ld	b,0
	ld	c,a
	jp	(hl)
l07a2:
	pop	hl
	scf
	ret
conout:
	push	bc
	push	de
	push	hl
	ld	c,2
	ld	e,a
	call	5
	pop	hl
	pop	de
	pop	bc
	ret
condir:
	push	bc
	push	de
	push	hl
	ld	c,6
	ld	e,a
	call	5
	pop	hl
	pop	de
	pop	bc
	ret
string:
	push	bc
	push	de
	push	hl
	ld	c,9
	call	5
	pop	hl
	pop	de
	pop	bc
	ret
break:
	push	bc
	push	de
	push	hl
	ld	c,0bh
	call	5
	pop	hl
	pop	de
	pop	bc
	rra
	ret
l07d8:
	push	bc
	push	de
	ld	(l0f08),a
	ld	c,a
	call	5
	ld	(l0f06),hl
	ld	(l0f06),a
	pop	de
	pop	bc
	ret
l07ea:
	push	bc
	push	de
	ld	de,l0f09
	ld	c,'1'
	call	5
	pop	de
	pop	bc
	ret
;
	dw	0
l07f9:
	push	bc
	push	de
	push	de
	ex	de,hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ld	(l07f9-2),de
	pop	de
	ld	c,98h
	call	5
	pop	de
	pop	bc
	inc	hl
	ld	a,l
	or	h
	dec	hl
	scf
	ret	z
	ld	a,l
	or	h
	ret
curdrv:
	push	bc
	push	de
	push	hl
	ld	c,19h
	call	5
	pop	hl
	pop	de
	pop	bc
	ret
seldrv:
	push	bc
	push	de
	push	hl
	ld	c,0eh
	ld	e,a
	call	5
	rla
	ld	a,h
	pop	hl
	pop	de
	pop	bc
	ret
getver:
	ld	c,0ch
	call	5
	ld	a,(vernum)
	ld	b,a
	ld	a,l
	cp	b
	ret
uppcon:
	cp	'a'
	ret	c
	cp	'z'+1
	ccf
	ret	c
	and	U.MSK
	ret
decout:
	ex	de,hl
	ld	(l0f14),hl
	ex	de,hl
	push	bc
	ld	de,l0f0c
	push	de
	ld	c,1
l0852:
	ex	(sp),hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	inc	hl
	ex	(sp),hl
	ld	b,0ffh
l085a:
	inc	b
	ld	a,l
	sub	e
	ld	l,a
	ld	a,h
	sbc	a,d
	ld	h,a
	jr	nc,l085a
	add	hl,de
	xor	a
	or	b
	jr	nz,l086b
	or	c
	jr	nz,l0879
l086b:
	ld	c,0
	or	'0'
	push	hl
	ld	hl,(l0f14)
	ld	(hl),a
	inc	hl
	ld	(l0f14),hl
	pop	hl
l0879:
	ld	a,e
	cp	0ah
	jr	nz,l0852
	ld	a,l
	or	'0'
	pop	de
	pop	bc
	ld	hl,(l0f14)
	ld	(hl),a
	inc	hl
	ld	(hl),b
	ret
indexa:
	ld	e,a
	ld	d,0
	add	hl,de
	add	hl,de
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	dec	hl
	ret
wcard:
	push	de
	push	bc
	inc	de
	ex	de,hl
	ld	bc,.fname+.fext
	ld	a,'?'
	cpir
	ex	de,hl
	pop	bc
	pop	de
	ret
l08a3:
	push	bc
	push	de
	push	hl
	ld	c,1ah
	call	5
	pop	hl
	pop	de
	pop	bc
	ret
ELSE
	dseg
ENDIF	;NOT	@SYSL
;
; DSEG starts
;
$HELP:
	db	cr,lf,tab,'CONVERT V3.4',cr,lf,lf
	db	'Call it:',cr,lf,lf
	db	tab,'CONVERT filespec{.ext} [option]',cr,lf
	db	'or',tab,'CONVERT file1=file2 [option]'
	db	cr,lf,lf
	db	'Program converts  a text  file to upper/lower'
	db	' case until '';'' found. This',cr,lf
	db	'is the delimiter for assembler comments. '
	db	'So only assembler mnemonics and',cr,lf
	db	'labels  will  be set to upper/lower  case,'
	db	' comments will stay intact. Of',cr,lf
	db	'course  constant text, enclosed in '
	db	'apostrophes, will also not be changed',cr,lf
	db	'The default extension of the file is .MAC'
	db	cr,lf,lf
	db	'The first form may contain wildcards in '
	db	'filename.',cr,lf
	db	'The name of the converted file(s) will not '
	db	'be changed.',cr,lf,lf
	db	'The options are:',cr,lf,lf
	db	'L - to convert upper to lower case',cr,lf
	db	'U - to convert lower to upper case',eot
$ILL.CPU:
	db	'Requires Z80 CPU',cr,lf,eot
$ILL.OS:
	db	'Requires CP/M 3.x or higher',eot
$NO.WILD:
	db	'No wildcard allowed in file name',eot
$ILL.CMD:
	db	'Invalid command line',eot
$ILL.OPT:
	db	'Parameter error, [U] or [L] expected',eot
$DIFF:
	db	'Files must be different in this mode',eot
$ILL.DRV:
	db	'Invalid drive select ',eot
$NO.FILE:
	db	'No file found',eot
$NO.PRST:
	db	'File not present',eot
$NO.CREC:
	db	'Cannot create file',eot
$DSK.FULL:
	db	' ',cr,lf
	db	'Disk full writing',eot
$NO.REN:
	db	'Cannot rename file',eot
$LIN.PRCD:
	db	', lines processed : ',eot
$CONV:
	db	'Converting ',eot
$EXIST:
	db	'exists, delete it [Y/N] ',eot
$BREAK:
	db	'*** User Break ***',cr,lf,eot
$DEF:
	db	'MAC'
$BAK:
	db	'$$$'
$DISP:
	db	'|/-\'
;
; Message table
;
MES$TAB:
	dw	ms00,ms01,ms02,ms03,ms04,ms05	;  0.. 5
	dw	ms06,ms07,ms08,ms09,ms0a,ms0b	;  6..11
;
PR$TAB:
	dw	pr$drv,pr$fi,pr$fo
ACT$TAB:
	dw	act$ren,act$del
;
; Message control blocks
; Byte 0,1 : Address of message
; Byte  2  : Print action (0 is none)
; Byte  3  : File action  (0 is none)
;
ms00:
	dw	$ILL.DRV
	db	1,0
ms01:
	dw	$NO.FILE
	db	2,0
ms02:
	dw	$DIFF
	db	0,0
ms03:
	dw	$ILL.CMD
	db	0,0
ms04:
	dw	$NO.WILD
	db	2,0
ms05:
	dw	$ILL.OS
	db	0,0
ms06:
	dw	$HELP
	db	0,0
ms07:
	dw	$ILL.OPT
	db	0,0
ms08:
	dw	$NO.PRST
	db	2,0
ms09:
	dw	$NO.REN
	db	2,0
ms0a:
	dw	$NO.CREC
	db	3,1
ms0b:
	dw	$DSK.FULL
	db	3,2
;
_MASK_:
	db	0,0
_RANGE_:
	db	0,0
_CMNT:
	db	FALSE
_STRG1:
	db	FALSE
_STRG2:
	db	FALSE
_eof:
	db	FALSE
dot?:
	db	0
nxt.chr:
	db	0
$memry:
IF	@SYSL
	ds	2
ELSE
	dw	__top__
ENDIF	;@SYSL
fn.ptr:
	dw	0
fn.cnt:
	dw	0
fn.mode:
	db	_SING
log.drv:
	db	0
ms.idx:
	db	0
$PB:
	dw	CCP,FCB
LIN.CNT:
	dw	-1
$LINE:
	db	LINLEN
	ds	LINLEN+1
O$DMA:
	ds	reclng
O$FCB:
	ds	fcblen
;
	ds	2*32
LocStk	equ	$
IF	NOT	@SYSL
;
; %%SYSLIB SUPPORT STARTS
;
; Read block
;
l0ef2:
	dw	DMA
rdbfp:
	db	reclng
l0ef5:
	dw	FCB
;
; Write block
;
wrbuf:
	dw	DMA
wrbfp:
	db	0
wrfcb:
	dw	FCB
;
l0efc:
	db	0,0
l0efe:
	dw	DMA
l0f00:
	db	0,0
l0f02:
	db	0
l0f03:
	db	cr,lf,eot
l0f06:
	db	0,0
l0f08:
	db	0
l0f09:
	db	3ch,0
vernum:
	db	031h
l0f0c:
	dw	10000
	dw	 1000
	dw	  100
	dw	   10
l0f14:
	db	0,0
l0f16:
	db	0,0
l0f18:
	db	0
__top__	equ	$
ENDIF	;NOT	@SYSL

	end

