📄 chipdef.cpp
字号:
int ChipDef::GetCSVText( char* Text, int Size, int BuildNumber )
{
int i;
int iT = 0;
if ( Text == NULL )
return 0;
DOTEXT "Comma-Separated Value information generated by %sCFG.EXE (Build %u)" NL
"Copyright (c) 2003 Epson Research and Development, Inc." NL
"All rights reserved." NL
"" NL, GetProductName(NULL,GN_NAME), BuildNumber );
DOTEXT "Configuration Data CRC: %04Xh" NL
"" NL, CalculateHalInfoCRC(m_HalInfo) );
for ( i=0; i<=m_MaxHalInfoRegIndex; i++ )
if ( IsRegisterValid(i,true) )
{
char szReg[16];
if ( false /*m_HalInfo.Regs[i].Index==REGFLAG_ONDELAY || m_HalInfo.Regs[i].Index==REGFLAG_OFFDELAY || m_HalInfo.Regs[i].Index==REGFLAG_PLLDELAY */)
strcpy( szReg, "Delay" );
else
sprintf( szReg, "%0*Xh", m_DefaultRegIndexField, m_HalInfo.Regs[i].Index );
DOTEXT "%s, %0*Xh, %s" NL, szReg, GetRegisterValueFieldWidth(i,true), m_HalInfo.Regs[i].Value, GetRegisterName(i,true,GN_NAME|GN_ATTRS) );
}
assert( iT < Size );
return iT;
}
int ChipDef::GetGenericHeaderText( char* Text, int Size, int BuildNumber, int ModeFlags )
{
int i;
int iT = 0;
char* pszField;
if ( Text == NULL )
return 0;
int bpp = GetFeatureNumValue("bpp");
int width = ( GetFeatureRawValue("stride") + 1 ) * 8 / GetFeatureRawValue("bpp");
int height = GetFeatureRawValue("lf") + 1;
int stride = ChipDefBase::GetFeatureRawValue( "stride" )+1;
DOTEXT "/*==================================================================" NL
"** Generic Header information generated by %sCFG.EXE (Build %u)" NL
"** Copyright (c) Seiko Epson Corporation 2003-2005." NL
"** All rights reserved." NL
"**" NL, GetProductName(NULL,GN_NAME), BuildNumber );
DOTEXT "**" NL
"** This file defines the configuration environment and registers," NL
"** which can be used by any software, such as display drivers." NL
"**" NL
"** Note: If you transfer this file to any non-PC system, use ASCII" NL
"** mode (not BINARY) to maintain system-specific line terminators." NL
"**==================================================================*/"NL
"" NL );
DOTEXT "#define S1D_%s" NL, GetProductName(NULL,GN_NAME) );
DOTEXT "#define S1D_DISPLAY_BPP %u" NL, bpp );
DOTEXT "#define S1D_DISPLAY_WIDTH %u" NL, width );
DOTEXT "#define S1D_DISPLAY_HEIGHT %u" NL, height );
DOTEXT "#define S1D_DISPLAY_SCANLINE_BYTES %u" NL, stride );
DOTEXT "#define S1D_DISPLAY_FRAME_RATE %u" NL, GetFeatureNumValue("framerate") );
DOTEXT "#define S1D_DISPLAY_PCLK %uL" NL, GetFeatureNumValue("pclk") );
DOTEXT "#define S1D_PHYSICAL_REG_ADDR 0x%08XL" NL, GetFeatureNumValue("regaddr") );
DOTEXT "#define S1D_PHYSICAL_VMEM_ADDR 0x%08XL" NL, GetFeatureNumValue("memaddr") );
DOTEXT "#define S1D_PHYSICAL_VMEM_SIZE %uL" NL, GetFeatureNumValue("bufsize") );
DOTEXT "#define S1D_PHYSICAL_VMEM_REQUIRED %uL" NL, GetFeatureNumValue("vram") );
DOTEXT "#define S1D_PHYSICAL_REG_SIZE 33" NL );
DOTEXT "#define S1D_REGRESERVED 0x%04X" NL, REGFLAG_BASE );
DOTEXT "#define S1D_REGDELAYOFF 0x%04X" NL, REGFLAG_OFFDELAY );
DOTEXT "#define S1D_REGDELAYON 0x%04X" NL, REGFLAG_ONDELAY );
DOTEXT "" NL );
DOTEXT "typedef unsigned short S1D_INDEX;" NL
"typedef unsigned short S1D_VALUE;" NL
"typedef struct" NL
"{" NL
" S1D_INDEX Index;" NL
" S1D_VALUE Value;" NL
"} S1D_REGS;" NL );
DOTEXT "" NL );
DOTEXT "#define S1D_INSTANTIATE_REGISTERS(scope_prefix,variable_name) \\" NL
" scope_prefix S1D_REGS variable_name[] = \\" NL
" { \\" NL );
DOTEXT " { 0x0008, 0x00 }, /* Sleep In Register */ \\" NL );
for ( i=0; i<=m_MaxHalInfoRegIndex; i++ )
if ( IsRegisterValid(i,true) )
{
if ( m_HalInfo.Regs[i].Index<REGFLAG_BASE )
{
switch( m_HalInfo.Regs[i].Index )
{
case REGFLAG_OFFDELAY: pszField=sprintfield(18,",","%s","S1D_REGDELAYOFF"); break;
case REGFLAG_ONDELAY: pszField=sprintfield(18,",","%s","S1D_REGDELAYON"); break;
case REGFLAG_ENDOFTABLE: pszField=NULL; break;
default: pszField=sprintfield(18,",","0x%0*X",m_DefaultRegIndexField,m_HalInfo.Regs[i].Index); break;
}
if ( pszField && m_HalInfo.Regs[i].Index != 0x08)
DOTEXT " { %s" "0x%0*X }, /* %-51s */ \\" NL, pszField, GetRegisterValueFieldWidth(i,true), m_HalInfo.Regs[i].Value, GetRegisterName(i,true,GN_NAME|GN_ATTRS) );
}
}
BlankLastCommaInString( Text+iT );
DOTEXT " }" NL );
// Add extra lines because Juro states that gcc needs them otherwise a warning occurs.
DOTEXT "" NL );
DOTEXT "" NL );
assert( iT < Size );
return iT;
}
int ChipDef::GetWinCEHeaderText( char* Text, int Size, unsigned Mode, int ModeFlags, int BuildNumber )
{
int i, f = 28;
int iT = 0;
char* pszField;
if ( Text == NULL )
return 0;
int bpp = GetFeatureNumValue("bpp");
DOTEXT "//==================================================================" NL
"// WinCE Header information generated by %sCFG.EXE (Build %u)" NL
"// Copyright (c) Seiko Epson Corporation 2003-2005." NL
"// All rights reserved." NL
"//" NL, GetProductName(NULL,GN_NAME), BuildNumber );
DOTEXT "//" NL
"// This file INSTANTIATES the a WinCE mode structure, and should" NL
"// only be included, one time, by a WinCE display driver." NL
"//==================================================================" NL
"" NL
"#ifndef __MODE%u_H__" NL
"#define __MODE%u_H__" NL
"" NL, Mode, Mode );
DOTEXT "#define Epson%uBpp" NL, bpp );
DOTEXT "#define riDELAYOFF 0x%0*X" NL, m_DefaultRegIndexField, REGFLAG_OFFDELAY );
DOTEXT "#define riDELAYON 0x%0*X" NL, m_DefaultRegIndexField, REGFLAG_ONDELAY );
DOTEXT "#define riREGEND 0x%0*X" NL, m_DefaultRegIndexField, REGFLAG_ENDOFTABLE );
DOTEXT "" NL
"{" NL
" {" NL );
DOTEXT " %s" "// Version 1.00" NL, sprintfield(f, ",", "0x%04X", 1*256+0) );
DOTEXT " %s" "// Physical Memory Address" NL, sprintfield(f, ",", "0x%08XL", GetFeatureNumValue("memaddr")) );
DOTEXT " %s" "// Physical Memory Size" NL, sprintfield(f, ",", "%uL", GetFeatureNumValue("bufsize")) );
DOTEXT " %s" "// Physical Register Address" NL, sprintfield(f, ",", "0x%08XL", GetFeatureNumValue("regaddr")) );
DOTEXT " %s" "// SYSCLK Frequency (in Hz)" NL, sprintfield(f, ",", "%uL", GetFeatureNumValue("sysclk")) );
BlankLastCommaInString( Text+iT );
DOTEXT " }," NL
" {" NL );
DOTEXT " 0x0008, 0x00, // Sleep In Register " NL );
for ( i=0; i<=m_MaxHalInfoRegIndex; i++ )
if ( IsRegisterValid(i,true) )
{
switch( m_HalInfo.Regs[i].Index )
{
case REGFLAG_OFFDELAY: pszField=sprintfield(12,",","%s","riDELAYOFF"); break;
case REGFLAG_ONDELAY: pszField=sprintfield(12,",","%s","riDELAYON"); break;
case REGFLAG_ENDOFTABLE: pszField=sprintfield(12,",","%s","riREGEND"); break;
default: pszField=sprintfield(12,",","0x%0*X",m_DefaultRegIndexField,m_HalInfo.Regs[i].Index); break;
}
if ( m_HalInfo.Regs[i].Index != 8 )
{
if ( m_HalInfo.Regs[i].Index == REGFLAG_ENDOFTABLE )
DOTEXT" %s" "0x%0*X, // %s" NL, pszField, GetRegisterValueFieldWidth(i,true), m_HalInfo.Regs[i].Value, GetRegisterName(i,true,GN_NAME|GN_ATTRS) );
else
DOTEXT" %s" "0x%0*X, // %s" NL, pszField, GetRegisterValueFieldWidth(i,true), m_HalInfo.Regs[i].Value, GetRegisterName(i,true,GN_NAME|GN_ATTRS) );
}
}
BlankLastCommaInString( Text+iT );
DOTEXT " }" NL
"}," NL
"" NL
"#endif // __MODE%u_H__" NL, Mode );
// Add extra lines because Juro states that gcc needs them otherwise a warning occurs.
DOTEXT "" NL );
DOTEXT "" NL );
assert( iT < Size );
return iT;
}
//=========IMPORT/EXPORT CONFIGURATION DATA WORKHORSE METHODS=================
const ChipDef::ReadConfigDataFunc ChipDef::m_pfnReadConfigData[] = { ReadBinaryConfigData };
const ChipDef::WriteConfigDataFunc ChipDef::m_pfnWriteConfigData[] = { WriteBinaryConfigData };
const int ChipDef::m_NumConfigDataFormats = sizeof(ChipDef::m_pfnReadConfigData)/sizeof(ChipDef::m_pfnReadConfigData[0]);
int ChipDef::ReadBinaryConfigData( HAL_STRUCT *pHalInfo, const UInt8* pData, UInt32 Size, bool VerifyCRC, const char* *ErrorText, ParsedConfigInfo* *ppReturnInfo )
//
// The supplied buffer must contain a valid HalInfo data structure that this
// method can locate and overwrite with the current configuration data.
//
{
int Success = 1; // -1=FAIL(but recognized), 0=FAIL(unknown), 1=SUCCESS
// Setd default to 1 so it won't fail in configuring file for no-intel platform(i.e. IDP68K).
#ifdef _WIN32
bool fFound=false;
UInt16 CRC;
HAL_STRUCT HalTemp;
int Len = Size-sizeof(HAL_STRUCT);
ParsedConfigInfo* pParsedInfo = new ParsedConfigInfo;
*ErrorText = "The file does not contain any configuration data.";
for ( int i=0; i<Len; i++ )
{
if ( memcmp(pData+i,szHalSignature,strlen(szHalSignature)) == 0 )
{
CopyMemory( &HalTemp, pData+i, sizeof(HalTemp) ); // Ensure aligned structure before accessing members.
if ( HalTemp.wDetectEndian==HAL_LITTLE_ENDIAN || HalTemp.wDetectEndian==HAL_BIG_ENDIAN )
{
if ( (HalTemp.wDetectEndian==HAL_LITTLE_ENDIAN && HalTemp.wSize==sizeof(HalTemp)) || (HalTemp.wDetectEndian==HAL_BIG_ENDIAN && swap16(HalTemp.wSize)==sizeof(HalTemp)) )
{
if ( !fFound )
{
fFound = true;
if ( strcmp(HalTemp.szChipId,m_HalInfo.szChipId) != 0 )
{
Success = -1;
*ErrorText = "The file contains configuration data for another chip.";
break;
}
else if ( VerifyCRC )
{
CRC = CalculateHalInfoCRC( HalTemp ); // Calculate native (little or big endian) CRC.
if ( (HalTemp.wDetectEndian==HAL_LITTLE_ENDIAN && HalTemp.wHalCRC==CRC) || (HalTemp.wDetectEndian==HAL_BIG_ENDIAN && swap16(HalTemp.wHalCRC)==CRC) )
{
Success = 1;
pParsedInfo->EXE.iHalInfoOffset = i;
}
else
{
Success = -1;
*ErrorText = (HalTemp.wHalCRC) ? "The file contains corrupted configuration data." : "The file has not yet been configured by this application.";
}
}
else
{
Success = 1;
pParsedInfo->EXE.iHalInfoOffset = i;
}
}
else
{
Success = -1;
*ErrorText = "The file contains multiple configuration data structures.";
break;
}
}
else
{
if ( !fFound ) // This error can be reasonably ignored if we've found config data.
{
Success = -1;
*ErrorText = "The configuration data structure size is incorrect.";
}
}
}
}
}
if ( Success == 1 )
{
// Send back requested information.
if ( pHalInfo )
CopyMemory( (void*)pHalInfo, pData+pParsedInfo->EXE.iHalInfoOffset, sizeof(*pHalInfo) ); // Ensure aligned structure before accessing members.
if ( ppReturnInfo )
*ppReturnInfo = pParsedInfo;
else
delete pParsedInfo;
}
else
delete pParsedInfo;
#endif
return Success;
}
int ChipDef::WriteBinaryConfigData( const HAL_STRUCT *pHalInfo, UInt8* pData, UInt32& Size, const char* *ErrorText )
//
// The supplied buffer must contain a valid HalInfo data structure that this
// method can locate and overwrite with the current configuration data.
//
{
int Success = 0; // -1=FAIL(but recognized), 0=FAIL(unknown), 1=SUCCESS
#ifdef _WIN32
ParsedConfigInfo* pParsedInfo;
if ( (Success = ReadBinaryConfigData(NULL,pData,Size,false,ErrorText,&pParsedInfo)) == 1 )
{
// Write the new HalInfo into the config data.
CopyMemory( pData+(pParsedInfo->EXE.iHalInfoOffset), pHalInfo, sizeof(*pHalInfo) );
// Free resources.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -