;------------------------------------------------------------------------------
szvip:		push	cx		;	Sz”veg t”m”r¡t‚se FS:[SI]-b“l
		push	si		;	ES:[DI]-be, CX db. byte-ot;
		push	di		;	el“t”m”r¡t‚s, zip ‚s pack k”zl
		jcxz	szvok7		;	a legjobbat v lasztja.
		push	ds
		push	es
		push	fs
		call	elbetm
		jz	szvok6
		test	uan,8
		jnz	nozip
		push	cx
		call	zip
		pop	ax
		cmp	cx,ax
		xchg	si,di
		xchg	ax,cx
		jbe	szvok1
nozip:		mov	ax,-1
szvok1:		test	uan,16
		push	ax
		jnz	nopack
		push	ds
		push	fs
		pop	ds
		call	pack
		push	ds
		cmp	cx,dx
		xchg	si,di
		pop	es
		xchg	cx,dx
		pop	ds
		jbe	szvok2
nopack:		mov	dx,-1
szvok2:		pop	ax
		cmp	dx,ax
		xchg	ax,dx
		jbe	szvok3
		cmp	dx,cx
		push	cx
		ja	szvok5
		call	zip
		pop	ax
		xchg	si,di
		xchg	ax,cx
		or	byte ptr es:[di-1],128
szvok3:		cmp	ax,cx
		jbe	szvok4
		push	cx
		and	byte ptr es:[di-1],127
szvok5:		push	ds
		mov	al,-1
		push	fs
		shr	cx,1
		stosb
		pop	ds
		jnc	csvok
		movsb
csvok:		rep	movsw
		pop	ds
		pop	ax
		inc	ax
szvok4:		xchg	ax,cx
szvok6:		pop	fs
		pop	es
		pop	ds
		inc	cx
szvok7:		pop	si
		pop	di
		pop	ax
		ret

elbetm:		push	ds
		push	fs
		pop	ds
		push	di
		xor	di,di
		cmp	cx,elmer
		push	es
		mov	es,cs:elpuf
		jbe	velb
		mov	cx,elmer
velb:		xor	dx,dx
		push	di
		mov	bx,offset cellal
		xor	ax,ax
		test	cs:uan,4
		jcxz	elbv
		jnz	elbv
celep:		push	cx
		mov	bp,3
		inc	dx
		push	si
gelep:		cmp	cs:[bx],ah
		js	gelv
		dec	cx
		lodsb
		js	celex
		cmp	al,cs:[bx]
		jne	celex
		inc	bx
		dec	bp
		jnz	gelep
gelv:		pop	ax
		pop	ax
		jmp	bebop
celex:		pop	si
		add	bx,bp
		cmp	dl,7
		pop	cx
		jb	celep
		xor	dx,dx
bebop:		jcxz	dlrok
		add	si,cx
		mov	bx,2
jehop:		dec	si
		lodsb
		cmp	al,cs:cellav[bx]
		jne	jehov
		dec	cx
		or	dl,cs:cellad[bx]
		dec	si
		jcxz	nehop
jehov:		dec	bx
		jns	jehop
		sub	si,cx
nehop:		test	cs:uan,1
		jnz	dlrok
		or	dl,dl
		mov	al,[si]
		jnz	dlrok
		cmp	al,64
		jcxz	dlrok
		ja	dlrok
		dec	ax
		dec	cx
		or	al,64
		inc	si
		mov	dl,al
dlrok:		xchg	ax,dx
elbv:		shr	cx,1
		stosb
		jnc	csehow
		movsb
csehow:		rep	movsw
		pop	si
		push	es
		mov	cx,di
		pop	ds
		sub	cx,si
		pop	es
		pop	di
		dec	cx
		push	ds
		movsb
		pop	fs
		pop	ds
		ret

cellal		db	9,19,34		;egy
		db	1,35,0		;az_
		db	1,0,-1		;a_
		db	0,-1,-1		;_
		db	1,-1,-1		;a
		db	116,-1,-1	;*o
		db	89,-1,-1	;"
cellav		db	101,99,113	;."*m
cellad		db	16,32,8

bpmaxapt:	mov	bp,elmer+2

bpmaxtom:	push	bp		;	Annyit t”m”r¡t be a sz”vegb“l,
		call	szvip		;	hogy a k‚sz k¢d max. BP legyen.
		pop	bp
		cmp	cx,bp
		mov	dx,ax
		jbe	bpoke
		shr	dx,1
		shr	dx,1
		shr	dx,1
		jnz	bpegy
		inc	dx
bpegy:		sub	ax,dx
		jb	bpnul
		xchg	si,di
		xchg	ax,cx
		jmp	bpmaxtom
bpnul:		xor	cx,cx
bpoke:		ret
;------------------------------------------------------------------------------
