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

📄 cc_tw88.c

📁 此程序为twell8806驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:

	return CC_Y_ORG - CC_FONT_HEIGHT;

}

void SetCCWindowY(BYTE winno, BYTE y)	// y=Row number 1 ~ 15
{
	BYTE dat;
	WORD tmp;

	SetCCWindowNum(winno);

	tmp = GetCCWindowYbyRow(y);

	dat = ReadTW88(TW88_WINSTART_HI) & 0x0f;
	dat = dat | ((tmp>>8)<<4);
	WriteTW88(TW88_WINSTART_HI, dat);
	WriteTW88(TW88_WINYSTART, tmp);
}
//=================================================================================================
//
//=================================================================================================
void CreateCCWindow(BYTE winno, BYTE x, BYTE y, BYTE w, BYTE h, WORD sa, BYTE attr)
{
	BYTE zoom_attr, new_attr;

	SetCCWindowNum(winno);

	SetCCWindowX(winno, x);				// * set x
	SetCCWindowY(winno, y);				// * set y

	WriteTW88(TW88_WINWIDTH,  w);		// * set w width(1 character width per 1 step)
	WriteTW88(TW88_WINHEIGHT, h); 		// * set h height(1 character height per 1 step)
	
	zoom_attr = CC_ZOOM-1;
	zoom_attr = zoom_attr*0x40 + zoom_attr*0x10 + (sa>>8);
	WriteTW88(TW88_WINZOOM, zoom_attr);

	WriteTW88(TW88_WINSADDRLO,  sa);		// * set sa start address of OSD RAM

	new_attr = attr & 0xf0;				//for color
	if( attr & SHOW ) new_attr |= 0x01;
	WriteTW88(TW88_WINATTR, new_attr);	// attribute

	// Disable all other functions
	WriteTW88( TW88_WINBRDATTR,   0x00 );
	WriteTW88( TW88_WINBRDWIDTH,  CC_HBORDER );
	WriteTW88( TW88_WINBRDHEIGHT, CC_VSPACE );
	WriteTW88( TW88_WINSPACE,     CC_VSPACE*0x10 + CC_HSPACE);
	WriteTW88( TW88_WINSHADOW,    0x00 );
	WriteTW88( TW88_WINBLENDING,  0x00 );
	WriteTW88( TW88_WINCHEFFECT,  0x40 );	// set multi-color enable to block garbage.

	#ifdef DEBUG_OSD
	dPrintf("\r\n++(CreateCCWindow) wino:%bd,", winno-1 );
	dPrintf("attr:0x%bx, new_attr:0x%bx __", attr, new_attr);
	#endif
}
  /*
void CreateCCWindow(BYTE winno, BYTE x, BYTE y, BYTE w, BYTE h, WORD sa, BYTE attr)
{
	WriteTW88(0x9e,  2);
	WriteTW88(0xa1, 200);
	WriteTW88(0xa2, 18);
	WriteTW88(0xa3,  17);
	WriteTW88(0xa4,  10);
	WriteTW88(0xa9, 0x10);
	WriteTW88(0xaa, 0x00);
    WriteTW88(0x9f, 0x01);
	WriteTW88( 0xa5,   0x00 );
	WriteTW88( 0xa6,  0x00 );
	WriteTW88( 0xa7, 0x00 );
	WriteTW88( 0xa8,     0x00);
	WriteTW88( 0xab,    0x00 );
	WriteTW88( 0xac,  0x00 );
	WriteTW88( 0xad,  0x40 );	// set multi-color enable to block garbage.
	WriteTW88(0xad, 0);	// disable muiti-font
	WriteTW88(0xac, 0xff);	// TW88_WINBLENDING ---0xac

}	  */
//=================================================================================================
//
//=================================================================================================
void WaitVSync(void)
{
	BYTE dat, i;
/*
	dat = ReadDecoder(CSTATUS);
	for(i=0; i<100; i++) {
		if( (dat & 0x10) != (ReadDecoder(CSTATUS) & 0x10) ) break;
	}
*/

	dat = ReadTW88(0x95);
	for(i=0; i<100; i++) {
		if( (dat & 0x40) != (ReadTW88(0x95) & 0x40) ) break;
	}

//	LastField = (dat & 0x80)>>7;
}

void WaitVSync1(void)
{
	BYTE dat, i;
/*
	dat = ReadDecoder(CSTATUS);
	for(i=0; i<100; i++) {
		if( (dat & 0x10) != (ReadDecoder(CSTATUS) & 0x10) ) break;
	}
*/

	dat = ReadTW88(0x95);
	for(i=0; i<100; i++) {
		if( (dat & 0x80) != (ReadTW88(0x95) & 0x80) ) break;
	}

	LastField = (dat & 0x80)>>7;
}
//=================================================================================================
//			Transparent Window for Blocking top of Roll-Up
//=================================================================================================
#define TRANS_CNT		CC_MAX_CHARS

void CreateTransWindow(void)
{
	CreateCCWindow(CCWINTRANS1, 1, 1, TRANS_CNT, 1, 0, BG_COLOR_BLACK);
	WriteTW88(TW88_WINCHEFFECT, 0);	// disable muiti-font
	WriteTW88(TW88_WINBLENDING, 0xff);	// TW88_WINBLENDING ---0xac

	CreateCCWindow(CCWINTRANS2, 1, 1, TRANS_CNT, 1, 0, BG_COLOR_BLACK);
	WriteTW88(TW88_WINCHEFFECT, 0);	// disable muiti-font
	WriteTW88(TW88_WINBLENDING, 0xff);

}

void EmptyTransWindow(WORD addr)
{

	addr &= 0x1ff;

	//--- Clear OSD data in Trans Window
	WriteTW88(TW88_ENABLERAM, 0x04);		// OSD RAM Auto Access Enable
	#ifndef TW8806
	{
	BYTE dat;
	dat = ReadTW88(TW88_OSDRAMADDRHI);
	dat = (dat & 0xfe) | (addr>>8);
	WriteTW88(TW88_OSDRAMADDRHI, dat);
	}
	#endif
	WriteTW88(TW88_OSDRAMADDRLO, (BYTE)addr);
	WriteI2CnD(TW88I2CAddress, TW88_OSDRAMDATALO, BG_COLOR_BLACK|CH_COLOR_BLACK, TRANS_CNT );
	WriteTW88(TW88_ENABLERAM, 0x00);		// OSD RAM Auto Access Disable
}

void TurnOnTransWindow(BYTE winno, BYTE x, BYTE y)
{
	SetCCWindowX( winno, x );
	SetCCWindowY( winno, y );
	ShowCCWindow( winno, TRUE );
}

void TurnOffTransWindow(void)
{
	ShowCCWindow( CCWINTRANS1, FALSE );
	ShowCCWindow( CCWINTRANS2, FALSE );
}
//=================================================================================================
//
//=================================================================================================
BYTE GetCCColor(BYTE color)
{
	switch( color ) {
	case 0x00:	return CH_COLOR_WHITE   | ( CC_attr & BG_COLOR_MASK );
	case 0x02:	return CH_COLOR_GREEN   | ( CC_attr & BG_COLOR_MASK );
	case 0x04:	return CH_COLOR_BLUE    | ( CC_attr & BG_COLOR_MASK );
	case 0x06:	return CH_COLOR_CYAN    | ( CC_attr & BG_COLOR_MASK );
	case 0x08:	return CH_COLOR_RED     | ( CC_attr & BG_COLOR_MASK );
	case 0x0a:	return CH_COLOR_YELLOW  | ( CC_attr & BG_COLOR_MASK );
	case 0x0c:	return CH_COLOR_MAGENTA | ( CC_attr & BG_COLOR_MASK );
	case 0x0e:	return CC_attr;	//italics
	}
	return 0;
}

#ifdef SUPPORT_ENRICHED_CC
BYTE GetCC_BColor(BYTE color)
{
	switch( color ) {
	case 0:		return BG_COLOR_WHITE   | ( CC_attr & CH_COLOR_MASK );
	case 2:		return BG_COLOR_GREEN   | ( CC_attr & CH_COLOR_MASK );
	case 4:		return BG_COLOR_BLUE    | ( CC_attr & CH_COLOR_MASK );
	case 6:		return BG_COLOR_CYAN    | ( CC_attr & CH_COLOR_MASK );
	case 0x08:	return BG_COLOR_RED     | ( CC_attr & CH_COLOR_MASK );
	case 0x0a:	return BG_COLOR_YELLOW  | ( CC_attr & CH_COLOR_MASK );
	case 0x0c:	return BG_COLOR_MAGENTA | ( CC_attr & CH_COLOR_MASK );
	case 0x0e:	return CC_attr;	//italics
	}
	return 0;
}
#endif


BYTE IsField1Data( BYTE cc_status )
{
	if( cc_status & 0x02 ) 			//Field 2 data--CC3, CC4, T3, T4, EDS
		return 0;
	return 1;
}

#define STD_CC_ROW1		43
#define STD_DIFF		13
#define STD_TOTAL		60			// 240 / LINES_PER_YSTEP

BYTE	GetCCRow(BYTE row_control)
{
	BYTE row;

	switch( row_control ) {
	case 0x14:	row=1;		break;
	case 0x16: 	row=2;		break;
	case 0x24:	row=3;		break;
	case 0x26:	row=4;		break;
	case 0x54:	row=5;		break;
	case 0x56:	row=6;		break;
	case 0x64:	row=7;		break;
	case 0x66:	row=8;		break;
	case 0x74:	row=9;		break;
	case 0x76:	row=10;		break;
	case 0x04:	row=11;		break;
	case 0x34:	row=12;		break;
	case 0x36:	row=13;		break;
	case 0x44:	row=14;		break;
	case 0x46:	row=15;		break;
	}

	return row;
}

BYTE SpecialCharToPrintable( BYTE cc_data )
{
	switch( cc_data ) 
	{
	case 0x30:	cc_data = 0x87;		break;
	case 0x31:	cc_data = 0x89;		break;
	case 0x32:	cc_data = 0x8a;		break;
	case 0x33:	cc_data = 0x84;		break;
	case 0x34:	cc_data = 0x88;		break;
	case 0x35:	cc_data = 0x85;		break;
	case 0x36:	cc_data = 0x8b;		break;
	case 0x37:	cc_data = 0x81;		break;
	case 0x38:	cc_data = 0x9b;		break;
	case 0x39:	cc_data = 0x20;		break;
	case 0x3a:	cc_data = 0x9c;		break;
	case 0x3b:	cc_data = 0xa0;		break;
	case 0x3c:	cc_data = 0xa1;		break;
	case 0x3d:	cc_data = 0xa2;		break;
	case 0x3e:	cc_data = 0xa3;		break;
	case 0x3f:	cc_data = 0xa4;		break;
	}
	return cc_data;
}

BYTE IncCCPos(void)
{
	CCPos++;
	if( CCPos > CCWinInfo[CCWin-CCWIN1].Cnt ) 
	{
		CCWinInfo[CCWin-CCWIN1].Cnt++;
		//Printf("\r\n(IncCCPos1:CCWinInfo[%d].Cnt:%d)", (WORD)CCWin, (WORD)CCWinInfo[CCWin].Cnt);
		if( CCWinInfo[CCWin-CCWIN1].Cnt + CCWinInfo[CCWin-CCWIN1].X <= CC_MAX_CHARS) 
			return TRUE;	//need to change width

		#ifdef DEBUG_CCEDS
		// do something for oveflow of row.
		//............
		ePrintf("\r\nline overflow (CCMode:%d)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", (WORD)CCMode);
		ePrintf("\r\n(CCWinInfo[%d].Cnt:%d)", (WORD)CCWin, (WORD)CCWinInfo[CCWin-CCWIN1].Cnt);
		#endif
				
		CCPos--;
		CCWinInfo[CCWin-CCWIN1].Cnt--;
		//Printf("\r\n(IncCCPos2:CCWinInfo[%d].Cnt:%d)", (WORD)CCWin, (WORD)CCWinInfo[CCWin].Cnt);
	}
	return FALSE;
}

BYTE DecCCPos(void)
{
	if( CCPos == CCWinInfo[CCWin-CCWIN1].Cnt ) {
		CCPos--;
		CCWinInfo[CCWin-CCWIN1].Cnt--;
		//Printf("\r\n(DecCCPos:CCWinInfo[%d].Cnt:%d)", (WORD)CCWin, (WORD)CCWinInfo[CCWin].Cnt);
		return TRUE;
	}

	CCPos--;
	return FALSE;
}

void CopyPrintableCCDataToOSD( BYTE cc_data, BYTE flag )
{
	CCAction = 1;

// Printf("[%bd,%04x]", CCPos + CCWinInfo[CCWin-CCWIN1].X, CCAddr);

	if( CCPos + CCWinInfo[CCWin-CCWIN1].X >= CC_MAX_CHARS ) CCAddr--;	// HHY 7/15/05 don't increase addr if it's full.

	if(flag==0) CopyCharToOSDRAM  (CCAddr++, CC_attr, cc_data);
	else        CopyUDCharToOSDRAM(CCAddr++, CC_attr, cc_data);


	switch( CCMode ) 
	{
	case POPON:
			IncCCPos();
			break;

	case ROLLUP2:
	case ROLLUP3:
	case ROLLUP4:
	case PAINTON:
			if( IncCCPos() ) 
			{
				SetCCWindowW( CCWin, CCWinInfo[CCWin-CCWIN1].Cnt  );
				
				if( CCWinInfo[CCWin-CCWIN1].Cnt==1 ) {			// first ch
					SetCCWindowColor( CCWin, CC_attr & 0xf0 );	//

					SetCCWindowX( CCWin, CCWinInfo[CCWin-CCWIN1].X + CCWinInfo[CCWin-CCWIN1].Tab );
					
					ShowCCWindow( CCWin, TRUE );
				}
			}
			break;

	case TEXTMODE:
			break;
	}
}

void BackspaceToOSD( void )
{
	CCAction = 50;

	#ifdef DEBUG_CCEDS
	dPrintf("\r\n(Backspace:CCPos:%d,", (WORD)CCPos );
	dPrintf("CCWinInfo[%d].Cnt:%d)", (WORD)CCWin, (WORD)CCWinInfo[CCWin-CCWIN1].Cnt );
	#endif
				
	switch( CCMode ) {
	case POPON:
			CCAddr--;
			DecCCPos();
			break;
	case ROLLUP2:
	case ROLLUP3:
	case ROLLUP4:
	case PAINTON:
			CCAddr--;
			if( DecCCPos() ) {
				SetCCWindowW( CCWin, CCWinInfo[CCWin-CCWIN1].Cnt  );
				if( CCWinInfo[CCWin-CCWIN1].Cnt ==0 )
					ShowCCWindow( CCWin, FALSE );
			}
			break;
	case TEXTMODE:
			CCAddr--;
			CopyCharToOSDRAM(CCAddr, BG_COLOR_BLACK | CH_COLOR_BLACK, ' '); 
			break;
	}
}

void DeleteEndOfRow( void )
{

	#ifdef DEBUG_CCEDS
	if( DebugTypeCCEDS>=BASIC )
		dPuts("\r\n[...Delete To End of Row...]");
	#endif

	switch( CCMode ) {
	case POPON:
			CCWinInfo[CCWin-CCWIN1].Cnt = CCPos;
			break;
	case ROLLUP2:
	case ROLLUP3:
	case ROLLUP4:
	case PAINTON:
			CCWinInfo[CCWin-CCWIN1].Cnt = CCPos;
			SetCCWindowW( CCWin, CCWinInfo[CCWin-CCWIN1].Cnt  );
			if( CCWinInfo[CCWin-CCWIN1].Cnt ==0 )
				ShowCCWindow( CCWin, FALSE );
			break;
	}
	//Printf("\r\n(DeleteEndOfRow:CCWinInfo[%d].Cnt:%d)", (WORD)CCWin, (WORD)CCWinInfo[CCWin-CCWIN1].Cnt);
}
/**
BYTE FoundSameRowWin( BYTE row, BYTE indent)
{
	BYTE i, temp;

	for(temp=S_CCWin, i=0; i<CCWinCnt; temp=GetLowerWinIndex(temp), i++ ) {
		if( CCWinInfo[temp-CCWIN1].Row == row ) break;
	}

	// couldn't fine same row
	if( i==CCWinCnt ) return FALSE;

	// found same row
	CCWin = temp;

	temp  = CCWinInfo[CCWin-CCWIN1].X;
	temp += CCWinInfo[CCWin-CCWIN1].Cnt;
	if ( indent < CCWinInfo[CCWin-CCWIN1].X ) {
		CCWinInfo[CCWin-CCWIN1].X = indent;
		CCAddr = CCAddrBuf + CC_MAX_CHARS * i + indent;
		CCPos = 0;
	}
	else if( indent < temp ) {
		CCAddr = CCAddrBuf + CC_MAX_CHARS * i + indent;
		CCPos = indent - CCWinInfo[CCWin-CCWIN1].X;
	}
	else {
		CCAddr = CCAddrBuf + CC_MAX_CHARS * i + temp;
		CCPos = CCWinInfo[CCWin-CCWIN1].Cnt;

		temp = indent - temp;
		CC_attr |= BG_COLOR_TRANS;
		for(; temp>0; temp--)
			CopyPrintableCCDataToOSD( ' ', 0);
		CC_attr &= (~BG_COLOR_TRANS);
	}

	return TRUE;
}
**/

BYTE FoundSameRowWin( BYTE row)
{
	BYTE i, temp;

	for(temp=S_CCWin, i=0; i<CCWinCnt; temp=GetLowerWinIndex(temp), i++ ) {
		if( CCWinInfo[temp-CCWIN1].Row == row ) break;
	}

	// couldn't fine same row
	if( i==CCWinCnt ) return FALSE;

	// found same row
	CCWin = temp;

⌨️ 快捷键说明

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