.386
.model	small,c

kaland	segment	use16
assume 	cs:kaland,ds:adat

include	<parancs.asm>
include	<extern.asm>

;------------------------------------------------------------------------------
start:		mov	ax,512
		mov	bx,100000/16+1
		push	ax
		popf
		mov	ah,4ah
		push	es
		int	21h
		mov	bx,40h
		pop	ax
		mov	ds,bx
		mov	es,ax
		push	wr ds:[17h]
		mov	cx,adat
		mov	br ds:[17h],icns
		push	bx
		mov	ds,cx
		mov	ever,ax
		mov	hexan,128
		mov	s_adat,cx

		mov	s_kaland,kaland
		mov	s_iotin,iotin

		mov	wr suttog+2,cx		;	!!!!!!!!!!!!!!!!!!!
		mov	wr monte+2,cx		;	mindenhov , ahol az
		mov	wr lapoz+2,cx		;	ADAT-ban "szegmens"
		mov	wr vesacim+2,cx		;	van (=0), kln be
		mov	wr maori+2,cx		;	kell Ħrni itt!!!
		mov	wr maori+6,cx		;	(a common miatt)
		mov	wr maori+10,kaland	;	!!!!!!!!!!!!!!!!!!!

		mov	wr maorex+8,(vaori3-maori3)/2

		mov	si,offset fmeret
		mov	di,offset rovar

begin:		push	ds
		xor	ax,ax
		mov	cx,7
		pop	es
		mov	inipuf,ax
		rep	movsw
		mov	inimret,ax
		mov	cl,12
		mov	inimmax,ax
		mov	di,offset cr8ho1
		mov	imret,ax
		and	wr boot,4
		mov	file,ax
		rep	stosw
		or	wr boot,1+256
		call	medmex
		mov	cx,1
		call	billmex
		test	chewan,1
		mov	al,angol
		mov	ah,boot
		sjnz	oori
		or	al,128
oori:		push	ax
		call	xaori
maorinop:	cli
		nop
		nop
		cli
		sjmp	maorinop
maori3		label	far
		db	"MAORI3"
		pop	bx
		pushf
		or	bl,bl
		sjs	reori
		mov	angol,bl
		mov	boot,bh
reori:		call	remegsz
		and	chewan,252
		;and	mode,239
		cmp	angol,0
		mov	kiterj+23,"h"
		sje	egin
		or	chewan,2
		;or	mode,16
		mov	kiterj+23,"e"
		mov	angol,1
egin:		popf
		mov	ax,ever
		pop	es
		sjnc	xvidee
		njmp	xvidox
xviss:		pop	ax
		njmp	xvidos
xvidee:		push	bx
		push	ax
		call	proctest
		call	patkany
		call	detect
		mov	cx,1
		call	billmex
		call	randomize
		pop	es
		call	elpath
		call	helyfogl
		mov	es,parpuf
		sjc	xviss
		xor	bx,bx
		cmp	bx,wr es:[bx]
		sjne	rewad
		call	loadini
rewad:		call	readini
		call	recobbe
		pop	ax
		or	chewan,4
		or	al,al
		mov	puffer,4
		sjs	rewo
		mov	angol,al
		mov	boot,ah
rewo:		mov	ax,1
		call	msg

		push	wr own
		and	own,223
		call	fco256
		pop	wr own
		
		test	setup,3
		sjnz	etup
		mov	setup,0
etup:		call	writeini
		call	wristart
		call	saveini
		sjnc	focikl
		or	boot,4
		or	setup,8

focikl:		cmp	puffer,4
		sjae	uffer
		call	pret
uffer:		mov	al,boot
		;call	fnuscro
		or	al,al
		sjz	nfoot
		sjns	hoot
		mov	ax,boomf
		and	wr pfadat,251*(256+1)
		or	mode,128
		and	wr pfadat+2,251*(256+1)
		and	boot,124
		mov	wr smode,ax
		and	pfadat+4,251
		sjmp	focikl
nfoot:		njmp	foot
nscot:		njmp	scot
nmood:		njmp	mood
vga98:		and	al,124
		test	smode,16
		sjz	graga
		or	al,al
		sjz	nfoot
		sjmp	scoot
graga:		or	al,2
		mov	boot,al
		mov	ax,1
		xchg	ax,wr smode
		mov	boomf,ax
		njmp	csoot
hoot:		test	al,1
		sjnz	vga98
scoot:		test	al,4
		mov	bl,ablak
		sjz	nscot
		and	bx,3
		test	setup,4
		mov	al,pufabl[bx]
		sjnz	nmood
		and	al,3
		mov	inspuf,al
oov:		call	prepost
		mov	al,3*8
		call	setpath
		mov	al,10
		mov	si,offset xesa+208
		sjc	noov
		cmp	hol,3
		mov	al,2*8
		sjne	noov
		call	setpath
		mov	al,11
		mov	si,offset xesa+144
		sjc	noov
		cmp	hol,2
		sje	toov
noov:		push	si
		call	fourdsg
		pop	si
		ncall	nectar
		mov	al,12
groov:		call	fourdsg
xoov:		mov	boot,0
		mov	setup,0
		call	prepost
		call	clearlines
		mov	al,14
		sjmp	doot
toov:		call	clearlines
		mov	al,1
		ncall	lsg
		mov	si,offset xesa+208
		ncall	necter
		mov	al,2
		ncall	lsg
		mov	si,offset xesa+144
		ncall	necter
		mov	al,3
		ncall	lsg
		call	pont
		call	fourlines
		mov	al,8
		test	al,setup
		mov	setup,4
		sjz	noox
		ncall	fourdsg
noox:		mov	al,9

		cmp	nyooo,0
		sjne	doot
		or	setup,1		;teszt!!!!!
		inc	nyooo
		sjmp	doot
nyooo		db	0

doot:		ncall	fourdsg
		njmp	csoot
mood:		mov	al,percent
		cmp	al,99
		sjbe	erc
		mov	al,99
erc:		cbw
		cmp	al,tercent
		mov	tercent,al
		sje	nerc
		push	ax
		call	clearlines
		mov	al,setup
		and	al,3
		pop	bx
		sjz	nerc
		push	bx
		add	al,3
		ncall	lsg
		pop	bx
		mov	ax,-9
		call	fnyers
		call	wstring
		mov	al,7
		ncall	lsg
		call	pont
		call	fourlines
nerc:		mov	al,setup
		and	tewan,251
		test	al,3
		mov	bl,al
		sjz	scot
		mov	cl,4
		shr	ax,cl
		and	al,3
		or	bl,bl
		sjns	lefu
phuphu:		inc	ax
		and	pentan,191
		and	al,3
		sjnz	smafu
		;sikeres
		call	writeini
		call	wristart
		call	saveini
		mov	al,13
		njmp	groov
lefu:		test	bl,64
		sjnz	mofu
smafu:		cmp	al,2
		sjne	fufu
		test	al,bl
		sjz	phuphu
fufu:		push	ax
		or	al,cl
		and	setup,15
		shl	ax,cl
		or	setup,al
		pop	ax
		push	ax
		add	al,19
		ncall	fourdsg
		pop	ax
mofu:		and	ax,3
		test	pentan,64
		xchg	ax,si
		sjnz	entan
		or	si,4
entan:		mov	al,setup
		add	si,si
		and	al,3
		call	telugr[si]
		sjnc	telef
		njmp	oov
telef:		or	pentan,64
scot:		sjmp	csoot
nxoov:		njmp	xoov
foot:		cmp	setup,0			;	call	cselekves + stb.
		sjne	nxoov

		;	*******

;		mov	si,offset textov
;		mov	cx,textvg-textov
;		mov	ax,0
;		call	writepath

		cmp	oot,0
		sja	csoot
		inc	oot
		call	pont
		mov	si,offset fastpath
		ncall	kircsi
		mov	si,offset pripath
		ncall	kircsi
		mov	si,offset secpath
		ncall	kircsi
		mov	si,offset terpath
		ncall	kircsi
		mov	si,offset elnev
		ncall	kircsi
		mov	si,offset server
		ncall	kircsi
		sjmp	csoot

kircsi:		push	ds
		mov	di,offset vesa
		pop	es
		mov	cx,64
		push	di
oth:		lodsb
		xor	bx,bx
		or	al,al
		sjz	broth
stoth:		cmp	al,asctabl[bx]
		sje	stot
		inc	bx
		cmp	bl,112
		sjb	stoth
		xor	bx,bx
stot:		xchg	ax,bx
		stosb
		loop	oth
broth:		mov	si,cx
		mov	cx,64
		sub	cx,si
		pop	si
		call	wstring
		call	pont
		ret
oot		db	0		

		;	*******

csoot:		call	recobbe
		call	hatter
		and	kwan,223
		call	egbevit
		mov	ah,angol
		or	ah,ah
		mov	al,chewan
		sjz	chango
		mov	ah,2
		mov	angol,1
chango:		and	al,2
		cmp	al,ah
		sje	chee
		test	ewan,32
		mov	bl,ablak
		sjz	choo
		and	bx,3
		test	pentan,128
		mov	al,pufabl[bx]
		sjnz	choo
		and	al,3
		xor	angol,1
		mov	puffer,al
		mov	ax,25
		call	dsg
		sjmp	chee
choo:		or	chewan,1
chee:		and	pentan,127
		call	bevitel
		sjnc	fee
		cmp	si,84
		sje	vee
fee:		test	chewan,1
		sjz	ocikl
		test	boot,3
		sjz	vee
ocikl:		njmp	focikl

vee:		call	writeini
		call	wristart
		call	saveini
vidos:		test	chewan,1
		mov	al,16
		sjnz	xvidos
		mov	kwan,12
		call	setmode
xvidos:		call	clearfast
		call	vipath
		call	remegsz
xvidox:		mov	ax,40h
		test	chewan,1
		mov	es,ax
		sjnz	restart
noot:		xor	ax,ax
		test	ewan,1
		pop	wr es:[17h]
		sjz	edox
		mov	ewan,al
		int	33h
edox:		mov	ax,04c00h
		int	21h

restart:	test	chewan,4
		mov	puffer,4
		sjz	noot
repuf:		call	clrpuf
		dec	puffer
		sjns	repuf
		push	ax
		mov	si,offset rever
		xor	bp,bp
strelp:		lodsw
		xor	bx,bx
		xchg	ax,bx
		push	si
		xchg	ax,wr ds:[bx]
		or	ax,ax
		mov	es,ax
		sjz	apr
		cmp	ax,bp
		sje	apr
		inc	ax
		sjz	apr
		push	es
		push	ds
		mov	ah,49h
		int	21h
		pop	ds
		pop	bp
apr:		pop	si
		cmp	si,offset rovar
		sjb	strelp
		mov	di,offset fmeret
		njmp	begin

mebyte:		mov	al,27
mebyb:		or	dx,dx
		sjnz	ybe
		cmp	bh,4
		sjb	bybe
ybe:		shr	dx,1
		rcr	bx,1
		shr	dx,1
		rcr	bx,1
		inc	ax
		mov	bl,bh
		mov	bh,dl
		mov	dl,dh
		xor	dh,dh
		cmp	al,29
		sjb	mebyb
bybe:		push	ax
		mov	ax,-1
		call	fnyers
		call	wstring
		pop	ax

fourdsg:	mov	bl,inspuf
		cbw
		and	tewan,251
		mov	puffer,bl
		call	dsg
		ret

lsg:		cbw
		mov	puffer,ah
		call	dsg
		ret

necter:		push	si
		lodsb
		mov	bx,netterv-netter
