📄 portio.c
字号:
CheckDlgButton(hDlg, IDC_D4, (gwDoState & 0x10));
CheckDlgButton(hDlg, IDC_D5, (gwDoState & 0x20));
CheckDlgButton(hDlg, IDC_D6, (gwDoState & 0x40));
CheckDlgButton(hDlg, IDC_D7, (gwDoState & 0x80));
CheckDlgButton(hDlg, IDC_D8, (gwDoState & 0x100));
CheckDlgButton(hDlg, IDC_D9, (gwDoState & 0x200));
CheckDlgButton(hDlg, IDC_D10, (gwDoState & 0x400));
CheckDlgButton(hDlg, IDC_D11, (gwDoState & 0x800));
CheckDlgButton(hDlg, IDC_D12, (gwDoState & 0x1000));
CheckDlgButton(hDlg, IDC_D13, (gwDoState & 0x2000));
CheckDlgButton(hDlg, IDC_D14, (gwDoState & 0x4000));
CheckDlgButton(hDlg, IDC_D15, (gwDoState & 0x8000));
return TRUE;
case WM_COMMAND :
switch (LOWORD(wParam))
{
case IDCANCEL :
EndDialog(hDlg, 0);
return TRUE;
case IDC_WRITEBYTE :
// get output byte value
if (IsDlgButtonChecked(hDlg, IDC_D0) > 0)
gwDoState = 1;
else
gwDoState = 0;
if (IsDlgButtonChecked(hDlg, IDC_D1) > 0)
gwDoState += 0x2;
if (IsDlgButtonChecked(hDlg, IDC_D2) > 0)
gwDoState += 0x4;
if (IsDlgButtonChecked(hDlg, IDC_D3) > 0)
gwDoState += 0x8;
if (IsDlgButtonChecked(hDlg, IDC_D4) > 0)
gwDoState += 0x10;
if (IsDlgButtonChecked(hDlg, IDC_D5) > 0)
gwDoState += 0x20;
if (IsDlgButtonChecked(hDlg, IDC_D6) > 0)
gwDoState += 0x40;
if (IsDlgButtonChecked(hDlg, IDC_D7) > 0)
gwDoState += 0x80;
// output byte
if((ErrCde = DRV_outp(glDevNum, gwPort, gwDoState)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
return TRUE;
case IDC_WRITEWORD:
// get output byte value
if (IsDlgButtonChecked(hDlg, IDC_D0) > 0)
gwDoState = 1;
else
gwDoState = 0;
if (IsDlgButtonChecked(hDlg, IDC_D1) > 0)
gwDoState += 0x2;
if (IsDlgButtonChecked(hDlg, IDC_D2) > 0)
gwDoState += 0x4;
if (IsDlgButtonChecked(hDlg, IDC_D3) > 0)
gwDoState += 0x8;
if (IsDlgButtonChecked(hDlg, IDC_D4) > 0)
gwDoState += 0x10;
if (IsDlgButtonChecked(hDlg, IDC_D5) > 0)
gwDoState += 0x20;
if (IsDlgButtonChecked(hDlg, IDC_D6) > 0)
gwDoState += 0x40;
if (IsDlgButtonChecked(hDlg, IDC_D7) > 0)
gwDoState += 0x80;
if (IsDlgButtonChecked(hDlg, IDC_D8) > 0)
gwDoState += 0x100;
if (IsDlgButtonChecked(hDlg, IDC_D9) > 0)
gwDoState += 0x200;
if (IsDlgButtonChecked(hDlg, IDC_D10) > 0)
gwDoState += 0x400;
if (IsDlgButtonChecked(hDlg, IDC_D11) > 0)
gwDoState += 0x800;
if (IsDlgButtonChecked(hDlg, IDC_D12) > 0)
gwDoState += 0x1000;
if (IsDlgButtonChecked(hDlg, IDC_D13) > 0)
gwDoState += 0x2000;
if (IsDlgButtonChecked(hDlg, IDC_D14) > 0)
gwDoState += 0x4000;
if (IsDlgButtonChecked(hDlg, IDC_D15) > 0)
gwDoState += 0x8000;
// output byte
if((ErrCde = DRV_outpw(glDevNum, gwPort, gwDoState)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
return TRUE;
case IDC_READBYTE:
// read port byte
if((ErrCde = DRV_inp(glDevNum, gwPort,
(USHORT far *)&gwDoState)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
// display the value
_itoa((int)(gwDoState & 0xff), szBuffer, 16);
SendDlgItemMessage(hDlg, IDC_BYTEDATA, WM_SETTEXT, 0,
(LPARAM)((LPSTR)szBuffer));
return TRUE;
case IDC_READWORD:
// read port byte
if((ErrCde = DRV_inpw(glDevNum, gwPort,
(USHORT far *)&gwDoState)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
// display the value
_ltoa((LONG)gwDoState, szBuffer, 16);
SendDlgItemMessage(hDlg, IDC_WORDDATA, WM_SETTEXT, 0,
(LPARAM)((LPSTR)szBuffer));
return TRUE;
}
break;
}
return FALSE ;
}
/***************************************************************************
FUNCTION: MainWndProc(HWND, unsigned, WPARAM, LPARAM)
PURPOSE: Processes messages
MESSAGES:
WM_CREATE - create window
WM_COMMAND - application menu (About dialog box)
WM_DESTROY - destroy window
****************************************************************************/
long FTYPE MainWndProc
(
HWND hWnd, // window handle
unsigned message, // type of message
WPARAM wParam, // additional information
LPARAM lParam // additional information
)
{
static HANDLE hInstance ;
switch (message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;
lpfnRunDlgProc = MakeProcInstance (RunDlgProc, hInstance) ;
return 0 ;
case WM_COMMAND: // message: from application menu
switch (LOWORD(wParam))
{
case IDM_SETTING :
DialogBox (hInstance, MAKEINTRESOURCE(IDD_SETTING),
hWnd, lpfnConfigDlgProc) ;
return 0;
case IDM_RUN :
DialogBox (hInstance, MAKEINTRESOURCE(IDD_RUN),
hWnd, lpfnRunDlgProc) ;
return 0;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return ((LONG)NULL);
}
//------------------------------------------------------------------
// Function : StringToDec
// PURPOSE : This function is used to do string conversion to base
// by 16 or base by 10.. etc.
// Parameters : szStr(IN), nBase(IN)
// Return : szStr (success)
// Call/Called procedure cross reference :
// Call Called Explanation
// Power
//------------------------------------------------------------------
static int StringToDec(char *szStr, int nBase)
{
int i,j,nValue, nResult;
char cNum;
nResult = 0;
for(i = strlen(szStr)-1, j = 0; i >=0 ; --i,++j)
{
cNum = *(szStr+i);
if(cNum >= '0' && cNum <= '9')
nValue = (int)(cNum - '0');
else
{
cNum = tolower(cNum);
nValue = (int)(cNum - 'a') + 10;
}
nResult = nResult + Power(nBase, j)* nValue;
}
return (nResult);
}
//------------------------------------------------------------------
// Function : Power
// PURPOSE : This function is used to do support StringToDec
// function.
// Parameters : nBase(IN), nPow(IN)
// Return : Value (success)
// Call/Called procedure cross reference :
// Call Called Explanation
// StringToDec
//------------------------------------------------------------------
static int Power(int nBase, int nPow)
{
int nValue,i;
if(nPow == 0)
return(1);
nValue = 1;
for(i = nPow; i > 0; i--)
nValue = nValue * nBase;
return(nValue);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -