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

📄 lcd.c

📁 贪吃蛇在arm版上的运行
💻 C
📖 第 1 页 / 共 2 页
字号:
				*((ByteType *)currPoint) = (color & 0xff);
				break;

			case 16:
				*((WordType *)currPoint) = (color & 0xffff);
				break;
		}

		// Make a LINE_SIZE increment to the currPoint,
		// in order to move point to the start position of next line
		(ByteType *)currPoint += LINE_SIZE;	}	
  	return;}// Draw a common line on the screen
void fb_DrawLine(short x1, short y1, short x2, short y2, ColorType color/*, int xorm */){	int i = 0;	int d = 0;	if(abs(y2 - y1) > abs(x2 - x1))	{		d = (y2 > y1) ? 1 : -1;		for(i = y1; i != y2; i += d)		{			fb_PutPixel(x1 + (i - y1) * ( x2 - x1) / (y2 - y1), i, color);		}	}	else	{		d = (x2 > x1) ? 1 : -1;		for(i = x1; i != x2; i += d)		{			fb_PutPixel(i, y1 + (i - x1) * (y2 - y1) / (x2 - x1), color);		}        	}}
// Draw a horizontal dashed line on the screen
void fb_DrawDashed_H(short x1, short x2, short y, short spaceWidth, ColorType color)
{
	short i;
	short dashCount;	/* dashed width counter */
	short isSpace;		/* sign for put a pixel or not */

	if (x1 > x2)
	{
		short tmp;

		tmp = x1;
		x1 = x2;
		x2 = tmp;
	}

	if (spaceWidth < 0 || spaceWidth > (x2 - x1))
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: spaceWidth out of range.\n");
		printf("DEBUG_INFO: spaceWidth = %d\n", spaceWidth);
#endif
		spaceWidth = DEFAULT_DASH;

#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Set to DEFAULT_DASH.\n");
		printf("DEBUG_INFO: spaceWidth = %d\n", spaceWidth);
#endif
	}

	dashCount = 0;
	isSpace = 0;
	for (i = x1; i <= x2; i++)
	{
		// to put a pixel with a specified color according isSpace sign
		if (!isSpace)
		{
			fb_PutPixel(i, y, color);
			dashCount++;
		}
		else
			dashCount++;

		if (dashCount == spaceWidth)
		{
			dashCount = 0;
			isSpace ^= 1;
		}
	}

	return;
}
// Draw a vertical dashed line on the screen
void fb_DrawDashed_V(short x, short y1, short y2, short spaceWidth, ColorType color)
{
	short i;
	short dashCount;	/* dashed width counter */
	short isSpace;		/* sign for put a pixel or not */

	if (y1 > y2)
	{
		short tmp;

		tmp = y1;
		y1 = y2;
		y2 = tmp;
	}

	if (spaceWidth < 0 || spaceWidth > (y2 - y1))
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: spaceWidth out of range.\n");
		printf("DEBUG_INFO: spaceWidth = %d\n", spaceWidth);
#endif
		spaceWidth = DEFAULT_DASH;

#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Set to DEFAULT_DASH.\n");
		printf("DEBUG_INFO: spaceWidth = %d\n", spaceWidth);
#endif
	}

	dashCount = 0;
	isSpace = 0;
	for (i = y1; i <= y2; i++)
	{
		// To put a pixel with a specified color according isSpace sign
		if (!isSpace)
		{
			fb_PutPixel(x, i, color);
			dashCount++;
		}
		else
			dashCount++;

		if (dashCount == spaceWidth)
		{
			dashCount = 0;
			isSpace ^= 1;
		}
	}

	return;
}
	// Draw a rectangle frame on the screen
void fb_DrawRect(short x1, short y1, short x2, short y2, ColorType color){
	// Draw horitontal frame
	fb_DrawLine_H(x1, x2, y1, color);
	fb_DrawLine_H(x1, x2, y2, color);
	// Draw vertical frame
	fb_DrawLine_V(x1, y1 + 1, y2 - 1, color);
	fb_DrawLine_V(x2, y1 + 1, y2 - 1, color);
	return;}                                                                                                                                                                                                                                                                                                                                                            // Draw a rectangle frame on the screen
