Remove Sprites class constructor parameter

The Sprites class has been given direct access to the screen buffer so it
doesn't need a pointer to been given to it.

Also updated README.md and keywords.txt, and made minor indent changes in
the .h files.
This commit is contained in:
Scott Allen 2016-10-20 13:28:29 -04:00
parent 9d2559c248
commit 40a028e5a1
7 changed files with 44 additions and 39 deletions

View File

@ -38,7 +38,7 @@ Main differences between Arduboy2 and Arduboy V1.1 are:
As of version 2.1.0 functionality from the [Team A.R.G.](http://www.team-arg.org/) *Arglib* library has been added: As of version 2.1.0 functionality from the [Team A.R.G.](http://www.team-arg.org/) *Arglib* library has been added:
- The sprite drawing functions, collision detection functions, and button handling functions that Team A.R.G. incorporated from the [ArduboyExtra](https://github.com/yyyc514/ArduboyExtra) project. The *poll()* function was renamed *pollButtons()* for clarity. - The sprite drawing functions, collision detection functions, and button handling functions that Team A.R.G. incorporated from the [ArduboyExtra](https://github.com/yyyc514/ArduboyExtra) project. The *poll()* function was renamed *pollButtons()* for clarity. The *Sprites* class doesn't require a parameter for the constructor, whereas in *Arglib* a pointer to an Arduboy class object is required.
- The *drawCompressed()* function, which allows compressed bitmaps to be drawn. Saving bitmaps in compressed form may reduce overall sketch size. - The *drawCompressed()* function, which allows compressed bitmaps to be drawn. Saving bitmaps in compressed form may reduce overall sketch size.
## Start up features ## Start up features
@ -98,6 +98,12 @@ void setup() {
The rest of the Arduboy2 functions will now be available for use. The rest of the Arduboy2 functions will now be available for use.
If you wish to use the Sprites class functions you must create a Sprites object:
```cpp
Sprites sprites;
```
Sample sketches have been included with the library as examples of how to use it. To load an example, for examination and uploading to the Arduboy, using the Arduino IDE menus select: Sample sketches have been included with the library as examples of how to use it. To load an example, for examination and uploading to the Arduboy, using the Arduino IDE menus select:
`File > Examples > Arduboy2` `File > Examples > Arduboy2`

View File

@ -8,6 +8,7 @@
Arduboy2 KEYWORD1 Arduboy2 KEYWORD1
Arduboy2Base KEYWORD1 Arduboy2Base KEYWORD1
Sprites KEYWORD1
####################################### #######################################
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
@ -20,6 +21,7 @@ boot KEYWORD2
bootLogo KEYWORD2 bootLogo KEYWORD2
buttonsState KEYWORD2 buttonsState KEYWORD2
clear KEYWORD2 clear KEYWORD2
collide KEYWORD2
cpuLoad KEYWORD2 cpuLoad KEYWORD2
digitalWriteRGB KEYWORD2 digitalWriteRGB KEYWORD2
display KEYWORD2 display KEYWORD2
@ -51,12 +53,15 @@ height KEYWORD2
idle KEYWORD2 idle KEYWORD2
initRandomSeed KEYWORD2 initRandomSeed KEYWORD2
invert KEYWORD2 invert KEYWORD2
justPressed KEYWORD2
justReleased KEYWORD2
nextFrame KEYWORD2 nextFrame KEYWORD2
notPressed KEYWORD2 notPressed KEYWORD2
off KEYWORD2 off KEYWORD2
on KEYWORD2 on KEYWORD2
paint8Pixels KEYWORD2 paint8Pixels KEYWORD2
paintScreen KEYWORD2 paintScreen KEYWORD2
pollButtons KEYWORD2
pressed KEYWORD2 pressed KEYWORD2
saveOnOff KEYWORD2 saveOnOff KEYWORD2
setCursor KEYWORD2 setCursor KEYWORD2
@ -69,6 +74,13 @@ setTextWrap KEYWORD2
systemButtons KEYWORD2 systemButtons KEYWORD2
width KEYWORD2 width KEYWORD2
# Sprites class
drawErase KEYWORD2
drawExternalMask KEYWORD2
drawOverwrite KEYWORD2
drawPlusMask KEYWORD2
drawSelfMasked KEYWORD2
####################################### #######################################
# Constants (LITERAL1) # Constants (LITERAL1)
####################################### #######################################

View File

@ -59,7 +59,9 @@ struct Point
class Arduboy2Base : public ArduboyCore class Arduboy2Base : public ArduboyCore
{ {
public: friend class Sprites;
public:
Arduboy2Base(); Arduboy2Base();
ArduboyAudio audio; ArduboyAudio audio;
@ -285,7 +287,7 @@ public:
*/ */
bool collide(Rect rect1, Rect rect2); bool collide(Rect rect1, Rect rect2);
protected: protected:
// helper function for sound enable/disable system control // helper function for sound enable/disable system control
void sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal); void sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal);
@ -312,7 +314,7 @@ protected:
class Arduboy2 : public Print, public Arduboy2Base class Arduboy2 : public Print, public Arduboy2Base
{ {
public: public:
Arduboy2(); Arduboy2();
/// Writes a single ASCII character to the screen. /// Writes a single ASCII character to the screen.
@ -350,7 +352,7 @@ public:
/// Clears the display and sets the cursor to 0, 0 /// Clears the display and sets the cursor to 0, 0
void clear(); void clear();
protected: protected:
int16_t cursor_x; int16_t cursor_x;
int16_t cursor_y; int16_t cursor_y;
uint8_t textColor; uint8_t textColor;

View File

@ -6,14 +6,14 @@
class ArduboyAudio class ArduboyAudio
{ {
public: public:
void static begin(); void static begin();
void static on(); void static on();
void static off(); void static off();
void static saveOnOff(); void static saveOnOff();
bool static enabled(); bool static enabled();
protected: protected:
bool static audio_enabled; bool static audio_enabled;
}; };

View File

@ -136,7 +136,7 @@
class ArduboyCore class ArduboyCore
{ {
public: public:
ArduboyCore(); ArduboyCore();
/// allows the CPU to idle between frames /// allows the CPU to idle between frames
@ -278,8 +278,7 @@ public:
*/ */
void static boot(); void static boot();
protected: protected:
/// Safe mode /// Safe mode
/** /**
* Safe Mode is engaged by holding down both the LEFT button and UP button * Safe Mode is engaged by holding down both the LEFT button and UP button
@ -300,7 +299,7 @@ protected:
void static inline bootPowerSaving() __attribute__((always_inline)); void static inline bootPowerSaving() __attribute__((always_inline));
private: private:
volatile static uint8_t *csport, *dcport; volatile static uint8_t *csport, *dcport;
uint8_t static cspinmask, dcpinmask; uint8_t static cspinmask, dcpinmask;

View File

@ -1,10 +1,5 @@
#include "Sprites.h" #include "Sprites.h"
Sprites::Sprites(uint8_t* buffer)
{
sBuffer = buffer;
}
void Sprites::drawExternalMask(int16_t x, int16_t y, const uint8_t *bitmap, void Sprites::drawExternalMask(int16_t x, int16_t y, const uint8_t *bitmap,
const uint8_t *mask, uint8_t frame, uint8_t mask_frame) const uint8_t *mask, uint8_t frame, uint8_t mask_frame)
{ {
@ -145,16 +140,16 @@ void Sprites::drawBitmap(int16_t x, int16_t y,
bitmap_data = pgm_read_byte(bofs) * mul_amt; bitmap_data = pgm_read_byte(bofs) * mul_amt;
if (sRow >= 0) { if (sRow >= 0) {
data = sBuffer[ofs]; data = Arduboy2Base::sBuffer[ofs];
data &= (uint8_t)(mask_data); data &= (uint8_t)(mask_data);
data |= (uint8_t)(bitmap_data); data |= (uint8_t)(bitmap_data);
sBuffer[ofs] = data; Arduboy2Base::sBuffer[ofs] = data;
} }
if (yOffset != 0 && sRow < 7) { if (yOffset != 0 && sRow < 7) {
data = sBuffer[ofs + WIDTH]; data = Arduboy2Base::sBuffer[ofs + WIDTH];
data &= (*((unsigned char *) (&mask_data) + 1)); data &= (*((unsigned char *) (&mask_data) + 1));
data |= (*((unsigned char *) (&bitmap_data) + 1)); data |= (*((unsigned char *) (&bitmap_data) + 1));
sBuffer[ofs + WIDTH] = data; Arduboy2Base::sBuffer[ofs + WIDTH] = data;
} }
ofs++; ofs++;
bofs++; bofs++;
@ -170,10 +165,10 @@ void Sprites::drawBitmap(int16_t x, int16_t y,
for (uint8_t iCol = 0; iCol < rendered_width; iCol++) { for (uint8_t iCol = 0; iCol < rendered_width; iCol++) {
bitmap_data = pgm_read_byte(bofs) * mul_amt; bitmap_data = pgm_read_byte(bofs) * mul_amt;
if (sRow >= 0) { if (sRow >= 0) {
sBuffer[ofs] |= (uint8_t)(bitmap_data); Arduboy2Base::sBuffer[ofs] |= (uint8_t)(bitmap_data);
} }
if (yOffset != 0 && sRow < 7) { if (yOffset != 0 && sRow < 7) {
sBuffer[ofs + WIDTH] |= (*((unsigned char *) (&bitmap_data) + 1)); Arduboy2Base::sBuffer[ofs + WIDTH] |= (*((unsigned char *) (&bitmap_data) + 1));
} }
ofs++; ofs++;
bofs++; bofs++;
@ -189,10 +184,10 @@ void Sprites::drawBitmap(int16_t x, int16_t y,
for (uint8_t iCol = 0; iCol < rendered_width; iCol++) { for (uint8_t iCol = 0; iCol < rendered_width; iCol++) {
bitmap_data = pgm_read_byte(bofs) * mul_amt; bitmap_data = pgm_read_byte(bofs) * mul_amt;
if (sRow >= 0) { if (sRow >= 0) {
sBuffer[ofs] &= ~(uint8_t)(bitmap_data); Arduboy2Base::sBuffer[ofs] &= ~(uint8_t)(bitmap_data);
} }
if (yOffset != 0 && sRow < 7) { if (yOffset != 0 && sRow < 7) {
sBuffer[ofs + WIDTH] &= ~(*((unsigned char *) (&bitmap_data) + 1)); Arduboy2Base::sBuffer[ofs + WIDTH] &= ~(*((unsigned char *) (&bitmap_data) + 1));
} }
ofs++; ofs++;
bofs++; bofs++;
@ -218,16 +213,16 @@ void Sprites::drawBitmap(int16_t x, int16_t y,
bitmap_data = pgm_read_byte(bofs) * mul_amt; bitmap_data = pgm_read_byte(bofs) * mul_amt;
if (sRow >= 0) { if (sRow >= 0) {
data = sBuffer[ofs]; data = Arduboy2Base::sBuffer[ofs];
data &= (uint8_t)(mask_data); data &= (uint8_t)(mask_data);
data |= (uint8_t)(bitmap_data); data |= (uint8_t)(bitmap_data);
sBuffer[ofs] = data; Arduboy2Base::sBuffer[ofs] = data;
} }
if (yOffset != 0 && sRow < 7) { if (yOffset != 0 && sRow < 7) {
data = sBuffer[ofs + WIDTH]; data = Arduboy2Base::sBuffer[ofs + WIDTH];
data &= (*((unsigned char *) (&mask_data) + 1)); data &= (*((unsigned char *) (&mask_data) + 1));
data |= (*((unsigned char *) (&bitmap_data) + 1)); data |= (*((unsigned char *) (&bitmap_data) + 1));
sBuffer[ofs + WIDTH] = data; Arduboy2Base::sBuffer[ofs + WIDTH] = data;
} }
ofs++; ofs++;
mask_ofs++; mask_ofs++;
@ -340,8 +335,8 @@ void Sprites::drawBitmap(int16_t x, int16_t y,
[x_count] "r" (rendered_width), [x_count] "r" (rendered_width),
[y_count] "r" (loop_h), [y_count] "r" (loop_h),
[sprite_ofs] "z" (bofs), [sprite_ofs] "z" (bofs),
[buffer_ofs] "x" (sBuffer+ofs), [buffer_ofs] "x" (Arduboy2Base::sBuffer+ofs),
[buffer_page2_ofs] "r" (sBuffer+ofs+WIDTH), // Y pointer [buffer_page2_ofs] "r" (Arduboy2Base::sBuffer+ofs+WIDTH), // Y pointer
[buffer_ofs_jump] "r" (WIDTH-rendered_width), [buffer_ofs_jump] "r" (WIDTH-rendered_width),
[sprite_ofs_jump] "r" ((w-rendered_width)*2), [sprite_ofs_jump] "r" ((w-rendered_width)*2),
[yOffset] "r" (yOffset), [yOffset] "r" (yOffset),

View File

@ -14,12 +14,6 @@
class Sprites class Sprites
{ {
public: public:
/// The class constructor.
/// `buffer` is a pointer to the screen buffer where the draw functions
/// will write to.
///
Sprites(uint8_t* buffer);
/// drawExternalMask() uses a separate mask to mask image (MASKED) /// drawExternalMask() uses a separate mask to mask image (MASKED)
/// ///
/// image mask before after /// image mask before after
@ -130,9 +124,6 @@ class Sprites
void drawBitmap(int16_t x, int16_t y, void drawBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, const uint8_t *mask, const uint8_t *bitmap, const uint8_t *mask,
int8_t w, int8_t h, uint8_t draw_mode); int8_t w, int8_t h, uint8_t draw_mode);
private:
unsigned char *sBuffer;
}; };
#endif #endif