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:
Wed Oct 11 20:35:52 2017 +0000
Revision:
6:72f87b7c7400
Fixed PokittoLib to fully working. Includes mbed-src

Who changed what in which revision?

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