⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poll.cpp

📁 通过VC源代码
💻 CPP
字号:
#include "stdafx.h"
#include "Simulator.h"
#include <sys\timeb.h>
#include "TraceWnd.h"
#include "RegVars.h"
#include "SpinnerButton.h"
#include "Register.h"
#include "RegData.h"
  #include "RegDisplay.h"
    #include "SimulatorDlg.h"
#include "uwm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/****************************************************************************
*                           CSimulatorDlg::watcher
* Inputs:
*       LPVOID me: (LPVOID)(CSimulatorDlg *)
* Result: UINT
*       0, always
* Effect: 
*       Top-level (static) thread function
****************************************************************************/

UINT CSimulatorDlg::watcher(LPVOID me)
    {
     ((CSimulatorDlg *)me)->poll();
     return 0;
    }

/****************************************************************************
*                         CSimulatorDlg::startPollingCycle
* Result: void
*       
* Effect: 
*       Sets the interlock to start polling
****************************************************************************/

void CSimulatorDlg::startPollingCycle()
    {
     OpenRegisterTransaction(_T("PollingCycle"));
    }

/****************************************************************************
*			CSimulatorDlg::endPollingCycle
* Result: void
*       
* Effect: 
*       Releases the spin lock
****************************************************************************/

void CSimulatorDlg::endPollingCycle()
    {
     CloseRegisterTransaction(_T("PollingCycle"));
    }

/****************************************************************************
*                          CSimulatorDlg::pollInput
* Result: void
*       
* Effect: 
*       If the GO bit is set, initiate the actions that will implement
*	the transfer of a byte to the simulated device's input
****************************************************************************/

#if 0
void CSimulatorDlg::pollInput()
    {
     BYTE command = registers.get(REGISTER_IN_COMMAND);
     // Compare to the previous state

     if( (command ^ CommandIn) & REGISTER_IN_COMMAND_GO)
        { /* Go bit set */
	 CommandIn = command;  // store current state

	 // Note this is an interthread SendMessage, so we don't resume
	 // this thread until it completes
	 ::SendMessage(mainWnd, UWM_GO_IN_SET, 0, 0);
	} /* Go bit set */

     if((command ^ CommandIn) & REGISTER_IN_COMMAND_IE)
        { /* IE bit set */
	 CommandIn = command; // Store current state
	 
	 // Note this is an interthread SendMessage, so we don't resume
	 // this thread until it completes
	 ::SendMessage(mainWnd, UWM_IE_IN_SET, 0, 0);
	} /* IE bit set */

     if((command ^ CommandIn) & REGISTER_IN_COMMAND_IACK)
        { /* IACK bit set */
	 CommandIn = command; // store current state

	 // Note this is an interthread SendMessage, so we don't resume
	 // this thread until it completes
	 ::SendMessage(mainWnd, UWM_IACK_IN_SET, 0, 0);
	} /* IACK bit set */

     if((command ^ CommandIn) & REGISTER_IN_COMMAND_RST)
	{ /* RST bit set */
	 CommandIn = command;
	 ::SendMessage(mainWnd, UWM_RST_IN_SET, 0, 0);
	} /* RST bit set */

    }
#endif

/****************************************************************************
*                          CSimulatorDlg::pollOutput
* Result: void
*       
* Effect: 
*       If the GO bit is set for the output side, accept the byte from the
*	device
****************************************************************************/

#if 0
void CSimulatorDlg::pollOutput()
    {
     BYTE command = registers.get(REGISTER_OUT_COMMAND);

     if(command & REGISTER_OUT_COMMAND_GO)
        { /* Go bit set */
	 // Note this is an interthread SendMessage, but we don't resume
	 // this thread until it completes
	 ::SendMessage(mainWnd, UWM_GO_OUT_SET, 0, 0);
	} /* Go bit set */

     if((command ^ CommandOut) & REGISTER_OUT_COMMAND_IE)
        { /* IE bit set */
	 CommandOut = command; // Store current state
	 
	 // Note this is an interthread SendMessage, so we don't resume
	 // this thread until it completes
	 ::SendMessage(mainWnd, UWM_IE_OUT_SET, 0, 0);
	} /* IE bit set */

     if((command ^ CommandOut) & REGISTER_OUT_COMMAND_IACK)
        { /* IACK bit set */
	 CommandOut = command; // store current state

	 // Note this is an interthread SendMessage, so we don't resume
	 // this thread until it completes
	 ::SendMessage(mainWnd, UWM_IACK_OUT_SET, 0, 0);
	} /* IACK bit set */

     if((command ^ CommandOut) & REGISTER_OUT_COMMAND_RST)
	{ /* RST bit set */
	 CommandOut = command;
	 ::SendMessage(mainWnd, UWM_RST_OUT_SET, 0, 0);
	} /* RST bit set */
    }
#endif

/****************************************************************************
*                             CSimulatorDlg::poll
* Result: void
*       
* Effect: 
*       Polls status
* Notes:
*	This is running as a separate thread, and thus CWnd-derived
*	objects have no meaning
****************************************************************************/

void CSimulatorDlg::poll()
    {
     polling = TRUE;

     while(polling)
        { /* polling */
	 WaitForSingleObject(freerun, INFINITE); // don't freerun unless released
	 ::ResetEvent(stop);

	 if(!singleStep)
	    Sleep(pollInterval);

	 if(!polling)
	    break;   // in case application was shut down while sleeping

	 ::PostMessage(mainWnd, UWM_PULSE, 0, 0);

	 ::ResetEvent(pause);
	     
	 ::PostMessage(mainWnd, UWM_POLL, 0, 0);
	 ::WaitForSingleObject(pause, INFINITE);

	 ::SetEvent(stop); // user may now stop
	 if(singleStep)
	    { /* end single step */
	     ::PostMessage(mainWnd, UWM_SET_MANUAL_MODE, TRUE, 0);
	    } /* end single step */
	} /* polling */
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -