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

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Fri Apr 05 11:18:14 2019 +0000
Revision:
68:61a4ccb0a4b6
Parent:
65:deed4aa606fb
Child:
71:531419862202
Pure polling method added for Buttons

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 46:e7e438368e16 1 /**************************************************************************/
Pokitto 46:e7e438368e16 2 /*!
Pokitto 46:e7e438368e16 3 @file HWLCD.cpp
Pokitto 46:e7e438368e16 4 @author Jonne Valola
Pokitto 46:e7e438368e16 5
Pokitto 46:e7e438368e16 6 @section LICENSE
Pokitto 46:e7e438368e16 7
Pokitto 46:e7e438368e16 8 Software License Agreement (BSD License)
Pokitto 46:e7e438368e16 9
Pokitto 46:e7e438368e16 10 Copyright (c) 2016, Jonne Valola
Pokitto 46:e7e438368e16 11 All rights reserved.
Pokitto 46:e7e438368e16 12
Pokitto 46:e7e438368e16 13 Redistribution and use in source and binary forms, with or without
Pokitto 46:e7e438368e16 14 modification, are permitted provided that the following conditions are met:
Pokitto 46:e7e438368e16 15 1. Redistributions of source code must retain the above copyright
Pokitto 46:e7e438368e16 16 notice, this list of conditions and the following disclaimer.
Pokitto 46:e7e438368e16 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 46:e7e438368e16 18 notice, this list of conditions and the following disclaimer in the
Pokitto 46:e7e438368e16 19 documentation and/or other materials provided with the distribution.
Pokitto 46:e7e438368e16 20 3. Neither the name of the copyright holders nor the
Pokitto 46:e7e438368e16 21 names of its contributors may be used to endorse or promote products
Pokitto 46:e7e438368e16 22 derived from this software without specific prior written permission.
Pokitto 46:e7e438368e16 23
Pokitto 46:e7e438368e16 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 46:e7e438368e16 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 46:e7e438368e16 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 46:e7e438368e16 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 46:e7e438368e16 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 46:e7e438368e16 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 46:e7e438368e16 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 46:e7e438368e16 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 46:e7e438368e16 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 46:e7e438368e16 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 46:e7e438368e16 34 */
Pokitto 46:e7e438368e16 35 /**************************************************************************/
Pokitto 46:e7e438368e16 36
Pokitto 46:e7e438368e16 37 #include "HWLCD.h" //HWLCD.h" #include "HWLCD.h"
Pokitto 46:e7e438368e16 38 #include "Pokitto_settings.h"
Pokitto 46:e7e438368e16 39
Pokitto 51:113b1d84c34f 40 #define avrmax(a,b) ((a)>(b)?(a):(b))
Pokitto 51:113b1d84c34f 41 #define avrmin(a,b) ((a)<(b)?(a):(b))
Pokitto 46:e7e438368e16 42
Pokitto 46:e7e438368e16 43 #ifdef DISABLEAVRMIN
Pokitto 46:e7e438368e16 44 #include <algorithm>
Pokitto 46:e7e438368e16 45 using std::min;
Pokitto 46:e7e438368e16 46 using std::max;
Pokitto 46:e7e438368e16 47 #endif // DISABLEAVRMIN
Pokitto 46:e7e438368e16 48
Pokitto 46:e7e438368e16 49 #define AB_JUMP 1024 // jump one 1-bit Arduboy screen forward to get next color bit
Pokitto 46:e7e438368e16 50 #define GB_JUMP 504 // jump one 1-bit Gamebuino screen forward to get next color bit
Pokitto 46:e7e438368e16 51
Pokitto 46:e7e438368e16 52 using namespace Pokitto;
Pokitto 46:e7e438368e16 53
Pokitto 46:e7e438368e16 54 uint16_t prevdata=0; // if data does not change, do not adjust LCD bus lines
Pokitto 46:e7e438368e16 55
Pokitto 46:e7e438368e16 56 #if POK_BOARDREV == 2
Pokitto 46:e7e438368e16 57 pwmout_t backlightpwm;
Pokitto 46:e7e438368e16 58 #endif
Pokitto 46:e7e438368e16 59
Pokitto 51:113b1d84c34f 60 volatile uint32_t *LCD = reinterpret_cast< volatile uint32_t * >(0xA0002188);
Pokitto 46:e7e438368e16 61
Pokitto 46:e7e438368e16 62 /**************************************************************************/
Pokitto 46:e7e438368e16 63 /*!
Pokitto 46:e7e438368e16 64 @brief set up the 16-bit bus
Pokitto 46:e7e438368e16 65 */
Pokitto 46:e7e438368e16 66 /**************************************************************************/
Pokitto 46:e7e438368e16 67
Pokitto 46:e7e438368e16 68 static inline void setup_data_16(uint16_t data)
Pokitto 46:e7e438368e16 69 {
Pokitto 46:e7e438368e16 70 //uint32_t p2=0;
Pokitto 46:e7e438368e16 71
Pokitto 46:e7e438368e16 72 //if (data != prevdata) {
Pokitto 46:e7e438368e16 73 //
Pokitto 46:e7e438368e16 74 //prevdata=data;
Pokitto 46:e7e438368e16 75
Pokitto 46:e7e438368e16 76 /** D0...D16 = P2_3 ... P2_18 **/
Pokitto 46:e7e438368e16 77 //p2 = data << 3;
Pokitto 46:e7e438368e16 78
Pokitto 46:e7e438368e16 79 //__disable_irq(); // Disable Interrupts
Pokitto 46:e7e438368e16 80 SET_MASK_P2;
Pokitto 46:e7e438368e16 81 LPC_GPIO_PORT->MPIN[2] = (data<<3); // write bits to port
Pokitto 46:e7e438368e16 82 CLR_MASK_P2;
Pokitto 46:e7e438368e16 83 //__enable_irq(); // Enable Interrupts
Pokitto 46:e7e438368e16 84 //}
Pokitto 46:e7e438368e16 85 }
Pokitto 46:e7e438368e16 86
Pokitto 46:e7e438368e16 87
Pokitto 46:e7e438368e16 88 /**************************************************************************/
Pokitto 46:e7e438368e16 89 /*!
Pokitto 46:e7e438368e16 90 @brief Write a command to the lcd, 16-bit bus
Pokitto 46:e7e438368e16 91 */
Pokitto 46:e7e438368e16 92 /**************************************************************************/
Pokitto 46:e7e438368e16 93 inline void write_command_16(uint16_t data)
Pokitto 46:e7e438368e16 94 {
Pokitto 46:e7e438368e16 95 CLR_CS; // select lcd
Pokitto 46:e7e438368e16 96 CLR_CD; // clear CD = command
Pokitto 46:e7e438368e16 97 SET_RD; // RD high, do not read
Pokitto 46:e7e438368e16 98 setup_data_16(data); // function that inputs the data into the relevant bus lines
Pokitto 46:e7e438368e16 99 CLR_WR_SLOW; // WR low
Pokitto 46:e7e438368e16 100 SET_WR; // WR low, then high = write strobe
Pokitto 46:e7e438368e16 101 SET_CS; // de-select lcd
Pokitto 46:e7e438368e16 102 }
Pokitto 46:e7e438368e16 103
Pokitto 46:e7e438368e16 104 /**************************************************************************/
Pokitto 46:e7e438368e16 105 /*!
Pokitto 46:e7e438368e16 106 @brief Write data to the lcd, 16-bit bus
Pokitto 46:e7e438368e16 107 */
Pokitto 46:e7e438368e16 108 /**************************************************************************/
Pokitto 46:e7e438368e16 109 inline void write_data_16(uint16_t data)
Pokitto 46:e7e438368e16 110 {
Pokitto 46:e7e438368e16 111 CLR_CS;
Pokitto 46:e7e438368e16 112 SET_CD;
Pokitto 46:e7e438368e16 113 SET_RD;
Pokitto 46:e7e438368e16 114 setup_data_16(data);
Pokitto 46:e7e438368e16 115 CLR_WR;
Pokitto 46:e7e438368e16 116 SET_WR;
Pokitto 46:e7e438368e16 117 SET_CS;
Pokitto 46:e7e438368e16 118 }
Pokitto 46:e7e438368e16 119
Pokitto 46:e7e438368e16 120 /**************************************************************************/
Pokitto 46:e7e438368e16 121 /*!
Pokitto 46:e7e438368e16 122 @brief Pump data to the lcd, 16-bit bus, public function
Pokitto 46:e7e438368e16 123 */
Pokitto 46:e7e438368e16 124 /**************************************************************************/
Pokitto 46:e7e438368e16 125 void Pokitto::pumpDRAMdata(uint16_t* data,uint16_t counter)
Pokitto 46:e7e438368e16 126 {
Pokitto 46:e7e438368e16 127 while (counter--) {
Pokitto 46:e7e438368e16 128 CLR_CS;
Pokitto 46:e7e438368e16 129 SET_CD;
Pokitto 46:e7e438368e16 130 SET_RD;
Pokitto 46:e7e438368e16 131 setup_data_16(*data++);
Pokitto 46:e7e438368e16 132 CLR_WR;
Pokitto 46:e7e438368e16 133 SET_WR;
Pokitto 46:e7e438368e16 134 SET_CS;
Pokitto 46:e7e438368e16 135 }
Pokitto 46:e7e438368e16 136 }
Pokitto 46:e7e438368e16 137
Pokitto 46:e7e438368e16 138
Pokitto 46:e7e438368e16 139 /**************************************************************************/
Pokitto 46:e7e438368e16 140 /*!
Pokitto 46:e7e438368e16 141 @brief Point to a (x,y) location in the LCD DRAM
Pokitto 46:e7e438368e16 142 */
Pokitto 46:e7e438368e16 143 /**************************************************************************/
Pokitto 46:e7e438368e16 144 static inline void setDRAMptr(uint8_t xptr, uint8_t yoffset)
Pokitto 46:e7e438368e16 145 {
Pokitto 46:e7e438368e16 146 write_command(0x20); // Vertical DRAM Address
Pokitto 46:e7e438368e16 147 write_data(yoffset);
Pokitto 46:e7e438368e16 148 write_command(0x21); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 149 write_data(xptr); //
Pokitto 46:e7e438368e16 150 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 151 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 152 }
Pokitto 46:e7e438368e16 153
Pokitto 46:e7e438368e16 154 /**************************************************************************/
Pokitto 46:e7e438368e16 155 /*!
Pokitto 46:e7e438368e16 156 @brief Point to a (x,y) location in the LCD DRAM, public function
Pokitto 46:e7e438368e16 157 */
Pokitto 46:e7e438368e16 158 /**************************************************************************/
Pokitto 46:e7e438368e16 159 void Pokitto::setDRAMpoint(uint8_t xptr, uint8_t yoffset)
Pokitto 46:e7e438368e16 160 {
Pokitto 46:e7e438368e16 161 write_command(0x20); // Vertical DRAM Address
Pokitto 46:e7e438368e16 162 write_data(yoffset);
Pokitto 46:e7e438368e16 163 write_command(0x21); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 164 write_data(xptr); //
Pokitto 46:e7e438368e16 165 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 166 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 167 }
Pokitto 46:e7e438368e16 168
Pokitto 46:e7e438368e16 169 void Pokitto::initBacklight() {
Pokitto 46:e7e438368e16 170 #if POK_BOARDREV == 2
Pokitto 46:e7e438368e16 171 pwmout_init(&backlightpwm,POK_BACKLIGHT_PIN);
Pokitto 46:e7e438368e16 172 pwmout_period_us(&backlightpwm,5);
Pokitto 46:e7e438368e16 173 pwmout_write(&backlightpwm,POK_BACKLIGHT_INITIALVALUE);
Pokitto 46:e7e438368e16 174 #endif
Pokitto 46:e7e438368e16 175 }
Pokitto 46:e7e438368e16 176
Pokitto 46:e7e438368e16 177 void Pokitto::setBacklight(float value) {
Pokitto 46:e7e438368e16 178 if (value>0.999f) value = 0.999f;
Pokitto 46:e7e438368e16 179 pwmout_write(&backlightpwm,value);
Pokitto 46:e7e438368e16 180 }
Pokitto 46:e7e438368e16 181
Pokitto 46:e7e438368e16 182 void Pokitto::lcdInit() {
Pokitto 46:e7e438368e16 183 initBacklight();
Pokitto 46:e7e438368e16 184
Pokitto 46:e7e438368e16 185 SET_RESET;
Pokitto 46:e7e438368e16 186 wait_ms(10);
Pokitto 46:e7e438368e16 187 CLR_RESET;
Pokitto 46:e7e438368e16 188 wait_ms(10);
Pokitto 46:e7e438368e16 189 SET_RESET;
Pokitto 46:e7e438368e16 190 wait_ms(10);
Pokitto 46:e7e438368e16 191 //************* Start Initial Sequence **********//
Pokitto 46:e7e438368e16 192 write_command(0x01); // driver output control, this also affects direction
Pokitto 46:e7e438368e16 193 write_data(0x11C); // originally: 0x11C 100011100 SS,NL4,NL3,NL2
Pokitto 46:e7e438368e16 194 // NL4...0 is the number of scan lines to drive the screen !!!
Pokitto 46:e7e438368e16 195 // so 11100 is 1c = 220 lines, correct
Pokitto 46:e7e438368e16 196 // test 1: 0x1C 11100 SS=0,NL4,NL3,NL2 -> no effect
Pokitto 46:e7e438368e16 197 // test 2: 0x31C 1100011100 GS=1,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 46:e7e438368e16 198 // test 3: 0x51C 10100011100 SM=1,GS=0,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 46:e7e438368e16 199 // test 4: 0x71C SM=1,GS=1,SS=1,NL4,NL3,NL2
Pokitto 46:e7e438368e16 200 // test 5: 0x
Pokitto 46:e7e438368e16 201 // seems to have no effect... is this perhaps only for RGB mode ?
Pokitto 46:e7e438368e16 202
Pokitto 46:e7e438368e16 203 write_command(0x02); // LCD driving control
Pokitto 46:e7e438368e16 204 write_data(0x0100); // INV = 1
Pokitto 46:e7e438368e16 205
Pokitto 46:e7e438368e16 206 write_command(0x03); // Entry mode... lets try if this affects the direction
Pokitto 46:e7e438368e16 207 write_data(0x1030); // originally 0x1030 1000000110000 BGR,ID1,ID0
Pokitto 46:e7e438368e16 208 // test 1: 0x1038 1000000111000 BGR,ID1,ID0,AM=1 ->drawing DRAM horizontally
Pokitto 46:e7e438368e16 209 // test 4: am=1, id0=0, id1=0, 1000000001000,0x1008 -> same as above, but flipped on long
Pokitto 46:e7e438368e16 210 // test 2: am=0, id0=0, 1000000100000, 0x1020 -> flipped on long axis
Pokitto 46:e7e438368e16 211 // test 3: am=0, id1=0, 1000000010000, 0x1010 -> picture flowed over back to screen
Pokitto 46:e7e438368e16 212
Pokitto 46:e7e438368e16 213
Pokitto 46:e7e438368e16 214 write_command(0x08); // Display control 2
Pokitto 46:e7e438368e16 215 write_data(0x0808); // 100000001000 FP2,BP2
Pokitto 46:e7e438368e16 216
Pokitto 46:e7e438368e16 217 write_command(0x0C); // RGB display interface
Pokitto 46:e7e438368e16 218 write_data(0x0000); // all off
Pokitto 46:e7e438368e16 219
Pokitto 46:e7e438368e16 220 write_command(0x0F); // Frame marker position
Pokitto 46:e7e438368e16 221 write_data(0x0001); // OSC_EN
Pokitto 46:e7e438368e16 222
Pokitto 46:e7e438368e16 223 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 224 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 225
Pokitto 46:e7e438368e16 226 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 227 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 228
Pokitto 46:e7e438368e16 229 //*************Power On sequence ****************//
Pokitto 46:e7e438368e16 230 write_command(0x10);
Pokitto 46:e7e438368e16 231 write_data(0x0000);
Pokitto 46:e7e438368e16 232
Pokitto 46:e7e438368e16 233 write_command(0x11);
Pokitto 46:e7e438368e16 234 write_data(0x1000);
Pokitto 46:e7e438368e16 235 wait_ms(10);
Pokitto 46:e7e438368e16 236 //------------------------ Set GRAM area --------------------------------//
Pokitto 46:e7e438368e16 237 write_command(0x30); // Gate scan position
Pokitto 46:e7e438368e16 238 write_data(0x0000); // if GS=0, 00h=G1, else 00h=G220
Pokitto 46:e7e438368e16 239
Pokitto 46:e7e438368e16 240 write_command(0x31); // Vertical scroll control
Pokitto 46:e7e438368e16 241 write_data(0x00DB); // scroll start line 11011011 = 219
Pokitto 46:e7e438368e16 242
Pokitto 46:e7e438368e16 243 write_command(0x32); // Vertical scroll control
Pokitto 46:e7e438368e16 244 write_data(0x0000); // scroll end line 0
Pokitto 46:e7e438368e16 245
Pokitto 46:e7e438368e16 246 write_command(0x33); // Vertical scroll control
Pokitto 46:e7e438368e16 247 write_data(0x0000); // 0=vertical scroll disabled
Pokitto 46:e7e438368e16 248
Pokitto 46:e7e438368e16 249 write_command(0x34); // Partial screen driving control
Pokitto 46:e7e438368e16 250 write_data(0x00DB); // db = full screen (end)
Pokitto 46:e7e438368e16 251
Pokitto 46:e7e438368e16 252 write_command(0x35); // partial screen
Pokitto 46:e7e438368e16 253 write_data(0x0000); // 0 = start
Pokitto 46:e7e438368e16 254
Pokitto 46:e7e438368e16 255 write_command(0x36); // Horizontal and vertical RAM position
Pokitto 46:e7e438368e16 256 write_data(0x00AF); //end address 175
Pokitto 46:e7e438368e16 257
Pokitto 46:e7e438368e16 258 write_command(0x37);
Pokitto 46:e7e438368e16 259 write_data(0x0000); // start address 0
Pokitto 46:e7e438368e16 260
Pokitto 46:e7e438368e16 261 write_command(0x38);
Pokitto 46:e7e438368e16 262 write_data(0x00DB); //end address 219
Pokitto 46:e7e438368e16 263
Pokitto 46:e7e438368e16 264 write_command(0x39); // start address 0
Pokitto 46:e7e438368e16 265 write_data(0x0000);
Pokitto 46:e7e438368e16 266 wait_ms(10);
Pokitto 46:e7e438368e16 267 write_command(0xff); // start gamma register control
Pokitto 46:e7e438368e16 268 write_data(0x0003);
Pokitto 46:e7e438368e16 269
Pokitto 46:e7e438368e16 270 // ----------- Adjust the Gamma Curve ----------//
Pokitto 46:e7e438368e16 271 write_command(0x50);
Pokitto 46:e7e438368e16 272 write_data(0x0203);
Pokitto 46:e7e438368e16 273
Pokitto 46:e7e438368e16 274 write_command(0x051);
Pokitto 46:e7e438368e16 275 write_data(0x0A09);
Pokitto 46:e7e438368e16 276
Pokitto 46:e7e438368e16 277 write_command(0x52);
Pokitto 46:e7e438368e16 278 write_data(0x0005);
Pokitto 46:e7e438368e16 279
Pokitto 46:e7e438368e16 280 write_command(0x53);
Pokitto 46:e7e438368e16 281 write_data(0x1021);
Pokitto 46:e7e438368e16 282
Pokitto 46:e7e438368e16 283 write_command(0x54);
Pokitto 46:e7e438368e16 284 write_data(0x0602);
Pokitto 46:e7e438368e16 285
Pokitto 46:e7e438368e16 286 write_command(0x55);
Pokitto 46:e7e438368e16 287 write_data(0x0003);
Pokitto 46:e7e438368e16 288
Pokitto 46:e7e438368e16 289 write_command(0x56);
Pokitto 46:e7e438368e16 290 write_data(0x0703);
Pokitto 46:e7e438368e16 291
Pokitto 46:e7e438368e16 292 write_command(0x57);
Pokitto 46:e7e438368e16 293 write_data(0x0507);
Pokitto 46:e7e438368e16 294
Pokitto 46:e7e438368e16 295 write_command(0x58);
Pokitto 46:e7e438368e16 296 write_data(0x1021);
Pokitto 46:e7e438368e16 297
Pokitto 46:e7e438368e16 298 write_command(0x59);
Pokitto 46:e7e438368e16 299 write_data(0x0703);
Pokitto 46:e7e438368e16 300
Pokitto 46:e7e438368e16 301 write_command(0xB0);
Pokitto 46:e7e438368e16 302 write_data(0x2501);
Pokitto 46:e7e438368e16 303
Pokitto 46:e7e438368e16 304 write_command(0xFF);
Pokitto 46:e7e438368e16 305 write_data(0x0000);
Pokitto 46:e7e438368e16 306
Pokitto 46:e7e438368e16 307 write_command(0x07);
Pokitto 46:e7e438368e16 308 write_data(0x1017);
Pokitto 46:e7e438368e16 309 wait_ms(200);
Pokitto 46:e7e438368e16 310 write_command(0x22);
Pokitto 46:e7e438368e16 311
Pokitto 46:e7e438368e16 312 lcdClear();
Pokitto 46:e7e438368e16 313 }
Pokitto 46:e7e438368e16 314
Pokitto 46:e7e438368e16 315 void Pokitto::lcdSleep(void){
Pokitto 46:e7e438368e16 316 write_command(0xFF);
Pokitto 46:e7e438368e16 317 write_data(0x0000);
Pokitto 46:e7e438368e16 318
Pokitto 46:e7e438368e16 319 write_command(0x07);
Pokitto 46:e7e438368e16 320 write_data(0x0000);
Pokitto 46:e7e438368e16 321 wait_ms(50);
Pokitto 46:e7e438368e16 322 write_command(0x10);// Enter Standby mode
Pokitto 46:e7e438368e16 323 write_data(0x0003);
Pokitto 46:e7e438368e16 324 wait_ms(200);
Pokitto 46:e7e438368e16 325
Pokitto 46:e7e438368e16 326 }
Pokitto 46:e7e438368e16 327
Pokitto 46:e7e438368e16 328 void Pokitto::lcdWakeUp (void){
Pokitto 46:e7e438368e16 329
Pokitto 46:e7e438368e16 330 wait_ms(200);
Pokitto 46:e7e438368e16 331 write_command(0xFF);
Pokitto 46:e7e438368e16 332 write_data(0x0000);
Pokitto 46:e7e438368e16 333
Pokitto 46:e7e438368e16 334 write_command(0x10);// Exit Sleep/ Standby mode
Pokitto 46:e7e438368e16 335 write_data(0x0000);
Pokitto 46:e7e438368e16 336 wait_ms(50);
Pokitto 46:e7e438368e16 337 write_command(0x07);
Pokitto 46:e7e438368e16 338 write_data(0x0117);
Pokitto 46:e7e438368e16 339 wait_ms(200);
Pokitto 46:e7e438368e16 340 }
Pokitto 46:e7e438368e16 341
Pokitto 46:e7e438368e16 342 void Pokitto::lcdFillSurface(uint16_t c) {
Pokitto 46:e7e438368e16 343 uint32_t i;
Pokitto 46:e7e438368e16 344 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 345 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 346 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 347 write_data(0);
Pokitto 46:e7e438368e16 348 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 349 setup_data_16(c);
Pokitto 46:e7e438368e16 350 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 351 for(i=0;i<220*176;i++)
Pokitto 46:e7e438368e16 352 {
Pokitto 46:e7e438368e16 353 CLR_WR;
Pokitto 46:e7e438368e16 354 SET_WR;
Pokitto 46:e7e438368e16 355 }
Pokitto 46:e7e438368e16 356 }
Pokitto 46:e7e438368e16 357
Pokitto 46:e7e438368e16 358 void Pokitto::lcdClear() {
Pokitto 46:e7e438368e16 359 uint32_t i;
Pokitto 46:e7e438368e16 360 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 361 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 362 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 363 write_data(0);
Pokitto 46:e7e438368e16 364 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 365 setup_data_16(0x0000);
Pokitto 46:e7e438368e16 366 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 367 for(i=0;i<220*176;i++)
Pokitto 46:e7e438368e16 368 {
Pokitto 46:e7e438368e16 369 CLR_WR;
Pokitto 46:e7e438368e16 370 SET_WR;
Pokitto 46:e7e438368e16 371 }
Pokitto 46:e7e438368e16 372 }
Pokitto 46:e7e438368e16 373
Pokitto 46:e7e438368e16 374 void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 46:e7e438368e16 375 if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
Pokitto 46:e7e438368e16 376 return;
Pokitto 46:e7e438368e16 377 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 378 write_data(y); // 0
Pokitto 46:e7e438368e16 379 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 380 write_data(x);
Pokitto 46:e7e438368e16 381 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 382 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 383 setup_data_16(color);
Pokitto 46:e7e438368e16 384 CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 385 }
Pokitto 46:e7e438368e16 386
Pokitto 46:e7e438368e16 387 void Pokitto::setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
Pokitto 46:e7e438368e16 388 write_command(0x37); write_data(x1);
Pokitto 46:e7e438368e16 389 write_command(0x36); write_data(x2);
Pokitto 46:e7e438368e16 390 write_command(0x39); write_data(y1);
Pokitto 46:e7e438368e16 391 write_command(0x38); write_data(y2);
Pokitto 46:e7e438368e16 392 write_command(0x20); write_data(x1);
Pokitto 46:e7e438368e16 393 write_command(0x21); write_data(y1);
Pokitto 46:e7e438368e16 394 }
Pokitto 46:e7e438368e16 395
Pokitto 46:e7e438368e16 396 void Pokitto::lcdTile(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t* gfx){
Pokitto 46:e7e438368e16 397 int width=x1-x0;
Pokitto 46:e7e438368e16 398 int height=y1-y0;
Pokitto 46:e7e438368e16 399 if (x0 > POK_LCD_W) return;
Pokitto 46:e7e438368e16 400 if (y0 > POK_LCD_H) return;
Pokitto 46:e7e438368e16 401 if (x0 < 0) x0=0;
Pokitto 46:e7e438368e16 402 if (y0 < 0) y0=0;
Pokitto 46:e7e438368e16 403
Pokitto 46:e7e438368e16 404 setWindow(y0, x0, y1-1, x1-1);
Pokitto 46:e7e438368e16 405 write_command(0x22);
Pokitto 46:e7e438368e16 406
Pokitto 46:e7e438368e16 407 for (int x=0; x<=width*height-1;x++) {
Pokitto 46:e7e438368e16 408 write_data(gfx[x]);
Pokitto 46:e7e438368e16 409 }
Pokitto 46:e7e438368e16 410 setWindow(0, 0, 175, 219);
Pokitto 46:e7e438368e16 411 }
Pokitto 46:e7e438368e16 412
Pokitto 46:e7e438368e16 413
Pokitto 46:e7e438368e16 414 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 46:e7e438368e16 415 int16_t temp;
Pokitto 46:e7e438368e16 416 if (x0>x1) {temp=x0;x0=x1;x1=temp;}
Pokitto 46:e7e438368e16 417 if (y0>y1) {temp=y0;y0=y1;y1=temp;}
Pokitto 46:e7e438368e16 418 if (x0 > POK_LCD_W) return;
Pokitto 46:e7e438368e16 419 if (y0 > POK_LCD_H) return;
Pokitto 46:e7e438368e16 420 if (x1 > POK_LCD_W) x1=POK_LCD_W;
Pokitto 46:e7e438368e16 421 if (y1 > POK_LCD_H) y1=POK_LCD_H;
Pokitto 46:e7e438368e16 422 if (x0 < 0) x0=0;
Pokitto 46:e7e438368e16 423 if (y0 < 0) y0=0;
Pokitto 46:e7e438368e16 424
Pokitto 46:e7e438368e16 425 int16_t x,y;
Pokitto 46:e7e438368e16 426 for (x=x0; x<=x1;x++) {
Pokitto 46:e7e438368e16 427 write_command(0x20); // Horizontal DRAM Address (=y on pokitto screen)
Pokitto 46:e7e438368e16 428 write_data(y0);
Pokitto 46:e7e438368e16 429 write_command(0x21); // Vertical DRAM Address (=x on pokitto screen)
Pokitto 46:e7e438368e16 430 write_data(x);
Pokitto 46:e7e438368e16 431 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 432
Pokitto 46:e7e438368e16 433 CLR_CS_SET_CD_RD_WR; // go to vram write mode
Pokitto 46:e7e438368e16 434
Pokitto 46:e7e438368e16 435
Pokitto 46:e7e438368e16 436 for (y=y0; y<y1;y++) {
Pokitto 46:e7e438368e16 437 setup_data_16(color); // setup the data (flat color = no change between pixels)
Pokitto 46:e7e438368e16 438 CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
Pokitto 46:e7e438368e16 439 }
Pokitto 46:e7e438368e16 440 }
Pokitto 46:e7e438368e16 441 }
Pokitto 46:e7e438368e16 442
Pokitto 46:e7e438368e16 443 /***
Pokitto 46:e7e438368e16 444 * Update the screen buffer of 220x176 pixels, 4 colors to LCD.
Pokitto 46:e7e438368e16 445 *
Pokitto 46:e7e438368e16 446 * The update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations, the
Pokitto 46:e7e438368e16 447 * x, y, and width of the update rect must be dividable by 4 pixels, and the height must be dividable by 8 pixels.
Pokitto 46:e7e438368e16 448 * Note: The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 46:e7e438368e16 449 * @param scrbuf The screen buffer.
Pokitto 46:e7e438368e16 450 * @param updRectX The update rect.
Pokitto 46:e7e438368e16 451 * @param updRectY The update rect.
Pokitto 46:e7e438368e16 452 * @param updRectW The update rect.
Pokitto 46:e7e438368e16 453 * @param updRectH The update rect.
Pokitto 46:e7e438368e16 454 * @param paletteptr The screen palette.
Pokitto 46:e7e438368e16 455 */
Pokitto 65:deed4aa606fb 456
Pokitto 65:deed4aa606fb 457
Pokitto 65:deed4aa606fb 458 #define MODE1_LOOP \
Pokitto 65:deed4aa606fb 459 " adds %[t], %[palette]" "\n" \
Pokitto 65:deed4aa606fb 460 " ldm %[t], {%[t], %[x]}" "\n" \
Pokitto 65:deed4aa606fb 461 " str %[t], [%[LCD], 0]" "\n" \
Pokitto 65:deed4aa606fb 462 " movs %[t], 252" "\n" \
Pokitto 65:deed4aa606fb 463 " str %[WRBit], [%[LCD], %[t]]" "\n" \
Pokitto 65:deed4aa606fb 464 " str %[WRBit], [%[LCD], 124]" "\n" \
Pokitto 65:deed4aa606fb 465 " str %[x], [%[LCD], 0]" "\n" \
Pokitto 65:deed4aa606fb 466 " str %[WRBit], [%[LCD], %[t]]" "\n" \
Pokitto 65:deed4aa606fb 467 " movs %[t], 0x0F" "\n" \
Pokitto 65:deed4aa606fb 468 " ands %[t], %[t], %[c]" "\n" \
Pokitto 65:deed4aa606fb 469 " str %[WRBit], [%[LCD], 124]" "\n" \
Pokitto 65:deed4aa606fb 470 \
Pokitto 65:deed4aa606fb 471 " lsls %[t], 3" "\n" \
Pokitto 65:deed4aa606fb 472 " adds %[t], %[palette]" "\n" \
Pokitto 65:deed4aa606fb 473 " ldm %[t], {%[t], %[x]}" "\n" \
Pokitto 65:deed4aa606fb 474 " str %[t], [%[LCD], 0]" "\n" \
Pokitto 65:deed4aa606fb 475 " movs %[t], 252" "\n" \
Pokitto 65:deed4aa606fb 476 " str %[WRBit], [%[LCD], %[t]]" "\n" \
Pokitto 65:deed4aa606fb 477 " str %[WRBit], [%[LCD], 124]" "\n" \
Pokitto 65:deed4aa606fb 478 " str %[x], [%[LCD], 0]" "\n" \
Pokitto 65:deed4aa606fb 479 " str %[WRBit], [%[LCD], %[t]]" "\n" \
Pokitto 65:deed4aa606fb 480 " lsrs %[c], 8" "\n" \
Pokitto 65:deed4aa606fb 481 " movs %[t], 0xF0" "\n" \
Pokitto 65:deed4aa606fb 482 " ands %[t], %[t], %[c]" "\n" \
Pokitto 65:deed4aa606fb 483 " lsrs %[t], %[t], 1" "\n" \
Pokitto 65:deed4aa606fb 484 " str %[WRBit], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 485
Pokitto 65:deed4aa606fb 486
Pokitto 46:e7e438368e16 487 void Pokitto::lcdRefreshMode1(uint8_t * scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 488
Pokitto 65:deed4aa606fb 489
Pokitto 65:deed4aa606fb 490 #ifdef XPERIMENTAL
Pokitto 65:deed4aa606fb 491 //#define __ARMCC_VERSION 1
Pokitto 65:deed4aa606fb 492 #endif
Pokitto 65:deed4aa606fb 493
Pokitto 65:deed4aa606fb 494 #ifndef __ARMCC_VERSION
Pokitto 65:deed4aa606fb 495
Pokitto 65:deed4aa606fb 496 write_command(0x03); write_data(0x1038);
Pokitto 65:deed4aa606fb 497 write_command(0x20); // Horizontal DRAM Address
Pokitto 65:deed4aa606fb 498 write_data(0);
Pokitto 65:deed4aa606fb 499 write_command(0x21); // Vertical DRAM Address
Pokitto 65:deed4aa606fb 500 write_data(0);
Pokitto 65:deed4aa606fb 501 write_command(0x22); // write data to DRAM
Pokitto 65:deed4aa606fb 502 CLR_CS_SET_CD_RD_WR;
Pokitto 65:deed4aa606fb 503
Pokitto 65:deed4aa606fb 504 uint8_t *end=&scrbuf[POK_SCREENBUFFERSIZE>>1]+4;
Pokitto 65:deed4aa606fb 505
Pokitto 65:deed4aa606fb 506 volatile uint32_t palette[32];
Pokitto 65:deed4aa606fb 507 for( uint32_t i=0; i<16; ++i ){
Pokitto 65:deed4aa606fb 508 palette[(i<<1)+1] = static_cast<uint32_t>(paletteptr[i&3 ]) << 3;
Pokitto 65:deed4aa606fb 509 palette[(i<<1) ] = static_cast<uint32_t>(paletteptr[i>>2]) << 3;
Pokitto 65:deed4aa606fb 510 }
Pokitto 65:deed4aa606fb 511
Pokitto 65:deed4aa606fb 512 SET_MASK_P2;
Pokitto 65:deed4aa606fb 513
Pokitto 65:deed4aa606fb 514 uint32_t c, WRBit = 1<<12;
Pokitto 65:deed4aa606fb 515
Pokitto 65:deed4aa606fb 516 register uint32_t x asm("r2");
Pokitto 65:deed4aa606fb 517 register uint32_t t asm("r1");
Pokitto 65:deed4aa606fb 518
Pokitto 65:deed4aa606fb 519 asm volatile(
Pokitto 65:deed4aa606fb 520
Pokitto 65:deed4aa606fb 521 ".syntax unified" "\n"
Pokitto 65:deed4aa606fb 522 "ldm %[scrbuf]!, {%[c]}" "\n" // load 4 bytes (16 pixels)
Pokitto 65:deed4aa606fb 523 "movs %[t], 0xF0" "\n"
Pokitto 65:deed4aa606fb 524 "ands %[t], %[t], %[c]" "\n"
Pokitto 65:deed4aa606fb 525 "lsrs %[t], %[t], 1" "\n"
Pokitto 65:deed4aa606fb 526 "mode1Loop%=:" "\n"
Pokitto 65:deed4aa606fb 527 MODE1_LOOP
Pokitto 65:deed4aa606fb 528 MODE1_LOOP
Pokitto 65:deed4aa606fb 529 MODE1_LOOP
Pokitto 65:deed4aa606fb 530 " adds %[t], %[palette]" "\n"
Pokitto 65:deed4aa606fb 531 " ldm %[t], {%[t], %[x]}" "\n"
Pokitto 65:deed4aa606fb 532 " str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 533 " movs %[t], 252" "\n"
Pokitto 65:deed4aa606fb 534 " str %[WRBit], [%[LCD], %[t]]" "\n"
Pokitto 65:deed4aa606fb 535 " str %[WRBit], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 536 " str %[x], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 537 " str %[WRBit], [%[LCD], %[t]]" "\n"
Pokitto 65:deed4aa606fb 538 " movs %[t], 0x0F" "\n"
Pokitto 65:deed4aa606fb 539 " ands %[t], %[t], %[c]" "\n"
Pokitto 65:deed4aa606fb 540 " str %[WRBit], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 541
Pokitto 65:deed4aa606fb 542 " lsls %[t], 3" "\n"
Pokitto 65:deed4aa606fb 543 " adds %[t], %[palette]" "\n"
Pokitto 65:deed4aa606fb 544 " ldm %[t], {%[t], %[x]}" "\n"
Pokitto 65:deed4aa606fb 545 " str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 546 " movs %[t], 252" "\n"
Pokitto 65:deed4aa606fb 547 " str %[WRBit], [%[LCD], %[t]]" "\n"
Pokitto 65:deed4aa606fb 548 " str %[WRBit], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 549 " str %[x], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 550 " str %[WRBit], [%[LCD], %[t]]" "\n"
Pokitto 65:deed4aa606fb 551
Pokitto 65:deed4aa606fb 552 " ldm %[scrbuf]!, {%[c]}" "\n" // load next 4 bytes
Pokitto 65:deed4aa606fb 553 " movs %[t], 0xF0" "\n"
Pokitto 65:deed4aa606fb 554 " ands %[t], %[t], %[c]" "\n"
Pokitto 65:deed4aa606fb 555 " lsrs %[t], %[t], 1" "\n"
Pokitto 65:deed4aa606fb 556 " str %[WRBit], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 557
Pokitto 65:deed4aa606fb 558 "cmp %[end], %[scrbuf]" "\n"
Pokitto 65:deed4aa606fb 559 "bne mode1Loop%=" "\n" // if scrbuf < end, loop
Pokitto 65:deed4aa606fb 560
Pokitto 65:deed4aa606fb 561 : // outputs
Pokitto 65:deed4aa606fb 562 [c]"+l" (c),
Pokitto 65:deed4aa606fb 563 [t]"+l" (t),
Pokitto 65:deed4aa606fb 564 [end]"+h" (end),
Pokitto 65:deed4aa606fb 565 [scrbuf]"+l" (scrbuf),
Pokitto 65:deed4aa606fb 566 [WRBit]"+l" (WRBit),
Pokitto 65:deed4aa606fb 567 [x]"+l" (x)
Pokitto 65:deed4aa606fb 568
Pokitto 65:deed4aa606fb 569 : // inputs
Pokitto 65:deed4aa606fb 570 [LCD]"l" (0xA0002188),
Pokitto 65:deed4aa606fb 571 [palette]"l" (palette)
Pokitto 65:deed4aa606fb 572
Pokitto 65:deed4aa606fb 573 : // clobbers
Pokitto 65:deed4aa606fb 574 "cc"
Pokitto 65:deed4aa606fb 575 );
Pokitto 65:deed4aa606fb 576
Pokitto 65:deed4aa606fb 577
Pokitto 65:deed4aa606fb 578 #else
Pokitto 65:deed4aa606fb 579 uint16_t x,y,xptr;
Pokitto 46:e7e438368e16 580 uint16_t scanline[4][176]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 65:deed4aa606fb 581 uint8_t *d, yoffset=0;
Pokitto 46:e7e438368e16 582
Pokitto 46:e7e438368e16 583 // If not the full screen is updated, check the validity of the update rect.
Pokitto 46:e7e438368e16 584 if ( updRectX != 0 || updRectY != 0 ||updRectW != LCDWIDTH ||updRectH != LCDHEIGHT ) {
Pokitto 46:e7e438368e16 585 uint8_t org_screenx = updRectX;
Pokitto 46:e7e438368e16 586 updRectX &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 587 updRectW += org_screenx - updRectX;
Pokitto 46:e7e438368e16 588 updRectW = (updRectW + 3) & 0xfc; // Make the value dividable by 4, round up.
Pokitto 46:e7e438368e16 589
Pokitto 46:e7e438368e16 590 uint8_t org_screeny = updRectY;
Pokitto 46:e7e438368e16 591 updRectY &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 592 updRectH += org_screeny - updRectY;
Pokitto 46:e7e438368e16 593 updRectH = (updRectH + 7) & 0xf8; // Make the value dividable by 8 (because of loop unroll optimization), round up.
Pokitto 46:e7e438368e16 594 }
Pokitto 46:e7e438368e16 595
Pokitto 46:e7e438368e16 596
Pokitto 46:e7e438368e16 597 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 598 xptr = 8;
Pokitto 46:e7e438368e16 599 setDRAMptr(8, 0);
Pokitto 46:e7e438368e16 600 #else
Pokitto 65:deed4aa606fb 601 xptr = 0;
Pokitto 46:e7e438368e16 602 setDRAMptr(0, 0);
Pokitto 46:e7e438368e16 603 #endif
Pokitto 46:e7e438368e16 604
Pokitto 46:e7e438368e16 605 for (x=updRectX; x<updRectX+updRectW; x+=4) {
Pokitto 46:e7e438368e16 606 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 607
Pokitto 46:e7e438368e16 608 /** find colours in one scanline **/
Pokitto 65:deed4aa606fb 609 uint8_t s=0;
Pokitto 46:e7e438368e16 610 d += (updRectY * 220/4);
Pokitto 46:e7e438368e16 611 for (y=updRectY; y<updRectY+updRectH; y++) {
Pokitto 46:e7e438368e16 612 uint8_t tdata = *d;
Pokitto 46:e7e438368e16 613 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 614 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 615 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 616 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 617
Pokitto 46:e7e438368e16 618 /** put nibble values in the scanlines **/
Pokitto 46:e7e438368e16 619 scanline[0][y] = paletteptr[t];
Pokitto 46:e7e438368e16 620 scanline[1][y] = paletteptr[t2];
Pokitto 46:e7e438368e16 621 scanline[2][y] = paletteptr[t3];
Pokitto 46:e7e438368e16 622 scanline[3][y] = paletteptr[t4];
Pokitto 46:e7e438368e16 623
Pokitto 46:e7e438368e16 624 d += 220/4; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 625 }
Pokitto 46:e7e438368e16 626
Pokitto 46:e7e438368e16 627 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 628 if (x>=8 ) {
Pokitto 46:e7e438368e16 629 #else
Pokitto 46:e7e438368e16 630 {
Pokitto 46:e7e438368e16 631
Pokitto 46:e7e438368e16 632 #endif
Pokitto 46:e7e438368e16 633
Pokitto 46:e7e438368e16 634 // Draw 8 vertical pixels at a time for performance reasons
Pokitto 46:e7e438368e16 635 setDRAMptr(x, updRectY);
Pokitto 46:e7e438368e16 636 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 637 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 638 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 639 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 640 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 641 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 642 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 643 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 644 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 645 }
Pokitto 46:e7e438368e16 646 setDRAMptr(x+1, updRectY);
Pokitto 46:e7e438368e16 647 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 648 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 649 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 650 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 651 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 652 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 653 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 654 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 655 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 656 }
Pokitto 46:e7e438368e16 657 setDRAMptr(x+2, updRectY);
Pokitto 46:e7e438368e16 658 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 659 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 660 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 661 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 662 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 663 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 664 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 665 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 666 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 667 }
Pokitto 46:e7e438368e16 668 setDRAMptr(x+3, updRectY);
Pokitto 46:e7e438368e16 669 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 670 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 671 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 672 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 673 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 674 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 675 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 676 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 677 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 678 }
Pokitto 46:e7e438368e16 679 }
Pokitto 46:e7e438368e16 680 }
Pokitto 65:deed4aa606fb 681 #endif
Pokitto 46:e7e438368e16 682
Pokitto 46:e7e438368e16 683 #ifdef POK_SIM
Pokitto 46:e7e438368e16 684 simulator.refreshDisplay();
Pokitto 46:e7e438368e16 685 #endif
Pokitto 46:e7e438368e16 686 }
Pokitto 46:e7e438368e16 687
Pokitto 46:e7e438368e16 688 // Copy sprite pixels to the scanline
Pokitto 46:e7e438368e16 689 #define SPRITE_2BPP_INNER_LOOP(n)\
Pokitto 46:e7e438368e16 690 \
Pokitto 46:e7e438368e16 691 /* If the sprite is enabled and contained in this vertical scanline, copy 4 pixels. */\
Pokitto 46:e7e438368e16 692 if (sprScanlineAddr[(n)] &&\
Pokitto 46:e7e438368e16 693 y >= sprites[(n)].y && y < sprites[(n)].y + sprites[(n)].h ) {\
Pokitto 46:e7e438368e16 694 \
Pokitto 46:e7e438368e16 695 int16_t sprx = sprites[(n)].x;\
Pokitto 46:e7e438368e16 696 uint16_t s_data16b = 0; /* sprite data, 2 bytes */\
Pokitto 46:e7e438368e16 697 \
Pokitto 46:e7e438368e16 698 /* Get pixel block, 4 or 8 pixels horizontally. Use the predefined bitshift mode. */\
Pokitto 46:e7e438368e16 699 /* Note:it is cheapest to compare to 0 first. */\
Pokitto 46:e7e438368e16 700 if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_MIDDLE_BYTE) {\
Pokitto 46:e7e438368e16 701 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 46:e7e438368e16 702 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 46:e7e438368e16 703 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 46:e7e438368e16 704 }\
Pokitto 46:e7e438368e16 705 else if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_FIRST_BYTE) {\
Pokitto 46:e7e438368e16 706 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 46:e7e438368e16 707 }\
Pokitto 46:e7e438368e16 708 else { /* BITSHIFT_MODE_LAST_BYTE */\
Pokitto 46:e7e438368e16 709 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 46:e7e438368e16 710 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 46:e7e438368e16 711 }\
Pokitto 46:e7e438368e16 712 \
Pokitto 46:e7e438368e16 713 /* Shift sprite pixels according to sprite x. After shifting we have only 4 pixels. */\
Pokitto 46:e7e438368e16 714 uint8_t shiftRight = (sprx&0x3) << 1;\
Pokitto 46:e7e438368e16 715 s_data16b = (s_data16b >> shiftRight);\
Pokitto 46:e7e438368e16 716 \
Pokitto 46:e7e438368e16 717 /* Get individual pixels */\
Pokitto 46:e7e438368e16 718 uint8_t s_t4 = s_data16b & 0x03; s_data16b >>= 2; /* lowest half-nibble */\
Pokitto 46:e7e438368e16 719 uint8_t s_t3 = s_data16b & 0x03; s_data16b >>= 2; /* second lowest half-nibble */\
Pokitto 46:e7e438368e16 720 uint8_t s_t2 = s_data16b & 0x03; s_data16b >>= 2; /* second highest half-nibble */\
Pokitto 46:e7e438368e16 721 uint8_t s_t1 = s_data16b & 0x03; /* highest half-nibble */\
Pokitto 46:e7e438368e16 722 \
Pokitto 46:e7e438368e16 723 /* Store pixels as 16-bit colors from the palette */\
Pokitto 46:e7e438368e16 724 if (s_t4 != transparentColor) p4 = sprites[(n)].palette[s_t4];\
Pokitto 46:e7e438368e16 725 if (s_t3 != transparentColor) p3 = sprites[(n)].palette[s_t3];\
Pokitto 46:e7e438368e16 726 if (s_t2 != transparentColor) p2 = sprites[(n)].palette[s_t2];\
Pokitto 46:e7e438368e16 727 if (s_t1 != transparentColor) p = sprites[(n)].palette[s_t1];\
Pokitto 46:e7e438368e16 728 \
Pokitto 46:e7e438368e16 729 /* Advance scanline address */\
Pokitto 46:e7e438368e16 730 sprScanlineAddr[(n)] += (sprites[(n)].w >> 2);\
Pokitto 46:e7e438368e16 731 }
Pokitto 46:e7e438368e16 732
Pokitto 46:e7e438368e16 733 // Loop unrolling macros
Pokitto 46:e7e438368e16 734 #define UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(0)
Pokitto 46:e7e438368e16 735 #define UNROLLED_LOOP_2() UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(1)
Pokitto 46:e7e438368e16 736 #define UNROLLED_LOOP_3() UNROLLED_LOOP_2() SPRITE_2BPP_INNER_LOOP(2)
Pokitto 46:e7e438368e16 737 #define UNROLLED_LOOP_4() UNROLLED_LOOP_3() SPRITE_2BPP_INNER_LOOP(3)
Pokitto 46:e7e438368e16 738 #define UNROLLED_LOOP_5() UNROLLED_LOOP_4() SPRITE_2BPP_INNER_LOOP(4)
Pokitto 46:e7e438368e16 739 #define UNROLLED_LOOP_6() UNROLLED_LOOP_5() SPRITE_2BPP_INNER_LOOP(5)
Pokitto 46:e7e438368e16 740 #define UNROLLED_LOOP_7() UNROLLED_LOOP_6() SPRITE_2BPP_INNER_LOOP(6)
Pokitto 46:e7e438368e16 741 #define UNROLLED_LOOP_8() UNROLLED_LOOP_7() SPRITE_2BPP_INNER_LOOP(7)
Pokitto 46:e7e438368e16 742 #define UNROLLED_LOOP_9() UNROLLED_LOOP_8() SPRITE_2BPP_INNER_LOOP(8)
Pokitto 46:e7e438368e16 743 #define UNROLLED_LOOP_10() UNROLLED_LOOP_9() SPRITE_2BPP_INNER_LOOP(9)
Pokitto 46:e7e438368e16 744 #define UNROLLED_LOOP_11() UNROLLED_LOOP_10() SPRITE_2BPP_INNER_LOOP(10)
Pokitto 46:e7e438368e16 745 #define UNROLLED_LOOP_12() UNROLLED_LOOP_11() SPRITE_2BPP_INNER_LOOP(11)
Pokitto 46:e7e438368e16 746 #define UNROLLED_LOOP_13() UNROLLED_LOOP_12() SPRITE_2BPP_INNER_LOOP(12)
Pokitto 46:e7e438368e16 747 #define UNROLLED_LOOP_14() UNROLLED_LOOP_13() SPRITE_2BPP_INNER_LOOP(13)
Pokitto 46:e7e438368e16 748 #define UNROLLED_LOOP_15() UNROLLED_LOOP_14() SPRITE_2BPP_INNER_LOOP(14)
Pokitto 46:e7e438368e16 749 #define UNROLLED_LOOP_16() UNROLLED_LOOP_15() SPRITE_2BPP_INNER_LOOP(15)
Pokitto 46:e7e438368e16 750 #define UNROLLED_LOOP_N_(n) UNROLLED_LOOP_##n()
Pokitto 46:e7e438368e16 751 #define UNROLLED_LOOP_N(n) UNROLLED_LOOP_N_(n)
Pokitto 46:e7e438368e16 752
Pokitto 46:e7e438368e16 753 /***
Pokitto 46:e7e438368e16 754 * Update the screen buffer of 220x176 pixels, 4 colors and free size 4 color sprites to LCD.
Pokitto 46:e7e438368e16 755 *
Pokitto 46:e7e438368e16 756 * The update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations, the
Pokitto 46:e7e438368e16 757 * x, y, and width of the update rect must be dividable by 4 pixels, and the height must be dividable by 8 pixels.
Pokitto 46:e7e438368e16 758 * Note: The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 46:e7e438368e16 759 * If drawSpritesOnly=true, only sprites are fully updated to LCD. However, the dirty rect of the screen buffer is
Pokitto 46:e7e438368e16 760 * drawn behind the sprite current and previous location.
Pokitto 46:e7e438368e16 761 * Note: Sprite is enabled if sprite.bitmapData is not NULL. Also all enabled sprites must be at the beginning of
Pokitto 46:e7e438368e16 762 * the sprites array. No gaps are allowed in the array.
Pokitto 46:e7e438368e16 763 * @param scrbuf The screen buffer.
Pokitto 46:e7e438368e16 764 * @param updRectX The update rect.
Pokitto 46:e7e438368e16 765 * @param updRectY The update rect.
Pokitto 46:e7e438368e16 766 * @param updRectW The update rect.
Pokitto 46:e7e438368e16 767 * @param updRectH The update rect.
Pokitto 46:e7e438368e16 768 * @param paletteptr The screen palette.
Pokitto 46:e7e438368e16 769 * @param sprites The sprite array.
Pokitto 46:e7e438368e16 770 * @param drawSpritesOnly True, if only sprites are drawn. False, if both sprites and the screen buffer are drawn.
Pokitto 46:e7e438368e16 771 */
Pokitto 46:e7e438368e16 772 void Pokitto::lcdRefreshMode1Spr(
Pokitto 46:e7e438368e16 773 uint8_t * scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr,
Pokitto 46:e7e438368e16 774 SpriteInfo* sprites, bool drawSpritesOnly) {
Pokitto 46:e7e438368e16 775
Pokitto 46:e7e438368e16 776 // In direct mode draw only sprites and their dirty rects. Return now if there are no sprites
Pokitto 46:e7e438368e16 777 if (drawSpritesOnly && (sprites == NULL || sprites[0].bitmapData == NULL))
Pokitto 46:e7e438368e16 778 return;
Pokitto 46:e7e438368e16 779
Pokitto 46:e7e438368e16 780 uint16_t x,y;
Pokitto 46:e7e438368e16 781 uint16_t scanline[4][176]; // read 4 half-nibbles (= 4 pixels) at a time
Pokitto 46:e7e438368e16 782 const uint8_t transparentColor = 0; // fixed palette index 0 for transparency
Pokitto 46:e7e438368e16 783
Pokitto 46:e7e438368e16 784 // If not the full screen is updated, check the validity of the update rect.
Pokitto 46:e7e438368e16 785 if ( updRectX != 0 || updRectY != 0 ||updRectW != LCDWIDTH ||updRectH != LCDHEIGHT ) {
Pokitto 46:e7e438368e16 786 uint8_t org_screenx = updRectX;
Pokitto 46:e7e438368e16 787 updRectX &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 788 updRectW += org_screenx - updRectX;
Pokitto 46:e7e438368e16 789 updRectW = (updRectW + 3) & 0xfc; // Make the value dividable by 4, round up.
Pokitto 46:e7e438368e16 790
Pokitto 46:e7e438368e16 791 uint8_t org_screeny = updRectY;
Pokitto 46:e7e438368e16 792 updRectY &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 793 updRectH += org_screeny - updRectY;
Pokitto 46:e7e438368e16 794 updRectH = (updRectH + 7) & 0xf8; // Make the value dividable by 8 (because of loop unroll optimization), round up.
Pokitto 46:e7e438368e16 795 }
Pokitto 46:e7e438368e16 796
Pokitto 46:e7e438368e16 797 // Calculate the current amount of sprites
Pokitto 46:e7e438368e16 798 // Note: Sprites must be taken into use from index 0 upwards, because the first sprite with bitmapData==NULL is considered as the last sprite
Pokitto 46:e7e438368e16 799 uint8_t spriteCount = 0;
Pokitto 46:e7e438368e16 800 if (sprites != NULL)
Pokitto 46:e7e438368e16 801 for (;sprites[spriteCount].bitmapData != NULL && spriteCount < SPRITE_COUNT; spriteCount++);
Pokitto 46:e7e438368e16 802
Pokitto 46:e7e438368e16 803 // If drawing the screen buffer, set the start pos to LCD commands only here.
Pokitto 46:e7e438368e16 804 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 805 if (!drawSpritesOnly) setDRAMptr(8, 0);
Pokitto 46:e7e438368e16 806 #else
Pokitto 46:e7e438368e16 807 if (!drawSpritesOnly) setDRAMptr(0, 0);
Pokitto 46:e7e438368e16 808 #endif
Pokitto 46:e7e438368e16 809
Pokitto 46:e7e438368e16 810 //*** GO THROUGH EACH VERTICAL GROUP OF 4 SCANLINES.***
Pokitto 46:e7e438368e16 811
Pokitto 46:e7e438368e16 812 for (x=0; x<LCDWIDTH; x+=4) {
Pokitto 46:e7e438368e16 813
Pokitto 46:e7e438368e16 814 uint8_t *screenBufScanlineAddr = scrbuf + (x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 815
Pokitto 46:e7e438368e16 816 /*Prepare scanline start address for sprites that are visible in this vertical scanline. Sprite width cannot exceed the screen width*/
Pokitto 46:e7e438368e16 817 uint8_t *sprScanlineAddr[SPRITE_COUNT]; // Sprite start address for the scanline
Pokitto 46:e7e438368e16 818 uint8_t sprScanlineBitshiftMode[SPRITE_COUNT]; // Sprite bitshift mode for the scanline
Pokitto 46:e7e438368e16 819 const uint8_t BITSHIFT_MODE_MIDDLE_BYTE = 0;
Pokitto 46:e7e438368e16 820 const uint8_t BITSHIFT_MODE_FIRST_BYTE = 1;
Pokitto 46:e7e438368e16 821 const uint8_t BITSHIFT_MODE_LAST_BYTE = 2;
Pokitto 46:e7e438368e16 822 uint8_t scanlineMinY = 255; // Init to uninitialized value. Do not draw by default.
Pokitto 46:e7e438368e16 823 uint8_t scanlineMaxY = 0; // Init to uninitialized value. Do not draw by default.
Pokitto 46:e7e438368e16 824
Pokitto 46:e7e438368e16 825 //*** CALCULATE DIRTY RECTS AND RESOLVE WHICH SPRITES BELONG TO THIS SCANLINE GROUP ***
Pokitto 46:e7e438368e16 826
Pokitto 46:e7e438368e16 827 if (sprites != NULL) {
Pokitto 46:e7e438368e16 828
Pokitto 46:e7e438368e16 829 // Check all the sprites for this scanline. That is used for handling the given update rect
Pokitto 46:e7e438368e16 830 // Note that the last round is when (sprindex == spriteCount). That is used to add the screen buffer
Pokitto 46:e7e438368e16 831 // update rect to the dirty rect.
Pokitto 46:e7e438368e16 832 for (int sprindex = 0; sprindex <= spriteCount; sprindex++) {
Pokitto 46:e7e438368e16 833
Pokitto 46:e7e438368e16 834 int16_t sprx, spry, sprOldX, sprOldY;
Pokitto 46:e7e438368e16 835 uint8_t sprw, sprh;
Pokitto 46:e7e438368e16 836 bool isCurrentSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 837 bool isOldSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 838
Pokitto 46:e7e438368e16 839 if (sprindex < spriteCount) {
Pokitto 46:e7e438368e16 840
Pokitto 46:e7e438368e16 841 sprx = sprites[sprindex].x;
Pokitto 46:e7e438368e16 842 spry = sprites[sprindex].y;
Pokitto 46:e7e438368e16 843 sprw = sprites[sprindex].w;
Pokitto 46:e7e438368e16 844 sprh = sprites[sprindex].h;
Pokitto 46:e7e438368e16 845 sprOldX = sprites[sprindex].oldx;
Pokitto 46:e7e438368e16 846 sprOldY = sprites[sprindex].oldy;
Pokitto 46:e7e438368e16 847 }
Pokitto 46:e7e438368e16 848
Pokitto 46:e7e438368e16 849 // Handle the screen buffer update rect after all sprites
Pokitto 46:e7e438368e16 850 else if(!drawSpritesOnly){
Pokitto 46:e7e438368e16 851
Pokitto 46:e7e438368e16 852 sprx = updRectX;
Pokitto 46:e7e438368e16 853 spry = updRectY;
Pokitto 46:e7e438368e16 854 sprw = updRectW;
Pokitto 46:e7e438368e16 855 sprh = updRectH;
Pokitto 46:e7e438368e16 856 sprOldX = updRectX;
Pokitto 46:e7e438368e16 857 sprOldY = updRectY;
Pokitto 46:e7e438368e16 858 isCurrentSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 859 isOldSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 860 }
Pokitto 46:e7e438368e16 861
Pokitto 46:e7e438368e16 862 // Check for out-of-screen
Pokitto 46:e7e438368e16 863 if (sprx >= LCDWIDTH || spry >= LCDHEIGHT)
Pokitto 46:e7e438368e16 864 isCurrentSpriteOutOfScreen = true;
Pokitto 46:e7e438368e16 865 if (sprOldX >= LCDWIDTH || sprOldY >= LCDHEIGHT)
Pokitto 46:e7e438368e16 866 isOldSpriteOutOfScreen = true;
Pokitto 46:e7e438368e16 867
Pokitto 46:e7e438368e16 868 // Skip if current and old sprites are out-of-screen
Pokitto 46:e7e438368e16 869 if (isCurrentSpriteOutOfScreen && isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 870 continue;
Pokitto 46:e7e438368e16 871
Pokitto 46:e7e438368e16 872 // Detect the dirty rect x-span by combining the previous and current sprite position.
Pokitto 51:113b1d84c34f 873 int16_t sprDirtyXMin = avrmin(sprx, sprOldX);
Pokitto 51:113b1d84c34f 874 int16_t sprDirtyXMax = avrmax(sprx, sprOldX);
Pokitto 46:e7e438368e16 875 if (isCurrentSpriteOutOfScreen)
Pokitto 46:e7e438368e16 876 sprDirtyXMax = sprOldX;
Pokitto 46:e7e438368e16 877 if (isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 878 sprDirtyXMax = sprx;
Pokitto 46:e7e438368e16 879
Pokitto 46:e7e438368e16 880 // Is current x inside the sprite combined dirty rect ?
Pokitto 46:e7e438368e16 881 int16_t sprDirtyXMaxEnd = sprDirtyXMax + sprw - 1 + 4; // Add 4 pixels to dirty rect width (needed?)
Pokitto 46:e7e438368e16 882 if (sprDirtyXMin <= x+3 && x <= sprDirtyXMaxEnd) {
Pokitto 46:e7e438368e16 883
Pokitto 46:e7e438368e16 884 // *** COMBINE DIRTY RECTS FOR THIS SCANLINE GROUP ***
Pokitto 46:e7e438368e16 885
Pokitto 46:e7e438368e16 886 // Dirty rect
Pokitto 51:113b1d84c34f 887 int sprDirtyYMin = avrmin(spry, sprOldY);
Pokitto 51:113b1d84c34f 888 sprDirtyYMin = avrmax((int)sprDirtyYMin, 0);
Pokitto 51:113b1d84c34f 889 int sprDirtyYMax = avrmax(spry, sprOldY);
Pokitto 46:e7e438368e16 890 if (isCurrentSpriteOutOfScreen)
Pokitto 46:e7e438368e16 891 sprDirtyYMax = sprOldY;
Pokitto 46:e7e438368e16 892 if (isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 893 sprDirtyYMax = spry;
Pokitto 46:e7e438368e16 894 int sprDirtyYMaxEnd = sprDirtyYMax + sprh - 1;
Pokitto 51:113b1d84c34f 895 sprDirtyYMaxEnd = avrmin(sprDirtyYMaxEnd, LCDHEIGHT - 1); // Should use LCDHEIGHT instead of screenH? Same with other screen* ?
Pokitto 46:e7e438368e16 896
Pokitto 46:e7e438368e16 897 // Get the scanline min and max y values for drawing
Pokitto 46:e7e438368e16 898 if (sprDirtyYMin < scanlineMinY)
Pokitto 46:e7e438368e16 899 scanlineMinY = sprDirtyYMin;
Pokitto 46:e7e438368e16 900 if (sprDirtyYMaxEnd > scanlineMaxY)
Pokitto 46:e7e438368e16 901 scanlineMaxY = sprDirtyYMaxEnd;
Pokitto 46:e7e438368e16 902
Pokitto 46:e7e438368e16 903 // *** PREPARE SPRITE FOR DRAWING ***
Pokitto 46:e7e438368e16 904
Pokitto 46:e7e438368e16 905 // Check if the sprite should be active for this vertical scanline group.
Pokitto 46:e7e438368e16 906 if (sprindex < spriteCount && // not for update rect
Pokitto 46:e7e438368e16 907 !isCurrentSpriteOutOfScreen && //out-of-screen
Pokitto 46:e7e438368e16 908 sprx <= x+3 && x < sprx + sprw) { // note: cover group of 4 pixels of the scanline (x+3)
Pokitto 46:e7e438368e16 909
Pokitto 46:e7e438368e16 910 // Find the byte number in the sprite data
Pokitto 46:e7e438368e16 911 int16_t byteNum = ((x+3) - sprx)>>2;
Pokitto 46:e7e438368e16 912
Pokitto 46:e7e438368e16 913 // Get the start addres of the spite data in this scanline.
Pokitto 46:e7e438368e16 914 sprScanlineAddr[sprindex] = const_cast<uint8_t*>(sprites[sprindex].bitmapData + byteNum);
Pokitto 46:e7e438368e16 915
Pokitto 46:e7e438368e16 916 // If the sprite goes over the top, it must be clipped from the top.
Pokitto 46:e7e438368e16 917 if(spry < 0)
Pokitto 46:e7e438368e16 918 sprScanlineAddr[sprindex] += (-spry) * (sprw >> 2);
Pokitto 46:e7e438368e16 919
Pokitto 46:e7e438368e16 920 // Select the bitshift mode for the blit algorithm
Pokitto 46:e7e438368e16 921 if (byteNum == 0)
Pokitto 46:e7e438368e16 922 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_FIRST_BYTE;
Pokitto 46:e7e438368e16 923 else if (byteNum >= (sprw >> 2))
Pokitto 46:e7e438368e16 924 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_LAST_BYTE;
Pokitto 46:e7e438368e16 925 else
Pokitto 46:e7e438368e16 926 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_MIDDLE_BYTE;
Pokitto 46:e7e438368e16 927 }
Pokitto 46:e7e438368e16 928 else
Pokitto 46:e7e438368e16 929 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 46:e7e438368e16 930 }
Pokitto 46:e7e438368e16 931 else
Pokitto 46:e7e438368e16 932 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 46:e7e438368e16 933 }
Pokitto 46:e7e438368e16 934 }
Pokitto 46:e7e438368e16 935
Pokitto 46:e7e438368e16 936 // *** ADJUST THE SCANLINE GROUP HEIGHT ***
Pokitto 46:e7e438368e16 937
Pokitto 46:e7e438368e16 938 // The height must dividable by 8. That is needed because later we copy 8 pixels at a time to the LCD.
Pokitto 46:e7e438368e16 939 if (scanlineMaxY - scanlineMinY + 1 > 0) {
Pokitto 46:e7e438368e16 940 uint8_t scanlineH = scanlineMaxY - scanlineMinY + 1;
Pokitto 46:e7e438368e16 941 uint8_t addW = 8 - (scanlineH & 0x7);
Pokitto 46:e7e438368e16 942
Pokitto 46:e7e438368e16 943 // if height is not dividable by 8, make it be.
Pokitto 46:e7e438368e16 944 if (addW != 0) {
Pokitto 46:e7e438368e16 945 if (scanlineMinY > addW )
Pokitto 46:e7e438368e16 946 scanlineMinY -= addW;
Pokitto 46:e7e438368e16 947 else if( scanlineMaxY + addW < updRectY+updRectH)
Pokitto 46:e7e438368e16 948 scanlineMaxY += addW;
Pokitto 46:e7e438368e16 949 else {
Pokitto 46:e7e438368e16 950 // Draw full height scanline
Pokitto 46:e7e438368e16 951 scanlineMinY = updRectY;
Pokitto 46:e7e438368e16 952 scanlineMaxY = updRectY+updRectH-1;
Pokitto 46:e7e438368e16 953 }
Pokitto 46:e7e438368e16 954 }
Pokitto 46:e7e438368e16 955 }
Pokitto 46:e7e438368e16 956
Pokitto 46:e7e438368e16 957 // *** COMBINE THE SCANLINE GROUP OF THE SCREEN BUFFER AND ALL SPRITES ***
Pokitto 46:e7e438368e16 958
Pokitto 46:e7e438368e16 959 // Find colours in this group of 4 scanlines
Pokitto 46:e7e438368e16 960 screenBufScanlineAddr += (scanlineMinY * 220/4);
Pokitto 46:e7e438368e16 961 for (y=scanlineMinY; y<=scanlineMaxY; y++)
Pokitto 46:e7e438368e16 962 {
Pokitto 46:e7e438368e16 963 // get the screen buffer data first
Pokitto 46:e7e438368e16 964 uint8_t tdata = *screenBufScanlineAddr;
Pokitto 46:e7e438368e16 965 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 966 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 967 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 968 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 969
Pokitto 46:e7e438368e16 970 // Convert to 16-bit colors in palette
Pokitto 46:e7e438368e16 971 uint16_t p = paletteptr[t];
Pokitto 46:e7e438368e16 972 uint16_t p2 = paletteptr[t2];
Pokitto 46:e7e438368e16 973 uint16_t p3 = paletteptr[t3];
Pokitto 46:e7e438368e16 974 uint16_t p4 = paletteptr[t4];
Pokitto 46:e7e438368e16 975
Pokitto 46:e7e438368e16 976 #if 0
Pokitto 46:e7e438368e16 977 // Dirty rect visual test
Pokitto 46:e7e438368e16 978 p = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 979 p2 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 980 p3 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 981 p4 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 982 #endif
Pokitto 46:e7e438368e16 983
Pokitto 46:e7e438368e16 984 // Add active sprite pixels
Pokitto 46:e7e438368e16 985 if (sprites != NULL) {
Pokitto 46:e7e438368e16 986
Pokitto 46:e7e438368e16 987 // Use loop unrolling for speed optimization
Pokitto 46:e7e438368e16 988 UNROLLED_LOOP_N(SPRITE_COUNT)
Pokitto 46:e7e438368e16 989 }
Pokitto 46:e7e438368e16 990
Pokitto 46:e7e438368e16 991 // put the result nibble values in the scanline
Pokitto 46:e7e438368e16 992 scanline[0][y] = p;
Pokitto 46:e7e438368e16 993 scanline[1][y] = p2;
Pokitto 46:e7e438368e16 994 scanline[2][y] = p3;
Pokitto 46:e7e438368e16 995 scanline[3][y] = p4;
Pokitto 46:e7e438368e16 996
Pokitto 46:e7e438368e16 997 screenBufScanlineAddr += 220>>2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 998 }
Pokitto 46:e7e438368e16 999
Pokitto 46:e7e438368e16 1000 // *** DRAW THE SCANLINE GROUP TO LCD
Pokitto 46:e7e438368e16 1001
Pokitto 46:e7e438368e16 1002 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1003 if (x>=8 && scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 46:e7e438368e16 1004 #else
Pokitto 46:e7e438368e16 1005 if (scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 46:e7e438368e16 1006 #endif
Pokitto 46:e7e438368e16 1007 // Draw 8 vertical pixels at a time for performance reasons
Pokitto 46:e7e438368e16 1008
Pokitto 46:e7e438368e16 1009 setDRAMptr(x, scanlineMinY);
Pokitto 46:e7e438368e16 1010 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 1011 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1012 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1013 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1014 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1015 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1016 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1017 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1018 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1019 }
Pokitto 46:e7e438368e16 1020
Pokitto 46:e7e438368e16 1021 setDRAMptr(x+1, scanlineMinY);
Pokitto 46:e7e438368e16 1022 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 1023 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1024 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1025 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1026 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1027 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1028 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1029 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1030 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1031 }
Pokitto 46:e7e438368e16 1032
Pokitto 46:e7e438368e16 1033 setDRAMptr(x+2, scanlineMinY);
Pokitto 46:e7e438368e16 1034 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 1035 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1036 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1037 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1038 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1039 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1040 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1041 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1042 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1043 }
Pokitto 46:e7e438368e16 1044
Pokitto 46:e7e438368e16 1045 setDRAMptr(x+3, scanlineMinY);
Pokitto 46:e7e438368e16 1046 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 1047 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1048 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1049 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1050 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1051 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1052 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1053 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1054 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1055 }
Pokitto 46:e7e438368e16 1056 }
Pokitto 46:e7e438368e16 1057 }
Pokitto 46:e7e438368e16 1058
Pokitto 46:e7e438368e16 1059 // Update old x and y for the sprites
Pokitto 46:e7e438368e16 1060 if (sprites != NULL) {
Pokitto 46:e7e438368e16 1061 for (int sprindex = 0; sprindex < spriteCount; sprindex++) {
Pokitto 46:e7e438368e16 1062 sprites[sprindex].oldx = sprites[sprindex].x;
Pokitto 46:e7e438368e16 1063 sprites[sprindex].oldy = sprites[sprindex].y;
Pokitto 46:e7e438368e16 1064 }
Pokitto 46:e7e438368e16 1065 }
Pokitto 46:e7e438368e16 1066
Pokitto 46:e7e438368e16 1067 #ifdef POK_SIM
Pokitto 46:e7e438368e16 1068 simulator.refreshDisplay();
Pokitto 46:e7e438368e16 1069 #endif
Pokitto 46:e7e438368e16 1070 }
Pokitto 46:e7e438368e16 1071
Pokitto 65:deed4aa606fb 1072
Pokitto 51:113b1d84c34f 1073 #define MODE2_INNER_LOOP_B \
Pokitto 51:113b1d84c34f 1074 " ldm %[scanline]!, {%[c]}" "\n" \
Pokitto 51:113b1d84c34f 1075 " str %[c], [%[LCD], 0]" "\n" \
Pokitto 51:113b1d84c34f 1076 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1077 " movs %[c], 252" "\n" \
Pokitto 51:113b1d84c34f 1078 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 1079 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1080 " subs %[x], 1" "\n" \
Pokitto 51:113b1d84c34f 1081 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 65:deed4aa606fb 1082
Pokitto 51:113b1d84c34f 1083
Pokitto 51:113b1d84c34f 1084 void Pokitto::lcdRefreshMode2(uint8_t * scrbuf, uint16_t* paletteptr ) {
Pokitto 65:deed4aa606fb 1085 uint32_t x,y,byte,c,t=1<<12;
Pokitto 51:113b1d84c34f 1086 uint32_t scanline[110];
Pokitto 51:113b1d84c34f 1087
Pokitto 51:113b1d84c34f 1088 write_command(0x03); write_data(0x1038);
Pokitto 51:113b1d84c34f 1089 write_command(0x20); // Horizontal DRAM Address
Pokitto 51:113b1d84c34f 1090 write_data(0); // 0
Pokitto 51:113b1d84c34f 1091 write_command(0x21); // Vertical DRAM Address
Pokitto 65:deed4aa606fb 1092
Pokitto 65:deed4aa606fb 1093 #ifndef __ARMCC_VERSION
Pokitto 65:deed4aa606fb 1094 write_data(1); // still has pixel 0 bug
Pokitto 51:113b1d84c34f 1095 write_command(0x22); // write data to DRAM
Pokitto 51:113b1d84c34f 1096 CLR_CS_SET_CD_RD_WR;
Pokitto 51:113b1d84c34f 1097 SET_MASK_P2;
Pokitto 51:113b1d84c34f 1098
Pokitto 65:deed4aa606fb 1099 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 65:deed4aa606fb 1100 setDRAMptr(0, 8);
Pokitto 65:deed4aa606fb 1101 y=4;
Pokitto 65:deed4aa606fb 1102 #endif
Pokitto 65:deed4aa606fb 1103
Pokitto 65:deed4aa606fb 1104 asm volatile(
Pokitto 51:113b1d84c34f 1105 ".syntax unified" "\n"
Pokitto 65:deed4aa606fb 1106
Pokitto 51:113b1d84c34f 1107 "mov r10, %[scanline]" "\n"
Pokitto 51:113b1d84c34f 1108 "mov r11, %[t]" "\n"
Pokitto 65:deed4aa606fb 1109
Pokitto 51:113b1d84c34f 1110 "mode2OuterLoop:" "\n"
Pokitto 65:deed4aa606fb 1111
Pokitto 51:113b1d84c34f 1112 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1113 "mode2InnerLoopA:"
Pokitto 51:113b1d84c34f 1114
Pokitto 51:113b1d84c34f 1115
Pokitto 65:deed4aa606fb 1116 " ldrb %[byte], [%[scrbuf],0]" "\n"
Pokitto 51:113b1d84c34f 1117 " lsrs %[c], %[byte], 4" "\n"
Pokitto 51:113b1d84c34f 1118
Pokitto 51:113b1d84c34f 1119 " movs %[t], 15" "\n"
Pokitto 65:deed4aa606fb 1120 " ands %[byte], %[t]" "\n"
Pokitto 65:deed4aa606fb 1121
Pokitto 65:deed4aa606fb 1122 " lsls %[c], 1" "\n"
Pokitto 65:deed4aa606fb 1123 " ldrh %[t], [%[paletteptr], %[c]]" "\n"
Pokitto 65:deed4aa606fb 1124 " lsls %[t], %[t], 3" "\n"
Pokitto 65:deed4aa606fb 1125 " str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 1126 " mov %[c], r11" "\n"
Pokitto 65:deed4aa606fb 1127 " str %[c], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 1128 " stm %[scanline]!, {%[t]}" "\n"
Pokitto 65:deed4aa606fb 1129 " movs %[t], 252" "\n"
Pokitto 65:deed4aa606fb 1130 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 65:deed4aa606fb 1131 " str %[c], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 1132 " lsls %[byte], %[byte], 1" "\n"
Pokitto 51:113b1d84c34f 1133 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 46:e7e438368e16 1134
Pokitto 65:deed4aa606fb 1135 " ldrh %[t], [%[paletteptr], %[byte]]" "\n"
Pokitto 65:deed4aa606fb 1136 " lsls %[t], %[t], 3" "\n"
Pokitto 65:deed4aa606fb 1137 " str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 1138 " mov %[c], r11" "\n"
Pokitto 65:deed4aa606fb 1139 " str %[c], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 1140 " stm %[scanline]!, {%[t]}" "\n"
Pokitto 65:deed4aa606fb 1141 " movs %[t], 252" "\n"
Pokitto 51:113b1d84c34f 1142 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 65:deed4aa606fb 1143 " str %[c], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 1144 " adds %[scrbuf], %[scrbuf], 1" "\n"
Pokitto 65:deed4aa606fb 1145 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 65:deed4aa606fb 1146
Pokitto 65:deed4aa606fb 1147 " subs %[x], 2" "\n"
Pokitto 51:113b1d84c34f 1148 " bne mode2InnerLoopA" "\n"
Pokitto 46:e7e438368e16 1149
Pokitto 51:113b1d84c34f 1150 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1151 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1152 "mov %[t], r11" "\n"
Pokitto 51:113b1d84c34f 1153 "mode2InnerLoopB:"
Pokitto 65:deed4aa606fb 1154 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1155 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1156 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1157 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1158 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1159 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1160 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1161 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1162 MODE2_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1163 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1164 " bne mode2InnerLoopB" "\n"
Pokitto 65:deed4aa606fb 1165
Pokitto 51:113b1d84c34f 1166 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1167 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1168 "movs %[c], 88" "\n"
Pokitto 51:113b1d84c34f 1169 "add %[y], %[t]" "\n" // y++... derpy, but it's the outer loop
Pokitto 51:113b1d84c34f 1170 "cmp %[y], %[c]" "\n"
Pokitto 51:113b1d84c34f 1171 "bne mode2OuterLoop" "\n" // if y != 88, loop
Pokitto 65:deed4aa606fb 1172
Pokitto 51:113b1d84c34f 1173 : // outputs
Pokitto 51:113b1d84c34f 1174 [c]"+l" (c),
Pokitto 51:113b1d84c34f 1175 [t]"+l" (t),
Pokitto 51:113b1d84c34f 1176 [x]"+l" (x),
Pokitto 51:113b1d84c34f 1177 [y]"+h" (y), // +:Read-Write l:lower (0-7) register
Pokitto 51:113b1d84c34f 1178 [scrbuf]"+l" (scrbuf)
Pokitto 65:deed4aa606fb 1179
Pokitto 51:113b1d84c34f 1180 : // inputs
Pokitto 51:113b1d84c34f 1181 [LCD]"l" (0xA0002188),
Pokitto 51:113b1d84c34f 1182 [scanline]"l" (scanline),
Pokitto 51:113b1d84c34f 1183 [paletteptr]"l" (paletteptr),
Pokitto 51:113b1d84c34f 1184 [byte]"l" (byte)
Pokitto 51:113b1d84c34f 1185 : // clobbers
Pokitto 51:113b1d84c34f 1186 "cc", "r10", "r11"
Pokitto 51:113b1d84c34f 1187 );
Pokitto 51:113b1d84c34f 1188
Pokitto 65:deed4aa606fb 1189
Pokitto 51:113b1d84c34f 1190 #else
Pokitto 65:deed4aa606fb 1191 write_data(0); // does not have pixel 0 bug
Pokitto 65:deed4aa606fb 1192 write_command(0x22); // write data to DRAM
Pokitto 65:deed4aa606fb 1193 CLR_CS_SET_CD_RD_WR;
Pokitto 65:deed4aa606fb 1194 SET_MASK_P2;
Pokitto 65:deed4aa606fb 1195
Pokitto 51:113b1d84c34f 1196 uint8_t* d = scrbuf;// point to beginning of line in data
Pokitto 51:113b1d84c34f 1197
Pokitto 51:113b1d84c34f 1198 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 51:113b1d84c34f 1199 setDRAMptr(0, 8);
Pokitto 51:113b1d84c34f 1200 wait_us(200); // Add wait to compensate skipping of 8 lines. Makes FPS counter to show the correct value.
Pokitto 51:113b1d84c34f 1201 for(y=4;y<88;y++)
Pokitto 51:113b1d84c34f 1202 #else
Pokitto 51:113b1d84c34f 1203 for(y=0;y<88;y++)
Pokitto 51:113b1d84c34f 1204 #endif
Pokitto 46:e7e438368e16 1205 {
Pokitto 51:113b1d84c34f 1206
Pokitto 51:113b1d84c34f 1207
Pokitto 46:e7e438368e16 1208 uint8_t s=0;
Pokitto 51:113b1d84c34f 1209 for(x=0;x<110;x+=2)
Pokitto 46:e7e438368e16 1210 {
Pokitto 51:113b1d84c34f 1211 uint8_t t = *d++;
Pokitto 51:113b1d84c34f 1212 uint32_t color;
Pokitto 51:113b1d84c34f 1213 color = uint32_t(paletteptr[t>>4])<<3;
Pokitto 51:113b1d84c34f 1214 scanline[s]=*LCD=color;TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1215 color = uint32_t(paletteptr[t&0xF])<<3;
Pokitto 51:113b1d84c34f 1216 scanline[s]=*LCD=color;TGL_WR_OP(s++);TGL_WR;
Pokitto 46:e7e438368e16 1217 }
Pokitto 46:e7e438368e16 1218
Pokitto 51:113b1d84c34f 1219 s=0;
Pokitto 51:113b1d84c34f 1220 for (s=0;s<110;) {
Pokitto 51:113b1d84c34f 1221 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1222 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1223 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1224 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1225 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1226 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1227 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1228 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1229 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1230 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 46:e7e438368e16 1231 }
Pokitto 46:e7e438368e16 1232
Pokitto 46:e7e438368e16 1233 }
Pokitto 51:113b1d84c34f 1234 #endif
Pokitto 51:113b1d84c34f 1235
Pokitto 51:113b1d84c34f 1236 CLR_MASK_P2;
Pokitto 46:e7e438368e16 1237 }
Pokitto 46:e7e438368e16 1238
Pokitto 46:e7e438368e16 1239 void Pokitto::lcdRefreshMode3(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1240 uint16_t x,y;
Pokitto 46:e7e438368e16 1241 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 46:e7e438368e16 1242 uint8_t *d;
Pokitto 46:e7e438368e16 1243
Pokitto 46:e7e438368e16 1244 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1245 write_data(0); // 0
Pokitto 46:e7e438368e16 1246 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1247 write_data(0);
Pokitto 46:e7e438368e16 1248 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1249 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1250
Pokitto 46:e7e438368e16 1251 for(x=0;x<220;x+=2)
Pokitto 46:e7e438368e16 1252 {
Pokitto 46:e7e438368e16 1253 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 46:e7e438368e16 1254 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1255 uint8_t s=0;
Pokitto 46:e7e438368e16 1256 for(y=0;y<176;y++)
Pokitto 46:e7e438368e16 1257 {
Pokitto 46:e7e438368e16 1258 uint8_t t = *d >> 4; // higher nibble
Pokitto 46:e7e438368e16 1259 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 46:e7e438368e16 1260 /** higher nibble = left pixel in pixel pair **/
Pokitto 46:e7e438368e16 1261 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 1262 scanline[1][s++] = paletteptr[t2];
Pokitto 46:e7e438368e16 1263 /** testing only **/
Pokitto 46:e7e438368e16 1264 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 46:e7e438368e16 1265 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 46:e7e438368e16 1266 //s++;
Pokitto 46:e7e438368e16 1267 /** until here **/
Pokitto 46:e7e438368e16 1268 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 1269 }
Pokitto 46:e7e438368e16 1270 s=0;
Pokitto 46:e7e438368e16 1271 /** draw scanlines **/
Pokitto 46:e7e438368e16 1272 /** leftmost scanline**/
Pokitto 46:e7e438368e16 1273
Pokitto 46:e7e438368e16 1274 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1275 if (x<8) continue;
Pokitto 46:e7e438368e16 1276 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 1277 #endif
Pokitto 46:e7e438368e16 1278
Pokitto 46:e7e438368e16 1279 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 1280 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1281 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1282 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1283 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1284 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1285 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1286 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1287 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1288 }
Pokitto 46:e7e438368e16 1289
Pokitto 46:e7e438368e16 1290 /** rightmost scanline**/
Pokitto 46:e7e438368e16 1291 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1292 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 1293 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1294 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1295 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1296 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1297 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1298 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1299 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1300 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1301 }
Pokitto 46:e7e438368e16 1302 }
Pokitto 46:e7e438368e16 1303 }
Pokitto 46:e7e438368e16 1304
Pokitto 46:e7e438368e16 1305 void Pokitto::lcdRefreshGB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1306 uint16_t x,y;
Pokitto 46:e7e438368e16 1307 uint16_t scanline[48];
Pokitto 46:e7e438368e16 1308 uint8_t * d;
Pokitto 46:e7e438368e16 1309
Pokitto 46:e7e438368e16 1310 #if POK_STRETCH
Pokitto 46:e7e438368e16 1311 //uint16_t xptr = 8;
Pokitto 46:e7e438368e16 1312 #else
Pokitto 46:e7e438368e16 1313 //xptr = 26;
Pokitto 46:e7e438368e16 1314 #endif
Pokitto 46:e7e438368e16 1315
Pokitto 46:e7e438368e16 1316 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1317 write_data(0); // 0
Pokitto 46:e7e438368e16 1318 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1319 write_data(0);
Pokitto 46:e7e438368e16 1320 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1321 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1322
Pokitto 46:e7e438368e16 1323 /** draw border **/
Pokitto 46:e7e438368e16 1324 for (int s=0;s<5*176;) {
Pokitto 46:e7e438368e16 1325 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 46:e7e438368e16 1326 }
Pokitto 46:e7e438368e16 1327
Pokitto 46:e7e438368e16 1328 for(x=0;x<84;x++)
Pokitto 46:e7e438368e16 1329 {
Pokitto 46:e7e438368e16 1330
Pokitto 46:e7e438368e16 1331 d = scrbuf + x;// point to beginning of line in data
Pokitto 46:e7e438368e16 1332
Pokitto 46:e7e438368e16 1333 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1334 uint8_t s=0;
Pokitto 46:e7e438368e16 1335 for(y=0;y<6;y++)
Pokitto 46:e7e438368e16 1336 {
Pokitto 46:e7e438368e16 1337 uint8_t t = *d;
Pokitto 46:e7e438368e16 1338 #if POK_COLORDEPTH > 1
Pokitto 46:e7e438368e16 1339 uint8_t t2 = *(d+504);
Pokitto 46:e7e438368e16 1340 #endif
Pokitto 46:e7e438368e16 1341 #if POK_COLORDEPTH > 2
Pokitto 46:e7e438368e16 1342 uint8_t t3 = *(d+504+504);
Pokitto 46:e7e438368e16 1343 #endif
Pokitto 46:e7e438368e16 1344 #if POK_COLORDEPTH > 3
Pokitto 46:e7e438368e16 1345 uint8_t t4 = *(d+504+504+504);
Pokitto 46:e7e438368e16 1346 #endif
Pokitto 46:e7e438368e16 1347 uint8_t paletteindex = 0;
Pokitto 46:e7e438368e16 1348
Pokitto 46:e7e438368e16 1349 /** bit 1 **/
Pokitto 46:e7e438368e16 1350 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1351 paletteindex = (t & 0x1);
Pokitto 46:e7e438368e16 1352 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1353 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 46:e7e438368e16 1354 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1355 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 46:e7e438368e16 1356 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1357 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 46:e7e438368e16 1358 #endif
Pokitto 46:e7e438368e16 1359 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1360
Pokitto 46:e7e438368e16 1361 /** bit 2 **/
Pokitto 46:e7e438368e16 1362 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1363 paletteindex = (t & 0x2)>>1;
Pokitto 46:e7e438368e16 1364 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1365 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 46:e7e438368e16 1366 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1367 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 46:e7e438368e16 1368 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1369 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 46:e7e438368e16 1370 #endif
Pokitto 46:e7e438368e16 1371 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1372
Pokitto 46:e7e438368e16 1373 /** bit 3 **/
Pokitto 46:e7e438368e16 1374 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1375 paletteindex = (t & 0x4)>>2;
Pokitto 46:e7e438368e16 1376 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1377 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 46:e7e438368e16 1378 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1379 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 46:e7e438368e16 1380 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1381 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 46:e7e438368e16 1382 #endif
Pokitto 46:e7e438368e16 1383 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1384
Pokitto 46:e7e438368e16 1385 /** bit 4 **/
Pokitto 46:e7e438368e16 1386 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1387 paletteindex = (t & 0x8)>>3;
Pokitto 46:e7e438368e16 1388 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1389 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 46:e7e438368e16 1390 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1391 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 46:e7e438368e16 1392 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1393 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 46:e7e438368e16 1394 #endif
Pokitto 46:e7e438368e16 1395 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1396
Pokitto 46:e7e438368e16 1397 /** bit 5 **/
Pokitto 46:e7e438368e16 1398 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1399 paletteindex = (t & 0x10)>>4;
Pokitto 46:e7e438368e16 1400 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1401 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 46:e7e438368e16 1402 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1403 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 46:e7e438368e16 1404 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1405 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 46:e7e438368e16 1406 #endif
Pokitto 46:e7e438368e16 1407 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1408
Pokitto 46:e7e438368e16 1409 /** bit 6 **/
Pokitto 46:e7e438368e16 1410 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1411 paletteindex = (t & 0x20)>>5;
Pokitto 46:e7e438368e16 1412 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1413 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 46:e7e438368e16 1414 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1415 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 46:e7e438368e16 1416 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1417 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 46:e7e438368e16 1418 #endif
Pokitto 46:e7e438368e16 1419 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1420
Pokitto 46:e7e438368e16 1421 /** bit 7 **/
Pokitto 46:e7e438368e16 1422 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1423 paletteindex = (t & 0x40)>>6;
Pokitto 46:e7e438368e16 1424 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1425 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 46:e7e438368e16 1426 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1427 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 46:e7e438368e16 1428 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1429 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 46:e7e438368e16 1430 #endif
Pokitto 46:e7e438368e16 1431 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1432
Pokitto 46:e7e438368e16 1433 /** bit 8 **/
Pokitto 46:e7e438368e16 1434 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1435 paletteindex = (t & 0x80)>>7;
Pokitto 46:e7e438368e16 1436 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1437 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 46:e7e438368e16 1438 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1439 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 46:e7e438368e16 1440 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1441 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 46:e7e438368e16 1442 #endif
Pokitto 46:e7e438368e16 1443 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1444
Pokitto 46:e7e438368e16 1445 d+=84; // jump to byte directly below
Pokitto 46:e7e438368e16 1446 }
Pokitto 46:e7e438368e16 1447
Pokitto 46:e7e438368e16 1448
Pokitto 46:e7e438368e16 1449 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1450 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1451 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1452 write_data(xptr++);
Pokitto 46:e7e438368e16 1453 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1454 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1455 /** draw border **/
Pokitto 46:e7e438368e16 1456 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1457
Pokitto 46:e7e438368e16 1458 s=0;
Pokitto 46:e7e438368e16 1459
Pokitto 46:e7e438368e16 1460 /** draw scanlines **/
Pokitto 46:e7e438368e16 1461 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1462 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1463 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1464 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1465 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1466 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1467 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1468 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1469 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1470 }
Pokitto 46:e7e438368e16 1471 /** draw border **/
Pokitto 46:e7e438368e16 1472 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1473
Pokitto 46:e7e438368e16 1474
Pokitto 46:e7e438368e16 1475 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1476 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1477 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1478 write_data(xptr++);
Pokitto 46:e7e438368e16 1479 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1480 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1481 /** draw border **/
Pokitto 46:e7e438368e16 1482 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1483
Pokitto 46:e7e438368e16 1484 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1485 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1486 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1487 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1488 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1489 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1490 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1491 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1492 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1493 }
Pokitto 46:e7e438368e16 1494
Pokitto 46:e7e438368e16 1495 /** draw border **/
Pokitto 46:e7e438368e16 1496 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1497
Pokitto 46:e7e438368e16 1498
Pokitto 46:e7e438368e16 1499 #if POK_STRETCH
Pokitto 46:e7e438368e16 1500 //if (x>16 && x<68)
Pokitto 46:e7e438368e16 1501 if (x&2)// && x&2)
Pokitto 46:e7e438368e16 1502 {
Pokitto 46:e7e438368e16 1503 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1504 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1505 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1506 write_data(xptr++);
Pokitto 46:e7e438368e16 1507 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1508 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1509 /** draw border **/
Pokitto 46:e7e438368e16 1510 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1511
Pokitto 46:e7e438368e16 1512
Pokitto 46:e7e438368e16 1513 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1514 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1515 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1516 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1517 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1518 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1519 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1520 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1521 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1522 }
Pokitto 46:e7e438368e16 1523
Pokitto 46:e7e438368e16 1524 /** draw border **/
Pokitto 46:e7e438368e16 1525 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR; CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1526
Pokitto 46:e7e438368e16 1527 }
Pokitto 46:e7e438368e16 1528 #endif
Pokitto 46:e7e438368e16 1529 }
Pokitto 46:e7e438368e16 1530 /** draw border **/
Pokitto 46:e7e438368e16 1531 for (int s=0;s<5*176;) {
Pokitto 46:e7e438368e16 1532 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 46:e7e438368e16 1533 }
Pokitto 46:e7e438368e16 1534 }
Pokitto 46:e7e438368e16 1535
Pokitto 46:e7e438368e16 1536
Pokitto 46:e7e438368e16 1537 void Pokitto::lcdRefreshAB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1538 uint16_t x,y;
Pokitto 46:e7e438368e16 1539 uint16_t scanline[64];
Pokitto 46:e7e438368e16 1540 uint8_t *d;
Pokitto 46:e7e438368e16 1541 //lcdClear();
Pokitto 46:e7e438368e16 1542 #if POK_STRETCH
Pokitto 46:e7e438368e16 1543 uint16_t xptr = 14;
Pokitto 46:e7e438368e16 1544 uint8_t yoffset = 24;
Pokitto 46:e7e438368e16 1545 #else
Pokitto 46:e7e438368e16 1546 uint16_t xptr = 0;
Pokitto 46:e7e438368e16 1547 uint8_t yoffset = 0;
Pokitto 46:e7e438368e16 1548 #endif
Pokitto 46:e7e438368e16 1549
Pokitto 46:e7e438368e16 1550 for(x=0;x<128;x++)
Pokitto 46:e7e438368e16 1551 {
Pokitto 46:e7e438368e16 1552 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1553 write_data(yoffset); // 0
Pokitto 46:e7e438368e16 1554 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1555 write_data(xptr++);
Pokitto 46:e7e438368e16 1556 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1557 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1558 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1559
Pokitto 46:e7e438368e16 1560 d = scrbuf + x;// point to beginning of line in data
Pokitto 46:e7e438368e16 1561
Pokitto 46:e7e438368e16 1562 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1563 uint8_t s=0;
Pokitto 46:e7e438368e16 1564 for(y=0;y<8;y++)
Pokitto 46:e7e438368e16 1565 {
Pokitto 46:e7e438368e16 1566 uint8_t t = *d;
Pokitto 46:e7e438368e16 1567 #if POK_COLORDEPTH > 1
Pokitto 46:e7e438368e16 1568 uint8_t t2 = *(d+AB_JUMP);
Pokitto 46:e7e438368e16 1569 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1570 #if POK_COLORDEPTH > 2
Pokitto 46:e7e438368e16 1571 uint8_t t3 = *(d+AB_JUMP+AB_JUMP);
Pokitto 46:e7e438368e16 1572 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1573 #if POK_COLORDEPTH > 3
Pokitto 46:e7e438368e16 1574 uint8_t t4 = *(d+AB_JUMP+AB_JUMP+AB_JUMP);
Pokitto 46:e7e438368e16 1575 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1576 uint8_t paletteindex = 0;
Pokitto 46:e7e438368e16 1577
Pokitto 46:e7e438368e16 1578 /** bit 1 **/
Pokitto 46:e7e438368e16 1579 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1580 paletteindex = (t & 0x1);
Pokitto 46:e7e438368e16 1581 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1582 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 46:e7e438368e16 1583 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1584 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 46:e7e438368e16 1585 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1586 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 46:e7e438368e16 1587 #endif
Pokitto 46:e7e438368e16 1588 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1589
Pokitto 46:e7e438368e16 1590 /** bit 2 **/
Pokitto 46:e7e438368e16 1591 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1592 paletteindex = (t & 0x2)>>1;
Pokitto 46:e7e438368e16 1593 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1594 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 46:e7e438368e16 1595 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1596 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 46:e7e438368e16 1597 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1598 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 46:e7e438368e16 1599 #endif
Pokitto 46:e7e438368e16 1600 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1601
Pokitto 46:e7e438368e16 1602 /** bit 3 **/
Pokitto 46:e7e438368e16 1603 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1604 paletteindex = (t & 0x4)>>2;
Pokitto 46:e7e438368e16 1605 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1606 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 46:e7e438368e16 1607 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1608 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 46:e7e438368e16 1609 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1610 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 46:e7e438368e16 1611 #endif
Pokitto 46:e7e438368e16 1612 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1613
Pokitto 46:e7e438368e16 1614 /** bit 4 **/
Pokitto 46:e7e438368e16 1615 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1616 paletteindex = (t & 0x8)>>3;
Pokitto 46:e7e438368e16 1617 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1618 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 46:e7e438368e16 1619 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1620 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 46:e7e438368e16 1621 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1622 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 46:e7e438368e16 1623 #endif
Pokitto 46:e7e438368e16 1624 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1625
Pokitto 46:e7e438368e16 1626 /** bit 5 **/
Pokitto 46:e7e438368e16 1627 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1628 paletteindex = (t & 0x10)>>4;
Pokitto 46:e7e438368e16 1629 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1630 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 46:e7e438368e16 1631 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1632 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 46:e7e438368e16 1633 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1634 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 46:e7e438368e16 1635 #endif
Pokitto 46:e7e438368e16 1636 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1637
Pokitto 46:e7e438368e16 1638 /** bit 6 **/
Pokitto 46:e7e438368e16 1639 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1640 paletteindex = (t & 0x20)>>5;
Pokitto 46:e7e438368e16 1641 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1642 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 46:e7e438368e16 1643 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1644 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 46:e7e438368e16 1645 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1646 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 46:e7e438368e16 1647 #endif
Pokitto 46:e7e438368e16 1648 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1649
Pokitto 46:e7e438368e16 1650 /** bit 7 **/
Pokitto 46:e7e438368e16 1651 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1652 paletteindex = (t & 0x40)>>6;
Pokitto 46:e7e438368e16 1653 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1654 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 46:e7e438368e16 1655 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1656 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 46:e7e438368e16 1657 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1658 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 46:e7e438368e16 1659 #endif
Pokitto 46:e7e438368e16 1660 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1661
Pokitto 46:e7e438368e16 1662 /** bit 8 **/
Pokitto 46:e7e438368e16 1663 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1664 paletteindex = (t & 0x80)>>7;
Pokitto 46:e7e438368e16 1665 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1666 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 46:e7e438368e16 1667 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1668 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 46:e7e438368e16 1669 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1670 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 46:e7e438368e16 1671 #endif
Pokitto 46:e7e438368e16 1672 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1673
Pokitto 46:e7e438368e16 1674 d+=128; // jump to byte directly below
Pokitto 46:e7e438368e16 1675 }
Pokitto 46:e7e438368e16 1676
Pokitto 46:e7e438368e16 1677 s=0;
Pokitto 46:e7e438368e16 1678
Pokitto 46:e7e438368e16 1679 /** draw scanlines **/
Pokitto 46:e7e438368e16 1680 for (s=0;s<64;) {
Pokitto 46:e7e438368e16 1681 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1682 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1683 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1684 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1685 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1686 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1687 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1688 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1689 }
Pokitto 46:e7e438368e16 1690
Pokitto 46:e7e438368e16 1691 #if POK_STRETCH
Pokitto 46:e7e438368e16 1692 if (x&1) {
Pokitto 46:e7e438368e16 1693 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1694 write_data(yoffset); // 0
Pokitto 46:e7e438368e16 1695 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1696 write_data(xptr++);
Pokitto 46:e7e438368e16 1697 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1698 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1699 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1700
Pokitto 46:e7e438368e16 1701 for (s=0;s<64;) {
Pokitto 46:e7e438368e16 1702 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1703 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1704 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1705 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1706 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1707 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1708 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1709 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1710 }
Pokitto 46:e7e438368e16 1711 }
Pokitto 46:e7e438368e16 1712 #endif
Pokitto 46:e7e438368e16 1713 }
Pokitto 46:e7e438368e16 1714 }
Pokitto 46:e7e438368e16 1715
Pokitto 46:e7e438368e16 1716 void Pokitto::lcdRefreshModeGBC(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1717 uint16_t x,y,xptr;
Pokitto 46:e7e438368e16 1718 uint16_t scanline[4][144]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 46:e7e438368e16 1719 uint8_t *d, yoffset=0;
Pokitto 46:e7e438368e16 1720
Pokitto 46:e7e438368e16 1721 xptr = 0;
Pokitto 46:e7e438368e16 1722 setDRAMptr(xptr,yoffset);
Pokitto 46:e7e438368e16 1723
Pokitto 46:e7e438368e16 1724
Pokitto 46:e7e438368e16 1725 for(x=0;x<160;x+=4)
Pokitto 46:e7e438368e16 1726 {
Pokitto 46:e7e438368e16 1727 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 1728 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1729 uint8_t s=0;
Pokitto 46:e7e438368e16 1730 for(y=0;y<144;y++)
Pokitto 46:e7e438368e16 1731 {
Pokitto 46:e7e438368e16 1732 uint8_t tdata = *d;
Pokitto 46:e7e438368e16 1733 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 1734 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 1735 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 1736 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 1737
Pokitto 46:e7e438368e16 1738 /** put nibble values in the scanlines **/
Pokitto 46:e7e438368e16 1739
Pokitto 46:e7e438368e16 1740 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 1741 scanline[1][s] = paletteptr[t2];
Pokitto 46:e7e438368e16 1742 scanline[2][s] = paletteptr[t3];
Pokitto 46:e7e438368e16 1743 scanline[3][s++] = paletteptr[t4];
Pokitto 46:e7e438368e16 1744
Pokitto 46:e7e438368e16 1745 d+=160/4; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 1746 }
Pokitto 46:e7e438368e16 1747
Pokitto 46:e7e438368e16 1748 s=0;
Pokitto 46:e7e438368e16 1749 /** draw scanlines **/
Pokitto 46:e7e438368e16 1750 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1751 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1752 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1753 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1754 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1755 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1756 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1757 }
Pokitto 46:e7e438368e16 1758 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1759 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1760 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1761 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1762 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1763 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1764 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1765 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1766 }
Pokitto 46:e7e438368e16 1767 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1768 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1769 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1770 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1771 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1772 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1773 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1774 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1775 }
Pokitto 46:e7e438368e16 1776 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1777 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1778 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1779 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1780 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1781 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1782 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1783 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1784 }
Pokitto 46:e7e438368e16 1785 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1786 }
Pokitto 46:e7e438368e16 1787 }
Pokitto 46:e7e438368e16 1788
Pokitto 46:e7e438368e16 1789
Pokitto 46:e7e438368e16 1790 void Pokitto::lcdRefreshT1(uint8_t* tilebuf, uint8_t* tilecolorbuf, uint8_t* tileset, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1791 #ifdef POK_TILEMODE
Pokitto 46:e7e438368e16 1792 uint16_t x,y,data,xptr;
Pokitto 46:e7e438368e16 1793 uint16_t scanline[176];
Pokitto 46:e7e438368e16 1794 uint8_t yoffset=0, tilebyte, tileindex, tilex=0, tiley=0,xcount;
Pokitto 46:e7e438368e16 1795
Pokitto 46:e7e438368e16 1796
Pokitto 46:e7e438368e16 1797 if (!tileset) return;
Pokitto 46:e7e438368e16 1798
Pokitto 46:e7e438368e16 1799 #if LCDWIDTH < POK_LCD_W
Pokitto 46:e7e438368e16 1800 xptr = (POK_LCD_W-LCDWIDTH)/2;
Pokitto 46:e7e438368e16 1801 #else
Pokitto 46:e7e438368e16 1802 xptr = 0;
Pokitto 46:e7e438368e16 1803 #endif
Pokitto 46:e7e438368e16 1804 #if LCDHEIGHT < POK_LCD_H
Pokitto 46:e7e438368e16 1805 yoffset = (POK_LCD_H-LCDHEIGHT)/2;
Pokitto 46:e7e438368e16 1806 #else
Pokitto 46:e7e438368e16 1807 yoffset = 0;
Pokitto 46:e7e438368e16 1808 #endif
Pokitto 46:e7e438368e16 1809
Pokitto 46:e7e438368e16 1810 for(x=0, xcount=0 ;x<LCDWIDTH;x++,xcount++) // loop through vertical columns
Pokitto 46:e7e438368e16 1811 {
Pokitto 46:e7e438368e16 1812 setDRAMptr(xptr++,yoffset); //point to VRAM
Pokitto 46:e7e438368e16 1813
Pokitto 46:e7e438368e16 1814 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1815 uint8_t s=0, tiley=0;
Pokitto 46:e7e438368e16 1816 //tileindex = tilebuf[tilex*POK_TILES_Y];
Pokitto 46:e7e438368e16 1817 if (xcount==POK_TILE_W) {
Pokitto 46:e7e438368e16 1818 tilex++;
Pokitto 46:e7e438368e16 1819 xcount=0;
Pokitto 46:e7e438368e16 1820 }
Pokitto 46:e7e438368e16 1821
Pokitto 46:e7e438368e16 1822 for(y=0;y<LCDHEIGHT;)
Pokitto 46:e7e438368e16 1823 {
Pokitto 46:e7e438368e16 1824 uint8_t tileval = tilebuf[tilex+tiley*POK_TILES_X]; //get tile number
Pokitto 46:e7e438368e16 1825 uint16_t index = tileval*POK_TILE_W+xcount;
Pokitto 46:e7e438368e16 1826 uint8_t tilebyte = tileset[index]; //get bitmap data
Pokitto 46:e7e438368e16 1827 for (uint8_t ycount=0, bitcount=0; ycount<POK_TILE_H; ycount++, y++, bitcount++) {
Pokitto 46:e7e438368e16 1828 if (bitcount==8) {
Pokitto 46:e7e438368e16 1829 bitcount=0;
Pokitto 46:e7e438368e16 1830 index += 176; //jump to byte below in the tileset bitmap
Pokitto 46:e7e438368e16 1831 tilebyte = tileset[index]; //get bitmap data
Pokitto 46:e7e438368e16 1832 }
Pokitto 46:e7e438368e16 1833 //tilebyte = tile[(tileindex>>4)+*POK_TILE_W]; //tilemaps are 16x16
Pokitto 46:e7e438368e16 1834 //uint8_t paletteindex = ((tilebyte>>(bitcount&0x7)) & 0x1);
Pokitto 46:e7e438368e16 1835 if (!tileval) scanline[s++] = COLOR_MAGENTA*((tilebyte>>bitcount)&0x1);//paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1836 else scanline[s++] = paletteptr[((tilebyte>>bitcount)&0x1)*tileval];//paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1837 }
Pokitto 46:e7e438368e16 1838 tiley++; //move to next tile
Pokitto 46:e7e438368e16 1839 }
Pokitto 46:e7e438368e16 1840 s=0;
Pokitto 46:e7e438368e16 1841
Pokitto 46:e7e438368e16 1842 /** draw scanlines **/
Pokitto 46:e7e438368e16 1843 for (s=0;s<LCDHEIGHT;) {
Pokitto 46:e7e438368e16 1844 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1845 }
Pokitto 46:e7e438368e16 1846 }
Pokitto 46:e7e438368e16 1847 #endif
Pokitto 46:e7e438368e16 1848 }
Pokitto 46:e7e438368e16 1849
Pokitto 51:113b1d84c34f 1850 #define MODE13_INNER_LOOP_A \
Pokitto 65:deed4aa606fb 1851 " add %[t], %[t], r10" "\n" \
Pokitto 51:113b1d84c34f 1852 " uxtb %[c], %[t] " "\n" \
Pokitto 51:113b1d84c34f 1853 " lsls %[c], 1" "\n" \
Pokitto 51:113b1d84c34f 1854 " ldrh %[t], [%[paletteptr], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 1855 " lsls %[t], %[t], 3" "\n" \
Pokitto 51:113b1d84c34f 1856 " str %[t], [%[LCD], 0]" "\n" \
Pokitto 65:deed4aa606fb 1857 " movs %[c], 252" "\n" \
Pokitto 65:deed4aa606fb 1858 " str %[offset], [%[LCD], %[c]]" "\n" \
Pokitto 65:deed4aa606fb 1859 " stm %[scanline]!, {%[t]}" "\n" \
Pokitto 65:deed4aa606fb 1860 " str %[offset], [%[LCD], 124]" "\n" \
Pokitto 65:deed4aa606fb 1861 " str %[offset], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 1862 " adds %[scrbuf], %[scrbuf], 1" "\n" \
Pokitto 65:deed4aa606fb 1863 " ldrb %[t], [%[scrbuf],0]" "\n" \
Pokitto 65:deed4aa606fb 1864 " str %[offset], [%[LCD], 124]" "\n"
Pokitto 46:e7e438368e16 1865
Pokitto 65:deed4aa606fb 1866 // This can be made 1 cycle faster (x -= 10 instead of x--),
Pokitto 65:deed4aa606fb 1867 // but there will be noise
Pokitto 65:deed4aa606fb 1868 #define MODE13_INNER_LOOP_B \
Pokitto 65:deed4aa606fb 1869 " str %[c], [%[LCD], 0]" "\n" \
Pokitto 65:deed4aa606fb 1870 " str %[offset], [%[LCD], %[t]]" "\n" \
Pokitto 65:deed4aa606fb 1871 " ldr %[c], [%[scanline]]" "\n" \
Pokitto 65:deed4aa606fb 1872 " str %[offset], [%[LCD], 124]" "\n" \
Pokitto 65:deed4aa606fb 1873 " str %[offset], [%[LCD], %[t]]" "\n" \
Pokitto 65:deed4aa606fb 1874 " adds %[scanline], 4" "\n" \
Pokitto 65:deed4aa606fb 1875 " subs %[x], 1" "\n" \
Pokitto 65:deed4aa606fb 1876 " str %[offset], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 1877
Pokitto 65:deed4aa606fb 1878
Pokitto 51:113b1d84c34f 1879 void Pokitto::lcdRefreshMode13(uint8_t * scrbuf, uint16_t* paletteptr, uint8_t offset){
Pokitto 51:113b1d84c34f 1880 uint32_t scanline[110]; // read two nibbles = pixels at a time
Pokitto 65:deed4aa606fb 1881
Pokitto 51:113b1d84c34f 1882 write_command_16(0x03); write_data_16(0x1038);
Pokitto 51:113b1d84c34f 1883 write_command(0x20); write_data(0);
Pokitto 65:deed4aa606fb 1884 write_command(0x21); write_data(0);
Pokitto 51:113b1d84c34f 1885 write_command(0x22);
Pokitto 51:113b1d84c34f 1886 CLR_CS_SET_CD_RD_WR;
Pokitto 51:113b1d84c34f 1887 SET_MASK_P2;
Pokitto 65:deed4aa606fb 1888
Pokitto 65:deed4aa606fb 1889 uint32_t x, y=0, c, t;
Pokitto 65:deed4aa606fb 1890
Pokitto 51:113b1d84c34f 1891 #ifndef __ARMCC_VERSION
Pokitto 65:deed4aa606fb 1892 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 65:deed4aa606fb 1893 setDRAMptr(0, 8);
Pokitto 65:deed4aa606fb 1894 y=4;
Pokitto 65:deed4aa606fb 1895 #endif
Pokitto 65:deed4aa606fb 1896
Pokitto 51:113b1d84c34f 1897 asm volatile(
Pokitto 51:113b1d84c34f 1898 ".syntax unified" "\n"
Pokitto 65:deed4aa606fb 1899
Pokitto 65:deed4aa606fb 1900 "mov r10, %[offset]" "\n"
Pokitto 65:deed4aa606fb 1901 "movs %[offset], 1" "\n"
Pokitto 65:deed4aa606fb 1902 "lsls %[offset], %[offset], 12" "\n"
Pokitto 65:deed4aa606fb 1903
Pokitto 51:113b1d84c34f 1904 "mode13OuterLoop:" "\n"
Pokitto 65:deed4aa606fb 1905
Pokitto 51:113b1d84c34f 1906 "movs %[x], 110" "\n"
Pokitto 65:deed4aa606fb 1907 "ldrb %[t], [%[scrbuf],0]" "\n"
Pokitto 51:113b1d84c34f 1908 "mode13InnerLoopA:"
Pokitto 51:113b1d84c34f 1909 MODE13_INNER_LOOP_A
Pokitto 51:113b1d84c34f 1910 MODE13_INNER_LOOP_A
Pokitto 65:deed4aa606fb 1911 " subs %[x], 2" "\n"
Pokitto 51:113b1d84c34f 1912 " bne mode13InnerLoopA" "\n"
Pokitto 46:e7e438368e16 1913
Pokitto 65:deed4aa606fb 1914 "subs %[scanline], 220" "\n"
Pokitto 65:deed4aa606fb 1915 "subs %[scanline], 220" "\n"
Pokitto 65:deed4aa606fb 1916
Pokitto 51:113b1d84c34f 1917 "movs %[x], 110" "\n"
Pokitto 65:deed4aa606fb 1918 "movs %[t], 252" "\n"
Pokitto 65:deed4aa606fb 1919 "ldm %[scanline]!, {%[c]}" "\n"
Pokitto 51:113b1d84c34f 1920 "mode13InnerLoopB:"
Pokitto 65:deed4aa606fb 1921 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1922 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1923 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1924 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1925 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1926 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1927 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1928 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1929 MODE13_INNER_LOOP_B
Pokitto 65:deed4aa606fb 1930 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1931 " bne mode13InnerLoopB" "\n"
Pokitto 65:deed4aa606fb 1932
Pokitto 65:deed4aa606fb 1933 "subs %[scanline], 220" "\n"
Pokitto 65:deed4aa606fb 1934 "subs %[scanline], 224" "\n"
Pokitto 51:113b1d84c34f 1935 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1936 "movs %[c], 88" "\n"
Pokitto 65:deed4aa606fb 1937 "add %[y], %[t]" "\n"
Pokitto 51:113b1d84c34f 1938 "cmp %[y], %[c]" "\n"
Pokitto 51:113b1d84c34f 1939 "bne mode13OuterLoop" "\n" // if y != 88, loop
Pokitto 65:deed4aa606fb 1940
Pokitto 51:113b1d84c34f 1941 : // outputs
Pokitto 51:113b1d84c34f 1942 [c]"+l" (c),
Pokitto 51:113b1d84c34f 1943 [t]"+l" (t),
Pokitto 51:113b1d84c34f 1944 [x]"+l" (x),
Pokitto 51:113b1d84c34f 1945 [y]"+h" (y), // +:Read-Write l:lower (0-7) register
Pokitto 65:deed4aa606fb 1946 [scrbuf]"+l" (scrbuf),
Pokitto 65:deed4aa606fb 1947 [offset]"+l" (offset)
Pokitto 65:deed4aa606fb 1948
Pokitto 51:113b1d84c34f 1949 : // inputs
Pokitto 51:113b1d84c34f 1950 [LCD]"l" (0xA0002188),
Pokitto 51:113b1d84c34f 1951 [scanline]"l" (scanline),
Pokitto 65:deed4aa606fb 1952 [paletteptr]"l" (paletteptr)
Pokitto 65:deed4aa606fb 1953
Pokitto 51:113b1d84c34f 1954 : // clobbers
Pokitto 65:deed4aa606fb 1955 "cc", "r10"
Pokitto 51:113b1d84c34f 1956 );
Pokitto 46:e7e438368e16 1957
Pokitto 51:113b1d84c34f 1958 #else
Pokitto 51:113b1d84c34f 1959 uint8_t* d = scrbuf;// point to beginning of line in data
Pokitto 51:113b1d84c34f 1960 for(y=0;y<88;y++){
Pokitto 65:deed4aa606fb 1961
Pokitto 51:113b1d84c34f 1962 uint32_t* s = scanline;
Pokitto 65:deed4aa606fb 1963
Pokitto 51:113b1d84c34f 1964 for(x=0;x<110;x+=10){
Pokitto 65:deed4aa606fb 1965 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1966 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1967 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1968 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1969 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1970 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1971 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1972 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1973 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 65:deed4aa606fb 1974 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1975 }
Pokitto 65:deed4aa606fb 1976
Pokitto 51:113b1d84c34f 1977 s = scanline;
Pokitto 51:113b1d84c34f 1978 uint32_t c = *s;
Pokitto 51:113b1d84c34f 1979 for(x=0;x<110;x+=10){
Pokitto 51:113b1d84c34f 1980 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1981 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1982 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1983 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1984 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1985 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1986 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1987 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1988 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1989 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1990 }
Pokitto 65:deed4aa606fb 1991
Pokitto 51:113b1d84c34f 1992 }
Pokitto 51:113b1d84c34f 1993 #endif
Pokitto 51:113b1d84c34f 1994 }
Pokitto 46:e7e438368e16 1995
Pokitto 65:deed4aa606fb 1996
Pokitto 65:deed4aa606fb 1997
Pokitto 65:deed4aa606fb 1998 void Pokitto::lcdRefreshMode64( uint8_t * scrbuf, uint16_t* paletteptr ){
Pokitto 65:deed4aa606fb 1999 uint8_t *end = &scrbuf[ POK_SCREENBUFFERSIZE+4 ];
Pokitto 65:deed4aa606fb 2000 write_command_16(0x03); write_data_16(0x1038);
Pokitto 65:deed4aa606fb 2001 write_command(0x20); write_data(0);
Pokitto 65:deed4aa606fb 2002 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 65:deed4aa606fb 2003 write_data(8);
Pokitto 65:deed4aa606fb 2004 scrbuf += 110*8;
Pokitto 65:deed4aa606fb 2005 #else
Pokitto 65:deed4aa606fb 2006 write_data(0);
Pokitto 65:deed4aa606fb 2007 #endif
Pokitto 65:deed4aa606fb 2008 write_command(0x21); write_data(0);
Pokitto 65:deed4aa606fb 2009 write_command(0x22);
Pokitto 65:deed4aa606fb 2010 CLR_CS_SET_CD_RD_WR;
Pokitto 65:deed4aa606fb 2011 SET_MASK_P2;
Pokitto 65:deed4aa606fb 2012
Pokitto 65:deed4aa606fb 2013 uint32_t TGL = 1<<12, CLR = 252, c, t;
Pokitto 65:deed4aa606fb 2014 #ifndef __ARMCC_VERSION
Pokitto 65:deed4aa606fb 2015 asm volatile(
Pokitto 65:deed4aa606fb 2016 ".syntax unified" "\n"
Pokitto 65:deed4aa606fb 2017 "ldm %[scrbuf]!, {%[c]}" "\n"
Pokitto 65:deed4aa606fb 2018 "lsls %[t], %[c], 24" "\n"
Pokitto 65:deed4aa606fb 2019 "mode64loop%=:" "\n"
Pokitto 65:deed4aa606fb 2020 "lsrs %[c], %[c], 8" "\n"
Pokitto 65:deed4aa606fb 2021 "lsrs %[t], %[t], 23" "\n"
Pokitto 65:deed4aa606fb 2022 "ldrh %[t], [%[paletteptr], %[t]]" "\n"
Pokitto 65:deed4aa606fb 2023 "lsls %[t], 3" "\n"
Pokitto 65:deed4aa606fb 2024 "str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 2025 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2026 "lsls %[t], %[c], 24" "\n"
Pokitto 65:deed4aa606fb 2027 "lsrs %[c], %[c], 8" "\n"
Pokitto 65:deed4aa606fb 2028 "lsrs %[t], %[t], 23" "\n"
Pokitto 65:deed4aa606fb 2029 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2030 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2031 "ldrh %[t], [%[paletteptr], %[t]]" "\n"
Pokitto 65:deed4aa606fb 2032 "lsls %[t], 3" "\n"
Pokitto 65:deed4aa606fb 2033 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2034
Pokitto 65:deed4aa606fb 2035 "str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 2036 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2037 "lsls %[t], %[c], 24" "\n"
Pokitto 65:deed4aa606fb 2038 "lsrs %[t], %[t], 23" "\n"
Pokitto 65:deed4aa606fb 2039 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2040 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2041 "ldrh %[t], [%[paletteptr], %[t]]" "\n"
Pokitto 65:deed4aa606fb 2042 "lsls %[t], 3" "\n"
Pokitto 65:deed4aa606fb 2043 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2044 "str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 2045 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2046 "lsrs %[c], %[c], 8" "\n"
Pokitto 65:deed4aa606fb 2047 "lsls %[t], %[c], 1" "\n"
Pokitto 65:deed4aa606fb 2048 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2049 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2050 "ldrh %[t], [%[paletteptr], %[t]]" "\n"
Pokitto 65:deed4aa606fb 2051 "lsls %[t], 3" "\n"
Pokitto 65:deed4aa606fb 2052 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2053
Pokitto 65:deed4aa606fb 2054 "str %[t], [%[LCD], 0]" "\n"
Pokitto 65:deed4aa606fb 2055 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2056 "ldm %[scrbuf]!, {%[c]}" "\n"
Pokitto 65:deed4aa606fb 2057 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2058 "str %[TGL], [%[LCD], %[CLR]]" "\n"
Pokitto 65:deed4aa606fb 2059 "lsls %[t], %[c], 24" "\n"
Pokitto 65:deed4aa606fb 2060 "cmp %[scrbuf], %[end]" "\n"
Pokitto 65:deed4aa606fb 2061 "str %[TGL], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2062
Pokitto 65:deed4aa606fb 2063 "bne mode64loop%=" "\n"
Pokitto 65:deed4aa606fb 2064
Pokitto 65:deed4aa606fb 2065 : // outputs
Pokitto 65:deed4aa606fb 2066 [c]"+l" (c),
Pokitto 65:deed4aa606fb 2067 [t]"+l" (t),
Pokitto 65:deed4aa606fb 2068 [scrbuf]"+l" (scrbuf)
Pokitto 65:deed4aa606fb 2069
Pokitto 65:deed4aa606fb 2070 : // inputs
Pokitto 65:deed4aa606fb 2071 [CLR]"l" (CLR),
Pokitto 65:deed4aa606fb 2072 [TGL]"l" (TGL),
Pokitto 65:deed4aa606fb 2073 [LCD]"l" (0xA0002188),
Pokitto 65:deed4aa606fb 2074 [paletteptr]"l" (paletteptr),
Pokitto 65:deed4aa606fb 2075 [end]"h" (end)
Pokitto 65:deed4aa606fb 2076
Pokitto 65:deed4aa606fb 2077 : // clobbers
Pokitto 65:deed4aa606fb 2078 "cc"
Pokitto 65:deed4aa606fb 2079 );
Pokitto 65:deed4aa606fb 2080
Pokitto 65:deed4aa606fb 2081 #else
Pokitto 65:deed4aa606fb 2082
Pokitto 65:deed4aa606fb 2083 c = uint32_t(paletteptr[(*scrbuf)&255])<<3;
Pokitto 65:deed4aa606fb 2084 while( scrbuf < end-4 ){
Pokitto 65:deed4aa606fb 2085 *LCD = c; TGL_WR_OP(scrbuf++);TGL_WR_OP( c = uint32_t(paletteptr[(*scrbuf)&255])<<3 );
Pokitto 65:deed4aa606fb 2086 *LCD = c; TGL_WR_OP(scrbuf++);TGL_WR_OP( c = uint32_t(paletteptr[(*scrbuf)&255])<<3 );
Pokitto 65:deed4aa606fb 2087 *LCD = c; TGL_WR_OP(scrbuf++);TGL_WR_OP( c = uint32_t(paletteptr[(*scrbuf)&255])<<3 );
Pokitto 65:deed4aa606fb 2088 *LCD = c; TGL_WR_OP(scrbuf++);TGL_WR_OP( c = uint32_t(paletteptr[(*scrbuf)&255])<<3 );
Pokitto 65:deed4aa606fb 2089 }
Pokitto 65:deed4aa606fb 2090
Pokitto 65:deed4aa606fb 2091 #endif
Pokitto 65:deed4aa606fb 2092 }
Pokitto 65:deed4aa606fb 2093
Pokitto 65:deed4aa606fb 2094
Pokitto 65:deed4aa606fb 2095
Pokitto 46:e7e438368e16 2096 void Pokitto::lcdRefreshMode14(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 65:deed4aa606fb 2097 uint16_t x,y,data,xptr;
Pokitto 46:e7e438368e16 2098 uint16_t scanline[176]; uint16_t* scptr;
Pokitto 46:e7e438368e16 2099 uint8_t *d;
Pokitto 46:e7e438368e16 2100
Pokitto 46:e7e438368e16 2101 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 2102 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 2103 write_command(0x22);
Pokitto 46:e7e438368e16 2104 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 2105
Pokitto 46:e7e438368e16 2106 for(x=0;x<220;x++)
Pokitto 46:e7e438368e16 2107 {
Pokitto 46:e7e438368e16 2108 d = scrbuf+x;
Pokitto 46:e7e438368e16 2109 scptr = &scanline[0];
Pokitto 46:e7e438368e16 2110
Pokitto 46:e7e438368e16 2111 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 2112 /*for(y=0;y<22;y++)
Pokitto 46:e7e438368e16 2113 {
Pokitto 46:e7e438368e16 2114
Pokitto 46:e7e438368e16 2115 uint16_t t = *d;
Pokitto 46:e7e438368e16 2116 uint16_t t2 = *(d+POK_BITFRAME);
Pokitto 46:e7e438368e16 2117 uint16_t t3 = *(d+POK_BITFRAME+POK_BITFRAME);
Pokitto 46:e7e438368e16 2118
Pokitto 46:e7e438368e16 2119 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2120 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2121 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2122 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2123
Pokitto 46:e7e438368e16 2124 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2125 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2126 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2127 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 2128
Pokitto 46:e7e438368e16 2129
Pokitto 46:e7e438368e16 2130 d+=220; // jump to word directly below
Pokitto 46:e7e438368e16 2131 }
Pokitto 46:e7e438368e16 2132 */
Pokitto 46:e7e438368e16 2133 /** alternative way: go through one color at a time **/
Pokitto 46:e7e438368e16 2134 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 2135 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 2136 {
Pokitto 46:e7e438368e16 2137 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 2138
Pokitto 46:e7e438368e16 2139 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2140 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2141 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2142 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2143 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2144 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2145 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2146 *scptr++ = R_MASK * (t&0x1);
Pokitto 46:e7e438368e16 2147 }
Pokitto 46:e7e438368e16 2148 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 2149 d = scrbuf+x+POK_BITFRAME;
Pokitto 46:e7e438368e16 2150 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 2151 {
Pokitto 46:e7e438368e16 2152 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 2153
Pokitto 46:e7e438368e16 2154 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2155 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2156 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2157 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2158 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2159 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2160 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2161 *scptr++ |= G_MASK * (t&0x1);
Pokitto 46:e7e438368e16 2162 }
Pokitto 46:e7e438368e16 2163 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 2164 d = scrbuf+x+POK_BITFRAME*2;
Pokitto 46:e7e438368e16 2165 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 2166 {
Pokitto 46:e7e438368e16 2167 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 2168
Pokitto 46:e7e438368e16 2169 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2170 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2171 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2172 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2173 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2174 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2175 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 2176 *scptr++ |= B_MASK * (t&0x1);
Pokitto 46:e7e438368e16 2177 }
Pokitto 46:e7e438368e16 2178
Pokitto 46:e7e438368e16 2179
Pokitto 46:e7e438368e16 2180 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 2181 if (x<8) continue;
Pokitto 46:e7e438368e16 2182 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 2183 #endif
Pokitto 46:e7e438368e16 2184
Pokitto 46:e7e438368e16 2185 /** draw scanlines **/
Pokitto 46:e7e438368e16 2186 for (int s=0;s<176;) {
Pokitto 46:e7e438368e16 2187 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2188 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2189 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2190 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2191 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2192 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2193 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2194 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2195
Pokitto 46:e7e438368e16 2196 }
Pokitto 46:e7e438368e16 2197
Pokitto 46:e7e438368e16 2198 }
Pokitto 46:e7e438368e16 2199 }
Pokitto 46:e7e438368e16 2200
Pokitto 46:e7e438368e16 2201 //#define ADEKTOSMODE15
Pokitto 46:e7e438368e16 2202
Pokitto 46:e7e438368e16 2203 #ifdef ADEKTOSMODE15
Pokitto 46:e7e438368e16 2204 void Pokitto::lcdRefreshMode15(uint16_t* pal, uint8_t* scrbuf){
Pokitto 46:e7e438368e16 2205 write_command(0x03); write_data(0x1038); //realy only need to call this once
Pokitto 46:e7e438368e16 2206 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 2207 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 2208
Pokitto 46:e7e438368e16 2209 write_command(0x22);
Pokitto 46:e7e438368e16 2210
Pokitto 46:e7e438368e16 2211 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 2212 for (int x=0,xt=0; x<0x4BA0;x++,xt++) {
Pokitto 46:e7e438368e16 2213 if (xt==110) xt=0;
Pokitto 46:e7e438368e16 2214 if (xt<8) {
Pokitto 46:e7e438368e16 2215 write_data(0);
Pokitto 46:e7e438368e16 2216 write_data(0);
Pokitto 46:e7e438368e16 2217 } else {
Pokitto 46:e7e438368e16 2218 write_data(pal[(((scrbuf[x]) & 0xf0) >> 4)]);
Pokitto 46:e7e438368e16 2219 write_data(pal[( (scrbuf[x]) & 0x0f)]);
Pokitto 46:e7e438368e16 2220 }
Pokitto 46:e7e438368e16 2221
Pokitto 46:e7e438368e16 2222 }
Pokitto 46:e7e438368e16 2223 #else
Pokitto 46:e7e438368e16 2224 for (int x=0; x<0x4BA0;x++) {
Pokitto 46:e7e438368e16 2225 write_data(pal[(((scrbuf[x]) & 0xf0) >> 4)]);
Pokitto 46:e7e438368e16 2226 write_data(pal[( (scrbuf[x]) & 0x0f)]);
Pokitto 46:e7e438368e16 2227 }
Pokitto 46:e7e438368e16 2228 #endif //PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 2229 }
Pokitto 46:e7e438368e16 2230
Pokitto 46:e7e438368e16 2231 #else
Pokitto 46:e7e438368e16 2232
Pokitto 46:e7e438368e16 2233 void Pokitto::lcdRefreshMode15(uint16_t* paletteptr, uint8_t* scrbuf){
Pokitto 65:deed4aa606fb 2234 // #define __ARMCC_VERSION
Pokitto 65:deed4aa606fb 2235 #ifndef __ARMCC_VERSION
Pokitto 65:deed4aa606fb 2236
Pokitto 65:deed4aa606fb 2237 #define MODE15_LOOP \
Pokitto 65:deed4aa606fb 2238 "ands %[tmp], %[color]" "\n" \
Pokitto 65:deed4aa606fb 2239 "lsrs %[tmp], 2" "\n" \
Pokitto 65:deed4aa606fb 2240 "ldr %[tmp], [%[palette], %[tmp]]" "\n" \
Pokitto 65:deed4aa606fb 2241 "str %[tmp], [%[LCD]]" "\n" \
Pokitto 65:deed4aa606fb 2242 "str %[WRBit], [%[LCD], %[CLR]]" "\n" \
Pokitto 65:deed4aa606fb 2243 "movs %[tmp], 0x0F" "\n" \
Pokitto 65:deed4aa606fb 2244 "ands %[tmp], %[color]" "\n" \
Pokitto 65:deed4aa606fb 2245 "str %[WRBit], [%[LCD], 124]" "\n" \
Pokitto 65:deed4aa606fb 2246 "lsls %[tmp], 2" "\n" \
Pokitto 65:deed4aa606fb 2247 "ldr %[tmp], [%[palette], %[tmp]]" "\n" \
Pokitto 65:deed4aa606fb 2248 "str %[tmp], [%[LCD]]" "\n" \
Pokitto 65:deed4aa606fb 2249 "str %[WRBit], [%[LCD], %[CLR]]" "\n" \
Pokitto 65:deed4aa606fb 2250 "movs %[tmp], 0xF0" "\n" \
Pokitto 65:deed4aa606fb 2251 "lsrs %[color], 8" "\n" \
Pokitto 65:deed4aa606fb 2252 "str %[WRBit], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2253
Pokitto 65:deed4aa606fb 2254 #define MODE15_ENDLOOP \
Pokitto 65:deed4aa606fb 2255 "ands %[tmp], %[color]" "\n" \
Pokitto 65:deed4aa606fb 2256 "lsrs %[tmp], 2" "\n" \
Pokitto 65:deed4aa606fb 2257 "ldr %[tmp], [%[palette], %[tmp]]" "\n" \
Pokitto 65:deed4aa606fb 2258 "str %[tmp], [%[LCD]]" "\n" \
Pokitto 65:deed4aa606fb 2259 "str %[WRBit], [%[LCD], %[CLR]]" "\n" \
Pokitto 65:deed4aa606fb 2260 "movs %[tmp], 0x0F" "\n" \
Pokitto 65:deed4aa606fb 2261 "ands %[tmp], %[color]" "\n" \
Pokitto 65:deed4aa606fb 2262 "str %[WRBit], [%[LCD], 124]" "\n" \
Pokitto 65:deed4aa606fb 2263 "lsls %[tmp], 2" "\n" \
Pokitto 65:deed4aa606fb 2264 "ldr %[tmp], [%[palette], %[tmp]]" "\n" \
Pokitto 65:deed4aa606fb 2265 "str %[tmp], [%[LCD]]" "\n" \
Pokitto 65:deed4aa606fb 2266 "str %[WRBit], [%[LCD], %[CLR]]" "\n" \
Pokitto 65:deed4aa606fb 2267 "ldm %[scrbuf]!, {%[color]}" "\n" \
Pokitto 65:deed4aa606fb 2268 "movs %[tmp], 0xF0" "\n" \
Pokitto 65:deed4aa606fb 2269 "str %[WRBit], [%[LCD], 124]" "\n"
Pokitto 65:deed4aa606fb 2270
Pokitto 65:deed4aa606fb 2271 uint8_t *end=&scrbuf[POK_SCREENBUFFERSIZE]+4;
Pokitto 65:deed4aa606fb 2272 volatile uint32_t palette[16];
Pokitto 65:deed4aa606fb 2273 for( uint32_t i=0; i<16; ++i )
Pokitto 65:deed4aa606fb 2274 palette[i] = uint32_t(paletteptr[i]) << 3;
Pokitto 65:deed4aa606fb 2275
Pokitto 65:deed4aa606fb 2276 write_command(0x03); write_data(0x1038);
Pokitto 65:deed4aa606fb 2277 write_command(0x21); // Vertical DRAM Address
Pokitto 65:deed4aa606fb 2278 write_data(0);
Pokitto 65:deed4aa606fb 2279 write_command(0x20); // Horizontal DRAM Address
Pokitto 65:deed4aa606fb 2280 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 65:deed4aa606fb 2281 write_data(8);
Pokitto 65:deed4aa606fb 2282 scrbuf += 110*8;
Pokitto 65:deed4aa606fb 2283 #else
Pokitto 65:deed4aa606fb 2284 write_data(0);
Pokitto 65:deed4aa606fb 2285 #endif
Pokitto 65:deed4aa606fb 2286 write_command(0x22); // write data to DRAM
Pokitto 65:deed4aa606fb 2287 CLR_CS_SET_CD_RD_WR;
Pokitto 65:deed4aa606fb 2288
Pokitto 65:deed4aa606fb 2289
Pokitto 65:deed4aa606fb 2290 SET_MASK_P2;
Pokitto 65:deed4aa606fb 2291
Pokitto 65:deed4aa606fb 2292 uint32_t WRBit = 1<<12, color, tmp;
Pokitto 65:deed4aa606fb 2293 asm volatile(
Pokitto 65:deed4aa606fb 2294 ".syntax unified" "\n"
Pokitto 65:deed4aa606fb 2295 "ldm %[scrbuf]!, {%[color]}" "\n"
Pokitto 65:deed4aa606fb 2296 "movs %[tmp], 0xF0" "\n"
Pokitto 65:deed4aa606fb 2297 "mode15Loop%=:" "\n"
Pokitto 65:deed4aa606fb 2298 MODE15_LOOP
Pokitto 65:deed4aa606fb 2299 MODE15_LOOP
Pokitto 65:deed4aa606fb 2300 MODE15_LOOP
Pokitto 65:deed4aa606fb 2301 MODE15_ENDLOOP
Pokitto 65:deed4aa606fb 2302 "cmp %[end], %[scrbuf]" "\n"
Pokitto 65:deed4aa606fb 2303 "bne mode15Loop%=" "\n"
Pokitto 65:deed4aa606fb 2304 :
Pokitto 65:deed4aa606fb 2305 [tmp]"+l" (tmp),
Pokitto 65:deed4aa606fb 2306 [color]"+l" (color),
Pokitto 65:deed4aa606fb 2307 [end]"+h" (end),
Pokitto 65:deed4aa606fb 2308 [scrbuf]"+l" (scrbuf),
Pokitto 65:deed4aa606fb 2309 [WRBit]"+l" (WRBit)
Pokitto 65:deed4aa606fb 2310
Pokitto 65:deed4aa606fb 2311 :
Pokitto 65:deed4aa606fb 2312 [CLR]"l" (252),
Pokitto 65:deed4aa606fb 2313 [LCD]"l" (0xA0002188),
Pokitto 65:deed4aa606fb 2314 [palette]"l" (palette)
Pokitto 65:deed4aa606fb 2315
Pokitto 65:deed4aa606fb 2316 :
Pokitto 65:deed4aa606fb 2317 "cc"
Pokitto 65:deed4aa606fb 2318 );
Pokitto 65:deed4aa606fb 2319
Pokitto 65:deed4aa606fb 2320 #else
Pokitto 65:deed4aa606fb 2321
Pokitto 65:deed4aa606fb 2322 uint16_t x,y,xptr;
Pokitto 46:e7e438368e16 2323 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 65:deed4aa606fb 2324 uint8_t *d, yoffset=0;
Pokitto 46:e7e438368e16 2325
Pokitto 65:deed4aa606fb 2326 xptr = 0;
Pokitto 46:e7e438368e16 2327 //setDRAMptr(xptr,yoffset);
Pokitto 46:e7e438368e16 2328
Pokitto 46:e7e438368e16 2329 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 2330 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 2331 write_command(0x22);
Pokitto 46:e7e438368e16 2332 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 2333
Pokitto 46:e7e438368e16 2334 for(x=0;x<220;x+=2)
Pokitto 46:e7e438368e16 2335 {
Pokitto 46:e7e438368e16 2336 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 46:e7e438368e16 2337 // find colours in one scanline
Pokitto 46:e7e438368e16 2338 uint8_t s=0;
Pokitto 46:e7e438368e16 2339 for(y=0;y<176;y++)
Pokitto 46:e7e438368e16 2340 {
Pokitto 46:e7e438368e16 2341 uint8_t t = *d >> 4; // higher nibble
Pokitto 46:e7e438368e16 2342 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 46:e7e438368e16 2343 // higher nibble = left pixel in pixel pair
Pokitto 46:e7e438368e16 2344 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 2345 scanline[1][s++] = paletteptr[t2];
Pokitto 46:e7e438368e16 2346
Pokitto 46:e7e438368e16 2347 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 2348 }
Pokitto 46:e7e438368e16 2349 s=0;
Pokitto 46:e7e438368e16 2350 // draw scanlines
Pokitto 46:e7e438368e16 2351
Pokitto 46:e7e438368e16 2352 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 2353 if (x<8) continue;
Pokitto 46:e7e438368e16 2354 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 2355 #endif
Pokitto 46:e7e438368e16 2356
Pokitto 46:e7e438368e16 2357 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 2358 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2359 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2360 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2361 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2362 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2363 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2364 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2365 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2366 }
Pokitto 46:e7e438368e16 2367
Pokitto 46:e7e438368e16 2368 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 2369 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2370 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2371 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2372 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2373 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2374 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2375 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2376 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2377 }
Pokitto 46:e7e438368e16 2378 }
Pokitto 65:deed4aa606fb 2379
Pokitto 65:deed4aa606fb 2380 #endif
Pokitto 65:deed4aa606fb 2381
Pokitto 46:e7e438368e16 2382 }
Pokitto 46:e7e438368e16 2383 #endif //ADEKTOSMODE15
Pokitto 46:e7e438368e16 2384
Pokitto 65:deed4aa606fb 2385 void Pokitto::lcdRefreshMixMode(const uint8_t * screenBuffer, const uint16_t * palettePointer, const uint8_t * scanType)
Pokitto 65:deed4aa606fb 2386 {
Pokitto 65:deed4aa606fb 2387 write_command(0x03);
Pokitto 65:deed4aa606fb 2388 write_data(0x1038);
Pokitto 65:deed4aa606fb 2389
Pokitto 65:deed4aa606fb 2390 // Horizontal DRAM Address
Pokitto 65:deed4aa606fb 2391 write_command(0x20);
Pokitto 65:deed4aa606fb 2392 write_data(0);
Pokitto 65:deed4aa606fb 2393
Pokitto 65:deed4aa606fb 2394 // Vertical DRAM Address
Pokitto 65:deed4aa606fb 2395 write_command(0x21);
Pokitto 65:deed4aa606fb 2396 write_data(0);
Pokitto 65:deed4aa606fb 2397
Pokitto 65:deed4aa606fb 2398 // write data to DRAM
Pokitto 65:deed4aa606fb 2399 write_command(0x22);
Pokitto 65:deed4aa606fb 2400 CLR_CS_SET_CD_RD_WR;
Pokitto 65:deed4aa606fb 2401 SET_MASK_P2;
Pokitto 65:deed4aa606fb 2402
Pokitto 65:deed4aa606fb 2403 uint32_t scanline[220];
Pokitto 65:deed4aa606fb 2404
Pokitto 65:deed4aa606fb 2405 // point to beginning of line in data
Pokitto 65:deed4aa606fb 2406 const uint8_t * d = screenBuffer;
Pokitto 65:deed4aa606fb 2407 for(uint32_t y = 0; y < 176; ++y)
Pokitto 65:deed4aa606fb 2408 {
Pokitto 65:deed4aa606fb 2409 // find colours in one scanline
Pokitto 65:deed4aa606fb 2410 uint8_t scanTypeIndex = y >> 1;
Pokitto 65:deed4aa606fb 2411 uint8_t lineIndex = 0;
Pokitto 65:deed4aa606fb 2412 switch(scanType[scanTypeIndex])
Pokitto 65:deed4aa606fb 2413 {
Pokitto 65:deed4aa606fb 2414 case 0:
Pokitto 65:deed4aa606fb 2415 {
Pokitto 65:deed4aa606fb 2416 // point to beginning of line in data
Pokitto 65:deed4aa606fb 2417 d = &screenBuffer[110 * scanTypeIndex];
Pokitto 65:deed4aa606fb 2418 for(uint8_t x = 0; x < (220 / 2); ++x)
Pokitto 65:deed4aa606fb 2419 {
Pokitto 65:deed4aa606fb 2420 uint32_t color = static_cast<uint32_t>(palettePointer[*d]) << 3;
Pokitto 65:deed4aa606fb 2421 ++d;
Pokitto 65:deed4aa606fb 2422 scanline[lineIndex] = color;
Pokitto 65:deed4aa606fb 2423 ++lineIndex;
Pokitto 65:deed4aa606fb 2424 scanline[lineIndex] = color;
Pokitto 65:deed4aa606fb 2425 ++lineIndex;
Pokitto 65:deed4aa606fb 2426 }
Pokitto 65:deed4aa606fb 2427 break;
Pokitto 65:deed4aa606fb 2428 }
Pokitto 65:deed4aa606fb 2429 case 1:
Pokitto 65:deed4aa606fb 2430 {
Pokitto 65:deed4aa606fb 2431 for(uint8_t x = 0; x < (220 / 4); ++x)
Pokitto 65:deed4aa606fb 2432 {
Pokitto 65:deed4aa606fb 2433 uint8_t t = *d;
Pokitto 65:deed4aa606fb 2434 ++d;
Pokitto 65:deed4aa606fb 2435
Pokitto 65:deed4aa606fb 2436 uint32_t color1 = static_cast<uint32_t>(palettePointer[256 + (t >> 4)]) << 3;
Pokitto 65:deed4aa606fb 2437 scanline[lineIndex] = color1;
Pokitto 65:deed4aa606fb 2438 ++lineIndex;
Pokitto 65:deed4aa606fb 2439 scanline[lineIndex] = color1;
Pokitto 65:deed4aa606fb 2440 ++lineIndex;
Pokitto 65:deed4aa606fb 2441
Pokitto 65:deed4aa606fb 2442 uint32_t color2 = static_cast<uint32_t>(palettePointer[256 + (t & 0xF)]) << 3;
Pokitto 65:deed4aa606fb 2443 scanline[lineIndex] = color2;
Pokitto 65:deed4aa606fb 2444 ++lineIndex;
Pokitto 65:deed4aa606fb 2445 scanline[lineIndex] = color2;
Pokitto 65:deed4aa606fb 2446 ++lineIndex;
Pokitto 65:deed4aa606fb 2447 }
Pokitto 65:deed4aa606fb 2448 break;
Pokitto 65:deed4aa606fb 2449 }
Pokitto 65:deed4aa606fb 2450 case 2:
Pokitto 65:deed4aa606fb 2451 {
Pokitto 65:deed4aa606fb 2452 for(uint8_t x = 0; x < (220 / 4); ++x)
Pokitto 65:deed4aa606fb 2453 {
Pokitto 65:deed4aa606fb 2454 uint8_t t = *d;
Pokitto 65:deed4aa606fb 2455 ++d;
Pokitto 65:deed4aa606fb 2456
Pokitto 65:deed4aa606fb 2457 scanline[lineIndex] = static_cast<uint32_t>(palettePointer[272 + ((t >> 6) & 0x03)]) << 3;
Pokitto 65:deed4aa606fb 2458 ++lineIndex;
Pokitto 65:deed4aa606fb 2459
Pokitto 65:deed4aa606fb 2460 scanline[lineIndex] = static_cast<uint32_t>(palettePointer[272 + ((t >> 4) & 0x03)]) << 3;
Pokitto 65:deed4aa606fb 2461 ++lineIndex;
Pokitto 65:deed4aa606fb 2462
Pokitto 65:deed4aa606fb 2463 scanline[lineIndex] = static_cast<uint32_t>(palettePointer[272 + ((t >> 2) & 0x03)]) << 3;
Pokitto 65:deed4aa606fb 2464 ++lineIndex;
Pokitto 65:deed4aa606fb 2465
Pokitto 65:deed4aa606fb 2466 scanline[lineIndex] = static_cast<uint32_t>(palettePointer[272 + ((t >> 0) & 0x03)]) << 3;
Pokitto 65:deed4aa606fb 2467 ++lineIndex;
Pokitto 65:deed4aa606fb 2468 }
Pokitto 65:deed4aa606fb 2469 break;
Pokitto 65:deed4aa606fb 2470 }
Pokitto 65:deed4aa606fb 2471 }
Pokitto 65:deed4aa606fb 2472
Pokitto 65:deed4aa606fb 2473 uint32_t color = scanline[0];
Pokitto 65:deed4aa606fb 2474 #define WRITE_SCANLINE *LCD = color; TGL_WR_OP(color = scanline[++i]);
Pokitto 65:deed4aa606fb 2475
Pokitto 65:deed4aa606fb 2476 volatile uint32_t * LCD = reinterpret_cast< volatile uint32_t * >(0xA0002188);
Pokitto 65:deed4aa606fb 2477 for (uint8_t i = 0; i < 220;)
Pokitto 65:deed4aa606fb 2478 {
Pokitto 65:deed4aa606fb 2479 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2480 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2481 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2482 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2483 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2484 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2485 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2486 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2487 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2488 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2489 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2490 WRITE_SCANLINE WRITE_SCANLINE WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2491 }
Pokitto 65:deed4aa606fb 2492
Pokitto 65:deed4aa606fb 2493 #undef WRITE_SCANLINE
Pokitto 65:deed4aa606fb 2494 }
Pokitto 65:deed4aa606fb 2495
Pokitto 65:deed4aa606fb 2496 CLR_MASK_P2;
Pokitto 65:deed4aa606fb 2497 }
Pokitto 65:deed4aa606fb 2498
Pokitto 65:deed4aa606fb 2499
Pokitto 46:e7e438368e16 2500 void Pokitto::blitWord(uint16_t c) {
Pokitto 46:e7e438368e16 2501 setup_data_16(c);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2502 }
Pokitto 46:e7e438368e16 2503
Pokitto 46:e7e438368e16 2504
Pokitto 65:deed4aa606fb 2505