From 79e25b0889e78a9130054b3ee58ddacd524c371e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 19 Oct 2023 22:08:39 +0200 Subject: [PATCH] feat: Added bitwise shift left/right data processor nodes --- plugins/builtin/romfs/lang/en_US.json | 5 ++ .../source/content/data_processor_nodes.cpp | 59 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 233290000a2a5..6eb84ee140fb1 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -282,6 +282,10 @@ "hex.builtin.nodes.bitwise.not.header": "Bitwise NOT", "hex.builtin.nodes.bitwise.or": "OR", "hex.builtin.nodes.bitwise.or.header": "Bitwise OR", + "hex.builtin.nodes.bitwise.shift_left": "Shift Left", + "hex.builtin.nodes.bitwise.shift_left.header": "Bitwise Shift Left", + "hex.builtin.nodes.bitwise.shift_right": "Shift Right", + "hex.builtin.nodes.bitwise.shift_right.header": "Bitwise Shift Right", "hex.builtin.nodes.bitwise.swap": "Reverse", "hex.builtin.nodes.bitwise.swap.header": "Reverse bits", "hex.builtin.nodes.bitwise.xor": "XOR", @@ -321,6 +325,7 @@ "hex.builtin.nodes.common.input.b": "Input B", "hex.builtin.nodes.common.output": "Output", "hex.builtin.nodes.common.width": "Width", + "hex.builtin.nodes.common.amount": "Amount", "hex.builtin.nodes.constants": "Constants", "hex.builtin.nodes.constants.buffer": "Buffer", "hex.builtin.nodes.constants.buffer.header": "Buffer", diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index e4e1dc2e3079d..2c91b29a8444f 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -376,6 +376,63 @@ namespace hex::plugin::builtin { } }; + class NodeBitwiseShiftLeft : public dp::Node { + public: + NodeBitwiseShiftLeft() : Node("hex.builtin.nodes.bitwise.shift_left.header", { + dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), + dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.amount"), + dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") + }) { } + + void process() override { + const auto &input = this->getBufferOnInput(0); + const auto &amount = this->getIntegerOnInput(1); + + std::vector output = input; + + for (u32 i = 0; i < amount; i += 1) { + u8 prevByte = 0x00; + for (auto &byte : output) { + auto startValue = byte; + + byte <<= 1; + byte |= (prevByte & 0x80) >> 7; + prevByte = startValue; + } + } + + this->setBufferOnOutput(2, output); + } + }; + + class NodeBitwiseShiftRight : public dp::Node { + public: + NodeBitwiseShiftRight() : Node("hex.builtin.nodes.bitwise.shift_left.header", { + dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), + dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.amount"), + dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") + }) { } + + void process() override { + const auto &input = this->getBufferOnInput(0); + const auto &amount = this->getIntegerOnInput(1); + + std::vector output = input; + + for (u32 i = 0; i < amount; i += 1) { + u8 prevByte = 0x00; + for (auto &byte : output | std::views::reverse) { + auto startValue = byte; + byte >>= 1; + byte |= (prevByte & 0x01) << 7; + prevByte = startValue; + } + } + + this->setBufferOnOutput(2, output); + } + }; + class NodeBitwiseADD : public dp::Node { public: NodeBitwiseADD() : Node("hex.builtin.nodes.bitwise.add.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { } @@ -1325,6 +1382,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.or"); ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.xor"); ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.not"); + ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.shift_left"); + ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.shift_right"); ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.swap"); ContentRegistry::DataProcessorNode::add("hex.builtin.nodes.decoding", "hex.builtin.nodes.decoding.base64");