From 7912a69246ff09e6544e1bde2dd85f55e34cc9ed Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 15 Feb 2025 15:44:04 +0000 Subject: [PATCH] Add: [NewGRF] More basic bitwise operators for varact2. Adds ANDN, NAND, NOR and XNOR operators for whoever might find them useful. --- src/newgrf_spritegroup.cpp | 4 ++++ src/newgrf_spritegroup.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index a8a081c0c2..b0ccef5859 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -175,6 +175,10 @@ static U EvalAdjustT(const DeterministicSpriteGroupAdjust &adjust, ScopeResolver case DSGA_OP_SHL: return (uint32_t)(U)last_value << ((U)value & 0x1F); // Same behaviour as in ParamSet, mask 'value' to 5 bits, which should behave the same on all architectures. case DSGA_OP_SHR: return (uint32_t)(U)last_value >> ((U)value & 0x1F); case DSGA_OP_SAR: return (int32_t)(S)last_value >> ((U)value & 0x1F); + case DSGA_OP_ANDN: return last_value & ~value; + case DSGA_OP_NAND: return ~(last_value & value); + case DSGA_OP_NOR: return ~(last_value | value); + case DSGA_OP_XNOR: return ~(last_value ^ value); default: return value; } } diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 6b49d17040..3e69329734 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -141,6 +141,10 @@ enum DeterministicSpriteGroupAdjustOperation : uint8_t { DSGA_OP_SHL, ///< a << b DSGA_OP_SHR, ///< (unsigned) a >> b DSGA_OP_SAR, ///< (signed) a >> b + DSGA_OP_ANDN, ///< x & ~y + DSGA_OP_NAND, ///< ~(x & y) + DSGA_OP_NOR, ///< ~(x | y) + DSGA_OP_XNOR, ///< ~(x ^ y) };