mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-09-28 08:54:53 +00:00
9ab075d0f6
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
84 lines
3.4 KiB
C++
84 lines
3.4 KiB
C++
#include "pch.h"
|
||
#include "MC6850.h"
|
||
|
||
#include <cassert>
|
||
|
||
bool EightBit::mc6850::selected() {
|
||
return
|
||
(CS0() == PinLevel::High)
|
||
&& (CS1() == PinLevel::High)
|
||
&& (CS2() == PinLevel::Low);
|
||
}
|
||
|
||
void EightBit::mc6850::reset() {
|
||
if (!m_powered)
|
||
IRQ() = RTS() = PinLevel::High;
|
||
status() = 0;
|
||
m_powered = true;
|
||
}
|
||
|
||
void EightBit::mc6850::step(int cycles) {
|
||
for (int i = 0; i < cycles; ++i)
|
||
step();
|
||
}
|
||
|
||
void EightBit::mc6850::step() {
|
||
|
||
if (!(powered() && selected()))
|
||
return;
|
||
|
||
Accessing.fire(EventArgs::empty());
|
||
|
||
const bool writing = RW() == PinLevel::Low;
|
||
const bool reading = !writing;
|
||
|
||
const bool registers = RS() == PinLevel::Low;
|
||
const bool transferring = !registers;
|
||
|
||
if (registers) {
|
||
if (writing) {
|
||
m_counterDivide = DATA() && (CR0 | CR1);
|
||
const bool masterReset = m_counterDivide == 0b11;
|
||
if (masterReset) {
|
||
reset();
|
||
} else {
|
||
m_wordConfiguration = (DATA() && (CR2 | CR3 | CR4)) >> 2;
|
||
m_transmitterControl = (DATA() && (CR5 | CR6)) >> 5;
|
||
m_receiveControl = (DATA() && CR7) >> 7;
|
||
}
|
||
} else {
|
||
DATA() = status();
|
||
}
|
||
} else {
|
||
IRQ() = PinLevel::High;
|
||
if (writing)
|
||
fillTDR();
|
||
else
|
||
drainRDR();
|
||
}
|
||
|
||
Accessed.fire(EventArgs::empty());
|
||
}
|
||
|
||
void EightBit::mc6850::fillRDR() {
|
||
Receiving.fire(EventArgs::empty());
|
||
RDR() = DATA();
|
||
Processor::setFlag(status(), RDRF, true);
|
||
}
|
||
|
||
void EightBit::mc6850::drainRDR() {
|
||
Processor::setFlag(status(), RDRF, false);
|
||
DATA() = RDR();
|
||
Received.fire(EventArgs::empty());
|
||
}
|
||
|
||
void EightBit::mc6850::fillTDR() {
|
||
Transmitting.fire(EventArgs::empty());
|
||
TDR() = DATA();
|
||
}
|
||
|
||
void EightBit::mc6850::drainTDR() {
|
||
DATA() = TDR();
|
||
Transmitted.fire(EventArgs::empty());
|
||
}
|