Пример #1
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var            lbi  = (ListBoxItem)value;
            AsmListBoxItem item = (AsmListBoxItem)lbi.Content;

            AddressItem addressItem = item as AddressItem;
            string      operand     = addressItem.Operand ?? "";

            Console.WriteLine(operand);

            int padding;

            operand = int.TryParse(parameter.ToString(), out padding) ? operand.PadRight(padding) : operand;

            AsmLine asmLine = item.AsmLine;

            if (asmLine.HasOperandArgument())
            {
                if (asmLine.OperandArgument.HasLabel())
                {
                    if (!(asmLine.IsJumpOperation() || asmLine.IsBranchOperation() || asmLine.Opcode == "rts"))
                    {
                        string label = asmLine.OperandArgument.Label;
                        operand = operand.Replace(label, "<Run Foreground=\"DarkOrange\">" + label + "</Run>");
                    }
                }
            }


            return(operand.Replace("&", "&amp;"));
        }
Пример #2
0
        private void OnPeekLabel(string label)
        {
            _lastItem = listBox.SelectedItem as AsmListBoxItem;
            int address = AsmReader.AddressByLabelDictionary()[label];

            // TODO: scrolling bedeutet eigentlich immer: Refresh() afterwards, oder?
            ScrollToAddress(address, ScrollMode.ScrollToCenterOfView);
            listBox.Refresh();
        }
Пример #3
0
        public void ScrollToAddress(int address, ScrollMode scrollMode = ScrollMode.Default)
        {
            AsmLine asmLine;

            if (!AsmReader.AsmLineByAddressDictionary().TryGetValue(address, out asmLine))
            {
                return;
            }
            AsmListBoxItem scrollItem = _itemsByAsmLine[asmLine];

            ScrollToItem(scrollItem, scrollMode);
        }
Пример #4
0
        private void GotoPreviousLabel()
        {
            AsmListBoxItem item    = listBox.SelectedItem as AsmListBoxItem;
            AsmLine        asmLine = item.AsmLine;
            int            index   = asmLine.Index - 1;

            while (index >= 0)
            {
                asmLine = AsmReader._asmLines[index];
                if (asmLine.IsMemoryMapped() && asmLine.HasLabel())
                {
                    ScrollToAddress(asmLine.DecimalAddress, ScrollMode.Smooth);
                    return;
                }
                index--;
            }
        }
Пример #5
0
        private void listBox_KeyDown(object sender, KeyEventArgs e)
        {
            bool IsShiftKey   = Keyboard.Modifiers.HasFlag(ModifierKeys.Shift);
            bool IsAltKey     = Keyboard.Modifiers.HasFlag(ModifierKeys.Alt);
            bool IsControlKey = Keyboard.Modifiers.HasFlag(ModifierKeys.Control);

            if (IsShiftKey && IsAltKey && IsControlKey)
            {
                AsmListBoxItem item = (AsmListBoxItem)listBox.SelectedItem;
                if (item is AddressItem)
                {
                    AddressItem addressItem = (AddressItem)item;
                    MessageBox.Show(addressItem.Address);
                    int addr = AsmReader.AddressByLabelDictionary()["chooseControls"];
                    ScrollToAddress(addr);
                }
            }
        }
Пример #6
0
        public void PopulateListbox()
        {
            int itemIndex = 0;

            foreach (AsmLine asmLine in AsmReader._asmLines)
            {
                AsmListBoxItem newItem = null;

                switch (asmLine.LineType)
                {
                case AsmLineType.CommentLine:
                    newItem = new CommentItem()
                    {
                        CommentLine = asmLine.Comment,
                    };
                    break;

                case AsmLineType.OpcodeLine:
                case AsmLineType.DirectiveLine:
                    newItem = new AddressItem()
                    {
                        Address         = Padded(asmLine.Address, 5),
                        Bytes           = Padded(asmLine.Bytes, 15),
                        Label           = Padded(asmLine.Label, 20),
                        Comment         = Padded(asmLine.Comment, 60),
                        CommentColor    = "Gray",
                        EvaluationColor = "Blue",
                    };
                    break;

                default:
                    continue;
                }
                AddressItem addressItem = newItem as AddressItem;

                switch (asmLine.LineType)
                {
                case AsmLineType.OpcodeLine:
                    addressItem.Instruction      = Padded(asmLine.Opcode, 6);
                    addressItem.Operand          = Padded(asmLine.OperandArgument.Operand, 40, paddedOperand => ColorOpcodeOperand(asmLine, paddedOperand));
                    addressItem.InstructionColor = InstructionColor(asmLine);
                    break;

                case AsmLineType.DirectiveLine:
                    addressItem.Instruction      = Padded(asmLine.Directive, 6);
                    addressItem.Operand          = Padded(asmLine.DirectiveArgument.Operand, 40);
                    addressItem.InstructionColor = "DarkMagenta";
                    break;
                }

                Debug.Assert(newItem != null);

                newItem.AsmLine = asmLine;
                _items.Add(newItem);
                _itemsByAsmLine.Add(asmLine, newItem);

                newItem.ItemIndex = itemIndex;

                if (itemIndex % 20 == 0)
                {
                    newItem.LineStatus = "<Run Foreground=\"Red\">abcd</Run>";
                }

                itemIndex++;
            }
        }
Пример #7
0
        private AsmLine SelectedAsmLine()
        {
            AsmListBoxItem item = listBox.SelectedItem as AsmListBoxItem;

            return(item.AsmLine);
        }
Пример #8
0
        private void ScrollToItem(AsmListBoxItem scrollItem, ScrollMode scrollMode)
        {
            if (scrollMode == ScrollMode.Default)
            {
                scrollMode = _defaultScrollMode;
            }

            switch (scrollMode)
            {
            case ScrollMode.ScrollIntoView:
                listBox.ScrollIntoView(scrollItem);
                break;

            case ScrollMode.ScrollToCenterOfView:
                listBox.ScrollToCenterOfView(scrollItem);
                break;

            case ScrollMode.Smooth:

                try {
                    SuspendKeyboardShortcuts();

                    var            scrollViewer   = UIHelpers.GetScrollViewer(listBox) as ScrollViewer;
                    AsmListBoxItem firstItem      = listBox.FirstVisibleItem() as AsmListBoxItem;
                    int            firstItemIndex = firstItem.ItemIndex;

                    int            lastItemIndex = firstItemIndex + (int)scrollViewer.ViewportHeight;
                    AsmListBoxItem lastItem      = _items[lastItemIndex];

                    int  scrollIndex    = scrollItem.ItemIndex;
                    bool alreadyVisible = scrollIndex >= firstItemIndex && scrollIndex <= lastItemIndex;
                    if (!alreadyVisible)
                    {
                        int offsets = scrollIndex - firstItemIndex;
                        int count   = Math.Abs(offsets);

                        int originalStep;
                        if (count < 20)
                        {
                            originalStep = 1;
                        }
                        else if (count < 100)
                        {
                            originalStep = 2;
                        }
                        else if (count < 200)
                        {
                            originalStep = 3;
                        }
                        else if (count < 500)
                        {
                            originalStep = 5;
                        }
                        else if (count < 1000)
                        {
                            originalStep = 10;
                        }
                        else
                        {
                            originalStep = 20;
                        }

                        originalStep = offsets > 0 ? originalStep : -originalStep;

                        int step = originalStep;
                        for (int offset = 0; Math.Abs(offset) < Math.Abs(offsets); offset += step)
                        {
                            if (Math.Abs(step) > 1)
                            {
                                double share = 1 - (double)offset / (double)offsets;
                                step = (int)(share * originalStep);

                                // make sure we always have a valid step
                                if (step == 0)
                                {
                                    step = originalStep / Math.Abs(originalStep);
                                }
                                //Console.WriteLine( step );
                            }
                            scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + step);
                            this.DoEvents();
                        }
                        listBox.ScrollIntoView(scrollItem);

                        /*
                         * // TODO: remove "flicker"
                         * for (int offset = 0; offset < 10; offset++) {
                         *  scrollViewer.ScrollToVerticalOffset( scrollViewer.VerticalOffset - 1 );
                         *  this.DoEvents();
                         * }
                         */
                    }
                } finally {
                    ResumeKeyboardShortcuts();
                }
                break;
            }
            listBox.FocusListBoxItem(scrollItem);
        }