diff --git a/Makefile b/Makefile index 2bb0999..1dcf012 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ t ?= esp32 TERMINAL_SPEED := 115200 CPPFLAGS = -Wall -DDEBUGGING -DCPU_DEBUG=false -DTERMINAL_SPEED=$(TERMINAL_SPEED) -DUSE_OWN_KBD -LIBRARIES = PS2KeyAdvanced PS2KeyMap +LIBRARIES = PS2KeyAdvanced PS2KeyMap SimpleTimer ifeq ($t, esp8266) BOARD := d1_mini @@ -11,7 +11,7 @@ EESZ := 4M1M F_CPU := 80 CPPFLAGS += -DUSER_SETUP_LOADED -DILI9341_DRIVER -DTFT_CS=PIN_D8 -DTFT_DC=PIN_D1 \ -DTFT_RST=-1 -DSPI_FREQUENCY=40000000 -DLOAD_GLCD \ - -DHARDWARE_H=\"hw/esp8bit.h\" -DPS2_SERIAL_KBD=\"UK\" + -DHARDWARE_H=\"hw/esp8bit.h\" LIBRARIES += TFT_eSPI SpiRAM LittleFS endif diff --git a/io.cpp b/io.cpp index 95e81aa..2671562 100644 --- a/io.cpp +++ b/io.cpp @@ -6,23 +6,24 @@ #include #include #include -#include +#include #include "io.h" #include "disp.h" -#include "hardware.h" #include "config.h" void io::reset() { + _loading = false; _dsp.reset(); _kbd.reset(); - - _loading = false; - PIA::reset(); + _pia.reset(); + _ch = 0; } bool io::start() { - + hardware_interval_timer(10, [this]() { poll(); }); + _pia.register_portb_write_handler([this](uint8_t b) { _dsp.write(b & 0x7f); }); + _pia.register_porta_read_handler([this]() { uint8_t c = _ch; _ch = 0; return c; }); return files.start(); } @@ -34,18 +35,15 @@ void io::load() { } void io::enter(uint8_t key) { - PIA::write_ca1(false); - PIA::write_porta_in(key + 0x80); - PIA::write_ca1(true); + _pia.write_ca1(false); + _ch = key | 0x80; + _pia.write_ca1(true); } -void io::write_portb(uint8_t b) { - b &= 0x7f; - _dsp.write(b); - PIA::write_portb(b); -} +void io::poll() { + if (_ch) + return; -uint8_t io::read_cra() { if (_loading) { if (files.more()) enter(files.read()); @@ -56,16 +54,14 @@ uint8_t io::read_cra() { if (c != -1) enter(c); } - - return PIA::read_cra(); } void io::checkpoint(Stream &s) { - PIA::checkpoint(s); + _pia.checkpoint(s); _dsp.checkpoint(s); } void io::restore(Stream &s) { - PIA::restore(s); + _pia.restore(s); _dsp.restore(s); } diff --git a/io.h b/io.h index 3b82852..58a7006 100644 --- a/io.h +++ b/io.h @@ -1,10 +1,9 @@ -#ifndef _IO_H -#define _IO_H +#pragma once class serial_kbd; class disp; -class io: public Memory::Device, public PIA { +class io: public Memory::Device { public: io(filer &files, serial_kbd &kbd, disp &dsp): Memory::Device(Memory::page_size), files(files), _kbd(kbd), _dsp(dsp) {} @@ -12,24 +11,22 @@ public: void reset(); bool start(); - void operator=(uint8_t b) { PIA::write(_acc, b); } - operator uint8_t() { return PIA::read(_acc); } + void operator=(uint8_t b) { _pia.write(_acc, b); } + operator uint8_t() { return _pia.read(_acc); } void checkpoint(Stream &); void restore(Stream &); - void write_portb(uint8_t); - uint8_t read_cra(); - + void poll(); void load(); filer &files; private: + PIA _pia; serial_kbd &_kbd; disp &_dsp; void enter(uint8_t); bool _loading; + uint8_t _ch; }; - -#endif diff --git a/screen_disp.cpp b/screen_disp.cpp index 1dc9d0d..e60d51f 100644 --- a/screen_disp.cpp +++ b/screen_disp.cpp @@ -2,29 +2,23 @@ #include #include #include -#include #include #include "disp.h" #include "screen_disp.h" #include "config.h" -static screen_disp *i; - -const int TICK_FREQ = 2; - -void IRAM_ATTR screen_disp::on_tick() { - - static int tick = 0; - tick = (tick + 1) % 3; - i->cursor(tick < 2); -} - void screen_disp::reset() { - if (!i) { - i = this; - timer_create(TICK_FREQ, on_tick); + static bool first_time = true; + + if (first_time) { + hardware_interval_timer(500, [this]() { + static int tick = 0; + tick = (tick + 1) % 3; + cursor(tick < 2); + }); + first_time = false; } Display::begin(BG_COLOUR, FG_COLOUR, ORIENT); diff --git a/screen_disp.h b/screen_disp.h index 2a5181a..787552e 100644 --- a/screen_disp.h +++ b/screen_disp.h @@ -11,12 +11,8 @@ public: void write(uint8_t); void status(const char *s) { Display::status(s); } -protected: - static void on_tick(); - - void cursor(bool on); - private: + void cursor(bool on); void draw(char, int, int); static const uint8_t ROWS = 24;