Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to new avr/pgmspace Syntax #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Gamby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void GambyBase::setColumn (byte column) {
* @param icon: The icon's location in `PROGMEM` (e.g. the name of the
* `PROGMEM` constant).
*/
void GambyBase::drawIcon(const prog_uchar *icon) {
void GambyBase::drawIcon(const unsigned char *icon) {
DATA_MODE();
byte w = pgm_read_byte_near(icon);
currentColumn += w;
Expand All @@ -271,7 +271,7 @@ void GambyBase::drawIcon(const prog_uchar *icon) {
* `PROGMEM` constant).
* @param frame The frame number, 0 to (total frames)-1
*/
void GambyBase::drawIcon(const prog_uchar *icon, byte frame) {
void GambyBase::drawIcon(const unsigned char *icon, byte frame) {
DATA_MODE();
byte w = pgm_read_byte_near(icon);
icon += w * frame;
Expand Down Expand Up @@ -1112,7 +1112,7 @@ boolean GambyGraphicsMode::getPatternPixel (byte x, byte y) {
* @param x The sprite's horizontal position
* @param y The sprite's vertical position
*/
void GambyGraphicsMode::drawSprite(byte x, byte y, const prog_uchar *sprite) {
void GambyGraphicsMode::drawSprite(byte x, byte y, const unsigned char *sprite) {
byte w = pgm_read_byte_near(sprite);
byte h = pgm_read_byte_near(++sprite);

Expand Down Expand Up @@ -1143,7 +1143,7 @@ void GambyGraphicsMode::drawSprite(byte x, byte y, const prog_uchar *sprite) {
* constant's name)
* @param frame The frame number to draw (0 to (number of frames)-1)
*/
void GambyGraphicsMode::drawSprite(byte x, byte y, const prog_uchar *sprite, byte frame) {
void GambyGraphicsMode::drawSprite(byte x, byte y, const unsigned char *sprite, byte frame) {
unsigned int w = pgm_read_byte_near(sprite);
unsigned int h = pgm_read_byte_near(++sprite);

Expand Down Expand Up @@ -1185,7 +1185,7 @@ void GambyGraphicsMode::drawSprite(byte x, byte y, const prog_uchar *sprite, byt
* @param mask: The address of the mask sprite in `PROGMEM`
* (e.g. the constant's name)
*/
void GambyGraphicsMode::drawSprite(byte x, byte y, const prog_uchar *sprite, const prog_uchar *mask) {
void GambyGraphicsMode::drawSprite(byte x, byte y, const unsigned char *sprite, const unsigned char *mask) {
byte w = pgm_read_byte_near(sprite);
byte h = pgm_read_byte_near(++sprite);

Expand Down Expand Up @@ -1226,8 +1226,8 @@ void GambyGraphicsMode::drawSprite(byte x, byte y, const prog_uchar *sprite, con
* @param maskFrame The mask image's frame number to draw
* (0 to (number of frames)-1)
*/
void GambyGraphicsMode::drawSprite(byte x, byte y, const prog_uchar *sprite, byte frame,
const prog_uchar *mask, byte maskFrame) {
void GambyGraphicsMode::drawSprite(byte x, byte y, const unsigned char *sprite, byte frame,
const unsigned char *mask, byte maskFrame) {
byte w = pgm_read_byte_near(sprite);
byte h = pgm_read_byte_near(++sprite);

Expand Down
16 changes: 8 additions & 8 deletions Gamby.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ class GambyBase {
byte getCharBaseline(byte);
int getTextWidth(char *);
int getTextWidth_P(const char *);
void drawIcon(const prog_uchar *);
void drawIcon(const prog_uchar *, byte);
void drawIcon(const unsigned char *);
void drawIcon(const unsigned char *, byte);
void drawChar(char);
void print(char *);
void print(long, uint8_t = 10);
Expand Down Expand Up @@ -255,7 +255,7 @@ class GambyBase {
static byte inputs; /**< The D-Pad and button states. Set by readInputs(). */
static byte textDraw;

const prog_int32_t* font; /**< The font to be used for drawing text, read from PROGMEM. */
const int32_t* font; /**< The font to be used for drawing text, read from PROGMEM. */

// private:
byte currentPage;
Expand Down Expand Up @@ -307,7 +307,7 @@ class GambyBlockMode: public GambyBase {
void update();
void update(byte, byte, byte, byte);

const prog_uint16_t* palette; /**< The palette of 16 4x4 pixel blocks */
const uint16_t* palette; /**< The palette of 16 4x4 pixel blocks */
byte offscreen[NUM_BLOCK_COLUMNS][NUM_PAGES]; /**< The offscreen buffer, where the screen is stored before being drawn */

};
Expand All @@ -334,10 +334,10 @@ class GambyGraphicsMode: public GambyBase {
void circle(int, int, int);
void disc(int, int, int);

void drawSprite(byte, byte, const prog_uchar *);
void drawSprite(byte, byte, const prog_uchar *, const prog_uchar *);
void drawSprite(byte, byte, const prog_uchar *, byte);
void drawSprite(byte, byte, const prog_uchar *, byte, const prog_uchar *, byte);
void drawSprite(byte, byte, const unsigned char *);
void drawSprite(byte, byte, const unsigned char *, const unsigned char *);
void drawSprite(byte, byte, const unsigned char *, byte);
void drawSprite(byte, byte, const unsigned char *, byte, const unsigned char *, byte);

void drawText(int, int, char *);
void drawText_P(int, int, const char *);
Expand Down
10 changes: 5 additions & 5 deletions examples/FirstTest/FirstTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ by David R. Stokes (gamby@logicalzero.com) 2012-08-14
// Splash screen graphics: 96 x 40 pixels. These are in the form of several
// 8-pixel-high 'icons' the full width of the screen.

PROGMEM prog_uchar screen_logo_graphic_1[] = {
PROGMEM const unsigned char screen_logo_graphic_1[] = {
96, // Width (full screen)
0xf0, 0x18, 0x8c, 0x44, 0xa4, 0x54, 0x24, 0x54, 0x24, 0x54, 0x24, 0x54,
0x24, 0x54, 0x24, 0x54, 0x24, 0x8c, 0xf8, 0xf8, 0x8c, 0x04, 0x24, 0x54,
Expand All @@ -30,7 +30,7 @@ PROGMEM prog_uchar screen_logo_graphic_1[] = {
};


PROGMEM prog_uchar screen_logo_graphic_2[] = {
PROGMEM const unsigned char screen_logo_graphic_2[] = {
96,
0xff, 0x00, 0xaa, 0x55, 0xaa, 0x55, 0x00, 0xff, 0xc7, 0x93, 0xab, 0x93,
0xab, 0x13, 0xab, 0x53, 0xa3, 0x07, 0xff, 0xff, 0x07, 0x53, 0xab, 0x53,
Expand All @@ -43,7 +43,7 @@ PROGMEM prog_uchar screen_logo_graphic_2[] = {
0xff, 0xff
};

PROGMEM prog_uchar screen_logo_graphic_3[] = {
PROGMEM const unsigned char screen_logo_graphic_3[] = {
96,
0x3f, 0xe0, 0xca, 0xd5, 0xca, 0xd5, 0xc8, 0xd5, 0xc9, 0xd5, 0xc9, 0xd5,
0xc9, 0xd4, 0xca, 0xd5, 0xca, 0xe0, 0xff, 0xff, 0xe0, 0xc5, 0xca, 0xd5,
Expand All @@ -56,7 +56,7 @@ PROGMEM prog_uchar screen_logo_graphic_3[] = {
0xff, 0xff
};

PROGMEM prog_uchar screen_logo_graphic_4[] = {
PROGMEM const unsigned char screen_logo_graphic_4[] = {
96,
0x1f, 0x31, 0x20, 0x24, 0x6a, 0x64, 0x6a, 0x64, 0x6a, 0x64, 0x6a, 0x64,
0x6a, 0x64, 0x6a, 0x64, 0x6a, 0x64, 0x6a, 0x64, 0x6a, 0x64, 0x6a, 0x64,
Expand All @@ -69,7 +69,7 @@ PROGMEM prog_uchar screen_logo_graphic_4[] = {
0x01, 0x00
};

PROGMEM prog_uchar screen_logo_text[] = {
PROGMEM const unsigned char screen_logo_text[] = {
96,
0x00, 0x3c, 0x0a, 0x0a, 0x3c, 0x00, 0x3e, 0x0a, 0x1a, 0x24,
0x00, 0x3e, 0x22, 0x22, 0x1c, 0x00, 0x1e, 0x20, 0x20, 0x1e, 0x00, 0x3e,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ by David R. Stokes (gamby@logicalzero.com) 2012-08-28

// Two spinning balls, each with 4 frames of animation.
// The first two numbers are the dimensions, the rest is the image data.
PROGMEM prog_uchar ball1[] = {16, 16,
PROGMEM const unsigned char ball1[] = {16, 16,
// Frame 0
7, 224, 31, 248, 53, 252, 127, 158, 127, 106, 255, 21, 255, 195, 255, 9,
216, 255, 162, 255, 216, 255, 100, 254, 120, 242, 63, 4, 31, 24, 7, 224,
Expand All @@ -33,7 +33,7 @@ PROGMEM prog_uchar ball1[] = {16, 16,
210, 255, 172, 255, 240, 249, 127, 2, 127, 2, 63, 4, 31, 24, 7, 224
};

PROGMEM prog_uchar ball2[] = {16, 16, // width and height
PROGMEM const unsigned char ball2[] = {16, 16, // width and height
// Frame 0
7, 224, 31, 248, 63, 252, 127, 126, 127, 214, 253, 43, 250, 213, 255, 3,
213, 171, 248, 85, 214, 171, 104, 86, 122, 162, 53, 4, 26, 24, 7, 224,
Expand All @@ -52,13 +52,13 @@ PROGMEM prog_uchar ball2[] = {16, 16, // width and height
// out the entire square, which would cause one ball to clip the other if
// they got too close. It is only a single frame; the shape of the ball does
// not change as it animates.
PROGMEM prog_uchar ballMask[] = {16, 16,
PROGMEM const unsigned char ballMask[] = {16, 16,
7, 224, 31, 248, 63, 252, 127, 254, 127, 254, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 127, 254, 127, 254, 63, 252, 31, 248, 7, 224
};

// An 'eraser' sprite, which is all white. It is also only a single frame.
PROGMEM prog_uchar ballEraser[] = {16, 16,
PROGMEM const unsigned char ballEraser[] = {16, 16,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
Expand Down Expand Up @@ -175,4 +175,3 @@ void loop() {
nextRead = now + readInputTime;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ David R. Stokes (gamby@logicalzero.com) 9/11/2012
#include <Gamby.h>
#include <avr/pgmspace.h>

const prog_uchar smiley8x8[] PROGMEM = {
const unsigned char smiley8x8[] PROGMEM = {
8, 8,
0x3c, 0x42, 0xad, 0xa1, 0xad, 0x91, 0x42, 0x3c
};

const prog_uchar smiley8x8_mask[] PROGMEM = {
const unsigned char smiley8x8_mask[] PROGMEM = {
8, 8,
0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c
};
Expand Down Expand Up @@ -229,7 +229,7 @@ unsigned long randomRects() {
}


unsigned long drawSpriteGrid(const prog_uchar *spriteIdx) {
unsigned long drawSpriteGrid(const unsigned char *spriteIdx) {
gamby.drawPattern = PATTERN_GRAY;
gamby.rect(0,0,NUM_COLUMNS-1, NUM_ROWS-1);
Serial.print("Sprite grid, plain:\t");
Expand All @@ -246,7 +246,7 @@ unsigned long drawSpriteGrid(const prog_uchar *spriteIdx) {
}


unsigned long drawSpriteGrid(const prog_uchar *spriteIdx, const prog_uchar *maskIdx) {
unsigned long drawSpriteGrid(const unsigned char *spriteIdx, const unsigned char *maskIdx) {
gamby.drawPattern = PATTERN_GRAY;
gamby.rect(0,0,NUM_COLUMNS-1, NUM_ROWS-1);
Serial.print("Sprite grid, masked:\t");
Expand All @@ -261,4 +261,3 @@ unsigned long drawSpriteGrid(const prog_uchar *spriteIdx, const prog_uchar *mask
Serial.println(startTime, DEC);
return startTime;
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,3 @@ void loop () {
// circle outline.
gamby.update();
}


4 changes: 2 additions & 2 deletions examples/Games/BlocDrop/BlocDrop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ unsigned int pieces[7][4] = {
// There is a duplicate of each block used for 'dropped' pieces (`n+8`); this
// makes it easy to ignore the currently falling piece's blocks when testing
// for collisions.
PROGMEM prog_uint16_t palette[] = {
PROGMEM const uint16_t palette[] = {
0x0000, // 0: Empty
0xf99f, // 1: Block 0 ("T")
0xadaf, // 2: Block 1 ("-")
Expand Down Expand Up @@ -86,7 +86,7 @@ unsigned long lastInputTime; // The time at which gamby.readInputs() was last ca
byte lastInputs; // The state of the inputs the last time they were checked.

// Bring in the font from the other tab (font.ino)
extern prog_int32_t font[];
extern const int32_t font[];

GambyBlockMode gamby;

Expand Down
6 changes: 2 additions & 4 deletions examples/Games/BlocDrop/font.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// bits 0-24: the character bitmap (by column)
// bits 25-27: character vertical offset
// bits 28-31: character width
PROGMEM prog_int32_t font[] = {
PROGMEM const int32_t font[] = {
0x00000002L, // character ' ' (32)
0xB8000001L, // character '!' (33)
0x18060003L, // character '"' (34)
Expand Down Expand Up @@ -100,7 +100,5 @@ PROGMEM prog_int32_t font[] = {
0xD8000001L, // character '|' (124)
0x8FC80003L, // character '}' (125)
0x20882004L, // character '~' (126)
0xFC631F85L, // character '' (127)
0xFC631F85L, // character ' (127)
};


4 changes: 2 additions & 2 deletions examples/Games/BlocDrop/splashscreen.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The introductory 'splash screen' with the game's title.
// It is stored as 8-pixel-high 'icons' the full width of the LCD with a
// separate 'frame' for each piece of the larger image.
PROGMEM prog_uchar splashscreen[] = {
PROGMEM const unsigned char splashscreen[] = {
96, // Width
// Row 0 ("frame" 0)
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 131, 131, 3, 3,
Expand Down Expand Up @@ -57,7 +57,7 @@ PROGMEM prog_uchar splashscreen[] = {
// The 'Game Over' message. Like the splash screen, it is a multi-frame 'icon',
// with each 'frame' comprising an 8 pixel row of the image. Unlike the splash
// screen, this is smaller than the screen; it only displays over the 'well'.
PROGMEM prog_uchar gameover[] = {
PROGMEM const unsigned char gameover[] = {
// Width
48,
// Row 0 ("frame" 0)
Expand Down
13 changes: 6 additions & 7 deletions examples/Games/Jewels/Jewels.ino
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Cursor cursor(board);
// Score: deleting squares gains you points.
unsigned score = 0;

void blit_inverted(prog_uchar *icon)
void blit_inverted(const unsigned char *icon)
{
DATA_MODE();
byte length = pgm_read_byte_near(icon);
Expand All @@ -216,7 +216,7 @@ void draw_board()
for (unsigned y = 0; y < board.height; y++) {
// We might get called in the middle of a run-deletion operation, so we have to
// be careful about masking out the run mark.
prog_uchar *icon = get_jewel(board.tile(x, y).jewel());
const unsigned char *icon = get_jewel(board.tile(x, y).jewel());
gamby.setPos(x * kColumnPixels, y);
bool inverted = false;
inverted |= cursor.blink().state() && cursor.Equals(x, y);
Expand Down Expand Up @@ -330,8 +330,8 @@ void animate_swap_horizontal(byte leftX, byte bothY, bool holdHighlight)
{
// We are exchanging the tile at leftX,bothY with the tile at leftX+1,bothY.
// Do a cute little animation thingy where the two tiles switch places.
prog_uchar *left_icon = get_jewel(board.tile(leftX, bothY).jewel());
prog_uchar *right_icon = get_jewel(board.tile(leftX+1, bothY).jewel());
const unsigned char *left_icon = get_jewel(board.tile(leftX, bothY).jewel());
const unsigned char *right_icon = get_jewel(board.tile(leftX+1, bothY).jewel());
byte local_left[16];
for (unsigned i = 0; i < 8; i++) {
local_left[i] = pgm_read_byte_near(left_icon + i + 1);
Expand Down Expand Up @@ -361,8 +361,8 @@ void animate_swap_horizontal(byte leftX, byte bothY, bool holdHighlight)
void animate_swap_vertical(byte bothX, byte topY, bool holdHighlight)
{
// Exchange the tile at bothX, topY with the tile at bothX, topY+1.
prog_uchar *top_icon = get_jewel(board.tile(bothX, topY).jewel());
prog_uchar *bot_icon = get_jewel(board.tile(bothX, topY+1).jewel());
const unsigned char *top_icon = get_jewel(board.tile(bothX, topY).jewel());
const unsigned char *bot_icon = get_jewel(board.tile(bothX, topY+1).jewel());
byte local_top[8];
for (unsigned i = 0; i < 8; i++) local_top[i] = pgm_read_byte_near(top_icon + i + 1);
byte local_bot[8];
Expand Down Expand Up @@ -512,4 +512,3 @@ void loop ()
gamby.setPos(0,0);
}
}

7 changes: 3 additions & 4 deletions examples/Games/Jewels/gameover.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void dissolve_away()
// ........ ........ ........ ........ ........ ........ ........ ........
// ........ ........ ........ ........ ........ ........ ........ ........

PROGMEM prog_uchar loss_display_top[65] = {64,
PROGMEM const unsigned char loss_display_top[65] = {64,
B00000110, B00000010, B11100110, B00010010, B00010110, B00010010, B00100110, B00000010,
B00000110, B11000010, B00100110, B00010010, B00100110, B11000010, B00000110, B00000010,
B11110110, B00100010, B11000110, B00100010, B11110110, B00000010, B00000110, B11110010,
Expand All @@ -54,7 +54,7 @@ PROGMEM prog_uchar loss_display_top[65] = {64,
B00000110, B00000010, B11110110, B10010010, B10010110, B00010010, B00010110, B00000010,
B00000110, B11110010, B10010110, B10010010, B10010110, B01100010, B00000110, B00000010
};
PROGMEM prog_uchar loss_display_bottom[65] = {64,
PROGMEM const unsigned char loss_display_bottom[65] = {64,
B00100000, B00110000, B00100011, B00110100, B00100100, B00110101, B00100111, B00110000,
B00100000, B00110111, B00100001, B00110001, B00100001, B00110111, B00100000, B00110000,
B00100111, B00110000, B00100000, B00110000, B00100111, B00110000, B00100000, B00110111,
Expand Down Expand Up @@ -138,7 +138,7 @@ void do_loss_animation()



PROGMEM prog_uchar win_display[8][65] = {
PROGMEM const unsigned char win_display[8][65] = {
{64,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B10000000,
Expand Down Expand Up @@ -280,4 +280,3 @@ bool check_end()
if (redraw) init_board();
return redraw;
}

6 changes: 2 additions & 4 deletions examples/Games/Jewels/jools.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// we represent them as 8x8-pixel icons
// this allows us to present a game field of 8x8 icons, with 32 px on the side

PROGMEM prog_uchar jewels[8][9] = {
PROGMEM const unsigned char jewels[8][9] = {
// hexagon (orange)
// . . . X . . . .
// . . X . X . . .
Expand Down Expand Up @@ -95,9 +95,7 @@ PROGMEM prog_uchar jewels[8][9] = {
{8, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000},
};

prog_uchar* get_jewel(unsigned id)
const unsigned char* get_jewel(unsigned id)
{
return jewels[id];
}


Loading