
/***********************************************************************************

Programmer: Bert Lee

Revision: 2022/05/10


***********************************************************************************/

#include "type.h"
#include "LT776_gra.h"


#define Disable_Interrupts	__asm("CPSID I")
#define Enable_Interrupts		__asm("CPSIE I")

void ClearScreen(UINT16 color)
{
	UINT16 *frameBuffer;
	UINT32 i;
	frameBuffer=(UINT16 *)FRAMBUFFER_ADDR;
	for (i=0;i<(LCD_SIZE_X*LCD_SIZE_X);i++)
	{
		*frameBuffer++=color;
	}
}


void Put16BitBMP(UINT16 x,UINT16 y,unsigned const char *bmp,UINT16 transColor)
{
	UINT32 i,bmpSize,sizeX,sizeY;
	UINT16 locX,pixelData;
	unsigned const char *bmpPtr;
	UINT16 *frameBuffer;
	
	locX=x; 
	x=0;	
	sizeX=*bmp|*(bmp+1)<<8;
	sizeY=*(bmp+4)|*(bmp+5)<<8;
	bmpSize=sizeX*sizeY;
	bmpPtr=bmp+8;
	
	frameBuffer=(UINT16*)(FRAMBUFFER_ADDR+(y*LCD_SIZE_X+locX)*2);	// x2
		
	for (i=0;i<bmpSize;i++)
	{
		pixelData=*bmpPtr++;
		pixelData|=(*(bmpPtr++)<<8);
		
		if (pixelData!=transColor)
			*frameBuffer=pixelData;
		frameBuffer++;
		
		x++;		
		if(x>=sizeX)
		{
			x=0;
			y++;
			frameBuffer=FRAMBUFFER_ADDR+(y*LCD_SIZE_X+locX)*2;	// x2
		}
	}
}
