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

Committer:
Pokitto
Date:
Sun Jul 01 06:32:10 2018 +0000
Revision:
51:113b1d84c34f
Parent:
48:30b068b0d9e8
Child:
60:8b6a110feeea
PokittoCookie and faster Mode2 and Mode13 added

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
Pokitto 46:e7e438368e16 414 void Pokitto::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
Pokitto 46:e7e438368e16 415 int16_t temp;
Pokitto 46:e7e438368e16 416 if (x0>x1) {temp=x0;x0=x1;x1=temp;}
Pokitto 46:e7e438368e16 417 if (y0>y1) {temp=y0;y0=y1;y1=temp;}
Pokitto 46:e7e438368e16 418 if (x0 > POK_LCD_W) return;
Pokitto 46:e7e438368e16 419 if (y0 > POK_LCD_H) return;
Pokitto 46:e7e438368e16 420 if (x1 > POK_LCD_W) x1=POK_LCD_W;
Pokitto 46:e7e438368e16 421 if (y1 > POK_LCD_H) y1=POK_LCD_H;
Pokitto 46:e7e438368e16 422 if (x0 < 0) x0=0;
Pokitto 46:e7e438368e16 423 if (y0 < 0) y0=0;
Pokitto 46:e7e438368e16 424
Pokitto 46:e7e438368e16 425 int16_t x,y;
Pokitto 46:e7e438368e16 426 for (x=x0; x<=x1;x++) {
Pokitto 46:e7e438368e16 427 write_command(0x20); // Horizontal DRAM Address (=y on pokitto screen)
Pokitto 46:e7e438368e16 428 write_data(y0);
Pokitto 46:e7e438368e16 429 write_command(0x21); // Vertical DRAM Address (=x on pokitto screen)
Pokitto 46:e7e438368e16 430 write_data(x);
Pokitto 46:e7e438368e16 431 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 432
Pokitto 46:e7e438368e16 433 CLR_CS_SET_CD_RD_WR; // go to vram write mode
Pokitto 46:e7e438368e16 434
Pokitto 46:e7e438368e16 435
Pokitto 46:e7e438368e16 436 for (y=y0; y<y1;y++) {
Pokitto 46:e7e438368e16 437 setup_data_16(color); // setup the data (flat color = no change between pixels)
Pokitto 46:e7e438368e16 438 CLR_WR;SET_WR; //CLR_WR;SET_WR;//toggle writeline, pokitto screen writes a column up to down
Pokitto 46:e7e438368e16 439 }
Pokitto 46:e7e438368e16 440 }
Pokitto 46:e7e438368e16 441 }
Pokitto 46:e7e438368e16 442
Pokitto 46:e7e438368e16 443 /***
Pokitto 46:e7e438368e16 444 * Update the screen buffer of 220x176 pixels, 4 colors to LCD.
Pokitto 46:e7e438368e16 445 *
Pokitto 46:e7e438368e16 446 * The update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations, the
Pokitto 46:e7e438368e16 447 * 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 448 * Note: The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 46:e7e438368e16 449 * @param scrbuf The screen buffer.
Pokitto 46:e7e438368e16 450 * @param updRectX The update rect.
Pokitto 46:e7e438368e16 451 * @param updRectY The update rect.
Pokitto 46:e7e438368e16 452 * @param updRectW The update rect.
Pokitto 46:e7e438368e16 453 * @param updRectH The update rect.
Pokitto 46:e7e438368e16 454 * @param paletteptr The screen palette.
Pokitto 46:e7e438368e16 455 */
Pokitto 46:e7e438368e16 456 void Pokitto::lcdRefreshMode1(uint8_t * scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 457
Pokitto 46:e7e438368e16 458 uint16_t x,y,xptr;
Pokitto 46:e7e438368e16 459 uint16_t scanline[4][176]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 46:e7e438368e16 460 uint8_t *d, yoffset=0;
Pokitto 46:e7e438368e16 461
Pokitto 46:e7e438368e16 462 // If not the full screen is updated, check the validity of the update rect.
Pokitto 46:e7e438368e16 463 if ( updRectX != 0 || updRectY != 0 ||updRectW != LCDWIDTH ||updRectH != LCDHEIGHT ) {
Pokitto 46:e7e438368e16 464 uint8_t org_screenx = updRectX;
Pokitto 46:e7e438368e16 465 updRectX &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 466 updRectW += org_screenx - updRectX;
Pokitto 46:e7e438368e16 467 updRectW = (updRectW + 3) & 0xfc; // Make the value dividable by 4, round up.
Pokitto 46:e7e438368e16 468
Pokitto 46:e7e438368e16 469 uint8_t org_screeny = updRectY;
Pokitto 46:e7e438368e16 470 updRectY &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 471 updRectH += org_screeny - updRectY;
Pokitto 46:e7e438368e16 472 updRectH = (updRectH + 7) & 0xf8; // Make the value dividable by 8 (because of loop unroll optimization), round up.
Pokitto 46:e7e438368e16 473 }
Pokitto 46:e7e438368e16 474
Pokitto 46:e7e438368e16 475
Pokitto 46:e7e438368e16 476 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 477 xptr = 8;
Pokitto 46:e7e438368e16 478 setDRAMptr(8, 0);
Pokitto 46:e7e438368e16 479 #else
Pokitto 46:e7e438368e16 480 xptr = 0;
Pokitto 46:e7e438368e16 481 setDRAMptr(0, 0);
Pokitto 46:e7e438368e16 482 #endif
Pokitto 46:e7e438368e16 483
Pokitto 46:e7e438368e16 484 for (x=updRectX; x<updRectX+updRectW; x+=4) {
Pokitto 46:e7e438368e16 485 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 486
Pokitto 46:e7e438368e16 487 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 488 uint8_t s=0;
Pokitto 46:e7e438368e16 489 d += (updRectY * 220/4);
Pokitto 46:e7e438368e16 490 for (y=updRectY; y<updRectY+updRectH; y++) {
Pokitto 46:e7e438368e16 491 uint8_t tdata = *d;
Pokitto 46:e7e438368e16 492 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 493 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 494 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 495 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 496
Pokitto 46:e7e438368e16 497 /** put nibble values in the scanlines **/
Pokitto 46:e7e438368e16 498 scanline[0][y] = paletteptr[t];
Pokitto 46:e7e438368e16 499 scanline[1][y] = paletteptr[t2];
Pokitto 46:e7e438368e16 500 scanline[2][y] = paletteptr[t3];
Pokitto 46:e7e438368e16 501 scanline[3][y] = paletteptr[t4];
Pokitto 46:e7e438368e16 502
Pokitto 46:e7e438368e16 503 d += 220/4; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 504 }
Pokitto 46:e7e438368e16 505
Pokitto 46:e7e438368e16 506 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 507 if (x>=8 ) {
Pokitto 46:e7e438368e16 508 #else
Pokitto 46:e7e438368e16 509 {
Pokitto 46:e7e438368e16 510
Pokitto 46:e7e438368e16 511 #endif
Pokitto 46:e7e438368e16 512
Pokitto 46:e7e438368e16 513 // Draw 8 vertical pixels at a time for performance reasons
Pokitto 46:e7e438368e16 514 setDRAMptr(x, updRectY);
Pokitto 46:e7e438368e16 515 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 516 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 517 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 518 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 519 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 520 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 521 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 522 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 523 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 524 }
Pokitto 46:e7e438368e16 525 setDRAMptr(x+1, updRectY);
Pokitto 46:e7e438368e16 526 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 527 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 528 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 529 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 530 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 531 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 532 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 533 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 534 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 535 }
Pokitto 46:e7e438368e16 536 setDRAMptr(x+2, updRectY);
Pokitto 46:e7e438368e16 537 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 538 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 539 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 540 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 541 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 542 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 543 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 544 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 545 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 546 }
Pokitto 46:e7e438368e16 547 setDRAMptr(x+3, updRectY);
Pokitto 46:e7e438368e16 548 for (uint8_t s=updRectY; s<updRectY+updRectH;) {
Pokitto 46:e7e438368e16 549 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 550 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 551 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 552 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 553 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 554 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 555 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 556 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 557 }
Pokitto 46:e7e438368e16 558 }
Pokitto 46:e7e438368e16 559 }
Pokitto 46:e7e438368e16 560
Pokitto 46:e7e438368e16 561 #ifdef POK_SIM
Pokitto 46:e7e438368e16 562 simulator.refreshDisplay();
Pokitto 46:e7e438368e16 563 #endif
Pokitto 46:e7e438368e16 564 }
Pokitto 46:e7e438368e16 565
Pokitto 46:e7e438368e16 566 // Copy sprite pixels to the scanline
Pokitto 46:e7e438368e16 567 #define SPRITE_2BPP_INNER_LOOP(n)\
Pokitto 46:e7e438368e16 568 \
Pokitto 46:e7e438368e16 569 /* If the sprite is enabled and contained in this vertical scanline, copy 4 pixels. */\
Pokitto 46:e7e438368e16 570 if (sprScanlineAddr[(n)] &&\
Pokitto 46:e7e438368e16 571 y >= sprites[(n)].y && y < sprites[(n)].y + sprites[(n)].h ) {\
Pokitto 46:e7e438368e16 572 \
Pokitto 46:e7e438368e16 573 int16_t sprx = sprites[(n)].x;\
Pokitto 46:e7e438368e16 574 uint16_t s_data16b = 0; /* sprite data, 2 bytes */\
Pokitto 46:e7e438368e16 575 \
Pokitto 46:e7e438368e16 576 /* Get pixel block, 4 or 8 pixels horizontally. Use the predefined bitshift mode. */\
Pokitto 46:e7e438368e16 577 /* Note:it is cheapest to compare to 0 first. */\
Pokitto 46:e7e438368e16 578 if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_MIDDLE_BYTE) {\
Pokitto 46:e7e438368e16 579 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 46:e7e438368e16 580 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 46:e7e438368e16 581 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 46:e7e438368e16 582 }\
Pokitto 46:e7e438368e16 583 else if (sprScanlineBitshiftMode[(n)] == BITSHIFT_MODE_FIRST_BYTE) {\
Pokitto 46:e7e438368e16 584 s_data16b = *(sprScanlineAddr[(n)]);\
Pokitto 46:e7e438368e16 585 }\
Pokitto 46:e7e438368e16 586 else { /* BITSHIFT_MODE_LAST_BYTE */\
Pokitto 46:e7e438368e16 587 uint16_t leftByte = *(sprScanlineAddr[(n)]-1);\
Pokitto 46:e7e438368e16 588 s_data16b = (leftByte << 8) | s_data16b;\
Pokitto 46:e7e438368e16 589 }\
Pokitto 46:e7e438368e16 590 \
Pokitto 46:e7e438368e16 591 /* Shift sprite pixels according to sprite x. After shifting we have only 4 pixels. */\
Pokitto 46:e7e438368e16 592 uint8_t shiftRight = (sprx&0x3) << 1;\
Pokitto 46:e7e438368e16 593 s_data16b = (s_data16b >> shiftRight);\
Pokitto 46:e7e438368e16 594 \
Pokitto 46:e7e438368e16 595 /* Get individual pixels */\
Pokitto 46:e7e438368e16 596 uint8_t s_t4 = s_data16b & 0x03; s_data16b >>= 2; /* lowest half-nibble */\
Pokitto 46:e7e438368e16 597 uint8_t s_t3 = s_data16b & 0x03; s_data16b >>= 2; /* second lowest half-nibble */\
Pokitto 46:e7e438368e16 598 uint8_t s_t2 = s_data16b & 0x03; s_data16b >>= 2; /* second highest half-nibble */\
Pokitto 46:e7e438368e16 599 uint8_t s_t1 = s_data16b & 0x03; /* highest half-nibble */\
Pokitto 46:e7e438368e16 600 \
Pokitto 46:e7e438368e16 601 /* Store pixels as 16-bit colors from the palette */\
Pokitto 46:e7e438368e16 602 if (s_t4 != transparentColor) p4 = sprites[(n)].palette[s_t4];\
Pokitto 46:e7e438368e16 603 if (s_t3 != transparentColor) p3 = sprites[(n)].palette[s_t3];\
Pokitto 46:e7e438368e16 604 if (s_t2 != transparentColor) p2 = sprites[(n)].palette[s_t2];\
Pokitto 46:e7e438368e16 605 if (s_t1 != transparentColor) p = sprites[(n)].palette[s_t1];\
Pokitto 46:e7e438368e16 606 \
Pokitto 46:e7e438368e16 607 /* Advance scanline address */\
Pokitto 46:e7e438368e16 608 sprScanlineAddr[(n)] += (sprites[(n)].w >> 2);\
Pokitto 46:e7e438368e16 609 }
Pokitto 46:e7e438368e16 610
Pokitto 46:e7e438368e16 611 // Loop unrolling macros
Pokitto 46:e7e438368e16 612 #define UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(0)
Pokitto 46:e7e438368e16 613 #define UNROLLED_LOOP_2() UNROLLED_LOOP_1() SPRITE_2BPP_INNER_LOOP(1)
Pokitto 46:e7e438368e16 614 #define UNROLLED_LOOP_3() UNROLLED_LOOP_2() SPRITE_2BPP_INNER_LOOP(2)
Pokitto 46:e7e438368e16 615 #define UNROLLED_LOOP_4() UNROLLED_LOOP_3() SPRITE_2BPP_INNER_LOOP(3)
Pokitto 46:e7e438368e16 616 #define UNROLLED_LOOP_5() UNROLLED_LOOP_4() SPRITE_2BPP_INNER_LOOP(4)
Pokitto 46:e7e438368e16 617 #define UNROLLED_LOOP_6() UNROLLED_LOOP_5() SPRITE_2BPP_INNER_LOOP(5)
Pokitto 46:e7e438368e16 618 #define UNROLLED_LOOP_7() UNROLLED_LOOP_6() SPRITE_2BPP_INNER_LOOP(6)
Pokitto 46:e7e438368e16 619 #define UNROLLED_LOOP_8() UNROLLED_LOOP_7() SPRITE_2BPP_INNER_LOOP(7)
Pokitto 46:e7e438368e16 620 #define UNROLLED_LOOP_9() UNROLLED_LOOP_8() SPRITE_2BPP_INNER_LOOP(8)
Pokitto 46:e7e438368e16 621 #define UNROLLED_LOOP_10() UNROLLED_LOOP_9() SPRITE_2BPP_INNER_LOOP(9)
Pokitto 46:e7e438368e16 622 #define UNROLLED_LOOP_11() UNROLLED_LOOP_10() SPRITE_2BPP_INNER_LOOP(10)
Pokitto 46:e7e438368e16 623 #define UNROLLED_LOOP_12() UNROLLED_LOOP_11() SPRITE_2BPP_INNER_LOOP(11)
Pokitto 46:e7e438368e16 624 #define UNROLLED_LOOP_13() UNROLLED_LOOP_12() SPRITE_2BPP_INNER_LOOP(12)
Pokitto 46:e7e438368e16 625 #define UNROLLED_LOOP_14() UNROLLED_LOOP_13() SPRITE_2BPP_INNER_LOOP(13)
Pokitto 46:e7e438368e16 626 #define UNROLLED_LOOP_15() UNROLLED_LOOP_14() SPRITE_2BPP_INNER_LOOP(14)
Pokitto 46:e7e438368e16 627 #define UNROLLED_LOOP_16() UNROLLED_LOOP_15() SPRITE_2BPP_INNER_LOOP(15)
Pokitto 46:e7e438368e16 628 #define UNROLLED_LOOP_N_(n) UNROLLED_LOOP_##n()
Pokitto 46:e7e438368e16 629 #define UNROLLED_LOOP_N(n) UNROLLED_LOOP_N_(n)
Pokitto 46:e7e438368e16 630
Pokitto 46:e7e438368e16 631 /***
Pokitto 46:e7e438368e16 632 * Update the screen buffer of 220x176 pixels, 4 colors and free size 4 color sprites to LCD.
Pokitto 46:e7e438368e16 633 *
Pokitto 46:e7e438368e16 634 * The update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations, the
Pokitto 46:e7e438368e16 635 * 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 636 * Note: The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 46:e7e438368e16 637 * If drawSpritesOnly=true, only sprites are fully updated to LCD. However, the dirty rect of the screen buffer is
Pokitto 46:e7e438368e16 638 * drawn behind the sprite current and previous location.
Pokitto 46:e7e438368e16 639 * Note: Sprite is enabled if sprite.bitmapData is not NULL. Also all enabled sprites must be at the beginning of
Pokitto 46:e7e438368e16 640 * the sprites array. No gaps are allowed in the array.
Pokitto 46:e7e438368e16 641 * @param scrbuf The screen buffer.
Pokitto 46:e7e438368e16 642 * @param updRectX The update rect.
Pokitto 46:e7e438368e16 643 * @param updRectY The update rect.
Pokitto 46:e7e438368e16 644 * @param updRectW The update rect.
Pokitto 46:e7e438368e16 645 * @param updRectH The update rect.
Pokitto 46:e7e438368e16 646 * @param paletteptr The screen palette.
Pokitto 46:e7e438368e16 647 * @param sprites The sprite array.
Pokitto 46:e7e438368e16 648 * @param drawSpritesOnly True, if only sprites are drawn. False, if both sprites and the screen buffer are drawn.
Pokitto 46:e7e438368e16 649 */
Pokitto 46:e7e438368e16 650 void Pokitto::lcdRefreshMode1Spr(
Pokitto 46:e7e438368e16 651 uint8_t * scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr,
Pokitto 46:e7e438368e16 652 SpriteInfo* sprites, bool drawSpritesOnly) {
Pokitto 46:e7e438368e16 653
Pokitto 46:e7e438368e16 654 // In direct mode draw only sprites and their dirty rects. Return now if there are no sprites
Pokitto 46:e7e438368e16 655 if (drawSpritesOnly && (sprites == NULL || sprites[0].bitmapData == NULL))
Pokitto 46:e7e438368e16 656 return;
Pokitto 46:e7e438368e16 657
Pokitto 46:e7e438368e16 658 uint16_t x,y;
Pokitto 46:e7e438368e16 659 uint16_t scanline[4][176]; // read 4 half-nibbles (= 4 pixels) at a time
Pokitto 46:e7e438368e16 660 const uint8_t transparentColor = 0; // fixed palette index 0 for transparency
Pokitto 46:e7e438368e16 661
Pokitto 46:e7e438368e16 662 // If not the full screen is updated, check the validity of the update rect.
Pokitto 46:e7e438368e16 663 if ( updRectX != 0 || updRectY != 0 ||updRectW != LCDWIDTH ||updRectH != LCDHEIGHT ) {
Pokitto 46:e7e438368e16 664 uint8_t org_screenx = updRectX;
Pokitto 46:e7e438368e16 665 updRectX &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 666 updRectW += org_screenx - updRectX;
Pokitto 46:e7e438368e16 667 updRectW = (updRectW + 3) & 0xfc; // Make the value dividable by 4, round up.
Pokitto 46:e7e438368e16 668
Pokitto 46:e7e438368e16 669 uint8_t org_screeny = updRectY;
Pokitto 46:e7e438368e16 670 updRectY &= 0xfc; // Make the value dividable by 4.
Pokitto 46:e7e438368e16 671 updRectH += org_screeny - updRectY;
Pokitto 46:e7e438368e16 672 updRectH = (updRectH + 7) & 0xf8; // Make the value dividable by 8 (because of loop unroll optimization), round up.
Pokitto 46:e7e438368e16 673 }
Pokitto 46:e7e438368e16 674
Pokitto 46:e7e438368e16 675 // Calculate the current amount of sprites
Pokitto 46:e7e438368e16 676 // 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 677 uint8_t spriteCount = 0;
Pokitto 46:e7e438368e16 678 if (sprites != NULL)
Pokitto 46:e7e438368e16 679 for (;sprites[spriteCount].bitmapData != NULL && spriteCount < SPRITE_COUNT; spriteCount++);
Pokitto 46:e7e438368e16 680
Pokitto 46:e7e438368e16 681 // If drawing the screen buffer, set the start pos to LCD commands only here.
Pokitto 46:e7e438368e16 682 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 683 if (!drawSpritesOnly) setDRAMptr(8, 0);
Pokitto 46:e7e438368e16 684 #else
Pokitto 46:e7e438368e16 685 if (!drawSpritesOnly) setDRAMptr(0, 0);
Pokitto 46:e7e438368e16 686 #endif
Pokitto 46:e7e438368e16 687
Pokitto 46:e7e438368e16 688 //*** GO THROUGH EACH VERTICAL GROUP OF 4 SCANLINES.***
Pokitto 46:e7e438368e16 689
Pokitto 46:e7e438368e16 690 for (x=0; x<LCDWIDTH; x+=4) {
Pokitto 46:e7e438368e16 691
Pokitto 46:e7e438368e16 692 uint8_t *screenBufScanlineAddr = scrbuf + (x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 693
Pokitto 46:e7e438368e16 694 /*Prepare scanline start address for sprites that are visible in this vertical scanline. Sprite width cannot exceed the screen width*/
Pokitto 46:e7e438368e16 695 uint8_t *sprScanlineAddr[SPRITE_COUNT]; // Sprite start address for the scanline
Pokitto 46:e7e438368e16 696 uint8_t sprScanlineBitshiftMode[SPRITE_COUNT]; // Sprite bitshift mode for the scanline
Pokitto 46:e7e438368e16 697 const uint8_t BITSHIFT_MODE_MIDDLE_BYTE = 0;
Pokitto 46:e7e438368e16 698 const uint8_t BITSHIFT_MODE_FIRST_BYTE = 1;
Pokitto 46:e7e438368e16 699 const uint8_t BITSHIFT_MODE_LAST_BYTE = 2;
Pokitto 46:e7e438368e16 700 uint8_t scanlineMinY = 255; // Init to uninitialized value. Do not draw by default.
Pokitto 46:e7e438368e16 701 uint8_t scanlineMaxY = 0; // Init to uninitialized value. Do not draw by default.
Pokitto 46:e7e438368e16 702
Pokitto 46:e7e438368e16 703 //*** CALCULATE DIRTY RECTS AND RESOLVE WHICH SPRITES BELONG TO THIS SCANLINE GROUP ***
Pokitto 46:e7e438368e16 704
Pokitto 46:e7e438368e16 705 if (sprites != NULL) {
Pokitto 46:e7e438368e16 706
Pokitto 46:e7e438368e16 707 // Check all the sprites for this scanline. That is used for handling the given update rect
Pokitto 46:e7e438368e16 708 // Note that the last round is when (sprindex == spriteCount). That is used to add the screen buffer
Pokitto 46:e7e438368e16 709 // update rect to the dirty rect.
Pokitto 46:e7e438368e16 710 for (int sprindex = 0; sprindex <= spriteCount; sprindex++) {
Pokitto 46:e7e438368e16 711
Pokitto 46:e7e438368e16 712 int16_t sprx, spry, sprOldX, sprOldY;
Pokitto 46:e7e438368e16 713 uint8_t sprw, sprh;
Pokitto 46:e7e438368e16 714 bool isCurrentSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 715 bool isOldSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 716
Pokitto 46:e7e438368e16 717 if (sprindex < spriteCount) {
Pokitto 46:e7e438368e16 718
Pokitto 46:e7e438368e16 719 sprx = sprites[sprindex].x;
Pokitto 46:e7e438368e16 720 spry = sprites[sprindex].y;
Pokitto 46:e7e438368e16 721 sprw = sprites[sprindex].w;
Pokitto 46:e7e438368e16 722 sprh = sprites[sprindex].h;
Pokitto 46:e7e438368e16 723 sprOldX = sprites[sprindex].oldx;
Pokitto 46:e7e438368e16 724 sprOldY = sprites[sprindex].oldy;
Pokitto 46:e7e438368e16 725 }
Pokitto 46:e7e438368e16 726
Pokitto 46:e7e438368e16 727 // Handle the screen buffer update rect after all sprites
Pokitto 46:e7e438368e16 728 else if(!drawSpritesOnly){
Pokitto 46:e7e438368e16 729
Pokitto 46:e7e438368e16 730 sprx = updRectX;
Pokitto 46:e7e438368e16 731 spry = updRectY;
Pokitto 46:e7e438368e16 732 sprw = updRectW;
Pokitto 46:e7e438368e16 733 sprh = updRectH;
Pokitto 46:e7e438368e16 734 sprOldX = updRectX;
Pokitto 46:e7e438368e16 735 sprOldY = updRectY;
Pokitto 46:e7e438368e16 736 isCurrentSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 737 isOldSpriteOutOfScreen = false;
Pokitto 46:e7e438368e16 738 }
Pokitto 46:e7e438368e16 739
Pokitto 46:e7e438368e16 740 // Check for out-of-screen
Pokitto 46:e7e438368e16 741 if (sprx >= LCDWIDTH || spry >= LCDHEIGHT)
Pokitto 46:e7e438368e16 742 isCurrentSpriteOutOfScreen = true;
Pokitto 46:e7e438368e16 743 if (sprOldX >= LCDWIDTH || sprOldY >= LCDHEIGHT)
Pokitto 46:e7e438368e16 744 isOldSpriteOutOfScreen = true;
Pokitto 46:e7e438368e16 745
Pokitto 46:e7e438368e16 746 // Skip if current and old sprites are out-of-screen
Pokitto 46:e7e438368e16 747 if (isCurrentSpriteOutOfScreen && isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 748 continue;
Pokitto 46:e7e438368e16 749
Pokitto 46:e7e438368e16 750 // Detect the dirty rect x-span by combining the previous and current sprite position.
Pokitto 51:113b1d84c34f 751 int16_t sprDirtyXMin = avrmin(sprx, sprOldX);
Pokitto 51:113b1d84c34f 752 int16_t sprDirtyXMax = avrmax(sprx, sprOldX);
Pokitto 46:e7e438368e16 753 if (isCurrentSpriteOutOfScreen)
Pokitto 46:e7e438368e16 754 sprDirtyXMax = sprOldX;
Pokitto 46:e7e438368e16 755 if (isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 756 sprDirtyXMax = sprx;
Pokitto 46:e7e438368e16 757
Pokitto 46:e7e438368e16 758 // Is current x inside the sprite combined dirty rect ?
Pokitto 46:e7e438368e16 759 int16_t sprDirtyXMaxEnd = sprDirtyXMax + sprw - 1 + 4; // Add 4 pixels to dirty rect width (needed?)
Pokitto 46:e7e438368e16 760 if (sprDirtyXMin <= x+3 && x <= sprDirtyXMaxEnd) {
Pokitto 46:e7e438368e16 761
Pokitto 46:e7e438368e16 762 // *** COMBINE DIRTY RECTS FOR THIS SCANLINE GROUP ***
Pokitto 46:e7e438368e16 763
Pokitto 46:e7e438368e16 764 // Dirty rect
Pokitto 51:113b1d84c34f 765 int sprDirtyYMin = avrmin(spry, sprOldY);
Pokitto 51:113b1d84c34f 766 sprDirtyYMin = avrmax((int)sprDirtyYMin, 0);
Pokitto 51:113b1d84c34f 767 int sprDirtyYMax = avrmax(spry, sprOldY);
Pokitto 46:e7e438368e16 768 if (isCurrentSpriteOutOfScreen)
Pokitto 46:e7e438368e16 769 sprDirtyYMax = sprOldY;
Pokitto 46:e7e438368e16 770 if (isOldSpriteOutOfScreen)
Pokitto 46:e7e438368e16 771 sprDirtyYMax = spry;
Pokitto 46:e7e438368e16 772 int sprDirtyYMaxEnd = sprDirtyYMax + sprh - 1;
Pokitto 51:113b1d84c34f 773 sprDirtyYMaxEnd = avrmin(sprDirtyYMaxEnd, LCDHEIGHT - 1); // Should use LCDHEIGHT instead of screenH? Same with other screen* ?
Pokitto 46:e7e438368e16 774
Pokitto 46:e7e438368e16 775 // Get the scanline min and max y values for drawing
Pokitto 46:e7e438368e16 776 if (sprDirtyYMin < scanlineMinY)
Pokitto 46:e7e438368e16 777 scanlineMinY = sprDirtyYMin;
Pokitto 46:e7e438368e16 778 if (sprDirtyYMaxEnd > scanlineMaxY)
Pokitto 46:e7e438368e16 779 scanlineMaxY = sprDirtyYMaxEnd;
Pokitto 46:e7e438368e16 780
Pokitto 46:e7e438368e16 781 // *** PREPARE SPRITE FOR DRAWING ***
Pokitto 46:e7e438368e16 782
Pokitto 46:e7e438368e16 783 // Check if the sprite should be active for this vertical scanline group.
Pokitto 46:e7e438368e16 784 if (sprindex < spriteCount && // not for update rect
Pokitto 46:e7e438368e16 785 !isCurrentSpriteOutOfScreen && //out-of-screen
Pokitto 46:e7e438368e16 786 sprx <= x+3 && x < sprx + sprw) { // note: cover group of 4 pixels of the scanline (x+3)
Pokitto 46:e7e438368e16 787
Pokitto 46:e7e438368e16 788 // Find the byte number in the sprite data
Pokitto 46:e7e438368e16 789 int16_t byteNum = ((x+3) - sprx)>>2;
Pokitto 46:e7e438368e16 790
Pokitto 46:e7e438368e16 791 // Get the start addres of the spite data in this scanline.
Pokitto 46:e7e438368e16 792 sprScanlineAddr[sprindex] = const_cast<uint8_t*>(sprites[sprindex].bitmapData + byteNum);
Pokitto 46:e7e438368e16 793
Pokitto 46:e7e438368e16 794 // If the sprite goes over the top, it must be clipped from the top.
Pokitto 46:e7e438368e16 795 if(spry < 0)
Pokitto 46:e7e438368e16 796 sprScanlineAddr[sprindex] += (-spry) * (sprw >> 2);
Pokitto 46:e7e438368e16 797
Pokitto 46:e7e438368e16 798 // Select the bitshift mode for the blit algorithm
Pokitto 46:e7e438368e16 799 if (byteNum == 0)
Pokitto 46:e7e438368e16 800 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_FIRST_BYTE;
Pokitto 46:e7e438368e16 801 else if (byteNum >= (sprw >> 2))
Pokitto 46:e7e438368e16 802 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_LAST_BYTE;
Pokitto 46:e7e438368e16 803 else
Pokitto 46:e7e438368e16 804 sprScanlineBitshiftMode[sprindex] = BITSHIFT_MODE_MIDDLE_BYTE;
Pokitto 46:e7e438368e16 805 }
Pokitto 46:e7e438368e16 806 else
Pokitto 46:e7e438368e16 807 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 46:e7e438368e16 808 }
Pokitto 46:e7e438368e16 809 else
Pokitto 46:e7e438368e16 810 sprScanlineAddr[sprindex] = NULL; // Deactive sprite for this scanline
Pokitto 46:e7e438368e16 811 }
Pokitto 46:e7e438368e16 812 }
Pokitto 46:e7e438368e16 813
Pokitto 46:e7e438368e16 814 // *** ADJUST THE SCANLINE GROUP HEIGHT ***
Pokitto 46:e7e438368e16 815
Pokitto 46:e7e438368e16 816 // The height must dividable by 8. That is needed because later we copy 8 pixels at a time to the LCD.
Pokitto 46:e7e438368e16 817 if (scanlineMaxY - scanlineMinY + 1 > 0) {
Pokitto 46:e7e438368e16 818 uint8_t scanlineH = scanlineMaxY - scanlineMinY + 1;
Pokitto 46:e7e438368e16 819 uint8_t addW = 8 - (scanlineH & 0x7);
Pokitto 46:e7e438368e16 820
Pokitto 46:e7e438368e16 821 // if height is not dividable by 8, make it be.
Pokitto 46:e7e438368e16 822 if (addW != 0) {
Pokitto 46:e7e438368e16 823 if (scanlineMinY > addW )
Pokitto 46:e7e438368e16 824 scanlineMinY -= addW;
Pokitto 46:e7e438368e16 825 else if( scanlineMaxY + addW < updRectY+updRectH)
Pokitto 46:e7e438368e16 826 scanlineMaxY += addW;
Pokitto 46:e7e438368e16 827 else {
Pokitto 46:e7e438368e16 828 // Draw full height scanline
Pokitto 46:e7e438368e16 829 scanlineMinY = updRectY;
Pokitto 46:e7e438368e16 830 scanlineMaxY = updRectY+updRectH-1;
Pokitto 46:e7e438368e16 831 }
Pokitto 46:e7e438368e16 832 }
Pokitto 46:e7e438368e16 833 }
Pokitto 46:e7e438368e16 834
Pokitto 46:e7e438368e16 835 // *** COMBINE THE SCANLINE GROUP OF THE SCREEN BUFFER AND ALL SPRITES ***
Pokitto 46:e7e438368e16 836
Pokitto 46:e7e438368e16 837 // Find colours in this group of 4 scanlines
Pokitto 46:e7e438368e16 838 screenBufScanlineAddr += (scanlineMinY * 220/4);
Pokitto 46:e7e438368e16 839 for (y=scanlineMinY; y<=scanlineMaxY; y++)
Pokitto 46:e7e438368e16 840 {
Pokitto 46:e7e438368e16 841 // get the screen buffer data first
Pokitto 46:e7e438368e16 842 uint8_t tdata = *screenBufScanlineAddr;
Pokitto 46:e7e438368e16 843 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 844 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 845 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 846 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 847
Pokitto 46:e7e438368e16 848 // Convert to 16-bit colors in palette
Pokitto 46:e7e438368e16 849 uint16_t p = paletteptr[t];
Pokitto 46:e7e438368e16 850 uint16_t p2 = paletteptr[t2];
Pokitto 46:e7e438368e16 851 uint16_t p3 = paletteptr[t3];
Pokitto 46:e7e438368e16 852 uint16_t p4 = paletteptr[t4];
Pokitto 46:e7e438368e16 853
Pokitto 46:e7e438368e16 854 #if 0
Pokitto 46:e7e438368e16 855 // Dirty rect visual test
Pokitto 46:e7e438368e16 856 p = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 857 p2 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 858 p3 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 859 p4 = COLOR_BLUE >> (Core::frameCount % 5);
Pokitto 46:e7e438368e16 860 #endif
Pokitto 46:e7e438368e16 861
Pokitto 46:e7e438368e16 862 // Add active sprite pixels
Pokitto 46:e7e438368e16 863 if (sprites != NULL) {
Pokitto 46:e7e438368e16 864
Pokitto 46:e7e438368e16 865 // Use loop unrolling for speed optimization
Pokitto 46:e7e438368e16 866 UNROLLED_LOOP_N(SPRITE_COUNT)
Pokitto 46:e7e438368e16 867 }
Pokitto 46:e7e438368e16 868
Pokitto 46:e7e438368e16 869 // put the result nibble values in the scanline
Pokitto 46:e7e438368e16 870 scanline[0][y] = p;
Pokitto 46:e7e438368e16 871 scanline[1][y] = p2;
Pokitto 46:e7e438368e16 872 scanline[2][y] = p3;
Pokitto 46:e7e438368e16 873 scanline[3][y] = p4;
Pokitto 46:e7e438368e16 874
Pokitto 46:e7e438368e16 875 screenBufScanlineAddr += 220>>2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 876 }
Pokitto 46:e7e438368e16 877
Pokitto 46:e7e438368e16 878 // *** DRAW THE SCANLINE GROUP TO LCD
Pokitto 46:e7e438368e16 879
Pokitto 46:e7e438368e16 880 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 881 if (x>=8 && scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 46:e7e438368e16 882 #else
Pokitto 46:e7e438368e16 883 if (scanlineMaxY - scanlineMinY +1 > 0) {
Pokitto 46:e7e438368e16 884 #endif
Pokitto 46:e7e438368e16 885 // Draw 8 vertical pixels at a time for performance reasons
Pokitto 46:e7e438368e16 886
Pokitto 46:e7e438368e16 887 setDRAMptr(x, scanlineMinY);
Pokitto 46:e7e438368e16 888 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 889 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 890 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 891 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 892 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 893 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 894 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 895 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 896 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 897 }
Pokitto 46:e7e438368e16 898
Pokitto 46:e7e438368e16 899 setDRAMptr(x+1, scanlineMinY);
Pokitto 46:e7e438368e16 900 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 901 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 902 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 903 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 904 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 905 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 906 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 907 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 908 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 909 }
Pokitto 46:e7e438368e16 910
Pokitto 46:e7e438368e16 911 setDRAMptr(x+2, scanlineMinY);
Pokitto 46:e7e438368e16 912 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 913 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 914 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 915 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 916 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 917 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 918 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 919 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 920 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 921 }
Pokitto 46:e7e438368e16 922
Pokitto 46:e7e438368e16 923 setDRAMptr(x+3, scanlineMinY);
Pokitto 46:e7e438368e16 924 for (uint8_t s=scanlineMinY;s<=scanlineMaxY;) {
Pokitto 46:e7e438368e16 925 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 926 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 927 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 928 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 929 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 930 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 931 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 932 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 933 }
Pokitto 46:e7e438368e16 934 }
Pokitto 46:e7e438368e16 935 }
Pokitto 46:e7e438368e16 936
Pokitto 46:e7e438368e16 937 // Update old x and y for the sprites
Pokitto 46:e7e438368e16 938 if (sprites != NULL) {
Pokitto 46:e7e438368e16 939 for (int sprindex = 0; sprindex < spriteCount; sprindex++) {
Pokitto 46:e7e438368e16 940 sprites[sprindex].oldx = sprites[sprindex].x;
Pokitto 46:e7e438368e16 941 sprites[sprindex].oldy = sprites[sprindex].y;
Pokitto 46:e7e438368e16 942 }
Pokitto 46:e7e438368e16 943 }
Pokitto 46:e7e438368e16 944
Pokitto 46:e7e438368e16 945 #ifdef POK_SIM
Pokitto 46:e7e438368e16 946 simulator.refreshDisplay();
Pokitto 46:e7e438368e16 947 #endif
Pokitto 46:e7e438368e16 948 }
Pokitto 46:e7e438368e16 949
Pokitto 51:113b1d84c34f 950
Pokitto 51:113b1d84c34f 951 #define MODE2_INNER_LOOP_B \
Pokitto 51:113b1d84c34f 952 " ldm %[scanline]!, {%[c]}" "\n" \
Pokitto 51:113b1d84c34f 953 " str %[c], [%[LCD], 0]" "\n" \
Pokitto 51:113b1d84c34f 954 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 955 " movs %[c], 252" "\n" \
Pokitto 51:113b1d84c34f 956 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 957 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 958 " subs %[x], 1" "\n" \
Pokitto 51:113b1d84c34f 959 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 960
Pokitto 51:113b1d84c34f 961
Pokitto 51:113b1d84c34f 962 void Pokitto::lcdRefreshMode2(uint8_t * scrbuf, uint16_t* paletteptr ) {
Pokitto 51:113b1d84c34f 963 uint32_t x,y,byte,c,t=1<<12;
Pokitto 51:113b1d84c34f 964 uint32_t scanline[110];
Pokitto 51:113b1d84c34f 965
Pokitto 51:113b1d84c34f 966 write_command(0x03); write_data(0x1038);
Pokitto 51:113b1d84c34f 967 write_command(0x20); // Horizontal DRAM Address
Pokitto 51:113b1d84c34f 968 write_data(0); // 0
Pokitto 51:113b1d84c34f 969 write_command(0x21); // Vertical DRAM Address
Pokitto 51:113b1d84c34f 970 write_data(1);
Pokitto 51:113b1d84c34f 971 write_command(0x22); // write data to DRAM
Pokitto 51:113b1d84c34f 972 CLR_CS_SET_CD_RD_WR;
Pokitto 51:113b1d84c34f 973 SET_MASK_P2;
Pokitto 51:113b1d84c34f 974
Pokitto 51:113b1d84c34f 975 #ifndef __ARMCC_VERSION
Pokitto 51:113b1d84c34f 976 asm volatile(
Pokitto 51:113b1d84c34f 977 ".syntax unified" "\n"
Pokitto 51:113b1d84c34f 978
Pokitto 51:113b1d84c34f 979 "mov r10, %[scanline]" "\n"
Pokitto 51:113b1d84c34f 980 "mov r11, %[t]" "\n"
Pokitto 51:113b1d84c34f 981
Pokitto 51:113b1d84c34f 982 "mode2OuterLoop:" "\n"
Pokitto 51:113b1d84c34f 983
Pokitto 51:113b1d84c34f 984 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 985 "mode2InnerLoopA:"
Pokitto 51:113b1d84c34f 986
Pokitto 51:113b1d84c34f 987
Pokitto 51:113b1d84c34f 988 " ldrb %[byte], [%[scrbuf],0]" "\n"
Pokitto 51:113b1d84c34f 989 " lsrs %[c], %[byte], 4" "\n"
Pokitto 51:113b1d84c34f 990
Pokitto 51:113b1d84c34f 991 " movs %[t], 15" "\n"
Pokitto 51:113b1d84c34f 992 " ands %[byte], %[t]" "\n"
Pokitto 51:113b1d84c34f 993
Pokitto 51:113b1d84c34f 994 " lsls %[c], 1" "\n"
Pokitto 51:113b1d84c34f 995 " ldrh %[t], [%[paletteptr], %[c]]" "\n"
Pokitto 51:113b1d84c34f 996 " lsls %[t], %[t], 3" "\n"
Pokitto 51:113b1d84c34f 997 " str %[t], [%[LCD], 0]" "\n"
Pokitto 51:113b1d84c34f 998 " mov %[c], r11" "\n"
Pokitto 51:113b1d84c34f 999 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1000 " stm %[scanline]!, {%[t]}" "\n"
Pokitto 51:113b1d84c34f 1001 " movs %[t], 252" "\n"
Pokitto 51:113b1d84c34f 1002 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1003 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1004 " lsls %[byte], %[byte], 1" "\n"
Pokitto 51:113b1d84c34f 1005 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 46:e7e438368e16 1006
Pokitto 51:113b1d84c34f 1007 " ldrh %[t], [%[paletteptr], %[byte]]" "\n"
Pokitto 51:113b1d84c34f 1008 " lsls %[t], %[t], 3" "\n"
Pokitto 51:113b1d84c34f 1009 " str %[t], [%[LCD], 0]" "\n"
Pokitto 51:113b1d84c34f 1010 " mov %[c], r11" "\n"
Pokitto 51:113b1d84c34f 1011 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1012 " stm %[scanline]!, {%[t]}" "\n"
Pokitto 51:113b1d84c34f 1013 " movs %[t], 252" "\n"
Pokitto 51:113b1d84c34f 1014 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1015 " str %[c], [%[LCD], 124]" "\n"
Pokitto 51:113b1d84c34f 1016 " adds %[scrbuf], %[scrbuf], 1" "\n"
Pokitto 51:113b1d84c34f 1017 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1018
Pokitto 51:113b1d84c34f 1019 " subs %[x], 2" "\n"
Pokitto 51:113b1d84c34f 1020 " bne mode2InnerLoopA" "\n"
Pokitto 46:e7e438368e16 1021
Pokitto 51:113b1d84c34f 1022 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1023 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1024 "mov %[t], r11" "\n"
Pokitto 51:113b1d84c34f 1025 "mode2InnerLoopB:"
Pokitto 51:113b1d84c34f 1026 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1027 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1028 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1029 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1030 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1031 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1032 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1033 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1034 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1035 MODE2_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1036 " bne mode2InnerLoopB" "\n"
Pokitto 51:113b1d84c34f 1037
Pokitto 51:113b1d84c34f 1038 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1039 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1040 "movs %[c], 88" "\n"
Pokitto 51:113b1d84c34f 1041 "add %[y], %[t]" "\n" // y++... derpy, but it's the outer loop
Pokitto 51:113b1d84c34f 1042 "cmp %[y], %[c]" "\n"
Pokitto 51:113b1d84c34f 1043 "bne mode2OuterLoop" "\n" // if y != 88, loop
Pokitto 51:113b1d84c34f 1044
Pokitto 51:113b1d84c34f 1045 : // outputs
Pokitto 51:113b1d84c34f 1046 [c]"+l" (c),
Pokitto 51:113b1d84c34f 1047 [t]"+l" (t),
Pokitto 51:113b1d84c34f 1048 [x]"+l" (x),
Pokitto 51:113b1d84c34f 1049 [y]"+h" (y), // +:Read-Write l:lower (0-7) register
Pokitto 51:113b1d84c34f 1050 [scrbuf]"+l" (scrbuf)
Pokitto 51:113b1d84c34f 1051
Pokitto 51:113b1d84c34f 1052 : // inputs
Pokitto 51:113b1d84c34f 1053 [LCD]"l" (0xA0002188),
Pokitto 51:113b1d84c34f 1054 [scanline]"l" (scanline),
Pokitto 51:113b1d84c34f 1055 [paletteptr]"l" (paletteptr),
Pokitto 51:113b1d84c34f 1056 [byte]"l" (byte)
Pokitto 51:113b1d84c34f 1057 : // clobbers
Pokitto 51:113b1d84c34f 1058 "cc", "r10", "r11"
Pokitto 51:113b1d84c34f 1059 );
Pokitto 51:113b1d84c34f 1060
Pokitto 51:113b1d84c34f 1061
Pokitto 51:113b1d84c34f 1062 #else
Pokitto 51:113b1d84c34f 1063 uint8_t* d = scrbuf;// point to beginning of line in data
Pokitto 51:113b1d84c34f 1064
Pokitto 51:113b1d84c34f 1065 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 51:113b1d84c34f 1066 setDRAMptr(0, 8);
Pokitto 51:113b1d84c34f 1067 wait_us(200); // Add wait to compensate skipping of 8 lines. Makes FPS counter to show the correct value.
Pokitto 51:113b1d84c34f 1068 for(y=4;y<88;y++)
Pokitto 51:113b1d84c34f 1069 #else
Pokitto 51:113b1d84c34f 1070 for(y=0;y<88;y++)
Pokitto 51:113b1d84c34f 1071 #endif
Pokitto 46:e7e438368e16 1072 {
Pokitto 51:113b1d84c34f 1073
Pokitto 51:113b1d84c34f 1074
Pokitto 46:e7e438368e16 1075 uint8_t s=0;
Pokitto 51:113b1d84c34f 1076 for(x=0;x<110;x+=2)
Pokitto 46:e7e438368e16 1077 {
Pokitto 51:113b1d84c34f 1078 uint8_t t = *d++;
Pokitto 51:113b1d84c34f 1079 uint32_t color;
Pokitto 51:113b1d84c34f 1080 color = uint32_t(paletteptr[t>>4])<<3;
Pokitto 51:113b1d84c34f 1081 scanline[s]=*LCD=color;TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1082 color = uint32_t(paletteptr[t&0xF])<<3;
Pokitto 51:113b1d84c34f 1083 scanline[s]=*LCD=color;TGL_WR_OP(s++);TGL_WR;
Pokitto 46:e7e438368e16 1084 }
Pokitto 46:e7e438368e16 1085
Pokitto 51:113b1d84c34f 1086 s=0;
Pokitto 51:113b1d84c34f 1087 for (s=0;s<110;) {
Pokitto 51:113b1d84c34f 1088 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1089 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1090 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1091 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1092 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1093 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1094 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
Pokitto 51:113b1d84c34f 1095 *LCD = (scanline[s]);TGL_WR_OP(s++);TGL_WR;
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 46:e7e438368e16 1098 }
Pokitto 46:e7e438368e16 1099
Pokitto 46:e7e438368e16 1100 }
Pokitto 51:113b1d84c34f 1101 #endif
Pokitto 51:113b1d84c34f 1102
Pokitto 51:113b1d84c34f 1103 CLR_MASK_P2;
Pokitto 46:e7e438368e16 1104 }
Pokitto 46:e7e438368e16 1105
Pokitto 46:e7e438368e16 1106 void Pokitto::lcdRefreshMode3(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1107 uint16_t x,y;
Pokitto 46:e7e438368e16 1108 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 46:e7e438368e16 1109 uint8_t *d;
Pokitto 46:e7e438368e16 1110
Pokitto 46:e7e438368e16 1111 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1112 write_data(0); // 0
Pokitto 46:e7e438368e16 1113 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1114 write_data(0);
Pokitto 46:e7e438368e16 1115 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1116 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1117
Pokitto 46:e7e438368e16 1118 for(x=0;x<220;x+=2)
Pokitto 46:e7e438368e16 1119 {
Pokitto 46:e7e438368e16 1120 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 46:e7e438368e16 1121 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1122 uint8_t s=0;
Pokitto 46:e7e438368e16 1123 for(y=0;y<176;y++)
Pokitto 46:e7e438368e16 1124 {
Pokitto 46:e7e438368e16 1125 uint8_t t = *d >> 4; // higher nibble
Pokitto 46:e7e438368e16 1126 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 46:e7e438368e16 1127 /** higher nibble = left pixel in pixel pair **/
Pokitto 46:e7e438368e16 1128 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 1129 scanline[1][s++] = paletteptr[t2];
Pokitto 46:e7e438368e16 1130 /** testing only **/
Pokitto 46:e7e438368e16 1131 //scanline[0][s] = 0xFFFF*(s&1);
Pokitto 46:e7e438368e16 1132 //scanline[1][s] = 0xFFFF*(!(s&1));
Pokitto 46:e7e438368e16 1133 //s++;
Pokitto 46:e7e438368e16 1134 /** until here **/
Pokitto 46:e7e438368e16 1135 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 1136 }
Pokitto 46:e7e438368e16 1137 s=0;
Pokitto 46:e7e438368e16 1138 /** draw scanlines **/
Pokitto 46:e7e438368e16 1139 /** leftmost scanline**/
Pokitto 46:e7e438368e16 1140
Pokitto 46:e7e438368e16 1141 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1142 if (x<8) continue;
Pokitto 46:e7e438368e16 1143 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 1144 #endif
Pokitto 46:e7e438368e16 1145
Pokitto 46:e7e438368e16 1146 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 1147 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1148 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1149 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1150 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1151 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1152 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1153 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1154 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1155 }
Pokitto 46:e7e438368e16 1156
Pokitto 46:e7e438368e16 1157 /** rightmost scanline**/
Pokitto 46:e7e438368e16 1158 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1159 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 1160 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1161 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1162 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1163 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1164 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1165 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1166 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1167 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1168 }
Pokitto 46:e7e438368e16 1169 }
Pokitto 46:e7e438368e16 1170 }
Pokitto 46:e7e438368e16 1171
Pokitto 46:e7e438368e16 1172 void Pokitto::lcdRefreshGB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1173 uint16_t x,y;
Pokitto 46:e7e438368e16 1174 uint16_t scanline[48];
Pokitto 46:e7e438368e16 1175 uint8_t * d;
Pokitto 46:e7e438368e16 1176
Pokitto 46:e7e438368e16 1177 #if POK_STRETCH
Pokitto 46:e7e438368e16 1178 //uint16_t xptr = 8;
Pokitto 46:e7e438368e16 1179 #else
Pokitto 46:e7e438368e16 1180 //xptr = 26;
Pokitto 46:e7e438368e16 1181 #endif
Pokitto 46:e7e438368e16 1182
Pokitto 46:e7e438368e16 1183 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1184 write_data(0); // 0
Pokitto 46:e7e438368e16 1185 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1186 write_data(0);
Pokitto 46:e7e438368e16 1187 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1188 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1189
Pokitto 46:e7e438368e16 1190 /** draw border **/
Pokitto 46:e7e438368e16 1191 for (int s=0;s<5*176;) {
Pokitto 46:e7e438368e16 1192 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 46:e7e438368e16 1193 }
Pokitto 46:e7e438368e16 1194
Pokitto 46:e7e438368e16 1195 for(x=0;x<84;x++)
Pokitto 46:e7e438368e16 1196 {
Pokitto 46:e7e438368e16 1197
Pokitto 46:e7e438368e16 1198 d = scrbuf + x;// point to beginning of line in data
Pokitto 46:e7e438368e16 1199
Pokitto 46:e7e438368e16 1200 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1201 uint8_t s=0;
Pokitto 46:e7e438368e16 1202 for(y=0;y<6;y++)
Pokitto 46:e7e438368e16 1203 {
Pokitto 46:e7e438368e16 1204 uint8_t t = *d;
Pokitto 46:e7e438368e16 1205 #if POK_COLORDEPTH > 1
Pokitto 46:e7e438368e16 1206 uint8_t t2 = *(d+504);
Pokitto 46:e7e438368e16 1207 #endif
Pokitto 46:e7e438368e16 1208 #if POK_COLORDEPTH > 2
Pokitto 46:e7e438368e16 1209 uint8_t t3 = *(d+504+504);
Pokitto 46:e7e438368e16 1210 #endif
Pokitto 46:e7e438368e16 1211 #if POK_COLORDEPTH > 3
Pokitto 46:e7e438368e16 1212 uint8_t t4 = *(d+504+504+504);
Pokitto 46:e7e438368e16 1213 #endif
Pokitto 46:e7e438368e16 1214 uint8_t paletteindex = 0;
Pokitto 46:e7e438368e16 1215
Pokitto 46:e7e438368e16 1216 /** bit 1 **/
Pokitto 46:e7e438368e16 1217 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1218 paletteindex = (t & 0x1);
Pokitto 46:e7e438368e16 1219 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1220 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 46:e7e438368e16 1221 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1222 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 46:e7e438368e16 1223 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1224 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 46:e7e438368e16 1225 #endif
Pokitto 46:e7e438368e16 1226 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1227
Pokitto 46:e7e438368e16 1228 /** bit 2 **/
Pokitto 46:e7e438368e16 1229 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1230 paletteindex = (t & 0x2)>>1;
Pokitto 46:e7e438368e16 1231 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1232 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 46:e7e438368e16 1233 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1234 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 46:e7e438368e16 1235 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1236 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 46:e7e438368e16 1237 #endif
Pokitto 46:e7e438368e16 1238 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1239
Pokitto 46:e7e438368e16 1240 /** bit 3 **/
Pokitto 46:e7e438368e16 1241 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1242 paletteindex = (t & 0x4)>>2;
Pokitto 46:e7e438368e16 1243 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1244 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 46:e7e438368e16 1245 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1246 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 46:e7e438368e16 1247 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1248 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 46:e7e438368e16 1249 #endif
Pokitto 46:e7e438368e16 1250 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1251
Pokitto 46:e7e438368e16 1252 /** bit 4 **/
Pokitto 46:e7e438368e16 1253 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1254 paletteindex = (t & 0x8)>>3;
Pokitto 46:e7e438368e16 1255 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1256 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 46:e7e438368e16 1257 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1258 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 46:e7e438368e16 1259 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1260 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 46:e7e438368e16 1261 #endif
Pokitto 46:e7e438368e16 1262 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1263
Pokitto 46:e7e438368e16 1264 /** bit 5 **/
Pokitto 46:e7e438368e16 1265 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1266 paletteindex = (t & 0x10)>>4;
Pokitto 46:e7e438368e16 1267 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1268 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 46:e7e438368e16 1269 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1270 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 46:e7e438368e16 1271 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1272 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 46:e7e438368e16 1273 #endif
Pokitto 46:e7e438368e16 1274 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1275
Pokitto 46:e7e438368e16 1276 /** bit 6 **/
Pokitto 46:e7e438368e16 1277 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1278 paletteindex = (t & 0x20)>>5;
Pokitto 46:e7e438368e16 1279 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1280 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 46:e7e438368e16 1281 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1282 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 46:e7e438368e16 1283 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1284 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 46:e7e438368e16 1285 #endif
Pokitto 46:e7e438368e16 1286 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1287
Pokitto 46:e7e438368e16 1288 /** bit 7 **/
Pokitto 46:e7e438368e16 1289 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1290 paletteindex = (t & 0x40)>>6;
Pokitto 46:e7e438368e16 1291 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1292 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 46:e7e438368e16 1293 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1294 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 46:e7e438368e16 1295 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1296 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 46:e7e438368e16 1297 #endif
Pokitto 46:e7e438368e16 1298 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1299
Pokitto 46:e7e438368e16 1300 /** bit 8 **/
Pokitto 46:e7e438368e16 1301 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1302 paletteindex = (t & 0x80)>>7;
Pokitto 46:e7e438368e16 1303 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1304 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 46:e7e438368e16 1305 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1306 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 46:e7e438368e16 1307 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1308 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 46:e7e438368e16 1309 #endif
Pokitto 46:e7e438368e16 1310 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1311
Pokitto 46:e7e438368e16 1312 d+=84; // jump to byte directly below
Pokitto 46:e7e438368e16 1313 }
Pokitto 46:e7e438368e16 1314
Pokitto 46:e7e438368e16 1315
Pokitto 46:e7e438368e16 1316 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1317 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1318 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1319 write_data(xptr++);
Pokitto 46:e7e438368e16 1320 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1321 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1322 /** draw border **/
Pokitto 46:e7e438368e16 1323 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 1324
Pokitto 46:e7e438368e16 1325 s=0;
Pokitto 46:e7e438368e16 1326
Pokitto 46:e7e438368e16 1327 /** draw scanlines **/
Pokitto 46:e7e438368e16 1328 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1329 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1330 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1331 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1332 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1333 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1334 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1335 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1336 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1337 }
Pokitto 46:e7e438368e16 1338 /** draw border **/
Pokitto 46:e7e438368e16 1339 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 1340
Pokitto 46:e7e438368e16 1341
Pokitto 46:e7e438368e16 1342 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1343 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1344 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1345 write_data(xptr++);
Pokitto 46:e7e438368e16 1346 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1347 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1348 /** draw border **/
Pokitto 46:e7e438368e16 1349 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 1350
Pokitto 46:e7e438368e16 1351 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1352 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1353 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1354 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1355 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1356 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1357 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1358 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1359 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1360 }
Pokitto 46:e7e438368e16 1361
Pokitto 46:e7e438368e16 1362 /** draw border **/
Pokitto 46:e7e438368e16 1363 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 1364
Pokitto 46:e7e438368e16 1365
Pokitto 46:e7e438368e16 1366 #if POK_STRETCH
Pokitto 46:e7e438368e16 1367 //if (x>16 && x<68)
Pokitto 46:e7e438368e16 1368 if (x&2)// && x&2)
Pokitto 46:e7e438368e16 1369 {
Pokitto 46:e7e438368e16 1370 /*write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1371 write_data(0x10); // 0
Pokitto 46:e7e438368e16 1372 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1373 write_data(xptr++);
Pokitto 46:e7e438368e16 1374 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1375 CLR_CS_SET_CD_RD_WR;*/
Pokitto 46:e7e438368e16 1376 /** draw border **/
Pokitto 46:e7e438368e16 1377 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 1378
Pokitto 46:e7e438368e16 1379
Pokitto 46:e7e438368e16 1380 for (s=0;s<48;) {
Pokitto 46:e7e438368e16 1381 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1382 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1383 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1384 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1385 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1386 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1387 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1388 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1389 }
Pokitto 46:e7e438368e16 1390
Pokitto 46:e7e438368e16 1391 /** draw border **/
Pokitto 46:e7e438368e16 1392 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 1393
Pokitto 46:e7e438368e16 1394 }
Pokitto 46:e7e438368e16 1395 #endif
Pokitto 46:e7e438368e16 1396 }
Pokitto 46:e7e438368e16 1397 /** draw border **/
Pokitto 46:e7e438368e16 1398 for (int s=0;s<5*176;) {
Pokitto 46:e7e438368e16 1399 setup_data_16(COLOR_BLACK);CLR_WR;SET_WR;s++;
Pokitto 46:e7e438368e16 1400 }
Pokitto 46:e7e438368e16 1401 }
Pokitto 46:e7e438368e16 1402
Pokitto 46:e7e438368e16 1403
Pokitto 46:e7e438368e16 1404 void Pokitto::lcdRefreshAB(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1405 uint16_t x,y;
Pokitto 46:e7e438368e16 1406 uint16_t scanline[64];
Pokitto 46:e7e438368e16 1407 uint8_t *d;
Pokitto 46:e7e438368e16 1408 //lcdClear();
Pokitto 46:e7e438368e16 1409 #if POK_STRETCH
Pokitto 46:e7e438368e16 1410 uint16_t xptr = 14;
Pokitto 46:e7e438368e16 1411 uint8_t yoffset = 24;
Pokitto 46:e7e438368e16 1412 #else
Pokitto 46:e7e438368e16 1413 uint16_t xptr = 0;
Pokitto 46:e7e438368e16 1414 uint8_t yoffset = 0;
Pokitto 46:e7e438368e16 1415 #endif
Pokitto 46:e7e438368e16 1416
Pokitto 46:e7e438368e16 1417 for(x=0;x<128;x++)
Pokitto 46:e7e438368e16 1418 {
Pokitto 46:e7e438368e16 1419 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1420 write_data(yoffset); // 0
Pokitto 46:e7e438368e16 1421 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1422 write_data(xptr++);
Pokitto 46:e7e438368e16 1423 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1424 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1425 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1426
Pokitto 46:e7e438368e16 1427 d = scrbuf + x;// point to beginning of line in data
Pokitto 46:e7e438368e16 1428
Pokitto 46:e7e438368e16 1429 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1430 uint8_t s=0;
Pokitto 46:e7e438368e16 1431 for(y=0;y<8;y++)
Pokitto 46:e7e438368e16 1432 {
Pokitto 46:e7e438368e16 1433 uint8_t t = *d;
Pokitto 46:e7e438368e16 1434 #if POK_COLORDEPTH > 1
Pokitto 46:e7e438368e16 1435 uint8_t t2 = *(d+AB_JUMP);
Pokitto 46:e7e438368e16 1436 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1437 #if POK_COLORDEPTH > 2
Pokitto 46:e7e438368e16 1438 uint8_t t3 = *(d+AB_JUMP+AB_JUMP);
Pokitto 46:e7e438368e16 1439 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1440 #if POK_COLORDEPTH > 3
Pokitto 46:e7e438368e16 1441 uint8_t t4 = *(d+AB_JUMP+AB_JUMP+AB_JUMP);
Pokitto 46:e7e438368e16 1442 #endif // POK_COLORDEPTH
Pokitto 46:e7e438368e16 1443 uint8_t paletteindex = 0;
Pokitto 46:e7e438368e16 1444
Pokitto 46:e7e438368e16 1445 /** bit 1 **/
Pokitto 46:e7e438368e16 1446 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1447 paletteindex = (t & 0x1);
Pokitto 46:e7e438368e16 1448 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1449 paletteindex = ((t & 0x1)) | ((t2 & 0x01)<<1);
Pokitto 46:e7e438368e16 1450 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1451 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2);
Pokitto 46:e7e438368e16 1452 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1453 paletteindex = (t & 0x1) | ((t2 & 0x1)<<1) | ((t3 & 0x1)<<2) | ((t4 & 0x1)<<3);
Pokitto 46:e7e438368e16 1454 #endif
Pokitto 46:e7e438368e16 1455 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1456
Pokitto 46:e7e438368e16 1457 /** bit 2 **/
Pokitto 46:e7e438368e16 1458 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1459 paletteindex = (t & 0x2)>>1;
Pokitto 46:e7e438368e16 1460 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1461 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x02));
Pokitto 46:e7e438368e16 1462 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1463 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1);
Pokitto 46:e7e438368e16 1464 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1465 paletteindex = ((t & 0x2)>>1) | ((t2 & 0x2)) | ((t3 & 0x2)<<1) | ((t4 & 0x2)<<2);
Pokitto 46:e7e438368e16 1466 #endif
Pokitto 46:e7e438368e16 1467 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1468
Pokitto 46:e7e438368e16 1469 /** bit 3 **/
Pokitto 46:e7e438368e16 1470 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1471 paletteindex = (t & 0x4)>>2;
Pokitto 46:e7e438368e16 1472 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1473 paletteindex = ((t & 4)>>2) | ((t2 & 0x04)>>1);
Pokitto 46:e7e438368e16 1474 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1475 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4);
Pokitto 46:e7e438368e16 1476 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1477 paletteindex = ((t & 0x4)>>2) | ((t2 & 0x4)>>1) | (t3 & 0x4) | ((t4 & 0x4)<<1);
Pokitto 46:e7e438368e16 1478 #endif
Pokitto 46:e7e438368e16 1479 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1480
Pokitto 46:e7e438368e16 1481 /** bit 4 **/
Pokitto 46:e7e438368e16 1482 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1483 paletteindex = (t & 0x8)>>3;
Pokitto 46:e7e438368e16 1484 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1485 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x08)>>2);
Pokitto 46:e7e438368e16 1486 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1487 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1);
Pokitto 46:e7e438368e16 1488 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1489 paletteindex = ((t & 0x8)>>3) | ((t2 & 0x8)>>2) | ((t3 & 0x8)>>1) | (t4 & 0x8);
Pokitto 46:e7e438368e16 1490 #endif
Pokitto 46:e7e438368e16 1491 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1492
Pokitto 46:e7e438368e16 1493 /** bit 5 **/
Pokitto 46:e7e438368e16 1494 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1495 paletteindex = (t & 0x10)>>4;
Pokitto 46:e7e438368e16 1496 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1497 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3);
Pokitto 46:e7e438368e16 1498 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1499 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2);
Pokitto 46:e7e438368e16 1500 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1501 paletteindex = ((t & 0x10)>>4) | ((t2 & 0x10)>>3) | ((t3 & 0x10)>>2) | ((t4 & 0x10)>>1);
Pokitto 46:e7e438368e16 1502 #endif
Pokitto 46:e7e438368e16 1503 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1504
Pokitto 46:e7e438368e16 1505 /** bit 6 **/
Pokitto 46:e7e438368e16 1506 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1507 paletteindex = (t & 0x20)>>5;
Pokitto 46:e7e438368e16 1508 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1509 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4);
Pokitto 46:e7e438368e16 1510 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1511 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3);
Pokitto 46:e7e438368e16 1512 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1513 paletteindex = ((t & 0x20)>>5) | ((t2 & 0x20)>>4) | ((t3 & 0x20)>>3) | ((t4 & 0x20)>>2);
Pokitto 46:e7e438368e16 1514 #endif
Pokitto 46:e7e438368e16 1515 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1516
Pokitto 46:e7e438368e16 1517 /** bit 7 **/
Pokitto 46:e7e438368e16 1518 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1519 paletteindex = (t & 0x40)>>6;
Pokitto 46:e7e438368e16 1520 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1521 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5);
Pokitto 46:e7e438368e16 1522 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1523 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) ;
Pokitto 46:e7e438368e16 1524 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1525 paletteindex = ((t & 0x40)>>6) | ((t2 & 0x40)>>5) | ((t3 & 0x40)>>4) | ((t4 & 0x40)>>3);
Pokitto 46:e7e438368e16 1526 #endif
Pokitto 46:e7e438368e16 1527 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1528
Pokitto 46:e7e438368e16 1529 /** bit 8 **/
Pokitto 46:e7e438368e16 1530 #if POK_COLORDEPTH == 1
Pokitto 46:e7e438368e16 1531 paletteindex = (t & 0x80)>>7;
Pokitto 46:e7e438368e16 1532 #elif POK_COLORDEPTH == 2
Pokitto 46:e7e438368e16 1533 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6);
Pokitto 46:e7e438368e16 1534 #elif POK_COLORDEPTH == 3
Pokitto 46:e7e438368e16 1535 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5);
Pokitto 46:e7e438368e16 1536 #elif POK_COLORDEPTH == 4
Pokitto 46:e7e438368e16 1537 paletteindex = ((t & 0x80)>>7) | ((t2 & 0x80)>>6) | ((t3 & 0x80)>>5) | ((t4 & 0x80)>>4);
Pokitto 46:e7e438368e16 1538 #endif
Pokitto 46:e7e438368e16 1539 scanline[s++] = paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1540
Pokitto 46:e7e438368e16 1541 d+=128; // jump to byte directly below
Pokitto 46:e7e438368e16 1542 }
Pokitto 46:e7e438368e16 1543
Pokitto 46:e7e438368e16 1544 s=0;
Pokitto 46:e7e438368e16 1545
Pokitto 46:e7e438368e16 1546 /** draw scanlines **/
Pokitto 46:e7e438368e16 1547 for (s=0;s<64;) {
Pokitto 46:e7e438368e16 1548 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1549 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1550 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1551 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1552 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1553 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1554 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1555 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1556 }
Pokitto 46:e7e438368e16 1557
Pokitto 46:e7e438368e16 1558 #if POK_STRETCH
Pokitto 46:e7e438368e16 1559 if (x&1) {
Pokitto 46:e7e438368e16 1560 write_command(0x20); // Horizontal DRAM Address
Pokitto 46:e7e438368e16 1561 write_data(yoffset); // 0
Pokitto 46:e7e438368e16 1562 write_command(0x21); // Vertical DRAM Address
Pokitto 46:e7e438368e16 1563 write_data(xptr++);
Pokitto 46:e7e438368e16 1564 write_command(0x22); // write data to DRAM
Pokitto 46:e7e438368e16 1565 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1566 //setDRAMptr(xptr++,yoffset);
Pokitto 46:e7e438368e16 1567
Pokitto 46:e7e438368e16 1568 for (s=0;s<64;) {
Pokitto 46:e7e438368e16 1569 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1570 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1571 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1572 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1573 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1574 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1575 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1576 setup_data_16(scanline[s++]);CLR_WR;SET_WR;CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1577 }
Pokitto 46:e7e438368e16 1578 }
Pokitto 46:e7e438368e16 1579 #endif
Pokitto 46:e7e438368e16 1580 }
Pokitto 46:e7e438368e16 1581 }
Pokitto 46:e7e438368e16 1582
Pokitto 46:e7e438368e16 1583 void Pokitto::lcdRefreshModeGBC(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1584 uint16_t x,y,xptr;
Pokitto 46:e7e438368e16 1585 uint16_t scanline[4][144]; // read 4 half-nibbles = 4 pixels at a time
Pokitto 46:e7e438368e16 1586 uint8_t *d, yoffset=0;
Pokitto 46:e7e438368e16 1587
Pokitto 46:e7e438368e16 1588 xptr = 0;
Pokitto 46:e7e438368e16 1589 setDRAMptr(xptr,yoffset);
Pokitto 46:e7e438368e16 1590
Pokitto 46:e7e438368e16 1591
Pokitto 46:e7e438368e16 1592 for(x=0;x<160;x+=4)
Pokitto 46:e7e438368e16 1593 {
Pokitto 46:e7e438368e16 1594 d = scrbuf+(x>>2);// point to beginning of line in data
Pokitto 46:e7e438368e16 1595 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1596 uint8_t s=0;
Pokitto 46:e7e438368e16 1597 for(y=0;y<144;y++)
Pokitto 46:e7e438368e16 1598 {
Pokitto 46:e7e438368e16 1599 uint8_t tdata = *d;
Pokitto 46:e7e438368e16 1600 uint8_t t4 = tdata & 0x03; tdata >>= 2;// lowest half-nibble
Pokitto 46:e7e438368e16 1601 uint8_t t3 = tdata & 0x03; tdata >>= 2;// second lowest half-nibble
Pokitto 46:e7e438368e16 1602 uint8_t t2 = tdata & 0x03; tdata >>= 2;// second highest half-nibble
Pokitto 46:e7e438368e16 1603 uint8_t t = tdata & 0x03;// highest half-nibble
Pokitto 46:e7e438368e16 1604
Pokitto 46:e7e438368e16 1605 /** put nibble values in the scanlines **/
Pokitto 46:e7e438368e16 1606
Pokitto 46:e7e438368e16 1607 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 1608 scanline[1][s] = paletteptr[t2];
Pokitto 46:e7e438368e16 1609 scanline[2][s] = paletteptr[t3];
Pokitto 46:e7e438368e16 1610 scanline[3][s++] = paletteptr[t4];
Pokitto 46:e7e438368e16 1611
Pokitto 46:e7e438368e16 1612 d+=160/4; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 1613 }
Pokitto 46:e7e438368e16 1614
Pokitto 46:e7e438368e16 1615 s=0;
Pokitto 46:e7e438368e16 1616 /** draw scanlines **/
Pokitto 46:e7e438368e16 1617 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1618 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1619 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1620 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1621 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1622 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1623 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1624 }
Pokitto 46:e7e438368e16 1625 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1626 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1627 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1628 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1629 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1630 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1631 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1632 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1633 }
Pokitto 46:e7e438368e16 1634 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1635 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1636 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1637 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1638 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1639 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1640 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1641 setup_data_16(scanline[2][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1642 }
Pokitto 46:e7e438368e16 1643 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1644 for (s=0;s<144;) {
Pokitto 46:e7e438368e16 1645 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1646 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1647 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1648 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1649 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1650 setup_data_16(scanline[3][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1651 }
Pokitto 46:e7e438368e16 1652 setDRAMptr(++xptr,yoffset);
Pokitto 46:e7e438368e16 1653 }
Pokitto 46:e7e438368e16 1654 }
Pokitto 46:e7e438368e16 1655
Pokitto 46:e7e438368e16 1656
Pokitto 46:e7e438368e16 1657 void Pokitto::lcdRefreshT1(uint8_t* tilebuf, uint8_t* tilecolorbuf, uint8_t* tileset, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1658 #ifdef POK_TILEMODE
Pokitto 46:e7e438368e16 1659 uint16_t x,y,data,xptr;
Pokitto 46:e7e438368e16 1660 uint16_t scanline[176];
Pokitto 46:e7e438368e16 1661 uint8_t yoffset=0, tilebyte, tileindex, tilex=0, tiley=0,xcount;
Pokitto 46:e7e438368e16 1662
Pokitto 46:e7e438368e16 1663
Pokitto 46:e7e438368e16 1664 if (!tileset) return;
Pokitto 46:e7e438368e16 1665
Pokitto 46:e7e438368e16 1666 #if LCDWIDTH < POK_LCD_W
Pokitto 46:e7e438368e16 1667 xptr = (POK_LCD_W-LCDWIDTH)/2;
Pokitto 46:e7e438368e16 1668 #else
Pokitto 46:e7e438368e16 1669 xptr = 0;
Pokitto 46:e7e438368e16 1670 #endif
Pokitto 46:e7e438368e16 1671 #if LCDHEIGHT < POK_LCD_H
Pokitto 46:e7e438368e16 1672 yoffset = (POK_LCD_H-LCDHEIGHT)/2;
Pokitto 46:e7e438368e16 1673 #else
Pokitto 46:e7e438368e16 1674 yoffset = 0;
Pokitto 46:e7e438368e16 1675 #endif
Pokitto 46:e7e438368e16 1676
Pokitto 46:e7e438368e16 1677 for(x=0, xcount=0 ;x<LCDWIDTH;x++,xcount++) // loop through vertical columns
Pokitto 46:e7e438368e16 1678 {
Pokitto 46:e7e438368e16 1679 setDRAMptr(xptr++,yoffset); //point to VRAM
Pokitto 46:e7e438368e16 1680
Pokitto 46:e7e438368e16 1681 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1682 uint8_t s=0, tiley=0;
Pokitto 46:e7e438368e16 1683 //tileindex = tilebuf[tilex*POK_TILES_Y];
Pokitto 46:e7e438368e16 1684 if (xcount==POK_TILE_W) {
Pokitto 46:e7e438368e16 1685 tilex++;
Pokitto 46:e7e438368e16 1686 xcount=0;
Pokitto 46:e7e438368e16 1687 }
Pokitto 46:e7e438368e16 1688
Pokitto 46:e7e438368e16 1689 for(y=0;y<LCDHEIGHT;)
Pokitto 46:e7e438368e16 1690 {
Pokitto 46:e7e438368e16 1691 uint8_t tileval = tilebuf[tilex+tiley*POK_TILES_X]; //get tile number
Pokitto 46:e7e438368e16 1692 uint16_t index = tileval*POK_TILE_W+xcount;
Pokitto 46:e7e438368e16 1693 uint8_t tilebyte = tileset[index]; //get bitmap data
Pokitto 46:e7e438368e16 1694 for (uint8_t ycount=0, bitcount=0; ycount<POK_TILE_H; ycount++, y++, bitcount++) {
Pokitto 46:e7e438368e16 1695 if (bitcount==8) {
Pokitto 46:e7e438368e16 1696 bitcount=0;
Pokitto 46:e7e438368e16 1697 index += 176; //jump to byte below in the tileset bitmap
Pokitto 46:e7e438368e16 1698 tilebyte = tileset[index]; //get bitmap data
Pokitto 46:e7e438368e16 1699 }
Pokitto 46:e7e438368e16 1700 //tilebyte = tile[(tileindex>>4)+*POK_TILE_W]; //tilemaps are 16x16
Pokitto 46:e7e438368e16 1701 //uint8_t paletteindex = ((tilebyte>>(bitcount&0x7)) & 0x1);
Pokitto 46:e7e438368e16 1702 if (!tileval) scanline[s++] = COLOR_MAGENTA*((tilebyte>>bitcount)&0x1);//paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1703 else scanline[s++] = paletteptr[((tilebyte>>bitcount)&0x1)*tileval];//paletteptr[paletteindex];
Pokitto 46:e7e438368e16 1704 }
Pokitto 46:e7e438368e16 1705 tiley++; //move to next tile
Pokitto 46:e7e438368e16 1706 }
Pokitto 46:e7e438368e16 1707 s=0;
Pokitto 46:e7e438368e16 1708
Pokitto 46:e7e438368e16 1709 /** draw scanlines **/
Pokitto 46:e7e438368e16 1710 for (s=0;s<LCDHEIGHT;) {
Pokitto 46:e7e438368e16 1711 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1712 }
Pokitto 46:e7e438368e16 1713 }
Pokitto 46:e7e438368e16 1714 #endif
Pokitto 46:e7e438368e16 1715 }
Pokitto 46:e7e438368e16 1716
Pokitto 51:113b1d84c34f 1717 #define MODE13_INNER_LOOP_A \
Pokitto 51:113b1d84c34f 1718 " ldrb %[t], [%[scrbuf],0]" "\n" \
Pokitto 51:113b1d84c34f 1719 " add %[t], %[t], %[offset]" "\n" \
Pokitto 51:113b1d84c34f 1720 " uxtb %[c], %[t] " "\n" \
Pokitto 51:113b1d84c34f 1721 " lsls %[c], 1" "\n" \
Pokitto 51:113b1d84c34f 1722 " ldrh %[t], [%[paletteptr], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 1723 " lsls %[t], %[t], 3" "\n" \
Pokitto 51:113b1d84c34f 1724 " str %[t], [%[LCD], 0]" "\n" \
Pokitto 51:113b1d84c34f 1725 " mov %[c], r11" "\n" \
Pokitto 51:113b1d84c34f 1726 " str %[c], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1727 " stm %[scanline]!, {%[t]}" "\n" \
Pokitto 51:113b1d84c34f 1728 " movs %[t], 252" "\n" \
Pokitto 51:113b1d84c34f 1729 " str %[c], [%[LCD], %[t]]" "\n" \
Pokitto 51:113b1d84c34f 1730 " str %[c], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1731 " adds %[scrbuf], %[scrbuf], 1" "\n" \
Pokitto 51:113b1d84c34f 1732 " str %[c], [%[LCD], %[t]]" "\n"
Pokitto 51:113b1d84c34f 1733
Pokitto 51:113b1d84c34f 1734 #define MODE13_INNER_LOOP_B \
Pokitto 51:113b1d84c34f 1735 " ldm %[scanline]!, {%[c]}" "\n" \
Pokitto 51:113b1d84c34f 1736 " str %[c], [%[LCD], 0]" "\n" \
Pokitto 51:113b1d84c34f 1737 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1738 " movs %[c], 252" "\n" \
Pokitto 51:113b1d84c34f 1739 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 51:113b1d84c34f 1740 " str %[t], [%[LCD], 124]" "\n" \
Pokitto 51:113b1d84c34f 1741 " subs %[x], 1" "\n" \
Pokitto 51:113b1d84c34f 1742 " str %[t], [%[LCD], %[c]]" "\n" \
Pokitto 46:e7e438368e16 1743
Pokitto 51:113b1d84c34f 1744
Pokitto 51:113b1d84c34f 1745 void Pokitto::lcdRefreshMode13(uint8_t * scrbuf, uint16_t* paletteptr, uint8_t offset){
Pokitto 51:113b1d84c34f 1746 uint32_t scanline[110]; // read two nibbles = pixels at a time
Pokitto 51:113b1d84c34f 1747
Pokitto 51:113b1d84c34f 1748 write_command_16(0x03); write_data_16(0x1038);
Pokitto 51:113b1d84c34f 1749 write_command(0x20); write_data(0);
Pokitto 51:113b1d84c34f 1750 write_command(0x21); write_data(1);
Pokitto 51:113b1d84c34f 1751 write_command(0x22);
Pokitto 51:113b1d84c34f 1752 CLR_CS_SET_CD_RD_WR;
Pokitto 51:113b1d84c34f 1753 SET_MASK_P2;
Pokitto 51:113b1d84c34f 1754
Pokitto 51:113b1d84c34f 1755 uint32_t x, y=0, c, t;
Pokitto 51:113b1d84c34f 1756
Pokitto 51:113b1d84c34f 1757 #ifndef __ARMCC_VERSION
Pokitto 51:113b1d84c34f 1758 asm volatile(
Pokitto 51:113b1d84c34f 1759 ".syntax unified" "\n"
Pokitto 51:113b1d84c34f 1760
Pokitto 51:113b1d84c34f 1761 "mov r10, %[scanline]" "\n"
Pokitto 51:113b1d84c34f 1762
Pokitto 51:113b1d84c34f 1763 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1764 "lsls %[t], %[t], 12" "\n"
Pokitto 51:113b1d84c34f 1765 "mov r11, %[t]" "\n"
Pokitto 51:113b1d84c34f 1766
Pokitto 51:113b1d84c34f 1767 "mode13OuterLoop:" "\n"
Pokitto 51:113b1d84c34f 1768
Pokitto 51:113b1d84c34f 1769 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1770 "mode13InnerLoopA:"
Pokitto 51:113b1d84c34f 1771 MODE13_INNER_LOOP_A
Pokitto 51:113b1d84c34f 1772 MODE13_INNER_LOOP_A
Pokitto 51:113b1d84c34f 1773 " subs %[x], 2" "\n"
Pokitto 51:113b1d84c34f 1774 " bne mode13InnerLoopA" "\n"
Pokitto 46:e7e438368e16 1775
Pokitto 51:113b1d84c34f 1776 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1777 "movs %[x], 110" "\n"
Pokitto 51:113b1d84c34f 1778 "mov %[t], r11" "\n"
Pokitto 51:113b1d84c34f 1779 "mode13InnerLoopB:"
Pokitto 51:113b1d84c34f 1780 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1781 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1782 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1783 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1784 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1785 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1786 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1787 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1788 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1789 MODE13_INNER_LOOP_B
Pokitto 51:113b1d84c34f 1790 " bne mode13InnerLoopB" "\n"
Pokitto 51:113b1d84c34f 1791
Pokitto 51:113b1d84c34f 1792 "mov %[scanline], r10" "\n"
Pokitto 51:113b1d84c34f 1793 "movs %[t], 1" "\n"
Pokitto 51:113b1d84c34f 1794 "movs %[c], 88" "\n"
Pokitto 51:113b1d84c34f 1795 "add %[y], %[t]" "\n" // y++... derpy, but it's the outer loop
Pokitto 51:113b1d84c34f 1796 "cmp %[y], %[c]" "\n"
Pokitto 51:113b1d84c34f 1797 "bne mode13OuterLoop" "\n" // if y != 88, loop
Pokitto 51:113b1d84c34f 1798
Pokitto 51:113b1d84c34f 1799 : // outputs
Pokitto 51:113b1d84c34f 1800 [c]"+l" (c),
Pokitto 51:113b1d84c34f 1801 [t]"+l" (t),
Pokitto 51:113b1d84c34f 1802 [x]"+l" (x),
Pokitto 51:113b1d84c34f 1803 [y]"+h" (y), // +:Read-Write l:lower (0-7) register
Pokitto 51:113b1d84c34f 1804 [scrbuf]"+l" (scrbuf)
Pokitto 51:113b1d84c34f 1805
Pokitto 51:113b1d84c34f 1806 : // inputs
Pokitto 51:113b1d84c34f 1807 [LCD]"l" (0xA0002188),
Pokitto 51:113b1d84c34f 1808 [scanline]"l" (scanline),
Pokitto 51:113b1d84c34f 1809 [paletteptr]"l" (paletteptr),
Pokitto 51:113b1d84c34f 1810 [offset]"l" (offset)
Pokitto 51:113b1d84c34f 1811 : // clobbers
Pokitto 51:113b1d84c34f 1812 "cc", "r10", "r11"
Pokitto 51:113b1d84c34f 1813 );
Pokitto 46:e7e438368e16 1814
Pokitto 51:113b1d84c34f 1815 #else
Pokitto 51:113b1d84c34f 1816 uint8_t* d = scrbuf;// point to beginning of line in data
Pokitto 51:113b1d84c34f 1817 for(y=0;y<88;y++){
Pokitto 51:113b1d84c34f 1818
Pokitto 51:113b1d84c34f 1819 uint32_t* s = scanline;
Pokitto 51:113b1d84c34f 1820
Pokitto 51:113b1d84c34f 1821 for(x=0;x<110;x+=10){
Pokitto 51:113b1d84c34f 1822 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1823 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1824 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1825 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1826 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1827 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1828 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
Pokitto 51:113b1d84c34f 1829 *LCD = *s = paletteptr[(*d + offset)&255]<<3; TGL_WR_OP(s++);TGL_WR_OP(d++);
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 }
Pokitto 51:113b1d84c34f 1833
Pokitto 51:113b1d84c34f 1834 s = scanline;
Pokitto 51:113b1d84c34f 1835 uint32_t c = *s;
Pokitto 51:113b1d84c34f 1836 for(x=0;x<110;x+=10){
Pokitto 51:113b1d84c34f 1837 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1838 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1839 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1840 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1841 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1842 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1843 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
Pokitto 51:113b1d84c34f 1844 *LCD = c; TGL_WR_OP(s++);TGL_WR_OP(c=*s);
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 }
Pokitto 51:113b1d84c34f 1848
Pokitto 51:113b1d84c34f 1849 }
Pokitto 51:113b1d84c34f 1850 #endif
Pokitto 51:113b1d84c34f 1851 }
Pokitto 46:e7e438368e16 1852
Pokitto 46:e7e438368e16 1853 void Pokitto::lcdRefreshMode14(uint8_t * scrbuf, uint16_t* paletteptr) {
Pokitto 46:e7e438368e16 1854 uint16_t x,y,data,xptr;
Pokitto 46:e7e438368e16 1855 uint16_t scanline[176]; uint16_t* scptr;
Pokitto 46:e7e438368e16 1856 uint8_t *d;
Pokitto 46:e7e438368e16 1857
Pokitto 46:e7e438368e16 1858 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 1859 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 1860 write_command(0x22);
Pokitto 46:e7e438368e16 1861 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 1862
Pokitto 46:e7e438368e16 1863 for(x=0;x<220;x++)
Pokitto 46:e7e438368e16 1864 {
Pokitto 46:e7e438368e16 1865 d = scrbuf+x;
Pokitto 46:e7e438368e16 1866 scptr = &scanline[0];
Pokitto 46:e7e438368e16 1867
Pokitto 46:e7e438368e16 1868 /** find colours in one scanline **/
Pokitto 46:e7e438368e16 1869 /*for(y=0;y<22;y++)
Pokitto 46:e7e438368e16 1870 {
Pokitto 46:e7e438368e16 1871
Pokitto 46:e7e438368e16 1872 uint16_t t = *d;
Pokitto 46:e7e438368e16 1873 uint16_t t2 = *(d+POK_BITFRAME);
Pokitto 46:e7e438368e16 1874 uint16_t t3 = *(d+POK_BITFRAME+POK_BITFRAME);
Pokitto 46:e7e438368e16 1875
Pokitto 46:e7e438368e16 1876 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1877 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1878 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1879 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1880
Pokitto 46:e7e438368e16 1881 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1882 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
Pokitto 46:e7e438368e16 1883 *scptr++ = (t & 0x1)*R_MASK | (t2 & 0x1)*G_MASK | (t3 & 0x1)*B_MASK; t >>= 1;t2 >>= 1;t3 >>= 1;
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
Pokitto 46:e7e438368e16 1886
Pokitto 46:e7e438368e16 1887 d+=220; // jump to word directly below
Pokitto 46:e7e438368e16 1888 }
Pokitto 46:e7e438368e16 1889 */
Pokitto 46:e7e438368e16 1890 /** alternative way: go through one color at a time **/
Pokitto 46:e7e438368e16 1891 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 1892 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 1893 {
Pokitto 46:e7e438368e16 1894 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 1895
Pokitto 46:e7e438368e16 1896 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1897 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1898 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1899 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1900 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1901 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1902 *scptr++ = R_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1903 *scptr++ = R_MASK * (t&0x1);
Pokitto 46:e7e438368e16 1904 }
Pokitto 46:e7e438368e16 1905 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 1906 d = scrbuf+x+POK_BITFRAME;
Pokitto 46:e7e438368e16 1907 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 1908 {
Pokitto 46:e7e438368e16 1909 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 1910
Pokitto 46:e7e438368e16 1911 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1912 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1913 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1914 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1915 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1916 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1917 *scptr++ |= G_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1918 *scptr++ |= G_MASK * (t&0x1);
Pokitto 46:e7e438368e16 1919 }
Pokitto 46:e7e438368e16 1920 scptr = &scanline[0]; // set to beginning of scanline
Pokitto 46:e7e438368e16 1921 d = scrbuf+x+POK_BITFRAME*2;
Pokitto 46:e7e438368e16 1922 for(y=0;y<22;y++, d +=220)
Pokitto 46:e7e438368e16 1923 {
Pokitto 46:e7e438368e16 1924 uint16_t t = *d & 0xFF;
Pokitto 46:e7e438368e16 1925
Pokitto 46:e7e438368e16 1926 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1927 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1928 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1929 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1930 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1931 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1932 *scptr++ |= B_MASK * (t&0x1); t >>= 1;
Pokitto 46:e7e438368e16 1933 *scptr++ |= B_MASK * (t&0x1);
Pokitto 46:e7e438368e16 1934 }
Pokitto 46:e7e438368e16 1935
Pokitto 46:e7e438368e16 1936
Pokitto 46:e7e438368e16 1937 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1938 if (x<8) continue;
Pokitto 46:e7e438368e16 1939 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 1940 #endif
Pokitto 46:e7e438368e16 1941
Pokitto 46:e7e438368e16 1942 /** draw scanlines **/
Pokitto 46:e7e438368e16 1943 for (int s=0;s<176;) {
Pokitto 46:e7e438368e16 1944 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1945 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1946 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1947 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1948 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1949 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1950 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1951 setup_data_16(scanline[s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 1952
Pokitto 46:e7e438368e16 1953 }
Pokitto 46:e7e438368e16 1954
Pokitto 46:e7e438368e16 1955 }
Pokitto 46:e7e438368e16 1956 }
Pokitto 46:e7e438368e16 1957
Pokitto 46:e7e438368e16 1958 //#define ADEKTOSMODE15
Pokitto 46:e7e438368e16 1959
Pokitto 46:e7e438368e16 1960 #ifdef ADEKTOSMODE15
Pokitto 46:e7e438368e16 1961 void Pokitto::lcdRefreshMode15(uint16_t* pal, uint8_t* scrbuf){
Pokitto 46:e7e438368e16 1962 write_command(0x03); write_data(0x1038); //realy only need to call this once
Pokitto 46:e7e438368e16 1963 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 1964 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 1965
Pokitto 46:e7e438368e16 1966 write_command(0x22);
Pokitto 46:e7e438368e16 1967
Pokitto 46:e7e438368e16 1968 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1969 for (int x=0,xt=0; x<0x4BA0;x++,xt++) {
Pokitto 46:e7e438368e16 1970 if (xt==110) xt=0;
Pokitto 46:e7e438368e16 1971 if (xt<8) {
Pokitto 46:e7e438368e16 1972 write_data(0);
Pokitto 46:e7e438368e16 1973 write_data(0);
Pokitto 46:e7e438368e16 1974 } else {
Pokitto 46:e7e438368e16 1975 write_data(pal[(((scrbuf[x]) & 0xf0) >> 4)]);
Pokitto 46:e7e438368e16 1976 write_data(pal[( (scrbuf[x]) & 0x0f)]);
Pokitto 46:e7e438368e16 1977 }
Pokitto 46:e7e438368e16 1978
Pokitto 46:e7e438368e16 1979 }
Pokitto 46:e7e438368e16 1980 #else
Pokitto 46:e7e438368e16 1981 for (int x=0; x<0x4BA0;x++) {
Pokitto 46:e7e438368e16 1982 write_data(pal[(((scrbuf[x]) & 0xf0) >> 4)]);
Pokitto 46:e7e438368e16 1983 write_data(pal[( (scrbuf[x]) & 0x0f)]);
Pokitto 46:e7e438368e16 1984 }
Pokitto 46:e7e438368e16 1985 #endif //PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 1986 }
Pokitto 46:e7e438368e16 1987
Pokitto 46:e7e438368e16 1988 #else
Pokitto 46:e7e438368e16 1989
Pokitto 46:e7e438368e16 1990 void Pokitto::lcdRefreshMode15(uint16_t* paletteptr, uint8_t* scrbuf){
Pokitto 46:e7e438368e16 1991 uint16_t x,y,xptr;
Pokitto 46:e7e438368e16 1992 uint16_t scanline[2][176]; // read two nibbles = pixels at a time
Pokitto 46:e7e438368e16 1993 uint8_t *d, yoffset=0;
Pokitto 46:e7e438368e16 1994
Pokitto 46:e7e438368e16 1995 xptr = 0;
Pokitto 46:e7e438368e16 1996 //setDRAMptr(xptr,yoffset);
Pokitto 46:e7e438368e16 1997
Pokitto 46:e7e438368e16 1998 write_command(0x20); write_data(0);
Pokitto 46:e7e438368e16 1999 write_command(0x21); write_data(0);
Pokitto 46:e7e438368e16 2000 write_command(0x22);
Pokitto 46:e7e438368e16 2001 CLR_CS_SET_CD_RD_WR;
Pokitto 46:e7e438368e16 2002
Pokitto 46:e7e438368e16 2003 for(x=0;x<220;x+=2)
Pokitto 46:e7e438368e16 2004 {
Pokitto 46:e7e438368e16 2005 d = scrbuf+(x>>1);// point to beginning of line in data
Pokitto 46:e7e438368e16 2006 // find colours in one scanline
Pokitto 46:e7e438368e16 2007 uint8_t s=0;
Pokitto 46:e7e438368e16 2008 for(y=0;y<176;y++)
Pokitto 46:e7e438368e16 2009 {
Pokitto 46:e7e438368e16 2010 uint8_t t = *d >> 4; // higher nibble
Pokitto 46:e7e438368e16 2011 uint8_t t2 = *d & 0xF; // lower nibble
Pokitto 46:e7e438368e16 2012 // higher nibble = left pixel in pixel pair
Pokitto 46:e7e438368e16 2013 scanline[0][s] = paletteptr[t];
Pokitto 46:e7e438368e16 2014 scanline[1][s++] = paletteptr[t2];
Pokitto 46:e7e438368e16 2015
Pokitto 46:e7e438368e16 2016 d+=220/2; // jump to read byte directly below in screenbuffer
Pokitto 46:e7e438368e16 2017 }
Pokitto 46:e7e438368e16 2018 s=0;
Pokitto 46:e7e438368e16 2019 // draw scanlines
Pokitto 46:e7e438368e16 2020
Pokitto 46:e7e438368e16 2021 #ifdef PROJ_SHOW_FPS_COUNTER
Pokitto 46:e7e438368e16 2022 if (x<8) continue;
Pokitto 46:e7e438368e16 2023 setDRAMptr(x, 0);
Pokitto 46:e7e438368e16 2024 #endif
Pokitto 46:e7e438368e16 2025
Pokitto 46:e7e438368e16 2026 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 2027 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2028 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2029 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2030 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2031 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2032 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2033 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2034 setup_data_16(scanline[0][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2035 }
Pokitto 46:e7e438368e16 2036
Pokitto 46:e7e438368e16 2037 for (s=0;s<176;) {
Pokitto 46:e7e438368e16 2038 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2039 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2040 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2041 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2042 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2043 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2044 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2045 setup_data_16(scanline[1][s++]);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2046 }
Pokitto 46:e7e438368e16 2047 }
Pokitto 46:e7e438368e16 2048 }
Pokitto 46:e7e438368e16 2049 #endif //ADEKTOSMODE15
Pokitto 46:e7e438368e16 2050
Pokitto 46:e7e438368e16 2051 void Pokitto::blitWord(uint16_t c) {
Pokitto 46:e7e438368e16 2052 setup_data_16(c);CLR_WR;SET_WR;
Pokitto 46:e7e438368e16 2053 }
Pokitto 46:e7e438368e16 2054
Pokitto 46:e7e438368e16 2055