From 047abb575ce46bfcd50358197a70410eb8da18b9 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Fri, 25 Feb 2011 04:31:34 +0000 Subject: [PATCH] squeezed another 550 bytes --- animations/programm.c | 4 ++-- defaults.mk | 2 +- games/breakout/breakout.c | 2 +- games/breakout/level.c | 6 ++--- games/breakout/playfield.c | 6 ++--- games/breakout/playfield.h | 12 +++++++--- games/snake/snake_game.c | 22 +++++++++++-------- games/tetris/bearing.h | 10 ++++++--- games/tetris/bucket.h | 24 +++++++++++++------- games/tetris/highscore.h | 10 ++++++--- games/tetris/input.c | 2 +- games/tetris/input.h | 22 +++++++++++++------ games/tetris/piece.h | 33 ++++++++++++++++++---------- games/tetris/variant_bastet.h | 4 ++-- games/tetris/variants.h | 2 +- games/tetris/view.h | 12 ++++++---- menu/menu.c | 11 +++++++--- pixel.h | 41 +++++++++++++++++++++++++++-------- scrolltext/scrolltext3.c | 9 +++++++- 19 files changed, 159 insertions(+), 75 deletions(-) diff --git a/animations/programm.c b/animations/programm.c index 72d0ef4..6474d14 100644 --- a/animations/programm.c +++ b/animations/programm.c @@ -110,7 +110,7 @@ void off() #ifdef ANIMATION_SPIRALE -static void walk(cursor* cur, unsigned char steps, unsigned int delay){ +static void walk(cursor_t* cur, unsigned char steps, unsigned int delay){ unsigned char x; for(x=steps;x--;){ set_cursor(cur, next_pixel(cur->pos, cur->dir)); @@ -121,7 +121,7 @@ static void walk(cursor* cur, unsigned char steps, unsigned int delay){ void spirale(unsigned int delay){ clear_screen(0); - cursor cur; + cursor_t cur; cur.dir = right; cur.mode = set; set_cursor (&cur, (pixel){NUM_COLS-1,0}); diff --git a/defaults.mk b/defaults.mk index b276d68..bac717f 100644 --- a/defaults.mk +++ b/defaults.mk @@ -37,7 +37,7 @@ ifeq ($(OSTYPE),cygwin) LDFLAGS_SIM = -Wl -mno-cygwin -T simulator/i386pe.x LIBS_SIM = -lglut32 -lglu32 -lopengl32 else - CFLAGS_SIM = -g -Wall -pedantic -std=c99 -O0 + CFLAGS_SIM = -g -Wall -pedantic -std=c99 -O0 -DNDEBUG ifeq ($(MACHINE),x86_64) LDFLAGS_SIM = -Wl -T simulator/elf_x86_64.x else diff --git a/games/breakout/breakout.c b/games/breakout/breakout.c index f788451..81d5a1d 100644 --- a/games/breakout/breakout.c +++ b/games/breakout/breakout.c @@ -39,7 +39,7 @@ void borg_breakout_game() void borg_breakout(uint8_t demomode) { - char my_playfield[NUM_COLS][NUM_ROWS]; + game_field_t my_playfield[NUM_COLS][NUM_ROWS]; playfield = &my_playfield; uint16_t cycles = DEMO_CYCLES; diff --git a/games/breakout/level.c b/games/breakout/level.c index 80c9457..d1c5ff6 100644 --- a/games/breakout/level.c +++ b/games/breakout/level.c @@ -21,8 +21,8 @@ static uint16_t maxscore; /* real level definition */ -enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl); -enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl) +game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl); +game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl) { switch (in_lvl) { @@ -82,7 +82,7 @@ enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl) void level_init (uint8_t in_levelnum) { uint8_t x,y; - enum game_field_t tmp; + game_field_t tmp; maxscore = 0; for (x=0;x= NUM_ROWS || in_y >= NUM_COLS) { @@ -80,7 +80,7 @@ uint8_t check_bounce (int8_t in_x, int8_t in_y) /* this is the actual draw function for a single field */ -static inline void draw_single_field (uint8_t in_x, uint8_t in_y, enum game_field_t in_f) +static inline void draw_single_field (uint8_t in_x, uint8_t in_y, game_field_t in_f) { pixel tmp; uint8_t b; diff --git a/games/breakout/playfield.h b/games/breakout/playfield.h index ce3f4f2..1433bae 100644 --- a/games/breakout/playfield.h +++ b/games/breakout/playfield.h @@ -28,7 +28,7 @@ #define BOUNCE_REBOUND 0x10 /* entries for the playing field */ -enum game_field_t +enum game_field { sp = 0, /* space */ b1 = 1, b2 = 2, b3 = 3, /* bricks */ @@ -36,8 +36,14 @@ enum game_field_t bl, /* ball */ rb /* rebound */ }; +#ifdef NDEBUG + typedef uint8_t game_field_t; +#else + typedef enum game_field game_field_t; +#endif -extern char (*playfield)[NUM_COLS][NUM_ROWS]; + +extern game_field_t (*playfield)[NUM_COLS][NUM_ROWS]; /* @description draw the current field */ @@ -45,7 +51,7 @@ void playfield_draw(); /* @description set a field with given property. */ -void playfield_set (uint8_t in_x, uint8_t in_y, enum game_field_t in_field); +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 */ diff --git a/games/snake/snake_game.c b/games/snake/snake_game.c index 6d80cb1..e7a9b20 100644 --- a/games/snake/snake_game.c +++ b/games/snake/snake_game.c @@ -43,15 +43,19 @@ game_descriptor_t snake_game_descriptor __attribute__((section(".game_descriptor /** * Directions of the snake. */ -typedef enum snake_dir +enum snake_dir { SNAKE_DIR_UP, //!< SNAKE_DIR_UP Snake is heading up. SNAKE_DIR_RIGHT,//!< SNAKE_DIR_RIGHT Snake is heading right. SNAKE_DIR_DOWN, //!< SNAKE_DIR_DOWN Snake is heading down. SNAKE_DIR_LEFT, //!< SNAKE_DIR_LEFT Snake is heading left. SNAKE_DIR_NONE //!< SNAKE_DIR_NONE Helper value for a "resting" joystick. -} snake_dir_t; - +}; +#ifdef NDEBUG + typedef uint8_t snake_dir_t; +#else + typedef enum snake_dir snake_dir_t; +#endif /** * This structure represents the snake character itself. It keeps track of the @@ -59,10 +63,10 @@ typedef enum snake_dir */ typedef struct snake_protagonist { - pixel aSegments[SNAKE_MAX_LENGTH]; /** All segments of the snake. */ - uint8_t nHeadIndex; /** Index of the head segment. */ - uint8_t nTailIndex; /** Index of the tail segment. */ - snake_dir_t dir; /** Direction of the snake. */ + pixel aSegments[SNAKE_MAX_LENGTH]; /**< All segments of the snake. */ + uint8_t nHeadIndex; /**< Index of the head segment. */ + uint8_t nTailIndex; /**< Index of the tail segment. */ + snake_dir_t dir; /**< Direction of the snake. */ } snake_protagonist_t; @@ -71,8 +75,8 @@ typedef struct snake_protagonist */ typedef struct snake_apples { - pixel aApples[SNAKE_MAX_APPLES]; /** All apple positions */ - uint8_t nAppleCount; /** Counter of currently existing apples */ + pixel aApples[SNAKE_MAX_APPLES]; /**< All apple positions */ + uint8_t nAppleCount; /**< Counter of currently existing apples*/ } snake_apples_t; diff --git a/games/tetris/bearing.h b/games/tetris/bearing.h index bde53cd..14f6b8e 100644 --- a/games/tetris/bearing.h +++ b/games/tetris/bearing.h @@ -1,13 +1,17 @@ #ifndef BEARING_H_ #define BEARING_H_ -typedef enum tetris_bearing_t +enum tetris_bearing { TETRIS_BEARING_0, TETRIS_BEARING_90, TETRIS_BEARING_180, TETRIS_BEARING_270 -} -tetris_bearing_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_bearing_t; +#else + typedef enum tetris_bearing tetris_bearing_t; +#endif #endif /* BEARING_H_ */ diff --git a/games/tetris/bucket.h b/games/tetris/bucket.h index b4849c8..f548fe7 100644 --- a/games/tetris/bucket.h +++ b/games/tetris/bucket.h @@ -18,28 +18,36 @@ *********/ // directions to which a piece can be moved -typedef enum tetris_bucket_direction_t +enum tetris_bucket_direction { TETRIS_BUD_LEFT, TETRIS_BUD_RIGHT -} -tetris_bucket_direction_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_bucket_direction_t; +#else + typedef enum tetris_bucket_direction tetris_bucket_direction_t; +#endif // status of the bucket -typedef enum tetris_bucket_status_t +enum tetris_bucket_status { TETRIS_BUS_READY, /** ready to get next piece */ TETRIS_BUS_HOVERING, /** piece is still hovering */ TETRIS_BUS_GLIDING, /** piece is gliding on the dump */ TETRIS_BUS_DOCKED, /** piece has been docked */ TETRIS_BUS_GAMEOVER /** bucket is filled up */ -} -tetris_bucket_status_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_bucket_status_t; +#else + typedef enum tetris_bucket_status tetris_bucket_status_t; +#endif // tetris_bucket_t -typedef struct tetris_bucket_t +typedef struct tetris_bucket { int8_t nWidth; /** width of bucket */ int8_t nHeight; /** height of bucket */ @@ -56,7 +64,7 @@ tetris_bucket_t; // iterator for predicted dump rows -typedef struct tetris_bucket_iterator_t +typedef struct tetris_bucket_iterator { tetris_bucket_t *pBucket; /** bucket to be examined */ uint16_t nPieceMap; /** piece bitmap */ diff --git a/games/tetris/highscore.h b/games/tetris/highscore.h index 757e3c2..2e0f5a3 100644 --- a/games/tetris/highscore.h +++ b/games/tetris/highscore.h @@ -6,15 +6,19 @@ /** * indexes for different tetris variants */ -typedef enum tetris_highscore_index_t +enum tetris_highscore_index { TETRIS_HISCORE_TETRIS, /**< high score index for the standard variant */ TETRIS_HISCORE_BASTET, /**< high score index for the bastet variant */ TETRIS_HISCORE_FP, /**< high score index for the first person variant */ TETRIS_HISCORE_PAD, /**< don't use (padding for an even array boundary)*/ TETRIS_HISCORE_END /**< boundary for the high score array */ -} tetris_highscore_index_t; - +}; +#ifdef NDEBUG + typedef uint8_t tetris_highscore_index_t; +#else + typedef enum tetris_highscore_index tetris_highscore_index_t; +#endif /** * lets the user enter his initials (three characters) diff --git a/games/tetris/input.c b/games/tetris/input.c index 47f203c..b9373f7 100644 --- a/games/tetris/input.c +++ b/games/tetris/input.c @@ -143,7 +143,7 @@ static void tetris_input_chatterProtect(tetris_input_t *pIn, tetris_input_command_t tetris_input_mapCommand(tetris_bearing_t nBearing, tetris_input_command_t nCmd) { - static uint8_t const nMapping[] PROGMEM = + static tetris_input_command_t const nMapping[] PROGMEM = { TETRIS_INCMD_DOWN, TETRIS_INCMD_ROT_CW, TETRIS_INCMD_RIGHT, TETRIS_INCMD_LEFT, diff --git a/games/tetris/input.h b/games/tetris/input.h index 565c7f7..4a84da0 100644 --- a/games/tetris/input.h +++ b/games/tetris/input.h @@ -31,7 +31,7 @@ /** * allowed input values */ -typedef enum tetris_input_command_t +enum tetris_input_command { TETRIS_INCMD_LEFT, /**< move piece left */ TETRIS_INCMD_RIGHT, /**< move piece right */ @@ -42,26 +42,34 @@ typedef enum tetris_input_command_t TETRIS_INCMD_GRAVITY, /**< piece gets pulled by gravity */ TETRIS_INCMD_PAUSE, /**< pause the game */ TETRIS_INCMD_NONE /**< idle (must alway be the last one) */ -} -tetris_input_command_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_input_command_t; +#else + typedef enum tetris_input_command tetris_input_command_t; +#endif /** * values which influence the gravity time limit for a piece */ -typedef enum tetris_input_pace_t +enum tetris_input_pace { TETRIS_INPACE_HOVERING, /**< normal falling pace */ TETRIS_INPACE_GLIDING /**< guarantees a minimum docking time to avoid accidentally docked pieces in higher levels */ -} -tetris_input_pace_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_input_pace_t; +#else + typedef enum tetris_input_pace tetris_input_pace_t; +#endif /** * data structure for the input module */ -typedef struct tetris_input_t +typedef struct tetris_input { /** * current level (determines falling speed) diff --git a/games/tetris/piece.h b/games/tetris/piece.h index 77d1967..7a9ebdb 100644 --- a/games/tetris/piece.h +++ b/games/tetris/piece.h @@ -14,7 +14,7 @@ *********/ /** shape attributes for a piece */ -typedef enum tetris_piece_shape_t +enum tetris_piece_shape { TETRIS_PC_LINE, /**< the I shaped brick */ TETRIS_PC_T, /**< the T shaped brick */ @@ -23,35 +23,46 @@ typedef enum tetris_piece_shape_t TETRIS_PC_LBACK, /**< the reverse L shaped brick */ TETRIS_PC_S, /**< the S shaped brick */ TETRIS_PC_Z /**< the Z shaped brick */ -} -tetris_piece_shape_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_piece_shape_t; +#else + typedef enum tetris_piece_shape tetris_piece_shape_t; +#endif /** possible angles for a brick */ -typedef enum tetris_piece_angle_t +enum tetris_piece_angle { TETRIS_PC_ANGLE_0, /**< standard angle */ TETRIS_PC_ANGLE_90, /**< rotated by 90 degrees */ TETRIS_PC_ANGLE_180, /**< rotated by 180 degrees */ TETRIS_PC_ANGLE_270 /**< rotated by 270 degrees */ -} -tetris_piece_angle_t; - +}; +#ifdef NDEBUG + typedef uint8_t tetris_piece_angle_t; +#else + typedef enum tetris_piece_angle tetris_piece_angle_t; +#endif /** rotation attributes */ -typedef enum tetris_piece_rotation_t +enum tetris_piece_rotation { TETRIS_PC_ROT_CW, /**< clockwise rotation */ TETRIS_PC_ROT_CCW /**< counter clockwise rotation */ -} -tetris_piece_rotation_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_piece_rotation_t; +#else + typedef enum tetris_piece_rotation tetris_piece_rotation_t; +#endif /** * describes the attributes of a piece * @see tetris_piece_shape_t * @see tetris_piece_angle_t */ -typedef struct tetris_piece_t +typedef struct tetris_piece { tetris_piece_shape_t shape; /**< specifies the shape of the piece */ tetris_piece_angle_t angle; /**< specifies one of 4 angels */ diff --git a/games/tetris/variant_bastet.h b/games/tetris/variant_bastet.h index bd25295..9437d3f 100644 --- a/games/tetris/variant_bastet.h +++ b/games/tetris/variant_bastet.h @@ -23,7 +23,7 @@ void tetris_bastet(void); * types * *********/ -typedef struct tetris_bastet_scorepair_t +typedef struct tetris_bastet_scorepair { tetris_piece_shape_t shape; int16_t nScore; @@ -31,7 +31,7 @@ typedef struct tetris_bastet_scorepair_t tetris_bastet_scorepair_t; -typedef struct tetris_bastet_variant_t +typedef struct tetris_bastet_variant { uint16_t nScore; /** score of the player */ uint16_t nHighscore; /** highscore */ diff --git a/games/tetris/variants.h b/games/tetris/variants.h index ef58c35..3cbcc40 100644 --- a/games/tetris/variants.h +++ b/games/tetris/variants.h @@ -8,7 +8,7 @@ #include "bucket.h" #include "input.h" -typedef struct tetris_variant_t +typedef struct tetris_variant { /** * constructs a variant data object diff --git a/games/tetris/view.h b/games/tetris/view.h index d7b59e1..91a8199 100644 --- a/games/tetris/view.h +++ b/games/tetris/view.h @@ -18,16 +18,20 @@ *********/ /** presentation modes */ -typedef enum tetris_view_mode_t +enum tetris_view_mode { TETRIS_VIMO_PAUSED, TETRIS_VIMO_RUNNING -} -tetris_view_mode_t; +}; +#ifdef NDEBUG + typedef uint8_t tetris_view_mode_t; +#else + typedef enum tetris_view_mode tetris_view_mode_t; +#endif /** data structure that drives the view module */ -typedef struct tetris_view_t +typedef struct tetris_view { tetris_variant_t const *pVariantMethods; /** variant function pointers */ void *pVariant; /** associated variant object */ diff --git a/menu/menu.c b/menu/menu.c index 8656e6b..6255cab 100644 --- a/menu/menu.c +++ b/menu/menu.c @@ -36,13 +36,18 @@ extern game_descriptor_t _game_descriptors_end__[]; #define MENU_PREVITEM(item) ((item + MENU_ITEM_MAX - 1) % MENU_ITEM_MAX) -typedef enum menu_direction_t +enum menu_direction { MENU_DIRECTION_LEFT, MENU_DIRECTION_RIGHT, MENU_DIRECTION_STILL -} -menu_direction_t; +}; +#ifdef NDEBUG + typedef uint8_t menu_direction_t; +#else + typedef enum menu_direction menu_direction_t; +#endif + static void menu_setpixel(uint8_t x, uint8_t y, uint8_t isSet) diff --git a/pixel.h b/pixel.h index 40678a9..241d0e6 100644 --- a/pixel.h +++ b/pixel.h @@ -12,12 +12,35 @@ typedef struct { } pixel; -typedef enum {up, right, down, left} direction; -typedef struct { +enum direction{ + up, + right, + down, + left +}; +#ifdef NDEBUG + typedef unsigned char direction_t; +#else + typedef enum direction direction_t; +#endif + + +enum pixelmode{ + clear, + set +}; +#ifdef NDEBUG + typedef unsigned char pixelmode_t; +#else + typedef enum pixelmode pixelmode_t; +#endif + + +typedef struct cursor{ pixel pos; - direction dir; - enum{clear=0, set=1} mode; -} cursor; + direction_t dir; + pixelmode_t mode; +} cursor_t; /**************************************************************************** * Pixel routines @@ -25,18 +48,18 @@ typedef struct { unsigned char get_pixel(pixel p); -static inline pixel next_pixel(pixel pix, direction dir){ +inline static pixel next_pixel(pixel pix, direction_t dir){ static char const nDelta[] = {0, -1, 0, 1, 0}; return (pixel){pix.x + nDelta[dir], pix.y + nDelta[dir + 1]}; } -static inline unsigned char get_next_pixel(pixel p, direction dir){ +inline static unsigned char get_next_pixel(pixel p, direction_t dir){ return get_pixel(next_pixel(p, dir)); } -static inline direction direction_r(direction dir){ +inline static direction_t direction_r(direction_t dir){ return (dir + 1) % 4; } @@ -51,7 +74,7 @@ void setpixel(pixel p, unsigned char value); void shift_pixmap_l(); -static inline void set_cursor(cursor* cur, pixel p){ +static inline void set_cursor(cursor_t* cur, pixel p){ cur->pos = p; setpixel(p, cur->mode ? 3 : 0); } diff --git a/scrolltext/scrolltext3.c b/scrolltext/scrolltext3.c index 10348f1..2e3ea8c 100644 --- a/scrolltext/scrolltext3.c +++ b/scrolltext/scrolltext3.c @@ -83,6 +83,13 @@ enum waitfor_e{ wait_col_l, wait_col_r }; +#ifdef NDEBUG + typedef unsigned char waitfor_e_t; +#else + typedef enum waitfor_e waitfor_e_t; +#endif + + #define DIRECTION_RIGHT 0x01 #define DIRECTION_DOWN 0x02 @@ -91,7 +98,7 @@ typedef struct blob_t_struct{ struct blob_t_struct * next, * last; char *str; char *commands; - enum waitfor_e waitfor; + waitfor_e_t waitfor; int sizex; char sizey; int posx;