
#define LCD_TRUE	1
#define LCD_FALSE	0
#define LCD_IO_BASE     0x90600000

//void SetFrameBase( unsigned char *base );
//void ClearScreen(unsigned char * adr);
//void Init_LCD(volatile unsigned int LCD_BASE);
void OSD_fg_color( unsigned int LCD_IO_Base, int pal0, int pal1, int pal2, int pal3);
void OSD_bg_color( unsigned int LCD_IO_Base, int pal1, int pal2, int pal3);
void OSD_On( unsigned int  base );
void OSD_Off( unsigned int  LCD_IO_Base );
void OSD_Pos( unsigned int  LCD_IO_Base, int  HPos, int VPos);
void OSD_Dim( unsigned int LCD_IO_Base, int HDim, int VDim);
void OSD_putc( char c, int position);
void OSD_puts( char *str, int position);

#if 0
void SetFrameBase( unsigned char  *pFrameBuffer )
{
 *(unsigned int *)(LCD_IO_BASE + 0x10) =  (unsigned int) pFrameBuffer;
}
#endif

int     LCDHSize  = 320, LCDVSize = 240;
int     ModeBpp   = 32/8;
int     HLocation = 10, VLocation = 3;

#if 0
void ClearScreen(unsigned char * adr)
{
	int i;
  unsigned char *fbStart= adr ;
	
	for( i=0; i< LCDHSize*LCDVSize*ModeBpp ; i++ )
	{
		*( fbStart+i)  =  0x55 ; 
  }	
}

void Init_LCD(volatile unsigned int LCD_Base)
{
   *(volatile unsigned int *) (LCD_Base + 0x0 )  = 0x0707044c;
   *(volatile unsigned int *) (LCD_Base + 0x4 )  = 0x010100ef;
   *(volatile unsigned int *) (LCD_Base + 0x8 )  = 0x00003fc7;
   *(volatile unsigned int *) (LCD_Base + 0x1c ) = 0x0001ba21; 
}
#endif

void OSD_fg_color( unsigned int LCD_IO_Base, int pal0, int pal1, int pal2, int pal3)
{
  *(unsigned int *) (LCD_IO_Base + 0x3c) = (pal0) | (pal1 <<8) | (pal2 << 16) | (pal3<< 24);
}

void OSD_bg_color( unsigned int LCD_IO_Base, int pal1, int pal2, int pal3)
{
  unsigned int value;

  value = *(unsigned int *) (LCD_IO_Base + 0x40);
  value &= 0x0000003f;
  value |= (pal1 <<8) | (pal2 << 16) | (pal3 << 24);
   *(unsigned int *) (LCD_IO_Base + 0x40) = value;

}

void OSD_On( unsigned int  base )  
{
    *(unsigned int *) (base + 0x34) &= 0xfffffffe;
    *(unsigned int *) (base + 0x34) |= 1;
}

void OSD_Off( unsigned int  LCD_IO_Base )  
{
    *(unsigned int *) (LCD_IO_Base + 0x34) &= 0xfffffffe;
}

void OSD_Pos( unsigned int  LCD_IO_Base, int  HPos, int VPos)
{
   *(unsigned int *) (LCD_IO_Base + 0x38) = (HPos << 10) |  VPos;
}

void OSD_Dim( unsigned int LCD_IO_Base, int HDim, int VDim)
{
  int value;

  value = *(unsigned int *) (LCD_IO_Base + 0x34);
  value &= 0x0000001f;
  value |= ((HDim << 10) | (VDim << 5));
  *(unsigned int *) (LCD_IO_Base + 0x34) = value;

}

void OSD_Scal( unsigned int LCD_IO_Base, int HScal, int VScal)
{
  unsigned int value;

  value = *(unsigned int *) (LCD_IO_Base + 0x34);
  value &= 0xffffffe1;
  value |= (HScal<<3) | (VScal << 1) ;
  *(unsigned int *) (LCD_IO_Base + 0x34) = value;
}

void OSD_putc( char c, int position)
{

  if( c >= '0' && c <= '9' )
   {
        *(unsigned int *) (LCD_IO_BASE + 0xc000 + position *4 )  = ( (c -'0') << 4);
   }
  else if( c>= 'A' && c <= 'Z')
  {
      *(unsigned int *) (LCD_IO_BASE + 0xc000 + position *4 )  = ( ( c - 'A' +10) << 4);
  }

  if( c == ' ' )
    *(unsigned int *) (LCD_IO_BASE + 0xc000 + position *4 )  = ( ( 'Z' - 'A' +10 + 1) << 4);

  if( c == '=')
   *(unsigned int *) (LCD_IO_BASE + 0xc000 + position *4 )  = ( ( 'Z' - 'A' +10 + 2) << 4);

  if( c == ',')
   *(unsigned int *) (LCD_IO_BASE + 0xc000 + position *4 )  = ( ( 'Z' - 'A' +10 + 3) << 4);

  if( c == ':')
   *(unsigned int *) (LCD_IO_BASE + 0xc000 + position *4 )  = ( ( 'Z' - 'A' +10 + 4) << 4);

}

void OSD_puts( char *str, int position)
{
  int i;

  for(i=0; i< strlen(str); i++)
    OSD_putc( *(str +i), position +i );

}
