
rutin	segment	use16
assume	cs:rutin,ds:adat

;------------------------------------------------------------------------------
patkany		proc	far		;	Eg‚r detekt l sa.
		call	minic
		mov	ax,4
		sjc	pimpa
		xor	cx,cx
		xor	dx,dx
		int	33h
		ret
pimpa:		or	iwan,3
		ret
patkany		endp

minic		proc	far		;	Eg‚r inicializ l sa.
		xor	ax,ax
		mov	es,ax
		mov	bx,es:[33h*4]
		or	bx,es:[33h*4+2]
		sjz	npatk
		int	33h
		inc	ax
		mov	bx,72
		mov	cx,80
		mov	dx,48
		mov	al,1ah
		sjnz	npatk
		int	33h
		mov	bp,s_iotin
		mov	ax,0ch
		mov	cx,127
		mov	dx,offset egirq
		mov	es,bp
		int	33h
		mov	cx,ikpuf
		mov	es,cx
		jcxz	papatk
		mov	dx,wr es:[90*2]		;	Hweger!
		xor	bx,bx
		xor	cx,cx
		or	dx,dx
		mov	ax,9
		sjz	papatk
		int	33h
papatk:		or	ewan,1
		ret
npatk:		and	ewan,252
		stc
		ret
minic		endp
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
xaori		proc	far
		mov	ax,maoris	;	XOR-ral titkos¡tott r‚szek
		sjmp	maoam		;	helyre ll¡t sa. (MAORI#...)
maolp:		add	bx,bx
		xor	cx,cx
		add	bx,bx
		xor	dx,dx
		xchg	cx,maorex[bx]
		xchg	dx,maorex[bx+2]
		sub	cx,3
		sjbe	maoam
		push	ds
		lds	bx,maori[bx]
		add	bx,6
maolp2:		xor	[bx],dx
		inc	bx
		inc	bx
		loop	maolp2
		pop	ds
maoam:		dec	ax
		mov	bx,ax
		sjns	maolp
nomaor:		and	chewan,253
		and	mode,239
		cmp	angol,0
		mov	kiterj+23,"h"
		mov	wr textov,"T<"
		mov	wr textov+2,"vo"
		mov	wr textov+4,"b "
		mov	wr textov+6,">b"
		sje	nanga
		or	chewan,2
		or	mode,16
		mov	kiterj+23,"e"
		mov	wr textov,0
		mov	wr textov+2,"M<"
		mov	wr textov+4,"ro"
		mov	wr textov+6,">e"
nanga:		cmp	fmeret,24
		sjae	jf1
		mov	fmeret,24
jf1:		cmp	utmret,16
		sjae	jf2
		mov	utmret,16
jf2:		test	chewan,4
		sjnz	nista
		call	secternam				 
nista:		call	prepost
		call	loadini
		sjc	prini
		cmp	ikpuf,0
		sje	prini
		call	readini
prini:		test	chewan,4
		mov	es,ever
		sjnz	arams
		call	params
arams:		mov	felhany,2
		sjmp	$+2
		nop
		nop
		nop
		nop
		ret
xaori		endp
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
dymem		proc	far		;	Dinamikus mem¢riafoglal shoz
		mov	bx,-1		;	a legjobb m‚retek eloszt sa.
		mov	ah,48h
		int	21h
		mov	cl,6
		mov	dx,bx
		shr	dx,cl

		mov	ax,jmeret
		mov	cl,10
		mov	si,64
		shl	jmeret,cl
		cmp	ax,si
		mov	di,-16
		sjb	jeo
		mov	ax,si
		mov	jmeret,di
jeo:		sub	dx,ax
		mov	ax,pmeret_min
		sjb	enmem2
		mov	pmeret,ax
		shl	pmeret,cl
		cmp	ax,si
		sjb	heo1
		mov	ax,si
		mov	pmeret,di
heo1:		mov	bx,pmeret_max
		sub	bx,ax
		add	ax,ax
		add	ax,ax
		add	bx,bx
		add	bx,bx
		sub	dx,ax
		mov	ax,dpszab_min
		sjb	enmem
		mov	dpszab,ax
		shl	dpszab,cl
		cmp	ax,si
		sjb	heo2
		mov	ax,si
		mov	dpszab,di
heo2:		sub	bx,ax
		add	bx,dpszab_max
		sub	dx,ax
enmem2:		sjb	enmem

		mov	cl,6
		shl	dx,cl
		xchg	ax,dx
		cwd
		cmp	bx,1
		mov	cl,4
		sjl	emeo
		div	bx
		or	ax,ax
		sjz	emeo
		cmp	ah,16
		sjb	emmok
		mov	ax,4095
emmok:		xchg	ax,bx
		shl	bx,cl
		mov	ax,pmeret_max
		sub	ax,pmeret_min
		mul	bx
		sjnc	seo1
		mov	ax,di
seo1:		add	pmeret,ax
		sjnc	meo1
		mov	pmeret,di
meo1:		mov	ax,dpszab_max
		sub	ax,dpszab_min
		mul	bx
		sjnc	seo2
		mov	ax,di
seo2:		add	ax,dpszab
		sjnc	meo2
		mov	ax,di
meo2:		test	suan,8
		sjz	leo2
		mov	ax,aptuf+1024
leo2:		mov	dpszab,ax

emeo:		clc
enmem:		ret
dymem		endp
;------------------------------------------------------------------------------

rutin	ends

param	segment	use16
assume	cs:param,ds:adat

;------------------------------------------------------------------------------
params		proc	far		;	Parancssori param‚terek
		xor	ch,ch		;	beolvas sa.
		;mov	ah,"h"
		;ncall	prams
		;sjc	cinfo
		;mov	ah,"H"
		;ncall	prams
		;sjc	cinfo
		mov	ah,"s"
		ncall	prams
		sjc	cinfo
		mov	ah,"S"
		ncall	prams
		sjc	cinfo
		mov	ah,"?"
		ncall	prams
		sjc	cinfo
		mov	di,81h
		mov	al,ah
		mov	cl,es:[di-1]
		repne	scasb
		sjne	ninfo
cinfo:		njmp	info
ninfo:		mov	ah,"n"
		ncall	prams
		sjc	vese
		mov	ah,"N"
		ncall	prams
		sjnc	nese
vese:		or	ewan,64
nese:		mov	ah,"v"
		ncall	prams
		sjc	vega
		mov	ah,"V"
		ncall	prams
		sjnc	nevga
vega:		or	ewan,128
nevga:		mov	ah,"!"
		ncall	prams
		sjnc	nemtel
		or	ewan,4
		or	boot,4
nemtel:		mov	ah,"q"
		ncall	prams
		sjc	egyedul
		mov	ah,"Q"
		ncall	prams
		;sjc	egyedul
		;mov	ah,"e"
		;ncall	prams
		;sjc	egyedul
		;mov	ah,"E"
		;ncall	prams
		sjnc	nemegye
egyedul:	or	ewan,8
nemegye:	mov	ah,"g"
		ncall	prams
		sjc	flball
		mov	ah,"G"
		ncall	prams
		sjc	flball
		mov	ah,"r"
		ncall	prams
		sjc	flball
		mov	ah,"R"
		ncall	prams
		sjnc	nemflb
flball:		and	smode,239
		jcxz	nemflb
		mov	ah,al
gserw:		inc	di
		mov	al,es:[di]
		cmp	al,ah
		sjne	gasv
		loop	gserw
gasv:		jcxz	nemflb
		mov	al,es:[di]
		sub	al,"0"
		sjb	gvan
		cmp	al,5
		sja	gvan
		mov	sfelb,al
gvan:		inc	di
		cmp	ah,es:[di]
		sjne	gasw
		loop	gvan
gasw:		jcxz	nemflb
		cmp	br es:[di],":"
		sjne	nemflb
gvan2:		inc	di
		mov	al,es:[di]
		cmp	al,ah
		sjne	gasw2
		loop	gvan2
gasw2:		jcxz	nemflb
		sub	al,"0"
		sjb	nemflb
		;sjnz	gagas
		;inc	ax
gagas:		cmp	al,3
		sja	nemflb
		mov	smode,al
nemflb:		mov	ah,"b"
		ncall	prams
		sjc	bckgnds
		mov	ah,"B"
		ncall	prams
		sjnc	nembck
bckgnds:	jcxz	nembck
		mov	ah,al
bserw:		inc	di
		mov	al,es:[di]
		cmp	al,ah
		sjne	basv
		loop	bserw
basv:		jcxz	nembck
		mov	al,es:[di]
		sub	al,"0"
		sjb	nembck
		cmp	al,5
		sja	nembck
		mov	salap,al
nembck:		mov	ah,"f"
		ncall	prams
		sjc	monokrom
		mov	ah,"F"
		ncall	prams
		sjc	monokrom
		mov	ah,"m"
		ncall	prams
		sjc	monokrom
		mov	ah,"M"
		ncall	prams
		sjnc	nemmon
monokrom:	or	mode,32
nemmon:		mov	ah,"k"
		ncall	prams
		sjc	kmegt
		mov	ah,"K"
		ncall	prams
		sjc	kmegt
		mov	ah,"t"
		ncall	prams
		sjc	kmegt
		mov	ah,"T"
		ncall	prams
		sjc	kmegt
		mov	ah,"x"
		ncall	prams
		sjc	xmegt
		mov	ah,"X"
		ncall	prams
		sjnc	nemxt
xmegt:		or	hexan,16
kmegt:		or	smode,16
nemxt:		mov	ah,"/"
		ncall	prams
		sjc	pserv
		mov	ah,"+"
		ncall	prams
		sjnc	sesveg
pserv:		mov	si,offset server
		xor	ah,ah
		jcxz	svan
pserw:		inc	di
		cmp	al,es:[di]
		sjne	sasv
		loop	pserw
sasv:		jcxz	svan
		cmp	cx,63
		sjbe	svasp
		mov	cl,63
svasp:		mov	al,es:[di]
		cmp	al,32
		mov	[si],al
		sjbe	svan
		cmp	al,"/"
		sje	svan
		inc	di
		inc	ah
		inc	si
		loop	svasp
svan:		mov	cl,64
		xor	al,al
		sub	cl,ah
svatt:		mov	[si],al
		inc	si
		loop	svatt
		sub	si,64
		dec	ax
		mov	di,si
shott:		mov	ah,al
scott:		lodsb
		cmp	al,":"
		sje	izrael
		or	al,al
		sjz	samael
		cmp	al,"A"
		sjb	muzzi
		cmp	al,"Z"
		sja	muzzi
		sub	al,"A"-"a"
muzzi:		cmp	al,"z"
		sja	scott
		sub	al,"a"
		sjb	scott
		sjmp	shott
izrael:		mov	al,"\"
		cmp	al,[si]
		sje	zrael
		mov	[di],al
dizrael:	inc	di
zrael:		lodsb
		or	al,al
		mov	[di],al
		sjnz	dizrael
samael:		mov	paths+5,ah
		or	ewan,16
		mov	inipaths+1,ah
sesveg:		sjmp	resveg
info:		mov	dx,offset manual
		mov	ah,9
		int	21h
		stc
pesveg:		mov	di,s_kaland
		mov	es,di
		mov	ax,9090h
		mov	di,offset maorinop
		stosw
		stosw
		stosw
		stosw
		stosw
		stosw
		ret
resveg:		mov	ah,"r"
		ncall	prams
		sjc	nerrast
		mov	ah,"R"
		ncall	prams
		sjnc	tetveg
nerrast:	or	tewan,2
tetveg:		mov	ah,"z"
		ncall	prams
		sjc	nemzen
		mov	ah,"Z"
		ncall	prams
		sjc	nemzen
		mov	ah,"s"
		ncall	prams
		sjc	nemzen
		mov	ah,"S"
		ncall	prams
		sjnc	atveg
nemzen:		or	tewan,16
atveg:		mov	ah,"a"
		ncall	prams
		sjc	nhszeg
		mov	ah,"A"
		sjnc	ikveg
nhszeg:		or	ewan,2
ikveg:		mov	ah,"i"
		ncall	prams
		sjc	ikki
		mov	ah,"I"
		ncall	prams
		sjnc	upveg
ikki:		or	iwan,3
upveg:		mov	ah,"u"
		ncall	prams
		sjc	uppi
		mov	ah,"U"
		ncall	prams
		sjnc	hwsveg
uppi:		or	iwan,32
hwsveg:		mov	ah,"w"
		ncall	prams
		sjc	hweger
		mov	ah,"W"
		ncall	prams
		sjnc	ssveg
hweger:		or	huan,8
ssveg:		mov	ah,"h"
		ncall	prams
		sjc	magyar
		mov	ah,"H"
		ncall	prams
		sjnc	nenga
magyar:		mov	angol,0
		and	chewan,253
		and	mode,239
nenga:		mov	ah,"e"
		ncall	prams
		sjc	english
		mov	ah,"E"
		ncall	prams
		sjnc	npesveg
english:	mov	angol,1
		or	chewan,2
		or	mode,16
npesveg:	njmp	pesveg
params		endp

prams:		mov	di,81h
		mov	cl,es:[di-1]
protv:		mov	al,"/"
		repne	scasb
		mov	al,32
		sjne	prossz
		cmp	al,es:[di]
		sjne	prasp
		inc	cx
		repe	scasb
		sje	prossz
		dec	di
prasp:		cmp	ah,es:[di]
		sjne	protv
		stc
		ret
prossz:		clc
		ret
;------------------------------------------------------------------------------

param	ends
