Beispiel #1
0
        private void PaintMemoryView(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            byte[] b = new byte[4] {
                0, 0, 0, 0
            };

            for (uint i = (uint)positionScrollBar.Value, p = 0; p < memoryPanel.Height && i < PropellerCPU.TOTAL_MEMORY; i += 4, p += (uint)MonoFont.Height)
            {
                if (Chip != null)
                {
                    for (uint bi = 0; bi < 4; bi++)
                    {
                        b[bi] = Chip.DirectReadByte(i + bi);
                    }
                }

                ushort s1 = (ushort)(b[0] | (b[1] << 8));
                ushort s2 = (ushort)(b[2] | (b[3] << 8));

                int i1 = (int)(s1 | (s2 << 16));

                g.FillRectangle(SystemBrushes.Control, 0, p, memoryPanel.Width, p + MonoFont.Height);
                g.DrawString(
                    String.Format("{0:X4}:  {1:X2} {2:X2} {3:X2} {4:X2}  : u16={5} {6}, s16={7} {8}, s32={9:d}",
                                  i, b[0], b[1], b[2], b[3], s1, s2, (short)s1, (short)s2, i1), MonoFont, SystemBrushes.ControlText, 0, p);
            }
        }
Beispiel #2
0
        private void OnPaint(object sender, PaintEventArgs e)
        {
            Graphics      g     = e.Graphics;
            ASCIIEncoding ascii = new ASCIIEncoding();

            g.Clear(SystemColors.Control);

            var addrSize  = TextRenderer.MeasureText("0000:", MonoSpace);
            var addrWidth = addrSize.Width;

            lineHeight = addrSize.Height;
            var byteWidth = TextRenderer.MeasureText("00", MonoSpace).Width;

            int lineBase   = Math.Max(scrollPosition.Value, 0) * bytesPerLine;
            var clientRect = hexView.ClientRectangle;
            int yPos       = clientRect.Top;

            while (lineBase < PropellerCPU.TOTAL_MEMORY && yPos < clientRect.Height)
            {
                int xPos = clientRect.Left;
                // Draw the address
                g.FillRectangle(Brushes.White, new Rectangle(xPos, yPos, addrWidth, lineHeight));
                g.DrawString(String.Format("{0:X4}:", lineBase), MonoSpace, SystemBrushes.ControlText, xPos, yPos);
                xPos += addrWidth;
                // Draw the line of data
                for (int addr = lineBase; (addr < lineBase + bytesPerLine) && (addr < PropellerCPU.TOTAL_MEMORY); ++addr)
                {
                    string dataString = (Chip != null
                        ? Chip.DirectReadByte((uint)(addr)).ToString("X2")
                        : "--");

                    Brush brush;
                    if (addr >= highlightStart && addr < highlightEnd)
                    {
                        brush = Brushes.Magenta;
                    }
                    else
                    {
                        brush = colorBrushes[colorMap[addr]];
                    }

                    g.FillRectangle(brush, new Rectangle(xPos, yPos, byteWidth, lineHeight));

                    // if (data > 32 && data < 127)
                    // {
                    //    g.DrawString(ascii.GetString(new byte[] { data }), MonoSpace, SystemBrushes.ControlText, dx, dy);
                    // }
                    // else
                    // {
                    g.DrawString(dataString, MonoSpace, SystemBrushes.ControlText, xPos, yPos);
                    // }
                    xPos += byteWidth;
                }

                yPos     += lineHeight;
                lineBase += bytesPerLine;
            }
        }
Beispiel #3
0
        private void ColorObject(uint objFrame, uint varFrame, TreeNode root)
        {
            uint i, addr, addrnext;

            root     = root.Nodes.Add(String.Format("Object {0:X}", objFrame));
            root.Tag = (int)objFrame;

            root.Nodes.Add(String.Format("Variable Space {0:X4}", varFrame)).Tag = (int)varFrame;
            Colorize[varFrame] = Brushes.LightBlue;

            ushort size    = Chip.DirectReadWord(objFrame);
            byte   longs   = Chip.DirectReadByte(objFrame + 2);
            byte   objects = Chip.DirectReadByte(objFrame + 3);

            for (i = 0; i < longs * 4; i++)
            {
                Colorize[i + objFrame] = Brushes.LightPink;
            }
            for (; i < (longs + objects) * 4; i++)
            {
                Colorize[i + objFrame] = Brushes.LavenderBlush;
            }
            for (; i < size; i++)
            {
                Colorize[i + objFrame] = Brushes.LightGreen;
            }

            addrnext = Chip.DirectReadWord(1 * 4 + objFrame) + objFrame;
            for (i = 1; i < longs; i++)
            {
                addr     = addrnext;
                addrnext = Chip.DirectReadWord((i + 1) * 4 + objFrame) + objFrame;
                if (i == longs - 1)
                {
                    addrnext = addr + 1;
                    while (Colorize[addrnext] == Brushes.LightGreen)
                    {
                        addrnext++;
                    }
                }
                ColorFunction(addr, addrnext, root);
            }

            for (i = 0; i < objects; i++)
            {
                ColorObject(Chip.DirectReadWord((longs + i) * 4 + objFrame) + objFrame,
                            Chip.DirectReadWord((longs + i) * 4 + 2 + objFrame) + varFrame, root);
            }
        }
Beispiel #4
0
        private void ColorObject(uint objFrame, uint varFrame, TreeNode parent)
        {
            uint i, addr, addrnext;

            var objectNode = parent.Nodes.Add(String.Format("Object {0:X}", objFrame));

            objectNode.Nodes.Add(String.Format("Variable Space {0:X4}", varFrame)).Tag =
                Tuple.Create((int)varFrame, (int)varFrame);
            colorMap[varFrame] = 4;

            ushort size        = Chip.DirectReadWord(objFrame);
            uint   clippedSize = Math.Min(size, (uint)PropellerCPU.TOTAL_MEMORY - objFrame);

            objectNode.Tag = Tuple.Create((int)objFrame, (int)(objFrame + clippedSize));
            byte longs   = Chip.DirectReadByte(objFrame + 2);
            byte objects = Chip.DirectReadByte(objFrame + 3);

            for (i = 0; i < longs * 4 && i < clippedSize; i++)
            {
                colorMap[i + objFrame] = 5;
            }
            for (; i < (longs + objects) * 4 && i < clippedSize; i++)
            {
                colorMap[i + objFrame] = 6;
            }
            for (; i + 4 < clippedSize; i++)
            {
                colorMap[i + objFrame] = 7;
            }

            addr = Chip.DirectReadWord(objFrame + 4) + objFrame;
            for (i = 1; i < longs - 1; i++)
            {
                addrnext = Chip.DirectReadWord(objFrame + 4 + i * 4) + objFrame;
                ColorFunction(addr, addrnext, objectNode);
                addr = addrnext;
            }
            if (longs > 0)
            {
                ColorFunction(addr, objFrame + clippedSize, objectNode);
            }

            for (i = 0; i < objects; i++)
            {
                ColorObject(Chip.DirectReadWord((longs + i) * 4 + objFrame) + objFrame,
                            Chip.DirectReadWord((longs + i) * 4 + 2 + objFrame) + varFrame, objectNode);
            }
        }
Beispiel #5
0
        private void ColorCode()
        {
            int i;

            objectView.Nodes.Clear();
            TreeNode root = objectView.Nodes.Add("Spin");
            TreeNode node;

            node     = root.Nodes.Add(String.Format("System Frequency: {0}mhz", Chip.DirectReadLong(0)));
            node.Tag = (int)0;
            node     = root.Nodes.Add(String.Format("Clock Mode: {0:X2}", Chip.DirectReadByte(4)));
            node.Tag = (int)4;
            node     = root.Nodes.Add(String.Format("Check Sum: {0:X2}", Chip.DirectReadByte(5)));
            node.Tag = (int)5;
            node     = root.Nodes.Add(String.Format("Root Object: {0:X4}", Chip.DirectReadWord(6)));
            node.Tag = (int)6;
            node     = root.Nodes.Add(String.Format("Variable Base: {0:X4}", Chip.DirectReadWord(8)));
            node.Tag = (int)8;
            node     = root.Nodes.Add(String.Format("Local Frame: {0:X4}", Chip.DirectReadWord(10)));
            node.Tag = (int)10;
            node     = root.Nodes.Add(String.Format("Entry PC: {0:X4}", Chip.DirectReadWord(12)));
            node.Tag = (int)12;
            node     = root.Nodes.Add(String.Format("Starting Stack: {0:X4}", Chip.DirectReadWord(14)));
            node.Tag = (int)14;

            for (i = 0; i < 16; i++)
            {
                Colorize[i] = Brushes.White;
            }

            for (i = Chip.DirectReadWord(0x8); i < Chip.DirectReadWord(0xA); i++)
            {
                Colorize[i] = Brushes.LightYellow;
            }

            for (; i < 0x8000; i++)
            {
                Colorize[i] = Brushes.LightGray;
            }

            ColorObject(Chip.DirectReadWord(0x6), Chip.DirectReadWord(0x8), root);
        }
