PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 16:13:07 2017 +0000
Revision:
9:570fdd653f1d
Parent:
2:968589ca3484
Child:
10:8cde5d0bafad
test

Who changed what in which revision?

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