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

Committer:
Pokitto
Date:
Tue May 01 18:42:56 2018 +0000
Revision:
43:6183b12dd99c
New volume control;

Who changed what in which revision?

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