Example #1
0
File: Swp.cs Project: embix/TIS100
 public IOperationResult Execute(AssemblyChip chip)
 {
     var swap = chip.Acc.Read();
      chip.Acc.Write(chip.Bak.Read());
      chip.Bak.Write(swap);
      return OperationResult.Advance;
 }
Example #2
0
File: Jgz.cs Project: embix/TIS100
        public IOperationResult Execute(AssemblyChip chip)
        {
            if (chip.Acc.Read().ToInteger() > 0) {
                 chip.Ip = Ip;
                 return OperationResult.Jump;
             }

             return OperationResult.Advance;
        }
Example #3
0
File: Sub.cs Project: embix/TIS100
        public IOperationResult Execute(AssemblyChip chip)
        {
            var source = Source.Reference(chip);

             if (source.IsReadyToRead()) {
                 chip.Acc.Write(chip.Acc.Read() - source.Read());
                 return OperationResult.Advance;
             }
             return OperationResult.Block;
        }
Example #4
0
File: Jro.cs Project: embix/TIS100
        public IOperationResult Execute(AssemblyChip chip)
        {
            var rw = Source.Reference(chip);

             if (rw.IsReadyToRead()) {
                 chip.Ip += rw.Read().ToInteger();
                 return OperationResult.Jump;
             }

             return OperationResult.Block;
        }
Example #5
0
File: Mov.cs Project: embix/TIS100
        public IOperationResult Execute(AssemblyChip chip)
        {
            var source = Source.Reference(chip);
            var destination = Destination.Reference(chip);

            if (state == MovState.Reading && source.IsReadyToRead()) {
                destination.Write(source.Read());
                state = MovState.Writing;
            }

            if (state == MovState.Writing && destination.IsDoneWriting()) {
                state = MovState.Reading;
                return OperationResult.Advance;
            }

            return OperationResult.Block;
        }
Example #6
0
        public void Sub_Basic_Works()
        {
            var board = new Board();
            var chip = new AssemblyChip();
            var input = new InputRW(new List<int>() { 1, 2, 4, 3 });
            var output = new OutputRW();

            chip.Operations = new List<IOperation>() {
                new Mov(new ConnectionRef("UP"), new ConnectionRef("ACC")),
                new Sub(new ConnectionRef("UP")),
                new Mov(new ConnectionRef("ACC"), new ConnectionRef("DOWN")),
            };

            board.Install(chip, new Point(0, 0));
            chip.Connections["UP"] = input;
            chip.Connections["DOWN"] = output;

            board.ExecuteUntilBlocked();

            Assert.AreEqual("-1, 1", output.ToString());
        }
Example #7
0
        private void AssertAddOutputMatches(List<int> inQueue, List<int> expectedOutQueue)
        {
            var board = new Board();
            var chip = new AssemblyChip();
            var input = new InputRW(inQueue);
            var output = new OutputRW();

            chip.Operations = new List<IOperation>
            {
                new Mov(UP, ACC),
                new Add(UP),
                new Mov(ACC, DOWN)
            };

            board.Install(chip, new Point(0, 0));
            chip.Connections[UP.RefName] = input;
            chip.Connections[DOWN.RefName] = output;

            board.ExecuteUntilBlocked();
            var expectedOutput = expectedOutQueue
                .Select(a => a.ToString())
                .Aggregate((a, b) => a + ", " + b);
            Assert.AreEqual(expectedOutput, output.ToString());
        }
Example #8
0
File: Neg.cs Project: embix/TIS100
 public IOperationResult Execute(AssemblyChip chip)
 {
     chip.Acc.Write(-chip.Acc.Read());
      return OperationResult.Advance;
 }
Example #9
0
File: Jmp.cs Project: embix/TIS100
 public IOperationResult Execute(AssemblyChip chip)
 {
     chip.Ip = Ip;
     return OperationResult.Jump;
 }
Example #10
0
 protected void NormalizeIp(AssemblyChip chip)
 {
     if (chip.Ip < 0 || chip.Ip >= chip.Operations.Count) {
         chip.Ip = 0;
     }
 }
Example #11
0
 public abstract void Apply(AssemblyChip chip);
Example #12
0
 public override void Apply(AssemblyChip chip)
 {
     chip.Status = ChipStatus.Executing;
     NormalizeIp(chip);
 }
Example #13
0
 public override void Apply(AssemblyChip chip)
 {
     chip.Status = ChipStatus.Blocked;
 }