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

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Tue Sep 19 08:47:36 2017 +0000
Revision:
2:968589ca3484
Parent:
0:e8b8f36b4505
Got rid of warnings at compile time

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