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

📄 dfysimulator.cpp

📁 这个也是我们的毕业设计课题
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DFYSimulator.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "DFYSimulator.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "DFYSimulatorDoc.h"
#include "DFYSimulatorView.h"

#include "ExecuteChildFrame.h"
#include "ExecuteDocument.h"
#include "ExecuteView.h"

#include "DebugChildFrame.h"
#include "DebugDocument.h"
#include "DebugView.h"
#include "DFYSimulator_i.c"

#include "ProcessorDlg.h"
#include "SimulatorSpeed.h"
#include "OutputWindow.h"
#include "MemoryDlg.h"
#include "StackDlg.h"
#include "VariableDlg.h"
#include "RegisterDlg.h"
#include "InitDlg.h"
#include "DFY\IRQDlg.h"
#include "CPUDlg.h"

#include "DFY\MemorySegment.h"
#include "DFY\CPU.h"
#include "DFY\DeviceInterface.h"
#include "DFY\BUSSystem.h"
#include "DFY\Instruction.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDFYSimulatorApp

BEGIN_MESSAGE_MAP(CDFYSimulatorApp, CWinApp)
	//{{AFX_MSG_MAP(CDFYSimulatorApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_MODE_EXECUTE, OnModeExecute)
	ON_COMMAND(ID_MODE_DEBUG, OnModeDebug)
	ON_COMMAND(ID_MODE_PROCESSOR, OnModeProcessor)
	ON_COMMAND(ID_MODE_SPEED, OnModeSpeed)
	ON_COMMAND(ID_DEBUG_MEMORY, OnViewMemory)
	ON_COMMAND(ID_DEBUG_REGISTER, OnViewRegister)
	ON_UPDATE_COMMAND_UI(ID_DEBUG_REGISTER, OnUpdateViewRegister)
	ON_COMMAND(ID_DEBUG_STACK, OnViewStack)
	ON_UPDATE_COMMAND_UI(ID_DEBUG_STACK, OnUpdateViewStack)
	ON_COMMAND(ID_DEBUG_VARIABLE, OnViewVariable)
	ON_UPDATE_COMMAND_UI(ID_DEBUG_VARIABLE, OnUpdateViewVariable)
	ON_COMMAND(ID_VIEW_OUTPUT, OnViewOutput)
	ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT, OnUpdateViewOutput)
	ON_UPDATE_COMMAND_UI(ID_DEBUG_MEMORY, OnUpdateViewMemory)
	ON_COMMAND(ID_DEVICE_8259, OnDevice8259)
	ON_UPDATE_COMMAND_UI(ID_DEVICE_8259, OnUpdateDevice8259)
	ON_COMMAND(ID_COMPONENT_CPU, OnComponentCpu)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDFYSimulatorApp construction

CDFYSimulatorApp::CDFYSimulatorApp()
{
	m_bExeFrameExist=FALSE;
	m_bDebugFrameExist=FALSE;
	_cpu=NULL;
	_memory=NULL;
	_busSystem=NULL;
	_deviceInterface=NULL;
	m_iSimulatorSpeed=5;
	m_strCurFileName=NULL;//initialize the cur file name to NULL
	m_iIntMask=0;
	m_bStep=FALSE;
	m_bOpenINT=FALSE;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CDFYSimulatorApp object

CDFYSimulatorApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CDFYSimulatorApp initialization

BOOL CDFYSimulatorApp::InitInstance()
{

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_DFYSIMTYPE,
		RUNTIME_CLASS(CDFYSimulatorDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CDFYSimulatorView));
	//excute doctemplate
	CMultiDocTemplate* pExecuteTemplate;
	pExecuteTemplate = new CMultiDocTemplate(
		IDR_EXECUTETYPE,
		RUNTIME_CLASS(CExecuteDocument),
		RUNTIME_CLASS(CExecuteChildFrame),
		RUNTIME_CLASS(CExecuteView));
	//debug doctemplate
	CMultiDocTemplate* pDebugTemplate;
	pDebugTemplate = new CMultiDocTemplate(
		IDR_DEBUGTYPE,
		RUNTIME_CLASS(CDebugDocument),
		RUNTIME_CLASS(CDebugChildFrame),
		RUNTIME_CLASS(CDebugView));
	//add doctemplate to doctemplate list
	AddDocTemplate(pDocTemplate);//first
	AddDocTemplate(pExecuteTemplate);//second
	AddDocTemplate(pDebugTemplate);//third
	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		return TRUE;
	}



	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();
	pMainFrame->DragAcceptFiles();
	EnableShellOpen();
	RegisterShellFileTypes();
	LoadSimulator();//load simulator to appliction
	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CDFYSimulatorApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CDFYSimulatorApp message handlers




void CDFYSimulatorApp::OnFileOpen() 
{
	LPCTSTR lpszDefExt="asm";
	LPCTSTR lpszFileName=NULL;
	DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	LPCTSTR lpszFilter="Assemble file (.asm)|*.asm|excutable file(.DFYexe)|*.DFYexe|Program data file (.pdf)|*.pdf|";
	CWnd* pParentWnd=NULL;
	CFileDialog fileDlg(TRUE,lpszDefExt,lpszFileName,dwFlags\
						,lpszFilter,pParentWnd);
	fileDlg.DoModal();
	CString strFilePathName;
	strFilePathName=fileDlg.GetPathName();
	
	if(!strFilePathName.IsEmpty())
	{
		CString strFileExt=fileDlg.GetFileExt();
		POSITION templatePos=GetFirstDocTemplatePosition();
		if(strFileExt=="asm")
		{
			//test if the file already open
			CMultiDocTemplate* pDocTemplate=(CMultiDocTemplate*)\
										GetNextDocTemplate(templatePos);
			POSITION docPos=pDocTemplate->GetFirstDocPosition();
			CString openFilePathName;
			while(docPos)
			{
				CDFYSimulatorDoc* pDFYSimulatorDoc=\
				(CDFYSimulatorDoc*)pDocTemplate->GetNextDoc(docPos);
				openFilePathName=pDFYSimulatorDoc->GetPathName();
				if(strFilePathName==openFilePathName)
					return;//if file already open , do nothing
			}
			//if the file not open ,creat a frame for it
			CDFYSimulatorDoc* pDFYSimulatorDoc=\
			(CDFYSimulatorDoc*)pDocTemplate->CreateNewDocument();
			CChildFrame* pChildFrame=(CChildFrame*)\
			pDocTemplate->CreateNewFrame(pDFYSimulatorDoc,NULL);
			//save the open file name to document
			pDFYSimulatorDoc->SetPathName(strFilePathName,TRUE);
			CString strFileTitle=fileDlg.GetFileName();
			//set window title
			//call the document's OnOpenDocument
			pDFYSimulatorDoc->OnOpenDocument(strFilePathName);
			pChildFrame->SetTitle(strFileTitle);
			pChildFrame->ShowWindow(SW_SHOW);
			pChildFrame->UpdateWindow();
			//make the child frame activity
			pChildFrame->ActivateFrame();

		}
		else if(strFileExt=="DFYexe")
		{
				
		}
	
	}
}
int CDFYSimulatorApp::ExitInstance()
{
	UninstallSimulator();
	return 0;
}

void CDFYSimulatorApp::OnModeExecute() 
{
	//the ExecuteDocTemplate is the second 
	//doctemplate in the App's doctemplate list
	
	//only one excute frame can exist any time
	POSITION templatePos=GetFirstDocTemplatePosition();
	GetNextDocTemplate(templatePos);//the pos will pointer to the next view position
	CMultiDocTemplate* pExecuteTemplate=(CMultiDocTemplate*)\
		GetNextDocTemplate(templatePos);
	CExecuteDocument*pExecuteDoc=NULL;
	if(!m_bExeFrameExist)//will create the Execute frame
	{
		pExecuteDoc=(CExecuteDocument*)\
		pExecuteTemplate->CreateNewDocument();
		CExecuteChildFrame*pChildFrame=(CExecuteChildFrame*)\
		pExecuteTemplate->CreateNewFrame(pExecuteDoc,NULL);
		CRect rect;
		pChildFrame->GetMDIFrame()->GetClientRect(&rect);
		pChildFrame->SetWindowPos(NULL,0,0,rect.Width(),rect.Height()-160,\
			SWP_FRAMECHANGED);
		pChildFrame->ShowWindow(SW_SHOW);
		pChildFrame->UpdateWindow();
		pChildFrame->ActivateFrame();
		m_bExeFrameExist=TRUE;//very important
	}
	else
	{
		//set the exist execute frame activity
		POSITION docPos=pExecuteTemplate->GetFirstDocPosition();
		pExecuteDoc=(CExecuteDocument*)pExecuteTemplate->GetNextDoc(docPos);
		POSITION viewPos=pExecuteDoc->GetFirstViewPosition();
		CExecuteView* pExeView=(CExecuteView*)pExecuteDoc->GetNextView(viewPos);
		CExecuteChildFrame* pExeChildFrame=(CExecuteChildFrame*)\
			pExeView->GetParentFrame();
		pExeChildFrame->ActivateFrame();
	
	}
}

void CDFYSimulatorApp::OnModeDebug() 
{
	//debug doctemplate is the first one in
	//the App's doctemplate list
	POSITION templatePos=GetFirstDocTemplatePosition();
	GetNextDocTemplate(templatePos);//first
	GetNextDocTemplate(templatePos);//second
	CMultiDocTemplate* pDebugTemplate=(CMultiDocTemplate*)\
		GetNextDocTemplate(templatePos);
	CDebugDocument* pDebugDoc = NULL;
	if(!m_bDebugFrameExist)
	{
		pDebugDoc =(CDebugDocument*)pDebugTemplate->\
			CreateNewDocument();
		CDebugChildFrame* pChildFrame=(CDebugChildFrame*)\
			pDebugTemplate->CreateNewFrame(pDebugDoc,NULL);
		CRect rect;
		pChildFrame->GetMDIFrame()->GetClientRect(&rect);
		pChildFrame->SetWindowPos(NULL,0,0,rect.Width(),rect.Height()-160,SWP_FRAMECHANGED);
		pChildFrame->ShowWindow(SW_SHOW);
		pChildFrame->UpdateWindow();
		pChildFrame->ActivateFrame();
		m_bDebugFrameExist=TRUE;//very important
	}
	else
	{
		//set the exist execute frame activity
		POSITION docPos=pDebugTemplate->GetFirstDocPosition();
		pDebugDoc=(CDebugDocument*)pDebugTemplate->GetNextDoc(docPos);
		POSITION viewPos=pDebugDoc->GetFirstViewPosition();
		CDebugView* pDebugView=(CDebugView*)pDebugDoc->GetNextView(viewPos);
		CDebugChildFrame* pDebugChildFrame=(CDebugChildFrame*)\
		pDebugView->GetParentFrame();
		pDebugChildFrame->ActivateFrame();
	}
}


void CDFYSimulatorApp::OnModeProcessor() 
{
	CProcessorDlg processorDlg(NULL);
	int i=processorDlg.DoModal();
	if(i=IDOK)
	{
	}
	else
	{
	}
	
}

void CDFYSimulatorApp::OnModeSpeed() 
{
	CSimulatorSpeed speedDlg(NULL);//CProcessSpeed is a dialog class
	int i=speedDlg.DoModal();
	if(i==IDOK)
	{
		m_iSimulatorSpeed=speedDlg.GetSpeed();
	}

}

void CDFYSimulatorApp::OnViewMemory() 
{
	CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
	CMemoryDlg* pMemoryDlg=pFrame->GetMemoryDlg();
	if(!pMemoryDlg)
	{
		pMemoryDlg=new CMemoryDlg();
		if(!pMemoryDlg)
		{
			MessageBox(NULL,"not enough memory !","Fatal error !",MB_OK);
			return;
		}
		if(!pMemoryDlg->Create(IDD_MEMORY,pFrame))

⌨️ 快捷键说明

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