From 12d4aab48a098e8f58d51844bf5d0d552adccfc2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 17 Mar 2020 20:02:38 -0400 Subject: [PATCH] Tweaks --- .../world/blocks/logic/LogicExecutor.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 core/src/mindustry/world/blocks/logic/LogicExecutor.java diff --git a/core/src/mindustry/world/blocks/logic/LogicExecutor.java b/core/src/mindustry/world/blocks/logic/LogicExecutor.java new file mode 100644 index 0000000000..ef7eac06ea --- /dev/null +++ b/core/src/mindustry/world/blocks/logic/LogicExecutor.java @@ -0,0 +1,67 @@ +package mindustry.world.blocks.logic; + +import arc.math.*; + +public class LogicExecutor{ + Instruction[] instructions; + int[] registers = new int[256]; + int counter; + + void step(){ + if(instructions.length == 0) return; + + instructions[counter].exec(); + counter ++; + + //loop counter + if(counter >= instructions.length) counter = 0; + } + + interface Instruction{ + void exec(); + } + + class RegisterI{ + Op op; + short from, to; + int immediate; + + public void exec(){ + registers[to] = op.function.get(registers[from], immediate); + } + } + + static class ReadI{ + + } + + static class WriteI{ + + } + + enum Op{ + add("+", (a, b) -> a + b), + sub("-", (a, b) -> a - b), + mul("*", (a, b) -> a * b), + div("/", (a, b) -> a / b), + mod("%", (a, b) -> a % b), + pow("^", Mathf::pow), + shl(">>", (a, b) -> a >> b), + shr("<<", (a, b) -> a << b), + or("or", (a, b) -> a | b), + and("and", (a, b) -> a & b), + xor("xor", (a, b) -> a ^ b); + + final BinaryOp function; + final String symbol; + + Op(String symbol, BinaryOp function){ + this.symbol = symbol; + this.function = function; + } + } + + interface BinaryOp{ + int get(int a, int b); + } +}