public void setOutput(int port, int value) { for (int i = 0; i < 3; i++) { SetOutput setOutput = new SetOutput(ip, port, value); if (setOutput.isOk) { break; } Thread.Sleep(delay); } }
public void Execute(Snapshot snapshot = null) { if (snapshot == null) { NextPointer = 0; BaseAddress = 0; additionnalMemory.Clear(); } else { buffer = snapshot.Buffer.ToArray(); additionnalMemory = snapshot.AdditionnalMemory.ToDictionary(x => x.Key, x => x.Value); BaseAddress = snapshot.BaseAddress; NextPointer = snapshot.NextPointer; } var theEnd = false; while (!theEnd) { Watch?.Invoke(DebugOutput); var instructionPointer = NextPointer; var opcode = (int)Memory[NextPointer++]; var instruction = (OpCode)(opcode % 100); switch (instruction) { case OpCode.END: theEnd = true; Log?.Invoke($"{instructionPointer,6} 99 END"); break; case OpCode.ADD: { NextPointer = RunInstruction_2_1(opcode, Memory, instructionPointer, NextPointer, (b1, b2) => b1 + b2); break; } case OpCode.MUL: { NextPointer = RunInstruction_2_1(opcode, Memory, instructionPointer, NextPointer, (b1, b2) => b1 * b2); break; } case OpCode.TEQ: { NextPointer = RunInstruction_2_1(opcode, Memory, instructionPointer, NextPointer, (b1, b2) => b1 == b2?1:0); break; } case OpCode.TLT: { NextPointer = RunInstruction_2_1(opcode, Memory, instructionPointer, NextPointer, (b1, b2) => b1 < b2?1:0); break; } case OpCode.JNZ: { NextPointer = RunInstruction_2_J(opcode, Memory, instructionPointer, NextPointer, (b1) => b1 != 0); break; } case OpCode.JZE: { NextPointer = RunInstruction_2_J(opcode, Memory, instructionPointer, NextPointer, (b1) => b1 == 0); break; } case OpCode.INP: { NextPointer = RunInstruction_0_1(opcode, Memory, instructionPointer, NextPointer, GetNextInput); break; } case OpCode.OUT: { NextPointer = RunInstruction_1_0(opcode, Memory, instructionPointer, NextPointer, x => SetOutput?.Invoke(x)); break; } case OpCode.ADB: { NextPointer = RunInstruction_1_0(opcode, Memory, instructionPointer, NextPointer, x => BaseAddress += x); break; } default: throw new Exception($"Invalid opcode : {opcode}"); } } }