2017-06-05 22:39:15 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Board.h"
|
2017-11-03 22:05:01 +00:00
|
|
|
|
2017-06-05 22:39:15 +01:00
|
|
|
Board::Board(const Configuration& configuration)
|
2018-11-24 10:56:00 +00:00
|
|
|
: m_configuration(configuration) {}
|
2017-06-05 22:39:15 +01:00
|
|
|
|
2018-11-11 16:48:44 +00:00
|
|
|
void Board::powerOn() {
|
|
|
|
EightBit::Bus::powerOn();
|
|
|
|
CPU().powerOn();
|
|
|
|
CPU().reset();
|
|
|
|
}
|
|
|
|
|
2018-11-27 22:28:09 +00:00
|
|
|
void Board::powerOff() noexcept {
|
2018-11-11 16:48:44 +00:00
|
|
|
CPU().powerOff();
|
|
|
|
EightBit::Bus::powerOff();
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:39:15 +01:00
|
|
|
void Board::initialise() {
|
|
|
|
|
|
|
|
auto romDirectory = m_configuration.getRomDirectory();
|
2017-09-07 01:04:09 +01:00
|
|
|
m_ram.load(romDirectory + "/zexall.com", 0x100); // Cringle/Bartholomew
|
2017-06-05 22:39:15 +01:00
|
|
|
|
2018-11-24 10:56:00 +00:00
|
|
|
m_cpu.ExecutingInstruction.connect([this] (EightBit::Z80& cpu) {
|
|
|
|
if (UNLIKELY(EightBit::Chip::lowered(cpu.HALT())))
|
|
|
|
powerOff();
|
|
|
|
switch (cpu.PC().word) {
|
|
|
|
case 0x0: // CP/M warm start
|
|
|
|
if (++m_warmstartCount == 3) {
|
|
|
|
powerOff();
|
|
|
|
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 22:39:15 +01:00
|
|
|
|
2018-08-25 01:34:30 +01:00
|
|
|
poke(0, 0xc3); // JMP
|
2018-11-11 16:48:44 +00:00
|
|
|
CPU().pokeWord(1, m_configuration.getStartAddress());
|
2018-08-25 01:34:30 +01:00
|
|
|
poke(5, 0xc9); // ret
|
2017-06-05 22:39:15 +01:00
|
|
|
}
|
|
|
|
|
2018-06-24 20:58:20 +01:00
|
|
|
void Board::bdos() {
|
2018-06-10 00:40:56 +01:00
|
|
|
switch (CPU().C()) {
|
|
|
|
case 0x2:
|
|
|
|
std::cout << CPU().E();
|
2017-06-05 22:39:15 +01: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 01:04:09 +01:00
|
|
|
std::cout << peek(i);
|
2017-06-05 22:39:15 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|