2017-06-05 21:39:15 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Board.h"
|
2017-11-03 22:05:01 +00:00
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
Board::Board(const Configuration& configuration)
|
2018-11-24 10:56:00 +00:00
|
|
|
: m_configuration(configuration) {}
|
2017-06-05 21:39:15 +00:00
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void Board::raisePOWER() noexcept {
|
2019-01-14 02:10:17 +00:00
|
|
|
EightBit::Bus::raisePOWER();
|
|
|
|
CPU().raisePOWER();
|
|
|
|
CPU().raiseRESET();
|
|
|
|
CPU().raiseINT();
|
|
|
|
CPU().raiseNMI();
|
2018-11-11 16:48:44 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
void Board::lowerPOWER() noexcept {
|
|
|
|
CPU().lowerPOWER();
|
|
|
|
EightBit::Bus::lowerPOWER();
|
2018-11-11 16:48:44 +00:00
|
|
|
}
|
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
void Board::initialise() {
|
|
|
|
|
|
|
|
auto romDirectory = m_configuration.getRomDirectory();
|
2017-09-07 00:04:09 +00:00
|
|
|
m_ram.load(romDirectory + "/zexall.com", 0x100); // Cringle/Bartholomew
|
2017-06-05 21:39:15 +00:00
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
m_cpu.LoweredHALT.connect([this](EightBit::EventArgs) {
|
|
|
|
lowerPOWER();
|
|
|
|
});
|
|
|
|
|
2018-11-24 10:56:00 +00:00
|
|
|
m_cpu.ExecutingInstruction.connect([this] (EightBit::Z80& cpu) {
|
|
|
|
switch (cpu.PC().word) {
|
|
|
|
case 0x0: // CP/M warm start
|
2019-01-14 02:10:17 +00:00
|
|
|
if (++m_warmstartCount == 2) {
|
|
|
|
lowerPOWER();
|
2018-11-24 10:56:00 +00:00
|
|
|
if (m_configuration.isProfileMode())
|
|
|
|
m_profiler.dump();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x5: // BDOS
|
|
|
|
bdos();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (m_configuration.isProfileMode())
|
|
|
|
m_cpu.ExecutingInstruction.connect([this] (EightBit::Z80& cpu) {
|
|
|
|
const auto pc = cpu.PC();
|
|
|
|
m_profiler.addAddress(pc.word);
|
|
|
|
m_profiler.addInstruction(peek(pc));
|
|
|
|
});
|
|
|
|
|
|
|
|
if (m_configuration.isDebugMode())
|
|
|
|
m_cpu.ExecutingInstruction.connect([this] (EightBit::Z80& cpu) {
|
|
|
|
std::cerr
|
|
|
|
<< EightBit::Disassembler::state(cpu)
|
|
|
|
<< "\t"
|
|
|
|
<< m_disassembler.disassemble(cpu)
|
|
|
|
<< std::endl;
|
|
|
|
});
|
2017-06-05 21:39:15 +00:00
|
|
|
|
2018-08-25 00:34:30 +00:00
|
|
|
poke(0, 0xc3); // JMP
|
2018-11-11 16:48:44 +00:00
|
|
|
CPU().pokeWord(1, m_configuration.getStartAddress());
|
2018-08-25 00:34:30 +00:00
|
|
|
poke(5, 0xc9); // ret
|
2017-06-05 21:39:15 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 19:58:20 +00:00
|
|
|
void Board::bdos() {
|
2018-06-09 23:40:56 +00:00
|
|
|
switch (CPU().C()) {
|
|
|
|
case 0x2:
|
|
|
|
std::cout << CPU().E();
|
2017-06-05 21:39:15 +00:00
|
|
|
break;
|
|
|
|
case 0x9:
|
2018-11-24 10:56:00 +00:00
|
|
|
for (uint16_t i = CPU().DE().word; peek(i) != '$'; ++i)
|
2017-09-07 00:04:09 +00:00
|
|
|
std::cout << peek(i);
|
2017-06-05 21:39:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|