📄 chipdef.cpp
字号:
delete pParsedInfo;
}
#endif
return Success;
}
//===================GENERAL PURPOSE WORK HORSE METHODS=======================
UInt32 ChipDef::GetRegisterHotValue( in UInt32 Index )
{
UInt32 RetVal = 0;
UInt32 iRegister;
assert( m_fHotHotHot );
if ( LookupRegister(Index,false,&iRegister) )
{
switch ( m_Registers[iRegister].BitWidth )
{
case 8: RetVal=(UInt32)halReadReg8((UInt16)Index); break;
case 16: RetVal=(UInt32)halReadReg16((UInt16)Index); break;
case 32: RetVal=halReadReg32((UInt16)Index); break;
default: assert( false ); break;
}
}
else
assert( false ); // ERROR: Could not find register! (If IsHALIndex==true, then register is not in the HAL list.)
return RetVal;
}
bool ChipDef::SetRegisterHotValue( in UInt32 Index, in UInt32 Value )
{
UInt32 iRegister;
assert( m_fHotHotHot );
if ( LookupRegister(Index,false,&iRegister) )
{
switch ( m_Registers[iRegister].BitWidth )
{
case 8: halWriteReg8((UInt16)Index,(UInt8)Value); break;
case 16: halWriteReg16((UInt16)Index,(UInt16)Value); break;
case 32: halWriteReg32((UInt16)Index,Value); break;
default: assert( false ); break;
}
// If auto show test pattern is enabled, see if this register is flagged to redraw the test pattern.
if ( m_fShowTestPattern && m_fChipInitialized )
for ( UInt32 iFeature=0; iFeature<m_NumFeatures; iFeature++ )
if ( m_Features[iFeature].RegIndex==m_Registers[iRegister].RegIndex && m_Features[iFeature].RedrawPattern )
{
m_nTimerTick = 1;
break;
}
return true;
}
assert( false ); // ERROR: Could not find register! (If IsHALIndex==true, then register is not in the HAL list.)
return false;
}
UInt32 ChipDef::GetRegisterHALValue( in UInt32 HalIndex )
{
return (UInt32)m_HalInfo.Regs[HalIndex].Value;
}
bool ChipDef::SetRegisterHALValue( in UInt32 HalIndex, in UInt32 Value )
{
m_HalInfo.Regs[HalIndex].Value = (UInt16)Value;
return true;
}
bool ChipDef::GetRegisterHALIndex( in UInt32 RegIndex, out UInt32& HalIndex, in bool InitialValue )
//
// If InitialValue==true, then this method returns the first occurance of given RegIndex (if only one exists, that one is returned).
// If InitialValue==false, then this method returns the last occurance of given RegIndex (if only one exists, that one is returned).
// If RegIndex is not found, this method will return false.
//
{
UInt32 OldHalIndex = HalIndex;
HalIndex = m_MaxHalInfoRegIndex;
for ( UInt32 i=0; i<(UInt32)m_MaxHalInfoRegIndex; i++ )
{
if ( m_HalInfo.Regs[i].Index==REGFLAG_ONDELAY && InitialValue )
if ( HalIndex != (UInt32)m_MaxHalInfoRegIndex )
return true;
if ( m_HalInfo.Regs[i].Index == (UInt16)RegIndex )
HalIndex = i;
}
if ( HalIndex == (UInt32)m_MaxHalInfoRegIndex )
{
HalIndex = OldHalIndex; // Restore previous value.
return false;
}
return true;
}
bool ChipDef::LookupRegisterFromHAL( in UInt32 HALIndex, out UInt32* RegIndex )
//
// Users of this method don't care if a register is repeated twice in the HAL list, they just want to
// know what REAL register is associated with it.
//
{
if ( HALIndex <= (UInt32)m_MaxHalInfoRegIndex )
{
if ( RegIndex != NULL )
*RegIndex = (UInt32)m_HalInfo.Regs[HALIndex].Index;
return true;
}
return false;
}
void ChipDef::FilterHALRegisterList( void )
{
UInt16 i, iBase;
for ( i=iBase=0,m_MaxHalInfoRegIndex=0; i<HAL_NUMREGS; i++ )
{
if ( m_HalInfo.Regs[i].Index == REGFLAG_ENDOFTABLE )
{
m_MaxHalInfoRegIndex = (int)iBase;
m_HalInfo.Regs[iBase++] = m_HalInfo.Regs[i];
// The list is now rebuilt, but zero-out the rest of the list because it affects the CRC.
// If any program reads this list and tries to predict CRC will fail if the rest of the list is not zero'd.
for ( ; iBase<HAL_NUMREGS; iBase++ )
{
m_HalInfo.Regs[iBase].Index = 0;
m_HalInfo.Regs[iBase].Value = 0;
}
break;
}
else
{
// Analyze the register to see if it is valid for the current chip type.
if ( IsRegisterValid(m_HalInfo.Regs[i].Index,false) )
m_HalInfo.Regs[iBase++] = m_HalInfo.Regs[i];
}
}
m_MaxHalInfoRegIndex = (int)iBase;
}
UInt16 ChipDef::CalculateHalInfoCRC( const HAL_STRUCT& HalData )
//
// This private method is used to calculate a 16-bit CRC for the contents of a HalInfo
// structure. The bits included in the calculation are those from the first byte following
// the wHalCRC member up to and including the last byte of the structure. The formula used
// is CRC16-CCITT, which is the polynomial x^16 + x^12 + x^5 + 1 (0x1021).
//
{
const UInt8* pHalByte;
int i, nBytes;
UInt16 crc;
// Setup the pointer, counter, and initial CRC value.
pHalByte = (UInt8*)&HalData.wHalCRC + sizeof(HalData.wHalCRC);
nBytes = sizeof(HalData) - offsetof(HAL_STRUCT,wHalCRC) - sizeof(HalData.wHalCRC);
crc = 0xFFFF;
// Calculate the CRC for the HalInfo structure (from byte after wHalCRC to end).
for (i = 0; i < nBytes; i++)
{
crc = (UInt16)( (crc << 8) | ((crc >> 8) ^ pHalByte[i]) );
crc ^= (crc & 0x00FF) >> 4;
crc ^= (crc << 12) ^ ((crc & 0x00FF) << 5);
}
// Return the calculated CRC.
return crc;
}
void ChipDef::SwapHalInfoMembers( HAL_STRUCT& HalData )
//
// This private method swaps all the 16-bit and 32-bit members of the specified
// HalInfo data structure. Note that the entire HalInfo.Regs array is swapped
// just to be safe, as a test for REGFLAG_ENDOFTABLE will fail for big endian data.
//
{
HalData.wSize = swap16( HalData.wSize );
HalData.wHalCRC = swap16( HalData.wHalCRC );
HalData.wDetectEndian = swap16( HalData.wDetectEndian );
HalData.wFrameRate = swap16( HalData.wFrameRate );
HalData.dwInternalOSC = swap32( HalData.dwInternalOSC );
HalData.dwClkI = swap32( HalData.dwClkI );
HalData.dwPClk = swap32( HalData.dwPClk );
HalData.wPanelWidth = swap16( HalData.wPanelWidth );
HalData.wPanelHeight = swap16( HalData.wPanelHeight );
HalData.wBpp = swap16( HalData.wBpp );
HalData.dwBaseAddress = swap32( HalData.dwBaseAddress );
HalData.dwRegisterOffset = swap32( HalData.dwRegisterOffset );
HalData.dwMemoryOffset = swap32( HalData.dwMemoryOffset );
HalData.dwRequiredVRAM = swap32( HalData.dwRequiredVRAM );
HalData.dwFlags = swap32( HalData.dwFlags );
//
for ( int i=0; i<sizeof(HalData.Regs)/sizeof(HalData.Regs[0]); i++ )
{
HalData.Regs[i].Index = swap16( HalData.Regs[i].Index );
HalData.Regs[i].Value = swap16( HalData.Regs[i].Value );
}
}
char* ChipDef::MakeHalFlagsString( UInt32 dwFlags )
{
char* Flags = GetCircularStr( m_SP );
int iF = 0;
if ( dwFlags & (fINDIRECT_INTERFACE|fDEBUG_REG_WRITES|fPCCARD_INTERFACE) )
{
if ( dwFlags & fINDIRECT_INTERFACE )
iF += sprintf( Flags+iF, "fINDIRECT_INTERFACE|" );
if ( dwFlags & fPCCARD_INTERFACE )
iF += sprintf( Flags+iF, "fPCCARD_INTERFACE|" );
if ( dwFlags & fDEBUG_REG_WRITES )
iF += sprintf( Flags+iF, "fDEBUG_REG_WRITES|" );
Flags[iF-1] = 0; // Delete last '|' character.
}
else
strcpy( Flags, "0" );
return Flags;
}
char* ChipDef::MakeWinCEFlagsString( UInt32 dwFlags )
{
char* Flags = GetCircularStr( m_SP );
int iF = 0;
// int swivel = GetFeatureNumValue("swivelview");
if ( (dwFlags & (MF_LCD|MF_SWCURSOR|MF_SWEMUL|MF_HWBLT)) /*|| swivel*/ )
{
if ( dwFlags & MF_LCD )
iF += sprintf( Flags+iF, "MF_LCD|" );
if ( dwFlags & MF_SWCURSOR )
iF += sprintf( Flags+iF, "MF_SWCURSOR|" );
if ( dwFlags & MF_SWEMUL )
iF += sprintf( Flags+iF, "MF_SWEMUL|" );
Flags[iF-1] = 0; // Delete last '|' character.
}
else
strcpy( Flags, "0" );
return Flags;
}
char* ChipDef::MakeFriendlyString( char* In, bool DoubleNullTerminated )
{
char* Text = GetCircularStr( m_SP );
char* Out = Text;
char e;
do
{
// Handle all known C string escapes.
switch ( *In )
{
case '\a': e='a'; break;
case '\b': e='b'; break;
case '\f': e='f'; break;
case '\n': e='n'; break;
case '\r': e='r'; break;
case '\t': e='t'; break;
case '\v': e='v'; break;
case '\"': e='"'; break;
case '\\': e='\\'; break;
default: e=0; break;
}
if ( e )
{
// If we found a C string escape, handle it.
*Out++ = '\\';
*Out++ = e;
}
else if ( *In < ' ' || *In > '~' )
{
// Handle non-ASCII character. Use string pasting if next c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -