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

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Mon Apr 02 22:37:04 2018 +0000
Revision:
35:4f7edccf8ed6
Parent:
31:f4b9b85c7b62
Child:
42:798b5d67b372
All changes synced with Github repo (mode 13, mode 15 etc.)

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.cpp
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 /* THE SEGMENT BELOW PERTAINS TO CIRCLE DRAWING FUNCTIONS ONLY
Pokitto 31:f4b9b85c7b62 39 *
Pokitto 31:f4b9b85c7b62 40 This is the core graphics library for all our displays, providing a common
Pokitto 31:f4b9b85c7b62 41 set of graphics primitives (points, lines, circles, etc.). It needs to be
Pokitto 31:f4b9b85c7b62 42 paired with a hardware-specific library for each display device we carry
Pokitto 31:f4b9b85c7b62 43 (to handle the lower-level functions).
Pokitto 31:f4b9b85c7b62 44 Adafruit invests time and resources providing this open source code, please
Pokitto 31:f4b9b85c7b62 45 support Adafruit & open-source hardware by purchasing products from Adafruit!
Pokitto 31:f4b9b85c7b62 46 Copyright (c) 2013 Adafruit Industries. All rights reserved.
Pokitto 31:f4b9b85c7b62 47 Redistribution and use in source and binary forms, with or without
Pokitto 31:f4b9b85c7b62 48 modification, are permitted provided that the following conditions are met:
Pokitto 31:f4b9b85c7b62 49 - Redistributions of source code must retain the above copyright notice,
Pokitto 31:f4b9b85c7b62 50 this list of conditions and the following disclaimer.
Pokitto 31:f4b9b85c7b62 51 - Redistributions in binary form must reproduce the above copyright notice,
Pokitto 31:f4b9b85c7b62 52 this list of conditions and the following disclaimer in the documentation
Pokitto 31:f4b9b85c7b62 53 and/or other materials provided with the distribution.
Pokitto 31:f4b9b85c7b62 54 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Pokitto 31:f4b9b85c7b62 55 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Pokitto 31:f4b9b85c7b62 56 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Pokitto 31:f4b9b85c7b62 57 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
Pokitto 31:f4b9b85c7b62 58 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Pokitto 31:f4b9b85c7b62 59 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Pokitto 31:f4b9b85c7b62 60 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Pokitto 31:f4b9b85c7b62 61 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Pokitto 31:f4b9b85c7b62 62 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Pokitto 31:f4b9b85c7b62 63 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Pokitto 31:f4b9b85c7b62 64 POSSIBILITY OF SUCH DAMAGE.
Pokitto 31:f4b9b85c7b62 65 */
Pokitto 31:f4b9b85c7b62 66
Pokitto 31:f4b9b85c7b62 67 #include "PokittoDisplay.h"
Pokitto 31:f4b9b85c7b62 68 #include "Pokitto_settings.h"
Pokitto 31:f4b9b85c7b62 69 #include "GBcompatibility.h"
Pokitto 31:f4b9b85c7b62 70 #include "PokittoCore.h"
Pokitto 31:f4b9b85c7b62 71 #include "PokittoSound.h"
Pokitto 31:f4b9b85c7b62 72 #include <stdio.h>
Pokitto 31:f4b9b85c7b62 73 #include <string.h>
Pokitto 31:f4b9b85c7b62 74
Pokitto 31:f4b9b85c7b62 75 #ifndef POK_SIM
Pokitto 31:f4b9b85c7b62 76 #include "HWLCD.h"
Pokitto 31:f4b9b85c7b62 77 #else
Pokitto 31:f4b9b85c7b62 78 #include "SimLCD.h"
Pokitto 31:f4b9b85c7b62 79 #endif
Pokitto 31:f4b9b85c7b62 80
Pokitto 35:4f7edccf8ed6 81 //extern "C" void CheckStack();
Pokitto 35:4f7edccf8ed6 82 //extern char _ebss[]; // In map file
Pokitto 35:4f7edccf8ed6 83 //extern char _vStackTop[]; // In map file
Pokitto 35:4f7edccf8ed6 84
Pokitto 31:f4b9b85c7b62 85 Pokitto::Core core;
Pokitto 31:f4b9b85c7b62 86 Pokitto::Sound _pdsound;
Pokitto 31:f4b9b85c7b62 87
Pokitto 31:f4b9b85c7b62 88 using namespace Pokitto;
Pokitto 31:f4b9b85c7b62 89
Pokitto 31:f4b9b85c7b62 90
Pokitto 31:f4b9b85c7b62 91
Pokitto 31:f4b9b85c7b62 92 uint8_t* Display::m_scrbuf;
Pokitto 31:f4b9b85c7b62 93 uint8_t* Display::m_tileset;
Pokitto 31:f4b9b85c7b62 94 uint8_t* Display::m_tilebuf;
Pokitto 31:f4b9b85c7b62 95 uint8_t* Display::m_tilecolorbuf;
Pokitto 31:f4b9b85c7b62 96 uint8_t Display::m_mode, Display::m_colordepth;
Pokitto 31:f4b9b85c7b62 97 uint8_t Display::palOffset;
Pokitto 31:f4b9b85c7b62 98 SpriteInfo Display::m_sprites[SPRITE_COUNT];
Pokitto 31:f4b9b85c7b62 99 uint8_t Display::fontSize=1;
Pokitto 31:f4b9b85c7b62 100 int16_t Display::cursorX,Display::cursorY;
Pokitto 31:f4b9b85c7b62 101 uint16_t Display::m_w,Display::m_h;
Pokitto 31:f4b9b85c7b62 102 uint8_t Display::fontWidth, Display::fontHeight;
Pokitto 31:f4b9b85c7b62 103 bool Display::textWrap=true;
Pokitto 31:f4b9b85c7b62 104
Pokitto 31:f4b9b85c7b62 105 uint8_t Display::persistence = 0;
Pokitto 31:f4b9b85c7b62 106 uint16_t Display::color = 1;
Pokitto 31:f4b9b85c7b62 107 uint16_t Display::bgcolor = 0;
Pokitto 31:f4b9b85c7b62 108 uint16_t Display::invisiblecolor = 17;
Pokitto 31:f4b9b85c7b62 109 uint16_t Display::directcolor=0xFFFF;
Pokitto 31:f4b9b85c7b62 110 uint16_t Display::directbgcolor=0x0;
Pokitto 31:f4b9b85c7b62 111 bool Display::directtextrotated=false;
Pokitto 31:f4b9b85c7b62 112 int16_t Display::clipX = 0;
Pokitto 31:f4b9b85c7b62 113 int16_t Display::clipY = 0;
Pokitto 31:f4b9b85c7b62 114 int16_t Display::clipW = LCDWIDTH;
Pokitto 31:f4b9b85c7b62 115 int16_t Display::clipH = LCDHEIGHT;
Pokitto 31:f4b9b85c7b62 116
Pokitto 31:f4b9b85c7b62 117 uint16_t* Display::paletteptr;
Pokitto 31:f4b9b85c7b62 118 uint16_t Display::palette[PALETTE_SIZE];
Pokitto 31:f4b9b85c7b62 119 const unsigned char* Display::font;
Pokitto 31:f4b9b85c7b62 120 int8_t Display::adjustCharStep = 1;
Pokitto 31:f4b9b85c7b62 121 int8_t Display::adjustLineStep = 1;
Pokitto 31:f4b9b85c7b62 122 bool Display::fixedWidthFont = false;
Pokitto 31:f4b9b85c7b62 123
Pokitto 31:f4b9b85c7b62 124 /** drawing canvas **/
Pokitto 31:f4b9b85c7b62 125 //uint8_t* Display::canvas; // points to the active buffer. if null, draw direct to screen
Pokitto 31:f4b9b85c7b62 126
Pokitto 31:f4b9b85c7b62 127 /** screenbuffer **/
Pokitto 31:f4b9b85c7b62 128 uint8_t Display::bpp = POK_COLORDEPTH;
Pokitto 31:f4b9b85c7b62 129 #ifndef POK_TILEDMODE
Pokitto 31:f4b9b85c7b62 130 #if (POK_SCREENMODE == MODE_HI_MONOCHROME)
Pokitto 31:f4b9b85c7b62 131 uint8_t Display::width = POK_LCD_W;
Pokitto 31:f4b9b85c7b62 132 uint8_t Display::height = POK_LCD_H;
Pokitto 31:f4b9b85c7b62 133 uint8_t Display::screenbuffer[((POK_LCD_H+1)*POK_LCD_W)*POK_COLORDEPTH/8]; // maximum resolution
Pokitto 31:f4b9b85c7b62 134 #elif (POK_SCREENMODE == MODE_HI_4COLOR)
Pokitto 31:f4b9b85c7b62 135 uint8_t Display::width = POK_LCD_W;
Pokitto 31:f4b9b85c7b62 136 uint8_t Display::height = POK_LCD_H;
Pokitto 31:f4b9b85c7b62 137 uint8_t __attribute__((section (".bss"))) Display::screenbuffer[((POK_LCD_H)*POK_LCD_W)/4]; // maximum resolution
Pokitto 31:f4b9b85c7b62 138 #elif (POK_SCREENMODE == MODE_FAST_16COLOR)
Pokitto 31:f4b9b85c7b62 139 uint8_t Display::width = POK_LCD_W/2;
Pokitto 31:f4b9b85c7b62 140 uint8_t Display::height = POK_LCD_H/2;
Pokitto 31:f4b9b85c7b62 141 uint8_t Display::screenbuffer[(((POK_LCD_H/2)+1)*POK_LCD_W/2)*POK_COLORDEPTH/8]; // half resolution
Pokitto 31:f4b9b85c7b62 142 #elif (POK_SCREENMODE == MODE_HI_16COLOR)
Pokitto 31:f4b9b85c7b62 143 uint8_t Display::width = POK_LCD_W;
Pokitto 31:f4b9b85c7b62 144 uint8_t Display::height = POK_LCD_H;
Pokitto 31:f4b9b85c7b62 145 uint8_t Display::screenbuffer[POK_LCD_H*POK_LCD_W/2]; // 4 bits per pixel
Pokitto 31:f4b9b85c7b62 146 #elif (POK_SCREENMODE == MODE_LAMENES)
Pokitto 31:f4b9b85c7b62 147 uint8_t Display::width = 128;
Pokitto 31:f4b9b85c7b62 148 uint8_t Display::height = 120;
Pokitto 31:f4b9b85c7b62 149 uint8_t Display::screenbuffer[((121)*128)*POK_COLORDEPTH/8]; // half resolution
Pokitto 31:f4b9b85c7b62 150 #elif (POK_SCREENMODE == MODE_GAMEBOY)
Pokitto 31:f4b9b85c7b62 151 uint8_t Display::width = 160;
Pokitto 31:f4b9b85c7b62 152 uint8_t Display::height = 144;
Pokitto 31:f4b9b85c7b62 153 uint8_t Display::screenbuffer[160*144/4];
Pokitto 35:4f7edccf8ed6 154 #elif (POK_SCREENMODE == MODE14)
Pokitto 35:4f7edccf8ed6 155 uint8_t Display::width = 220;
Pokitto 35:4f7edccf8ed6 156 uint8_t Display::height = 176;
Pokitto 35:4f7edccf8ed6 157 uint8_t Display::screenbuffer[14520];
Pokitto 35:4f7edccf8ed6 158 #elif (POK_SCREENMODE == MODE13)
Pokitto 35:4f7edccf8ed6 159 uint8_t Display::width = 110;
Pokitto 35:4f7edccf8ed6 160 uint8_t Display::height = 88;
Pokitto 35:4f7edccf8ed6 161 uint8_t Display::screenbuffer[110*88]; // 8bit 110x88
Pokitto 35:4f7edccf8ed6 162 #elif (POK_SCREENMODE == MODE15)
Pokitto 35:4f7edccf8ed6 163 uint8_t Display::width = 220;
Pokitto 35:4f7edccf8ed6 164 uint8_t Display::height = 176;
Pokitto 35:4f7edccf8ed6 165 uint8_t Display::screenbuffer[0x4BA0];
Pokitto 31:f4b9b85c7b62 166 #else
Pokitto 31:f4b9b85c7b62 167 uint8_t Display::width = 84;
Pokitto 31:f4b9b85c7b62 168 uint8_t Display::height = 48;
Pokitto 31:f4b9b85c7b62 169 uint8_t Display::screenbuffer[128*64]; // not needed because Gamebuino and Arduboy have their own buffer
Pokitto 31:f4b9b85c7b62 170 #endif
Pokitto 31:f4b9b85c7b62 171 #else //Tiledmode
Pokitto 31:f4b9b85c7b62 172 #if (POK_SCREENMODE == MODE_TILED_1BIT)
Pokitto 31:f4b9b85c7b62 173 uint8_t Display::width = POK_LCD_W;
Pokitto 31:f4b9b85c7b62 174 uint8_t Display::height = POK_LCD_H;
Pokitto 31:f4b9b85c7b62 175 uint8_t Display::screenbuffer[0];
Pokitto 31:f4b9b85c7b62 176 #else
Pokitto 31:f4b9b85c7b62 177 uint8_t Display::width = POK_LCD_W;
Pokitto 31:f4b9b85c7b62 178 uint8_t Display::height = POK_LCD_H;
Pokitto 31:f4b9b85c7b62 179 uint8_t Display::screenbuffer[0];
Pokitto 31:f4b9b85c7b62 180 #endif
Pokitto 31:f4b9b85c7b62 181 #endif //tiledmode
Pokitto 31:f4b9b85c7b62 182
Pokitto 31:f4b9b85c7b62 183 // RLE decoding
Pokitto 31:f4b9b85c7b62 184 #define RLE_ESC_EOL 0
Pokitto 31:f4b9b85c7b62 185 #define RLE_ESC_EOB 1
Pokitto 31:f4b9b85c7b62 186 #define RLE_ESC_OFFSET 2
Pokitto 31:f4b9b85c7b62 187
Pokitto 31:f4b9b85c7b62 188 Display::Display() {
Pokitto 31:f4b9b85c7b62 189 m_scrbuf = screenbuffer;
Pokitto 31:f4b9b85c7b62 190 setDefaultPalette();
Pokitto 31:f4b9b85c7b62 191 m_mode = 1; // direct printing on by default
Pokitto 31:f4b9b85c7b62 192 m_w = POK_LCD_W;
Pokitto 31:f4b9b85c7b62 193 m_h = POK_LCD_H;
Pokitto 31:f4b9b85c7b62 194 setFont(DEFAULT_FONT);
Pokitto 31:f4b9b85c7b62 195 invisiblecolor=17;
Pokitto 31:f4b9b85c7b62 196 bgcolor=0;
Pokitto 31:f4b9b85c7b62 197 if (POK_COLORDEPTH) m_colordepth = POK_COLORDEPTH;
Pokitto 31:f4b9b85c7b62 198 else m_colordepth = 4;
Pokitto 31:f4b9b85c7b62 199 #if POK_GAMEBUINO_SUPPORT
Pokitto 31:f4b9b85c7b62 200 setColorDepth(1);
Pokitto 31:f4b9b85c7b62 201 #endif // POK_GAMEBUINO_SUPPORT
Pokitto 31:f4b9b85c7b62 202
Pokitto 31:f4b9b85c7b62 203 // Reset sprites
Pokitto 31:f4b9b85c7b62 204 m_tilecolorbuf = NULL; //!!HV
Pokitto 31:f4b9b85c7b62 205 for (uint8_t s = 0; s < SPRITE_COUNT; s++) m_sprites[s].bitmapData = NULL;
Pokitto 31:f4b9b85c7b62 206 }
Pokitto 31:f4b9b85c7b62 207
Pokitto 31:f4b9b85c7b62 208 uint16_t Display::getWidth() {
Pokitto 31:f4b9b85c7b62 209 return width;
Pokitto 31:f4b9b85c7b62 210 }
Pokitto 31:f4b9b85c7b62 211
Pokitto 31:f4b9b85c7b62 212 uint8_t Display::getNumberOfColors() {
Pokitto 31:f4b9b85c7b62 213 return 1<<POK_COLORDEPTH;
Pokitto 31:f4b9b85c7b62 214 }
Pokitto 31:f4b9b85c7b62 215
Pokitto 31:f4b9b85c7b62 216 uint16_t Display::getHeight() {
Pokitto 31:f4b9b85c7b62 217 return height;
Pokitto 31:f4b9b85c7b62 218 }
Pokitto 31:f4b9b85c7b62 219
Pokitto 31:f4b9b85c7b62 220 uint8_t Display::getColorDepth() {
Pokitto 31:f4b9b85c7b62 221 return m_colordepth;
Pokitto 31:f4b9b85c7b62 222 }
Pokitto 31:f4b9b85c7b62 223
Pokitto 31:f4b9b85c7b62 224 void Display::setColorDepth(uint8_t v) {
Pokitto 31:f4b9b85c7b62 225 if (v > POK_COLORDEPTH) v=POK_COLORDEPTH;
Pokitto 31:f4b9b85c7b62 226 m_colordepth = v;
Pokitto 31:f4b9b85c7b62 227 }
Pokitto 31:f4b9b85c7b62 228
Pokitto 31:f4b9b85c7b62 229 void Display::clearLCD() {
Pokitto 31:f4b9b85c7b62 230 lcdFillSurface(0);
Pokitto 31:f4b9b85c7b62 231 setCursor(0,0); // old basic computer style
Pokitto 31:f4b9b85c7b62 232 }
Pokitto 31:f4b9b85c7b62 233
Pokitto 31:f4b9b85c7b62 234 void Display::fillLCD(uint16_t c) {
Pokitto 31:f4b9b85c7b62 235 lcdFillSurface(c);
Pokitto 31:f4b9b85c7b62 236 }
Pokitto 31:f4b9b85c7b62 237
Pokitto 31:f4b9b85c7b62 238 void Display::directPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 31:f4b9b85c7b62 239 if ((invisiblecolor < PALETTE_SIZE) && (invisiblecolor < 16) && (color == palette[invisiblecolor])) return;
Pokitto 31:f4b9b85c7b62 240 lcdPixel(x,y,color);
Pokitto 31:f4b9b85c7b62 241 }
Pokitto 31:f4b9b85c7b62 242
Pokitto 31:f4b9b85c7b62 243 void Display::directTile(int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t* gfx) {
Pokitto 31:f4b9b85c7b62 244 lcdTile(x,y,x2,y2,gfx);
Pokitto 31:f4b9b85c7b62 245 }
Pokitto 31:f4b9b85c7b62 246
Pokitto 31:f4b9b85c7b62 247 void Display::directRectangle(int16_t x, int16_t y,int16_t x2, int16_t y2, uint16_t color) {
Pokitto 31:f4b9b85c7b62 248 lcdRectangle(x,y,x2,y2,color);
Pokitto 31:f4b9b85c7b62 249 }
Pokitto 31:f4b9b85c7b62 250
Pokitto 31:f4b9b85c7b62 251 void Display::begin() {
Pokitto 31:f4b9b85c7b62 252 lcdInit();
Pokitto 31:f4b9b85c7b62 253 }
Pokitto 31:f4b9b85c7b62 254
Pokitto 31:f4b9b85c7b62 255 void Display::setCursor(int16_t x,int16_t y) {
Pokitto 31:f4b9b85c7b62 256 cursorX = x;
Pokitto 31:f4b9b85c7b62 257 cursorY = y;
Pokitto 31:f4b9b85c7b62 258 }
Pokitto 31:f4b9b85c7b62 259
Pokitto 31:f4b9b85c7b62 260 /**
Pokitto 31:f4b9b85c7b62 261 * Update the display.
Pokitto 31:f4b9b85c7b62 262 * The update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations, the
Pokitto 31:f4b9b85c7b62 263 * x, y, and width of the update rect must be dividable by 4 pixels, and the height must be dividable by 8 pixels.
Pokitto 31:f4b9b85c7b62 264 * Note: The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 31:f4b9b85c7b62 265 * @param useDirectMode True, if only direct screen drawing is used. False, if the screen buffer is drawn. Note: If sprites are enabled, they are drawn in both modes.
Pokitto 31:f4b9b85c7b62 266 * @param updRectX The update rect.
Pokitto 31:f4b9b85c7b62 267 * @param updRectY The update rect.
Pokitto 31:f4b9b85c7b62 268 * @param updRectW The update rect.
Pokitto 31:f4b9b85c7b62 269 * @param updRectH The update rect.
Pokitto 31:f4b9b85c7b62 270 */
Pokitto 31:f4b9b85c7b62 271 void Display::update(bool useDirectDrawMode, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH) {
Pokitto 31:f4b9b85c7b62 272
Pokitto 31:f4b9b85c7b62 273 #if POK_SCREENMODE == MODE_HI_4COLOR
Pokitto 31:f4b9b85c7b62 274 // If there is one or more sprites, use sprite enabled drawing.
Pokitto 31:f4b9b85c7b62 275 if (m_sprites[0].bitmapData != NULL)
Pokitto 31:f4b9b85c7b62 276 lcdRefreshMode1Spr(m_scrbuf, updRectX, updRectY, updRectW, updRectH, paletteptr, m_sprites, useDirectDrawMode);
Pokitto 31:f4b9b85c7b62 277 else if (!useDirectDrawMode)
Pokitto 31:f4b9b85c7b62 278 lcdRefreshMode1(m_scrbuf, updRectX, updRectY, updRectW, updRectH, paletteptr);
Pokitto 31:f4b9b85c7b62 279 #endif
Pokitto 31:f4b9b85c7b62 280
Pokitto 31:f4b9b85c7b62 281 // For the screen modes that do not support sprites, return if the direct draw mode is used.
Pokitto 31:f4b9b85c7b62 282 if (! useDirectDrawMode) {
Pokitto 35:4f7edccf8ed6 283 #if POK_SCREENMODE == MODE13
Pokitto 35:4f7edccf8ed6 284 lcdRefreshMode13(m_scrbuf, paletteptr, palOffset);
Pokitto 35:4f7edccf8ed6 285 #endif
Pokitto 31:f4b9b85c7b62 286
Pokitto 31:f4b9b85c7b62 287 #if POK_SCREENMODE == MODE_GAMEBOY
Pokitto 31:f4b9b85c7b62 288 lcdRefreshModeGBC(m_scrbuf, paletteptr);
Pokitto 31:f4b9b85c7b62 289 #endif
Pokitto 31:f4b9b85c7b62 290
Pokitto 31:f4b9b85c7b62 291 #if POK_SCREENMODE == MODE_HI_16COLOR
Pokitto 31:f4b9b85c7b62 292 lcdRefreshMode3(m_scrbuf, paletteptr);
Pokitto 31:f4b9b85c7b62 293 #endif
Pokitto 31:f4b9b85c7b62 294
Pokitto 31:f4b9b85c7b62 295 #if POK_SCREENMODE == MODE_FAST_16COLOR
Pokitto 31:f4b9b85c7b62 296 lcdRefreshMode2(m_scrbuf, paletteptr);
Pokitto 31:f4b9b85c7b62 297 #endif
Pokitto 31:f4b9b85c7b62 298
Pokitto 31:f4b9b85c7b62 299 #if POK_SCREENMODE == MODE_GAMEBUINO_16COLOR
Pokitto 31:f4b9b85c7b62 300 lcdRefreshGB(m_scrbuf, paletteptr);
Pokitto 31:f4b9b85c7b62 301 #endif
Pokitto 31:f4b9b85c7b62 302
Pokitto 31:f4b9b85c7b62 303 #if POK_SCREENMODE == MODE_ARDUBOY_16COLOR
Pokitto 31:f4b9b85c7b62 304 lcdRefreshAB(m_scrbuf, paletteptr);
Pokitto 31:f4b9b85c7b62 305 #endif
Pokitto 31:f4b9b85c7b62 306
Pokitto 35:4f7edccf8ed6 307 #if POK_SCREENMODE == MODE14
Pokitto 35:4f7edccf8ed6 308 lcdRefreshMode14(m_scrbuf, paletteptr);
Pokitto 35:4f7edccf8ed6 309 #endif
Pokitto 35:4f7edccf8ed6 310
Pokitto 35:4f7edccf8ed6 311 #if POK_SCREENMODE == MODE15
Pokitto 35:4f7edccf8ed6 312 lcdRefreshMode15(paletteptr, m_scrbuf);
Pokitto 35:4f7edccf8ed6 313 #endif
Pokitto 35:4f7edccf8ed6 314
Pokitto 31:f4b9b85c7b62 315 #if POK_SCREENMODE == MODE_TILED_1BIT
Pokitto 31:f4b9b85c7b62 316 lcdRefreshT1(m_tilebuf, m_tilecolorbuf, m_tileset, paletteptr);
Pokitto 31:f4b9b85c7b62 317 #endif
Pokitto 31:f4b9b85c7b62 318 }
Pokitto 31:f4b9b85c7b62 319
Pokitto 31:f4b9b85c7b62 320 if (!persistence) clear();
Pokitto 31:f4b9b85c7b62 321
Pokitto 31:f4b9b85c7b62 322 /** draw volume bar if visible **/
Pokitto 31:f4b9b85c7b62 323 #if POK_SHOW_VOLUME > 0
Pokitto 31:f4b9b85c7b62 324 if (core.volbar_visible) {
Pokitto 31:f4b9b85c7b62 325 core.drawvolbar(4,20,_pdsound.getVolume(),true);
Pokitto 31:f4b9b85c7b62 326 core.volbar_visible--;
Pokitto 31:f4b9b85c7b62 327 }
Pokitto 31:f4b9b85c7b62 328 #endif // POK_SHOW_VOLUME
Pokitto 31:f4b9b85c7b62 329
Pokitto 31:f4b9b85c7b62 330 /** draw FPS if visible **/
Pokitto 35:4f7edccf8ed6 331 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 35:4f7edccf8ed6 332
Pokitto 35:4f7edccf8ed6 333 if(core.fps_counter_updated) {
Pokitto 31:f4b9b85c7b62 334
Pokitto 35:4f7edccf8ed6 335 // Store current state
Pokitto 35:4f7edccf8ed6 336 bool temp = isDirectPrintingEnabled();
Pokitto 35:4f7edccf8ed6 337 uint16_t oldcol = directcolor;
Pokitto 35:4f7edccf8ed6 338 uint16_t oldinvisiblecolor = invisiblecolor;
Pokitto 35:4f7edccf8ed6 339 uint16_t oldbgcol = directbgcolor;
Pokitto 35:4f7edccf8ed6 340 bool olddirecttextrotated = directtextrotated;
Pokitto 35:4f7edccf8ed6 341 int8_t oldadjustCharStep = adjustCharStep;
Pokitto 35:4f7edccf8ed6 342 const unsigned char * oldFont = font;
Pokitto 31:f4b9b85c7b62 343
Pokitto 35:4f7edccf8ed6 344 // Print FPS
Pokitto 35:4f7edccf8ed6 345 char str[16];
Pokitto 35:4f7edccf8ed6 346 sprintf(str,"FPS:%d ", (int)core.fps_counter);
Pokitto 35:4f7edccf8ed6 347 directcolor = COLOR_WHITE;
Pokitto 35:4f7edccf8ed6 348 invisiblecolor = COLOR_BLACK;
Pokitto 35:4f7edccf8ed6 349 directbgcolor = 0x0001; // Cannot be black as that is transparent color
Pokitto 35:4f7edccf8ed6 350 directtextrotated = true;
Pokitto 35:4f7edccf8ed6 351 adjustCharStep = 0;
Pokitto 35:4f7edccf8ed6 352 setFont(fontC64);
Pokitto 35:4f7edccf8ed6 353 enableDirectPrinting(true);
Pokitto 35:4f7edccf8ed6 354 print(0,0, str);
Pokitto 31:f4b9b85c7b62 355
Pokitto 35:4f7edccf8ed6 356 // Restore state
Pokitto 35:4f7edccf8ed6 357 enableDirectPrinting(temp);
Pokitto 35:4f7edccf8ed6 358 directcolor = oldcol;
Pokitto 35:4f7edccf8ed6 359 invisiblecolor = oldinvisiblecolor;
Pokitto 35:4f7edccf8ed6 360 directbgcolor = oldbgcol;
Pokitto 35:4f7edccf8ed6 361 directtextrotated = olddirecttextrotated;
Pokitto 35:4f7edccf8ed6 362 adjustCharStep = oldadjustCharStep;
Pokitto 35:4f7edccf8ed6 363 setFont(font);
Pokitto 35:4f7edccf8ed6 364
Pokitto 35:4f7edccf8ed6 365 core.fps_counter_updated = false;
Pokitto 35:4f7edccf8ed6 366 }
Pokitto 31:f4b9b85c7b62 367 #endif
Pokitto 31:f4b9b85c7b62 368 }
Pokitto 31:f4b9b85c7b62 369
Pokitto 31:f4b9b85c7b62 370 void Display::directBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t depth, uint8_t scale) {
Pokitto 31:f4b9b85c7b62 371 uint8_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 372 uint8_t h = *(bitmap + 1);
Pokitto 31:f4b9b85c7b62 373 bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
Pokitto 31:f4b9b85c7b62 374 int16_t i, j;
Pokitto 31:f4b9b85c7b62 375 int8_t byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 376
Pokitto 31:f4b9b85c7b62 377 if (depth == 1) {
Pokitto 31:f4b9b85c7b62 378 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 379 byteNum = i / 8;
Pokitto 31:f4b9b85c7b62 380 bitNum = i % 8;
Pokitto 31:f4b9b85c7b62 381 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 382 if (*(bitmap + j * byteWidth + byteNum) & (0x80 >> bitNum)) { //0x80 = B10000000
Pokitto 31:f4b9b85c7b62 383 if (scale==1) directPixel(x + i, y + j,directcolor);
Pokitto 31:f4b9b85c7b62 384 else {
Pokitto 31:f4b9b85c7b62 385 directPixel(x + i + i, y + j + j,directcolor);
Pokitto 31:f4b9b85c7b62 386 directPixel(x + 1 + i + i, y + j + j,directcolor);
Pokitto 31:f4b9b85c7b62 387 directPixel(x + i + i, y + j + j + 1,directcolor);
Pokitto 31:f4b9b85c7b62 388 directPixel(x + i + i + 1 , y + j + j + 1,directcolor);
Pokitto 31:f4b9b85c7b62 389 }
Pokitto 31:f4b9b85c7b62 390 }
Pokitto 31:f4b9b85c7b62 391 }
Pokitto 31:f4b9b85c7b62 392 }
Pokitto 31:f4b9b85c7b62 393 } else if (depth == 4) {
Pokitto 31:f4b9b85c7b62 394 for (j = 0; j < h; j+=1) {
Pokitto 31:f4b9b85c7b62 395 for (i = 0; i < w; i+=2) {
Pokitto 31:f4b9b85c7b62 396 uint16_t col = paletteptr[*bitmap>>4]; //higher nibble
Pokitto 31:f4b9b85c7b62 397 if (scale==2) {
Pokitto 31:f4b9b85c7b62 398 directPixel(x + (i<<1), y + (j<<1),col);
Pokitto 31:f4b9b85c7b62 399 directPixel(x + (i<<1) + 1, y + (j<<1),col);
Pokitto 31:f4b9b85c7b62 400 directPixel(x + (i<<1) + 1, y + (j<<1) + 1,col);
Pokitto 31:f4b9b85c7b62 401 directPixel(x + (i<<1), y + (j<<1) + 1,col);
Pokitto 31:f4b9b85c7b62 402 } else directPixel(x + i, y + j,col);
Pokitto 31:f4b9b85c7b62 403 col = paletteptr[*bitmap&0xF]; // lower nibble
Pokitto 31:f4b9b85c7b62 404 if (scale==2) {
Pokitto 31:f4b9b85c7b62 405 directPixel(x + (i<<1) + 2, y + (j<<1),col);
Pokitto 31:f4b9b85c7b62 406 directPixel(x + (i<<1) + 1 + 2, y + (j<<1),col);
Pokitto 31:f4b9b85c7b62 407 directPixel(x + (i<<1) + 1 + 2, y + (j<<1) + 1,col);
Pokitto 31:f4b9b85c7b62 408 directPixel(x + (i<<1) + 2 , y + (j<<1) + 1,col);
Pokitto 31:f4b9b85c7b62 409 } else directPixel(x + i + 1, y + j,col);
Pokitto 31:f4b9b85c7b62 410 bitmap++;
Pokitto 31:f4b9b85c7b62 411 }
Pokitto 31:f4b9b85c7b62 412 }
Pokitto 31:f4b9b85c7b62 413 }
Pokitto 31:f4b9b85c7b62 414
Pokitto 31:f4b9b85c7b62 415 }
Pokitto 31:f4b9b85c7b62 416
Pokitto 31:f4b9b85c7b62 417 int Display::directChar(int16_t x, int16_t y, uint16_t index){
Pokitto 31:f4b9b85c7b62 418 const uint8_t* bitmap = font;
Pokitto 31:f4b9b85c7b62 419 uint8_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 420 uint8_t h = *(bitmap + 1);
Pokitto 31:f4b9b85c7b62 421 uint8_t hbytes=0, xtra=1;
Pokitto 31:f4b9b85c7b62 422 if (h==8 || h==16) xtra=0; //don't add if exactly on byte limit
Pokitto 31:f4b9b85c7b62 423 hbytes=(h>>3)+xtra; //GLCD fonts are arranged w+1 times h/8 bytes
Pokitto 31:f4b9b85c7b62 424 //bitmap = bitmap + 3 + index * h * ((w>>3)+xtra); //add an offset to the pointer (fonts !)
Pokitto 31:f4b9b85c7b62 425 bitmap = bitmap + 4 + index * (w * hbytes + 1); //add an offset to the pointer (fonts !)
Pokitto 31:f4b9b85c7b62 426 //int8_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 427 int8_t i, j, numBytes;
Pokitto 31:f4b9b85c7b62 428 numBytes = *bitmap++; //first byte of char is the width in bytes
Pokitto 31:f4b9b85c7b62 429 // GLCD fonts are arranged LSB = topmost pixel of char, so its easy to just shift through the column
Pokitto 31:f4b9b85c7b62 430 uint16_t bitcolumn; //16 bits for 2x8 bit high characters
Pokitto 31:f4b9b85c7b62 431
Pokitto 31:f4b9b85c7b62 432 for (i = 0; i < numBytes; i++) {
Pokitto 31:f4b9b85c7b62 433 bitcolumn = *bitmap++;
Pokitto 31:f4b9b85c7b62 434 if (hbytes == 2) bitcolumn |= (*bitmap++)<<8; // add second byte for 16 bit high fonts
Pokitto 31:f4b9b85c7b62 435 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 436 if (bitcolumn&0x1) {
Pokitto 31:f4b9b85c7b62 437 if (fontSize==2) {
Pokitto 31:f4b9b85c7b62 438 directPixel(x + (i<<1) , y + (j<<1),directcolor);
Pokitto 31:f4b9b85c7b62 439 directPixel(x + (i<<1)+1, y + (j<<1),directcolor);
Pokitto 31:f4b9b85c7b62 440 directPixel(x + (i<<1) , y + (j<<1)+1,directcolor);
Pokitto 31:f4b9b85c7b62 441 directPixel(x + (i<<1)+1, y + (j<<1)+1,directcolor);
Pokitto 31:f4b9b85c7b62 442 } else {
Pokitto 31:f4b9b85c7b62 443 if(directtextrotated) directPixel(y + h - j - 1, x + i,directcolor);
Pokitto 31:f4b9b85c7b62 444 else directPixel(x + i, y + j,directcolor);
Pokitto 31:f4b9b85c7b62 445 }
Pokitto 31:f4b9b85c7b62 446
Pokitto 31:f4b9b85c7b62 447 } else if (directbgcolor != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 448 if (fontSize==2) {
Pokitto 31:f4b9b85c7b62 449 directPixel(x + (i<<1) , y + (j<<1),directbgcolor);
Pokitto 31:f4b9b85c7b62 450 directPixel(x + (i<<1)+1, y + (j<<1),directbgcolor);
Pokitto 31:f4b9b85c7b62 451 directPixel(x + (i<<1) , y + (j<<1)+1,directbgcolor);
Pokitto 31:f4b9b85c7b62 452 directPixel(x + (i<<1)+1, y + (j<<1)+1,directbgcolor);
Pokitto 31:f4b9b85c7b62 453 } else {
Pokitto 31:f4b9b85c7b62 454 if(directtextrotated) directPixel(y + h - j - 1, x + i,directbgcolor);
Pokitto 31:f4b9b85c7b62 455 else directPixel(x + i, y + j,directbgcolor);
Pokitto 31:f4b9b85c7b62 456 }
Pokitto 31:f4b9b85c7b62 457 }
Pokitto 31:f4b9b85c7b62 458 bitcolumn>>=1;
Pokitto 31:f4b9b85c7b62 459 }
Pokitto 31:f4b9b85c7b62 460 }
Pokitto 31:f4b9b85c7b62 461 return (numBytes+adjustCharStep)*fontSize; // for character stepping
Pokitto 31:f4b9b85c7b62 462 }
Pokitto 31:f4b9b85c7b62 463
Pokitto 31:f4b9b85c7b62 464 int Display::bufferChar(int16_t x, int16_t y, uint16_t index){
Pokitto 31:f4b9b85c7b62 465 const uint8_t* bitmap = font;
Pokitto 31:f4b9b85c7b62 466 uint8_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 467 uint8_t h = *(bitmap + 1);
Pokitto 31:f4b9b85c7b62 468 uint8_t hbytes=0, xtra=1;
Pokitto 31:f4b9b85c7b62 469 if (h==8 || h==16) xtra=0; //don't add if exactly on byte limit
Pokitto 31:f4b9b85c7b62 470 hbytes=(h>>3)+xtra; //GLCD fonts are arranged w+1 times h/8 bytes
Pokitto 31:f4b9b85c7b62 471 //bitmap = bitmap + 3 + index * h * ((w>>3)+xtra); //add an offset to the pointer (fonts !)
Pokitto 31:f4b9b85c7b62 472 bitmap = bitmap + 4 + index * (w * hbytes + 1); //add an offset to the pointer (fonts !)
Pokitto 31:f4b9b85c7b62 473 //int8_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 474 int8_t i, j, numBytes;
Pokitto 31:f4b9b85c7b62 475 numBytes = *bitmap++; //first byte of char is the width in bytes
Pokitto 31:f4b9b85c7b62 476 // GLCD fonts are arranged LSB = topmost pixel of char, so its easy to just shift through the column
Pokitto 31:f4b9b85c7b62 477 uint16_t bitcolumn; //16 bits for 2x8 bit high characters
Pokitto 31:f4b9b85c7b62 478
Pokitto 31:f4b9b85c7b62 479 for (i = 0; i < numBytes; i++) {
Pokitto 31:f4b9b85c7b62 480 bitcolumn = *bitmap++;
Pokitto 31:f4b9b85c7b62 481 if (hbytes == 2) bitcolumn |= (*bitmap++)<<8; // add second byte for 16 bit high fonts
Pokitto 31:f4b9b85c7b62 482 for (j = 0; j <= h; j++) { // was j<=h
Pokitto 31:f4b9b85c7b62 483 #if PROJ_ARDUBOY > 0
Pokitto 31:f4b9b85c7b62 484 if (bitcolumn&0x1) {
Pokitto 31:f4b9b85c7b62 485 drawPixel(x + i, y + 7 - j,color);
Pokitto 31:f4b9b85c7b62 486 } else drawPixel(x + i, y + 7 - j,bgcolor);
Pokitto 31:f4b9b85c7b62 487 bitcolumn>>=1;
Pokitto 31:f4b9b85c7b62 488 #else
Pokitto 31:f4b9b85c7b62 489 if (bitcolumn&0x1) {
Pokitto 31:f4b9b85c7b62 490 drawPixel(x + i, y + j,color);
Pokitto 31:f4b9b85c7b62 491 } else drawPixel(x + i, y + j,bgcolor);
Pokitto 31:f4b9b85c7b62 492 bitcolumn>>=1;
Pokitto 31:f4b9b85c7b62 493 #endif // PROJ_ARDUBOY
Pokitto 31:f4b9b85c7b62 494
Pokitto 31:f4b9b85c7b62 495 }
Pokitto 31:f4b9b85c7b62 496 }
Pokitto 31:f4b9b85c7b62 497
Pokitto 31:f4b9b85c7b62 498 return numBytes+adjustCharStep; // for character stepping
Pokitto 31:f4b9b85c7b62 499 }
Pokitto 31:f4b9b85c7b62 500
Pokitto 31:f4b9b85c7b62 501 void Display::clear() {
Pokitto 31:f4b9b85c7b62 502
Pokitto 31:f4b9b85c7b62 503 uint8_t c=0;
Pokitto 31:f4b9b85c7b62 504 c = bgcolor & (PALETTE_SIZE-1) ; //don't let palette go out of bounds
Pokitto 31:f4b9b85c7b62 505 if (bpp==1 && bgcolor) c=0xFF; // bgcolor !=0, set all pixels
Pokitto 31:f4b9b85c7b62 506 else if (bpp==2) {
Pokitto 31:f4b9b85c7b62 507 c = bgcolor & 0x3;
Pokitto 31:f4b9b85c7b62 508 c = c | (c << 2);
Pokitto 31:f4b9b85c7b62 509 c = c | (c << 4);
Pokitto 35:4f7edccf8ed6 510 } else if (bpp==3){
Pokitto 35:4f7edccf8ed6 511 uint16_t j = POK_BITFRAME;
Pokitto 35:4f7edccf8ed6 512 if (bgcolor & 0x1) memset((void*)m_scrbuf,0xFF,j);// R
Pokitto 35:4f7edccf8ed6 513 else memset((void*)m_scrbuf,0x00,j);// R
Pokitto 35:4f7edccf8ed6 514 if ((bgcolor>>1) & 0x1) memset((void*)m_scrbuf+POK_BITFRAME,0xFF,j);// G
Pokitto 35:4f7edccf8ed6 515 else memset((void*)m_scrbuf+POK_BITFRAME,0x00,j);// G
Pokitto 35:4f7edccf8ed6 516 if ((bgcolor>>2) & 0x1) memset((void*)m_scrbuf+POK_BITFRAME*2,0xFF,j);// B
Pokitto 35:4f7edccf8ed6 517 else memset((void*)m_scrbuf+POK_BITFRAME*2,0x00,j);// B
Pokitto 35:4f7edccf8ed6 518 setCursor(0,0);
Pokitto 35:4f7edccf8ed6 519 return;
Pokitto 31:f4b9b85c7b62 520 } else {
Pokitto 31:f4b9b85c7b62 521 c = (c & 0x0F) | (c << 4);
Pokitto 31:f4b9b85c7b62 522 }
Pokitto 31:f4b9b85c7b62 523 uint16_t j = sizeof(screenbuffer);
Pokitto 31:f4b9b85c7b62 524 memset((void*)m_scrbuf,c,j);
Pokitto 31:f4b9b85c7b62 525
Pokitto 31:f4b9b85c7b62 526 setCursor(0,0);
Pokitto 31:f4b9b85c7b62 527
Pokitto 31:f4b9b85c7b62 528 }
Pokitto 31:f4b9b85c7b62 529
Pokitto 31:f4b9b85c7b62 530 void Display::scroll(int16_t pixelrows) {
Pokitto 31:f4b9b85c7b62 531 uint16_t index = 0, index2=0,oc;
Pokitto 31:f4b9b85c7b62 532 if (pixelrows==0) return;
Pokitto 31:f4b9b85c7b62 533 if (pixelrows >= height) pixelrows=height-1;
Pokitto 31:f4b9b85c7b62 534 if (bpp == 4) index2 = pixelrows*width/2;
Pokitto 31:f4b9b85c7b62 535 else if (bpp == 2) index2 = pixelrows*width/4;
Pokitto 31:f4b9b85c7b62 536 else return;
Pokitto 31:f4b9b85c7b62 537 oc = color;
Pokitto 31:f4b9b85c7b62 538 color = bgcolor;
Pokitto 31:f4b9b85c7b62 539 if (pixelrows>0) {
Pokitto 31:f4b9b85c7b62 540 for (uint16_t y=0;y<height-pixelrows;y++) {
Pokitto 31:f4b9b85c7b62 541 for (uint16_t x=0;x<(width/8)*bpp;x++) screenbuffer[index++]=screenbuffer[index2++];
Pokitto 31:f4b9b85c7b62 542 }
Pokitto 31:f4b9b85c7b62 543 fillRect(0,cursorY,width,height);
Pokitto 31:f4b9b85c7b62 544 } else {
Pokitto 31:f4b9b85c7b62 545 for (uint16_t y=pixelrows;y<height;y++) {
Pokitto 31:f4b9b85c7b62 546 for (uint16_t x=0;x<(width*bpp)/8;x++) screenbuffer[index2++]=screenbuffer[index++];
Pokitto 31:f4b9b85c7b62 547 }
Pokitto 31:f4b9b85c7b62 548 fillRect(0,0,width,pixelrows);
Pokitto 31:f4b9b85c7b62 549 }
Pokitto 31:f4b9b85c7b62 550 color=oc;
Pokitto 31:f4b9b85c7b62 551 }
Pokitto 31:f4b9b85c7b62 552
Pokitto 31:f4b9b85c7b62 553 void Display::fillScreen(uint16_t c) {
Pokitto 31:f4b9b85c7b62 554 c = c & (PALETTE_SIZE-1) ; //don't let palette go out of bounds
Pokitto 31:f4b9b85c7b62 555 if (bpp==1 && c) c=0xFF; // set all pixels
Pokitto 31:f4b9b85c7b62 556 else if (bpp==2) {
Pokitto 31:f4b9b85c7b62 557 c = c & 0x3;
Pokitto 31:f4b9b85c7b62 558 c = c | (c << 2);
Pokitto 31:f4b9b85c7b62 559 c = c | (c << 4);
Pokitto 31:f4b9b85c7b62 560 } else {
Pokitto 31:f4b9b85c7b62 561 c = (c & 0x0F) | (c << 4);
Pokitto 31:f4b9b85c7b62 562 }
Pokitto 31:f4b9b85c7b62 563 memset((void*)m_scrbuf,c,sizeof(screenbuffer));
Pokitto 31:f4b9b85c7b62 564 }
Pokitto 31:f4b9b85c7b62 565
Pokitto 31:f4b9b85c7b62 566 void Display::setDefaultPalette() {
Pokitto 31:f4b9b85c7b62 567 #if PICOPALETTE
Pokitto 31:f4b9b85c7b62 568 loadRGBPalette(palettePico);
Pokitto 31:f4b9b85c7b62 569 #else
Pokitto 31:f4b9b85c7b62 570 loadRGBPalette(POK_DEFAULT_PALETTE);
Pokitto 31:f4b9b85c7b62 571 #endif //PICOPALETTE
Pokitto 31:f4b9b85c7b62 572 }
Pokitto 31:f4b9b85c7b62 573
Pokitto 31:f4b9b85c7b62 574 void Display::setColor(uint8_t c) {
Pokitto 31:f4b9b85c7b62 575 color = c & ((1<<POK_COLORDEPTH)-1); // cut out colors that go above palette limit
Pokitto 31:f4b9b85c7b62 576 }
Pokitto 31:f4b9b85c7b62 577
Pokitto 31:f4b9b85c7b62 578 void Display::setColor(uint8_t c,uint8_t bgc){
Pokitto 31:f4b9b85c7b62 579 color = c & ((1<<POK_COLORDEPTH)-1); // cut out colors that go above palette limit
Pokitto 31:f4b9b85c7b62 580 bgcolor = bgc & ((1<<POK_COLORDEPTH)-1); // cut out colors that go above palette limit
Pokitto 31:f4b9b85c7b62 581 }
Pokitto 31:f4b9b85c7b62 582
Pokitto 31:f4b9b85c7b62 583 void Display::setInvisibleColor(uint16_t c){
Pokitto 31:f4b9b85c7b62 584 invisiblecolor = c; // invisible color can have values beyond 255 for identification purposes
Pokitto 31:f4b9b85c7b62 585 }
Pokitto 31:f4b9b85c7b62 586
Pokitto 31:f4b9b85c7b62 587 uint8_t Display::getColor() {
Pokitto 31:f4b9b85c7b62 588 return color;
Pokitto 31:f4b9b85c7b62 589 }
Pokitto 31:f4b9b85c7b62 590
Pokitto 31:f4b9b85c7b62 591 uint8_t Display::getBgColor() {
Pokitto 31:f4b9b85c7b62 592 return bgcolor;
Pokitto 31:f4b9b85c7b62 593 }
Pokitto 31:f4b9b85c7b62 594
Pokitto 31:f4b9b85c7b62 595 uint16_t Display::getInvisibleColor() {
Pokitto 31:f4b9b85c7b62 596 return invisiblecolor;
Pokitto 31:f4b9b85c7b62 597 }
Pokitto 31:f4b9b85c7b62 598
Pokitto 31:f4b9b85c7b62 599 void Display::setClipRect(int16_t x, int16_t y, int16_t w, int16_t h) {
Pokitto 31:f4b9b85c7b62 600 clipX = x; clipY = y; clipW = w; clipH = h;
Pokitto 31:f4b9b85c7b62 601 }
Pokitto 31:f4b9b85c7b62 602
Pokitto 31:f4b9b85c7b62 603
Pokitto 31:f4b9b85c7b62 604 void Display::drawPixel(int16_t x,int16_t y, uint8_t col) {
Pokitto 31:f4b9b85c7b62 605 if (col==invisiblecolor) return; // do not draw transparent pixels
Pokitto 31:f4b9b85c7b62 606 if ((uint16_t)x >= width || (uint16_t)y >= height) return;
Pokitto 31:f4b9b85c7b62 607 col &= (PALETTE_SIZE-1);
Pokitto 31:f4b9b85c7b62 608
Pokitto 31:f4b9b85c7b62 609 #if POK_COLORDEPTH == 8
Pokitto 31:f4b9b85c7b62 610 m_scrbuf[x+width*y] = col;
Pokitto 31:f4b9b85c7b62 611 #endif
Pokitto 31:f4b9b85c7b62 612
Pokitto 31:f4b9b85c7b62 613 #if POK_GAMEBUINO_SUPPORT >0
Pokitto 31:f4b9b85c7b62 614
Pokitto 31:f4b9b85c7b62 615 uint8_t c = col;
Pokitto 31:f4b9b85c7b62 616 uint8_t ct = col;
Pokitto 31:f4b9b85c7b62 617
Pokitto 31:f4b9b85c7b62 618 uint16_t bitptr=0;
Pokitto 31:f4b9b85c7b62 619 for (uint8_t cbit=0;cbit<POK_COLORDEPTH;cbit++) {
Pokitto 31:f4b9b85c7b62 620 c = ct & 1; // take the lowest bit of the color index number
Pokitto 31:f4b9b85c7b62 621 if(c == 0){ //white - or actually "Clear bit"
Pokitto 31:f4b9b85c7b62 622 m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] &= ~_BV(y % 8);
Pokitto 31:f4b9b85c7b62 623 } else { //black - or actually "Set bit"
Pokitto 31:f4b9b85c7b62 624 m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] |= _BV(y % 8);
Pokitto 31:f4b9b85c7b62 625 }
Pokitto 31:f4b9b85c7b62 626 ct >>=1; // shift to get next bit
Pokitto 31:f4b9b85c7b62 627 bitptr += POK_BITFRAME; // move one screen worth of buffer forward to get to the next color bit
Pokitto 31:f4b9b85c7b62 628 } // POK_COLOURDEPTH
Pokitto 31:f4b9b85c7b62 629
Pokitto 31:f4b9b85c7b62 630 #else
Pokitto 31:f4b9b85c7b62 631 #if POK_COLORDEPTH == 1
Pokitto 31:f4b9b85c7b62 632 if (col) {m_scrbuf[(y >> 3) * width + x] |= (0x80 >> (y & 7)); return;}
Pokitto 31:f4b9b85c7b62 633 m_scrbuf[(y >> 3) * width + x] &= ~(0x80 >> (y & 7));
Pokitto 31:f4b9b85c7b62 634 #elif POK_COLORDEPTH == 2
Pokitto 31:f4b9b85c7b62 635 if (col) {
Pokitto 31:f4b9b85c7b62 636 col &= 3;
Pokitto 31:f4b9b85c7b62 637 }
Pokitto 31:f4b9b85c7b62 638 uint16_t i = y*(width>>2) + (x>>2);
Pokitto 31:f4b9b85c7b62 639 uint8_t pixel = m_scrbuf[i];
Pokitto 31:f4b9b85c7b62 640 uint8_t column = x&0x03;
Pokitto 31:f4b9b85c7b62 641 if (column==3) pixel = (pixel&0xFC)|(col); // bits 0-1
Pokitto 31:f4b9b85c7b62 642 else if (column==2) pixel = (pixel&0xF3)|(col<<2); // bits 2-3
Pokitto 31:f4b9b85c7b62 643 else if (column==1) pixel = (pixel&0xCF)|(col<<4); // bits 4-5
Pokitto 31:f4b9b85c7b62 644 else pixel = (pixel&0x3F)|(col<<6); // bits 6-7
Pokitto 31:f4b9b85c7b62 645 m_scrbuf[i] = pixel;
Pokitto 31:f4b9b85c7b62 646 #elif POK_COLORDEPTH == 3
Pokitto 35:4f7edccf8ed6 647 uint8_t c = col;
Pokitto 35:4f7edccf8ed6 648 uint8_t ct = col;
Pokitto 35:4f7edccf8ed6 649
Pokitto 35:4f7edccf8ed6 650 uint16_t bitptr=0;
Pokitto 35:4f7edccf8ed6 651 for (uint8_t cbit=0;cbit<POK_COLORDEPTH;cbit++) {
Pokitto 35:4f7edccf8ed6 652 c = ct & 1; // take the lowest bit of the color index number
Pokitto 35:4f7edccf8ed6 653 if(c == 0){ //white - or actually "Clear bit"
Pokitto 35:4f7edccf8ed6 654 m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] &= ~_BV(y % 8);
Pokitto 35:4f7edccf8ed6 655 } else { //black - or actually "Set bit"
Pokitto 35:4f7edccf8ed6 656 m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] |= _BV(y % 8);
Pokitto 35:4f7edccf8ed6 657 }
Pokitto 35:4f7edccf8ed6 658 ct >>=1; // shift to get next bit
Pokitto 35:4f7edccf8ed6 659 bitptr += POK_BITFRAME; // move one screen worth of buffer forward to get to the next color bit
Pokitto 35:4f7edccf8ed6 660 } // POK_COLOURDEPTH
Pokitto 31:f4b9b85c7b62 661 #elif POK_COLORDEPTH == 4
Pokitto 31:f4b9b85c7b62 662 uint16_t i = y*(width>>1) + (x>>1);
Pokitto 31:f4b9b85c7b62 663 uint8_t pixel = m_scrbuf[i];
Pokitto 31:f4b9b85c7b62 664 if (x&1) pixel = (pixel&0xF0)|(col);
Pokitto 31:f4b9b85c7b62 665 else pixel = (pixel&0x0F) | (col<<4);
Pokitto 31:f4b9b85c7b62 666 m_scrbuf[i] = pixel;
Pokitto 31:f4b9b85c7b62 667 #endif // POK_COLORDEPTH
Pokitto 31:f4b9b85c7b62 668 #endif // POK_GAMEBUINO_SUPPORT
Pokitto 31:f4b9b85c7b62 669 }
Pokitto 31:f4b9b85c7b62 670
Pokitto 31:f4b9b85c7b62 671 void Display::drawPixel(int16_t x,int16_t y) {
Pokitto 31:f4b9b85c7b62 672 if ((uint16_t)x >= width || (uint16_t)y >= height) return;
Pokitto 31:f4b9b85c7b62 673
Pokitto 31:f4b9b85c7b62 674 #if POK_COLORDEPTH == 8
Pokitto 31:f4b9b85c7b62 675 m_scrbuf[x+width*y] = color;
Pokitto 31:f4b9b85c7b62 676 #endif
Pokitto 31:f4b9b85c7b62 677
Pokitto 31:f4b9b85c7b62 678 #if POK_GAMEBUINO_SUPPORT > 0
Pokitto 31:f4b9b85c7b62 679
Pokitto 31:f4b9b85c7b62 680 uint8_t c = color;
Pokitto 31:f4b9b85c7b62 681 uint8_t ct = color;
Pokitto 31:f4b9b85c7b62 682 if(ct == INVERT){
Pokitto 31:f4b9b85c7b62 683 ct = !getPixel(x, y); //jonne - was c = !getP...
Pokitto 31:f4b9b85c7b62 684 }
Pokitto 31:f4b9b85c7b62 685
Pokitto 31:f4b9b85c7b62 686 uint16_t bitptr=0;
Pokitto 31:f4b9b85c7b62 687 for (uint8_t cbit=0;cbit<POK_COLORDEPTH;cbit++) {
Pokitto 31:f4b9b85c7b62 688 c = ct & 1; // take the lowest bit of the color index number
Pokitto 31:f4b9b85c7b62 689 if(c == 0){ //white - or actually "Clear bit"
Pokitto 31:f4b9b85c7b62 690 #if DISPLAY_ROT == NOROT
Pokitto 31:f4b9b85c7b62 691 m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] &= ~_BV(y % 8);
Pokitto 31:f4b9b85c7b62 692 #elif DISPLAY_ROT == ROTCCW
Pokitto 31:f4b9b85c7b62 693 m_scrbuf[LCDHEIGHT - y - 1 + (x / 8) * LCDWIDTH_NOROT + bitptr] &= ~_BV(x % 8);
Pokitto 31:f4b9b85c7b62 694 #elif DISPLAY_ROT == ROT180
Pokitto 31:f4b9b85c7b62 695 m_scrbuf[LCDWIDTH - x - 1 + ((LCDHEIGHT - y - 1) / 8) * LCDWIDTH_NOROT + bitptr] &= ~_BV((LCDHEIGHT - y - 1) % 8);
Pokitto 31:f4b9b85c7b62 696 #elif DISPLAY_ROT == ROTCW
Pokitto 31:f4b9b85c7b62 697 m_scrbuf[y + ((LCDWIDTH - x - 1) / 8) * LCDWIDTH_NOROT + bitbtr] &= ~_BV((LCDWIDTH - x - 1) % 8);
Pokitto 31:f4b9b85c7b62 698 #endif
Pokitto 31:f4b9b85c7b62 699 //return; //jonne
Pokitto 31:f4b9b85c7b62 700 } else { //black - or actually "Set bit"
Pokitto 31:f4b9b85c7b62 701 #if DISPLAY_ROT == NOROT
Pokitto 31:f4b9b85c7b62 702 m_scrbuf[x + (y / 8) * LCDWIDTH + bitptr] |= _BV(y % 8);
Pokitto 31:f4b9b85c7b62 703 #elif DISPLAY_ROT == ROTCCW
Pokitto 31:f4b9b85c7b62 704 m_scrbuf[LCDHEIGHT - y - 1 + (x / 8) * LCDWIDTH_NOROT + bitptr] |= _BV(x % 8);
Pokitto 31:f4b9b85c7b62 705 #elif DISPLAY_ROT == ROT180
Pokitto 31:f4b9b85c7b62 706 m_scrbuf[LCDWIDTH - x - 1 + ((LCDHEIGHT - y - 1) / 8) * LCDWIDTH_NOROT + bitptr] |= _BV((LCDHEIGHT - y - 1) % 8);
Pokitto 31:f4b9b85c7b62 707 #elif DISPLAY_ROT == ROTCW
Pokitto 31:f4b9b85c7b62 708 m_scrbuf[y + ((LCDWIDTH - x - 1) / 8) * LCDWIDTH_NOROT + bitptr] |= _BV((LCDWIDTH - x -1) % 8);
Pokitto 31:f4b9b85c7b62 709 #endif
Pokitto 31:f4b9b85c7b62 710 //return; //jonne
Pokitto 31:f4b9b85c7b62 711 }
Pokitto 31:f4b9b85c7b62 712 ct >>=1; // shift to get next bit
Pokitto 31:f4b9b85c7b62 713 bitptr += POK_BITFRAME; // move one screen worth of buffer forward to get to the next color bit
Pokitto 31:f4b9b85c7b62 714 } // POK_COLOURDEPTH
Pokitto 31:f4b9b85c7b62 715
Pokitto 31:f4b9b85c7b62 716 #else
Pokitto 31:f4b9b85c7b62 717
Pokitto 31:f4b9b85c7b62 718 /** NOT Gamebuino */
Pokitto 31:f4b9b85c7b62 719 #if POK_COLORDEPTH == 1
Pokitto 31:f4b9b85c7b62 720 if (color) {m_scrbuf[(y >> 3) * width + x] |= (0x80 >> (y & 7)); return;}
Pokitto 31:f4b9b85c7b62 721 m_scrbuf[(y >> 3) * width + x] &= ~(0x80 >> (y & 7));
Pokitto 31:f4b9b85c7b62 722 #elif POK_COLORDEPTH == 2
Pokitto 31:f4b9b85c7b62 723 uint16_t i = y*(width>>2) + (x>>2);
Pokitto 31:f4b9b85c7b62 724 uint8_t pixel = m_scrbuf[i];
Pokitto 31:f4b9b85c7b62 725 uint8_t column = x&0x03;
Pokitto 31:f4b9b85c7b62 726 if (column==3) pixel = (pixel&0xFC)|(color); // bits 0-1
Pokitto 31:f4b9b85c7b62 727 else if (column==2) pixel = (pixel&0xF3)|(color<<2); // bits 2-3
Pokitto 31:f4b9b85c7b62 728 else if (column==1) pixel = (pixel&0xCF)|(color<<4); // bits 4-5
Pokitto 31:f4b9b85c7b62 729 else pixel = (pixel&0x3F)|(color<<6); // bits 6-7
Pokitto 31:f4b9b85c7b62 730 m_scrbuf[i] = pixel;
Pokitto 31:f4b9b85c7b62 731 #elif POK_COLORDEPTH == 3
Pokitto 31:f4b9b85c7b62 732 #elif POK_COLORDEPTH == 4
Pokitto 31:f4b9b85c7b62 733 uint16_t i = y*(width>>1) + (x>>1);
Pokitto 31:f4b9b85c7b62 734 uint8_t pixel = m_scrbuf[i];
Pokitto 31:f4b9b85c7b62 735 if (x&1) pixel = (pixel&0xF0)|(color);
Pokitto 31:f4b9b85c7b62 736 else pixel = (pixel&0x0F) | (color<<4);
Pokitto 31:f4b9b85c7b62 737 m_scrbuf[i] = pixel;
Pokitto 31:f4b9b85c7b62 738 #endif // POK_COLORDEPTH
Pokitto 31:f4b9b85c7b62 739 #endif // POK_GAMEBUINO_SUPPORT
Pokitto 31:f4b9b85c7b62 740 }
Pokitto 31:f4b9b85c7b62 741
Pokitto 31:f4b9b85c7b62 742 uint8_t Display::getPixel(int16_t x,int16_t y) {
Pokitto 31:f4b9b85c7b62 743 if ((uint16_t)x >= width || (uint16_t)y >= height) return 0;
Pokitto 35:4f7edccf8ed6 744 #if POK_COLORDEPTH == 8
Pokitto 35:4f7edccf8ed6 745 uint16_t i = y*width+x;
Pokitto 35:4f7edccf8ed6 746 return m_scrbuf[i];
Pokitto 35:4f7edccf8ed6 747 #endif // POK_COLORDEPTH
Pokitto 35:4f7edccf8ed6 748
Pokitto 31:f4b9b85c7b62 749 #if POK_GAMEBUINO_SUPPORT
Pokitto 31:f4b9b85c7b62 750 uint8_t color=0; //jonne
Pokitto 31:f4b9b85c7b62 751 for (uint8_t cbit=0; cbit<POK_COLORDEPTH;cbit++) {
Pokitto 31:f4b9b85c7b62 752 color |= (m_scrbuf[x + (y / 8) * LCDWIDTH+POK_BITFRAME*cbit] >> (y % 8)) & 0x1 ; //jonne - added +504*cbit
Pokitto 31:f4b9b85c7b62 753 }
Pokitto 31:f4b9b85c7b62 754 return color;
Pokitto 31:f4b9b85c7b62 755 #else
Pokitto 31:f4b9b85c7b62 756 /** not gamebuino */
Pokitto 31:f4b9b85c7b62 757 #if POK_COLORDEPTH == 1
Pokitto 31:f4b9b85c7b62 758 return (m_scrbuf[(y >> 3) * width + x] & (0x80 >> (y & 7))) ? 1:0;
Pokitto 31:f4b9b85c7b62 759 #elif POK_COLORDEPTH == 2
Pokitto 31:f4b9b85c7b62 760 uint16_t i = y*(width>>2) + (x>>2);
Pokitto 31:f4b9b85c7b62 761 uint8_t pixel = m_scrbuf[i];
Pokitto 31:f4b9b85c7b62 762 uint8_t column = x&0x03;
Pokitto 31:f4b9b85c7b62 763 if (column==0) return pixel & 0x03; // bits 0-1
Pokitto 31:f4b9b85c7b62 764 else if (column==1) return (pixel & 0x0C)>>2; // bits 2-3
Pokitto 31:f4b9b85c7b62 765 else if (column==2) return (pixel & 0x30)>>4; // bits 4-5
Pokitto 31:f4b9b85c7b62 766 else return pixel>>6;; // bits 6-7
Pokitto 31:f4b9b85c7b62 767 #elif POK_COLORDEPTH == 3
Pokitto 31:f4b9b85c7b62 768 #elif POK_COLORDEPTH == 4
Pokitto 31:f4b9b85c7b62 769 uint16_t i = y*(width>>1) + (x>>1);
Pokitto 31:f4b9b85c7b62 770 uint8_t pixel = m_scrbuf[i];
Pokitto 31:f4b9b85c7b62 771 if (x&1) return pixel & 0x0F;
Pokitto 31:f4b9b85c7b62 772 else return pixel>>4;
Pokitto 31:f4b9b85c7b62 773 #endif // POK_COLORDEPTH
Pokitto 31:f4b9b85c7b62 774 #endif // POK_GAMEBUINO_SUPPORT
Pokitto 31:f4b9b85c7b62 775 }
Pokitto 31:f4b9b85c7b62 776
Pokitto 31:f4b9b85c7b62 777 void Display::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1) {
Pokitto 31:f4b9b85c7b62 778 if ((uint16_t)x0 >= width || (uint16_t)y0 >= height || (uint16_t)x1 >= width || (uint16_t)y1 >= height ) {
Pokitto 31:f4b9b85c7b62 779 if (clipLine (&x0,&y0,&x1,&y1)==0) return; // line out of bounds
Pokitto 31:f4b9b85c7b62 780 }
Pokitto 31:f4b9b85c7b62 781 if (x0 == x1)
Pokitto 31:f4b9b85c7b62 782 drawColumn(x0,y0,y1);
Pokitto 31:f4b9b85c7b62 783 else if (y0 == y1)
Pokitto 31:f4b9b85c7b62 784 drawRow(x0,x1,y0);
Pokitto 31:f4b9b85c7b62 785 else {
Pokitto 31:f4b9b85c7b62 786 int e;
Pokitto 31:f4b9b85c7b62 787 signed int dx,dy,j, temp;
Pokitto 31:f4b9b85c7b62 788 signed char s1,s2, xchange;
Pokitto 31:f4b9b85c7b62 789 signed int x,y;
Pokitto 31:f4b9b85c7b62 790
Pokitto 31:f4b9b85c7b62 791 x = x0;
Pokitto 31:f4b9b85c7b62 792 y = y0;
Pokitto 31:f4b9b85c7b62 793
Pokitto 31:f4b9b85c7b62 794 //take absolute value
Pokitto 31:f4b9b85c7b62 795 if (x1 < x0) {
Pokitto 31:f4b9b85c7b62 796 dx = x0 - x1;
Pokitto 31:f4b9b85c7b62 797 s1 = -1;
Pokitto 31:f4b9b85c7b62 798 }
Pokitto 31:f4b9b85c7b62 799 else if (x1 == x0) {
Pokitto 31:f4b9b85c7b62 800 dx = 0;
Pokitto 31:f4b9b85c7b62 801 s1 = 0;
Pokitto 31:f4b9b85c7b62 802 }
Pokitto 31:f4b9b85c7b62 803 else {
Pokitto 31:f4b9b85c7b62 804 dx = x1 - x0;
Pokitto 31:f4b9b85c7b62 805 s1 = 1;
Pokitto 31:f4b9b85c7b62 806 }
Pokitto 31:f4b9b85c7b62 807
Pokitto 31:f4b9b85c7b62 808 if (y1 < y0) {
Pokitto 31:f4b9b85c7b62 809 dy = y0 - y1;
Pokitto 31:f4b9b85c7b62 810 s2 = -1;
Pokitto 31:f4b9b85c7b62 811 }
Pokitto 31:f4b9b85c7b62 812 else if (y1 == y0) {
Pokitto 31:f4b9b85c7b62 813 dy = 0;
Pokitto 31:f4b9b85c7b62 814 s2 = 0;
Pokitto 31:f4b9b85c7b62 815 }
Pokitto 31:f4b9b85c7b62 816 else {
Pokitto 31:f4b9b85c7b62 817 dy = y1 - y0;
Pokitto 31:f4b9b85c7b62 818 s2 = 1;
Pokitto 31:f4b9b85c7b62 819 }
Pokitto 31:f4b9b85c7b62 820
Pokitto 31:f4b9b85c7b62 821 xchange = 0;
Pokitto 31:f4b9b85c7b62 822
Pokitto 31:f4b9b85c7b62 823 if (dy>dx) {
Pokitto 31:f4b9b85c7b62 824 temp = dx;
Pokitto 31:f4b9b85c7b62 825 dx = dy;
Pokitto 31:f4b9b85c7b62 826 dy = temp;
Pokitto 31:f4b9b85c7b62 827 xchange = 1;
Pokitto 31:f4b9b85c7b62 828 }
Pokitto 31:f4b9b85c7b62 829
Pokitto 31:f4b9b85c7b62 830 e = ((int)dy<<1) - dx;
Pokitto 31:f4b9b85c7b62 831
Pokitto 31:f4b9b85c7b62 832 for (j=0; j<=dx; j++) {
Pokitto 31:f4b9b85c7b62 833 drawPixel(x,y);
Pokitto 31:f4b9b85c7b62 834
Pokitto 31:f4b9b85c7b62 835 if (e>=0) {
Pokitto 31:f4b9b85c7b62 836 if (xchange==1) x = x + s1;
Pokitto 31:f4b9b85c7b62 837 else y = y + s2;
Pokitto 31:f4b9b85c7b62 838 e = e - ((int)dx<<1);
Pokitto 31:f4b9b85c7b62 839 }
Pokitto 31:f4b9b85c7b62 840 if (xchange==1)
Pokitto 31:f4b9b85c7b62 841 y = y + s2;
Pokitto 31:f4b9b85c7b62 842 else
Pokitto 31:f4b9b85c7b62 843 x = x + s1;
Pokitto 31:f4b9b85c7b62 844 e = e + ((int)dy<<1);
Pokitto 31:f4b9b85c7b62 845 }
Pokitto 31:f4b9b85c7b62 846 }
Pokitto 31:f4b9b85c7b62 847 }
Pokitto 31:f4b9b85c7b62 848
Pokitto 31:f4b9b85c7b62 849 uint8_t Display::clipLine(int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1){
Pokitto 31:f4b9b85c7b62 850 // Check X bounds
Pokitto 31:f4b9b85c7b62 851 if (*x1<*x0) {
Pokitto 31:f4b9b85c7b62 852 //std::swap (*x1,*x0); // swap so that we dont have to check x1 also
Pokitto 31:f4b9b85c7b62 853 swapWT(int16_t*,x1,x0);
Pokitto 31:f4b9b85c7b62 854 //std::swap (*y1,*y0); // y needs to be swaaped also
Pokitto 31:f4b9b85c7b62 855 swapWT(int16_t*,y1,y0);
Pokitto 31:f4b9b85c7b62 856 }
Pokitto 31:f4b9b85c7b62 857
Pokitto 31:f4b9b85c7b62 858 if (*x0>=width) return 0; // whole line is out of bounds
Pokitto 31:f4b9b85c7b62 859
Pokitto 31:f4b9b85c7b62 860 // Clip against X0 = 0
Pokitto 31:f4b9b85c7b62 861 if (*x0 < 0) {
Pokitto 31:f4b9b85c7b62 862 if ( *x1 < 0) return 0; // nothing visible
Pokitto 31:f4b9b85c7b62 863 int16_t dx = (*x1 - *x0);
Pokitto 31:f4b9b85c7b62 864 int16_t dy = ((*y1 - *y0) << 8); // 8.8 fixed point calculation trick
Pokitto 31:f4b9b85c7b62 865 int16_t m = dy/dx;
Pokitto 31:f4b9b85c7b62 866 *y0 = *y0 + ((m*-*x0)>>8); // get y0 at boundary
Pokitto 31:f4b9b85c7b62 867 *x0 = 0;
Pokitto 31:f4b9b85c7b62 868 }
Pokitto 31:f4b9b85c7b62 869
Pokitto 31:f4b9b85c7b62 870 // Clip against x1 = 83
Pokitto 31:f4b9b85c7b62 871 if (*x1 >= width) {
Pokitto 31:f4b9b85c7b62 872 int16_t dx = (*x1 - *x0);
Pokitto 31:f4b9b85c7b62 873 int16_t dy = ((*y1 - *y0) << 8); // 8.8 fixed point calculation trick
Pokitto 31:f4b9b85c7b62 874 int16_t m = dy/dx;
Pokitto 31:f4b9b85c7b62 875 //*y1 = *y1 + ((m*(*x1-XMAX))>>8); // get y0 at boundary
Pokitto 31:f4b9b85c7b62 876 *y1 = *y1 + ((m*(width-1-*x1))>>8); // get y0 at boundary
Pokitto 31:f4b9b85c7b62 877 *x1 = width-1;
Pokitto 31:f4b9b85c7b62 878 }
Pokitto 31:f4b9b85c7b62 879
Pokitto 31:f4b9b85c7b62 880 // Check Y bounds
Pokitto 31:f4b9b85c7b62 881 if (*y1<*y0) {
Pokitto 31:f4b9b85c7b62 882 //std::swap (*x1,*x0); // swap so that we dont have to check x1 also
Pokitto 31:f4b9b85c7b62 883 swapWT(int16_t*,x1,x0);
Pokitto 31:f4b9b85c7b62 884 //std::swap (*y1,*y0); // y needs to be swaaped also
Pokitto 31:f4b9b85c7b62 885 swapWT(int16_t*,y1,y0);
Pokitto 31:f4b9b85c7b62 886 }
Pokitto 31:f4b9b85c7b62 887
Pokitto 31:f4b9b85c7b62 888 if (*y0>=height) return 0; // whole line is out of bounds
Pokitto 31:f4b9b85c7b62 889
Pokitto 31:f4b9b85c7b62 890 if (*y0 < 0) {
Pokitto 31:f4b9b85c7b62 891 if ( *y1 < 0) return 0; // nothing visible
Pokitto 31:f4b9b85c7b62 892 int16_t dx = (*x1 - *x0) << 8;
Pokitto 31:f4b9b85c7b62 893 int16_t dy = (*y1 - *y0); // 8.8 fixed point calculation trick
Pokitto 31:f4b9b85c7b62 894 int16_t m = dx/dy;
Pokitto 31:f4b9b85c7b62 895 *x0 = *x0 + ((m*-*y0)>>8); // get x0 at boundary
Pokitto 31:f4b9b85c7b62 896 *y0 = 0;
Pokitto 31:f4b9b85c7b62 897 }
Pokitto 31:f4b9b85c7b62 898
Pokitto 31:f4b9b85c7b62 899 // Clip against y1 = 47
Pokitto 31:f4b9b85c7b62 900 if (*y1 >= height) {
Pokitto 31:f4b9b85c7b62 901 int16_t dx = (*x1 - *x0) << 8;
Pokitto 31:f4b9b85c7b62 902 int16_t dy = (*y1 - *y0); // 8.8 fixed point calculation trick
Pokitto 31:f4b9b85c7b62 903 int16_t m = dx/dy;
Pokitto 31:f4b9b85c7b62 904 *x1 = *x1 + ((m*(height-1-*y1))>>8); // get y0 at boundary
Pokitto 31:f4b9b85c7b62 905 //*x1 = *x1 + ((m*(*y1-YMAX))>>8); // get y0 at boundary
Pokitto 31:f4b9b85c7b62 906 *y1 = height-1;
Pokitto 31:f4b9b85c7b62 907 }
Pokitto 31:f4b9b85c7b62 908 return 1; // clipped succesfully
Pokitto 31:f4b9b85c7b62 909 }
Pokitto 31:f4b9b85c7b62 910
Pokitto 31:f4b9b85c7b62 911 void Display::map1BitColumn(int16_t x, int16_t sy, int16_t ey, const uint8_t* bitmap, uint16_t column){
Pokitto 31:f4b9b85c7b62 912 if ((uint16_t)sy>=height && (uint16_t)ey>=height) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 913 if ((uint16_t)x>=width) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 914 if (sy>ey) {
Pokitto 31:f4b9b85c7b62 915 int y=sy;
Pokitto 31:f4b9b85c7b62 916 sy=ey;
Pokitto 31:f4b9b85c7b62 917 ey=y; // swap around so that x0 is less than x1
Pokitto 31:f4b9b85c7b62 918 }
Pokitto 31:f4b9b85c7b62 919 uint16_t bmw,bmh;
Pokitto 31:f4b9b85c7b62 920 float texelstep, texelindex;
Pokitto 31:f4b9b85c7b62 921 bmw = *(bitmap);
Pokitto 31:f4b9b85c7b62 922 bmh = *(bitmap+1);
Pokitto 31:f4b9b85c7b62 923 if (column>bmw-1) column=bmw-1;
Pokitto 31:f4b9b85c7b62 924 bitmap += 2;
Pokitto 31:f4b9b85c7b62 925 bitmap += column;
Pokitto 31:f4b9b85c7b62 926 texelstep = (float)bmh/((float)ey-(float)sy);
Pokitto 31:f4b9b85c7b62 927 texelindex = 0;
Pokitto 31:f4b9b85c7b62 928 for (int y=sy; y <= ey; y++, texelindex += texelstep) {
Pokitto 31:f4b9b85c7b62 929 uint8_t texel;
Pokitto 31:f4b9b85c7b62 930 uint8_t currbyte, bit;
Pokitto 31:f4b9b85c7b62 931 currbyte = texelindex / 8;
Pokitto 31:f4b9b85c7b62 932 bit = 7-((uint16_t) texelindex & 0x7);
Pokitto 31:f4b9b85c7b62 933 texel=*(bitmap+currbyte*bmw);
Pokitto 31:f4b9b85c7b62 934 if (texel & (1<<bit)) drawPixel(x,y);
Pokitto 31:f4b9b85c7b62 935 else if (bgcolor != invisiblecolor) drawPixel(x,y,bgcolor);
Pokitto 31:f4b9b85c7b62 936 }
Pokitto 31:f4b9b85c7b62 937 };
Pokitto 31:f4b9b85c7b62 938
Pokitto 31:f4b9b85c7b62 939 void Display::drawColumn(int16_t x, int16_t sy, int16_t ey){
Pokitto 31:f4b9b85c7b62 940 if ((uint16_t)sy>=height && (uint16_t)ey>=height) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 941 if ((uint16_t)x>=width) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 942 if (sy>ey) {
Pokitto 31:f4b9b85c7b62 943 int y=sy;
Pokitto 31:f4b9b85c7b62 944 sy=ey;
Pokitto 31:f4b9b85c7b62 945 ey=y; // swap around so that x0 is less than x1
Pokitto 31:f4b9b85c7b62 946 }
Pokitto 31:f4b9b85c7b62 947 for (int y=sy; y <= ey; y++) {
Pokitto 31:f4b9b85c7b62 948 drawPixel(x,y);
Pokitto 31:f4b9b85c7b62 949 }
Pokitto 31:f4b9b85c7b62 950 }
Pokitto 31:f4b9b85c7b62 951
Pokitto 31:f4b9b85c7b62 952 void Display::drawRow(int16_t x0, int16_t x1, int16_t y){
Pokitto 31:f4b9b85c7b62 953 if ((uint16_t)x0>=width && (uint16_t)x1>=width) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 954 if ((uint16_t)y>=height) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 955
Pokitto 31:f4b9b85c7b62 956 if (x0>x1) {
Pokitto 31:f4b9b85c7b62 957 int x=x0;
Pokitto 31:f4b9b85c7b62 958 x0=x1;
Pokitto 31:f4b9b85c7b62 959 x1=x; // swap around so that x0 is less than x1
Pokitto 31:f4b9b85c7b62 960 }
Pokitto 31:f4b9b85c7b62 961 for (int x=x0; x <= x1; x++) {
Pokitto 31:f4b9b85c7b62 962 drawPixel(x,y);
Pokitto 31:f4b9b85c7b62 963 }
Pokitto 31:f4b9b85c7b62 964 }
Pokitto 31:f4b9b85c7b62 965
Pokitto 31:f4b9b85c7b62 966 void Display::drawFastVLine(int16_t x, int16_t y, int16_t h){
Pokitto 31:f4b9b85c7b62 967 if (h<0) {y += h; h = -h;}
Pokitto 31:f4b9b85c7b62 968 drawColumn(x,y,y+h);
Pokitto 31:f4b9b85c7b62 969 }
Pokitto 31:f4b9b85c7b62 970
Pokitto 31:f4b9b85c7b62 971 void Display::drawFastHLine(int16_t x, int16_t y, int16_t w){
Pokitto 31:f4b9b85c7b62 972 if (w<0) {x += w; w = -w;}
Pokitto 31:f4b9b85c7b62 973 drawRow(x,x+w-1,y);
Pokitto 31:f4b9b85c7b62 974 }
Pokitto 31:f4b9b85c7b62 975
Pokitto 31:f4b9b85c7b62 976 void Display::drawRectangle(int16_t x0, int16_t y0, int16_t w, int16_t h) {
Pokitto 31:f4b9b85c7b62 977 drawColumn(x0,y0,y0+h);
Pokitto 31:f4b9b85c7b62 978 drawColumn(x0+w,y0,y0+h);
Pokitto 31:f4b9b85c7b62 979 drawRow(x0,x0+w,y0);
Pokitto 31:f4b9b85c7b62 980 drawRow(x0,x0+w,y0+h);
Pokitto 31:f4b9b85c7b62 981 }
Pokitto 31:f4b9b85c7b62 982
Pokitto 31:f4b9b85c7b62 983 void Display::fillRectangle(int16_t x0,int16_t y0, int16_t w, int16_t h){
Pokitto 31:f4b9b85c7b62 984 int16_t x,y,x1,y1;
Pokitto 31:f4b9b85c7b62 985 x1=x0+w;y1=y0+h;
Pokitto 31:f4b9b85c7b62 986 if ((x0<0 && x1<0) || (x0>=width && x1 >=width)) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 987 if ((y0<0 && y1<0) || (y0>=height && y1 >=height)) return; //completely out of bounds
Pokitto 31:f4b9b85c7b62 988 if (x0>x1) {x=x1;x1=x0;}
Pokitto 31:f4b9b85c7b62 989 else x=x0;
Pokitto 31:f4b9b85c7b62 990 if (y0>y1) {y=y1;y1=y0;}
Pokitto 31:f4b9b85c7b62 991 else y=y0;
Pokitto 31:f4b9b85c7b62 992 if (x<0) x=0;
Pokitto 31:f4b9b85c7b62 993 if (y<0) y=0;
Pokitto 31:f4b9b85c7b62 994 for (;x<x1;x++) drawColumn(x,y,y1);
Pokitto 31:f4b9b85c7b62 995 }
Pokitto 31:f4b9b85c7b62 996
Pokitto 31:f4b9b85c7b62 997 void Display::fillRect(int16_t x, int16_t y, int16_t w, int16_t h) {
Pokitto 31:f4b9b85c7b62 998 fillRectangle(x,y,w,h);
Pokitto 31:f4b9b85c7b62 999 }
Pokitto 31:f4b9b85c7b62 1000
Pokitto 31:f4b9b85c7b62 1001 void Display::drawRect(int16_t x, int16_t y, int16_t w, int16_t h) {
Pokitto 31:f4b9b85c7b62 1002 drawRectangle(x,y,w,h);
Pokitto 31:f4b9b85c7b62 1003 }
Pokitto 31:f4b9b85c7b62 1004
Pokitto 31:f4b9b85c7b62 1005 void Display::drawCircle(int16_t x0, int16_t y0, int16_t r) {
Pokitto 31:f4b9b85c7b62 1006 int16_t f = 1 - r;
Pokitto 31:f4b9b85c7b62 1007 int16_t ddF_x = 1;
Pokitto 31:f4b9b85c7b62 1008 int16_t ddF_y = -2 * r;
Pokitto 31:f4b9b85c7b62 1009 int16_t x = 0;
Pokitto 31:f4b9b85c7b62 1010 int16_t y = r;
Pokitto 31:f4b9b85c7b62 1011
Pokitto 31:f4b9b85c7b62 1012 drawPixel(x0, y0 + r);
Pokitto 31:f4b9b85c7b62 1013 drawPixel(x0, y0 - r);
Pokitto 31:f4b9b85c7b62 1014 drawPixel(x0 + r, y0);
Pokitto 31:f4b9b85c7b62 1015 drawPixel(x0 - r, y0);
Pokitto 31:f4b9b85c7b62 1016
Pokitto 31:f4b9b85c7b62 1017 while (x < y) {
Pokitto 31:f4b9b85c7b62 1018 if (f >= 0) {
Pokitto 31:f4b9b85c7b62 1019
Pokitto 31:f4b9b85c7b62 1020 y--;
Pokitto 31:f4b9b85c7b62 1021 ddF_y += 2;
Pokitto 31:f4b9b85c7b62 1022 f += ddF_y;
Pokitto 31:f4b9b85c7b62 1023 }
Pokitto 31:f4b9b85c7b62 1024 x++;
Pokitto 31:f4b9b85c7b62 1025 ddF_x += 2;
Pokitto 31:f4b9b85c7b62 1026 f += ddF_x;
Pokitto 31:f4b9b85c7b62 1027
Pokitto 31:f4b9b85c7b62 1028 drawPixel(x0 + x, y0 + y);
Pokitto 31:f4b9b85c7b62 1029 drawPixel(x0 - x, y0 + y);
Pokitto 31:f4b9b85c7b62 1030 drawPixel(x0 + x, y0 - y);
Pokitto 31:f4b9b85c7b62 1031 drawPixel(x0 - x, y0 - y);
Pokitto 31:f4b9b85c7b62 1032 drawPixel(x0 + y, y0 + x);
Pokitto 31:f4b9b85c7b62 1033 drawPixel(x0 - y, y0 + x);
Pokitto 31:f4b9b85c7b62 1034 drawPixel(x0 + y, y0 - x);
Pokitto 31:f4b9b85c7b62 1035 drawPixel(x0 - y, y0 - x);
Pokitto 31:f4b9b85c7b62 1036
Pokitto 31:f4b9b85c7b62 1037 }
Pokitto 31:f4b9b85c7b62 1038 }
Pokitto 31:f4b9b85c7b62 1039
Pokitto 31:f4b9b85c7b62 1040 void Display::drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername) {
Pokitto 31:f4b9b85c7b62 1041 int16_t f = 1 - r;
Pokitto 31:f4b9b85c7b62 1042 int16_t ddF_x = 1;
Pokitto 31:f4b9b85c7b62 1043 int16_t ddF_y = -2 * r;
Pokitto 31:f4b9b85c7b62 1044 int16_t x = 0;
Pokitto 31:f4b9b85c7b62 1045 int16_t y = r;
Pokitto 31:f4b9b85c7b62 1046
Pokitto 31:f4b9b85c7b62 1047 while (x < y) {
Pokitto 31:f4b9b85c7b62 1048 if (f >= 0) {
Pokitto 31:f4b9b85c7b62 1049 y--;
Pokitto 31:f4b9b85c7b62 1050 ddF_y += 2;
Pokitto 31:f4b9b85c7b62 1051 f += ddF_y;
Pokitto 31:f4b9b85c7b62 1052 }
Pokitto 31:f4b9b85c7b62 1053 x++;
Pokitto 31:f4b9b85c7b62 1054 ddF_x += 2;
Pokitto 31:f4b9b85c7b62 1055 f += ddF_x;
Pokitto 31:f4b9b85c7b62 1056 if (cornername & 0x4) {
Pokitto 31:f4b9b85c7b62 1057 drawPixel(x0 + x, y0 + y);
Pokitto 31:f4b9b85c7b62 1058 drawPixel(x0 + y, y0 + x);
Pokitto 31:f4b9b85c7b62 1059 }
Pokitto 31:f4b9b85c7b62 1060 if (cornername & 0x2) {
Pokitto 31:f4b9b85c7b62 1061 drawPixel(x0 + x, y0 - y);
Pokitto 31:f4b9b85c7b62 1062 drawPixel(x0 + y, y0 - x);
Pokitto 31:f4b9b85c7b62 1063 }
Pokitto 31:f4b9b85c7b62 1064 if (cornername & 0x8) {
Pokitto 31:f4b9b85c7b62 1065 drawPixel(x0 - y, y0 + x);
Pokitto 31:f4b9b85c7b62 1066 drawPixel(x0 - x, y0 + y);
Pokitto 31:f4b9b85c7b62 1067 }
Pokitto 31:f4b9b85c7b62 1068 if (cornername & 0x1) {
Pokitto 31:f4b9b85c7b62 1069
Pokitto 31:f4b9b85c7b62 1070 drawPixel(x0 - y, y0 - x);
Pokitto 31:f4b9b85c7b62 1071 drawPixel(x0 - x, y0 - y);
Pokitto 31:f4b9b85c7b62 1072 }
Pokitto 31:f4b9b85c7b62 1073 }
Pokitto 31:f4b9b85c7b62 1074 }
Pokitto 31:f4b9b85c7b62 1075
Pokitto 31:f4b9b85c7b62 1076 void Display::fillCircle(int16_t x0, int16_t y0, int16_t r) {
Pokitto 31:f4b9b85c7b62 1077 drawFastVLine(x0, y0 - r, 2 * r );
Pokitto 31:f4b9b85c7b62 1078 fillCircleHelper(x0, y0, r, 3, 0);
Pokitto 31:f4b9b85c7b62 1079 }
Pokitto 31:f4b9b85c7b62 1080
Pokitto 31:f4b9b85c7b62 1081 void Display::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername, int16_t delta) {
Pokitto 31:f4b9b85c7b62 1082 int16_t f = 1 - r;
Pokitto 31:f4b9b85c7b62 1083 int16_t ddF_x = 1;
Pokitto 31:f4b9b85c7b62 1084 int16_t ddF_y = -2 * r;
Pokitto 31:f4b9b85c7b62 1085 int16_t x = 0;
Pokitto 31:f4b9b85c7b62 1086 int16_t y = r;
Pokitto 31:f4b9b85c7b62 1087
Pokitto 31:f4b9b85c7b62 1088 while (x < y) {
Pokitto 31:f4b9b85c7b62 1089 if (f >= 0) {
Pokitto 31:f4b9b85c7b62 1090 y--;
Pokitto 31:f4b9b85c7b62 1091 ddF_y += 2;
Pokitto 31:f4b9b85c7b62 1092 f += ddF_y;
Pokitto 31:f4b9b85c7b62 1093 }
Pokitto 31:f4b9b85c7b62 1094 x++;
Pokitto 31:f4b9b85c7b62 1095 ddF_x += 2;
Pokitto 31:f4b9b85c7b62 1096 f += ddF_x;
Pokitto 31:f4b9b85c7b62 1097
Pokitto 31:f4b9b85c7b62 1098 if (cornername & 0x1) {
Pokitto 31:f4b9b85c7b62 1099 drawFastVLine(x0 + x, y0 - y, 2 * y + 1 + delta-1); //added -1 here, jonne
Pokitto 31:f4b9b85c7b62 1100 drawFastVLine(x0 + y, y0 - x, 2 * x + 1 + delta-1); //added -1 here, jonne
Pokitto 31:f4b9b85c7b62 1101 }
Pokitto 31:f4b9b85c7b62 1102 if (cornername & 0x2) {
Pokitto 31:f4b9b85c7b62 1103
Pokitto 31:f4b9b85c7b62 1104 drawFastVLine(x0 - x, y0 - y, 2 * y + 1 + delta-1); //added -1 here, jonne
Pokitto 31:f4b9b85c7b62 1105 drawFastVLine(x0 - y, y0 - x, 2 * x + 1 + delta-1); //added -1 here, jonne
Pokitto 31:f4b9b85c7b62 1106 }
Pokitto 31:f4b9b85c7b62 1107 }
Pokitto 31:f4b9b85c7b62 1108 }
Pokitto 31:f4b9b85c7b62 1109
Pokitto 31:f4b9b85c7b62 1110 void Display::drawRoundRect(int16_t x, int16_t y, int16_t w,int16_t h, int16_t r) {
Pokitto 31:f4b9b85c7b62 1111 if (r<2) {drawRectangle(x,y,w,h);return;}
Pokitto 31:f4b9b85c7b62 1112 // smarter version
Pokitto 31:f4b9b85c7b62 1113 drawFastHLine(x + r, y, w - 2 * r); // Top
Pokitto 31:f4b9b85c7b62 1114 drawFastHLine(x + r, y + h - 1, w - 2 * r); // Bottom
Pokitto 31:f4b9b85c7b62 1115 drawFastVLine(x, y + r, h - 2 * r); // Left
Pokitto 31:f4b9b85c7b62 1116 drawFastVLine(x + w - 1, y + r, h - 2 * r); // Right
Pokitto 31:f4b9b85c7b62 1117 // draw four corners
Pokitto 31:f4b9b85c7b62 1118 drawCircleHelper(x + r, y + r, r, 1);
Pokitto 31:f4b9b85c7b62 1119 drawCircleHelper(x + w - r - 1, y + r, r, 2);
Pokitto 31:f4b9b85c7b62 1120 drawCircleHelper(x + w - r - 1, y + h - r - 1, r, 4);
Pokitto 31:f4b9b85c7b62 1121 drawCircleHelper(x + r, y + h - r - 1, r, 8);
Pokitto 31:f4b9b85c7b62 1122 }
Pokitto 31:f4b9b85c7b62 1123
Pokitto 31:f4b9b85c7b62 1124 void Display::fillRoundRect(int16_t x, int16_t y, int16_t w,int16_t h, int16_t r) {
Pokitto 31:f4b9b85c7b62 1125 if (r<2) {fillRectangle(x,y,w,h);return;}
Pokitto 31:f4b9b85c7b62 1126 fillRectangle(x + r, y, w - 2 * r, h-1);
Pokitto 31:f4b9b85c7b62 1127 // draw four corners
Pokitto 31:f4b9b85c7b62 1128 fillCircleHelper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1);
Pokitto 31:f4b9b85c7b62 1129 fillCircleHelper(x + r, y + r, r, 2, h - 2 * r - 1);
Pokitto 31:f4b9b85c7b62 1130 }
Pokitto 31:f4b9b85c7b62 1131
Pokitto 31:f4b9b85c7b62 1132 void Display::drawTriangle(int16_t x0, int16_t y0,
Pokitto 31:f4b9b85c7b62 1133 int16_t x1, int16_t y1,
Pokitto 31:f4b9b85c7b62 1134 int16_t x2, int16_t y2) {
Pokitto 31:f4b9b85c7b62 1135 drawLine(x0, y0, x1, y1);
Pokitto 31:f4b9b85c7b62 1136 drawLine(x1, y1, x2, y2);
Pokitto 31:f4b9b85c7b62 1137 drawLine(x2, y2, x0, y0);
Pokitto 31:f4b9b85c7b62 1138 }
Pokitto 31:f4b9b85c7b62 1139
Pokitto 31:f4b9b85c7b62 1140 void Display::fillTriangle(int16_t x0, int16_t y0,
Pokitto 31:f4b9b85c7b62 1141 int16_t x1, int16_t y1,
Pokitto 31:f4b9b85c7b62 1142 int16_t x2, int16_t y2) {
Pokitto 31:f4b9b85c7b62 1143 int16_t a, b, y, last;
Pokitto 31:f4b9b85c7b62 1144
Pokitto 31:f4b9b85c7b62 1145 // Sort coordinates by Y order (y2 >= y1 >= y0)
Pokitto 31:f4b9b85c7b62 1146 if (y0 > y1) {
Pokitto 31:f4b9b85c7b62 1147 swapWT(int16_t,y0, y1);
Pokitto 31:f4b9b85c7b62 1148 swapWT(int16_t,x0, x1);
Pokitto 31:f4b9b85c7b62 1149 }
Pokitto 31:f4b9b85c7b62 1150 if (y1 > y2) {
Pokitto 31:f4b9b85c7b62 1151 swapWT(int16_t,y2, y1);
Pokitto 31:f4b9b85c7b62 1152 swapWT(int16_t,x2, x1);
Pokitto 31:f4b9b85c7b62 1153 }
Pokitto 31:f4b9b85c7b62 1154 if (y0 > y1) {
Pokitto 31:f4b9b85c7b62 1155 swapWT(int16_t,y0, y1);
Pokitto 31:f4b9b85c7b62 1156 swapWT(int16_t,x0, x1);
Pokitto 31:f4b9b85c7b62 1157 }
Pokitto 31:f4b9b85c7b62 1158
Pokitto 31:f4b9b85c7b62 1159 if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
Pokitto 31:f4b9b85c7b62 1160 a = b = x0;
Pokitto 31:f4b9b85c7b62 1161 if (x1 < a) a = x1;
Pokitto 31:f4b9b85c7b62 1162 else if (x1 > b) b = x1;
Pokitto 31:f4b9b85c7b62 1163 if (x2 < a) a = x2;
Pokitto 31:f4b9b85c7b62 1164 else if (x2 > b) b = x2;
Pokitto 31:f4b9b85c7b62 1165 drawFastHLine(a, y0, b - a + 1);
Pokitto 31:f4b9b85c7b62 1166 return;
Pokitto 31:f4b9b85c7b62 1167 }
Pokitto 31:f4b9b85c7b62 1168
Pokitto 31:f4b9b85c7b62 1169 int16_t
Pokitto 31:f4b9b85c7b62 1170 dx01 = x1 - x0,
Pokitto 31:f4b9b85c7b62 1171 dy01 = y1 - y0,
Pokitto 31:f4b9b85c7b62 1172 dx02 = x2 - x0,
Pokitto 31:f4b9b85c7b62 1173 dy02 = y2 - y0,
Pokitto 31:f4b9b85c7b62 1174 dx12 = x2 - x1,
Pokitto 31:f4b9b85c7b62 1175 dy12 = y2 - y1,
Pokitto 31:f4b9b85c7b62 1176 sa = 0,
Pokitto 31:f4b9b85c7b62 1177 sb = 0;
Pokitto 31:f4b9b85c7b62 1178
Pokitto 31:f4b9b85c7b62 1179 // For upper part of triangle, find scanline crossings for segments
Pokitto 31:f4b9b85c7b62 1180 // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
Pokitto 31:f4b9b85c7b62 1181 // is included here (and second loop will be skipped, avoiding a /0
Pokitto 31:f4b9b85c7b62 1182 // error there), otherwise scanline y1 is skipped here and handled
Pokitto 31:f4b9b85c7b62 1183 // in the second loop...which also avoids a /0 error here if y0=y1
Pokitto 31:f4b9b85c7b62 1184 // (flat-topped triangle).
Pokitto 31:f4b9b85c7b62 1185 if (y1 == y2) last = y1; // Include y1 scanline
Pokitto 31:f4b9b85c7b62 1186 else last = y1 - 1; // Skip it
Pokitto 31:f4b9b85c7b62 1187
Pokitto 31:f4b9b85c7b62 1188 for (y = y0; y <= last; y++) {
Pokitto 31:f4b9b85c7b62 1189 a = x0 + sa / dy01;
Pokitto 31:f4b9b85c7b62 1190 b = x0 + sb / dy02;
Pokitto 31:f4b9b85c7b62 1191 sa += dx01;
Pokitto 31:f4b9b85c7b62 1192 sb += dx02;
Pokitto 31:f4b9b85c7b62 1193 /* longhand:
Pokitto 31:f4b9b85c7b62 1194 a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
Pokitto 31:f4b9b85c7b62 1195 b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
Pokitto 31:f4b9b85c7b62 1196 */
Pokitto 31:f4b9b85c7b62 1197 if (a > b) swapWT(int16_t,a, b);
Pokitto 31:f4b9b85c7b62 1198 drawFastHLine(a, y, b - a + 1);
Pokitto 31:f4b9b85c7b62 1199 }
Pokitto 31:f4b9b85c7b62 1200
Pokitto 31:f4b9b85c7b62 1201 // For lower part of triangle, find scanline crossings for segments
Pokitto 31:f4b9b85c7b62 1202 // 0-2 and 1-2. This loop is skipped if y1=y2.
Pokitto 31:f4b9b85c7b62 1203 sa = dx12 * (y - y1);
Pokitto 31:f4b9b85c7b62 1204 sb = dx02 * (y - y0);
Pokitto 31:f4b9b85c7b62 1205 for (; y <= y2; y++) {
Pokitto 31:f4b9b85c7b62 1206 a = x1 + sa / dy12;
Pokitto 31:f4b9b85c7b62 1207 b = x0 + sb / dy02;
Pokitto 31:f4b9b85c7b62 1208 sa += dx12;
Pokitto 31:f4b9b85c7b62 1209 sb += dx02;
Pokitto 31:f4b9b85c7b62 1210
Pokitto 31:f4b9b85c7b62 1211 if (a > b) swapWT(int16_t,a, b);
Pokitto 31:f4b9b85c7b62 1212 drawFastHLine(a, y, b - a + 1);
Pokitto 31:f4b9b85c7b62 1213 }
Pokitto 31:f4b9b85c7b62 1214 }
Pokitto 31:f4b9b85c7b62 1215
Pokitto 31:f4b9b85c7b62 1216 void Display::setFont(const unsigned char * f) {
Pokitto 31:f4b9b85c7b62 1217 font = f;
Pokitto 31:f4b9b85c7b62 1218 fontWidth = *(font)+1;
Pokitto 31:f4b9b85c7b62 1219 fontHeight = *(font + 1)+1;
Pokitto 31:f4b9b85c7b62 1220 }
Pokitto 31:f4b9b85c7b62 1221
Pokitto 31:f4b9b85c7b62 1222 void Display::drawMonoBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t index) {
Pokitto 31:f4b9b85c7b62 1223 uint8_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 1224 uint8_t h = *(bitmap + 1);
Pokitto 31:f4b9b85c7b62 1225 uint8_t xtra=0;
Pokitto 31:f4b9b85c7b62 1226 if (w&0x7) xtra=1;
Pokitto 31:f4b9b85c7b62 1227 bitmap = bitmap + 3 + index * h * ((w>>3)+xtra); //add an offset to the pointer (fonts !)
Pokitto 31:f4b9b85c7b62 1228 #if POK_GAMEBUINO_SUPPORT > 0
Pokitto 31:f4b9b85c7b62 1229 int8_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 1230 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1231 byteNum = i / 8;
Pokitto 31:f4b9b85c7b62 1232 bitNum = i % 8;
Pokitto 31:f4b9b85c7b62 1233 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1234 uint8_t source = *(bitmap + j * byteWidth + byteNum);
Pokitto 31:f4b9b85c7b62 1235 if (source & (0x80 >> bitNum)) {
Pokitto 31:f4b9b85c7b62 1236 drawPixel(x + i, y + j);
Pokitto 31:f4b9b85c7b62 1237 }
Pokitto 31:f4b9b85c7b62 1238 }
Pokitto 31:f4b9b85c7b62 1239 }
Pokitto 31:f4b9b85c7b62 1240 #else
Pokitto 31:f4b9b85c7b62 1241 /** not gamebuino */
Pokitto 31:f4b9b85c7b62 1242 int8_t scrx,scry;
Pokitto 31:f4b9b85c7b62 1243 uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
Pokitto 31:f4b9b85c7b62 1244 int8_t bitptr;
Pokitto 31:f4b9b85c7b62 1245 for (scry = y; scry < y+h; scry+=1) {
Pokitto 31:f4b9b85c7b62 1246 if ((x&1)==0) { /** EVEN pixel starting line**/
Pokitto 31:f4b9b85c7b62 1247 for (scrx = x, bitptr=7; scrx < w+x; scrx+=2) {
Pokitto 31:f4b9b85c7b62 1248 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1249 if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF) | color<<4; // upper nibble
Pokitto 31:f4b9b85c7b62 1250 else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF) | bgcolor<<4; // upper nibble
Pokitto 31:f4b9b85c7b62 1251 bitptr--;
Pokitto 31:f4b9b85c7b62 1252 if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF0) | color; // lower nibble
Pokitto 31:f4b9b85c7b62 1253 else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF0) | bgcolor; // lower nibble
Pokitto 31:f4b9b85c7b62 1254 bitptr--;
Pokitto 31:f4b9b85c7b62 1255 if (bitptr<0) { bitptr = 7; bitmap++; }
Pokitto 31:f4b9b85c7b62 1256 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1257 scrptr++;
Pokitto 31:f4b9b85c7b62 1258 }
Pokitto 31:f4b9b85c7b62 1259 } else { /** ODD pixel starting line **/
Pokitto 31:f4b9b85c7b62 1260 for (scrx = x, bitptr=7; scrx < w+x; scrx+=2) {
Pokitto 31:f4b9b85c7b62 1261 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1262 // store higher nibble of source pixel in lower nibble of target
Pokitto 31:f4b9b85c7b62 1263 if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF0) | color; // lower nibble
Pokitto 31:f4b9b85c7b62 1264 else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF0) | bgcolor; // lower nibble
Pokitto 31:f4b9b85c7b62 1265 *scrptr = targetpixel; // store
Pokitto 31:f4b9b85c7b62 1266 bitptr--;scrptr++;targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1267 // store lower nibble of source pixel in higher nibble of target
Pokitto 31:f4b9b85c7b62 1268 if (*bitmap & (1<<bitptr)) targetpixel = (targetpixel & 0xF) | color<<4; // higher nibble
Pokitto 31:f4b9b85c7b62 1269 else if (bgcolor != invisiblecolor) targetpixel = (targetpixel & 0xF) | bgcolor<<4; // higher nibble
Pokitto 31:f4b9b85c7b62 1270 *scrptr = targetpixel; // store
Pokitto 31:f4b9b85c7b62 1271 bitptr--; // do not increment scrptr here !
Pokitto 31:f4b9b85c7b62 1272 }
Pokitto 31:f4b9b85c7b62 1273 }
Pokitto 31:f4b9b85c7b62 1274 if (bitptr!=7) bitmap++; // force skip to next line
Pokitto 31:f4b9b85c7b62 1275 // increment the y jump in the scrptr
Pokitto 31:f4b9b85c7b62 1276 scrptr = scrptr + ((width - w)>>1);
Pokitto 31:f4b9b85c7b62 1277 }
Pokitto 31:f4b9b85c7b62 1278 #endif // POK_GAMEBUINO_SUPPORT
Pokitto 31:f4b9b85c7b62 1279 }
Pokitto 31:f4b9b85c7b62 1280
Pokitto 31:f4b9b85c7b62 1281
Pokitto 31:f4b9b85c7b62 1282 void Display::drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t frame)
Pokitto 31:f4b9b85c7b62 1283 {
Pokitto 31:f4b9b85c7b62 1284 int16_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 1285 int16_t h = *(bitmap + 1);
Pokitto 31:f4b9b85c7b62 1286 uint8_t framew = *(bitmap+2);
Pokitto 31:f4b9b85c7b62 1287 bitmap = bitmap + 3; //add an offset to the pointer to start after the width and height
Pokitto 31:f4b9b85c7b62 1288 /** visibility check */
Pokitto 31:f4b9b85c7b62 1289 if (y<-h || y>height) return; //invisible
Pokitto 31:f4b9b85c7b62 1290 if (x<-framew || x>width) return; //invisible
Pokitto 31:f4b9b85c7b62 1291 /** 1 bpp mode */
Pokitto 31:f4b9b85c7b62 1292 if (m_colordepth<2) {
Pokitto 31:f4b9b85c7b62 1293 int16_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 1294 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1295 byteNum = i / 8;
Pokitto 31:f4b9b85c7b62 1296 bitNum = i % 8;
Pokitto 31:f4b9b85c7b62 1297 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1298 uint8_t source = *(bitmap + j * byteWidth + byteNum);
Pokitto 31:f4b9b85c7b62 1299 if (source & (0x80 >> bitNum)) {
Pokitto 31:f4b9b85c7b62 1300 drawPixel(x + i, y + j);
Pokitto 31:f4b9b85c7b62 1301 }
Pokitto 31:f4b9b85c7b62 1302 }
Pokitto 31:f4b9b85c7b62 1303 }
Pokitto 31:f4b9b85c7b62 1304
Pokitto 31:f4b9b85c7b62 1305 return;
Pokitto 31:f4b9b85c7b62 1306 }
Pokitto 31:f4b9b85c7b62 1307 /** 2 bpp mode */
Pokitto 31:f4b9b85c7b62 1308 if (m_colordepth<4) {
Pokitto 31:f4b9b85c7b62 1309 int16_t i, j, byteNum, bitNum, byteWidth = w >> 2;
Pokitto 31:f4b9b85c7b62 1310 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1311 byteNum = i / 4;
Pokitto 31:f4b9b85c7b62 1312 bitNum = (i % 4)<<1;
Pokitto 31:f4b9b85c7b62 1313 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1314 uint8_t source = *(bitmap + j * byteWidth + byteNum);
Pokitto 31:f4b9b85c7b62 1315 uint8_t output = (source & (0xC0 >> bitNum));
Pokitto 31:f4b9b85c7b62 1316 output >>= (6-bitNum);
Pokitto 31:f4b9b85c7b62 1317 if (output != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 1318 setColor(output);
Pokitto 31:f4b9b85c7b62 1319 drawPixel(x + i, y + j);
Pokitto 31:f4b9b85c7b62 1320 }
Pokitto 31:f4b9b85c7b62 1321 }
Pokitto 31:f4b9b85c7b62 1322 }
Pokitto 31:f4b9b85c7b62 1323
Pokitto 31:f4b9b85c7b62 1324 return;
Pokitto 31:f4b9b85c7b62 1325 }
Pokitto 31:f4b9b85c7b62 1326 /** 4bpp fast version */
Pokitto 31:f4b9b85c7b62 1327 int16_t scrx,scry,xclip,xjump,scrxjump;
Pokitto 31:f4b9b85c7b62 1328 xclip=xjump=scrxjump=0;
Pokitto 31:f4b9b85c7b62 1329 bitmap += (framew*frame)>>1;
Pokitto 31:f4b9b85c7b62 1330 /** y clipping */
Pokitto 31:f4b9b85c7b62 1331 if (y<0) { h+=y; bitmap -= y*(w>>1); y=0;}
Pokitto 31:f4b9b85c7b62 1332 else if (y+h>height) { h -=(y-height);}
Pokitto 31:f4b9b85c7b62 1333 /** x clipping */
Pokitto 31:f4b9b85c7b62 1334 xjump = (w-framew)>>1;
Pokitto 31:f4b9b85c7b62 1335 if (x<0) { xclip=(x&1)<<1; framew+=x; xjump = ((-x)>>1); bitmap += xjump; x=0;}
Pokitto 31:f4b9b85c7b62 1336 else if (x+framew>width) {
Pokitto 31:f4b9b85c7b62 1337 xclip = (x&1)<<1;
Pokitto 31:f4b9b85c7b62 1338 scrxjump = x&1;
Pokitto 31:f4b9b85c7b62 1339 xjump=((x+framew-width)>>1)+scrxjump;
Pokitto 31:f4b9b85c7b62 1340 framew = width-x;}
Pokitto 31:f4b9b85c7b62 1341
Pokitto 31:f4b9b85c7b62 1342 uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
Pokitto 31:f4b9b85c7b62 1343 /** ONLY 4-bit mode for time being **/
Pokitto 31:f4b9b85c7b62 1344 for (scry = y; scry < y+h; scry+=1) {
Pokitto 31:f4b9b85c7b62 1345 if (scry>=height) return;
Pokitto 31:f4b9b85c7b62 1346 if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
Pokitto 31:f4b9b85c7b62 1347 for (scrx = x; scrx < framew+x-xclip; scrx+=2) {
Pokitto 31:f4b9b85c7b62 1348 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1349 if (xclip) {
Pokitto 31:f4b9b85c7b62 1350 sourcepixel <<=4;
Pokitto 31:f4b9b85c7b62 1351 sourcepixel |= ((*(bitmap+1))>>4);
Pokitto 31:f4b9b85c7b62 1352 }
Pokitto 31:f4b9b85c7b62 1353 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1354 if ((sourcepixel>>4) != invisiblecolor ) targetpixel = (targetpixel&0x0F) | (sourcepixel & 0xF0);
Pokitto 31:f4b9b85c7b62 1355 if ((sourcepixel&0x0F) != invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel & 0x0F);
Pokitto 31:f4b9b85c7b62 1356 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1357 bitmap++;
Pokitto 31:f4b9b85c7b62 1358 scrptr++;
Pokitto 31:f4b9b85c7b62 1359 }
Pokitto 31:f4b9b85c7b62 1360 if (xclip){
Pokitto 31:f4b9b85c7b62 1361 if (framew&1) {
Pokitto 31:f4b9b85c7b62 1362 /**last pixel is odd pixel due to clipping & odd width*/
Pokitto 31:f4b9b85c7b62 1363 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1364 if ((sourcepixel&0x0F) != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 1365 sourcepixel <<=4;
Pokitto 31:f4b9b85c7b62 1366 uint8_t targetpixel = *scrptr;// & 0x0F;
Pokitto 31:f4b9b85c7b62 1367 targetpixel |= sourcepixel;
Pokitto 31:f4b9b85c7b62 1368 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1369 }
Pokitto 31:f4b9b85c7b62 1370 //scrptr++;
Pokitto 31:f4b9b85c7b62 1371 }
Pokitto 31:f4b9b85c7b62 1372 bitmap++;
Pokitto 31:f4b9b85c7b62 1373 scrptr++;
Pokitto 31:f4b9b85c7b62 1374 }
Pokitto 31:f4b9b85c7b62 1375 bitmap += xjump; // needed if x<0 clipping occurs
Pokitto 31:f4b9b85c7b62 1376 } else { /** ODD pixel starting line **/
Pokitto 31:f4b9b85c7b62 1377 for (scrx = x; scrx < framew+x-xclip; scrx+=2) {
Pokitto 31:f4b9b85c7b62 1378 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1379 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1380 // store higher nibble of source pixel in lower nibble of target
Pokitto 31:f4b9b85c7b62 1381 if((sourcepixel>>4)!=invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel >> 4 );
Pokitto 31:f4b9b85c7b62 1382 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1383 scrptr++;
Pokitto 31:f4b9b85c7b62 1384 targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1385 // store lower nibble of source pixel in higher nibble of target
Pokitto 31:f4b9b85c7b62 1386 if((sourcepixel&0x0F)!=invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel << 4);
Pokitto 31:f4b9b85c7b62 1387 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1388 bitmap++;
Pokitto 31:f4b9b85c7b62 1389 }
Pokitto 31:f4b9b85c7b62 1390 bitmap+=xjump;
Pokitto 31:f4b9b85c7b62 1391 }
Pokitto 31:f4b9b85c7b62 1392 // increment the y jump in the scrptr
Pokitto 31:f4b9b85c7b62 1393 scrptr = scrptr + ((width - framew)>>1)+scrxjump;
Pokitto 31:f4b9b85c7b62 1394 }
Pokitto 31:f4b9b85c7b62 1395 }
Pokitto 31:f4b9b85c7b62 1396
Pokitto 31:f4b9b85c7b62 1397
Pokitto 31:f4b9b85c7b62 1398 void Display::drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap)
Pokitto 31:f4b9b85c7b62 1399 {
Pokitto 31:f4b9b85c7b62 1400 int16_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 1401 int16_t h = *(bitmap + 1);
Pokitto 31:f4b9b85c7b62 1402 bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
Pokitto 31:f4b9b85c7b62 1403 drawBitmapData(x, y, w, h, bitmap);
Pokitto 31:f4b9b85c7b62 1404 }
Pokitto 31:f4b9b85c7b62 1405
Pokitto 31:f4b9b85c7b62 1406 void Display::drawBitmapData(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t* bitmap) {
Pokitto 31:f4b9b85c7b62 1407 /** visibility check */
Pokitto 31:f4b9b85c7b62 1408 if (y<-h || y>height) return; //invisible
Pokitto 31:f4b9b85c7b62 1409 if (x<-w || x>width) return; //invisible
Pokitto 31:f4b9b85c7b62 1410 /** 1 bpp mode */
Pokitto 31:f4b9b85c7b62 1411 if (m_colordepth<2) {
Pokitto 31:f4b9b85c7b62 1412 int16_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 1413 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1414 byteNum = i / 8;
Pokitto 31:f4b9b85c7b62 1415 bitNum = i % 8;
Pokitto 31:f4b9b85c7b62 1416 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1417 uint8_t source = *(bitmap + j * byteWidth + byteNum);
Pokitto 31:f4b9b85c7b62 1418 if (source & (0x80 >> bitNum)) {
Pokitto 31:f4b9b85c7b62 1419 drawPixel(x + i, y + j);
Pokitto 31:f4b9b85c7b62 1420 }
Pokitto 31:f4b9b85c7b62 1421 }
Pokitto 31:f4b9b85c7b62 1422 }
Pokitto 31:f4b9b85c7b62 1423
Pokitto 31:f4b9b85c7b62 1424 return;
Pokitto 31:f4b9b85c7b62 1425 }
Pokitto 31:f4b9b85c7b62 1426 /** 2 bpp mode */
Pokitto 35:4f7edccf8ed6 1427 else if (m_colordepth==2) {
Pokitto 31:f4b9b85c7b62 1428 if(clipH > 0) {
Pokitto 31:f4b9b85c7b62 1429
Pokitto 31:f4b9b85c7b62 1430 // Clip
Pokitto 31:f4b9b85c7b62 1431 int16_t x1 = max(x, clipX);
Pokitto 31:f4b9b85c7b62 1432 int16_t x2 = min(x + w, clipX + clipW);
Pokitto 31:f4b9b85c7b62 1433 int16_t bmupdateX = x1 - x;
Pokitto 31:f4b9b85c7b62 1434 int16_t bmupdateX2 = x2 - x;
Pokitto 31:f4b9b85c7b62 1435 int16_t y1 = max(y, clipY);
Pokitto 31:f4b9b85c7b62 1436 int16_t y2 = min(y + h, clipY + clipH);
Pokitto 31:f4b9b85c7b62 1437 int16_t bmupdateY = y1 - y;
Pokitto 31:f4b9b85c7b62 1438 int16_t bmupdateY2 = y2 - y;
Pokitto 31:f4b9b85c7b62 1439
Pokitto 31:f4b9b85c7b62 1440 int16_t i, j, byteNum, bitNum, byteWidth = w >> 2;
Pokitto 31:f4b9b85c7b62 1441 for (i = bmupdateX; i < bmupdateX2; i++) {
Pokitto 31:f4b9b85c7b62 1442 byteNum = i / 4;
Pokitto 31:f4b9b85c7b62 1443 bitNum = (i % 4)<<1;
Pokitto 31:f4b9b85c7b62 1444 for (j = bmupdateY; j < bmupdateY2; j++) {
Pokitto 31:f4b9b85c7b62 1445 uint8_t source = *(bitmap + (j * byteWidth) + byteNum);
Pokitto 31:f4b9b85c7b62 1446 uint8_t output = (source & (0xC0 >> bitNum));
Pokitto 31:f4b9b85c7b62 1447 output >>= (6-bitNum);
Pokitto 31:f4b9b85c7b62 1448 if (output != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 1449 setColor(output);
Pokitto 31:f4b9b85c7b62 1450 drawPixel(x + i, y + j);
Pokitto 31:f4b9b85c7b62 1451 }
Pokitto 31:f4b9b85c7b62 1452 }
Pokitto 31:f4b9b85c7b62 1453 }
Pokitto 31:f4b9b85c7b62 1454 }
Pokitto 31:f4b9b85c7b62 1455 else {
Pokitto 31:f4b9b85c7b62 1456 int16_t i, j, byteNum, bitNum, byteWidth = w >> 2;
Pokitto 31:f4b9b85c7b62 1457 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1458 byteNum = i / 4;
Pokitto 31:f4b9b85c7b62 1459 bitNum = (i % 4)<<1;
Pokitto 31:f4b9b85c7b62 1460 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1461 uint8_t source = *(bitmap + (j * byteWidth) + byteNum);
Pokitto 31:f4b9b85c7b62 1462 uint8_t output = (source & (0xC0 >> bitNum));
Pokitto 31:f4b9b85c7b62 1463 output >>= (6-bitNum);
Pokitto 31:f4b9b85c7b62 1464 if (output != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 1465 setColor(output);
Pokitto 31:f4b9b85c7b62 1466 drawPixel(x + i, y + j);
Pokitto 31:f4b9b85c7b62 1467 }
Pokitto 31:f4b9b85c7b62 1468 }
Pokitto 31:f4b9b85c7b62 1469 }
Pokitto 31:f4b9b85c7b62 1470 }
Pokitto 31:f4b9b85c7b62 1471 return;
Pokitto 31:f4b9b85c7b62 1472 }
Pokitto 35:4f7edccf8ed6 1473
Pokitto 35:4f7edccf8ed6 1474 /** 3 bpp mode */
Pokitto 35:4f7edccf8ed6 1475 else if (m_colordepth==3) {
Pokitto 35:4f7edccf8ed6 1476 int16_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 35:4f7edccf8ed6 1477 int16_t bitFrame = w * h / 8;
Pokitto 35:4f7edccf8ed6 1478 for (i = 0; i < w; i++) {
Pokitto 35:4f7edccf8ed6 1479 byteNum = i / 8;
Pokitto 35:4f7edccf8ed6 1480 bitNum = i % 8;
Pokitto 35:4f7edccf8ed6 1481
Pokitto 35:4f7edccf8ed6 1482 uint8_t bitcount=0;
Pokitto 35:4f7edccf8ed6 1483 for (j = 0; j <= h/8; j++) {
Pokitto 35:4f7edccf8ed6 1484 uint8_t r_val = *(bitmap + j * byteWidth + byteNum);
Pokitto 35:4f7edccf8ed6 1485 uint8_t g_val = *(bitmap + bitFrame + j * byteWidth + byteNum);
Pokitto 35:4f7edccf8ed6 1486 uint8_t b_val = *(bitmap + (bitFrame<<1) + j * byteWidth + byteNum);
Pokitto 35:4f7edccf8ed6 1487 for (bitcount=0; bitcount<8; bitcount++) {
Pokitto 35:4f7edccf8ed6 1488 uint8_t col = (r_val&0x1) | ((g_val&0x1)<<1) | ((b_val&0x1)<<2);
Pokitto 35:4f7edccf8ed6 1489 r_val >>= 1; g_val >>= 1; b_val >>= 1;
Pokitto 35:4f7edccf8ed6 1490 drawPixel(x + i, y + j+bitcount,col);
Pokitto 35:4f7edccf8ed6 1491 }
Pokitto 35:4f7edccf8ed6 1492 }
Pokitto 35:4f7edccf8ed6 1493 }
Pokitto 35:4f7edccf8ed6 1494
Pokitto 35:4f7edccf8ed6 1495 return;
Pokitto 35:4f7edccf8ed6 1496 }
Pokitto 35:4f7edccf8ed6 1497
Pokitto 35:4f7edccf8ed6 1498
Pokitto 35:4f7edccf8ed6 1499 /** 4bpp fast version */
Pokitto 35:4f7edccf8ed6 1500 else if (m_colordepth==4) {
Pokitto 35:4f7edccf8ed6 1501
Pokitto 31:f4b9b85c7b62 1502 /** 4bpp fast version */
Pokitto 31:f4b9b85c7b62 1503 int16_t scrx,scry,xclip,xjump,scrxjump;
Pokitto 31:f4b9b85c7b62 1504 xclip=xjump=scrxjump=0;
Pokitto 31:f4b9b85c7b62 1505 /** y clipping */
Pokitto 31:f4b9b85c7b62 1506 if (y<0) { h+=y; bitmap -= y*(w>>1); y=0;}
Pokitto 31:f4b9b85c7b62 1507 else if (y+h>height) { h -=(y-height);}
Pokitto 31:f4b9b85c7b62 1508 /** x clipping */
Pokitto 31:f4b9b85c7b62 1509 if (x<0) { xclip=(x&1)<<1; w+=x; xjump = ((-x)>>1); bitmap += xjump; x=0;}
Pokitto 31:f4b9b85c7b62 1510 else if (x+w>width) {
Pokitto 31:f4b9b85c7b62 1511 xclip = (x&1)<<1;
Pokitto 31:f4b9b85c7b62 1512 scrxjump = x&1;
Pokitto 31:f4b9b85c7b62 1513 xjump=((x+w-width)>>1)+scrxjump;
Pokitto 31:f4b9b85c7b62 1514 w = width-x;}
Pokitto 31:f4b9b85c7b62 1515
Pokitto 31:f4b9b85c7b62 1516 uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
Pokitto 31:f4b9b85c7b62 1517 /** ONLY 4-bit mode for time being **/
Pokitto 31:f4b9b85c7b62 1518 for (scry = y; scry < y+h; scry+=1) {
Pokitto 31:f4b9b85c7b62 1519 if (scry>=height) return;
Pokitto 31:f4b9b85c7b62 1520 if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
Pokitto 31:f4b9b85c7b62 1521 for (scrx = x; scrx < w+x-xclip; scrx+=2) {
Pokitto 31:f4b9b85c7b62 1522 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1523 if (xclip) {
Pokitto 31:f4b9b85c7b62 1524 sourcepixel <<=4;
Pokitto 31:f4b9b85c7b62 1525 sourcepixel |= ((*(bitmap+1))>>4);
Pokitto 31:f4b9b85c7b62 1526 }
Pokitto 31:f4b9b85c7b62 1527 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1528 if ((sourcepixel>>4) != invisiblecolor ) targetpixel = (targetpixel&0x0F) | (sourcepixel & 0xF0);
Pokitto 31:f4b9b85c7b62 1529 if ((sourcepixel&0x0F) != invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel & 0x0F);
Pokitto 31:f4b9b85c7b62 1530 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1531 bitmap++;
Pokitto 31:f4b9b85c7b62 1532 scrptr++;
Pokitto 31:f4b9b85c7b62 1533 }
Pokitto 31:f4b9b85c7b62 1534 if (xclip){
Pokitto 31:f4b9b85c7b62 1535 if (w&1) {
Pokitto 31:f4b9b85c7b62 1536 /**last pixel is odd pixel due to clipping & odd width*/
Pokitto 31:f4b9b85c7b62 1537 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1538 if ((sourcepixel&0x0F) != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 1539 sourcepixel <<=4;
Pokitto 35:4f7edccf8ed6 1540 uint8_t targetpixel = *scrptr;// & 0x0F;
Pokitto 31:f4b9b85c7b62 1541 targetpixel |= sourcepixel;
Pokitto 31:f4b9b85c7b62 1542 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1543 }
Pokitto 31:f4b9b85c7b62 1544 //scrptr++;
Pokitto 31:f4b9b85c7b62 1545 }
Pokitto 31:f4b9b85c7b62 1546 bitmap++;
Pokitto 31:f4b9b85c7b62 1547 scrptr++;
Pokitto 31:f4b9b85c7b62 1548 }
Pokitto 31:f4b9b85c7b62 1549 bitmap += xjump; // needed if x<0 clipping occurs
Pokitto 31:f4b9b85c7b62 1550 } else { /** ODD pixel starting line **/
Pokitto 31:f4b9b85c7b62 1551 for (scrx = x; scrx < w+x-xclip; scrx+=2) {
Pokitto 31:f4b9b85c7b62 1552 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1553 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1554 // store higher nibble of source pixel in lower nibble of target
Pokitto 31:f4b9b85c7b62 1555 if((sourcepixel>>4)!=invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel >> 4 );
Pokitto 31:f4b9b85c7b62 1556 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1557 scrptr++;
Pokitto 31:f4b9b85c7b62 1558 targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1559 // store lower nibble of source pixel in higher nibble of target
Pokitto 31:f4b9b85c7b62 1560 if((sourcepixel&0x0F)!=invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel << 4);
Pokitto 31:f4b9b85c7b62 1561 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1562 bitmap++;
Pokitto 31:f4b9b85c7b62 1563 }
Pokitto 31:f4b9b85c7b62 1564 bitmap+=xjump;
Pokitto 31:f4b9b85c7b62 1565 }
Pokitto 31:f4b9b85c7b62 1566 // increment the y jump in the scrptr
Pokitto 31:f4b9b85c7b62 1567 scrptr = scrptr + ((width - w)>>1)+scrxjump;
Pokitto 31:f4b9b85c7b62 1568 }
Pokitto 35:4f7edccf8ed6 1569
Pokitto 35:4f7edccf8ed6 1570 return;
Pokitto 35:4f7edccf8ed6 1571 }
Pokitto 35:4f7edccf8ed6 1572
Pokitto 35:4f7edccf8ed6 1573 /** 4bpp fast version */
Pokitto 35:4f7edccf8ed6 1574
Pokitto 35:4f7edccf8ed6 1575 if (m_colordepth==8) {
Pokitto 35:4f7edccf8ed6 1576 int16_t scrx,scry,xclip,xjump,scrxjump;
Pokitto 35:4f7edccf8ed6 1577 xclip=xjump=scrxjump=0;
Pokitto 35:4f7edccf8ed6 1578 /** y clipping */
Pokitto 35:4f7edccf8ed6 1579 if (y<0) { h+=y; bitmap -= y*w; y=0;}
Pokitto 35:4f7edccf8ed6 1580 else if (y+h>height) { h -=(y-height);}
Pokitto 35:4f7edccf8ed6 1581 /** x clipping */
Pokitto 35:4f7edccf8ed6 1582 if (x<0) { xclip=x; w+=x; xjump = (-x); bitmap += xjump; x=0;}
Pokitto 35:4f7edccf8ed6 1583 else if (x+w>width) {
Pokitto 35:4f7edccf8ed6 1584 xclip = x;
Pokitto 35:4f7edccf8ed6 1585 scrxjump = x;
Pokitto 35:4f7edccf8ed6 1586 xjump=(x+w-width)+scrxjump;
Pokitto 35:4f7edccf8ed6 1587 w = width-x;}
Pokitto 35:4f7edccf8ed6 1588
Pokitto 35:4f7edccf8ed6 1589 uint8_t* scrptr = m_scrbuf + (y*width + x);
Pokitto 35:4f7edccf8ed6 1590 for (scry = y; scry < y+h; scry+=1) {
Pokitto 35:4f7edccf8ed6 1591 if (scry>=height) return;
Pokitto 35:4f7edccf8ed6 1592 for (scrx = x; scrx < w+x; scrx++) {
Pokitto 35:4f7edccf8ed6 1593 uint8_t sourcepixel = *bitmap;
Pokitto 35:4f7edccf8ed6 1594 uint8_t targetpixel = *scrptr;
Pokitto 35:4f7edccf8ed6 1595 if (sourcepixel != invisiblecolor ) targetpixel = sourcepixel;
Pokitto 35:4f7edccf8ed6 1596 *scrptr = targetpixel;
Pokitto 35:4f7edccf8ed6 1597 bitmap++;
Pokitto 35:4f7edccf8ed6 1598 scrptr++;
Pokitto 35:4f7edccf8ed6 1599 }
Pokitto 35:4f7edccf8ed6 1600 bitmap += xjump; // needed if x<0 clipping occurs
Pokitto 35:4f7edccf8ed6 1601 scrptr = scrptr + (width - w)+scrxjump;
Pokitto 35:4f7edccf8ed6 1602 }
Pokitto 35:4f7edccf8ed6 1603 return;
Pokitto 35:4f7edccf8ed6 1604 }
Pokitto 35:4f7edccf8ed6 1605
Pokitto 35:4f7edccf8ed6 1606
Pokitto 31:f4b9b85c7b62 1607 }
Pokitto 31:f4b9b85c7b62 1608
Pokitto 31:f4b9b85c7b62 1609 void Display::drawRleBitmap(int16_t x, int16_t y, const uint8_t* rlebitmap)
Pokitto 31:f4b9b85c7b62 1610 {
Pokitto 31:f4b9b85c7b62 1611 // ONLY can copy 4-bit bitmap to 4-bit screen mode for time being
Pokitto 31:f4b9b85c7b62 1612 #if (POK_SCREENMODE != MODE_FAST_16COLOR)
Pokitto 31:f4b9b85c7b62 1613 return;
Pokitto 31:f4b9b85c7b62 1614 #endif
Pokitto 31:f4b9b85c7b62 1615
Pokitto 31:f4b9b85c7b62 1616 int16_t w = *rlebitmap;
Pokitto 31:f4b9b85c7b62 1617 int16_t h = *(rlebitmap + 1);
Pokitto 31:f4b9b85c7b62 1618 rlebitmap = rlebitmap + 2; //add an offset to the pointer to start after the width and height
Pokitto 31:f4b9b85c7b62 1619
Pokitto 31:f4b9b85c7b62 1620 // visibility check
Pokitto 31:f4b9b85c7b62 1621 if (y<-h || y>height) return; //invisible
Pokitto 31:f4b9b85c7b62 1622 if (x<-w || x>width) return; //invisible
Pokitto 31:f4b9b85c7b62 1623
Pokitto 31:f4b9b85c7b62 1624 // Clipping is not supported
Pokitto 31:f4b9b85c7b62 1625 if ((x < 0) || (x+w > width) || (y < 0) || (y+h > height)) return;
Pokitto 31:f4b9b85c7b62 1626
Pokitto 31:f4b9b85c7b62 1627 // Currently only support RLE bitmaps in 16 color mode.
Pokitto 31:f4b9b85c7b62 1628 if (m_colordepth != 4) //
Pokitto 31:f4b9b85c7b62 1629 return;
Pokitto 31:f4b9b85c7b62 1630
Pokitto 31:f4b9b85c7b62 1631 // Go through each line.
Pokitto 31:f4b9b85c7b62 1632 uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
Pokitto 31:f4b9b85c7b62 1633 bool is_endofbitmap = false;
Pokitto 31:f4b9b85c7b62 1634 for (int16_t scry = y; scry < y+h && !is_endofbitmap;) {
Pokitto 31:f4b9b85c7b62 1635
Pokitto 31:f4b9b85c7b62 1636 // Process one line. Go through each pixel run and escape command in RLE data.
Pokitto 31:f4b9b85c7b62 1637 for (int16_t scrx = x;;) {
Pokitto 31:f4b9b85c7b62 1638 uint8_t rle_count = *rlebitmap++;
Pokitto 31:f4b9b85c7b62 1639
Pokitto 31:f4b9b85c7b62 1640 if (rle_count == 0) {
Pokitto 31:f4b9b85c7b62 1641
Pokitto 31:f4b9b85c7b62 1642 /* Escape or absolute mode */
Pokitto 31:f4b9b85c7b62 1643
Pokitto 31:f4b9b85c7b62 1644 uint8_t rle_escape_or_runsize = *rlebitmap++;
Pokitto 31:f4b9b85c7b62 1645 if ( rle_escape_or_runsize == RLE_ESC_EOL) {
Pokitto 31:f4b9b85c7b62 1646 // End of line.
Pokitto 31:f4b9b85c7b62 1647 break;
Pokitto 31:f4b9b85c7b62 1648 }
Pokitto 31:f4b9b85c7b62 1649 else if ( rle_escape_or_runsize == RLE_ESC_EOB) {
Pokitto 31:f4b9b85c7b62 1650 // End of bitmap.
Pokitto 31:f4b9b85c7b62 1651 is_endofbitmap = true;
Pokitto 31:f4b9b85c7b62 1652 break;
Pokitto 31:f4b9b85c7b62 1653 }
Pokitto 31:f4b9b85c7b62 1654 else if ( rle_escape_or_runsize == RLE_ESC_OFFSET) {
Pokitto 31:f4b9b85c7b62 1655 // Move position in target.
Pokitto 31:f4b9b85c7b62 1656 // TODO: not tested yet.
Pokitto 31:f4b9b85c7b62 1657 uint8_t xoffset = *rlebitmap++;
Pokitto 31:f4b9b85c7b62 1658 uint8_t yoffset = *rlebitmap++;
Pokitto 31:f4b9b85c7b62 1659 scrptr += (xoffset>1);
Pokitto 31:f4b9b85c7b62 1660 scrx += xoffset;
Pokitto 31:f4b9b85c7b62 1661 scrptr += yoffset*width;
Pokitto 31:f4b9b85c7b62 1662 scry += yoffset;
Pokitto 31:f4b9b85c7b62 1663 }
Pokitto 31:f4b9b85c7b62 1664 else {
Pokitto 31:f4b9b85c7b62 1665
Pokitto 31:f4b9b85c7b62 1666 /* Absolute mode. Copy pixels from the source bitmap to the target screen. */
Pokitto 31:f4b9b85c7b62 1667
Pokitto 31:f4b9b85c7b62 1668 int16_t runsize = rle_escape_or_runsize;
Pokitto 31:f4b9b85c7b62 1669 uint8_t targetpixel = *scrptr; // initial value
Pokitto 31:f4b9b85c7b62 1670 uint8_t sourcepixel = *rlebitmap; // initial value
Pokitto 31:f4b9b85c7b62 1671 for( int16_t runx = 0; runx < runsize; ) {
Pokitto 31:f4b9b85c7b62 1672 if (scrx&0x1) { // screen pixel is in the low nibble
Pokitto 31:f4b9b85c7b62 1673 if (runx&0x1) { // bitmap pixel is in the low nibble
Pokitto 31:f4b9b85c7b62 1674 if ((sourcepixel&0x0F) != invisiblecolor)
Pokitto 31:f4b9b85c7b62 1675 targetpixel = (targetpixel&0xF0) | (sourcepixel&0x0F); // Copy low to low nibble.
Pokitto 31:f4b9b85c7b62 1676 rlebitmap++;
Pokitto 31:f4b9b85c7b62 1677 }
Pokitto 31:f4b9b85c7b62 1678 else // bitmap pixel is in the high nibble
Pokitto 31:f4b9b85c7b62 1679 if ((sourcepixel>>4) != invisiblecolor)
Pokitto 31:f4b9b85c7b62 1680 targetpixel = (targetpixel&0xF0) | (sourcepixel>>4); // Copy high to low nibble.
Pokitto 31:f4b9b85c7b62 1681
Pokitto 31:f4b9b85c7b62 1682 // Copy the byte to the target.
Pokitto 31:f4b9b85c7b62 1683 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1684 scrptr++;
Pokitto 31:f4b9b85c7b62 1685 }
Pokitto 31:f4b9b85c7b62 1686 else { // screen pixel is in the high nibble
Pokitto 31:f4b9b85c7b62 1687 targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1688 sourcepixel = *rlebitmap;
Pokitto 31:f4b9b85c7b62 1689 if (runx&0x1) { // bitmap pixel is sourcepixel = *rlebitmapin the low nibble
Pokitto 31:f4b9b85c7b62 1690 if ((sourcepixel&0x0F) != invisiblecolor )
Pokitto 31:f4b9b85c7b62 1691 targetpixel = (targetpixel&0x0F) | ((sourcepixel<<4)&0xF0); // Copy low to high nibble.
Pokitto 31:f4b9b85c7b62 1692 rlebitmap++; // read the new source byte
Pokitto 31:f4b9b85c7b62 1693 }
Pokitto 31:f4b9b85c7b62 1694 else // bitmap pixel is in the high nibble
Pokitto 31:f4b9b85c7b62 1695 if ((sourcepixel>>4) != invisiblecolor )
Pokitto 31:f4b9b85c7b62 1696 targetpixel = (targetpixel&0x0F) | (sourcepixel&0xF0); // Copy high to high nibble.
Pokitto 31:f4b9b85c7b62 1697 }
Pokitto 31:f4b9b85c7b62 1698 runx++;
Pokitto 31:f4b9b85c7b62 1699 scrx++;
Pokitto 31:f4b9b85c7b62 1700 } // end for
Pokitto 31:f4b9b85c7b62 1701
Pokitto 31:f4b9b85c7b62 1702 // If this is odd target index, copy the byte to the target.
Pokitto 31:f4b9b85c7b62 1703 if (scrx&0x1) {
Pokitto 31:f4b9b85c7b62 1704 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1705 scrptr++;
Pokitto 31:f4b9b85c7b62 1706 }
Pokitto 31:f4b9b85c7b62 1707
Pokitto 31:f4b9b85c7b62 1708 // In absolute mode the source size is always padded to the word boundary.
Pokitto 31:f4b9b85c7b62 1709 if (runsize%4) {
Pokitto 31:f4b9b85c7b62 1710 int16_t padpixcount = 4 - (runsize%4);
Pokitto 31:f4b9b85c7b62 1711 rlebitmap += padpixcount>>1; // skip n padding bytes
Pokitto 31:f4b9b85c7b62 1712 }
Pokitto 31:f4b9b85c7b62 1713 }
Pokitto 31:f4b9b85c7b62 1714 }
Pokitto 31:f4b9b85c7b62 1715 else {
Pokitto 31:f4b9b85c7b62 1716
Pokitto 31:f4b9b85c7b62 1717 /* Encoded mode. Duplicate one pixel pair to the all required pixels on the target screen */
Pokitto 31:f4b9b85c7b62 1718
Pokitto 31:f4b9b85c7b62 1719 int16_t runsize = rle_count;
Pokitto 31:f4b9b85c7b62 1720 uint8_t clonepixelpair = *rlebitmap++;
Pokitto 31:f4b9b85c7b62 1721 uint8_t targetpixel = *scrptr; // initial value
Pokitto 31:f4b9b85c7b62 1722 for( int16_t runx = 0; runx < runsize; ) {
Pokitto 31:f4b9b85c7b62 1723 if (scrx&0x1) { // screen pixel is in the low nibble
Pokitto 31:f4b9b85c7b62 1724 if (runx&0x1) { // bitmap pixel is in the low nibble
Pokitto 31:f4b9b85c7b62 1725 if ((clonepixelpair&0x0F) != invisiblecolor)
Pokitto 31:f4b9b85c7b62 1726 targetpixel = (targetpixel&0xF0) | (clonepixelpair&0x0F); // Copy low to low nibble.
Pokitto 31:f4b9b85c7b62 1727 }
Pokitto 31:f4b9b85c7b62 1728 else // bitmap pixel is in the high nibble
Pokitto 31:f4b9b85c7b62 1729 if ((clonepixelpair>>4) != invisiblecolor)
Pokitto 31:f4b9b85c7b62 1730 targetpixel = (targetpixel&0xF0) | (clonepixelpair>>4); // Copy high to low nibble.
Pokitto 31:f4b9b85c7b62 1731
Pokitto 31:f4b9b85c7b62 1732 // Copy the byte to the target.
Pokitto 31:f4b9b85c7b62 1733 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1734 scrptr++;
Pokitto 31:f4b9b85c7b62 1735 }
Pokitto 31:f4b9b85c7b62 1736 else { // screen pixel is in the high nibble
Pokitto 31:f4b9b85c7b62 1737 targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1738 if (runx&0x1) {// bitmap pixel is in the low nibble
Pokitto 31:f4b9b85c7b62 1739 if ((clonepixelpair&0x0F) != invisiblecolor )
Pokitto 31:f4b9b85c7b62 1740 targetpixel = (targetpixel&0x0F) | ((clonepixelpair<<4)&0xF0); // Copy low to high nibble.
Pokitto 31:f4b9b85c7b62 1741 }
Pokitto 31:f4b9b85c7b62 1742 else // bitmap pixel is in the high nibble
Pokitto 31:f4b9b85c7b62 1743 if ((clonepixelpair>>4) != invisiblecolor )
Pokitto 31:f4b9b85c7b62 1744 targetpixel = (targetpixel&0x0F) | (clonepixelpair&0xF0); // Copy high to high nibble.
Pokitto 31:f4b9b85c7b62 1745 }
Pokitto 31:f4b9b85c7b62 1746 runx++;
Pokitto 31:f4b9b85c7b62 1747 scrx++;
Pokitto 31:f4b9b85c7b62 1748
Pokitto 31:f4b9b85c7b62 1749 } // end for
Pokitto 31:f4b9b85c7b62 1750
Pokitto 31:f4b9b85c7b62 1751 // If this is odd target index, copy the byte to the target.
Pokitto 31:f4b9b85c7b62 1752 if (scrx&0x1) {
Pokitto 31:f4b9b85c7b62 1753 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1754 scrptr++;
Pokitto 31:f4b9b85c7b62 1755 }
Pokitto 31:f4b9b85c7b62 1756 } // end if
Pokitto 31:f4b9b85c7b62 1757 } // end while
Pokitto 31:f4b9b85c7b62 1758
Pokitto 31:f4b9b85c7b62 1759 // Increment the target screen pointer and index.
Pokitto 31:f4b9b85c7b62 1760 scrptr = scrptr + ((width - w)>>1);
Pokitto 31:f4b9b85c7b62 1761 scry++;
Pokitto 31:f4b9b85c7b62 1762 } // end for scry
Pokitto 31:f4b9b85c7b62 1763 }
Pokitto 31:f4b9b85c7b62 1764
Pokitto 31:f4b9b85c7b62 1765 void Display::drawBitmapXFlipped(int16_t x, int16_t y, const uint8_t* bitmap)
Pokitto 31:f4b9b85c7b62 1766 {
Pokitto 31:f4b9b85c7b62 1767 int16_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 1768 int16_t h = *(bitmap + 1);
Pokitto 31:f4b9b85c7b62 1769 bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
Pokitto 31:f4b9b85c7b62 1770 /** visibility check */
Pokitto 31:f4b9b85c7b62 1771 if (y<-h || y>height) return; //invisible
Pokitto 31:f4b9b85c7b62 1772 if (x<-w || x>width) return; //invisible
Pokitto 31:f4b9b85c7b62 1773 /** 1 bpp mode */
Pokitto 31:f4b9b85c7b62 1774 if (m_colordepth<2) {
Pokitto 31:f4b9b85c7b62 1775 int16_t i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 1776 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1777 byteNum = i / 8;
Pokitto 31:f4b9b85c7b62 1778 bitNum = i % 8;
Pokitto 31:f4b9b85c7b62 1779 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1780 uint8_t source = *(bitmap + j * byteWidth + byteNum);
Pokitto 31:f4b9b85c7b62 1781 if (source & (0x80 >> bitNum)) {
Pokitto 31:f4b9b85c7b62 1782 drawPixel(x + w - i, y + j);
Pokitto 31:f4b9b85c7b62 1783 }
Pokitto 31:f4b9b85c7b62 1784 }
Pokitto 31:f4b9b85c7b62 1785 }
Pokitto 31:f4b9b85c7b62 1786
Pokitto 31:f4b9b85c7b62 1787 return;
Pokitto 31:f4b9b85c7b62 1788 }
Pokitto 31:f4b9b85c7b62 1789 /** 2 bpp mode */
Pokitto 31:f4b9b85c7b62 1790 if (m_colordepth<4) {
Pokitto 31:f4b9b85c7b62 1791 int16_t i, j, byteNum, bitNum, byteWidth = w >> 2;
Pokitto 31:f4b9b85c7b62 1792 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1793 byteNum = i / 4;
Pokitto 31:f4b9b85c7b62 1794 bitNum = (i % 4)<<1;
Pokitto 31:f4b9b85c7b62 1795 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1796 uint8_t source = *(bitmap + j * byteWidth + byteNum);
Pokitto 31:f4b9b85c7b62 1797 uint8_t output = (source & (0xC0 >> bitNum));
Pokitto 31:f4b9b85c7b62 1798 output >>= (6-bitNum);
Pokitto 31:f4b9b85c7b62 1799 if (output != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 1800 setColor(output);
Pokitto 31:f4b9b85c7b62 1801 drawPixel(x + i, y + j);
Pokitto 31:f4b9b85c7b62 1802 }
Pokitto 31:f4b9b85c7b62 1803 }
Pokitto 31:f4b9b85c7b62 1804 }
Pokitto 31:f4b9b85c7b62 1805
Pokitto 31:f4b9b85c7b62 1806 return;
Pokitto 31:f4b9b85c7b62 1807 }
Pokitto 31:f4b9b85c7b62 1808 /** 4bpp fast version */
Pokitto 31:f4b9b85c7b62 1809 int16_t scrx,scry,xclip,xjump,scrxjump;
Pokitto 31:f4b9b85c7b62 1810 xclip=xjump=scrxjump=0;
Pokitto 31:f4b9b85c7b62 1811 /** y clipping */
Pokitto 31:f4b9b85c7b62 1812 if (y<0) { h+=y; bitmap -= y*(w>>1); y=0;}
Pokitto 31:f4b9b85c7b62 1813 else if (y+h>height) { h -=(y-height);}
Pokitto 31:f4b9b85c7b62 1814 /** x clipping */
Pokitto 31:f4b9b85c7b62 1815 bitmap += ((w>>1)-1); //inverted!
Pokitto 31:f4b9b85c7b62 1816 if (x<0) {
Pokitto 31:f4b9b85c7b62 1817 xclip=(x&1)<<1;
Pokitto 31:f4b9b85c7b62 1818 w+=x;
Pokitto 31:f4b9b85c7b62 1819 xjump = ((-x)>>1);
Pokitto 31:f4b9b85c7b62 1820 //bitmap += xjump; // do not clip left edge of source, as bitmap is inverted !
Pokitto 31:f4b9b85c7b62 1821 x=0;
Pokitto 31:f4b9b85c7b62 1822 }
Pokitto 31:f4b9b85c7b62 1823 else if (x+w>width) {
Pokitto 31:f4b9b85c7b62 1824 xclip = (x&1)<<1;
Pokitto 31:f4b9b85c7b62 1825 scrxjump = x&1;
Pokitto 31:f4b9b85c7b62 1826 xjump=((x+w-width)>>1)+scrxjump;
Pokitto 31:f4b9b85c7b62 1827 w = width-x;}
Pokitto 31:f4b9b85c7b62 1828
Pokitto 31:f4b9b85c7b62 1829 //uint8_t* scrptr = m_scrbuf + (y*(width>>1) + ((x+width)>>1));
Pokitto 31:f4b9b85c7b62 1830 uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
Pokitto 31:f4b9b85c7b62 1831 /** ONLY 4-bit mode for time being **/
Pokitto 31:f4b9b85c7b62 1832 for (scry = y; scry < y+h; scry+=1) {
Pokitto 31:f4b9b85c7b62 1833 // for (scry = y; scry < y+2; scry+=1) {
Pokitto 31:f4b9b85c7b62 1834 if (scry>=height) return;
Pokitto 31:f4b9b85c7b62 1835 if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
Pokitto 31:f4b9b85c7b62 1836 //for (scrx = w+x-xclip-1; scrx >= x; scrx-=2) {
Pokitto 31:f4b9b85c7b62 1837 for (scrx = x; scrx < w+x-xclip; scrx+=2) {
Pokitto 31:f4b9b85c7b62 1838 uint8_t sourcepixel = *(bitmap);
Pokitto 31:f4b9b85c7b62 1839 if (xclip) {
Pokitto 31:f4b9b85c7b62 1840 sourcepixel <<=4;
Pokitto 31:f4b9b85c7b62 1841 sourcepixel |= ((*(bitmap-1))>>4);//inverted!
Pokitto 31:f4b9b85c7b62 1842 }
Pokitto 31:f4b9b85c7b62 1843 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1844 // NIBBLES ARE INVERTED BECAUSE PICTURE IS FLIPPED !!!
Pokitto 31:f4b9b85c7b62 1845 if ((sourcepixel>>4) != invisiblecolor ) targetpixel = (targetpixel&0xF0) | (sourcepixel>>4);
Pokitto 31:f4b9b85c7b62 1846 if ((sourcepixel&0x0F) != invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel<<4);
Pokitto 31:f4b9b85c7b62 1847 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1848 bitmap--;
Pokitto 31:f4b9b85c7b62 1849 scrptr++;
Pokitto 31:f4b9b85c7b62 1850 }
Pokitto 31:f4b9b85c7b62 1851 bitmap += w; // w*2 >> 1 because inverted and because 2 pixels per byte!!
Pokitto 31:f4b9b85c7b62 1852 if (xclip){
Pokitto 31:f4b9b85c7b62 1853 if (w&1) {
Pokitto 31:f4b9b85c7b62 1854 /**last pixel is odd pixel due to clipping & odd width*/
Pokitto 31:f4b9b85c7b62 1855 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1856 if ((sourcepixel&0x0F) != invisiblecolor) {
Pokitto 31:f4b9b85c7b62 1857 sourcepixel <<=4;
Pokitto 31:f4b9b85c7b62 1858 uint8_t targetpixel = *scrptr;// & 0x0F;
Pokitto 31:f4b9b85c7b62 1859 targetpixel |= sourcepixel;
Pokitto 31:f4b9b85c7b62 1860 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1861 }
Pokitto 31:f4b9b85c7b62 1862 //scrptr++;
Pokitto 31:f4b9b85c7b62 1863 }
Pokitto 31:f4b9b85c7b62 1864 bitmap++;
Pokitto 31:f4b9b85c7b62 1865 scrptr++;
Pokitto 31:f4b9b85c7b62 1866 }
Pokitto 31:f4b9b85c7b62 1867 bitmap += xjump; // needed if x<0 clipping occurs
Pokitto 31:f4b9b85c7b62 1868 } else { /** ODD pixel starting line **/
Pokitto 31:f4b9b85c7b62 1869 for (scrx = x; scrx < w+x-xclip; scrx+=2 ) {
Pokitto 31:f4b9b85c7b62 1870 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 1871 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1872 // inverted !!! store lower nibble of source pixel in lower nibble of target
Pokitto 31:f4b9b85c7b62 1873 if((sourcepixel&0x0F)!=invisiblecolor) targetpixel = (targetpixel & 0xF0) | (sourcepixel & 0x0F );
Pokitto 31:f4b9b85c7b62 1874 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1875 scrptr++;
Pokitto 31:f4b9b85c7b62 1876 targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 1877 // inverted ! store higher nibble of source pixel in higher nibble of target
Pokitto 31:f4b9b85c7b62 1878 if((sourcepixel>>4)!=invisiblecolor) targetpixel = (targetpixel & 0x0F) | (sourcepixel & 0xF0);
Pokitto 31:f4b9b85c7b62 1879 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 1880 bitmap--;
Pokitto 31:f4b9b85c7b62 1881 }
Pokitto 31:f4b9b85c7b62 1882 bitmap += w; // w*2 >> 1 because inverted and because 2 pixels per byte!!
Pokitto 31:f4b9b85c7b62 1883 bitmap+=xjump;
Pokitto 31:f4b9b85c7b62 1884 }
Pokitto 31:f4b9b85c7b62 1885 // increment the y jump in the scrptr
Pokitto 31:f4b9b85c7b62 1886 scrptr = scrptr + ((width - w)>>1)+scrxjump;
Pokitto 31:f4b9b85c7b62 1887 }
Pokitto 31:f4b9b85c7b62 1888 }
Pokitto 31:f4b9b85c7b62 1889
Pokitto 31:f4b9b85c7b62 1890 void Display::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip) {
Pokitto 31:f4b9b85c7b62 1891 #if PROJ_GAMEBUINO == 0
Pokitto 31:f4b9b85c7b62 1892 if (!flip) drawBitmap(x,y,bitmap);
Pokitto 31:f4b9b85c7b62 1893 else drawBitmapXFlipped(x,y,bitmap);
Pokitto 31:f4b9b85c7b62 1894 #else
Pokitto 31:f4b9b85c7b62 1895 if((rotation == NOROT) && (flip == NOFLIP)){
Pokitto 31:f4b9b85c7b62 1896 drawBitmap(x,y,bitmap); //use the faster algorithm
Pokitto 31:f4b9b85c7b62 1897 return;
Pokitto 31:f4b9b85c7b62 1898 }
Pokitto 31:f4b9b85c7b62 1899 uint8_t w = bitmap[0];
Pokitto 31:f4b9b85c7b62 1900 uint8_t h = bitmap[1];
Pokitto 31:f4b9b85c7b62 1901 bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
Pokitto 31:f4b9b85c7b62 1902 int8_t i, j, //coordinates in the raw bitmap
Pokitto 31:f4b9b85c7b62 1903 k, l, //coordinates in the rotated/flipped bitmap
Pokitto 31:f4b9b85c7b62 1904 byteNum, bitNum, byteWidth = (w + 7) >> 3;
Pokitto 31:f4b9b85c7b62 1905
Pokitto 31:f4b9b85c7b62 1906 rotation %= 4;
Pokitto 31:f4b9b85c7b62 1907
Pokitto 31:f4b9b85c7b62 1908 for (i = 0; i < w; i++) {
Pokitto 31:f4b9b85c7b62 1909 byteNum = i / 8;
Pokitto 31:f4b9b85c7b62 1910 bitNum = i % 8;
Pokitto 31:f4b9b85c7b62 1911 for (j = 0; j < h; j++) {
Pokitto 31:f4b9b85c7b62 1912 if (bitmap[j * byteWidth + byteNum] & (B10000000 >> bitNum)) {
Pokitto 31:f4b9b85c7b62 1913 switch (rotation) {
Pokitto 31:f4b9b85c7b62 1914 case NOROT: //no rotation
Pokitto 31:f4b9b85c7b62 1915 k = i;
Pokitto 31:f4b9b85c7b62 1916 l = j;
Pokitto 31:f4b9b85c7b62 1917 break;
Pokitto 31:f4b9b85c7b62 1918 case ROTCCW: //90° counter-clockwise
Pokitto 31:f4b9b85c7b62 1919 k = j;
Pokitto 31:f4b9b85c7b62 1920 l = w - i - 1;
Pokitto 31:f4b9b85c7b62 1921 break;
Pokitto 31:f4b9b85c7b62 1922 case ROT180: //180°
Pokitto 31:f4b9b85c7b62 1923 k = w - i - 1;
Pokitto 31:f4b9b85c7b62 1924 l = h - j - 1;
Pokitto 31:f4b9b85c7b62 1925 break;
Pokitto 31:f4b9b85c7b62 1926 case ROTCW: //90° clockwise
Pokitto 31:f4b9b85c7b62 1927 k = h - j - 1;
Pokitto 31:f4b9b85c7b62 1928 l = i;
Pokitto 31:f4b9b85c7b62 1929 break;
Pokitto 31:f4b9b85c7b62 1930 }
Pokitto 31:f4b9b85c7b62 1931 if (flip) {
Pokitto 31:f4b9b85c7b62 1932 flip %= 4;
Pokitto 31:f4b9b85c7b62 1933 if (flip & B00000001) { //horizontal flip
Pokitto 31:f4b9b85c7b62 1934 k = w - k;
Pokitto 31:f4b9b85c7b62 1935 }
Pokitto 31:f4b9b85c7b62 1936 if (flip & B00000010) { //vertical flip
Pokitto 31:f4b9b85c7b62 1937 l = h - l;
Pokitto 31:f4b9b85c7b62 1938 }
Pokitto 31:f4b9b85c7b62 1939 }
Pokitto 31:f4b9b85c7b62 1940 k += x; //place the bitmap on the screen
Pokitto 31:f4b9b85c7b62 1941 l += y;
Pokitto 31:f4b9b85c7b62 1942 drawPixel(k, l);
Pokitto 31:f4b9b85c7b62 1943 }
Pokitto 31:f4b9b85c7b62 1944 }
Pokitto 31:f4b9b85c7b62 1945 }
Pokitto 31:f4b9b85c7b62 1946 #endif //PROJ_GAMEBUINO
Pokitto 31:f4b9b85c7b62 1947
Pokitto 31:f4b9b85c7b62 1948 }
Pokitto 31:f4b9b85c7b62 1949
Pokitto 31:f4b9b85c7b62 1950 uint8_t* Display::getBuffer() {
Pokitto 31:f4b9b85c7b62 1951 return m_scrbuf;
Pokitto 31:f4b9b85c7b62 1952 }
Pokitto 31:f4b9b85c7b62 1953
Pokitto 31:f4b9b85c7b62 1954 uint8_t Display::getBitmapPixel(const uint8_t* bitmap, uint16_t x, uint16_t y) {
Pokitto 31:f4b9b85c7b62 1955 uint16_t w = *bitmap;
Pokitto 31:f4b9b85c7b62 1956 uint8_t sourcebyte = bitmap[2+(y * ((w+7)>>3))+ (x>>3)];
Pokitto 31:f4b9b85c7b62 1957 return sourcebyte & (0x80>>(x&7));
Pokitto 31:f4b9b85c7b62 1958 }
Pokitto 31:f4b9b85c7b62 1959
Pokitto 31:f4b9b85c7b62 1960 int Display::print_char(uint8_t x, uint8_t y, unsigned char c) {
Pokitto 31:f4b9b85c7b62 1961 c -= font[2];
Pokitto 31:f4b9b85c7b62 1962 if (m_mode) return directChar(x,y,c);
Pokitto 31:f4b9b85c7b62 1963 return bufferChar(x,y,c);
Pokitto 31:f4b9b85c7b62 1964 }
Pokitto 31:f4b9b85c7b62 1965
Pokitto 31:f4b9b85c7b62 1966 void Display::drawChar(int8_t x, int8_t y, unsigned char c, uint8_t size) {
Pokitto 31:f4b9b85c7b62 1967 print_char(x,y,c);
Pokitto 31:f4b9b85c7b62 1968 return;
Pokitto 31:f4b9b85c7b62 1969 }
Pokitto 31:f4b9b85c7b62 1970
Pokitto 31:f4b9b85c7b62 1971
Pokitto 31:f4b9b85c7b62 1972 bool Display::isDirectPrintingEnabled() {
Pokitto 31:f4b9b85c7b62 1973 return m_mode;
Pokitto 31:f4b9b85c7b62 1974 }
Pokitto 31:f4b9b85c7b62 1975
Pokitto 31:f4b9b85c7b62 1976 void Display::enableDirectPrinting(uint8_t m) {
Pokitto 31:f4b9b85c7b62 1977 if (m) {
Pokitto 31:f4b9b85c7b62 1978 m_mode=true;
Pokitto 31:f4b9b85c7b62 1979 m_w = POK_LCD_W;
Pokitto 31:f4b9b85c7b62 1980 m_h = POK_LCD_H;
Pokitto 31:f4b9b85c7b62 1981 } else {
Pokitto 31:f4b9b85c7b62 1982 m_mode=false;
Pokitto 31:f4b9b85c7b62 1983 m_w = getWidth();
Pokitto 31:f4b9b85c7b62 1984 m_h = getHeight();
Pokitto 31:f4b9b85c7b62 1985 }
Pokitto 31:f4b9b85c7b62 1986 }
Pokitto 31:f4b9b85c7b62 1987
Pokitto 31:f4b9b85c7b62 1988 void Display::write(uint8_t c) {
Pokitto 31:f4b9b85c7b62 1989 int charstep=0;
Pokitto 31:f4b9b85c7b62 1990 if(font[3]) {
Pokitto 31:f4b9b85c7b62 1991 // only caps in this font
Pokitto 31:f4b9b85c7b62 1992 if (c>=97) c-=32;
Pokitto 31:f4b9b85c7b62 1993 }
Pokitto 31:f4b9b85c7b62 1994 switch(c) {
Pokitto 31:f4b9b85c7b62 1995 case '\0': //null
Pokitto 31:f4b9b85c7b62 1996 break;
Pokitto 31:f4b9b85c7b62 1997 case '\n': //line feed
Pokitto 31:f4b9b85c7b62 1998 cursorX = 0;
Pokitto 31:f4b9b85c7b62 1999 inc_txtline();
Pokitto 31:f4b9b85c7b62 2000 break;
Pokitto 31:f4b9b85c7b62 2001 case 8: //backspace
Pokitto 31:f4b9b85c7b62 2002 cursorX -= font[0];
Pokitto 31:f4b9b85c7b62 2003 charstep=print_char(cursorX,cursorY,' ');
Pokitto 31:f4b9b85c7b62 2004 break;
Pokitto 31:f4b9b85c7b62 2005 case 13: //carriage return
Pokitto 31:f4b9b85c7b62 2006 cursorX = 0;
Pokitto 31:f4b9b85c7b62 2007 break;
Pokitto 31:f4b9b85c7b62 2008 case 14: //form feed new page(clear screen)
Pokitto 31:f4b9b85c7b62 2009 //clear_screen();
Pokitto 31:f4b9b85c7b62 2010 break;
Pokitto 31:f4b9b85c7b62 2011 default:
Pokitto 31:f4b9b85c7b62 2012 if (cursorX >= (m_w - font[0])) {
Pokitto 31:f4b9b85c7b62 2013 cursorX = 0;
Pokitto 31:f4b9b85c7b62 2014 if (textWrap) inc_txtline();
Pokitto 31:f4b9b85c7b62 2015 else return; // stop outputting text
Pokitto 31:f4b9b85c7b62 2016 charstep=print_char(cursorX,cursorY,c);
Pokitto 31:f4b9b85c7b62 2017 }
Pokitto 31:f4b9b85c7b62 2018 else
Pokitto 31:f4b9b85c7b62 2019 charstep=print_char(cursorX,cursorY,c);
Pokitto 31:f4b9b85c7b62 2020 if (c==' ' && adjustCharStep) charstep=(charstep>>1)+1;
Pokitto 31:f4b9b85c7b62 2021 cursorX += charstep;
Pokitto 31:f4b9b85c7b62 2022 }
Pokitto 31:f4b9b85c7b62 2023 }
Pokitto 31:f4b9b85c7b62 2024
Pokitto 31:f4b9b85c7b62 2025 void Display::inc_txtline() {
Pokitto 31:f4b9b85c7b62 2026 if (cursorY > m_h - 2*font[1]) //= (height - (font[1]+1)))
Pokitto 31:f4b9b85c7b62 2027 #if SCROLL_TEXT > 0
Pokitto 31:f4b9b85c7b62 2028 scroll(font[1] + adjustLineStep);
Pokitto 31:f4b9b85c7b62 2029 #else
Pokitto 31:f4b9b85c7b62 2030 cursorY = 0;
Pokitto 31:f4b9b85c7b62 2031 #endif
Pokitto 31:f4b9b85c7b62 2032 else
Pokitto 31:f4b9b85c7b62 2033 cursorY += font[1] + adjustLineStep;
Pokitto 31:f4b9b85c7b62 2034 }
Pokitto 31:f4b9b85c7b62 2035
Pokitto 31:f4b9b85c7b62 2036 /* default implementation: may be overridden */
Pokitto 31:f4b9b85c7b62 2037 void Display::write(const char *str)
Pokitto 31:f4b9b85c7b62 2038 {
Pokitto 31:f4b9b85c7b62 2039 while (*str)
Pokitto 31:f4b9b85c7b62 2040 write(*str++);
Pokitto 31:f4b9b85c7b62 2041 }
Pokitto 31:f4b9b85c7b62 2042
Pokitto 31:f4b9b85c7b62 2043 /* default implementation: may be overridden */
Pokitto 31:f4b9b85c7b62 2044 void Display::write(const uint8_t *buffer, uint8_t size)
Pokitto 31:f4b9b85c7b62 2045 {
Pokitto 31:f4b9b85c7b62 2046 while (size--)
Pokitto 31:f4b9b85c7b62 2047 write(*buffer++);
Pokitto 31:f4b9b85c7b62 2048 }
Pokitto 31:f4b9b85c7b62 2049
Pokitto 31:f4b9b85c7b62 2050 void Display::print(const char str[])
Pokitto 31:f4b9b85c7b62 2051 {
Pokitto 31:f4b9b85c7b62 2052 write(str);
Pokitto 31:f4b9b85c7b62 2053 }
Pokitto 31:f4b9b85c7b62 2054
Pokitto 31:f4b9b85c7b62 2055 void Display::print(char c, int base)
Pokitto 31:f4b9b85c7b62 2056 {
Pokitto 31:f4b9b85c7b62 2057 print((long) c, base);
Pokitto 31:f4b9b85c7b62 2058 }
Pokitto 31:f4b9b85c7b62 2059
Pokitto 31:f4b9b85c7b62 2060 void Display::print(unsigned char b, int base)
Pokitto 31:f4b9b85c7b62 2061 {
Pokitto 31:f4b9b85c7b62 2062 print((unsigned long) b, base);
Pokitto 31:f4b9b85c7b62 2063 }
Pokitto 31:f4b9b85c7b62 2064
Pokitto 31:f4b9b85c7b62 2065 void Display::print(int n, int base)
Pokitto 31:f4b9b85c7b62 2066 {
Pokitto 31:f4b9b85c7b62 2067 print((long) n, base);
Pokitto 31:f4b9b85c7b62 2068 }
Pokitto 31:f4b9b85c7b62 2069
Pokitto 31:f4b9b85c7b62 2070 void Display::print(unsigned int n, int base)
Pokitto 31:f4b9b85c7b62 2071 {
Pokitto 31:f4b9b85c7b62 2072 print((unsigned long) n, base);
Pokitto 31:f4b9b85c7b62 2073 }
Pokitto 31:f4b9b85c7b62 2074
Pokitto 31:f4b9b85c7b62 2075 void Display::print(long n, int base)
Pokitto 31:f4b9b85c7b62 2076 {
Pokitto 31:f4b9b85c7b62 2077 if (base == 0) {
Pokitto 31:f4b9b85c7b62 2078 write(n);
Pokitto 31:f4b9b85c7b62 2079 } else if (base == 10) {
Pokitto 31:f4b9b85c7b62 2080 if (n < 0) {
Pokitto 31:f4b9b85c7b62 2081 print('-');
Pokitto 31:f4b9b85c7b62 2082 n = -n;
Pokitto 31:f4b9b85c7b62 2083 }
Pokitto 31:f4b9b85c7b62 2084 printNumber(n, 10);
Pokitto 31:f4b9b85c7b62 2085 } else {
Pokitto 31:f4b9b85c7b62 2086 printNumber(n, base);
Pokitto 31:f4b9b85c7b62 2087 }
Pokitto 31:f4b9b85c7b62 2088 }
Pokitto 31:f4b9b85c7b62 2089
Pokitto 31:f4b9b85c7b62 2090 void Display::print(unsigned long n, int base)
Pokitto 31:f4b9b85c7b62 2091 {
Pokitto 31:f4b9b85c7b62 2092 if (base == 0) write(n);
Pokitto 31:f4b9b85c7b62 2093 else printNumber(n, base);
Pokitto 31:f4b9b85c7b62 2094 }
Pokitto 31:f4b9b85c7b62 2095
Pokitto 31:f4b9b85c7b62 2096 void Display::print(double n, int digits)
Pokitto 31:f4b9b85c7b62 2097 {
Pokitto 31:f4b9b85c7b62 2098 printFloat(n, digits);
Pokitto 31:f4b9b85c7b62 2099 }
Pokitto 31:f4b9b85c7b62 2100
Pokitto 31:f4b9b85c7b62 2101 void Display::println(void)
Pokitto 31:f4b9b85c7b62 2102 {
Pokitto 31:f4b9b85c7b62 2103 print('\r');
Pokitto 31:f4b9b85c7b62 2104 print('\n');
Pokitto 31:f4b9b85c7b62 2105 }
Pokitto 31:f4b9b85c7b62 2106
Pokitto 31:f4b9b85c7b62 2107 void Display::println(const char c[])
Pokitto 31:f4b9b85c7b62 2108 {
Pokitto 31:f4b9b85c7b62 2109 print(c);
Pokitto 31:f4b9b85c7b62 2110 println();
Pokitto 31:f4b9b85c7b62 2111 }
Pokitto 31:f4b9b85c7b62 2112
Pokitto 31:f4b9b85c7b62 2113 void Display::println(char c, int base)
Pokitto 31:f4b9b85c7b62 2114 {
Pokitto 31:f4b9b85c7b62 2115 print(c, base);
Pokitto 31:f4b9b85c7b62 2116 println();
Pokitto 31:f4b9b85c7b62 2117 }
Pokitto 31:f4b9b85c7b62 2118
Pokitto 31:f4b9b85c7b62 2119 void Display::println(unsigned char b, int base)
Pokitto 31:f4b9b85c7b62 2120 {
Pokitto 31:f4b9b85c7b62 2121 print(b, base);
Pokitto 31:f4b9b85c7b62 2122 println();
Pokitto 31:f4b9b85c7b62 2123 }
Pokitto 31:f4b9b85c7b62 2124
Pokitto 31:f4b9b85c7b62 2125 void Display::println(int n, int base)
Pokitto 31:f4b9b85c7b62 2126 {
Pokitto 31:f4b9b85c7b62 2127 print(n, base);
Pokitto 31:f4b9b85c7b62 2128 println();
Pokitto 31:f4b9b85c7b62 2129 }
Pokitto 31:f4b9b85c7b62 2130
Pokitto 31:f4b9b85c7b62 2131 void Display::println(unsigned int n, int base)
Pokitto 31:f4b9b85c7b62 2132 {
Pokitto 31:f4b9b85c7b62 2133 print(n, base);
Pokitto 31:f4b9b85c7b62 2134 println();
Pokitto 31:f4b9b85c7b62 2135 }
Pokitto 31:f4b9b85c7b62 2136
Pokitto 31:f4b9b85c7b62 2137 void Display::println(long n, int base)
Pokitto 31:f4b9b85c7b62 2138 {
Pokitto 31:f4b9b85c7b62 2139 print(n, base);
Pokitto 31:f4b9b85c7b62 2140 println();
Pokitto 31:f4b9b85c7b62 2141 }
Pokitto 31:f4b9b85c7b62 2142
Pokitto 31:f4b9b85c7b62 2143 void Display::println(unsigned long n, int base)
Pokitto 31:f4b9b85c7b62 2144 {
Pokitto 31:f4b9b85c7b62 2145 print(n, base);
Pokitto 31:f4b9b85c7b62 2146 println();
Pokitto 31:f4b9b85c7b62 2147 }
Pokitto 31:f4b9b85c7b62 2148
Pokitto 31:f4b9b85c7b62 2149 void Display::println(double n, int digits)
Pokitto 31:f4b9b85c7b62 2150 {
Pokitto 31:f4b9b85c7b62 2151 print(n, digits);
Pokitto 31:f4b9b85c7b62 2152 println();
Pokitto 31:f4b9b85c7b62 2153 }
Pokitto 31:f4b9b85c7b62 2154
Pokitto 31:f4b9b85c7b62 2155 void Display::set_cursor(uint8_t x, uint8_t y) {
Pokitto 31:f4b9b85c7b62 2156 cursorX = x;
Pokitto 31:f4b9b85c7b62 2157 cursorY = y;
Pokitto 31:f4b9b85c7b62 2158 }
Pokitto 31:f4b9b85c7b62 2159
Pokitto 31:f4b9b85c7b62 2160 void Display::print(uint8_t x, uint8_t y, const char str[]) {
Pokitto 31:f4b9b85c7b62 2161 cursorX = x;
Pokitto 31:f4b9b85c7b62 2162 cursorY = y;
Pokitto 31:f4b9b85c7b62 2163 write(str);
Pokitto 31:f4b9b85c7b62 2164
Pokitto 31:f4b9b85c7b62 2165 }
Pokitto 31:f4b9b85c7b62 2166 void Display::print(uint8_t x, uint8_t y, char c, int base) {
Pokitto 31:f4b9b85c7b62 2167 cursorX = x;
Pokitto 31:f4b9b85c7b62 2168 cursorY = y;
Pokitto 31:f4b9b85c7b62 2169 print((long) c, base);
Pokitto 31:f4b9b85c7b62 2170 }
Pokitto 31:f4b9b85c7b62 2171 void Display::print(uint8_t x, uint8_t y, unsigned char b, int base) {
Pokitto 31:f4b9b85c7b62 2172 cursorX = x;
Pokitto 31:f4b9b85c7b62 2173 cursorY = y;
Pokitto 31:f4b9b85c7b62 2174 print((unsigned long) b, base);
Pokitto 31:f4b9b85c7b62 2175 }
Pokitto 31:f4b9b85c7b62 2176 void Display::print(uint8_t x, uint8_t y, int n, int base) {
Pokitto 31:f4b9b85c7b62 2177 cursorX = x;
Pokitto 31:f4b9b85c7b62 2178 cursorY = y;
Pokitto 31:f4b9b85c7b62 2179 print((long) n, base);
Pokitto 31:f4b9b85c7b62 2180 }
Pokitto 31:f4b9b85c7b62 2181 void Display::print(uint8_t x, uint8_t y, unsigned int n, int base) {
Pokitto 31:f4b9b85c7b62 2182 cursorX = x;
Pokitto 31:f4b9b85c7b62 2183 cursorY = y;
Pokitto 31:f4b9b85c7b62 2184 print((unsigned long) n, base);
Pokitto 31:f4b9b85c7b62 2185 }
Pokitto 31:f4b9b85c7b62 2186 void Display::print(uint8_t x, uint8_t y, long n, int base) {
Pokitto 31:f4b9b85c7b62 2187 cursorX = x;
Pokitto 31:f4b9b85c7b62 2188 cursorY = y;
Pokitto 31:f4b9b85c7b62 2189 print(n,base);
Pokitto 31:f4b9b85c7b62 2190 }
Pokitto 31:f4b9b85c7b62 2191 void Display::print(uint8_t x, uint8_t y, unsigned long n, int base) {
Pokitto 31:f4b9b85c7b62 2192 cursorX = x;
Pokitto 31:f4b9b85c7b62 2193 cursorY = y;
Pokitto 31:f4b9b85c7b62 2194 print(n,base);
Pokitto 31:f4b9b85c7b62 2195 }
Pokitto 31:f4b9b85c7b62 2196 void Display::print(uint8_t x, uint8_t y, double n, int digits) {
Pokitto 31:f4b9b85c7b62 2197 cursorX = x;
Pokitto 31:f4b9b85c7b62 2198 cursorY = y;
Pokitto 31:f4b9b85c7b62 2199 print(n,digits);
Pokitto 31:f4b9b85c7b62 2200 }
Pokitto 31:f4b9b85c7b62 2201
Pokitto 31:f4b9b85c7b62 2202 void Display::println(uint8_t x, uint8_t y, const char c[])
Pokitto 31:f4b9b85c7b62 2203 {
Pokitto 31:f4b9b85c7b62 2204 cursorX = x;
Pokitto 31:f4b9b85c7b62 2205 cursorY = y;
Pokitto 31:f4b9b85c7b62 2206 print(c);
Pokitto 31:f4b9b85c7b62 2207 println();
Pokitto 31:f4b9b85c7b62 2208 }
Pokitto 31:f4b9b85c7b62 2209
Pokitto 31:f4b9b85c7b62 2210 void Display::println(uint8_t x, uint8_t y, char c, int base)
Pokitto 31:f4b9b85c7b62 2211 {
Pokitto 31:f4b9b85c7b62 2212 cursorX = x;
Pokitto 31:f4b9b85c7b62 2213 cursorY = y;
Pokitto 31:f4b9b85c7b62 2214 print(c, base);
Pokitto 31:f4b9b85c7b62 2215 println();
Pokitto 31:f4b9b85c7b62 2216 }
Pokitto 31:f4b9b85c7b62 2217
Pokitto 31:f4b9b85c7b62 2218 void Display::println(uint8_t x, uint8_t y, unsigned char b, int base)
Pokitto 31:f4b9b85c7b62 2219 {
Pokitto 31:f4b9b85c7b62 2220 cursorX = x;
Pokitto 31:f4b9b85c7b62 2221 cursorY = y;
Pokitto 31:f4b9b85c7b62 2222 print(b, base);
Pokitto 31:f4b9b85c7b62 2223 println();
Pokitto 31:f4b9b85c7b62 2224 }
Pokitto 31:f4b9b85c7b62 2225
Pokitto 31:f4b9b85c7b62 2226 void Display::println(uint8_t x, uint8_t y, int n, int base)
Pokitto 31:f4b9b85c7b62 2227 {
Pokitto 31:f4b9b85c7b62 2228 cursorX = x;
Pokitto 31:f4b9b85c7b62 2229 cursorY = y;
Pokitto 31:f4b9b85c7b62 2230 print(n, base);
Pokitto 31:f4b9b85c7b62 2231 println();
Pokitto 31:f4b9b85c7b62 2232 }
Pokitto 31:f4b9b85c7b62 2233
Pokitto 31:f4b9b85c7b62 2234 void Display::println(uint8_t x, uint8_t y, unsigned int n, int base)
Pokitto 31:f4b9b85c7b62 2235 {
Pokitto 31:f4b9b85c7b62 2236 cursorX = x;
Pokitto 31:f4b9b85c7b62 2237 cursorY = y;
Pokitto 31:f4b9b85c7b62 2238 print(n, base);
Pokitto 31:f4b9b85c7b62 2239 println();
Pokitto 31:f4b9b85c7b62 2240 }
Pokitto 31:f4b9b85c7b62 2241
Pokitto 31:f4b9b85c7b62 2242 void Display::println(uint8_t x, uint8_t y, long n, int base)
Pokitto 31:f4b9b85c7b62 2243 {
Pokitto 31:f4b9b85c7b62 2244 cursorX = x;
Pokitto 31:f4b9b85c7b62 2245 cursorY = y;
Pokitto 31:f4b9b85c7b62 2246 print(n, base);
Pokitto 31:f4b9b85c7b62 2247 println();
Pokitto 31:f4b9b85c7b62 2248 }
Pokitto 31:f4b9b85c7b62 2249
Pokitto 31:f4b9b85c7b62 2250 void Display::println(uint8_t x, uint8_t y, unsigned long n, int base)
Pokitto 31:f4b9b85c7b62 2251 {
Pokitto 31:f4b9b85c7b62 2252 cursorX = x;
Pokitto 31:f4b9b85c7b62 2253 cursorY = y;
Pokitto 31:f4b9b85c7b62 2254 print(n, base);
Pokitto 31:f4b9b85c7b62 2255 println();
Pokitto 31:f4b9b85c7b62 2256 }
Pokitto 31:f4b9b85c7b62 2257
Pokitto 31:f4b9b85c7b62 2258 void Display::println(uint8_t x, uint8_t y, double n, int digits)
Pokitto 31:f4b9b85c7b62 2259 {
Pokitto 31:f4b9b85c7b62 2260 cursorX = x;
Pokitto 31:f4b9b85c7b62 2261 cursorY = y;
Pokitto 31:f4b9b85c7b62 2262 print(n, digits);
Pokitto 31:f4b9b85c7b62 2263 println();
Pokitto 31:f4b9b85c7b62 2264 }
Pokitto 31:f4b9b85c7b62 2265
Pokitto 31:f4b9b85c7b62 2266 void Display::printNumber(unsigned long n, uint8_t base)
Pokitto 31:f4b9b85c7b62 2267 {
Pokitto 31:f4b9b85c7b62 2268 unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
Pokitto 31:f4b9b85c7b62 2269 unsigned long i = 0;
Pokitto 31:f4b9b85c7b62 2270
Pokitto 31:f4b9b85c7b62 2271 if (n == 0) {
Pokitto 31:f4b9b85c7b62 2272 print('0');
Pokitto 31:f4b9b85c7b62 2273 return;
Pokitto 31:f4b9b85c7b62 2274 }
Pokitto 31:f4b9b85c7b62 2275
Pokitto 31:f4b9b85c7b62 2276 while (n > 0) {
Pokitto 31:f4b9b85c7b62 2277 buf[i++] = n % base;
Pokitto 31:f4b9b85c7b62 2278 n /= base;
Pokitto 31:f4b9b85c7b62 2279 }
Pokitto 31:f4b9b85c7b62 2280
Pokitto 31:f4b9b85c7b62 2281 for (; i > 0; i--)
Pokitto 31:f4b9b85c7b62 2282 print((char) (buf[i - 1] < 10 ?
Pokitto 31:f4b9b85c7b62 2283 '0' + buf[i - 1] :
Pokitto 31:f4b9b85c7b62 2284 'A' + buf[i - 1] - 10));
Pokitto 31:f4b9b85c7b62 2285 }
Pokitto 31:f4b9b85c7b62 2286
Pokitto 31:f4b9b85c7b62 2287 void Display::printFloat(double number, uint8_t digits)
Pokitto 31:f4b9b85c7b62 2288 {
Pokitto 31:f4b9b85c7b62 2289 // Handle negative numbers
Pokitto 31:f4b9b85c7b62 2290 if (number < 0.0)
Pokitto 31:f4b9b85c7b62 2291 {
Pokitto 31:f4b9b85c7b62 2292 print('-');
Pokitto 31:f4b9b85c7b62 2293 number = -number;
Pokitto 31:f4b9b85c7b62 2294 }
Pokitto 31:f4b9b85c7b62 2295
Pokitto 31:f4b9b85c7b62 2296 // Round correctly so that print(1.999, 2) prints as "2.00"
Pokitto 31:f4b9b85c7b62 2297 double rounding = 0.5;
Pokitto 31:f4b9b85c7b62 2298 for (uint8_t i=0; i<digits; ++i)
Pokitto 31:f4b9b85c7b62 2299 rounding /= 10.0;
Pokitto 31:f4b9b85c7b62 2300
Pokitto 31:f4b9b85c7b62 2301 number += rounding;
Pokitto 31:f4b9b85c7b62 2302
Pokitto 31:f4b9b85c7b62 2303 // Extract the integer part of the number and print it
Pokitto 31:f4b9b85c7b62 2304 unsigned long int_part = (unsigned long)number;
Pokitto 31:f4b9b85c7b62 2305 double remainder = number - (double)int_part;
Pokitto 31:f4b9b85c7b62 2306 print(int_part);
Pokitto 31:f4b9b85c7b62 2307
Pokitto 31:f4b9b85c7b62 2308 // Print the decimal point, but only if there are digits beyond
Pokitto 31:f4b9b85c7b62 2309 if (digits > 0)
Pokitto 31:f4b9b85c7b62 2310 print(".");
Pokitto 31:f4b9b85c7b62 2311
Pokitto 31:f4b9b85c7b62 2312 // Extract digits from the remainder one at a time
Pokitto 31:f4b9b85c7b62 2313 while (digits-- > 0)
Pokitto 31:f4b9b85c7b62 2314 {
Pokitto 31:f4b9b85c7b62 2315 remainder *= 10.0;
Pokitto 31:f4b9b85c7b62 2316 int toPrint = int(remainder);
Pokitto 31:f4b9b85c7b62 2317 print(toPrint);
Pokitto 31:f4b9b85c7b62 2318 remainder -= toPrint;
Pokitto 31:f4b9b85c7b62 2319 }
Pokitto 31:f4b9b85c7b62 2320 }
Pokitto 31:f4b9b85c7b62 2321
Pokitto 31:f4b9b85c7b62 2322 void Display::draw4BitColumn(int16_t x, int16_t y, uint8_t h, uint8_t* bitmap)
Pokitto 31:f4b9b85c7b62 2323 {
Pokitto 31:f4b9b85c7b62 2324 int8_t scry;
Pokitto 31:f4b9b85c7b62 2325 uint8_t* scrptr = m_scrbuf + (y*(width>>1) + (x>>1));
Pokitto 31:f4b9b85c7b62 2326
Pokitto 31:f4b9b85c7b62 2327 /** ONLY 4-bit mode for time being **/
Pokitto 31:f4b9b85c7b62 2328
Pokitto 31:f4b9b85c7b62 2329 if ((x&1)==0) { /** EVEN pixel starting line, very simple, just copypaste **/
Pokitto 31:f4b9b85c7b62 2330 for (scry = y; scry < h+y; scry++) {
Pokitto 31:f4b9b85c7b62 2331 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 2332 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 2333 targetpixel = (targetpixel&0x0F) | (sourcepixel << 4);
Pokitto 31:f4b9b85c7b62 2334 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 2335 bitmap++;
Pokitto 31:f4b9b85c7b62 2336 scrptr+=55;
Pokitto 31:f4b9b85c7b62 2337 }
Pokitto 31:f4b9b85c7b62 2338 } else { /** ODD pixel starting line **/
Pokitto 31:f4b9b85c7b62 2339 for (scry = y; scry < h+y; scry++) {
Pokitto 31:f4b9b85c7b62 2340 uint8_t sourcepixel = *bitmap;
Pokitto 31:f4b9b85c7b62 2341 uint8_t targetpixel = *scrptr;
Pokitto 31:f4b9b85c7b62 2342 // store source pixel in lower nibble of target
Pokitto 31:f4b9b85c7b62 2343 targetpixel = (targetpixel & 0xF0) | (sourcepixel);
Pokitto 31:f4b9b85c7b62 2344 *scrptr = targetpixel;
Pokitto 31:f4b9b85c7b62 2345 scrptr+=55;
Pokitto 31:f4b9b85c7b62 2346 bitmap++;
Pokitto 31:f4b9b85c7b62 2347 }
Pokitto 31:f4b9b85c7b62 2348 }
Pokitto 31:f4b9b85c7b62 2349 }
Pokitto 31:f4b9b85c7b62 2350
Pokitto 31:f4b9b85c7b62 2351 /**
Pokitto 31:f4b9b85c7b62 2352 * Setup or disable the sprite. Note that enabled sprites must always have subsequent indices, starting from the index zero.
Pokitto 31:f4b9b85c7b62 2353 * You cannot have gaps in indices of enabled sprites.
Pokitto 31:f4b9b85c7b62 2354 * The max number of sprites can be changed by a SPRITE_COUNT define, the default is 4.
Pokitto 31:f4b9b85c7b62 2355 * Note: the sprites currently work only in the 220 x 176 x 2bpp mode.
Pokitto 31:f4b9b85c7b62 2356 * @param index The sprite index. The lower index is drawn first, i.e. is on bottom.
Pokitto 31:f4b9b85c7b62 2357 * @param bitmap A pointer to a 2bpp bitmap. A NULL value means that the sprite is disabled. The ownership is not transferred, so the caller must keep the bitmap alive.
Pokitto 31:f4b9b85c7b62 2358 * @param palette4x16bit Four color palette of 16bit elements. The first color value is considered as transparent. The palette is copied to the sprite struct, so the caller do not have to keep it alive.
Pokitto 31:f4b9b85c7b62 2359 * @param x The initial x
Pokitto 31:f4b9b85c7b62 2360 * @param y The initial y
Pokitto 31:f4b9b85c7b62 2361 * @param doResetDirtyRect (default=true) True, if the previous coordinates are reseted.
Pokitto 31:f4b9b85c7b62 2362 */
Pokitto 31:f4b9b85c7b62 2363 void Display::setSpriteBitmap(uint8_t index, const uint8_t* bitmap, const uint16_t* palette4x16bit, int16_t x, int16_t y, bool doResetDirtyRect ) {
Pokitto 31:f4b9b85c7b62 2364
Pokitto 31:f4b9b85c7b62 2365 setSprite(index, &(bitmap[2]), palette4x16bit, x, y, bitmap[0], bitmap[1], doResetDirtyRect);
Pokitto 31:f4b9b85c7b62 2366 }
Pokitto 31:f4b9b85c7b62 2367
Pokitto 31:f4b9b85c7b62 2368 /**
Pokitto 31:f4b9b85c7b62 2369 * Setup or disable the sprite. Note that enabled sprites must always have subsequent indices, starting from the index zero.
Pokitto 31:f4b9b85c7b62 2370 * You cannot have gaps in indices of enabled sprites.
Pokitto 31:f4b9b85c7b62 2371 * The max number of sprites can be changed by a SPRITE_COUNT define, the default is 4.
Pokitto 31:f4b9b85c7b62 2372 * Note: the sprites currently work only in the 220 x 176 x 2bpp mode.
Pokitto 31:f4b9b85c7b62 2373 * @param index The sprite index. The lower index is drawn first, i.e. is on bottom. Note that
Pokitto 31:f4b9b85c7b62 2374 * @param data A pointer to a 2bpp pixel data of size w x h. A NULL value means that the sprite is disabled. The ownership is not transferred, so the caller must keep the data alive.
Pokitto 31:f4b9b85c7b62 2375 * @param palette4x16bit Four color palette of 16bit elements. The first color value is considered as transparent. The palette is copied to the sprite struct, so the caller do not have to keep it alive.
Pokitto 31:f4b9b85c7b62 2376 * @param x The initial x
Pokitto 31:f4b9b85c7b62 2377 * @param y The initial y
Pokitto 31:f4b9b85c7b62 2378 * @param w Width
Pokitto 31:f4b9b85c7b62 2379 * @param h Height
Pokitto 31:f4b9b85c7b62 2380 */
Pokitto 31:f4b9b85c7b62 2381 void Display::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 ) {
Pokitto 31:f4b9b85c7b62 2382
Pokitto 31:f4b9b85c7b62 2383 if(index >= SPRITE_COUNT) return;
Pokitto 31:f4b9b85c7b62 2384 m_sprites[index].bitmapData = data;
Pokitto 31:f4b9b85c7b62 2385 m_sprites[index].x = x;
Pokitto 31:f4b9b85c7b62 2386 m_sprites[index].y = y;
Pokitto 31:f4b9b85c7b62 2387 if (doResetDirtyRect) {
Pokitto 31:f4b9b85c7b62 2388 m_sprites[index].oldx = x;
Pokitto 31:f4b9b85c7b62 2389 m_sprites[index].oldy = y;
Pokitto 31:f4b9b85c7b62 2390 }
Pokitto 31:f4b9b85c7b62 2391 m_sprites[index].w = w;
Pokitto 31:f4b9b85c7b62 2392 m_sprites[index].h = h;
Pokitto 35:4f7edccf8ed6 2393 if( palette4x16bit ) memcpy(m_sprites[index].palette, palette4x16bit, 4*2);
Pokitto 31:f4b9b85c7b62 2394 }
Pokitto 31:f4b9b85c7b62 2395
Pokitto 31:f4b9b85c7b62 2396 /**
Pokitto 31:f4b9b85c7b62 2397 * Set the sprite position.
Pokitto 31:f4b9b85c7b62 2398 * @param index The sprite index
Pokitto 31:f4b9b85c7b62 2399 * @param x
Pokitto 31:f4b9b85c7b62 2400 * @param y
Pokitto 31:f4b9b85c7b62 2401 */
Pokitto 31:f4b9b85c7b62 2402 void Display::setSpritePos(uint8_t index, int16_t x, int16_t y) {
Pokitto 31:f4b9b85c7b62 2403
Pokitto 31:f4b9b85c7b62 2404 if(index >= SPRITE_COUNT) return;
Pokitto 31:f4b9b85c7b62 2405 m_sprites[index].x = x;
Pokitto 31:f4b9b85c7b62 2406 m_sprites[index].y = y;
Pokitto 31:f4b9b85c7b62 2407 }
Pokitto 31:f4b9b85c7b62 2408
Pokitto 31:f4b9b85c7b62 2409 void Display::lcdRefresh(unsigned char* scr, bool useDirectDrawMode) {
Pokitto 31:f4b9b85c7b62 2410
Pokitto 31:f4b9b85c7b62 2411 #if POK_SCREENMODE == MODE_HI_4COLOR
Pokitto 31:f4b9b85c7b62 2412 // If there is one or more sprites, use sprite enabled drawing.
Pokitto 31:f4b9b85c7b62 2413 if (m_sprites[0].bitmapData != NULL)
Pokitto 31:f4b9b85c7b62 2414 lcdRefreshMode1Spr(scr, 0, 0, LCDWIDTH, LCDHEIGHT, paletteptr, m_sprites, useDirectDrawMode);
Pokitto 31:f4b9b85c7b62 2415 else if (!useDirectDrawMode)
Pokitto 31:f4b9b85c7b62 2416 lcdRefreshMode1(m_scrbuf, 0, 0, LCDWIDTH, LCDHEIGHT, paletteptr);
Pokitto 31:f4b9b85c7b62 2417 #endif
Pokitto 31:f4b9b85c7b62 2418
Pokitto 31:f4b9b85c7b62 2419 // For the screen modes that do not support sprites, return if the direct draw mode is used.
Pokitto 31:f4b9b85c7b62 2420 if (useDirectDrawMode) return;
Pokitto 35:4f7edccf8ed6 2421 #if POK_SCREENMODE == MODE13
Pokitto 35:4f7edccf8ed6 2422 lcdRefreshMode13(m_scrbuf, paletteptr, palOffset);
Pokitto 35:4f7edccf8ed6 2423 #endif
Pokitto 31:f4b9b85c7b62 2424
Pokitto 31:f4b9b85c7b62 2425 #if POK_SCREENMODE == MODE_GAMEBOY
Pokitto 31:f4b9b85c7b62 2426 lcdRefreshModeGBC(scr, paletteptr);
Pokitto 31:f4b9b85c7b62 2427 #endif
Pokitto 31:f4b9b85c7b62 2428
Pokitto 31:f4b9b85c7b62 2429 #if POK_SCREENMODE == MODE_FAST_16COLOR
Pokitto 31:f4b9b85c7b62 2430 lcdRefreshMode2(scr, paletteptr);
Pokitto 31:f4b9b85c7b62 2431 #endif
Pokitto 31:f4b9b85c7b62 2432
Pokitto 31:f4b9b85c7b62 2433 #if POK_SCREENMODE == MODE_GAMEBUINO_16COLOR
Pokitto 31:f4b9b85c7b62 2434 lcdRefreshGB(scr, paletteptr);
Pokitto 31:f4b9b85c7b62 2435 #endif
Pokitto 31:f4b9b85c7b62 2436
Pokitto 31:f4b9b85c7b62 2437 #if POK_SCREENMODE == MODE_ARDUBOY_16COLOR
Pokitto 31:f4b9b85c7b62 2438 lcdRefreshAB(scr, paletteptr);
Pokitto 31:f4b9b85c7b62 2439 #endif
Pokitto 31:f4b9b85c7b62 2440
Pokitto 31:f4b9b85c7b62 2441 }
Pokitto 31:f4b9b85c7b62 2442
Pokitto 31:f4b9b85c7b62 2443 void Display::setFrameBufferTo(uint8_t* sb) {
Pokitto 31:f4b9b85c7b62 2444 m_scrbuf = sb;
Pokitto 31:f4b9b85c7b62 2445 };
Pokitto 31:f4b9b85c7b62 2446
Pokitto 31:f4b9b85c7b62 2447 void Display::setTileBufferTo(uint8_t* tb) {
Pokitto 31:f4b9b85c7b62 2448 m_tilebuf = tb;
Pokitto 31:f4b9b85c7b62 2449 };
Pokitto 31:f4b9b85c7b62 2450
Pokitto 31:f4b9b85c7b62 2451 void Display::loadTileset(const uint8_t* ts) {
Pokitto 31:f4b9b85c7b62 2452 m_tileset = (uint8_t*) ts;
Pokitto 31:f4b9b85c7b62 2453 };
Pokitto 31:f4b9b85c7b62 2454
Pokitto 31:f4b9b85c7b62 2455 void Display::setTile(uint16_t i, uint8_t t) {
Pokitto 31:f4b9b85c7b62 2456 if (!m_tilebuf) return;
Pokitto 31:f4b9b85c7b62 2457 m_tilebuf[i]=t;
Pokitto 31:f4b9b85c7b62 2458 };
Pokitto 31:f4b9b85c7b62 2459
Pokitto 35:4f7edccf8ed6 2460 // Convert an integer to a hexadecimal string
Pokitto 35:4f7edccf8ed6 2461 char* itoa_hex(int num, char* dest, int destLen) {
Pokitto 35:4f7edccf8ed6 2462 int i = destLen-1;
Pokitto 35:4f7edccf8ed6 2463 do {
Pokitto 35:4f7edccf8ed6 2464 char c = (num % 16) + '0';
Pokitto 35:4f7edccf8ed6 2465 if (c > '9') c += 7;
Pokitto 35:4f7edccf8ed6 2466 dest[i--] = c;
Pokitto 35:4f7edccf8ed6 2467 num /= 16;
Pokitto 35:4f7edccf8ed6 2468 } while (num && i >= 0);
Pokitto 35:4f7edccf8ed6 2469 return &(dest[i+1]);
Pokitto 35:4f7edccf8ed6 2470 }
Pokitto 35:4f7edccf8ed6 2471
Pokitto 35:4f7edccf8ed6 2472 // Draw the crash screen and wait forever
Pokitto 35:4f7edccf8ed6 2473 void ShowCrashScreenAndWait( const char* texLine1, const char* texLine2, const char* texLine3, const char* texLine4, const char* texLine5 ) {
Pokitto 35:4f7edccf8ed6 2474
Pokitto 35:4f7edccf8ed6 2475 // draw screen red
Pokitto 35:4f7edccf8ed6 2476 lcdFillSurface(COLOR_RED);
Pokitto 35:4f7edccf8ed6 2477
Pokitto 35:4f7edccf8ed6 2478 // Draw text
Pokitto 35:4f7edccf8ed6 2479 Display::directcolor = COLOR_WHITE;
Pokitto 35:4f7edccf8ed6 2480 Display::invisiblecolor = COLOR_RED;
Pokitto 35:4f7edccf8ed6 2481 Display::directbgcolor = COLOR_RED; // Cannot be black as that is a transparent color
Pokitto 35:4f7edccf8ed6 2482 Display::directtextrotated = false;
Pokitto 35:4f7edccf8ed6 2483 Display::adjustCharStep = 0;
Pokitto 35:4f7edccf8ed6 2484 Display::adjustLineStep = 0;
Pokitto 35:4f7edccf8ed6 2485 Display::setFont(fntC64UIGfx); // A special font set that contains UI gfx in lower case letters.
Pokitto 35:4f7edccf8ed6 2486 Display::fixedWidthFont = true; // Needed for the non-proportional C64 font (default value=false)
Pokitto 35:4f7edccf8ed6 2487 Display::enableDirectPrinting(true);
Pokitto 35:4f7edccf8ed6 2488
Pokitto 35:4f7edccf8ed6 2489 // Draw texts
Pokitto 35:4f7edccf8ed6 2490 int yOffsetInPixels = 5;
Pokitto 35:4f7edccf8ed6 2491 Display::set_cursor(0, 9 + yOffsetInPixels);
Pokitto 35:4f7edccf8ed6 2492 Display::print(" "); Display::println(texLine1);
Pokitto 35:4f7edccf8ed6 2493 Display::print(" "); Display::println(texLine2);
Pokitto 35:4f7edccf8ed6 2494 Display::print(" "); Display::println(texLine3);
Pokitto 35:4f7edccf8ed6 2495 Display::println();
Pokitto 35:4f7edccf8ed6 2496 Display::print(" *"); Display::println(texLine4);
Pokitto 35:4f7edccf8ed6 2497 Display::print(" *"); Display::println(texLine5);
Pokitto 35:4f7edccf8ed6 2498
Pokitto 35:4f7edccf8ed6 2499 Display::set_cursor(0, 0 + yOffsetInPixels);
Pokitto 35:4f7edccf8ed6 2500
Pokitto 35:4f7edccf8ed6 2501 // Frame
Pokitto 35:4f7edccf8ed6 2502 Display::println(" abbbbbbbbbbbbbbbbbbbbbbbbc");
Pokitto 35:4f7edccf8ed6 2503 Display::print (" |"); Display::println(26*8, Display::cursorY,"|");
Pokitto 35:4f7edccf8ed6 2504 Display::print (" |"); Display::println(26*8, Display::cursorY,"|");
Pokitto 35:4f7edccf8ed6 2505 Display::print (" |"); Display::println(26*8, Display::cursorY,"|");
Pokitto 35:4f7edccf8ed6 2506 Display::print (" |"); Display::println(26*8, Display::cursorY,"|");
Pokitto 35:4f7edccf8ed6 2507 Display::print (" |"); Display::println(26*8, Display::cursorY,"|");
Pokitto 35:4f7edccf8ed6 2508 Display::print (" |"); Display::println(26*8, Display::cursorY,"|");
Pokitto 35:4f7edccf8ed6 2509 Display::println(" dbbbzybbbbbbbbbbbbbbbbbbbe");
Pokitto 35:4f7edccf8ed6 2510 Display::println(" {e");
Pokitto 35:4f7edccf8ed6 2511
Pokitto 35:4f7edccf8ed6 2512 // Pokitto image
Pokitto 35:4f7edccf8ed6 2513 Display::println ("");
Pokitto 35:4f7edccf8ed6 2514 Display::println (" ijkl");
Pokitto 35:4f7edccf8ed6 2515 Display::println (" mnop");
Pokitto 35:4f7edccf8ed6 2516 Display::println (" qrst");
Pokitto 35:4f7edccf8ed6 2517 Display::println (" uvwx");
Pokitto 35:4f7edccf8ed6 2518
Pokitto 35:4f7edccf8ed6 2519 // loop forever
Pokitto 35:4f7edccf8ed6 2520 while(1){;}
Pokitto 35:4f7edccf8ed6 2521 }
Pokitto 35:4f7edccf8ed6 2522
Pokitto 35:4f7edccf8ed6 2523 // Check the stack size and show a crash screen if the stack is too big.
Pokitto 35:4f7edccf8ed6 2524 /*void CheckStack() {
Pokitto 35:4f7edccf8ed6 2525 #ifndef POK_SIM
Pokitto 35:4f7edccf8ed6 2526 int currStackTop;
Pokitto 35:4f7edccf8ed6 2527 const int freeStackThreshold = 400;
Pokitto 35:4f7edccf8ed6 2528 if ((int)&currStackTop - (int)_ebss < freeStackThreshold) {
Pokitto 35:4f7edccf8ed6 2529
Pokitto 35:4f7edccf8ed6 2530 // Create info string: "<stack size>:<current stack pointer>", e.g. "12345ABC:12345ABC"
Pokitto 35:4f7edccf8ed6 2531 const int infoStringLen = 8+1+8;
Pokitto 35:4f7edccf8ed6 2532 static char infoString[infoStringLen+1];
Pokitto 35:4f7edccf8ed6 2533 memset(infoString,0,infoStringLen+1);
Pokitto 35:4f7edccf8ed6 2534 const int stackSize = (int)_vStackTop - (int)&currStackTop;
Pokitto 35:4f7edccf8ed6 2535 const int tmpStrLen = 8;
Pokitto 35:4f7edccf8ed6 2536 static char tmpStr[tmpStrLen+1];
Pokitto 35:4f7edccf8ed6 2537 memset(tmpStr,0,tmpStrLen+1);
Pokitto 35:4f7edccf8ed6 2538 char* subStr = itoa_hex(stackSize, tmpStr, tmpStrLen); // keep ending null
Pokitto 35:4f7edccf8ed6 2539 strcat(infoString, subStr); // Add stack size as hex string
Pokitto 35:4f7edccf8ed6 2540 strcat(infoString, ":");
Pokitto 35:4f7edccf8ed6 2541 subStr = itoa_hex((int)&currStackTop, tmpStr, tmpStrLen); // keep ending null
Pokitto 35:4f7edccf8ed6 2542 strcat(infoString, subStr); // Add stack pointer address as hex string
Pokitto 35:4f7edccf8ed6 2543
Pokitto 35:4f7edccf8ed6 2544 // Draw the crash screen and wait forever. Use static const strings to avoid more stack usage.
Pokitto 35:4f7edccf8ed6 2545 static const char* texLine1 = "OOPS! PLEASE, RESTART";
Pokitto 35:4f7edccf8ed6 2546 static const char* texLine2 = "POKITTO OR RELOAD";
Pokitto 35:4f7edccf8ed6 2547 static const char* texLine3 = "SOFTWARE.";
Pokitto 35:4f7edccf8ed6 2548 static const char* texLine4 = "STACK TOO BIG!";
Pokitto 35:4f7edccf8ed6 2549 ShowCrashScreenAndWait(texLine1, texLine2, texLine3, texLine4, infoString);
Pokitto 35:4f7edccf8ed6 2550 }
Pokitto 35:4f7edccf8ed6 2551 #endif
Pokitto 35:4f7edccf8ed6 2552 }*/
Pokitto 31:f4b9b85c7b62 2553
Pokitto 31:f4b9b85c7b62 2554 /** Eof */
Pokitto 31:f4b9b85c7b62 2555
Pokitto 31:f4b9b85c7b62 2556
Pokitto 31:f4b9b85c7b62 2557
Pokitto 31:f4b9b85c7b62 2558