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

Committer:
Pokitto
Date:
Tue Jan 30 10:41:47 2018 +0000
Revision:
31:f4b9b85c7b62
Sound output improvements added:  louder, clearer, faster!

Who changed what in which revision?

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