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

Committer:
Pokitto
Date:
Fri Dec 29 05:17:10 2017 +0000
Revision:
23:f88837b8f914
Parent:
22:e826f80d8582
PokittoLib mbed and Github are back in sync with all contributions from Hanski and Spinal included

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 22:e826f80d8582 1 /**************************************************************************/
Pokitto 22:e826f80d8582 2 /*!
Pokitto 22:e826f80d8582 3 @file HWLCD.cpp
Pokitto 22:e826f80d8582 4 @author Jonne Valola
Pokitto 22:e826f80d8582 5
Pokitto 22:e826f80d8582 6 @section LICENSE
Pokitto 22:e826f80d8582 7
Pokitto 22:e826f80d8582 8 Software License Agreement (BSD License)
Pokitto 22:e826f80d8582 9
Pokitto 22:e826f80d8582 10 Copyright (c) 2016, Jonne Valola
Pokitto 22:e826f80d8582 11 All rights reserved.
Pokitto 22:e826f80d8582 12
Pokitto 22:e826f80d8582 13 Redistribution and use in source and binary forms, with or without
Pokitto 22:e826f80d8582 14 modification, are permitted provided that the following conditions are met:
Pokitto 22:e826f80d8582 15 1. Redistributions of source code must retain the above copyright
Pokitto 22:e826f80d8582 16 notice, this list of conditions and the following disclaimer.
Pokitto 22:e826f80d8582 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 22:e826f80d8582 18 notice, this list of conditions and the following disclaimer in the
Pokitto 22:e826f80d8582 19 documentation and/or other materials provided with the distribution.
Pokitto 22:e826f80d8582 20 3. Neither the name of the copyright holders nor the
Pokitto 22:e826f80d8582 21 names of its contributors may be used to endorse or promote products
Pokitto 22:e826f80d8582 22 derived from this software without specific prior written permission.
Pokitto 22:e826f80d8582 23
Pokitto 22:e826f80d8582 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 22:e826f80d8582 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 22:e826f80d8582 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 22:e826f80d8582 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 22:e826f80d8582 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 22:e826f80d8582 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 22:e826f80d8582 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 22:e826f80d8582 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 22:e826f80d8582 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 22:e826f80d8582 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 22:e826f80d8582 34 */
Pokitto 22:e826f80d8582 35 /**************************************************************************/
Pokitto 22:e826f80d8582 36
Pokitto 22:e826f80d8582 37 #include "HWLCD.h" //HWLCD.h" #include "HWLCD.h"
Pokitto 22:e826f80d8582 38 #include "Pokitto_settings.h"
Pokitto 22:e826f80d8582 39
Pokitto 23:f88837b8f914 40 #ifndef DISABLEAVRMIN
Pokitto 23:f88837b8f914 41 #define max(a,b) ((a)>(b)?(a):(b))
Pokitto 23:f88837b8f914 42 #define min(a,b) ((a)<(b)?(a):(b))
Pokitto 23:f88837b8f914 43 #endif // DISABLEAVRMIN
Pokitto 23:f88837b8f914 44
Pokitto 22:e826f80d8582 45 #define AB_JUMP 1024 // jump one 1-bit Arduboy screen forward to get next color bit
Pokitto 22:e826f80d8582 46 #define GB_JUMP 504 // jump one 1-bit Gamebuino screen forward to get next color bit
Pokitto 22:e826f80d8582 47
Pokitto 22:e826f80d8582 48 using namespace Pokitto;
Pokitto 22:e826f80d8582 49
Pokitto 22:e826f80d8582 50 uint16_t prevdata=0; // if data does not change, do not adjust LCD bus lines
Pokitto 22:e826f80d8582 51
Pokitto 22:e826f80d8582 52 #if POK_BOARDREV == 2
Pokitto 22:e826f80d8582 53 pwmout_t backlightpwm;
Pokitto 22:e826f80d8582 54 #endif
Pokitto 22:e826f80d8582 55
Pokitto 22:e826f80d8582 56
Pokitto 22:e826f80d8582 57 /**************************************************************************/
Pokitto 22:e826f80d8582 58 /*!
Pokitto 22:e826f80d8582 59 @brief set up the 16-bit bus
Pokitto 22:e826f80d8582 60 */
Pokitto 22:e826f80d8582 61 /**************************************************************************/
Pokitto 22:e826f80d8582 62
Pokitto 22:e826f80d8582 63 static inline void setup_data_16(uint16_t data)
Pokitto 22:e826f80d8582 64 {
Pokitto 22:e826f80d8582 65 uint32_t p2=0;
Pokitto 22:e826f80d8582 66
Pokitto 22:e826f80d8582 67 if (data != prevdata) {
Pokitto 22:e826f80d8582 68
Pokitto 22:e826f80d8582 69 prevdata=data;
Pokitto 22:e826f80d8582 70
Pokitto 22:e826f80d8582 71 /** D0...D16 = P2_3 ... P2_18 **/
Pokitto 22:e826f80d8582 72 p2 = data << 3;
Pokitto 22:e826f80d8582 73
Pokitto 22:e826f80d8582 74 //__disable_irq(); // Disable Interrupts
Pokitto 22:e826f80d8582 75 SET_MASK_P2;
Pokitto 22:e826f80d8582 76 LPC_GPIO_PORT->MPIN[2] = p2; // write bits to port
Pokitto 22:e826f80d8582 77 CLR_MASK_P2;
Pokitto 22:e826f80d8582 78 //__enable_irq(); // Enable Interrupts
Pokitto 22:e826f80d8582 79 }
Pokitto 22:e826f80d8582 80 }
Pokitto 22:e826f80d8582 81
Pokitto 22:e826f80d8582 82
Pokitto 22:e826f80d8582 83 /**************************************************************************/
Pokitto 22:e826f80d8582 84 /*!
Pokitto 22:e826f80d8582 85 @brief Write a command to the lcd, 16-bit bus
Pokitto 22:e826f80d8582 86 */
Pokitto 22:e826f80d8582 87 /**************************************************************************/
Pokitto 22:e826f80d8582 88 inline void write_command_16(uint16_t data)
Pokitto 22:e826f80d8582 89 {
Pokitto 22:e826f80d8582 90 CLR_CS; // select lcd
Pokitto 22:e826f80d8582 91 CLR_CD; // clear CD = command
Pokitto 22:e826f80d8582 92 SET_RD; // RD high, do not read
Pokitto 22:e826f80d8582 93 setup_data_16(data); // function that inputs the data into the relevant bus lines
Pokitto 22:e826f80d8582 94 CLR_WR; // WR low
Pokitto 22:e826f80d8582 95 SET_WR; // WR low, then high = write strobe
Pokitto 22:e826f80d8582 96 SET_CS; // de-select lcd
Pokitto 22:e826f80d8582 97 }
Pokitto 22:e826f80d8582 98
Pokitto 22:e826f80d8582 99 /**************************************************************************/
Pokitto 22:e826f80d8582 100 /*!
Pokitto 22:e826f80d8582 101 @brief Write data to the lcd, 16-bit bus
Pokitto 22:e826f80d8582 102 */
Pokitto 22:e826f80d8582 103 /**************************************************************************/
Pokitto 22:e826f80d8582 104 inline void write_data_16(uint16_t data)
Pokitto 22:e826f80d8582 105 {
Pokitto 22:e826f80d8582 106 CLR_CS;
Pokitto 22:e826f80d8582 107 SET_CD;
Pokitto 22:e826f80d8582 108 SET_RD;
Pokitto 22:e826f80d8582 109 setup_data_16(data);
Pokitto 22:e826f80d8582 110 CLR_WR;
Pokitto 22:e826f80d8582 111 SET_WR;
Pokitto 22:e826f80d8582 112 SET_CS;
Pokitto 22:e826f80d8582 113 }
Pokitto 22:e826f80d8582 114
Pokitto 22:e826f80d8582 115 /**************************************************************************/
Pokitto 22:e826f80d8582 116 /*!
Pokitto 22:e826f80d8582 117 @brief Point to a (x,y) location in the LCD DRAM
Pokitto 22:e826f80d8582 118 */
Pokitto 22:e826f80d8582 119 /**************************************************************************/
Pokitto 22:e826f80d8582 120 static inline void setDRAMptr(uint8_t xptr, uint8_t yoffset)
Pokitto 22:e826f80d8582 121 {
Pokitto 22:e826f80d8582 122 write_command(0x20); // Vertical DRAM Address
Pokitto 22:e826f80d8582 123 write_data(yoffset);
Pokitto 22:e826f80d8582 124 write_command(0x21); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 125 write_data(xptr); //
Pokitto 22:e826f80d8582 126 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 127 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 128 }
Pokitto 22:e826f80d8582 129
Pokitto 22:e826f80d8582 130 void Pokitto::initBacklight() {
Pokitto 22:e826f80d8582 131 #if POK_BOARDREV == 2
Pokitto 22:e826f80d8582 132 pwmout_init(&backlightpwm,POK_BACKLIGHT_PIN);
Pokitto 22:e826f80d8582 133 pwmout_period_us(&backlightpwm,5);
Pokitto 22:e826f80d8582 134 pwmout_write(&backlightpwm,POK_BACKLIGHT_INITIALVALUE);
Pokitto 22:e826f80d8582 135 #endif
Pokitto 22:e826f80d8582 136 }
Pokitto 22:e826f80d8582 137
Pokitto 22:e826f80d8582 138 void Pokitto::setBacklight(float value) {
Pokitto 22:e826f80d8582 139 if (value>0.999f) value = 0.999f;
Pokitto 22:e826f80d8582 140 pwmout_write(&backlightpwm,value);
Pokitto 22:e826f80d8582 141 }
Pokitto 22:e826f80d8582 142
Pokitto 22:e826f80d8582 143 void Pokitto::lcdInit() {
Pokitto 22:e826f80d8582 144 initBacklight();
Pokitto 22:e826f80d8582 145
Pokitto 22:e826f80d8582 146 SET_RESET;
Pokitto 22:e826f80d8582 147 wait_ms(10);
Pokitto 22:e826f80d8582 148 CLR_RESET;
Pokitto 22:e826f80d8582 149 wait_ms(10);
Pokitto 22:e826f80d8582 150 SET_RESET;
Pokitto 22:e826f80d8582 151 wait_ms(10);
Pokitto 22:e826f80d8582 152 //************* Start Initial Sequence **********//
Pokitto 22:e826f80d8582 153 write_command(0x01); // driver output control, this also affects direction
Pokitto 22:e826f80d8582 154 write_data(0x11C); // originally: 0x11C 100011100 SS,NL4,NL3,NL2
Pokitto 22:e826f80d8582 155 // NL4...0 is the number of scan lines to drive the screen !!!
Pokitto 22:e826f80d8582 156 // so 11100 is 1c = 220 lines, correct
Pokitto 22:e826f80d8582 157 // test 1: 0x1C 11100 SS=0,NL4,NL3,NL2 -> no effect
Pokitto 22:e826f80d8582 158 // test 2: 0x31C 1100011100 GS=1,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 22:e826f80d8582 159 // test 3: 0x51C 10100011100 SM=1,GS=0,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 22:e826f80d8582 160 // test 4: 0x71C SM=1,GS=1,SS=1,NL4,NL3,NL2
Pokitto 22:e826f80d8582 161 // test 5: 0x
Pokitto 22:e826f80d8582 162 // seems to have no effect... is this perhaps only for RGB mode ?
Pokitto 22:e826f80d8582 163
Pokitto 22:e826f80d8582 164 write_command(0x02); // LCD driving control
Pokitto 22:e826f80d8582 165 write_data(0x0100); // INV = 1
Pokitto 22:e826f80d8582 166
Pokitto 22:e826f80d8582 167 write_command(0x03); // Entry mode... lets try if this affects the direction
Pokitto 22:e826f80d8582 168 write_data(0x1030); // originally 0x1030 1000000110000 BGR,ID1,ID0
Pokitto 22:e826f80d8582 169 // test 1: 0x1038 1000000111000 BGR,ID1,ID0,AM=1 ->drawing DRAM horizontally
Pokitto 22:e826f80d8582 170 // test 4: am=1, id0=0, id1=0, 1000000001000,0x1008 -> same as above, but flipped on long
Pokitto 22:e826f80d8582 171 // test 2: am=0, id0=0, 1000000100000, 0x1020 -> flipped on long axis
Pokitto 22:e826f80d8582 172 // test 3: am=0, id1=0, 1000000010000, 0x1010 -> picture flowed over back to screen
Pokitto 22:e826f80d8582 173
Pokitto 22:e826f80d8582 174
Pokitto 22:e826f80d8582 175 write_command(0x08); // Display control 2
Pokitto 22:e826f80d8582 176 write_data(0x0808); // 100000001000 FP2,BP2
Pokitto 22:e826f80d8582 177
Pokitto 22:e826f80d8582 178 write_command(0x0C); // RGB display interface
Pokitto 22:e826f80d8582 179 write_data(0x0000); // all off
Pokitto 22:e826f80d8582 180
Pokitto 22:e826f80d8582 181 write_command(0x0F); // Frame marker position
Pokitto 22:e826f80d8582 182 write_data(0x0001); // OSC_EN
Pokitto 22:e826f80d8582 183
Pokitto 22:e826f80d8582 184 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 185 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 186
Pokitto 22:e826f80d8582 187 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 188 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 189
Pokitto 22:e826f80d8582 190 //*************Power On sequence ****************//
Pokitto 22:e826f80d8582 191 write_command(0x10);
Pokitto 22:e826f80d8582 192 write_data(0x0000);
Pokitto 22:e826f80d8582 193
Pokitto 22:e826f80d8582 194 write_command(0x11);
Pokitto 22:e826f80d8582 195 write_data(0x1000);
Pokitto 22:e826f80d8582 196 wait_ms(10);
Pokitto 22:e826f80d8582 197 //------------------------ Set GRAM area --------------------------------//
Pokitto 22:e826f80d8582 198 write_command(0x30); // Gate scan position
Pokitto 22:e826f80d8582 199 write_data(0x0000); // if GS=0, 00h=G1, else 00h=G220
Pokitto 22:e826f80d8582 200
Pokitto 22:e826f80d8582 201 write_command(0x31); // Vertical scroll control
Pokitto 22:e826f80d8582 202 write_data(0x00DB); // scroll start line 11011011 = 219
Pokitto 22:e826f80d8582 203
Pokitto 22:e826f80d8582 204 write_command(0x32); // Vertical scroll control
Pokitto 22:e826f80d8582 205 write_data(0x0000); // scroll end line 0
Pokitto 22:e826f80d8582 206
Pokitto 22:e826f80d8582 207 write_command(0x33); // Vertical scroll control
Pokitto 22:e826f80d8582 208 write_data(0x0000); // 0=vertical scroll disabled
Pokitto 22:e826f80d8582 209
Pokitto 22:e826f80d8582 210 write_command(0x34); // Partial screen driving control
Pokitto 22:e826f80d8582 211 write_data(0x00DB); // db = full screen (end)
Pokitto 22:e826f80d8582 212
Pokitto 22:e826f80d8582 213 write_command(0x35); // partial screen
Pokitto 22:e826f80d8582 214 write_data(0x0000); // 0 = start
Pokitto 22:e826f80d8582 215
Pokitto 22:e826f80d8582 216 write_command(0x36); // Horizontal and vertical RAM position
Pokitto 22:e826f80d8582 217 write_data(0x00AF); //end address 175
Pokitto 22:e826f80d8582 218
Pokitto 22:e826f80d8582 219 write_command(0x37);
Pokitto 22:e826f80d8582 220 write_data(0x0000); // start address 0
Pokitto 22:e826f80d8582 221
Pokitto 22:e826f80d8582 222 write_command(0x38);
Pokitto 22:e826f80d8582 223 write_data(0x00DB); //end address 219
Pokitto 22:e826f80d8582 224
Pokitto 22:e826f80d8582 225 write_command(0x39); // start address 0
Pokitto 22:e826f80d8582 226 write_data(0x0000);
Pokitto 22:e826f80d8582 227 wait_ms(10);
Pokitto 22:e826f80d8582 228 write_command(0xff); // start gamma register control
Pokitto 22:e826f80d8582 229 write_data(0x0003);
Pokitto 22:e826f80d8582 230
Pokitto 22:e826f80d8582 231 // ----------- Adjust the Gamma Curve ----------//
Pokitto 22:e826f80d8582 232 write_command(0x50);
Pokitto 22:e826f80d8582 233 write_data(0x0203);
Pokitto 22:e826f80d8582 234
Pokitto 22:e826f80d8582 235 write_command(0x051);
Pokitto 22:e826f80d8582 236 write_data(0x0A09);
Pokitto 22:e826f80d8582 237
Pokitto 22:e826f80d8582 238 write_command(0x52);
Pokitto 22:e826f80d8582 239 write_data(0x0005);
Pokitto 22:e826f80d8582 240
Pokitto 22:e826f80d8582 241 write_command(0x53);
Pokitto 22:e826f80d8582 242 write_data(0x1021);
Pokitto 22:e826f80d8582 243
Pokitto 22:e826f80d8582 244 write_command(0x54);
Pokitto 22:e826f80d8582 245 write_data(0x0602);
Pokitto 22:e826f80d8582 246
Pokitto 22:e826f80d8582 247 write_command(0x55);
Pokitto 22:e826f80d8582 248 write_data(0x0003);
Pokitto 22:e826f80d8582 249
Pokitto 22:e826f80d8582 250 write_command(0x56);
Pokitto 22:e826f80d8582 251 write_data(0x0703);
Pokitto 22:e826f80d8582 252
Pokitto 22:e826f80d8582 253 write_command(0x57);
Pokitto 22:e826f80d8582 254 write_data(0x0507);
Pokitto 22:e826f80d8582 255
Pokitto 22:e826f80d8582 256 write_command(0x58);
Pokitto 22:e826f80d8582 257 write_data(0x1021);
Pokitto 22:e826f80d8582 258
Pokitto 22:e826f80d8582 259 write_command(0x59);
Pokitto 22:e826f80d8582 260 write_data(0x0703);
Pokitto 22:e826f80d8582 261
Pokitto 22:e826f80d8582 262 write_command(0xB0);
Pokitto 22:e826f80d8582 263 write_data(0x2501);
Pokitto 22:e826f80d8582 264
Pokitto 22:e826f80d8582 265 write_command(0xFF);
Pokitto 22:e826f80d8582 266 write_data(0x0000);
Pokitto 22:e826f80d8582 267
Pokitto 22:e826f80d8582 268 write_command(0x07);
Pokitto 22:e826f80d8582 269 write_data(0x1017);
Pokitto 22:e826f80d8582 270 wait_ms(200);
Pokitto 22:e826f80d8582 271 write_command(0x22);
Pokitto 22:e826f80d8582 272
Pokitto 22:e826f80d8582 273 lcdClear();
Pokitto 22:e826f80d8582 274 }
Pokitto 22:e826f80d8582 275
Pokitto 22:e826f80d8582 276 void Pokitto::lcdSleep(void){
Pokitto 22:e826f80d8582 277 write_command(0xFF);
Pokitto 22:e826f80d8582 278 write_data(0x0000);
Pokitto 22:e826f80d8582 279
Pokitto 22:e826f80d8582 280 write_command(0x07);
Pokitto 22:e826f80d8582 281 write_data(0x0000);
Pokitto 22:e826f80d8582 282 wait_ms(50);
Pokitto 22:e826f80d8582 283 write_command(0x10);// Enter Standby mode
Pokitto 22:e826f80d8582 284 write_data(0x0003);
Pokitto 22:e826f80d8582 285 wait_ms(200);
Pokitto 22:e826f80d8582 286
Pokitto 22:e826f80d8582 287 }
Pokitto 22:e826f80d8582 288
Pokitto 22:e826f80d8582 289 void Pokitto::lcdWakeUp (void){
Pokitto 22:e826f80d8582 290
Pokitto 22:e826f80d8582 291 wait_ms(200);
Pokitto 22:e826f80d8582 292 write_command(0xFF);
Pokitto 22:e826f80d8582 293 write_data(0x0000);
Pokitto 22:e826f80d8582 294
Pokitto 22:e826f80d8582 295 write_command(0x10);// Exit Sleep/ Standby mode
Pokitto 22:e826f80d8582 296 write_data(0x0000);
Pokitto 22:e826f80d8582 297 wait_ms(50);
Pokitto 22:e826f80d8582 298 write_command(0x07);
Pokitto 22:e826f80d8582 299 write_data(0x0117);
Pokitto 22:e826f80d8582 300 wait_ms(200);
Pokitto 22:e826f80d8582 301 }
Pokitto 22:e826f80d8582 302
Pokitto 22:e826f80d8582 303 void Pokitto::lcdFillSurface(uint16_t c) {
Pokitto 22:e826f80d8582 304 uint32_t i;
Pokitto 22:e826f80d8582 305 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 306 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 307 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 308 write_data(0);
Pokitto 22:e826f80d8582 309 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 310 setup_data_16(c);
Pokitto 22:e826f80d8582 311 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 312 for(i=0;i<220*176;i++)
Pokitto 22:e826f80d8582 313 {
Pokitto 22:e826f80d8582 314 CLR_WR;
Pokitto 22:e826f80d8582 315 SET_WR;
Pokitto 22:e826f80d8582 316 }
Pokitto 22:e826f80d8582 317 }
Pokitto 22:e826f80d8582 318
Pokitto 22:e826f80d8582 319 void Pokitto::lcdClear() {
Pokitto 22:e826f80d8582 320 uint32_t i;
Pokitto 22:e826f80d8582 321 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 322 write_data(0x0000); // 0
Pokitto 22:e826f80d8582 323 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 324 write_data(0);
Pokitto 22:e826f80d8582 325 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 326 setup_data_16(0x0000);
Pokitto 22:e826f80d8582 327 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 328 for(i=0;i<220*176;i++)
Pokitto 22:e826f80d8582 329 {
Pokitto 22:e826f80d8582 330 CLR_WR;
Pokitto 22:e826f80d8582 331 SET_WR;
Pokitto 22:e826f80d8582 332 }
Pokitto 22:e826f80d8582 333 }
Pokitto 22:e826f80d8582 334
Pokitto 23:f88837b8f914 335
Pokitto 22:e826f80d8582 336 void Pokitto::setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
Pokitto 22:e826f80d8582 337 write_command(0x37); write_data(x1);
Pokitto 22:e826f80d8582 338 write_command(0x36); write_data(x2);
Pokitto 22:e826f80d8582 339 write_command(0x39); write_data(y1);
Pokitto 22:e826f80d8582 340 write_command(0x38); write_data(y2);
Pokitto 22:e826f80d8582 341 write_command(0x20); write_data(x1);
Pokitto 22:e826f80d8582 342 write_command(0x21); write_data(y1);
Pokitto 22:e826f80d8582 343 }
Pokitto 22:e826f80d8582 344
Pokitto 22:e826f80d8582 345
Pokitto 22:e826f80d8582 346 void Pokitto::lcdTile(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t* gfx){
Pokitto 22:e826f80d8582 347 int width=x1-x0;
Pokitto 22:e826f80d8582 348 int height=y1-y0;
Pokitto 22:e826f80d8582 349 if (x0 > POK_LCD_W) return;
Pokitto 22:e826f80d8582 350 if (y0 > POK_LCD_H) return;
Pokitto 22:e826f80d8582 351 if (x0 < 0) x0=0;
Pokitto 22:e826f80d8582 352 if (y0 < 0) y0=0;
Pokitto 22:e826f80d8582 353
Pokitto 22:e826f80d8582 354 setWindow(y0, x0, y1-1, x1-1);
Pokitto 22:e826f80d8582 355 write_command(0x22);
Pokitto 22:e826f80d8582 356
Pokitto 22:e826f80d8582 357 for (int x=0; x<=width*height-1;x++) {
Pokitto 22:e826f80d8582 358 write_data(gfx[x]);
Pokitto 22:e826f80d8582 359 }
Pokitto 22:e826f80d8582 360 setWindow(0, 0, 175, 219);
Pokitto 22:e826f80d8582 361 }
Pokitto 22:e826f80d8582 362
Pokitto 22:e826f80d8582 363 /* original
Pokitto 22:e826f80d8582 364 void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 22:e826f80d8582 365 if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
Pokitto 22:e826f80d8582 366 return;
Pokitto 22:e826f80d8582 367 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 368 write_data(y); // 0
Pokitto 22:e826f80d8582 369 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 370 write_data(x);
Pokitto 22:e826f80d8582 371 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 372 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 373 setup_data_16(color);
Pokitto 22:e826f80d8582 374 CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 375 }*/
Pokitto 22:e826f80d8582 376
Pokitto 22:e826f80d8582 377 /* by Spinal_code */
Pokitto 22:e826f80d8582 378 void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 22:e826f80d8582 379 if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
Pokitto 22:e826f80d8582 380 return;
Pokitto 22:e826f80d8582 381 write_command(0x20); write_data(y);
Pokitto 22:e826f80d8582 382 write_command(0x21); write_data(x);
Pokitto 22:e826f80d8582 383 write_command(0x22); write_data(color);
Pokitto 22:e826f80d8582 384 }
Pokitto 22:e826f80d8582 385
Pokitto 22:e826f80d8582 386 /* Original
Pokitto 22:e826f80d8582 387 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 22:e826f80d8582 388 int16_t temp;
Pokitto 22:e826f80d8582 389 if (x0>x1) {temp=x0;x0=x1;x1=temp;}
Pokitto 22:e826f80d8582 390 if (y0>y1) {temp=y0;y0=y1;y1=temp;}
Pokitto 22:e826f80d8582 391 if (x0 > POK_LCD_W) return;
Pokitto 22:e826f80d8582 392 if (y0 > POK_LCD_H) return;
Pokitto 22:e826f80d8582 393 if (x1 > POK_LCD_W) x1=POK_LCD_W;
Pokitto 22:e826f80d8582 394 if (y1 > POK_LCD_H) y1=POK_LCD_W;
Pokitto 22:e826f80d8582 395 if (x0 < 0) x0=0;
Pokitto 22:e826f80d8582 396 if (y0 < 0) y0=0;
Pokitto 22:e826f80d8582 397
Pokitto 22:e826f80d8582 398 int16_t x,y;
Pokitto 22:e826f80d8582 399 for (x=x0; x<=x1;x++) {
Pokitto 22:e826f80d8582 400 write_command(0x20); // Horizontal DRAM Address (=y on pokitto screen)
Pokitto 22:e826f80d8582 401 write_data(y0);
Pokitto 22:e826f80d8582 402 write_command(0x21); // Vertical DRAM Address (=x on pokitto screen)
Pokitto 22:e826f80d8582 403 write_data(x);
Pokitto 22:e826f80d8582 404 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 405
Pokitto 22:e826f80d8582 406 CLR_CS_SET_CD_RD_WR; // go to vram write mode
Pokitto 22:e826f80d8582 407
Pokitto 22:e826f80d8582 408
Pokitto 22:e826f80d8582 409 for (y=y0; y<y1;y++) {
Pokitto 22:e826f80d8582 410 setup_data_16(color); // setup the data (flat color = no change between pixels)
Pokitto 22:e826f80d8582 411 CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
Pokitto 22:e826f80d8582 412 }
Pokitto 22:e826f80d8582 413 }
Pokitto 22:e826f80d8582 414 }*/
Pokitto 22:e826f80d8582 415
Pokitto 22:e826f80d8582 416 /* By Spinal_code */
Pokitto 22:e826f80d8582 417
Pokitto 22:e826f80d8582 418 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 22:e826f80d8582 419 if(x1<=x0)x1=x0+1;
Pokitto 22:e826f80d8582 420 if(y1<=y0)y1=y0+1;
Pokitto 22:e826f80d8582 421 setWindow(y0, x0, y1-1, x1-1);
Pokitto 22:e826f80d8582 422 write_command(0x22);
Pokitto 22:e826f80d8582 423 int width=x1-x0;
Pokitto 22:e826f80d8582 424 int height=y1-y0;
Pokitto 22:e826f80d8582 425 int i=width*height;
Pokitto 22:e826f80d8582 426 while (i--) {
Pokitto 22:e826f80d8582 427 write_data(color);
Pokitto 22:e826f80d8582 428 }
Pokitto 22:e826f80d8582 429 }
Pokitto 22:e826f80d8582 430
Pokitto 22:e826f80d8582 431 void Pokitto::lcdRefreshRegionMode1(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t * scrbuf, uint16_t * paletteptr){
Pokitto 22:e826f80d8582 432 if(x1<=x0)x1=x0+1;
Pokitto 22:e826f80d8582 433 if(y1<=y0)y1=y0+1;
Pokitto 22:e826f80d8582 434 setWindow(y0, x0, y1-1, x1-1);
Pokitto 22:e826f80d8582 435 write_command(0x22);
Pokitto 22:e826f80d8582 436 uint8_t pix;
Pokitto 22:e826f80d8582 437 uint8_t quartWide=(x1-x0)/4;
Pokitto 22:e826f80d8582 438 uint8_t pic;
Pokitto 22:e826f80d8582 439
Pokitto 22:e826f80d8582 440 x0/=4;
Pokitto 22:e826f80d8582 441
Pokitto 22:e826f80d8582 442 for(int y=y0; y<y1; y++){
Pokitto 22:e826f80d8582 443 for(int x=x0; x<x0+quartWide; x++){
Pokitto 22:e826f80d8582 444 pic = scrbuf[x+55*y];
Pokitto 22:e826f80d8582 445 pix = (pic >> 6)&3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 446 pix = (pic >> 4)&3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 447 pix = (pic >> 2)&3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 448 pix = pic &3; write_data(paletteptr[pix]);
Pokitto 22:e826f80d8582 449 }
Pokitto 22:e826f80d8582 450 }
Pokitto 22:e826f80d8582 451 }
Pokitto 22:e826f80d8582 452
Pokitto 22:e826f80d8582 453 void Pokitto::lcdRefreshMode1(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 454 uint16_t x,y,xptr;
Pokitto 22:e826f80d8582 455 uint16_t scanline[4][176]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 22:e826f80d8582 456 uint8_t *d, yoffset=0;
Pokitto 22:e826f80d8582 457
Pokitto 23:f88837b8f914 458 #ifdef PROJ_USE_FPS_COUNTER
Pokitto 23:f88837b8f914 459 xptr = 8;
Pokitto 23:f88837b8f914 460 #else
Pokitto 22:e826f80d8582 461 xptr = 0;
Pokitto 23:f88837b8f914 462 #endif
Pokitto 22:e826f80d8582 463 setDRAMptr(xptr,yoffset);
Pokitto 22:e826f80d8582 464
Pokitto 22:e826f80d8582 465
Pokitto 22:e826f80d8582 466 for(x=0;x<220;x+=4)
Pokitto 22:e826f80d8582 467 {
Pokitto 22:e826f80d8582 468 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 22:e826f80d8582 469 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 470 uint8_t s=0;
Pokitto 22:e826f80d8582 471 for(y=0;y<176;y++)
Pokitto 22:e826f80d8582 472 {
Pokitto 22:e826f80d8582 473 uint8_t tdata = *d;
Pokitto 22:e826f80d8582 474 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 22:e826f80d8582 475 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 22:e826f80d8582 476 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 22:e826f80d8582 477 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 22:e826f80d8582 478
Pokitto 22:e826f80d8582 479 /** put nibble values in the scanlines **/
Pokitto 22:e826f80d8582 480 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 481 scanline[1][s] = paletteptr[t2];
Pokitto 22:e826f80d8582 482 scanline[2][s] = paletteptr[t3];
Pokitto 22:e826f80d8582 483 scanline[3][s++] = paletteptr[t4];
Pokitto 22:e826f80d8582 484
Pokitto 22:e826f80d8582 485 d+=220/4; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 486 }
Pokitto 23:f88837b8f914 487
Pokitto 23:f88837b8f914 488 #ifdef PROJ_USE_FPS_COUNTER
Pokitto 23:f88837b8f914 489 if (x>=8 ) {
Pokitto 23:f88837b8f914 490 #else
Pokitto 23:f88837b8f914 491 {
Pokitto 23:f88837b8f914 492
Pokitto 23:f88837b8f914 493 #endif
Pokitto 23:f88837b8f914 494
Pokitto 23:f88837b8f914 495 /** draw scanlines **/
Pokitto 23:f88837b8f914 496 for (s=0;s<176;) {
Pokitto 23:f88837b8f914 497 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 498 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 499 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 500 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 501 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 502 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 503 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 504 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 505 }
Pokitto 23:f88837b8f914 506 for (s=0;s<176;) {
Pokitto 23:f88837b8f914 507 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 508 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 509 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 510 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 511 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 512 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 513 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 514 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 515 }
Pokitto 23:f88837b8f914 516 for (s=0;s<176;) {
Pokitto 23:f88837b8f914 517 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 518 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 519 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 520 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 521 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 522 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 523 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 524 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 525 }
Pokitto 23:f88837b8f914 526 for (s=0;s<176;) {
Pokitto 23:f88837b8f914 527 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 528 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 529 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 530 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 531 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 532 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 533 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 534 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 535 }
Pokitto 22:e826f80d8582 536 }
Pokitto 22:e826f80d8582 537 }
Pokitto 22:e826f80d8582 538 }
Pokitto 22:e826f80d8582 539
Pokitto 23:f88837b8f914 540 // Copy sprite pixels to the scanline
Pokitto 23:f88837b8f914 541 #define SPRITE_2BPP_INNER_LOOP(n)\
Pokitto 23:f88837b8f914 542 \
Pokitto 23:f88837b8f914 543 /* If the sprite is enabled and contained in this vertical scanline, copy 4 pixels. */\
Pokitto 23:f88837b8f914 544 if (sprScanlineAddr[(n)] &&\
Pokitto 23:f88837b8f914 545 y >= sprites[(n)].y && y < sprites[(n)].y + sprites[(n)].h ) {\
Pokitto 23:f88837b8f914 546 \
Pokitto 23:f88837b8f914 547 int16_t sprx = sprites[(n)].x;\
Pokitto 23:f88837b8f914 548 uint16_t s_data16b = 0; /* sprite data, 2 bytes */\
Pokitto 23:f88837b8f914 549 \
Pokitto 23:f88837b8f914 550 /* Get pixel block, 4 or 8 pixels horizontally. Use the predefined bitshift mode. */\
Pokitto 23:f88837b8f914 551 /* Note:it is cheapest to compare to 0 first. */\
Pokitto 23:f88837b8f914 552 if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_MIDDLE_BYTE) {\
Pokitto 23:f88837b8f914 553 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 23:f88837b8f914 554 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 23:f88837b8f914 555 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 23:f88837b8f914 556 }\
Pokitto 23:f88837b8f914 557 else if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_FIRST_BYTE) {\
Pokitto 23:f88837b8f914 558 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 23:f88837b8f914 559 }\
Pokitto 23:f88837b8f914 560 else { /* BITSHIFT_MODE_LAST_BYTE */\
Pokitto 23:f88837b8f914 561 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 23:f88837b8f914 562 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 23:f88837b8f914 563 }\
Pokitto 23:f88837b8f914 564 \
Pokitto 23:f88837b8f914 565 /* Shift sprite pixels according to sprite x. After shifting we have only 4 pixels. */\
Pokitto 23:f88837b8f914 566 uint8_t shiftRight = (sprx&0x3) << 1;\
Pokitto 23:f88837b8f914 567 s_data16b = (s_data16b >> shiftRight);\
Pokitto 23:f88837b8f914 568 \
Pokitto 23:f88837b8f914 569 /* Get individual pixels */\
Pokitto 23:f88837b8f914 570 uint8_t s_t4 = s_data16b & 0x03; s_data16b >>= 2; /* lowest half-nibble */\
Pokitto 23:f88837b8f914 571 uint8_t s_t3 = s_data16b & 0x03; s_data16b >>= 2; /* second lowest half-nibble */\
Pokitto 23:f88837b8f914 572 uint8_t s_t2 = s_data16b & 0x03; s_data16b >>= 2; /* second highest half-nibble */\
Pokitto 23:f88837b8f914 573 uint8_t s_t1 = s_data16b & 0x03; /* highest half-nibble */\
Pokitto 23:f88837b8f914 574 \
Pokitto 23:f88837b8f914 575 /* Store pixels as 16-bit colors from the palette */\
Pokitto 23:f88837b8f914 576 if (s_t4 != transparentColor) p4 = sprites[(n)].palette[s_t4];\
Pokitto 23:f88837b8f914 577 if (s_t3 != transparentColor) p3 = sprites[(n)].palette[s_t3];\
Pokitto 23:f88837b8f914 578 if (s_t2 != transparentColor) p2 = sprites[(n)].palette[s_t2];\
Pokitto 23:f88837b8f914 579 if (s_t1 != transparentColor) p = sprites[(n)].palette[s_t1];\
Pokitto 23:f88837b8f914 580 \
Pokitto 23:f88837b8f914 581 /* Advance scanline address */\
Pokitto 23:f88837b8f914 582 sprScanlineAddr[(n)] += (sprites[(n)].w >> 2);\
Pokitto 23:f88837b8f914 583 }
Pokitto 23:f88837b8f914 584
Pokitto 23:f88837b8f914 585 // Loop unrolling macros
Pokitto 23:f88837b8f914 586 #define UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(0)
Pokitto 23:f88837b8f914 587 #define UNROLLED_LOOP_2() UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(1)
Pokitto 23:f88837b8f914 588 #define UNROLLED_LOOP_3() UNROLLED_LOOP_2() SPRITE_2BPP_INNER_LOOP(2)
Pokitto 23:f88837b8f914 589 #define UNROLLED_LOOP_4() UNROLLED_LOOP_3() SPRITE_2BPP_INNER_LOOP(3)
Pokitto 23:f88837b8f914 590 #define UNROLLED_LOOP_5() UNROLLED_LOOP_4() SPRITE_2BPP_INNER_LOOP(4)
Pokitto 23:f88837b8f914 591 #define UNROLLED_LOOP_6() UNROLLED_LOOP_5() SPRITE_2BPP_INNER_LOOP(5)
Pokitto 23:f88837b8f914 592 #define UNROLLED_LOOP_7() UNROLLED_LOOP_6() SPRITE_2BPP_INNER_LOOP(6)
Pokitto 23:f88837b8f914 593 #define UNROLLED_LOOP_8() UNROLLED_LOOP_7() SPRITE_2BPP_INNER_LOOP(7)
Pokitto 23:f88837b8f914 594 #define UNROLLED_LOOP_9() UNROLLED_LOOP_8() SPRITE_2BPP_INNER_LOOP(8)
Pokitto 23:f88837b8f914 595 #define UNROLLED_LOOP_10() UNROLLED_LOOP_9() SPRITE_2BPP_INNER_LOOP(9)
Pokitto 23:f88837b8f914 596 #define UNROLLED_LOOP_11() UNROLLED_LOOP_10() SPRITE_2BPP_INNER_LOOP(10)
Pokitto 23:f88837b8f914 597 #define UNROLLED_LOOP_12() UNROLLED_LOOP_11() SPRITE_2BPP_INNER_LOOP(11)
Pokitto 23:f88837b8f914 598 #define UNROLLED_LOOP_13() UNROLLED_LOOP_12() SPRITE_2BPP_INNER_LOOP(12)
Pokitto 23:f88837b8f914 599 #define UNROLLED_LOOP_14() UNROLLED_LOOP_13() SPRITE_2BPP_INNER_LOOP(13)
Pokitto 23:f88837b8f914 600 #define UNROLLED_LOOP_15() UNROLLED_LOOP_14() SPRITE_2BPP_INNER_LOOP(14)
Pokitto 23:f88837b8f914 601 #define UNROLLED_LOOP_16() UNROLLED_LOOP_15() SPRITE_2BPP_INNER_LOOP(15)
Pokitto 23:f88837b8f914 602 #define UNROLLED_LOOP_N_(n) UNROLLED_LOOP_##n()
Pokitto 23:f88837b8f914 603 #define UNROLLED_LOOP_N(n) UNROLLED_LOOP_N_(n)
Pokitto 23:f88837b8f914 604
Pokitto 23:f88837b8f914 605 /**
Pokitto 23:f88837b8f914 606 Update the screen buffer of 220x176 pixels and sprites to LCD.
Pokitto 23:f88837b8f914 607
Pokitto 23:f88837b8f914 608 If useDirectMode=true only sprites are updated TO LCD and the dirty rect is drawn behind the sprite current and previous
Pokitto 23:f88837b8f914 609 location.
Pokitto 23:f88837b8f914 610 If useDirectMode=false both the full screen buffer and sprites are updated to LCD.
Pokitto 23:f88837b8f914 611
Pokitto 23:f88837b8f914 612 Limitations of sprites:
Pokitto 23:f88837b8f914 613 - Sprite is enabled if sprites.bitmapData is not NULL
Pokitto 23:f88837b8f914 614 - All enabled sprites must be at the beginning of the sprites array.
Pokitto 23:f88837b8f914 615 */
Pokitto 23:f88837b8f914 616 void Pokitto::lcdRefreshMode1Spr(uint8_t * scrbuf, uint16_t* paletteptr, SpriteInfo* sprites, bool useDirectMode) {
Pokitto 23:f88837b8f914 617
Pokitto 23:f88837b8f914 618 // In direct mode, return now if there are no sprites
Pokitto 23:f88837b8f914 619 if (useDirectMode && (sprites == NULL || sprites[0].bitmapData == NULL))
Pokitto 23:f88837b8f914 620 return;
Pokitto 23:f88837b8f914 621
Pokitto 23:f88837b8f914 622 uint16_t x,y;
Pokitto 23:f88837b8f914 623 uint16_t scanline[4][176]; // read 4 half-nibbles (= 4 pixels) at a time
Pokitto 23:f88837b8f914 624 const uint8_t transparentColor = 0; // fixed palette index 0 for transparency
Pokitto 23:f88837b8f914 625
Pokitto 23:f88837b8f914 626 // Calculate the current amount of sprites
Pokitto 23:f88837b8f914 627 // Note: Sprites must be taken into use from index 0 upwards, because the first sprite with bitmapData==NULL is considered as the last sprite
Pokitto 23:f88837b8f914 628 uint8_t spriteCount = 0;
Pokitto 23:f88837b8f914 629 if (sprites != NULL)
Pokitto 23:f88837b8f914 630 for (;sprites[spriteCount].bitmapData != NULL && spriteCount < SPRITE_COUNT; spriteCount++);
Pokitto 23:f88837b8f914 631
Pokitto 23:f88837b8f914 632 // If drawing the screen buffer, set the start pos to LCD commands only here.
Pokitto 23:f88837b8f914 633 #ifdef PROJ_USE_FPS_COUNTER
Pokitto 23:f88837b8f914 634 if (!useDirectMode) setDRAMptr(8, 0);
Pokitto 23:f88837b8f914 635 #else
Pokitto 23:f88837b8f914 636 if (!useDirectMode) setDRAMptr(0, 0);
Pokitto 23:f88837b8f914 637 #endif
Pokitto 23:f88837b8f914 638
Pokitto 23:f88837b8f914 639 // TODO OPTIMIZE: if a sprite is totally out-of-screen, it could be marked here already. Even in this case we might
Pokitto 23:f88837b8f914 640 // need to clear the previous sprite location with screen buffer pixels.
Pokitto 23:f88837b8f914 641
Pokitto 23:f88837b8f914 642 // Go through each vertical group of 4 scanlines.
Pokitto 23:f88837b8f914 643 for (x=0; x<220; x+=4) {
Pokitto 23:f88837b8f914 644
Pokitto 23:f88837b8f914 645 uint8_t *screenBufScanlineAddr = scrbuf + (x>>2);// point to beginning of line in data
Pokitto 23:f88837b8f914 646
Pokitto 23:f88837b8f914 647 /*Prepare scanline start address for sprites that are visible in this vertical scanline. Sprite width cannot exceed the screen width*/
Pokitto 23:f88837b8f914 648 uint8_t *sprScanlineAddr[SPRITE_COUNT]; // Sprite start address for the scanline
Pokitto 23:f88837b8f914 649 uint8_t sprScanlineBitshiftMode[SPRITE_COUNT]; // Sprite bitshift mode for the scanline
Pokitto 23:f88837b8f914 650 const uint8_t BITSHIFT_MODE_MIDDLE_BYTE = 0;
Pokitto 23:f88837b8f914 651 const uint8_t BITSHIFT_MODE_FIRST_BYTE = 1;
Pokitto 23:f88837b8f914 652 const uint8_t BITSHIFT_MODE_LAST_BYTE = 2;
Pokitto 23:f88837b8f914 653 uint8_t scanlineMinY = 0; // Min y to draw for the scanline
Pokitto 23:f88837b8f914 654 uint8_t scanlineMaxY = 175; // Max y to draw for the scanline
Pokitto 23:f88837b8f914 655
Pokitto 23:f88837b8f914 656 // If not drawing the screen buffer, reset min and max to uninitialized values
Pokitto 23:f88837b8f914 657 if (useDirectMode ) {
Pokitto 23:f88837b8f914 658 scanlineMinY = 255;
Pokitto 23:f88837b8f914 659 scanlineMaxY = 0;
Pokitto 23:f88837b8f914 660 }
Pokitto 23:f88837b8f914 661 if (sprites != NULL) {
Pokitto 23:f88837b8f914 662
Pokitto 23:f88837b8f914 663 // Check all the sprites for this scanline.
Pokitto 23:f88837b8f914 664 for (int sprindex = 0; sprindex < spriteCount; sprindex++) {
Pokitto 23:f88837b8f914 665
Pokitto 23:f88837b8f914 666 int16_t sprx = sprites[sprindex].x;
Pokitto 23:f88837b8f914 667 int16_t spry = sprites[sprindex].y;
Pokitto 23:f88837b8f914 668 uint8_t sprw = sprites[sprindex].w;
Pokitto 23:f88837b8f914 669 uint8_t sprh = sprites[sprindex].h;
Pokitto 23:f88837b8f914 670 int16_t sprOldX = sprites[sprindex].oldx;
Pokitto 23:f88837b8f914 671 int16_t sprOldY = sprites[sprindex].oldy;
Pokitto 23:f88837b8f914 672
Pokitto 23:f88837b8f914 673 // Detect the dirty rect x-span by combining the previous and current sprite position.
Pokitto 23:f88837b8f914 674 int16_t sprDirtyXMin = min(sprx, sprOldX);
Pokitto 23:f88837b8f914 675 int16_t sprDirtyXMax = max(sprx, sprOldX);
Pokitto 23:f88837b8f914 676
Pokitto 23:f88837b8f914 677 // Is current x inside the sprite combined dirty rect ?
Pokitto 23:f88837b8f914 678 int16_t sprDirtyXMaxEnd = sprDirtyXMax + sprw - 1 + 4; // Add 4 pixels to dirty rect width (needed?)
Pokitto 23:f88837b8f914 679 if (sprDirtyXMin <= x+3 && x <= sprDirtyXMaxEnd) {
Pokitto 23:f88837b8f914 680
Pokitto 23:f88837b8f914 681 // If not drawing the whole screen buffer, detect the dirty rect y-span by combining the old and
Pokitto 23:f88837b8f914 682 // current sprite position, and combine all the sprites.
Pokitto 23:f88837b8f914 683 if (useDirectMode) {
Pokitto 23:f88837b8f914 684
Pokitto 23:f88837b8f914 685 // Dirty rect
Pokitto 23:f88837b8f914 686 int16_t sprDirtyYMin = min(spry, sprOldY);
Pokitto 23:f88837b8f914 687 sprDirtyYMin = max(sprDirtyYMin, 0);
Pokitto 23:f88837b8f914 688 int16_t sprDirtyYMax = max(spry, sprOldY);
Pokitto 23:f88837b8f914 689 int16_t sprDirtyYMaxEnd = sprDirtyYMax + sprh - 1;
Pokitto 23:f88837b8f914 690 sprDirtyYMaxEnd = min(sprDirtyYMaxEnd, 175);
Pokitto 23:f88837b8f914 691
Pokitto 23:f88837b8f914 692 // Get the scanline min and max y values for drawing
Pokitto 23:f88837b8f914 693 if (sprDirtyYMin < scanlineMinY)
Pokitto 23:f88837b8f914 694 scanlineMinY = sprDirtyYMin;
Pokitto 23:f88837b8f914 695 if (sprDirtyYMaxEnd > scanlineMaxY)
Pokitto 23:f88837b8f914 696 scanlineMaxY = sprDirtyYMaxEnd;
Pokitto 23:f88837b8f914 697 }
Pokitto 23:f88837b8f914 698
Pokitto 23:f88837b8f914 699 // Check if the sprite should be active for this vertical scanline group.
Pokitto 23:f88837b8f914 700 if (sprx <= x+3 && x < sprx + sprw) { // note: cover group of 4 pixels of the scanline (x+3)
Pokitto 23:f88837b8f914 701
Pokitto 23:f88837b8f914 702 // Find the byte number in the sprite data
Pokitto 23:f88837b8f914 703 int16_t byteNum = ((x+3) - sprx)>>2;
Pokitto 23:f88837b8f914 704
Pokitto 23:f88837b8f914 705 // Get the start addres of the spite data in this scanline.
Pokitto 23:f88837b8f914 706 sprScanlineAddr[sprindex] = const_cast<uint8_t*>(sprites[sprindex].bitmapData + byteNum);
Pokitto 23:f88837b8f914 707
Pokitto 23:f88837b8f914 708 // If the sprite goes over the top, it must be clipped from the top.
Pokitto 23:f88837b8f914 709 if(spry < 0)
Pokitto 23:f88837b8f914 710 sprScanlineAddr[sprindex] += (-spry) * (sprw >> 2);
Pokitto 23:f88837b8f914 711
Pokitto 23:f88837b8f914 712 // Select the bitshift mode for the blit algorithm
Pokitto 23:f88837b8f914 713 if (byteNum == 0)
Pokitto 23:f88837b8f914 714 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_FIRST_BYTE;
Pokitto 23:f88837b8f914 715 else if (byteNum >= (sprw >> 2))
Pokitto 23:f88837b8f914 716 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_LAST_BYTE;
Pokitto 23:f88837b8f914 717 else
Pokitto 23:f88837b8f914 718 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_MIDDLE_BYTE;
Pokitto 23:f88837b8f914 719 }
Pokitto 23:f88837b8f914 720 else
Pokitto 23:f88837b8f914 721 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 23:f88837b8f914 722 }
Pokitto 23:f88837b8f914 723 else
Pokitto 23:f88837b8f914 724 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 23:f88837b8f914 725 }
Pokitto 23:f88837b8f914 726 }
Pokitto 23:f88837b8f914 727
Pokitto 23:f88837b8f914 728 // The height must dividable by 8. That is needed because later we copy 8 pixels at a time to the LCD.
Pokitto 23:f88837b8f914 729 if (useDirectMode && scanlineMaxY - scanlineMinY + 1 > 0) {
Pokitto 23:f88837b8f914 730 uint8_t scanlineH = scanlineMaxY - scanlineMinY + 1;
Pokitto 23:f88837b8f914 731 uint8_t addW = 8 - (scanlineH & 0x7);
Pokitto 23:f88837b8f914 732
Pokitto 23:f88837b8f914 733 // if height is not dividable by 8, make it be.
Pokitto 23:f88837b8f914 734 if (addW != 0) {
Pokitto 23:f88837b8f914 735 if (scanlineMinY > addW )
Pokitto 23:f88837b8f914 736 scanlineMinY -= addW;
Pokitto 23:f88837b8f914 737 else if( scanlineMaxY + addW < 176)
Pokitto 23:f88837b8f914 738 scanlineMaxY += addW;
Pokitto 23:f88837b8f914 739 else {
Pokitto 23:f88837b8f914 740 scanlineMinY = 0;
Pokitto 23:f88837b8f914 741 scanlineMaxY = 175;
Pokitto 23:f88837b8f914 742 }
Pokitto 23:f88837b8f914 743 }
Pokitto 23:f88837b8f914 744 }
Pokitto 23:f88837b8f914 745
Pokitto 23:f88837b8f914 746 // Find colours in this group of 4 scanlines
Pokitto 23:f88837b8f914 747 screenBufScanlineAddr += (scanlineMinY * 220/4);
Pokitto 23:f88837b8f914 748 for (y=scanlineMinY; y<=scanlineMaxY; y++)
Pokitto 23:f88837b8f914 749 {
Pokitto 23:f88837b8f914 750 // get the screen buffer data first
Pokitto 23:f88837b8f914 751 uint8_t tdata = *screenBufScanlineAddr;
Pokitto 23:f88837b8f914 752 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 23:f88837b8f914 753 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 23:f88837b8f914 754 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 23:f88837b8f914 755 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 23:f88837b8f914 756
Pokitto 23:f88837b8f914 757 // Convert to 16-bit colors in palette
Pokitto 23:f88837b8f914 758 uint16_t p = paletteptr[t];
Pokitto 23:f88837b8f914 759 uint16_t p2 = paletteptr[t2];
Pokitto 23:f88837b8f914 760 uint16_t p3 = paletteptr[t3];
Pokitto 23:f88837b8f914 761 uint16_t p4 = paletteptr[t4];
Pokitto 23:f88837b8f914 762
Pokitto 23:f88837b8f914 763 // Add active sprite pixels
Pokitto 23:f88837b8f914 764 if (sprites != NULL) {
Pokitto 23:f88837b8f914 765
Pokitto 23:f88837b8f914 766 // Use loop unrolling for speed optimization
Pokitto 23:f88837b8f914 767 UNROLLED_LOOP_N(SPRITE_COUNT)
Pokitto 23:f88837b8f914 768 }
Pokitto 23:f88837b8f914 769
Pokitto 23:f88837b8f914 770 // put the result nibble values in the scanline
Pokitto 23:f88837b8f914 771 scanline[0][y] = p;
Pokitto 23:f88837b8f914 772 scanline[1][y] = p2;
Pokitto 23:f88837b8f914 773 scanline[2][y] = p3;
Pokitto 23:f88837b8f914 774 scanline[3][y] = p4;
Pokitto 23:f88837b8f914 775
Pokitto 23:f88837b8f914 776 screenBufScanlineAddr += 220>>2; // jump to read byte directly below in screenbuffer
Pokitto 23:f88837b8f914 777 }
Pokitto 23:f88837b8f914 778
Pokitto 23:f88837b8f914 779 // Draw scanline to LCD
Pokitto 23:f88837b8f914 780 #ifdef PROJ_USE_FPS_COUNTER
Pokitto 23:f88837b8f914 781 if (x>=8 && scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 23:f88837b8f914 782 #else
Pokitto 23:f88837b8f914 783 if (scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 23:f88837b8f914 784 #endif
Pokitto 23:f88837b8f914 785 if (useDirectMode) setDRAMptr(x, scanlineMinY);
Pokitto 23:f88837b8f914 786 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 23:f88837b8f914 787 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 788 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 789 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 790 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 791 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 792 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 793 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 794 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 795 }
Pokitto 23:f88837b8f914 796
Pokitto 23:f88837b8f914 797 if (useDirectMode) setDRAMptr(x+1, scanlineMinY);
Pokitto 23:f88837b8f914 798 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 23:f88837b8f914 799 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 800 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 801 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 802 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 803 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 804 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 805 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 806 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 807 }
Pokitto 23:f88837b8f914 808
Pokitto 23:f88837b8f914 809 if (useDirectMode) setDRAMptr(x+2, scanlineMinY);
Pokitto 23:f88837b8f914 810 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 23:f88837b8f914 811 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 812 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 813 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 814 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 815 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 816 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 817 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 818 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 819 }
Pokitto 23:f88837b8f914 820
Pokitto 23:f88837b8f914 821 if (useDirectMode) setDRAMptr(x+3, scanlineMinY);
Pokitto 23:f88837b8f914 822 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 23:f88837b8f914 823 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 824 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 825 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 826 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 827 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 828 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 829 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 830 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 831 }
Pokitto 23:f88837b8f914 832 }
Pokitto 23:f88837b8f914 833 }
Pokitto 23:f88837b8f914 834
Pokitto 23:f88837b8f914 835 // Update old x and y for the sprites
Pokitto 23:f88837b8f914 836 if (sprites != NULL) {
Pokitto 23:f88837b8f914 837 for (int sprindex = 0; sprindex < spriteCount; sprindex++) {
Pokitto 23:f88837b8f914 838 sprites[sprindex].oldx = sprites[sprindex].x;
Pokitto 23:f88837b8f914 839 sprites[sprindex].oldy = sprites[sprindex].y;
Pokitto 23:f88837b8f914 840 }
Pokitto 23:f88837b8f914 841 }
Pokitto 23:f88837b8f914 842
Pokitto 23:f88837b8f914 843 #ifdef POK_SIM
Pokitto 23:f88837b8f914 844 simulator.refreshDisplay();
Pokitto 23:f88837b8f914 845 #endif
Pokitto 23:f88837b8f914 846 }
Pokitto 23:f88837b8f914 847
Pokitto 22:e826f80d8582 848 void Pokitto::lcdRefreshMode2(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 849 uint16_t x,y;
Pokitto 22:e826f80d8582 850 uint16_t scanline[2][88]; // read two nibbles = pixels at a time
Pokitto 22:e826f80d8582 851 uint8_t *d;
Pokitto 22:e826f80d8582 852
Pokitto 22:e826f80d8582 853 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 854 write_data(0); // 0
Pokitto 22:e826f80d8582 855 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 856 write_data(0);
Pokitto 22:e826f80d8582 857 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 858 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 859
Pokitto 22:e826f80d8582 860 for(x=0;x<110;x+=2)
Pokitto 22:e826f80d8582 861 {
Pokitto 22:e826f80d8582 862 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 22:e826f80d8582 863 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 864 uint8_t s=0;
Pokitto 22:e826f80d8582 865 for(y=0;y<88;y++)
Pokitto 22:e826f80d8582 866 {
Pokitto 22:e826f80d8582 867 uint8_t t = *d >> 4; // higher nibble
Pokitto 22:e826f80d8582 868 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 22:e826f80d8582 869 /** higher nibble = left pixel in pixel pair **/
Pokitto 22:e826f80d8582 870 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 871 scanline[1][s++] = paletteptr[t2];
Pokitto 22:e826f80d8582 872 /** testing only **/
Pokitto 22:e826f80d8582 873 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 22:e826f80d8582 874 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 22:e826f80d8582 875 //s++;
Pokitto 22:e826f80d8582 876 /** until here **/
Pokitto 22:e826f80d8582 877 d+=110/2; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 878 }
Pokitto 22:e826f80d8582 879 s=0;
Pokitto 22:e826f80d8582 880 /** draw scanlines **/
Pokitto 22:e826f80d8582 881 /** leftmost scanline twice**/
Pokitto 22:e826f80d8582 882
Pokitto 22:e826f80d8582 883 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 884 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 885 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 886 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 887 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 888 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 889 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 890 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 891 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 892 }
Pokitto 22:e826f80d8582 893
Pokitto 22:e826f80d8582 894 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 895 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 896 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 897 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 898 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 899 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 900 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 901 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 902 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 903 }
Pokitto 22:e826f80d8582 904 /** rightmost scanline twice**/
Pokitto 22:e826f80d8582 905 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 906 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 907 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 908 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 909 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 910 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 911 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 912 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 913 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 914 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 915 }
Pokitto 22:e826f80d8582 916
Pokitto 22:e826f80d8582 917 for (s=0;s<88;) {
Pokitto 22:e826f80d8582 918 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 919 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 920 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 921 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 922 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 923 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 924 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 925 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 926 }
Pokitto 22:e826f80d8582 927 }
Pokitto 22:e826f80d8582 928 }
Pokitto 22:e826f80d8582 929
Pokitto 22:e826f80d8582 930 void Pokitto::lcdRefreshMode3(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 931 uint16_t x,y;
Pokitto 22:e826f80d8582 932 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 22:e826f80d8582 933 uint8_t *d;
Pokitto 22:e826f80d8582 934
Pokitto 22:e826f80d8582 935 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 936 write_data(0); // 0
Pokitto 22:e826f80d8582 937 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 938 write_data(0);
Pokitto 22:e826f80d8582 939 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 940 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 941
Pokitto 22:e826f80d8582 942 for(x=0;x<220;x+=2)
Pokitto 22:e826f80d8582 943 {
Pokitto 22:e826f80d8582 944 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 22:e826f80d8582 945 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 946 uint8_t s=0;
Pokitto 22:e826f80d8582 947 for(y=0;y<176;y++)
Pokitto 22:e826f80d8582 948 {
Pokitto 22:e826f80d8582 949 uint8_t t = *d >> 4; // higher nibble
Pokitto 22:e826f80d8582 950 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 22:e826f80d8582 951 /** higher nibble = left pixel in pixel pair **/
Pokitto 22:e826f80d8582 952 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 953 scanline[1][s++] = paletteptr[t2];
Pokitto 22:e826f80d8582 954 /** testing only **/
Pokitto 22:e826f80d8582 955 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 22:e826f80d8582 956 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 22:e826f80d8582 957 //s++;
Pokitto 22:e826f80d8582 958 /** until here **/
Pokitto 22:e826f80d8582 959 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 960 }
Pokitto 22:e826f80d8582 961 s=0;
Pokitto 22:e826f80d8582 962 /** draw scanlines **/
Pokitto 22:e826f80d8582 963 /** leftmost scanline**/
Pokitto 22:e826f80d8582 964
Pokitto 22:e826f80d8582 965 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 966 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 967 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 968 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 969 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 970 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 971 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 972 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 973 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 974 }
Pokitto 22:e826f80d8582 975
Pokitto 22:e826f80d8582 976 /** rightmost scanline**/
Pokitto 22:e826f80d8582 977 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 978 for (s=0;s<176;) {
Pokitto 22:e826f80d8582 979 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 980 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 981 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 982 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 983 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 984 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 985 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 986 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 987 }
Pokitto 22:e826f80d8582 988 }
Pokitto 22:e826f80d8582 989 }
Pokitto 22:e826f80d8582 990
Pokitto 22:e826f80d8582 991 void Pokitto::lcdRefreshGB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 992 uint16_t x,y;
Pokitto 22:e826f80d8582 993 uint16_t scanline[48];
Pokitto 22:e826f80d8582 994 uint8_t * d;
Pokitto 22:e826f80d8582 995
Pokitto 22:e826f80d8582 996 #if POK_STRETCH
Pokitto 22:e826f80d8582 997 //uint16_t xptr = 8;
Pokitto 22:e826f80d8582 998 #else
Pokitto 22:e826f80d8582 999 //xptr = 26;
Pokitto 22:e826f80d8582 1000 #endif
Pokitto 22:e826f80d8582 1001
Pokitto 22:e826f80d8582 1002 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 1003 write_data(0); // 0
Pokitto 22:e826f80d8582 1004 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 1005 write_data(0);
Pokitto 22:e826f80d8582 1006 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 1007 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 1008
Pokitto 22:e826f80d8582 1009 /** draw border **/
Pokitto 22:e826f80d8582 1010 for (int s=0;s<5*176;) {
Pokitto 22:e826f80d8582 1011 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 22:e826f80d8582 1012 }
Pokitto 22:e826f80d8582 1013
Pokitto 22:e826f80d8582 1014 for(x=0;x<84;x++)
Pokitto 22:e826f80d8582 1015 {
Pokitto 22:e826f80d8582 1016
Pokitto 22:e826f80d8582 1017 d = scrbuf + x;// point to beginning of line in data
Pokitto 22:e826f80d8582 1018
Pokitto 22:e826f80d8582 1019 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 1020 uint8_t s=0;
Pokitto 22:e826f80d8582 1021 for(y=0;y<6;y++)
Pokitto 22:e826f80d8582 1022 {
Pokitto 22:e826f80d8582 1023 uint8_t t = *d;
Pokitto 22:e826f80d8582 1024 #if POK_COLORDEPTH > 1
Pokitto 22:e826f80d8582 1025 uint8_t t2 = *(d+504);
Pokitto 22:e826f80d8582 1026 #endif
Pokitto 22:e826f80d8582 1027 #if POK_COLORDEPTH > 2
Pokitto 22:e826f80d8582 1028 uint8_t t3 = *(d+504+504);
Pokitto 22:e826f80d8582 1029 #endif
Pokitto 22:e826f80d8582 1030 #if POK_COLORDEPTH > 3
Pokitto 22:e826f80d8582 1031 uint8_t t4 = *(d+504+504+504);
Pokitto 22:e826f80d8582 1032 #endif
Pokitto 22:e826f80d8582 1033 uint8_t paletteindex = 0;
Pokitto 22:e826f80d8582 1034
Pokitto 22:e826f80d8582 1035 /** bit 1 **/
Pokitto 22:e826f80d8582 1036 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1037 paletteindex = (t & 0x1);
Pokitto 22:e826f80d8582 1038 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1039 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 22:e826f80d8582 1040 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1041 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 22:e826f80d8582 1042 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1043 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 22:e826f80d8582 1044 #endif
Pokitto 22:e826f80d8582 1045 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1046
Pokitto 22:e826f80d8582 1047 /** bit 2 **/
Pokitto 22:e826f80d8582 1048 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1049 paletteindex = (t & 0x2)>>1;
Pokitto 22:e826f80d8582 1050 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1051 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 22:e826f80d8582 1052 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1053 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 22:e826f80d8582 1054 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1055 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 22:e826f80d8582 1056 #endif
Pokitto 22:e826f80d8582 1057 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1058
Pokitto 22:e826f80d8582 1059 /** bit 3 **/
Pokitto 22:e826f80d8582 1060 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1061 paletteindex = (t & 0x4)>>2;
Pokitto 22:e826f80d8582 1062 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1063 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 22:e826f80d8582 1064 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1065 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 22:e826f80d8582 1066 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1067 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 22:e826f80d8582 1068 #endif
Pokitto 22:e826f80d8582 1069 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1070
Pokitto 22:e826f80d8582 1071 /** bit 4 **/
Pokitto 22:e826f80d8582 1072 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1073 paletteindex = (t & 0x8)>>3;
Pokitto 22:e826f80d8582 1074 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1075 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 22:e826f80d8582 1076 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1077 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 22:e826f80d8582 1078 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1079 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 22:e826f80d8582 1080 #endif
Pokitto 22:e826f80d8582 1081 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1082
Pokitto 22:e826f80d8582 1083 /** bit 5 **/
Pokitto 22:e826f80d8582 1084 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1085 paletteindex = (t & 0x10)>>4;
Pokitto 22:e826f80d8582 1086 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1087 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 22:e826f80d8582 1088 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1089 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 22:e826f80d8582 1090 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1091 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 22:e826f80d8582 1092 #endif
Pokitto 22:e826f80d8582 1093 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1094
Pokitto 22:e826f80d8582 1095 /** bit 6 **/
Pokitto 22:e826f80d8582 1096 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1097 paletteindex = (t & 0x20)>>5;
Pokitto 22:e826f80d8582 1098 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1099 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 22:e826f80d8582 1100 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1101 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 22:e826f80d8582 1102 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1103 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 22:e826f80d8582 1104 #endif
Pokitto 22:e826f80d8582 1105 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1106
Pokitto 22:e826f80d8582 1107 /** bit 7 **/
Pokitto 22:e826f80d8582 1108 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1109 paletteindex = (t & 0x40)>>6;
Pokitto 22:e826f80d8582 1110 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1111 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 22:e826f80d8582 1112 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1113 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 22:e826f80d8582 1114 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1115 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 22:e826f80d8582 1116 #endif
Pokitto 22:e826f80d8582 1117 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1118
Pokitto 22:e826f80d8582 1119 /** bit 8 **/
Pokitto 22:e826f80d8582 1120 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1121 paletteindex = (t & 0x80)>>7;
Pokitto 22:e826f80d8582 1122 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1123 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 22:e826f80d8582 1124 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1125 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 22:e826f80d8582 1126 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1127 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 22:e826f80d8582 1128 #endif
Pokitto 22:e826f80d8582 1129 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1130
Pokitto 22:e826f80d8582 1131 d+=84; // jump to byte directly below
Pokitto 22:e826f80d8582 1132 }
Pokitto 22:e826f80d8582 1133
Pokitto 22:e826f80d8582 1134
Pokitto 22:e826f80d8582 1135 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 1136 write_data(0x10); // 0
Pokitto 22:e826f80d8582 1137 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 1138 write_data(xptr++);
Pokitto 22:e826f80d8582 1139 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 1140 CLR_CS_SET_CD_RD_WR;*/
Pokitto 22:e826f80d8582 1141 /** draw border **/
Pokitto 22:e826f80d8582 1142 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 22:e826f80d8582 1143
Pokitto 22:e826f80d8582 1144 s=0;
Pokitto 22:e826f80d8582 1145
Pokitto 22:e826f80d8582 1146 /** draw scanlines **/
Pokitto 22:e826f80d8582 1147 for (s=0;s<48;) {
Pokitto 22:e826f80d8582 1148 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1149 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1150 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1151 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1152 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1153 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1154 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1155 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1156 }
Pokitto 22:e826f80d8582 1157 /** draw border **/
Pokitto 22:e826f80d8582 1158 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 22:e826f80d8582 1159
Pokitto 22:e826f80d8582 1160
Pokitto 22:e826f80d8582 1161 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 1162 write_data(0x10); // 0
Pokitto 22:e826f80d8582 1163 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 1164 write_data(xptr++);
Pokitto 22:e826f80d8582 1165 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 1166 CLR_CS_SET_CD_RD_WR;*/
Pokitto 22:e826f80d8582 1167 /** draw border **/
Pokitto 22:e826f80d8582 1168 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 22:e826f80d8582 1169
Pokitto 22:e826f80d8582 1170 for (s=0;s<48;) {
Pokitto 22:e826f80d8582 1171 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1172 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1173 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1174 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1175 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1176 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1177 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1178 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1179 }
Pokitto 22:e826f80d8582 1180
Pokitto 22:e826f80d8582 1181 /** draw border **/
Pokitto 22:e826f80d8582 1182 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 22:e826f80d8582 1183
Pokitto 22:e826f80d8582 1184
Pokitto 22:e826f80d8582 1185 #if POK_STRETCH
Pokitto 22:e826f80d8582 1186 //if (x>16 && x<68)
Pokitto 22:e826f80d8582 1187 if (x&2)// && x&2)
Pokitto 22:e826f80d8582 1188 {
Pokitto 22:e826f80d8582 1189 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 1190 write_data(0x10); // 0
Pokitto 22:e826f80d8582 1191 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 1192 write_data(xptr++);
Pokitto 22:e826f80d8582 1193 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 1194 CLR_CS_SET_CD_RD_WR;*/
Pokitto 22:e826f80d8582 1195 /** draw border **/
Pokitto 22:e826f80d8582 1196 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 22:e826f80d8582 1197
Pokitto 22:e826f80d8582 1198
Pokitto 22:e826f80d8582 1199 for (s=0;s<48;) {
Pokitto 22:e826f80d8582 1200 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1201 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1202 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1203 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1204 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1205 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1206 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1207 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1208 }
Pokitto 22:e826f80d8582 1209
Pokitto 22:e826f80d8582 1210 /** draw border **/
Pokitto 22:e826f80d8582 1211 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 22:e826f80d8582 1212
Pokitto 22:e826f80d8582 1213 }
Pokitto 22:e826f80d8582 1214 #endif
Pokitto 22:e826f80d8582 1215 }
Pokitto 22:e826f80d8582 1216 /** draw border **/
Pokitto 22:e826f80d8582 1217 for (int s=0;s<5*176;) {
Pokitto 22:e826f80d8582 1218 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 22:e826f80d8582 1219 }
Pokitto 22:e826f80d8582 1220 }
Pokitto 22:e826f80d8582 1221
Pokitto 22:e826f80d8582 1222
Pokitto 22:e826f80d8582 1223 void Pokitto::lcdRefreshAB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 1224 uint16_t x,y;
Pokitto 22:e826f80d8582 1225 uint16_t scanline[64];
Pokitto 22:e826f80d8582 1226 uint8_t *d;
Pokitto 22:e826f80d8582 1227 //lcdClear();
Pokitto 22:e826f80d8582 1228 #if POK_STRETCH
Pokitto 22:e826f80d8582 1229 uint16_t xptr = 14;
Pokitto 22:e826f80d8582 1230 uint8_t yoffset = 24;
Pokitto 22:e826f80d8582 1231 #else
Pokitto 22:e826f80d8582 1232 xptr = 0; //was 26
Pokitto 22:e826f80d8582 1233 #endif
Pokitto 22:e826f80d8582 1234
Pokitto 22:e826f80d8582 1235 for(x=0;x<128;x++)
Pokitto 22:e826f80d8582 1236 {
Pokitto 22:e826f80d8582 1237 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 1238 write_data(yoffset); // 0
Pokitto 22:e826f80d8582 1239 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 1240 write_data(xptr++);
Pokitto 22:e826f80d8582 1241 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 1242 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 1243 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 1244
Pokitto 22:e826f80d8582 1245 d = scrbuf + x;// point to beginning of line in data
Pokitto 22:e826f80d8582 1246
Pokitto 22:e826f80d8582 1247 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 1248 uint8_t s=0;
Pokitto 22:e826f80d8582 1249 for(y=0;y<8;y++)
Pokitto 22:e826f80d8582 1250 {
Pokitto 22:e826f80d8582 1251 uint8_t t = *d;
Pokitto 22:e826f80d8582 1252 #if POK_COLORDEPTH > 1
Pokitto 22:e826f80d8582 1253 uint8_t t2 = *(d+AB_JUMP);
Pokitto 22:e826f80d8582 1254 #endif // POK_COLORDEPTH
Pokitto 22:e826f80d8582 1255 #if POK_COLORDEPTH > 2
Pokitto 22:e826f80d8582 1256 uint8_t t3 = *(d+AB_JUMP+AB_JUMP);
Pokitto 22:e826f80d8582 1257 #endif // POK_COLORDEPTH
Pokitto 22:e826f80d8582 1258 #if POK_COLORDEPTH > 3
Pokitto 22:e826f80d8582 1259 uint8_t t4 = *(d+AB_JUMP+AB_JUMP+AB_JUMP);
Pokitto 22:e826f80d8582 1260 #endif // POK_COLORDEPTH
Pokitto 22:e826f80d8582 1261 uint8_t paletteindex = 0;
Pokitto 22:e826f80d8582 1262
Pokitto 22:e826f80d8582 1263 /** bit 1 **/
Pokitto 22:e826f80d8582 1264 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1265 paletteindex = (t & 0x1);
Pokitto 22:e826f80d8582 1266 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1267 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 22:e826f80d8582 1268 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1269 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 22:e826f80d8582 1270 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1271 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 22:e826f80d8582 1272 #endif
Pokitto 22:e826f80d8582 1273 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1274
Pokitto 22:e826f80d8582 1275 /** bit 2 **/
Pokitto 22:e826f80d8582 1276 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1277 paletteindex = (t & 0x2)>>1;
Pokitto 22:e826f80d8582 1278 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1279 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 22:e826f80d8582 1280 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1281 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 22:e826f80d8582 1282 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1283 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 22:e826f80d8582 1284 #endif
Pokitto 22:e826f80d8582 1285 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1286
Pokitto 22:e826f80d8582 1287 /** bit 3 **/
Pokitto 22:e826f80d8582 1288 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1289 paletteindex = (t & 0x4)>>2;
Pokitto 22:e826f80d8582 1290 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1291 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 22:e826f80d8582 1292 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1293 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 22:e826f80d8582 1294 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1295 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 22:e826f80d8582 1296 #endif
Pokitto 22:e826f80d8582 1297 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1298
Pokitto 22:e826f80d8582 1299 /** bit 4 **/
Pokitto 22:e826f80d8582 1300 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1301 paletteindex = (t & 0x8)>>3;
Pokitto 22:e826f80d8582 1302 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1303 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 22:e826f80d8582 1304 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1305 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 22:e826f80d8582 1306 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1307 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 22:e826f80d8582 1308 #endif
Pokitto 22:e826f80d8582 1309 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1310
Pokitto 22:e826f80d8582 1311 /** bit 5 **/
Pokitto 22:e826f80d8582 1312 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1313 paletteindex = (t & 0x10)>>4;
Pokitto 22:e826f80d8582 1314 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1315 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 22:e826f80d8582 1316 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1317 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 22:e826f80d8582 1318 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1319 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 22:e826f80d8582 1320 #endif
Pokitto 22:e826f80d8582 1321 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1322
Pokitto 22:e826f80d8582 1323 /** bit 6 **/
Pokitto 22:e826f80d8582 1324 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1325 paletteindex = (t & 0x20)>>5;
Pokitto 22:e826f80d8582 1326 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1327 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 22:e826f80d8582 1328 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1329 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 22:e826f80d8582 1330 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1331 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 22:e826f80d8582 1332 #endif
Pokitto 22:e826f80d8582 1333 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1334
Pokitto 22:e826f80d8582 1335 /** bit 7 **/
Pokitto 22:e826f80d8582 1336 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1337 paletteindex = (t & 0x40)>>6;
Pokitto 22:e826f80d8582 1338 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1339 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 22:e826f80d8582 1340 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1341 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 22:e826f80d8582 1342 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1343 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 22:e826f80d8582 1344 #endif
Pokitto 22:e826f80d8582 1345 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1346
Pokitto 22:e826f80d8582 1347 /** bit 8 **/
Pokitto 22:e826f80d8582 1348 #if POK_COLORDEPTH == 1
Pokitto 22:e826f80d8582 1349 paletteindex = (t & 0x80)>>7;
Pokitto 22:e826f80d8582 1350 #elif POK_COLORDEPTH == 2
Pokitto 22:e826f80d8582 1351 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 22:e826f80d8582 1352 #elif POK_COLORDEPTH == 3
Pokitto 22:e826f80d8582 1353 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 22:e826f80d8582 1354 #elif POK_COLORDEPTH == 4
Pokitto 22:e826f80d8582 1355 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 22:e826f80d8582 1356 #endif
Pokitto 22:e826f80d8582 1357 scanline[s++] = paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1358
Pokitto 22:e826f80d8582 1359 d+=128; // jump to byte directly below
Pokitto 22:e826f80d8582 1360 }
Pokitto 22:e826f80d8582 1361
Pokitto 22:e826f80d8582 1362 s=0;
Pokitto 22:e826f80d8582 1363
Pokitto 22:e826f80d8582 1364 /** draw scanlines **/
Pokitto 22:e826f80d8582 1365 for (s=0;s<64;) {
Pokitto 22:e826f80d8582 1366 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1367 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1368 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1369 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1370 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1371 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1372 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1373 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1374 }
Pokitto 22:e826f80d8582 1375
Pokitto 22:e826f80d8582 1376 #if POK_STRETCH
Pokitto 22:e826f80d8582 1377 if (x&1) {
Pokitto 22:e826f80d8582 1378 write_command(0x20); // Horizontal DRAM Address
Pokitto 22:e826f80d8582 1379 write_data(yoffset); // 0
Pokitto 22:e826f80d8582 1380 write_command(0x21); // Vertical DRAM Address
Pokitto 22:e826f80d8582 1381 write_data(xptr++);
Pokitto 22:e826f80d8582 1382 write_command(0x22); // write data to DRAM
Pokitto 22:e826f80d8582 1383 CLR_CS_SET_CD_RD_WR;
Pokitto 22:e826f80d8582 1384 //setDRAMptr(xptr++,yoffset);
Pokitto 22:e826f80d8582 1385
Pokitto 22:e826f80d8582 1386 for (s=0;s<64;) {
Pokitto 22:e826f80d8582 1387 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1388 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1389 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1390 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1391 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1392 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1393 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1394 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1395 }
Pokitto 22:e826f80d8582 1396 }
Pokitto 22:e826f80d8582 1397 #endif
Pokitto 22:e826f80d8582 1398 }
Pokitto 22:e826f80d8582 1399 }
Pokitto 22:e826f80d8582 1400
Pokitto 22:e826f80d8582 1401 void Pokitto::lcdRefreshModeGBC(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 1402 uint16_t x,y,xptr;
Pokitto 22:e826f80d8582 1403 uint16_t scanline[4][144]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 22:e826f80d8582 1404 uint8_t *d, yoffset=0;
Pokitto 22:e826f80d8582 1405
Pokitto 22:e826f80d8582 1406 xptr = 0;
Pokitto 22:e826f80d8582 1407 setDRAMptr(xptr,yoffset);
Pokitto 22:e826f80d8582 1408
Pokitto 22:e826f80d8582 1409
Pokitto 22:e826f80d8582 1410 for(x=0;x<160;x+=4)
Pokitto 22:e826f80d8582 1411 {
Pokitto 22:e826f80d8582 1412 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 22:e826f80d8582 1413 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 1414 uint8_t s=0;
Pokitto 22:e826f80d8582 1415 for(y=0;y<144;y++)
Pokitto 22:e826f80d8582 1416 {
Pokitto 22:e826f80d8582 1417 uint8_t tdata = *d;
Pokitto 22:e826f80d8582 1418 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 22:e826f80d8582 1419 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 22:e826f80d8582 1420 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 22:e826f80d8582 1421 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 22:e826f80d8582 1422
Pokitto 22:e826f80d8582 1423 /** put nibble values in the scanlines **/
Pokitto 22:e826f80d8582 1424
Pokitto 22:e826f80d8582 1425 scanline[0][s] = paletteptr[t];
Pokitto 22:e826f80d8582 1426 scanline[1][s] = paletteptr[t2];
Pokitto 22:e826f80d8582 1427 scanline[2][s] = paletteptr[t3];
Pokitto 22:e826f80d8582 1428 scanline[3][s++] = paletteptr[t4];
Pokitto 22:e826f80d8582 1429
Pokitto 22:e826f80d8582 1430 d+=160/4; // jump to read byte directly below in screenbuffer
Pokitto 22:e826f80d8582 1431 }
Pokitto 22:e826f80d8582 1432
Pokitto 22:e826f80d8582 1433 s=0;
Pokitto 22:e826f80d8582 1434 /** draw scanlines **/
Pokitto 22:e826f80d8582 1435 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1436 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1437 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1438 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1439 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1440 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1441 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1442 }
Pokitto 22:e826f80d8582 1443 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1444 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1445 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1446 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1447 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1448 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1449 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1450 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1451 }
Pokitto 22:e826f80d8582 1452 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1453 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1454 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1455 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1456 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1457 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1458 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1459 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1460 }
Pokitto 22:e826f80d8582 1461 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1462 for (s=0;s<144;) {
Pokitto 22:e826f80d8582 1463 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1464 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1465 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1466 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1467 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1468 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1469 }
Pokitto 22:e826f80d8582 1470 setDRAMptr(++xptr,yoffset);
Pokitto 22:e826f80d8582 1471 }
Pokitto 22:e826f80d8582 1472 }
Pokitto 22:e826f80d8582 1473
Pokitto 22:e826f80d8582 1474
Pokitto 22:e826f80d8582 1475 void Pokitto::lcdRefreshT1(uint8_t* tilebuf, uint8_t* tilecolorbuf, uint8_t* tileset, uint16_t* paletteptr) {
Pokitto 22:e826f80d8582 1476 #ifdef POK_TILEMODE
Pokitto 22:e826f80d8582 1477 uint16_t x,y,data,xptr;
Pokitto 22:e826f80d8582 1478 uint16_t scanline[176];
Pokitto 22:e826f80d8582 1479 uint8_t yoffset=0, tilebyte, tileindex, tilex=0, tiley=0,xcount;
Pokitto 22:e826f80d8582 1480
Pokitto 22:e826f80d8582 1481
Pokitto 22:e826f80d8582 1482 if (!tileset) return;
Pokitto 22:e826f80d8582 1483
Pokitto 22:e826f80d8582 1484 #if LCDWIDTH < POK_LCD_W
Pokitto 22:e826f80d8582 1485 xptr = (POK_LCD_W-LCDWIDTH)/2;
Pokitto 22:e826f80d8582 1486 #else
Pokitto 22:e826f80d8582 1487 xptr = 0;
Pokitto 22:e826f80d8582 1488 #endif
Pokitto 22:e826f80d8582 1489 #if LCDHEIGHT < POK_LCD_H
Pokitto 22:e826f80d8582 1490 yoffset = (POK_LCD_H-LCDHEIGHT)/2;
Pokitto 22:e826f80d8582 1491 #else
Pokitto 22:e826f80d8582 1492 yoffset = 0;
Pokitto 22:e826f80d8582 1493 #endif
Pokitto 22:e826f80d8582 1494
Pokitto 22:e826f80d8582 1495 for(x=0, xcount=0 ;x<LCDWIDTH;x++,xcount++) // loop through vertical columns
Pokitto 22:e826f80d8582 1496 {
Pokitto 22:e826f80d8582 1497 setDRAMptr(xptr++,yoffset); //point to VRAM
Pokitto 22:e826f80d8582 1498
Pokitto 22:e826f80d8582 1499 /** find colours in one scanline **/
Pokitto 22:e826f80d8582 1500 uint8_t s=0, tiley=0;
Pokitto 22:e826f80d8582 1501 //tileindex = tilebuf[tilex*POK_TILES_Y];
Pokitto 22:e826f80d8582 1502 if (xcount==POK_TILE_W) {
Pokitto 22:e826f80d8582 1503 tilex++;
Pokitto 22:e826f80d8582 1504 xcount=0;
Pokitto 22:e826f80d8582 1505 }
Pokitto 22:e826f80d8582 1506
Pokitto 22:e826f80d8582 1507 for(y=0;y<LCDHEIGHT;)
Pokitto 22:e826f80d8582 1508 {
Pokitto 22:e826f80d8582 1509 uint8_t tileval = tilebuf[tilex+tiley*POK_TILES_X]; //get tile number
Pokitto 22:e826f80d8582 1510 uint16_t index = tileval*POK_TILE_W+xcount;
Pokitto 22:e826f80d8582 1511 uint8_t tilebyte = tileset[index]; //get bitmap data
Pokitto 22:e826f80d8582 1512 for (uint8_t ycount=0, bitcount=0; ycount<POK_TILE_H; ycount++, y++, bitcount++) {
Pokitto 22:e826f80d8582 1513 if (bitcount==8) {
Pokitto 22:e826f80d8582 1514 bitcount=0;
Pokitto 22:e826f80d8582 1515 index += 176; //jump to byte below in the tileset bitmap
Pokitto 22:e826f80d8582 1516 tilebyte = tileset[index]; //get bitmap data
Pokitto 22:e826f80d8582 1517 }
Pokitto 22:e826f80d8582 1518 //tilebyte = tile[(tileindex>>4)+*POK_TILE_W]; //tilemaps are 16x16
Pokitto 22:e826f80d8582 1519 //uint8_t paletteindex = ((tilebyte>>(bitcount&0x7)) & 0x1);
Pokitto 22:e826f80d8582 1520 if (!tileval) scanline[s++] = COLOR_MAGENTA*((tilebyte>>bitcount)&0x1);//paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1521 else scanline[s++] = paletteptr[((tilebyte>>bitcount)&0x1)*tileval];//paletteptr[paletteindex];
Pokitto 22:e826f80d8582 1522 }
Pokitto 22:e826f80d8582 1523 tiley++; //move to next tile
Pokitto 22:e826f80d8582 1524 }
Pokitto 22:e826f80d8582 1525 s=0;
Pokitto 22:e826f80d8582 1526
Pokitto 22:e826f80d8582 1527 /** draw scanlines **/
Pokitto 22:e826f80d8582 1528 for (s=0;s<LCDHEIGHT;) {
Pokitto 22:e826f80d8582 1529 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1530 }
Pokitto 22:e826f80d8582 1531 }
Pokitto 22:e826f80d8582 1532 #endif
Pokitto 22:e826f80d8582 1533 }
Pokitto 22:e826f80d8582 1534
Pokitto 23:f88837b8f914 1535
Pokitto 23:f88837b8f914 1536 void Pokitto::lcdRefreshMode13(uint8_t * scrbuf, uint16_t* paletteptr, uint8_t offset){
Pokitto 23:f88837b8f914 1537 uint16_t x,y;
Pokitto 23:f88837b8f914 1538 uint16_t scanline[2][110]; // read two nibbles = pixels at a time
Pokitto 23:f88837b8f914 1539 uint8_t *d;
Pokitto 23:f88837b8f914 1540
Pokitto 23:f88837b8f914 1541 write_command(0x20); write_data(0);
Pokitto 23:f88837b8f914 1542 write_command(0x21); write_data(0);
Pokitto 23:f88837b8f914 1543 write_command(0x22);
Pokitto 23:f88837b8f914 1544 CLR_CS_SET_CD_RD_WR;
Pokitto 23:f88837b8f914 1545
Pokitto 23:f88837b8f914 1546 for(x=0;x<110;x+=2)
Pokitto 23:f88837b8f914 1547 {
Pokitto 23:f88837b8f914 1548 d = scrbuf+x;// point to beginning of line in data
Pokitto 23:f88837b8f914 1549 uint8_t s=0;
Pokitto 23:f88837b8f914 1550 for(y=0;y<88;y++)
Pokitto 23:f88837b8f914 1551 {
Pokitto 23:f88837b8f914 1552 uint8_t t = *d;
Pokitto 23:f88837b8f914 1553 uint8_t t1 = *(d+1);
Pokitto 23:f88837b8f914 1554 scanline[0][s] = paletteptr[(t+offset)&255];
Pokitto 23:f88837b8f914 1555 scanline[1][s++] = paletteptr[(t1+offset)&255];
Pokitto 23:f88837b8f914 1556 d+=110; // jump to read byte directly below in screenbuffer
Pokitto 23:f88837b8f914 1557 }
Pokitto 23:f88837b8f914 1558 s=0;
Pokitto 23:f88837b8f914 1559 for (s=0;s<88;) {
Pokitto 23:f88837b8f914 1560 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1561 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1562 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1563 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1564 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1565 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1566 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1567 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1568 }
Pokitto 23:f88837b8f914 1569 for (s=0;s<88;) {
Pokitto 23:f88837b8f914 1570 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1571 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1572 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1573 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1574 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1575 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1576 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1577 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1578 }
Pokitto 23:f88837b8f914 1579 for (s=0;s<88;) {
Pokitto 23:f88837b8f914 1580 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1581 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1582 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1583 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1584 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1585 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1586 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1587 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1588 }
Pokitto 23:f88837b8f914 1589 for (s=0;s<88;) {
Pokitto 23:f88837b8f914 1590 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1591 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1592 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1593 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1594 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1595 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1596 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1597 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 23:f88837b8f914 1598 }
Pokitto 23:f88837b8f914 1599 }
Pokitto 23:f88837b8f914 1600
Pokitto 23:f88837b8f914 1601 }
Pokitto 23:f88837b8f914 1602
Pokitto 23:f88837b8f914 1603
Pokitto 23:f88837b8f914 1604
Pokitto 23:f88837b8f914 1605
Pokitto 22:e826f80d8582 1606 void Pokitto::blitWord(uint16_t c) {
Pokitto 22:e826f80d8582 1607 setup_data_16(c);CLR_WR;SET_WR;
Pokitto 22:e826f80d8582 1608 }
Pokitto 22:e826f80d8582 1609
Pokitto 22:e826f80d8582 1610
Pokitto 23:f88837b8f914 1611