// rev 1.03
#include "stdafx.h"
#include "qbus_memory.h"

#include "Debugger.h"

QBUS_Memory10::QBUS_Memory10()
	: QBUS_Memory10(0100000, MEM_SIZE10_B)
{
}

QBUS_Memory10::QBUS_Memory10(size_t nStart, size_t nSizeB)
	: QBUS_Device()
	, m_nMemStart(nStart)
	, m_nMemSize(nSizeB)
{
	m_nMemEnd = m_nMemStart + m_nMemSize;
	memset(m_memb, 0, m_nMemSize);
}


QBUS_Memory10::~QBUS_Memory10()
{
}

void QBUS_Memory10::AttachDebugger(CDebugger *pDbg)
{
	pDbg->AttachMemoryROMModule(m_memb, m_nMemSize);
}

bool QBUS_Memory10::DecodeAddr()
{
	//TRACE1("MEM Request: %06o\n", m_IOPins.pin_ad);
	return ((m_nMemStart <= m_nAddr) && (m_nAddr < m_nMemEnd));
}

bool QBUS_Memory10::ReadOp()
{
	//TRACE1("MEM Read: %06o\n", nAddr);
	m_IOPins.pin_ad = m_memw[m_nAddr >> 1];
	/*
	FILE *Log = fopen("_vm1pin_log.txt", "a");
	fprintf(Log, "MEM Read:: addr: %06o ; data: %06o\n", m_nAddr, m_IOPins.pin_ad );
	fclose(Log);
	//*/
	return true;
}

bool QBUS_Memory10::WriteOp()
{
	//TRACE1("MEM Write: %06o\n", nAddr);
	if (m_IOPins.pin_wtbt)
	{
		if (m_nAddr & 1)
		{
			m_memb[m_nAddr] = HIBYTE(m_IOPins.pin_ad);
		}
		else
		{
			m_memb[m_nAddr] = LOBYTE(m_IOPins.pin_ad);
		}
	}
	else
	{
		m_memw[m_nAddr >> 1] = m_IOPins.pin_ad;
	}

	return true;
}


QBUS_Memory11::QBUS_Memory11()
	: QBUS_Memory10(0140000, MEM_SIZE11_B)
{
}

QBUS_Memory11::~QBUS_Memory11()
{
}

