⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcidata.cpp

📁 浏览所有的PCI设备
💻 CPP
字号:
// PCIData.cpp : implementation file
//

#include "stdafx.h"
#include "PCI Explorer.h"

#include "NumericEdit.h"
#include "IDCombo.h"
#include "pci.h"
#include "DataDisplay.h"
#include "PCIScanIoctl.h"
#include "PCIData.h"
#include "codes.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static IDData Displays[] = {
	{ IDS_HEX_BYTES, DISPLAY_HEX_BYTES},
	{ IDS_HEX_WORDS, DISPLAY_HEX_WORDS},
	{ IDS_HEX_DWORDS, DISPLAY_HEX_DWORDS},
	{ IDS_DECIMAL_BYTES, DISPLAY_DECIMAL_BYTES},
	{ IDS_DECIMAL_WORDS, DISPLAY_DECIMAL_WORDS},
	{ IDS_DECIMAL_DWORDS, DISPLAY_DECIMAL_DWORDS},
	{ IDS_ANSI_CHARACTERS, DISPLAY_ANSI_CHARACTERS},
        { IDS_UNICODE_CHARACTERS, DISPLAY_UNICODE_CHARACTERS},
	{0, 0} //EOT
			   };

/////////////////////////////////////////////////////////////////////////////
// PCIData property page

IMPLEMENT_DYNCREATE(PCIData, CPropertyPage)

PCIData::PCIData() : CPropertyPage(PCIData::IDD)
{
	//{{AFX_DATA_INIT(PCIData)
	//}}AFX_DATA_INIT
}

PCIData::PCIData(CString cpt) : CPropertyPage(PCIData::IDD)
    {
     TCHAR * title = new TCHAR[cpt.GetLength()+1];
     lstrcpy(title, cpt);
     m_psp.pszTitle = title;
     m_psp.dwFlags |= PSP_USETITLE;
    }

PCIData::~PCIData()
{
}

void PCIData::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(PCIData)
	DDX_Control(pDX, IDC_FUNCTION, c_Function);
	DDX_Control(pDX, IDC_DEVICE, c_Device);
	DDX_Control(pDX, IDC_BUS, c_Bus);
	DDX_Control(pDX, IDC_VENDORNAME, c_VendorName);
	DDX_Control(pDX, IDC_DEVICENAME, c_DeviceName);
	DDX_Control(pDX, IDC_HEX, c_Hex);
	DDX_Control(pDX, IDC_DECIMAL, c_Decimal);
	DDX_Control(pDX, IDC_SUBSYSTEMID, c_SubSystemID);
	DDX_Control(pDX, IDC_SUBVENDORID, c_SubVendorID);
	DDX_Control(pDX, IDC_ROMBASEADDRESS, c_ROMBaseAddress);
	DDX_Control(pDX, IDC_RESERVED2, c_Reserved2);
	DDX_Control(pDX, IDC_RESERVED1, c_Reserved1);
	DDX_Control(pDX, IDC_VENDORID, c_VendorID);
	DDX_Control(pDX, IDC_SUBCLASS, c_SubClass);
	DDX_Control(pDX, IDC_STATUS, c_Status);
	DDX_Control(pDX, IDC_REVISIONID, c_RevisionID);
	DDX_Control(pDX, IDC_PROGIF, c_ProgIf);
	DDX_Control(pDX, IDC_MINIMUMGRANT, c_MinimumGrant);
	DDX_Control(pDX, IDC_MAXIMUMLATENCY, c_MaximumLatency);
	DDX_Control(pDX, IDC_LATENCYTIMER, c_LatencyTimer);
	DDX_Control(pDX, IDC_INTERRUPTPIN, c_InterruptPin);
	DDX_Control(pDX, IDC_INTERRUPTLINE, c_InterruptLine);
	DDX_Control(pDX, IDC_HEADERTYPE, c_HeaderType);
	DDX_Control(pDX, IDC_DISPLAYAS, c_DisplayAs);
	DDX_Control(pDX, IDC_DEVICEID, c_DeviceID);
	DDX_Control(pDX, IDC_DATA, c_Data);
	DDX_Control(pDX, IDC_COMMAND, c_Command);
	DDX_Control(pDX, IDC_CIS, c_CIS);
	DDX_Control(pDX, IDC_CACHELINESIZE, c_CacheLineSize);
	DDX_Control(pDX, IDC_BIST, c_BIST);
	DDX_Control(pDX, IDC_BASECLASS, c_BaseClass);
	DDX_Control(pDX, IDC_BASEADDRESS5, c_BaseAddress5);
	DDX_Control(pDX, IDC_BASEADDRESS4, c_BaseAddress4);
	DDX_Control(pDX, IDC_BASEADDRESS3, c_BaseAddress3);
	DDX_Control(pDX, IDC_BASEADDRESS2, c_BaseAddress2);
	DDX_Control(pDX, IDC_BASEADDRESS1, c_BaseAddress1);
	DDX_Control(pDX, IDC_BASEADDRESS0, c_BaseAddress0);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(PCIData, CPropertyPage)
	//{{AFX_MSG_MAP(PCIData)
	ON_BN_CLICKED(IDC_HEX, OnHex)
	ON_BN_CLICKED(IDC_DECIMAL, OnDecimal)
	ON_CBN_SELENDOK(IDC_DISPLAYAS, OnSelendokDisplayas)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// PCIData message handlers


