//#define MAXMARK 20;
//word markPoint[MAXMARK];
//word markCount = 0;

//#define markSize 8192
//:word markSeg;


:void fastcall resetMark()
{
	$push ds
	DS = markSeg;
	MEMSETZ(0,markSize);
	$pop ds
}

:word fastcall searchNextMark1(BX)
{
	DX = DI = -1;
	FOR(CX = 0; CX < markCount; CX++)
	{
		AX = markPoint[CX];
		IF(AX == 0) CONTINUE;
		AX--;
		IF(AX < DX) DX = AX;
		IF(AX > BX)
		{
			SI = AX;
			DI = AX - BX;
		}
	}

	IF(CX == markCount) AX = DX;
	AX++;	
}

:byte fastcall getMark1(AX)
{
	$push ds
	CX = 8;
	DX = 0;
	$div cx
	BX = AX;
	DS = CS;
	DS = markSeg;
	AL = 1 << DX & DSBYTE[BX];
	$pop ds
}

:void fastcall switchMark1(AX)
{
	$push ds
	CX = 8;
	DX = 0;
	$div cx
	BX = AX;
	DS = markSeg;
	DSBYTE[BX] ^= 1 << DX;
	$pop ds
}

:word fastcall searchNextMark2(AX)
{
	AX++;
	SI = AX;
	WHILE(AX < 65532)
	{
		$push ax
		IF(getMark(AX))
		{
			$pop ax
			return AX;
		}
		$pop ax
		AX++;
	}
	
	AX = 0;
	WHILE(AX < SI)
	{
		$push ax
		IF(getMark(AX))
		{
			$pop ax
			return AX;
		}
		$pop ax
		AX++;
	}
	return -1;
}

:byte fastcall getMarkFromSI()
{
	$push si
	SI += STRLEN(SI);
	$lodsb
	$pop si
}

:byte fastcall getMark(CX)
{
	$push si,ds
	SETLINEDSSI(CX);
//	SI += STRLEN(SI);
//	$lodsb
	getMarkFromSI();
	$pop ds,si
}

:void fastcall switchMarkFromSI()
{
	$push si
	SI += STRLEN(SI);
	DSBYTE[SI] ^= 1;
	$pop si
}

:void fastcall switchMark(CX)
{
	$push si,ds
	SETLINEDSSI(CX);
//	SI += STRLEN(SI);
//	DSBYTE[SI] ^= 1;
	switchMarkFromSI();
	$pop ds,si
}

:byte stringOne = {1,0};

:word fastcall searchNextMark4(BX)
{
	getRealPointDSSIByFile();
	AX = SI;
	$push es
	ES = DS;
	DS = CS;
	search(#stringOne,1,AX,fileSize,CaseSensitive);
	IF(AX == -1) search(#stringOne,1,0,fileSize,CaseSensitive);
	IF(AX != -1) getRealFileXY(AX);
	ELSE CX = -1;
	$pop es
	return CX;
}

:word fastcall searchNextMark(BX)
{
	$push ds
	BX++;
	SETLINEDSSI(BX);
	CX = BX;
	for(;;)
	{
		_GONEXTLINE();
		SI--;
		IF(SI > CSWORD[#fileSize])
		{
			SI = 0;
			CX = 0;
			CONTINUE;
		}
		$lodsb
		IF(AL == 1) GOTO EXIT;
		CX++;
		IF(CX == BX) 
		{
			CX = -1;
			GOTO EXIT;
		}
	}
EXIT:
	$pop ds	
	return CX;
}

:word fastcall searchNextMark3(BX)
{
	$push si,ds
	BX++;
	SETLINEDSSI(BX);
	CX = BX;
	WHILE(_GONEXTLINE() == 0)
	{
		AL = DSBYTE[SI-1];
		IF(AL == 1)
		{
			AX = CX;
			$pop ds,si
			return;
		}
		CX++;
	}
	SI = 0;
	CX = 0;
	WHILE(_GONEXTLINE() == 0) && (CX < BX)
	{
		AL = DSBYTE[SI-1];
		IF(AL == 1)
		{
			AX = CX;
			$pop ds,si
			return;
		}
		CX++;
	}
	$pop ds,si
	return -1;
}