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:
Fri Dec 29 05:17:38 2017 +0000
Revision:
24:9561281d0378
Child:
25:4363d43c4917
PokittoLib synced with Github and all Spianl & Hanski contributions so far

Who changed what in which revision?

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