#include "stdafx.h"
#include "FDDStd326Mem.h"

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

CFDDStd326Mem::CFDDStd326Mem()
{
	//хак, чтобы не зацикливаться при старте
	*(uint16_t *)&m_pMemory[020000] = 0;
}


CFDDStd326Mem::~CFDDStd326Mem()
{
}

BK_BOARD_MODEL CFDDStd326Mem::GetBoardModel()
{
	return DEV_MPI_STD_MEM;
}

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

	return CFDDStd326::GetByte(addr, pValue);
}

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

	return CFDDStd326::GetWord(addr, pValue);
}

bool CFDDStd326Mem::SetByte(register uint16_t addr, register uint8_t value)
{
	if (0120000 <= addr && addr < 0160000)
	{
		m_pMemory[addr & 077777] = value;
		return true;
	}

	return CFDDStd326::SetByte(addr, value);
}

bool CFDDStd326Mem::SetWord(register uint16_t addr, register uint16_t value)
{
	if (0120000 <= addr && addr < 0160000)
	{
		*(uint16_t *)&m_pMemory[addr & 077776] = value;
		return true;
	}

	return CFDDStd326::SetWord(addr, value);
}

void CFDDStd326Mem::MemoryManager()
{
	CFDDStd326::MemoryManager();
	//по адресам 120000-160000 ОЗУ
	m_MemoryMap[KNGMD_RAM1_BNK].bReadable = TRUE;
	m_MemoryMap[KNGMD_RAM1_BNK].bWritable = TRUE;
	m_MemoryMap[KNGMD_RAM2_BNK].bReadable = TRUE;
	m_MemoryMap[KNGMD_RAM2_BNK].bWritable = TRUE;
}
