FabGL
ESP32 Display Controller and Graphics Library
graphicsadapter.h
Go to the documentation of this file.
1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2022 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27#pragma once
28
29
38#include <stdlib.h>
39#include <stdint.h>
40
41#include "fabgl.h"
42
43
44
45namespace fabgl {
46
47
48
49class GraphicsAdapter {
50
51public:
52
53 enum class Emulation {
54 None,
55 PC_Text_40x25_16Colors, // CGA Color Text Mode (PC BIOS 00h/01h)
56 PC_Text_80x25_16Colors, // CGA Color Text Mode (PC BIOS 02h/03h) - not visually because use 640x400 screen with 8x16 fonts, while should be 640x200 with 8x8 fonts
57 PC_Graphics_320x200_4Colors, // CGA 320x200, 4 Colors Graphics Mode (PC BIOS 04h/05h)
58 PC_Graphics_640x200_2Colors, // CGA 640x200, 2 Colors Graphics Mode (PC BIOS 06h)
59 PC_Graphics_HGC_720x348, // Hercules 720x348 Graphics Black/White
60 };
61
62
63 GraphicsAdapter();
64 ~GraphicsAdapter();
65
66 void setEmulation(Emulation emulation);
67 Emulation emulation() { return m_emulation; }
68
69 bool enableVideo(bool value);
70
71 void setVideoBuffer(void const * videoBuffer);
72
73 // text modes methods
74 void setCursorShape(int start, int end);
75 void setCursorPos(int row, int column);
76 void setCursorVisible(bool value) { m_cursorVisible = value; }
77 void setBit7Blink(bool value) { m_bit7blink = value; }
78 int getTextColumns() { return m_columns; }
79 int getTextRows() { return m_rows; }
80
81 // PC graphics modes methods
82 void setPCGraphicsBackgroundColorIndex(int colorIndex);
83 void setPCGraphicsForegroundColorIndex(int colorIndex);
84 void setPCGraphicsPaletteInUse(int paletteIndex);
85 int getGraphWidth() { return m_VGADCtrl.getViewPortWidth(); }
86 int getGraphHeight() { return m_VGADCtrl.getViewPortHeight(); }
87
88 bool VSync() { return m_VGADCtrl.VSync(); }
89
90
91private:
92
93 void cleanupFont();
94
95 void freeLUT();
96 void setupLUT();
97
98 void setFont(FontInfo const * font);
99
100 void createCursorGlyph(int width, int height, int start, int end);
101
102 void setupEmulation(Emulation emulation);
103
104 static void drawScanline_PC_Text_80x25_16Colors(void * arg, uint8_t * dest, int scanLine);
105 static void drawScanline_PC_Text_40x25_16Colors(void * arg, uint8_t * dest, int scanLine);
106 static void drawScanline_PC_Graphics_320x200_4Colors(void * arg, uint8_t * dest, int scanLine);
107 static void drawScanline_PC_Graphics_640x200_2Colors(void * arg, uint8_t * dest, int scanLine);
108 static void drawScanline_PC_Graphics_HGC_720x348(void * arg, uint8_t * dest, int scanLine);
109
110
111 VGADirectController m_VGADCtrl;
112 Emulation m_emulation;
113 uint8_t const * m_videoBuffer;
114
115 uint8_t * m_rawLUT;
116
117 uint32_t m_frameCounter;
118
119 // text mode parameters
120 FontInfo m_font;
121 int16_t m_columns;
122 int16_t m_rows;
123 int16_t m_cursorRow;
124 int16_t m_cursorCol;
125 uint8_t m_cursorStart; // cursor shape scanline start
126 uint8_t m_cursorEnd; // cursor shape scanline end
127 bool m_cursorVisible;
128 uint8_t * m_cursorGlyph;
129 bool m_bit7blink;
130
131 // PC graphics parameters
132 int8_t m_PCGraphicsBackgroundColorIndex; // used as background color index on 320x200
133 int8_t m_PCGraphicsForegroundColorIndex; // used as foreground color index on 640x200
134 int8_t m_PCGraphicsPaletteInUse; // 0 = palette 0 low intensity, 1 = palette 0 high intensity, 2 = palette 1 low intensity, 3 = palette 2 high intensity
135
136 bool m_videoEnabled;
137
138};
139
140
141
142}; // fabgl namespace
uint8_t width
uint8_t height
This file is the all in one include file. Application can just include this file to use FabGL library...