📄 mgt.cpp
字号:
/*****************************************************************************
* Change Log
* Date | Change
*-----------+-----------------------------------------------------------------
* 21-Mar-99 | Created change log
* 21-Mar-99 | The RST check box does not appear unless the V2 conditional is
* | defined
* 21-Mar-99 | Added RST processing
*****************************************************************************/
// mgt.cpp: functions associated solely with window management or process
// management
#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 "buzzword.h"
#include "SetupDlg.h"
#include "About.h"
#include "uwm.h"
#include "format.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL CSimulatorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
time_t t;
time(&t);
srand(t);
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
#ifdef _MAC
// On the Macintosh, the "About..." menu item is already there. We
// just need to rename it and attach it to the about command.
pSysMenu->ModifyMenu(0, MF_BYPOSITION, IDM_ABOUTBOX, strAboutMenu);
#else
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
#endif
}
// 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
// Open the simulator device
if(!registers.Open())
{ /* failed */
PostMessage(UWM_OPEN_FAILED, 0, GetLastError()); // tell that it failed
} /* failed */
// Create an event for the manual/freerun state
freerun = ::CreateEvent(
NULL, // ignore security
TRUE, // manual-reset
FALSE, // initially reset
NULL); // Anonymouse
stop = ::CreateEvent(
NULL, // ignore security
TRUE, // manual-reset
TRUE, // initially set
NULL); // Anonymous
pause = ::CreateEvent(
NULL, // ignore security
TRUE, // manual-reset
FALSE, // initially reset
NULL); // Anonymous
c_Manual.SetCheck(BST_CHECKED); // indicate manual run
manual = TRUE;
singleStep = FALSE;
// Note that the freerun event *must* be created before the
// thread is started
#ifndef _V2_
c_RSTIn.ShowWindow(SW_HIDE);
c_RSTOut.ShowWindow(SW_HIDE);
#endif
mainWnd = m_hWnd; // for cross-thread sendMessage calls
TimeStamp ts(TRUE);
c_Trace.setTimeBase(ts.getMS());
pollthread = AfxBeginThread(watcher, (LPVOID)this);
if(pollthread != NULL)
{ /* started */
TraceItem * item = new TraceItem(TRACE_TYPE_THREAD, _T("Status Register Watcher started"));
c_Trace.AddString(item);
} /* started */
RegistryInt regIRQ(IDS_IRQ);
regIRQ.load(-1);
irq = regIRQ.value;
RegistryInt interval(IDS_POLLING_INTERVAL);
interval.load(50);
pollInterval = interval.value;
RegistryInt minimum(IDS_GODONEMIN);
minimum.load(GoDoneMinimum); // use current value as default
GoDoneMinimum = minimum.value;
RegistryInt variance(IDS_GODONEVAR);
variance.load(GoDoneVariance); // use current value as default
GoDoneVariance = variance.value;
RegistryInt pErr(IDS_PROB_ERR);
pErr.load(ProbErr);
ProbErr = pErr.value;
RegistryInt pOvrUnd(IDS_PROB_OVR_UND);
pOvrUnd.load(ProbOvrUnd);
ProbOvrUnd = pOvrUnd.value;
RegistryInt pLost(IDS_PROB_LOST);
pLost.load(ProbLost);
ProbLost = pLost.value;
RegistryInt pSpurious(IDS_PROB_SPURIOUS);
pSpurious.load(ProbSpurious);
ProbSpurious = pSpurious.value;
OpenRegisterTransaction(_T("OnInitDialog"));
updateControls();
CloseRegisterTransaction(_T("OnInitDialog"));
return TRUE; // return TRUE unless you set the focus to a control
}
/****************************************************************************
* CSimulatorDlg::updateControls
* Inputs:
* BOOL valid: TRUE (default) if register set is valid
* FALSE if register set is not valid
* Result: void
*
* Effect:
* Updates all controls
****************************************************************************/
void CSimulatorDlg::updateControls(BOOL valid /* = TRUE */)
{
BOOL isManual = c_Manual.GetCheck() == BST_CHECKED;
c_GoHackIn.ShowWindow(isManual ? SW_HIDE : SW_SHOW);
c_GoHackOut.ShowWindow(isManual ? SW_HIDE : SW_SHOW);
//----------------------------------------------------------------------
// The Send button is enabled if
// We are in freerun mode, the data string is nonempty, and
// the data buffer is empty
// We are in manual mode, and
// the data string is nonempty and the data buffer is empty
// the data buffer is nonempty
BOOL enable =
(c_FreeRun.GetCheck() &&
c_Data.GetWindowTextLength() > 0 &&
c_Transfer.GetWindowTextLength() == 0) ||
(c_Manual.GetCheck() &&
((c_Data.GetWindowTextLength() > 0 &&
c_Transfer.GetWindowTextLength() == 0) ||
(c_Transfer.GetWindowTextLength() > 0)));
CString sendCaption;
sendCaption.LoadString((c_FreeRun.GetCheck() ||
(c_Manual.GetCheck() &&
c_Transfer.GetWindowTextLength() == 0))
? IDS_SEND
: IDS_SEND_NEXT);
CString currentCaption;
c_Send.GetWindowText(currentCaption);
c_Send.EnableWindow(enable);
if(sendCaption != currentCaption)
c_Send.SetWindowText(sendCaption);
//----------------------------------------------------------------------
c_Int.EnableWindow(c_Manual.GetCheck() == BST_CHECKED);
//----------------------------------------------------------------------
// IN CONTROLS
//----------------------------------------------------------------------
c_DoneIn.EnableWindow(c_Manual.GetCheck() == BST_CHECKED &&
c_DoneIn.GetCheck() == BST_UNCHECKED);
// if(valid)
// { /* use registers */
// BYTE command = registers.get(REGISTER_IN_COMMAND);
//
// c_GoIn.EnableWindow(isManual && (command & REGISTER_IN_COMMAND_GO) == 0);
// } /* use registers */
c_GoIn.EnableWindow(isManual);
c_IEIn.EnableWindow(isManual);
c_IACKIn.EnableWindow(isManual);
c_ErrIn.EnableWindow(isManual);
c_OvrIn.EnableWindow(isManual);
c_EopIn.EnableWindow(isManual);
c_IntIn.EnableWindow(isManual);
c_DoneIn.EnableWindow(isManual);
//----------------------------------------------------------------------
// OUT CONTROLS
//----------------------------------------------------------------------
// if(valid)
// { /* update GO */
// BYTE command = registers.get(REGISTER_OUT_COMMAND);
// c_GoOut.EnableWindow(isManual && (command & REGISTER_OUT_COMMAND_GO) != 0);
// } /* update GO */
c_GoOut.EnableWindow(isManual);
c_IEOut.EnableWindow(isManual);
c_IACKOut.EnableWindow(isManual);
c_ErrOut.EnableWindow(isManual);
c_UndOut.EnableWindow(isManual);
c_BusyOut.EnableWindow(isManual);
c_IntOut.EnableWindow(isManual);
c_DoneOut.EnableWindow(isManual);
c_GetState.EnableWindow(isManual);
c_SingleStep.EnableWindow(isManual);
}
/****************************************************************************
* CSimulatorDlg::OnSysCommand
* Inputs:
* UINT nID: ID of command
* LPARAM lParam: passed on to superclass
* Result: void
*
* Effect:
* Handles system command messages (for About box etc.)
****************************************************************************/
void CSimulatorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
doAbout();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
/****************************************************************************
* CSimulatorDlg::OnDestroy
* Result: void
*
* Effect:
* Closes the open simulator device, closes down help
****************************************************************************/
void CSimulatorDlg::OnDestroy()
{
registers.Close();
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
}
// 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 CSimulatorDlg::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 CSimulatorDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSimulatorDlg::OnCancel()
{
shutdown();
CDialog::OnCancel();
}
void CSimulatorDlg::OnOK()
{
shutdown();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -