Browse Source

resolved some signedness issues, still many to go (btw: 78 bytes eliminated in the process)

feature/2015
Christian Kroll 12 years ago
parent
commit
d3c94d3101
  1. 47
      animations/bitmapscroller.c
  2. 2
      animations/bitmapscroller.h
  3. 2
      animations/blackhole.c
  4. 2
      animations/fpmath_patterns.c
  5. 23
      animations/gameoflife.c
  6. 49
      animations/ltn_ant.c
  7. 4
      animations/program.c
  8. 2
      animations/program.h
  9. 8
      animations/squares.c
  10. 4
      can/borg_can.c
  11. 7
      games/breakout/ball.c
  12. 6
      games/breakout/playfield.c
  13. 2
      games/breakout/playfield.h
  14. 7
      games/snake/snake_game.c
  15. 3
      games/space_invaders/invaders2.c
  16. 2
      games/space_invaders/invaders2.h
  17. 6
      games/tetris/bucket.c
  18. 6
      games/tetris/highscore.c
  19. 2
      games/tetris/input.c
  20. 11
      games/tetris/variant_bastet.c
  21. 2
      games/tetris/variant_std.c
  22. 10
      games/tetris/view.c
  23. 2
      pixel.h

47
animations/bitmapscroller.c

@ -152,33 +152,27 @@ static void bitmap_drawViewport(bitmap_t const *const pBitmap,
/** /**
* This functions calculates randomly chosen offsets to move the viewport * Dices a new value for one component of the movement vector so that the
* accross the bitmap. * moving view port changes its direction.
* @param pBitmap The bitmap of interest. * @param nComponent The component (either x or y) we want to change.
* @param x The current x-coordinate of the viewport. * @param nDomain The maximum allowed value for nCompoment.
* @param y The current y-coordinate of the viewport. * @param nDelta The delta which is currently applied to nComponent.
* @param pdx Pointer to a variable which shall hold the horizontal offset. * @return The newly calculated delta for nComponent.
* @param pdy Pointer to a variable which shall hold the vertical offset.
*/ */
static void bitmap_recalculateVector(bitmap_t const *const pBitmap, static signed char bitmap_bounce(unsigned char const nComponent,
unsigned char const x, unsigned char const nDomain,
unsigned char const y, signed char const nDelta)
signed char *const pdx,
signed char *const pdy)
{ {
if (((x + *pdx) > (pBitmap->nXDomain)) || ((x + *pdx) < 0)) signed char nResult;
{ if (((nComponent == 0u) || (nComponent >= nDomain)) && nDelta)
*pdx = random8() % 2u * (x < (pBitmap->nXDomain / 2) ? 1 : -1);
}
if (((y + *pdy) > (pBitmap->nYDomain)) || ((y + *pdy) < 0))
{ {
*pdy = random8() % 2u * (y < (pBitmap->nYDomain / 2) ? 1 : -1); nResult = (signed char)(random8() & 0x01) * (nComponent ? -1 : 1);
} }
if (*pdx == 0 && *pdy == 0) else
{ {
*pdx = (x < (pBitmap->nXDomain / 2) ? 1 : -1); nResult = nDelta;
*pdy = (y < (pBitmap->nYDomain / 2) ? 1 : -1);
} }
return nResult;
} }
@ -197,7 +191,7 @@ void bitmap_scroll(unsigned char const nWidth,
unsigned char const nHeight, unsigned char const nHeight,
unsigned char const nBitPlanes, unsigned char const nBitPlanes,
unsigned int const nTickCount, unsigned int const nTickCount,
unsigned int const nTick, int const nTick,
unsigned char const nFrameTickDivider, unsigned char const nFrameTickDivider,
unsigned char const nMovementTickDivider, unsigned char const nMovementTickDivider,
bitmap_getChunk_t fpGetChunk) bitmap_getChunk_t fpGetChunk)
@ -238,7 +232,14 @@ void bitmap_scroll(unsigned char const nWidth,
} }
if ((i % nMovementTickDivider) == 0) if ((i % nMovementTickDivider) == 0)
{ {
bitmap_recalculateVector(&bitmap, x, y, &dx, &dy); dx = bitmap_bounce(x, bitmap.nXDomain, dx);
dy = bitmap_bounce(y, bitmap.nYDomain, dy);
if ((dx == 0) && (dy == 0))
{
dx = (x < (bitmap.nXDomain / 2) ? 1 : -1);
dy = (y < (bitmap.nYDomain / 2) ? 1 : -1);
}
x += bitmap.nWidth > bitmap.nViewportWidth ? dx : 0; x += bitmap.nWidth > bitmap.nViewportWidth ? dx : 0;
y += bitmap.nHeight > bitmap.nViewportHeight ? dy : 0; y += bitmap.nHeight > bitmap.nViewportHeight ? dy : 0;
} }

2
animations/bitmapscroller.h

@ -38,7 +38,7 @@ void bitmap_scroll(unsigned char const nWidth,
unsigned char const nHeight, unsigned char const nHeight,
unsigned char const nBitPlanes, unsigned char const nBitPlanes,
unsigned int const nTickCount, unsigned int const nTickCount,
unsigned int const nTick, int const nTick,
unsigned char const nFrameTickDivider, unsigned char const nFrameTickDivider,
unsigned char const nMovementTickDivider, unsigned char const nMovementTickDivider,
bitmap_getChunk_t fpGetChunk); bitmap_getChunk_t fpGetChunk);

2
animations/blackhole.c

@ -18,7 +18,7 @@
* @param angle angle based on an integer (range from 0 to 63) * @param angle angle based on an integer (range from 0 to 63)
* @return result of the sine function normalized to a range from -64 to 64 * @return result of the sine function normalized to a range from -64 to 64
*/ */
static signed char sin_i(signed char angle) { static signed char sin_i(unsigned char angle) {
// the aforementioned lookup table // the aforementioned lookup table
static signed char const sine_table[] PROGMEM = static signed char const sine_table[] PROGMEM =
{0, 6, 12, 19, 24, 30, 36, 41, 45, 49, 53, 56, 59, 61, 63, 64}; {0, 6, 12, 19, 24, 30, 36, 41, 45, 49, 53, 56, 59, 61, 63, 64};

2
animations/fpmath_patterns.c

@ -288,7 +288,7 @@ static fixp_t fixSqrt(ufixp_interim_t const a)
nRoot++; nRoot++;
} }
} while (nCount-- != 0); } while (nCount-- != 0);
return (nRoot); return (fixp_t)nRoot;
} }

23
animations/gameoflife.c

@ -124,14 +124,27 @@ static cell_t getcell(field_t pf, coord_t x, coord_t y) {
/******************************************************************************/ /******************************************************************************/
uint8_t countsurroundingalive(field_t pf, coord_t x, coord_t y) { uint8_t countsurroundingalive(field_t pf, coord_t x, coord_t y) {
#define P 1u
#define NX (XSIZE - 1u) /* emulated horizontal -1 */
#define NY (YSIZE - 1u) /* emulated vertical -1 */
#if XSIZE == YSIZE
static coord_t const offset[] = {NX, NX, 0, P, P, P, 0, NX, NX, NX};
#else
static coord_t const xoffset[] = {0, P, P, P, 0, NX, NX, NX};
static coord_t const yoffset[] = {NY, NY, 0, P, P, P, 0, NY};
#endif
static int8_t const offset[] = {-1, -1, 0, +1, +1, +1, 0, -1, -1, -1};
x += XSIZE;
y += YSIZE;
uint8_t i, ret = 0; uint8_t i, ret = 0;
for (i = 8; i--;) { for (i = 8; i--;) {
// getcell(...) returns either 0 or 1 // getcell(...) returns either 0 or 1
ret += getcell(pf, (x + offset[i+2]) % XSIZE, (y + offset[i]) % YSIZE); #if XSIZE == YSIZE
ret += getcell(pf, (coord_t)(x + offset[i+2u]) % XSIZE,
(coord_t)(y + offset[i]) % YSIZE);
#else
ret += getcell(pf, (coord_t)(x + xoffset[i]) % XSIZE,
(coord_t)(y + yoffset[i]) % YSIZE);
#endif
} }
return ret; return ret;
@ -315,6 +328,6 @@ void gameoflife() {
} }
} }
pfcopy(ldbuf[ldbuf_idx], pf1); pfcopy(ldbuf[ldbuf_idx], pf1);
ldbuf_idx = (ldbuf_idx + 1) % LOOP_DETECT_BUFFER_SIZE; ldbuf_idx = (ldbuf_idx + 1u) % LOOP_DETECT_BUFFER_SIZE;
} }
} }

49
animations/ltn_ant.c

@ -19,33 +19,53 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
#include <limits.h>
#include "../config.h" #include "../config.h"
#include "../pixel.h" #include "../pixel.h"
#include "../util.h" #include "../util.h"
#include "../random/prng.h" #include "../random/prng.h"
#if (UNUMCOLS <= (UCHAR_MAX / 2)) && (UNUMROWS <= (UCHAR_MAX / 2))
typedef unsigned char coord_t;
#else
typedef unsigned int coord_t;
#endif
#define P (1u)
#define NX (UNUM_COLS - 1u)
#define NY (UNUM_ROWS - 1u)
#if UNUM_ROWS == UNUM_COLS
static coord_t const dcomp[] = {0, P, NX};
#define xdcomp dcomp
#define ydcomp dcomp
#else
static coord_t const xdcomp[] = {0, P, NX};
static coord_t const ydcomp[] = {0, P, NY};
#endif
void ltn_ant() { void ltn_ant() {
clear_screen(0); clear_screen(0);
struct { struct {
unsigned char x, y; coord_t x, y;
unsigned char ox, oy; /* Used to set old pixels so brightness 2 */ coord_t ox, oy; /* Used to set old pixels to brightness 2 */
signed char dx, dy; /* Vector can only be (0,1),(1,0),(0,-1),(-1,0) */ coord_t dx, dy; /* Vector can only be (0,1),(1,0),(0,-1),(-1,0) */
} ant; } ant;
signed char temp; unsigned char temp;
unsigned int cycles = 500; unsigned int cycles = 500;
/* Random start position and direction */ /* Random start position and direction */
ant.x = random8() % NUM_COLS; ant.x = random8() % UNUM_COLS;
ant.y = random8() % NUM_ROWS; ant.y = random8() % UNUM_ROWS;
/* Make sure we do have a valid vector */ /* Make sure we do have a valid vector */
ant.dx = (random8() % 3) - 1; ant.dx = xdcomp[random8() % 3];
do { do {
ant.dy = (random8() % 3) - 1; ant.dy = ydcomp[random8() % 3];
} while(ant.dx == ant.dy); } while(ant.dx == ant.dy);
ant.ox = ant.x; ant.ox = ant.x;
@ -78,15 +98,8 @@ void ltn_ant() {
wait(100); wait(100);
/* Playing field is modeled after a torus */ /* Playing field is modeled after a torus */
if(ant.x == 0 && ant.dx < 0) ant.x = (coord_t)(ant.x + ant.dx) % UNUM_COLS;
ant.x = NUM_COLS - 1; ant.y = (coord_t)(ant.y + ant.dy) % UNUM_ROWS;
else
ant.x = (ant.x + ant.dx) % UNUM_COLS;
if(ant.y == 0 && ant.dy < 0)
ant.y = NUM_ROWS - 1;
else
ant.y = (ant.y + ant.dy) % UNUM_ROWS;
cycles--; cycles--;
} }

4
animations/program.c

@ -47,7 +47,7 @@ void test_palette2(){
#ifdef ANIMATION_SPIRAL #ifdef ANIMATION_SPIRAL
static void walk(cursor_t* cur, unsigned char steps, unsigned int delay){ static void walk(cursor_t* cur, unsigned char steps, int delay){
unsigned char x; unsigned char x;
for(x=steps;x--;){ for(x=steps;x--;){
set_cursor(cur, next_pixel(cur->pos, cur->dir)); set_cursor(cur, next_pixel(cur->pos, cur->dir));
@ -55,7 +55,7 @@ static void walk(cursor_t* cur, unsigned char steps, unsigned int delay){
} }
} }
void spiral(unsigned int delay){ void spiral(int delay){
clear_screen(0); clear_screen(0);
cursor_t cur; cursor_t cur;

2
animations/program.h

@ -20,7 +20,7 @@ inline static void off()
} }
#endif #endif
void spiral(unsigned int delay); void spiral(int delay);
void joern1(); void joern1();
void checkerboard(unsigned char times); void checkerboard(unsigned char times);
void fire(); void fire();

8
animations/squares.c

@ -19,7 +19,7 @@
#include "../random/prng.h" #include "../random/prng.h"
#include "squares.h" #include "squares.h"
#define STEP_WIDTH (NUMPLANE * 2u) #define STEP ((uint8_t)(NUMPLANE * 2u))
#define TICK 100 #define TICK 100
#define CYCLES 200u #define CYCLES 200u
@ -44,8 +44,8 @@ void squares(void) {
for (uint8_t y = 0; y < NUM_ROWS; ++y) { for (uint8_t y = 0; y < NUM_ROWS; ++y) {
uint8_t nColor = 0; uint8_t nColor = 0;
for (uint8_t nLayer = 0; nLayer < NUMPLANE; ++nLayer) { for (uint8_t nLayer = 0; nLayer < NUMPLANE; ++nLayer) {
nColor += (((x + nOffsets[nLayer]) / STEP_WIDTH) + ((y + nColor += (uint8_t)(((x + nOffsets[nLayer]) / STEP) +
nOffsets[nLayer] + STEP_WIDTH) / STEP_WIDTH)) % 2u; ((y + nOffsets[nLayer] + STEP) / STEP)) % 2u;
} }
setpixel((pixel){x, y}, setpixel((pixel){x, y},
nColorMap[(nColOffset + nColor) % (2* NUMPLANE)]); nColorMap[(nColOffset + nColor) % (2* NUMPLANE)]);
@ -54,7 +54,7 @@ void squares(void) {
// add randomly calculated offsets to each layer starting points // add randomly calculated offsets to each layer starting points
for (uint8_t i = 0; i < NUMPLANE; ++i) { for (uint8_t i = 0; i < NUMPLANE; ++i) {
nOffsets[i] = (nOffsets[i] + random8()) % STEP_WIDTH; nOffsets[i] = (uint8_t)(nOffsets[i] + random8()) % STEP;
} }
// rotate color map // rotate color map
nColOffset = (nColOffset + 1) % (NUMPLANE * 2); nColOffset = (nColOffset + 1) % (NUMPLANE * 2);

4
can/borg_can.c

@ -90,7 +90,7 @@ void process_borg_msg(pdo_message *msg)
case FKT_BORG_SCROLLTEXT_RESET: case FKT_BORG_SCROLLTEXT_RESET:
for (i = 0; i < msg->dlc - 1; i++) { for (i = 0; i < msg->dlc - 1; i++) {
scrolltext_text[i] = msg->data[i]; scrolltext_text[i] = (char)msg->data[i];
} }
scrolltext_text[i] = 0; scrolltext_text[i] = 0;
break; break;
@ -101,7 +101,7 @@ void process_borg_msg(pdo_message *msg)
j++; j++;
for (i = 0; i < msg->dlc - 1; i++) { for (i = 0; i < msg->dlc - 1; i++) {
scrolltext_text[i + j] = msg->data[i]; scrolltext_text[i + j] = (char)msg->data[i];
} }
scrolltext_text[i + j] = 0; scrolltext_text[i + j] = 0;
break; break;

7
games/breakout/ball.c

@ -20,7 +20,7 @@
/* internal functions */ /* internal functions */
static void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x, int16_t in_dir_y) static void ball_spawn (ball_t *in_ball, int16_t in_x, int16_t in_y, int16_t in_dir_x, int16_t in_dir_y)
{ {
in_ball->x = in_x; in_ball->x = in_x;
in_ball->y = in_y; in_ball->y = in_y;
@ -41,7 +41,7 @@ static void ball_die (ball_t *in_b)
} }
/* modify a vecotor according to given type of bouncing */ /* modify a vecotor according to given type of bouncing */
static void bounce_rand_vector (ball_t *in_b, uint8_t in_bouncetype) static void bounce_rand_vector (ball_t *in_b, int8_t in_bouncetype)
{ {
uint8_t rval = random8(); uint8_t rval = random8();
@ -183,6 +183,5 @@ void ball_spawn_default (ball_t *in_b)
if (random8() & 0x01) if (random8() & 0x01)
xdir *= -1; xdir *= -1;
ball_spawn (in_b, (uint16_t) rebound_getpos() * 256, (NUM_ROWS -2) * 256, ball_spawn (in_b, rebound_getpos() * 256, (NUM_ROWS - 2) * 256, xdir, -131);
xdir, -131);
} }

6
games/breakout/playfield.c

@ -54,7 +54,7 @@ static void draw_single_field (uint8_t in_x, uint8_t in_y, game_field_t in_f)
setpixel (tmp, b); setpixel (tmp, b);
} }
static void brick_damage (uint8_t in_x, uint8_t in_y) static void brick_damage (int8_t in_x, int8_t in_y)
{ {
if ((*playfield)[in_x][in_y] >= bs || (*playfield)[in_x][in_y] == 0) if ((*playfield)[in_x][in_y] >= bs || (*playfield)[in_x][in_y] == 0)
return; return;
@ -74,9 +74,9 @@ void playfield_set (uint8_t in_x, uint8_t in_y, game_field_t in_field)
(*playfield)[in_x][in_y] = in_field; (*playfield)[in_x][in_y] = in_field;
} }
uint8_t check_bounce (int8_t in_x, int8_t in_y) int8_t check_bounce (int8_t in_x, int8_t in_y)
{ {
uint8_t ov = 0; int8_t ov = 0;
/* overflow check */ /* overflow check */
if (in_x >= NUM_ROWS || in_x < 0) if (in_x >= NUM_ROWS || in_x < 0)
ov |= BOUNCE_X; ov |= BOUNCE_X;

2
games/breakout/playfield.h

@ -55,6 +55,6 @@ void playfield_set (uint8_t in_x, uint8_t in_y, game_field_t in_field);
/* @description Checks if there is an object in the way. If so, it returns 1 /* @description Checks if there is an object in the way. If so, it returns 1
*/ */
uint8_t check_bounce (int8_t in_x, int8_t in_y); int8_t check_bounce (int8_t in_x, int8_t in_y);
#endif /* PLAYFIELD_H */ #endif /* PLAYFIELD_H */

7
games/snake/snake_game.c

@ -306,7 +306,7 @@ static void snake_autoRoute(snake_protagonist_t *pprotSnake,
return; return;
} }
} }
pprotSnake->dir = (pprotSnake->dir + 1) % 4u; pprotSnake->dir = (pprotSnake->dir + 1u) % 4u;
} }
else else
{ {
@ -423,7 +423,7 @@ void snake_engine(uint8_t bDemoMode)
// actually move head // actually move head
pixel pxOldHead = protSnake.aSegments[protSnake.nHeadIndex]; pixel pxOldHead = protSnake.aSegments[protSnake.nHeadIndex];
protSnake.nHeadIndex = (protSnake.nHeadIndex + 1) % USNAKE_MAX_LENGTH; protSnake.nHeadIndex = (protSnake.nHeadIndex + 1u) % USNAKE_MAX_LENGTH;
protSnake.aSegments[protSnake.nHeadIndex] = protSnake.aSegments[protSnake.nHeadIndex] =
snake_nextDirection(pxOldHead, protSnake.dir); snake_nextDirection(pxOldHead, protSnake.dir);
@ -440,7 +440,8 @@ void snake_engine(uint8_t bDemoMode)
// remove last segment // remove last segment
clearpixel(protSnake.aSegments[protSnake.nTailIndex]) clearpixel(protSnake.aSegments[protSnake.nTailIndex])
protSnake.nTailIndex = (protSnake.nTailIndex +1) % USNAKE_MAX_LENGTH; protSnake.nTailIndex =
(protSnake.nTailIndex + 1u) % USNAKE_MAX_LENGTH;
// new apples // new apples
snake_spawnApples(&apples); snake_spawnApples(&apples);

3
games/space_invaders/invaders2.c

@ -103,7 +103,8 @@ void borg_invaders()
} }
else if (ivStatus == 1) //WON else if (ivStatus == 1) //WON
{ {
unsigned int bonus= POINTS_FOR_LEVEL * (level + 1) * (12 - iv.pos.y); unsigned int bonus = POINTS_FOR_LEVEL * (level + 1u) *
(unsigned int)(12 - iv.pos.y);
pl.points += bonus; pl.points += bonus;
//printf("cleared l: %d , y: %d bonus: %d \n", //printf("cleared l: %d , y: %d bonus: %d \n",
// level, iv.pos.y, bonus); // level, iv.pos.y, bonus);

2
games/space_invaders/invaders2.h

@ -132,7 +132,7 @@ typedef struct
typedef struct typedef struct
{ {
signed char lives; unsigned char lives;
unsigned int points; unsigned int points;
} Player; } Player;

6
games/tetris/bucket.c

@ -73,7 +73,7 @@ static uint8_t tetris_bucket_collision(tetris_bucket_t *pBucket,
int8_t const nStart = nRow + tetris_piece_getBottomOffset(nPieceMap); int8_t const nStart = nRow + tetris_piece_getBottomOffset(nPieceMap);
int8_t const nStop = nRow >= 0 ? nRow : 0; int8_t const nStop = nRow >= 0 ? nRow : 0;
// mask those blocks which are not covered by the piece // mask those blocks which are not covered by the piece
uint16_t const nDumpMask = nCol >= 0 ? 0x000F << nCol : 0x000F >> -nCol; uint16_t const nDumpMask = nCol >= 0 ? 0x000Fu << nCol : 0x000Fu >> -nCol;
// value for shifting blocks to the corresponding part of the piece // value for shifting blocks to the corresponding part of the piece
int8_t nShift = 12 - nCol - 4 * (nRow + 3 - nStart); int8_t nShift = 12 - nCol - 4 * (nRow + 3 - nStart);
// compare piece with dump // compare piece with dump
@ -124,7 +124,7 @@ tetris_bucket_t *tetris_bucket_construct(int8_t nWidth,
tetris_bucket_t *pBucket = tetris_bucket_t *pBucket =
(tetris_bucket_t *)malloc(sizeof(tetris_bucket_t)); (tetris_bucket_t *)malloc(sizeof(tetris_bucket_t));
assert(pBucket != NULL); assert(pBucket != NULL);
pBucket->dump = (uint16_t *)calloc(nHeight, sizeof(uint16_t)); pBucket->dump = (uint16_t *)calloc((size_t)nHeight, sizeof(uint16_t));
assert(pBucket->dump != NULL); assert(pBucket->dump != NULL);
// setting requested attributes // setting requested attributes
@ -156,7 +156,7 @@ void tetris_bucket_reset(tetris_bucket_t *pBucket)
pBucket->status = TETRIS_BUS_READY; pBucket->status = TETRIS_BUS_READY;
// clear dump // clear dump
memset(pBucket->dump, 0, pBucket->nHeight * sizeof(uint16_t)); memset(pBucket->dump, 0, (size_t)pBucket->nHeight * sizeof(uint16_t));
} }

6
games/tetris/highscore.c

@ -35,7 +35,7 @@ uint16_t tetris_highscore_inputName(void)
while (1) while (1)
{ {
// we need our own blink interval // we need our own blink interval
nBlink = (nBlink + 1) % 4u; nBlink = (nBlink + 1u) % 4u;
// construct command for scrolltext and execute // construct command for scrolltext and execute
static uint8_t const nOffset[3] = {15, 19, 23}; static uint8_t const nOffset[3] = {15, 19, 23};
@ -98,7 +98,9 @@ uint16_t tetris_highscore_inputName(void)
} }
// return result // return result
return (pszNick[0] - 65) << 10 | (pszNick[1] - 65) << 5 | (pszNick[2] - 65); return (uint16_t)(pszNick[0] - 65) << 10 |
(uint16_t)(pszNick[1] - 65) << 5 |
(uint16_t)(pszNick[2] - 65);
#else #else
return (0); return (0);
#endif #endif

2
games/tetris/input.c

@ -142,7 +142,7 @@ static
tetris_input_command_t tetris_input_mapCommand(tetris_bearing_t nBearing, tetris_input_command_t tetris_input_mapCommand(tetris_bearing_t nBearing,
tetris_input_command_t nCmd) tetris_input_command_t nCmd)
{ {
return (nCmd < TETRIS_INCMD_ROT_CCW) ? (nCmd - nBearing + 4) % 4u : nCmd; return (nCmd < TETRIS_INCMD_ROT_CCW) ? (nCmd - nBearing + 4u) % 4u : nCmd;
} }

11
games/tetris/variant_bastet.c

@ -58,12 +58,13 @@
static void tetris_bastet_doPreprocessing(tetris_bastet_variant_t *pBastet) static void tetris_bastet_doPreprocessing(tetris_bastet_variant_t *pBastet)
{ {
// retrieve sane start and stop values for the column and row indices // retrieve sane start and stop values for the column and row indices
int8_t const nWidth = tetris_bucket_getWidth(pBastet->pBucket); size_t const nWidth = (size_t)tetris_bucket_getWidth(pBastet->pBucket);
int8_t const nStartRow = tetris_bucket_getHeight(pBastet->pBucket) - 1; int8_t const nStartRow = tetris_bucket_getHeight(pBastet->pBucket) - 1;
int8_t const nStopRow = tetris_bucket_getFirstTaintedRow(pBastet->pBucket); int8_t const nStopRow = tetris_bucket_getFirstTaintedRow(pBastet->pBucket);
// clear old precalculated scores (last three elements are always 0) // clear old precalculated scores (last three elements are always 0)
memset(pBastet->pColScore, 0, nWidth * sizeof(int16_t)); memset(pBastet->pColScore, 0, nWidth * sizeof(int16_t));
// calculate the column heights of the actual bucket configuration // calculate the column heights of the actual bucket configuration
// NOTE: in this loop, pColScore stores the actual column heights, // NOTE: in this loop, pColScore stores the actual column heights,
// later it will contain the "score impact" of every unchanged column // later it will contain the "score impact" of every unchanged column
@ -132,7 +133,7 @@ static void tetris_bastet_predictColHeights(tetris_bastet_variant_t *pBastet,
pBastet->pBucket, pPiece, nDeepestRow, nColumn); pBastet->pBucket, pPiece, nDeepestRow, nColumn);
while (pDump != NULL) while (pDump != NULL)
{ {
uint16_t nColMask = 0x0001 << nStartCol; uint16_t nColMask = 0x0001u << nStartCol;
for (int8_t x = nStartCol; x <= nStopCol; ++x) for (int8_t x = nStartCol; x <= nStopCol; ++x)
{ {
if ((*pDump & nColMask) != 0) if ((*pDump & nColMask) != 0)
@ -248,9 +249,9 @@ static void tetris_bastet_evaluatePieces(tetris_bastet_variant_t *pBastet)
TETRIS_PC_ANGLE_0); TETRIS_PC_ANGLE_0);
for (uint8_t nBlock = TETRIS_PC_LINE; nBlock <= TETRIS_PC_Z; ++nBlock) for (uint8_t nBlock = TETRIS_PC_LINE; nBlock <= TETRIS_PC_Z; ++nBlock)
{ {
int16_t nMaxScore = -32768; int16_t nMaxScore = INT16_MIN;
tetris_piece_setShape(pPiece, nBlock); tetris_piece_setShape(pPiece, nBlock);
int8_t nAngleCount = tetris_piece_getAngleCount(pPiece); uint8_t nAngleCount = tetris_piece_getAngleCount(pPiece);
for (uint8_t nAngle = TETRIS_PC_ANGLE_0; nAngle < nAngleCount; ++nAngle) for (uint8_t nAngle = TETRIS_PC_ANGLE_0; nAngle < nAngleCount; ++nAngle)
{ {
tetris_piece_setAngle(pPiece, nAngle); tetris_piece_setAngle(pPiece, nAngle);
@ -325,7 +326,7 @@ void *tetris_bastet_construct(tetris_bucket_t *pBucket)
pBastet->pBucket = pBucket; pBastet->pBucket = pBucket;
int8_t nWidth = tetris_bucket_getWidth(pBastet->pBucket); size_t nWidth = (size_t)tetris_bucket_getWidth(pBastet->pBucket);
pBastet->pColScore = (int16_t*) calloc(nWidth + 3, sizeof(int16_t)); pBastet->pColScore = (int16_t*) calloc(nWidth + 3, sizeof(int16_t));
pBastet->pStartingRow = (int8_t*) calloc(nWidth + 3, sizeof(int8_t)); pBastet->pStartingRow = (int8_t*) calloc(nWidth + 3, sizeof(int8_t));
pBastet->pColHeights = (int8_t*) calloc(nWidth, sizeof(int8_t)); pBastet->pColHeights = (int8_t*) calloc(nWidth, sizeof(int8_t));

2
games/tetris/variant_std.c

@ -150,7 +150,7 @@ void tetris_std_completeDrop(void *pVariantData,
assert(pVariantData != 0); assert(pVariantData != 0);
tetris_standard_variant_t *pStdVariant = tetris_standard_variant_t *pStdVariant =
(tetris_standard_variant_t *)pVariantData; (tetris_standard_variant_t *)pVariantData;
pStdVariant->nScore += nLines * 2; pStdVariant->nScore += nLines * 2u;
} }

10
games/tetris/view.c

@ -243,8 +243,8 @@ static void tetris_view_drawDump(tetris_view_t *pV)
tetris_piece_getBitmap(tetris_bucket_getPiece(pV->pBucket)); tetris_piece_getBitmap(tetris_bucket_getPiece(pV->pBucket));
// clear all bits of the piece we are not interested in and // clear all bits of the piece we are not interested in and
// align the remaining row to LSB // align the remaining row to LSB
int8_t y = nRow - nPieceRow; uint8_t y = (uint8_t)(nRow - nPieceRow);
nPieceMap = (nPieceMap & (0x000F << (y * 4))) >> (y * 4); nPieceMap = (nPieceMap & (0x000Fu << (y * 4u))) >> (y * 4u);
// shift remaining part to current column and embed piece into view // shift remaining part to current column and embed piece into view
nRowMap |= nColumn >= 0 ? nRowMap |= nColumn >= 0 ?
nPieceMap << nColumn : nPieceMap >> -nColumn; nPieceMap << nColumn : nPieceMap >> -nColumn;
@ -256,7 +256,7 @@ static void tetris_view_drawDump(tetris_view_t *pV)
unsigned char nColor = (nRowMap & nElementMask) ? unsigned char nColor = (nRowMap & nElementMask) ?
tetris_view_getPieceColor(pV) : TETRIS_VIEW_COLORSPACE; tetris_view_getPieceColor(pV) : TETRIS_VIEW_COLORSPACE;
tetris_view_setpixel(nBearing, TETRIS_VIEW_XOFFSET_DUMP + x, tetris_view_setpixel(nBearing, TETRIS_VIEW_XOFFSET_DUMP + x,
TETRIS_VIEW_YOFFSET_DUMP + nRow, nColor); TETRIS_VIEW_YOFFSET_DUMP + (uint8_t)nRow, nColor);
nElementMask <<= 1; nElementMask <<= 1;
} }
} }
@ -481,8 +481,8 @@ static void tetris_view_blinkLines(tetris_view_t *pV)
uint8_t nColor = (nColIdx == 0 ? TETRIS_VIEW_COLORFADE uint8_t nColor = (nColIdx == 0 ? TETRIS_VIEW_COLORFADE
: TETRIS_VIEW_COLORPIECE); : TETRIS_VIEW_COLORPIECE);
tetris_view_setpixel(nBearing, tetris_view_setpixel(nBearing,
TETRIS_VIEW_XOFFSET_DUMP + x, TETRIS_VIEW_XOFFSET_DUMP + (uint8_t)x,
TETRIS_VIEW_YOFFSET_DUMP + y, TETRIS_VIEW_YOFFSET_DUMP + (uint8_t)y,
nColor); nColor);
} }
} }

2
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){ inline static direction_t direction_r(direction_t dir){
return (dir + 1) % 4u; return (dir + 1u) % 4u;
} }

Loading…
Cancel
Save