public void SetInPlay(ShiftCommand command)
 {
     shiftCommand = command;
     beingPulled  = false;
     SnapToPosition();
     gameObject.SetActive(true);
 }
Exemplo n.º 2
0
 public void Reset()
 {
     _A       = 0;
     _B       = 0;
     _command = ShiftCommand.NON;
     _result  = 0;
 }
 public void OnEndDrag(PointerEventData eventData)
 {
     if (beingPulled)
     {
         ShiftCommand insertBefore = feed.GetBestInsertBeforeCard(this);
         beingPulled = false;
         OnReleaseRobotCommand?.Invoke(this.shiftCommand, insertBefore);
     }
 }
Exemplo n.º 4
0
 private void SendSynchFeed()
 {
     for (int idx = 0, l = instructionsFeed.Count; idx < l; idx++)
     {
         if (instructionsFeed[idx].LeftOrOn(idx))
         {
             instructionsFeed[idx] = ShiftCommand.MoveLeftFrom(instructionsFeed[idx].command, idx);
         }
     }
     OnSyncCommands?.Invoke(instructionsFeed, heldCard);
 }
Exemplo n.º 5
0
    IEnumerator <WaitForSeconds> WipeFeed()
    {
        heldCard = ShiftCommand.NothingHeld;

        //Remove what remains
        float flushSpeed = 0.1f;

        while (instructionsFeed.Count > 0)
        {
            ExecuteCommand(flushSpeed, false);
            yield return(new WaitForSeconds(flushSpeed));
        }
    }
Exemplo n.º 6
0
    private void UIRobotCommand_OnReleaseRobotCommand(ShiftCommand command, ShiftCommand insertBefore)
    {
        if (!robotAlive || reachedGoal)
        {
            return;
        }

        if (!heldCard.SameAs(command))
        {
            Debug.LogWarning(string.Format("Trying to insert card {0} that doesn't match what is held {1}.", command, heldCard));
            return;
        }
        bool         inserted  = false;
        ShiftCommand insertion = ShiftCommand.NothingHeld;
        int          position  = 0;

        for (int i = 0, l = instructionsFeed.Count; i < l; i++)
        {
            if (inserted)
            {
                instructionsFeed[i] = ShiftCommand.JumpRight(instructionsFeed[i]);
            }
            else
            {
                if (instructionsFeed[i].SameAs(insertBefore))
                {
                    insertion = ShiftCommand.Insert(instructionsFeed[i], command.command);
                    inserted  = true;
                    position  = i;
                }
            }
        }
        if (inserted)
        {
            instructionsFeed.Insert(position, insertion);
        }
        else
        {
            instructionsFeed.Add(ShiftCommand.MoveLeftFrom(command.command, instructionsFeed.Count));
        }

        heldCard = ShiftCommand.NothingHeld;
        OnSyncCommands?.Invoke(instructionsFeed, heldCard);
    }
Exemplo n.º 7
0
    private void DrawOne()
    {
        // Get new draw deck if needed
        if (drawDeck.Count == 0)
        {
            FlipTrash();
        }

        // Get the card
        RobotCommand cmd = RobotCommand.NONE;

        if (drawDeck.Count > 0)
        {
            cmd = drawDeck[0];
            drawDeck.RemoveAt(0);
        }

        // Insert card
        instructionsFeed.Add(ShiftCommand.MoveLeftFrom(cmd, instructionsFeed.Count));

        // Inform subscribers
        SendSynchFeed();
    }
