	title	Module from library HILIB_3 : @MID
	name	('@MID')
	maclib	baselib.lib

; Language : BASIC

; Get MID$ of a string

; Copyright (C)	Werner Cirsovius
;		Hohe Weide 44
;		D-20253 Hamburg
;		Tel.: +49-40-4223247

;		Version 1.0, August 1987

; ENTRY	Reg pair HL points to target
;	Reg pair DE points to substring
;	Reg C points to position within target
;	Reg B holds optional length of substring
;	(If zero, all to end will be copied)

; EXIT	Carry set on position error

	entry	@mid

	extrn	@copy,@leng

@mid:
	xor	a
	ld	(de),a
	ld	a,b		; Test if length here
	or	a
	jp	nz,@copy	; Copy selected characters
	call	@leng		; Get length
	ld	a,b
	sub	c		; Get length
	ld	b,a
	ret	c		; End on error
	inc	b		; Fix length
	jp	@copy

	end

