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