// BKMSTD10.cpp: implementation of the CBKMSTD10 class.
//


#include "stdafx.h"
#include "resource.h"
#include "BKMSTD10.h"

#include "Platform.h"
#include "BK001001.h"

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

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

CBKMSTD10::CBKMSTD10()
{
	//инициализируем список загружаемых ПЗУ
	m_aBoardRomList[0] = { IDS_INI_BK10_RE2_018_FOCAL, BRD_10_FOCAL_BNK };
	m_aBoardRomList[1] = { IDS_INI_BK10_RE2_019_MSTD, BRD_10_TESTS_BNK };
	m_aBoardRomList[2] = { 0, 0 };
}

CBKMSTD10::~CBKMSTD10()
{}

BK_BOARD_MODEL CBKMSTD10::GetBoardModel()
{
	return BK_BOARD_MODEL::DEV_MPI_MSTD10;
}

bool CBKMSTD10::InitDevice(uint16_t addrStart)
{
	//выключаем ПЗУ бейсика БК10
	if (g_Platform.GetBoardPtr())
	{
		g_Platform.GetBoardPtr()->BasicRomOFF(true);
	}

	//инициализация карты памяти
	return InitMemoryModules();
}


bool CBKMSTD10::GetByteT(register uint16_t addr, register uint8_t *pValue, int &nTC)
{
	register int nBank = ADDRESS_TO_BANK(addr);

	if ((nBank == BRD_10_FOCAL_BNK) ||
	        (nBank == BRD_10_TESTS_BNK && addr < m_nBKPortsIOArea))
	{
		nTC = m_MemoryMap[nBank].nTimingCorrection;
		*pValue = m_pMemory[addr];
		return true;
	}

	*pValue = 0;
	return false;
}

bool CBKMSTD10::GetWordT(register uint16_t addr, register uint16_t *pValue, int &nTC)
{
	register int nBank = ADDRESS_TO_BANK(addr);

	if ((nBank == BRD_10_FOCAL_BNK) ||
	        (nBank == BRD_10_TESTS_BNK && addr < m_nBKPortsIOArea))
	{
		nTC = m_MemoryMap[nBank].nTimingCorrection;
		*pValue = *(uint16_t *)&m_pMemory[addr & 0177776];
		return true;
	}

	*pValue = 0;
	return false;
}

void CBKMSTD10::MemoryManager()
{
	CBKMPIDevice::MemoryManager();
	m_MemoryMap[BRD_10_FOCAL_BNK].bReadable = TRUE;
	m_MemoryMap[BRD_10_FOCAL_BNK].nTimingCorrection = ROM_TIMING_CORR_VALUE;
	m_MemoryMap[BRD_10_TESTS_BNK].bReadable = TRUE;
	m_MemoryMap[BRD_10_TESTS_BNK].nTimingCorrection = ROM_TIMING_CORR_VALUE;
}

bool CBKMSTD10::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 CBKMSTD10::RestoreMemoryMap(DWORD id, CMSFManager *pMsf)
{
	if (pMsf->IsLoad())
	{
		return pMsf->GetBlockMemMap(id, m_MemoryMap);
	}
	else
	{
		return pMsf->SetBlockMemMap(id, m_MemoryMap);
	}
}

