📄 cpu.h
字号:
//CPU.H refer to Instruction.h, MemorySegment.h and type.h
#if !defined(AFX_CPU1_H__DA23E57C_CB80_42D8_8935_0B03C91F85F9__INCLUDED_)
#define AFX_CPU1_H__DA23E57C_CB80_42D8_8935_0B03C91F85F9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "type.h"
#define REGISTER_EXTENSION_NUMBER 10//The number of the register that will be extented
#define MAXNUMBER 127//The max number that the simulator supports
//declare classes will be used in the class CPU:
class Instruction;
class BUSSystem;
class CIRQDlg;
class CPU
{
private:
//Data member
//General register
WORD GR[5];
//Segment register
UNSHORT CS;
UNSHORT DS;
UNSHORT ES;
UNSHORT SS;
//Offset register
WORD IP;
WORD SP;
//Flags register
WORD FLAGS;
//Current instruction
WORD PC;
DWORD OP;//code
//temp data
WORD m_tempData;//to hold the temp value that the CPU will be use
Instruction* _instruction;
//States
BOOL m_bBG;//BUS Grant information . It means CPU occupy the
//BUS if the value of m_bBG is TRUE
BOOL m_bContinue;//to determine whether the program can contiue excute
//used by the step interrupt
BOOL m_bIRQ;//the IRQ state
BYTE m_bIRQMask;//the IRQ mask bit
//Handler Entry
Instruction* _instructionEntry[MAXNUMBER];
//this arry may contains the handler classes,you should
//use InstructionEntry[i]->Excute() to specify a Instruction
//class server for you
//the attached interrupt system
//the attached BUSSystem
BUSSystem* _busSystem;
public:
void SetIntCtrl(CIRQDlg * pIRQDlg);//set interrupt control
BYTE GetIRQMask();
void SetIRQMask(BYTE bMask);
void Ack();
void ReportState(CString strState);
//Constructor and Destructor
CPU();
~CPU();
//Initialize
void Initialize();
//Attribute
//General register
WORD GetGR(BYTE bIndex);;
void SetGR(WORD wGR,BYTE bIndex);
//Segment register
UNSHORT GetCS(){return CS;}
UNSHORT GetDS(){return DS;}
UNSHORT GetES(){return ES;}
UNSHORT GetSS(){return SS;}
void SetCS(UNSHORT wCS){CS=wCS;}
void SetDS(UNSHORT wDS){DS=wDS;}
void SetES(UNSHORT wES){ES=wES;}
void SetSS(UNSHORT wSS){SS=wSS;}
//Offset register
WORD GetIP(){return IP;}
WORD GetSP(){return SP;}
void SetIP(WORD wIP){IP=wIP;}
void SetSP(WORD wSP){SP=wSP;}
//Flag register
WORD GetFLAGS(){return FLAGS;}
void SetFLAGS(WORD wFLAGS){FLAGS=wFLAGS;}
//program counter
void SetPC(UNSHORT uPC){PC=uPC;}
WORD GetPC(){return PC;}
DWORD GetOP(){return OP;}
//tempData
void SetTempData(WORD wData){m_tempData=wData;}
WORD GetTempData(){return m_tempData;}
//instruction
Instruction* GetInstruction(BYTE bIndex);
//step interrupt
void SetContinue(BOOL bState){m_bContinue=bState;}
BOOL GetContinue(){return m_bContinue;}
//interrupr operation
void SetIRQ(){m_bIRQ=TRUE;}
void ResetIRQ(){m_bIRQ=FALSE;}
//Operation:
void Excute();//excute instruction
int AddInstruction(Instruction* lpInstruction,BYTE bCode);
//The follow operations are used to operate the BUS
void SetBUSSystem(BUSSystem*lpBUSSystem){_busSystem=lpBUSSystem;}
UNSHORT ReadAddrFromAddrBUS();//used to view the addr in the Addr BUS
//make sure CPU have the BUS control, or this operate may be
//failed,so, in this function,you must first call the
//RequestBUS() function to get the BUS control,and remember
//release it if you no long meed
void WriteAddrToAddrBUS(UNSHORT uAddr);//make sure CPU have the BUS control, or this operate may be
//failed,so, in this function,you must first call the
//RequestBUS() function to get the BUS control,and remember
//release it if you no long meed
void SetIOWrite(BOOL bState);//it means Write if bState is FALSE,otherwise Write
//it will be called by the BUSSyste's SetIORead() funcion
void SetIORead(BOOL bState);//it means Read if bState is FALSE
//it will be called by the BUSSyste's SetIOWrite() funcion
WORD ReadDataFromMemory();//make sure CPU have the BUS control, or this operate may be
//failed,so, in this function,you must first call the
//RequestBUS() function to get the BUS control,and remember
//release it if you no long meed
void WriteDataToMemory(WORD& wData);//make sure CPU have the BUS control, or this operate may be
//failed,so, in this function,you must first call the
//RequestBUS() function to get the BUS control,and remember
//release it if you no long meed
void ReadDataFromDevicePort(WORD& wData);//make sure CPU have the BUS control, or this operate may be
//failed,so, in this function,you must first call the
//RequestBUS() function to get the BUS control,and remember
//release it if you no long meed
WORD WriteDataToDevicePort();//make sure CPU have the BUS control, or this operate may be
//failed,so, in this function,you must first call the
//RequestBUS() function to get the BUS control,and remember
//release it if you no long meed
void RequestBUS();//Request BUS control
void ReleaseBUS();//To release the BUS control
//the file and put it into the Memory
//The follow datamember and method are used for supporting future extension
//like I/O and interrupt system
//data member
private:
CIRQDlg* _IRQDlg;
void LoadInstructionFromMemory();
WORD m_wRegisters[REGISTER_EXTENSION_NUMBER];
LPCTSTR m_lpRegisterName[REGISTER_EXTENSION_NUMBER];
//Method
virtual int AddRegister(LPCTSTR lpRegisterName);
};
#endif // !defined(AFX_CPU1_H__DA23E57C_CB80_42D8_8935_0B03C91F85F9__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -