// BKMSTD11.cpp: implementation of the CBKMSTD11 class.
//


#include "stdafx.h"
#include "resource.h"
#include "BKMSTD11.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction

CBKMSTD11::CBKMSTD11()
{
	//инициализируем список загружаемых ПЗУ
	m_aBoardRomList[0] = { IDS_INI_BK11_RE2_203_MSTD, BRD_11_TESTS_BNK };
	m_aBoardRomList[1] = { 0, 0 };
}

CBKMSTD11::~CBKMSTD11()
{}

BK_BOARD_MODEL CBKMSTD11::GetBoardModel()
{
	return DEV_MPI_MSTD11;
}

bool CBKMSTD11::InitDevice(uint16_t addrStart)
{
	//инициализация карты памяти
	return InitMemoryModules();
}


bool CBKMSTD11::GetByte(register uint16_t addr, register uint8_t *pValue)
{
	if (0160000 <= addr && addr < m_nBKPortsIOArea)
	{
		*pValue = m_pMemory[addr];
		return true;
	}

	*pValue = 0;
	return false;
}

bool CBKMSTD11::GetWord(register uint16_t addr, register uint16_t *pValue)
{
	if (0160000 <= addr && addr < m_nBKPortsIOArea)
	{
		*pValue = *(uint16_t *)&m_pMemory[addr & 0177776];
		return true;
	}

	*pValue = 0;
	return false;
}


void CBKMSTD11::MemoryManager()
{
	CBKMPIDevice::MemoryManager();
	m_MemoryMap[BRD_11_TESTS_BNK].bReadable = TRUE;
}


bool CBKMSTD11::RestoreMemory(DWORD id, CMSFManager *pMsf)
{
	if (pMsf->IsLoad())
	{
		return pMsf->GetBlockBaseMemory(id, m_pMemory, m_nMemorySize);
	}
	else
	{
		return pMsf->SetBlockBaseMemory(id, m_pMemory, m_nMemorySize);
	}
}

bool CBKMSTD11::RestoreMemoryMap(DWORD id, CMSFManager *pMsf)
{
	if (pMsf->IsLoad())
	{
		return pMsf->GetBlockMemMap(id, m_MemoryMap);
	}
	else
	{
		return pMsf->SetBlockMemMap(id, m_MemoryMap);
	}
}

