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