Game entry for the Game Programming Contest sponsored by OutrageousCircuits.com (RETRO Game Console)

Dependencies:   mbed

Fork of Official_RETRO by GHI Electronics

Committer:
Rogerup
Date:
Sun Mar 01 09:34:29 2015 +0000
Revision:
4:2d41b942a823
Parent:
1:cd8a3926f263
Game Entry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
john_ghielec 0:21669ea33448 1 #include "DisplayN18.h"
john_ghielec 0:21669ea33448 2
john_ghielec 1:cd8a3926f263 3 DisplayN18::DisplayN18() : resetPin(P0_20), backlightPin(P0_19), rsPin(P0_7), csPin(P0_2), spi(P0_21, P0_22, P1_15) {
john_ghielec 0:21669ea33448 4 this->resetPin.write(false);
john_ghielec 0:21669ea33448 5 this->backlightPin.write(true);
john_ghielec 0:21669ea33448 6 this->rsPin.write(false);
john_ghielec 0:21669ea33448 7
john_ghielec 0:21669ea33448 8 this->spi.format(8, 3);
john_ghielec 0:21669ea33448 9 this->spi.frequency(15000000);
john_ghielec 0:21669ea33448 10
john_ghielec 0:21669ea33448 11 this->initialize();
john_ghielec 0:21669ea33448 12 }
john_ghielec 0:21669ea33448 13
john_ghielec 1:cd8a3926f263 14 void DisplayN18::writeCommand(unsigned char command) {
john_ghielec 0:21669ea33448 15 this->rsPin.write(false);
john_ghielec 0:21669ea33448 16
john_ghielec 0:21669ea33448 17 this->csPin.write(false);
john_ghielec 0:21669ea33448 18
john_ghielec 0:21669ea33448 19 this->spi.write(command);
john_ghielec 0:21669ea33448 20
john_ghielec 0:21669ea33448 21 this->csPin.write(true);
john_ghielec 0:21669ea33448 22 }
john_ghielec 0:21669ea33448 23
john_ghielec 1:cd8a3926f263 24 void DisplayN18::writeData(unsigned char data) {
john_ghielec 0:21669ea33448 25 this->writeData(&data, 1);
john_ghielec 0:21669ea33448 26 }
john_ghielec 0:21669ea33448 27
john_ghielec 1:cd8a3926f263 28 void DisplayN18::writeData(const unsigned char* data, unsigned int length) {
john_ghielec 0:21669ea33448 29 this->rsPin.write(true);
john_ghielec 0:21669ea33448 30
john_ghielec 0:21669ea33448 31 this->csPin.write(false);
john_ghielec 0:21669ea33448 32
john_ghielec 0:21669ea33448 33 for (unsigned int i = 0; i < length; i++)
john_ghielec 0:21669ea33448 34 this->spi.write(data[i]);
john_ghielec 0:21669ea33448 35
john_ghielec 0:21669ea33448 36 this->csPin.write(true);
john_ghielec 0:21669ea33448 37 }
john_ghielec 0:21669ea33448 38
john_ghielec 1:cd8a3926f263 39 void DisplayN18::reset() {
john_ghielec 0:21669ea33448 40 this->resetPin.write(false);
john_ghielec 0:21669ea33448 41 wait_ms(300);
john_ghielec 0:21669ea33448 42
john_ghielec 0:21669ea33448 43 this->resetPin.write(true);
john_ghielec 0:21669ea33448 44 wait_ms(500);
john_ghielec 0:21669ea33448 45 }
john_ghielec 0:21669ea33448 46
john_ghielec 1:cd8a3926f263 47 void DisplayN18::initialize() {
john_ghielec 0:21669ea33448 48 this->reset();
john_ghielec 0:21669ea33448 49
john_ghielec 0:21669ea33448 50 this->writeCommand(0x11);
john_ghielec 0:21669ea33448 51
john_ghielec 0:21669ea33448 52 wait_ms(120);
john_ghielec 0:21669ea33448 53
john_ghielec 0:21669ea33448 54 this->writeCommand(0xB1);
john_ghielec 0:21669ea33448 55 this->writeData(0x01); this->writeData(0x2C); this->writeData(0x2D);
john_ghielec 0:21669ea33448 56 this->writeCommand(0xB2);
john_ghielec 0:21669ea33448 57 this->writeData(0x01); this->writeData(0x2C); this->writeData(0x2D);
john_ghielec 0:21669ea33448 58 this->writeCommand(0xB3);
john_ghielec 0:21669ea33448 59 this->writeData(0x01); this->writeData(0x2C); this->writeData(0x2D);
john_ghielec 0:21669ea33448 60 this->writeData(0x01); this->writeData(0x2C); this->writeData(0x2D);
john_ghielec 0:21669ea33448 61
john_ghielec 0:21669ea33448 62 this->writeCommand(0xB4);
john_ghielec 0:21669ea33448 63 this->writeData(0x07);
john_ghielec 0:21669ea33448 64
john_ghielec 0:21669ea33448 65 this->writeCommand(0xC0);
john_ghielec 0:21669ea33448 66 this->writeData(0xA2); this->writeData(0x02); this->writeData(0x84);
john_ghielec 0:21669ea33448 67 this->writeCommand(0xC1); this->writeData(0xC5);
john_ghielec 0:21669ea33448 68 this->writeCommand(0xC2);
john_ghielec 0:21669ea33448 69 this->writeData(0x0A); this->writeData(0x00);
john_ghielec 0:21669ea33448 70 this->writeCommand(0xC3);
john_ghielec 0:21669ea33448 71 this->writeData(0x8A); this->writeData(0x2A);
john_ghielec 0:21669ea33448 72 this->writeCommand(0xC4);
john_ghielec 0:21669ea33448 73 this->writeData(0x8A); this->writeData(0xEE);
john_ghielec 0:21669ea33448 74
john_ghielec 0:21669ea33448 75 this->writeCommand(0xC5);
john_ghielec 0:21669ea33448 76 this->writeData(0x0E);
john_ghielec 0:21669ea33448 77
john_ghielec 0:21669ea33448 78 this->writeCommand(0x36);
john_ghielec 0:21669ea33448 79 this->writeData(0xA8);
john_ghielec 0:21669ea33448 80
john_ghielec 0:21669ea33448 81 this->writeCommand(0xe0);
john_ghielec 0:21669ea33448 82 this->writeData(0x0f); this->writeData(0x1a);
john_ghielec 0:21669ea33448 83 this->writeData(0x0f); this->writeData(0x18);
john_ghielec 0:21669ea33448 84 this->writeData(0x2f); this->writeData(0x28);
john_ghielec 0:21669ea33448 85 this->writeData(0x20); this->writeData(0x22);
john_ghielec 0:21669ea33448 86 this->writeData(0x1f); this->writeData(0x1b);
john_ghielec 0:21669ea33448 87 this->writeData(0x23); this->writeData(0x37); this->writeData(0x00);
john_ghielec 0:21669ea33448 88 this->writeData(0x07);
john_ghielec 0:21669ea33448 89 this->writeData(0x02); this->writeData(0x10);
john_ghielec 0:21669ea33448 90
john_ghielec 0:21669ea33448 91 this->writeCommand(0xe1);
john_ghielec 0:21669ea33448 92 this->writeData(0x0f); this->writeData(0x1b);
john_ghielec 0:21669ea33448 93 this->writeData(0x0f); this->writeData(0x17);
john_ghielec 0:21669ea33448 94 this->writeData(0x33); this->writeData(0x2c);
john_ghielec 0:21669ea33448 95 this->writeData(0x29); this->writeData(0x2e);
john_ghielec 0:21669ea33448 96 this->writeData(0x30); this->writeData(0x30);
john_ghielec 0:21669ea33448 97 this->writeData(0x39); this->writeData(0x3f);
john_ghielec 0:21669ea33448 98 this->writeData(0x00); this->writeData(0x07);
john_ghielec 0:21669ea33448 99 this->writeData(0x03); this->writeData(0x10);
john_ghielec 0:21669ea33448 100
john_ghielec 0:21669ea33448 101 this->writeCommand(0x2a);
john_ghielec 0:21669ea33448 102 this->writeData(0x00); this->writeData(0x00);
john_ghielec 0:21669ea33448 103 this->writeData(0x00); this->writeData(0x7f);
john_ghielec 0:21669ea33448 104 this->writeCommand(0x2b);
john_ghielec 0:21669ea33448 105 this->writeData(0x00); this->writeData(0x00);
john_ghielec 0:21669ea33448 106 this->writeData(0x00); this->writeData(0x9f);
john_ghielec 0:21669ea33448 107
john_ghielec 0:21669ea33448 108 this->writeCommand(0xF0);
john_ghielec 0:21669ea33448 109 this->writeData(0x01);
john_ghielec 0:21669ea33448 110 this->writeCommand(0xF6);
john_ghielec 0:21669ea33448 111 this->writeData(0x00);
john_ghielec 0:21669ea33448 112
john_ghielec 0:21669ea33448 113 this->writeCommand(0x3A);
john_ghielec 0:21669ea33448 114 this->writeData(0x05);
john_ghielec 0:21669ea33448 115
john_ghielec 0:21669ea33448 116 this->writeCommand(0x29);
john_ghielec 0:21669ea33448 117
john_ghielec 0:21669ea33448 118 this->clear();
john_ghielec 0:21669ea33448 119 }
john_ghielec 0:21669ea33448 120
john_ghielec 1:cd8a3926f263 121 void DisplayN18::setClippingArea(unsigned char x, unsigned char y, unsigned char width, unsigned char height) {
john_ghielec 0:21669ea33448 122 unsigned char data[4] = { 0x00, 0x00, 0x00, 0x00 };
john_ghielec 0:21669ea33448 123
john_ghielec 0:21669ea33448 124 data[1] = x;
john_ghielec 0:21669ea33448 125 data[3] = x + width;
john_ghielec 0:21669ea33448 126 this->writeCommand(0x2A);
john_ghielec 0:21669ea33448 127 this->writeData(data, 4);
john_ghielec 0:21669ea33448 128
john_ghielec 0:21669ea33448 129 data[1] = y;
john_ghielec 0:21669ea33448 130 data[3] = y + height;
john_ghielec 0:21669ea33448 131 this->writeCommand(0x2B);
john_ghielec 0:21669ea33448 132 this->writeData(data, 4);
john_ghielec 0:21669ea33448 133 }
john_ghielec 0:21669ea33448 134
john_ghielec 1:cd8a3926f263 135 unsigned short DisplayN18::rgbToShort(unsigned char r, unsigned char g, unsigned char b) {
john_ghielec 0:21669ea33448 136 unsigned short red = r;
john_ghielec 0:21669ea33448 137 unsigned short green = g;
john_ghielec 0:21669ea33448 138 unsigned short blue = b;
john_ghielec 0:21669ea33448 139
john_ghielec 0:21669ea33448 140 red /= 8;
john_ghielec 0:21669ea33448 141 green /= 4;
john_ghielec 0:21669ea33448 142 blue /= 8;
john_ghielec 0:21669ea33448 143
john_ghielec 0:21669ea33448 144 red &= 0x1F;
john_ghielec 0:21669ea33448 145 green &= 0x3F;
john_ghielec 0:21669ea33448 146 blue &= 0x1F;
john_ghielec 0:21669ea33448 147
john_ghielec 0:21669ea33448 148 red <<= 3;
john_ghielec 0:21669ea33448 149 blue <<= 8;
john_ghielec 0:21669ea33448 150 green = ((green & 0x7) << 13) + ((green & 0x38) >> 3);
john_ghielec 0:21669ea33448 151
john_ghielec 0:21669ea33448 152 return red | green | blue;
john_ghielec 0:21669ea33448 153 }
john_ghielec 0:21669ea33448 154
john_ghielec 1:cd8a3926f263 155 void DisplayN18::clear(unsigned short backColor) {
john_ghielec 0:21669ea33448 156 for (unsigned int i = 0; i < DisplayN18::WIDTH; i += 10)
john_ghielec 0:21669ea33448 157 for (unsigned int j = 0; j < DisplayN18::HEIGHT; j += 8)
john_ghielec 0:21669ea33448 158 this->fillRect(i, j, 10, 8, backColor);
john_ghielec 0:21669ea33448 159 }
john_ghielec 0:21669ea33448 160
john_ghielec 1:cd8a3926f263 161 void DisplayN18::draw(const unsigned short* data, int x, int y, int width, int height) {
john_ghielec 0:21669ea33448 162 this->setClippingArea(x, y, width - 1, height - 1);
john_ghielec 0:21669ea33448 163 this->writeCommand(0x2C);
john_ghielec 0:21669ea33448 164 this->writeData(reinterpret_cast<const unsigned char*>(data), width * height * 2);
john_ghielec 0:21669ea33448 165 }
john_ghielec 0:21669ea33448 166
john_ghielec 1:cd8a3926f263 167 void DisplayN18::setPixel(int x, int y, unsigned short foreColor) {
john_ghielec 0:21669ea33448 168 this->draw(&foreColor, x, y, 1, 1);
john_ghielec 0:21669ea33448 169 }
john_ghielec 0:21669ea33448 170
john_ghielec 1:cd8a3926f263 171 void DisplayN18::fillRect(int x, int y, int width, int height, unsigned short foreColor) {
john_ghielec 0:21669ea33448 172 this->setClippingArea(static_cast<unsigned char>(x), static_cast<unsigned char>(y), static_cast<unsigned char>(width - 1), static_cast<unsigned char>(height));
john_ghielec 0:21669ea33448 173
john_ghielec 0:21669ea33448 174 this->writeCommand(0x2C);
john_ghielec 0:21669ea33448 175
john_ghielec 0:21669ea33448 176 unsigned short buffer[50];
john_ghielec 0:21669ea33448 177 for (int j = 0; j < sizeof(buffer) / 2; j++)
john_ghielec 0:21669ea33448 178 buffer[j] = foreColor;
john_ghielec 0:21669ea33448 179
john_ghielec 0:21669ea33448 180 this->rsPin.write(true);
john_ghielec 0:21669ea33448 181
john_ghielec 0:21669ea33448 182 int i;
john_ghielec 0:21669ea33448 183 for (i = sizeof(buffer); i < height * width * 2; i += sizeof(buffer))
john_ghielec 0:21669ea33448 184 this->writeData(reinterpret_cast<unsigned char*>(buffer), sizeof(buffer));
john_ghielec 0:21669ea33448 185
john_ghielec 0:21669ea33448 186 i -= sizeof(buffer);
john_ghielec 0:21669ea33448 187 if (i != height * width * 2)
john_ghielec 0:21669ea33448 188 this->writeData(reinterpret_cast<unsigned char*>(buffer), height * width * 2 - i);
john_ghielec 0:21669ea33448 189 }
john_ghielec 0:21669ea33448 190
john_ghielec 1:cd8a3926f263 191 void DisplayN18::drawRect(int x, int y, int width, int height, unsigned short foreColor) {
Rogerup 4:2d41b942a823 192 //this->drawLine(x, y, x + width, y, foreColor);
Rogerup 4:2d41b942a823 193 //this->drawLine(x, y + height, x + width, y + height, foreColor);
Rogerup 4:2d41b942a823 194 //this->drawLine(x, y, x, y + height, foreColor);
Rogerup 4:2d41b942a823 195 //this->drawLine(x + width, y, x + width, y + height, foreColor);
john_ghielec 0:21669ea33448 196 }
john_ghielec 0:21669ea33448 197
john_ghielec 1:cd8a3926f263 198 void DisplayN18::fillCircle(int x, int y, int radius, unsigned short foreColor) {
john_ghielec 0:21669ea33448 199 int f = 1 - radius;
john_ghielec 0:21669ea33448 200 int dd_f_x = 1;
john_ghielec 0:21669ea33448 201 int dd_f_y = -2 * radius;
john_ghielec 0:21669ea33448 202 int x1 = 0;
john_ghielec 0:21669ea33448 203 int y1 = radius;
john_ghielec 0:21669ea33448 204
john_ghielec 0:21669ea33448 205 for (int i = y - radius; i <= y + radius; i++)
john_ghielec 0:21669ea33448 206 this->setPixel(x, i, foreColor);
john_ghielec 0:21669ea33448 207
john_ghielec 1:cd8a3926f263 208 while (x1 < y1) {
john_ghielec 1:cd8a3926f263 209 if (f >= 0) {
john_ghielec 0:21669ea33448 210 y1--;
john_ghielec 0:21669ea33448 211 dd_f_y += 2;
john_ghielec 0:21669ea33448 212 f += dd_f_y;
john_ghielec 0:21669ea33448 213 }
john_ghielec 0:21669ea33448 214
john_ghielec 0:21669ea33448 215 x1++;
john_ghielec 0:21669ea33448 216 dd_f_x += 2;
john_ghielec 0:21669ea33448 217 f += dd_f_x;
john_ghielec 0:21669ea33448 218
john_ghielec 1:cd8a3926f263 219 for (int i = y - y1; i <= y + y1; i++) {
john_ghielec 0:21669ea33448 220 this->setPixel(x + x1, i, foreColor);
john_ghielec 0:21669ea33448 221 this->setPixel(x - x1, i, foreColor);
john_ghielec 0:21669ea33448 222 }
john_ghielec 0:21669ea33448 223
john_ghielec 1:cd8a3926f263 224 for (int i = y - x1; i <= y + x1; i++) {
john_ghielec 0:21669ea33448 225 this->setPixel(x + y1, i, foreColor);
john_ghielec 0:21669ea33448 226 this->setPixel(x - y1, i, foreColor);
john_ghielec 0:21669ea33448 227 }
john_ghielec 0:21669ea33448 228 }
john_ghielec 0:21669ea33448 229 }
john_ghielec 0:21669ea33448 230
john_ghielec 1:cd8a3926f263 231 void DisplayN18::drawCircle(int x, int y, int radius, unsigned short foreColor) {
john_ghielec 0:21669ea33448 232 int f = 1 - radius;
john_ghielec 0:21669ea33448 233 int dd_f_x = 1;
john_ghielec 0:21669ea33448 234 int dd_f_y = -2 * radius;
john_ghielec 0:21669ea33448 235 int x1 = 0;
john_ghielec 0:21669ea33448 236 int y1 = radius;
john_ghielec 0:21669ea33448 237
john_ghielec 0:21669ea33448 238 this->setPixel(x, y + radius, foreColor);
john_ghielec 0:21669ea33448 239 this->setPixel(x, y - radius, foreColor);
john_ghielec 0:21669ea33448 240 this->setPixel(x + radius, y, foreColor);
john_ghielec 0:21669ea33448 241 this->setPixel(x - radius, y, foreColor);
john_ghielec 0:21669ea33448 242
john_ghielec 1:cd8a3926f263 243 while (x1 < y1) {
john_ghielec 1:cd8a3926f263 244 if (f >= 0) {
john_ghielec 0:21669ea33448 245 y1--;
john_ghielec 0:21669ea33448 246 dd_f_y += 2;
john_ghielec 0:21669ea33448 247 f += dd_f_y;
john_ghielec 0:21669ea33448 248 }
john_ghielec 0:21669ea33448 249
john_ghielec 0:21669ea33448 250 x1++;
john_ghielec 0:21669ea33448 251 dd_f_x += 2;
john_ghielec 0:21669ea33448 252 f += dd_f_x;
john_ghielec 0:21669ea33448 253
john_ghielec 0:21669ea33448 254 this->setPixel(x + x1, y + y1, foreColor);
john_ghielec 0:21669ea33448 255 this->setPixel(x - x1, y + y1, foreColor);
john_ghielec 0:21669ea33448 256 this->setPixel(x + x1, y - y1, foreColor);
john_ghielec 0:21669ea33448 257 this->setPixel(x - x1, y - y1, foreColor);
john_ghielec 0:21669ea33448 258
john_ghielec 0:21669ea33448 259 this->setPixel(x + y1, y + x1, foreColor);
john_ghielec 0:21669ea33448 260 this->setPixel(x - y1, y + x1, foreColor);
john_ghielec 0:21669ea33448 261 this->setPixel(x + y1, y - x1, foreColor);
john_ghielec 0:21669ea33448 262 this->setPixel(x - y1, y - x1, foreColor);
john_ghielec 0:21669ea33448 263 }
john_ghielec 0:21669ea33448 264 }
john_ghielec 0:21669ea33448 265
Rogerup 4:2d41b942a823 266 /*
john_ghielec 1:cd8a3926f263 267 void DisplayN18::drawLine(int x0, int y0, int x1, int y1, unsigned short foreColor) {
john_ghielec 1:cd8a3926f263 268 if (x0 == x1) {
john_ghielec 1:cd8a3926f263 269 if (y1 < y0) {
john_ghielec 0:21669ea33448 270 int temp = y0;
john_ghielec 0:21669ea33448 271 y0 = y1;
john_ghielec 0:21669ea33448 272 y1 = temp;
john_ghielec 0:21669ea33448 273 }
john_ghielec 0:21669ea33448 274
john_ghielec 0:21669ea33448 275 this->setClippingArea(static_cast<unsigned char>(x0), static_cast<unsigned char>(y0), 0, static_cast<unsigned char>(y1 - y0 - 1));
john_ghielec 0:21669ea33448 276 this->writeCommand(0x2C);
john_ghielec 0:21669ea33448 277
john_ghielec 0:21669ea33448 278 unsigned short data[DisplayN18::STEP];
john_ghielec 0:21669ea33448 279 for (int i = 0; i < DisplayN18::STEP; i++)
john_ghielec 0:21669ea33448 280 data[i] = foreColor;
john_ghielec 0:21669ea33448 281
john_ghielec 0:21669ea33448 282 for (unsigned char thisY = y0; thisY < y1; thisY += DisplayN18::STEP)
john_ghielec 0:21669ea33448 283 this->writeData(reinterpret_cast<unsigned char*>(data), (thisY + DisplayN18::STEP <= y1 ? DisplayN18::STEP : y1 - thisY) * 2);
john_ghielec 0:21669ea33448 284
john_ghielec 0:21669ea33448 285 return;
john_ghielec 0:21669ea33448 286 }
john_ghielec 0:21669ea33448 287
john_ghielec 1:cd8a3926f263 288 if (y0 == y1) {
john_ghielec 1:cd8a3926f263 289 if (x1 < x0) {
john_ghielec 0:21669ea33448 290 int temp = x0;
john_ghielec 0:21669ea33448 291 x0 = x1;
john_ghielec 0:21669ea33448 292 x1 = temp;
john_ghielec 0:21669ea33448 293 }
john_ghielec 0:21669ea33448 294
john_ghielec 0:21669ea33448 295 this->setClippingArea(static_cast<unsigned char>(x0), static_cast<unsigned char>(y0), static_cast<unsigned char>(x1 - x0 - 1), 0);
john_ghielec 0:21669ea33448 296 this->writeCommand(0x2C);
john_ghielec 0:21669ea33448 297
john_ghielec 0:21669ea33448 298 unsigned short data[DisplayN18::STEP];
john_ghielec 0:21669ea33448 299 for (int i = 0; i < DisplayN18::STEP; i++)
john_ghielec 0:21669ea33448 300 data[i] = foreColor;
john_ghielec 0:21669ea33448 301
john_ghielec 0:21669ea33448 302 for (unsigned char thisX = x0; thisX < x1; thisX += DisplayN18::STEP)
john_ghielec 0:21669ea33448 303 this->writeData(reinterpret_cast<unsigned char*>(data), (thisX + DisplayN18::STEP <= x1 ? DisplayN18::STEP : x1 - thisX) * 2);
john_ghielec 0:21669ea33448 304
john_ghielec 0:21669ea33448 305 return;
john_ghielec 0:21669ea33448 306 }
john_ghielec 0:21669ea33448 307
john_ghielec 0:21669ea33448 308 int t;
john_ghielec 0:21669ea33448 309 bool steep = ((y1 - y0) < 0 ? -(y1 - y0) : (y1 - y0)) > ((x1 - x0) < 0 ? -(x1 - x0) : (x1 - x0));
john_ghielec 0:21669ea33448 310
john_ghielec 1:cd8a3926f263 311 if (steep) {
john_ghielec 0:21669ea33448 312 t = x0;
john_ghielec 0:21669ea33448 313 x0 = y0;
john_ghielec 0:21669ea33448 314 y0 = t;
john_ghielec 0:21669ea33448 315 t = x1;
john_ghielec 0:21669ea33448 316 x1 = y1;
john_ghielec 0:21669ea33448 317 y1 = t;
john_ghielec 0:21669ea33448 318 }
john_ghielec 0:21669ea33448 319
john_ghielec 1:cd8a3926f263 320 if (x0 > x1) {
john_ghielec 0:21669ea33448 321 t = x0;
john_ghielec 0:21669ea33448 322 x0 = x1;
john_ghielec 0:21669ea33448 323 x1 = t;
john_ghielec 0:21669ea33448 324
john_ghielec 0:21669ea33448 325 t = y0;
john_ghielec 0:21669ea33448 326 y0 = y1;
john_ghielec 0:21669ea33448 327 y1 = t;
john_ghielec 0:21669ea33448 328 }
john_ghielec 0:21669ea33448 329
john_ghielec 0:21669ea33448 330 int dx, dy;
john_ghielec 0:21669ea33448 331 dx = x1 - x0;
john_ghielec 0:21669ea33448 332 dy = (y1 - y0) < 0 ? -(y1 - y0) : (y1 - y0);
john_ghielec 0:21669ea33448 333
john_ghielec 0:21669ea33448 334 int err = (dx / 2);
john_ghielec 0:21669ea33448 335 int ystep;
john_ghielec 0:21669ea33448 336
john_ghielec 1:cd8a3926f263 337 ystep = y0 < y1 ? 1 : -1;
john_ghielec 0:21669ea33448 338
john_ghielec 1:cd8a3926f263 339 for (; x0 < x1; x0++) {
john_ghielec 0:21669ea33448 340 if (steep)
john_ghielec 0:21669ea33448 341 this->setPixel(y0, x0, foreColor);
john_ghielec 0:21669ea33448 342 else
john_ghielec 0:21669ea33448 343 this->setPixel(x0, y0, foreColor);
john_ghielec 0:21669ea33448 344
john_ghielec 0:21669ea33448 345 err -= dy;
john_ghielec 0:21669ea33448 346
john_ghielec 1:cd8a3926f263 347 if (err < 0) {
john_ghielec 0:21669ea33448 348 y0 += (char)ystep;
john_ghielec 0:21669ea33448 349 err += dx;
john_ghielec 0:21669ea33448 350 }
john_ghielec 0:21669ea33448 351 }
john_ghielec 0:21669ea33448 352 }
Rogerup 4:2d41b942a823 353 */
john_ghielec 0:21669ea33448 354
Rogerup 4:2d41b942a823 355 unsigned char characters[59 * 5] = {
john_ghielec 0:21669ea33448 356 0x00, 0x00, 0x00, 0x00, 0x00, /* Space 0x20 */
Rogerup 4:2d41b942a823 357 0x00, 0x4f, 0x4f, 0x00, 0x00, /* ! */
john_ghielec 0:21669ea33448 358 0x00, 0x07, 0x00, 0x07, 0x00, /* " */
john_ghielec 0:21669ea33448 359 0x14, 0x7f, 0x14, 0x7f, 0x14, /* # */
john_ghielec 0:21669ea33448 360 0x24, 0x2a, 0x7f, 0x2a, 0x12, /* $ */
john_ghielec 0:21669ea33448 361 0x23, 0x13, 0x08, 0x64, 0x62, /* % */
john_ghielec 0:21669ea33448 362 0x36, 0x49, 0x55, 0x22, 0x20, /* & */
john_ghielec 0:21669ea33448 363 0x00, 0x05, 0x03, 0x00, 0x00, /* ' */
john_ghielec 0:21669ea33448 364 0x00, 0x1c, 0x22, 0x41, 0x00, /* ( */
john_ghielec 0:21669ea33448 365 0x00, 0x41, 0x22, 0x1c, 0x00, /* ) */
john_ghielec 0:21669ea33448 366 0x14, 0x08, 0x3e, 0x08, 0x14, /* // */
john_ghielec 0:21669ea33448 367 0x08, 0x08, 0x3e, 0x08, 0x08, /* + */
john_ghielec 0:21669ea33448 368 0x50, 0x30, 0x00, 0x00, 0x00, /* , */
john_ghielec 0:21669ea33448 369 0x08, 0x08, 0x08, 0x08, 0x08, /* - */
john_ghielec 0:21669ea33448 370 0x00, 0x60, 0x60, 0x00, 0x00, /* . */
john_ghielec 0:21669ea33448 371 0x20, 0x10, 0x08, 0x04, 0x02, /* / */
Rogerup 4:2d41b942a823 372 0x3e, 0x41, 0x41, 0x7f, 0x3e, /* 0 0x30 */
Rogerup 4:2d41b942a823 373 0x00, 0x42, 0x7f, 0x7f, 0x40, /* 1 */
Rogerup 4:2d41b942a823 374 0x72, 0x59, 0x49, 0x4f, 0x46, /* 2 */
Rogerup 4:2d41b942a823 375 0x49, 0x49, 0x49, 0x7f, 0x36, /* 3 */
Rogerup 4:2d41b942a823 376 0x1f, 0x10, 0x10, 0x7f, 0x7f, /* 4 */
Rogerup 4:2d41b942a823 377 0x4f, 0x4f, 0x49, 0x79, 0x31, /* 5 */
Rogerup 4:2d41b942a823 378 0x3e, 0x7f, 0x49, 0x49, 0x32, /* 6 */
Rogerup 4:2d41b942a823 379 0x01, 0x61, 0x79, 0x1f, 0x07, /* 7 */
Rogerup 4:2d41b942a823 380 0x36, 0x49, 0x49, 0x7f, 0x36, /* 8 */
Rogerup 4:2d41b942a823 381 0x26, 0x49, 0x49, 0x7f, 0x3e, /* 9 */
john_ghielec 0:21669ea33448 382 0x00, 0x36, 0x36, 0x00, 0x00, /* : */
john_ghielec 0:21669ea33448 383 0x00, 0x56, 0x36, 0x00, 0x00, /* ; */
john_ghielec 0:21669ea33448 384 0x08, 0x14, 0x22, 0x41, 0x00, /* < */
john_ghielec 0:21669ea33448 385 0x14, 0x14, 0x14, 0x14, 0x14, /* = */
Rogerup 4:2d41b942a823 386 0x08, 0x08, 0x08, 0x1C, 0x08, /* > */
john_ghielec 0:21669ea33448 387 0x02, 0x01, 0x51, 0x09, 0x06, /* ? */
john_ghielec 0:21669ea33448 388 0x3e, 0x41, 0x5d, 0x55, 0x1e, /* @ 0x40 */
Rogerup 4:2d41b942a823 389 0x7e, 0x7f, 0x11, 0x11, 0x7e, /* A */
Rogerup 4:2d41b942a823 390 0x7f, 0x7f, 0x49, 0x49, 0x36, /* B */
Rogerup 4:2d41b942a823 391 0x3e, 0x7f, 0x41, 0x41, 0x22, /* C */
Rogerup 4:2d41b942a823 392 0x7f, 0x7f, 0x41, 0x22, 0x1c, /* D */
Rogerup 4:2d41b942a823 393 0x7f, 0x7f, 0x49, 0x49, 0x49, /* E */
Rogerup 4:2d41b942a823 394 0x7f, 0x7f, 0x09, 0x09, 0x01, /* F */
john_ghielec 0:21669ea33448 395 0x3e, 0x41, 0x49, 0x49, 0x7a, /* G */
Rogerup 4:2d41b942a823 396 0x7f, 0x7f, 0x08, 0x08, 0x7f, /* H */
Rogerup 4:2d41b942a823 397 0x41, 0x7f, 0x7f, 0x41, 0x00, /* I */
john_ghielec 0:21669ea33448 398 0x20, 0x40, 0x41, 0x3f, 0x01, /* J */
Rogerup 4:2d41b942a823 399 0x7f, 0x7f, 0x14, 0x22, 0x41, /* K */
Rogerup 4:2d41b942a823 400 0x7f, 0x7f, 0x40, 0x40, 0x40, /* L */
Rogerup 4:2d41b942a823 401 0x7f, 0x7e, 0x0c, 0x06, 0x7f, /* M */ //02->06
Rogerup 4:2d41b942a823 402 0x7f, 0x7e, 0x08, 0x10, 0x7f, /* N */
Rogerup 4:2d41b942a823 403 0x3e, 0x7f, 0x41, 0x41, 0x3e, /* O */
Rogerup 4:2d41b942a823 404 0x7f, 0x7f, 0x09, 0x09, 0x06, /* P 0x50 */
Rogerup 4:2d41b942a823 405 0x3e, 0x7f, 0x51, 0x21, 0x5e, /* Q */
Rogerup 4:2d41b942a823 406 0x7f, 0x7f, 0x19, 0x29, 0x46, /* R */
Rogerup 4:2d41b942a823 407 0x26, 0x4f, 0x49, 0x79, 0x32, /* S */
Rogerup 4:2d41b942a823 408 0x01, 0x7f, 0x7f, 0x01, 0x01, /* T */
Rogerup 4:2d41b942a823 409 0x3f, 0x7f, 0x40, 0x40, 0x3f, /* U */
Rogerup 4:2d41b942a823 410 0x1f, 0x3f, 0x40, 0x20, 0x1f, /* V */
Rogerup 4:2d41b942a823 411 //0x3f, 0x40, 0x38, 0x40, 0x3f, /* W */
Rogerup 4:2d41b942a823 412 0x7f, 0x3f, 0x18, 0x20, 0x7f, /* W */
john_ghielec 0:21669ea33448 413 0x63, 0x14, 0x08, 0x14, 0x63, /* X */
Rogerup 4:2d41b942a823 414 0x07, 0x0f, 0x78, 0x08, 0x07, /* Y */
john_ghielec 0:21669ea33448 415 0x61, 0x51, 0x49, 0x45, 0x43, /* Z */
john_ghielec 0:21669ea33448 416 };
john_ghielec 0:21669ea33448 417
Rogerup 4:2d41b942a823 418 unsigned short numbers[10] = { 0xF6BE, 0x592E, 0xE7CE, 0xE79E, 0xB792, 0xF39E, 0xF3DE, 0xE492, 0xF7DE, 0xF79E };
Rogerup 4:2d41b942a823 419
Rogerup 4:2d41b942a823 420 void DisplayN18::drawNumber(int x, int y, const char character, unsigned short foreColor, unsigned short backColor)
Rogerup 4:2d41b942a823 421 {
Rogerup 4:2d41b942a823 422 unsigned short mask = 0x8000;
Rogerup 4:2d41b942a823 423
Rogerup 4:2d41b942a823 424 for (int i = 0; i < 5; i++) {
Rogerup 4:2d41b942a823 425 for (int j = 0; j < 3; j++) {
Rogerup 4:2d41b942a823 426 if( numbers[character] & mask )
Rogerup 4:2d41b942a823 427 draw(&foreColor, x+j, y+i, 1, 1);
Rogerup 4:2d41b942a823 428 else
Rogerup 4:2d41b942a823 429 draw(&backColor, x+j, y+i, 1, 1);
Rogerup 4:2d41b942a823 430
Rogerup 4:2d41b942a823 431 mask >>= 1;
Rogerup 4:2d41b942a823 432 }
Rogerup 4:2d41b942a823 433 }
Rogerup 4:2d41b942a823 434 }
Rogerup 4:2d41b942a823 435
john_ghielec 1:cd8a3926f263 436 void DisplayN18::drawCharacter(int x, int y, const char character, unsigned short foreColor, unsigned short backColor, unsigned char fontSize) {
john_ghielec 0:21669ea33448 437 if (character > 126 || character < 32)
john_ghielec 0:21669ea33448 438 return;
john_ghielec 0:21669ea33448 439
john_ghielec 0:21669ea33448 440 unsigned short* horizontal = new unsigned short[DisplayN18::CHAR_HEIGHT * fontSize];
john_ghielec 1:cd8a3926f263 441 for (int i = 0; i < DisplayN18::CHAR_WIDTH; i++) {
john_ghielec 0:21669ea33448 442 for (int j = 0; j < DisplayN18::CHAR_HEIGHT; j++)
john_ghielec 0:21669ea33448 443 for (int k = 0; k < fontSize; k++)
john_ghielec 0:21669ea33448 444 horizontal[j * fontSize + k] = characters[(character - 32) * 5 + i] & (1 << j) ? foreColor : backColor;
john_ghielec 0:21669ea33448 445
john_ghielec 0:21669ea33448 446 for (int k = 0; k < fontSize; k++)
john_ghielec 0:21669ea33448 447 this->draw(horizontal, x + i * fontSize + k, y, 1, DisplayN18::CHAR_HEIGHT * fontSize);
john_ghielec 0:21669ea33448 448 }
john_ghielec 0:21669ea33448 449
john_ghielec 0:21669ea33448 450 for (int i = 0; i < DisplayN18::CHAR_HEIGHT; i++)
john_ghielec 0:21669ea33448 451 for (int k = 0; k < fontSize; k++)
john_ghielec 0:21669ea33448 452 horizontal[i * fontSize + k] = backColor;
john_ghielec 0:21669ea33448 453
john_ghielec 0:21669ea33448 454 for (int k = 0; k < fontSize; k++)
john_ghielec 0:21669ea33448 455 this->draw(horizontal, x + DisplayN18::CHAR_WIDTH * fontSize + k, y, 1, DisplayN18::CHAR_HEIGHT * fontSize);
john_ghielec 0:21669ea33448 456
john_ghielec 0:21669ea33448 457 delete[] horizontal;
john_ghielec 0:21669ea33448 458 }
john_ghielec 0:21669ea33448 459
john_ghielec 1:cd8a3926f263 460 void DisplayN18::drawString(int x, int y, const char* str, unsigned short foreColor, unsigned short backColor, unsigned char fontSize) {
john_ghielec 0:21669ea33448 461 if (*str == '\0')
john_ghielec 0:21669ea33448 462 return;
john_ghielec 0:21669ea33448 463
john_ghielec 1:cd8a3926f263 464 do {
john_ghielec 0:21669ea33448 465 this->drawCharacter(x, y, *str, foreColor, backColor, fontSize);
john_ghielec 0:21669ea33448 466
john_ghielec 0:21669ea33448 467 x += (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * fontSize;
john_ghielec 0:21669ea33448 468 } while (*(++str) != '\0');
john_ghielec 0:21669ea33448 469 }