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-2021 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. Feel free to use FabGL in free software and hardware:
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 namespace fabgl {
45 
46 
47 class GraphicsAdapter {
48 
49 public:
50 
51  enum class Emulation {
52  None,
53  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
54  PC_Text_40x25_16Colors, // CGA Color Text Mode (PC BIOS 00h/01h)
55  PC_Graphics_320x200_4Colors, // CGA 320x200, 4 Colors Graphics Mode (PC BIOS 04h/05h)
56  PC_Graphics_640x200_2Colors, // CGA 640x200, 2 Colors Graphics Mode (PC BIOS 06h)
57  PC_Graphics_HGC_720x348, // Hercules 720x348 Graphics Black/White
58  };
59 
60 
61  GraphicsAdapter();
62  ~GraphicsAdapter();
63 
64  void setEmulation(Emulation emulation);
65  Emulation emulation() { return m_emulation; }
66 
67  void setVideoBuffer(void const * videoBuffer);
68 
69  // text modes methods
70  void setCursorShape(int start, int end);
71  void setCursorPos(int row, int column);
72  void setCursorVisible(bool value) { m_cursorVisible = value; }
73  void setBit7Blink(bool value) { m_bit7blink = value; }
74  int getTextColumns() { return m_columns; }
75  int getTextRows() { return m_rows; }
76 
77  // PC graphics modes methods
78  void setPCGraphicsBackgroundColorIndex(int colorIndex);
79  void setPCGraphicsForegroundColorIndex(int colorIndex);
80  void setPCGraphicsPaletteInUse(int paletteIndex);
81  int getGraphWidth() { return m_VGADCtrl.getViewPortWidth(); }
82  int getGraphHeight() { return m_VGADCtrl.getViewPortHeight(); }
83 
84  bool VSync() { return m_VGADCtrl.VSync(); }
85 
86 
87 private:
88 
89  void cleanupFont();
90 
91  void freeLUT();
92  void setupLUT();
93 
94  void setFont(FontInfo const * font);
95 
96  void createCursorGlyph(int width, int height, int start, int end);
97 
98  static void drawScanline_PC_Text_80x25_16Colors(void * arg, uint8_t * dest, int scanLine);
99  static void drawScanline_PC_Text_40x25_16Colors(void * arg, uint8_t * dest, int scanLine);
100  static void drawScanline_PC_Graphics_320x200_4Colors(void * arg, uint8_t * dest, int scanLine);
101  static void drawScanline_PC_Graphics_640x200_2Colors(void * arg, uint8_t * dest, int scanLine);
102  static void drawScanline_PC_Graphics_HGC_720x348(void * arg, uint8_t * dest, int scanLine);
103 
104 
105  VGADirectController m_VGADCtrl;
106  Emulation m_emulation;
107  uint8_t const * m_videoBuffer;
108 
109  uint8_t * m_rawLUT;
110 
111  uint32_t m_frameCounter;
112 
113  // text mode parameters
114  FontInfo m_font;
115  int16_t m_columns;
116  int16_t m_rows;
117  int16_t m_cursorRow;
118  int16_t m_cursorCol;
119  uint8_t m_cursorStart; // cursor shape scanline start
120  uint8_t m_cursorEnd; // cursor shape scanline end
121  bool m_cursorVisible;
122  uint8_t * m_cursorGlyph;
123  bool m_bit7blink;
124 
125  // PC graphics parameters
126  int8_t m_PCGraphicsBackgroundColorIndex; // used as background color index on 320x200
127  int8_t m_PCGraphicsForegroundColorIndex; // used as foreground color index on 640x200
128  int8_t m_PCGraphicsPaletteInUse; // 0 = palette 0 low intensity, 1 = palette 0 high intensity, 2 = palette 1 low intensity, 3 = palette 2 high intensity
129 
130 };
131 
132 
133 
134 }; // fabgl namespace
Definition: canvas.cpp:36
This file is the all in one include file. Application can just include this file to use FabGL library...
uint8_t height
uint8_t width