zetor:		cmp	al,netter[bx]
		sjne	mghaz
		mov	al,35
		call	wchar
		sjmp	zeta
mghaz:		dec	bx
		sjns	zetor
zeta:		pop	si
nectar:		mov	dl,105
		call	nstring
		ret

tszh:		ncall	next
;		sjnc	sztup

		njnc	sztup		;teszt!!!!!

		mov	dl,paths+2
		mov	ah,36h
		inc	dx
		int	21h
		inc	ax
		sjz	tetup
		dec	ax
		mul	bx
		or	dh,dh
		sjnz	tetup
		or	dl,dl
		sjnz	zetup
		mul	cx
		sjmp	wetup
zetup:		mov	al,ah
		mov	ah,dl
		mul	cx
		or	dh,dh
		mov	dh,dl
		mov	dl,ah
		mov	ah,al
		sjnz	tetup
		xor	al,al
wetup:		xchg	ax,cx
		sjmp	detup
tetup:		mov	cx,-1
		mov	dx,cx
detup:
		pushad			;teszt!!!!!
		push	cx
		push	dx
		mov	bx,hennyit
		mov	dx,hennyit+2
		mov	ax,-1
		call	fnyers
		call	wstring
		call	pont
		pop	dx
		pop	bx
		mov	ax,-1
		call	fnyers
		call	wstring
		call	pont
		popad

		mov	ax,hennyit
		mov	tennyit,ax
		mov	bx,ax
		sub	ax,cx
		mov	ax,hennyit+2
		mov	tennyit+2,ax
		sbb	ax,dx
		sjb	joch
		sja	nroszh
		cmp	bx,cx
		sjb	joch
nroszh:		njmp	roszh
joch:		xor	ax,ax
		ncall	etszh
xetup:		or	setup,128
		ret
sztup:		mov	bx,file
clup:		mov	ah,3eh
		int	21h
		ret

trnd:
tgfx:
tgyb:
;		sjmp	xetup		;teszt!!!!!

		ncall	next
		mov	al,2*8
		sjc	xetup
		call	setpath
		sjc	yrwed2
		cmp	hol,2
		mov	dx,offset advnev
		mov	ah,3bh
		sjne	yrwed2
		int	21h
		mov	ax,danya
		and	al,7
		mov	ah,9
		sjz	wrenw
		mul	ah
		add	ax,offset advnev
		xchg	ax,dx
		mov	ah,3bh
		int	21h
		sjc	yrwed2
wrenw:

;		ncall	reluxa		;teszt!!!!!
		sjmp	xetup

		mov	ax,nabyb
		xor	cx,cx
		or	ax,nabyb+2
		mov	dx,offset vesa
		push	ax
		mov	ax,3c00h
		sjz	letre
		mov	ax,3d02h
letre:		int	21h
		pop	cx
		sjc	yrwed2
		mov	wile,ax
		xchg	ax,bx
		jcxz	petre
		mov	dx,nabyb
		mov	cx,nabyb+2
		mov	ax,4200h
		int	21h
petre:		mov	cx,onefile
		sjnc	etre
wyrwed:		mov	bx,wile
		ncall	clup
yrwed2:		njmp	yrwed
etre:		jcxz	optre
		push	cx
		call	begbevit
		push	ds
		xor	dx,dx
		mov	cx,fmeret
		mov	bx,file
		and	koppany,64
		mov	ds,filepuf
		mov	ah,3fh
		int	21h
		pop	ds
		xchg	ax,cx
pyrwed:		pop	bp
		sjc	wyrwed
		jcxz	optre
		push	bp
		call	begbevit
		push	ds
		mov	bx,wile
		xor	dx,dx
		;and	koppany,64
		mov	ds,filepuf
		mov	ah,40h
		int	21h
		pop	ds
		sjc	pyrwed
		cmp	ax,cx
		pop	cx
		sjne	optre
		loop	etre
optre:		mov	bx,wile
		ncall	clup
		njmp	sztup

stszh:		xor	ax,ax
		mov	tennyit,ax
		mov	tennyit+2,ax
etszh:		mov	cx,8
		mov	di,offset hennyit
htszh:		push	ds
		pop	es
		rep	stosw
		ret

strnd:		mov	dx,offset system
		sjmp	strand

stgfx:		mov	dx,offset gfx256
		ncall	strand
		sjc	scrend
		mov	dx,offset gfxhi
		ncall	strand
		sjc	scrend
		mov	dx,offset gfxtru
		sjmp	strand

roszh:		push	cx
		mov	al,15
		push	dx
		ncall	fourdsg
		mov	al,setup
		and	al,3
		add	al,3
		ncall	fourdsg
		mov	al,16
		ncall	fourdsg
		mov	bx,tennyit
		mov	dx,tennyit+2
		ncall	mebyte
		mov	al,17
		ncall	fourdsg
		pop	dx
		pop	bx
		ncall	mebyte
		mov	al,18
		sjmp	szvex

yrwed:		ncall	sztup
		sjmp	arwed

stgyb:		mov	dx,offset dox
		ncall	strand
		sjc	strend
		mov	dx,offset saves
		ncall	strand
scrend:		sjc	strend
		mov	dx,offset strt

strand:		mov	al,2*8
		push	dx
		call	setpath
		sjc	strex
stress:		cmp	hol,2
		mov	ah,3bh
		mov	dx,offset advnev
		sjne	strex
		int	21h
		sjnc	strest
		mov	ah,39h
		mov	dx,offset advnev
		int	21h
		sjnc	stress
strest:		pop	dx
		mov	ah,3bh
		push	dx
		int	21h
		pop	dx
		sjnc	strend
		push	dx
		mov	ah,39h
		int	21h
		sjnc	strest
strex:		pop	dx
arwed:		mov	al,23
szvex:		ncall	fourdsg
zsend:		stc
strend:		ret

qend:		mov	br danya,4

csend:		mov	bx,offset urfile
		xor	ax,ax
		mov	cx,5
		mov	di,offset tanya
		xchg	bx,kerofs
		ncall	htszh
		cmp	bx,offset ur000
		mov	al,setup
		mov	cl,4
		sje	csanya
		inc	br danya
csanya:		shr	ax,cl
		and	al,3
		xchg	ax,si
		mov	al,br danya
qwaxt:		cmp	al,menya[si]
		mov	ah,setup
		sjae	zsend
		cmp	al,4
		sja	next
		sjb	oxt
		and	ah,3
		cmp	ah,3
		sjb	strend
oxt:		sub	al,2
		sjb	next
		cmp	ah,2
		mov	ah,6
		sjb	qend
		mul	ah
		add	ax,offset ur000
		cmp	ax,bx
		sjne	axt
		sub	ax,6
axt:		mov	kerofs,ax

next:
;		mov	bx,danya	;teszt!!!!!
;		xor	dx,dx
;		mov	ax,-9
;		call	fnyers
;		call	wstring
;		xor	al,al
;		call	wchar
;		mov	bx,tanya
;		xor	dx,dx
;		mov	ax,-9
;		call	fnyers
;		call	wstring
;		call	pont

		mov	ax,danya
		or	al,al
		mov	cl,4
		sjnz	nuxa
		mov	al,setup
		shr	ax,cl
		mov	bx,offset urfile
		and	al,3
		xchg	ax,si
		mov	al,stenya[si]
		mov	kerofs,bx
		or	al,al
		mov	br danya,al

;		njnz	qwaxt		;teszt!!!!!

		sjnz	qwaxt
nuxa:		push	ax
		mov	al,3*8
		call	setpath
		pop	ax
		sjc	scsend
		cmp	hol,3
		mov	dx,offset advnev
		sjne	scsend
		push	ax
		mov	ah,3bh
		int	21h
		pop	ax
		and	al,7
		mov	ah,9
		sjz	wren
		mul	ah
		add	ax,offset advnev
		xchg	ax,dx
		mov	ah,3bh
		int	21h
		sjc	scsend
wren:

		ncall	reluxa		;teszt!!!!!
		sjmp	scsend

;		pushad
;		mov	al,26		;teszt!!!!!
;		ncall	fourdsg
;		popad

		mov	ax,habyb
		or	ax,habyb+2
		sjnz	zend
		inc	tanya
zend:		mov	ah,4eh
		mov	cx,tanya
		sjmp	veszta
scsend:		njmp	csend
aveszta:	mov	ah,4fh
veszta:		jcxz	scsend
		mov	bx,file
		push	cx
		mov	dx,kerofs
		xor	cx,cx
		int	21h
		pop	cx
		sjc	scsend
		push	cx
		call	nevazon
		cmp	kerofs,offset urfile
		mov	al,setup
		pop	cx
		sje	eszta
		and	al,3
		cmp	al,3
		sje	eszta
		cmp	br es:[bx],"2"
		sjae	aveszta
eszta:		push	ds
		mov	si,bx
		push	es
		mov	di,offset vesa
		mov	ax,3d00h
		pop	ds
		mov	dx,di
		pop	es
nyit:		cmp	al,[si]
		movsb
		sjne	nyit
		push	es
		pop	ds
		loop	aveszta
		int	21h
		sjc	scsend
		mov	file,ax
		xor	dx,dx
		xchg	ax,bx
		xor	cx,cx
		mov	ax,4202h
		push	bx
		int	21h
		pop	bx
		mov	cx,habyb+2
		push	dx
		mov	nabyb+2,cx
		mov	dx,habyb
		push	ax
		mov	nabyb,dx
		mov	ax,4200h
		int	21h
		mov	ax,onefile
		pop	si
		xor	bp,bp
		mul	fmeret
		sub	si,habyb
		xchg	ax,bx
		pop	di
		mov	al,br tennyit+1
		mov	ah,br tennyit+2
		sbb	di,habyb+2
		mov	cx,ax
		sjc	rext
		or	cl,br tennyit+3
		cmp	si,bx
		push	di
		sbb	di,dx
		pop	di
		sjb	keny
		sja	neun
		cmp	si,bx
		sjbe	keny
neun:		jcxz	keny
		mov	si,bx
		mov	di,dx
		inc	bp
keny:		add	hennyit,si
		mov	bx,100
		mov	dl,br tennyit+3
		adc	hennyit+2,di
		jcxz	rext
		div	bx
		xor	dh,dh
		xchg	ax,cx
		mov	dl,br hennyit+3
		mov	ah,br hennyit+2
		mov	al,br hennyit+1
		jcxz	sext
		div	cx
rext:		mov	percent,al
sext:		add	habyb,si
		adc	habyb+2,di
		or	bp,bp
		sjnz	xext
		mov	habyb,bp
		mov	habyb+2,bp
xext:		ret

reluxa:		pushf		;teszt!!!!!
		pushad
		xor	dx,dx
		mov	ah,47h
		int	21h
		mov	ax,adat
		mov	cx,64
		mov	di,offset vesa
		mov	es,ax
		push	di
		xor	dx,dx
roop:		lodsb
		xor	bx,bx
		or	al,al
		sjz	hoop
troop:		cmp	al,asctabl[bx]
		sje	joop
		inc	bx
		cmp	bx,112
		sjb	troop
		xor	bx,bx
joop:		xchg	ax,bx
		inc	dx
		stosb
		loop	roop
hoop:		push	dx
		mov	al,83
		call	wchar
		pop	cx
		pop	si
		call	wstring
		call	pont
		popad
		popf
		ret

vaori3		label	far
;------------------------------------------------------------------------------

include	<iotin.asm>
include	<adat.asm>

kaland	ends

verem	segment	use16 stack
db	384 dup(0)
verem	ends

end	start
