//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include <stdio.h>
#include "WinIo.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma link "WinIo_bc.lib"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
bWinIoInitOK = InitializeWinIo();
if(!bWinIoInitOK)
{
Application->MessageBox("Init WinIO NG!","Message",MB_OK|MB_ICONSTOP);
Application->Terminate();
}
InitPortFuncs();
}
//---------------------------------------------------------------------------
int TForm1::IN_Port_Long(
unsigned int PortBase,
unsigned int PortOffset,
unsigned int *PortRegValue
)
{
*PortRegValue = inportd(PortBase + PortOffset);
return 1;
}
//---------------------------------------------------------------------------
int TForm1::Out_Port_Long(
unsigned int PortBase,
unsigned int PortOffset,
unsigned int PortRegValue
)
{
int rg, count;
count = 0;
do
{
outportd(PortBase + PortOffset, PortRegValue);
rg = inportd(PortBase + PortOffset);
count++;
} while((rg != PortRegValue) && (rg != 0xFF) && (count < 10));
if (count < 10)
return 1;
else
return 0;
}
//---------------------------------------------------------------------------
void TForm1::PCI_Scan(void)
{
StatusBar1->SimpleText = "Scanning PCI Bus now......";
StatusBar1->Update();
int Bus, Dev, Fun, Reg, ID[4], RevID, CCode[2], INT[2], Amount_PCI_Device, i;
unsigned int ChkReg;
Amount_PCI_Device = 0;
Application->ProcessMessages();
Panel1->Color = clBtnFace; Panel1->Caption = "";
Panel1->Update();
Application->ProcessMessages();
PCI_Device_Info->Lines->BeginUpdate();
PCI_Device_Info->Lines->Append("PCI Device Information:");
PCI_Device_Info->Lines->Append("Bus Dev Func VenID DevID RevID CCode IRQ INT");
PCI_Device_Info->Lines->Append("==================================================");
Application->ProcessMessages();
for (Bus = 0; Bus <= 0xff; Bus++)
for (Dev = 0; Dev <= 0x1f; Dev++)
for (Fun = 0; Fun <= 0x07; Fun++)
{
Reg = 0x80000000 + (Bus << 16) + (Dev << 11) + (Fun << 8);
PassFlag &= Out_Port_Long(0xcf8, 0, Reg);
PassFlag &= IN_Port_Long(0xcfc, 0, &ChkReg);
/* Vendor Identification & Device Identification */
if (ChkReg != 0x00000000 && ChkReg != 0xffffffff)
{
Amount_PCI_Device++;
for (i = 0; i <= 3; i++)
ID[i] = (ChkReg >> (8 * i)) & 0xff;
/* Revision ID */
PassFlag &= Out_Port_Long(0xcf8, 0, Reg + 0x08);
PassFlag &= IN_Port_Long(0xcfc, 0, &ChkReg);
RevID = ChkReg & 0xff;
/* Class Code */
PassFlag &= Out_Port_Long(0xcf8, 0, Reg + 0x08);
PassFlag &= IN_Port_Long(0xcfc, 0, &ChkReg);
for (i = 0; i <= 1; i++)
CCode[i] = (ChkReg >> (16 + 8 * i)) & 0xff;
/* Interrupt */
PassFlag &= Out_Port_Long(0xcf8, 0, Reg + 0x3c);
PassFlag &= IN_Port_Long(0xcfc, 0, &ChkReg);
for (i = 0; i <= 1; i++)
INT[i] = (ChkReg >> (8 * i)) & 0xff;
Application->ProcessMessages();
PCI_Device_Info->Lines->Append(
" " + IntToHex(Bus, 2) +
" " + IntToHex(Dev, 2) +
" " + IntToHex(Fun, 2) +
" " + IntToHex(ID[1], 2) + IntToHex(ID[0], 2) +
" " + IntToHex(ID[3], 2) + IntToHex(ID[2], 2) +
" " + IntToHex(RevID, 2) +
" " + IntToHex(CCode[1], 2) + IntToHex(CCode[0], 2) +
" " + IntToHex(INT[0], 2) +
" " + IntToHex(INT[1], 2));
}
}
PCI_Device_Info->Lines->EndUpdate();
if (PassFlag)
{
Panel1->Color = clGreen;
Panel1->Caption = "PASS";
Edit1->Text = Amount_PCI_Device;
StatusBar1->SimpleText = "Scan PCI Device passed!";
StatusBar1->Update();
}
else
{
Panel1->Color = clRed;
Panel1->Caption = "FAIL";
StatusBar1->SimpleText = "Scan PCI Device failed!";
StatusBar1->Update();
MessageDlg("Scan PCI Device failed!", mtError, TMsgDlgButtons() << mbOK, 0);
return;
}
}
//---------------------------------------------------------------------------
void TForm1::Check_System(void)
{
int PCI_Device_Len, Compared_File_Len, i;
FILE *Compare_File_FD;
Compare_File_FD = fopen(TestConfigIniFile.Compared_File_Name.c_str(), "r");
if (Compare_File_FD == NULL)
{
fclose(Compare_File_FD);
Panel2->Color = clRed;
Panel2->Caption = "FAIL";
StatusBar1->SimpleText = "Open the compared file failed!";
StatusBar1->Update();
MessageDlg("Open the compared file failed!", mtError, TMsgDlgButtons() << mbOK, 0);
PassFlag = 1;
return;
}
fclose(Compare_File_FD);
Application->ProcessMessages();
Panel2->Color = clBtnFace; Panel2->Caption = "";
Panel2->Update();
Application->ProcessMessages();
Compared_File_Info->Lines->LoadFromFile(TestConfigIniFile.Compared_File_Name);
Compared_File_Info->Update();
PCI_Device_Len = PCI_Device_Info->Lines->Count;
Compared_File_Len = Compared_File_Info->Lines->Count;
if (PCI_Device_Len == Compared_File_Len)
for (i = 0; i <= Compared_File_Len; i++)
{
if (PCI_Device_Info->Lines->Strings[i] != Compared_File_Info->Lines->Strings[i])
{
PassFlag &= 0;
break;
}
}
else
PassFlag &= 0;
if (PassFlag)
{
Panel2->Color = clGreen;
Panel2->Caption = "PASS";
StatusBar1->SimpleText = "Check system information passed!";
StatusBar1->Update();
}
else
{
Panel2->Color = clRed;
Panel2->Caption = "FAIL";
if (PCI_Device_Len == Compared_File_Len)
StatusBar1->SimpleText = "The failed data: " + PCI_Device_Info->Lines->Strings[i] + ". The compared data: " + Compared_File_Info->Lines->Strings[i] + ".";
else
StatusBar1->SimpleText = "Check the amount of PCI Device failed!";
StatusBar1->Update();
PassFlag = 1;
}
}
//---------------------------------------------------------------------------
void TForm1::BIOS_Scan(void)
{
HANDLE hPhyMem;
AnsiString BIOS_Name, BIOS_Message, BIOS_Copyright, BIOS_Date, BIOS_SN;
char *lpInfo = MapPhysToLin((char*)0xf0000, 65536, &hPhyMem);
BIOS_Name = lpInfo + 0xe061;
BIOS_Message = lpInfo + 0xe0c1;
BIOS_Copyright = lpInfo + 0xe091;
BIOS_Date = lpInfo + 0xfff5;
BIOS_SN = lpInfo + 0xec71;
UnmapPhysicalMemory(hPhyMem, lpInfo);
Application->ProcessMessages();
PCI_Device_Info->Clear();
PCI_Device_Info->Lines->BeginUpdate();
PCI_Device_Info->Lines->Append("BIOS Information:");
PCI_Device_Info->Lines->Append("==================================================");
if (TestConfigIniFile.Scan_BIOS_Name == 1)
{
PCI_D