📄 saa7114.c
字号:
SoftwareReset(pDE,nChannel);
}
void SoftwareReset(PDEVICE_EXTENSION pDE, ULONG nChannel)
{
UCHAR VIPAddresses[2]={IIC_SUB_VIP,IIC_SUB_VIP2};
//SoftWare Reset
IICWrite(pDE,VIPAddresses[nChannel],0x88,0xd0); //88H,bit SWRST
IICWrite(pDE,VIPAddresses[nChannel],0x88,0xf0);
}
void GetTimeBias(PDEVICE_EXTENSION pDE);
void SetOwnerChar(PDEVICE_EXTENSION pDE, ULONG nChineseChar, unsigned char *pHanLib, int nIndex);
void SetUserBitmap(PDEVICE_EXTENSION pDE, unsigned char *pBitmap);
//bit 7-0 of nMode: 0 -- disable
// 1 -- YY/MM/DD
// 2 -- YY/DD/MM
// 3 -- DD/MM/YY
// 4 -- mmmDD/YY
// 5 -- YY/mmmDD
//bit 15-8 of nMode: 0 -- '-'
// 1 -- '.'
// 2 -- '/'
// 3 -- ' '
const char cSpaceChar[]={'-', '.', '/', ' '};
const char *sMon[12]={
"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
};
#define BASE_OWNER_CHAR 248
#define UPDATE_DATE 0x01
#define UPDATE_NAME 0x02
int SetOSD(PDEVICE_EXTENSION pDE, int nMode, unsigned char *pName, unsigned char *pHanLib)
{
int i;
int nUser;
int nReplace=BASE_OWNER_CHAR;
int nOSDMode=nMode&0xff;
unsigned char buf[8];
if(pDE->nOSDMode && nOSDMode==0){//trun OSD off
//close OSD:
//clear ram data & disable OSD
buf[0]=15|0x80;
buf[1]=17;
buf[2]=0x06;
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
//buf[0]=15|0x80;
//buf[1]=17;
//buf[2]=0x00;//disable OSD
//IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
KeCancelTimer(&pDE->OSDTimer);
pDE->nOSDMode = 0;
//DebugPrintMsg("OSD off!");
return 1;
}
if(nOSDMode==0) {
return 1;
}
if(((nMode>>8)&0xff)>3) {
return 0;
}
pDE->nSpaceChar=cSpaceChar[(nMode>>8)&0xff];
if(nMode&0x80000000){ //pBitmap
for(i=0; i<6; i++)
*(pDE->pChannelName+i)=BASE_OWNER_CHAR+i;
SetUserBitmap(pDE, pHanLib);
}
else{
memcpy(pDE->pChannelName, pName, 6);
for(i=0; i<6; i++){
if(pName[i]==0){//if meet string end, fill in 0 (blank for MTV118)
memset(pDE->pChannelName+i, 0, 6-i);
break;
}
if(pName[i]&0x80){//chinese character
if(pHanLib){
SetOwnerChar(pDE, (pName[i]<<8)|pName[i+1], pHanLib, nReplace-BASE_OWNER_CHAR);
pDE->pChannelName[i++]=nReplace++;
pDE->pChannelName[i]=nReplace++;
}
else{
pDE->pChannelName[i++]=0;
pDE->pChannelName[i]=0;
}
}
}
}
pDE->nOSDUpdate=UPDATE_NAME|UPDATE_DATE;
if(pDE->nOSDMode==0 && nOSDMode){//trun OSD on
LARGE_INTEGER llDelay;
llDelay.LowPart=-1000;
llDelay.HighPart=0;
pDE->nOSDMode=nOSDMode;
KeSetTimerEx(&pDE->OSDTimer, llDelay, 1000, &pDE->OSDDpc);
}
else
pDE->nOSDMode=nOSDMode;
#if _WIN32_WINNT==0x0500 && TD_WIN98
//query system timezone setting
GetTimeBias(pDE);
#endif
return 1;
}
#if _WIN32_WINNT==0x0500 && TD_WIN98
NTSTATUS GetTimeBiasCallback(
IN PWSTR ValueName,
IN ULONG ValueType,
IN PVOID ValueData,
IN ULONG ValueLength,
IN PVOID Context,
IN PVOID EntryContext)
{
PDEVICE_EXTENSION pDE=(PDEVICE_EXTENSION)Context;
pDE->nTimeBias=-*(PLONG)ValueData;
return STATUS_SUCCESS;
}
void GetTimeBias(PDEVICE_EXTENSION pDE)
{
RTL_QUERY_REGISTRY_TABLE QueryTable[2];
int DefaultBias=-8*60;//for China, +8:00
memset(QueryTable, 0, sizeof(RTL_QUERY_REGISTRY_TABLE)*2);
QueryTable[0].QueryRoutine=GetTimeBiasCallback;
QueryTable[0].Name=L"ActiveTimeBias";
QueryTable[0].DefaultType=REG_BINARY;
QueryTable[0].DefaultData=&DefaultBias;
QueryTable[0].DefaultLength=4;
QueryTable[1].QueryRoutine=NULL;
QueryTable[1].Name=NULL;
RtlQueryRegistryValues(
RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
QueryTable,
pDE,
NULL);
}
#endif
const char *sDateFormat[]={
"%02d%c%02d%c%02d",
"%s%02d%c%02d",
"%02d%c%s%02d"
};
void InitOSD(PDEVICE_EXTENSION pDE)
{
unsigned char buf[40];
//clear ram data
buf[0]=15|0x80;
buf[1]=17;
buf[2]=0x06;
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
//enable OSD
buf[0]=15|0x80;
buf[1]=17;
buf[2]=0x80;
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
//horizonal offset
buf[0]=15|0x80;
buf[1]=13;
//buf[2]=60;//81;
buf[2]=60; //add by caca
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
//vertical offset
buf[0]=15|0x80;
buf[1]=12;
buf[2]=67;
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
//polarity
buf[0]=15|0x80;
buf[1]=18;
//buf[2]=0x54;
buf[2]=0x44; //add by caca
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
//DebugPrintMsg("InitOSD end!");
}
void ExtendString(char *pDest, const char *pSrc) //call in AVE6KDpcForOSD
{
int i;
char c;
for(i=0; i<=8; i++){
c=*pSrc++;
if(c==' ')
c=0;
*pDest++=c;
pDest++;
}
}
VOID AVE6KDpcForOSD(
IN PKDPC Dpc,
IN PVOID DeferredContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2
)
{
PDEVICE_OBJECT DeviceObject = DeferredContext;
PDEVICE_EXTENSION pDE = DeviceObject->DeviceExtension;
unsigned char buf[40];
unsigned char sDTString[10];//date & time string
LARGE_INTEGER Time, LocalTime, TimeBias;
TIME_FIELDS TimeFields;
int nDay, nMon, nYear, nHour, nMin, nSec;
//Get date & time
KeQuerySystemTime(&Time);
// ExSystemTimeToLocalTime(&Time, &LocalTime);
#if _WIN32_WINNT==0x0400 || !TD_WIN98
//NT, 2000 & later
ExSystemTimeToLocalTime(&Time, &LocalTime);
#else
//win98 (& me?)
TimeBias.QuadPart=pDE->nTimeBias;
TimeBias.QuadPart*=60*10000000;
LocalTime=RtlLargeIntegerAdd(Time, TimeBias);
#endif
RtlTimeToTimeFields(&LocalTime, &TimeFields);
if(pDE->nDay!=TimeFields.Day)
pDE->nOSDUpdate|=UPDATE_DATE;
nDay=TimeFields.Day;
nMon=TimeFields.Month;
nYear=(TimeFields.Year+1600-2000)%100;
nHour=TimeFields.Hour;
nMin=TimeFields.Minute;
nSec=TimeFields.Second;
//DebugPrint("OSD Dpc: Day=%d, Mon=%d, Year=%d, Hour=%d, Min=%d, Sec=%d",nDay,nMon,nYear,nHour,nMin,nSec);
buf[0]=15|0x80;
buf[1]=17;
buf[2]=0x80;//enable OSD
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
if(pDE->nOSDUpdate&UPDATE_NAME){
//SetChannelName;
buf[0]=0|0x80;//row
buf[1]=18|0x40;//column
memset(buf+2, 0, 6*2);
ExtendString((char *)buf+2, pDE->pChannelName);
IICWriteBytes(pDE, IIC_SUB_OSD, 6*2+2, buf);
buf[0]=0|0xa0;//row
buf[1]=18|0x40;//column
memset((char *)buf+2, 0x07, 6*2);
IICWriteBytes(pDE, IIC_SUB_OSD, 6*2+2, buf);
buf[0]=0|0x80;//row
buf[1]=30;
buf[2]=0x01;
//buf[2]=0x00; //add by caca
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
pDE->nOSDUpdate &= ~UPDATE_NAME;
}
if(pDE->nOSDUpdate&UPDATE_DATE){
//build date string
char cSpace;
cSpace=(unsigned char)(pDE->nSpaceChar);
switch(pDE->nOSDMode){
case 1:
sprintf(sDTString, sDateFormat[0], nYear, cSpace, nMon, cSpace, nDay);
break;
case 2:
sprintf(sDTString, sDateFormat[0], nYear, cSpace, nDay, cSpace, nMon);
break;
case 3:
sprintf(sDTString, sDateFormat[0], nDay, cSpace, nMon, cSpace, nYear);
break;
case 4:
sprintf(sDTString, sDateFormat[1], sMon[nMon-1], nDay, cSpace, nYear);
break;
case 5:
sprintf(sDTString, sDateFormat[2], nYear, cSpace, sMon[nMon-1], nDay);
break;
}
//Set date string
buf[0]=0|0x80;//row
buf[1]=0|0x40;//column
ExtendString((char *)buf+2, sDTString);
IICWriteBytes(pDE, IIC_SUB_OSD, 8*2+2, buf);
buf[0]=0|0xa0;//row
buf[1]=0|0x40;//column
memset((char *)buf+2, 0x07, 8*2);
IICWriteBytes(pDE, IIC_SUB_OSD, 8*2+2, buf);
pDE->nOSDUpdate &= ~UPDATE_DATE;
}
//build time string
sprintf(sDTString, "%02d:%02d:%02d", nHour, nMin, nSec); //add by caca
//Set date & time string
buf[0]=1|0x80;//row
buf[1]=0|0x40;//column
ExtendString((char *)buf+2, sDTString);
IICWriteBytes(pDE, IIC_SUB_OSD, 8*2+2, buf);
buf[0]=1|0xa0;//row
buf[1]=0|0x40;//column
memset((char *)buf+2, 0x07, 8*2);
IICWriteBytes(pDE, IIC_SUB_OSD, 8*2+2, buf);
buf[0]=1|0x80;//row
buf[1]=30;
buf[2]=0x01;
//buf[2]=0x00; //add by caca
IICWriteBytes(pDE, IIC_SUB_OSD, 3, buf);
}
void SetOwnerChar(PDEVICE_EXTENSION pDE, ULONG nCnChar, unsigned char *pHanLib, int nIndex)
{
unsigned char c1, c2;
unsigned char buf[40];
int nRow=nIndex;
int i;
unsigned char byData;
c1=(unsigned char)(nCnChar>>8);
c2=(unsigned char)(nCnChar&0xff);
if(c1<0xa1 || c1>0xf7 || c2<0xa1 || c2>0xfe)
return;
if(c1>=0xb0)
c1-=4;
pHanLib+=((c1-0xa1)*0x5e+c2-0xa1)*32;
// 1/2
buf[0]=nRow|0xc0;
buf[1]=0|0x40;
buf[2]=0;
buf[3]=0;
buf[36]=0;
buf[37]=0;
for(i=0; i<16; i++){
byData=*(pHanLib+i);
buf[i*2+4]=byData>>4;
buf[i*2+5]=(byData&0x0f)<<4;
}
IICWriteBytes(pDE, IIC_SUB_OSD, 38, buf);
nRow++;
// 2/2
buf[0]=nRow|0xc0;
buf[1]=0|0x40;//column
for(i=0; i<16; i++){
byData=*(pHanLib+i+16);
buf[i*2+4]=byData;
buf[i*2+5]=0;
}
IICWriteBytes(pDE, IIC_SUB_OSD, 38, buf);
}
void SetUserBitmap(PDEVICE_EXTENSION pDE, unsigned char *pBitmap)
{
int i,j;
unsigned char buf[40];
unsigned char *pData;
for(i=0; i<3; i++){
// 1/2
buf[0]=(i*2)|0xc0;
buf[1]=0|0x40;
for(j=0; j<18; j++){
pData=pBitmap+j*9+i*3;
buf[j*2+2]=*pData;
buf[j*2+3]=*(pData+1);
}
IICWriteBytes(pDE, IIC_SUB_OSD, 38, buf);
// 2/2
buf[0]=(i*2+1)|0xc0;
buf[1]=0|0x40;
for(j=0; j<18; j++){
pData=pBitmap+j*9+i*3+1;
buf[j*2+2]=(*pData<<4)|(*(pData+1)>>4);
buf[j*2+3]=*(pData+1)<<4;
}
IICWriteBytes(pDE, IIC_SUB_OSD, 38, buf);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -