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

Committer:
spinal
Date:
Sun Nov 18 15:47:54 2018 +0000
Revision:
64:6e6c6c2b664e
Parent:
60:8b6a110feeea
added fix for directrectangle()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 46:e7e438368e16 1 /**************************************************************************/
Pokitto 46:e7e438368e16 2 /*!
Pokitto 46:e7e438368e16 3 @file HWLCD.cpp
Pokitto 46:e7e438368e16 4 @author Jonne Valola
Pokitto 46:e7e438368e16 5
Pokitto 46:e7e438368e16 6 @section LICENSE
Pokitto 46:e7e438368e16 7
Pokitto 46:e7e438368e16 8 Software License Agreement (BSD License)
Pokitto 46:e7e438368e16 9
Pokitto 46:e7e438368e16 10 Copyright (c) 2016, Jonne Valola
Pokitto 46:e7e438368e16 11 All rights reserved.
Pokitto 46:e7e438368e16 12
Pokitto 46:e7e438368e16 13 Redistribution and use in source and binary forms, with or without
Pokitto 46:e7e438368e16 14 modification, are permitted provided that the following conditions are met:
Pokitto 46:e7e438368e16 15 1. Redistributions of source code must retain the above copyright
Pokitto 46:e7e438368e16 16 notice, this list of conditions and the following disclaimer.
Pokitto 46:e7e438368e16 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 46:e7e438368e16 18 notice, this list of conditions and the following disclaimer in the
Pokitto 46:e7e438368e16 19 documentation and/or other materials provided with the distribution.
Pokitto 46:e7e438368e16 20 3. Neither the name of the copyright holders nor the
Pokitto 46:e7e438368e16 21 names of its contributors may be used to endorse or promote products
Pokitto 46:e7e438368e16 22 derived from this software without specific prior written permission.
Pokitto 46:e7e438368e16 23
Pokitto 46:e7e438368e16 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 46:e7e438368e16 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 46:e7e438368e16 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 46:e7e438368e16 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 46:e7e438368e16 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 46:e7e438368e16 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 46:e7e438368e16 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 46:e7e438368e16 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 46:e7e438368e16 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 46:e7e438368e16 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 46:e7e438368e16 34 */
Pokitto 46:e7e438368e16 35 /**************************************************************************/
Pokitto 46:e7e438368e16 36
Pokitto 46:e7e438368e16 37 #include "HWLCD.h" //HWLCD.h" #include "HWLCD.h"
Pokitto 46:e7e438368e16 38 #include "Pokitto_settings.h"
Pokitto 46:e7e438368e16 39
Pokitto 51:113b1d84c34f 40 #define avrmax(a,b) ((a)>(b)?(a):(b))
Pokitto 51:113b1d84c34f 41 #define avrmin(a,b) ((a)<(b)?(a):(b))
Pokitto 46:e7e438368e16 42
Pokitto 46:e7e438368e16 43 #ifdef DISABLEAVRMIN
Pokitto 46:e7e438368e16 44 #include <algorithm>
Pokitto 46:e7e438368e16 45 using std::min;
Pokitto 46:e7e438368e16 46 using std::max;
Pokitto 46:e7e438368e16 47 #endif // DISABLEAVRMIN
Pokitto 46:e7e438368e16 48
Pokitto 46:e7e438368e16 49 #define AB_JUMP 1024 // jump one 1-bit Arduboy screen forward to get next color bit
Pokitto 46:e7e438368e16 50 #define GB_JUMP 504 // jump one 1-bit Gamebuino screen forward to get next color bit
Pokitto 46:e7e438368e16 51
Pokitto 46:e7e438368e16 52 using namespace Pokitto;
Pokitto 46:e7e438368e16 53
Pokitto 46:e7e438368e16 54 uint16_t prevdata=0; // if data does not change, do not adjust LCD bus lines
Pokitto 46:e7e438368e16 55
Pokitto 46:e7e438368e16 56 #if POK_BOARDREV == 2
Pokitto 46:e7e438368e16 57 pwmout_t backlightpwm;
Pokitto 46:e7e438368e16 58 #endif
Pokitto 46:e7e438368e16 59
Pokitto 51:113b1d84c34f 60 volatile uint32_t *LCD = reinterpret_cast< volatile uint32_t * >(0xA0002188);
Pokitto 46:e7e438368e16 61
Pokitto 46:e7e438368e16 62 /**************************************************************************/
Pokitto 46:e7e438368e16 63 /*!
Pokitto 46:e7e438368e16 64 @brief set up the 16-bit bus
Pokitto 46:e7e438368e16 65 */
Pokitto 46:e7e438368e16 66 /**************************************************************************/
Pokitto 46:e7e438368e16 67
Pokitto 46:e7e438368e16 68 static inline void setup_data_16(uint16_t data)
Pokitto 46:e7e438368e16 69 {
Pokitto 46:e7e438368e16 70 //uint32_t p2=0;
Pokitto 46:e7e438368e16 71
Pokitto 46:e7e438368e16 72 //if (data != prevdata) {
Pokitto 46:e7e438368e16 73 //
Pokitto 46:e7e438368e16 74 //prevdata=data;
Pokitto 46:e7e438368e16 75
Pokitto 46:e7e438368e16 76 /** D0...D16 = P2_3 ... P2_18 **/
Pokitto 46:e7e438368e16 77 //p2 = data << 3;
Pokitto 46:e7e438368e16 78
Pokitto 46:e7e438368e16 79 //__disable_irq(); // Disable Interrupts
Pokitto 46:e7e438368e16 80 SET_MASK_P2;
Pokitto 46:e7e438368e16 81 LPC_GPIO_PORT->MPIN[2] = (data<<3); // write bits to port
Pokitto 46:e7e438368e16 82 CLR_MASK_P2;
Pokitto 46:e7e438368e16 83 //__enable_irq(); // Enable Interrupts
Pokitto 46:e7e438368e16 84 //}
Pokitto 46:e7e438368e16 85 }
Pokitto 46:e7e438368e16 86
Pokitto 46:e7e438368e16 87
Pokitto 46:e7e438368e16 88 /**************************************************************************/
Pokitto 46:e7e438368e16 89 /*!
Pokitto 46:e7e438368e16 90 @brief Write a command to the lcd, 16-bit bus
Pokitto 46:e7e438368e16 91 */
Pokitto 46:e7e438368e16 92 /**************************************************************************/
Pokitto 46:e7e438368e16 93 inline void write_command_16(uint16_t data)
Pokitto 46:e7e438368e16 94 {
Pokitto 46:e7e438368e16 95 CLR_CS; // select lcd
Pokitto 46:e7e438368e16 96 CLR_CD; // clear CD = command
Pokitto 46:e7e438368e16 97 SET_RD; // RD high, do not read
Pokitto 46:e7e438368e16 98 setup_data_16(data); // function that inputs the data into the relevant bus lines
Pokitto 46:e7e438368e16 99 CLR_WR_SLOW; // WR low
Pokitto 46:e7e438368e16 100 SET_WR; // WR low, then high = write strobe
Pokitto 46:e7e438368e16 101 SET_CS; // de-select lcd
Pokitto 46:e7e438368e16 102 }
Pokitto 46:e7e438368e16 103
Pokitto 46:e7e438368e16 104 /**************************************************************************/
Pokitto 46:e7e438368e16 105 /*!
Pokitto 46:e7e438368e16 106 @brief Write data to the lcd, 16-bit bus
Pokitto 46:e7e438368e16 107 */
Pokitto 46:e7e438368e16 108 /**************************************************************************/
Pokitto 46:e7e438368e16 109 inline void write_data_16(uint16_t data)
Pokitto 46:e7e438368e16 110 {
Pokitto 46:e7e438368e16 111 CLR_CS;
Pokitto 46:e7e438368e16 112 SET_CD;
Pokitto 46:e7e438368e16 113 SET_RD;
Pokitto 46:e7e438368e16 114 setup_data_16(data);
Pokitto 46:e7e438368e16 115 CLR_WR;
Pokitto 46:e7e438368e16 116 SET_WR;
Pokitto 46:e7e438368e16 117 SET_CS;
Pokitto 46:e7e438368e16 118 }
Pokitto 46:e7e438368e16 119
Pokitto 46:e7e438368e16 120 /**************************************************************************/
Pokitto 46:e7e438368e16 121 /*!
Pokitto 46:e7e438368e16 122 @brief Pump data to the lcd, 16-bit bus, public function
Pokitto 46:e7e438368e16 123 */
Pokitto 46:e7e438368e16 124 /**************************************************************************/
Pokitto 46:e7e438368e16 125 void Pokitto::pumpDRAMdata(uint16_t* data,uint16_t counter)
Pokitto 46:e7e438368e16 126 {
Pokitto 46:e7e438368e16 127 while (counter--) {
Pokitto 46:e7e438368e16 128 CLR_CS;
Pokitto 46:e7e438368e16 129 SET_CD;
Pokitto 46:e7e438368e16 130 SET_RD;
Pokitto 46:e7e438368e16 131 setup_data_16(*data++);
Pokitto 46:e7e438368e16 132 CLR_WR;
Pokitto 46:e7e438368e16 133 SET_WR;
Pokitto 46:e7e438368e16 134 SET_CS;
Pokitto 46:e7e438368e16 135 }
Pokitto 46:e7e438368e16 136 }
Pokitto 46:e7e438368e16 137
Pokitto 46:e7e438368e16 138
Pokitto 46:e7e438368e16 139 /**************************************************************************/
Pokitto 46:e7e438368e16 140 /*!
Pokitto 46:e7e438368e16 141 @brief Point to a (x,y) location in the LCD DRAM
Pokitto 46:e7e438368e16 142 */
Pokitto 46:e7e438368e16 143 /**************************************************************************/
Pokitto 46:e7e438368e16 144 static inline void setDRAMptr(uint8_t xptr, uint8_t yoffset)
Pokitto 46:e7e438368e16 145 {
Pokitto 46:e7e438368e16 146 write_command(0x20); // Vertical DRAM Address
Pokitto 46:e7e438368e16 147 write_data(yoffset);
Pokitto 46:e7e438368e16 148 write_command(0x21); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 149 write_data(xptr); //
Pokitto 46:e7e438368e16 150 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 151 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 152 }
Pokitto 46:e7e438368e16 153
Pokitto 46:e7e438368e16 154 /**************************************************************************/
Pokitto 46:e7e438368e16 155 /*!
Pokitto 46:e7e438368e16 156 @brief Point to a (x,y) location in the LCD DRAM, public function
Pokitto 46:e7e438368e16 157 */
Pokitto 46:e7e438368e16 158 /**************************************************************************/
Pokitto 46:e7e438368e16 159 void Pokitto::setDRAMpoint(uint8_t xptr, uint8_t yoffset)
Pokitto 46:e7e438368e16 160 {
Pokitto 46:e7e438368e16 161 write_command(0x20); // Vertical DRAM Address
Pokitto 46:e7e438368e16 162 write_data(yoffset);
Pokitto 46:e7e438368e16 163 write_command(0x21); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 164 write_data(xptr); //
Pokitto 46:e7e438368e16 165 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 166 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 167 }
Pokitto 46:e7e438368e16 168
Pokitto 46:e7e438368e16 169 void Pokitto::initBacklight() {
Pokitto 46:e7e438368e16 170 #if POK_BOARDREV == 2
Pokitto 46:e7e438368e16 171 pwmout_init(&backlightpwm,POK_BACKLIGHT_PIN);
Pokitto 46:e7e438368e16 172 pwmout_period_us(&backlightpwm,5);
Pokitto 46:e7e438368e16 173 pwmout_write(&backlightpwm,POK_BACKLIGHT_INITIALVALUE);
Pokitto 46:e7e438368e16 174 #endif
Pokitto 46:e7e438368e16 175 }
Pokitto 46:e7e438368e16 176
Pokitto 46:e7e438368e16 177 void Pokitto::setBacklight(float value) {
Pokitto 46:e7e438368e16 178 if (value>0.999f) value = 0.999f;
Pokitto 46:e7e438368e16 179 pwmout_write(&backlightpwm,value);
Pokitto 46:e7e438368e16 180 }
Pokitto 46:e7e438368e16 181
Pokitto 46:e7e438368e16 182 void Pokitto::lcdInit() {
Pokitto 46:e7e438368e16 183 initBacklight();
Pokitto 46:e7e438368e16 184
Pokitto 46:e7e438368e16 185 SET_RESET;
Pokitto 46:e7e438368e16 186 wait_ms(10);
Pokitto 46:e7e438368e16 187 CLR_RESET;
Pokitto 46:e7e438368e16 188 wait_ms(10);
Pokitto 46:e7e438368e16 189 SET_RESET;
Pokitto 46:e7e438368e16 190 wait_ms(10);
Pokitto 46:e7e438368e16 191 //************* Start Initial Sequence **********//
Pokitto 46:e7e438368e16 192 write_command(0x01); // driver output control, this also affects direction
Pokitto 46:e7e438368e16 193 write_data(0x11C); // originally: 0x11C 100011100 SS,NL4,NL3,NL2
Pokitto 46:e7e438368e16 194 // NL4...0 is the number of scan lines to drive the screen !!!
Pokitto 46:e7e438368e16 195 // so 11100 is 1c = 220 lines, correct
Pokitto 46:e7e438368e16 196 // test 1: 0x1C 11100 SS=0,NL4,NL3,NL2 -> no effect
Pokitto 46:e7e438368e16 197 // test 2: 0x31C 1100011100 GS=1,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 46:e7e438368e16 198 // test 3: 0x51C 10100011100 SM=1,GS=0,SS=1,NL4,NL3,NL2 -> no effect
Pokitto 46:e7e438368e16 199 // test 4: 0x71C SM=1,GS=1,SS=1,NL4,NL3,NL2
Pokitto 46:e7e438368e16 200 // test 5: 0x
Pokitto 46:e7e438368e16 201 // seems to have no effect... is this perhaps only for RGB mode ?
Pokitto 46:e7e438368e16 202
Pokitto 46:e7e438368e16 203 write_command(0x02); // LCD driving control
Pokitto 46:e7e438368e16 204 write_data(0x0100); // INV = 1
Pokitto 46:e7e438368e16 205
Pokitto 46:e7e438368e16 206 write_command(0x03); // Entry mode... lets try if this affects the direction
Pokitto 46:e7e438368e16 207 write_data(0x1030); // originally 0x1030 1000000110000 BGR,ID1,ID0
Pokitto 46:e7e438368e16 208 // test 1: 0x1038 1000000111000 BGR,ID1,ID0,AM=1 ->drawing DRAM horizontally
Pokitto 46:e7e438368e16 209 // test 4: am=1, id0=0, id1=0, 1000000001000,0x1008 -> same as above, but flipped on long
Pokitto 46:e7e438368e16 210 // test 2: am=0, id0=0, 1000000100000, 0x1020 -> flipped on long axis
Pokitto 46:e7e438368e16 211 // test 3: am=0, id1=0, 1000000010000, 0x1010 -> picture flowed over back to screen
Pokitto 46:e7e438368e16 212
Pokitto 46:e7e438368e16 213
Pokitto 46:e7e438368e16 214 write_command(0x08); // Display control 2
Pokitto 46:e7e438368e16 215 write_data(0x0808); // 100000001000 FP2,BP2
Pokitto 46:e7e438368e16 216
Pokitto 46:e7e438368e16 217 write_command(0x0C); // RGB display interface
Pokitto 46:e7e438368e16 218 write_data(0x0000); // all off
Pokitto 46:e7e438368e16 219
Pokitto 46:e7e438368e16 220 write_command(0x0F); // Frame marker position
Pokitto 46:e7e438368e16 221 write_data(0x0001); // OSC_EN
Pokitto 46:e7e438368e16 222
Pokitto 46:e7e438368e16 223 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 224 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 225
Pokitto 46:e7e438368e16 226 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 227 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 228
Pokitto 46:e7e438368e16 229 //*************Power On sequence ****************//
Pokitto 46:e7e438368e16 230 write_command(0x10);
Pokitto 46:e7e438368e16 231 write_data(0x0000);
Pokitto 46:e7e438368e16 232
Pokitto 46:e7e438368e16 233 write_command(0x11);
Pokitto 46:e7e438368e16 234 write_data(0x1000);
Pokitto 46:e7e438368e16 235 wait_ms(10);
Pokitto 46:e7e438368e16 236 //------------------------ Set GRAM area --------------------------------//
Pokitto 46:e7e438368e16 237 write_command(0x30); // Gate scan position
Pokitto 46:e7e438368e16 238 write_data(0x0000); // if GS=0, 00h=G1, else 00h=G220
Pokitto 46:e7e438368e16 239
Pokitto 46:e7e438368e16 240 write_command(0x31); // Vertical scroll control
Pokitto 46:e7e438368e16 241 write_data(0x00DB); // scroll start line 11011011 = 219
Pokitto 46:e7e438368e16 242
Pokitto 46:e7e438368e16 243 write_command(0x32); // Vertical scroll control
Pokitto 46:e7e438368e16 244 write_data(0x0000); // scroll end line 0
Pokitto 46:e7e438368e16 245
Pokitto 46:e7e438368e16 246 write_command(0x33); // Vertical scroll control
Pokitto 46:e7e438368e16 247 write_data(0x0000); // 0=vertical scroll disabled
Pokitto 46:e7e438368e16 248
Pokitto 46:e7e438368e16 249 write_command(0x34); // Partial screen driving control
Pokitto 46:e7e438368e16 250 write_data(0x00DB); // db = full screen (end)
Pokitto 46:e7e438368e16 251
Pokitto 46:e7e438368e16 252 write_command(0x35); // partial screen
Pokitto 46:e7e438368e16 253 write_data(0x0000); // 0 = start
Pokitto 46:e7e438368e16 254
Pokitto 46:e7e438368e16 255 write_command(0x36); // Horizontal and vertical RAM position
Pokitto 46:e7e438368e16 256 write_data(0x00AF); //end address 175
Pokitto 46:e7e438368e16 257
Pokitto 46:e7e438368e16 258 write_command(0x37);
Pokitto 46:e7e438368e16 259 write_data(0x0000); // start address 0
Pokitto 46:e7e438368e16 260
Pokitto 46:e7e438368e16 261 write_command(0x38);
Pokitto 46:e7e438368e16 262 write_data(0x00DB); //end address 219
Pokitto 46:e7e438368e16 263
Pokitto 46:e7e438368e16 264 write_command(0x39); // start address 0
Pokitto 46:e7e438368e16 265 write_data(0x0000);
Pokitto 46:e7e438368e16 266 wait_ms(10);
Pokitto 46:e7e438368e16 267 write_command(0xff); // start gamma register control
Pokitto 46:e7e438368e16 268 write_data(0x0003);
Pokitto 46:e7e438368e16 269
Pokitto 46:e7e438368e16 270 // ----------- Adjust the Gamma Curve ----------//
Pokitto 46:e7e438368e16 271 write_command(0x50);
Pokitto 46:e7e438368e16 272 write_data(0x0203);
Pokitto 46:e7e438368e16 273
Pokitto 46:e7e438368e16 274 write_command(0x051);
Pokitto 46:e7e438368e16 275 write_data(0x0A09);
Pokitto 46:e7e438368e16 276
Pokitto 46:e7e438368e16 277 write_command(0x52);
Pokitto 46:e7e438368e16 278 write_data(0x0005);
Pokitto 46:e7e438368e16 279
Pokitto 46:e7e438368e16 280 write_command(0x53);
Pokitto 46:e7e438368e16 281 write_data(0x1021);
Pokitto 46:e7e438368e16 282
Pokitto 46:e7e438368e16 283 write_command(0x54);
Pokitto 46:e7e438368e16 284 write_data(0x0602);
Pokitto 46:e7e438368e16 285
Pokitto 46:e7e438368e16 286 write_command(0x55);
Pokitto 46:e7e438368e16 287 write_data(0x0003);
Pokitto 46:e7e438368e16 288
Pokitto 46:e7e438368e16 289 write_command(0x56);
Pokitto 46:e7e438368e16 290 write_data(0x0703);
Pokitto 46:e7e438368e16 291
Pokitto 46:e7e438368e16 292 write_command(0x57);
Pokitto 46:e7e438368e16 293 write_data(0x0507);
Pokitto 46:e7e438368e16 294
Pokitto 46:e7e438368e16 295 write_command(0x58);
Pokitto 46:e7e438368e16 296 write_data(0x1021);
Pokitto 46:e7e438368e16 297
Pokitto 46:e7e438368e16 298 write_command(0x59);
Pokitto 46:e7e438368e16 299 write_data(0x0703);
Pokitto 46:e7e438368e16 300
Pokitto 46:e7e438368e16 301 write_command(0xB0);
Pokitto 46:e7e438368e16 302 write_data(0x2501);
Pokitto 46:e7e438368e16 303
Pokitto 46:e7e438368e16 304 write_command(0xFF);
Pokitto 46:e7e438368e16 305 write_data(0x0000);
Pokitto 46:e7e438368e16 306
Pokitto 46:e7e438368e16 307 write_command(0x07);
Pokitto 46:e7e438368e16 308 write_data(0x1017);
Pokitto 46:e7e438368e16 309 wait_ms(200);
Pokitto 46:e7e438368e16 310 write_command(0x22);
Pokitto 46:e7e438368e16 311
Pokitto 46:e7e438368e16 312 lcdClear();
Pokitto 46:e7e438368e16 313 }
Pokitto 46:e7e438368e16 314
Pokitto 46:e7e438368e16 315 void Pokitto::lcdSleep(void){
Pokitto 46:e7e438368e16 316 write_command(0xFF);
Pokitto 46:e7e438368e16 317 write_data(0x0000);
Pokitto 46:e7e438368e16 318
Pokitto 46:e7e438368e16 319 write_command(0x07);
Pokitto 46:e7e438368e16 320 write_data(0x0000);
Pokitto 46:e7e438368e16 321 wait_ms(50);
Pokitto 46:e7e438368e16 322 write_command(0x10);// Enter Standby mode
Pokitto 46:e7e438368e16 323 write_data(0x0003);
Pokitto 46:e7e438368e16 324 wait_ms(200);
Pokitto 46:e7e438368e16 325
Pokitto 46:e7e438368e16 326 }
Pokitto 46:e7e438368e16 327
Pokitto 46:e7e438368e16 328 void Pokitto::lcdWakeUp (void){
Pokitto 46:e7e438368e16 329
Pokitto 46:e7e438368e16 330 wait_ms(200);
Pokitto 46:e7e438368e16 331 write_command(0xFF);
Pokitto 46:e7e438368e16 332 write_data(0x0000);
Pokitto 46:e7e438368e16 333
Pokitto 46:e7e438368e16 334 write_command(0x10);// Exit Sleep/ Standby mode
Pokitto 46:e7e438368e16 335 write_data(0x0000);
Pokitto 46:e7e438368e16 336 wait_ms(50);
Pokitto 46:e7e438368e16 337 write_command(0x07);
Pokitto 46:e7e438368e16 338 write_data(0x0117);
Pokitto 46:e7e438368e16 339 wait_ms(200);
Pokitto 46:e7e438368e16 340 }
Pokitto 46:e7e438368e16 341
Pokitto 46:e7e438368e16 342 void Pokitto::lcdFillSurface(uint16_t c) {
Pokitto 46:e7e438368e16 343 uint32_t i;
Pokitto 46:e7e438368e16 344 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 345 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 346 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 347 write_data(0);
Pokitto 46:e7e438368e16 348 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 349 setup_data_16(c);
Pokitto 46:e7e438368e16 350 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 351 for(i=0;i<220*176;i++)
Pokitto 46:e7e438368e16 352 {
Pokitto 46:e7e438368e16 353 CLR_WR;
Pokitto 46:e7e438368e16 354 SET_WR;
Pokitto 46:e7e438368e16 355 }
Pokitto 46:e7e438368e16 356 }
Pokitto 46:e7e438368e16 357
Pokitto 46:e7e438368e16 358 void Pokitto::lcdClear() {
Pokitto 46:e7e438368e16 359 uint32_t i;
Pokitto 46:e7e438368e16 360 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 361 write_data(0x0000); // 0
Pokitto 46:e7e438368e16 362 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 363 write_data(0);
Pokitto 46:e7e438368e16 364 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 365 setup_data_16(0x0000);
Pokitto 46:e7e438368e16 366 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 367 for(i=0;i<220*176;i++)
Pokitto 46:e7e438368e16 368 {
Pokitto 46:e7e438368e16 369 CLR_WR;
Pokitto 46:e7e438368e16 370 SET_WR;
Pokitto 46:e7e438368e16 371 }
Pokitto 46:e7e438368e16 372 }
Pokitto 46:e7e438368e16 373
Pokitto 46:e7e438368e16 374 void Pokitto::lcdPixel(int16_t x, int16_t y, uint16_t color) {
Pokitto 46:e7e438368e16 375 if ((x < 0) || (x >= POK_LCD_W) || (y < 0) || (y >= POK_LCD_H))
Pokitto 46:e7e438368e16 376 return;
Pokitto 46:e7e438368e16 377 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 378 write_data(y); // 0
Pokitto 46:e7e438368e16 379 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 380 write_data(x);
Pokitto 46:e7e438368e16 381 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 382 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 383 setup_data_16(color);
Pokitto 46:e7e438368e16 384 CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 385 }
Pokitto 46:e7e438368e16 386
Pokitto 46:e7e438368e16 387 void Pokitto::setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
Pokitto 46:e7e438368e16 388 write_command(0x37); write_data(x1);
Pokitto 46:e7e438368e16 389 write_command(0x36); write_data(x2);
Pokitto 46:e7e438368e16 390 write_command(0x39); write_data(y1);
Pokitto 46:e7e438368e16 391 write_command(0x38); write_data(y2);
Pokitto 46:e7e438368e16 392 write_command(0x20); write_data(x1);
Pokitto 46:e7e438368e16 393 write_command(0x21); write_data(y1);
Pokitto 46:e7e438368e16 394 }
Pokitto 46:e7e438368e16 395
Pokitto 46:e7e438368e16 396 void Pokitto::lcdTile(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t* gfx){
Pokitto 46:e7e438368e16 397 int width=x1-x0;
Pokitto 46:e7e438368e16 398 int height=y1-y0;
Pokitto 46:e7e438368e16 399 if (x0 > POK_LCD_W) return;
Pokitto 46:e7e438368e16 400 if (y0 > POK_LCD_H) return;
Pokitto 46:e7e438368e16 401 if (x0 < 0) x0=0;
Pokitto 46:e7e438368e16 402 if (y0 < 0) y0=0;
Pokitto 46:e7e438368e16 403
Pokitto 46:e7e438368e16 404 setWindow(y0, x0, y1-1, x1-1);
Pokitto 46:e7e438368e16 405 write_command(0x22);
Pokitto 46:e7e438368e16 406
Pokitto 46:e7e438368e16 407 for (int x=0; x<=width*height-1;x++) {
Pokitto 46:e7e438368e16 408 write_data(gfx[x]);
Pokitto 46:e7e438368e16 409 }
Pokitto 46:e7e438368e16 410 setWindow(0, 0, 175, 219);
Pokitto 46:e7e438368e16 411 }
Pokitto 46:e7e438368e16 412
Pokitto 46:e7e438368e16 413 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 46:e7e438368e16 414 int16_t temp;
Pokitto 46:e7e438368e16 415 if (x0>x1) {temp=x0;x0=x1;x1=temp;}
Pokitto 46:e7e438368e16 416 if (y0>y1) {temp=y0;y0=y1;y1=temp;}
Pokitto 46:e7e438368e16 417 if (x0 > POK_LCD_W) return;
Pokitto 46:e7e438368e16 418 if (y0 > POK_LCD_H) return;
Pokitto 46:e7e438368e16 419 if (x1 > POK_LCD_W) x1=POK_LCD_W;
Pokitto 46:e7e438368e16 420 if (y1 > POK_LCD_H) y1=POK_LCD_H;
Pokitto 46:e7e438368e16 421 if (x0 < 0) x0=0;
Pokitto 46:e7e438368e16 422 if (y0 < 0) y0=0;
spinal 64:6e6c6c2b664e 423
Pokitto 46:e7e438368e16 424 int16_t x,y;
spinal 64:6e6c6c2b664e 425
spinal 64:6e6c6c2b664e 426 for (y=y0; y<y1;y++) {
spinal 64:6e6c6c2b664e 427
spinal 64:6e6c6c2b664e 428 write_command(0x20); // Horizontal DRAM Address (=y on pokitto screen)
spinal 64:6e6c6c2b664e 429
spinal 64:6e6c6c2b664e 430 write_data(y);
spinal 64:6e6c6c2b664e 431
spinal 64:6e6c6c2b664e 432 write_command(0x21); // Vertical DRAM Address (=x on pokitto screen)
spinal 64:6e6c6c2b664e 433
spinal 64:6e6c6c2b664e 434 write_data(x0);
spinal 64:6e6c6c2b664e 435
Pokitto 46:e7e438368e16 436 write_command(0x22); // write data to DRAM
spinal 64:6e6c6c2b664e 437
spinal 64:6e6c6c2b664e 438 CLR_CS_SET_CD_RD_WR; // go to vram write mode
spinal 64:6e6c6c2b664e 439
spinal 64:6e6c6c2b664e 440 for (x=x0; x<x1;x++) {
spinal 64:6e6c6c2b664e 441
spinal 64:6e6c6c2b664e 442 setup_data_16(color); // setup the data (flat color = no change between pixels)
spinal 64:6e6c6c2b664e 443
spinal 64:6e6c6c2b664e 444 CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
spinal 64:6e6c6c2b664e 445
spinal 64:6e6c6c2b664e 446 }
spinal 64:6e6c6c2b664e 447
spinal 64:6e6c6c2b664e 448 }
Pokitto 46:e7e438368e16 449
spinal 64:6e6c6c2b664e 450 }
Pokitto 46:e7e438368e16 451
Pokitto 46:e7e438368e16 452
Pokitto 46:e7e438368e16 453 /***
Pokitto 46:e7e438368e16 454 * Update the screen buffer of 220x176 pixels, 4 colors to LCD.
Pokitto 46:e7e438368e16 455 *
Pokitto 46:e7e438368e16 456 * The update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations, the
Pokitto 46:e7e438368e16 457 * x, y, and width of the update rect must be dividable by 4 pixels, and the height must be dividable by 8 pixels.
Pokitto 46:e7e438368e16 458 * Note: The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 46:e7e438368e16 459 * @param scrbuf The screen buffer.
Pokitto 46:e7e438368e16 460 * @param updRectX The update rect.
Pokitto 46:e7e438368e16 461 * @param updRectY The update rect.
Pokitto 46:e7e438368e16 462 * @param updRectW The update rect.
Pokitto 46:e7e438368e16 463 * @param updRectH The update rect.
Pokitto 46:e7e438368e16 464 * @param paletteptr The screen palette.
Pokitto 46:e7e438368e16 465 */
Pokitto 46:e7e438368e16 466 void Pokitto::lcdRefreshMode1(uint8_t * scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 467
Pokitto 60:8b6a110feeea 468 uint16_t x,y;
Pokitto 46:e7e438368e16 469 uint16_t scanline[4][176]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 60:8b6a110feeea 470 uint8_t *d;
Pokitto 46:e7e438368e16 471
Pokitto 46:e7e438368e16 472 // If not the full screen is updated, check the validity of the update rect.
Pokitto 46:e7e438368e16 473 if ( updRectX != 0 || updRectY != 0 ||updRectW != LCDWIDTH ||updRectH != LCDHEIGHT ) {
Pokitto 46:e7e438368e16 474 uint8_t org_screenx = updRectX;
Pokitto 46:e7e438368e16 475 updRectX &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 476 updRectW += org_screenx - updRectX;
Pokitto 46:e7e438368e16 477 updRectW = (updRectW + 3) & 0xfc; // Make the value dividable by 4, round up.
Pokitto 46:e7e438368e16 478
Pokitto 46:e7e438368e16 479 uint8_t org_screeny = updRectY;
Pokitto 46:e7e438368e16 480 updRectY &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 481 updRectH += org_screeny - updRectY;
Pokitto 46:e7e438368e16 482 updRectH = (updRectH + 7) & 0xf8; // Make the value dividable by 8 (because of loop unroll optimization), round up.
Pokitto 46:e7e438368e16 483 }
Pokitto 46:e7e438368e16 484
Pokitto 46:e7e438368e16 485
Pokitto 46:e7e438368e16 486 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 487 xptr = 8;
Pokitto 46:e7e438368e16 488 setDRAMptr(8, 0);
Pokitto 46:e7e438368e16 489 #else
Pokitto 46:e7e438368e16 490 setDRAMptr(0, 0);
Pokitto 46:e7e438368e16 491 #endif
Pokitto 46:e7e438368e16 492
Pokitto 46:e7e438368e16 493 for (x=updRectX; x<updRectX+updRectW; x+=4) {
Pokitto 46:e7e438368e16 494 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 495
Pokitto 46:e7e438368e16 496 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 497 d += (updRectY * 220/4);
Pokitto 46:e7e438368e16 498 for (y=updRectY; y<updRectY+updRectH; y++) {
Pokitto 46:e7e438368e16 499 uint8_t tdata = *d;
Pokitto 46:e7e438368e16 500 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 501 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 502 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 503 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 504
Pokitto 46:e7e438368e16 505 /** put nibble values in the scanlines **/
Pokitto 46:e7e438368e16 506 scanline[0][y] = paletteptr[t];
Pokitto 46:e7e438368e16 507 scanline[1][y] = paletteptr[t2];
Pokitto 46:e7e438368e16 508 scanline[2][y] = paletteptr[t3];
Pokitto 46:e7e438368e16 509 scanline[3][y] = paletteptr[t4];
Pokitto 46:e7e438368e16 510
Pokitto 46:e7e438368e16 511 d += 220/4; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 512 }
Pokitto 46:e7e438368e16 513
Pokitto 46:e7e438368e16 514 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 515 if (x>=8 ) {
Pokitto 46:e7e438368e16 516 #else
Pokitto 46:e7e438368e16 517 {
Pokitto 46:e7e438368e16 518
Pokitto 46:e7e438368e16 519 #endif
Pokitto 46:e7e438368e16 520
Pokitto 46:e7e438368e16 521 // Draw 8 vertical pixels at a time for performance reasons
Pokitto 46:e7e438368e16 522 setDRAMptr(x, updRectY);
Pokitto 46:e7e438368e16 523 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 524 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 525 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 526 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 527 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 528 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 529 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 530 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 531 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 532 }
Pokitto 46:e7e438368e16 533 setDRAMptr(x+1, updRectY);
Pokitto 46:e7e438368e16 534 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 535 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 536 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 537 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 538 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 539 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 540 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 541 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 542 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 543 }
Pokitto 46:e7e438368e16 544 setDRAMptr(x+2, updRectY);
Pokitto 46:e7e438368e16 545 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 546 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 547 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 548 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 549 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 550 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 551 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 552 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 553 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 554 }
Pokitto 46:e7e438368e16 555 setDRAMptr(x+3, updRectY);
Pokitto 46:e7e438368e16 556 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 557 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 558 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 559 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 560 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 561 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 562 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 563 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 564 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 565 }
Pokitto 46:e7e438368e16 566 }
Pokitto 46:e7e438368e16 567 }
Pokitto 46:e7e438368e16 568
Pokitto 46:e7e438368e16 569 #ifdef POK_SIM
Pokitto 46:e7e438368e16 570 simulator.refreshDisplay();
Pokitto 46:e7e438368e16 571 #endif
Pokitto 46:e7e438368e16 572 }
Pokitto 46:e7e438368e16 573
Pokitto 46:e7e438368e16 574 // Copy sprite pixels to the scanline
Pokitto 46:e7e438368e16 575 #define SPRITE_2BPP_INNER_LOOP(n)\
Pokitto 46:e7e438368e16 576 \
Pokitto 46:e7e438368e16 577 /* If the sprite is enabled and contained in this vertical scanline, copy 4 pixels. */\
Pokitto 46:e7e438368e16 578 if (sprScanlineAddr[(n)] &&\
Pokitto 46:e7e438368e16 579 y >= sprites[(n)].y && y < sprites[(n)].y + sprites[(n)].h ) {\
Pokitto 46:e7e438368e16 580 \
Pokitto 46:e7e438368e16 581 int16_t sprx = sprites[(n)].x;\
Pokitto 46:e7e438368e16 582 uint16_t s_data16b = 0; /* sprite data, 2 bytes */\
Pokitto 46:e7e438368e16 583 \
Pokitto 46:e7e438368e16 584 /* Get pixel block, 4 or 8 pixels horizontally. Use the predefined bitshift mode. */\
Pokitto 46:e7e438368e16 585 /* Note:it is cheapest to compare to 0 first. */\
Pokitto 46:e7e438368e16 586 if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_MIDDLE_BYTE) {\
Pokitto 46:e7e438368e16 587 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 46:e7e438368e16 588 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 46:e7e438368e16 589 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 46:e7e438368e16 590 }\
Pokitto 46:e7e438368e16 591 else if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_FIRST_BYTE) {\
Pokitto 46:e7e438368e16 592 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 46:e7e438368e16 593 }\
Pokitto 46:e7e438368e16 594 else { /* BITSHIFT_MODE_LAST_BYTE */\
Pokitto 46:e7e438368e16 595 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 46:e7e438368e16 596 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 46:e7e438368e16 597 }\
Pokitto 46:e7e438368e16 598 \
Pokitto 46:e7e438368e16 599 /* Shift sprite pixels according to sprite x. After shifting we have only 4 pixels. */\
Pokitto 46:e7e438368e16 600 uint8_t shiftRight = (sprx&0x3) << 1;\
Pokitto 46:e7e438368e16 601 s_data16b = (s_data16b >> shiftRight);\
Pokitto 46:e7e438368e16 602 \
Pokitto 46:e7e438368e16 603 /* Get individual pixels */\
Pokitto 46:e7e438368e16 604 uint8_t s_t4 = s_data16b & 0x03; s_data16b >>= 2; /* lowest half-nibble */\
Pokitto 46:e7e438368e16 605 uint8_t s_t3 = s_data16b & 0x03; s_data16b >>= 2; /* second lowest half-nibble */\
Pokitto 46:e7e438368e16 606 uint8_t s_t2 = s_data16b & 0x03; s_data16b >>= 2; /* second highest half-nibble */\
Pokitto 46:e7e438368e16 607 uint8_t s_t1 = s_data16b & 0x03; /* highest half-nibble */\
Pokitto 46:e7e438368e16 608 \
Pokitto 46:e7e438368e16 609 /* Store pixels as 16-bit colors from the palette */\
Pokitto 46:e7e438368e16 610 if (s_t4 != transparentColor) p4 = sprites[(n)].palette[s_t4];\
Pokitto 46:e7e438368e16 611 if (s_t3 != transparentColor) p3 = sprites[(n)].palette[s_t3];\
Pokitto 46:e7e438368e16 612 if (s_t2 != transparentColor) p2 = sprites[(n)].palette[s_t2];\
Pokitto 46:e7e438368e16 613 if (s_t1 != transparentColor) p = sprites[(n)].palette[s_t1];\
Pokitto 46:e7e438368e16 614 \
Pokitto 46:e7e438368e16 615 /* Advance scanline address */\
Pokitto 46:e7e438368e16 616 sprScanlineAddr[(n)] += (sprites[(n)].w >> 2);\
Pokitto 46:e7e438368e16 617 }
Pokitto 46:e7e438368e16 618
Pokitto 46:e7e438368e16 619 // Loop unrolling macros
Pokitto 46:e7e438368e16 620 #define UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(0)
Pokitto 46:e7e438368e16 621 #define UNROLLED_LOOP_2() UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(1)
Pokitto 46:e7e438368e16 622 #define UNROLLED_LOOP_3() UNROLLED_LOOP_2() SPRITE_2BPP_INNER_LOOP(2)
Pokitto 46:e7e438368e16 623 #define UNROLLED_LOOP_4() UNROLLED_LOOP_3() SPRITE_2BPP_INNER_LOOP(3)
Pokitto 46:e7e438368e16 624 #define UNROLLED_LOOP_5() UNROLLED_LOOP_4() SPRITE_2BPP_INNER_LOOP(4)
Pokitto 46:e7e438368e16 625 #define UNROLLED_LOOP_6() UNROLLED_LOOP_5() SPRITE_2BPP_INNER_LOOP(5)
Pokitto 46:e7e438368e16 626 #define UNROLLED_LOOP_7() UNROLLED_LOOP_6() SPRITE_2BPP_INNER_LOOP(6)
Pokitto 46:e7e438368e16 627 #define UNROLLED_LOOP_8() UNROLLED_LOOP_7() SPRITE_2BPP_INNER_LOOP(7)
Pokitto 46:e7e438368e16 628 #define UNROLLED_LOOP_9() UNROLLED_LOOP_8() SPRITE_2BPP_INNER_LOOP(8)
Pokitto 46:e7e438368e16 629 #define UNROLLED_LOOP_10() UNROLLED_LOOP_9() SPRITE_2BPP_INNER_LOOP(9)
Pokitto 46:e7e438368e16 630 #define UNROLLED_LOOP_11() UNROLLED_LOOP_10() SPRITE_2BPP_INNER_LOOP(10)
Pokitto 46:e7e438368e16 631 #define UNROLLED_LOOP_12() UNROLLED_LOOP_11() SPRITE_2BPP_INNER_LOOP(11)
Pokitto 46:e7e438368e16 632 #define UNROLLED_LOOP_13() UNROLLED_LOOP_12() SPRITE_2BPP_INNER_LOOP(12)
Pokitto 46:e7e438368e16 633 #define UNROLLED_LOOP_14() UNROLLED_LOOP_13() SPRITE_2BPP_INNER_LOOP(13)
Pokitto 46:e7e438368e16 634 #define UNROLLED_LOOP_15() UNROLLED_LOOP_14() SPRITE_2BPP_INNER_LOOP(14)
Pokitto 46:e7e438368e16 635 #define UNROLLED_LOOP_16() UNROLLED_LOOP_15() SPRITE_2BPP_INNER_LOOP(15)
Pokitto 46:e7e438368e16 636 #define UNROLLED_LOOP_N_(n) UNROLLED_LOOP_##n()
Pokitto 46:e7e438368e16 637 #define UNROLLED_LOOP_N(n) UNROLLED_LOOP_N_(n)
Pokitto 46:e7e438368e16 638
Pokitto 46:e7e438368e16 639 /***
Pokitto 46:e7e438368e16 640 * Update the screen buffer of 220x176 pixels, 4 colors and free size 4 color sprites to LCD.
Pokitto 46:e7e438368e16 641 *
Pokitto 46:e7e438368e16 642 * The update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations, the
Pokitto 46:e7e438368e16 643 * x, y, and width of the update rect must be dividable by 4 pixels, and the height must be dividable by 8 pixels.
Pokitto 46:e7e438368e16 644 * Note: The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 46:e7e438368e16 645 * If drawSpritesOnly=true, only sprites are fully updated to LCD. However, the dirty rect of the screen buffer is
Pokitto 46:e7e438368e16 646 * drawn behind the sprite current and previous location.
Pokitto 46:e7e438368e16 647 * Note: Sprite is enabled if sprite.bitmapData is not NULL. Also all enabled sprites must be at the beginning of
Pokitto 46:e7e438368e16 648 * the sprites array. No gaps are allowed in the array.
Pokitto 46:e7e438368e16 649 * @param scrbuf The screen buffer.
Pokitto 46:e7e438368e16 650 * @param updRectX The update rect.
Pokitto 46:e7e438368e16 651 * @param updRectY The update rect.
Pokitto 46:e7e438368e16 652 * @param updRectW The update rect.
Pokitto 46:e7e438368e16 653 * @param updRectH The update rect.
Pokitto 46:e7e438368e16 654 * @param paletteptr The screen palette.
Pokitto 46:e7e438368e16 655 * @param sprites The sprite array.
Pokitto 46:e7e438368e16 656 * @param drawSpritesOnly True, if only sprites are drawn. False, if both sprites and the screen buffer are drawn.
Pokitto 46:e7e438368e16 657 */
Pokitto 46:e7e438368e16 658 void Pokitto::lcdRefreshMode1Spr(
Pokitto 46:e7e438368e16 659 uint8_t * scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr,
Pokitto 46:e7e438368e16 660 SpriteInfo* sprites, bool drawSpritesOnly) {
Pokitto 46:e7e438368e16 661
Pokitto 46:e7e438368e16 662 // In direct mode draw only sprites and their dirty rects. Return now if there are no sprites
Pokitto 46:e7e438368e16 663 if (drawSpritesOnly && (sprites == NULL || sprites[0].bitmapData == NULL))
Pokitto 46:e7e438368e16 664 return;
Pokitto 46:e7e438368e16 665
Pokitto 46:e7e438368e16 666 uint16_t x,y;
Pokitto 46:e7e438368e16 667 uint16_t scanline[4][176]; // read 4 half-nibbles (= 4 pixels) at a time
Pokitto 46:e7e438368e16 668 const uint8_t transparentColor = 0; // fixed palette index 0 for transparency
Pokitto 46:e7e438368e16 669
Pokitto 46:e7e438368e16 670 // If not the full screen is updated, check the validity of the update rect.
Pokitto 46:e7e438368e16 671 if ( updRectX != 0 || updRectY != 0 ||updRectW != LCDWIDTH ||updRectH != LCDHEIGHT ) {
Pokitto 46:e7e438368e16 672 uint8_t org_screenx = updRectX;
Pokitto 46:e7e438368e16 673 updRectX &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 674 updRectW += org_screenx - updRectX;
Pokitto 46:e7e438368e16 675 updRectW = (updRectW + 3) & 0xfc; // Make the value dividable by 4, round up.
Pokitto 46:e7e438368e16 676
Pokitto 46:e7e438368e16 677 uint8_t org_screeny = updRectY;
Pokitto 46:e7e438368e16 678 updRectY &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 679 updRectH += org_screeny - updRectY;
Pokitto 46:e7e438368e16 680 updRectH = (updRectH + 7) & 0xf8; // Make the value dividable by 8 (because of loop unroll optimization), round up.
Pokitto 46:e7e438368e16 681 }
Pokitto 46:e7e438368e16 682
Pokitto 46:e7e438368e16 683 // Calculate the current amount of sprites
Pokitto 46:e7e438368e16 684 // 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 46:e7e438368e16 685 uint8_t spriteCount = 0;
Pokitto 46:e7e438368e16 686 if (sprites != NULL)
Pokitto 46:e7e438368e16 687 for (;sprites[spriteCount].bitmapData != NULL && spriteCount < SPRITE_COUNT; spriteCount++);
Pokitto 46:e7e438368e16 688
Pokitto 46:e7e438368e16 689 // If drawing the screen buffer, set the start pos to LCD commands only here.
Pokitto 46:e7e438368e16 690 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 691 if (!drawSpritesOnly) setDRAMptr(8, 0);
Pokitto 46:e7e438368e16 692 #else
Pokitto 46:e7e438368e16 693 if (!drawSpritesOnly) setDRAMptr(0, 0);
Pokitto 46:e7e438368e16 694 #endif
Pokitto 46:e7e438368e16 695
Pokitto 46:e7e438368e16 696 //*** GO THROUGH EACH VERTICAL GROUP OF 4 SCANLINES.***
Pokitto 46:e7e438368e16 697
Pokitto 46:e7e438368e16 698 for (x=0; x<LCDWIDTH; x+=4) {
Pokitto 46:e7e438368e16 699
Pokitto 46:e7e438368e16 700 uint8_t *screenBufScanlineAddr = scrbuf + (x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 701
Pokitto 46:e7e438368e16 702 /*Prepare scanline start address for sprites that are visible in this vertical scanline. Sprite width cannot exceed the screen width*/
Pokitto 46:e7e438368e16 703 uint8_t *sprScanlineAddr[SPRITE_COUNT]; // Sprite start address for the scanline
Pokitto 46:e7e438368e16 704 uint8_t sprScanlineBitshiftMode[SPRITE_COUNT]; // Sprite bitshift mode for the scanline
Pokitto 46:e7e438368e16 705 const uint8_t BITSHIFT_MODE_MIDDLE_BYTE = 0;
Pokitto 46:e7e438368e16 706 const uint8_t BITSHIFT_MODE_FIRST_BYTE = 1;
Pokitto 46:e7e438368e16 707 const uint8_t BITSHIFT_MODE_LAST_BYTE = 2;
Pokitto 46:e7e438368e16 708 uint8_t scanlineMinY = 255; // Init to uninitialized value. Do not draw by default.
Pokitto 46:e7e438368e16 709 uint8_t scanlineMaxY = 0; // Init to uninitialized value. Do not draw by default.
Pokitto 46:e7e438368e16 710
Pokitto 46:e7e438368e16 711 //*** CALCULATE DIRTY RECTS AND RESOLVE WHICH SPRITES BELONG TO THIS SCANLINE GROUP ***
Pokitto 46:e7e438368e16 712
Pokitto 46:e7e438368e16 713 if (sprites != NULL) {
Pokitto 46:e7e438368e16 714
Pokitto 46:e7e438368e16 715 // Check all the sprites for this scanline. That is used for handling the given update rect
Pokitto 46:e7e438368e16 716 // Note that the last round is when (sprindex == spriteCount). That is used to add the screen buffer
Pokitto 46:e7e438368e16 717 // update rect to the dirty rect.
Pokitto 46:e7e438368e16 718 for (int sprindex = 0; sprindex <= spriteCount; sprindex++) {
Pokitto 46:e7e438368e16 719
Pokitto 46:e7e438368e16 720 int16_t sprx, spry, sprOldX, sprOldY;
Pokitto 46:e7e438368e16 721 uint8_t sprw, sprh;
Pokitto 46:e7e438368e16 722 bool isCurrentSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 723 bool isOldSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 724
Pokitto 46:e7e438368e16 725 if (sprindex < spriteCount) {
Pokitto 46:e7e438368e16 726
Pokitto 46:e7e438368e16 727 sprx = sprites[sprindex].x;
Pokitto 46:e7e438368e16 728 spry = sprites[sprindex].y;
Pokitto 46:e7e438368e16 729 sprw = sprites[sprindex].w;
Pokitto 46:e7e438368e16 730 sprh = sprites[sprindex].h;
Pokitto 46:e7e438368e16 731 sprOldX = sprites[sprindex].oldx;
Pokitto 46:e7e438368e16 732 sprOldY = sprites[sprindex].oldy;
Pokitto 46:e7e438368e16 733 }
Pokitto 46:e7e438368e16 734
Pokitto 46:e7e438368e16 735 // Handle the screen buffer update rect after all sprites
Pokitto 46:e7e438368e16 736 else if(!drawSpritesOnly){
Pokitto 46:e7e438368e16 737
Pokitto 46:e7e438368e16 738 sprx = updRectX;
Pokitto 46:e7e438368e16 739 spry = updRectY;
Pokitto 46:e7e438368e16 740 sprw = updRectW;
Pokitto 46:e7e438368e16 741 sprh = updRectH;
Pokitto 46:e7e438368e16 742 sprOldX = updRectX;
Pokitto 46:e7e438368e16 743 sprOldY = updRectY;
Pokitto 46:e7e438368e16 744 isCurrentSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 745 isOldSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 746 }
Pokitto 46:e7e438368e16 747
Pokitto 46:e7e438368e16 748 // Check for out-of-screen
Pokitto 46:e7e438368e16 749 if (sprx >= LCDWIDTH || spry >= LCDHEIGHT)
Pokitto 46:e7e438368e16 750 isCurrentSpriteOutOfScreen = true;
Pokitto 46:e7e438368e16 751 if (sprOldX >= LCDWIDTH || sprOldY >= LCDHEIGHT)
Pokitto 46:e7e438368e16 752 isOldSpriteOutOfScreen = true;
Pokitto 46:e7e438368e16 753
Pokitto 46:e7e438368e16 754 // Skip if current and old sprites are out-of-screen
Pokitto 46:e7e438368e16 755 if (isCurrentSpriteOutOfScreen && isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 756 continue;
Pokitto 46:e7e438368e16 757
Pokitto 46:e7e438368e16 758 // Detect the dirty rect x-span by combining the previous and current sprite position.
Pokitto 51:113b1d84c34f 759 int16_t sprDirtyXMin = avrmin(sprx, sprOldX);
Pokitto 51:113b1d84c34f 760 int16_t sprDirtyXMax = avrmax(sprx, sprOldX);
Pokitto 46:e7e438368e16 761 if (isCurrentSpriteOutOfScreen)
Pokitto 46:e7e438368e16 762 sprDirtyXMax = sprOldX;
Pokitto 46:e7e438368e16 763 if (isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 764 sprDirtyXMax = sprx;
Pokitto 46:e7e438368e16 765
Pokitto 46:e7e438368e16 766 // Is current x inside the sprite combined dirty rect ?
Pokitto 46:e7e438368e16 767 int16_t sprDirtyXMaxEnd = sprDirtyXMax + sprw - 1 + 4; // Add 4 pixels to dirty rect width (needed?)
Pokitto 46:e7e438368e16 768 if (sprDirtyXMin <= x+3 && x <= sprDirtyXMaxEnd) {
Pokitto 46:e7e438368e16 769
Pokitto 46:e7e438368e16 770 // *** COMBINE DIRTY RECTS FOR THIS SCANLINE GROUP ***
Pokitto 46:e7e438368e16 771
Pokitto 46:e7e438368e16 772 // Dirty rect
Pokitto 51:113b1d84c34f 773 int sprDirtyYMin = avrmin(spry, sprOldY);
Pokitto 51:113b1d84c34f 774 sprDirtyYMin = avrmax((int)sprDirtyYMin, 0);
Pokitto 51:113b1d84c34f 775 int sprDirtyYMax = avrmax(spry, sprOldY);
Pokitto 46:e7e438368e16 776 if (isCurrentSpriteOutOfScreen)
Pokitto 46:e7e438368e16 777 sprDirtyYMax = sprOldY;
Pokitto 46:e7e438368e16 778 if (isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 779 sprDirtyYMax = spry;
Pokitto 46:e7e438368e16 780 int sprDirtyYMaxEnd = sprDirtyYMax + sprh - 1;
Pokitto 51:113b1d84c34f 781 sprDirtyYMaxEnd = avrmin(sprDirtyYMaxEnd, LCDHEIGHT - 1); // Should use LCDHEIGHT instead of screenH? Same with other screen* ?
Pokitto 46:e7e438368e16 782
Pokitto 46:e7e438368e16 783 // Get the scanline min and max y values for drawing
Pokitto 46:e7e438368e16 784 if (sprDirtyYMin < scanlineMinY)
Pokitto 46:e7e438368e16 785 scanlineMinY = sprDirtyYMin;
Pokitto 46:e7e438368e16 786 if (sprDirtyYMaxEnd > scanlineMaxY)
Pokitto 46:e7e438368e16 787 scanlineMaxY = sprDirtyYMaxEnd;
Pokitto 46:e7e438368e16 788
Pokitto 46:e7e438368e16 789 // *** PREPARE SPRITE FOR DRAWING ***
Pokitto 46:e7e438368e16 790
Pokitto 46:e7e438368e16 791 // Check if the sprite should be active for this vertical scanline group.
Pokitto 46:e7e438368e16 792 if (sprindex < spriteCount && // not for update rect
Pokitto 46:e7e438368e16 793 !isCurrentSpriteOutOfScreen && //out-of-screen
Pokitto 46:e7e438368e16 794 sprx <= x+3 && x < sprx + sprw) { // note: cover group of 4 pixels of the scanline (x+3)
Pokitto 46:e7e438368e16 795
Pokitto 46:e7e438368e16 796 // Find the byte number in the sprite data
Pokitto 46:e7e438368e16 797 int16_t byteNum = ((x+3) - sprx)>>2;
Pokitto 46:e7e438368e16 798
Pokitto 46:e7e438368e16 799 // Get the start addres of the spite data in this scanline.
Pokitto 46:e7e438368e16 800 sprScanlineAddr[sprindex] = const_cast<uint8_t*>(sprites[sprindex].bitmapData + byteNum);
Pokitto 46:e7e438368e16 801
Pokitto 46:e7e438368e16 802 // If the sprite goes over the top, it must be clipped from the top.
Pokitto 46:e7e438368e16 803 if(spry < 0)
Pokitto 46:e7e438368e16 804 sprScanlineAddr[sprindex] += (-spry) * (sprw >> 2);
Pokitto 46:e7e438368e16 805
Pokitto 46:e7e438368e16 806 // Select the bitshift mode for the blit algorithm
Pokitto 46:e7e438368e16 807 if (byteNum == 0)
Pokitto 46:e7e438368e16 808 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_FIRST_BYTE;
Pokitto 46:e7e438368e16 809 else if (byteNum >= (sprw >> 2))
Pokitto 46:e7e438368e16 810 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_LAST_BYTE;
Pokitto 46:e7e438368e16 811 else
Pokitto 46:e7e438368e16 812 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_MIDDLE_BYTE;
Pokitto 46:e7e438368e16 813 }
Pokitto 46:e7e438368e16 814 else
Pokitto 46:e7e438368e16 815 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 46:e7e438368e16 816 }
Pokitto 46:e7e438368e16 817 else
Pokitto 46:e7e438368e16 818 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 46:e7e438368e16 819 }
Pokitto 46:e7e438368e16 820 }
Pokitto 46:e7e438368e16 821
Pokitto 46:e7e438368e16 822 // *** ADJUST THE SCANLINE GROUP HEIGHT ***
Pokitto 46:e7e438368e16 823
Pokitto 46:e7e438368e16 824 // The height must dividable by 8. That is needed because later we copy 8 pixels at a time to the LCD.
Pokitto 46:e7e438368e16 825 if (scanlineMaxY - scanlineMinY + 1 > 0) {
Pokitto 46:e7e438368e16 826 uint8_t scanlineH = scanlineMaxY - scanlineMinY + 1;
Pokitto 46:e7e438368e16 827 uint8_t addW = 8 - (scanlineH & 0x7);
Pokitto 46:e7e438368e16 828
Pokitto 46:e7e438368e16 829 // if height is not dividable by 8, make it be.
Pokitto 46:e7e438368e16 830 if (addW != 0) {
Pokitto 46:e7e438368e16 831 if (scanlineMinY > addW )
Pokitto 46:e7e438368e16 832 scanlineMinY -= addW;
Pokitto 46:e7e438368e16 833 else if( scanlineMaxY + addW < updRectY+updRectH)
Pokitto 46:e7e438368e16 834 scanlineMaxY += addW;
Pokitto 46:e7e438368e16 835 else {
Pokitto 46:e7e438368e16 836 // Draw full height scanline
Pokitto 46:e7e438368e16 837 scanlineMinY = updRectY;
Pokitto 46:e7e438368e16 838 scanlineMaxY = updRectY+updRectH-1;
Pokitto 46:e7e438368e16 839 }
Pokitto 46:e7e438368e16 840 }
Pokitto 46:e7e438368e16 841 }
Pokitto 46:e7e438368e16 842
Pokitto 46:e7e438368e16 843 // *** COMBINE THE SCANLINE GROUP OF THE SCREEN BUFFER AND ALL SPRITES ***
Pokitto 46:e7e438368e16 844
Pokitto 46:e7e438368e16 845 // Find colours in this group of 4 scanlines
Pokitto 46:e7e438368e16 846 screenBufScanlineAddr += (scanlineMinY * 220/4);
Pokitto 46:e7e438368e16 847 for (y=scanlineMinY; y<=scanlineMaxY; y++)
Pokitto 46:e7e438368e16 848 {
Pokitto 46:e7e438368e16 849 // get the screen buffer data first
Pokitto 46:e7e438368e16 850 uint8_t tdata = *screenBufScanlineAddr;
Pokitto 46:e7e438368e16 851 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 852 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 853 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 854 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 855
Pokitto 46:e7e438368e16 856 // Convert to 16-bit colors in palette
Pokitto 46:e7e438368e16 857 uint16_t p = paletteptr[t];
Pokitto 46:e7e438368e16 858 uint16_t p2 = paletteptr[t2];
Pokitto 46:e7e438368e16 859 uint16_t p3 = paletteptr[t3];
Pokitto 46:e7e438368e16 860 uint16_t p4 = paletteptr[t4];
Pokitto 46:e7e438368e16 861
Pokitto 46:e7e438368e16 862 #if 0
Pokitto 46:e7e438368e16 863 // Dirty rect visual test
Pokitto 46:e7e438368e16 864 p = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 865 p2 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 866 p3 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 867 p4 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 868 #endif
Pokitto 46:e7e438368e16 869
Pokitto 46:e7e438368e16 870 // Add active sprite pixels
Pokitto 46:e7e438368e16 871 if (sprites != NULL) {
Pokitto 46:e7e438368e16 872
Pokitto 46:e7e438368e16 873 // Use loop unrolling for speed optimization
Pokitto 46:e7e438368e16 874 UNROLLED_LOOP_N(SPRITE_COUNT)
Pokitto 46:e7e438368e16 875 }
Pokitto 46:e7e438368e16 876
Pokitto 46:e7e438368e16 877 // put the result nibble values in the scanline
Pokitto 46:e7e438368e16 878 scanline[0][y] = p;
Pokitto 46:e7e438368e16 879 scanline[1][y] = p2;
Pokitto 46:e7e438368e16 880 scanline[2][y] = p3;
Pokitto 46:e7e438368e16 881 scanline[3][y] = p4;
Pokitto 46:e7e438368e16 882
Pokitto 46:e7e438368e16 883 screenBufScanlineAddr += 220>>2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 884 }
Pokitto 46:e7e438368e16 885
Pokitto 46:e7e438368e16 886 // *** DRAW THE SCANLINE GROUP TO LCD
Pokitto 46:e7e438368e16 887
Pokitto 46:e7e438368e16 888 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 889 if (x>=8 && scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 46:e7e438368e16 890 #else
Pokitto 46:e7e438368e16 891 if (scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 46:e7e438368e16 892 #endif
Pokitto 46:e7e438368e16 893 // Draw 8 vertical pixels at a time for performance reasons
Pokitto 46:e7e438368e16 894
Pokitto 46:e7e438368e16 895 setDRAMptr(x, scanlineMinY);
Pokitto 46:e7e438368e16 896 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 897 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 898 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 899 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 900 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 901 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 902 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 903 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 904 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 905 }
Pokitto 46:e7e438368e16 906
Pokitto 46:e7e438368e16 907 setDRAMptr(x+1, scanlineMinY);
Pokitto 46:e7e438368e16 908 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 909 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 910 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 911 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 912 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 913 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 914 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 915 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 916 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 917 }
Pokitto 46:e7e438368e16 918
Pokitto 46:e7e438368e16 919 setDRAMptr(x+2, scanlineMinY);
Pokitto 46:e7e438368e16 920 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 921 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 922 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 923 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 924 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 925 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 926 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 927 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 928 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 929 }
Pokitto 46:e7e438368e16 930
Pokitto 46:e7e438368e16 931 setDRAMptr(x+3, scanlineMinY);
Pokitto 46:e7e438368e16 932 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 933 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 934 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 935 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 936 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 937 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 938 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 939 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 940 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 941 }
Pokitto 46:e7e438368e16 942 }
Pokitto 46:e7e438368e16 943 }
Pokitto 46:e7e438368e16 944
Pokitto 46:e7e438368e16 945 // Update old x and y for the sprites
Pokitto 46:e7e438368e16 946 if (sprites != NULL) {
Pokitto 46:e7e438368e16 947 for (int sprindex = 0; sprindex < spriteCount; sprindex++) {
Pokitto 46:e7e438368e16 948 sprites[sprindex].oldx = sprites[sprindex].x;
Pokitto 46:e7e438368e16 949 sprites[sprindex].oldy = sprites[sprindex].y;
Pokitto 46:e7e438368e16 950 }
Pokitto 46:e7e438368e16 951 }
Pokitto 46:e7e438368e16 952
Pokitto 46:e7e438368e16 953 #ifdef POK_SIM
Pokitto 46:e7e438368e16 954 simulator.refreshDisplay();
Pokitto 46:e7e438368e16 955 #endif
Pokitto 46:e7e438368e16 956 }
Pokitto 46:e7e438368e16 957
Pokitto 51:113b1d84c34f 958
Pokitto 51:113b1d84c34f 959 #define MODE2_INNER_LOOP_B \
Pokitto 51:113b1d84c34f 960 " ldm %[scanline]!, {%[c]}" "\n" \
Pokitto 51:113b1d84c34f 961 " str %[c], [%[LCD], 0]" "\n" \
Pokitto 51:113b1d84c34f 962 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 963 " movs %[c], 252" "\n" \
Pokitto 51:113b1d84c34f 964 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 965 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 966 " subs %[x], 1" "\n" \
Pokitto 51:113b1d84c34f 967 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 968
Pokitto 51:113b1d84c34f 969
Pokitto 51:113b1d84c34f 970 void Pokitto::lcdRefreshMode2(uint8_t * scrbuf, uint16_t* paletteptr ) {
Pokitto 60:8b6a110feeea 971 uint32_t x,y;
Pokitto 51:113b1d84c34f 972 uint32_t scanline[110];
Pokitto 51:113b1d84c34f 973
Pokitto 51:113b1d84c34f 974 write_command(0x03); write_data(0x1038);
Pokitto 51:113b1d84c34f 975 write_command(0x20); // Horizontal DRAM Address
Pokitto 51:113b1d84c34f 976 write_data(0); // 0
Pokitto 51:113b1d84c34f 977 write_command(0x21); // Vertical DRAM Address
Pokitto 51:113b1d84c34f 978 write_data(1);
Pokitto 51:113b1d84c34f 979 write_command(0x22); // write data to DRAM
Pokitto 51:113b1d84c34f 980 CLR_CS_SET_CD_RD_WR;
Pokitto 51:113b1d84c34f 981 SET_MASK_P2;
Pokitto 51:113b1d84c34f 982
Pokitto 51:113b1d84c34f 983 #ifndef __ARMCC_VERSION
Pokitto 51:113b1d84c34f 984 asm volatile(
Pokitto 51:113b1d84c34f 985 ".syntax unified" "\n"
Pokitto 51:113b1d84c34f 986
Pokitto 51:113b1d84c34f 987 "mov r10, %[scanline]" "\n"
Pokitto 51:113b1d84c34f 988 "mov r11, %[t]" "\n"
Pokitto 51:113b1d84c34f 989
Pokitto 51:113b1d84c34f 990 "mode2OuterLoop:" "\n"
Pokitto 51:113b1d84c34f 991
Pokitto 51:113b1d84c34f 992 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 993 "mode2InnerLoopA:"
Pokitto 51:113b1d84c34f 994
Pokitto 51:113b1d84c34f 995
Pokitto 51:113b1d84c34f 996 " ldrb %[byte], [%[scrbuf],0]" "\n"
Pokitto 51:113b1d84c34f 997 " lsrs %[c], %[byte], 4" "\n"
Pokitto 51:113b1d84c34f 998
Pokitto 51:113b1d84c34f 999 " movs %[t], 15" "\n"
Pokitto 51:113b1d84c34f 1000 " ands %[byte], %[t]" "\n"
Pokitto 51:113b1d84c34f 1001
Pokitto 51:113b1d84c34f 1002 " lsls %[c], 1" "\n"
Pokitto 51:113b1d84c34f 1003 " ldrh %[t], [%[paletteptr], %[c]]" "\n"
Pokitto 51:113b1d84c34f 1004 " lsls %[t], %[t], 3" "\n"
Pokitto 51:113b1d84c34f 1005 " str %[t], [%[LCD], 0]" "\n"
Pokitto 51:113b1d84c34f 1006 " mov %[c], r11" "\n"
Pokitto 51:113b1d84c34f 1007 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1008 " stm %[scanline]!, {%[t]}" "\n"
Pokitto 51:113b1d84c34f 1009 " movs %[t], 252" "\n"
Pokitto 51:113b1d84c34f 1010 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1011 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1012 " lsls %[byte], %[byte], 1" "\n"
Pokitto 51:113b1d84c34f 1013 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 46:e7e438368e16 1014
Pokitto 51:113b1d84c34f 1015 " ldrh %[t], [%[paletteptr], %[byte]]" "\n"
Pokitto 51:113b1d84c34f 1016 " lsls %[t], %[t], 3" "\n"
Pokitto 51:113b1d84c34f 1017 " str %[t], [%[LCD], 0]" "\n"
Pokitto 51:113b1d84c34f 1018 " mov %[c], r11" "\n"
Pokitto 51:113b1d84c34f 1019 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1020 " stm %[scanline]!, {%[t]}" "\n"
Pokitto 51:113b1d84c34f 1021 " movs %[t], 252" "\n"
Pokitto 51:113b1d84c34f 1022 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1023 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1024 " adds %[scrbuf], %[scrbuf], 1" "\n"
Pokitto 51:113b1d84c34f 1025 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1026
Pokitto 51:113b1d84c34f 1027 " subs %[x], 2" "\n"
Pokitto 51:113b1d84c34f 1028 " bne mode2InnerLoopA" "\n"
Pokitto 46:e7e438368e16 1029
Pokitto 51:113b1d84c34f 1030 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1031 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1032 "mov %[t], r11" "\n"
Pokitto 51:113b1d84c34f 1033 "mode2InnerLoopB:"
Pokitto 51:113b1d84c34f 1034 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1035 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1036 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1037 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1038 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1039 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1040 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1041 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1042 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1043 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1044 " bne mode2InnerLoopB" "\n"
Pokitto 51:113b1d84c34f 1045
Pokitto 51:113b1d84c34f 1046 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1047 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1048 "movs %[c], 88" "\n"
Pokitto 51:113b1d84c34f 1049 "add %[y], %[t]" "\n" // y++... derpy, but it's the outer loop
Pokitto 51:113b1d84c34f 1050 "cmp %[y], %[c]" "\n"
Pokitto 51:113b1d84c34f 1051 "bne mode2OuterLoop" "\n" // if y != 88, loop
Pokitto 51:113b1d84c34f 1052
Pokitto 51:113b1d84c34f 1053 : // outputs
Pokitto 51:113b1d84c34f 1054 [c]"+l" (c),
Pokitto 51:113b1d84c34f 1055 [t]"+l" (t),
Pokitto 51:113b1d84c34f 1056 [x]"+l" (x),
Pokitto 51:113b1d84c34f 1057 [y]"+h" (y), // +:Read-Write l:lower (0-7) register
Pokitto 51:113b1d84c34f 1058 [scrbuf]"+l" (scrbuf)
Pokitto 51:113b1d84c34f 1059
Pokitto 51:113b1d84c34f 1060 : // inputs
Pokitto 51:113b1d84c34f 1061 [LCD]"l" (0xA0002188),
Pokitto 51:113b1d84c34f 1062 [scanline]"l" (scanline),
Pokitto 51:113b1d84c34f 1063 [paletteptr]"l" (paletteptr),
Pokitto 51:113b1d84c34f 1064 [byte]"l" (byte)
Pokitto 51:113b1d84c34f 1065 : // clobbers
Pokitto 51:113b1d84c34f 1066 "cc", "r10", "r11"
Pokitto 51:113b1d84c34f 1067 );
Pokitto 51:113b1d84c34f 1068
Pokitto 51:113b1d84c34f 1069
Pokitto 51:113b1d84c34f 1070 #else
Pokitto 51:113b1d84c34f 1071 uint8_t* d = scrbuf;// point to beginning of line in data
Pokitto 51:113b1d84c34f 1072
Pokitto 51:113b1d84c34f 1073 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 51:113b1d84c34f 1074 setDRAMptr(0, 8);
Pokitto 51:113b1d84c34f 1075 wait_us(200); // Add wait to compensate skipping of 8 lines. Makes FPS counter to show the correct value.
Pokitto 51:113b1d84c34f 1076 for(y=4;y<88;y++)
Pokitto 51:113b1d84c34f 1077 #else
Pokitto 51:113b1d84c34f 1078 for(y=0;y<88;y++)
Pokitto 51:113b1d84c34f 1079 #endif
Pokitto 46:e7e438368e16 1080 {
Pokitto 51:113b1d84c34f 1081
Pokitto 51:113b1d84c34f 1082
Pokitto 46:e7e438368e16 1083 uint8_t s=0;
Pokitto 51:113b1d84c34f 1084 for(x=0;x<110;x+=2)
Pokitto 46:e7e438368e16 1085 {
Pokitto 51:113b1d84c34f 1086 uint8_t t = *d++;
Pokitto 51:113b1d84c34f 1087 uint32_t color;
Pokitto 51:113b1d84c34f 1088 color = uint32_t(paletteptr[t>>4])<<3;
Pokitto 51:113b1d84c34f 1089 scanline[s]=*LCD=color;TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1090 color = uint32_t(paletteptr[t&0xF])<<3;
Pokitto 51:113b1d84c34f 1091 scanline[s]=*LCD=color;TGL_WR_OP(s++);TGL_WR;
Pokitto 46:e7e438368e16 1092 }
Pokitto 46:e7e438368e16 1093
Pokitto 51:113b1d84c34f 1094 s=0;
Pokitto 51:113b1d84c34f 1095 for (s=0;s<110;) {
Pokitto 51:113b1d84c34f 1096 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1097 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1098 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1099 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1100 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1101 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1102 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1103 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1104 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1105 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 46:e7e438368e16 1106 }
Pokitto 46:e7e438368e16 1107
Pokitto 46:e7e438368e16 1108 }
Pokitto 51:113b1d84c34f 1109 #endif
Pokitto 51:113b1d84c34f 1110
Pokitto 51:113b1d84c34f 1111 CLR_MASK_P2;
Pokitto 46:e7e438368e16 1112 }
Pokitto 46:e7e438368e16 1113
Pokitto 46:e7e438368e16 1114 void Pokitto::lcdRefreshMode3(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1115 uint16_t x,y;
Pokitto 46:e7e438368e16 1116 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 46:e7e438368e16 1117 uint8_t *d;
Pokitto 46:e7e438368e16 1118
Pokitto 46:e7e438368e16 1119 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1120 write_data(0); // 0
Pokitto 46:e7e438368e16 1121 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1122 write_data(0);
Pokitto 46:e7e438368e16 1123 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1124 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1125
Pokitto 46:e7e438368e16 1126 for(x=0;x<220;x+=2)
Pokitto 46:e7e438368e16 1127 {
Pokitto 46:e7e438368e16 1128 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 46:e7e438368e16 1129 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1130 uint8_t s=0;
Pokitto 46:e7e438368e16 1131 for(y=0;y<176;y++)
Pokitto 46:e7e438368e16 1132 {
Pokitto 46:e7e438368e16 1133 uint8_t t = *d >> 4; // higher nibble
Pokitto 46:e7e438368e16 1134 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 46:e7e438368e16 1135 /** higher nibble = left pixel in pixel pair **/
Pokitto 46:e7e438368e16 1136 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 1137 scanline[1][s++] = paletteptr[t2];
Pokitto 46:e7e438368e16 1138 /** testing only **/
Pokitto 46:e7e438368e16 1139 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 46:e7e438368e16 1140 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 46:e7e438368e16 1141 //s++;
Pokitto 46:e7e438368e16 1142 /** until here **/
Pokitto 46:e7e438368e16 1143 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 1144 }
Pokitto 46:e7e438368e16 1145 s=0;
Pokitto 46:e7e438368e16 1146 /** draw scanlines **/
Pokitto 46:e7e438368e16 1147 /** leftmost scanline**/
Pokitto 46:e7e438368e16 1148
Pokitto 46:e7e438368e16 1149 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1150 if (x<8) continue;
Pokitto 46:e7e438368e16 1151 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 1152 #endif
Pokitto 46:e7e438368e16 1153
Pokitto 46:e7e438368e16 1154 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 1155 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1156 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1157 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1158 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1159 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1160 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1161 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1162 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1163 }
Pokitto 46:e7e438368e16 1164
Pokitto 46:e7e438368e16 1165 /** rightmost scanline**/
Pokitto 46:e7e438368e16 1166 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1167 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 1168 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1169 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1170 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1171 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1172 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1173 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1174 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1175 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1176 }
Pokitto 46:e7e438368e16 1177 }
Pokitto 46:e7e438368e16 1178 }
Pokitto 46:e7e438368e16 1179
Pokitto 46:e7e438368e16 1180 void Pokitto::lcdRefreshGB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1181 uint16_t x,y;
Pokitto 46:e7e438368e16 1182 uint16_t scanline[48];
Pokitto 46:e7e438368e16 1183 uint8_t * d;
Pokitto 46:e7e438368e16 1184
Pokitto 46:e7e438368e16 1185 #if POK_STRETCH
Pokitto 46:e7e438368e16 1186 //uint16_t xptr = 8;
Pokitto 46:e7e438368e16 1187 #else
Pokitto 46:e7e438368e16 1188 //xptr = 26;
Pokitto 46:e7e438368e16 1189 #endif
Pokitto 46:e7e438368e16 1190
Pokitto 46:e7e438368e16 1191 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1192 write_data(0); // 0
Pokitto 46:e7e438368e16 1193 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1194 write_data(0);
Pokitto 46:e7e438368e16 1195 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1196 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1197
Pokitto 46:e7e438368e16 1198 /** draw border **/
Pokitto 46:e7e438368e16 1199 for (int s=0;s<5*176;) {
Pokitto 46:e7e438368e16 1200 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 46:e7e438368e16 1201 }
Pokitto 46:e7e438368e16 1202
Pokitto 46:e7e438368e16 1203 for(x=0;x<84;x++)
Pokitto 46:e7e438368e16 1204 {
Pokitto 46:e7e438368e16 1205
Pokitto 46:e7e438368e16 1206 d = scrbuf + x;// point to beginning of line in data
Pokitto 46:e7e438368e16 1207
Pokitto 46:e7e438368e16 1208 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1209 uint8_t s=0;
Pokitto 46:e7e438368e16 1210 for(y=0;y<6;y++)
Pokitto 46:e7e438368e16 1211 {
Pokitto 46:e7e438368e16 1212 uint8_t t = *d;
Pokitto 46:e7e438368e16 1213 #if POK_COLORDEPTH > 1
Pokitto 46:e7e438368e16 1214 uint8_t t2 = *(d+504);
Pokitto 46:e7e438368e16 1215 #endif
Pokitto 46:e7e438368e16 1216 #if POK_COLORDEPTH > 2
Pokitto 46:e7e438368e16 1217 uint8_t t3 = *(d+504+504);
Pokitto 46:e7e438368e16 1218 #endif
Pokitto 46:e7e438368e16 1219 #if POK_COLORDEPTH > 3
Pokitto 46:e7e438368e16 1220 uint8_t t4 = *(d+504+504+504);
Pokitto 46:e7e438368e16 1221 #endif
Pokitto 46:e7e438368e16 1222 uint8_t paletteindex = 0;
Pokitto 46:e7e438368e16 1223
Pokitto 46:e7e438368e16 1224 /** bit 1 **/
Pokitto 46:e7e438368e16 1225 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1226 paletteindex = (t & 0x1);
Pokitto 46:e7e438368e16 1227 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1228 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 46:e7e438368e16 1229 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1230 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 46:e7e438368e16 1231 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1232 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 46:e7e438368e16 1233 #endif
Pokitto 46:e7e438368e16 1234 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1235
Pokitto 46:e7e438368e16 1236 /** bit 2 **/
Pokitto 46:e7e438368e16 1237 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1238 paletteindex = (t & 0x2)>>1;
Pokitto 46:e7e438368e16 1239 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1240 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 46:e7e438368e16 1241 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1242 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 46:e7e438368e16 1243 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1244 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 46:e7e438368e16 1245 #endif
Pokitto 46:e7e438368e16 1246 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1247
Pokitto 46:e7e438368e16 1248 /** bit 3 **/
Pokitto 46:e7e438368e16 1249 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1250 paletteindex = (t & 0x4)>>2;
Pokitto 46:e7e438368e16 1251 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1252 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 46:e7e438368e16 1253 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1254 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 46:e7e438368e16 1255 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1256 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 46:e7e438368e16 1257 #endif
Pokitto 46:e7e438368e16 1258 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1259
Pokitto 46:e7e438368e16 1260 /** bit 4 **/
Pokitto 46:e7e438368e16 1261 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1262 paletteindex = (t & 0x8)>>3;
Pokitto 46:e7e438368e16 1263 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1264 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 46:e7e438368e16 1265 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1266 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 46:e7e438368e16 1267 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1268 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 46:e7e438368e16 1269 #endif
Pokitto 46:e7e438368e16 1270 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1271
Pokitto 46:e7e438368e16 1272 /** bit 5 **/
Pokitto 46:e7e438368e16 1273 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1274 paletteindex = (t & 0x10)>>4;
Pokitto 46:e7e438368e16 1275 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1276 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 46:e7e438368e16 1277 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1278 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 46:e7e438368e16 1279 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1280 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 46:e7e438368e16 1281 #endif
Pokitto 46:e7e438368e16 1282 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1283
Pokitto 46:e7e438368e16 1284 /** bit 6 **/
Pokitto 46:e7e438368e16 1285 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1286 paletteindex = (t & 0x20)>>5;
Pokitto 46:e7e438368e16 1287 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1288 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 46:e7e438368e16 1289 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1290 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 46:e7e438368e16 1291 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1292 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 46:e7e438368e16 1293 #endif
Pokitto 46:e7e438368e16 1294 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1295
Pokitto 46:e7e438368e16 1296 /** bit 7 **/
Pokitto 46:e7e438368e16 1297 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1298 paletteindex = (t & 0x40)>>6;
Pokitto 46:e7e438368e16 1299 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1300 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 46:e7e438368e16 1301 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1302 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 46:e7e438368e16 1303 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1304 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 46:e7e438368e16 1305 #endif
Pokitto 46:e7e438368e16 1306 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1307
Pokitto 46:e7e438368e16 1308 /** bit 8 **/
Pokitto 46:e7e438368e16 1309 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1310 paletteindex = (t & 0x80)>>7;
Pokitto 46:e7e438368e16 1311 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1312 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 46:e7e438368e16 1313 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1314 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 46:e7e438368e16 1315 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1316 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 46:e7e438368e16 1317 #endif
Pokitto 46:e7e438368e16 1318 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1319
Pokitto 46:e7e438368e16 1320 d+=84; // jump to byte directly below
Pokitto 46:e7e438368e16 1321 }
Pokitto 46:e7e438368e16 1322
Pokitto 46:e7e438368e16 1323
Pokitto 46:e7e438368e16 1324 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1325 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1326 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1327 write_data(xptr++);
Pokitto 46:e7e438368e16 1328 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1329 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1330 /** draw border **/
Pokitto 46:e7e438368e16 1331 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 46:e7e438368e16 1332
Pokitto 46:e7e438368e16 1333 s=0;
Pokitto 46:e7e438368e16 1334
Pokitto 46:e7e438368e16 1335 /** draw scanlines **/
Pokitto 46:e7e438368e16 1336 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1337 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1338 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1339 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1340 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1341 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1342 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1343 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1344 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1345 }
Pokitto 46:e7e438368e16 1346 /** draw border **/
Pokitto 46:e7e438368e16 1347 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 46:e7e438368e16 1348
Pokitto 46:e7e438368e16 1349
Pokitto 46:e7e438368e16 1350 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1351 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1352 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1353 write_data(xptr++);
Pokitto 46:e7e438368e16 1354 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1355 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1356 /** draw border **/
Pokitto 46:e7e438368e16 1357 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 46:e7e438368e16 1358
Pokitto 46:e7e438368e16 1359 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1360 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1361 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1362 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1363 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1364 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1365 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1366 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1367 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1368 }
Pokitto 46:e7e438368e16 1369
Pokitto 46:e7e438368e16 1370 /** draw border **/
Pokitto 46:e7e438368e16 1371 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 46:e7e438368e16 1372
Pokitto 46:e7e438368e16 1373
Pokitto 46:e7e438368e16 1374 #if POK_STRETCH
Pokitto 46:e7e438368e16 1375 //if (x>16 && x<68)
Pokitto 46:e7e438368e16 1376 if (x&2)// && x&2)
Pokitto 46:e7e438368e16 1377 {
Pokitto 46:e7e438368e16 1378 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1379 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1380 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1381 write_data(xptr++);
Pokitto 46:e7e438368e16 1382 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1383 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1384 /** draw border **/
Pokitto 46:e7e438368e16 1385 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 46:e7e438368e16 1386
Pokitto 46:e7e438368e16 1387
Pokitto 46:e7e438368e16 1388 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1389 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1390 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1391 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1392 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1393 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1394 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1395 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1396 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1397 }
Pokitto 46:e7e438368e16 1398
Pokitto 46:e7e438368e16 1399 /** draw border **/
Pokitto 46:e7e438368e16 1400 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 46:e7e438368e16 1401
Pokitto 46:e7e438368e16 1402 }
Pokitto 46:e7e438368e16 1403 #endif
Pokitto 46:e7e438368e16 1404 }
Pokitto 46:e7e438368e16 1405 /** draw border **/
Pokitto 46:e7e438368e16 1406 for (int s=0;s<5*176;) {
Pokitto 46:e7e438368e16 1407 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 46:e7e438368e16 1408 }
Pokitto 46:e7e438368e16 1409 }
Pokitto 46:e7e438368e16 1410
Pokitto 46:e7e438368e16 1411
Pokitto 46:e7e438368e16 1412 void Pokitto::lcdRefreshAB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1413 uint16_t x,y;
Pokitto 46:e7e438368e16 1414 uint16_t scanline[64];
Pokitto 46:e7e438368e16 1415 uint8_t *d;
Pokitto 46:e7e438368e16 1416 //lcdClear();
Pokitto 46:e7e438368e16 1417 #if POK_STRETCH
Pokitto 46:e7e438368e16 1418 uint16_t xptr = 14;
Pokitto 46:e7e438368e16 1419 uint8_t yoffset = 24;
Pokitto 46:e7e438368e16 1420 #else
Pokitto 46:e7e438368e16 1421 uint16_t xptr = 0;
Pokitto 46:e7e438368e16 1422 uint8_t yoffset = 0;
Pokitto 46:e7e438368e16 1423 #endif
Pokitto 46:e7e438368e16 1424
Pokitto 46:e7e438368e16 1425 for(x=0;x<128;x++)
Pokitto 46:e7e438368e16 1426 {
Pokitto 46:e7e438368e16 1427 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1428 write_data(yoffset); // 0
Pokitto 46:e7e438368e16 1429 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1430 write_data(xptr++);
Pokitto 46:e7e438368e16 1431 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1432 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1433 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1434
Pokitto 46:e7e438368e16 1435 d = scrbuf + x;// point to beginning of line in data
Pokitto 46:e7e438368e16 1436
Pokitto 46:e7e438368e16 1437 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1438 uint8_t s=0;
Pokitto 46:e7e438368e16 1439 for(y=0;y<8;y++)
Pokitto 46:e7e438368e16 1440 {
Pokitto 46:e7e438368e16 1441 uint8_t t = *d;
Pokitto 46:e7e438368e16 1442 #if POK_COLORDEPTH > 1
Pokitto 46:e7e438368e16 1443 uint8_t t2 = *(d+AB_JUMP);
Pokitto 46:e7e438368e16 1444 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1445 #if POK_COLORDEPTH > 2
Pokitto 46:e7e438368e16 1446 uint8_t t3 = *(d+AB_JUMP+AB_JUMP);
Pokitto 46:e7e438368e16 1447 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1448 #if POK_COLORDEPTH > 3
Pokitto 46:e7e438368e16 1449 uint8_t t4 = *(d+AB_JUMP+AB_JUMP+AB_JUMP);
Pokitto 46:e7e438368e16 1450 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1451 uint8_t paletteindex = 0;
Pokitto 46:e7e438368e16 1452
Pokitto 46:e7e438368e16 1453 /** bit 1 **/
Pokitto 46:e7e438368e16 1454 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1455 paletteindex = (t & 0x1);
Pokitto 46:e7e438368e16 1456 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1457 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 46:e7e438368e16 1458 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1459 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 46:e7e438368e16 1460 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1461 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 46:e7e438368e16 1462 #endif
Pokitto 46:e7e438368e16 1463 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1464
Pokitto 46:e7e438368e16 1465 /** bit 2 **/
Pokitto 46:e7e438368e16 1466 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1467 paletteindex = (t & 0x2)>>1;
Pokitto 46:e7e438368e16 1468 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1469 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 46:e7e438368e16 1470 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1471 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 46:e7e438368e16 1472 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1473 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 46:e7e438368e16 1474 #endif
Pokitto 46:e7e438368e16 1475 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1476
Pokitto 46:e7e438368e16 1477 /** bit 3 **/
Pokitto 46:e7e438368e16 1478 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1479 paletteindex = (t & 0x4)>>2;
Pokitto 46:e7e438368e16 1480 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1481 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 46:e7e438368e16 1482 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1483 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 46:e7e438368e16 1484 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1485 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 46:e7e438368e16 1486 #endif
Pokitto 46:e7e438368e16 1487 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1488
Pokitto 46:e7e438368e16 1489 /** bit 4 **/
Pokitto 46:e7e438368e16 1490 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1491 paletteindex = (t & 0x8)>>3;
Pokitto 46:e7e438368e16 1492 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1493 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 46:e7e438368e16 1494 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1495 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 46:e7e438368e16 1496 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1497 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 46:e7e438368e16 1498 #endif
Pokitto 46:e7e438368e16 1499 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1500
Pokitto 46:e7e438368e16 1501 /** bit 5 **/
Pokitto 46:e7e438368e16 1502 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1503 paletteindex = (t & 0x10)>>4;
Pokitto 46:e7e438368e16 1504 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1505 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 46:e7e438368e16 1506 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1507 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 46:e7e438368e16 1508 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1509 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 46:e7e438368e16 1510 #endif
Pokitto 46:e7e438368e16 1511 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1512
Pokitto 46:e7e438368e16 1513 /** bit 6 **/
Pokitto 46:e7e438368e16 1514 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1515 paletteindex = (t & 0x20)>>5;
Pokitto 46:e7e438368e16 1516 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1517 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 46:e7e438368e16 1518 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1519 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 46:e7e438368e16 1520 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1521 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 46:e7e438368e16 1522 #endif
Pokitto 46:e7e438368e16 1523 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1524
Pokitto 46:e7e438368e16 1525 /** bit 7 **/
Pokitto 46:e7e438368e16 1526 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1527 paletteindex = (t & 0x40)>>6;
Pokitto 46:e7e438368e16 1528 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1529 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 46:e7e438368e16 1530 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1531 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 46:e7e438368e16 1532 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1533 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 46:e7e438368e16 1534 #endif
Pokitto 46:e7e438368e16 1535 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1536
Pokitto 46:e7e438368e16 1537 /** bit 8 **/
Pokitto 46:e7e438368e16 1538 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1539 paletteindex = (t & 0x80)>>7;
Pokitto 46:e7e438368e16 1540 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1541 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 46:e7e438368e16 1542 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1543 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 46:e7e438368e16 1544 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1545 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 46:e7e438368e16 1546 #endif
Pokitto 46:e7e438368e16 1547 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1548
Pokitto 46:e7e438368e16 1549 d+=128; // jump to byte directly below
Pokitto 46:e7e438368e16 1550 }
Pokitto 46:e7e438368e16 1551
Pokitto 46:e7e438368e16 1552 s=0;
Pokitto 46:e7e438368e16 1553
Pokitto 46:e7e438368e16 1554 /** draw scanlines **/
Pokitto 46:e7e438368e16 1555 for (s=0;s<64;) {
Pokitto 46:e7e438368e16 1556 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1557 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1558 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1559 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1560 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1561 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1562 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1563 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1564 }
Pokitto 46:e7e438368e16 1565
Pokitto 46:e7e438368e16 1566 #if POK_STRETCH
Pokitto 46:e7e438368e16 1567 if (x&1) {
Pokitto 46:e7e438368e16 1568 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1569 write_data(yoffset); // 0
Pokitto 46:e7e438368e16 1570 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1571 write_data(xptr++);
Pokitto 46:e7e438368e16 1572 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1573 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1574 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1575
Pokitto 46:e7e438368e16 1576 for (s=0;s<64;) {
Pokitto 46:e7e438368e16 1577 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1578 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1579 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1580 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1581 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1582 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1583 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1584 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1585 }
Pokitto 46:e7e438368e16 1586 }
Pokitto 46:e7e438368e16 1587 #endif
Pokitto 46:e7e438368e16 1588 }
Pokitto 46:e7e438368e16 1589 }
Pokitto 46:e7e438368e16 1590
Pokitto 46:e7e438368e16 1591 void Pokitto::lcdRefreshModeGBC(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1592 uint16_t x,y,xptr;
Pokitto 46:e7e438368e16 1593 uint16_t scanline[4][144]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 46:e7e438368e16 1594 uint8_t *d, yoffset=0;
Pokitto 46:e7e438368e16 1595
Pokitto 46:e7e438368e16 1596 xptr = 0;
Pokitto 46:e7e438368e16 1597 setDRAMptr(xptr,yoffset);
Pokitto 46:e7e438368e16 1598
Pokitto 46:e7e438368e16 1599
Pokitto 46:e7e438368e16 1600 for(x=0;x<160;x+=4)
Pokitto 46:e7e438368e16 1601 {
Pokitto 46:e7e438368e16 1602 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 1603 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1604 uint8_t s=0;
Pokitto 46:e7e438368e16 1605 for(y=0;y<144;y++)
Pokitto 46:e7e438368e16 1606 {
Pokitto 46:e7e438368e16 1607 uint8_t tdata = *d;
Pokitto 46:e7e438368e16 1608 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 1609 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 1610 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 1611 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 1612
Pokitto 46:e7e438368e16 1613 /** put nibble values in the scanlines **/
Pokitto 46:e7e438368e16 1614
Pokitto 46:e7e438368e16 1615 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 1616 scanline[1][s] = paletteptr[t2];
Pokitto 46:e7e438368e16 1617 scanline[2][s] = paletteptr[t3];
Pokitto 46:e7e438368e16 1618 scanline[3][s++] = paletteptr[t4];
Pokitto 46:e7e438368e16 1619
Pokitto 46:e7e438368e16 1620 d+=160/4; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 1621 }
Pokitto 46:e7e438368e16 1622
Pokitto 46:e7e438368e16 1623 s=0;
Pokitto 46:e7e438368e16 1624 /** draw scanlines **/
Pokitto 46:e7e438368e16 1625 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1626 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1627 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1628 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1629 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1630 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1631 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1632 }
Pokitto 46:e7e438368e16 1633 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1634 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1635 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1636 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1637 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1638 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1639 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1640 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1641 }
Pokitto 46:e7e438368e16 1642 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1643 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1644 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1645 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1646 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1647 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1648 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1649 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1650 }
Pokitto 46:e7e438368e16 1651 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1652 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1653 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1654 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1655 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1656 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1657 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1658 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1659 }
Pokitto 46:e7e438368e16 1660 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1661 }
Pokitto 46:e7e438368e16 1662 }
Pokitto 46:e7e438368e16 1663
Pokitto 46:e7e438368e16 1664
Pokitto 46:e7e438368e16 1665 void Pokitto::lcdRefreshT1(uint8_t* tilebuf, uint8_t* tilecolorbuf, uint8_t* tileset, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1666 #ifdef POK_TILEMODE
Pokitto 46:e7e438368e16 1667 uint16_t x,y,data,xptr;
Pokitto 46:e7e438368e16 1668 uint16_t scanline[176];
Pokitto 46:e7e438368e16 1669 uint8_t yoffset=0, tilebyte, tileindex, tilex=0, tiley=0,xcount;
Pokitto 46:e7e438368e16 1670
Pokitto 46:e7e438368e16 1671
Pokitto 46:e7e438368e16 1672 if (!tileset) return;
Pokitto 46:e7e438368e16 1673
Pokitto 46:e7e438368e16 1674 #if LCDWIDTH < POK_LCD_W
Pokitto 46:e7e438368e16 1675 xptr = (POK_LCD_W-LCDWIDTH)/2;
Pokitto 46:e7e438368e16 1676 #else
Pokitto 46:e7e438368e16 1677 xptr = 0;
Pokitto 46:e7e438368e16 1678 #endif
Pokitto 46:e7e438368e16 1679 #if LCDHEIGHT < POK_LCD_H
Pokitto 46:e7e438368e16 1680 yoffset = (POK_LCD_H-LCDHEIGHT)/2;
Pokitto 46:e7e438368e16 1681 #else
Pokitto 46:e7e438368e16 1682 yoffset = 0;
Pokitto 46:e7e438368e16 1683 #endif
Pokitto 46:e7e438368e16 1684
Pokitto 46:e7e438368e16 1685 for(x=0, xcount=0 ;x<LCDWIDTH;x++,xcount++) // loop through vertical columns
Pokitto 46:e7e438368e16 1686 {
Pokitto 46:e7e438368e16 1687 setDRAMptr(xptr++,yoffset); //point to VRAM
Pokitto 46:e7e438368e16 1688
Pokitto 46:e7e438368e16 1689 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1690 uint8_t s=0, tiley=0;
Pokitto 46:e7e438368e16 1691 //tileindex = tilebuf[tilex*POK_TILES_Y];
Pokitto 46:e7e438368e16 1692 if (xcount==POK_TILE_W) {
Pokitto 46:e7e438368e16 1693 tilex++;
Pokitto 46:e7e438368e16 1694 xcount=0;
Pokitto 46:e7e438368e16 1695 }
Pokitto 46:e7e438368e16 1696
Pokitto 46:e7e438368e16 1697 for(y=0;y<LCDHEIGHT;)
Pokitto 46:e7e438368e16 1698 {
Pokitto 46:e7e438368e16 1699 uint8_t tileval = tilebuf[tilex+tiley*POK_TILES_X]; //get tile number
Pokitto 46:e7e438368e16 1700 uint16_t index = tileval*POK_TILE_W+xcount;
Pokitto 46:e7e438368e16 1701 uint8_t tilebyte = tileset[index]; //get bitmap data
Pokitto 46:e7e438368e16 1702 for (uint8_t ycount=0, bitcount=0; ycount<POK_TILE_H; ycount++, y++, bitcount++) {
Pokitto 46:e7e438368e16 1703 if (bitcount==8) {
Pokitto 46:e7e438368e16 1704 bitcount=0;
Pokitto 46:e7e438368e16 1705 index += 176; //jump to byte below in the tileset bitmap
Pokitto 46:e7e438368e16 1706 tilebyte = tileset[index]; //get bitmap data
Pokitto 46:e7e438368e16 1707 }
Pokitto 46:e7e438368e16 1708 //tilebyte = tile[(tileindex>>4)+*POK_TILE_W]; //tilemaps are 16x16
Pokitto 46:e7e438368e16 1709 //uint8_t paletteindex = ((tilebyte>>(bitcount&0x7)) & 0x1);
Pokitto 46:e7e438368e16 1710 if (!tileval) scanline[s++] = COLOR_MAGENTA*((tilebyte>>bitcount)&0x1);//paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1711 else scanline[s++] = paletteptr[((tilebyte>>bitcount)&0x1)*tileval];//paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1712 }
Pokitto 46:e7e438368e16 1713 tiley++; //move to next tile
Pokitto 46:e7e438368e16 1714 }
Pokitto 46:e7e438368e16 1715 s=0;
Pokitto 46:e7e438368e16 1716
Pokitto 46:e7e438368e16 1717 /** draw scanlines **/
Pokitto 46:e7e438368e16 1718 for (s=0;s<LCDHEIGHT;) {
Pokitto 46:e7e438368e16 1719 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1720 }
Pokitto 46:e7e438368e16 1721 }
Pokitto 46:e7e438368e16 1722 #endif
Pokitto 46:e7e438368e16 1723 }
Pokitto 46:e7e438368e16 1724
Pokitto 51:113b1d84c34f 1725 #define MODE13_INNER_LOOP_A \
Pokitto 51:113b1d84c34f 1726 " ldrb %[t], [%[scrbuf],0]" "\n" \
Pokitto 51:113b1d84c34f 1727 " add %[t], %[t], %[offset]" "\n" \
Pokitto 51:113b1d84c34f 1728 " uxtb %[c], %[t] " "\n" \
Pokitto 51:113b1d84c34f 1729 " lsls %[c], 1" "\n" \
Pokitto 51:113b1d84c34f 1730 " ldrh %[t], [%[paletteptr], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 1731 " lsls %[t], %[t], 3" "\n" \
Pokitto 51:113b1d84c34f 1732 " str %[t], [%[LCD], 0]" "\n" \
Pokitto 51:113b1d84c34f 1733 " mov %[c], r11" "\n" \
Pokitto 51:113b1d84c34f 1734 " str %[c], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1735 " stm %[scanline]!, {%[t]}" "\n" \
Pokitto 51:113b1d84c34f 1736 " movs %[t], 252" "\n" \
Pokitto 51:113b1d84c34f 1737 " str %[c], [%[LCD], %[t]]" "\n" \
Pokitto 51:113b1d84c34f 1738 " str %[c], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1739 " adds %[scrbuf], %[scrbuf], 1" "\n" \
Pokitto 51:113b1d84c34f 1740 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1741
Pokitto 51:113b1d84c34f 1742 #define MODE13_INNER_LOOP_B \
Pokitto 51:113b1d84c34f 1743 " ldm %[scanline]!, {%[c]}" "\n" \
Pokitto 51:113b1d84c34f 1744 " str %[c], [%[LCD], 0]" "\n" \
Pokitto 51:113b1d84c34f 1745 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1746 " movs %[c], 252" "\n" \
Pokitto 51:113b1d84c34f 1747 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 1748 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1749 " subs %[x], 1" "\n" \
Pokitto 51:113b1d84c34f 1750 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 46:e7e438368e16 1751
Pokitto 51:113b1d84c34f 1752
Pokitto 51:113b1d84c34f 1753 void Pokitto::lcdRefreshMode13(uint8_t * scrbuf, uint16_t* paletteptr, uint8_t offset){
Pokitto 51:113b1d84c34f 1754 uint32_t scanline[110]; // read two nibbles = pixels at a time
Pokitto 51:113b1d84c34f 1755
Pokitto 51:113b1d84c34f 1756 write_command_16(0x03); write_data_16(0x1038);
Pokitto 51:113b1d84c34f 1757 write_command(0x20); write_data(0);
Pokitto 51:113b1d84c34f 1758 write_command(0x21); write_data(1);
Pokitto 51:113b1d84c34f 1759 write_command(0x22);
Pokitto 51:113b1d84c34f 1760 CLR_CS_SET_CD_RD_WR;
Pokitto 51:113b1d84c34f 1761 SET_MASK_P2;
Pokitto 51:113b1d84c34f 1762
Pokitto 60:8b6a110feeea 1763 uint32_t x, y=0;
Pokitto 51:113b1d84c34f 1764
Pokitto 51:113b1d84c34f 1765 #ifndef __ARMCC_VERSION
Pokitto 51:113b1d84c34f 1766 asm volatile(
Pokitto 51:113b1d84c34f 1767 ".syntax unified" "\n"
Pokitto 51:113b1d84c34f 1768
Pokitto 51:113b1d84c34f 1769 "mov r10, %[scanline]" "\n"
Pokitto 51:113b1d84c34f 1770
Pokitto 51:113b1d84c34f 1771 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1772 "lsls %[t], %[t], 12" "\n"
Pokitto 51:113b1d84c34f 1773 "mov r11, %[t]" "\n"
Pokitto 51:113b1d84c34f 1774
Pokitto 51:113b1d84c34f 1775 "mode13OuterLoop:" "\n"
Pokitto 51:113b1d84c34f 1776
Pokitto 51:113b1d84c34f 1777 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1778 "mode13InnerLoopA:"
Pokitto 51:113b1d84c34f 1779 MODE13_INNER_LOOP_A
Pokitto 51:113b1d84c34f 1780 MODE13_INNER_LOOP_A
Pokitto 51:113b1d84c34f 1781 " subs %[x], 2" "\n"
Pokitto 51:113b1d84c34f 1782 " bne mode13InnerLoopA" "\n"
Pokitto 46:e7e438368e16 1783
Pokitto 51:113b1d84c34f 1784 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1785 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1786 "mov %[t], r11" "\n"
Pokitto 51:113b1d84c34f 1787 "mode13InnerLoopB:"
Pokitto 51:113b1d84c34f 1788 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1789 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1790 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1791 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1792 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1793 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1794 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1795 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1796 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1797 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1798 " bne mode13InnerLoopB" "\n"
Pokitto 51:113b1d84c34f 1799
Pokitto 51:113b1d84c34f 1800 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1801 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1802 "movs %[c], 88" "\n"
Pokitto 51:113b1d84c34f 1803 "add %[y], %[t]" "\n" // y++... derpy, but it's the outer loop
Pokitto 51:113b1d84c34f 1804 "cmp %[y], %[c]" "\n"
Pokitto 51:113b1d84c34f 1805 "bne mode13OuterLoop" "\n" // if y != 88, loop
Pokitto 51:113b1d84c34f 1806
Pokitto 51:113b1d84c34f 1807 : // outputs
Pokitto 51:113b1d84c34f 1808 [c]"+l" (c),
Pokitto 51:113b1d84c34f 1809 [t]"+l" (t),
Pokitto 51:113b1d84c34f 1810 [x]"+l" (x),
Pokitto 51:113b1d84c34f 1811 [y]"+h" (y), // +:Read-Write l:lower (0-7) register
Pokitto 51:113b1d84c34f 1812 [scrbuf]"+l" (scrbuf)
Pokitto 51:113b1d84c34f 1813
Pokitto 51:113b1d84c34f 1814 : // inputs
Pokitto 51:113b1d84c34f 1815 [LCD]"l" (0xA0002188),
Pokitto 51:113b1d84c34f 1816 [scanline]"l" (scanline),
Pokitto 51:113b1d84c34f 1817 [paletteptr]"l" (paletteptr),
Pokitto 51:113b1d84c34f 1818 [offset]"l" (offset)
Pokitto 51:113b1d84c34f 1819 : // clobbers
Pokitto 51:113b1d84c34f 1820 "cc", "r10", "r11"
Pokitto 51:113b1d84c34f 1821 );
Pokitto 46:e7e438368e16 1822
Pokitto 51:113b1d84c34f 1823 #else
Pokitto 51:113b1d84c34f 1824 uint8_t* d = scrbuf;// point to beginning of line in data
Pokitto 51:113b1d84c34f 1825 for(y=0;y<88;y++){
Pokitto 51:113b1d84c34f 1826
Pokitto 51:113b1d84c34f 1827 uint32_t* s = scanline;
Pokitto 51:113b1d84c34f 1828
Pokitto 51:113b1d84c34f 1829 for(x=0;x<110;x+=10){
Pokitto 51:113b1d84c34f 1830 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1831 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1832 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1833 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1834 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1835 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1836 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1837 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1838 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1839 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1840 }
Pokitto 51:113b1d84c34f 1841
Pokitto 51:113b1d84c34f 1842 s = scanline;
Pokitto 51:113b1d84c34f 1843 uint32_t c = *s;
Pokitto 51:113b1d84c34f 1844 for(x=0;x<110;x+=10){
Pokitto 51:113b1d84c34f 1845 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1846 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1847 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1848 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1849 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1850 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1851 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1852 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1853 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1854 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1855 }
Pokitto 51:113b1d84c34f 1856
Pokitto 51:113b1d84c34f 1857 }
Pokitto 51:113b1d84c34f 1858 #endif
Pokitto 51:113b1d84c34f 1859 }
Pokitto 46:e7e438368e16 1860
Pokitto 46:e7e438368e16 1861 void Pokitto::lcdRefreshMode14(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 60:8b6a110feeea 1862 uint16_t x,y;
Pokitto 46:e7e438368e16 1863 uint16_t scanline[176]; uint16_t* scptr;
Pokitto 46:e7e438368e16 1864 uint8_t *d;
Pokitto 46:e7e438368e16 1865
Pokitto 46:e7e438368e16 1866 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 1867 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 1868 write_command(0x22);
Pokitto 46:e7e438368e16 1869 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1870
Pokitto 46:e7e438368e16 1871 for(x=0;x<220;x++)
Pokitto 46:e7e438368e16 1872 {
Pokitto 46:e7e438368e16 1873 d = scrbuf+x;
Pokitto 46:e7e438368e16 1874 scptr = &scanline[0];
Pokitto 46:e7e438368e16 1875
Pokitto 46:e7e438368e16 1876 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1877 /*for(y=0;y<22;y++)
Pokitto 46:e7e438368e16 1878 {
Pokitto 46:e7e438368e16 1879
Pokitto 46:e7e438368e16 1880 uint16_t t = *d;
Pokitto 46:e7e438368e16 1881 uint16_t t2 = *(d+POK_BITFRAME);
Pokitto 46:e7e438368e16 1882 uint16_t t3 = *(d+POK_BITFRAME+POK_BITFRAME);
Pokitto 46:e7e438368e16 1883
Pokitto 46:e7e438368e16 1884 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1885 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1886 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1887 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1888
Pokitto 46:e7e438368e16 1889 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1890 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1891 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1892 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1893
Pokitto 46:e7e438368e16 1894
Pokitto 46:e7e438368e16 1895 d+=220; // jump to word directly below
Pokitto 46:e7e438368e16 1896 }
Pokitto 46:e7e438368e16 1897 */
Pokitto 46:e7e438368e16 1898 /** alternative way: go through one color at a time **/
Pokitto 46:e7e438368e16 1899 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 1900 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 1901 {
Pokitto 46:e7e438368e16 1902 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 1903
Pokitto 46:e7e438368e16 1904 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1905 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1906 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1907 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1908 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1909 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1910 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1911 *scptr++ = R_MASK * (t&0x1);
Pokitto 46:e7e438368e16 1912 }
Pokitto 46:e7e438368e16 1913 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 1914 d = scrbuf+x+POK_BITFRAME;
Pokitto 46:e7e438368e16 1915 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 1916 {
Pokitto 46:e7e438368e16 1917 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 1918
Pokitto 46:e7e438368e16 1919 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1920 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1921 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1922 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1923 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1924 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1925 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1926 *scptr++ |= G_MASK * (t&0x1);
Pokitto 46:e7e438368e16 1927 }
Pokitto 46:e7e438368e16 1928 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 1929 d = scrbuf+x+POK_BITFRAME*2;
Pokitto 46:e7e438368e16 1930 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 1931 {
Pokitto 46:e7e438368e16 1932 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 1933
Pokitto 46:e7e438368e16 1934 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1935 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1936 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1937 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1938 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1939 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1940 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1941 *scptr++ |= B_MASK * (t&0x1);
Pokitto 46:e7e438368e16 1942 }
Pokitto 46:e7e438368e16 1943
Pokitto 46:e7e438368e16 1944
Pokitto 46:e7e438368e16 1945 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1946 if (x<8) continue;
Pokitto 46:e7e438368e16 1947 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 1948 #endif
Pokitto 46:e7e438368e16 1949
Pokitto 46:e7e438368e16 1950 /** draw scanlines **/
Pokitto 46:e7e438368e16 1951 for (int s=0;s<176;) {
Pokitto 46:e7e438368e16 1952 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1953 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1954 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1955 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1956 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1957 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1958 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1959 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1960
Pokitto 46:e7e438368e16 1961 }
Pokitto 46:e7e438368e16 1962
Pokitto 46:e7e438368e16 1963 }
Pokitto 46:e7e438368e16 1964 }
Pokitto 46:e7e438368e16 1965
Pokitto 46:e7e438368e16 1966 //#define ADEKTOSMODE15
Pokitto 46:e7e438368e16 1967
Pokitto 46:e7e438368e16 1968 #ifdef ADEKTOSMODE15
Pokitto 46:e7e438368e16 1969 void Pokitto::lcdRefreshMode15(uint16_t* pal, uint8_t* scrbuf){
Pokitto 46:e7e438368e16 1970 write_command(0x03); write_data(0x1038); //realy only need to call this once
Pokitto 46:e7e438368e16 1971 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 1972 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 1973
Pokitto 46:e7e438368e16 1974 write_command(0x22);
Pokitto 46:e7e438368e16 1975
Pokitto 46:e7e438368e16 1976 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1977 for (int x=0,xt=0; x<0x4BA0;x++,xt++) {
Pokitto 46:e7e438368e16 1978 if (xt==110) xt=0;
Pokitto 46:e7e438368e16 1979 if (xt<8) {
Pokitto 46:e7e438368e16 1980 write_data(0);
Pokitto 46:e7e438368e16 1981 write_data(0);
Pokitto 46:e7e438368e16 1982 } else {
Pokitto 46:e7e438368e16 1983 write_data(pal[(((scrbuf[x]) & 0xf0) >> 4)]);
Pokitto 46:e7e438368e16 1984 write_data(pal[( (scrbuf[x]) & 0x0f)]);
Pokitto 46:e7e438368e16 1985 }
Pokitto 46:e7e438368e16 1986
Pokitto 46:e7e438368e16 1987 }
Pokitto 46:e7e438368e16 1988 #else
Pokitto 46:e7e438368e16 1989 for (int x=0; x<0x4BA0;x++) {
Pokitto 46:e7e438368e16 1990 write_data(pal[(((scrbuf[x]) & 0xf0) >> 4)]);
Pokitto 46:e7e438368e16 1991 write_data(pal[( (scrbuf[x]) & 0x0f)]);
Pokitto 46:e7e438368e16 1992 }
Pokitto 46:e7e438368e16 1993 #endif //PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1994 }
Pokitto 46:e7e438368e16 1995
Pokitto 46:e7e438368e16 1996 #else
Pokitto 46:e7e438368e16 1997
Pokitto 46:e7e438368e16 1998 void Pokitto::lcdRefreshMode15(uint16_t* paletteptr, uint8_t* scrbuf){
Pokitto 60:8b6a110feeea 1999 uint16_t x,y;
Pokitto 46:e7e438368e16 2000 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 60:8b6a110feeea 2001 uint8_t *d;
Pokitto 46:e7e438368e16 2002
Pokitto 46:e7e438368e16 2003 //setDRAMptr(xptr,yoffset);
Pokitto 46:e7e438368e16 2004
Pokitto 46:e7e438368e16 2005 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 2006 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 2007 write_command(0x22);
Pokitto 46:e7e438368e16 2008 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 2009
Pokitto 46:e7e438368e16 2010 for(x=0;x<220;x+=2)
Pokitto 46:e7e438368e16 2011 {
Pokitto 46:e7e438368e16 2012 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 46:e7e438368e16 2013 // find colours in one scanline
Pokitto 46:e7e438368e16 2014 uint8_t s=0;
Pokitto 46:e7e438368e16 2015 for(y=0;y<176;y++)
Pokitto 46:e7e438368e16 2016 {
Pokitto 46:e7e438368e16 2017 uint8_t t = *d >> 4; // higher nibble
Pokitto 46:e7e438368e16 2018 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 46:e7e438368e16 2019 // higher nibble = left pixel in pixel pair
Pokitto 46:e7e438368e16 2020 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 2021 scanline[1][s++] = paletteptr[t2];
Pokitto 46:e7e438368e16 2022
Pokitto 46:e7e438368e16 2023 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 2024 }
Pokitto 46:e7e438368e16 2025 s=0;
Pokitto 46:e7e438368e16 2026 // draw scanlines
Pokitto 46:e7e438368e16 2027
Pokitto 46:e7e438368e16 2028 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 2029 if (x<8) continue;
Pokitto 46:e7e438368e16 2030 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 2031 #endif
Pokitto 46:e7e438368e16 2032
Pokitto 46:e7e438368e16 2033 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 2034 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2035 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2036 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2037 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2038 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2039 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2040 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2041 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2042 }
Pokitto 46:e7e438368e16 2043
Pokitto 46:e7e438368e16 2044 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 2045 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2046 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2047 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2048 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2049 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2050 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2051 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2052 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2053 }
Pokitto 46:e7e438368e16 2054 }
Pokitto 46:e7e438368e16 2055 }
Pokitto 46:e7e438368e16 2056 #endif //ADEKTOSMODE15
Pokitto 46:e7e438368e16 2057
Pokitto 46:e7e438368e16 2058 void Pokitto::blitWord(uint16_t c) {
Pokitto 46:e7e438368e16 2059 setup_data_16(c);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2060 }
Pokitto 46:e7e438368e16 2061
Pokitto 46:e7e438368e16 2062