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),
|
2018-10-20 19:52:41 +00:00
|
|
|
m_cpu(EightBit::Intel8080(*this, m_ports)),
|
|
|
|
m_disassembler(*this) {
|
2017-06-05 16:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Board::initialise() {
|
|
|
|
|
|
|
|
auto romDirectory = m_configuration.getRomDirectory();
|
|
|
|
|
2017-09-06 23:55:06 +00:00
|
|
|
//m_ram.load(romDirectory + "/TEST.COM", 0x100); // Microcosm
|
|
|
|
//m_ram.load(romDirectory + "/8080PRE.COM", 0x100); // Bartholomew preliminary
|
|
|
|
m_ram.load(romDirectory + "/8080EX1.COM", 0x100); // Cringle/Bartholomew
|
|
|
|
//m_ram.load(romDirectory + "/CPUTEST.COM", 0x100); // SuperSoft diagnostics
|
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));
|
|
|
|
}
|
|
|
|
|
2017-12-10 21:41:48 +00:00
|
|
|
CPU().powerOn();
|
2018-08-25 00:34:30 +00:00
|
|
|
CPU().reset();
|
|
|
|
|
|
|
|
poke(0, 0xc3); // JMP
|
2018-10-14 19:39:09 +00:00
|
|
|
CPU().pokeWord(1, m_configuration.getStartAddress());
|
2018-08-25 00:34:30 +00:00
|
|
|
|
|
|
|
poke(5, 0xc9); // ret
|
2017-06-05 16:31:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 21:33:02 +00:00
|
|
|
void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Intel8080& cpu) {
|
2018-06-09 23:40:56 +00:00
|
|
|
switch (cpu.PC().word) {
|
2017-06-05 16:31:21 +00:00
|
|
|
case 0x0: // CP/M warm start
|
2018-08-25 00:34:30 +00:00
|
|
|
if (++m_warmstartCount == 3) {
|
|
|
|
CPU().powerOff();
|
|
|
|
if (m_configuration.isProfileMode()) {
|
|
|
|
m_profiler.dump();
|
|
|
|
}
|
2017-06-22 09:27:19 +00:00
|
|
|
}
|
2017-06-05 16:31:21 +00:00
|
|
|
break;
|
|
|
|
case 0x5: // BDOS
|
|
|
|
bdos();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 19:58:20 +00:00
|
|
|
void Board::bdos() {
|
2018-06-09 23:40:56 +00:00
|
|
|
switch (CPU().C()) {
|
2017-06-05 16:31:21 +00:00
|
|
|
case 0x2: {
|
2018-06-09 23:40:56 +00:00
|
|
|
const auto character = CPU().E();
|
2017-06-05 16:31:21 +00:00
|
|
|
std::cout << character;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x9:
|
2017-12-10 21:41:48 +00:00
|
|
|
for (uint16_t i = CPU().DE().word; peek(i) != '$'; ++i) {
|
2017-09-06 23:55:06 +00:00
|
|
|
std::cout << peek(i);
|
2017-06-05 16:31:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 21:33:02 +00:00
|
|
|
void Board::Cpu_ExecutingInstruction_Profile(EightBit::Intel8080& cpu) {
|
2017-06-05 16:31:21 +00:00
|
|
|
|
2018-06-09 23:40:56 +00:00
|
|
|
const auto pc = cpu.PC();
|
2017-06-05 16:31:21 +00:00
|
|
|
|
|
|
|
m_profiler.addAddress(pc.word);
|
2017-09-06 23:55:06 +00:00
|
|
|
m_profiler.addInstruction(peek(pc.word));
|
2017-06-05 16:31:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 23:40:56 +00:00
|
|
|
void Board::Cpu_ExecutingInstruction_Debug(const EightBit::Intel8080& cpu) {
|
2017-06-05 16:31:21 +00:00
|
|
|
|
|
|
|
std::cerr
|
2017-12-10 21:41:48 +00:00
|
|
|
<< EightBit::Disassembler::state(CPU())
|
2017-06-05 16:31:21 +00:00
|
|
|
<< "\t"
|
2017-12-10 21:41:48 +00:00
|
|
|
<< m_disassembler.disassemble(CPU())
|
2017-06-05 16:31:21 +00:00
|
|
|
<< '\n';
|
|
|
|
}
|