12static constexpr unsigned STAT_TXRDY = 0x01;
13static constexpr unsigned STAT_RXRDY = 0x02;
14static constexpr unsigned STAT_OE = 0x10;
15static constexpr unsigned STAT_FE = 0x20;
18static constexpr unsigned CMD_TXEN = 0x01;
19static constexpr unsigned CMD_TXIE = 0x02;
20static constexpr unsigned CMD_RXEN = 0x04;
21static constexpr unsigned CMD_RXIE = 0x08;
22static constexpr unsigned CMD_ER = 0x10;
23static constexpr unsigned CMD_IR = 0x80;
29static constexpr auto CHAR_DURATION = BIT_DURATION * 10;
32 :
MidiInConnector(motherBoard.getPluggingController(), name_ +
"-MIDI-in")
33 , syncRecv (motherBoard.getScheduler())
34 , syncTrans(motherBoard.getScheduler())
35 , rxIRQ(motherBoard, name_ +
"-rx-IRQ")
36 , txIRQ(motherBoard, name_ +
"-tx-IRQ")
37 , outConnector(motherBoard.getPluggingController(), name_ +
"-MIDI-out")
44 syncRecv .removeSyncPoint();
45 syncTrans.removeSyncPoint();
55void YM2148::recvByte(
byte value, EmuTime::param time)
57 assert(acceptsData() && ready());
59 if (status & STAT_RXRDY) {
68 if (commandReg & CMD_RXIE) rxIRQ.
set();
73 syncRecv.setSyncPoint(time + CHAR_DURATION);
77void YM2148::execRecv(EmuTime::param time)
79 assert(commandReg & CMD_RXEN);
92bool YM2148::acceptsData()
94 return (commandReg & CMD_RXEN) != 0;
99void YM2148::setDataBits(DataBits )
103void YM2148::setStopBits(StopBits )
107void YM2148::setParityBit(
bool , Parity )
125 status &=
byte(~STAT_RXRDY);
137 if (value & CMD_IR) {
141 if (value & CMD_ER) {
142 status &=
byte(~(STAT_OE | STAT_FE));
146 byte diff = commandReg ^ value;
149 if (diff & CMD_RXEN) {
150 if (commandReg & CMD_RXEN) {
156 syncRecv.removeSyncPoint();
157 status &=
byte(~STAT_RXRDY);
160 if (diff & CMD_TXEN) {
161 if (commandReg & CMD_TXEN) {
163 status |= STAT_TXRDY;
167 status &=
byte(~STAT_TXRDY);
168 syncTrans.removeSyncPoint();
173 rxIRQ.
set((value & CMD_RXIE) && (status & STAT_RXRDY));
174 txIRQ.
set((value & CMD_TXIE) && (status & STAT_TXRDY));
180 if (!(commandReg & CMD_TXEN))
return;
182 if (syncTrans.pendingSyncPoint()) {
186 status &=
byte(~STAT_TXRDY);
196void YM2148::send(
byte value, EmuTime::param time)
199 syncTrans.setSyncPoint(time + CHAR_DURATION);
203void YM2148::execTrans(EmuTime::param time)
205 assert(commandReg & CMD_TXEN);
207 outConnector.
recvByte(txBuffer1, time);
209 if (status & STAT_TXRDY) {
214 status |= STAT_TXRDY;
215 if (commandReg & CMD_TXIE) txIRQ.
set();
216 send(txBuffer2, time);
226template<
typename Archive>
229 if (ar.versionAtLeast(version, 2)) {
230 ar.template serializeBase<MidiInConnector>(*
this);
231 ar.serialize(
"outConnector", outConnector,
233 "syncRecv", syncRecv,
234 "syncTrans", syncTrans,
240 "rxBuffer", rxBuffer,
241 "txBuffer1", txBuffer1,
242 "txBuffer2", txBuffer2,
244 "commandReg", commandReg);
static constexpr EmuDuration hz(unsigned x)
void set()
Set the interrupt request on the bus.
void reset()
Reset the interrupt request on the bus.
bool getState() const
Get the interrupt state.
MidiInDevice & getPluggedMidiInDev() const
virtual void signal(EmuTime::param time)=0
void recvByte(byte value, EmuTime::param time) override
byte readData(EmuTime::param time)
void writeCommand(byte value)
YM2148(const std::string &name, MSXMotherBoard &motherBoard)
void serialize(Archive &ar, unsigned version)
byte peekData(EmuTime::param time) const
byte readStatus(EmuTime::param time) const
byte peekStatus(EmuTime::param time) const
void writeData(byte value, EmuTime::param time)
This file implemented 3 utility functions:
uint8_t byte
8 bit unsigned integer
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)