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

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Sun Oct 07 10:19:52 2018 +0000
Revision:
60:8b6a110feeea
Parent:
51:113b1d84c34f
Child:
64:1d52d8287c39
Rid of all warnings on build all

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