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

📄 eds.c

📁 此程序为twell8806驱动程序
💻 C
字号:
// EDS.c
//========================================================================
// EDS
// ver1.07-1 10/3/2001 .Created	for v-chip.
//					   .Using OSDWindow3.
//
//
//	ljy01xx04	(with ...CC_ comment)
//				.Modify whole structure of CheckVchip() 
//
//========================================================================
//	Possible EDS format
//		Control_code	Type	(d1,d2)[,(d3,d4),,,,(d31, d32)]
//		Control_code	checksum
//------------------------------------------------------------------------

#include "Config.h"
#ifdef SUPPORT_CCD_VCHIP
#include "typedefs.h"
#include "main.h"
#include "i2c.h"
#include "tw88.h"
#include "dispinfo.h"
#include "osdbasic.h"
#include "debug.h"
#include "printf.h"
#include "etc_eep.h"
#include "cc.h"
#include "audio.h"
#include "osdmenu.h"
#include "eds.h"

#define  CURRENT_CLASS_START		0x01
#define  CURRENT_CLASS_CONT_		0x02
#define  PROGRAM_RATING				0x05


static	IDATA BYTE  EDS_control=0;
static  IDATA BYTE  MovieRating=0, EDS_packet_len=0;
static  IDATA BYTE  BlockedTV, BlockedMovie, CurrentMovieRating=0, CurrentTVRating=0;
		bit   Block_On=0;
extern  bit		DisplayInputHold;


#define TV_Y7		2
//for CurrentTVRating and DisplayBlockedRating_Content()
// 0DVS Lrrr
#define CONTENT_TV_D_MASK	0x40		
#define CONTENT_TV_V_MASK	0x20
#define CONTENT_TV_S_MASK	0x10
#define CONTENT_TV_L_MASK	0x08
#define TVRATING_MASK		0x07

static  IDATA BYTE  BlockedTV_Content[7];

CODE BYTE OSDBlockedMovieStr[][10]={	//LJY100401 v-chip
	{ "None     " },
	{ "MPAA G   " },
	{ "MPAA PG  " },
	{ "MPAA PG13" },
	{ "MPAA R   " },
	{ "MPAA NC17" },
	{ "MPAA X   " },
	{ "MPAA NR  " }	//ljy020105...
};


CODE BYTE OSDBlockedTVStr[][7]={	//LJY100401 v-chip
	{ "None " },
	{ "TV-Y " },
	{ "TV-Y7" },
	{ "TV-G " },
	{ "TV-PG" },
	{ "TV-14" },
	{ "TV-MA" },
	{ "" }
};
CODE BYTE BlockedStr[]={ "Blocked:          "};
CODE BYTE ContentFVStr[]={"FV"};
CODE BYTE ContentVStr[]={"V"};
CODE BYTE ContentSStr[]={"S"};
CODE BYTE ContentLStr[]={"L"};
CODE BYTE ContentDStr[]={"D"};

void DisplayBlockedRating(CODE_P BYTE *str)
{
	extern CODE BYTE Init_Osd_DisplayVchipWindow[];
	extern CODE BYTE Str_Vchip_E[];
	BYTE length;

	if( GetDisplayedOSD() & INPUTINFO )		ClearInput();

	if( !(GetDisplayedOSD() & RATINGINFO))
	{
		ClearClosedCaption();//Change_OSDColorLookup();

		ClearDataCnt(RATINGINFO_ADDR, 18*2); 
		InitOSDWindow(Init_Osd_DisplayVchipWindow);

		DrawAttrCnt(RATINGINFO_ADDR, BACK_COLOR|CH_COLOR_WHITE, 18 );	 
		DrawAttrCnt(RATINGINFO_ADDR+18, BACK_COLOR|CH_COLOR_RED, 18 );
		WriteStringToAddr(RATINGINFO_ADDR, Str_Vchip_E, 6);

		SetDisplayedOSD ( RATINGINFO );
		#ifdef DEBUG_CCEDS
		Printf("\r\n SetDisplayedOSD : RATINGINFO ");
		#endif


	}
	WriteStringToAddr(RATINGINFO_ADDR+18, BlockedStr, 18);
	ShowOSDWindow(RATINGINFO_OSDWIN,TRUE);
	ShowOSDWindowAll(1);

	length=strlen(str);
	WriteStringToAddr(RATINGINFO_ADDR+18+8, str, length);
	#ifdef DEBUG_CCEDS
	Printf("\r\n DisplayBlockedRating==> %s",str);
	#endif
}

