summaryrefslogtreecommitdiff
path: root/macros.h
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-07-30 09:29:20 +0000
committertron <tron@openttd.org>2005-07-30 09:29:20 +0000
commit9b676d2cd992726223c39fd46db97994685df13f (patch)
tree4e9f7fae006fcf7f0433f1e421bad805c1c2013f /macros.h
parent79620db9be3e0cf8e773558ccd8b0fa399fe90d7 (diff)
downloadopenttd-9b676d2cd992726223c39fd46db97994685df13f.tar.xz
(svn r2758) Add the AB() macro to add a value to a bit range and use it in a few places, also make use of GB and SB nearby
Diffstat (limited to 'macros.h')
-rw-r--r--macros.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/macros.h b/macros.h
index a335b05e3..1232005cd 100644
--- a/macros.h
+++ b/macros.h
@@ -146,8 +146,10 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
/// Fetch n bits starting at bit s from x
#define GB(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1))
-/// Set n bits in x starting at bit s to d
+/// Set n bits starting at bit s in x to d
#define SB(x, s, n, d) ((x) = ((x) & ~(((1 << (n)) - 1) << (s))) | ((d) << (s)))
+/// Add i to the n bits starting at bit s in x
+#define AB(x, s, n, i) ((x) = ((x) & ~(((1 << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1 << (n)) - 1) << (s))))
/**
* ROtate x Left/Right by n (must be >= 0)