📄 osdbasic.c
字号:
//osd_basic.c
// ver0.11 2/1x/2001 Change display format from hex to decimal
// 1.32 LJY11262001 .Add border features to OSD window
// 1.70 LJY05302003 .Support a menu with external OSD.
// 2.00 BYH05102007 .Support internal MCU, which connect with direct memoty bus
// It needs change whole ReadTW88, WriteTW88 to regTW88
#include "Config.h"
#include "typedefs.h"
#include "i2c.h"
#include "main.h"
#include "tw88.h"
#include "osdbasic.h"
#include "dispinfo.h"
#include "measure.h"
#include "printf.h"
#include "udfont.h"
#include "regmap.h"
extern CODE struct RegisterInfo UserRange;
//CODE BYTE ZoomAttr[]={ 0, 0, 0x40, 0x80, 0xc0 };
//IDATA struct BarInfo BarInfo;
IDATA struct OSDStrInfo OSDStrInfo;
extern bit I2CAutoIncFlagOn ;
//********************************************************************
//
// Font
//
//********************************************************************
void WaitEndofDisplayArea(void)
{
BYTE ret,i;
ret = ReadTW88(OSDWINSTATUS) & 0x40;
for(i=0;i<10;i++){
if( ret^ (ReadTW88(OSDWINSTATUS)&0x40)) break;
}
}
//=============================================================================
// Download OSD Color Look up
//=============================================================================
void Change_OSDColorLookup(void)
{
BYTE i,j;
for(j=0; j<2; j++) {
for(i=0; i<8; i++) {
WriteTW88(0x9c, i+j*8);
WriteTW88(0x9d, OSD_Color_LookUp_Data_Table[j][i]);
}
}
}
//=============================================================================
// Download RAM Font Data
//=============================================================================
#ifdef INTERNAL_MCU // it doesn't have auto increase I2C mode
void DownloadUDFont(void)
{
BYTE i, j;
#ifndef INTERNAL_MCU
BYTE k;
#endif
WriteTW88(TW88_MULTISTART, COLORFONT_START); // Set Color Font Start Address.
for(i=0; (i< NO_UDFONT) && (i<= MAX_FONT_RAM_CHARS) ; i++) {
//DownloadFont(i, RAMFONTDATA[i]);
WriteTW88(TW88_ENABLERAM, ReadTW88(TW88_ENABLERAM) | 0x01); // Font RAM access mode ON
WriteTW88(TW88_FONTRAMADDR, i);
WriteTW88(0xff, ReadTW88(0xff) | 0x10); // Disable I2C index auto increment during multi-write
//WriteI2Cn( TW88I2CAddress, TW88_FONTRAMDATA, fontdata, 27 );
for ( j = 0; j<27; j++ ) {
WriteTW88(TW88_FONTRAMDATA, RAMFONTDATA[i][j]);
#ifndef INTERNAL_MCU
for ( k=5; k!=0; k-- ) ;
#endif
}
WriteTW88(TW88_ENABLERAM, (ReadTW88(TW88_ENABLERAM) & 0xfe)); // OSD RAM access mode OFF
#ifdef DEBUG_OSD
if (( i % 10 )== 0)
dPuts("\r\n");
dPrintf("%02xh, ", (WORD)i);
#endif
}
}
#else
void DownloadFont(BYTE cod, CODE_P BYTE *fontdata)
{
WriteTW88(TW88_ENABLERAM, ReadTW88(TW88_ENABLERAM) | 0x01); // Font RAM access mode
WriteTW88(TW88_FONTRAMADDR, cod);
// WriteTW88(0xff, ReadTW88(0xff) | 0x10); // Disable I2C index auto increment during multi-write
WriteTW88(0xe0, ReadTW88(0xe0) | 0x10); // Disable I2C index auto increment during multi-write
WriteI2Cn( TW88I2CAddress, TW88_FONTRAMDATA, fontdata, 27 );
WriteTW88(TW88_ENABLERAM, ReadTW88(TW88_ENABLERAM) & 0xfe); // OSD RAM access mode
}
void DownloadUDFont(void)
{
BYTE i;
WriteTW88(TW88_MULTISTART, COLORFONT_START); // Set Color Font Start Address.
for(i=0; i< NO_UDFONT && i<= MAX_FONT_RAM_CHARS ; i++) {
DownloadFont(i, RAMFONTDATA[i]);
}
}
#endif
//*****************************************************************************
// OSD Window internal subfunction for TW88xx
//*****************************************************************************
//*****************************************************************************
// Functions for TW88xx internal OSD
//*****************************************************************************
#ifdef SUPPORT_OSDPOSITIONMOVE
void SetOSDWindowX_TW88(BYTE winno, BYTE x)
{
WORD tmp;
BYTE dat;
if( winno<1 || winno>8 ) return;
SetOSDWindowNum(winno);
tmp = x << 3;
dat = ReadTW88(TW88_WINSTART_HI) & 0xf0;
dat = dat | (tmp>>8);
WriteTW88(TW88_WINSTART_HI, dat);
WriteTW88(TW88_WINXSTART, tmp);
}
#endif
void SetOSDWindowY_TW88(BYTE winno, BYTE y)
{
WORD tmp;
BYTE dat;
if( winno<1 || winno>8 ) return;
SetOSDWindowNum(winno);
tmp = y << 2;
dat = ReadTW88(TW88_WINSTART_HI) & 0x0f;
dat = dat | ((tmp>>8)<<4);
WriteTW88(TW88_WINSTART_HI, dat);
WriteTW88(TW88_WINYSTART, tmp);
}
//=============================================================================
// ShowOSDWindow_TW88
//=============================================================================
void ShowOSDWindowAll(BYTE on)
{
BYTE rd;
WaitEndofDisplayArea();
rd = ReadTW88(TW88_OSDLOCKUPSEL);
if( on )
WriteTW88(TW88_OSDLOCKUPSEL, rd&0xef); //
else
WriteTW88(TW88_OSDLOCKUPSEL, rd|0x10); // OSD All Off (TW8806B)
}
void ShowOSDWindow_TW88(BYTE winno, BYTE onoff)
{
BYTE rd;
if( winno<1 || winno>8 ) return;
SetOSDWindowNum(winno);
rd = ReadTW88(TW88_WINATTR);
if( onoff ) rd |= 0x01;
else rd &= 0xfe;
WaitEndofDisplayArea();
WriteTW88(TW88_WINATTR, rd);
}
#ifdef SUPPORT_OSDPOSITIONMOVE
WORD GetOSDWindowX(BYTE winno)
{
WORD x;
if( winno<1 || winno>8 ) return 0;
SetOSDWindowNum(winno);
x = (ReadTW88(TW88_WINSTART_HI) & 0x0f) << 8;
x = x | ReadTW88(TW88_WINXSTART);
return (BYTE)(x >> 3);
}
#endif
WORD GetOSDWindowY(BYTE winno)
{
WORD y;
if( winno<1 || winno>8 ) return 0;
SetOSDWindowNum(winno);
y = (ReadTW88(TW88_WINSTART_HI) & 0xf0) << 4;
y = y | ReadTW88(TW88_WINYSTART);
return (BYTE)(y >> 2);
}
#include "osdTW88.c"
//*****************************************************************************
//
// Internal Font test
//
//*****************************************************************************
//-----------------------------------------------------------------------------
// CopyUDCharToOSDWindow(BYTE winno, BYTE xoff, BYTE yoff, BYTE attr, BYTE ch)
// - For FONT RAM Char.
//-----------------------------------------------------------------------------
code BYTE FontTestWindow[] = { 0xa1, 10, 0xa2, 10, 0xa0, 0, 0xa3, 16, 0xa4, 16, 0xa5, 0x91,
0xa6, 1, 0xa7, 1, 0xa8, 0x22, 0xa9, 0x00, 0xaa, 00, 0xab, 0x62 };
void DisplayROMFont( BYTE scode )
{
BYTE i;
WriteTW88( 0x94, 0x02 ); // clear OSD RAM clear
WriteTW88( 0x9e, 0 ); // window #0
for ( i=0; i<(sizeof(FontTestWindow)/2); i++ )
WriteTW88(FontTestWindow[i*2], FontTestWindow[i*2+1]);
if ( scode == 0 ) {
WriteTW88( 0x94, 0x00 ); //0000 1100 ROM Font select with same attribute
for ( i=0; i<0xfe; i++ ) {
WriteTW88( 0x96, i );
WriteTW88( 0x97, i );
WriteTW88( 0x98, 0x97 );
}
}
else {
WriteTW88( 0x94, 0x0C ); //0000 1100 ROM Font select with same attribute
Puts("\r\nIf you'd like to exit, press any Key....");
while ( !RS_ready() ){
WriteTW88( 0x94, 0x0C ); //0000 1100 ROM Font select with same attribute
WriteTW88( 0x96, 0 ); // set start position of RAM
WriteTW88( 0x98, 0x47 ); // different color with upper
i = 0;
do {
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
} while ( i != 0 );
}
}
WriteTW88( 0x9f, 0x17 ); // enable Window #2
WriteTW88( 0x9c, 0x0f); // turn ON
}
void DisplayRAMFont(BYTE scode)
{
BYTE i, j;
WriteTW88( 0x94, 0x02 ); // clear OSD RAM clear
WriteTW88( 0x9e, 1 ); // window #1
for ( i=0; i<(sizeof(FontTestWindow)/2); i++ )
WriteTW88(FontTestWindow[i*2], FontTestWindow[i*2+1]);
if ( scode == 0 ) {
WriteTW88( 0x94, 0x80 ); //0000 1101 RAM Font select with same attribute
for ( i=0; i<0xfe; i++ ) {
WriteTW88( 0x96, i );
WriteTW88( 0x97, i );
WriteTW88( 0x98, 0x97 );
}
}
else if ( scode == 1 ) {
Puts("\r\nIf you'd like to exit, press any Key....");
j = 0;
while ( !RS_ready() ){
WriteTW88( 0x94, 0x8C ); //0000 1101 RAM Font select with same attribute
WriteTW88( 0x96, 0 ); // set start position of RAM
WriteTW88( 0x98, 0x47 ); // different color with upper
i = 0;
do {
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
WriteTW88( 0x97, i++ );
} while ( i != 0 );
}
}
else {
DownloadUDFont();
}
WriteTW88( 0x9f, 0x17 ); // enable Window #2
WriteTW88( 0x9c, 0x0f); // turn ON
}
//*****************************************************************************
//
// Functions for only CC.
//
//*****************************************************************************
//ljy052903: Only In CC
//*****************************************************************************
// Move to CC by Harry
//===============================================================================
// Used OSD Menu
//===============================================================================
//------------------------------------------------------------
void WriteStringToAddr(WORD addr, BYTE *str, BYTE cnt)
{
//if( I2CAutoIncFlagOn==0 )
WriteTW88(TW88_ENABLERAM, 0x04); // OSD RAM Auto Access Enable, ROMFONT Start Enable
WriteTW88(TW88_OSDRAMADDRLO, addr);
WriteI2Cn( TW88I2CAddress, TW88_OSDRAMDATAHI, str, cnt );
// if( I2CAutoIncFlagOn==0 )
WriteTW88(TW88_ENABLERAM, 0x00); // OSD RAM Auto Access Disable
}
#ifdef PAL_TV
void DrawAttrString(WORD addr, BYTE *Str, BYTE cnt)
{
// if( I2CAutoIncFlagOn==0 )
WriteTW88(TW88_ENABLERAM, 0x04); // OSD RAM Auto Access Enable
WriteTW88(TW88_OSDRAMADDRLO, addr);
WriteI2Cn( TW88I2CAddress, TW88_OSDRAMDATALO, Str, cnt ); // Attr
// if( I2CAutoIncFlagOn==0 )
WriteTW88(TW88_ENABLERAM, 0x00); // OSD RAM Auto Access Disable
}
#endif
void DrawAttrCnt(WORD addr, BYTE color, BYTE cnt)
{
WriteTW88(TW88_ENABLERAM, 0x04); // OSD RAM Auto Access Enable
WriteTW88(TW88_OSDRAMADDRLO, addr);
WriteI2CnD( TW88I2CAddress, TW88_OSDRAMDATALO, color, cnt );
WriteTW88(TW88_ENABLERAM, 0x00); // OSD RAM Auto Access Disable
}
void ClearDataCnt(WORD addr, BYTE cnt)
{
// if( I2CAutoIncFlagOn==0 )
WriteTW88(TW88_ENABLERAM, 0x04); // OSD RAM Auto Access Enable
WriteTW88(TW88_OSDRAMADDRLO, addr);
WriteI2CnD( TW88I2CAddress, TW88_OSDRAMDATAHI, ' ', cnt );
// if( I2CAutoIncFlagOn==0 )
WriteTW88(TW88_ENABLERAM, 0x00); // OSD RAM Auto Access Disable
}
//*****************************************************************************
//
// Conversion Functions.
//
//*****************************************************************************
BYTE utoa(WORD value, BYTE *str, BYTE radix)
{
BYTE cnt, *str1;
WORD i, div;
#ifdef DEBUG_OSD
dPrintf("\r\n++(utoa):0x%x__", value);
#endif
str1 = str;
cnt=0;
if( radix==10) {
for(div = 10000; div>=10; div/=10) {
i = value/div;
if( i ) {
*str++ = i+'0';
cnt++;
}
else if( cnt ) // 100, 200, 20,,,,
*str++ = '0';
value%=div;
}
*str++ = value+'0';
*str = 0;
}
else if( radix==16) {
for(div = 0x1000; div>=0x10; div/=0x10) {
i = value/div;
if( i ) {
if( i>=0xa )
*str++ = i-0xa+'A';
else
*str++ = i+'0';
value%=div;
}
}
if( value>=0xa )
*str++ = value-0xa+'A';
else
*str++ = value+'0';
*str = 0;
}
return 1;
}
BYTE ltoa_K(long value, BYTE *str, BYTE i_part)
{
BYTE j;
long divider;
#ifdef DEBUG_OSD
dPrintf("\r\n++(ltoa_K):%ld__", value);
#endif
j=0;
for( divider = 100000000L; divider >= 1000; divider /=10) {
if( ( value/ divider ) || j ) {
*str++ = value/divider + '0';
j++;
}
value %= divider;
}
*str++ = '.';
j++;
for( ; divider >= 10; divider /=10) {
if( value/ divider || j) {
*str++ = value/divider + '0';
j++;
i_part--;
}
if( i_part==0 ) {
*str = 0;
return j;
}
value %= divider;
}
if( value ) {
*str++ = value + '0';
j++;
}
*str = 0;
return j;
}
BYTE strlen( BYTE *str )
{
BYTE i=0;
while( *str++ ) i++;
return i;
}
//=============================================================================
// Init Menu Window Data initialize
//=============================================================================
#include "OsdInitTable.c"
void InitOSDWindow(BYTE *ptr)
{
BYTE i, page;
page = ReadTW88(0xff);
WriteTW88( 0xff, (page&0xfe));
WriteTW88(0xe0, ReadTW88(0xe0) & 0xef);
i = 0;
while(ptr[i]) {
WriteI2Cn_(TW88I2CAddress, &ptr[i+1], ptr[i]);
WriteI2Cn_(TW88I2CAddress, &ptr[i+1], 5); // To set position LSB...
i += ptr[i] + 1;
};
WriteTW88(0xe0, ReadTW88(0xe0) | 0x10);
WriteTW88( 0xff, page );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -