// DIODlg.cpp : implementation file // #include "stdafx.h" #include "DIO.h" #include "DIODlg.h" #include "ACCES32.h" #define MyKey "Software\\PCIFIND\\NTioPCI\\Parameters" #define InsCR(x) x += 0x0d; x += 0x0a; /* struct TPCI_COMMON_CONFIG { unsigned short VendorID; unsigned short DeviceID; unsigned short Command; unsigned short Status; unsigned char RevisionID; unsigned char ProgIf; unsigned char SubClass; unsigned char BaseClass; unsigned char CacheLineSize; unsigned char LatencyTimer; unsigned char HeaderType; unsigned char BIST; unsigned long BaseAddresses[6]; unsigned long Reserved1[2]; unsigned long RomBaseAddress; unsigned long Reserved2[2]; unsigned char InterruptLine; unsigned char InterruptPin; unsigned char MinimumGrant; unsigned char MaximumLatency; }; */ TPCI_COMMON_CONFIG buf[64]; bool RunFlag; unsigned long Address; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDIODlg dialog CDIODlg::CDIODlg(CWnd* pParent /*=NULL*/) : CDialog(CDIODlg::IDD, pParent) { //{{AFX_DATA_INIT(CDIODlg) m_CardName = _T(""); m_AddressSelection = _T(""); m_InputA = _T("00000000"); m_InputB = _T("00000000"); m_OutputA = _T("00000000"); m_StatusEdit = _T("This sample outputs a walking bit on Port A of the selected group. It then reads back the value from Port A. This should be identical to the output value due to on-chip readback. It also displays the Input from Port B. If a wrap plug is installed, Port B should read the same value. Otherwise, ground individual bits on Port B to see them show zeroes on the display."); m_IsaEdit = _T("300"); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CDIODlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDIODlg) DDX_Control(pDX, IDC_ISA_STATIC, m_IsaStatic); DDX_Control(pDX, IDC_ISA_EDIT, m_IsaEditCtrl); DDX_Control(pDX, IDC_STATUS, m_StatusControl); DDX_Control(pDX, IDOK, m_TimerButton); DDX_Control(pDX, IDC_COMBO1, m_AddressCombo); DDX_Text(pDX, IDC_CARD_NAME, m_CardName); DDX_CBString(pDX, IDC_COMBO1, m_AddressSelection); DDX_Text(pDX, IDC_INPUTA, m_InputA); DDX_Text(pDX, IDC_INPUTB, m_InputB); DDX_Text(pDX, IDC_OUTPUTA, m_OutputA); DDX_Text(pDX, IDC_STATUS, m_StatusEdit); DDX_Text(pDX, IDC_ISA_EDIT, m_IsaEdit); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDIODlg, CDialog) //{{AFX_MSG_MAP(CDIODlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDOK, OnBeginButton) ON_BN_CLICKED(IDCANCEL, OnExitButton) ON_CBN_SELCHANGE(IDC_COMBO1, OnAddressComboChange) ON_WM_TIMER() ON_WM_SHOWWINDOW() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDIODlg message handlers BOOL CDIODlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon if (InPortB(0x61) == 0xAA55) { MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", MB_OK); } // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } // 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 CDIODlg::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 CDIODlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CDIODlg::OnExitButton() { exit(0); } void CDIODlg::FindCards(void) { int i; bool found; HKEY Key; unsigned long DataType, DataLength; long Num; char AddStr[255]; found = false; RegOpenKeyEx(HKEY_LOCAL_MACHINE, MyKey, 0, KEY_READ, &Key); DataLength = sizeof(Num); if (RegQueryValueEx(Key, "NumDevices", NULL, &DataType, (PUCHAR)&Num, &DataLength) != ERROR_SUCCESS) Num = 0; RunFlag = true; if (Num > 0) { DataLength = Num * sizeof(TPCI_COMMON_CONFIG); RegQueryValueEx(Key, "PCICommonConfig", NULL, &DataType, (PUCHAR)buf, &DataLength); } for (i=0; i 0) + 0x30); m_OutputA = msg; for (j=0; j<8; j++) msg[7-j] = (((value[1] & (1 << j)) > 0) + 0x30); m_InputA = msg; for (j=0; j<8; j++) msg[7-j] = (((value[2] & (1 << j)) > 0) + 0x30); m_InputB = msg; UpdateData(false); CDialog::OnTimer(nIDEvent); } void CDIODlg::UpdateDriverRegistry(void) { unsigned long TypeValue, StartValue, ErrorControlValue; HKEY Key; char str[255]; RegOpenKeyEx(HKEY_LOCAL_MACHINE, MyKey, 0, KEY_ALL_ACCESS, &Key); TypeValue = 1; RegSetValueEx(Key, "Type", 0, REG_DWORD, (PUCHAR)&TypeValue, sizeof(TypeValue)); StartValue = 2; RegSetValueEx(Key, "Start", 0, REG_DWORD, (PUCHAR)&StartValue, sizeof(StartValue)); ErrorControlValue = 1; RegSetValueEx(Key, "ErrorControl", 0, REG_DWORD, (PUCHAR)&ErrorControlValue, sizeof(ErrorControlValue)); *str = 0; strcat(str, "Extended Base"); RegSetValueEx(Key, "Group", 0, REG_SZ, (PUCHAR)str, strlen(str)); RegCloseKey(Key); } void CDIODlg::OnShowWindow(BOOL bShow, UINT nStatus) { CDialog::OnShowWindow(bShow, nStatus); InsCR(m_StatusEdit); FindCards(); }