void CheckAndBlockInput(BYTE rating)
{
	BYTE redisp=0;

	SetLastBlockedTime();
	if( CurrentMovieRating != rating ) 
	{
			CurrentMovieRating = rating;
			CurrentTVRating = 0;
			if( GetDisplayedOSD() & CC ) 	
				ClearClosedCaption();
			//ClearClosedCaption();
			PanelBlack(1);//ForceDecoderOutput(BLUE_DECODER);
			DisplayBlockedRating(OSDBlockedMovieStr[rating]);
			Block_On = 1;

			// Audio Mute
			AudioOff();
			//SetAudioMute(1);

	}

}

void DisplayBlockedRating_Content(BYTE content)
{
	WORD pos;
	BYTE length;
	//content: 000FVSLD
	if( !content )
		return;

	SetOSDWindowNum(RATINGINFO_OSDWIN);
	pos = RATINGINFO_ADDR+18+8+6; 
	pos++;

	if( content & CONTENT_TV_V_MASK ) {	//V
		if( (content & TVRATING_MASK) == TV_Y7 ) { //FV
			length = strlen(ContentFVStr);
			WriteStringToAddr(pos, ContentFVStr, length);
	#ifdef DEBUG_CCEDS
			Printf("\r\n DisplayBlockedRating_Content==> %s",ContentFVStr);
	#endif
			pos+=2;
		}
		else {							//V
			length = strlen(ContentVStr);
			WriteStringToAddr(pos, ContentVStr,  length);
	#ifdef DEBUG_CCEDS
			Printf("\r\n DisplayBlockedRating_Content==> %s",ContentVStr);
	#endif
			pos++;
		}
	}
	if( content & CONTENT_TV_S_MASK ) {	//S
		WriteStringToAddr(pos, ContentSStr,  strlen(ContentSStr));
	#ifdef DEBUG_CCEDS
		Printf("\r\n DisplayBlockedRating_Content==> %s",ContentSStr);
	#endif
		pos++;
	}
	if( content & CONTENT_TV_L_MASK ) {	//L
		WriteStringToAddr(pos, ContentLStr,  strlen(ContentLStr));
	#ifdef DEBUG_CCEDS
		Printf("\r\n DisplayBlockedRating_Content==> %s",ContentLStr);
	#endif
		pos++;
	}
	if( content & CONTENT_TV_D_MASK ) 	//D
	{	WriteStringToAddr(pos, ContentDStr,  strlen(ContentDStr));
	#ifdef DEBUG_CCEDS
		Printf("\r\n DisplayBlockedRating_Content==> %s",ContentDStr);
	#endif
	}
}

void DisplayBlockedTVRating(void)
{
		PanelBlack(1);//ForceDecoderOutput(BLUE_DECODER);
		DisplayBlockedRating(OSDBlockedTVStr[CurrentTVRating&TVRATING_MASK]);
		DisplayBlockedRating_Content( CurrentTVRating );	// same as content_D
		Block_On = 1;

		AudioOff();
	  	//SetAudioMute(1);

}

