📄 err.cpp
字号:
#include "stdafx.h"
#include "Simulator.h"
#include <sys\timeb.h>
#include "TraceWnd.h"
#include "Regvars.h"
#include "NumericEdit.h"
#include "InterruptMgt.h"
#include "SpinnerButton.h"
#include "register.h"
#include "RegData.h"
#include "RegDisplay.h"
#include "SimulatorDlg.h"
#include "err.h"
/****************************************************************************
* CSimulatorDlg::OnUpdateProbabilities
* Inputs:
* WPARAM: code indicating which probability to update
* LPARAM: new probability
* Result: LRESULT
* 0, always
* Effect:
* Stores the selected probability in its associated variable
****************************************************************************/
LRESULT CSimulatorDlg::OnUpdateProbabilities(WPARAM wParam, LPARAM lParam)
{
switch(wParam)
{ /* which one */
case PROB_ERR:
{
RegistryInt pErr(IDS_PROB_ERR);
ProbErr = lParam;
pErr.value = lParam;
pErr.store();
}
break;
case PROB_LOST:
{
RegistryInt pLost(IDS_PROB_LOST);
ProbLost = lParam;
pLost.value = lParam;
pLost.store();
}
break;
case PROB_SPURIOUS:
{
RegistryInt pSpurious(IDS_PROB_SPURIOUS);
ProbSpurious = lParam;
pSpurious.value = lParam;
pSpurious.store();
}
break;
case PROB_OVRUND:
{
RegistryInt pOvrUnd(IDS_PROB_OVR_UND);
ProbOvrUnd = lParam;
pOvrUnd.value = lParam;
pOvrUnd.store();
}
break;
} /* which one */
return 0;
}
/****************************************************************************
* CSimulatorDlg::injectErr
* Result: BOOL
* TRUE if an error should be injected
* FALSE for no error
* Notes:
* If error injection is disabled, this always returns FALSE
* If error injection is enabled, this will be based on the probability
* of error set by the configuration panel and stored in ProbErr
****************************************************************************/
BOOL CSimulatorDlg::injectErr()
{
return prob(c_Errors, ProbErr);
}
/****************************************************************************
* CSimulatorDlg::injectOvrUnd
* Result: BOOL
* TRUE if an OVR/UND error should be injected
* FALSE if not
* Notes:
*
****************************************************************************/
BOOL CSimulatorDlg::injectOvrUnd()
{
return prob(c_OverUnder, ProbOvrUnd);
}
/****************************************************************************
* CSimulatorDlg::prob
* Inputs:
* CButton & ctl: Control to be checked
* DWORD p: Probability value being an error (0..100)
* Result: BOOL
* TRUE if
* FALSE if
****************************************************************************/
BOOL CSimulatorDlg::prob(CButton & ctl, DWORD p)
{
if(ctl.GetCheck() == BST_UNCHECKED)
return FALSE;
if(p == 0)
return FALSE;
DWORD n = rand() % 100;
if(n < p)
return TRUE;
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -