#include <stdio.h>
#include <stdlib.h>

#define LCD_H_Sync	*((unsigned int *)0x90600000)
#define LCD_V_Sync	*((unsigned int *)0x90600004)
#define LCD_Clock	*((unsigned int *)0x90600008)
#define LCD_FrameBase	*((unsigned int *)0x90600010)
#define LCD_Pixel	*((unsigned int *)0x9060001C)

#define fbBase	0x8B7C0

void InitialLCD(void);
void ClearScreen(void);
void RGB_Colo(void);
void Delay(int count);

void main(void)
{
	InitialLCD();
	ClearScreen();
	Delay(10000000);
	RGB_Colo();
}

void InitialLCD(void)
{
	LCD_H_Sync		= 0x0707004C;
	LCD_V_Sync		= 0x010100EF;
	LCD_Clock		= 0x3FC6;
	LCD_FrameBase	= fbBase;
	LCD_Pixel		= 0x1B82B;
}

void ClearScreen(void)
{
	int i;
	unsigned char *fbStart=(unsigned char *)fbBase;
	
	for(i=0;i<320*240;i++) //Panel size
	{
		*(fbStart+(4*i)+0)  =  0x00; //R
		*(fbStart+(4*i)+1)  =  0x00; //G
		*(fbStart+(4*i)+2)  =  0x00; //B
		*(fbStart+(4*i)+3)  =  0x00; //
	}
}

void RGB_Colo(void)
{
	int i;
	unsigned char *fbStart=(unsigned char *)fbBase;
	
	for(i=0;i<320*80;i++)
	{
		*(fbStart+(4*i)+0)  =  0xFF; //R
		*(fbStart+(4*i)+1)  =  0x00; //G
		*(fbStart+(4*i)+2)  =  0x00; //B
		*(fbStart+(4*i)+3)  =  0x00; //
	}
	for(i=320*80;i<320*160;i++)
	{
		*(fbStart+(4*i)+0)  =  0x00; //R
		*(fbStart+(4*i)+1)  =  0xFF; //G
		*(fbStart+(4*i)+2)  =  0x00; //B
		*(fbStart+(4*i)+3)  =  0x00; //
	}
	for(i=320*160;i<320*240;i++)
	{
		*(fbStart+(4*i)+0)  =  0x00; //R
		*(fbStart+(4*i)+1)  =  0x00; //G
		*(fbStart+(4*i)+2)  =  0xFF; //B
		*(fbStart+(4*i)+3)  =  0x00; //
	}	
}

void Delay(int count)
{	
	int i,j;
	for(i=0;i<100000;i++);
		for(j=0;j<100000;j++);
}