void CheckAndBlockInputForTV(BYTE rating, BYTE content_D)
{
	#ifdef DEBUG_CCEDS
	Printf("\r\n CheckAndBlockInputForTV==> rating:%2x  content_D:%2x", (WORD)rating, (WORD)content_D);
	#endif
	//rating: xxVS Lrrr, content_D: xxDx xxxx 
	content_D = (content_D & 0x20) << 1 ;	// 0D00 0000
	content_D |= ( rating & 0x3f) ;			// 0DVS Lrrr

	if( CurrentTVRating != content_D ) {
		CurrentTVRating = content_D;
		CurrentMovieRating = 0;
		if( GetDisplayedOSD() & CC ) 		ClearClosedCaption();
		//ClearClosedCaption();
		DisplayBlockedTVRating();
		/*PanelBlack(1);//ForceDecoderOutput(BLUE_DECODER);
		DisplayBlockedRating(OSDBlockedTVStr[CurrentTVRating&TVRATING_MASK]);
		DisplayBlockedRating_Content( CurrentTVRating );	// same as content_D
		Block_On = 1;*/
	}
}


BYTE EnabledVChip(void)
{
	BYTE val;
	val = ( BlockedTV || BlockedMovie 
		|| BlockedTV_Content[1] // TV-Y			
		|| BlockedTV_Content[2] // TV-Y7		
		|| BlockedTV_Content[3] // TV-G
		|| BlockedTV_Content[4] // TV-PG
		|| BlockedTV_Content[5] // TV-14
		|| BlockedTV_Content[6] // TV-MA
		);
	return val;
}

void ChangeTVRating_Content(void)
{
	BYTE i, content=0;
	#ifdef DEBUG_CCEDS
	Printf("\r\n ChangeTVRating_Content");
	#endif

	BlockedTV_Content[0] = 0;
	for(i=1; i<7; i++){
		//if(BlockedTV == 0 ) BlockedTV_Content[i] = 0;
		//else 
		BlockedTV_Content[i] = GetBlockedTV_FLDSLEE(i);

		#ifdef DEBUG_CCEDS
		Printf("\r\n+++ Content of %s:%2x",OSDBlockedTVStr[i],(WORD)BlockedTV_Content[i]);
		#endif
	}
}

void ClearBlockedInput(void)
{
	CurrentMovieRating = 0;
	CurrentTVRating = 0;
	//ljy061303...ClearBlockedRating();
	//ClearForcedDecoderOutput();
	if( GetDisplayedOSD() & RATINGINFO ) {
		ClearDisplayedOSD (RATINGINFO);
		#ifdef DEBUG_CCEDS
		Printf("\r\n ===> ClearDisplayedOSD : RATINGINFO \n\n\n");
		#endif
		ShowOSDWindow(RATINGINFO_OSDWIN,FALSE);
	}
}

void CheckAndClearBlockedInput(void)
{
	//if( GetDisplayedOSD() & RATINGINFO ) {
	if( Block_On == 1){
		#ifdef DEBUG_CCEDS
		dPuts("\r\n(CheckAndClearBlockedInput)");
		#endif
		ClearBlockedInput();
		PanelBlack(0);////ClearForcedDecoderOutput();
		InitClosedCaption();
		if( DisplayInputHold ) DisplayInput();
		else	
		if( IsAudioMuteOn() ) DisplayMuteInfo();
		else  AudioOn();			//SetMSPVol();

		Block_On = 0;

		//SetAudioMute(0);

	}
}

BYTE IsBlock_On(void)
{
	return Block_On;
}

void InitEDS(void)
{
	//dPuts("\r\n++(InitEDS)--");
	EDS_control = 0;
	EnableEDS();
}

void ClearEDS(void)
{
	CheckAndClearBlockedInput();
	DisableEDS();
}

