mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-11-19 17:30:56 +00:00
Modernise the signal handling and construction sequence of the Z80 test board.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
cec760767a
commit
5ff883305e
@ -1,19 +1,11 @@
|
||||
#include "stdafx.h"
|
||||
#include "Board.h"
|
||||
|
||||
#include <Disassembler.h>
|
||||
|
||||
Board::Board(const Configuration& configuration)
|
||||
: m_configuration(configuration),
|
||||
m_cpu(EightBit::Z80(*this, m_ports)),
|
||||
m_disassembler(*this),
|
||||
m_profiler(m_cpu, m_disassembler) {
|
||||
}
|
||||
: m_configuration(configuration) {}
|
||||
|
||||
void Board::powerOn() {
|
||||
|
||||
EightBit::Bus::powerOn();
|
||||
|
||||
CPU().powerOn();
|
||||
CPU().reset();
|
||||
}
|
||||
@ -26,73 +18,56 @@ void Board::powerOff() {
|
||||
void Board::initialise() {
|
||||
|
||||
auto romDirectory = m_configuration.getRomDirectory();
|
||||
|
||||
//m_ram.load(romDirectory + "/prelim.com", 0x100); // Bartholomew preliminary
|
||||
//m_ram.load(romDirectory + "/zexdoc.com", 0x100); // Cringle/Bartholomew
|
||||
m_ram.load(romDirectory + "/zexall.com", 0x100); // Cringle/Bartholomew
|
||||
//m_ram.load(romDirectory + "/CPUTEST.COM", 0x100); // SuperSoft diagnostics
|
||||
|
||||
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Cpm, this, std::placeholders::_1));
|
||||
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(std::bind(&Board::Cpu_ExecutingInstruction_Profile, this, std::placeholders::_1));
|
||||
}
|
||||
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(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
||||
}
|
||||
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;
|
||||
});
|
||||
|
||||
poke(0, 0xc3); // JMP
|
||||
CPU().pokeWord(1, m_configuration.getStartAddress());
|
||||
poke(5, 0xc9); // ret
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Cpm(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;
|
||||
}
|
||||
}
|
||||
|
||||
void Board::bdos() {
|
||||
switch (CPU().C()) {
|
||||
case 0x2:
|
||||
std::cout << CPU().E();
|
||||
break;
|
||||
case 0x9:
|
||||
for (uint16_t i = CPU().DE().word; peek(i) != '$'; ++i) {
|
||||
for (uint16_t i = CPU().DE().word; peek(i) != '$'; ++i)
|
||||
std::cout << peek(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Profile(EightBit::Z80& cpu) {
|
||||
|
||||
const auto pc = cpu.PC();
|
||||
|
||||
m_profiler.addAddress(pc.word);
|
||||
m_profiler.addInstruction(peek(pc));
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Debug(EightBit::Z80& cpu) {
|
||||
|
||||
std::cerr
|
||||
<< EightBit::Disassembler::state(cpu)
|
||||
<< "\t"
|
||||
<< m_disassembler.disassemble(cpu)
|
||||
<< std::endl;
|
||||
}
|
||||
|
@ -31,15 +31,10 @@ private:
|
||||
const Configuration& m_configuration;
|
||||
EightBit::Ram m_ram = 0x10000;
|
||||
EightBit::InputOutput m_ports;
|
||||
EightBit::Z80 m_cpu;
|
||||
EightBit::Disassembler m_disassembler;
|
||||
EightBit::Profiler m_profiler;
|
||||
EightBit::Z80 m_cpu = { *this, m_ports };
|
||||
EightBit::Disassembler m_disassembler = *this;
|
||||
EightBit::Profiler m_profiler = { m_cpu, m_disassembler };
|
||||
int m_warmstartCount = 0;
|
||||
|
||||
void Cpu_ExecutingInstruction_Cpm(EightBit::Z80& cpu);
|
||||
|
||||
void Cpu_ExecutingInstruction_Debug(EightBit::Z80& cpu);
|
||||
void Cpu_ExecutingInstruction_Profile(EightBit::Z80& cpu);
|
||||
|
||||
void bdos();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user