2019-10-11 00:54:29 +00:00
|
|
|
//
|
|
|
|
// 6850.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 10/10/2019.
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Motorola_ACIA_6850_hpp
|
|
|
|
#define Motorola_ACIA_6850_hpp
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
2019-11-09 20:00:12 +00:00
|
|
|
#include "../../ClockReceiver/ForceInline.hpp"
|
2019-10-13 03:46:57 +00:00
|
|
|
#include "../../ClockReceiver/ClockingHintSource.hpp"
|
2019-11-09 20:21:51 +00:00
|
|
|
#include "../Serial/Line.hpp"
|
2019-10-11 00:54:29 +00:00
|
|
|
|
|
|
|
namespace Motorola {
|
|
|
|
namespace ACIA {
|
|
|
|
|
2019-10-21 03:34:30 +00:00
|
|
|
class ACIA: public ClockingHint::Source, private Serial::Line::ReadDelegate {
|
2019-10-11 00:54:29 +00:00
|
|
|
public:
|
2019-10-14 01:32:34 +00:00
|
|
|
static constexpr const HalfCycles SameAsTransmit = HalfCycles(0);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Constructs a new instance of ACIA which will receive a transmission clock at a rate of
|
|
|
|
@c transmit_clock_rate, and a receive clock at a rate of @c receive_clock_rate.
|
|
|
|
*/
|
|
|
|
ACIA(HalfCycles transmit_clock_rate, HalfCycles receive_clock_rate = SameAsTransmit);
|
2019-10-13 03:14:29 +00:00
|
|
|
|
2019-10-12 04:04:02 +00:00
|
|
|
/*!
|
|
|
|
Reads from the ACIA.
|
|
|
|
|
|
|
|
Bit 0 of the address is used as the ACIA's register select line —
|
|
|
|
so even addresses select control/status registers, odd addresses
|
|
|
|
select transmit/receive data registers.
|
|
|
|
*/
|
2019-10-11 00:54:29 +00:00
|
|
|
uint8_t read(int address);
|
2019-10-12 04:04:02 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Writes to the ACIA.
|
|
|
|
|
|
|
|
Bit 0 of the address is used as the ACIA's register select line —
|
|
|
|
so even addresses select control/status registers, odd addresses
|
|
|
|
select transmit/receive data registers.
|
|
|
|
*/
|
2019-10-11 00:54:29 +00:00
|
|
|
void write(int address, uint8_t value);
|
|
|
|
|
2019-10-14 01:32:34 +00:00
|
|
|
/*!
|
|
|
|
Advances @c transmission_cycles in time, which should be
|
|
|
|
counted relative to the @c transmit_clock_rate.
|
|
|
|
*/
|
2019-11-09 20:00:12 +00:00
|
|
|
forceinline void run_for(HalfCycles transmission_cycles) {
|
|
|
|
if(transmit.transmission_data_time_remaining() > HalfCycles(0)) {
|
|
|
|
const auto write_data_time_remaining = transmit.write_data_time_remaining();
|
|
|
|
|
|
|
|
// There's at most one further byte available to enqueue, so a single 'if'
|
|
|
|
// rather than a 'while' is correct here. It's the responsibilit of the caller
|
|
|
|
// to ensure run_for lengths are appropriate for longer sequences.
|
|
|
|
if(transmission_cycles >= write_data_time_remaining) {
|
|
|
|
if(next_transmission_ != NoValueMask) {
|
|
|
|
transmit.advance_writer(write_data_time_remaining);
|
|
|
|
consider_transmission();
|
|
|
|
transmit.advance_writer(transmission_cycles - write_data_time_remaining);
|
|
|
|
} else {
|
|
|
|
transmit.advance_writer(transmission_cycles);
|
|
|
|
update_clocking_observer();
|
2019-11-12 02:49:02 +00:00
|
|
|
update_interrupt_line();
|
2019-11-09 20:00:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
transmit.advance_writer(transmission_cycles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-12 04:04:02 +00:00
|
|
|
|
2019-10-14 01:32:34 +00:00
|
|
|
bool get_interrupt_line() const;
|
2019-12-09 02:20:06 +00:00
|
|
|
void reset();
|
2019-10-13 03:46:57 +00:00
|
|
|
|
2019-10-13 03:14:29 +00:00
|
|
|
// Input lines.
|
|
|
|
Serial::Line receive;
|
|
|
|
Serial::Line clear_to_send;
|
|
|
|
Serial::Line data_carrier_detect;
|
|
|
|
|
|
|
|
// Output lines.
|
|
|
|
Serial::Line transmit;
|
|
|
|
Serial::Line request_to_send;
|
|
|
|
|
2019-10-21 02:10:05 +00:00
|
|
|
// ClockingHint::Source.
|
2020-05-10 01:22:51 +00:00
|
|
|
ClockingHint::Preference preferred_clocking() const final;
|
2019-10-21 02:10:05 +00:00
|
|
|
|
2019-10-22 02:40:38 +00:00
|
|
|
struct InterruptDelegate {
|
|
|
|
virtual void acia6850_did_change_interrupt_status(ACIA *acia) = 0;
|
|
|
|
};
|
|
|
|
void set_interrupt_delegate(InterruptDelegate *delegate);
|
|
|
|
|
2019-10-12 04:04:02 +00:00
|
|
|
private:
|
|
|
|
int divider_ = 1;
|
2019-10-12 22:19:55 +00:00
|
|
|
enum class Parity {
|
|
|
|
Even, Odd, None
|
|
|
|
} parity_ = Parity::None;
|
2019-10-13 03:14:29 +00:00
|
|
|
int data_bits_ = 7, stop_bits_ = 2;
|
|
|
|
|
2019-12-22 05:22:17 +00:00
|
|
|
static constexpr int NoValueMask = 0x100;
|
2019-10-22 00:10:19 +00:00
|
|
|
int next_transmission_ = NoValueMask;
|
|
|
|
int received_data_ = NoValueMask;
|
|
|
|
|
|
|
|
int bits_received_ = 0;
|
|
|
|
int bits_incoming_ = 0;
|
2019-12-09 02:20:06 +00:00
|
|
|
bool overran_ = false;
|
2019-10-14 03:04:57 +00:00
|
|
|
|
2019-10-13 03:14:29 +00:00
|
|
|
void consider_transmission();
|
2019-10-22 00:10:19 +00:00
|
|
|
int expected_bits();
|
|
|
|
uint8_t parity(uint8_t value);
|
2019-10-13 03:14:29 +00:00
|
|
|
|
2019-10-12 22:19:55 +00:00
|
|
|
bool receive_interrupt_enabled_ = false;
|
|
|
|
bool transmit_interrupt_enabled_ = false;
|
2019-10-13 03:46:57 +00:00
|
|
|
|
2019-10-14 01:32:34 +00:00
|
|
|
HalfCycles transmit_clock_rate_;
|
|
|
|
HalfCycles receive_clock_rate_;
|
2019-10-21 03:34:30 +00:00
|
|
|
|
|
|
|
bool serial_line_did_produce_bit(Serial::Line *line, int bit) final;
|
2019-10-22 02:40:38 +00:00
|
|
|
|
2019-11-12 02:49:02 +00:00
|
|
|
bool interrupt_line_ = false;
|
|
|
|
void update_interrupt_line();
|
2019-10-22 02:40:38 +00:00
|
|
|
InterruptDelegate *interrupt_delegate_ = nullptr;
|
2019-11-12 02:49:02 +00:00
|
|
|
uint8_t get_status();
|
2019-10-11 00:54:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Motorola_ACIA_6850_hpp */
|