2018-08-26 18:09:34 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Board.h"
|
|
|
|
|
|
|
|
Board::Board(const Configuration& configuration)
|
2018-11-18 22:15:49 +00:00
|
|
|
: m_configuration(configuration) {}
|
2018-08-26 18:09:34 +00:00
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
void Board::raisePOWER() {
|
2018-08-26 18:09:34 +00:00
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
EightBit::Bus::raisePOWER();
|
2018-08-26 18:09:34 +00:00
|
|
|
|
2018-09-29 13:31:50 +00:00
|
|
|
// Get the CPU ready for action
|
2019-01-14 02:10:17 +00:00
|
|
|
CPU().raisePOWER();
|
|
|
|
CPU().lowerRESET();
|
|
|
|
CPU().raiseINT();
|
|
|
|
CPU().raiseNMI();
|
|
|
|
CPU().raiseFIRQ();
|
|
|
|
CPU().raiseHALT();
|
2018-08-26 18:09:34 +00:00
|
|
|
|
2018-09-29 13:31:50 +00:00
|
|
|
// Get the ACIA ready for action
|
2018-10-20 21:54:10 +00:00
|
|
|
ADDRESS() = 0b1010000000000000;
|
2019-05-05 09:29:41 +00:00
|
|
|
DATA() = EightBit::mc6850::CR0 | EightBit::mc6850::CR1; // Master reset
|
2018-10-22 23:01:33 +00:00
|
|
|
ACIA().lower(ACIA().CTS());
|
2019-05-27 09:57:02 +00:00
|
|
|
ACIA().lower(ACIA().RW());
|
|
|
|
updateAciaPins();
|
2019-01-14 02:10:17 +00:00
|
|
|
ACIA().raisePOWER();
|
2018-10-27 20:58:23 +00:00
|
|
|
accessAcia();
|
2018-11-11 16:48:44 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
void Board::lowerPOWER() {
|
2021-04-07 20:35:33 +00:00
|
|
|
|
|
|
|
if (m_configuration.isProfileMode()) {
|
|
|
|
m_profiler.EmitLine.connect([this](EightBit::ProfileLineEventArgs line) {
|
|
|
|
std::cout << EightBit::Disassembly::dump_WordValue(line.address()) << " " << line.source() << std::endl;
|
|
|
|
});
|
|
|
|
m_profiler.Generate();
|
|
|
|
}
|
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
ACIA().lowerPOWER();
|
|
|
|
CPU().lowerPOWER();
|
|
|
|
EightBit::Bus::lowerPOWER();
|
2018-11-11 16:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Board::initialise() {
|
|
|
|
|
|
|
|
// Load our BASIC interpreter
|
|
|
|
const auto directory = m_configuration.getRomDirectory() + "\\";
|
|
|
|
loadHexFile(directory + "ExBasROM.hex");
|
2018-09-29 13:31:50 +00:00
|
|
|
|
2018-11-18 22:15:49 +00:00
|
|
|
// Catch a byte being transmitted
|
|
|
|
ACIA().Transmitting.connect([this] (EightBit::EventArgs&) {
|
|
|
|
std::cout << ACIA().TDR();
|
|
|
|
ACIA().markTransmitComplete();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Marshal data from memory -> ACIA
|
|
|
|
WrittenByte.connect([this] (EightBit::EventArgs&) {
|
2019-05-27 09:57:02 +00:00
|
|
|
updateAciaPins();
|
2019-09-15 11:49:32 +00:00
|
|
|
if (ACIA().selected())
|
2018-11-18 22:15:49 +00:00
|
|
|
accessAcia();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Marshal data from ACIA -> memory
|
|
|
|
ReadingByte.connect([this] (EightBit::EventArgs&) {
|
2019-05-27 09:57:02 +00:00
|
|
|
updateAciaPins();
|
2018-11-18 22:15:49 +00:00
|
|
|
if (accessAcia())
|
|
|
|
poke(ACIA().DATA());
|
|
|
|
});
|
|
|
|
|
|
|
|
// Keyboard wiring, check for input once per frame
|
|
|
|
CPU().ExecutedInstruction.connect([this] (EightBit::mc6809& cpu) {
|
|
|
|
assert(cpu.cycles() > 0);
|
|
|
|
m_frameCycleCount -= cpu.cycles();
|
|
|
|
if (m_frameCycleCount < 0) {
|
|
|
|
if (_kbhit()) {
|
|
|
|
ACIA().RDR() = _getch();
|
|
|
|
ACIA().markReceiveStarting();
|
|
|
|
}
|
|
|
|
m_frameCycleCount = Configuration::FrameCycleInterval;
|
|
|
|
}
|
|
|
|
});
|
2018-09-23 12:14:10 +00:00
|
|
|
|
2021-04-07 20:35:33 +00:00
|
|
|
if (m_configuration.isProfileMode()) {
|
|
|
|
m_cpu.ExecutingInstruction.connect([this](EightBit::mc6809& cpu) {
|
|
|
|
m_profiler.addInstruction(peek(cpu.PC()));
|
|
|
|
});
|
|
|
|
m_cpu.ExecutedInstruction.connect([this](EightBit::mc6809& cpu) {
|
|
|
|
m_profiler.addAddress(cpu.PC().word, cpu.cycles());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-29 13:31:50 +00:00
|
|
|
if (m_configuration.isDebugMode()) {
|
2018-11-18 22:15:49 +00:00
|
|
|
// MC6809 disassembly wiring
|
|
|
|
CPU().ExecutingInstruction.connect([this] (EightBit::mc6809& cpu) {
|
|
|
|
m_disassembleAt = cpu.PC();
|
|
|
|
m_ignoreDisassembly = m_disassembler.ignore();
|
|
|
|
});
|
|
|
|
CPU().ExecutedInstruction.connect([this] (EightBit::mc6809&) {
|
|
|
|
if (!m_ignoreDisassembly)
|
|
|
|
std::cout << m_disassembler.trace(m_disassembleAt) << " " << ACIA().dumpStatus() << std::endl;
|
|
|
|
});
|
2018-09-29 13:31:50 +00:00
|
|
|
}
|
2018-08-26 18:09:34 +00:00
|
|
|
|
2018-11-18 22:15:49 +00:00
|
|
|
if (m_configuration.terminatesEarly()) {
|
|
|
|
// Early termination condition for CPU timing code
|
|
|
|
CPU().ExecutedInstruction.connect([this] (EightBit::mc6809& cpu) {
|
|
|
|
assert(cpu.cycles() > 0);
|
|
|
|
m_totalCycleCount += cpu.cycles();
|
|
|
|
if (m_totalCycleCount > Configuration::TerminationCycles)
|
2019-01-14 02:10:17 +00:00
|
|
|
lowerPOWER();
|
2018-11-18 22:15:49 +00:00
|
|
|
});
|
|
|
|
}
|
2018-09-20 23:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
EightBit::MemoryMapping Board::mapping(uint16_t address) noexcept {
|
2018-08-26 18:09:34 +00:00
|
|
|
|
|
|
|
if (address < 0x8000)
|
2018-12-01 15:24:29 +00:00
|
|
|
return { m_ram, 0x0000, EightBit::Chip::Mask16, EightBit::MemoryMapping::AccessLevel::ReadWrite };
|
2018-08-26 18:09:34 +00:00
|
|
|
|
2018-09-16 18:49:52 +00:00
|
|
|
if (address < 0xa000)
|
2018-12-01 15:24:29 +00:00
|
|
|
return { m_unused2000, 0x8000, EightBit::Chip::Mask16, EightBit::MemoryMapping::AccessLevel::ReadOnly };
|
2018-09-16 18:49:52 +00:00
|
|
|
|
2018-08-26 18:09:34 +00:00
|
|
|
if (address < 0xc000)
|
2018-12-01 15:24:29 +00:00
|
|
|
return { m_io, 0xa000, EightBit::Chip::Mask16, EightBit::MemoryMapping::AccessLevel::ReadWrite };
|
2018-08-26 18:09:34 +00:00
|
|
|
|
2018-12-01 15:24:29 +00:00
|
|
|
return { m_rom, 0xc000, EightBit::Chip::Mask16, EightBit::MemoryMapping::AccessLevel::ReadOnly };
|
2018-09-23 12:14:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
void Board::updateAciaPins() {
|
2018-09-23 12:14:10 +00:00
|
|
|
ACIA().DATA() = DATA();
|
2019-09-15 11:49:32 +00:00
|
|
|
EightBit::Device::match(ACIA().RW(), CPU().RW());
|
2019-06-02 11:12:04 +00:00
|
|
|
EightBit::Device::match(ACIA().RS(), ADDRESS().word & EightBit::Chip::Bit0);
|
|
|
|
EightBit::Device::match(ACIA().CS0(), ADDRESS().word & EightBit::Chip::Bit15);
|
|
|
|
EightBit::Device::match(ACIA().CS1(), ADDRESS().word & EightBit::Chip::Bit13);
|
|
|
|
EightBit::Device::match(ACIA().CS2(), ADDRESS().word & EightBit::Chip::Bit14);
|
2018-09-23 12:14:10 +00:00
|
|
|
}
|
|
|
|
|
2018-10-27 20:58:23 +00:00
|
|
|
bool Board::accessAcia() {
|
|
|
|
ACIA().raise(ACIA().E());
|
2019-05-05 09:29:41 +00:00
|
|
|
ACIA().tick();
|
2019-05-05 12:35:33 +00:00
|
|
|
const bool activated = ACIA().activated();
|
2018-10-27 20:58:23 +00:00
|
|
|
ACIA().lower(ACIA().E());
|
2019-05-05 12:35:33 +00:00
|
|
|
return activated;
|
2018-10-27 20:58:23 +00:00
|
|
|
}
|