Ejemplo n.º 1
0
 private void SetConstantType(Data.ConstantType constType)
 {
     for (int i = 0; i < table.SelectedCells.Count; i++)
     {
         Project.Data.SetConstantType(table.SelectedCells[i].RowIndex + ViewOffset, constType);
     }
     UpdateUI();
 }
Ejemplo n.º 2
0
        public void PaintCell(int offset, DataGridViewCellStyle style, int column_index, int selOffset, DataGridViewCellPaintingEventArgs cell)
        {
            // editable cells show up green
            string column = ColumnName(column_index);

            if (column == "label" || column == "base" || column == "db" || column == "dp" || column == "ia" || column == "comment")
            {
                style.SelectionBackColor = Color.Chartreuse;
            }

            bool diff = Project.Data.GetLabelName(Project.Data.ConvertPCtoSnes(offset)) == "" && (offset > 0 && Project.Data.GetFlag(offset - 1) == Project.Data.GetFlag(offset));

            Data.InOutPoint   point    = Project.Data.GetInOutPoint(offset);
            Data.FlagType     flag     = Project.Data.GetFlag(offset);
            Data.ConstantType constant = Project.Data.GetConstantType(offset);
            switch (flag)
            {
            case Data.FlagType.Unreached:
                style.BackColor = Color.LightGray;
                style.ForeColor = Color.DarkSlateGray;
                break;

            case Data.FlagType.Opcode:
                int opcode = Project.Data.GetRomByte(offset);
                switch (column)
                {
                case "points":
                    int r = 255, g = 255, b = 255;
                    if ((point & (Data.InOutPoint.EndPoint | Data.InOutPoint.OutPoint)) != 0)
                    {
                        g -= 50;
                    }
                    if ((point & (Data.InOutPoint.InPoint)) != 0)
                    {
                        r -= 50;
                    }
                    if ((point & (Data.InOutPoint.ReadPoint)) != 0)
                    {
                        b -= 50;
                    }
                    style.BackColor = Color.FromArgb(r, g, b);
                    break;

                case "instruction":
                    if (opcode == 0x40 || opcode == 0xCB || opcode == 0xDB || opcode == 0xF8 ||      // RTI WAI STP SED
                        opcode == 0xFB || opcode == 0x00 || opcode == 0x02 || opcode == 0x42            // XCE BRK COP WDM
                        )
                    {
                        style.BackColor = Color.Yellow;
                    }
                    if (constant != Data.ConstantType.Hexadecimal)
                    {
                        style.BackColor = Color.FromArgb(50 - (int)constant, 100 - (int)constant, 255 - ((int)constant * 20));
                        style.ForeColor = Color.White;
                    }
                    break;

                case "db":
                    if (opcode == 0xAB || opcode == 0x44 || opcode == 0x54)         // PLB MVP MVN
                    {
                        style.BackColor = Color.OrangeRed;
                    }
                    else if (opcode == 0x8B)         // PHB
                    {
                        style.BackColor = Color.Yellow;
                    }
                    break;

                case "dp":
                    if (opcode == 0x2B || opcode == 0x5B)         // PLD TCD
                    {
                        style.BackColor = Color.OrangeRed;
                    }
                    if (opcode == 0x0B || opcode == 0x7B)         // PHD TDC
                    {
                        style.BackColor = Color.Yellow;
                    }
                    break;

                case "m":
                case "x":
                    int mask = column == "m" ? 0x20 : 0x10;
                    if (opcode == 0x28 || ((opcode == 0xC2 || opcode == 0xE2) &&      // PLP SEP REP
                                           (Project.Data.GetRomByte(offset + 1) & mask) != 0)) // relevant bit set
                    {
                        style.BackColor = Color.OrangeRed;
                    }
                    if (opcode == 0x08)         // PHP
                    {
                        style.BackColor = Color.Yellow;
                    }
                    break;
                }
                switch (opcode)
                {
                case 0x4C:
                case 0x5C:
                case 0x6C:
                case 0x7C:
                case 0xDC:
                    style.BackColor = Color.WhiteSmoke;
                    break;

                case 0x60:
                case 0x6B:
                    style.BackColor = Color.LightGreen;
                    break;
                }
                break;

            case Data.FlagType.Operand:
                style.ForeColor = Color.LightGray;
                break;

            case Data.FlagType.Graphics:
                style.BackColor = Color.LightPink;
                break;

            case Data.FlagType.Music:
                style.BackColor = Color.PowderBlue;
                break;

            case Data.FlagType.Data8Bit:
            case Data.FlagType.Data16Bit:
            case Data.FlagType.Data24Bit:
            case Data.FlagType.Data32Bit:
                style.BackColor = Color.NavajoWhite;
                if (column == "ia" && Project.Data.GetConstantType(offset) == Data.ConstantType.Color && (point & Data.InOutPoint.ReadPoint) > 0)
                {
                    if (flag == Data.FlagType.Data16Bit)
                    {
                        style.BackColor = Util.ColorRGB555(Project.Data.GetRomWord(offset));
                    }
                    else if (flag == Data.FlagType.Data24Bit)
                    {
                        style.BackColor = Color.FromArgb(Project.Data.GetRomByte(offset + 2), Project.Data.GetRomByte(offset + 1), Project.Data.GetRomByte(offset));
                    }
                }
                if (RomUtil.GetByteLengthForFlag(flag) > 1 && (point & Data.InOutPoint.ReadPoint) == 0)
                {
                    style.ForeColor = Color.DarkGray;
                }
                break;

            case Data.FlagType.Pointer16Bit:
            case Data.FlagType.Pointer24Bit:
            case Data.FlagType.Pointer32Bit:
                style.BackColor = Color.Orchid;
                if ((point & (Data.InOutPoint.ReadPoint | Data.InOutPoint.EndPoint)) == 0)
                {
                    style.ForeColor = Color.DarkMagenta;
                }
                break;

            case Data.FlagType.Text:
                style.BackColor = Color.Aquamarine;
                if (diff)
                {
                    style.ForeColor = Color.DarkGray;
                }
                break;

            case Data.FlagType.Empty:
                style.BackColor = Color.DarkSlateGray;
                style.ForeColor = Color.LightGray;
                break;

            case Data.FlagType.Binary:
                style.BackColor = Color.Aqua;
                break;
            }

            int ia  = Project.Data.ConvertSnesToPc(Project.Data.GetIntermediateAddressOrPointer(offset));
            int sia = Project.Data.ConvertSnesToPc(Project.Data.GetIntermediateAddressOrPointer(selOffset));

            if (selOffset >= 0 && selOffset < Project.Data.GetRomSize())
            {
                if ((column == "pc" && sia >= 0 && sia == offset) || (column == "ia" && ia >= 0 && ia == selOffset))
                {
                    style.BackColor = Color.DeepPink;
                }
            }


            switch (column)
            {
            case "label":
                style.ForeColor = Project.Data.GetLabelName(Project.Data.ConvertPCtoSnes(offset)) == "" ? Color.LightGray : style.ForeColor;
                break;

            case "base":
                style.ForeColor = Project.Data.GetBaseAddr(offset) > 0 /*&& Project.Data.GetFlag(offset) != Data.FlagType.Operand*/ ? Color.DarkBlue : Color.LightGray;
                break;

            case "ia":
                if (Project.Data.GetIndirectAddr(offset) > 0 /*&& Project.Data.GetFlag(offset) != Data.FlagType.Operand*/)
                {
                    style.ForeColor = Color.Red;
                }
                break;

            case "constant":
                if (constant != Data.ConstantType.Hexadecimal)
                {
                    style.BackColor = Color.FromArgb(50 - (int)constant, 100 - (int)constant, 255 - ((int)constant * 20));
                    style.ForeColor = Color.White;
                }
                break;

            case "comment":
                if (Project.Data.GetComment(Project.Data.ConvertPCtoSnes(offset)) == "")
                {
                    style.ForeColor = Color.LightGray;
                }
                break;
            }

            cell.PaintBackground(cell.CellBounds, true);
            if (sia >= 0)
            {
                if (column == "pc" && ((sia > selOffset && offset < sia && offset > selOffset) || (sia < selOffset && offset > sia && offset <= selOffset)))
                {
                    cell.Graphics.DrawLine(new Pen(Color.DeepPink, 2F), cell.CellBounds.Right - 2, cell.CellBounds.Top, cell.CellBounds.Right - 2, cell.CellBounds.Bottom);
                }
                if (((sia >= 0 && selOffset == offset - 1) || (ia >= 0 && ia == offset)) && column_index > ColumnIndex("pc") && column_index <= ColumnIndex("ia"))
                {
                    cell.Graphics.DrawLine(Pens.DeepPink, cell.CellBounds.Left, cell.CellBounds.Top, cell.CellBounds.Right, cell.CellBounds.Top);
                }
            }

            cell.Paint(cell.ClipBounds, DataGridViewPaintParts.ContentForeground);
            cell.Handled = true;
        }
Ejemplo n.º 3
0
        private void table_CellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            string value = e.Value as string;
            int    result, row = e.RowIndex + ViewOffset;

            if (row >= Project.Data.GetRomSize())
            {
                return;
            }
            switch (ColumnName(e.ColumnIndex))
            {
            case "label":
                if (value != null && !Regex.IsMatch(value, ".?[a-zA-Z0-9_]+|[\\+\\-]+"))
                {
                    value = null;
                }
                Project.Data.AddLabel(Project.Data.ConvertPCtoSnes(row), new Diz.Core.model.Label()
                {
                    Name = value
                }, true);
                break;

            case "db":
                Project.Data.SetDataBank(row, int.TryParse(value, NumberStyles.HexNumber, null, out result) ? result : 0);
                break;

            case "dp":
                Project.Data.SetDirectPage(row, int.TryParse(value, NumberStyles.HexNumber, null, out result) ? result : 0);
                break;

            case "base":
                Project.Data.SetBaseAddr(row, int.TryParse(value, NumberStyles.HexNumber, null, out result) ? result : 0);
                break;

            case "ia":
                Project.Data.SetIndirectAddr(row, int.TryParse(value, NumberStyles.HexNumber, null, out result) && result != Project.Data.GetIntermediateAddressOrPointer(row, true) ? result : 0);
                break;

            case "m":
                Project.Data.SetMFlag(row, (value == "8" || value.ToUpper() == "M"));
                break;

            case "x":
                Project.Data.SetXFlag(row, (value == "8" || value.ToUpper() == "X"));
                break;

            case "constant":
                Data.ConstantType ctype = value.ToUpper() switch
                {
                    "D" => Data.ConstantType.Decimal,
                    "B" => Data.ConstantType.Binary,
                    "T" => Data.ConstantType.Text,
                    _ => Data.ConstantType.Hexadecimal
                };
                Project.Data.SetConstantType(row, ctype);
                break;

            case "comment":
                Project.Data.AddComment(Project.Data.ConvertPCtoSnes(row), value, true);
                break;
            }

            InvalidateTable();
        }