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

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
spinal
Date:
Wed Oct 18 14:47:54 2017 +0000
Revision:
15:0bbe8f6fae32
Parent:
7:72f87b7c7400
direct lcd stuff used by sensitive

Who changed what in which revision?

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