squeezed another 550 bytes

This commit is contained in:
Christian Kroll 2011-02-25 04:31:34 +00:00
parent aa29c51bd8
commit 047abb575c
19 changed files with 159 additions and 75 deletions

View File

@ -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});

View File

@ -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

View File

@ -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;

View File

@ -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_COLS;x++)

View File

@ -17,9 +17,9 @@
*/
#include "playfield.h"
char (*playfield)[NUM_COLS][NUM_ROWS];
game_field_t (*playfield)[NUM_COLS][NUM_ROWS];
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)
{
if (in_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;

View File

@ -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
*/

View File

@ -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;

View File

@ -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_ */

View File

@ -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 */

View File

@ -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)

View File

@ -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,

View File

@ -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)

View File

@ -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 */

View File

@ -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 */

View File

@ -8,7 +8,7 @@
#include "bucket.h"
#include "input.h"
typedef struct tetris_variant_t
typedef struct tetris_variant
{
/**
* constructs a variant data object

View File

@ -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 */

View File

@ -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)

41
pixel.h
View File

@ -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);
}

View File

@ -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;