Beispiel #1
0
            protected override void RunInstruction(ComputerInstruction instruction, ArgumentInfo arg0, ArgumentInfo arg1, ref int instructionOffset)
            {
                switch (instruction.Operator)
                {
                case ComputerOperator.Send:
                    long message = arg0.Value;
                    LinkedProgram.messageQueue.Enqueue(message);
                    HaltRequested = ValueSent?.Invoke(message) ?? false;
                    break;

                case ComputerOperator.Receive:
                    bool received = messageQueue.TryDequeue(out long value);
                    if (!received)
                    {
                        // Reattempt receiving the value when continuing execution, halt until rerun
                        instructionOffset = 0;
                        HaltRequested     = true;
                        break;
                    }

                    Registers[arg0.RegisterName] = value;
                    break;

                default:
                    base.RunInstruction(instruction, arg0, arg1, ref instructionOffset);
                    return;
                }
            }
Beispiel #2
0
        protected override void RunInstruction(ComputerInstruction instruction, ArgumentInfo arg0, ArgumentInfo arg1, ref int instructionOffset)
        {
            switch (instruction.Operator)
            {
            case ComputerOperator.Send:
                lastSound = arg0.Value32;
                break;

            case ComputerOperator.Add:
                Registers[arg0.RegisterName] += arg1.Value;
                break;

            case ComputerOperator.Subtract:
                Registers[arg0.RegisterName] -= arg1.Value;
                break;

            case ComputerOperator.Multiply:
                Registers[arg0.RegisterName] *= arg1.Value;
                break;

            case ComputerOperator.Modulo:
                Registers[arg0.RegisterName] %= arg1.Value;
                break;

            case ComputerOperator.Receive:
                if (lastSound is 0)
                {
                    break;
                }
                HaltRequested = SoundRecoveredHandler(lastSound);
                break;

            default:
                base.RunInstruction(instruction, arg0, arg1, ref instructionOffset);
                return;
            }
        }
Beispiel #3
0
 protected override void LoadState()
 {
     instructions = ParsedFileLines(s => ComputerInstruction.Parse(s));
 }