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

📄 memorysegment.cpp

📁 这个也是我们的毕业设计课题
💻 CPP
字号:
//MemorySegment.cpp
//used for implementing the Memory Segment operation
//refer to MemorySegment.h
#include "stdafx.h"
#include ".\MemorySegment.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//class Memory implementing
#include "BUSSystem.h"
//construction/destruction
Memory::Memory()
{
	m_lpuMemorySegAddr=NULL;
	_busSystem=NULL;
	m_uMemorySegSize=0;
	m_bIORead=TRUE;
	m_bIOWrite=TRUE;
}
//Alloc a memory segment
//the size is specified by uSegSize
//the maxsize of this segment is 128kb
Memory::Memory(UNSHORT uSegSize)
{
	_busSystem=NULL;
	m_lpuMemorySegAddr=NULL;
	m_uMemorySegSize=0;
	m_lpuMemorySegAddr=new UNSHORT[uSegSize];
	m_uMemorySegSize=uSegSize;
	if(!m_lpuMemorySegAddr)
	{
		MessageBox(NULL,"Not enough memory !","Error!",MB_OK);
		m_uMemorySegSize=0;
		return;
	}
	for(int i=0;i<uSegSize;i++)
		m_lpuMemorySegAddr[i]=0;
}
Memory::~Memory()
{
	if(m_lpuMemorySegAddr)
	{
		delete[] m_lpuMemorySegAddr;
		m_uMemorySegSize=0;
	}
	_busSystem=NULL;
}

//operation
//set a memory segment,the size is specified by uSegSize
//Note: call this function will lead destroying the 
//previous data that in the segment
void Memory::SetSegSize(UNSHORT uSegSize)
{
	
	if(m_lpuMemorySegAddr)
	{
		delete[] m_lpuMemorySegAddr;
		m_uMemorySegSize=0;
	}
	m_lpuMemorySegAddr=new UNSHORT[uSegSize];
	m_uMemorySegSize=uSegSize;
	if(!m_lpuMemorySegAddr)
	{
		MessageBox(NULL,"Not enough memory !","Error!",MB_OK);
		m_uMemorySegSize=0;
		return;
	}
	for(int i=0;i<uSegSize;i++)
	m_lpuMemorySegAddr[i]=0;
}
//relead the Memory segment
void Memory::Release()
{
	if(m_lpuMemorySegAddr)
	{
		delete[] m_lpuMemorySegAddr;
		m_uMemorySegSize=0;
	}
}
//write wData to the address specified by uAddr
void Memory::WriteMemory(UNSHORT uAddr,WORD wData)
{
	if(uAddr>m_uMemorySegSize-1)
	{
		ReportState("sorry, the address you want to\
			\n write is out boundary or\
			\nthe memory segment not exist");
		return;
	}
	m_lpuMemorySegAddr[uAddr]=wData;
}
//read wData from the address specified by uAddr
void Memory::ReadMemory(UNSHORT uAddr,WORD& wData)
{
	if(uAddr>m_uMemorySegSize-1)
	{
		ReportState("sorry, the address you want to\
			\n read is out boundary or\
			\nthe memory segment not exist");
		return;
	}
	wData=m_lpuMemorySegAddr[uAddr];
}
void Memory::AccessMemory()
{
	if(_busSystem)
	{
		UNSHORT uAddr=0;
		_busSystem->ReadAddrFromAddrBUS(uAddr);
		if(!m_bIOWrite)//if the IO operation is write
		{
			WORD wData=0;
			_busSystem->ReadDataFromDataBUS(wData);
			WriteMemory(uAddr,wData);
		}
		else if(!m_bIORead)
		{
			WORD wData=0;
			ReadMemory(uAddr,wData);
			_busSystem->WriteDataToDataBUS(wData);
		}
		else
		{
			MessageBox(NULL,"Unknown operate!","Error",MB_OK);
			return;
		}
	}
	else
	{
		MessageBox(NULL,"The memory haven't found any \nBUSSystem attach to it.","Error!",MB_OK);
		return;
	}
}



void Memory::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 + -