private void table_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) { int row = e.RowIndex + viewOffset; if (row >= Data.GetROMSize()) { return; } switch (e.ColumnIndex) { case 0: e.Value = Data.GetLabel(Util.ConvertPCtoSNES(row)); break; case 1: e.Value = Util.NumberToBaseString(Util.ConvertPCtoSNES(row), Util.NumberBase.Hexadecimal, 6); break; case 2: e.Value = (char)Data.GetROMByte(row); break; case 3: e.Value = Util.NumberToBaseString(Data.GetROMByte(row), DisplayBase); break; case 4: e.Value = Util.PointToString(Data.GetInOutPoint(row)); break; case 5: int len = Manager.GetInstructionLength(row); if (row + len <= Data.GetROMSize()) { e.Value = Util.GetInstruction(row); } else { e.Value = ""; } break; case 6: int ia = Util.GetIntermediateAddressOrPointer(row); if (ia >= 0) { e.Value = Util.NumberToBaseString(ia, Util.NumberBase.Hexadecimal, 6); } else { e.Value = ""; } break; case 7: e.Value = Util.TypeToString(Data.GetFlag(row)); break; case 8: e.Value = Util.NumberToBaseString(Data.GetDataBank(row), Util.NumberBase.Hexadecimal, 2); break; case 9: e.Value = Util.NumberToBaseString(Data.GetDirectPage(row), Util.NumberBase.Hexadecimal, 4); break; case 10: e.Value = Util.BoolToSize(Data.GetMFlag(row)); break; case 11: e.Value = Util.BoolToSize(Data.GetXFlag(row)); break; case 12: e.Value = Data.GetComment(Util.ConvertPCtoSNES(row)); break; } }
private static string GetLine(int offset, string special) { string line = ""; for (int i = 0; i < list.Count; i++) { if (list[i].Item2 == int.MaxValue) // string literal { line += list[i].Item1; } else if (special != null) // special parameter (replaces code & everything else = empty) { line += GetParameter(offset, "%" + (list[i].Item1 == "code" ? special : "empty"), list[i].Item2); } else // normal parameter { line += GetParameter(offset, list[i].Item1, list[i].Item2); } } if (special == null) { // throw out some errors if stuff looks fishy Data.FlagType flag = Data.GetFlag(offset), check = flag == Data.FlagType.Opcode ? Data.FlagType.Operand : flag; int step = flag == Data.FlagType.Opcode ? GetLineByteLength(offset) : Util.TypeStepSize(flag), size = Data.GetROMSize(); if (flag == Data.FlagType.Operand) { err.WriteLine("({0}) Offset 0x{1:X}: Bytes marked as operands formatted as data.", ++errorCount, offset); } else if (step > 1) { for (int i = 1; i < step; i++) { if (offset + i >= size) { err.WriteLine("({0}) Offset 0x{1:X}: {2} extends past the end of the ROM.", ++errorCount, offset, Util.TypeToString(check)); break; } else if (Data.GetFlag(offset + i) != check) { err.WriteLine("({0}) Offset 0x{1:X}: Expected {2}, but got {3} instead.", ++errorCount, offset + i, Util.TypeToString(check), Util.TypeToString(Data.GetFlag(offset + i))); break; } } } int ia = Util.GetIntermediateAddress(offset, true); if (ia >= 0 && flag == Data.FlagType.Opcode && Data.GetInOutPoint(offset) == Data.InOutPoint.OutPoint && Data.GetFlag(Util.ConvertSNEStoPC(ia)) != Data.FlagType.Opcode) { err.WriteLine("({0}) Offset 0x{1:X}: Branch or jump instruction to a non-instruction.", ++errorCount, offset); } } return(line); }
public static void PaintCell(int offset, DataGridViewCellStyle style, int column, int selOffset) { // editable cells show up green if (column == 0 || column == 8 || column == 9 || column == 12) { style.SelectionBackColor = Color.Chartreuse; } switch (Data.GetFlag(offset)) { case Data.FlagType.Unreached: style.BackColor = Color.LightGray; style.ForeColor = Color.DarkSlateGray; break; case Data.FlagType.Opcode: int opcode = Data.GetROMByte(offset); switch (column) { case 4: // <*> Data.InOutPoint point = Data.GetInOutPoint(offset); 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 5: // 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; } break; case 8: // Data Bank 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 9: // Direct Page if (opcode == 0x2B || opcode == 0x5B) // PLD TCD { style.BackColor = Color.OrangeRed; } if (opcode == 0x0B || opcode == 0x7B) // PHD TDC { style.BackColor = Color.Yellow; } break; case 10: // M Flag case 11: // X Flag int mask = column == 10 ? 0x20 : 0x10; if (opcode == 0x28 || ((opcode == 0xC2 || opcode == 0xE2) && // PLP SEP REP (Data.GetROMByte(offset + 1) & mask) != 0)) // relevant bit set { style.BackColor = Color.OrangeRed; } if (opcode == 0x08) // PHP { style.BackColor = Color.Yellow; } 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; break; case Data.FlagType.Pointer16Bit: case Data.FlagType.Pointer24Bit: case Data.FlagType.Pointer32Bit: style.BackColor = Color.Orchid; break; case Data.FlagType.Text: style.BackColor = Color.Aquamarine; break; case Data.FlagType.Empty: style.BackColor = Color.DarkSlateGray; style.ForeColor = Color.LightGray; break; } if (selOffset >= 0 && selOffset < Data.GetROMSize()) { if (column == 1 //&& (Data.GetFlag(selOffset) == Data.FlagType.Opcode || Data.GetFlag(selOffset) == Data.FlagType.Unreached) && ConvertSNEStoPC(GetIntermediateAddressOrPointer(selOffset)) == offset ) { style.BackColor = Color.DeepPink; } if (column == 6 //&& (Data.GetFlag(offset) == Data.FlagType.Opcode || Data.GetFlag(offset) == Data.FlagType.Unreached) && ConvertSNEStoPC(GetIntermediateAddressOrPointer(offset)) == selOffset ) { style.BackColor = Color.DeepPink; } } }
public static int CreateLog(StreamWriter sw, StreamWriter er) { Dictionary <int, string> tempAlias = Data.GetAllLabels(); Data.Restore(a: new Dictionary <int, string>(tempAlias)); AliasList.me.locked = true; bankSize = Data.GetROMMapMode() == Data.ROMMapMode.LoROM ? 0x8000 : 0x10000; // todo AddTemporaryLabels(); string[] split = format.Split('%'); err = er; errorCount = 0; usedLabels = new List <int>(); list = new List <Tuple <string, int> >(); for (int i = 0; i < split.Length; i++) { if (i % 2 == 0) { list.Add(Tuple.Create(split[i], int.MaxValue)); } else { int colon = split[i].IndexOf(':'); if (colon < 0) { list.Add(Tuple.Create(split[i], parameters[split[i]].Item2)); } else { list.Add(Tuple.Create(split[i].Substring(0, colon), int.Parse(split[i].Substring(colon + 1)))); } } } int pointer = 0, size = (Data.GetTable() == ExportDisassembly.sampleTable) ? 0x7B : Data.GetROMSize(), bank = -1; if (structure == FormatStructure.OneBankPerFile) { folder = Path.GetDirectoryName(((FileStream)sw.BaseStream).Name); sw.WriteLine(GetLine(pointer, "map")); sw.WriteLine(GetLine(pointer, "empty")); for (int i = 0; i < size; i += bankSize) { sw.WriteLine(GetLine(i, "incsrc")); } sw.WriteLine(GetLine(-1, "incsrc")); } else { sw.WriteLine(GetLine(pointer, "map")); sw.WriteLine(GetLine(pointer, "empty")); } while (pointer < size) { int snes = Util.ConvertPCtoSNES(pointer); if ((snes >> 16) != bank) { if (structure == FormatStructure.OneBankPerFile) { sw.Close(); sw = new StreamWriter(string.Format("{0}/bank_{1}.asm", folder, Util.NumberToBaseString((snes >> 16), Util.NumberBase.Hexadecimal, 2))); } sw.WriteLine(GetLine(pointer, "empty")); sw.WriteLine(GetLine(pointer, "org")); sw.WriteLine(GetLine(pointer, "empty")); if ((snes % bankSize) != 0) { err.WriteLine("({0}) Offset 0x{1:X}: An instruction crossed a bank boundary.", ++errorCount, pointer); } bank = snes >> 16; } string label; if ((Data.GetInOutPoint(pointer) & (Data.InOutPoint.ReadPoint)) != 0 || (tempAlias.TryGetValue(pointer, out label) && label.Length > 0)) { sw.WriteLine(GetLine(pointer, "empty")); } sw.WriteLine(GetLine(pointer, null)); if ((Data.GetInOutPoint(pointer) & (Data.InOutPoint.EndPoint)) != 0) { sw.WriteLine(GetLine(pointer, "empty")); } pointer += GetLineByteLength(pointer); } if (structure == FormatStructure.OneBankPerFile) { sw.Close(); sw = new StreamWriter(string.Format("{0}/labels.asm", folder)); } else { sw.WriteLine(GetLine(pointer, "empty")); } foreach (KeyValuePair <int, string> pair in Data.GetAllLabels()) { if (!usedLabels.Contains(pair.Key)) { sw.WriteLine(GetLine(pair.Key, "labelassign")); } } if (structure == FormatStructure.OneBankPerFile) { sw.Close(); } Data.Restore(a: tempAlias); AliasList.me.locked = false; return(errorCount); }
private static byte[] SaveVersion1() { int size = Data.GetROMSize(); byte[] romSettings = new byte[31]; romSettings[0] = (byte)Data.GetROMMapMode(); romSettings[1] = (byte)Data.GetROMSpeed(); Util.IntegerIntoByteArray(size, romSettings, 2); for (int i = 0; i < 0x15; i++) { romSettings[6 + i] = (byte)Data.GetROMByte(Util.ConvertSNEStoPC(0xFFC0 + i)); } for (int i = 0; i < 4; i++) { romSettings[27 + i] = (byte)Data.GetROMByte(Util.ConvertSNEStoPC(0xFFDC + i)); } // TODO put selected offset in save file List <byte> label = new List <byte>(), comment = new List <byte>(); Dictionary <int, string> all_labels = Data.GetAllLabels(), all_comments = Data.GetAllComments(); Util.IntegerIntoByteList(all_labels.Count, label); foreach (KeyValuePair <int, string> pair in all_labels) { Util.IntegerIntoByteList(pair.Key, label); for (int i = 0; i < pair.Value.Length; i++) { label.Add((byte)pair.Value[i]); } label.Add(0); } Util.IntegerIntoByteList(all_comments.Count, comment); foreach (KeyValuePair <int, string> pair in all_comments) { Util.IntegerIntoByteList(pair.Key, comment); for (int i = 0; i < pair.Value.Length; i++) { comment.Add((byte)pair.Value[i]); } comment.Add(0); } byte[] romLocation = Util.StringToByteArray(currentROMFile); byte[] data = new byte[romSettings.Length + romLocation.Length + 8 * size + label.Count + comment.Count]; romSettings.CopyTo(data, 0); for (int i = 0; i < romLocation.Length; i++) { data[romSettings.Length + i] = romLocation[i]; } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + i] = (byte)Data.GetDataBank(i); } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + size + i] = (byte)Data.GetDirectPage(i); } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + 2 * size + i] = (byte)(Data.GetDirectPage(i) >> 8); } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + 3 * size + i] = (byte)(Data.GetXFlag(i) ? 1 : 0); } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + 4 * size + i] = (byte)(Data.GetMFlag(i) ? 1 : 0); } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + 5 * size + i] = (byte)Data.GetFlag(i); } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + 6 * size + i] = (byte)Data.GetArchitechture(i); } for (int i = 0; i < size; i++) { data[romSettings.Length + romLocation.Length + 7 * size + i] = (byte)Data.GetInOutPoint(i); } // ??? label.CopyTo(data, romSettings.Length + romLocation.Length + 8 * size); comment.CopyTo(data, romSettings.Length + romLocation.Length + 8 * size + label.Count); // ??? return(data); }