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 06:38:08 2017 +0000
Revision:
25:4363d43c4917
Parent:
24:9561281d0378
palOffset definition added

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