//----------------------------------------------------------------------
//	eds_data
//		0			.To make pair or checksum for end of packet command(0x0f)
//					.Can come as second byte.
//		<=0xF		.Control code or Type
//					.If EDS_control==0, Control code
//					 else, type code
//		<=0x1F		.Only for checksum
//		<=0xFF		.Information or checksum
//					
//----------------------------------------------------------------------
//ljy012304...CC_ACURATE_EDS
#define  IsSecondCharInPair				(cc_status %2)		//( !(EDS_packet_len%2) )
#define  IsFirstCharInPair				( !(cc_status%2) )	//( EDS_packet_len%2 )
#define  CHECKSUM						0x0f
#define  CURRENT_CLASS_START_RATING		0x15
#define  CURRENT_CLASS_CONT_RATING		0x25
#define	 _CLEAR_EDS_CONTROL_			{	EDS_control = 0;		EDS_packet_len = 0;	}
#ifdef SUPPORT_TW88_CC_DECODER
#define	 _SET_EDS_CONTROL_				{	EDS_control = eds_data;	EDS_packet_len = 1;	\
											if(	DoesCCFlagNeedDataFor(FIELD2) ) \
												ClearCCControl();} 
											//Clear CC_Control_byte1 if CC3,4,T3, or 4 want to be captured
											//because in this case, EDS and CC info data can not be mixed.
#else					
#define	 _SET_EDS_CONTROL_	;
#endif									
#define  IsChecksumPair					( (EDS_control==CHECKSUM) && (EDS_packet_len==2) )

BYTE CheckVchip(BYTE cc_status,BYTE eds_data) 
{

	EDS_packet_len++;

	if( eds_data==0 ) 
	{  //last char for pair or checksum
		if( IsChecksumPair || ( EDS_control && IsSecondCharInPair )  )
			_CLEAR_EDS_CONTROL_
		else 
		{
			//maybe CC data??
			#ifdef DEBUG_CCEDS1
			dPrintf("*** v-chip : maybe CC data(0)");
			#endif
			return FALSE;
		}
	}
	else if( eds_data <= 0x0f ) 
	{	//first or second control code or checksum
		if( IsChecksumPair ) 										//checksum value
			_CLEAR_EDS_CONTROL_
		else if( EDS_control ) 
		{									//second control code or new control code
			if( EDS_packet_len==2 )
			 {									//second control code
				EDS_control = (EDS_control <<4)| eds_data;					//make combined control code.
			}
			else if( IsFirstCharInPair ) 								//new contol code
				_SET_EDS_CONTROL_
			else 
			{
				;
				#ifdef DEBUG_CCEDS1
				dPrintf("*** v-chip : Invalid Data(~0f)");
				#endif
			}
		}
		else 
			_SET_EDS_CONTROL_
	}
	else if( eds_data <= 0x1f ) 
	{	//checksum , possible second control or CC data
		if( IsChecksumPair ) 										//checksum value
			_CLEAR_EDS_CONTROL_
		else if( EDS_control && (EDS_packet_len==2) )				//possible second control
			;
		else 
		{
			//maybe CC data??
			#ifdef DEBUG_CCEDS1
			dPrintf("*** v-chip : maybe CC data(~1f)");
			#endif
			return FALSE;
		}
	}
	else {						// checksum or Info data
		if( IsChecksumPair ) 										//checksum value
			_CLEAR_EDS_CONTROL_
		else if( EDS_control && (EDS_packet_len>2) )				//Info data
			;
		else {
			//maybe CC data??
			#ifdef DEBUG_CCEDS1
			dPrintf("*** v-chip : maybe CC data(~ff)");
			#endif
			return FALSE;
		}
	}

	#ifdef DEBUG_CCEDS
	if( GetDebugTypeCCEDS()>=ENHANCED1 ) 
		if( EDS_packet_len==1 )
			dPrintf("\r\nF2:%02X[%02X]:E ", (WORD)cc_status, (WORD)eds_data);
		else
			dPrintf("F2:%02X[%02X]:e ", (WORD)cc_status, (WORD)eds_data);
	if( GetDebugTypeCCEDS()>=ENHANCED2 ) 
		dPrintf("[ctrl:0x%x,len:%d] ", (WORD)EDS_control, (WORD)EDS_packet_len);
	#endif

	
	
	if( EDS_control== CURRENT_CLASS_START_RATING || EDS_control==CURRENT_CLASS_CONT_RATING )
	 {
		switch( EDS_packet_len ) 
		{
		case 3:						// eds_data==Information
				if( eds_data >= 0x40 )	MovieRating = eds_data;
				else					
				{
					MovieRating = 0;
					#ifdef DEBUG_CCEDS1
					dPrintf("*** v-chip :Invalid MovieRating Data");
					#endif
				}
				break;
		case 4:
				if( eds_data >= 0x40 ) 
				{	// Valid data 
					//TV rating
					if( (MovieRating & 0x40) && (eds_data & 0x40) ) 
					{	//valid data for rating
						if( (MovieRating & 0x08)==0 ) 
						{	//valid data for movie rating
							MovieRating &= 0x07;
						
							#ifdef DEBUG_CCEDS
							if( GetDebugTypeCCEDS() >=BASIC )
								dPrintf("*** v-chip info(%s)", OSDBlockedMovieStr[MovieRating]);
							#endif


							if( BlockedMovie && (MovieRating >= BlockedMovie) ) 
							{
								CheckAndBlockInput(MovieRating);	// Movie
							}
							else 
								CheckAndClearBlockedInput();
						 }
						else if( (MovieRating & 0x18)==0x08 ) 
						{	//valid data for USA TV rating
							//-----------------------------------------------------------------------
							//BYTE val;
							//val = (BlockedTV_Content[(eds_data&0x07)]&0x70) >> 1;
							#ifdef DEBUG_CCEDS
							if( GetDebugTypeCCEDS()>=BASIC )
								Printf("*** v-chip info(%s)", OSDBlockedTVStr[eds_data & 0x07]);
							#endif
							
							if( 
								( BlockedTV && ((eds_data&0x07) >= BlockedTV) )  || 
								(  ((BlockedTV_Content[(eds_data&0x07)]&0x70) >> 1) & (eds_data&0x38) ) || 
								(  (BlockedTV_Content[(eds_data&0x07)]&0x08) && ( MovieRating&0x20) ) // D
							   )
							 {
								Printf("*** eds_data:%2x   MovieRating:%2x ", (WORD)eds_data, (WORD)MovieRating );

								CheckAndBlockInputForTV(eds_data, MovieRating );	// TV
							}
							else 
								CheckAndClearBlockedInput();
							//-----------------------------------------------------------------------
						}
					}
				// ljy013105...for old standard...requested by DMTech of Korea
				}
				else					
				{
					MovieRating = 0;
					#ifdef DEBUG_CCEDS
					dPrintf("*** v-chip :Invalid MovieRating Data");
					#endif
				}
				_CLEAR_EDS_CONTROL_
				break;
		}
	}
	return TRUE;
}


/*ljy012004
BYTE IsEDS_control(void)
{
	return EDS_control;
}
*/

BYTE GetMPAARating(void)
{
	return BlockedMovie;
}
/*
BYTE GetTVRating(void)
{
	return BlockedTV;
}



BYTE SetMPAARating(BYTE wd)
{
	BlockedMovie = wd;
	return BlockedMovie;
}

BYTE SetTVRating(BYTE wd)
{
	BlockedTV = wd;
	#ifdef DEBUG_CCEDS
	Printf("\r\n SetTVRating==> BlockedTV:%s",OSDBlockedTVStr[BlockedTV]);
	#endif
	return BlockedTV;
}
*/
void ChangeVchipTV(BYTE newv)
{
	BlockedTV = newv;
	SaveBlockedTVEE(BlockedTV);

	ChangeTVRating_Content();

	#ifdef DEBUG_CCEDS
	Printf("\r\n ChangeVchipTV==> Changed BlockedTV:%s \n\n\n\n+++++++",OSDBlockedTVStr[BlockedTV]);
	#endif

	( EnabledVChip() ?	InitEDS()   :   ClearEDS()	);

}

BYTE ChangeVchipMovie(BYTE val)
{
	
	BlockedMovie = val;
	SaveBlockedMovieEE(BlockedMovie);
	( EnabledVChip() ?	InitEDS()   :   ClearEDS()	);

	return BlockedMovie;
}
#endif

⌨️ 快捷键说明

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