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

Committer:
Pokitto
Date:
Tue Oct 09 12:07:25 2018 +0000
Revision:
61:123aefc978a7
Parent:
56:71e4c6b1efb4
Minor fixes;

Who changed what in which revision?

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