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

📄 bussystem.h

📁 这个也是我们的毕业设计课题
💻 H
字号:
//BUSSystem.h
//refer to relationships betweem CPU and BUSSystem , relationships 
//between BUSSystem and Memory , relationships between BUSSystem and
//DeviceInterface , CPU.h , MemorySegment.h.

//Abstract class BUS defination
//used for holding the BUS width information
#if !defined(AFX_BUSSYSTEM1_H__CF035033_72C4_4AC3_9440_D09DA354F145__INCLUDED_)
#define AFX_BUSSYSTEM1_H__CF035033_72C4_4AC3_9440_D09DA354F145__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "type.h"
//declare classes that will be used in the 
//class BUSSystem
class CPU;
class Memory;
class DeviceInterface;
class BUS
{
private:
	BYTE m_nBUSWidth;//the BUS's width
public:
	//construction/destruction
	BUS(){}
	BUS(BYTE nBUSWidth){m_nBUSWidth=nBUSWidth;}
	~BUS(){}
};

//the following classes are the subclass of BUS
//class DetermineBUS defination
//used for holding the RB and RG states
class DetermineBUS:public BUS
{
private:
	BOOL m_nBS;//holding the device's BUS Request information,
				//make sure , the value of m_nBS not below 0
	BOOL m_nBG;//holding the BUS Grant information , make sure
				//,the value of m_nBG not below 0
public:
	//construction/destruction
	DetermineBUS():BUS(2){m_nBS=FALSE;m_nBG=FALSE;}
	//attribute
	void SetBS(BOOL nBR){m_nBS=nBR;}
	void GetBS(BOOL& nBR){nBR=m_nBS;}
	void SetBG(BOOL nBG){m_nBG=nBG;}
	void GetBG(BOOL& nBG){nBG=m_nBG;}
	friend class BUSDetermine;//the BUSdetermine can modify the m_nBG
								//directly
};

//class AddrBUS defination
//used for holding the memory or device address information
class AddrBUS:public BUS
{
private:
	UNSHORT m_uAddr;
public:
	//construction/destruction
	AddrBUS():BUS(16){m_uAddr=0;}
	~AddrBUS(){m_uAddr=0;}
	//attribute
	void ReadAddr(UNSHORT& uAddr){uAddr=m_uAddr;}
	void WriteAddr(UNSHORT& uAddr){m_uAddr=uAddr;}
};
//class DataBUS defination
//used for holding memory or device data
class DataBUS:public BUS
{
private:
	WORD m_wData;
public:
	//construction/destruction
	DataBUS():BUS(16){m_wData=0;}
	~DataBUS(){m_wData=0;}
	//attribute
	void ReadData(WORD& wData){wData=m_wData;}
	void WriteData(WORD& wData){m_wData=wData;}
};

//class IOBUS defination
//used for holding the IO states
class IOBUS:public BUS
{
private:
	BOOL m_bIORead;//it means Read if m_bIORead is FALSE
	BOOL m_bIOWrite;//it means Write if m_bIOWrite is FALSE
	Memory* _memory;
	DeviceInterface* _deviceInterface;
public:
	//construction/destruction
	IOBUS():BUS(2){m_bIORead=TRUE;m_bIOWrite=TRUE;_memory=NULL;_deviceInterface=NULL;}
	~IOBUS(){_memory=NULL;_deviceInterface=NULL;}
	//attribute
	void SetIORead(BOOL bIOState);//it will be called by the BUSSystem's SetIORead() function
								//and it will also call the Memory's or DeviceInterface's
								//SetIORead() function
	void SetIOWrite(BOOL bIOState);//it will be called by the BUSSystem's SetIOWrite() function
								//and it will also call the Memory's or DeviceInterface's
								//SetIOWrite() function
	void GetIORead(BOOL& bIOState){bIOState=m_bIORead;}
	void GetIOWrite(BOOL& bIOState){bIOState=m_bIOWrite;}
	void SetMemory(Memory* lpMemory){_memory=lpMemory;}//it will be called in the BUSSystem's
													//AttachTomMemory() function
	void SetDeviceInterface(DeviceInterface* lpDeviceInterface)//it will be called in the BUSSystem's
													//AttachTomMemory() function
	{
		_deviceInterface=lpDeviceInterface;
	}
};


//class BUSDetermine defination
//the only function of this class is to determine which device can
//occupy the BUS 
class BUSDetermine
{
private:
	BYTE m_bDevicePrior;//the prior level of the device that occupy
						//the BUS . it can be used by member function
						//Determine() for implementing algorithm
	DetermineBUS* _determineBUS;
public:
	void ReportState(CString strState);
	//construction/destruction
	BUSDetermine(){m_bDevicePrior=0;_determineBUS=NULL;}
	~BUSDetermine(){m_bDevicePrior=0;_determineBUS=NULL;}
	//operation 
	//must be implementing
	virtual BOOL Determine();//determine whether the device that Request BUS
					//can occupy the BUS ,return TRUE if it can, it will change the state of DetermineBUS
					//your own algorithm to override this function by inheritance
	//attribute
	void SetCurDevicePrior(BYTE& bDevicePrior){m_bDevicePrior=bDevicePrior;}
	void GerCurDevicePrior(BYTE& bDevicePrior){bDevicePrior=m_bDevicePrior;}
	void AttachToDetermineBUS(DetermineBUS* lpDetermineBUS){_determineBUS=lpDetermineBUS;}
	void DetachFromDetermineBUS(){_determineBUS=NULL;}
};

//class BUSSystem defination
//make all the BUS work together
//make the BUS work correctly with each other
//can be extended by inheriting
class BUSSystem
{
private:
	//construction/destruction
	CPU* _cpu;
	Memory* _memory;
	DeviceInterface* _deviceInterface;
	BUSDetermine* m_lpBUSDetermine;
	DetermineBUS* m_lpDetermineBUS;
	IOBUS* m_lpIOBUS;
	AddrBUS* m_lpAddrBUS;
	DataBUS* m_lpDataBUS;
public:
	void ReportState(CString strState);
	//constructio/destruction
	BUSSystem();
	~BUSSystem();
	//attribute
	void SetBUSDetermine(BUSDetermine* lpBUSDetermine);
	void SetDetermineBUS(DetermineBUS* lpDetermineBUS);
	void SetIOBUS(IOBUS* lpIOBUS);
	void SetAddrBUS(AddrBUS* lpAddrBUS);
	void SetDataBUS(DataBUS* lpDataBUS);
	BUSDetermine* GetBUSDetermine();
	DetermineBUS* GetDetermineBUS();
	IOBUS* GetIOBUS();
	AddrBUS* GetAddrBUS();
	DataBUS* GetDataBUS();
	//operation
	void SetBS(BOOL bSate);
	void ReadAddrFromAddrBUS(UNSHORT& uAddr);
	void WriteAddrToAddrBUS(UNSHORT& uAddr);
	void ReadDataFromDataBUS(WORD& wData);
	void WriteDataToDataBUS(WORD& wData);
	void SetIORead(BOOL bState);//it will called by the CPU's SetIORead() function
								//it will call the IOBUS's SetIORead() funtion
	void SetIOWrite(BOOL bState);//it will called by the CPU's SetWrite() function
								//it will call the IOBUS's SetIOWrite() funtion
	void AccessMemory();//Read data from or Write data to memory
						//it will call the memory's AccessMemory() function
	void AccessDevicePort();//Read data from or Write data to device port
						//it will call the deviceInerface's AccessDevice() function
						
	virtual BOOL Determine();//this function is used for determing whether
					//the device that Request the BUS can occupy
					//the BUS,return TRUE if it can, It will change the state of DetermineBUS. you can uae your own
					//algorithm to override this function by inheritance
	void AttachToCPU(CPU* lpCPU);//if the BUSSystem have had a CPU
									//it attach to ,you must first call DetachFromCPU()
									//if you want the BUSSystem attach to another
									//CPU
	void DetachFromCPU();
	void AttachToMemory(Memory* lpMemory);//if the BUSSystem have had a memory
									//it attach to ,you must first call DetachFromMemory()
									//if you want the BUSSystem attach to another
									//memory
	void AttachToDevice(DeviceInterface* lpDeviceInterface);//if the BUSSystem have had a deviceInterface
									//it attach to ,you must first call DetachFromDevice()
									//if you want the BUSSystem attach to another
									//deviceInterface
	void DetachFromMemory();//detach the memory ,this function also lead the memory's
							//data memember _busSystem point to NULL;
	void DetachFromDevice();//detach the deviceInterface ,this function also lead the deviceInerface's
							//data memember _busSystem point to NULL;
};
#endif // !defined(AFX_BUSSYSTEM1_H__CF035033_72C4_4AC3_9440_D09DA354F145__INCLUDED_)


⌨️ 快捷键说明

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