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

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
spinal
Date:
Thu Oct 12 16:24:33 2017 +0000
Revision:
5:9b96eaceeb30
Parent:
2:968589ca3484
added directTile, hope I didn't break anything

Who changed what in which revision?

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