⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m2b4_fil.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 2 页
字号:
		firstOffset = 0x03;
	}
	else
	{	/* 4 bpp */
		flipMask = 1;
		shiftMask = 0xf0;
		firstOffset = 0x01;
	}

	lclLineCnt = dRect.Ymax - dRect.Ymin - 1;
	dstBgnByte = (dRect.Xmin >> flipMask);
	pxShift =  (dRect.Xmin & firstOffset) * shfCnt;
	byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
	ptrnY = dRect.Ymin % patHeight;	/* start of pattern allignment */
	ptrnY *= patWidthInBytes;
	lclShift = (flipMask << 1);
	while (lclLineCnt-- >= 0)
	{	/* for each row */
		dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
			+ dstBgnByte;
		ptrnX = dstBgnByte % patWidthInBytes;
		lclByteCnt = byteCntM1;
		/* check if first pixel aligned */
		if (pxShift != 0)
		{	/* no, align it */
			pxBit = (byte) (shiftMask >> pxShift);
			while (pxBit > 0)
			{
				pxColor = (savePat->imData[ptrnX + ptrnY] & pxBit);
				*dstPtr = (*dstPtr & ~pxBit) | pxColor;
				pxBit = (pxBit >> shfCnt);
				lclByteCnt--;
				if (lclByteCnt < 0) break;
			}
			dstPtr++;
			ptrnX++;
			if (ptrnX == patWidthInBytes) ptrnX = 0;
		}
		/* do the whole bytes */
		while (lclByteCnt >= lclShift)
		{	/* for each byte in the row */
			*dstPtr = savePat->imData[ptrnX + ptrnY];
			dstPtr++;
			ptrnX++;
			if (ptrnX == patWidthInBytes) ptrnX = 0;
			lclByteCnt -= lclShift;
		}
		/* do the last pixels if any */
		if (lclByteCnt >= 0)
		{
			if (shfCnt == 2)
			{
				pxBit = 0xc0;
			}
			else
			{
				pxBit = 0xf0;
			}
			while (lclByteCnt-- >= 0)
			{
				pxColor = (savePat->imData[ptrnX + ptrnY] & pxBit);
				*dstPtr = (*dstPtr & ~pxBit) | pxColor;
				pxBit = (pxBit >> shfCnt);
			}
		}
		
		ptrnY += patWidthInBytes;
		if (ptrnY == patLength) ptrnY = 0;
	}

	return;
}


/* Function SolidFillRect fills the rectangle in memory */
void SolidFillRectM2_4B(blitRcd *blitRec)
{

	lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
	dstBgnByte = (dRect.Xmin >> flipMask);
	byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
	if (shfCnt == 2)
	{	/* 2 bpp */
		pnColr = pnColr & 0x03;
		pnColr = pnColr | (pnColr << 2);
		pnColr = pnColr | (pnColr << 4);
		bkColr = bkColr & 0x03;
		bkColr = bkColr | (bkColr << 2);
		bkColr = bkColr | (bkColr << 4);
	}
	else
	{	/* 4 bpp */
		pnColr = pnColr & 0x0f;
		pnColr = pnColr | (pnColr << 4);
		bkColr = bkColr & 0x0f;
		bkColr = bkColr | (bkColr << 4);
	}

	optPtr();	/* blit the rectangle */

	return;
}


/* Function InvertDestM2_4B inverts the destination pixel data. */
void InvertDestM2_4B(void)
{
	short lclYmin, lclShift;
	int lclLineCnt, lclByteCnt;
	int pxShift;
	byte pxBit;

	lclLineCnt = lineCntM1;
	lclYmin = dRect.Ymin;
	pxShift =  (dRect.Xmin & firstOffset) * shfCnt;
	lclShift = (flipMask << 1);

	while (lclLineCnt-- >= 0)
	{	/* for each row */
		dstPtr = (byte *) (*(dstBmap->mapTable[0] + lclYmin))
			+ dstBgnByte;
		lclByteCnt = byteCntM1;
		/* check if first pixel aligned */
		if (pxShift != 0)
		{	/* no, align it */
			pxBit = (byte) (shiftMask >> pxShift);
			while (pxBit > 0)
			{
				*dstPtr = *dstPtr ^ pxBit;
				pxBit = (pxBit >> shfCnt);
				lclByteCnt--;
				if (lclByteCnt < 0) break;
			}
			dstPtr++;
		}
		/* do the whole bytes */
		while (lclByteCnt >= lclShift)
		{	/* for each byte in the row */
			*dstPtr = ~*dstPtr;
			dstPtr++;
			lclByteCnt -= lclShift;
		}
		/* do the last pixels if any */
		if (lclByteCnt >= 0)
		{
			if (shfCnt == 2)
			{
				pxBit = 0xc0;
			}
			else
			{
				pxBit = 0xf0;
			}
			while (lclByteCnt-- >= 0)
			{
				*dstPtr = *dstPtr ^ pxBit;
				pxBit = (pxBit >> shfCnt);
			}
		}

		lclYmin++;	/* advance to next row */
	}

	return;
}


/* Function SetDestM2_4B sets the destination pixel data. */
void SetDestM2_4B(void)
{
	int lclLineCnt, lclByteCnt;
	int pxShift, lclShift;
	byte pxBit;

	lclLineCnt = lineCntM1;
	pxShift =  (dRect.Xmin & firstOffset) * shfCnt;
	lclShift = (flipMask << 1);
	while (lclLineCnt-- >= 0)
	{	/* for each row */
		dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
			+ dstBgnByte;
		lclByteCnt = byteCntM1;
		/* check if first pixel aligned */
		if (pxShift != 0)
		{	/* no, align it */
			pxBit = (byte) (shiftMask >> pxShift);
			while (pxBit > 0)
			{
				*dstPtr = (*dstPtr & ~pxBit) | (pxBit & pnColr);
				pxBit = (pxBit >> shfCnt);
				lclByteCnt--;
				if (lclByteCnt < 0) break;
			}
			dstPtr++;
		}
		/* do the whole bytes */
		while (lclByteCnt >= lclShift)
		{	/* for each byte in the row */
			*dstPtr = pnColr;
			dstPtr++;
			lclByteCnt -= lclShift;
		}
		/* do the last pixels if any */
		if (lclByteCnt >= 0)
		{
			if (shfCnt == 2)
			{
				pxBit = 0xc0;
			}
			else
			{
				pxBit = 0xf0;
			}
			while (lclByteCnt-- >= 0)
			{
				*dstPtr = (*dstPtr & ~pxBit) | (pxBit & pnColr);
				pxBit = (pxBit >> shfCnt);
			}
		}

		dRect.Ymin++;	/* advance to next row */
	}

	return;
}


/* Function NotDestFillM2_4B handles memory "not dst" by inverting the
destination first. */
void NotDestFillM2_4B(void)
{
	void InvertDestM2_4B(void);
	void FillOXADestM2_4B(void);

	InvertDestM2_4B();

	FillOXADestM2_4B();	/* fill this rectangle */

	return;
}


/* Function NotDestMonoFillM2_4B handles memory "not dst" by inverting
the destination first. */
void NotDestMonoFillM2_4B(void)
{
	void InvertDestM2_4B(void);
	void MonoFillOXADestM2_4B(void);

	InvertDestM2_4B();

	MonoFillOXADestM2_4B();	/* fill this rectangle */

	return;
}


/* Function MonoFillDestM2_4B sets the destination pixel data to pnColr
if the source is 1 else bkColr. */
void MonoFillDestM2_4B(void)
{
	int lclLineCnt, lclByteCnt;
	int ptrnX, ptrnY, ptrnByte, ptrnBt, ptrnColr;
	int pxShift;
	byte pxBit;

	lclLineCnt = lineCntM1;
	ptrnY = dRect.Ymin % patHeight;	/* start of pattern allignment */
	ptrnY *= patWidthInBytes;
	pxShift =  (dRect.Xmin & firstOffset) * shfCnt;
	while (lclLineCnt-- >= 0)
	{	/* for each row */
		ptrnX = dRect.Xmin % patWidthInBytes;
		ptrnBt = (128 >> (dRect.Xmin & 7));
		ptrnByte = savePat->imData[ptrnX + ptrnY];
		dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
			+ dstBgnByte;
		lclByteCnt = byteCntM1;
		pxBit = (byte) (shiftMask >> pxShift);
		while (lclByteCnt-- >= 0)
		{
			if (ptrnByte & ptrnBt)
			{
				ptrnColr = pnColr;
			}
			else
			{
				ptrnColr = bkColr;
			}

			*dstPtr = (*dstPtr & ~pxBit) | (pxBit & ptrnColr);
			pxBit = (pxBit >> shfCnt);
			if (pxBit == 0)
			{	/* advance to next byte */
				dstPtr++;
				if (shfCnt == 2)
				{
					pxBit = 0xc0;
				}
				else
				{
					pxBit = 0xf0;
				}
			}

			ptrnBt = ptrnBt >> 1;
			if (ptrnBt == 0)
			{
				ptrnBt = 128;
				ptrnX++;
				if (ptrnX == patWidthInBytes) ptrnX = 0;
				ptrnByte = savePat->imData[ptrnX + ptrnY];
			}
		}

		dRect.Ymin++;	/* advance to next row */
		ptrnY += patWidthInBytes;
		if (ptrnY == patLength) ptrnY = 0;
	}

	return;
}


/* Function FillOXADestM2_4B sets the destination pixel data based on
the logical function "OR", "XOR" or "AND". */
void FillOXADestM2_4B(void)
{
	int lclLineCnt, lclByteCnt;
	int pxShift, lclShift;
	byte pxBit;
	int logFnc;

	lclLineCnt = lineCntM1;
	pxShift =  (dRect.Xmin & firstOffset) * shfCnt;
	lclShift = (flipMask << 1);
	logFnc = (dstClass & 3);	/* only two lower bits needed */
	while (lclLineCnt-- >= 0)
	{	/* for each row */
		dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
			+ dstBgnByte;
		lclByteCnt = byteCntM1;
		/* check if first pixel aligned */
		if (pxShift != 0)
		{	/* no, align it */
			pxBit = (byte) (shiftMask >> pxShift);
			while (pxBit > 0)
			{
				switch (logFnc)
				{
				case 0:	/* handled elsewhere */
				case 1:	/* "OR" */
					*dstPtr = *dstPtr | (pxBit & pnColr);
					break;
				case 2:	/* "XOR" */
					*dstPtr = *dstPtr ^ (pxBit & pnColr);
					break;
				case 3:	/* "AND" */
					*dstPtr = *dstPtr & (~pxBit | (pxBit & pnColr));
				}
				pxBit = (pxBit >> shfCnt);
				lclByteCnt--;
				if (lclByteCnt < 0) break;
			}
			dstPtr++;
		}
		/* do the whole bytes */
		while (lclByteCnt >= lclShift)
		{	/* for each byte in the row */
			switch (logFnc)
			{
			case 0:	/* handled elsewhere */
			case 1:	/* "OR" */
				*dstPtr = *dstPtr | pnColr;
				break;
			case 2:	/* "XOR" */
				*dstPtr = *dstPtr ^ pnColr;
				break;
			case 3:	/* "AND" */
				*dstPtr = *dstPtr & pnColr;
			}
			dstPtr++;
			lclByteCnt -= lclShift;
		}
		/* do the last pixels if any */
		if (lclByteCnt >= 0)
		{
			if (shfCnt == 2)
			{
				pxBit = 0xc0;
			}
			else
			{
				pxBit = 0xf0;
			}
			while (lclByteCnt-- >= 0)
			{
				switch (logFnc)
				{
				case 0:	/* handled elsewhere */
				case 1:	/* "OR" */
					*dstPtr = *dstPtr | (pxBit & pnColr);
					break;
				case 2:	/* "XOR" */
					*dstPtr = *dstPtr ^ (pxBit & pnColr);
					break;
				case 3:	/* "AND" */
					*dstPtr = *dstPtr & (~pxBit | (pxBit & pnColr));
				}
				pxBit = (pxBit >> shfCnt);
			}
		}

		dRect.Ymin++;	/* advance to next row */
	}

	return;
}


/* Function MonoFillOXADestM2_4B sets the destination pixel data based on
the logical function "OR", "XOR" or "AND" and the pattern bit. */
void MonoFillOXADestM2_4B(void)
{
	int lclLineCnt, lclByteCnt;
	int ptrnX, ptrnY, ptrnByte, ptrnBt, ptrnColr;
	int pxShift;
	byte pxBit;
	int logFnc;

	lclLineCnt = lineCntM1;
	ptrnY = dRect.Ymin % patHeight;	/* start of pattern allignment */
	ptrnY *= patWidthInBytes;
	pxShift =  (dRect.Xmin & firstOffset) * shfCnt;
	logFnc = (dstClass & 3);	/* only two lower bits needed */
	while (lclLineCnt-- >= 0)
	{	/* for each row */
		ptrnX = dRect.Xmin % patWidthInBytes;
		ptrnBt = (128 >> (dRect.Xmin & 7));
		ptrnByte = savePat->imData[ptrnX + ptrnY];
		dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
			+ dstBgnByte;
		lclByteCnt = byteCntM1;
		pxBit = (byte) (shiftMask >> pxShift);
		while (lclByteCnt-- >= 0)
		{
			if (ptrnByte & ptrnBt)
			{
				ptrnColr = pnColr;
			}
			else
			{
				ptrnColr = bkColr;
			}

			switch (logFnc)
			{
			case 0:	/* handled elsewhere */
			case 1:	/* "OR" */
				*dstPtr = *dstPtr | (pxBit & ptrnColr);
				break;
			case 2:	/* "XOR" */
				*dstPtr = *dstPtr ^ (pxBit & ptrnColr);
				break;
			case 3:	/* "AND" */
				*dstPtr = *dstPtr & (~pxBit | (pxBit & ptrnColr));
			}

			pxBit = (pxBit >> shfCnt);
			if (pxBit == 0)
			{	/* advance to next byte */
				dstPtr++;
				if (shfCnt == 2)
				{
					pxBit = 0xc0;
				}
				else
				{
					pxBit = 0xf0;
				}
			}

			ptrnBt = ptrnBt >> 1;
			if (ptrnBt == 0)
			{
				ptrnBt = 128;
				ptrnX++;
				if (ptrnX == patWidthInBytes) ptrnX = 0;
				ptrnByte = savePat->imData[ptrnX + ptrnY];
			}
		}

		dRect.Ymin++;	/* advance to next row */
		ptrnY += patWidthInBytes;
		if (ptrnY == patLength) ptrnY = 0;
	}

	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -