From 3e908415008db1cfe090bb12956c406a59bb28c8 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Wed, 27 Sep 2023 15:38:16 +0100 Subject: [PATCH] acia updates (#22) --- acia.cpp | 48 ++++++++++++++++++++++++++++++------------------ acia.h | 11 +++++++++-- timed.h | 4 ++++ 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/acia.cpp b/acia.cpp index bfd9ab1..5555ab6 100644 --- a/acia.cpp +++ b/acia.cpp @@ -5,46 +5,58 @@ #include "acia.h" void ACIA::write(Memory::address a, uint8_t b) { - if (a & 1) { - _device->write(b); - return; - } + if (a & 1) + write_data(b); + else + write_control(b); +} + +void ACIA::write_control(uint8_t b) { if ((b & cd_mask) == reset) { - _device->reset(); + _serial->reset(); return; } switch (b & ws_mask) { case ws7e2: - _device->framing(7, 2, even); + _serial->framing(7, 2, even); break; case ws7o2: - _device->framing(7, 2, odd); + _serial->framing(7, 2, odd); break; case ws7e1: - _device->framing(7, 1, even); + _serial->framing(7, 1, even); break; case ws7o1: - _device->framing(7, 1, odd); + _serial->framing(7, 1, odd); break; case ws8n2: - _device->framing(8, 2, none); + _serial->framing(8, 2, none); break; case ws8n1: - _device->framing(8, 1, none); + _serial->framing(8, 1, none); break; case ws8e1: - _device->framing(8, 1, even); + _serial->framing(8, 1, even); break; case ws8o1: - _device->framing(8, 1, odd); + _serial->framing(8, 1, odd); break; }; // FIXME: more } -uint8_t ACIA::read(Memory::address a) { - if (a & 1) - return _device->read(); - - return _device->more()? rdrf | tdre: tdre; +void ACIA::write_data(uint8_t b) { + _serial->write(b); +} + +uint8_t ACIA::read(Memory::address a) { + return (a & 1)? read_data(): read_status(); +} + +uint8_t ACIA::read_data() { + return _serial->read(); +} + +uint8_t ACIA::read_status() { + return _serial->more()? rdrf | tdre: tdre; } diff --git a/acia.h b/acia.h index b20cec9..96f7def 100644 --- a/acia.h +++ b/acia.h @@ -8,7 +8,7 @@ public: void write(Memory::address, uint8_t); uint8_t read(Memory::address); - ACIA(serialio &d): _device(&d) {} + ACIA(serialio &s): _serial(&s) {} // status bits // @@ -47,7 +47,14 @@ public: static const uint8_t eri = 1 << 7; // enable receive interrupt +protected: + // overrideable device memory interface + virtual uint8_t read_status(); + virtual uint8_t read_data(); + virtual void write_control(uint8_t); + virtual void write_data(uint8_t); + private: - class serialio *_device; + class serialio *_serial; }; #endif diff --git a/timed.h b/timed.h index 1d73720..246aadb 100644 --- a/timed.h +++ b/timed.h @@ -5,4 +5,8 @@ typedef void (*handler_t)(void); void timer_create(unsigned freq, handler_t handler); +#if !defined(ESP32) && !defined(ESP8266) +#define IRAM_ATTR +#endif + #endif