📄 bussystem.cpp
字号:
#include "stdafx.h"
#include "DFYSimulator.h"
#include "BUSSystem.h"
#include "MainFrm.h"
#include "OutputWindow.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include "CPU.H"
#include "MemorySegment.h"
#include "DeviceInterface.h"
//class IOBUS implementing
void IOBUS::SetIOWrite(BOOL bIOState)
{
if(_memory)
_memory->SetIOWrite(bIOState);
if(_deviceInterface)
_deviceInterface->SetIOWrite(bIOState);
}
void IOBUS::SetIORead(BOOL bIOState)
{
if(_memory)
_memory->SetIORead(bIOState);
if(_deviceInterface)
_deviceInterface->SetIORead(bIOState);
}
//class BUSDetermine implementing
//the following is the default implementing of BUSDtermine::Determine
//the device prior level in requesting BUS is equal
BOOL BUSDetermine::Determine()
{
if(!_determineBUS)//if no DetermineBUS attach to the BUSDetermine
{
ReportState("no DetermineBUS attach to the BUSDetermine");
return FALSE;
}
if(!(_determineBUS->m_nBS))//if no device occupy the BUS
{
_determineBUS->m_nBS=TRUE;
return TRUE;
}
return FALSE;
}
//BUSSystem implementing
//construction implementing
BUSSystem::BUSSystem()
{
_cpu=NULL;
_memory=NULL;
_deviceInterface=NULL;
m_lpDetermineBUS=NULL;
m_lpBUSDetermine=NULL;
m_lpIOBUS=NULL;
m_lpAddrBUS=NULL;
m_lpDataBUS=NULL;
}
//destruction implementing
BUSSystem::~BUSSystem()
{
if(m_lpDetermineBUS)delete m_lpDetermineBUS;
if(m_lpBUSDetermine)delete m_lpBUSDetermine;
if(m_lpIOBUS)delete m_lpIOBUS;
if(m_lpAddrBUS)delete m_lpAddrBUS;
if(m_lpDataBUS)delete m_lpDataBUS;
if(_cpu)DetachFromCPU();
if(_memory)DetachFromMemory();
if(_deviceInterface)DetachFromDevice();
}
//attribute
void BUSSystem::SetAddrBUS(AddrBUS* lpAddrBUS)
{
m_lpAddrBUS=lpAddrBUS;
}
void BUSSystem::SetBUSDetermine(BUSDetermine* lpBUSDetermine)
{
m_lpBUSDetermine=lpBUSDetermine;
if(m_lpDetermineBUS)
{
m_lpBUSDetermine->AttachToDetermineBUS(m_lpDetermineBUS);
}
}
void BUSSystem::SetDataBUS(DataBUS* lpDataBUS)
{
m_lpDataBUS=lpDataBUS;
}
void BUSSystem::SetDetermineBUS(DetermineBUS* lpDetermineBUS)
{
m_lpDetermineBUS=lpDetermineBUS;
if(m_lpBUSDetermine)
{
m_lpBUSDetermine->AttachToDetermineBUS(m_lpDetermineBUS);
}
}
void BUSSystem::SetIOBUS(IOBUS* lpIOBUS)
{
m_lpIOBUS=lpIOBUS;
}
AddrBUS* BUSSystem::GetAddrBUS()
{
return m_lpAddrBUS;
}
DataBUS* BUSSystem::GetDataBUS()
{
return m_lpDataBUS;
}
DetermineBUS* BUSSystem::GetDetermineBUS()
{
return m_lpDetermineBUS;
}
BUSDetermine* BUSSystem::GetBUSDetermine()
{
return m_lpBUSDetermine;
}
IOBUS* BUSSystem::GetIOBUS()
{
return m_lpIOBUS;
}
//operation
void BUSSystem::SetBS(BOOL bState)
{
if(m_lpDetermineBUS)
{
m_lpDetermineBUS->SetBS(bState);
return;
}
else
{
ReportState("the BUSSystem can't find the DetermineBUS");
return;
}
}
void BUSSystem::SetIORead(BOOL bState)
{
if(m_lpIOBUS)
{
m_lpIOBUS->SetIORead(bState);
return;
}
else
{
ReportState("the BUSSystem can't find the IOBUS");
return;
}
}
void BUSSystem::SetIOWrite(BOOL bState)
{
if(m_lpIOBUS)
{
m_lpIOBUS->SetIOWrite(bState);
return;
}
else
{
ReportState("the BUSSystem can't find the IOBUS");
return;
}
}
BOOL BUSSystem::Determine()
{
if(m_lpBUSDetermine)
{
return m_lpBUSDetermine->Determine();
}
else
{
ReportState("the BUSSystem can't find BUSDetermine, please attach it to a BUSDetermine and try again");
return FALSE;
}
}
void BUSSystem::ReadAddrFromAddrBUS(UNSHORT& uAddr)
{
uAddr=0;
if(m_lpAddrBUS)
{
m_lpAddrBUS->ReadAddr(uAddr);
}
else
{
ReportState("the BUSSystem can't find AddrBUS");
return;
}
}
void BUSSystem::WriteAddrToAddrBUS(UNSHORT& uAddr)
{
if(m_lpAddrBUS)
{
m_lpAddrBUS->WriteAddr(uAddr);
return;
}
else
{
ReportState("the BUSSystem can't find AddrBUS");
return;
}
}
void BUSSystem::ReadDataFromDataBUS(WORD& wData)
{
wData=0;
if(m_lpDataBUS)
{
m_lpDataBUS->ReadData(wData);
return;
}
else
{
ReportState("the BUSSystem can't find the DataBUS");
return;
}
}
void BUSSystem::WriteDataToDataBUS(WORD& wData)
{
if(m_lpDataBUS)
{
m_lpDataBUS->WriteData(wData);
return;
}
else
{
ReportState("the BUSSystem can't find the DataBUS");
return;
}
}
void BUSSystem::AccessMemory()
{
if(_memory)
{
_memory->AccessMemory();
return;
}
else
{
ReportState("the BUSSystem can't find the memory");
return;
}
}
void BUSSystem::AccessDevicePort()
{
if(_deviceInterface)
{
_deviceInterface->AccessDevice();
return;
}
else
{
ReportState("the BUSSystem can't find the deviceInerface");
return;
}
}
//Attach operation
void BUSSystem::AttachToMemory(Memory* lpMemory)
{
if(!_memory)
{
_memory=lpMemory;
_memory->SetBUSSystem(this);
if(m_lpIOBUS)
m_lpIOBUS->SetMemory(_memory);
else
ReportState("The IOBUS not exist, you can't attach it to a memory");
}
else
{
ReportState("The BUSSystem is already attach to a Memory,please call DetachFromCPU() first if you want attach it to an other Memory");
}
}
void BUSSystem::AttachToDevice(DeviceInterface* lpDeviceInterface)
{
if(!_deviceInterface)
{
_deviceInterface=lpDeviceInterface;
_deviceInterface->SetBUSSystem(this);
if(m_lpIOBUS)
m_lpIOBUS->SetDeviceInterface(lpDeviceInterface);
else
ReportState("The IOBUS not exist, you can't attach it to a deviceInterface");
}
else
{
ReportState("The BUSSystem is already attach to a Device,please call DetachFromDevice() first if you want attach it to an other Device");
}
}
void BUSSystem::DetachFromMemory()
{
if(_memory)
_memory->SetBUSSystem(NULL);
_memory=NULL;
if(m_lpIOBUS)
m_lpIOBUS->SetMemory(NULL);
}
void BUSSystem::DetachFromDevice()
{
if(_deviceInterface)
_deviceInterface->SetBUSSystem(NULL);
_deviceInterface=NULL;
if(m_lpIOBUS)
m_lpIOBUS->SetDeviceInterface(NULL);
}
void BUSSystem::AttachToCPU(CPU* lpCPU)
{
if(!_cpu)
{
_cpu=lpCPU;
_cpu->SetBUSSystem(this);
}
else
{
ReportState("The BUSSystem is already attach toa CPU,please call DetachFromCPU() first if you want attach it to an other CPU");
}
}
void BUSSystem::DetachFromCPU()
{
if(_cpu)
_cpu->SetBUSSystem(NULL);
_cpu=NULL;
}
void BUSDetermine::ReportState(CString strState)
{
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
COutputWindow* pOutputWindow=(COutputWindow*)pMainFrame->GetOutputWindow();
if(pOutputWindow)
{
pOutputWindow->ShowState(strState);
}
}
void BUSSystem::ReportState(CString strState)
{
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
COutputWindow* pOutputWindow=(COutputWindow*)pMainFrame->GetOutputWindow();
if(pOutputWindow)
{
pOutputWindow->ShowState(strState);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -