PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Committer:
Pokitto
Date:
Fri Dec 29 02:55:34 2017 +0000
Revision:
22:e826f80d8582
PokittoLib with @Spinalcodes direct non-buffered tricks

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 22:e826f80d8582 1 /**************************************************************************/
Pokitto 22:e826f80d8582 2 /*!
Pokitto 22:e826f80d8582 3 @file PokittoDisplay.h
Pokitto 22:e826f80d8582 4 @author Jonne Valola
Pokitto 22:e826f80d8582 5
Pokitto 22:e826f80d8582 6 @section LICENSE
Pokitto 22:e826f80d8582 7
Pokitto 22:e826f80d8582 8 Software License Agreement (BSD License)
Pokitto 22:e826f80d8582 9
Pokitto 22:e826f80d8582 10 Copyright (c) 2016, Jonne Valola
Pokitto 22:e826f80d8582 11 All rights reserved.
Pokitto 22:e826f80d8582 12
Pokitto 22:e826f80d8582 13 Redistribution and use in source and binary forms, with or without
Pokitto 22:e826f80d8582 14 modification, are permitted provided that the following conditions are met:
Pokitto 22:e826f80d8582 15 1. Redistributions of source code must retain the above copyright
Pokitto 22:e826f80d8582 16 notice, this list of conditions and the following disclaimer.
Pokitto 22:e826f80d8582 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 22:e826f80d8582 18 notice, this list of conditions and the following disclaimer in the
Pokitto 22:e826f80d8582 19 documentation and/or other materials provided with the distribution.
Pokitto 22:e826f80d8582 20 3. Neither the name of the copyright holders nor the
Pokitto 22:e826f80d8582 21 names of its contributors may be used to endorse or promote products
Pokitto 22:e826f80d8582 22 derived from this software without specific prior written permission.
Pokitto 22:e826f80d8582 23
Pokitto 22:e826f80d8582 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 22:e826f80d8582 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 22:e826f80d8582 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 22:e826f80d8582 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 22:e826f80d8582 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 22:e826f80d8582 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 22:e826f80d8582 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 22:e826f80d8582 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 22:e826f80d8582 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 22:e826f80d8582 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 22:e826f80d8582 34 */
Pokitto 22:e826f80d8582 35 /**************************************************************************/
Pokitto 22:e826f80d8582 36
Pokitto 22:e826f80d8582 37
Pokitto 22:e826f80d8582 38
Pokitto 22:e826f80d8582 39 /* THE SEGMENT BELOW PERTAINS TO CIRCLE DRAWING FUNCTIONS ONLY
Pokitto 22:e826f80d8582 40 *
Pokitto 22:e826f80d8582 41 This is the core graphics library for all our displays, providing a common
Pokitto 22:e826f80d8582 42 set of graphics primitives (points, lines, circles, etc.). It needs to be
Pokitto 22:e826f80d8582 43 paired with a hardware-specific library for each display device we carry
Pokitto 22:e826f80d8582 44 (to handle the lower-level functions).
Pokitto 22:e826f80d8582 45 Adafruit invests time and resources providing this open source code, please
Pokitto 22:e826f80d8582 46 support Adafruit & open-source hardware by purchasing products from Adafruit!
Pokitto 22:e826f80d8582 47 Copyright (c) 2013 Adafruit Industries. All rights reserved.
Pokitto 22:e826f80d8582 48 Redistribution and use in source and binary forms, with or without
Pokitto 22:e826f80d8582 49 modification, are permitted provided that the following conditions are met:
Pokitto 22:e826f80d8582 50 - Redistributions of source code must retain the above copyright notice,
Pokitto 22:e826f80d8582 51 this list of conditions and the following disclaimer.
Pokitto 22:e826f80d8582 52 - Redistributions in binary form must reproduce the above copyright notice,
Pokitto 22:e826f80d8582 53 this list of conditions and the following disclaimer in the documentation
Pokitto 22:e826f80d8582 54 and/or other materials provided with the distribution.
Pokitto 22:e826f80d8582 55 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Pokitto 22:e826f80d8582 56 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Pokitto 22:e826f80d8582 57 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Pokitto 22:e826f80d8582 58 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
Pokitto 22:e826f80d8582 59 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Pokitto 22:e826f80d8582 60 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Pokitto 22:e826f80d8582 61 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Pokitto 22:e826f80d8582 62 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Pokitto 22:e826f80d8582 63 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Pokitto 22:e826f80d8582 64 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Pokitto 22:e826f80d8582 65 POSSIBILITY OF SUCH DAMAGE.
Pokitto 22:e826f80d8582 66 */
Pokitto 22:e826f80d8582 67
Pokitto 22:e826f80d8582 68 #ifndef POKITTODISPLAY_H
Pokitto 22:e826f80d8582 69 #define POKITTODISPLAY_H
Pokitto 22:e826f80d8582 70
Pokitto 22:e826f80d8582 71 #include <stdint.h>
Pokitto 22:e826f80d8582 72 #include "Pokitto_settings.h"
Pokitto 22:e826f80d8582 73 #include "PokittoGlobs.h"
Pokitto 22:e826f80d8582 74 #include "PokittoFonts.h"
Pokitto 22:e826f80d8582 75 #include "PokittoPalettes.h"
Pokitto 22:e826f80d8582 76
Pokitto 22:e826f80d8582 77 // Basic Color definitions
Pokitto 22:e826f80d8582 78 #define COLOR_BLACK (uint16_t)(0x0000)
Pokitto 22:e826f80d8582 79 #define COLOR_BLUE (uint16_t)(0x001F)
Pokitto 22:e826f80d8582 80 #define COLOR_RED (uint16_t)(0xF800)
Pokitto 22:e826f80d8582 81 #define COLOR_GREEN (uint16_t)(0x07E0)
Pokitto 22:e826f80d8582 82 #define COLOR_CYAN (uint16_t)(0x07FF)
Pokitto 22:e826f80d8582 83 #define COLOR_MAGENTA (uint16_t)(0xF81F)
Pokitto 22:e826f80d8582 84 #define COLOR_YELLOW (uint16_t)(0xFFE0)
Pokitto 22:e826f80d8582 85 #define COLOR_WHITE (uint16_t)(0xFFFF)
Pokitto 22:e826f80d8582 86
Pokitto 22:e826f80d8582 87 // Grayscale Values
Pokitto 22:e826f80d8582 88 #define COLOR_GRAY_15 (uint16_t)(0x0861) // 15 15 15
Pokitto 22:e826f80d8582 89 #define COLOR_GRAY_30 (uint16_t)(0x18E3) // 30 30 30
Pokitto 22:e826f80d8582 90 #define COLOR_GRAY_50 (uint16_t)(0x3186) // 50 50 50
Pokitto 22:e826f80d8582 91 #define COLOR_GRAY_80 (uint16_t)(0x528A) // 80 80 80
Pokitto 22:e826f80d8582 92 #define COLOR_GRAY_128 (uint16_t)(0x8410) // 128 128 128
Pokitto 22:e826f80d8582 93 #define COLOR_GRAY_200 (uint16_t)(0xCE59) // 200 200 200
Pokitto 22:e826f80d8582 94 #define COLOR_GRAY_225 (uint16_t)(0xE71C) // 225 225 225
Pokitto 22:e826f80d8582 95
Pokitto 22:e826f80d8582 96 /** The tables below are palettes, that resemble the Pico 8 palette*/
Pokitto 22:e826f80d8582 97
Pokitto 22:e826f80d8582 98 enum defcolors {
Pokitto 22:e826f80d8582 99 C_BLACK,
Pokitto 22:e826f80d8582 100 C_DARKBLUE,
Pokitto 22:e826f80d8582 101 C_PURPLE,
Pokitto 22:e826f80d8582 102 C_DARKGREEN,
Pokitto 22:e826f80d8582 103
Pokitto 22:e826f80d8582 104 C_BROWN,
Pokitto 22:e826f80d8582 105 C_DARKBROWN,
Pokitto 22:e826f80d8582 106 C_LIGHTGRAY,
Pokitto 22:e826f80d8582 107 C_WHITE,
Pokitto 22:e826f80d8582 108
Pokitto 22:e826f80d8582 109 C_RED,
Pokitto 22:e826f80d8582 110 C_ORANGE,
Pokitto 22:e826f80d8582 111 C_YELLOW,
Pokitto 22:e826f80d8582 112 C_GREEN,
Pokitto 22:e826f80d8582 113
Pokitto 22:e826f80d8582 114 C_BLUE,
Pokitto 22:e826f80d8582 115 C_DARKGRAY,
Pokitto 22:e826f80d8582 116 C_PINK,
Pokitto 22:e826f80d8582 117 C_PEACH
Pokitto 22:e826f80d8582 118 };
Pokitto 22:e826f80d8582 119
Pokitto 22:e826f80d8582 120 const uint16_t def565palette[16] = {
Pokitto 22:e826f80d8582 121 //kind of like pico8 palette
Pokitto 22:e826f80d8582 122 0,0x194a,0x792a,0x42a,
Pokitto 22:e826f80d8582 123 0xaa86,0x5aa9,0xc618,0xff9d,
Pokitto 22:e826f80d8582 124 0xf809,0xfd00,0xff84,0x72a,
Pokitto 22:e826f80d8582 125 0x2d7f,0x83b3,0xfbb5,0xfe75
Pokitto 22:e826f80d8582 126 };
Pokitto 22:e826f80d8582 127
Pokitto 22:e826f80d8582 128 #define PALETTE_SIZE 16
Pokitto 22:e826f80d8582 129 #include <stdint.h>
Pokitto 22:e826f80d8582 130 #include <stdlib.h>
Pokitto 22:e826f80d8582 131 #include <string.h>
Pokitto 22:e826f80d8582 132
Pokitto 22:e826f80d8582 133
Pokitto 22:e826f80d8582 134 namespace Pokitto {
Pokitto 22:e826f80d8582 135
Pokitto 22:e826f80d8582 136 class Display {
Pokitto 22:e826f80d8582 137 public:
Pokitto 22:e826f80d8582 138 Display();
Pokitto 22:e826f80d8582 139
Pokitto 22:e826f80d8582 140 // PROPERTIES
Pokitto 22:e826f80d8582 141 private:
Pokitto 22:e826f80d8582 142 static uint8_t* canvas;
Pokitto 22:e826f80d8582 143 static uint8_t bpp;
Pokitto 22:e826f80d8582 144 static uint8_t m_colordepth;
Pokitto 22:e826f80d8582 145 public:
Pokitto 22:e826f80d8582 146 static uint8_t width;
Pokitto 22:e826f80d8582 147 static uint8_t height;
Pokitto 22:e826f80d8582 148 static uint8_t screenbuffer[];
Pokitto 22:e826f80d8582 149
Pokitto 22:e826f80d8582 150 // PROPERTIES
Pokitto 22:e826f80d8582 151 static void setColorDepth(uint8_t);
Pokitto 22:e826f80d8582 152 static uint8_t getColorDepth();
Pokitto 22:e826f80d8582 153 static uint8_t getBitsPerPixel();
Pokitto 22:e826f80d8582 154 static uint16_t getWidth();
Pokitto 22:e826f80d8582 155 static uint16_t getHeight();
Pokitto 22:e826f80d8582 156 static uint8_t getNumberOfColors();
Pokitto 22:e826f80d8582 157
Pokitto 22:e826f80d8582 158 // IMPORTANT PUBLIC STATE MEMBERS
Pokitto 22:e826f80d8582 159 /** Selected font */
Pokitto 22:e826f80d8582 160 static const unsigned char * font;
Pokitto 22:e826f80d8582 161 /** Set if screen is cleared between updates or not*/
Pokitto 22:e826f80d8582 162 static uint8_t persistence;
Pokitto 22:e826f80d8582 163 /** Selected drawing color */
Pokitto 22:e826f80d8582 164 static uint16_t color;
Pokitto 22:e826f80d8582 165 /** Selected background color */
Pokitto 22:e826f80d8582 166 static uint16_t bgcolor;
Pokitto 22:e826f80d8582 167 /** Selected invisible color */
Pokitto 22:e826f80d8582 168 static uint16_t invisiblecolor;
Pokitto 22:e826f80d8582 169 /** Direct unbuffered color */
Pokitto 22:e826f80d8582 170 static uint16_t directcolor;
Pokitto 22:e826f80d8582 171 /** Direct unbuffered background color */
Pokitto 22:e826f80d8582 172 static uint16_t directbgcolor;
Pokitto 22:e826f80d8582 173 /** set color with a command */
Pokitto 22:e826f80d8582 174 static void setColor(uint8_t);
Pokitto 22:e826f80d8582 175 /** set color and bgcolor with a command */
Pokitto 22:e826f80d8582 176 static void setColor(uint8_t,uint8_t);
Pokitto 22:e826f80d8582 177 /** set invisiblecolor with a command */
Pokitto 22:e826f80d8582 178 static void setInvisibleColor(uint16_t);
Pokitto 22:e826f80d8582 179 /** get color */
Pokitto 22:e826f80d8582 180 static uint8_t getColor();
Pokitto 22:e826f80d8582 181 /** get background color */
Pokitto 22:e826f80d8582 182 static uint8_t getBgColor();
Pokitto 22:e826f80d8582 183 /** get invisible color */
Pokitto 22:e826f80d8582 184 static uint16_t getInvisibleColor();
Pokitto 22:e826f80d8582 185
Pokitto 22:e826f80d8582 186
Pokitto 22:e826f80d8582 187 /** Initialize display */
Pokitto 22:e826f80d8582 188 static void begin();
Pokitto 22:e826f80d8582 189 /** Clear display buffer */
Pokitto 22:e826f80d8582 190 static void clear();
Pokitto 22:e826f80d8582 191 /** Scroll by x lines */
Pokitto 22:e826f80d8582 192 static void scroll(int16_t);
Pokitto 22:e826f80d8582 193 /** Fill display buffer */
Pokitto 22:e826f80d8582 194 static void fillScreen(uint16_t);
Pokitto 22:e826f80d8582 195 /** Send display buffer to display hardware */
Pokitto 22:e826f80d8582 196 static void update();
Pokitto 22:e826f80d8582 197 /** Forced update of LCD display memory with a given pixel buffer */
Pokitto 22:e826f80d8582 198 static void lcdRefresh(unsigned char*);
Pokitto 22:e826f80d8582 199 /** Clear LCD hardware memory */
Pokitto 22:e826f80d8582 200 static void clearLCD();
Pokitto 22:e826f80d8582 201 /** Fill LCD hardware memory */
Pokitto 22:e826f80d8582 202 static void fillLCD(uint16_t);
Pokitto 22:e826f80d8582 203 /** Show Pokitto logo at startup*/
Pokitto 22:e826f80d8582 204 static void showLogo();
Pokitto 22:e826f80d8582 205 /** Point to another screenbuffer instead of the default one */
Pokitto 22:e826f80d8582 206 static void setFrameBufferTo(uint8_t*);
Pokitto 22:e826f80d8582 207
Pokitto 22:e826f80d8582 208 // COLORS AND PALETTE
Pokitto 22:e826f80d8582 209 public:
Pokitto 22:e826f80d8582 210 /** set default palette */
Pokitto 22:e826f80d8582 211 static void setDefaultPalette();
Pokitto 22:e826f80d8582 212 /** master palette */
Pokitto 22:e826f80d8582 213 static uint16_t palette[PALETTE_SIZE];
Pokitto 22:e826f80d8582 214 /** runtime palette pointer */
Pokitto 22:e826f80d8582 215 static uint16_t *paletteptr;
Pokitto 22:e826f80d8582 216 /** convert RGB to 565 color value */
Pokitto 22:e826f80d8582 217 static uint16_t RGBto565(uint8_t,uint8_t,uint8_t);
Pokitto 22:e826f80d8582 218 /** linear interpolation between colors */
Pokitto 22:e826f80d8582 219 static uint16_t interpolateColor(uint16_t, uint16_t, uint8_t);
Pokitto 22:e826f80d8582 220 /** load an R,G,B triplet palette */
Pokitto 22:e826f80d8582 221 static void loadRGBPalette(const unsigned char*);
Pokitto 22:e826f80d8582 222 /** load a ready-made 565 palette */
Pokitto 22:e826f80d8582 223 static void load565Palette(const uint16_t*);
Pokitto 22:e826f80d8582 224 /** rotate palette by step */
Pokitto 22:e826f80d8582 225 static void rotatePalette(int8_t);
Pokitto 22:e826f80d8582 226 /** tween between two palettes **/
Pokitto 22:e826f80d8582 227 static void tweenPalette(uint16_t*, const uint16_t*, const uint16_t*, uint8_t);
Pokitto 22:e826f80d8582 228
Pokitto 22:e826f80d8582 229 // DIRECT DRAWING (NO BUFFERING)
Pokitto 22:e826f80d8582 230 /** Direct pixel (not through display buffer) */
Pokitto 22:e826f80d8582 231 static void directPixel(int16_t,int16_t,uint16_t);
Pokitto 22:e826f80d8582 232 /** Direct tile 16bit (not through display buffer) */
Pokitto 22:e826f80d8582 233 static void directTile(int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t* gfx);
Pokitto 22:e826f80d8582 234 /** Direct rectangle (not through display buffer) */
Pokitto 22:e826f80d8582 235 static void directRectangle(int16_t, int16_t,int16_t, int16_t, uint16_t);
Pokitto 22:e826f80d8582 236 /** Set the cursor for printing to a certain screen position */
Pokitto 22:e826f80d8582 237 static void setCursor(int16_t,int16_t);
Pokitto 22:e826f80d8582 238 /** direct bitmap to screen (no buffering) */
Pokitto 22:e826f80d8582 239 static void directBitmap(int16_t,int16_t,const uint8_t*, uint8_t,uint8_t);
Pokitto 22:e826f80d8582 240
Pokitto 22:e826f80d8582 241
Pokitto 22:e826f80d8582 242 // DRAWING METHODS
Pokitto 22:e826f80d8582 243 /** Draw pixel at various bit depths */
Pokitto 22:e826f80d8582 244 static void drawPixel(int16_t,int16_t);
Pokitto 22:e826f80d8582 245 /** Draw pixel with specific color index at various bit depths */
Pokitto 22:e826f80d8582 246 static void drawPixel(int16_t x,int16_t y, uint8_t col);
Pokitto 22:e826f80d8582 247 /** Get pixel at various bit depths */
Pokitto 22:e826f80d8582 248 static uint8_t getPixel(int16_t,int16_t);
Pokitto 22:e826f80d8582 249 /** Draw line **/
Pokitto 22:e826f80d8582 250 static void drawLine(int16_t,int16_t,int16_t,int16_t);
Pokitto 22:e826f80d8582 251 /** Clip line with screen boundaries, returns 0 if whole line is out of bounds */
Pokitto 22:e826f80d8582 252 static uint8_t clipLine(int16_t*, int16_t*, int16_t*, int16_t*);
Pokitto 22:e826f80d8582 253 /** Draw a column real fast */
Pokitto 22:e826f80d8582 254 static void drawColumn(int16_t, int16_t, int16_t);
Pokitto 22:e826f80d8582 255 /** Map a 1-bit column real fast */
Pokitto 22:e826f80d8582 256 static void map1BitColumn(int16_t, int16_t, int16_t, const uint8_t*, uint16_t);
Pokitto 22:e826f80d8582 257 /** Draw a row real fast */
Pokitto 22:e826f80d8582 258 static void drawRow(int16_t, int16_t, int16_t);
Pokitto 22:e826f80d8582 259 /** Legacy drawColumn name, for compatibility - macros are not OK because of scope problems */
Pokitto 22:e826f80d8582 260 static void drawFastVLine(int16_t, int16_t, int16_t);
Pokitto 22:e826f80d8582 261 /** Legacy drawRow name, for compatibility - macros are not OK because of scope problems */
Pokitto 22:e826f80d8582 262 static void drawFastHLine(int16_t, int16_t, int16_t);
Pokitto 22:e826f80d8582 263 /** Draw rectangle (edges only) */
Pokitto 22:e826f80d8582 264 static void drawRectangle(int16_t,int16_t,int16_t,int16_t);
Pokitto 22:e826f80d8582 265 /** Fill rectangle */
Pokitto 22:e826f80d8582 266 static void fillRectangle(int16_t,int16_t,int16_t,int16_t);
Pokitto 22:e826f80d8582 267 /** GB compatibility fillRect */
Pokitto 22:e826f80d8582 268 static void fillRect(int16_t x, int16_t y, int16_t w, int16_t h);
Pokitto 22:e826f80d8582 269 /** GB compatibility drawRect */
Pokitto 22:e826f80d8582 270 static void drawRect(int16_t x, int16_t y, int16_t w, int16_t h);
Pokitto 22:e826f80d8582 271
Pokitto 22:e826f80d8582 272 // Functions lifted from Adafruit GFX library (see PokittoDisplay.h for license //
Pokitto 22:e826f80d8582 273 /** Draw circle */
Pokitto 22:e826f80d8582 274 static void drawCircle(int16_t x0, int16_t y0, int16_t r);
Pokitto 22:e826f80d8582 275 /** Draw circle helper */
Pokitto 22:e826f80d8582 276 static void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername);
Pokitto 22:e826f80d8582 277 /** Fill circle */
Pokitto 22:e826f80d8582 278 static void fillCircle(int16_t x0, int16_t y0, int16_t r);
Pokitto 22:e826f80d8582 279 /** Fill circle helper*/
Pokitto 22:e826f80d8582 280 static void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername, int16_t delta);
Pokitto 22:e826f80d8582 281 /** draw triangle */
Pokitto 22:e826f80d8582 282 static void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
Pokitto 22:e826f80d8582 283 /** Fill triangle*/
Pokitto 22:e826f80d8582 284 static void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
Pokitto 22:e826f80d8582 285 /** Draw rounded rectangle */
Pokitto 22:e826f80d8582 286 static void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius);
Pokitto 22:e826f80d8582 287 /** Fill rounded rectangle */
Pokitto 22:e826f80d8582 288 static void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius);
Pokitto 22:e826f80d8582 289
Pokitto 22:e826f80d8582 290 // BITMAPS !
Pokitto 22:e826f80d8582 291 /** Draw monochromatic bitmap. Used in font rendering */
Pokitto 22:e826f80d8582 292 static void drawMonoBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t index);
Pokitto 22:e826f80d8582 293 /** Draw bitmap */
Pokitto 22:e826f80d8582 294 static void drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap);
Pokitto 22:e826f80d8582 295 /** Draw RLE bitmap */
Pokitto 22:e826f80d8582 296 static void drawRleBitmap(int16_t x, int16_t y, const uint8_t* bitmap);
Pokitto 22:e826f80d8582 297 /** Draw animated bitmap frame */
Pokitto 22:e826f80d8582 298 static void drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t frame);
Pokitto 22:e826f80d8582 299 /** Draw bitmap flipped on x-axis*/
Pokitto 22:e826f80d8582 300 static void drawBitmapXFlipped(int16_t x, int16_t y, const uint8_t* bitmap);
Pokitto 22:e826f80d8582 301 /** Draw bitmap with options */
Pokitto 22:e826f80d8582 302 static void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip);
Pokitto 22:e826f80d8582 303 /** Get pointer to the screen buffer - GB compatibility */
Pokitto 22:e826f80d8582 304 static uint8_t* getBuffer();
Pokitto 22:e826f80d8582 305 /** Get pixel in a monochromatic bitmap - GB compatibility */
Pokitto 22:e826f80d8582 306 static uint8_t getBitmapPixel(const uint8_t*, uint16_t, uint16_t);
Pokitto 22:e826f80d8582 307 /** Optimized functions for drawing bit columns - used in raytracing */
Pokitto 22:e826f80d8582 308 static void draw4BitColumn(int16_t x, int16_t y, uint8_t h, uint8_t* bitmap);
Pokitto 22:e826f80d8582 309
Pokitto 22:e826f80d8582 310 // PRINTING
Pokitto 22:e826f80d8582 311 /** direct character to screen (no buffering) */
Pokitto 22:e826f80d8582 312 static int directChar(int16_t, int16_t, uint16_t);
Pokitto 22:e826f80d8582 313 /** character to screenbuffer */
Pokitto 22:e826f80d8582 314 static int bufferChar(int16_t, int16_t, uint16_t);
Pokitto 22:e826f80d8582 315 /** set the active font */
Pokitto 22:e826f80d8582 316 static void setFont(const unsigned char * f);
Pokitto 22:e826f80d8582 317 /** font dimensions */
Pokitto 22:e826f80d8582 318 static uint8_t fontWidth, fontHeight;
Pokitto 22:e826f80d8582 319 /** text wrapping */
Pokitto 22:e826f80d8582 320 static bool textWrap;
Pokitto 22:e826f80d8582 321 /** GB compatibility drawChar */
Pokitto 22:e826f80d8582 322 static void drawChar(int8_t x, int8_t y, unsigned char c, uint8_t size);
Pokitto 22:e826f80d8582 323
Pokitto 22:e826f80d8582 324 static void enableDirectPrinting(uint8_t m);
Pokitto 22:e826f80d8582 325 static bool isDirectPrintingEnabled();
Pokitto 22:e826f80d8582 326 static int print_char(uint8_t x, uint8_t y, unsigned char c);
Pokitto 22:e826f80d8582 327 static void set_cursor(uint8_t, uint8_t);
Pokitto 22:e826f80d8582 328 static void write(uint8_t);
Pokitto 22:e826f80d8582 329 static void write(const char *str);
Pokitto 22:e826f80d8582 330 static void write(const uint8_t *buffer, uint8_t size);
Pokitto 22:e826f80d8582 331 static void print(const char[]);
Pokitto 22:e826f80d8582 332 static void print(char, int base = 0);
Pokitto 22:e826f80d8582 333 static void print(unsigned char, int base = 0);
Pokitto 22:e826f80d8582 334 static void print(int, int base = 10);
Pokitto 22:e826f80d8582 335 static void print(unsigned int, int base = 10);
Pokitto 22:e826f80d8582 336 static void print(long, int base = 10);
Pokitto 22:e826f80d8582 337 static void print(unsigned long, int base = 10);
Pokitto 22:e826f80d8582 338 static void print(double, int base = 2);
Pokitto 22:e826f80d8582 339 static void print(uint8_t, uint8_t, const char[]);
Pokitto 22:e826f80d8582 340 static void print(uint8_t, uint8_t, char, int = 0);
Pokitto 22:e826f80d8582 341 static void print(uint8_t, uint8_t, unsigned char, int = 0);
Pokitto 22:e826f80d8582 342 static void print(uint8_t, uint8_t, int, int = 10);
Pokitto 22:e826f80d8582 343 static void print(uint8_t, uint8_t, unsigned int, int = 10);
Pokitto 22:e826f80d8582 344 static void print(uint8_t, uint8_t, long, int = 10);
Pokitto 22:e826f80d8582 345 static void print(uint8_t, uint8_t, unsigned long, int = 10);
Pokitto 22:e826f80d8582 346 static void print(uint8_t, uint8_t, double, int = 2);
Pokitto 22:e826f80d8582 347 static void println(uint8_t, uint8_t, const char[]);
Pokitto 22:e826f80d8582 348 static void println(uint8_t, uint8_t, char, int = 0);
Pokitto 22:e826f80d8582 349 static void println(uint8_t, uint8_t, unsigned char, int = 0);
Pokitto 22:e826f80d8582 350 static void println(uint8_t, uint8_t, int, int = 10);
Pokitto 22:e826f80d8582 351 static void println(uint8_t, uint8_t, unsigned int, int = 10);
Pokitto 22:e826f80d8582 352 static void println(uint8_t, uint8_t, long, int = 10);
Pokitto 22:e826f80d8582 353 static void println(uint8_t, uint8_t, unsigned long, int = 10);
Pokitto 22:e826f80d8582 354 static void println(uint8_t, uint8_t, double, int = 2);
Pokitto 22:e826f80d8582 355 static void println(uint8_t, uint8_t);
Pokitto 22:e826f80d8582 356 static void println(const char[]);
Pokitto 22:e826f80d8582 357 static void println(char, int = 0);
Pokitto 22:e826f80d8582 358 static void println(unsigned char, int = 0);
Pokitto 22:e826f80d8582 359 static void println(int, int = 10);
Pokitto 22:e826f80d8582 360 static void println(unsigned int, int = 10);
Pokitto 22:e826f80d8582 361 static void println(long, int = 10 );
Pokitto 22:e826f80d8582 362 static void println(unsigned long, int = 10);
Pokitto 22:e826f80d8582 363 static void println(double, int = 2);
Pokitto 22:e826f80d8582 364 static void println(void);
Pokitto 22:e826f80d8582 365
Pokitto 22:e826f80d8582 366 static int16_t cursorX,cursorY;
Pokitto 22:e826f80d8582 367 static uint8_t fontSize;
Pokitto 22:e826f80d8582 368 static int8_t adjustCharStep, adjustLineStep;
Pokitto 22:e826f80d8582 369 static bool fixedWidthFont;
Pokitto 22:e826f80d8582 370
Pokitto 22:e826f80d8582 371 static void inc_txtline();
Pokitto 22:e826f80d8582 372 static void printNumber(unsigned long, uint8_t);
Pokitto 22:e826f80d8582 373 static void printFloat(double, uint8_t);
Pokitto 22:e826f80d8582 374
Pokitto 22:e826f80d8582 375 /** Tiled mode functions **/
Pokitto 22:e826f80d8582 376
Pokitto 22:e826f80d8582 377 static void loadTileset(const uint8_t*);
Pokitto 22:e826f80d8582 378
Pokitto 22:e826f80d8582 379 static void setTileBufferTo(uint8_t*);
Pokitto 22:e826f80d8582 380 static void clearTileBuffer();
Pokitto 22:e826f80d8582 381 static void shiftTileBuffer(int8_t,int8_t);
Pokitto 22:e826f80d8582 382
Pokitto 22:e826f80d8582 383 static void setTile(uint16_t,uint8_t);
Pokitto 22:e826f80d8582 384 static uint8_t getTile(uint16_t);
Pokitto 22:e826f80d8582 385 static uint8_t getTile(uint8_t,uint8_t);
Pokitto 22:e826f80d8582 386
Pokitto 22:e826f80d8582 387
Pokitto 22:e826f80d8582 388
Pokitto 22:e826f80d8582 389 private:
Pokitto 22:e826f80d8582 390 static uint8_t m_mode;
Pokitto 22:e826f80d8582 391 static uint16_t m_w,m_h; // store these for faster access when switching printing modes
Pokitto 22:e826f80d8582 392 /** Pointer to screen buffer */
Pokitto 22:e826f80d8582 393 static uint8_t* m_scrbuf;
Pokitto 22:e826f80d8582 394 /** Pointer to tileset */
Pokitto 22:e826f80d8582 395 static uint8_t* m_tileset;
Pokitto 22:e826f80d8582 396 /** Pointer to tilebuffer */
Pokitto 22:e826f80d8582 397 static uint8_t* m_tilebuf;
Pokitto 22:e826f80d8582 398 /** Pointer to tilecolorbuffer */
Pokitto 22:e826f80d8582 399 static uint8_t* m_tilecolorbuf;
Pokitto 22:e826f80d8582 400
Pokitto 22:e826f80d8582 401 };
Pokitto 22:e826f80d8582 402
Pokitto 22:e826f80d8582 403 }
Pokitto 22:e826f80d8582 404
Pokitto 22:e826f80d8582 405 #endif // POKITTODISPLAY_H
Pokitto 22:e826f80d8582 406
Pokitto 22:e826f80d8582 407
Pokitto 22:e826f80d8582 408
Pokitto 22:e826f80d8582 409
Pokitto 22:e826f80d8582 410