Exemplo n.º 8
0
 private void UIRobotCommand_OnGrabRobotCommand(ShiftCommand command, ShiftCommand insertBefore)
 {
     if (reachedGoal || !robotAlive || !insertBefore.Held)
     {
         return;
     }
     for (int i = 0, l = instructionsFeed.Count; i < l; i++)
     {
         ShiftCommand card = instructionsFeed[i];
         if (card.SameAs(command))
         {
             instructionsFeed.RemoveAt(i);
             if (!heldCard.Empty)
             {
                 Debug.LogWarning(string.Format("Picking up a second card {0} while holding {1}", card, heldCard));
                 trashDeck.Add(heldCard.command);
             }
             heldCard = ShiftCommand.Pickup(card);
             SendSynchFeed();
             return;
         }
     }
     Debug.LogWarning(string.Format("Tried to pickup card {0}, but couldn't find it", command));
 }
 public bool SameAs(ShiftCommand other)
 {
     return(command == other.command &&
            position == other.position &&
            targetPosition == other.targetPosition);
 }
 public void ShiftLeft(ShiftCommand command)
 {
     shiftCommand = command;
     SnapToPosition();
 }
 public void ShiftRight(ShiftCommand command)
 {
     shiftCommand = command;
     SnapToPosition(true);
 }
 public static ShiftCommand Insert(ShiftCommand previousHolder, RobotCommand command)
 {
     return(new ShiftCommand(command, previousHolder.position, previousHolder.targetPosition));
 }
 public static ShiftCommand Remove(ShiftCommand previous)
 {
     return(new ShiftCommand(previous.command, previous.targetPosition, OUTSIDE_FEED));
 }
 public static ShiftCommand JumpRight(ShiftCommand previous)
 {
     return(new ShiftCommand(previous.command, previous.position + 1, previous.targetPosition + 1));
 }
 public static ShiftCommand Pickup(ShiftCommand previous)
 {
     return(new ShiftCommand(previous.command, previous.position, HELD));
 }
 public bool SameButShiftedRight(ShiftCommand other)
 {
     return(command == other.command &&
            other.targetPosition == position);
 }
 public bool SameButPickedUp(ShiftCommand other)
 {
     return(command == other.command &&
            other.targetPosition == HELD &&
            position == other.position);
 }
 public void SetInPlay(ShiftCommand command, Sprite sprite)
 {
     image.sprite = sprite;
     SetInPlay(command);
 }
Exemplo n.º 19
0
        private bool ParseLine()
        {
            //A Blank line in the source file
            if (_text.Length == 0)
            {
                _type        = SourceLineType.BLANK;
                _instruction = ARMInstruction.NOP;
                return(true);
            }

            //Line is a comment
            if (_text[0] == ';')
            {
                _type        = SourceLineType.COMMENT;
                _instruction = ARMInstruction.NOP;
                return(true);
            }

            //Remove any comments from the line
            string temp = _text;
            int    commentStartIndex = _text.IndexOf(';');

            if (commentStartIndex > 0)
            {
                temp = _text.Remove(commentStartIndex);
            }

            //Trim white space
            temp = temp.Trim();

            //Split into fields delimited by whitespace
            string[] fields = temp.Split(new char[] { ' ', '\t' });

            //Is the first field a directive, label, or instruction?
            // Refactor into bool isDirective(string)
            Array typeArray = Enum.GetValues(typeof(SourceLineType));

            foreach (SourceLineType st in typeArray)
            {
                if (fields[0].Equals(st.ToString()))
                {
                    _type        = st;
                    _label       = st.ToString();
                    _instruction = ARMInstruction.NOP;



                    //Ignore any text following a directive to the assembler
                    return(true);
                }
            }

            //MOV has 3 fields at this point:
            //MOV
            //R1,R1,LSL
            //#0x1


            //Only one field, not a directive so must be a label
            if (fields.Length == 1)
            {
                _label       = fields[0];
                _type        = SourceLineType.LABEL;
                _instruction = ARMInstruction.NOP;
                return(true);
            }

            //If there are 3 fields, the first must be a label, the second the instruction
            //and third operands, or theres is no label and a shift in the second field
            bool shiftOperation = false;

            foreach (string cmd in Enum.GetNames(typeof(ShiftCommand)))
            {
                if (fields[1].Contains(cmd))
                {
                    shiftOperation = true;
                    break;
                }
            }

            int instructionIndex = 0;
            int operandIndex     = 0;
            int shiftAmountIndex = 0;

            if (shiftOperation == true)
            {
                instructionIndex = 0;
                operandIndex     = 1;
                shiftAmountIndex = 2;
            }
            else
            {
                //If there are 2 fields, the first must be the instruction and the second the operand
                //int labelIndex = fields.Length > 2 ? 0 : -1;
                instructionIndex = fields.Length > 2 ? 1 : 0;
                operandIndex     = fields.Length > 2 ? 2 : 1;
            }

            //Store the label if present
            if ((fields.Length > 2) && (shiftOperation == false))
            {
                _label = fields[0];
            }

            //Instruction field contains instruction, condition code and set flags, or variable type
            bool  foundInstruction = false;
            Array opArray          = Enum.GetValues(typeof(ARMInstruction));

            foreach (ARMInstruction op in opArray)
            {
                if (fields[instructionIndex].StartsWith(op.ToString()))
                {
                    _type            = SourceLineType.CODE;
                    _instruction     = op;
                    foundInstruction = true;
                    break;
                }
            }

            if (foundInstruction)
            {
                int instrLength = _instruction.ToString().Length;
                int codeLength  = fields[instructionIndex].Length - instrLength;
                switch (codeLength)
                {
                case 0:
                {
                    //No Condition or set flags directive
                    _code     = ConditionCode.AL;
                    _setFlags = false;
                    break;
                }

                case 1:
                {
                    //Must be Set Flags directive only
                    if (fields[instructionIndex][instrLength + 1] == 'S')
                    {
                        _setFlags = true;
                    }
                    else
                    {
                        //Single character should only be S - all condition codes are two characters
                        _setFlags = false;
                        return(false);
                    }
                    _code = ConditionCode.AL;
                    break;
                }

                case 2:
                {
                    //Must be a condition code only
                    string codeString = fields[instructionIndex].Substring(instrLength, 2);
                    Array  ccArray    = Enum.GetValues(typeof(ConditionCode));
                    foreach (ConditionCode cc in ccArray)
                    {
                        if (codeString.Equals(cc.ToString()))
                        {
                            _code = cc;
                            break;
                        }
                    }
                    _setFlags = false;
                    break;
                }

                case 3:
                {
                    //Must be a condition code then set flags
                    string codeString = fields[instructionIndex].Substring(instrLength, 2);
                    Array  ccArray    = Enum.GetValues(typeof(ConditionCode));
                    foreach (ConditionCode cc in ccArray)
                    {
                        if (codeString.Equals(cc.ToString()))
                        {
                            _code = cc;
                            break;
                        }
                    }
                    if (fields[instructionIndex][instrLength + 2] == 'S')
                    {
                        _setFlags = true;
                    }
                    else
                    {
                        //Character following condition code must only be S
                        _setFlags = false;
                        return(false);
                    }
                    break;
                }

                default:
                {
                    //Invalid characters following instruction
                    _setFlags = false;
                    return(false);
                }
                }
            }
            else
            {
                //Not directive, label or instruction. Should be a variable definition.
                Array vtArray = Enum.GetValues(typeof(VariableType));
                foreach (VariableType vt in vtArray)
                {
                    if (fields[instructionIndex].Equals(vt.ToString()))
                    {
                        _type        = SourceLineType.VARIABLE;
                        _instruction = ARMInstruction.NOP;
                        _code        = ConditionCode.AL;
                        _setFlags    = false;
                    }
                }
            }

            //Final field contains operands, split by commas
            string[] operands = fields[operandIndex].Split(new char[] { ',' });

            //For a variable definition, store first operand only for now
            if (_type == SourceLineType.VARIABLE)
            {
                //Variable definitions typically have one operand, but some may have two to
                //perform operations with 64bit numbers

                //The type of the value to be assigned to the variable
                System.Globalization.NumberStyles type = System.Globalization.NumberStyles.HexNumber;
                string tempVar = operands[0];

                if (tempVar[0] == '&')
                {
                    type    = System.Globalization.NumberStyles.HexNumber;
                    tempVar = tempVar.Remove(0, 1);
                }
                else if (tempVar[0] == '#')
                {
                    type    = System.Globalization.NumberStyles.Number;
                    tempVar = tempVar.Remove(0, 1);
                }
                else if (tempVar.StartsWith("0x"))
                {
                    type    = System.Globalization.NumberStyles.HexNumber;
                    tempVar = tempVar.Remove(0, 2);
                }
                else
                {
                    type = System.Globalization.NumberStyles.Number;
                }

                //temp now contains only a value, hex or decimal
                _variable = UInt32.Parse(tempVar, type);

                //Call the manager to add this to the memory representation
                Manager.GetInstance().AddData(_label, _variable);
            }
            else
            {
                //Operands are for an instruction

                //SWI &11           Op1
                if (operands.Length == 1)
                {
                    //Also check for B, BL offset values

                    if (_instruction == ARMInstruction.SWI)
                    {
                        string val = operands[0];
                        //Remove '&'
                        _Op1 = val.Remove(0, 1);
                    }

                    if (_instruction == ARMInstruction.B)
                    {
                        //store label to branch to if condition met
                        _Op1 = operands[0];
                    }
                }
                else if (operands.Length == 2)
                {
                    if (_instruction == ARMInstruction.CMP)
                    {
                        string val = operands[0];
                        //Remove 'R'
                        val = val.Remove(0, 1);
                        _Rn = Int32.Parse(val, System.Globalization.NumberStyles.Number);
                    }
                    else
                    {
                        //First operand is always Rd (destination register)
                        string val = operands[0];
                        //Remove 'R'
                        val = val.Remove(0, 1);
                        _Rd = Int32.Parse(val, System.Globalization.NumberStyles.Number);
                    }
                    //Second operand will be stored in Op1 or Op2


                    //LDR R1,Value1     Rd, Op2
                    //LDR R2,Value1     Rd, Op2
                    //STR R1,Result     Rd, Op2
                    if (_instruction == ARMInstruction.LDR || _instruction == ARMInstruction.STR)
                    {
                        //Store label for op2
                        _Op2 = operands[1];
                    }
                    //MOV R1, R1        Rd, Op1  (register)
                    //MOV R1, #1234     Rd, Op1  (immediate)
                    //MVN R1, R1        Rd, Op1  (register)
                    //CMP R1, R2        Rn, Op1   (register)
                    else
                    {
                        //Need to store indication of register or immediate for analysis at run-time
                        _Op1 = operands[1];
                    }
                }
                else
                {
                    //First operand is always Rd (destination register)
                    string val = operands[0];
                    //Remove 'R'
                    val = val.Remove(0, 1);
                    _Rd = Int32.Parse(val, System.Globalization.NumberStyles.Number);


                    //ADD R1,R1,R2      Rd, Rn, Op1
                    if (_instruction == ARMInstruction.ADD)
                    {
                        string rnVal = operands[1];
                        rnVal = rnVal.Remove(0, 1);
                        _Rn   = Int32.Parse(rnVal, System.Globalization.NumberStyles.Number);

                        //Need to store indication of register or immediate for analysis at run-time
                        _Op1 = operands[2];
                    }
                    //MOV R1,R1,LSL #0x1    Rd,Op1
                    //MOV R1,R1,LSL R2    Rd,Op1 //Shift by amount in R2
                    if (_instruction == ARMInstruction.MOV)
                    {
                        //MOV with 3 operands - must be a shift
                        //shift op1 by the method in op2 by the amount in field[shiftIndex]
                        _shift = true;

                        //Destination Always a register - remove R indicator
                        //Register contains the number that we want to shift
                        string shiftRegVal = operands[1];
                        shiftRegVal    = shiftRegVal.Remove(0, 1);
                        _shiftRegister = Int32.Parse(shiftRegVal, System.Globalization.NumberStyles.Number);

                        //Operand 2 contains the type of shift
                        _shiftType = (ShiftCommand)Enum.Parse(typeof(ShiftCommand), operands[2]);

                        //Shift amount immediate (&,# or register?)
                        System.Globalization.NumberStyles type = System.Globalization.NumberStyles.HexNumber;
                        string tempVar = fields[shiftAmountIndex];
                        if (tempVar[0] == '&')
                        {
                            type    = System.Globalization.NumberStyles.HexNumber;
                            tempVar = tempVar.Remove(0, 1);
                        }
                        else if (tempVar[0] == '#')
                        {
                            if (fields[shiftAmountIndex].StartsWith("#0x"))
                            {
                                type    = System.Globalization.NumberStyles.HexNumber;
                                tempVar = tempVar.Remove(0, 3);
                            }
                            else
                            {
                                type    = System.Globalization.NumberStyles.Number;
                                tempVar = tempVar.Remove(0, 1);
                            }
                        }
                        else
                        {
                            type = System.Globalization.NumberStyles.Number;
                        }

                        //temp now contains only a value, hex or decimal
                        _shiftAmount = Int32.Parse(tempVar, type);

                        //Store shifter operand - if register then we use this value, otherwise use immediate value
                        //stored in shiftAmount
                        _Op1 = fields[shiftAmountIndex];
                    }

                    //Need special case for SWP - uses Rm, Rd, Rn...
                }
            }



            return(true);
        }
