?? msvc50dlg.cpp
字號:
// msvc50Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "msvc50.h"
#include "msvc50Dlg.h"
#include <winsvc.h>
#include "tvichw32.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
PVicHW32Descriptor HwCtrl = NULL;
BOOL ActiveHW = FALSE;
short IRQ = 10;
void * PointPhys = NULL;
DWORD PhysAddr = 0;
long Flag_Intr = 0;
BYTE membuffer[256];
char buffer[255];
HFONT hFontMemdump = 0;
UINT TimerID = 0;
DWORD Sum_Ticks = 0;
DWORD IRQCounter = 0;
DWORD Flag_Tim = 0;
DWORD OldTicker =0, CurrTicker = 0;
HANDLE hDlg;
short Data_Reg, Status_Reg, Scan_Code;
/////////////////////////////////////////////////////////////////////////////
// CMSVC50Dlg dialog
CMSVC50Dlg::CMSVC50Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMSVC50Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMSVC50Dlg)
m_Unmask = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMSVC50Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMSVC50Dlg)
DDX_Check(pDX, IDC_UNMASK, m_Unmask);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMSVC50Dlg, CDialog)
//{{AFX_MSG_MAP(CMSVC50Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_OPENDRIVER, OnOpendriver)
ON_BN_CLICKED(ID_CLOSEDRIVER, OnClosedriver)
ON_BN_CLICKED(IDC_WPIN1, OnWpin)
ON_BN_CLICKED(IDC_READPORT, OnReadPort)
ON_BN_CLICKED(IDC_WRITEPORT, OnWritePort)
ON_BN_CLICKED(IDC_HARD, OnHardAccess)
ON_BN_CLICKED(IDC_READMEMORY, OnReadMemory)
ON_BN_CLICKED(IDC_RPIN25, OnShowButtons)
ON_BN_CLICKED(IDC_UNMASK, OnUnmask)
ON_BN_CLICKED(IDC_INIT, OnLPTInit)
ON_EN_CHANGE(IDC_LPT_NUMBER, OnChangeLptNumber)
ON_BN_CLICKED(IDC_WPIN10, OnWpin)
ON_BN_CLICKED(IDC_EXIT, OnOK)
ON_BN_CLICKED(IDC_WPIN2, OnWpin)
ON_BN_CLICKED(IDC_WPIN20, OnWpin)
ON_BN_CLICKED(IDC_WPIN11, OnWpin)
ON_BN_CLICKED(IDC_WPIN3, OnWpin)
ON_BN_CLICKED(IDC_WPIN12, OnWpin)
ON_BN_CLICKED(IDC_WPIN13, OnWpin)
ON_BN_CLICKED(IDC_WPIN14, OnWpin)
ON_BN_CLICKED(IDC_WPIN15, OnWpin)
ON_BN_CLICKED(IDC_WPIN16, OnWpin)
ON_BN_CLICKED(IDC_WPIN17, OnWpin)
ON_BN_CLICKED(IDC_WPIN18, OnWpin)
ON_BN_CLICKED(IDC_WPIN19, OnWpin)
ON_BN_CLICKED(IDC_WPIN4, OnWpin)
ON_BN_CLICKED(IDC_WPIN5, OnWpin)
ON_BN_CLICKED(IDC_WPIN6, OnWpin)
ON_BN_CLICKED(IDC_WPIN7, OnWpin)
ON_BN_CLICKED(IDC_WPIN8, OnWpin)
ON_BN_CLICKED(IDC_WPIN9, OnWpin)
ON_BN_CLICKED(IDC_WPIN21, OnWpin)
ON_BN_CLICKED(IDC_WPIN22, OnWpin)
ON_BN_CLICKED(IDC_WPIN23, OnWpin)
ON_BN_CLICKED(IDC_WPIN24, OnWpin)
ON_BN_CLICKED(IDC_WPIN25, OnWpin)
ON_BN_CLICKED(IDC_LPT_IRQ, OnLptIrq)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//----------------------------------------------------------------------------
DWORD
HexToInt(char* s)
{
char hexch[] = "0123456789ABCDEF";
int i,j;
DWORD r,n,k;
char ch;
k=1; r=0;
for (i=strlen(s); i>0; i--) {
ch = s[i-1]; if (ch > 0x3f) ch &= 0xDF;
n = 0;
for (j = 0; j<16; j++)
if (ch == hexch[j])
n = j;
r += (n*k);
k *= 16;
}
return r;
}
//----------------------------------------------------------------------------
char*
PrintMemLine(char *szBuf, LPSTR mem, int len, int dwid, DWORD olbl)
{
int i, j;
BYTE c;
BYTE buff[80];
BYTE tbuf[80];
if (len > dwid)
len = dwid;
*szBuf = 0;
// memory address
sprintf((char *)tbuf, "%08X ", olbl);
strcpy(szBuf, (char *)tbuf);
for (i = 0; i < len; i++) {
c = *mem++;
sprintf((char *)tbuf, "%02X", c);
strcat(szBuf, (char *)tbuf);
if (c >= 32 && c < 127)
buff[i] = c;
else
buff[i] = 46;
}
j = dwid - i;
buff[i] = 0;
for (i = j; i > 0; i--)
strcat(szBuf, " ");
// add ASCII codes.
sprintf((char *)tbuf, " %s", (char *)buff); // " |%s|"
strcat(szBuf, (char *)tbuf);
for (i = j; i > 0; i--)
strcat(szBuf, " ");
return(szBuf);
}
void CALLBACK EXPORT OnMyTimer(
HWND hWnd, //handle of CWnd that called SetTimer
UINT nMsg, //WM_TIMER
UINT nIDEvent, //timer identification
DWORD dwTime //system time
)
{
int n,i;
if (ActiveHW) {
for (i=1; i<=17; i++) {
n = GetPin(HwCtrl,i)?1:0;
CheckDlgButton(hWnd,IDC_RPIN+i,n);
}
CheckDlgButton(hWnd,IDC_ACKWL,GetLPTAckwl(HwCtrl)?1:0);
CheckDlgButton(hWnd,IDC_BUSY,GetLPTBusy(HwCtrl)?1:0);
CheckDlgButton(hWnd,IDC_ERROR,GetLPTError(HwCtrl)?1:0);
CheckDlgButton(hWnd,IDC_PE,GetLPTPaperEnd(HwCtrl)?1:0);
CheckDlgButton(hWnd,IDC_SLCT,GetLPTSlct(HwCtrl)?1:0);
SetDlgItemInt(hWnd,IDE_IRQCOUNT , IRQCounter, FALSE);
SetDlgItemInt(hWnd,IDE_IRQHANDLED, Flag_Intr, FALSE);
SetDlgItemInt(hWnd,IDE_IRQTIME , Flag_Tim / 1000, FALSE);
sprintf(buffer, "%02Xh", Scan_Code);
SetDlgItemText(hWnd,IDC_SCAN,buffer);
sprintf(buffer, "%02Xh", Data_Reg);
SetDlgItemText(hWnd,IDC_DATA,buffer);
sprintf(buffer, "%02Xh", Status_Reg);
SetDlgItemText(hWnd,IDC_STATUS,buffer);
if (ActiveHW && (!IsIRQMasked(HwCtrl))){
CurrTicker = GetTickCount();
Flag_Tim = Sum_Ticks+CurrTicker-OldTicker;
}
else OldTicker = GetTickCount();
}
}
/////////////////////////////////////////////////////////////////////////////
// CMSVC50Dlg message handlers
BOOL CMSVC50Dlg::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
// TODO: Add extra initialization here
CheckDlgButton(IDC_HARD,1);
SetDlgItemText(IDC_PORT0, "300");
SetDlgItemText(IDC_PORT1, "300");
SetDlgItemText(IDC_PORT2, "300");
SetDlgItemText(IDC_PORT3, "300");
SetDlgItemText(IDE_MEMADDR, "000C0044");
SetDlgItemText(IDC_IRQ, "10");
SetDlgItemText(IDC_LPTS, "0");
SetDlgItemText(IDC_LPT_NUMBER, "0");
SetDlgItemText(IDC_BASE, "000h");
hFontMemdump = CreateFont(-12, 0, 0, 0, FW_NORMAL,
0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FIXED_PITCH | FF_DONTCARE, "Courier New");
SendDlgItemMessage(IDL_MEMDUMP, WM_SETFONT, (WPARAM)hFontMemdump, 0L);
SendDlgItemMessage(IDE_MEMADDR, WM_SETFONT, (WPARAM)hFontMemdump, 0L);
//SendDlgItemMessage(IDL_MEMDUMP, WM_SETFONT, (WPARAM)hFontMemdump, 0L);
//SendDlgItemMessage(IDL_MEMDUMP, WM_SETFONT, (WPARAM)hFontMemdump, 0L);
//SendDlgItemMessage(IDL_MEMDUMP, WM_SETFONT, (WPARAM)hFontMemdump, 0L);
GetDlgItem(IDC_WPIN10)->EnableWindow(FALSE);
GetDlgItem(IDC_WPIN11)->EnableWindow(FALSE);
GetDlgItem(IDC_WPIN12)->EnableWindow(FALSE);
GetDlgItem(IDC_WPIN13)->EnableWindow(FALSE);
GetDlgItem(IDC_WPIN15)->EnableWindow(FALSE);
if ((GetVersion() & 0x80000000)!=0) GetDlgItem(IDC_LABEL3)->SetWindowText("Operating system: Windows 95/98");
else GetDlgItem(IDC_LABEL3)->SetWindowText("Operating system: Windows NT");
TimerID = SetTimer(1000, 100, OnMyTimer);
UpdateData();
//E_Addr.text = IntToHex(PhysAddr,8);
OnShowButtons();
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 CMSVC50Dlg::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 CMSVC50Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMSVC50Dlg::OnOpendriver()
{
HwCtrl = 0;
HwCtrl = OpenTVicHW32(HwCtrl);
if (!GetActiveHW(HwCtrl)){
MessageBeep(0);
MessageBox("The driver VICHWxx not found",
" Warning! ",MB_OK | MB_ICONWARNING);
}
else {
ActiveHW = TRUE;
IRQ = (WORD) GetDlgItemInt(IDC_IRQ, NULL, FALSE);
SetIRQ(HwCtrl,IRQ,NULL);
for (int i = 1; i<=17; i++)
SetPin(HwCtrl,i,FALSE);
};
GetDlgItem(IDC_READMEMORY)->EnableWindow(TRUE);
OnShowButtons();
}
void CMSVC50Dlg::OnClosedriver()
{
if (ActiveHW) SetPortByte(HwCtrl,GetLPTBasePort(HwCtrl)+2,0);
CheckDlgButton(IDC_LPT_IRQ,0);
CheckDlgButton(IDC_UNMASK,0);
PointPhys=NULL;
GetDlgItem(IDC_READMEMORY)->EnableWindow(FALSE);
Flag_Intr=0;
ActiveHW=FALSE;
HwCtrl=CloseTVicHW32(HwCtrl);
OnShowButtons();
}
void CMSVC50Dlg::OnOK()
{
OnClosedriver();
CDialog::OnOK();
}
BEGIN_EVENTSINK_MAP(CMSVC50Dlg, CDialog)
//{{AFX_EVENTSINK_MAP(CMSVC50Dlg)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CMSVC50Dlg::OnWpin()
{
if (ActiveHW)
for (int i = 1; i<=17; i++)
SetPin(HwCtrl,i,IsDlgButtonChecked(IDC_WPIN1+i-1)==1);
}
void CMSVC50Dlg::OnReadPort()
{
WORD a;
for (int i=0; i<4; i++) {
GetDlgItemText(IDC_PORT0 + i, buffer, 40);
a = (WORD) HexToInt(buffer);
sprintf(buffer, "%02X", GetPortByte( HwCtrl, a ));
SetDlgItemText(IDC_VAL0 + i, buffer);
}
}
void CMSVC50Dlg::OnWritePort()
{
WORD a;
BYTE d;
for (int i=0; i<4; i++) {
GetDlgItemText(IDC_PORT0 + i, buffer, 40);
a = (WORD) HexToInt(buffer);
GetDlgItemText(IDC_VAL0 + i, buffer, 40);
d = (BYTE) HexToInt(buffer);
SetPortByte( HwCtrl, a, d);
}
}
void CMSVC50Dlg::OnHardAccess()
{
SetHardAccess( HwCtrl, (BOOL)((SendDlgItemMessage(IDC_HARD, BM_GETSTATE, 0, 0) & 1) != 0) );
}
void CMSVC50Dlg::OnReadMemory()
{
GetDlgItemText(IDE_MEMADDR, buffer, 40);
PhysAddr = HexToInt(buffer);
sprintf(buffer, "%08X", PhysAddr);
SetDlgItemText(IDE_MEMADDR, buffer);
PointPhys = (void*)MapPhysToLinear(HwCtrl,PhysAddr, 256);
//sprintf(buffer, "%08X", PointPhys);
//SetDlgItemText(IDE_MEMADDR2, buffer);
OnShowButtons();
if (PointPhys != NULL) {
memcpy(membuffer, (BYTE*) PointPhys, 256);
SendDlgItemMessage( IDL_MEMDUMP, LB_RESETCONTENT, 0, 0);
for (int i=0; i<16; i++) {
PrintMemLine(buffer, (LPSTR) &membuffer[i*16], 16, 16, PhysAddr + (DWORD)(i*16));
SendDlgItemMessage(IDL_MEMDUMP, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR)buffer);
}
}
}
void CMSVC50Dlg::OnShowButtons()
{
GetDlgItem(IDC_READMEMORY)->EnableWindow(ActiveHW);
if (ActiveHW) {
SetDlgItemInt(IDC_LPTS,GetLPTNumPorts(HwCtrl));
if (GetDlgItemInt(IDC_LPT_NUMBER) != (WORD)GetLPTNumber(HwCtrl))
SetDlgItemInt(IDC_LPT_NUMBER,GetLPTNumber(HwCtrl));
sprintf(buffer, "%03Xh", GetLPTBasePort(HwCtrl));
SetDlgItemText(IDC_BASE, buffer);
}
GetDlgItem(IDC_BASE)->EnableWindow(ActiveHW);
GetDlgItem(IDC_LPT_NUMBER)->EnableWindow(ActiveHW);
GetDlgItem(IDC_INIT)->EnableWindow(ActiveHW);
GetDlgItem(IDC_LPTS)->EnableWindow(ActiveHW);
CheckDlgButton(IDC_HARD,(!ActiveHW) || (GetHardAccess(HwCtrl))?1:0);
GetDlgItem(IDC_HARD)->EnableWindow(ActiveHW);
GetDlgItem(IDC_IRQ)->EnableWindow(ActiveHW && (!IsDlgButtonChecked(IDC_UNMASK)));
GetDlgItem(ID_OPENDRIVER)->EnableWindow(!ActiveHW);
GetDlgItem(ID_CLOSEDRIVER)->EnableWindow(ActiveHW);
GetDlgItem(IDC_READPORT)->EnableWindow(ActiveHW);
GetDlgItem(IDC_WRITEPORT)->EnableWindow(ActiveHW);
GetDlgItem(IDC_UNMASK)->EnableWindow((ActiveHW && IRQ>0 && IRQ<16)?1:0);
GetDlgItem(IDC_LPT_IRQ)->EnableWindow(ActiveHW &&
((IRQ==7) && (GetLPTNumber(HwCtrl) == 1)) ||
((IRQ==5) && (GetLPTNumber(HwCtrl) == 2)));
for (int i = 1; i<18; i++) {
if (!ActiveHW) CheckDlgButton(IDC_RPIN1+i-1,0);
if (!ActiveHW) CheckDlgButton(IDC_WPIN1+i-1,0);
};
}
void __stdcall OnHWInterrupt(long HWCounter,
short LPT_DataReg,
short LPT_StatusReg,
short Keyb_ScanCode)
{
Flag_Intr++;
Data_Reg = LPT_DataReg;
Status_Reg = LPT_StatusReg;
Scan_Code = Keyb_ScanCode;
IRQCounter = HWCounter;
}
void CMSVC50Dlg::OnUnmask()
{
if (!IsIRQMasked(HwCtrl)) {
Sum_Ticks = Flag_Tim;
MaskIRQ(HwCtrl);
SetPortByte(HwCtrl,GetLPTBasePort(HwCtrl)+2,0);
CheckDlgButton(IDC_LPT_IRQ,0);
}
else {
IRQ = (WORD) GetDlgItemInt(IDC_IRQ, NULL, FALSE);
Flag_Intr = 0;
Sum_Ticks = 0;
Flag_Tim = 0;
Scan_Code = 0;
SetIRQ(HwCtrl,IRQ,OnHWInterrupt);
UnmaskIRQ(HwCtrl);
};
OnShowButtons();
}
void CMSVC50Dlg::OnLPTInit()
{
LPTInit(HwCtrl);
}
void CMSVC50Dlg::OnChangeLptNumber()
{
int n = GetDlgItemInt(IDC_LPT_NUMBER, NULL, FALSE);
if (!ActiveHW) return;
if ((n>0) && (n<=GetLPTNumPorts(HwCtrl))) {
SetLPTNumber(HwCtrl,n);
}
else {
MessageBeep(0);
MessageBox("Incorrect value!",
" Warning! ",MB_OK | MB_ICONWARNING);
};
OnShowButtons();
}
void CMSVC50Dlg::OnLptIrq()
{
if (IsDlgButtonChecked(IDC_LPT_IRQ)) SetPortByte(HwCtrl,GetLPTBasePort(HwCtrl)+2,0x10);
else SetPortByte(HwCtrl,GetLPTBasePort(HwCtrl)+2,0x00);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -