Modified version of official firmware for Outrageous Circuits' RETRO. See Game.cpp for change history.
Fork of Official_RETRO by
Diff: DisplayN18.cpp
- Revision:
- 1:cd8a3926f263
- Parent:
- 0:21669ea33448
diff -r 21669ea33448 -r cd8a3926f263 DisplayN18.cpp --- a/DisplayN18.cpp Mon Nov 10 13:04:42 2014 +0000 +++ b/DisplayN18.cpp Mon Nov 17 19:51:24 2014 +0000 @@ -1,7 +1,6 @@ #include "DisplayN18.h" -DisplayN18::DisplayN18() : resetPin(P0_20), backlightPin(P0_19), rsPin(P0_7), csPin(P0_2), spi(P0_21, P0_22, P1_15) -{ +DisplayN18::DisplayN18() : resetPin(P0_20), backlightPin(P0_19), rsPin(P0_7), csPin(P0_2), spi(P0_21, P0_22, P1_15) { this->resetPin.write(false); this->backlightPin.write(true); this->rsPin.write(false); @@ -12,8 +11,7 @@ this->initialize(); } -void DisplayN18::writeCommand(unsigned char command) -{ +void DisplayN18::writeCommand(unsigned char command) { this->rsPin.write(false); this->csPin.write(false); @@ -23,13 +21,11 @@ this->csPin.write(true); } -void DisplayN18::writeData(unsigned char data) -{ +void DisplayN18::writeData(unsigned char data) { this->writeData(&data, 1); } -void DisplayN18::writeData(const unsigned char* data, unsigned int length) -{ +void DisplayN18::writeData(const unsigned char* data, unsigned int length) { this->rsPin.write(true); this->csPin.write(false); @@ -40,8 +36,7 @@ this->csPin.write(true); } -void DisplayN18::reset() -{ +void DisplayN18::reset() { this->resetPin.write(false); wait_ms(300); @@ -49,8 +44,7 @@ wait_ms(500); } -void DisplayN18::initialize() -{ +void DisplayN18::initialize() { this->reset(); this->writeCommand(0x11); @@ -124,8 +118,7 @@ this->clear(); } -void DisplayN18::setClippingArea(unsigned char x, unsigned char y, unsigned char width, unsigned char height) -{ +void DisplayN18::setClippingArea(unsigned char x, unsigned char y, unsigned char width, unsigned char height) { unsigned char data[4] = { 0x00, 0x00, 0x00, 0x00 }; data[1] = x; @@ -139,8 +132,7 @@ this->writeData(data, 4); } -unsigned short DisplayN18::rgbToShort(unsigned char r, unsigned char g, unsigned char b) -{ +unsigned short DisplayN18::rgbToShort(unsigned char r, unsigned char g, unsigned char b) { unsigned short red = r; unsigned short green = g; unsigned short blue = b; @@ -160,27 +152,23 @@ return red | green | blue; } -void DisplayN18::clear(unsigned short backColor) -{ +void DisplayN18::clear(unsigned short backColor) { for (unsigned int i = 0; i < DisplayN18::WIDTH; i += 10) for (unsigned int j = 0; j < DisplayN18::HEIGHT; j += 8) this->fillRect(i, j, 10, 8, backColor); } -void DisplayN18::draw(const unsigned short* data, int x, int y, int width, int height) -{ +void DisplayN18::draw(const unsigned short* data, int x, int y, int width, int height) { this->setClippingArea(x, y, width - 1, height - 1); this->writeCommand(0x2C); this->writeData(reinterpret_cast<const unsigned char*>(data), width * height * 2); } -void DisplayN18::setPixel(int x, int y, unsigned short foreColor) -{ +void DisplayN18::setPixel(int x, int y, unsigned short foreColor) { this->draw(&foreColor, x, y, 1, 1); } -void DisplayN18::fillRect(int x, int y, int width, int height, unsigned short foreColor) -{ +void DisplayN18::fillRect(int x, int y, int width, int height, unsigned short foreColor) { this->setClippingArea(static_cast<unsigned char>(x), static_cast<unsigned char>(y), static_cast<unsigned char>(width - 1), static_cast<unsigned char>(height)); this->writeCommand(0x2C); @@ -200,16 +188,14 @@ this->writeData(reinterpret_cast<unsigned char*>(buffer), height * width * 2 - i); } -void DisplayN18::drawRect(int x, int y, int width, int height, unsigned short foreColor) -{ +void DisplayN18::drawRect(int x, int y, int width, int height, unsigned short foreColor) { this->drawLine(x, y, x + width, y, foreColor); this->drawLine(x, y + height, x + width, y + height, foreColor); this->drawLine(x, y, x, y + height, foreColor); this->drawLine(x + width, y, x + width, y + height, foreColor); } -void DisplayN18::fillCircle(int x, int y, int radius, unsigned short foreColor) -{ +void DisplayN18::fillCircle(int x, int y, int radius, unsigned short foreColor) { int f = 1 - radius; int dd_f_x = 1; int dd_f_y = -2 * radius; @@ -219,10 +205,8 @@ for (int i = y - radius; i <= y + radius; i++) this->setPixel(x, i, foreColor); - while (x1 < y1) - { - if (f >= 0) - { + while (x1 < y1) { + if (f >= 0) { y1--; dd_f_y += 2; f += dd_f_y; @@ -232,22 +216,19 @@ dd_f_x += 2; f += dd_f_x; - for (int i = y - y1; i <= y + y1; i++) - { + for (int i = y - y1; i <= y + y1; i++) { this->setPixel(x + x1, i, foreColor); this->setPixel(x - x1, i, foreColor); } - for (int i = y - x1; i <= y + x1; i++) - { + for (int i = y - x1; i <= y + x1; i++) { this->setPixel(x + y1, i, foreColor); this->setPixel(x - y1, i, foreColor); } } } -void DisplayN18::drawCircle(int x, int y, int radius, unsigned short foreColor) -{ +void DisplayN18::drawCircle(int x, int y, int radius, unsigned short foreColor) { int f = 1 - radius; int dd_f_x = 1; int dd_f_y = -2 * radius; @@ -259,10 +240,8 @@ this->setPixel(x + radius, y, foreColor); this->setPixel(x - radius, y, foreColor); - while (x1 < y1) - { - if (f >= 0) - { + while (x1 < y1) { + if (f >= 0) { y1--; dd_f_y += 2; f += dd_f_y; @@ -284,12 +263,9 @@ } } -void DisplayN18::drawLine(int x0, int y0, int x1, int y1, unsigned short foreColor) -{ - if (x0 == x1) - { - if (y1 < y0) - { +void DisplayN18::drawLine(int x0, int y0, int x1, int y1, unsigned short foreColor) { + if (x0 == x1) { + if (y1 < y0) { int temp = y0; y0 = y1; y1 = temp; @@ -308,10 +284,8 @@ return; } - if (y0 == y1) - { - if (x1 < x0) - { + if (y0 == y1) { + if (x1 < x0) { int temp = x0; x0 = x1; x1 = temp; @@ -333,8 +307,7 @@ int t; bool steep = ((y1 - y0) < 0 ? -(y1 - y0) : (y1 - y0)) > ((x1 - x0) < 0 ? -(x1 - x0) : (x1 - x0)); - if (steep) - { + if (steep) { t = x0; x0 = y0; y0 = t; @@ -343,8 +316,7 @@ y1 = t; } - if (x0 > x1) - { + if (x0 > x1) { t = x0; x0 = x1; x1 = t; @@ -361,13 +333,9 @@ int err = (dx / 2); int ystep; - if (y0 < y1) - ystep = 1; - else - ystep = -1; + ystep = y0 < y1 ? 1 : -1; - for (; x0 < x1; x0++) - { + for (; x0 < x1; x0++) { if (steep) this->setPixel(y0, x0, foreColor); else @@ -375,8 +343,7 @@ err -= dy; - if (err < 0) - { + if (err < 0) { y0 += (char)ystep; err += dx; } @@ -481,14 +448,12 @@ 0x08, 0x08, 0x2a, 0x1c, 0x08 /* ~ */ }; -void DisplayN18::drawCharacter(int x, int y, const char character, unsigned short foreColor, unsigned short backColor, unsigned char fontSize) -{ +void DisplayN18::drawCharacter(int x, int y, const char character, unsigned short foreColor, unsigned short backColor, unsigned char fontSize) { if (character > 126 || character < 32) return; unsigned short* horizontal = new unsigned short[DisplayN18::CHAR_HEIGHT * fontSize]; - for (int i = 0; i < DisplayN18::CHAR_WIDTH; i++) - { + for (int i = 0; i < DisplayN18::CHAR_WIDTH; i++) { for (int j = 0; j < DisplayN18::CHAR_HEIGHT; j++) for (int k = 0; k < fontSize; k++) horizontal[j * fontSize + k] = characters[(character - 32) * 5 + i] & (1 << j) ? foreColor : backColor; @@ -507,13 +472,11 @@ delete[] horizontal; } -void DisplayN18::drawString(int x, int y, const char* str, unsigned short foreColor, unsigned short backColor, unsigned char fontSize) -{ +void DisplayN18::drawString(int x, int y, const char* str, unsigned short foreColor, unsigned short backColor, unsigned char fontSize) { if (*str == '\0') return; - do - { + do { this->drawCharacter(x, y, *str, foreColor, backColor, fontSize); x += (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * fontSize;