From 8a23a3bc8d75a04cfbdb5c0f8a0d9a0d05b06ac3 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Mon, 7 Mar 2011 01:13:35 +0000 Subject: [PATCH] saved 46 bytes by making some literal modulo operands explicitly unsigned --- animations/bitmapscroller.c | 4 ++-- games/snake/snake_game.c | 6 +++--- pixel.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/animations/bitmapscroller.c b/animations/bitmapscroller.c index f216eb5..ba4c4a8 100644 --- a/animations/bitmapscroller.c +++ b/animations/bitmapscroller.c @@ -150,11 +150,11 @@ static void bitmap_recalculateVector(bitmap_t const *const pBitmap, { if (((x + *pdx) > (pBitmap->nXDomain)) || ((x + *pdx) < 0)) { - *pdx = random8() % 2 * (x < (pBitmap->nXDomain / 2) ? 1 : -1); + *pdx = random8() % 2u * (x < (pBitmap->nXDomain / 2) ? 1 : -1); } if (((y + *pdy) > (pBitmap->nYDomain)) || ((y + *pdy) < 0)) { - *pdy = random8() % 2 * (y < (pBitmap->nYDomain / 2) ? 1 : -1); + *pdy = random8() % 2u * (y < (pBitmap->nYDomain / 2) ? 1 : -1); } if (*pdx == 0 && *pdy == 0) { diff --git a/games/snake/snake_game.c b/games/snake/snake_game.c index e7a9b20..b53f430 100644 --- a/games/snake/snake_game.c +++ b/games/snake/snake_game.c @@ -27,7 +27,7 @@ game_descriptor_t snake_game_descriptor __attribute__((section(".game_descriptor #define SNAKE_NEWCONTROL // limits -#define SNAKE_MAX_LENGTH 64 +#define SNAKE_MAX_LENGTH 64u #define SNAKE_MAX_APPLES 10 // delays (in milliseconds) @@ -194,7 +194,7 @@ static void snake_userControl(snake_protagonist_t *pprotSnake, { // rotate through directions (either clockwise or counterclockwise) pprotSnake->dir = (pprotSnake->dir + - (dirJoystick == SNAKE_DIR_LEFT ? 3 : 1)) % 4; + (dirJoystick == SNAKE_DIR_LEFT ? 3 : 1)) % 4u; } } *pdirLast = dirJoystick; @@ -273,7 +273,7 @@ static void snake_autoRoute(snake_protagonist_t *pprotSnake, return; } } - pprotSnake->dir = (pprotSnake->dir + 1) % 4; + pprotSnake->dir = (pprotSnake->dir + 1) % 4u; } else { diff --git a/pixel.h b/pixel.h index 241d0e6..4f0f98d 100644 --- a/pixel.h +++ b/pixel.h @@ -60,7 +60,7 @@ inline static unsigned char get_next_pixel(pixel p, direction_t dir){ inline static direction_t direction_r(direction_t dir){ - return (dir + 1) % 4; + return (dir + 1) % 4u; }