From 072c15ff3308920c30ebceeca4f0519298bce719 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 19 Jul 2024 11:40:49 +0100 Subject: [PATCH] refactor ACIA + allow compile with no hw def --- acia.cpp | 31 +++++++++++-------------------- acia.h | 12 +++++------- display.cpp | 3 +-- hardware.cpp | 4 ++++ hw/user.h | 2 +- serialio.h | 2 +- 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/acia.cpp b/acia.cpp index 856f8fc..cf008be 100644 --- a/acia.cpp +++ b/acia.cpp @@ -1,4 +1,4 @@ -#include +#include #include "memory.h" #include "serialio.h" @@ -13,40 +13,35 @@ void ACIA::write(Memory::address a, uint8_t b) { void ACIA::write_control(uint8_t b) { if ((b & cd_mask) == reset) { - _serial->reset(); + acia_reset(); return; } switch (b & ws_mask) { case ws7e2: - _serial->framing(7, 2, even); + acia_framing(SERIAL_7E2); break; case ws7o2: - _serial->framing(7, 2, odd); + acia_framing(SERIAL_7O2); break; case ws7e1: - _serial->framing(7, 1, even); + acia_framing(SERIAL_7E1); break; case ws7o1: - _serial->framing(7, 1, odd); + acia_framing(SERIAL_7O1); break; case ws8n2: - _serial->framing(8, 2, none); + acia_framing(SERIAL_8N2); break; case ws8n1: - _serial->framing(8, 1, none); + acia_framing(SERIAL_8N1); break; case ws8e1: - _serial->framing(8, 1, even); + acia_framing(SERIAL_8E1); break; case ws8o1: - _serial->framing(8, 1, odd); + acia_framing(SERIAL_8O1); break; }; - // FIXME: more -} - -void ACIA::write_data(uint8_t b) { - _serial->write(b); } uint8_t ACIA::read(Memory::address a) { @@ -57,10 +52,6 @@ uint8_t ACIA::read(Memory::address a) { return 0; } -uint8_t ACIA::read_data() { - return _serial->read(); -} - uint8_t ACIA::read_status() { - return _serial->more()? rdrf | tdre: tdre; + return acia_more()? rdrf | tdre: tdre; } diff --git a/acia.h b/acia.h index 960824e..4de42a1 100644 --- a/acia.h +++ b/acia.h @@ -8,8 +8,7 @@ public: void write(Memory::address, uint8_t); uint8_t read(Memory::address); - ACIA(serialio &s): _serial(&s) {} - void set_device(serialio *s) { _serial = s; } + virtual void acia_reset() {} // status bits // @@ -51,11 +50,10 @@ public: protected: // overrideable device memory interface virtual uint8_t read_status(); - virtual uint8_t read_data(); + virtual uint8_t read_data() = 0; virtual void write_control(uint8_t); - virtual void write_data(uint8_t); - -private: - serialio *_serial; + virtual void write_data(uint8_t) = 0; + virtual void acia_framing(uint32_t config) {} + virtual bool acia_more() = 0; }; #endif diff --git a/display.cpp b/display.cpp index 64c483f..859353f 100644 --- a/display.cpp +++ b/display.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include "hardware.h" #include "memory.h" #include "display.h" diff --git a/hardware.cpp b/hardware.cpp index cad907f..76f5b5e 100644 --- a/hardware.cpp +++ b/hardware.cpp @@ -1,6 +1,10 @@ +#include +#include #include "hardware.h" +#if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_LITTLEFS) || defined(USE_SPIRAM) #include +#endif #if defined(USE_SD) #include diff --git a/hw/user.h b/hw/user.h index 5431d0d..5c3e358 100644 --- a/hw/user.h +++ b/hw/user.h @@ -1,3 +1,3 @@ // user-configured hardware description -#error "hw/user.h not configured!" +#warning "hw/user.h not configured!" diff --git a/serialio.h b/serialio.h index 07337a9..56a3ae8 100644 --- a/serialio.h +++ b/serialio.h @@ -10,7 +10,7 @@ enum parity { class serialio { public: virtual void reset() {} - virtual void framing(unsigned data_bits, unsigned stop_bits, parity p) {} + virtual void framing(uint32_t) {} virtual void write(uint8_t) {} virtual uint8_t read() =0;