1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-11-10 13:04:59 +00:00
r65emu/display.cpp

156 lines
3.3 KiB
C++
Raw Normal View History

2018-11-03 13:30:49 +00:00
#include <stdint.h>
#include "hardware.h"
#include "memory.h"
2023-07-25 13:10:35 +00:00
#include "display.h"
2018-11-03 13:30:49 +00:00
#if defined(USE_UTFT)
2020-07-08 13:33:31 +00:00
#pragma message "UTFT configured"
2018-11-03 13:30:49 +00:00
#include <UTFT.h>
#include "TinyFont.h"
2019-03-03 14:38:47 +00:00
#if !defined(TFT_SER)
#define TFT_SER 0
#endif
static UTFT utft(TFT_MODEL, TFT_RS, TFT_WR, TFT_CS, TFT_RST, TFT_SER);
2018-11-03 13:30:49 +00:00
#elif defined(USE_ESPI)
2021-02-27 13:32:49 +00:00
#pragma message "Configure TFT_eSPI in Makefile or <TFT_eSPI/User_Setup.h>"
2018-11-03 13:30:49 +00:00
#include <TFT_eSPI.h>
static TFT_eSPI espi;
2020-07-08 13:33:31 +00:00
2023-07-25 13:10:35 +00:00
#elif defined(USE_VGA)
#pragma message "FabGL VGA configured"
#include <fabgl.h>
static fabgl::VGAController vga;
static fabgl::Canvas canvas(&vga);
static const fabgl::RGB888 rgb(colour_t c) {
switch(c) {
case BLACK: return Color::Black;
2023-07-26 12:47:15 +00:00
case RED: return Color::Red;
2023-07-25 13:10:35 +00:00
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;
2023-07-26 12:47:15 +00:00
case WHITE: return Color::White;
2023-07-25 13:10:35 +00:00
}
2023-07-26 12:47:15 +00:00
return Color::BrightWhite;
2023-07-25 13:10:35 +00:00
}
2020-07-08 13:33:31 +00:00
#else
#pragma error "Display not configured!"
2018-11-03 13:30:49 +00:00
#endif
static inline void setColor(colour_t c) {
#if defined(USE_UTFT)
utft.setColor(c);
#elif defined(USE_ESPI)
espi.setTextColor(c);
2023-07-25 13:10:35 +00:00
#elif defined(USE_VGA)
canvas.setPenColor(rgb(c));
2018-11-03 13:30:49 +00:00
#endif
}
2023-07-25 13:10:35 +00:00
void Display::begin(unsigned bg, unsigned fg, orientation_t orient) {
2018-11-03 13:30:49 +00:00
_bg = bg;
_fg = fg;
#if defined(USE_UTFT)
utft.InitLCD(orient);
_dx = utft.getDisplayXSize();
_dy = utft.getDisplayYSize();
utft.setFont((uint8_t *)TinyFont);
_cx = utft.getFontXsize();
_cy = utft.getFontYsize();
2020-07-08 13:33:31 +00:00
2018-11-03 13:30:49 +00:00
#elif defined(USE_ESPI)
espi.init();
espi.setRotation(orient);
_dx = espi.width();
_dy = espi.height();
_cy = espi.fontHeight();
2018-11-12 22:18:44 +00:00
_cx = 6; // FIXME
2023-07-25 13:10:35 +00:00
#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();
2018-11-03 13:30:49 +00:00
#endif
setColor(fg);
_oxs = _dx;
}
2023-07-25 13:10:35 +00:00
void Display::clear() {
2018-11-03 13:30:49 +00:00
#if defined(USE_UTFT)
utft.fillScr(_bg);
#elif defined(USE_ESPI)
espi.fillScreen(_bg);
2023-07-25 13:10:35 +00:00
#elif defined(USE_VGA)
canvas.clear();
2018-11-03 13:30:49 +00:00
#endif
}
2023-07-25 13:10:35 +00:00
void Display::status(const char *s) {
2018-11-03 13:30:49 +00:00
setColor(_fg);
#if defined(USE_UTFT)
unsigned y = _dy - _cy, n = strlen(s), xs = _dx - n*_cx;
for (unsigned x = _oxs; x < xs; x += _cx)
utft.print(" ", x, y);
utft.print(s, xs, y);
_oxs = xs;
#elif defined(USE_ESPI)
2018-11-10 13:34:36 +00:00
espi.fillRect(_dx - _oxs, _dy - _cy, _oxs, _cy, _bg);
2018-11-03 13:30:49 +00:00
_oxs = espi.textWidth(s);
2018-11-10 13:34:36 +00:00
espi.setTextDatum(BR_DATUM);
espi.drawString(s, _dx, _dy);
2023-07-25 13:10:35 +00:00
#elif defined(USE_VGA)
canvas.fillRectangle(_dx - _oxs, _dy - _cy, _dx, _dy);
_oxs = canvas.textExtent(s) + _cx;
canvas.drawText(_dx - _oxs, _dy - _cy, s);
2018-11-03 13:30:49 +00:00
#endif
}
2023-07-25 13:10:35 +00:00
void Display::drawPixel(unsigned x, unsigned y, colour_t col) {
2018-11-03 13:30:49 +00:00
#if defined(USE_UTFT)
utft.setColor(col);
utft.drawPixel(x, y);
#elif defined(USE_ESPI)
2018-11-10 13:34:36 +00:00
espi.drawPixel(x, y, col);
2023-07-25 13:10:35 +00:00
#elif defined(USE_VGA)
canvas.setPixel(x, y, rgb(col));
2018-11-03 13:30:49 +00:00
#endif
}
2018-11-12 07:46:21 +00:00
2023-07-25 13:10:35 +00:00
void Display::drawString(const char *s, unsigned x, unsigned y) {
2018-11-12 07:46:21 +00:00
#if defined(USE_UTFT)
utft.print(s, x, y);
#elif defined(USE_ESPI)
2018-11-12 22:18:44 +00:00
espi.setTextDatum(TL_DATUM);
unsigned w = espi.textWidth(s);
espi.fillRect(x, y, w, _cy, _bg);
2018-11-12 07:46:21 +00:00
espi.drawString(s, x, y);
2023-07-25 13:10:35 +00:00
#elif defined(USE_VGA)
canvas.drawText(x, y, s);
2018-11-12 07:46:21 +00:00
#endif
}