Exemplo n.º 20
0
 public ShiftTableDefinition Add(ShiftCommand command) =>
     new ShiftTableDefinition(base.Content.Union(new[] {command}));
Exemplo n.º 21
0
    private void RemoteController_OnSyncCommands(List <ShiftCommand> commands, ShiftCommand held)
    {
        int idC = 0;
        int lC  = commands.Count;

        for (int idF = 0, lF = feed.Count; idF < lF; idF++)
        {
            var command = commands[idC];
            var card    = feed[idF];
            // Card is where it should be, nothing to do
            if (card.shiftCommand.SameAs(command))
            {
                idC++;
                continue;
            }

            // Card has moved leftward
            if (card.shiftCommand.SameButShiftedLeft(command))
            {
                card.ShiftLeft(command);
                idC++;
                continue;
            }

            // Card needs to shift rightward
            if (card.shiftCommand.SameButShiftedRight(command))
            {
                card.ShiftRight(command);
                idC++;
                continue;
            }

            // Card is picked up
            if (card.shiftCommand.SameButPickedUp(held))
            {
                if (heldCard != null)
                {
                    cardsNotInPlay.Add(heldCard);
                    heldCard.NotInPlay();
                }

                heldCard = card;
                feed.RemoveAt(idF);
                idF--;
                lF--;
                idC++;
                continue;
            }

            // Actually previously held card is now here
            if (heldCard != null && command.command == heldCard.shiftCommand.command)
            {
                heldCard.SetInPlay(command);
                feed.Insert(idF, heldCard);
                heldCard = null;
                lF++;
                continue;
            }

            // Remove card because not in play
            if (idF > 0)
            {
                Debug.LogWarning(string.Format("Lost track of UI Card {0}, this should not happen", card));
            }
            card.NotInPlay();
            cardsNotInPlay.Add(card);
            feed.RemoveAt(idF);
            idF--;
            lF--;
            continue;
        }

        if (idC != feed.Count)
        {
            Debug.LogWarning(string.Format("We have a gap in the feed, it should be {0} long, but is {1}", idC, feed.Count));
        }

        // Fillout new cards
        while (idC < lC)
        {
            ShiftCommand command = commands[(int)idC];
            if (!command.Empty)
            {
                var card = GetInactiveOrSpawn();
                card.SetInPlay(command, cardSprites[(int)command.command]);
                feed.Add(card);
            }
            idC++;
        }

        //Deal with held card
        if (held.Empty && heldCard != null)
        {
            heldCard.NotInPlay();
            cardsNotInPlay.Add(heldCard);
            heldCard = null;
        }
        else if (!held.Empty && heldCard != null && !held.SameAs(heldCard.shiftCommand))
        {
            Debug.LogWarning(string.Format("Held card is wrong, this should not happen, expected {0}, but found {1} (updating)", held, heldCard.shiftCommand));
            heldCard.SetInPlay(held, cardSprites[(int)held.command]);
        }
    }
