2017-06-05 16:31:21 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Board.h"
|
|
|
|
#include "Configuration.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
Board::Board(const Configuration& configuration)
|
|
|
|
: m_configuration(configuration),
|
|
|
|
m_memory(0xffff),
|
|
|
|
m_cpu(EightBit::Intel8080(m_memory, m_ports)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Board::initialise() {
|
|
|
|
|
|
|
|
m_memory.clear();
|
|
|
|
auto romDirectory = m_configuration.getRomDirectory();
|
|
|
|
|
|
|
|
//m_memory.loadRam(romDirectory + "/TEST.COM", 0x100); // Microcosm
|
|
|
|
//m_memory.loadRam(romDirectory + "/8080PRE.COM", 0x100); // Bartholomew preliminary
|
|
|
|
m_memory.loadRam(romDirectory + "/8080EX1.COM", 0x100); // Cringle/Bartholomew
|
|
|
|
//m_memory.loadRam(romDirectory + "/CPUTEST.COM", 0x100); // SuperSoft diagnostics
|
|
|
|
|
2017-08-23 22:17:45 +00:00
|
|
|
m_memory.poke(5, 0xc9); // ret
|
2017-06-05 16:31:21 +00:00
|
|
|
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Cpm, this, std::placeholders::_1));
|
|
|
|
|
|
|
|
if (m_configuration.isProfileMode()) {
|
|
|
|
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Profile, this, std::placeholders::_1));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_configuration.isDebugMode()) {
|
|
|
|
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cpu.initialise();
|
2017-06-19 12:53:00 +00:00
|
|
|
m_cpu.PC() = m_configuration.getStartAddress();
|
2017-06-05 16:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Intel8080&) {
|
2017-06-19 12:53:00 +00:00
|
|
|
auto pc = m_cpu.PC();
|
2017-06-05 16:31:21 +00:00
|
|
|
switch (pc.word) {
|
|
|
|
case 0x0: // CP/M warm start
|
|
|
|
m_cpu.halt();
|
2017-06-22 09:27:19 +00:00
|
|
|
if (m_configuration.isProfileMode()) {
|
|
|
|
m_profiler.dump();
|
|
|
|
}
|
2017-06-05 16:31:21 +00:00
|
|
|
break;
|
|
|
|
case 0x5: // BDOS
|
|
|
|
bdos();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Board::bdos() {
|
|
|
|
auto c = m_cpu.C();
|
|
|
|
switch (c) {
|
|
|
|
case 0x2: {
|
|
|
|
auto character = m_cpu.E();
|
|
|
|
std::cout << character;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x9:
|
2017-06-20 13:09:44 +00:00
|
|
|
for (uint16_t i = m_cpu.DE().word; m_memory.peek(i) != '$'; ++i) {
|
|
|
|
std::cout << m_memory.peek(i);
|
2017-06-05 16:31:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Board::Cpu_ExecutingInstruction_Profile(const EightBit::Intel8080& cpu) {
|
|
|
|
|
2017-06-19 12:53:00 +00:00
|
|
|
const auto pc = m_cpu.PC();
|
2017-06-05 16:31:21 +00:00
|
|
|
|
|
|
|
m_profiler.addAddress(pc.word);
|
|
|
|
m_profiler.addInstruction(m_memory.peek(pc.word));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Board::Cpu_ExecutingInstruction_Debug(const EightBit::Intel8080&) {
|
|
|
|
|
|
|
|
std::cerr
|
|
|
|
<< EightBit::Disassembler::state(m_cpu)
|
|
|
|
<< "\t"
|
2017-07-25 13:12:34 +00:00
|
|
|
<< m_disassembler.disassemble(m_cpu)
|
2017-06-05 16:31:21 +00:00
|
|
|
<< '\n';
|
|
|
|
}
|