Ejemplo n.º 1
0
    public int FixMisalignedFlags()
    {
        int count = 0, size = GetRomSize();

        for (var i = 0; i < size; i++)
        {
            var flag = GetFlag(i);

            switch (flag)
            {
            case FlagType.Opcode:
            {
                int len = GetInstructionLength(i);
                for (var j = 1; j < len && i + j < size; j++)
                {
                    if (GetFlag(i + j) != FlagType.Operand)
                    {
                        SetFlag(i + j, FlagType.Operand);
                        count++;
                    }
                }
                i += len - 1;
                break;
            }

            case FlagType.Operand:
                SetFlag(i, FlagType.Opcode);
                count++;
                i--;
                break;

            default:
            {
                if (RomUtil.GetByteLengthForFlag(flag) > 1)
                {
                    int step = RomUtil.GetByteLengthForFlag(flag);
                    for (int j = 1; j < step; j++)
                    {
                        if (GetFlag(i + j) == flag)
                        {
                            continue;
                        }
                        SetFlag(i + j, flag);
                        count++;
                    }
                    i += step - 1;
                }

                break;
            }
            }
        }

        return(count);
    }
Ejemplo n.º 2
0
        private void Mark(int offset)
        {
            if (!RomDataPresent())
            {
                return;
            }

            ProjectController.MarkChanged();
            var newOffset = Project.Data.MarkTypeFlag(offset, markFlag, RomUtil.GetByteLengthForFlag(markFlag));

            SelectOffset(newOffset);

            UpdateUI_Tmp3();
        }
Ejemplo n.º 3
0
    private void Mark(int offset)
    {
        if (!RomDataPresent())
        {
            return;
        }

        ProjectController.MarkChanged();
        var newOffset = Project.Data.GetSnesApi().MarkTypeFlag(offset, markFlag, RomUtil.GetByteLengthForFlag(markFlag));

        SelectOffset(newOffset, new ISnesNavigation.HistoryArgs {
            Description = "Mark (single)"
        });

        UpdateUi_TimerAndPercent();
    }
Ejemplo n.º 4
0
        private int GetByteLengthFollowing(int offset)
        {
            var flag = Data.GetFlag(offset);

            return(flag == Data.FlagType.Opcode ? GetLineByteLength(offset) : RomUtil.GetByteLengthForFlag(flag));
        }
Ejemplo n.º 5
0
        private void buttonScan_Click(object sender, EventArgs e)
        {
            textLog.Text = "";
            int found = 0, offset = 0;

            while (found < 500 && offset < Data.GetRomSize())
            {
                FlagType flag = Data.GetFlag(offset), check = flag == FlagType.Opcode ? FlagType.Operand : flag;
                var      step = flag == FlagType.Opcode ? Data.GetInstructionLength(offset) : RomUtil.GetByteLengthForFlag(flag);

                if (flag == FlagType.Operand)
                {
                    found++;
                    textLog.Text +=
                        $"{Util.NumberToBaseString(Data.ConvertPCtoSnes(offset), Util.NumberBase.Hexadecimal, 6, true)} (0x{Util.NumberToBaseString(offset, Util.NumberBase.Hexadecimal, 0)}): Operand without Opcode\r\n";
                }
                else if (step > 1)
                {
                    for (var i = 1; i < step; i++)
                    {
                        if (Data.GetFlag(offset + i) == check)
                        {
                            continue;
                        }
                        found++;
                        textLog.Text +=
                            $"{Util.NumberToBaseString(Data.ConvertPCtoSnes(offset + i), Util.NumberBase.Hexadecimal, 6, true)} (0x{Util.NumberToBaseString(offset + i, Util.NumberBase.Hexadecimal, 0)}): {Util.GetEnumDescription(Data.GetFlag(offset + i))} is not {Util.GetEnumDescription(check)}\r\n";
                    }
                }

                offset += step;
            }

            if (found == 0)
            {
                textLog.Text = "No misaligned flags found!";
            }
        }
Ejemplo n.º 6
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;
        }