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

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
Pokitto
Date:
Wed Oct 11 20:35:52 2017 +0000
Revision:
7:72f87b7c7400
Child:
12:811f1ed5e21d
Child:
15:0bbe8f6fae32
Fixed PokittoLib to fully working. Includes mbed-src

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
Pokitto 7:72f87b7c7400 330 void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 7:72f87b7c7400 331 if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
Pokitto 7:72f87b7c7400 332 return;
Pokitto 7:72f87b7c7400 333 write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 334 write_data(y); // 0
Pokitto 7:72f87b7c7400 335 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 336 write_data(x);
Pokitto 7:72f87b7c7400 337 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 338 CLR_CS_SET_CD_RD_WR;
Pokitto 7:72f87b7c7400 339 setup_data_16(color);
Pokitto 7:72f87b7c7400 340 CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 341 }
Pokitto 7:72f87b7c7400 342
Pokitto 7:72f87b7c7400 343 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 7:72f87b7c7400 344 int16_t temp;
Pokitto 7:72f87b7c7400 345 if (x0>x1) {temp=x0;x0=x1;x1=temp;}
Pokitto 7:72f87b7c7400 346 if (y0>y1) {temp=y0;y0=y1;y1=temp;}
Pokitto 7:72f87b7c7400 347 if (x0 > POK_LCD_W) return;
Pokitto 7:72f87b7c7400 348 if (y0 > POK_LCD_H) return;
Pokitto 7:72f87b7c7400 349 if (x1 > POK_LCD_W) x1=POK_LCD_W;
Pokitto 7:72f87b7c7400 350 if (y1 > POK_LCD_H) y1=POK_LCD_W;
Pokitto 7:72f87b7c7400 351 if (x0 < 0) x0=0;
Pokitto 7:72f87b7c7400 352 if (y0 < 0) y0=0;
Pokitto 7:72f87b7c7400 353
Pokitto 7:72f87b7c7400 354 int16_t x,y;
Pokitto 7:72f87b7c7400 355 for (x=x0; x<=x1;x++) {
Pokitto 7:72f87b7c7400 356 write_command(0x20); // Horizontal DRAM Address (=y on pokitto screen)
Pokitto 7:72f87b7c7400 357 write_data(y0);
Pokitto 7:72f87b7c7400 358 write_command(0x21); // Vertical DRAM Address (=x on pokitto screen)
Pokitto 7:72f87b7c7400 359 write_data(x);
Pokitto 7:72f87b7c7400 360 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 361
Pokitto 7:72f87b7c7400 362 CLR_CS_SET_CD_RD_WR; // go to vram write mode
Pokitto 7:72f87b7c7400 363
Pokitto 7:72f87b7c7400 364
Pokitto 7:72f87b7c7400 365 for (y=y0; y<y1;y++) {
Pokitto 7:72f87b7c7400 366 setup_data_16(color); // setup the data (flat color = no change between pixels)
Pokitto 7:72f87b7c7400 367 CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
Pokitto 7:72f87b7c7400 368 }
Pokitto 7:72f87b7c7400 369 }
Pokitto 7:72f87b7c7400 370 }
Pokitto 7:72f87b7c7400 371
Pokitto 7:72f87b7c7400 372 void Pokitto::lcdRefreshMode1(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 7:72f87b7c7400 373 uint16_t x,y,xptr;
Pokitto 7:72f87b7c7400 374 uint16_t scanline[4][176]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 7:72f87b7c7400 375 uint8_t *d, yoffset=0;
Pokitto 7:72f87b7c7400 376
Pokitto 7:72f87b7c7400 377 xptr = 0;
Pokitto 7:72f87b7c7400 378 setDRAMptr(xptr,yoffset);
Pokitto 7:72f87b7c7400 379
Pokitto 7:72f87b7c7400 380
Pokitto 7:72f87b7c7400 381 for(x=0;x<220;x+=4)
Pokitto 7:72f87b7c7400 382 {
Pokitto 7:72f87b7c7400 383 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 7:72f87b7c7400 384 /** find colours in one scanline **/
Pokitto 7:72f87b7c7400 385 uint8_t s=0;
Pokitto 7:72f87b7c7400 386 for(y=0;y<176;y++)
Pokitto 7:72f87b7c7400 387 {
Pokitto 7:72f87b7c7400 388 uint8_t tdata = *d;
Pokitto 7:72f87b7c7400 389 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 7:72f87b7c7400 390 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 7:72f87b7c7400 391 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 7:72f87b7c7400 392 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 7:72f87b7c7400 393
Pokitto 7:72f87b7c7400 394 /** put nibble values in the scanlines **/
Pokitto 7:72f87b7c7400 395 scanline[0][s] = paletteptr[t];
Pokitto 7:72f87b7c7400 396 scanline[1][s] = paletteptr[t2];
Pokitto 7:72f87b7c7400 397 scanline[2][s] = paletteptr[t3];
Pokitto 7:72f87b7c7400 398 scanline[3][s++] = paletteptr[t4];
Pokitto 7:72f87b7c7400 399
Pokitto 7:72f87b7c7400 400 d+=220/4; // jump to read byte directly below in screenbuffer
Pokitto 7:72f87b7c7400 401 }
Pokitto 7:72f87b7c7400 402 s=0;
Pokitto 7:72f87b7c7400 403 /** draw scanlines **/
Pokitto 7:72f87b7c7400 404 for (s=0;s<176;) {
Pokitto 7:72f87b7c7400 405 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 406 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 407 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 408 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 409 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 410 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 411 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 412 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 413 }
Pokitto 7:72f87b7c7400 414 for (s=0;s<176;) {
Pokitto 7:72f87b7c7400 415 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 416 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 417 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 418 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 419 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 420 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 421 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 422 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 423 }
Pokitto 7:72f87b7c7400 424 for (s=0;s<176;) {
Pokitto 7:72f87b7c7400 425 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 426 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 427 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 428 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 429 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 430 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 431 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 432 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 433 }
Pokitto 7:72f87b7c7400 434 for (s=0;s<176;) {
Pokitto 7:72f87b7c7400 435 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 436 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 437 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 438 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 439 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 440 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 441 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 442 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 443 }
Pokitto 7:72f87b7c7400 444 }
Pokitto 7:72f87b7c7400 445 }
Pokitto 7:72f87b7c7400 446
Pokitto 7:72f87b7c7400 447 void Pokitto::lcdRefreshMode2(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 7:72f87b7c7400 448 uint16_t x,y;
Pokitto 7:72f87b7c7400 449 uint16_t scanline[2][88]; // read two nibbles = pixels at a time
Pokitto 7:72f87b7c7400 450 uint8_t *d;
Pokitto 7:72f87b7c7400 451
Pokitto 7:72f87b7c7400 452 write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 453 write_data(0); // 0
Pokitto 7:72f87b7c7400 454 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 455 write_data(0);
Pokitto 7:72f87b7c7400 456 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 457 CLR_CS_SET_CD_RD_WR;
Pokitto 7:72f87b7c7400 458
Pokitto 7:72f87b7c7400 459 for(x=0;x<110;x+=2)
Pokitto 7:72f87b7c7400 460 {
Pokitto 7:72f87b7c7400 461 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 7:72f87b7c7400 462 /** find colours in one scanline **/
Pokitto 7:72f87b7c7400 463 uint8_t s=0;
Pokitto 7:72f87b7c7400 464 for(y=0;y<88;y++)
Pokitto 7:72f87b7c7400 465 {
Pokitto 7:72f87b7c7400 466 uint8_t t = *d >> 4; // higher nibble
Pokitto 7:72f87b7c7400 467 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 7:72f87b7c7400 468 /** higher nibble = left pixel in pixel pair **/
Pokitto 7:72f87b7c7400 469 scanline[0][s] = paletteptr[t];
Pokitto 7:72f87b7c7400 470 scanline[1][s++] = paletteptr[t2];
Pokitto 7:72f87b7c7400 471 /** testing only **/
Pokitto 7:72f87b7c7400 472 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 7:72f87b7c7400 473 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 7:72f87b7c7400 474 //s++;
Pokitto 7:72f87b7c7400 475 /** until here **/
Pokitto 7:72f87b7c7400 476 d+=110/2; // jump to read byte directly below in screenbuffer
Pokitto 7:72f87b7c7400 477 }
Pokitto 7:72f87b7c7400 478 s=0;
Pokitto 7:72f87b7c7400 479 /** draw scanlines **/
Pokitto 7:72f87b7c7400 480 /** leftmost scanline twice**/
Pokitto 7:72f87b7c7400 481
Pokitto 7:72f87b7c7400 482 for (s=0;s<88;) {
Pokitto 7:72f87b7c7400 483 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 484 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 485 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 486 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 487 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 488 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 489 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 490 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 491 }
Pokitto 7:72f87b7c7400 492
Pokitto 7:72f87b7c7400 493 for (s=0;s<88;) {
Pokitto 7:72f87b7c7400 494 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 495 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 496 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 497 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 498 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 499 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 500 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 501 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 502 }
Pokitto 7:72f87b7c7400 503 /** rightmost scanline twice**/
Pokitto 7:72f87b7c7400 504 //setDRAMptr(xptr++,yoffset);
Pokitto 7:72f87b7c7400 505 for (s=0;s<88;) {
Pokitto 7:72f87b7c7400 506 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 507 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 508 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 509 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 510 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 511 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 512 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 513 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 514 }
Pokitto 7:72f87b7c7400 515
Pokitto 7:72f87b7c7400 516 for (s=0;s<88;) {
Pokitto 7:72f87b7c7400 517 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 518 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 519 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 520 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 521 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 522 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 523 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 524 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 525 }
Pokitto 7:72f87b7c7400 526 }
Pokitto 7:72f87b7c7400 527 }
Pokitto 7:72f87b7c7400 528
Pokitto 7:72f87b7c7400 529 void Pokitto::lcdRefreshMode3(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 7:72f87b7c7400 530 uint16_t x,y;
Pokitto 7:72f87b7c7400 531 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 7:72f87b7c7400 532 uint8_t *d;
Pokitto 7:72f87b7c7400 533
Pokitto 7:72f87b7c7400 534 write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 535 write_data(0); // 0
Pokitto 7:72f87b7c7400 536 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 537 write_data(0);
Pokitto 7:72f87b7c7400 538 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 539 CLR_CS_SET_CD_RD_WR;
Pokitto 7:72f87b7c7400 540
Pokitto 7:72f87b7c7400 541 for(x=0;x<220;x+=2)
Pokitto 7:72f87b7c7400 542 {
Pokitto 7:72f87b7c7400 543 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 7:72f87b7c7400 544 /** find colours in one scanline **/
Pokitto 7:72f87b7c7400 545 uint8_t s=0;
Pokitto 7:72f87b7c7400 546 for(y=0;y<176;y++)
Pokitto 7:72f87b7c7400 547 {
Pokitto 7:72f87b7c7400 548 uint8_t t = *d >> 4; // higher nibble
Pokitto 7:72f87b7c7400 549 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 7:72f87b7c7400 550 /** higher nibble = left pixel in pixel pair **/
Pokitto 7:72f87b7c7400 551 scanline[0][s] = paletteptr[t];
Pokitto 7:72f87b7c7400 552 scanline[1][s++] = paletteptr[t2];
Pokitto 7:72f87b7c7400 553 /** testing only **/
Pokitto 7:72f87b7c7400 554 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 7:72f87b7c7400 555 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 7:72f87b7c7400 556 //s++;
Pokitto 7:72f87b7c7400 557 /** until here **/
Pokitto 7:72f87b7c7400 558 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 7:72f87b7c7400 559 }
Pokitto 7:72f87b7c7400 560 s=0;
Pokitto 7:72f87b7c7400 561 /** draw scanlines **/
Pokitto 7:72f87b7c7400 562 /** leftmost scanline**/
Pokitto 7:72f87b7c7400 563
Pokitto 7:72f87b7c7400 564 for (s=0;s<176;) {
Pokitto 7:72f87b7c7400 565 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 566 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 567 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 568 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 569 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 570 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 571 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 572 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 573 }
Pokitto 7:72f87b7c7400 574
Pokitto 7:72f87b7c7400 575 /** rightmost scanline**/
Pokitto 7:72f87b7c7400 576 //setDRAMptr(xptr++,yoffset);
Pokitto 7:72f87b7c7400 577 for (s=0;s<176;) {
Pokitto 7:72f87b7c7400 578 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 579 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 580 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 581 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 582 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 583 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 584 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 585 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 586 }
Pokitto 7:72f87b7c7400 587 }
Pokitto 7:72f87b7c7400 588 }
Pokitto 7:72f87b7c7400 589
Pokitto 7:72f87b7c7400 590 void Pokitto::lcdRefreshGB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 7:72f87b7c7400 591 uint16_t x,y;
Pokitto 7:72f87b7c7400 592 uint16_t scanline[48];
Pokitto 7:72f87b7c7400 593 uint8_t * d;
Pokitto 7:72f87b7c7400 594
Pokitto 7:72f87b7c7400 595 #if POK_STRETCH
Pokitto 7:72f87b7c7400 596 //uint16_t xptr = 8;
Pokitto 7:72f87b7c7400 597 #else
Pokitto 7:72f87b7c7400 598 //xptr = 26;
Pokitto 7:72f87b7c7400 599 #endif
Pokitto 7:72f87b7c7400 600
Pokitto 7:72f87b7c7400 601 write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 602 write_data(0); // 0
Pokitto 7:72f87b7c7400 603 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 604 write_data(0);
Pokitto 7:72f87b7c7400 605 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 606 CLR_CS_SET_CD_RD_WR;
Pokitto 7:72f87b7c7400 607
Pokitto 7:72f87b7c7400 608 /** draw border **/
Pokitto 7:72f87b7c7400 609 for (int s=0;s<5*176;) {
Pokitto 7:72f87b7c7400 610 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 7:72f87b7c7400 611 }
Pokitto 7:72f87b7c7400 612
Pokitto 7:72f87b7c7400 613 for(x=0;x<84;x++)
Pokitto 7:72f87b7c7400 614 {
Pokitto 7:72f87b7c7400 615
Pokitto 7:72f87b7c7400 616 d = scrbuf + x;// point to beginning of line in data
Pokitto 7:72f87b7c7400 617
Pokitto 7:72f87b7c7400 618 /** find colours in one scanline **/
Pokitto 7:72f87b7c7400 619 uint8_t s=0;
Pokitto 7:72f87b7c7400 620 for(y=0;y<6;y++)
Pokitto 7:72f87b7c7400 621 {
Pokitto 7:72f87b7c7400 622 uint8_t t = *d;
Pokitto 7:72f87b7c7400 623 #if POK_COLORDEPTH > 1
Pokitto 7:72f87b7c7400 624 uint8_t t2 = *(d+504);
Pokitto 7:72f87b7c7400 625 #endif
Pokitto 7:72f87b7c7400 626 #if POK_COLORDEPTH > 2
Pokitto 7:72f87b7c7400 627 uint8_t t3 = *(d+504+504);
Pokitto 7:72f87b7c7400 628 #endif
Pokitto 7:72f87b7c7400 629 #if POK_COLORDEPTH > 3
Pokitto 7:72f87b7c7400 630 uint8_t t4 = *(d+504+504+504);
Pokitto 7:72f87b7c7400 631 #endif
Pokitto 7:72f87b7c7400 632 uint8_t paletteindex = 0;
Pokitto 7:72f87b7c7400 633
Pokitto 7:72f87b7c7400 634 /** bit 1 **/
Pokitto 7:72f87b7c7400 635 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 636 paletteindex = (t & 0x1);
Pokitto 7:72f87b7c7400 637 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 638 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 7:72f87b7c7400 639 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 640 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 7:72f87b7c7400 641 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 642 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 7:72f87b7c7400 643 #endif
Pokitto 7:72f87b7c7400 644 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 645
Pokitto 7:72f87b7c7400 646 /** bit 2 **/
Pokitto 7:72f87b7c7400 647 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 648 paletteindex = (t & 0x2)>>1;
Pokitto 7:72f87b7c7400 649 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 650 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 7:72f87b7c7400 651 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 652 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 7:72f87b7c7400 653 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 654 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 7:72f87b7c7400 655 #endif
Pokitto 7:72f87b7c7400 656 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 657
Pokitto 7:72f87b7c7400 658 /** bit 3 **/
Pokitto 7:72f87b7c7400 659 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 660 paletteindex = (t & 0x4)>>2;
Pokitto 7:72f87b7c7400 661 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 662 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 7:72f87b7c7400 663 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 664 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 7:72f87b7c7400 665 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 666 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 7:72f87b7c7400 667 #endif
Pokitto 7:72f87b7c7400 668 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 669
Pokitto 7:72f87b7c7400 670 /** bit 4 **/
Pokitto 7:72f87b7c7400 671 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 672 paletteindex = (t & 0x8)>>3;
Pokitto 7:72f87b7c7400 673 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 674 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 7:72f87b7c7400 675 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 676 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 7:72f87b7c7400 677 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 678 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 7:72f87b7c7400 679 #endif
Pokitto 7:72f87b7c7400 680 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 681
Pokitto 7:72f87b7c7400 682 /** bit 5 **/
Pokitto 7:72f87b7c7400 683 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 684 paletteindex = (t & 0x10)>>4;
Pokitto 7:72f87b7c7400 685 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 686 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 7:72f87b7c7400 687 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 688 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 7:72f87b7c7400 689 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 690 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 7:72f87b7c7400 691 #endif
Pokitto 7:72f87b7c7400 692 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 693
Pokitto 7:72f87b7c7400 694 /** bit 6 **/
Pokitto 7:72f87b7c7400 695 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 696 paletteindex = (t & 0x20)>>5;
Pokitto 7:72f87b7c7400 697 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 698 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 7:72f87b7c7400 699 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 700 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 7:72f87b7c7400 701 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 702 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 7:72f87b7c7400 703 #endif
Pokitto 7:72f87b7c7400 704 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 705
Pokitto 7:72f87b7c7400 706 /** bit 7 **/
Pokitto 7:72f87b7c7400 707 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 708 paletteindex = (t & 0x40)>>6;
Pokitto 7:72f87b7c7400 709 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 710 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 7:72f87b7c7400 711 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 712 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 7:72f87b7c7400 713 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 714 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 7:72f87b7c7400 715 #endif
Pokitto 7:72f87b7c7400 716 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 717
Pokitto 7:72f87b7c7400 718 /** bit 8 **/
Pokitto 7:72f87b7c7400 719 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 720 paletteindex = (t & 0x80)>>7;
Pokitto 7:72f87b7c7400 721 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 722 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 7:72f87b7c7400 723 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 724 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 7:72f87b7c7400 725 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 726 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 7:72f87b7c7400 727 #endif
Pokitto 7:72f87b7c7400 728 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 729
Pokitto 7:72f87b7c7400 730 d+=84; // jump to byte directly below
Pokitto 7:72f87b7c7400 731 }
Pokitto 7:72f87b7c7400 732
Pokitto 7:72f87b7c7400 733
Pokitto 7:72f87b7c7400 734 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 735 write_data(0x10); // 0
Pokitto 7:72f87b7c7400 736 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 737 write_data(xptr++);
Pokitto 7:72f87b7c7400 738 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 739 CLR_CS_SET_CD_RD_WR;*/
Pokitto 7:72f87b7c7400 740 /** draw border **/
Pokitto 7:72f87b7c7400 741 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 742
Pokitto 7:72f87b7c7400 743 s=0;
Pokitto 7:72f87b7c7400 744
Pokitto 7:72f87b7c7400 745 /** draw scanlines **/
Pokitto 7:72f87b7c7400 746 for (s=0;s<48;) {
Pokitto 7:72f87b7c7400 747 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 748 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 749 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 750 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 751 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 752 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 753 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 754 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 755 }
Pokitto 7:72f87b7c7400 756 /** draw border **/
Pokitto 7:72f87b7c7400 757 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 758
Pokitto 7:72f87b7c7400 759
Pokitto 7:72f87b7c7400 760 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 761 write_data(0x10); // 0
Pokitto 7:72f87b7c7400 762 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 763 write_data(xptr++);
Pokitto 7:72f87b7c7400 764 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 765 CLR_CS_SET_CD_RD_WR;*/
Pokitto 7:72f87b7c7400 766 /** draw border **/
Pokitto 7:72f87b7c7400 767 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 768
Pokitto 7:72f87b7c7400 769 for (s=0;s<48;) {
Pokitto 7:72f87b7c7400 770 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 771 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 772 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 773 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 774 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
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 }
Pokitto 7:72f87b7c7400 779
Pokitto 7:72f87b7c7400 780 /** draw border **/
Pokitto 7:72f87b7c7400 781 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 782
Pokitto 7:72f87b7c7400 783
Pokitto 7:72f87b7c7400 784 #if POK_STRETCH
Pokitto 7:72f87b7c7400 785 //if (x>16 && x<68)
Pokitto 7:72f87b7c7400 786 if (x&2)// && x&2)
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
Pokitto 7:72f87b7c7400 798 for (s=0;s<48;) {
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 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 807 }
Pokitto 7:72f87b7c7400 808
Pokitto 7:72f87b7c7400 809 /** draw border **/
Pokitto 7:72f87b7c7400 810 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 811
Pokitto 7:72f87b7c7400 812 }
Pokitto 7:72f87b7c7400 813 #endif
Pokitto 7:72f87b7c7400 814 }
Pokitto 7:72f87b7c7400 815 /** draw border **/
Pokitto 7:72f87b7c7400 816 for (int s=0;s<5*176;) {
Pokitto 7:72f87b7c7400 817 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 7:72f87b7c7400 818 }
Pokitto 7:72f87b7c7400 819 }
Pokitto 7:72f87b7c7400 820
Pokitto 7:72f87b7c7400 821
Pokitto 7:72f87b7c7400 822 void Pokitto::lcdRefreshAB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 7:72f87b7c7400 823 uint16_t x,y;
Pokitto 7:72f87b7c7400 824 uint16_t scanline[64];
Pokitto 7:72f87b7c7400 825 uint8_t *d;
Pokitto 7:72f87b7c7400 826 //lcdClear();
Pokitto 7:72f87b7c7400 827 #if POK_STRETCH
Pokitto 7:72f87b7c7400 828 uint16_t xptr = 14;
Pokitto 7:72f87b7c7400 829 uint8_t yoffset = 24;
Pokitto 7:72f87b7c7400 830 #else
Pokitto 7:72f87b7c7400 831 xptr = 0; //was 26
Pokitto 7:72f87b7c7400 832 #endif
Pokitto 7:72f87b7c7400 833
Pokitto 7:72f87b7c7400 834 for(x=0;x<128;x++)
Pokitto 7:72f87b7c7400 835 {
Pokitto 7:72f87b7c7400 836 write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 837 write_data(yoffset); // 0
Pokitto 7:72f87b7c7400 838 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 839 write_data(xptr++);
Pokitto 7:72f87b7c7400 840 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 841 CLR_CS_SET_CD_RD_WR;
Pokitto 7:72f87b7c7400 842 //setDRAMptr(xptr++,yoffset);
Pokitto 7:72f87b7c7400 843
Pokitto 7:72f87b7c7400 844 d = scrbuf + x;// point to beginning of line in data
Pokitto 7:72f87b7c7400 845
Pokitto 7:72f87b7c7400 846 /** find colours in one scanline **/
Pokitto 7:72f87b7c7400 847 uint8_t s=0;
Pokitto 7:72f87b7c7400 848 for(y=0;y<8;y++)
Pokitto 7:72f87b7c7400 849 {
Pokitto 7:72f87b7c7400 850 uint8_t t = *d;
Pokitto 7:72f87b7c7400 851 #if POK_COLORDEPTH > 1
Pokitto 7:72f87b7c7400 852 uint8_t t2 = *(d+AB_JUMP);
Pokitto 7:72f87b7c7400 853 #endif // POK_COLORDEPTH
Pokitto 7:72f87b7c7400 854 #if POK_COLORDEPTH > 2
Pokitto 7:72f87b7c7400 855 uint8_t t3 = *(d+AB_JUMP+AB_JUMP);
Pokitto 7:72f87b7c7400 856 #endif // POK_COLORDEPTH
Pokitto 7:72f87b7c7400 857 #if POK_COLORDEPTH > 3
Pokitto 7:72f87b7c7400 858 uint8_t t4 = *(d+AB_JUMP+AB_JUMP+AB_JUMP);
Pokitto 7:72f87b7c7400 859 #endif // POK_COLORDEPTH
Pokitto 7:72f87b7c7400 860 uint8_t paletteindex = 0;
Pokitto 7:72f87b7c7400 861
Pokitto 7:72f87b7c7400 862 /** bit 1 **/
Pokitto 7:72f87b7c7400 863 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 864 paletteindex = (t & 0x1);
Pokitto 7:72f87b7c7400 865 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 866 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 7:72f87b7c7400 867 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 868 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 7:72f87b7c7400 869 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 870 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 7:72f87b7c7400 871 #endif
Pokitto 7:72f87b7c7400 872 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 873
Pokitto 7:72f87b7c7400 874 /** bit 2 **/
Pokitto 7:72f87b7c7400 875 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 876 paletteindex = (t & 0x2)>>1;
Pokitto 7:72f87b7c7400 877 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 878 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 7:72f87b7c7400 879 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 880 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 7:72f87b7c7400 881 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 882 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 7:72f87b7c7400 883 #endif
Pokitto 7:72f87b7c7400 884 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 885
Pokitto 7:72f87b7c7400 886 /** bit 3 **/
Pokitto 7:72f87b7c7400 887 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 888 paletteindex = (t & 0x4)>>2;
Pokitto 7:72f87b7c7400 889 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 890 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 7:72f87b7c7400 891 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 892 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 7:72f87b7c7400 893 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 894 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 7:72f87b7c7400 895 #endif
Pokitto 7:72f87b7c7400 896 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 897
Pokitto 7:72f87b7c7400 898 /** bit 4 **/
Pokitto 7:72f87b7c7400 899 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 900 paletteindex = (t & 0x8)>>3;
Pokitto 7:72f87b7c7400 901 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 902 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 7:72f87b7c7400 903 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 904 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 7:72f87b7c7400 905 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 906 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 7:72f87b7c7400 907 #endif
Pokitto 7:72f87b7c7400 908 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 909
Pokitto 7:72f87b7c7400 910 /** bit 5 **/
Pokitto 7:72f87b7c7400 911 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 912 paletteindex = (t & 0x10)>>4;
Pokitto 7:72f87b7c7400 913 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 914 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 7:72f87b7c7400 915 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 916 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 7:72f87b7c7400 917 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 918 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 7:72f87b7c7400 919 #endif
Pokitto 7:72f87b7c7400 920 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 921
Pokitto 7:72f87b7c7400 922 /** bit 6 **/
Pokitto 7:72f87b7c7400 923 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 924 paletteindex = (t & 0x20)>>5;
Pokitto 7:72f87b7c7400 925 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 926 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 7:72f87b7c7400 927 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 928 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 7:72f87b7c7400 929 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 930 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 7:72f87b7c7400 931 #endif
Pokitto 7:72f87b7c7400 932 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 933
Pokitto 7:72f87b7c7400 934 /** bit 7 **/
Pokitto 7:72f87b7c7400 935 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 936 paletteindex = (t & 0x40)>>6;
Pokitto 7:72f87b7c7400 937 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 938 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 7:72f87b7c7400 939 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 940 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 7:72f87b7c7400 941 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 942 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 7:72f87b7c7400 943 #endif
Pokitto 7:72f87b7c7400 944 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 945
Pokitto 7:72f87b7c7400 946 /** bit 8 **/
Pokitto 7:72f87b7c7400 947 #if POK_COLORDEPTH == 1
Pokitto 7:72f87b7c7400 948 paletteindex = (t & 0x80)>>7;
Pokitto 7:72f87b7c7400 949 #elif POK_COLORDEPTH == 2
Pokitto 7:72f87b7c7400 950 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 7:72f87b7c7400 951 #elif POK_COLORDEPTH == 3
Pokitto 7:72f87b7c7400 952 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 7:72f87b7c7400 953 #elif POK_COLORDEPTH == 4
Pokitto 7:72f87b7c7400 954 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 7:72f87b7c7400 955 #endif
Pokitto 7:72f87b7c7400 956 scanline[s++] = paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 957
Pokitto 7:72f87b7c7400 958 d+=128; // jump to byte directly below
Pokitto 7:72f87b7c7400 959 }
Pokitto 7:72f87b7c7400 960
Pokitto 7:72f87b7c7400 961 s=0;
Pokitto 7:72f87b7c7400 962
Pokitto 7:72f87b7c7400 963 /** draw scanlines **/
Pokitto 7:72f87b7c7400 964 for (s=0;s<64;) {
Pokitto 7:72f87b7c7400 965 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 966 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 967 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 968 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 969 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 970 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 971 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 972 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 973 }
Pokitto 7:72f87b7c7400 974
Pokitto 7:72f87b7c7400 975 #if POK_STRETCH
Pokitto 7:72f87b7c7400 976 if (x&1) {
Pokitto 7:72f87b7c7400 977 write_command(0x20); // Horizontal DRAM Address
Pokitto 7:72f87b7c7400 978 write_data(yoffset); // 0
Pokitto 7:72f87b7c7400 979 write_command(0x21); // Vertical DRAM Address
Pokitto 7:72f87b7c7400 980 write_data(xptr++);
Pokitto 7:72f87b7c7400 981 write_command(0x22); // write data to DRAM
Pokitto 7:72f87b7c7400 982 CLR_CS_SET_CD_RD_WR;
Pokitto 7:72f87b7c7400 983 //setDRAMptr(xptr++,yoffset);
Pokitto 7:72f87b7c7400 984
Pokitto 7:72f87b7c7400 985 for (s=0;s<64;) {
Pokitto 7:72f87b7c7400 986 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 987 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 988 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 989 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 990 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 991 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 992 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 993 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 994 }
Pokitto 7:72f87b7c7400 995 }
Pokitto 7:72f87b7c7400 996 #endif
Pokitto 7:72f87b7c7400 997 }
Pokitto 7:72f87b7c7400 998 }
Pokitto 7:72f87b7c7400 999
Pokitto 7:72f87b7c7400 1000 void Pokitto::lcdRefreshModeGBC(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 7:72f87b7c7400 1001 uint16_t x,y,xptr;
Pokitto 7:72f87b7c7400 1002 uint16_t scanline[4][144]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 7:72f87b7c7400 1003 uint8_t *d, yoffset=0;
Pokitto 7:72f87b7c7400 1004
Pokitto 7:72f87b7c7400 1005 xptr = 0;
Pokitto 7:72f87b7c7400 1006 setDRAMptr(xptr,yoffset);
Pokitto 7:72f87b7c7400 1007
Pokitto 7:72f87b7c7400 1008
Pokitto 7:72f87b7c7400 1009 for(x=0;x<160;x+=4)
Pokitto 7:72f87b7c7400 1010 {
Pokitto 7:72f87b7c7400 1011 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 7:72f87b7c7400 1012 /** find colours in one scanline **/
Pokitto 7:72f87b7c7400 1013 uint8_t s=0;
Pokitto 7:72f87b7c7400 1014 for(y=0;y<144;y++)
Pokitto 7:72f87b7c7400 1015 {
Pokitto 7:72f87b7c7400 1016 uint8_t tdata = *d;
Pokitto 7:72f87b7c7400 1017 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 7:72f87b7c7400 1018 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 7:72f87b7c7400 1019 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 7:72f87b7c7400 1020 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 7:72f87b7c7400 1021
Pokitto 7:72f87b7c7400 1022 /** put nibble values in the scanlines **/
Pokitto 7:72f87b7c7400 1023
Pokitto 7:72f87b7c7400 1024 scanline[0][s] = paletteptr[t];
Pokitto 7:72f87b7c7400 1025 scanline[1][s] = paletteptr[t2];
Pokitto 7:72f87b7c7400 1026 scanline[2][s] = paletteptr[t3];
Pokitto 7:72f87b7c7400 1027 scanline[3][s++] = paletteptr[t4];
Pokitto 7:72f87b7c7400 1028
Pokitto 7:72f87b7c7400 1029 d+=160/4; // jump to read byte directly below in screenbuffer
Pokitto 7:72f87b7c7400 1030 }
Pokitto 7:72f87b7c7400 1031
Pokitto 7:72f87b7c7400 1032 s=0;
Pokitto 7:72f87b7c7400 1033 /** draw scanlines **/
Pokitto 7:72f87b7c7400 1034 for (s=0;s<144;) {
Pokitto 7:72f87b7c7400 1035 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1036 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1037 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1038 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1039 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1040 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1041 }
Pokitto 7:72f87b7c7400 1042 setDRAMptr(++xptr,yoffset);
Pokitto 7:72f87b7c7400 1043 for (s=0;s<144;) {
Pokitto 7:72f87b7c7400 1044 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1045 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1046 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1047 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1048 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1049 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1050 }
Pokitto 7:72f87b7c7400 1051 setDRAMptr(++xptr,yoffset);
Pokitto 7:72f87b7c7400 1052 for (s=0;s<144;) {
Pokitto 7:72f87b7c7400 1053 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1054 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1055 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1056 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1057 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1058 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1059 }
Pokitto 7:72f87b7c7400 1060 setDRAMptr(++xptr,yoffset);
Pokitto 7:72f87b7c7400 1061 for (s=0;s<144;) {
Pokitto 7:72f87b7c7400 1062 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1063 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1064 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1065 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1066 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1067 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1068 }
Pokitto 7:72f87b7c7400 1069 setDRAMptr(++xptr,yoffset);
Pokitto 7:72f87b7c7400 1070 }
Pokitto 7:72f87b7c7400 1071 }
Pokitto 7:72f87b7c7400 1072
Pokitto 7:72f87b7c7400 1073
Pokitto 7:72f87b7c7400 1074 void Pokitto::lcdRefreshT1(uint8_t* tilebuf, uint8_t* tilecolorbuf, uint8_t* tileset, uint16_t* paletteptr) {
Pokitto 7:72f87b7c7400 1075 #ifdef POK_TILEMODE
Pokitto 7:72f87b7c7400 1076 uint16_t x,y,data,xptr;
Pokitto 7:72f87b7c7400 1077 uint16_t scanline[176];
Pokitto 7:72f87b7c7400 1078 uint8_t yoffset=0, tilebyte, tileindex, tilex=0, tiley=0,xcount;
Pokitto 7:72f87b7c7400 1079
Pokitto 7:72f87b7c7400 1080
Pokitto 7:72f87b7c7400 1081 if (!tileset) return;
Pokitto 7:72f87b7c7400 1082
Pokitto 7:72f87b7c7400 1083 #if LCDWIDTH < POK_LCD_W
Pokitto 7:72f87b7c7400 1084 xptr = (POK_LCD_W-LCDWIDTH)/2;
Pokitto 7:72f87b7c7400 1085 #else
Pokitto 7:72f87b7c7400 1086 xptr = 0;
Pokitto 7:72f87b7c7400 1087 #endif
Pokitto 7:72f87b7c7400 1088 #if LCDHEIGHT < POK_LCD_H
Pokitto 7:72f87b7c7400 1089 yoffset = (POK_LCD_H-LCDHEIGHT)/2;
Pokitto 7:72f87b7c7400 1090 #else
Pokitto 7:72f87b7c7400 1091 yoffset = 0;
Pokitto 7:72f87b7c7400 1092 #endif
Pokitto 7:72f87b7c7400 1093
Pokitto 7:72f87b7c7400 1094 for(x=0, xcount=0 ;x<LCDWIDTH;x++,xcount++) // loop through vertical columns
Pokitto 7:72f87b7c7400 1095 {
Pokitto 7:72f87b7c7400 1096 setDRAMptr(xptr++,yoffset); //point to VRAM
Pokitto 7:72f87b7c7400 1097
Pokitto 7:72f87b7c7400 1098 /** find colours in one scanline **/
Pokitto 7:72f87b7c7400 1099 uint8_t s=0, tiley=0;
Pokitto 7:72f87b7c7400 1100 //tileindex = tilebuf[tilex*POK_TILES_Y];
Pokitto 7:72f87b7c7400 1101 if (xcount==POK_TILE_W) {
Pokitto 7:72f87b7c7400 1102 tilex++;
Pokitto 7:72f87b7c7400 1103 xcount=0;
Pokitto 7:72f87b7c7400 1104 }
Pokitto 7:72f87b7c7400 1105
Pokitto 7:72f87b7c7400 1106 for(y=0;y<LCDHEIGHT;)
Pokitto 7:72f87b7c7400 1107 {
Pokitto 7:72f87b7c7400 1108 uint8_t tileval = tilebuf[tilex+tiley*POK_TILES_X]; //get tile number
Pokitto 7:72f87b7c7400 1109 uint16_t index = tileval*POK_TILE_W+xcount;
Pokitto 7:72f87b7c7400 1110 uint8_t tilebyte = tileset[index]; //get bitmap data
Pokitto 7:72f87b7c7400 1111 for (uint8_t ycount=0, bitcount=0; ycount<POK_TILE_H; ycount++, y++, bitcount++) {
Pokitto 7:72f87b7c7400 1112 if (bitcount==8) {
Pokitto 7:72f87b7c7400 1113 bitcount=0;
Pokitto 7:72f87b7c7400 1114 index += 176; //jump to byte below in the tileset bitmap
Pokitto 7:72f87b7c7400 1115 tilebyte = tileset[index]; //get bitmap data
Pokitto 7:72f87b7c7400 1116 }
Pokitto 7:72f87b7c7400 1117 //tilebyte = tile[(tileindex>>4)+*POK_TILE_W]; //tilemaps are 16x16
Pokitto 7:72f87b7c7400 1118 //uint8_t paletteindex = ((tilebyte>>(bitcount&0x7)) & 0x1);
Pokitto 7:72f87b7c7400 1119 if (!tileval) scanline[s++] = COLOR_MAGENTA*((tilebyte>>bitcount)&0x1);//paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 1120 else scanline[s++] = paletteptr[((tilebyte>>bitcount)&0x1)*tileval];//paletteptr[paletteindex];
Pokitto 7:72f87b7c7400 1121 }
Pokitto 7:72f87b7c7400 1122 tiley++; //move to next tile
Pokitto 7:72f87b7c7400 1123 }
Pokitto 7:72f87b7c7400 1124 s=0;
Pokitto 7:72f87b7c7400 1125
Pokitto 7:72f87b7c7400 1126 /** draw scanlines **/
Pokitto 7:72f87b7c7400 1127 for (s=0;s<LCDHEIGHT;) {
Pokitto 7:72f87b7c7400 1128 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1129 }
Pokitto 7:72f87b7c7400 1130 }
Pokitto 7:72f87b7c7400 1131 #endif
Pokitto 7:72f87b7c7400 1132 }
Pokitto 7:72f87b7c7400 1133
Pokitto 7:72f87b7c7400 1134 void Pokitto::blitWord(uint16_t c) {
Pokitto 7:72f87b7c7400 1135 setup_data_16(c);CLR_WR;SET_WR;
Pokitto 7:72f87b7c7400 1136 }
Pokitto 7:72f87b7c7400 1137