public static string GetPointer(int offset, int bytes) { int ia = -1; string format = "", param = ""; switch (bytes) { case 2: ia = (Data.GetDataBank(offset) << 16) | GetROMWord(offset); format = "dw {0}"; param = NumberToBaseString(GetROMWord(offset), NumberBase.Hexadecimal, 4, true); break; case 3: ia = GetROMLong(offset); format = "dl {0}"; param = NumberToBaseString(GetROMLong(offset), NumberBase.Hexadecimal, 6, true); break; case 4: ia = GetROMLong(offset); format = "dl {0}" + string.Format(" : db {0}", NumberToBaseString(Data.GetROMByte(offset + 3), NumberBase.Hexadecimal, 2, true)); param = NumberToBaseString(GetROMLong(offset), NumberBase.Hexadecimal, 6, true); break; } int pc = ConvertSNEStoPC(ia); if (pc >= 0 && Data.GetLabel(pc) != "") { param = Data.GetLabel(pc); } return(string.Format(format, param)); }
public static int GetIntermediateAddress(int offset) { int bank, directPage, operand, programCounter; int opcode = Data.GetROMByte(offset); AddressMode mode = GetAddressMode(offset); switch (mode) { case AddressMode.DIRECT_PAGE: case AddressMode.DIRECT_PAGE_X_INDEX: case AddressMode.DIRECT_PAGE_Y_INDEX: case AddressMode.DIRECT_PAGE_INDIRECT: case AddressMode.DIRECT_PAGE_X_INDEX_INDIRECT: case AddressMode.DIRECT_PAGE_INDIRECT_Y_INDEX: case AddressMode.DIRECT_PAGE_LONG_INDIRECT: case AddressMode.DIRECT_PAGE_LONG_INDIRECT_Y_INDEX: directPage = Data.GetDirectPage(offset); operand = Data.GetROMByte(offset + 1); return((directPage + operand) & 0xFFFF); case AddressMode.DIRECT_PAGE_S_INDEX: case AddressMode.DIRECT_PAGE_S_INDEX_INDIRECT_Y_INDEX: return(Data.GetROMByte(offset + 1)); case AddressMode.ADDRESS: case AddressMode.ADDRESS_X_INDEX: case AddressMode.ADDRESS_Y_INDEX: case AddressMode.ADDRESS_X_INDEX_INDIRECT: bank = (opcode == 0x20 || opcode == 0x4C || opcode == 0x7C || opcode == 0xFC) ? Util.ConvertPCtoSNES(offset) >> 16 : Data.GetDataBank(offset); operand = Util.GetROMWord(offset + 1); return((bank << 16) | operand); case AddressMode.ADDRESS_INDIRECT: case AddressMode.ADDRESS_LONG_INDIRECT: operand = Util.GetROMWord(offset + 1); return(operand); case AddressMode.LONG: case AddressMode.LONG_X_INDEX: operand = Util.GetROMLong(offset + 1); return(operand); case AddressMode.RELATIVE_8: programCounter = Util.ConvertPCtoSNES(offset + 2); bank = programCounter >> 16; offset = (sbyte)Data.GetROMByte(offset + 1); return((bank << 16) | ((programCounter + offset) & 0xFFFF)); case AddressMode.RELATIVE_16: programCounter = Util.ConvertPCtoSNES(offset + 3); bank = programCounter >> 16; offset = (short)Util.GetROMWord(offset + 1); return((bank << 16) | ((programCounter + offset) & 0xFFFF)); } return(-1); }
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 void UpdateGroup() { flagCombo.Visible = (property.SelectedIndex == 0); regValue.Visible = (property.SelectedIndex == 1 || property.SelectedIndex == 2); mxCombo.Visible = (property.SelectedIndex == 3 || property.SelectedIndex == 4); archCombo.Visible = (property.SelectedIndex == 5); regValue.MaxLength = (property.SelectedIndex == 1 ? 3 : 5); value = property.SelectedIndex == 1 ? Data.GetDataBank(start) : Data.GetDirectPage(start); }
public static int GetEffectiveAddressOrPointer(int offset) { switch (Data.GetFlag(offset)) { case Data.FlagType.Opcode: return(GetEffectiveAddress(offset)); case Data.FlagType.Pointer16Bit: int bank = Data.GetDataBank(offset); return((bank << 16) | GetROMWord(offset)); case Data.FlagType.Pointer24Bit: case Data.FlagType.Pointer32Bit: return(GetROMLong(offset)); } return(-1); }
// length forced to 2 private static string GetDataBank(int offset, int length) { return(Util.NumberToBaseString(Data.GetDataBank(offset), Util.NumberBase.Hexadecimal, 2)); }
public static int Step(int offset, bool branch, bool force, int prevOffset) { int opcode = Data.GetROMByte(offset); int prevDirectPage = Data.GetDirectPage(offset); int prevDataBank = Data.GetDataBank(offset); bool prevX = Data.GetXFlag(offset), prevM = Data.GetMFlag(offset); while (prevOffset >= 0 && Data.GetFlag(prevOffset) == Data.FlagType.Operand) { prevOffset--; } if (prevOffset >= 0 && Data.GetFlag(prevOffset) == Data.FlagType.Opcode) { prevDirectPage = Data.GetDirectPage(prevOffset); prevDataBank = Data.GetDataBank(prevOffset); prevX = Data.GetXFlag(prevOffset); prevM = Data.GetMFlag(prevOffset); } if (opcode == 0xC2 || opcode == 0xE2) // REP SEP { prevX = (Data.GetROMByte(offset + 1) & 0x10) != 0 ? opcode == 0xE2 : prevX; prevM = (Data.GetROMByte(offset + 1) & 0x20) != 0 ? opcode == 0xE2 : prevM; } // set first byte first, so the instruction length is correct Data.SetFlag(offset, Data.FlagType.Opcode); Data.SetDataBank(offset, prevDataBank); Data.SetDirectPage(offset, prevDirectPage); Data.SetXFlag(offset, prevX); Data.SetMFlag(offset, prevM); int length = GetInstructionLength(offset); for (int i = 1; i < length; i++) { Data.SetFlag(offset + i, Data.FlagType.Operand); Data.SetDataBank(offset + i, prevDataBank); Data.SetDirectPage(offset + i, prevDirectPage); Data.SetXFlag(offset + i, prevX); Data.SetMFlag(offset + i, prevM); } MarkInOutPoints(offset); int nextOffset = offset + length; if (!force && (opcode == 0x4C || opcode == 0x5C || opcode == 0x80 || opcode == 0x82 || // JMP JML BRA BRL (branch && (opcode == 0x10 || opcode == 0x30 || opcode == 0x50 || // BPL BMI BVC opcode == 0x70 || opcode == 0x90 || opcode == 0xB0 || opcode == 0xD0 || // BVS BCC BCS BNE opcode == 0xF0 || opcode == 0x20 || opcode == 0x22)))) // BEQ JSR JSL { int iaNextOffsetPC = Util.ConvertSNEStoPC(Util.GetIntermediateAddress(offset, true)); if (iaNextOffsetPC >= 0) { nextOffset = iaNextOffsetPC; } } return(nextOffset); }
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); }