EightBit/MC6809/test/Board.cpp
Adrian Conlon e88cbc269b Add a skeletal half way house between a 6809 tester and a CoCo 2 emulator.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2018-08-26 19:09:34 +01:00

81 lines
2.1 KiB
C++

#include "stdafx.h"
#include "Board.h"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <assert.h>
Board::Board(const Configuration& configuration)
: m_configuration(configuration),
m_cpu(EightBit::mc6809(*this)),
m_disassembler(m_cpu) {}
void Board::initialise() {
const auto directory = m_configuration.getRomDirectory() + "\\";
m_extendedBasic.load(directory + "extbas11.rom");
m_colorBasic.load(directory + "bas12.rom");
m_diskBasic.load(directory + "disk11.rom");
if (m_configuration.isDebugMode()) {
CPU().ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
}
CPU().powerOn();
CPU().reset();
}
void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809& cpu) {
auto address = cpu.PC().word;
auto cell = peek(address);
std::cout << std::hex;
std::cout << "PC=" << std::setw(4) << std::setfill('0') << address << ":";
std::cout << "CC=" << m_disassembler.dump_Flags(CPU().CC()) << ", ";
std::cout << "D=" << (int)CPU().D().word << ", ";
std::cout << "X=" << (int)CPU().X().word << ", ";
std::cout << "Y=" << (int)CPU().Y().word << ", ";
std::cout << "U=" << (int)CPU().U().word << ",";
std::cout << "S=" << (int)CPU().S().word << ", ";
std::cout << std::setw(2) << std::setfill('0');
std::cout << "DP=" << (int)CPU().DP() << "\t";
std::cout << m_disassembler.disassemble(address);
std::cout << "\n";
}
uint8_t& Board::reference(uint16_t address) {
// 0x0000 - 0x7fff
if (address < 0x8000)
return m_ram.reference(address);
// 0x8000 - 0x9fff
if (address < 0xa000)
return DATA() = m_extendedBasic.peek(address - 0x8000);
// 0xa000 - 0xbfff
if (address < 0xc000)
return DATA() = m_colorBasic.peek(address - 0xa000);
// 0xc000 - 0xdfff
if (address < 0xe000)
return DATA() = m_diskBasic.peek(address - 0xc000);
// 0xe000 - 0xfeff
if (address < 0xff00)
return DATA() = 0xff;
// 0xe000 - 0xfeff
if (address < 0xfff0)
return m_io.reference(address - 0xff00);
// 0xfff0 - 0xffff
const auto offset = address - 0xfff0;
return DATA() = m_colorBasic.peek(0x1ff0 + offset);
}