public void AddBranch(Instruction instruction)
            {
                var branch = instruction.Branch;

                AddSeparator("[");
                AddKeyword(branch.Condition ? "TRUE" : "FALSE");
                AddSeparator("] ");

                if (branch.Kind == BranchKind.RFalse)
                {
                    AddKeyword("rfalse");
                }
                else if (branch.Kind == BranchKind.RTrue)
                {
                    AddKeyword("rtrue");
                }
                else // BranchKind.Address
                {
                    var targetAddress = instruction.Address + instruction.Length + branch.Offset - 2;
                    var targetLabel   = labelService.GetLabel(targetAddress);
                    if (targetLabel == null)
                    {
                        AddAddress(targetAddress);
                    }
                    else
                    {
                        AddLabel(targetLabel.Value);
                    }
                }
            }
Exemplo n.º 2
0
 /// <summary>
 /// Создание нулевого ярлыка
 /// </summary>
 public void CreateNoneLabel()
 {
     if (LabelService.LabelCountTest(DesktopService.GetDesktop(DesktopIndex).LabelCount))
     {
         LabelService.CreateLabel(false);
         Labels.Add(new LabelViewModel(LabelService.GetLabel(LabelService.GetLabelsCount() - 1), CreateViewModel()));
     }
     else
     {
         if (DesktopIndex == User.DesktopCount - 1)
         {
             DesktopService.CreateDesktop();
             User.DesktopCount++;
         }
         DesktopIndex++;
         LoadLabels();
         CreateNoneLabel();
         LeftButtonFlag = true;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Создание нового ярлыка
 /// </summary>
 /// <param name="labelPath"></param>
 /// <param name="task"></param>
 /// <param name="imagePath"></param>
 public void CreateLabel(String labelPath, String task, String imagePath)
 {
     LabelService.CreateLabel(task, imagePath, labelPath, true, LabelService.GetLabelsCount() - 1);
     Labels[DesktopService.GetDesktop(DesktopIndex).LabelCount] = new LabelViewModel(LabelService.GetLabel(LabelService.GetLabelsCount() - 1), User.Login,
                                                                                     User.Font, User.FontSize, User.FontBold, User.FontItalic, User.FontUnderline, User.FontStrikeout, User.FontColor);
     DesktopService.GetDesktop(DesktopIndex).LabelCount++;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Загрузка нулевого ярлыка на текущий рабочий стол
 /// </summary>
 public void LoadNoneLabel()
 {
     Labels.Add(new LabelViewModel(LabelService.GetLabel(LabelService.GetLabelsCount() - 1), CreateViewModel()));
 }
Exemplo n.º 5
0
        private void RefreshInstruction()
        {
            builder.Clear();

            var instruction = Instruction;

            if (instruction == null)
            {
                return;
            }

            if (instruction.OperandCount > 0)
            {
                if (instruction.Opcode.IsCall)
                {
                    var callOp = instruction.Operands[0];
                    if (callOp.Kind == OperandKind.Variable)
                    {
                        builder.AddVariable(Variable.FromByte((byte)callOp.Value));
                    }
                    else
                    {
                        var callAddress = callOp.Value;
                        if (storyService.IsStoryOpen)
                        {
                            builder.AddAddress(storyService.Story.UnpackRoutineAddress(callAddress));
                        }
                        else
                        {
                            builder.AddAddress(callAddress);
                        }
                    }

                    if (instruction.OperandCount > 1)
                    {
                        builder.AddSeparator(" (");
                        builder.AddOperands(instruction.Operands.Skip(1));
                        builder.AddSeparator(")");
                    }
                }
                else if (instruction.Opcode.IsJump)
                {
                    var jumpOffset  = (short)instruction.Operands[0].Value;
                    var jumpAddress = instruction.Address + instruction.Length + jumpOffset - 2;
                    int?label       = labelService.GetLabel(jumpAddress);
                    if (label == null)
                    {
                        builder.AddAddress(jumpAddress);
                    }
                    else
                    {
                        builder.AddLabel(label.Value);
                    }
                }
                else if (instruction.Opcode.IsFirstOpByRef)
                {
                    builder.AddByRefOperand(instruction.Operands[0]);

                    if (instruction.OperandCount > 1)
                    {
                        builder.AddSeparator(", ");
                        builder.AddOperands(instruction.Operands.Skip(1));
                    }
                }
                else
                {
                    builder.AddOperands(instruction.Operands);
                }
            }

            if (instruction.HasZText && storyService.IsStoryOpen)
            {
                var ztextBuilder = new StringBuilder(storyService.Story.ZText.ZWordsAsString(instruction.ZText, ZTextFlags.All));
                var ztext        = ztextBuilder.ToString();

                if (ztext.Length > 0)
                {
                    int lastIndex = ztext.Length;
                    do
                    {
                        lastIndex = ztext.LastIndexOfAny(new char[] { '\n', '\r', '\v', '\t', ' ' }, lastIndex - 1);
                        if (lastIndex < 0)
                        {
                            break;
                        }

                        // Replace the found character with a zero-width space or line separator to allow line breaking
                        // and insert replacement text.
                        char foundChar = ztext[lastIndex];

                        if (foundChar == ' ')
                        {
                            ztextBuilder[lastIndex] = '\u200b';
                        }
                        else if (lastIndex != ztext.Length - 1)
                        {
                            ztextBuilder[lastIndex] = '\u2028';
                        }

                        switch (foundChar)
                        {
                        case '\n':
                            ztextBuilder.Insert(lastIndex, "\\n");
                            break;

                        case '\r':
                            ztextBuilder.Insert(lastIndex, "\\r");
                            break;

                        case '\v':
                            ztextBuilder.Insert(lastIndex, "\\v");
                            break;

                        case '\t':
                            ztextBuilder.Insert(lastIndex, "\\t");
                            break;

                        case ' ':
                            ztextBuilder.Insert(lastIndex, "\u00b7");
                            break;
                        }
                    }while (lastIndex > 0);
                }

                builder.AddZText(ztextBuilder.ToString());
            }

            if (instruction.HasStoreVariable)
            {
                builder.AddSeparator(" -> ");
                builder.AddVariable(instruction.StoreVariable, @out: true);
            }

            if (instruction.HasBranch)
            {
                if (instruction.OperandCount > 0)
                {
                    builder.AddSeparator(" ");
                }

                builder.AddBranch(instruction);
            }

            update = false;
        }