Beispiel #6
0
        private void ColorCode()
        {
            int i;

            objectView.Nodes.Clear();
            TreeNode root = objectView.Nodes.Add("Spin");
            TreeNode node;

            node     = root.Nodes.Add(String.Format("System Frequency: {0}mhz", Chip.DirectReadLong(0)));
            node.Tag = Tuple.Create(0, 4);
            node     = root.Nodes.Add(String.Format("Clock Mode: {0:X2}", Chip.DirectReadByte(4)));
            node.Tag = Tuple.Create(4, 5);
            node     = root.Nodes.Add(String.Format("Check Sum: {0:X2}", Chip.DirectReadByte(5)));
            node.Tag = Tuple.Create(5, 6);
            node     = root.Nodes.Add(String.Format("Root Object: {0:X4}", Chip.DirectReadWord(6)));
            node.Tag = Tuple.Create(6, 8);
            node     = root.Nodes.Add(String.Format("Variable Base: {0:X4}", Chip.DirectReadWord(8)));
            node.Tag = Tuple.Create(8, 10);
            node     = root.Nodes.Add(String.Format("Local Frame: {0:X4}", Chip.DirectReadWord(10)));
            node.Tag = Tuple.Create(10, 12);
            node     = root.Nodes.Add(String.Format("Entry PC: {0:X4}", Chip.DirectReadWord(12)));
            node.Tag = Tuple.Create(12, 14);
            node     = root.Nodes.Add(String.Format("Starting Stack: {0:X4}", Chip.DirectReadWord(14)));
            node.Tag = Tuple.Create(14, 16);

            for (i = 0; i < 16; i++)
            {
                colorMap[i] = 1;
            }

            for (i = Chip.DirectReadWord(0x8); i < Chip.DirectReadWord(0xA); i++)
            {
                colorMap[i] = 2;
            }

            for (; i < 0x8000; i++)
            {
                colorMap[i] = 3;
            }

            ColorObject(Chip.DirectReadWord(0x6), Chip.DirectReadWord(0x8), root);
        }
Beispiel #7
0
        public override void Repaint(bool force)
        {
            if (Chip == null)
            {
                return;
            }

            Graphics      g     = Graphics.FromImage((Image)BackBuffer);
            ASCIIEncoding ascii = new ASCIIEncoding();

            g.Clear(SystemColors.Control);

            Size s = TextRenderer.MeasureText("00", MonoSpace);
            Size a = TextRenderer.MeasureText("0000:", MonoSpace);

            for (int y = scrollPosition.Value, dy = 0; y < 0x10000 && dy < hexView.ClientRectangle.Height; dy += s.Height)
            {
                // Draw the address
                g.FillRectangle(Brushes.White, new Rectangle(0, dy, a.Width, s.Height));
                g.DrawString(String.Format("{0:X4}:", y), MonoSpace, SystemBrushes.ControlText, 0, dy);
                // Draw the line of data
                for (int x = 0, dx = a.Width; y < 0x10000 && x < 16; x++, dx += s.Width, y++)
                {
                    byte data = Chip.DirectReadByte((uint)y);
                    g.FillRectangle(Colorize[y], new Rectangle(dx, dy, s.Width, s.Height));

                    // if (data > 32 && data < 127)
                    // {
                    //    g.DrawString(ascii.GetString(new byte[] { data }), MonoSpace, SystemBrushes.ControlText, dx, dy);
                    // }
                    // else
                    // {
                    g.DrawString(String.Format("{0:X2}", data), MonoSpace, SystemBrushes.ControlText, dx, dy);
                    // }
                }
            }

            hexView.CreateGraphics().DrawImageUnscaled(BackBuffer, 0, 0);
        }
Beispiel #8
0
        private void Repaint(bool tick, InterpretedCog host)
        {
            Graphics g = Graphics.FromImage((Image)BackBuffer);
            Brush    brush;

            g.Clear(SystemColors.Control);

            String display;
            uint   topLine, bottomLine;

            topLine    = 5;
            bottomLine = (uint)((ClientRectangle.Height / MonoFont.Height) - 5);

            zeroFlagLabel.Text   = "";
            carryFlagLabel.Text  = "";
            OpcodeSize.Visible   = true;
            DisplayUnits.Visible = true;

            if (memoryViewButton.Checked)
            {
                for (uint i = (uint)positionScroll.Value, y = 0;
                     y < ClientRectangle.Height;
                     y += (uint)MonoFont.Height, i++)
                {
                    if ((i > 0xFFFF) || (i < 0))
                    {
                        continue;
                    }

                    uint mem = host[(int)i];

                    string binary = Convert.ToString((long)mem, 2);

                    while (binary.Length < 32)
                    {
                        binary = "0" + binary;
                    }

                    display = String.Format("{0:X4}:  {1:X8}   {2}   ",
                                            i, mem, binary);
                    if (displayAsHexadecimal)
                    {
                        display = display + String.Format("{0:X8}", mem);
                    }
                    else
                    {
                        display = display + String.Format("{0}", mem);
                    }

                    g.FillRectangle(SystemBrushes.Control, 0, y, assemblyPanel.Width, y + MonoFont.Height);

                    g.DrawString(
                        display,
                        (host.ProgramCursor == i) ? MonoFontBold : MonoFont,
                        SystemBrushes.ControlText, 0, y);
                }
            }
            else
            {
                uint y = 0;

                for (uint i = (uint)positionScroll.Value, line = 1; y < ClientRectangle.Height; y += (uint)MonoFont.Height, line++)
                {
                    if (i > 0xFFFF)
                    {
                        continue;
                    }

                    uint start = i;

                    Propeller.MemoryManager mem = new Propeller.MemoryManager(Chip, i);
                    string inst = InstructionDisassembler.InterpreterText(mem, displayAsHexadecimal, useShortOpcodes);
                    i                   = mem.Address;
                    display             = String.Format("{0:X4}: ", start);
                    InterpAddress[line] = start;

                    for (uint q = start; q < start + 4; q++)
                    {
                        if (q < i)
                        {
                            byte b = Chip.DirectReadByte(q);
                            display += String.Format(" {0:X2}", b);
                        }
                        else
                        {
                            display += "   ";
                        }
                    }


                    display += "  " + inst;

                    if (InterpAddress[line] == host.BreakPoint)
                    {
                        brush = System.Drawing.Brushes.Pink;
                    }
                    else if ((!followPCButton.Checked) || (line <= topLine) || (line >= bottomLine))
                    {
                        brush = SystemBrushes.Control;
                    }
                    else
                    {
                        brush = SystemBrushes.Window;
                    }
                    g.FillRectangle(brush, 0, y, assemblyPanel.Width, y + MonoFont.Height);

                    g.DrawString(
                        display,
                        (host.ProgramCursor == start) ? MonoFontBold : MonoFont,
                        SystemBrushes.ControlText, 0, y);
                }

                StringBrush = SystemBrushes.ControlText;
                StringY     = 0;
                StringX     = (uint)(assemblyPanel.Width - StackMargin);

                DrawString(g, String.Format("@Stk[0] = ${0:X4} {0}", host.Stack));
                DrawString(g, String.Format("@Obj[0] = ${0:X4} {0}", host.Object));
                DrawString(g, String.Format("@Loc[0] = ${0:X4} {0}", host.Local));
                DrawString(g, String.Format("@Var[0] = ${0:X4} {0}", host.Variable));
                g.DrawLine(Pens.Black, assemblyPanel.Width - StackMargin, StringY, assemblyPanel.Width, StringY);
                DrawString(g, String.Format("Caller& = ${0:X4} {0}", Chip.DirectReadWord(host.Local - 8)));
                DrawString(g, String.Format("          ${0:X4} {0}", Chip.DirectReadWord(host.Local - 6)));
                DrawString(g, String.Format("          ${0:X4} {0}", Chip.DirectReadWord(host.Local - 4)));
                DrawString(g, String.Format("Return& = ${0:X4}", Chip.DirectReadWord(host.Local - 2)));
                g.DrawLine(Pens.Black, assemblyPanel.Width - StackMargin, StringY, assemblyPanel.Width, StringY);

                for (uint i = host.Local; i < host.Stack && StringY < ClientRectangle.Height; i += 4)
                {
                    DrawString(g, String.Format("${0:X8}  {0}", (int)Chip.DirectReadLong(i)));
                }
            }
        }