/****************************************************************************
*                            PCIData::LoadPCIData
* Result: void
*       
* Effect: 
*       Loads the PCI data to the display using the selected radix
****************************************************************************/

void PCIData::LoadPCIData()
    {
     CString ByteFormat;
     CString WordFormat;
     CString DWordFormat;
     BOOL hex = c_Hex.GetCheck() == BST_CHECKED;

     BOOL found = FALSE;

     CString fullname;
     CString shortname;
     found = findVendor(data.PciData.VendorID, shortname, fullname);

     if(found)
	 c_VendorName.SetWindowText(fullname);

     c_VendorName.ShowWindow(found ? SW_SHOW : SW_HIDE);

     CString chip;
     CString desc;
     found = findDevice(data.PciData.VendorID, data.PciData.DeviceID,
     				chip, desc);
     if(found)
	{ /* found it */
	 // ID	cases		display
	 // --------------------------------
	 // I	"" "desc"	desc
	 // II	"chip" ""	chip
	 // III  "chip" "desc"	chip: desc
	 // IV	"" ""		none

	 found = TRUE;

	 if(lstrlen(chip) == 0 && lstrlen(desc) != 0)
	    { /* I */
	     c_DeviceName.SetWindowText(desc);
	    } /* I */
	 else
	 if(lstrlen(chip) != 0 && lstrlen(desc) == 0)
	    { /* II */
	     c_DeviceName.SetWindowText(chip);
	    } /* II */
	 else
	 if(lstrlen(chip) != 0 && lstrlen(desc) != 0)
	    { /* III */
	     CString s;
	     s.Format(_T("%s: %s"), chip, desc);
	     c_DeviceName.SetWindowText(s);
	    } /* III */
	 else
	 if(lstrlen(chip) == 0 && lstrlen(desc) == 0)
	    { /* IV */
	     found = FALSE; // found, but not interesting, pretend didn't
	    } /* IV */
	} /* found it */

     c_DeviceName.ShowWindow(found ? SW_SHOW : SW_HIDE);

     ByteFormat = (hex ? _T("%02x") : _T("%u"));
     WordFormat = (hex ? _T("%04x") : _T("%u"));
     DWordFormat = (hex ? _T("%08x") : _T("%u"));

     c_VendorID.SetWindowText(data.PciData.VendorID, WordFormat);
     c_DeviceID.SetWindowText(data.PciData.DeviceID, WordFormat);
     c_Command.SetWindowText(data.PciData.Command, WordFormat);
     c_Status.SetWindowText(data.PciData.Status, WordFormat);
     c_RevisionID.SetWindowText(data.PciData.RevisionID, ByteFormat);
     c_ProgIf.SetWindowText(data.PciData.ProgIf, ByteFormat);
     c_SubClass.SetWindowText(data.PciData.SubClass, ByteFormat);
     c_BaseClass.SetWindowText(data.PciData.BaseClass, ByteFormat);
     c_CacheLineSize.SetWindowText(data.PciData.CacheLineSize, ByteFormat);
     c_LatencyTimer.SetWindowText(data.PciData.LatencyTimer, ByteFormat);
     c_HeaderType.SetWindowText(data.PciData.HeaderType, ByteFormat);
     c_BIST.SetWindowText(data.PciData.BIST, ByteFormat);
     
     c_Bus.SetWindowText(data.BusNumber, ByteFormat);
     c_Device.SetWindowText(data.SlotData.u.bits.DeviceNumber, ByteFormat);
     c_Function.SetWindowText(data.SlotData.u.bits.FunctionNumber, ByteFormat);

     // This is always a Type 0 header. A Type 1 header would use a
     // different class, or subclass this one...

     c_BaseAddress0.SetWindowText  (data.PciData.u.type0.BaseAddresses[0], DWordFormat);
     c_BaseAddress1.SetWindowText  (data.PciData.u.type0.BaseAddresses[1], DWordFormat);
     c_BaseAddress2.SetWindowText  (data.PciData.u.type0.BaseAddresses[2], DWordFormat);
     c_BaseAddress3.SetWindowText  (data.PciData.u.type0.BaseAddresses[3], DWordFormat);
     c_BaseAddress4.SetWindowText  (data.PciData.u.type0.BaseAddresses[4], DWordFormat);
     c_BaseAddress5.SetWindowText  (data.PciData.u.type0.BaseAddresses[5], DWordFormat);

     c_CIS.SetWindowText           (data.PciData.u.type0.CIS, DWordFormat);
     c_SubVendorID.SetWindowText   (data.PciData.u.type0.SubVendorID, WordFormat);
     c_SubSystemID.SetWindowText   (data.PciData.u.type0.SubSystemID, WordFormat);
     c_ROMBaseAddress.SetWindowText(data.PciData.u.type0.ROMBaseAddress, DWordFormat);
     c_Reserved1.SetWindowText     (data.PciData.u.type0.Reserved2[0], DWordFormat);
     c_Reserved2.SetWindowText     (data.PciData.u.type0.Reserved2[1], DWordFormat);

     c_InterruptLine.SetWindowText (data.PciData.u.type0.InterruptLine, ByteFormat);
     c_InterruptPin.SetWindowText  (data.PciData.u.type0.InterruptPin, ByteFormat);
     c_MinimumGrant.SetWindowText  (data.PciData.u.type0.MinimumGrant, ByteFormat);
     c_MaximumLatency.SetWindowText(data.PciData.u.type0.MaximumLatency, ByteFormat);

     c_Data.ResetContent();

     for(int i = 0; i < sizeof(data.PciData.DeviceSpecific); i += sizeof(DWORD))
        { /* load dev specific */
	 c_Data.AddString(*(DWORD*)&data.PciData.DeviceSpecific[i]);
	} /* load dev specific */
    }


BOOL PCIData::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
 	CheckRadioButton(IDC_HEX, IDC_DECIMAL, IDC_HEX);

	c_DisplayAs.AddStrings(Displays);
	c_DisplayAs.SetCurSel(0);
	c_Data.SetFormat(c_DisplayAs.GetItemData(c_DisplayAs.GetCurSel()));

 	LoadPCIData();
	
	SetWindowText(caption);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void PCIData::OnHex() 
{
 LoadPCIData();
	
}

void PCIData::OnDecimal() 
{
 LoadPCIData();
	
}

void PCIData::OnSelendokDisplayas() 
{
 c_Data.SetFormat(c_DisplayAs.GetItemData(c_DisplayAs.GetCurSel()));
}

void PCIData::PostNcDestroy() 
{
 	delete [] (LPTSTR)m_psp.pszTitle;
 	delete this;
	CPropertyPage::PostNcDestroy();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -