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

📄 cc_tw88.c

📁 此程序为twell8806驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
//=================================================================================================
//
//                                             CC with TW8804
//
//=================================================================================================
//
// Proper order of CC Data
// Pop-On mode:  
//				 Resume Caption Loading( to select pop-on style).
//				 Erase Nondisplayed Memory(optional)
//				 Preamble Command( to set row, indent, attr)
//				 text
//				 Preamble Command( to set row, indent, attr for next element)
//				 text,,,
//				 Erase Displayed Memory(optional)
//				 End Of Caption(to display the caption just received)
//
// Roll-Up mode: 
//				 RollUp captions,2rows or RU3 or RU4
//				 Carrige Return
//				 PAC
//				 text
//				 RollUp captions,2rows or RU3 or RU4
//				 ...
//
// Paint-On mode:
//				 Resume Direct Captioning
//				 PAC
//				 text
//				 PAC
//				 text or Delete to End of row
//				 (pause, or other data)
//				 Resume Direct Captioning
//				 PAC
//				 text
//				 Erase Displayed Memory
//
//
//	LJY120301	.Support ROLL-UP mode.
//
//	ljy01xx04	(with ...CC_ comment)
//				.Fix an horizontal indentation bug.
//				.Fix to support paused 'PaintOn' mode.
//				.Improve to support extended char set with OSD FONT RAM.
//				.Improve debugging messages to several levels.
//				.Give flexability to use OSD window (round).
//				.Improve to erase incorrect or unneeded CC display
//				.Try to improve Y position to mactch accurately, but need to restructure.
//========================================================================
/* 

	-- EDS
	----------------------------------------------------------------------
	----------------------------------------------------------------------
	0000 0001									
	.
	.
	.
	0000 ffff



	-- CC
	----------------------------------------------------------------------
	CC_control_byte1, CC_control_byte2
	----------------------------------------------------------------------
	0001 C000   0010 xxxx(>=0x20)	................Optional Attribute code ** need backspace

	----------------------------------------------------------------------
	0001 C000   010x xxxx(>=0x40)	................Preamble(row11, attr)

	----------------------------------------------------------------------
	0001 C001	0010 xxxx	............................Midrow

	0001 C001	0011 xxxx ....................................Special char.

	0001 C001   010x xxxx ..........................Preamble(row1, attr)
				011x xxxx	........................Preamble(row2, attr)

	----------------------------------------------------------------------
	0001 C010	001x xxxx	........................Extended Char
				
	0001 C010   010x xxxx	........................Preamble(row3, attr)
				011x xxxx	........................Preamble(row4, attr)
  
	----------------------------------------------------------------------
	0001 C011	001x xxxx	........................Extended Char
				
	0001 C011   010x xxxx	........................Preamble(row12, attr)
				011x xxxx	........................Preamble(row13, attr)

	----------------------------------------------------------------------
	0001 C10F	0010 xxxx	............................Misc.

	0001 C100   010x xxxx	........................Preamble(row14, attr)
				011x xxxx	........................Preamble(row15, attr)

	----------------------------------------------------------------------
	0001 C101   010x xxxx	........................Preamble(row5, attr)
				011x xxxx	........................Preamble(row6, attr)

	----------------------------------------------------------------------
	0001 C110   010x xxxx	........................Preamble(row7, attr)
				011x xxxx	........................Preamble(row8, attr)
  
	----------------------------------------------------------------------
	0001 C111	0010 xxxx	............................Misc.

	0001 C111	0010 0100	........................Optional Closed Group Extension
	                ~1010	........................Optional Closed Group Extension

	0001 C111	0010 1101	........................Optional attribute code ** need backspace
	                 1110	........................Optional attribute code(black) ** need backspace
	                 1111	........................Optional attribute code(black underline) ** need backspace

	0001 C111   010x xxxx	........................Preamble(row9, attr)
				011x xxxx	........................Preamble(row10, attr)

	----------------------------------------------------------------------
*/


//=================================================================================================

#include "panel.h"

#if (defined SXGA)

	#define CC_ZOOM			WINZOOMx3
	#define CC_HSPACE		0
	#define CC_VSPACE		1


#elif (defined XGA) || (defined WXGA)

	#define CC_ZOOM			WINZOOMx2
	#define CC_HSPACE		0//2
	#define CC_VSPACE		2

#elif (defined SVGA) || (defined WSVGA)

	#define CC_ZOOM			WINZOOMx2
	#define CC_HSPACE		0
	#define CC_VSPACE		0

#elif (defined VGA) || (defined WVGA)

	#define CC_ZOOM			WINZOOMx1
	#define CC_HSPACE		1//3
	#define CC_VSPACE		5

#else

	#define CC_ZOOM			WINZOOMx1
	#define CC_HSPACE		1//3
	#define CC_VSPACE		4

#endif

#define CC_FONT_WIDTH	(FONT_WIDTH_TW88*CC_ZOOM  + CC_HSPACE*CC_ZOOM)
#define CC_FONT_HEIGHT	(FONT_HEIGHT_TW88*CC_ZOOM + CC_VSPACE*2*CC_ZOOM)

#define CC_HBORDER		CC_FONT_WIDTH/CC_ZOOM
#define CC_X_ORG		(PHR_ - CC_FONT_WIDTH*34) / 2
#define CC_Y_ORG		(PVR_ - CC_FONT_HEIGHT*15) / 2

#ifdef SVGA
	#undef CC_HBORDER
	#undef CC_Y_ORG
	#undef CC_X_ORG

	#define CC_HBORDER		4
	#define CC_Y_ORG		CC_FONT_HEIGHT
	#define CC_X_ORG		8
#endif

#ifdef WSVGA
	#undef CC_Y_ORG
	#define CC_Y_ORG		CC_FONT_HEIGHT
#endif



//=================================================================================================


#define		HIGHBYTE_DATA		( (*cc_status) & 0x01 )

#ifdef DEBUG
#define		MAX_CCEDS_BUF		10
#else
#define		MAX_CCEDS_BUF		10
#endif

static	DATA BYTE DebugTypeCCEDS=BASIC;	
static	PDATA	BYTE CCEDSStatusBuf[MAX_CCEDS_BUF];
		PDATA	BYTE CCEDSDataBuf[MAX_CCEDS_BUF];
		DATA	BYTE CCEDSDataBuf_rear=1, CCEDSDataBuf_front=0;
		bit  CC_remove_pair=0;
static  IDATA BYTE  CC_control_byte1=0, CC_control_byte2 = 0;
//		ljy011304...CC_INFO...
//		CC_control_byte1 : 
//		1) 0x10-0x1f: The first byte of CC control code.
//		2) 0		: Not in the middle of control code.
//		3) 0xff		: previous control code was for other channel.			

#define CCWINTRANS1			0			// block bottom
#define CCWINTRANS2			1			// block upper

#define CCWIN1				2			// 4th line
#define CCWIN2				3			// 3rd line
#define CCWIN3				4			// 2nd line
#define CCWIN4				5			// 1st line
#define CCWIN5				6			// 0 line for scroll

#define CCWINCNT			4

#define CC_MAX_CHARS		32
#define CC_ADDR2			0		
#define TEXTMODE_WIN		CCWIN4		//ljy011404...CC_ADD_TEXTMODE_WIN...TEXTMODE uses only 1 window.
#define ROLLUP_START_WIN	CCWIN4		//ljy011504...CC_FIX_SWITCH_STYLE

#define TEXTMODE_STARTROW	3
#define TEXTMODE_MAXROWS	10
#define TEXTMODE_MAXCLMS	32

//-----CCMode
#define POPON				0x20
#define ROLLUP2				0x25
#define ROLLUP3				0x26
#define ROLLUP4				0x27
#define PAINTON				0x29
#define TEXTMODE			0x2a

#ifdef DEBUG_CCEDS
CODE char CCAttrStr[][20]={
	{"white"},
	{"green"},
	{"blue"},
	{"cyan"},
	{"red"},
	{"yellow"},
	{"magenta"},
	{"italics"},
	{"indent0, white"},
	{"indent4, white"},
	{"indent8, white"},
	{"indent12, white"},
	{"indent16, white"},
	{"indent20, white"},
	{"indent24, white"},
	{"indent28, white"}
};
#endif // DEBUG_CCEDS

static  BYTE CCAction=0;
struct  CCWinInfo {
	BYTE Cnt, Row, X, Tab;
}   CCWinInfo[CCWIN4-CCWIN1+1];

static  IDATA BYTE	CCWin,	CCWinCnt,	S_CCWin, CCPos;
static  IDATA WORD  CCAddr, CCAddrBuf;
//----------------------------------------------------------------------------------------------
//		ljy011204...CC_INFO...
//		CCPos:		(CaptionMode:PaintOn, PopOn, RollUp)- CursorOffset from startX
//			 :		(TextMode)							- Not used.
//
//		CCAddrBuf:	(CaptionMode:PaintOn, PopOn, RollUp)- The first OSD RAM address of the first row.
//				 :	(TextMode)							- The first OSD RAM address of working row.
//
//		CCAddr:		(Every Mode)						- Current OSD RAM address.
//
//		CCWin:		(CaptionMode:PaintOn, PopOn, RollUp)- OSD Window's index for current working row.
//					(TextMode)							- Always TEXTMODE_WIN.
//
//		CCWinCnt:	(CaptionMode:PaintOn, PopOn, RollUP)- The number of OSD Windows having data.
//					(TextMode)							- Not used.
//----------------------------------------------------------------------------------------------

static  IDATA BYTE  control_code_count=0, CC_attr=0, CCMode;
static  bit   UnwantedMode = 0;

#define GetNextCCAddr ( (CCAddr + CC_MAX_CHARS - 1 ) / CC_MAX_CHARS * CC_MAX_CHARS )

//----------------------------------------------------------------------------------------------
//		ljy011304...CC_FIX_PROCESS_OTHER_CH_MODE
//		UnwantedMode:	1 - When received text mode data even though user want to see CaptionMode or vice versa.
//						0 - When the mode user set matches with input data
//----------------------------------------------------------------------------------------------
#define SetForOtherCh()			CC_control_byte1 = 0xff
#define IsForOtherCh()			(CC_control_byte1==0xff)
#define OnUnwantedMode()		UnwantedMode	= 1	
#define OffUnwantedMode()		UnwantedMode	= 0
#define IsUnwantedMode()		( UnwantedMode )

#define GetLowerWinIndex(A)		( (((A-CCWIN1)+CCWINCNT-1)%CCWINCNT)+CCWIN1 )
#define GetUpperWinIndex(A)		( (((A-CCWIN1)+1)%CCWINCNT)+CCWIN1 )

#define SetCCWindowNum(a)		WriteTW88(TW88_WINNUM, a);

//=================================================================================================
// For Roll-Up
static DATA BYTE lines=CC_FONT_HEIGHT;
static DATA BYTE StartWin=0, StartRow=0;
static DATA BYTE WinCnt=0;
static bit LastField=0;
//=================================================================================================

void ShowCCWindow(BYTE winno, BYTE onoff)
{
	BYTE rd;

	SetCCWindowNum(winno);

	rd = ReadTW88(TW88_WINATTR);
	if( onoff ) rd |= 0x01;
	else 		rd &= 0xfe;
	WriteTW88(TW88_WINATTR, rd);
}
//=================================================================================================
//
//=================================================================================================
void CopyCharToOSDRAM(WORD addr, BYTE attr, BYTE ch)
{

	EnableOSDRAMAndChangeFont( FONT_ROM );
	#ifndef TW8806
	{
	BYTE dat;
	addr &= 0x1ff;
	dat = ReadTW88(TW88_OSDRAMADDRHI) & 0xfe;
	dat |= addr>>8;
	WriteTW88(TW88_OSDRAMADDRHI, dat);
	}
	#endif
	WriteTW88(TW88_OSDRAMADDRLO, addr);
	WriteTW88(TW88_OSDRAMDATALO, attr);
	WriteTW88(TW88_OSDRAMDATAHI, ch);
}

void CopyUDCharToOSDRAM(WORD addr, BYTE attr, BYTE ch)
{

	EnableOSDRAMAndChangeFont( FONT_RAM );
	#ifndef TW8806
	{
	BYTE dat;
	addr &= 0x1ff;
	dat = ReadTW88(TW88_OSDRAMADDRHI) & 0xfe;
	dat |= addr>>8;
	WriteTW88(TW88_OSDRAMADDRHI, dat);
	}
	#endif
	WriteTW88(TW88_OSDRAMADDRLO, addr);
	WriteTW88(TW88_OSDRAMDATALO, attr);
	WriteTW88(TW88_OSDRAMDATAHI, ch);
}
//=================================================================================================
//				Get/Set Window/Char attribute for CC
//=================================================================================================
WORD GetCCWindowSA(BYTE winno)
{
	WORD Addr;

	SetCCWindowNum(winno);

	Addr = ReadTW88(TW88_WINSADDRLO);
	Addr += (ReadTW88(TW88_WINSADDRHI) & 0x01)<<8;

	return Addr;
}

void SetCCWindowW(BYTE winno, BYTE w)
{
	SetCCWindowNum(winno);
	WriteTW88(TW88_WINWIDTH, w);	// x width(1 character width per 1 step)
}

void SetCCWindowSA(BYTE winno, WORD sa)
{
	BYTE dat;

	SetCCWindowNum(winno);

	sa &= 0x1ff;
	dat = (ReadTW88(TW88_WINSADDRHI) & 0xfe) | (sa>>8);
	WriteTW88(TW88_WINSADDRHI, dat);
	WriteTW88(TW88_WINSADDRLO, sa);		// Start address of OSD RAM
}

void SetCCWindowColor(BYTE winno, BYTE color)
{
	BYTE dat;

	SetCCWindowNum(winno);
	
	dat = ReadTW88(TW88_WINATTR) & 0x0f;
	WriteTW88(TW88_WINATTR, dat | color);
}

void SetOSDItalicsAndUnderline(BYTE italics, BYTE underline)
{
	BYTE dat;

	dat = ReadTW88(TW88_ENABLERAM) & 0x9f;

	if(italics) dat |= 0x40;
	if(underline) dat |= 0x20;

	WriteTW88(TW88_ENABLERAM, dat);
}

//=================================================================================================
//
//=================================================================================================
void ClearBlending(void)
{
	BYTE i, winno;

	for(winno=CCWIN1; winno<=CCWIN4; winno++) {
		for(i=0; i<16; i++) {
			WriteTW88(TW88_WINNUM, winno | (i*0x10) );
			WriteTW88(TW88_WINBLENDING, 0);
		}
	}
}
//=================================================================================================
//			X(Column) = 0 ~ 31, Y(Row) = 1 ~ 15
//=================================================================================================
void SetCCWindowX(BYTE winno, BYTE x)
{
	BYTE dat;
	WORD tmp;

	SetCCWindowNum(winno);

	tmp = x * CC_FONT_WIDTH + CC_X_ORG;

	dat = ReadTW88(TW88_WINSTART_HI) & 0xf0;
	dat = dat | (tmp>>8);
	WriteTW88(TW88_WINSTART_HI, dat);
	WriteTW88(TW88_WINXSTART, tmp);
}

WORD GetCCWindowYbyRow(BYTE row)
{
	if( row>=0 && row <=16 ) 
		return( (row-1) * CC_FONT_HEIGHT + CC_Y_ORG );

	#ifdef DEBUG_CCEDS
	ePrintf("\r\n+++++++ Row is outof range:%02bx", row);
	#endif

⌨️ 快捷键说明

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