| 1 |
#ifndef MC6850_HH |
| 2 |
#define MC6850_HH |
| 3 |
|
| 4 |
#include "MidiInConnector.hh" |
| 5 |
#include "MidiOutConnector.hh" |
| 6 |
|
| 7 |
#include "DynamicClock.hh" |
| 8 |
#include "IRQHelper.hh" |
| 9 |
#include "Schedulable.hh" |
| 10 |
|
| 11 |
#include "outer.hh" |
| 12 |
|
| 13 |
#include <cstdint> |
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
class Scheduler; |
| 18 |
|
| 19 |
class MC6850 final : public MidiInConnector |
| 20 |
{ |
| 21 |
public: |
| 22 |
MC6850(const std::string& name, MSXMotherBoard& motherBoard, unsigned clockFreq); |
| 23 |
void reset(EmuTime time); |
| 24 |
|
| 25 |
[[nodiscard]] uint8_t readStatusReg() const; |
| 26 |
[[nodiscard]] uint8_t peekStatusReg() const; |
| 27 |
[[nodiscard]] uint8_t readDataReg(); |
| 28 |
[[nodiscard]] uint8_t peekDataReg() const; |
| 29 |
void writeControlReg(uint8_t value, EmuTime time); |
| 30 |
void writeDataReg (uint8_t value, EmuTime time); |
| 31 |
|
| 32 |
template<typename Archive> |
| 33 |
void serialize(Archive& ar, unsigned version); |
| 34 |
|
| 35 |
private: |
| 36 |
void setDataFormat(); |
| 37 |
|
| 38 |
|
| 39 |
[[nodiscard]] bool ready() override; |
| 40 |
[[nodiscard]] bool acceptsData() override; |
| 41 |
void setDataBits(DataBits bits) override; |
| 42 |
void setStopBits(StopBits bits) override; |
| 43 |
void setParityBit(bool enable, Parity parity) override; |
| 44 |
void recvByte(uint8_t value, EmuTime time) override; |
| 45 |
|
| 46 |
|
| 47 |
struct SyncRecv final : Schedulable { |
| 48 |
friend class MC6850; |
| 49 |
explicit SyncRecv(Scheduler& s) : Schedulable(s) {} |
| 50 |
void executeUntil(EmuTime time) override { |
| 51 |
auto& mc6850 = OUTER(MC6850, syncRecv); |
| 52 |
mc6850.execRecv(time); |
| 53 |
} |
| 54 |
} syncRecv; |
| 55 |
struct SyncTrans final : Schedulable { |
| 56 |
friend class MC6850; |
| 57 |
explicit SyncTrans(Scheduler& s) : Schedulable(s) {} |
| 58 |
void executeUntil(EmuTime time) override { |
| 59 |
auto& mc6850 = OUTER(MC6850, syncTrans); |
| 60 |
mc6850.execTrans(time); |
| 61 |
} |
| 62 |
} syncTrans; |
| 63 |
void execRecv (EmuTime time); |
| 64 |
void execTrans(EmuTime time); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
DynamicClock txClock{EmuTime::zero()}; |
| 69 |
const unsigned clockFreq; |
| 70 |
|
| 71 |
IRQHelper rxIRQ; |
| 72 |
IRQHelper txIRQ; |
| 73 |
bool rxReady; |
| 74 |
bool txShiftRegValid; |
| 75 |
bool pendingOVRN; |
| 76 |
uint8_t rxDataReg; |
| 77 |
uint8_t txDataReg = 0; |
| 78 |
uint8_t txShiftReg = 0; |
| 79 |
uint8_t controlReg; |
| 80 |
uint8_t statusReg; |
| 81 |
uint8_t charLen; |
| 82 |
|
| 83 |
MidiOutConnector outConnector; |
| 84 |
}; |
| 85 |
SERIALIZE_CLASS_VERSION(MC6850, 3); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
#endif |