📄 dfysimulator.cpp
字号:
{
MessageBox(NULL,"Failed to creat MemoryDlg","Error",MB_OK);
return;
}
pFrame->SetMemoryDlg(pMemoryDlg);//very important
pMemoryDlg->ShowWindow(SW_SHOW);
}
else
{
pMemoryDlg->DestroyWindow();
pFrame->SetMemoryDlg(NULL);//very important
}
pFrame->SetActiveWindow();//set the mainFrame activity
}
void CDFYSimulatorApp::OnViewRegister()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CRegisterDlg* pRegisterDlg=pFrame->GetRegisterDlg();
if(!pRegisterDlg)
{
pRegisterDlg=new CRegisterDlg();
if(!pRegisterDlg)
{
MessageBox(NULL,"not enough memory !","Fatal error !",MB_OK);
return;
}
if(!pRegisterDlg->Create(IDD_REGISTER,pFrame))
{
MessageBox(NULL,"failed to create registerDlg !","Error !",MB_OK);
return;
}
pFrame->SetRegisterDlg(pRegisterDlg);//very important
pRegisterDlg->ShowWindow(SW_SHOW);
pRegisterDlg->UpdateWindow();
}
else
{
pRegisterDlg->DestroyWindow();
pFrame->SetRegisterDlg(NULL);//very important
}
pFrame->SetActiveWindow();//set the mainFrame activity
}
void CDFYSimulatorApp::OnUpdateViewRegister(CCmdUI* pCmdUI)
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CRegisterDlg* pRegisterDlg=pFrame->GetRegisterDlg();
if(pRegisterDlg)
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CDFYSimulatorApp::OnViewStack()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CStackDlg* pStackDlg=(CStackDlg*)pFrame->GetStackDlg();
if(!pStackDlg)
{
pStackDlg=new CStackDlg();
if(!pStackDlg)
{
MessageBox(NULL,"not enough memory !","Fatal error !",MB_OK);
return;
}
if(!pStackDlg->Create(IDD_STACK,pFrame))
{
MessageBox(NULL,"failed to create StackDlg !","Error",MB_OK);
return;
}
pFrame->SetStackDlg(pStackDlg);//very important
pStackDlg->ShowWindow(SW_SHOW);
pStackDlg->UpdateWindow();
}
else
{
pStackDlg->DestroyWindow();
pFrame->SetStackDlg(NULL);//very important
}
pFrame->SetActiveWindow();//set the mainFrame activity
}
void CDFYSimulatorApp::OnUpdateViewStack(CCmdUI* pCmdUI)
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CStackDlg* pStackDlg=pFrame->GetStackDlg();
if(pStackDlg)
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CDFYSimulatorApp::OnViewVariable()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CVariableDlg* pVariableDlg=pFrame->GetVariableDlg();
if(!pVariableDlg)
{
pVariableDlg=new CVariableDlg();
if(!pVariableDlg)
{
MessageBox(NULL,"not enough memory !","Fatal error",MB_OK);
return;
}
if(!pVariableDlg->Create(IDD_VARIABLE,pFrame))
{
MessageBox(NULL,"failed to create variableDlg !","Error",MB_OK);
return;
}
pFrame->SetVariableDlg(pVariableDlg);//very important
//call this founction will set the
//mainFrame's m_pVariableDlg member data
pVariableDlg->ShowWindow(SW_SHOW);
pVariableDlg->UpdateWindow();
}
else
{
pVariableDlg->DestroyWindow();
pFrame->SetVariableDlg(NULL);//very important
}
pFrame->SetActiveWindow();
}
void CDFYSimulatorApp::OnUpdateViewVariable(CCmdUI* pCmdUI)
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CVariableDlg* pVariableDlg=pFrame->GetVariableDlg();
if(pVariableDlg)
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CDFYSimulatorApp::OnViewOutput()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
COutputWindow* pWndOutputWindow=pFrame->GetOutputWindow();
//First create OutputWindow
if(!pWndOutputWindow)
{
pWndOutputWindow=new COutputWindow();
if(!pWndOutputWindow)
{
MessageBox(NULL,"not enough memory !","Fatal Error !",MB_OK);
return;
}
CRect clientRect;
if(!pWndOutputWindow->Create(0,NULL,WS_CHILD|WS_DLGFRAME|WS_OVERLAPPED\
|WS_HSCROLL|WS_TABSTOP|WS_VSCROLL,clientRect,pFrame,\
NULL))
{
MessageBox(NULL,"Failed to create Output Window !","Error!",MB_OK);
return;
}
pFrame->GetClientRect(&clientRect);
pWndOutputWindow->SetWindowPos(NULL,clientRect.left,\
clientRect.bottom-160,clientRect.Width(),\
120,SWP_FRAMECHANGED|SWP_NOACTIVATE);
pFrame->SetOutputWindow(pWndOutputWindow);
pWndOutputWindow->ShowWindow(SW_SHOW);
pWndOutputWindow->UpdateWindow();
}
else
{
pWndOutputWindow->DestroyWindow();
pFrame->SetOutputWindow(NULL);
}
}
void CDFYSimulatorApp::OnUpdateViewOutput(CCmdUI* pCmdUI)
{
CMainFrame* pFrame=(CMainFrame*)GetMainWnd();
COutputWindow* pWndOutputWindow=pFrame->GetOutputWindow();
if(pWndOutputWindow)
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CDFYSimulatorApp::OnUpdateViewMemory(CCmdUI* pCmdUI)
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CMemoryDlg* pMemoryDlg=pFrame->GetMemoryDlg();
if(pMemoryDlg)
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CDFYSimulatorApp::LoadSimulator()
{
//show a initialize dialog
CInitDlg* initDlg=new CInitDlg();
initDlg->Create(IDD_SIMULATOR_INIT);
initDlg->ShowWindow(SW_SHOW);
initDlg->UpdateWindow();
//constructing simulator component
initDlg->SetState("constructing _cpu...");
_cpu=new CPU();
if(!_cpu)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing _cpu...");
return;
}
initDlg->SetProgressPos(10);
initDlg->SetState("constructing _memory...");
_memory=new Memory();
if(!_memory)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing _memory.");
return;
}
initDlg->SetProgressPos(20);
initDlg->SetState("constructing _busSystem.");
_busSystem=new BUSSystem();
if(!_busSystem)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing _busSystem.");
return;
}
initDlg->SetProgressPos(22);
DetermineBUS* pDetermineBUS=new DetermineBUS();
if(!pDetermineBUS)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing pDetermineBUS");
return;
}
initDlg->SetProgressPos(24);
BUSDetermine* pBUSDetermine=new BUSDetermine();
if(!pBUSDetermine)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing pBUSDetermine.");
return;
}
initDlg->SetProgressPos(26);
IOBUS* pIOBUS=new IOBUS();
if(!pIOBUS)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing pIOBUS.");
return;
}
initDlg->SetProgressPos(28);
AddrBUS* pAddrBUS=new AddrBUS();
if(!pAddrBUS)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing pAddrBUS");
return;
}
initDlg->SetProgressPos(30);
DataBUS* pDataBUS=new DataBUS();
if(!pDataBUS)
{
initDlg->SetWindowText("Error !");
initDlg->SetState("can't constructing pDataBUS");
return;
}
initDlg->SetProgressPos(32);
//initializing simulator
initDlg->SetState("loading instructions...");
_cpu->Initialize();
initDlg->SetProgressPos(60);
initDlg->SetState("allocing memory...");
UNSHORT uSegSize=65535;
_memory->SetSegSize(uSegSize);
initDlg->SetProgressPos(70);
initDlg->SetState("initializing BUS...");
_busSystem->SetAddrBUS(pAddrBUS);
initDlg->SetProgressPos(74);
_busSystem->SetIOBUS(pIOBUS);
initDlg->SetProgressPos(78);
_busSystem->SetDataBUS(pDataBUS);
initDlg->SetProgressPos(82);
_busSystem->SetDetermineBUS(pDetermineBUS);
initDlg->SetProgressPos(86);
_busSystem->SetBUSDetermine(pBUSDetermine);
initDlg->SetProgressPos(90);
//connecting...
initDlg->SetState("attach _cpu to _busSystem");
_busSystem->AttachToCPU(_cpu);
initDlg->SetProgressPos(94);
initDlg->SetState("attach _memory to _busSystem");
_busSystem->AttachToMemory(_memory);
initDlg->SetProgressPos(100);
initDlg->SetWindowText("OK...");
initDlg->SetState("DFYSimulator succeed loaded.");
}
void CDFYSimulatorApp::UninstallSimulator()
{
if(_cpu)delete _cpu;
if(_memory)delete _memory;
if(_busSystem)delete _busSystem;
if(_deviceInterface)delete _deviceInterface;
}
int CDFYSimulatorApp::GetSimulatorSpeed()
{
return m_iSimulatorSpeed;
}
void CDFYSimulatorApp::SetCurFileName(char* strFileName)
{
if(!strFileName)
{
m_strCurFileName=NULL;
return;
}
int nFileSize=strlen(strFileName);
m_strCurFileName=new char[nFileSize+1];
strcpy(m_strCurFileName,strFileName);
}
char* CDFYSimulatorApp::GetCurFileName()
{
return m_strCurFileName;
}
void CDFYSimulatorApp::OnDevice8259()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CIRQDlg* pIRQDlg=pFrame->GetIRQDlg();
if(!pIRQDlg)
{
pIRQDlg=new CIRQDlg();
if(!pIRQDlg)
{
MessageBox(NULL,"not enough memory !","Fatal error !",MB_OK);
return;
}
if(!pIRQDlg->Create(IDD_IRQ,pFrame))
{
MessageBox(NULL,"Failed to creat IRQDlg","Error",MB_OK);
return;
}
pFrame->SetIRQDlg(pIRQDlg);//very important
pIRQDlg->ShowWindow(SW_SHOW);
}
else
{
pIRQDlg->DestroyWindow();
pFrame->SetIRQDlg(NULL);//very important
}
pFrame->SetActiveWindow();//set the mainFrame activity
}
void CDFYSimulatorApp::OnUpdateDevice8259(CCmdUI* pCmdUI)
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CIRQDlg* pIRQDlg=pFrame->GetIRQDlg();
if(pIRQDlg)
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CDFYSimulatorApp::OnComponentCpu()
{
CCPUDlg cpuDlg;
cpuDlg.m_iIntMask=m_iIntMask;
cpuDlg.m_bStep=m_bStep;
cpuDlg.m_bOpenINT=m_bOpenINT;
int i=cpuDlg.DoModal();
if(i==IDOK)
{
m_iIntMask=cpuDlg.m_iIntMask;
m_bStep=cpuDlg.m_bStep;
m_bOpenINT=cpuDlg.m_bOpenINT;
if(_cpu)
{
WORD wFlag=_cpu->GetFLAGS();
if(m_bStep)
{
wFlag=wFlag | 0X0010;
_cpu->SetFLAGS(wFlag);
}
else
{
wFlag=wFlag & 0XFFEF;
_cpu->SetFLAGS(wFlag);
}
if(m_bOpenINT)
{
wFlag=wFlag | 0X0008;
_cpu->SetFLAGS(wFlag);
}
else
{
wFlag=wFlag & 0XFFF7;
_cpu->SetFLAGS(wFlag);
}
_cpu->SetIRQMask((BYTE)m_iIntMask);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -