📄 globalvar.cpp
字号:
// GlobalVar.cpp: implementation of the GlobalVar class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "8051class.h"
#include "GlobalVar.h"
#include "..\DeviceManager.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
GlobalVar * var8051[CPUNUM];
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//BYTE xdata[65536];//外部数据内存
//BYTE code[65536];//外部代码内存
GlobalVar::GlobalVar()
{
isready=0;
}
GlobalVar::~GlobalVar()
{
#if OS!=1
delete IPC;
delete inst;
delete KMsg;
delete mem;
delete pTIMER;
#endif
#if OS==1
VirtualFree(IPC,sizeof(InterruptController),MEM_DECOMMIT);
VirtualFree(inst,sizeof(instruction),MEM_DECOMMIT);
VirtualFree(KMsg,sizeof(kernelMsg),MEM_DECOMMIT);
VirtualFree(mem,sizeof(memory),MEM_DECOMMIT);
VirtualFree(pTIMER,sizeof(TIMER),MEM_DECOMMIT);
#endif
}
//5个小时就为了找这个BUG.............VirtualAlloc方式产生C++实例必须构造,否则一些情况下会产生错误
//因为有些内存是需要初始化的,比如虚拟函数表,只有调用了构造函数才可以初始化虚拟函数表
int GlobalVar::init()
{
memset(NAME,0,512);
#if OS!=1
mem=new memory;//初始化内存类
#endif
#if OS==1
mem=(memory *)VirtualAlloc(NULL,sizeof(memory),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
mem->memory::memory();
#endif
//mem->pcode=code;
//mem->pxdata=xdata;
mem->init();
mem->MemReset();
#if OS!=1
inst=new instruction;
#endif
#if OS==1
inst=(instruction *)VirtualAlloc(NULL,sizeof(instruction),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
inst->instruction::instruction();
#endif
inst->mem=mem;//初始化指令类
inst->CreateMap();
#if OS!=1
KMsg=new kernelMsg;
#endif
#if OS==1
KMsg=(kernelMsg *)VirtualAlloc(NULL,sizeof(kernelMsg),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
KMsg->kernelMsg::kernelMsg();
#endif
KMsg->mem=mem;
KMsg->init();
inst->pKMsg=KMsg;
inst->init();
#if OS!=1
IPC=new InterruptController;
#endif
#if OS==1
IPC=(InterruptController *)VirtualAlloc(NULL,sizeof(InterruptController),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
IPC->InterruptController::InterruptController();
#endif
IPC->SetMem(inst);
IPC->pKMsg=KMsg;
IPC->init();
#if OS!=1
pTIMER=new TIMER;
#endif
#if OS==1
pTIMER=(TIMER *)VirtualAlloc(NULL,sizeof(TIMER),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
pTIMER->TIMER::TIMER();
#endif
pTIMER->pKMsg=KMsg;
pTIMER->mem=mem;
pTIMER->init();
#if OS!=1
PS=new Serial;
#endif
#if OS==1
PS=(Serial *)VirtualAlloc(NULL,sizeof(Serial),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
PS->Serial::Serial();//kao,基础太差产生的BUG
#endif
PS->pKMsg=KMsg;
PS->mem=mem;
PS->init();
isready|=ID_INIT_READY;
return true;
}
void GlobalVar::SetFqy(unsigned int f=22118400)
{
fqy=f;
}
int GlobalVar::SetMem(BYTE *pcodemem, BYTE *pxdatamem)
{
mem->pcode=pcodemem;
mem->pxdata=pxdatamem;
isready|=ID_MEM_READY;
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -