private void unreachedToolStripMenuItem_Click(object sender, EventArgs e) { markFlag = Data.FlagType.Unreached; UpdateMarkerLabel(); }
private void operandToolStripMenuItem_Click(object sender, EventArgs e) { markFlag = Data.FlagType.Operand; UpdateMarkerLabel(); }
private void dWordPointerToolStripMenuItem_Click(object sender, EventArgs e) { markFlag = Data.FlagType.Pointer32Bit; UpdateMarkerLabel(); }
private void textToolStripMenuItem_Click(object sender, EventArgs e) { markFlag = Data.FlagType.Text; UpdateMarkerLabel(); }
private void graphicsToolStripMenuItem_Click(object sender, EventArgs e) { markFlag = Data.FlagType.Graphics; UpdateMarkerLabel(); }
private void bitDataToolStripMenuItem3_Click(object sender, EventArgs e) { markFlag = Data.FlagType.Data32Bit; UpdateMarkerLabel(); }
private void LogStats(int pc, int dataBank, int directPage, bool xflagSet, bool mflagSet, Data.FlagType flagType) { var mMarks = data.GetFlag(pc) != flagType; var mDb = data.GetDataBank(pc) != dataBank; var mDp = data.GetDirectPage(pc) != directPage; var mX = data.GetXFlag(pc) != xflagSet; var mM = data.GetMFlag(pc) != mflagSet; if (mMarks || mDb || mDp || mX || mM) { CurrentStats.NumRomBytesModified++; } CurrentStats.NumMarksModified += mMarks ? 1 : 0; CurrentStats.NumDbModified += mDb ? 1 : 0; CurrentStats.NumDpModified += mDp ? 1 : 0; CurrentStats.NumXFlagsModified += mX ? 1 : 0; CurrentStats.NumMFlagsModified += mM ? 1 : 0; }
public static int AutoStep(int offset, bool harsh, int amount) { Project.unsavedChanges = true; int newOffset = offset, prevOffset = offset - 1, nextOffset = offset; if (harsh) { while (newOffset < offset + amount) { nextOffset = Step(newOffset, false, true, prevOffset); prevOffset = newOffset; newOffset = nextOffset; } } else { Stack <int> stack = new Stack <int>(); List <int> seenBranches = new List <int>(); bool keepGoing = true; while (keepGoing) { switch (Data.GetArchitechture(newOffset)) { case Data.Architechture.CPU65C816: if (seenBranches.Contains(newOffset)) { keepGoing = false; break; } int opcode = Data.GetROMByte(newOffset); nextOffset = Step(newOffset, false, false, prevOffset); int jumpOffset = Step(newOffset, true, false, prevOffset); 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 opcode == 0x6C || opcode == 0x7C || opcode == 0xDC || opcode == 0xFC // JMP JMP JML JSR ) { keepGoing = false; } if (opcode == 0x4C || opcode == 0x5C || opcode == 0x80 || opcode == 0x82 || // JMP JML BRA BRL opcode == 0x10 || opcode == 0x30 || opcode == 0x50 || opcode == 0x70 || // BPL BMI BVC BVS opcode == 0x90 || opcode == 0xB0 || opcode == 0xD0 || opcode == 0xF0 // BCC BCS BNE BEQ ) { seenBranches.Add(newOffset); } if (opcode == 0x08) // PHP { stack.Push(Data.GetMXFlags(newOffset)); } else if (opcode == 0x28) // PLP { if (stack.Count == 0) { keepGoing = false; break; } else { Data.SetMXFlags(newOffset, stack.Pop()); } } if (opcode == 0x60 || opcode == 0x6B) // RTS RTL { if (stack.Count == 0) { keepGoing = false; break; } else { prevOffset = newOffset; newOffset = stack.Pop(); } } else if (opcode == 0x20 || opcode == 0x22) // JSR JSL { stack.Push(nextOffset); prevOffset = newOffset; newOffset = jumpOffset; } else { prevOffset = newOffset; newOffset = nextOffset; } break; case Data.Architechture.APUSPC700: case Data.Architechture.GPUSuperFX: nextOffset = Step(newOffset, false, true, prevOffset); prevOffset = newOffset; newOffset = nextOffset; break; } Data.FlagType flag = Data.GetFlag(newOffset); if (!(flag == Data.FlagType.Unreached || flag == Data.FlagType.Opcode || flag == Data.FlagType.Operand)) { keepGoing = false; } } } return(newOffset); }
public int SearchOffset(int direction = 1) { direction = direction > 0 ? 1 : -1; int offset = SelectedOffset > 0 ? SelectedOffset : 0; Data.FlagType flag = Project.Data.GetFlag(offset), current; try { if (toolStripFlagType.SelectedIndex > 0) { flag = GetFlagType(toolStripFlagType.SelectedIndex - 1); } if (toolStripSearchBox.Text.Length > 0) { while ((offset += direction) > 0 && offset < Project.Data.GetRomSize()) { if (toolStripFlagType.SelectedIndex > 0 && Project.Data.GetFlag(offset) != flag) { continue; } if (Regex.IsMatch(Project.Data.GetInstruction(offset, true), toolStripSearchBox.Text)) { break; } } return(offset); } if (toolStripFlagType.SelectedIndex > 0) { if (direction > 0) { while (++offset < Project.Data.GetRomSize() && Project.Data.GetFlag(offset) == flag) { continue; } while (++offset < Project.Data.GetRomSize() && Project.Data.GetFlag(offset) != flag) { continue; } } else { while (--offset >= 0 && Project.Data.GetFlag(offset) != flag) { continue; } while (--offset >= 0 && Project.Data.GetFlag(offset) == flag) { continue; } offset++; } } else { while ((offset += direction) > 0 && offset < Project.Data.GetRomSize()) { current = Project.Data.GetFlag(offset); if (flag == Data.FlagType.Opcode && current == Data.FlagType.Operand) { continue; } if (flag == Data.FlagType.Operand && current == Data.FlagType.Opcode) { continue; } if (flag != current) { break; } } } } catch (System.Exception exception) { ShowError(exception.Message); } return(offset >= 0 && offset < Project.Data.GetRomSize() ? offset : -1); }
private void SetMarkerLabel(Data.FlagType flagType) { markFlag = flagType; UpdateMarkerLabel(); }
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; }
protected string GetCode(int offset, int length) { var bytes = GetLineByteLength(offset); string code = "", label = ""; FileStream file; Data.FlagType flag = Data.GetFlag(offset); switch (flag) { case Data.FlagType.Opcode: code = Data.GetInstruction(offset, Settings.LowerCaseOpcodes); break; case Data.FlagType.Unreached: case Data.FlagType.Operand: case Data.FlagType.Data8Bit: code = Data.GetFormattedBytes(offset, 1, bytes); break; case Data.FlagType.Empty: var padbyte = Util.NumberToBaseString(Data.GetRomByte(offset), Util.NumberBase.Hexadecimal, 2, false); var pad = Util.NumberToBaseString(Data.ConvertPCtoSnes(offset + bytes), Util.NumberBase.Hexadecimal, 6, false); code = $"padbyte ${padbyte} : pad ${pad}"; if ((offset + bytes) / BankSize != (offset / BankSize)) { code = $"check bankcross off : {code} : check bankcross on"; } break; case Data.FlagType.Graphics: case Data.FlagType.Music: case Data.FlagType.Binary: label = Data.GetLabelName(Data.ConvertPCtoSnes(offset)); if (label == "") { label = "data_" + Util.NumberToBaseString(Data.ConvertPCtoSnes(offset), Util.NumberBase.Hexadecimal, 6, false); } code = $"incbin {label}.bin"; if ((offset + bytes) / BankSize != (offset / BankSize)) { code = $"check bankcross off : {code} : check bankcross on"; } file = new FileStream(Output.BuildStreamPath($"{label}.bin"), FileMode.Create, FileAccess.Write); while (bytes > 0) { file.WriteByte((byte)Data.GetRomByte(offset)); bytes--; offset++; } file.Close(); break; case Data.FlagType.Data16Bit: code = Data.GetFormattedBytes(offset, 2, bytes); break; case Data.FlagType.Data24Bit: code = Data.GetFormattedBytes(offset, 3, bytes); break; case Data.FlagType.Data32Bit: code = Data.GetFormattedBytes(offset, 4, bytes); break; case Data.FlagType.Pointer16Bit: code = Data.GetPointer(offset, 2); break; case Data.FlagType.Pointer24Bit: code = Data.GetPointer(offset, 3); break; case Data.FlagType.Pointer32Bit: code = Data.GetPointer(offset, 4); break; case Data.FlagType.Text: code = Data.GetFormattedText(offset, bytes); break; } return(string.Format("{0," + (length < 0 ? length * -1 : 0) + "}{1," + (length > 0 ? length * -1 : 0) + "}", "", code)); }
protected int GetLineByteLength(int offset) { int max = 1, step = 1; var size = Data.GetRomSize(); bool checkbank = true, checkbyte = false, checksublabel = false; Data.FlagType flag = Data.GetFlag(offset); switch (flag) { case Data.FlagType.Opcode: return(Data.OpcodeByteLength(offset)); case Data.FlagType.Unreached: case Data.FlagType.Operand: case Data.FlagType.Data8Bit: max = Settings.DataPerLine; break; case Data.FlagType.Graphics: case Data.FlagType.Music: case Data.FlagType.Text: max = 0x8000; checksublabel = true; break; case Data.FlagType.Empty: case Data.FlagType.Binary: max = 0xFFFFFF; checkbank = false; checksublabel = true; checkbyte = flag == Data.FlagType.Empty; break; case Data.FlagType.Data16Bit: step = 2; max = Settings.DataPerLine; break; case Data.FlagType.Data24Bit: step = 3; max = Settings.DataPerLine; break; case Data.FlagType.Data32Bit: step = 4; max = Settings.DataPerLine; break; case Data.FlagType.Pointer16Bit: step = 2; max = 2; break; case Data.FlagType.Pointer24Bit: step = 3; max = 3; break; case Data.FlagType.Pointer32Bit: step = 4; max = 4; break; } int min = step, myBank = offset / BankSize; while ( min < max && offset + min < size && (!checkbyte || Data.GetRomByte(offset + min) == Data.GetRomByte(offset)) && Data.GetFlag(offset + min) == Data.GetFlag(offset) && (Data.GetLabelName(Data.ConvertPCtoSnes(offset + min)) == "" || (checksublabel && Data.GetLabelName(Data.ConvertPCtoSnes(offset + min))[0] == '.') || Data.GetFlag(offset) == Data.FlagType.Binary) && //(Data.GetFlag(offset + min) == Data.FlagType.Text && Data.GetRomByte(offset + min) > 0x00) && (!checkbank || (offset + min) / BankSize == myBank) ) { min += step; } return(min); }