void fb_FillRect(short x1, short y1, short x2, short y2, ColorType color)
{
	short currLine;
	unsigned long startOffset;

	if (x1 < 0 || x1 >= SCREEN_WIDTH || 
		x2 < 0 || x2 >= SCREEN_WIDTH ||
		y1 < 0 || y1 >= SCREEN_HEIGHT ||
		y2 < 0 || y2 >= SCREEN_HEIGHT)
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Pixel out of screen range.\n");
		printf("DEBUG_INFO: x1 = %d, y1 = %d, x2 = %d, y2 = %d\n", x1, y1, x2, y2);
#endif
		x1 = (x1 < 0) ? 0 : x1;
		x2 = (x2 < 0) ? 0 : x2;
		y1 = (y1 < 0) ? 0 : y1;
		y2 = (y2 < 0) ? 0 : y2;

		x1 = (x1 >= SCREEN_WIDTH) ? SCREEN_WIDTH - 1 : x1;
		x2 = (x2 >= SCREEN_WIDTH) ? SCREEN_WIDTH - 1 : x2;
		y1 = (y1 >= SCREEN_HEIGHT) ? SCREEN_HEIGHT - 1 : y1;
		y2 = (y2 >= SCREEN_HEIGHT) ? SCREEN_HEIGHT - 1 : y2;
	}

	if (x1 > x2)
	{
		short tmp;

		tmp = x1;
		x1 = x2;
		x2 = tmp;
	}

	if (y1 > y2)
	{
		short tmp;

		tmp = y1;
		y1 = y2;
		y2 = tmp;
	}

	startOffset = y1 * LINE_SIZE + x1 * PIXEL_SIZE;

#ifdef DEBUG
	printf("DEBUG_INFO: x1 = %d, y1 = %d, x2 = %d, y2= %d, color = 0x%x\n", x1, y1, x2, y2, color);
#endif

	// Directly access memory instead of call putpixel function 
	// to make more effective performance of drawing a line
	for (currLine = y1; currLine <= y2; currLine++)
	{
		switch (BPP)
		{
			case 8:
				memset((ByteType *)((ByteType *)frame_base + startOffset), (color & 0xff), (x2 - x1 + 1) * PIXEL_SIZE);
				break;

			case 16:
				memset((WordType *)((ByteType *)frame_base + startOffset), (color & 0xffff), (x2 - x1 + 1) * PIXEL_SIZE);
				break;
		}
		// Make a LINE_SIZE increment to the startOffset,
		// in order to move point to the start position of next line
		startOffset += SCREEN_WIDTH * PIXEL_SIZE;
	}

	return;
}

// Draw a specified character with 16 x 8 dot matrix code on the screen
void fb_Text_8x16(short x, short y, unsigned char * dotCodes, ColorType color)
{
	int i, j;

	if (x < 0 || x >= SCREEN_WIDTH ||
		y < 0 || y >= SCREEN_HEIGHT)
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Pixel out of screen range.\n");
		printf("DEBUG_INFO: x = %d, y = %d\n", x, y);
#endif
		return;
	}

	if (dotCodes == NULL)
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Dot codes NULL.\n");
#endif
		return;
	}

	for (i = 0; i < 16; i++)
	{
		x += 8;
		
		for (j = 0; j < 8; j++)
		{
			x--;

			if ((dotCodes[i] >> j) & 0x1)
			{
				fb_PutPixel(x, y, color);
			}
		}

		y++;
	}

	return;
}

// Draw a specified character with 16 x 16 dot matrix code on the screen
void fb_Text_16x16(int x, int y, unsigned char * dotCodes, ColorType color)
{
	int i, j, k;

	if (x < 0 || x >= SCREEN_WIDTH ||
		y < 0 || y >= SCREEN_HEIGHT)
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Pixel out of screen range.\n");
		printf("DEBUG_INFO: x = %d, y = %d\n", x, y);
#endif
		return;
	}

	if (dotCodes == NULL)
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Dot codes NULL.\n");
#endif
		return;
	}

	for(i = 0; i < 16; i++)
	{
		for (j = 0; j < 2; j++)
		{
			x += 8 * ( j + 1);

			for (k = 0; k < 8; k++)
			{
				x--;

				if ((dotCodes[2 * i + j] >> k) & 0x1)
				{
					fb_PutPixel(x, y, color);
				}
			}
		}

		x -= 8;
		++y;
	}

	return;
}

// Draw a ellipse, center at point (x, y), 
// a specifies x_axis radius, b specifies y_axis radius
void fb_DrawEllipse(short x, short y, short a, short b, ColorType color)
{	int wx, wy;	int thresh;	int asq = a * a;	int bsq = b * b;	int xa, ya;		if (a < 0 || b < 0)
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Radius invalid.\n");
		printf("DEBUG_INFO: a = %d, b = %d\n", a, b);
#endif
		return;
	}
	fb_PutPixel(x, y + b, color);	fb_PutPixel(x, y - b, color);	wx = 0;	wy = b;	xa = 0;	ya = asq * 2 * b;	thresh = asq / 4 - asq * b;	// Draw upper half of ellipse	while(1)	{		thresh += xa + bsq;		if (thresh >= 0)		{			ya -= asq * 2;			thresh -= ya;			wy--;		}		xa += bsq * 2;		wx++;		if (xa >= ya)			break;		fb_PutPixel(x + wx, y - wy, color);		fb_PutPixel(x - wx, y - wy, color);		fb_PutPixel(x + wx, y + wy, color);		fb_PutPixel(x - wx, y + wy, color);	}	fb_PutPixel(x + a, y, color);	fb_PutPixel(x - a, y, color);	wx = a;	wy = 0;	xa = (bsq * a) << 1;	ya = 0;	thresh = (bsq >> 2) - bsq * a;	// Draw lower half of ellipse	while(1)	{		thresh += ya + asq;		if (thresh >= 0)		{			xa -= bsq + bsq;			thresh = thresh - xa;			wx--;		}		ya += asq + asq;		wy++;		if (ya > xa)			break;		fb_PutPixel(x + wx, y - wy, color);		fb_PutPixel(x - wx, y - wy, color);		fb_PutPixel(x + wx, y + wy, color);		fb_PutPixel(x - wx, y + wy, color);	}}// Draw a ellipse, center at point (x, y), 
// a specifies x_axis radius, b specifies y_axis radius
void fb_FillEllipse(short x, short y, short a, short b, ColorType color)
{
	int wx, wy;
	int thresh;
	int asq = a * a;
	int bsq = b * b;
	int xa, ya;

	if (a < 0 || b < 0)
	{
#ifdef ERR_DEBUG
		printf("DEBUG_INFO: Radius invalid.\n");
		printf("DEBUG_INFO: a = %d, b = %d\n", a, b);
#endif
		return;
	}

	fb_PutPixel(x, y + b, color);
	fb_PutPixel(x, y - b, color);

	wx = 0;
	wy = b;
	xa = 0;
	ya = asq * 2 * b;
	thresh = asq / 4 - asq * b;

	// Fill upper half of ellipse	while(1)
	{
		thresh += xa + bsq;

		if (thresh >= 0)
		{
			ya -= asq * 2;
			thresh -= ya;
			wy--;
		}

		xa += bsq * 2;
		wx++;

		if (xa >= ya)
			break;

		fb_DrawLine_H(x - wx, x + wx, y - wy, color);
		fb_DrawLine_H(x - wx, x + wx, y + wy, color);
	}

	fb_DrawLine_H(x - a, x + a, y, color);

	wx = a;
	wy = 0;
	xa = (bsq * a) << 1;

	ya = 0;
	thresh = (bsq >> 2) - bsq * a;

	// Fill lower half of ellipse	while(1)	{
		thresh += ya + asq;

		if (thresh >= 0)
		{
			xa -= bsq + bsq;
			thresh = thresh - xa;
			wx--;
		}

		ya += asq + asq;
		wy++;

		if (ya > xa)
			break;

		fb_DrawLine_H(x - wx, x + wx, y - wy, color);
		fb_DrawLine_H(x - wx, x + wx, y + wy, color);
	}
}

#endif	// __FB_LCD_C

⌨️ 快捷键说明

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