src/macros.h
changeset 6201 bee01dc45e39
parent 6111 dc71fc907291
child 6491 00dc414c909d
equal deleted inserted replaced
6200:10efd7fb90d4 6201:bee01dc45e39
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file macros.h */
     2 
     4 
     3 #ifndef MACROS_H
     5 #ifndef MACROS_H
     4 #define MACROS_H
     6 #define MACROS_H
     5 
     7 
     6 /// Fetch n bits starting at bit s from x
     8 /* Fetch n bits starting at bit s from x */
     7 #define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1))
     9 #define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1))
     8 /// Set n bits starting at bit s in x to d
    10 /* Set n bits starting at bit s in x to d */
     9 #define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s)))
    11 #define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s)))
    10 /// Add i to the n bits starting at bit s in x
    12 /* Add i to the n bits starting at bit s in x */
    11 #define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s))))
    13 #define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s))))
    12 
    14 
    13 #ifdef min
    15 #ifdef min
    14 #undef min
    16 #undef min
    15 #endif
    17 #endif
    77 {
    79 {
    78 	return x ^= (T)1 << y;
    80 	return x ^= (T)1 << y;
    79 }
    81 }
    80 
    82 
    81 
    83 
    82 // checking more bits. Maybe unneccessary, but easy to use
    84 /* checking more bits. Maybe unneccessary, but easy to use */
    83 #define HASBITS(x,y) ((x) & (y))
    85 #define HASBITS(x,y) ((x) & (y))
    84 #define SETBITS(x,y) ((x) |= (y))
    86 #define SETBITS(x,y) ((x) |= (y))
    85 #define CLRBITS(x,y) ((x) &= ~(y))
    87 #define CLRBITS(x,y) ((x) &= ~(y))
    86 
    88 
    87 #define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START)
    89 #define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START)