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 18:03:02 2017 +0000
Revision:
11:02ad9c807a21
Parent:
10:8cde5d0bafad
fixed 4color refreshRegion code

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