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