Fix unsigned/signed compare bug in drawFastHLine

Also change int arguments to int16_t in drawPixel for consistency
This commit is contained in:
Scott Allen 2016-09-14 17:50:05 -04:00
parent 9f9691d546
commit fd4cef7025
4 changed files with 31 additions and 27 deletions

View File

@ -7,7 +7,7 @@
"type": "git", "type": "git",
"url": "https://github.com/MLXXXp/Arduboy2.git" "url": "https://github.com/MLXXXp/Arduboy2.git"
}, },
"version": "2.0.1", "version": "2.0.2",
"exclude": "extras", "exclude": "extras",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "atmelavr" "platforms": "atmelavr"

View File

@ -1,5 +1,5 @@
name=Arduboy2 name=Arduboy2
version=2.0.1 version=2.0.2
author=Chris J. Martinez, Kevin Bates, Josh Goebel, Scott Allen, Ross O. Shoger author=Chris J. Martinez, Kevin Bates, Josh Goebel, Scott Allen, Ross O. Shoger
maintainer=Scott Allen saydisp-git@yahoo.ca maintainer=Scott Allen saydisp-git@yahoo.ca
sentence=An alternative library for use with the Arduboy game system. sentence=An alternative library for use with the Arduboy game system.

View File

@ -202,7 +202,7 @@ void Arduboy2Base::clear()
fillScreen(BLACK); fillScreen(BLACK);
} }
void Arduboy2Base::drawPixel(int x, int y, uint8_t color) void Arduboy2Base::drawPixel(int16_t x, int16_t y, uint8_t color)
{ {
#ifdef PIXEL_SAFE_MODE #ifdef PIXEL_SAFE_MODE
if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1)) if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1))
@ -428,46 +428,50 @@ void Arduboy2Base::drawFastVLine
void Arduboy2Base::drawFastHLine void Arduboy2Base::drawFastHLine
(int16_t x, int16_t y, uint8_t w, uint8_t color) (int16_t x, int16_t y, uint8_t w, uint8_t color)
{ {
// Do bounds/limit checks int16_t xEnd; // last x point + 1
if (y < 0 || y >= HEIGHT) {
return;
}
// make sure we don't try to draw below 0 // Do y bounds checks
if (x < 0) { if (y < 0 || y >= HEIGHT)
w += x; return;
xEnd = x + w;
// Check if the entire line is not on the display
if (xEnd <= 0 || x >= WIDTH)
return;
// Don't start before the left edge
if (x < 0)
x = 0; x = 0;
}
// make sure we don't go off the edge of the display // Don't end past the right edge
if ((x + w) > WIDTH) { if (xEnd > WIDTH)
w = (WIDTH - x); xEnd = WIDTH;
}
// if our width is now negative, punt // calculate actual width (even if unchanged)
if (w <= 0) { w = xEnd - x;
return;
}
// buffer pointer plus row offset + x offset // buffer pointer plus row offset + x offset
register uint8_t *pBuf = sBuffer + ((y/8) * WIDTH) + x; register uint8_t *pBuf = sBuffer + ((y / 8) * WIDTH) + x;
// pixel mask // pixel mask
register uint8_t mask = 1 << (y&7); register uint8_t mask = 1 << (y & 7);
switch (color) switch (color)
{ {
case WHITE: case WHITE:
while(w--) { while (w--)
{
*pBuf++ |= mask; *pBuf++ |= mask;
}; }
break; break;
case BLACK: case BLACK:
mask = ~mask; mask = ~mask;
while(w--) { while (w--)
{
*pBuf++ &= mask; *pBuf++ &= mask;
}; }
break; break;
} }
} }

View File

@ -9,7 +9,7 @@
// For a version number in the form of x.y.z the value of the define will be // For a version number in the form of x.y.z the value of the define will be
// ((x * 10000) + (y * 100) + (z)) as a decimal number. // ((x * 10000) + (y * 100) + (z)) as a decimal number.
// So, it will read as xxxyyzz, with no leading zeros on x. // So, it will read as xxxyyzz, with no leading zeros on x.
#define ARDUBOY_LIB_VER 20001 #define ARDUBOY_LIB_VER 20002
// EEPROM settings // EEPROM settings
#define EEPROM_VERSION 0 #define EEPROM_VERSION 0
@ -108,7 +108,7 @@ public:
void display(); void display();
/// Sets a single pixel on the screen buffer to white or black. /// Sets a single pixel on the screen buffer to white or black.
void drawPixel(int x, int y, uint8_t color = WHITE); void drawPixel(int16_t x, int16_t y, uint8_t color = WHITE);
/// Returns the state of the given pixel in the screen buffer. /// Returns the state of the given pixel in the screen buffer.
/** /**