Exemplo n.º 22
0
 public ShiftTableDefinition TryAdd(CoreTransition transition, IDictionary<Core, int> coreToIndex) =>
     transition.Symbol is Terminal ? this.Add(ShiftCommand.Of(transition, coreToIndex)) : this;
 public bool SameButShiftedLeft(ShiftCommand other)
 {
     return(command == other.command &&
            targetPosition == other.position);
 }
Exemplo n.º 24
0
        private void opMov(int rd, string op1, bool shift, int shiftAmount, ShiftCommand shiftType, int shiftRegister)
        {
            if (shift == false)
            {
                //Rd <--- Op1
                //Check op1 is reg or immediate or label...
                if (op1[0].Equals('R'))
                {
                    string val = op1.Remove(0, 1);
                    _registers[rd] = _registers[Int32.Parse(val)];
                    if (RegisterUpdated != null)
                    {
                        RegisterUpdated(rd);
                    }
                }
                else
                {
                    //assume is '#' - base 10 number
                    string val = op1.Remove(0, 1);
                    _registers[rd] = UInt32.Parse(val);
                    if (RegisterUpdated != null)
                    {
                        RegisterUpdated(rd);
                    }
                }
            }
            else
            {
                //If Shift Register, then set shift _bs.B to amount in register
                if (op1[0].Equals('R'))
                {
                    string val = op1.Remove(0, 1);
                    _bs.B = (int)_registers[Int32.Parse(val)];
                }
                else
                {
                    //Immediate - use shiftAmount already set
                    _bs.B = shiftAmount;
                }

                //Put values in barrel shifter
                _bs.A = _registers[shiftRegister];
                ///TODO: Animation from register to ALU

                _bs.Command = shiftType;

                //Perform the Shift...
                _bs.Calculate();

                //Copy result into destination register - other registers reamin unchanged
                if (RegisterChangedFromBsResult != null)
                {
                    RegisterChangedFromBsResult(rd);
                }
                _registers[rd] = _bs.Result;
                if (RegisterUpdated != null)
                {
                    RegisterUpdated(rd);
                }
            }
        }