Emulation of the 1970's Chip-8 machine. The emulator has 7 games that are unmodified from the original Chip-8 format.
Diff: LCD_ST7735/Bitmap1bpp.cpp
- Revision:
- 0:bc3f11b1b41f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD_ST7735/Bitmap1bpp.cpp Sun Feb 08 01:58:57 2015 +0000 @@ -0,0 +1,61 @@ +#include "mbed.h" +#include "Bitmap1bpp.h" + +Bitmap1bpp::Bitmap1bpp(uint16_t width, uint16_t height): + _width(width), + _height(height), + _stride((width >> 3) + ((width & 0x07) ? 1 : 0)), + _pBitmapData(new uint8_t[_stride * height]) +{ + +} + +Bitmap1bpp::~Bitmap1bpp() +{ + if (_pBitmapData != NULL) + { + delete []_pBitmapData; + _pBitmapData = NULL; + } +} + +void Bitmap1bpp::clear() +{ + memset(_pBitmapData, 0, _stride * _height); +} + +void Bitmap1bpp::setPixel(int16_t x, int16_t y, uint16_t color) +{ + if (x < 0 || x >= _width || y < 0 || y >= _height) return; + + uint8_t mask = 1 << (7 - (x % 8)); + uint8_t *p = _pBitmapData + ((y * _stride) + (x / 8)); + + if (color) *p |= mask; else *p &= ~mask; +} + +uint16_t Bitmap1bpp::getPixel(int16_t x, int16_t y) +{ + if (x < 0 || x >= _width || y < 0 || y >= _height) return 0; + + uint8_t mask = 1 << (7 - (x % 8)); + uint8_t *p = _pBitmapData + ((y * _stride) + (x / 8)); + + return (*p & mask) == mask ? 1 : 0; +} + +void Bitmap1bpp::fastHLine(int16_t x1, int16_t x2, int16_t y, uint16_t color) +{ + for (int x = x1; x <= x2; ++x) + { + setPixel(x, y, color); + } +} + +void Bitmap1bpp::fastVLine(int16_t y1, int16_t y2, int16_t x, uint16_t color) +{ + for (int y = y1; y <= y2; ++y) + { + setPixel(x, y, color); + } +} \ No newline at end of file