1
0
Fork 0
forked from len0rd/rockbox

Solitaire: Don't use bitfields where it's unnecessary, and use 'int' for single variables. Saves ~400 bytes of code on SH1, and ~1200 bytes of code on coldfire. ARM doesn't profit though.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11016 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2006-09-20 23:34:54 +00:00
parent e63e62b2a1
commit 84d64e16c4

View file

@ -275,18 +275,18 @@ static char helptext[] =
#endif #endif
#if HAVE_LCD_COLOR #if HAVE_LCD_COLOR
static const unsigned colors[4] = { static const fb_data colors[4] = {
LCD_BLACK, LCD_RGBPACK(255, 0, 0), LCD_BLACK, LCD_RGBPACK(255, 0, 0) LCD_BLACK, LCD_RGBPACK(255, 0, 0), LCD_BLACK, LCD_RGBPACK(255, 0, 0)
}; };
#elif LCD_DEPTH > 1 #elif LCD_DEPTH > 1
static const unsigned colors[4] = { static const fb_data colors[4] = {
LCD_BLACK, LCD_BRIGHTNESS(127), LCD_BLACK, LCD_BRIGHTNESS(127) LCD_BLACK, LCD_BRIGHTNESS(127), LCD_BLACK, LCD_BRIGHTNESS(127)
}; };
#endif #endif
#define CONFIG_FILENAME "sol.cfg" #define CONFIG_FILENAME "sol.cfg"
#define NOT_A_CARD 255 #define NOT_A_CARD -1
/* number of cards per suit */ /* number of cards per suit */
#define CARDS_PER_SUIT 13 #define CARDS_PER_SUIT 13
@ -305,7 +305,7 @@ static char helptext[] =
/* column COL_NUM + SUITS corresponds to the remains' stack */ /* column COL_NUM + SUITS corresponds to the remains' stack */
#define REM_COL (STACKS_COL + SUITS) #define REM_COL (STACKS_COL + SUITS)
#define NOT_A_COL 255 #define NOT_A_COL -1
/* background color */ /* background color */
#define BACKGROUND_COLOR LCD_RGBPACK(0,157,0) #define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
@ -316,11 +316,11 @@ static char helptext[] =
typedef struct typedef struct
{ {
unsigned char suit : 2; signed char suit;
unsigned char num : 4; signed char num;
unsigned char known : 1; bool known : 1;
unsigned char used : 1;/* this is what is used when dealing cards */ bool used : 1; /* this is what is used when dealing cards */
unsigned char next; signed char next;
} card_t; } card_t;
@ -336,7 +336,7 @@ static void draw_cursor( int x, int y )
} }
/* Draw a card's border, select it if it's selected and draw the cursor /* Draw a card's border, select it if it's selected and draw the cursor
* is the cursor is currently over the card */ * if the cursor is currently over the card */
static void draw_card_ext( int x, int y, bool selected, bool cursor ) static void draw_card_ext( int x, int y, bool selected, bool cursor )
{ {
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
@ -360,7 +360,7 @@ static void draw_card_ext( int x, int y, bool selected, bool cursor )
} }
/* Draw a card's inner graphics */ /* Draw a card's inner graphics */
static void draw_card( card_t card, int x, int y, static void draw_card( card_t *card, int x, int y,
bool selected, bool cursor, bool leftstyle ) bool selected, bool cursor, bool leftstyle )
{ {
#ifndef HAVE_LCD_COLOR #ifndef HAVE_LCD_COLOR
@ -377,7 +377,7 @@ static void draw_card( card_t card, int x, int y,
rb->lcd_set_drawmode( DRMODE_SOLID ); rb->lcd_set_drawmode( DRMODE_SOLID );
#endif #endif
#endif #endif
if( card.known ) if( card->known )
{ {
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
/* On Color LCDs we have a card back so we only need to clear /* On Color LCDs we have a card back so we only need to clear
@ -387,26 +387,26 @@ static void draw_card( card_t card, int x, int y,
#endif #endif
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
rb->lcd_set_foreground( colors[card.suit] ); rb->lcd_set_foreground( colors[card->suit] );
#endif #endif
if( leftstyle ) if( leftstyle )
{ {
#if MARGIN > 0 #if MARGIN > 0
draw_suit( card.suit, x+1, y+2+NUMBER_HEIGHT ); draw_suit( card->suit, x+1, y+2+NUMBER_HEIGHT );
draw_number( card.num, x+1, y+1 ); draw_number( card->num, x+1, y+1 );
#else #else
draw_suit( card.suit, x+1, y+NUMBER_HEIGHT ); draw_suit( card->suit, x+1, y+NUMBER_HEIGHT );
draw_number( card.num, x+1, y ); draw_number( card->num, x+1, y );
#endif #endif
} }
else else
{ {
#if MARGIN > 0 #if MARGIN > 0
draw_suit( card.suit, x+2+NUMBER_WIDTH, y+1 ); draw_suit( card->suit, x+2+NUMBER_WIDTH, y+1 );
#else #else
draw_suit( card.suit, x+1+NUMBER_WIDTH, y+1 ); draw_suit( card->suit, x+1+NUMBER_WIDTH, y+1 );
#endif #endif
draw_number( card.num, x+1, y+1 ); draw_number( card->num, x+1, y+1 );
} }
} }
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
@ -667,38 +667,38 @@ int solitaire_menu(bool in_game)
*/ */
/* player's cursor */ /* player's cursor */
unsigned char cur_card; int cur_card;
/* player's cursor column num */ /* player's cursor column num */
unsigned char cur_col; int cur_col;
/* selected card */ /* selected card */
unsigned char sel_card; int sel_card;
/* the deck */ /* the deck */
card_t deck[ NUM_CARDS ]; card_t deck[ NUM_CARDS ];
/* the remaining cards */ /* the remaining cards */
/* first card of the remains' stack */ /* first card of the remains' stack */
unsigned char rem; int rem;
/* upper visible card from the remains' stack */ /* upper visible card from the remains' stack */
unsigned char cur_rem; int cur_rem;
/* number of cards drawn from the remains stack - 1 */ /* number of cards drawn from the remains stack - 1 */
signed char count_rem; int count_rem;
/* number of cards per draw of the remains' stack */ /* number of cards per draw of the remains' stack */
signed char cards_per_draw; int cards_per_draw;
/* the 7 game columns */ /* the 7 game columns */
unsigned char cols[COL_NUM]; int cols[COL_NUM];
/* the 4 final stacks */ /* the 4 final stacks */
unsigned char stacks[SUITS]; int stacks[SUITS];
/** /**
* Card handling routines * Card handling routines
*/ */
unsigned char next_random_card( card_t *deck ) int next_random_card( card_t *deck )
{ {
unsigned char i,r; int i,r;
r = rb->rand()%(NUM_CARDS)+1; r = rb->rand()%(NUM_CARDS)+1;
i = 0; i = 0;
@ -709,7 +709,7 @@ unsigned char next_random_card( card_t *deck )
if( !deck[i].used ) r--; if( !deck[i].used ) r--;
} }
deck[i].used = 1; deck[i].used = true;
return i; return i;
} }
@ -719,7 +719,7 @@ unsigned char next_random_card( card_t *deck )
void solitaire_init( void ) void solitaire_init( void )
{ {
unsigned char c; int c;
int i, j; int i, j;
/* number of cards that are drawn on the remains' stack (by pressing F2) */ /* number of cards that are drawn on the remains' stack (by pressing F2) */
@ -740,8 +740,8 @@ void solitaire_init( void )
#define card deck[i*CARDS_PER_SUIT+j] #define card deck[i*CARDS_PER_SUIT+j]
card.suit = i; card.suit = i;
card.num = j; card.num = j;
card.known = 1; card.known = true;
card.used = 0; card.used = false;
card.next = NOT_A_CARD; card.next = NOT_A_CARD;
#undef card #undef card
} }
@ -765,7 +765,7 @@ void solitaire_init( void )
c = deck[c].next; c = deck[c].next;
} }
if( j < i ) if( j < i )
deck[c].known = 0; deck[c].known = false;
} }
} }
@ -801,10 +801,10 @@ void solitaire_init( void )
} }
/* find the column number in which 'card' can be found */ /* find the column number in which 'card' can be found */
unsigned char find_card_col( unsigned char card ) int find_card_col( int card )
{ {
int i; int i;
unsigned char c; int c;
if( card == NOT_A_CARD ) return NOT_A_COL; if( card == NOT_A_CARD ) return NOT_A_COL;
@ -833,7 +833,7 @@ unsigned char find_card_col( unsigned char card )
/* find the card preceding 'card' */ /* find the card preceding 'card' */
/* if it doesn't exist, return NOT_A_CARD */ /* if it doesn't exist, return NOT_A_CARD */
unsigned char find_prev_card( unsigned char card ){ int find_prev_card( int card ){
int i; int i;
for( i=0; i < NUM_CARDS; i++ ) for( i=0; i < NUM_CARDS; i++ )
@ -845,9 +845,9 @@ unsigned char find_prev_card( unsigned char card ){
} }
/* find the last card of a given column */ /* find the last card of a given column */
unsigned char find_last_card( unsigned char col ) int find_last_card( int col )
{ {
unsigned char c; int c;
if( col < COL_NUM ) if( col < COL_NUM )
{ {
@ -874,16 +874,16 @@ unsigned char find_last_card( unsigned char col )
enum move { MOVE_OK, MOVE_NOT_OK }; enum move { MOVE_OK, MOVE_NOT_OK };
enum move move_card( unsigned char dest_col, unsigned char src_card ) enum move move_card( int dest_col, int src_card )
{ {
/* the column on which to take src_card */ /* the column on which to take src_card */
unsigned char src_col; int src_col;
/* the last card of dest_col */ /* the last card of dest_col */
unsigned char dest_card; int dest_card;
/* the card under src_card */ /* the card under src_card */
unsigned char src_card_prev; int src_card_prev;
/* you can't move no card (at least, it doesn't have any consequence) */ /* you can't move no card (at least, it doesn't have any consequence) */
if( src_card == NOT_A_CARD ) return MOVE_NOT_OK; if( src_card == NOT_A_CARD ) return MOVE_NOT_OK;
@ -1047,7 +1047,7 @@ int bouncing_cards( void )
fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 8; fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 8;
} }
y = fp_y >> 8; y = fp_y >> 8;
draw_card( deck[j*CARDS_PER_SUIT+i], x, y, draw_card( &deck[j*CARDS_PER_SUIT+i], x, y,
false, false, false ); false, false, false );
rb->lcd_update_rect( x<0?0:x, y<0?0:y, rb->lcd_update_rect( x<0?0:x, y<0?0:y,
CARD_WIDTH, CARD_HEIGHT ); CARD_WIDTH, CARD_HEIGHT );
@ -1072,7 +1072,7 @@ int solitaire( void )
int i,j; int i,j;
int button, lastbutton = 0; int button, lastbutton = 0;
unsigned char c,h,prevcard; int c,h,prevcard;
int biggest_col_length; int biggest_col_length;
rb->srand( *rb->current_tick ); rb->srand( *rb->current_tick );
@ -1143,7 +1143,7 @@ int solitaire( void )
break; break;
} }
draw_card( deck[c], MARGIN+i*((LCD_WIDTH-2*MARGIN)/COL_NUM), draw_card( &deck[c], MARGIN+i*((LCD_WIDTH-2*MARGIN)/COL_NUM),
j+1, c == sel_card, c == cur_card, false ); j+1, c == sel_card, c == cur_card, false );
h = c; h = c;
@ -1170,7 +1170,7 @@ int solitaire( void )
if( c != NOT_A_CARD ) if( c != NOT_A_CARD )
{ {
draw_card( deck[c], draw_card( &deck[c],
LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1, LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1,
MARGIN, MARGIN,
c == sel_card, cur_col == STACKS_COL + i, false ); c == sel_card, cur_col == STACKS_COL + i, false );
@ -1189,7 +1189,7 @@ int solitaire( void )
{ {
/* gruik ! (we want to display a card back) */ /* gruik ! (we want to display a card back) */
deck[rem].known = false; deck[rem].known = false;
draw_card( deck[rem], MARGIN, MARGIN, false, false, false ); draw_card( &deck[rem], MARGIN, MARGIN, false, false, false );
deck[rem].known = true; deck[rem].known = true;
} }
@ -1211,7 +1211,7 @@ int solitaire( void )
prevcard = find_prev_card(prevcard); prevcard = find_prev_card(prevcard);
for( i = 0; i <= count_rem; i++ ) for( i = 0; i <= count_rem; i++ )
{ {
draw_card( deck[prevcard], j, draw_card( &deck[prevcard], j,
MARGIN, sel_card == prevcard, MARGIN, sel_card == prevcard,
cur_card == prevcard, i < count_rem ); cur_card == prevcard, i < count_rem );
prevcard = deck[prevcard].next; prevcard = deck[prevcard].next;
@ -1315,7 +1315,7 @@ int solitaire( void )
else else
{ {
cur_card = cols[cur_col]; cur_card = cols[cur_col];
while( deck[ cur_card].known == 0 while( !deck[ cur_card].known
&& deck[cur_card].next != NOT_A_CARD ) && deck[cur_card].next != NOT_A_CARD )
{ {
cur_card = deck[cur_card].next; cur_card = deck[cur_card].next;
@ -1352,7 +1352,7 @@ int solitaire( void )
cur_card = find_last_card( cur_col ); cur_card = find_last_card( cur_col );
} }
} while( deck[cur_card].next != NOT_A_CARD } while( deck[cur_card].next != NOT_A_CARD
&& deck[cur_card].known == 0 ); && !deck[cur_card].known );
break; break;
/* Try to put card under cursor on one of the stacks */ /* Try to put card under cursor on one of the stacks */
@ -1376,10 +1376,10 @@ int solitaire( void )
if( cur_card != NOT_A_CARD ) if( cur_card != NOT_A_CARD )
{ {
if( deck[cur_card].next == NOT_A_CARD if( deck[cur_card].next == NOT_A_CARD
&& deck[cur_card].known == 0 ) && !deck[cur_card].known )
{ {
/* reveal a hidden card */ /* reveal a hidden card */
deck[cur_card].known = 1; deck[cur_card].known = true;
} }
else if( cur_col == REM_COL && cur_rem == NOT_A_CARD ) else if( cur_col == REM_COL && cur_rem == NOT_A_CARD )
{ {