From 870127fd307c1ac46c55cea2bd28a7301c54ca96 Mon Sep 17 00:00:00 2001 From: tron Date: Sun, 22 May 2005 07:12:09 +0000 Subject: (svn r2358) Add macros for getting (GB) and setting (SB) a range of bits Use them exemplarily to prettify (Get|Set)Tile(Type|Height) --- macros.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'macros.h') diff --git a/macros.h b/macros.h index 81eae88cb..eb11b8a5c 100644 --- a/macros.h +++ b/macros.h @@ -151,4 +151,9 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a } #endif +// Fetch count bits starting at bit start from value +#define GB(value, start, count) (((value) >> (start)) & ((1 << (count)) - 1)) +// Set count bits in value starting at bit start to data +#define SB(value, start, count, data) ((value) = ((value) & ~(((1 << (count)) - 1) << (start))) | ((data) << (start))) + #endif /* MACROS_H */ -- cgit v1.2.3-54-g00ecf