diff --git a/tftdisplay.cpp b/display.cpp similarity index 53% rename from tftdisplay.cpp rename to display.cpp index db78ea9..e76bb50 100644 --- a/tftdisplay.cpp +++ b/display.cpp @@ -1,7 +1,7 @@ #include #include "hardware.h" #include "memory.h" -#include "tftdisplay.h" +#include "display.h" #if defined(USE_UTFT) #pragma message "UTFT configured" @@ -20,6 +20,27 @@ static UTFT utft(TFT_MODEL, TFT_RS, TFT_WR, TFT_CS, TFT_RST, TFT_SER); static TFT_eSPI espi; +#elif defined(USE_VGA) +#pragma message "FabGL VGA configured" +#include + +static fabgl::VGAController vga; +static fabgl::Canvas canvas(&vga); + +static const fabgl::RGB888 rgb(colour_t c) { + switch(c) { + case BLACK: return Color::Black; + case RED: return Color::Red; + case GREEN: return Color::Green; + case YELLOW: return Color::Yellow; + case BLUE: return Color::Blue; + case MAGENTA: return Color::Magenta; + case CYAN: return Color::Cyan; + case WHITE: return Color::White; + } + return Color::BrightWhite; +} + #else #pragma error "Display not configured!" #endif @@ -29,10 +50,12 @@ static inline void setColor(colour_t c) { utft.setColor(c); #elif defined(USE_ESPI) espi.setTextColor(c); +#elif defined(USE_VGA) + canvas.setPenColor(rgb(c)); #endif } -void TFTDisplay::begin(unsigned bg, unsigned fg, orientation_t orient) { +void Display::begin(unsigned bg, unsigned fg, orientation_t orient) { _bg = bg; _fg = fg; @@ -52,21 +75,41 @@ void TFTDisplay::begin(unsigned bg, unsigned fg, orientation_t orient) { _dy = espi.height(); _cy = espi.fontHeight(); _cx = 6; // FIXME + +#elif defined(USE_VGA) + static bool init; + + if (init) + vga.end(); + init = true; + vga.begin(); + vga.setResolution(VGA_480x300_75Hz); + + canvas.setBrushColor(rgb(_bg)); + canvas.clear(); + canvas.setGlyphOptions(GlyphOptions().FillBackground(true)); + canvas.selectFont(&fabgl::FONT_5x7); + _cy = canvas.getFontInfo()->height; + _cx = canvas.getFontInfo()->width; + _dx = canvas.getWidth(); + _dy = canvas.getHeight(); #endif setColor(fg); _oxs = _dx; } -void TFTDisplay::clear() { +void Display::clear() { #if defined(USE_UTFT) utft.fillScr(_bg); #elif defined(USE_ESPI) espi.fillScreen(_bg); +#elif defined(USE_VGA) + canvas.clear(); #endif } -void TFTDisplay::status(const char *s) { +void Display::status(const char *s) { setColor(_fg); #if defined(USE_UTFT) @@ -80,19 +123,25 @@ void TFTDisplay::status(const char *s) { _oxs = espi.textWidth(s); espi.setTextDatum(BR_DATUM); espi.drawString(s, _dx, _dy); +#elif defined(USE_VGA) + canvas.fillRectangle(_dx - _oxs, _dy - _cy, _dx, _dy); + _oxs = canvas.textExtent(s) + _cx; + canvas.drawText(_dx - _oxs, _dy - _cy, s); #endif } -void TFTDisplay::drawPixel(unsigned x, unsigned y, colour_t col) { +void Display::drawPixel(unsigned x, unsigned y, colour_t col) { #if defined(USE_UTFT) utft.setColor(col); utft.drawPixel(x, y); #elif defined(USE_ESPI) espi.drawPixel(x, y, col); +#elif defined(USE_VGA) + canvas.setPixel(x, y, rgb(col)); #endif } -void TFTDisplay::drawString(const char *s, unsigned x, unsigned y) { +void Display::drawString(const char *s, unsigned x, unsigned y) { #if defined(USE_UTFT) utft.print(s, x, y); #elif defined(USE_ESPI) @@ -100,5 +149,7 @@ void TFTDisplay::drawString(const char *s, unsigned x, unsigned y) { unsigned w = espi.textWidth(s); espi.fillRect(x, y, w, _cy, _bg); espi.drawString(s, x, y); +#elif defined(USE_VGA) + canvas.drawText(x, y, s); #endif } diff --git a/tftdisplay.h b/display.h similarity index 93% rename from tftdisplay.h rename to display.h index d319027..d6f9d13 100644 --- a/tftdisplay.h +++ b/display.h @@ -1,5 +1,5 @@ -#ifndef __TFTDISPLAY_H__ -#define __TFTDISPLAY_H__ +#ifndef __DISPLAY_H__ +#define __DISPLAY_H__ typedef enum { portrait, landscape, reverse_portrait, reverse_landscape @@ -27,7 +27,7 @@ const colour_t ORANGE = 0xFDA0; const colour_t GREENYELLOW = 0xB7E0; const colour_t PINK = 0xFC9F; -class TFTDisplay { +class Display { public: void begin(colour_t bg, colour_t fg, orientation_t o = landscape); void clear(); diff --git a/hw/lilygo-vga32.h b/hw/lilygo-vga32.h new file mode 100644 index 0000000..44a9668 --- /dev/null +++ b/hw/lilygo-vga32.h @@ -0,0 +1,22 @@ +// LilyGO TTGO VGA32 + +#define USE_VGA + +#define USE_KBD +#define KBD_DATA 32 +#define KBD_IRQ 33 + +#define RAM_SIZE 0x10000u + +// sound: dac and pwm +#define DAC_SOUND 25 + +// PWM doesn't work +// "assert failed: ledc_clk_cfg_to_global_clk ledc.c:443 (false)" +//#define PWM_SOUND 25 +//#define PWM_DUTY 20 // 20/1024 -> volume + +// "tape" storage... +#undef USE_SD +#undef USE_FS +#define USE_SPIFFS diff --git a/r65emu.h b/r65emu.h index 5114cf9..b66a853 100644 --- a/r65emu.h +++ b/r65emu.h @@ -7,7 +7,7 @@ #include "spiram.h" #include "prom.h" #include "ps2drv.h" -#include "tftdisplay.h" +#include "display.h" #include "keyboard.h" #include "serialio.h" #include "filer.h"