📄 rtmdemodlg.cpp
字号:
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRtmDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRtmDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRtmDemoDlg::OnChangeDeditMask()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CRtmDemoDlg::OnStarttimer()
{
char *stopstring;
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(bStartStop ==0){
std.port = (unsigned short)strtoul( m_dport, &stopstring, 16 );
std.mask = (unsigned short)strtoul( m_dmask, &stopstring, 16 );
std.bbyte = m_bdbyte ;
std.inout = m_bdoutput ;
std.quantum = m_dquantum;
std.curquantum = 0;
std.nvalue = 0;
std.dbgtm = 0;
sta.port = (unsigned short)strtoul( m_aport, &stopstring, 16 );
sta.mask = (unsigned short)strtoul( m_arange, &stopstring, 16 );
sta.bbyte = m_babyte ;
sta.inout = m_baoutput ;
sta.quantum = m_aquantum;
sta.curquantum = 0;
sta.nvalue = 0;
sta.dbgtm = 0;
StartTimer(&std, &sta );
bStartStop = 1;
KillTimer(0xe000);
SetTimer(0xe000, 50, NULL);
}
}
void CRtmDemoDlg::OnStoptimer()
{
// TODO: Add your control notification handler code here
if(bStartStop ){
KillTimer(0xe000);
StopTimer();
bStartStop = 0;
}
}
void CRtmDemoDlg::OnAradioOutput()
{
// TODO: Add your control notification handler code here
m_baoutput = TRUE;
}
void CRtmDemoDlg::OnAradioInput()
{
// TODO: Add your control notification handler code here
m_baoutput = FALSE;
}
void CRtmDemoDlg::OnDradioOutput()
{
// TODO: Add your control notification handler code here
m_bdoutput = TRUE;
}
void CRtmDemoDlg::OnDradioInput()
{
// TODO: Add your control notification handler code here
m_bdoutput = FALSE;
}
CRtmDemoDlg::~CRtmDemoDlg()
{
// TODO: Add your control notification handler code here
}
void CRtmDemoDlg::OnTimer(UINT nIDEvent)
{
char buff[16];
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
if( bStartStop )
{
GetValue(&std, &sta );
SetDlgItemText(IDC_DIG_VALUE,_itoa(std.nvalue,buff,10));
SetDlgItemText(IDC_ANL_VALUE,_itoa(sta.nvalue,buff,10));
}
}
//BOOL CWnd::KillTimer(UINT_PTR nIDEvent)
// { ASSERT(::IsWindow(m_hWnd)); return ::KillTimer(m_hWnd, nIDEvent); }
void CRtmDemoDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
OnStoptimer();
CloseRTM();
CDialog::OnClose();
}
void CRtmDemoDlg::OnAbout()
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CRtmDemoDlg::OnSelDChangeCombo()
{
// TODO: Add your control notification handler code here
CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_D_SIZE);
m_bdbyte = pCBox->GetCurSel();
}
void CRtmDemoDlg::OnSelAChangeCombo()
{
// TODO: Add your control notification handler code here
CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_A_SIZE);
m_babyte = pCBox->GetCurSel();
}
void CRtmDemoDlg::PCIButtonEnable(BOOL bmode)
{
((CButton *)GetDlgItem(IDC_BUTTON_ASSIGN_RES))->EnableWindow(bmode);
((CButton *)GetDlgItem(IDC_BUTTON_RELEASE))->EnableWindow(bmode);
((CButton *)GetDlgItem(IDC_BUTTON_PCIREAD))->EnableWindow(bmode);
((CButton *)GetDlgItem(IDC_BUTTON_PCIWRITE))->EnableWindow(bmode);
}
void CRtmDemoDlg::OnSelChangePCIList(NMHDR* pNMHDR, LRESULT* pResult )
{
int i ;
NM_LISTVIEW* pNMListView;
PCIINFO *pci;
pNMListView = (NM_LISTVIEW*)pNMHDR;
if( pNMListView->uChanged&LVIF_STATE )
{
if( pNMListView->uNewState&LVIS_SELECTED )
{
m_pciiItem = i = pNMListView->iItem;
if(pNMListView->uOldState == 0)
{
pci = (PCIINFO*)m_listpci.GetItemData(i);
FillPciResource(pci);
if(pci->pcidata.VendorID !=0x8086 && pci->pcidata.HeaderType != PCI_BRIDGE_TYPE)
{
PCIButtonEnable(TRUE);
if(pci->bAssign == FALSE)
((CButton *)GetDlgItem(IDC_BUTTON_RELEASE))->EnableWindow(FALSE);
else
((CButton *)GetDlgItem(IDC_BUTTON_ASSIGN_RES))->EnableWindow(FALSE);
}
else
PCIButtonEnable(FALSE);
}
}
}
}
BOOL CRtmDemoDlg::SetRWValue(BOOL bmode,unsigned *naddr,unsigned *nsize)
{
LVITEM lvi;
char *stopstring;
char szBuff[32];
if(m_resiItem == -1) return FALSE;
lvi.mask = LVIF_TEXT | LVIF_STATE;
lvi.iItem = m_resiItem;
lvi.iSubItem = 1;
lvi.pszText = szBuff;
lvi.cchTextMax = 31;
lvi.stateMask = 0xFFFF;
m_listres.GetItem(&lvi);
if(bmode == TRUE)
SetDlgItemText(IDC_EDIT_ADDRESS,szBuff);
if(naddr)
*naddr = (unsigned )strtoul(szBuff, &stopstring, 16 );
if(nsize)
{
lvi.mask = LVIF_TEXT | LVIF_STATE;
lvi.iItem = m_resiItem;
lvi.iSubItem = 2;//lvi.iSubItem + 1;
lvi.pszText = szBuff;
lvi.cchTextMax = 32;
lvi.stateMask = 0xFFFF; // get all state flags
m_listres.GetItem(&lvi);
*nsize = (unsigned )strtoul(szBuff, &stopstring, 16 );
}
return TRUE;
}
void CRtmDemoDlg::OnSelChangePCIResList(NMHDR* pNMHDR, LRESULT* pResult )
{
int i ;
NM_LISTVIEW* pNMListView;
pNMListView = (NM_LISTVIEW*)pNMHDR;
i = pNMListView->iItem;
if( pNMListView->uChanged&LVIF_STATE )
{
if( pNMListView->uNewState&LVIS_SELECTED )
{
if(pNMListView->uOldState == 0)
{
m_resiItem = i;
SetRWValue();
}
}
}
}
void CRtmDemoDlg::OnOK()
{
return ;
}
void CRtmDemoDlg::OnButtonPciread()
{
char szBuff[32];
char *stopstring;
unsigned nvalue;
unsigned naddr;
unsigned nbaseaddr;
unsigned noff;
if(GetDlgItemText(IDC_EDIT_ADDRESS,szBuff,31)>31)return;
naddr = (unsigned )strtoul(szBuff, &stopstring, 16 );
SetRWValue(FALSE,&nbaseaddr,&noff);
if(szBuff[0] && (naddr >= nbaseaddr && naddr < nbaseaddr + noff))
{
int nsize;
// Ok
nsize =((CComboBox*) GetDlgItem(IDC_COMBO_RW_SIZE))->GetCurSel();
nsize = nsize * 2;
if(nsize == 0) nsize = 1;
if(GetDlgItemText(IDC_RW_VALUE,szBuff,31)>31)return;
nvalue = 0;//(unsigned )strtoul(szBuff, &stopstring, 16 );
ReadPhysicalAddress(m_listpci.GetSelectionMark(),naddr,&nvalue,1,nsize);
sprintf(szBuff,"%x",nvalue);
SetDlgItemText(IDC_RW_VALUE,szBuff);
}
else
::MessageBox(NULL,"Error : address out of range",_T("RTM"),MB_OK);
}
void CRtmDemoDlg::OnButtonPciwrite()
{
char szBuff[32];
char *stopstring;
unsigned nvalue;
unsigned naddr;
unsigned nbaseaddr;
unsigned noff;
if(GetDlgItemText(IDC_EDIT_ADDRESS,szBuff,31)>31)return;
naddr = (unsigned )strtoul(szBuff, &stopstring, 16 );
SetRWValue(FALSE,&nbaseaddr,&noff);
if(szBuff[0] && (naddr >= nbaseaddr && naddr < nbaseaddr + noff))
{
int nsize;
// Ok
nsize =((CComboBox*) GetDlgItem(IDC_COMBO_RW_SIZE))->GetCurSel();
nsize = nsize * 2;
if(nsize == 0) nsize =1;
// Ok
if(GetDlgItemText(IDC_RW_VALUE,szBuff,31)>31)return;
nvalue = (unsigned )strtoul(szBuff, &stopstring, 16 );
WritePhysicalAddress(m_listpci.GetSelectionMark(),naddr,&nvalue,1,nsize);
}
else
::MessageBox(NULL,"Error : address out of range",_T("RTM"),MB_OK);
}
void CRtmDemoDlg::OnButtonAssignRes()
{
PCIINFO *pci;
pci = (PCIINFO *)m_listpci.GetItemData(m_pciiItem);
if(pci && PCIResource(TRUE,pci) != -1)
{
pci->bAssign = TRUE;
((CButton *)GetDlgItem(IDC_BUTTON_ASSIGN_RES))->EnableWindow(FALSE);
((CButton *)GetDlgItem(IDC_BUTTON_RELEASE))->EnableWindow(TRUE);
((CButton *)GetDlgItem(IDC_BUTTON_RELEASE))->SetFocus();//(TRUE);
}
}
void CRtmDemoDlg::OnButtonReleaseRes()
{
PCIINFO *pci;
pci = (PCIINFO *)m_listpci.GetItemData(m_pciiItem);
if(pci && PCIResource(FALSE,pci) != -1)
{
pci->bAssign = FALSE;
((CButton *)GetDlgItem(IDC_BUTTON_ASSIGN_RES))->EnableWindow(TRUE);
((CButton *)GetDlgItem(IDC_BUTTON_RELEASE))->EnableWindow(FALSE);
((CButton *)GetDlgItem(IDC_BUTTON_ASSIGN_RES))->SetFocus();
}
}
void CRtmDemoDlg::OnRtmDebug()
{
// TODO: Add your control notification handler code here
StartDebug(((CButton *)GetDlgItem(IDC_RTM_DEBUG))->GetCheck());
}
void CRtmDemoDlg::OnButtonUpdatepci()
{
int count;
// TODO: Add your control notification handler code here
count = ScanPci(pcibuff);
if(count)
{
FillPCI(pcibuff,count);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -