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

Committer:
Pokitto
Date:
Mon Apr 02 22:37:22 2018 +0000
Revision:
36:771321e70814
Synced with Github repo

Who changed what in which revision?

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