From 619ec9cab33d944be272e075bcc57b5c86e39e1b Mon Sep 17 00:00:00 2001 From: gumi Date: Tue, 12 May 2020 18:16:23 -0400 Subject: add bitwise abstraction functions --- npc/functions/bitwise.txt | 23 +++++++++++++++++++++++ npc/scripts.conf | 1 + 2 files changed, 24 insertions(+) create mode 100644 npc/functions/bitwise.txt (limited to 'npc') diff --git a/npc/functions/bitwise.txt b/npc/functions/bitwise.txt new file mode 100644 index 00000000..58ad8b5c --- /dev/null +++ b/npc/functions/bitwise.txt @@ -0,0 +1,23 @@ +/** + * gets a bitmasked value in a variable + * + * @arg 0 - the variable + * @arg 1 - mask + * @arg 2 - shift + */ +function script bitwise_get { + return (getarg(0) & getarg(1)) >> getarg(2, 0); +} + +/** + * sets a bitmasked value in a variable + * + * @arg 0 - the target variable + * @arg 1 - mask + * @arg 2 - shift + * @arg 3 - new value + * @return a reference to the variable + */ +function script bitwise_set { + return set(getarg(0), (getarg(0) & ~(getarg(1))) | (getarg(3, 0) << getarg(2, 0))); +} diff --git a/npc/scripts.conf b/npc/scripts.conf index d15eaef7..f0e48c98 100644 --- a/npc/scripts.conf +++ b/npc/scripts.conf @@ -13,6 +13,7 @@ "npc/functions/math.txt", "npc/functions/warp.txt", "npc/functions/gender.txt", +"npc/functions/bitwise.txt", // Misc functions "npc/functions/main.txt", -- cgit v1.2.3-70-g09d2