r65emu/acia.cpp

67 lines
1.1 KiB
C++
Raw Permalink Normal View History

2018-09-13 10:24:05 +00:00
#include <stdint.h>
#include "memory.h"
2019-02-11 18:28:38 +00:00
#include "serialio.h"
2018-09-13 10:24:05 +00:00
#include "acia.h"
2023-09-27 10:27:45 +00:00
void ACIA::write(Memory::address a, uint8_t b) {
2023-09-27 14:38:16 +00:00
if (a & 1)
write_data(b);
else
write_control(b);
}
void ACIA::write_control(uint8_t b) {
2018-09-13 11:56:54 +00:00
if ((b & cd_mask) == reset) {
2023-09-27 14:38:16 +00:00
_serial->reset();
2018-09-13 11:56:54 +00:00
return;
}
switch (b & ws_mask) {
case ws7e2:
2023-09-27 14:38:16 +00:00
_serial->framing(7, 2, even);
2018-09-13 11:56:54 +00:00
break;
case ws7o2:
2023-09-27 14:38:16 +00:00
_serial->framing(7, 2, odd);
2018-09-13 11:56:54 +00:00
break;
case ws7e1:
2023-09-27 14:38:16 +00:00
_serial->framing(7, 1, even);
2018-09-13 11:56:54 +00:00
break;
case ws7o1:
2023-09-27 14:38:16 +00:00
_serial->framing(7, 1, odd);
2018-09-13 11:56:54 +00:00
break;
case ws8n2:
2023-09-27 14:38:16 +00:00
_serial->framing(8, 2, none);
2018-09-13 11:56:54 +00:00
break;
case ws8n1:
2023-09-27 14:38:16 +00:00
_serial->framing(8, 1, none);
2018-09-13 11:56:54 +00:00
break;
case ws8e1:
2023-09-27 14:38:16 +00:00
_serial->framing(8, 1, even);
2018-09-13 11:56:54 +00:00
break;
case ws8o1:
2023-09-27 14:38:16 +00:00
_serial->framing(8, 1, odd);
2018-09-13 11:56:54 +00:00
break;
};
2018-09-13 10:24:05 +00:00
// FIXME: more
}
2023-09-27 14:38:16 +00:00
void ACIA::write_data(uint8_t b) {
_serial->write(b);
}
2023-09-27 10:27:45 +00:00
uint8_t ACIA::read(Memory::address a) {
if (a == 0)
return read_status();
if (a == 1)
return read_data();
return 0;
2023-09-27 14:38:16 +00:00
}
uint8_t ACIA::read_data() {
return _serial->read();
}
2018-09-13 10:24:05 +00:00
2023-09-27 14:38:16 +00:00
uint8_t ACIA::read_status() {
return _serial->more()? rdrf | tdre: tdre;
2018-09-13 10:24:05 +00:00
}