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

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Fri Dec 29 02:55:34 2017 +0000
Revision:
22:e826f80d8582
Child:
23:f88837b8f914
PokittoLib with @Spinalcodes direct non-buffered tricks

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 22:e826f80d8582 1 /**************************************************************************/
Pokitto 22:e826f80d8582 2 /*!
Pokitto 22:e826f80d8582 3 @file HWLCD.cpp
Pokitto 22:e826f80d8582 4 @author Jonne Valola
Pokitto 22:e826f80d8582 5
Pokitto 22:e826f80d8582 6 @section LICENSE
Pokitto 22:e826f80d8582 7
Pokitto 22:e826f80d8582 8 Software License Agreement (BSD License)
Pokitto 22:e826f80d8582 9
Pokitto 22:e826f80d8582 10 Copyright (c) 2016, Jonne Valola
Pokitto 22:e826f80d8582 11 All rights reserved.
Pokitto 22:e826f80d8582 12
Pokitto 22:e826f80d8582 13 Redistribution and use in source and binary forms, with or without
Pokitto 22:e826f80d8582 14 modification, are permitted provided that the following conditions are met:
Pokitto 22:e826f80d8582 15 1. Redistributions of source code must retain the above copyright
Pokitto 22:e826f80d8582 16 notice, this list of conditions and the following disclaimer.
Pokitto 22:e826f80d8582 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 22:e826f80d8582 18 notice, this list of conditions and the following disclaimer in the
Pokitto 22:e826f80d8582 19 documentation and/or other materials provided with the distribution.
Pokitto 22:e826f80d8582 20 3. Neither the name of the copyright holders nor the
Pokitto 22:e826f80d8582 21 names of its contributors may be used to endorse or promote products
Pokitto 22:e826f80d8582 22 derived from this software without specific prior written permission.
Pokitto 22:e826f80d8582 23
Pokitto 22:e826f80d8582 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 22:e826f80d8582 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 22:e826f80d8582 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 22:e826f80d8582 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 22:e826f80d8582 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 22:e826f80d8582 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 22:e826f80d8582 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 22:e826f80d8582 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 22:e826f80d8582 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 22:e826f80d8582 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 22:e826f80d8582 34 */
Pokitto 22:e826f80d8582 35 /**************************************************************************/
Pokitto 22:e826f80d8582 36
Pokitto 22:e826f80d8582 37 #include "HWLCD.h" //HWLCD.h" #include "HWLCD.h"
Pokitto 22:e826f80d8582 38 #include "Pokitto_settings.h"
Pokitto 22:e826f80d8582 39
Pokitto 22:e826f80d8582 40 #define AB_JUMP 1024 // jump one 1-bit Arduboy screen forward to get next color bit
Pokitto 22:e826f80d8582 41 #define GB_JUMP 504 // jump one 1-bit Gamebuino screen forward to get next color bit
Pokitto 22:e826f80d8582 42
Pokitto 22:e826f80d8582 43 using namespace Pokitto;
Pokitto 22:e826f80d8582 44
Pokitto 22:e826f80d8582 45 uint16_t prevdata=0; // if data does not change, do not adjust LCD bus lines
Pokitto 22:e826f80d8582 46
Pokitto 22:e826f80d8582 47 #if POK_BOARDREV == 2
Pokitto 22:e826f80d8582 48 pwmout_t backlightpwm;
Pokitto 22:e826f80d8582 49 #endif
Pokitto 22:e826f80d8582 50
Pokitto 22:e826f80d8582 51
Pokitto 22:e826f80d8582 52 /**************************************************************************/
Pokitto 22:e826f80d8582 53 /*!
Pokitto 22:e826f80d8582 54 @brief set up the 16-bit bus
Pokitto 22:e826f80d8582 55 */
Pokitto 22:e826f80d8582 56 /**************************************************************************/
Pokitto 22:e826f80d8582 57
Pokitto 22:e826f80d8582 58 static inline void setup_data_16(uint16_t data)
Pokitto 22:e826f80d8582 59 {
Pokitto 22:e826f80d8582 60 uint32_t p2=0;
Pokitto 22:e826f80d8582 61
Pokitto 22:e826f80d8582 62 if (data != prevdata) {
Pokitto 22:e826f80d8582 63
Pokitto 22:e826f80d8582 64 prevdata=data;
Pokitto 22:e826f80d8582 65
Pokitto 22:e826f80d8582 66 /** D0...D16 = P2_3 ... P2_18 **/
Pokitto 22:e826f80d8582 67 p2 = data << 3;
Pokitto 22:e826f80d8582 68
Pokitto 22:e826f80d8582 69 //__disable_irq(); // Disable Interrupts
Pokitto 22:e826f80d8582 70 SET_MASK_P2;
Pokitto 22:e826f80d8582 71 LPC_GPIO_PORT->MPIN[2] = p2; // write bits to port
Pokitto 22:e826f80d8582 72 CLR_MASK_P2;
Pokitto 22:e826f80d8582 73 //__enable_irq(); // Enable Interrupts
Pokitto 22:e826f80d8582 74 }
Pokitto 22:e826f80d8582 75 }
Pokitto 22:e826f80d8582 76
Pokitto 22:e826f80d8582 77
Pokitto 22:e826f80d8582 78 /**************************************************************************/
Pokitto 22:e826f80d8582 79 /*!
Pokitto 22:e826f80d8582 80 @brief Write a command to the lcd, 16-bit bus
Pokitto 22:e826f80d8582 81 */
Pokitto 22:e826f80d8582 82 /**************************************************************************/
Pokitto 22:e826f80d8582 83 inline void write_command_16(uint16_t data)
Pokitto 22:e826f80d8582 84 {
Pokitto 22:e826f80d8582 85 CLR_CS; // select lcd
Pokitto 22:e826f80d8582 86 CLR_CD; // clear CD = command
Pokitto 22:e826f80d8582 87 SET_RD; // RD high, do not read
Pokitto 22:e826f80d8582 88 setup_data_16(data); // function that inputs the data into the relevant bus lines
Pokitto 22:e826f80d8582 89 CLR_WR; // WR low
Pokitto 22:e826f80d8582 90 SET_WR; // WR low, then high = write strobe
Pokitto 22:e826f80d8582 91 SET_CS; // de-select lcd
Pokitto 22:e826f80d8582 92 }
Pokitto 22:e826f80d8582 93
Pokitto 22:e826f80d8582 94 /**************************************************************************/
Pokitto 22:e826f80d8582 95 /*!
Pokitto 22:e826f80d8582 96 @brief Write data to the lcd, 16-bit bus
Pokitto 22:e826f80d8582 97 */
Pokitto 22:e826f80d8582 98 /**************************************************************************/
Pokitto 22:e826f80d8582 99 inline void write_data_16(uint16_t data)
Pokitto 22:e826f80d8582 100 {
Pokitto 22:e826f80d8582 101 CLR_CS;
Pokitto 22:e826f80d8582 102 SET_CD;
Pokitto 22:e826f80d8582 103 SET_RD;
Pokitto 22:e826f80d8582 104 setup_data_16(data);
Pokitto 22:e826f80d8582 105 CLR_WR;
Pokitto 22:e826f80d8582 106 SET_WR;
Pokitto 22:e826f80d8582 107 SET_CS;
Pokitto 22:e826f80d8582 108 }
Pokitto 22:e826f80d8582 109
Pokitto 22:e826f80d8582 110 /**************************************************************************/
Pokitto 22:e826f80d8582 111 /*!
Pokitto 22:e826f80d8582 112 @brief Point to a (x,y) location in the LCD DRAM
Pokitto 22:e826f80d8582 113 */
Pokitto 22:e826f80d8582 114 /**************************************************************************/
Pokitto 22:e826f80d8582 115 static inline void setDRAMptr(uint8_t xptr, uint8_t yoffset)
Pokitto 22:e826f80d8582 116 {
Pokitto 22:e826f80d8582 117 write_command(0x20); // Vertical DRAM Address
Pokitto 22:e826f80d8582 118 write_data(yoffset);
Pokitto 22:e826f80d8582 119 write_command(0x21); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 120 write_data(xptr); //
Pokitto 22:e826f80d8582 121 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 122 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 123 }
Pokitto 22:e826f80d8582 124
Pokitto 22:e826f80d8582 125 void Pokitto::initBacklight() {
Pokitto 22:e826f80d8582 126 #if POK_BOARDREV == 2
Pokitto 22:e826f80d8582 127 pwmout_init(&backlightpwm,POK_BACKLIGHT_PIN);
Pokitto 22:e826f80d8582 128 pwmout_period_us(&backlightpwm,5);
Pokitto 22:e826f80d8582 129 pwmout_write(&backlightpwm,POK_BACKLIGHT_INITIALVALUE);
Pokitto 22:e826f80d8582 130 #endif
Pokitto 22:e826f80d8582 131 }
Pokitto 22:e826f80d8582 132
Pokitto 22:e826f80d8582 133 void Pokitto::setBacklight(float value) {
Pokitto 22:e826f80d8582 134 if (value>0.999f) value = 0.999f;
Pokitto 22:e826f80d8582 135 pwmout_write(&backlightpwm,value);
Pokitto 22:e826f80d8582 136 }
Pokitto 22:e826f80d8582 137
Pokitto 22:e826f80d8582 138 void Pokitto::lcdInit() {
Pokitto 22:e826f80d8582 139 initBacklight();
Pokitto 22:e826f80d8582 140
Pokitto 22:e826f80d8582 141 SET_RESET;
Pokitto 22:e826f80d8582 142 wait_ms(10);
Pokitto 22:e826f80d8582 143 CLR_RESET;
Pokitto 22:e826f80d8582 144 wait_ms(10);
Pokitto 22:e826f80d8582 145 SET_RESET;
Pokitto 22:e826f80d8582 146 wait_ms(10);
Pokitto 22:e826f80d8582 147 //************* Start Initial Sequence **********//
Pokitto 22:e826f80d8582 148 write_command(0x01); // driver output control, this also affects direction
Pokitto 22:e826f80d8582 149 write_data(0x11C); // originally: 0x11C 100011100 SS,NL4,NL3,NL2
Pokitto 22:e826f80d8582 150 // NL4...0 is the number of scan lines to drive the screen !!!
Pokitto 22:e826f80d8582 151 // so 11100 is 1c = 220 lines, correct
Pokitto 22:e826f80d8582 152 // test 1: 0x1C 11100 SS=0,NL4,NL3,NL2 -> no effect
Pokitto 22:e826f80d8582 153 // test 2: 0x31C 1100011100 GS=1,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 22:e826f80d8582 154 // test 3: 0x51C 10100011100 SM=1,GS=0,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 22:e826f80d8582 155 // test 4: 0x71C SM=1,GS=1,SS=1,NL4,NL3,NL2
Pokitto 22:e826f80d8582 156 // test 5: 0x
Pokitto 22:e826f80d8582 157 // seems to have no effect... is this perhaps only for RGB mode ?
Pokitto 22:e826f80d8582 158
Pokitto 22:e826f80d8582 159 write_command(0x02); // LCD driving control
Pokitto 22:e826f80d8582 160 write_data(0x0100); // INV = 1
Pokitto 22:e826f80d8582 161
Pokitto 22:e826f80d8582 162 write_command(0x03); // Entry mode... lets try if this affects the direction
Pokitto 22:e826f80d8582 163 write_data(0x1030); // originally 0x1030 1000000110000 BGR,ID1,ID0
Pokitto 22:e826f80d8582 164 // test 1: 0x1038 1000000111000 BGR,ID1,ID0,AM=1 ->drawing DRAM horizontally
Pokitto 22:e826f80d8582 165 // test 4: am=1, id0=0, id1=0, 1000000001000,0x1008 -> same as above, but flipped on long
Pokitto 22:e826f80d8582 166 // test 2: am=0, id0=0, 1000000100000, 0x1020 -> flipped on long axis
Pokitto 22:e826f80d8582 167 // test 3: am=0, id1=0, 1000000010000, 0x1010 -> picture flowed over back to screen
Pokitto 22:e826f80d8582 168
Pokitto 22:e826f80d8582 169
Pokitto 22:e826f80d8582 170 write_command(0x08); // Display control 2
Pokitto 22:e826f80d8582 171 write_data(0x0808); // 100000001000 FP2,BP2
Pokitto 22:e826f80d8582 172
Pokitto 22:e826f80d8582 173 write_command(0x0C); // RGB display interface
Pokitto 22:e826f80d8582 174 write_data(0x0000); // all off
Pokitto 22:e826f80d8582 175
Pokitto 22:e826f80d8582 176 write_command(0x0F); // Frame marker position
Pokitto 22:e826f80d8582 177 write_data(0x0001); // OSC_EN
Pokitto 22:e826f80d8582 178
Pokitto 22:e826f80d8582 179 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 180 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 181
Pokitto 22:e826f80d8582 182 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 183 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 184
Pokitto 22:e826f80d8582 185 //*************Power On sequence ****************//
Pokitto 22:e826f80d8582 186 write_command(0x10);
Pokitto 22:e826f80d8582 187 write_data(0x0000);
Pokitto 22:e826f80d8582 188
Pokitto 22:e826f80d8582 189 write_command(0x11);
Pokitto 22:e826f80d8582 190 write_data(0x1000);
Pokitto 22:e826f80d8582 191 wait_ms(10);
Pokitto 22:e826f80d8582 192 //------------------------ Set GRAM area --------------------------------//
Pokitto 22:e826f80d8582 193 write_command(0x30); // Gate scan position
Pokitto 22:e826f80d8582 194 write_data(0x0000); // if GS=0, 00h=G1, else 00h=G220
Pokitto 22:e826f80d8582 195
Pokitto 22:e826f80d8582 196 write_command(0x31); // Vertical scroll control
Pokitto 22:e826f80d8582 197 write_data(0x00DB); // scroll start line 11011011 = 219
Pokitto 22:e826f80d8582 198
Pokitto 22:e826f80d8582 199 write_command(0x32); // Vertical scroll control
Pokitto 22:e826f80d8582 200 write_data(0x0000); // scroll end line 0
Pokitto 22:e826f80d8582 201
Pokitto 22:e826f80d8582 202 write_command(0x33); // Vertical scroll control
Pokitto 22:e826f80d8582 203 write_data(0x0000); // 0=vertical scroll disabled
Pokitto 22:e826f80d8582 204
Pokitto 22:e826f80d8582 205 write_command(0x34); // Partial screen driving control
Pokitto 22:e826f80d8582 206 write_data(0x00DB); // db = full screen (end)
Pokitto 22:e826f80d8582 207
Pokitto 22:e826f80d8582 208 write_command(0x35); // partial screen
Pokitto 22:e826f80d8582 209 write_data(0x0000); // 0 = start
Pokitto 22:e826f80d8582 210
Pokitto 22:e826f80d8582 211 write_command(0x36); // Horizontal and vertical RAM position
Pokitto 22:e826f80d8582 212 write_data(0x00AF); //end address 175
Pokitto 22:e826f80d8582 213
Pokitto 22:e826f80d8582 214 write_command(0x37);
Pokitto 22:e826f80d8582 215 write_data(0x0000); // start address 0
Pokitto 22:e826f80d8582 216
Pokitto 22:e826f80d8582 217 write_command(0x38);
Pokitto 22:e826f80d8582 218 write_data(0x00DB); //end address 219
Pokitto 22:e826f80d8582 219
Pokitto 22:e826f80d8582 220 write_command(0x39); // start address 0
Pokitto 22:e826f80d8582 221 write_data(0x0000);
Pokitto 22:e826f80d8582 222 wait_ms(10);
Pokitto 22:e826f80d8582 223 write_command(0xff); // start gamma register control
Pokitto 22:e826f80d8582 224 write_data(0x0003);
Pokitto 22:e826f80d8582 225
Pokitto 22:e826f80d8582 226 // ----------- Adjust the Gamma Curve ----------//
Pokitto 22:e826f80d8582 227 write_command(0x50);
Pokitto 22:e826f80d8582 228 write_data(0x0203);
Pokitto 22:e826f80d8582 229
Pokitto 22:e826f80d8582 230 write_command(0x051);
Pokitto 22:e826f80d8582 231 write_data(0x0A09);
Pokitto 22:e826f80d8582 232
Pokitto 22:e826f80d8582 233 write_command(0x52);
Pokitto 22:e826f80d8582 234 write_data(0x0005);
Pokitto 22:e826f80d8582 235
Pokitto 22:e826f80d8582 236 write_command(0x53);
Pokitto 22:e826f80d8582 237 write_data(0x1021);
Pokitto 22:e826f80d8582 238
Pokitto 22:e826f80d8582 239 write_command(0x54);
Pokitto 22:e826f80d8582 240 write_data(0x0602);
Pokitto 22:e826f80d8582 241
Pokitto 22:e826f80d8582 242 write_command(0x55);
Pokitto 22:e826f80d8582 243 write_data(0x0003);
Pokitto 22:e826f80d8582 244
Pokitto 22:e826f80d8582 245 write_command(0x56);
Pokitto 22:e826f80d8582 246 write_data(0x0703);
Pokitto 22:e826f80d8582 247
Pokitto 22:e826f80d8582 248 write_command(0x57);
Pokitto 22:e826f80d8582 249 write_data(0x0507);
Pokitto 22:e826f80d8582 250
Pokitto 22:e826f80d8582 251 write_command(0x58);
Pokitto 22:e826f80d8582 252 write_data(0x1021);
Pokitto 22:e826f80d8582 253
Pokitto 22:e826f80d8582 254 write_command(0x59);
Pokitto 22:e826f80d8582 255 write_data(0x0703);
Pokitto 22:e826f80d8582 256
Pokitto 22:e826f80d8582 257 write_command(0xB0);
Pokitto 22:e826f80d8582 258 write_data(0x2501);
Pokitto 22:e826f80d8582 259
Pokitto 22:e826f80d8582 260 write_command(0xFF);
Pokitto 22:e826f80d8582 261 write_data(0x0000);
Pokitto 22:e826f80d8582 262
Pokitto 22:e826f80d8582 263 write_command(0x07);
Pokitto 22:e826f80d8582 264 write_data(0x1017);
Pokitto 22:e826f80d8582 265 wait_ms(200);
Pokitto 22:e826f80d8582 266 write_command(0x22);
Pokitto 22:e826f80d8582 267
Pokitto 22:e826f80d8582 268 lcdClear();
Pokitto 22:e826f80d8582 269 }
Pokitto 22:e826f80d8582 270
Pokitto 22:e826f80d8582 271 void Pokitto::lcdSleep(void){
Pokitto 22:e826f80d8582 272 write_command(0xFF);
Pokitto 22:e826f80d8582 273 write_data(0x0000);
Pokitto 22:e826f80d8582 274
Pokitto 22:e826f80d8582 275 write_command(0x07);
Pokitto 22:e826f80d8582 276 write_data(0x0000);
Pokitto 22:e826f80d8582 277 wait_ms(50);
Pokitto 22:e826f80d8582 278 write_command(0x10);// Enter Standby mode
Pokitto 22:e826f80d8582 279 write_data(0x0003);
Pokitto 22:e826f80d8582 280 wait_ms(200);
Pokitto 22:e826f80d8582 281
Pokitto 22:e826f80d8582 282 }
Pokitto 22:e826f80d8582 283
Pokitto 22:e826f80d8582 284 void Pokitto::lcdWakeUp (void){
Pokitto 22:e826f80d8582 285
Pokitto 22:e826f80d8582 286 wait_ms(200);
Pokitto 22:e826f80d8582 287 write_command(0xFF);
Pokitto 22:e826f80d8582 288 write_data(0x0000);
Pokitto 22:e826f80d8582 289
Pokitto 22:e826f80d8582 290 write_command(0x10);// Exit Sleep/ Standby mode
Pokitto 22:e826f80d8582 291 write_data(0x0000);
Pokitto 22:e826f80d8582 292 wait_ms(50);
Pokitto 22:e826f80d8582 293 write_command(0x07);
Pokitto 22:e826f80d8582 294 write_data(0x0117);
Pokitto 22:e826f80d8582 295 wait_ms(200);
Pokitto 22:e826f80d8582 296 }
Pokitto 22:e826f80d8582 297
Pokitto 22:e826f80d8582 298 void Pokitto::lcdFillSurface(uint16_t c) {
Pokitto 22:e826f80d8582 299 uint32_t i;
Pokitto 22:e826f80d8582 300 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 301 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 302 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 303 write_data(0);
Pokitto 22:e826f80d8582 304 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 305 setup_data_16(c);
Pokitto 22:e826f80d8582 306 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 307 for(i=0;i<220*176;i++)
Pokitto 22:e826f80d8582 308 {
Pokitto 22:e826f80d8582 309 CLR_WR;
Pokitto 22:e826f80d8582 310 SET_WR;
Pokitto 22:e826f80d8582 311 }
Pokitto 22:e826f80d8582 312 }
Pokitto 22:e826f80d8582 313
Pokitto 22:e826f80d8582 314 void Pokitto::lcdClear() {
Pokitto 22:e826f80d8582 315 uint32_t i;
Pokitto 22:e826f80d8582 316 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 317 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 318 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 319 write_data(0);
Pokitto 22:e826f80d8582 320 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 321 setup_data_16(0x0000);
Pokitto 22:e826f80d8582 322 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 323 for(i=0;i<220*176;i++)
Pokitto 22:e826f80d8582 324 {
Pokitto 22:e826f80d8582 325 CLR_WR;
Pokitto 22:e826f80d8582 326 SET_WR;
Pokitto 22:e826f80d8582 327 }
Pokitto 22:e826f80d8582 328 }
Pokitto 22:e826f80d8582 329
Pokitto 22:e826f80d8582 330 void Pokitto::setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
Pokitto 22:e826f80d8582 331 write_command(0x37); write_data(x1);
Pokitto 22:e826f80d8582 332 write_command(0x36); write_data(x2);
Pokitto 22:e826f80d8582 333 write_command(0x39); write_data(y1);
Pokitto 22:e826f80d8582 334 write_command(0x38); write_data(y2);
Pokitto 22:e826f80d8582 335 write_command(0x20); write_data(x1);
Pokitto 22:e826f80d8582 336 write_command(0x21); write_data(y1);
Pokitto 22:e826f80d8582 337 }
Pokitto 22:e826f80d8582 338
Pokitto 22:e826f80d8582 339
Pokitto 22:e826f80d8582 340 void Pokitto::lcdTile(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t* gfx){
Pokitto 22:e826f80d8582 341 int width=x1-x0;
Pokitto 22:e826f80d8582 342 int height=y1-y0;
Pokitto 22:e826f80d8582 343 if (x0 > POK_LCD_W) return;
Pokitto 22:e826f80d8582 344 if (y0 > POK_LCD_H) return;
Pokitto 22:e826f80d8582 345 if (x0 < 0) x0=0;
Pokitto 22:e826f80d8582 346 if (y0 < 0) y0=0;
Pokitto 22:e826f80d8582 347
Pokitto 22:e826f80d8582 348 setWindow(y0, x0, y1-1, x1-1);
Pokitto 22:e826f80d8582 349 write_command(0x22);
Pokitto 22:e826f80d8582 350
Pokitto 22:e826f80d8582 351 for (int x=0; x<=width*height-1;x++) {
Pokitto 22:e826f80d8582 352 write_data(gfx[x]);
Pokitto 22:e826f80d8582 353 }
Pokitto 22:e826f80d8582 354 setWindow(0, 0, 175, 219);
Pokitto 22:e826f80d8582 355 }
Pokitto 22:e826f80d8582 356
Pokitto 22:e826f80d8582 357 /* original
Pokitto 22:e826f80d8582 358 void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 22:e826f80d8582 359 if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
Pokitto 22:e826f80d8582 360 return;
Pokitto 22:e826f80d8582 361 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 362 write_data(y); // 0
Pokitto 22:e826f80d8582 363 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 364 write_data(x);
Pokitto 22:e826f80d8582 365 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 366 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 367 setup_data_16(color);
Pokitto 22:e826f80d8582 368 CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 369 }*/
Pokitto 22:e826f80d8582 370
Pokitto 22:e826f80d8582 371 /* by Spinal_code */
Pokitto 22:e826f80d8582 372 void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 22:e826f80d8582 373 if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
Pokitto 22:e826f80d8582 374 return;
Pokitto 22:e826f80d8582 375 write_command(0x20); write_data(y);
Pokitto 22:e826f80d8582 376 write_command(0x21); write_data(x);
Pokitto 22:e826f80d8582 377 write_command(0x22); write_data(color);
Pokitto 22:e826f80d8582 378 }
Pokitto 22:e826f80d8582 379
Pokitto 22:e826f80d8582 380 /* Original
Pokitto 22:e826f80d8582 381 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 22:e826f80d8582 382 int16_t temp;
Pokitto 22:e826f80d8582 383 if (x0>x1) {temp=x0;x0=x1;x1=temp;}
Pokitto 22:e826f80d8582 384 if (y0>y1) {temp=y0;y0=y1;y1=temp;}
Pokitto 22:e826f80d8582 385 if (x0 > POK_LCD_W) return;
Pokitto 22:e826f80d8582 386 if (y0 > POK_LCD_H) return;
Pokitto 22:e826f80d8582 387 if (x1 > POK_LCD_W) x1=POK_LCD_W;
Pokitto 22:e826f80d8582 388 if (y1 > POK_LCD_H) y1=POK_LCD_W;
Pokitto 22:e826f80d8582 389 if (x0 < 0) x0=0;
Pokitto 22:e826f80d8582 390 if (y0 < 0) y0=0;
Pokitto 22:e826f80d8582 391
Pokitto 22:e826f80d8582 392 int16_t x,y;
Pokitto 22:e826f80d8582 393 for (x=x0; x<=x1;x++) {
Pokitto 22:e826f80d8582 394 write_command(0x20); // Horizontal DRAM Address (=y on pokitto screen)
Pokitto 22:e826f80d8582 395 write_data(y0);
Pokitto 22:e826f80d8582 396 write_command(0x21); // Vertical DRAM Address (=x on pokitto screen)
Pokitto 22:e826f80d8582 397 write_data(x);
Pokitto 22:e826f80d8582 398 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 399
Pokitto 22:e826f80d8582 400 CLR_CS_SET_CD_RD_WR; // go to vram write mode
Pokitto 22:e826f80d8582 401
Pokitto 22:e826f80d8582 402
Pokitto 22:e826f80d8582 403 for (y=y0; y<y1;y++) {
Pokitto 22:e826f80d8582 404 setup_data_16(color); // setup the data (flat color = no change between pixels)
Pokitto 22:e826f80d8582 405 CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
Pokitto 22:e826f80d8582 406 }
Pokitto 22:e826f80d8582 407 }
Pokitto 22:e826f80d8582 408 }*/
Pokitto 22:e826f80d8582 409
Pokitto 22:e826f80d8582 410 /* By Spinal_code */
Pokitto 22:e826f80d8582 411
Pokitto 22:e826f80d8582 412 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 22:e826f80d8582 413 if(x1<=x0)x1=x0+1;
Pokitto 22:e826f80d8582 414 if(y1<=y0)y1=y0+1;
Pokitto 22:e826f80d8582 415 setWindow(y0, x0, y1-1, x1-1);
Pokitto 22:e826f80d8582 416 write_command(0x22);
Pokitto 22:e826f80d8582 417 int width=x1-x0;
Pokitto 22:e826f80d8582 418 int height=y1-y0;
Pokitto 22:e826f80d8582 419 int i=width*height;
Pokitto 22:e826f80d8582 420 while (i--) {
Pokitto 22:e826f80d8582 421 write_data(color);
Pokitto 22:e826f80d8582 422 }
Pokitto 22:e826f80d8582 423 }
Pokitto 22:e826f80d8582 424
Pokitto 22:e826f80d8582 425 void Pokitto::lcdRefreshRegionMode1(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t * scrbuf, uint16_t * paletteptr){
Pokitto 22:e826f80d8582 426 if(x1<=x0)x1=x0+1;
Pokitto 22:e826f80d8582 427 if(y1<=y0)y1=y0+1;
Pokitto 22:e826f80d8582 428 setWindow(y0, x0, y1-1, x1-1);
Pokitto 22:e826f80d8582 429 write_command(0x22);
Pokitto 22:e826f80d8582 430 uint8_t pix;
Pokitto 22:e826f80d8582 431 uint8_t quartWide=(x1-x0)/4;
Pokitto 22:e826f80d8582 432 uint8_t pic;
Pokitto 22:e826f80d8582 433
Pokitto 22:e826f80d8582 434 x0/=4;
Pokitto 22:e826f80d8582 435
Pokitto 22:e826f80d8582 436 for(int y=y0; y<y1; y++){
Pokitto 22:e826f80d8582 437 for(int x=x0; x<x0+quartWide; x++){
Pokitto 22:e826f80d8582 438 pic = scrbuf[x+55*y];
Pokitto 22:e826f80d8582 439 pix = (pic >> 6)&3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 440 pix = (pic >> 4)&3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 441 pix = (pic >> 2)&3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 442 pix = pic &3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 443 }
Pokitto 22:e826f80d8582 444 }
Pokitto 22:e826f80d8582 445 }
Pokitto 22:e826f80d8582 446
Pokitto 22:e826f80d8582 447 void Pokitto::lcdRefreshMode1(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 448 uint16_t x,y,xptr;
Pokitto 22:e826f80d8582 449 uint16_t scanline[4][176]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 22:e826f80d8582 450 uint8_t *d, yoffset=0;
Pokitto 22:e826f80d8582 451
Pokitto 22:e826f80d8582 452 xptr = 0;
Pokitto 22:e826f80d8582 453 setDRAMptr(xptr,yoffset);
Pokitto 22:e826f80d8582 454
Pokitto 22:e826f80d8582 455
Pokitto 22:e826f80d8582 456 for(x=0;x<220;x+=4)
Pokitto 22:e826f80d8582 457 {
Pokitto 22:e826f80d8582 458 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 22:e826f80d8582 459 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 460 uint8_t s=0;
Pokitto 22:e826f80d8582 461 for(y=0;y<176;y++)
Pokitto 22:e826f80d8582 462 {
Pokitto 22:e826f80d8582 463 uint8_t tdata = *d;
Pokitto 22:e826f80d8582 464 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 22:e826f80d8582 465 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 22:e826f80d8582 466 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 22:e826f80d8582 467 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 22:e826f80d8582 468
Pokitto 22:e826f80d8582 469 /** put nibble values in the scanlines **/
Pokitto 22:e826f80d8582 470 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 471 scanline[1][s] = paletteptr[t2];
Pokitto 22:e826f80d8582 472 scanline[2][s] = paletteptr[t3];
Pokitto 22:e826f80d8582 473 scanline[3][s++] = paletteptr[t4];
Pokitto 22:e826f80d8582 474
Pokitto 22:e826f80d8582 475 d+=220/4; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 476 }
Pokitto 22:e826f80d8582 477 s=0;
Pokitto 22:e826f80d8582 478 /** draw scanlines **/
Pokitto 22:e826f80d8582 479 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 480 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 481 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 482 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 483 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 484 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 485 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 486 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 487 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 488 }
Pokitto 22:e826f80d8582 489 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 490 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 491 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 492 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 493 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 494 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 495 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 496 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 497 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 498 }
Pokitto 22:e826f80d8582 499 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 500 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 501 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 502 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 503 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 504 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 505 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 506 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 507 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 508 }
Pokitto 22:e826f80d8582 509 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 510 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 511 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 512 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 513 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 514 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 515 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 516 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 517 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 518 }
Pokitto 22:e826f80d8582 519 }
Pokitto 22:e826f80d8582 520 }
Pokitto 22:e826f80d8582 521
Pokitto 22:e826f80d8582 522 void Pokitto::lcdRefreshMode2(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 523 uint16_t x,y;
Pokitto 22:e826f80d8582 524 uint16_t scanline[2][88]; // read two nibbles = pixels at a time
Pokitto 22:e826f80d8582 525 uint8_t *d;
Pokitto 22:e826f80d8582 526
Pokitto 22:e826f80d8582 527 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 528 write_data(0); // 0
Pokitto 22:e826f80d8582 529 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 530 write_data(0);
Pokitto 22:e826f80d8582 531 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 532 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 533
Pokitto 22:e826f80d8582 534 for(x=0;x<110;x+=2)
Pokitto 22:e826f80d8582 535 {
Pokitto 22:e826f80d8582 536 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 22:e826f80d8582 537 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 538 uint8_t s=0;
Pokitto 22:e826f80d8582 539 for(y=0;y<88;y++)
Pokitto 22:e826f80d8582 540 {
Pokitto 22:e826f80d8582 541 uint8_t t = *d >> 4; // higher nibble
Pokitto 22:e826f80d8582 542 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 22:e826f80d8582 543 /** higher nibble = left pixel in pixel pair **/
Pokitto 22:e826f80d8582 544 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 545 scanline[1][s++] = paletteptr[t2];
Pokitto 22:e826f80d8582 546 /** testing only **/
Pokitto 22:e826f80d8582 547 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 22:e826f80d8582 548 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 22:e826f80d8582 549 //s++;
Pokitto 22:e826f80d8582 550 /** until here **/
Pokitto 22:e826f80d8582 551 d+=110/2; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 552 }
Pokitto 22:e826f80d8582 553 s=0;
Pokitto 22:e826f80d8582 554 /** draw scanlines **/
Pokitto 22:e826f80d8582 555 /** leftmost scanline twice**/
Pokitto 22:e826f80d8582 556
Pokitto 22:e826f80d8582 557 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 558 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 559 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 560 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 561 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 562 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 563 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 564 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 565 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 566 }
Pokitto 22:e826f80d8582 567
Pokitto 22:e826f80d8582 568 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 569 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 570 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 571 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 572 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 573 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 574 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 575 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 576 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 577 }
Pokitto 22:e826f80d8582 578 /** rightmost scanline twice**/
Pokitto 22:e826f80d8582 579 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 580 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 581 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 582 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 583 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 584 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 585 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 586 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 587 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 588 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 589 }
Pokitto 22:e826f80d8582 590
Pokitto 22:e826f80d8582 591 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 592 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 593 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 594 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 595 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 596 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 597 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 598 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 599 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 600 }
Pokitto 22:e826f80d8582 601 }
Pokitto 22:e826f80d8582 602 }
Pokitto 22:e826f80d8582 603
Pokitto 22:e826f80d8582 604 void Pokitto::lcdRefreshMode3(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 605 uint16_t x,y;
Pokitto 22:e826f80d8582 606 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 22:e826f80d8582 607 uint8_t *d;
Pokitto 22:e826f80d8582 608
Pokitto 22:e826f80d8582 609 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 610 write_data(0); // 0
Pokitto 22:e826f80d8582 611 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 612 write_data(0);
Pokitto 22:e826f80d8582 613 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 614 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 615
Pokitto 22:e826f80d8582 616 for(x=0;x<220;x+=2)
Pokitto 22:e826f80d8582 617 {
Pokitto 22:e826f80d8582 618 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 22:e826f80d8582 619 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 620 uint8_t s=0;
Pokitto 22:e826f80d8582 621 for(y=0;y<176;y++)
Pokitto 22:e826f80d8582 622 {
Pokitto 22:e826f80d8582 623 uint8_t t = *d >> 4; // higher nibble
Pokitto 22:e826f80d8582 624 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 22:e826f80d8582 625 /** higher nibble = left pixel in pixel pair **/
Pokitto 22:e826f80d8582 626 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 627 scanline[1][s++] = paletteptr[t2];
Pokitto 22:e826f80d8582 628 /** testing only **/
Pokitto 22:e826f80d8582 629 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 22:e826f80d8582 630 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 22:e826f80d8582 631 //s++;
Pokitto 22:e826f80d8582 632 /** until here **/
Pokitto 22:e826f80d8582 633 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 634 }
Pokitto 22:e826f80d8582 635 s=0;
Pokitto 22:e826f80d8582 636 /** draw scanlines **/
Pokitto 22:e826f80d8582 637 /** leftmost scanline**/
Pokitto 22:e826f80d8582 638
Pokitto 22:e826f80d8582 639 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 640 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 641 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 642 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 643 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 644 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 645 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 646 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 647 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 648 }
Pokitto 22:e826f80d8582 649
Pokitto 22:e826f80d8582 650 /** rightmost scanline**/
Pokitto 22:e826f80d8582 651 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 652 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 653 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 654 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 655 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 656 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 657 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 658 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 659 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 660 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 661 }
Pokitto 22:e826f80d8582 662 }
Pokitto 22:e826f80d8582 663 }
Pokitto 22:e826f80d8582 664
Pokitto 22:e826f80d8582 665 void Pokitto::lcdRefreshGB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 666 uint16_t x,y;
Pokitto 22:e826f80d8582 667 uint16_t scanline[48];
Pokitto 22:e826f80d8582 668 uint8_t * d;
Pokitto 22:e826f80d8582 669
Pokitto 22:e826f80d8582 670 #if POK_STRETCH
Pokitto 22:e826f80d8582 671 //uint16_t xptr = 8;
Pokitto 22:e826f80d8582 672 #else
Pokitto 22:e826f80d8582 673 //xptr = 26;
Pokitto 22:e826f80d8582 674 #endif
Pokitto 22:e826f80d8582 675
Pokitto 22:e826f80d8582 676 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 677 write_data(0); // 0
Pokitto 22:e826f80d8582 678 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 679 write_data(0);
Pokitto 22:e826f80d8582 680 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 681 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 682
Pokitto 22:e826f80d8582 683 /** draw border **/
Pokitto 22:e826f80d8582 684 for (int s=0;s<5*176;) {
Pokitto 22:e826f80d8582 685 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 22:e826f80d8582 686 }
Pokitto 22:e826f80d8582 687
Pokitto 22:e826f80d8582 688 for(x=0;x<84;x++)
Pokitto 22:e826f80d8582 689 {
Pokitto 22:e826f80d8582 690
Pokitto 22:e826f80d8582 691 d = scrbuf + x;// point to beginning of line in data
Pokitto 22:e826f80d8582 692
Pokitto 22:e826f80d8582 693 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 694 uint8_t s=0;
Pokitto 22:e826f80d8582 695 for(y=0;y<6;y++)
Pokitto 22:e826f80d8582 696 {
Pokitto 22:e826f80d8582 697 uint8_t t = *d;
Pokitto 22:e826f80d8582 698 #if POK_COLORDEPTH > 1
Pokitto 22:e826f80d8582 699 uint8_t t2 = *(d+504);
Pokitto 22:e826f80d8582 700 #endif
Pokitto 22:e826f80d8582 701 #if POK_COLORDEPTH > 2
Pokitto 22:e826f80d8582 702 uint8_t t3 = *(d+504+504);
Pokitto 22:e826f80d8582 703 #endif
Pokitto 22:e826f80d8582 704 #if POK_COLORDEPTH > 3
Pokitto 22:e826f80d8582 705 uint8_t t4 = *(d+504+504+504);
Pokitto 22:e826f80d8582 706 #endif
Pokitto 22:e826f80d8582 707 uint8_t paletteindex = 0;
Pokitto 22:e826f80d8582 708
Pokitto 22:e826f80d8582 709 /** bit 1 **/
Pokitto 22:e826f80d8582 710 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 711 paletteindex = (t & 0x1);
Pokitto 22:e826f80d8582 712 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 713 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 22:e826f80d8582 714 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 715 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 22:e826f80d8582 716 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 717 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 22:e826f80d8582 718 #endif
Pokitto 22:e826f80d8582 719 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 720
Pokitto 22:e826f80d8582 721 /** bit 2 **/
Pokitto 22:e826f80d8582 722 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 723 paletteindex = (t & 0x2)>>1;
Pokitto 22:e826f80d8582 724 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 725 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 22:e826f80d8582 726 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 727 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 22:e826f80d8582 728 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 729 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 22:e826f80d8582 730 #endif
Pokitto 22:e826f80d8582 731 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 732
Pokitto 22:e826f80d8582 733 /** bit 3 **/
Pokitto 22:e826f80d8582 734 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 735 paletteindex = (t & 0x4)>>2;
Pokitto 22:e826f80d8582 736 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 737 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 22:e826f80d8582 738 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 739 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 22:e826f80d8582 740 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 741 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 22:e826f80d8582 742 #endif
Pokitto 22:e826f80d8582 743 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 744
Pokitto 22:e826f80d8582 745 /** bit 4 **/
Pokitto 22:e826f80d8582 746 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 747 paletteindex = (t & 0x8)>>3;
Pokitto 22:e826f80d8582 748 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 749 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 22:e826f80d8582 750 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 751 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 22:e826f80d8582 752 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 753 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 22:e826f80d8582 754 #endif
Pokitto 22:e826f80d8582 755 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 756
Pokitto 22:e826f80d8582 757 /** bit 5 **/
Pokitto 22:e826f80d8582 758 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 759 paletteindex = (t & 0x10)>>4;
Pokitto 22:e826f80d8582 760 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 761 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 22:e826f80d8582 762 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 763 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 22:e826f80d8582 764 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 765 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 22:e826f80d8582 766 #endif
Pokitto 22:e826f80d8582 767 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 768
Pokitto 22:e826f80d8582 769 /** bit 6 **/
Pokitto 22:e826f80d8582 770 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 771 paletteindex = (t & 0x20)>>5;
Pokitto 22:e826f80d8582 772 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 773 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 22:e826f80d8582 774 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 775 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 22:e826f80d8582 776 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 777 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 22:e826f80d8582 778 #endif
Pokitto 22:e826f80d8582 779 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 780
Pokitto 22:e826f80d8582 781 /** bit 7 **/
Pokitto 22:e826f80d8582 782 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 783 paletteindex = (t & 0x40)>>6;
Pokitto 22:e826f80d8582 784 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 785 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 22:e826f80d8582 786 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 787 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 22:e826f80d8582 788 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 789 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 22:e826f80d8582 790 #endif
Pokitto 22:e826f80d8582 791 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 792
Pokitto 22:e826f80d8582 793 /** bit 8 **/
Pokitto 22:e826f80d8582 794 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 795 paletteindex = (t & 0x80)>>7;
Pokitto 22:e826f80d8582 796 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 797 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 22:e826f80d8582 798 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 799 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 22:e826f80d8582 800 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 801 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 22:e826f80d8582 802 #endif
Pokitto 22:e826f80d8582 803 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 804
Pokitto 22:e826f80d8582 805 d+=84; // jump to byte directly below
Pokitto 22:e826f80d8582 806 }
Pokitto 22:e826f80d8582 807
Pokitto 22:e826f80d8582 808
Pokitto 22:e826f80d8582 809 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 810 write_data(0x10); // 0
Pokitto 22:e826f80d8582 811 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 812 write_data(xptr++);
Pokitto 22:e826f80d8582 813 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 814 CLR_CS_SET_CD_RD_WR;*/
Pokitto 22:e826f80d8582 815 /** draw border **/
Pokitto 22:e826f80d8582 816 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 22:e826f80d8582 817
Pokitto 22:e826f80d8582 818 s=0;
Pokitto 22:e826f80d8582 819
Pokitto 22:e826f80d8582 820 /** draw scanlines **/
Pokitto 22:e826f80d8582 821 for (s=0;s<48;) {
Pokitto 22:e826f80d8582 822 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 823 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 824 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 825 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 826 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 827 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 828 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 829 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 830 }
Pokitto 22:e826f80d8582 831 /** draw border **/
Pokitto 22:e826f80d8582 832 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 22:e826f80d8582 833
Pokitto 22:e826f80d8582 834
Pokitto 22:e826f80d8582 835 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 836 write_data(0x10); // 0
Pokitto 22:e826f80d8582 837 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 838 write_data(xptr++);
Pokitto 22:e826f80d8582 839 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 840 CLR_CS_SET_CD_RD_WR;*/
Pokitto 22:e826f80d8582 841 /** draw border **/
Pokitto 22:e826f80d8582 842 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 22:e826f80d8582 843
Pokitto 22:e826f80d8582 844 for (s=0;s<48;) {
Pokitto 22:e826f80d8582 845 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 846 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 847 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 848 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 849 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 850 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 851 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 852 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 853 }
Pokitto 22:e826f80d8582 854
Pokitto 22:e826f80d8582 855 /** draw border **/
Pokitto 22:e826f80d8582 856 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 22:e826f80d8582 857
Pokitto 22:e826f80d8582 858
Pokitto 22:e826f80d8582 859 #if POK_STRETCH
Pokitto 22:e826f80d8582 860 //if (x>16 && x<68)
Pokitto 22:e826f80d8582 861 if (x&2)// && x&2)
Pokitto 22:e826f80d8582 862 {
Pokitto 22:e826f80d8582 863 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 864 write_data(0x10); // 0
Pokitto 22:e826f80d8582 865 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 866 write_data(xptr++);
Pokitto 22:e826f80d8582 867 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 868 CLR_CS_SET_CD_RD_WR;*/
Pokitto 22:e826f80d8582 869 /** draw border **/
Pokitto 22:e826f80d8582 870 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 22:e826f80d8582 871
Pokitto 22:e826f80d8582 872
Pokitto 22:e826f80d8582 873 for (s=0;s<48;) {
Pokitto 22:e826f80d8582 874 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 875 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 876 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 877 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 878 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 879 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 880 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 881 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 882 }
Pokitto 22:e826f80d8582 883
Pokitto 22:e826f80d8582 884 /** draw border **/
Pokitto 22:e826f80d8582 885 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 22:e826f80d8582 886
Pokitto 22:e826f80d8582 887 }
Pokitto 22:e826f80d8582 888 #endif
Pokitto 22:e826f80d8582 889 }
Pokitto 22:e826f80d8582 890 /** draw border **/
Pokitto 22:e826f80d8582 891 for (int s=0;s<5*176;) {
Pokitto 22:e826f80d8582 892 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 22:e826f80d8582 893 }
Pokitto 22:e826f80d8582 894 }
Pokitto 22:e826f80d8582 895
Pokitto 22:e826f80d8582 896
Pokitto 22:e826f80d8582 897 void Pokitto::lcdRefreshAB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 898 uint16_t x,y;
Pokitto 22:e826f80d8582 899 uint16_t scanline[64];
Pokitto 22:e826f80d8582 900 uint8_t *d;
Pokitto 22:e826f80d8582 901 //lcdClear();
Pokitto 22:e826f80d8582 902 #if POK_STRETCH
Pokitto 22:e826f80d8582 903 uint16_t xptr = 14;
Pokitto 22:e826f80d8582 904 uint8_t yoffset = 24;
Pokitto 22:e826f80d8582 905 #else
Pokitto 22:e826f80d8582 906 xptr = 0; //was 26
Pokitto 22:e826f80d8582 907 #endif
Pokitto 22:e826f80d8582 908
Pokitto 22:e826f80d8582 909 for(x=0;x<128;x++)
Pokitto 22:e826f80d8582 910 {
Pokitto 22:e826f80d8582 911 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 912 write_data(yoffset); // 0
Pokitto 22:e826f80d8582 913 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 914 write_data(xptr++);
Pokitto 22:e826f80d8582 915 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 916 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 917 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 918
Pokitto 22:e826f80d8582 919 d = scrbuf + x;// point to beginning of line in data
Pokitto 22:e826f80d8582 920
Pokitto 22:e826f80d8582 921 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 922 uint8_t s=0;
Pokitto 22:e826f80d8582 923 for(y=0;y<8;y++)
Pokitto 22:e826f80d8582 924 {
Pokitto 22:e826f80d8582 925 uint8_t t = *d;
Pokitto 22:e826f80d8582 926 #if POK_COLORDEPTH > 1
Pokitto 22:e826f80d8582 927 uint8_t t2 = *(d+AB_JUMP);
Pokitto 22:e826f80d8582 928 #endif // POK_COLORDEPTH
Pokitto 22:e826f80d8582 929 #if POK_COLORDEPTH > 2
Pokitto 22:e826f80d8582 930 uint8_t t3 = *(d+AB_JUMP+AB_JUMP);
Pokitto 22:e826f80d8582 931 #endif // POK_COLORDEPTH
Pokitto 22:e826f80d8582 932 #if POK_COLORDEPTH > 3
Pokitto 22:e826f80d8582 933 uint8_t t4 = *(d+AB_JUMP+AB_JUMP+AB_JUMP);
Pokitto 22:e826f80d8582 934 #endif // POK_COLORDEPTH
Pokitto 22:e826f80d8582 935 uint8_t paletteindex = 0;
Pokitto 22:e826f80d8582 936
Pokitto 22:e826f80d8582 937 /** bit 1 **/
Pokitto 22:e826f80d8582 938 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 939 paletteindex = (t & 0x1);
Pokitto 22:e826f80d8582 940 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 941 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 22:e826f80d8582 942 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 943 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 22:e826f80d8582 944 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 945 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 22:e826f80d8582 946 #endif
Pokitto 22:e826f80d8582 947 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 948
Pokitto 22:e826f80d8582 949 /** bit 2 **/
Pokitto 22:e826f80d8582 950 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 951 paletteindex = (t & 0x2)>>1;
Pokitto 22:e826f80d8582 952 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 953 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 22:e826f80d8582 954 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 955 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 22:e826f80d8582 956 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 957 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 22:e826f80d8582 958 #endif
Pokitto 22:e826f80d8582 959 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 960
Pokitto 22:e826f80d8582 961 /** bit 3 **/
Pokitto 22:e826f80d8582 962 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 963 paletteindex = (t & 0x4)>>2;
Pokitto 22:e826f80d8582 964 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 965 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 22:e826f80d8582 966 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 967 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 22:e826f80d8582 968 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 969 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 22:e826f80d8582 970 #endif
Pokitto 22:e826f80d8582 971 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 972
Pokitto 22:e826f80d8582 973 /** bit 4 **/
Pokitto 22:e826f80d8582 974 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 975 paletteindex = (t & 0x8)>>3;
Pokitto 22:e826f80d8582 976 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 977 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 22:e826f80d8582 978 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 979 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 22:e826f80d8582 980 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 981 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 22:e826f80d8582 982 #endif
Pokitto 22:e826f80d8582 983 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 984
Pokitto 22:e826f80d8582 985 /** bit 5 **/
Pokitto 22:e826f80d8582 986 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 987 paletteindex = (t & 0x10)>>4;
Pokitto 22:e826f80d8582 988 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 989 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 22:e826f80d8582 990 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 991 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 22:e826f80d8582 992 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 993 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 22:e826f80d8582 994 #endif
Pokitto 22:e826f80d8582 995 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 996
Pokitto 22:e826f80d8582 997 /** bit 6 **/
Pokitto 22:e826f80d8582 998 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 999 paletteindex = (t & 0x20)>>5;
Pokitto 22:e826f80d8582 1000 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1001 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 22:e826f80d8582 1002 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1003 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 22:e826f80d8582 1004 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1005 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 22:e826f80d8582 1006 #endif
Pokitto 22:e826f80d8582 1007 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1008
Pokitto 22:e826f80d8582 1009 /** bit 7 **/
Pokitto 22:e826f80d8582 1010 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1011 paletteindex = (t & 0x40)>>6;
Pokitto 22:e826f80d8582 1012 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1013 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 22:e826f80d8582 1014 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1015 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 22:e826f80d8582 1016 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1017 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 22:e826f80d8582 1018 #endif
Pokitto 22:e826f80d8582 1019 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1020
Pokitto 22:e826f80d8582 1021 /** bit 8 **/
Pokitto 22:e826f80d8582 1022 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1023 paletteindex = (t & 0x80)>>7;
Pokitto 22:e826f80d8582 1024 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1025 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 22:e826f80d8582 1026 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1027 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 22:e826f80d8582 1028 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1029 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 22:e826f80d8582 1030 #endif
Pokitto 22:e826f80d8582 1031 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1032
Pokitto 22:e826f80d8582 1033 d+=128; // jump to byte directly below
Pokitto 22:e826f80d8582 1034 }
Pokitto 22:e826f80d8582 1035
Pokitto 22:e826f80d8582 1036 s=0;
Pokitto 22:e826f80d8582 1037
Pokitto 22:e826f80d8582 1038 /** draw scanlines **/
Pokitto 22:e826f80d8582 1039 for (s=0;s<64;) {
Pokitto 22:e826f80d8582 1040 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1041 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1042 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1043 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1044 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1045 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1046 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1047 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1048 }
Pokitto 22:e826f80d8582 1049
Pokitto 22:e826f80d8582 1050 #if POK_STRETCH
Pokitto 22:e826f80d8582 1051 if (x&1) {
Pokitto 22:e826f80d8582 1052 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 1053 write_data(yoffset); // 0
Pokitto 22:e826f80d8582 1054 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 1055 write_data(xptr++);
Pokitto 22:e826f80d8582 1056 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 1057 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 1058 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 1059
Pokitto 22:e826f80d8582 1060 for (s=0;s<64;) {
Pokitto 22:e826f80d8582 1061 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1062 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1063 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1064 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1065 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1066 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1067 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1068 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1069 }
Pokitto 22:e826f80d8582 1070 }
Pokitto 22:e826f80d8582 1071 #endif
Pokitto 22:e826f80d8582 1072 }
Pokitto 22:e826f80d8582 1073 }
Pokitto 22:e826f80d8582 1074
Pokitto 22:e826f80d8582 1075 void Pokitto::lcdRefreshModeGBC(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 1076 uint16_t x,y,xptr;
Pokitto 22:e826f80d8582 1077 uint16_t scanline[4][144]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 22:e826f80d8582 1078 uint8_t *d, yoffset=0;
Pokitto 22:e826f80d8582 1079
Pokitto 22:e826f80d8582 1080 xptr = 0;
Pokitto 22:e826f80d8582 1081 setDRAMptr(xptr,yoffset);
Pokitto 22:e826f80d8582 1082
Pokitto 22:e826f80d8582 1083
Pokitto 22:e826f80d8582 1084 for(x=0;x<160;x+=4)
Pokitto 22:e826f80d8582 1085 {
Pokitto 22:e826f80d8582 1086 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 22:e826f80d8582 1087 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 1088 uint8_t s=0;
Pokitto 22:e826f80d8582 1089 for(y=0;y<144;y++)
Pokitto 22:e826f80d8582 1090 {
Pokitto 22:e826f80d8582 1091 uint8_t tdata = *d;
Pokitto 22:e826f80d8582 1092 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 22:e826f80d8582 1093 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 22:e826f80d8582 1094 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 22:e826f80d8582 1095 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 22:e826f80d8582 1096
Pokitto 22:e826f80d8582 1097 /** put nibble values in the scanlines **/
Pokitto 22:e826f80d8582 1098
Pokitto 22:e826f80d8582 1099 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 1100 scanline[1][s] = paletteptr[t2];
Pokitto 22:e826f80d8582 1101 scanline[2][s] = paletteptr[t3];
Pokitto 22:e826f80d8582 1102 scanline[3][s++] = paletteptr[t4];
Pokitto 22:e826f80d8582 1103
Pokitto 22:e826f80d8582 1104 d+=160/4; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 1105 }
Pokitto 22:e826f80d8582 1106
Pokitto 22:e826f80d8582 1107 s=0;
Pokitto 22:e826f80d8582 1108 /** draw scanlines **/
Pokitto 22:e826f80d8582 1109 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1110 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1111 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1112 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1113 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1114 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1115 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1116 }
Pokitto 22:e826f80d8582 1117 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1118 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1119 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1120 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1121 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1122 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1123 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1124 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1125 }
Pokitto 22:e826f80d8582 1126 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1127 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1128 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1129 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1130 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1131 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1132 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1133 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1134 }
Pokitto 22:e826f80d8582 1135 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1136 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1137 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1138 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1139 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1140 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1141 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1142 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1143 }
Pokitto 22:e826f80d8582 1144 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1145 }
Pokitto 22:e826f80d8582 1146 }
Pokitto 22:e826f80d8582 1147
Pokitto 22:e826f80d8582 1148
Pokitto 22:e826f80d8582 1149 void Pokitto::lcdRefreshT1(uint8_t* tilebuf, uint8_t* tilecolorbuf, uint8_t* tileset, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 1150 #ifdef POK_TILEMODE
Pokitto 22:e826f80d8582 1151 uint16_t x,y,data,xptr;
Pokitto 22:e826f80d8582 1152 uint16_t scanline[176];
Pokitto 22:e826f80d8582 1153 uint8_t yoffset=0, tilebyte, tileindex, tilex=0, tiley=0,xcount;
Pokitto 22:e826f80d8582 1154
Pokitto 22:e826f80d8582 1155
Pokitto 22:e826f80d8582 1156 if (!tileset) return;
Pokitto 22:e826f80d8582 1157
Pokitto 22:e826f80d8582 1158 #if LCDWIDTH < POK_LCD_W
Pokitto 22:e826f80d8582 1159 xptr = (POK_LCD_W-LCDWIDTH)/2;
Pokitto 22:e826f80d8582 1160 #else
Pokitto 22:e826f80d8582 1161 xptr = 0;
Pokitto 22:e826f80d8582 1162 #endif
Pokitto 22:e826f80d8582 1163 #if LCDHEIGHT < POK_LCD_H
Pokitto 22:e826f80d8582 1164 yoffset = (POK_LCD_H-LCDHEIGHT)/2;
Pokitto 22:e826f80d8582 1165 #else
Pokitto 22:e826f80d8582 1166 yoffset = 0;
Pokitto 22:e826f80d8582 1167 #endif
Pokitto 22:e826f80d8582 1168
Pokitto 22:e826f80d8582 1169 for(x=0, xcount=0 ;x<LCDWIDTH;x++,xcount++) // loop through vertical columns
Pokitto 22:e826f80d8582 1170 {
Pokitto 22:e826f80d8582 1171 setDRAMptr(xptr++,yoffset); //point to VRAM
Pokitto 22:e826f80d8582 1172
Pokitto 22:e826f80d8582 1173 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 1174 uint8_t s=0, tiley=0;
Pokitto 22:e826f80d8582 1175 //tileindex = tilebuf[tilex*POK_TILES_Y];
Pokitto 22:e826f80d8582 1176 if (xcount==POK_TILE_W) {
Pokitto 22:e826f80d8582 1177 tilex++;
Pokitto 22:e826f80d8582 1178 xcount=0;
Pokitto 22:e826f80d8582 1179 }
Pokitto 22:e826f80d8582 1180
Pokitto 22:e826f80d8582 1181 for(y=0;y<LCDHEIGHT;)
Pokitto 22:e826f80d8582 1182 {
Pokitto 22:e826f80d8582 1183 uint8_t tileval = tilebuf[tilex+tiley*POK_TILES_X]; //get tile number
Pokitto 22:e826f80d8582 1184 uint16_t index = tileval*POK_TILE_W+xcount;
Pokitto 22:e826f80d8582 1185 uint8_t tilebyte = tileset[index]; //get bitmap data
Pokitto 22:e826f80d8582 1186 for (uint8_t ycount=0, bitcount=0; ycount<POK_TILE_H; ycount++, y++, bitcount++) {
Pokitto 22:e826f80d8582 1187 if (bitcount==8) {
Pokitto 22:e826f80d8582 1188 bitcount=0;
Pokitto 22:e826f80d8582 1189 index += 176; //jump to byte below in the tileset bitmap
Pokitto 22:e826f80d8582 1190 tilebyte = tileset[index]; //get bitmap data
Pokitto 22:e826f80d8582 1191 }
Pokitto 22:e826f80d8582 1192 //tilebyte = tile[(tileindex>>4)+*POK_TILE_W]; //tilemaps are 16x16
Pokitto 22:e826f80d8582 1193 //uint8_t paletteindex = ((tilebyte>>(bitcount&0x7)) & 0x1);
Pokitto 22:e826f80d8582 1194 if (!tileval) scanline[s++] = COLOR_MAGENTA*((tilebyte>>bitcount)&0x1);//paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1195 else scanline[s++] = paletteptr[((tilebyte>>bitcount)&0x1)*tileval];//paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1196 }
Pokitto 22:e826f80d8582 1197 tiley++; //move to next tile
Pokitto 22:e826f80d8582 1198 }
Pokitto 22:e826f80d8582 1199 s=0;
Pokitto 22:e826f80d8582 1200
Pokitto 22:e826f80d8582 1201 /** draw scanlines **/
Pokitto 22:e826f80d8582 1202 for (s=0;s<LCDHEIGHT;) {
Pokitto 22:e826f80d8582 1203 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1204 }
Pokitto 22:e826f80d8582 1205 }
Pokitto 22:e826f80d8582 1206 #endif
Pokitto 22:e826f80d8582 1207 }
Pokitto 22:e826f80d8582 1208
Pokitto 22:e826f80d8582 1209 void Pokitto::blitWord(uint16_t c) {
Pokitto 22:e826f80d8582 1210 setup_data_16(c);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1211 }
Pokitto 22:e826f80d8582 1212
Pokitto 22:e826f80d8582 1213