📄 tmmon.cpp
字号:
CloseHandle ( hFile );
return FALSE;
}
if ( pFirstHalfBuffer && FirstHalfBufferSize > 0) // wrap around has occured
{
if ( WriteFile ( hFile,
pFirstHalfBuffer, FirstHalfBufferSize, &BytesWritten, Null ) != True )
{
MessageBox(AfxGetMainWnd()->m_hWnd,
"TMMon : ERROR : Writing Trace File",
"TraceP", MB_OK);
CloseHandle ( hFile );
return FALSE;
}
}
if ( WriteFile ( hFile,
pSecondHalfBuffer, SecondHalfBufferSize, &BytesWritten, Null ) != True )
{
MessageBox(AfxGetMainWnd()->m_hWnd,
"TMMon : ERROR : Writing Trace File",
"TraceP", MB_OK);
CloseHandle ( hFile );
return FALSE;
}
CloseHandle ( hFile );
}
else
{ // no filename, dump to memory
if ( pObject->fTraceIntoFile == False )
{
int noOfLF = 0;
UInt32 memSize = 0;
UInt32 memIndex = 0;
UInt32 i;
fTraceIntoFile = FALSE;
// calculate number of LF in the two buffers and also the amount of memory
// to be allocated for the buffer in which LF is translated to CR+LF
if ( pFirstHalfBuffer ) // wrap around has occured
{
memSize = FirstHalfBufferSize;
for (i=0; i<FirstHalfBufferSize; i++)
{
if(pFirstHalfBuffer[i] == '\n')
noOfLF++;
}
}
for(i=0; i<SecondHalfBufferSize; i++)
{
for (i=0; i<SecondHalfBufferSize; i++)
{
if(pSecondHalfBuffer[i] == '\n')
noOfLF++;
}
}
memSize += (SecondHalfBufferSize + noOfLF);
m_traceBuffer = new char[memSize + 16]; // Keep some margin
if(m_traceBuffer==NULL)
{
AfxMessageBox("Not Enough Memory to Display Complete Trace Buffer\n"
"Redirect Output to Trace File");
// Try allocating with a smaller size
memSize = 20000;
m_traceBuffer = new char[memSize + 16];
if(m_traceBuffer==NULL)
{
AfxMessageBox("Cannot Allocate Memory");
return FALSE;
}
}
// Copy DP buffers to m_traceBuffer and convert LF to CR+LF
memIndex = 0;
if ( pFirstHalfBuffer ) // wrap around has occured
{
for (i=0; i<FirstHalfBufferSize; i++)
{
if(memIndex >= memSize)
break;
if(pFirstHalfBuffer[i] == '\n')
{
if(memIndex > 0)
{
if(m_traceBuffer[memIndex-1] != '\r')
m_traceBuffer[memIndex++]='\r';
}
else
m_traceBuffer[memIndex++]='\r';
}
m_traceBuffer[memIndex++] = pFirstHalfBuffer[i];
}
}
if(memIndex < memSize)
{
for(i=0; i<SecondHalfBufferSize; i++)
{
if(memIndex >= memSize)
break;
if(pSecondHalfBuffer[i] == '\n')
{
if(memIndex > 0)
{
if(m_traceBuffer[memIndex-1] != '\r')
m_traceBuffer[memIndex++]='\r';
}
else
m_traceBuffer[memIndex++]='\r';
}
m_traceBuffer[memIndex++] = pSecondHalfBuffer[i];
}
}
// Null terminate the string
m_traceBuffer[memIndex] = 0;
}
}
return TRUE;
}
BOOL CTmmon::ExeDSP (UInt32 DSPNumber)
{
wState = DSP_CMD;
PCMD_DSP pObject = (PCMD_DSP)&CmdDSPContext;
TMStatus TMMANStatus;
UInt32 DSPHandle;
pObject->DSPNumber = DSPNumber;
if ( pObject->DSPNumber >= tmmanDSPGetNum() )
{
wState = CMD_WAIT;
return FALSE;
}
TMMANStatus = tmmanDSPClose ( m_CurrentDSPHandle );
TMMANStatus = tmmanDSPOpen ( pObject->DSPNumber, &DSPHandle );
m_CurrentDSPHandle = DSPHandle;
m_CurrentDSPNumber = pObject->DSPNumber;
TMMANStatus = tmmanDSPGetInfo ( DSPHandle, &m_CurrentDSPInfo);
wState = CMD_WAIT;
return TRUE;
}
BOOL CTmmon::ctc_main (CTmgmonDlg* pTmgmonDlg,char* verstr)
{
// required for processing arguments
DWORD dwWaitTimeOut = 0;
DWORD dwWindowLines = 0;
WORD wCount = 0 ;
tmmanVersion Version;
sprintf ( verstr,
"TriMedia Monitor - Version [%d.%d.%d] (c)Philips Semiconductors\n[%s %s]",
verGetFileMajorVersion (),
verGetFileMinorVersion (),
verGetFileBuildVersion (),__DATE__, __TIME__);
//initize the parser data structre
wState = CMD_WAIT;
fTraceIntoFile = FALSE;
ProgramState = PROG_STATE_NOTINIT;
if ( dwWaitTimeOut == 0 )
dwWaitTimeOut = 100;
Version.Major = verGetFileMajorVersion();
Version.Minor = verGetFileMinorVersion();
tmmanNegotiateVersion (
constTMManDefault,
&Version );
if ( ( Version.Major != verGetFileMajorVersion() ) ||
( Version.Minor != verGetFileMinorVersion()) )
{
TCHAR szTemp[1024];
wsprintf (szTemp, "ERROR : TMGMon.exe Version[%d.%d] is INCOMPATIBLE With TMMan32.dll Version[%d.%d]\n",
verGetFileMajorVersion(), verGetFileMinorVersion(),
Version.Major, Version.Minor );
AfxMessageBox(szTemp);
return FALSE;
}
if(!Initial())
return FALSE;
ShowProcessorInfo(pTmgmonDlg);
return TRUE;
}
void CTmmon::ctc_exit(void)
{
UInt32 DSPStatus;
tmmanDSPGetStatus ( m_CurrentDSPHandle, &DSPStatus );
if ( DSPStatus == constTMManDSPStatusRunning )
tmmanDSPStop( m_CurrentDSPHandle );
Exit();
}
BOOL CTmmon::ctc_mem(HWND hwnd,DWORD PhyAddress,int dumptype,BOOL start)
{
DWORD LinearAdr,Size;
static int memtype=0;
UINT wDataSize;
if(dumptype == 0)
wDataSize = 1;
else if(dumptype == 1)
wDataSize = 2;
else if(dumptype == 2)
wDataSize = 4;
else
return FALSE;
if(start)
{
if (halValidateAddress ( wDataSize,
PhyAddress,
&LinearAdr,
&Size,
&memtype)
== CMD_STATUS_INADEQUATE)
return FALSE;
}
if(memtype == 2) // MMIO
{
dumptype=2;
PhyAddress &= 0xffffffffc;
}
ViewMem(hwnd,PhyAddress,(PVOID)LinearAdr,Size,dumptype,memtype,start);
return TRUE;
}
void CTmmon::ctc_trace(CEdit * pEdit,char *str)
{
CWaitCursor wait; // display wait cursor
traceEdit=TRUE;
pTraceView=pEdit;
pTraceView->SetWindowText("");
if(ExeTraceP( str ))
{
if (fTraceIntoFile == False)
{
extern BOOL tracefull;
// Write in trace edit box
pTraceView->SetWindowText(m_traceBuffer);
if(tracefull)
{
tracefull=FALSE;
// if(traceIndex != 0 && pTraceView->GetWindowTextLength() == 0)
// {
m_traceBuffer[20000]=0;
pTraceView->SetWindowText(m_traceBuffer);
// }
}
if(m_traceBuffer)
{
delete (m_traceBuffer);
m_traceBuffer = NULL;
}
}
}
traceEdit=FALSE;
}
#if 0
DisplayTrace(PVOID pBuffer, DWORD dwLength)
{
DWORD i;
PBYTE pByte;
traceBuffer=new char[dwLength + 10];
if (traceBuffer == NULL)
return 0;
memcpy(traceBuffer, pBuffer, dwLength);
pByte = (PBYTE)traceBuffer;
for(i=0;i<dwLength;i++)
{
if(traceIndex >= 64000)
break;
if(*pByte == '\n')
{
if(traceIndex > 0)
if(pcTmmon->m_traceBuffer[traceIndex-1] != '\r')
pcTmmon->m_traceBuffer[traceIndex++]='\r';
}
pcTmmon->m_traceBuffer[traceIndex++]=*pByte;
pByte++;
}
delete traceBuffer;
return 1;
}
#endif
typedef DWORD ( FAR WINAPI *LPFNDDCREATE)( PVOID, LPDIRECTDRAW *, PVOID );
BOOL GetDisplayInfo(void)
{
HINSTANCE hDDraw;
LPDIRECTDRAW pDD;
LPDIRECTDRAWSURFACE pDDSPrimary;
LPFNDDCREATE lpfnDirectDrawCreate;
BOOL returnStatus=TRUE;
HKEY RegistryHandle;
DWORD BytesXfered;
DWORD DDrawEnable;
// initialize default values
if ( ERROR_SUCCESS == RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
constTMManRegistryPath,
0,
KEY_READ,
&RegistryHandle ) )
{
BytesXfered = sizeof ( DWORD);
if ( ERROR_SUCCESS != RegQueryValueEx(
RegistryHandle,
TEXT("TMGMonDDraw"),
NULL,
NULL,
(BYTE*)&DDrawEnable,
&BytesXfered ) )
{
DDrawEnable=TRUE; // Enable ddraw if value not in registry
}
RegCloseKey ( RegistryHandle );
}
else
DDrawEnable=TRUE; // Enable ddraw if key not in registry
if ( DDrawEnable )
{
hDDraw = LoadLibrary( "DDRAW" );
if ( !hDDraw )
{
// AfxMessageBox("Error: Failed to load ddraw.dll");
return FALSE;
}
if ( !( lpfnDirectDrawCreate = (LPFNDDCREATE) GetProcAddress( hDDraw,"DirectDrawCreate" ) ) )
{
FreeLibrary( hDDraw );
// AfxMessageBox("Error: Failed to get address of DirectDrawCreate in ddraw.dll");
return FALSE;
}
if ( ( *lpfnDirectDrawCreate )( NULL, &pDD, NULL ) )
{
FreeLibrary( hDDraw );
// AfxMessageBox("Error: DirectDrawCreate failed");
return FALSE;
}
if ( pDD->SetCooperativeLevel( NULL, DDSCL_NORMAL ) )
{
FreeLibrary( hDDraw );
return FALSE;
}
DDSURFACEDESC ddsd;
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if ( pDD->CreateSurface( &ddsd, &pDDSPrimary, NULL ) )
{
FreeLibrary( hDDraw );
// AfxMessageBox("Error: CreateSurface failed");
return FALSE;
}
if ( pDDSPrimary->GetSurfaceDesc( &ddsd ) )
{
pDDSPrimary->Release();
FreeLibrary( hDDraw );
return FALSE;
}
if ( ( ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB ) )
{
g_dwStride = ddsd.lPitch;
g_dwPixelDepth = ddsd.ddpfPixelFormat.dwRGBBitCount;
pDDSPrimary->Lock( NULL, &ddsd, 0, NULL );
g_dwLinearAddress = (DWORD) ddsd.lpSurface;
pDDSPrimary->Unlock( NULL );
if (tmmanTranslateAdapterAddress(g_dwLinearAddress,
g_dwStride * ddsd.dwHeight,
&g_dwPhysicalAddress)!= statusSuccess)
{
// AfxMessageBox("Error: tmmanTranslateAdapterAddress failed to determine video adapter address");
returnStatus=FALSE;
}
}
pDDSPrimary->Release();
FreeLibrary( hDDraw );
}
else
returnStatus=FALSE;
return returnStatus;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -