public Maps.GetLabelsResult GetLabels(BankID bankId, ushort address) { BankID mapped; return(SourceMaps.GetLabelsAt(bankId, address) ?? SourceMaps.GetLabelsAt(bankId.All, address) ?? SourceMaps.GetLabelsAt(BankID.Unpaged(), address) ?? SourceMaps.GetLabelsAt(mapped = Memory.GetMappedBank(address), address) ?? SourceMaps.GetLabelsAt(mapped.All, address)); }
public int GetLineOfAddressInDisassembly(BankID bankId, ushort address) { DisasmBank bank; if (!_disasmBanks.TryGetValue(bankId, out bank)) { var slot = Memory.GetSlot(address); bank = GetDisasmBank(slot.Bank.ID); } var offset = address - Memory.Bank(bankId).PagedAddress; bank.Lines.TryGetValue((ushort)offset, out var line); return(line?.FileLine ?? 0); }
DisasmBank GetDisasmBank(BankID bankId) { if (_disasmBanks.TryGetValue(bankId, out var d)) { return(d); } d = new DisasmBank() { ID = bankId }; _disasmBanks[bankId] = d; return(d); }
public AddressDetails GetAddressDetails(BankID bankId, ushort address, ushort maxLabelDistance = 0x800) { // get address details of address by checking three levels: // specified bank + specified address // 'all' bank + specified address // bank currently paged in to specified address's slot + specified address _tempAddressDetails.Clear(); _tempAddressDetails.Add(SourceMaps.GetAddressDetails(bankId, address, maxLabelDistance)); if (bankId.Part != BankID.PartEnum.All) { _tempAddressDetails.Add(SourceMaps.GetAddressDetails(bankId.All, address, maxLabelDistance)); } if (bankId != BankID.Unpaged()) { _tempAddressDetails.Add(SourceMaps.GetAddressDetails(BankID.Unpaged(), address, maxLabelDistance)); } var curBank = Memory.GetMappedBank(address); if (bankId != curBank) { _tempAddressDetails.Add(SourceMaps.GetAddressDetails(curBank, address, maxLabelDistance)); } // now merge the details so move any Source and Label info present to the first entry for (var i = 1; i < _tempAddressDetails.Count; i++) { // shuffle up source info if (_tempAddressDetails[0].Source == null && _tempAddressDetails[i].Source != null) { _tempAddressDetails[0].Source = _tempAddressDetails[0].Source ?? _tempAddressDetails[i].Source; } // shuffle up labels & associated info if (_tempAddressDetails[0].Labels == null && _tempAddressDetails[i].Labels != null) { _tempAddressDetails[0].Labels = _tempAddressDetails[i].Labels; _tempAddressDetails[0].LabelledAddress = _tempAddressDetails[i].LabelledAddress; _tempAddressDetails[0].LabelledSource = _tempAddressDetails[i].LabelledSource; } } return(_tempAddressDetails[0]); }
public Bank Bank(BankID pID) { return(_banks[pID]); }
public BankID GetMappedBank(ushort address) { return(GetSlot(address)?.Bank?.ID ?? BankID.Unpaged()); }
string FormatInstruction(DisasmLine line, BankID bankId, ushort bankOffset) { var instruction = line.Instruction; string comment = null; var text = instruction.Text; if (instruction.Operands != null && instruction.Operands.Length > 0) { foreach (var op in instruction.Operands) { int offset; int absOffset; char sign; List <Label> labels; switch (op.Type) { case Disassembler.Operand.TypeEnum.Imm8: text = text.ReplaceFirst("{b}", ((byte)op.Value).ToHex()); break; case Disassembler.Operand.TypeEnum.Imm16: text = text.ReplaceFirst("{w}", op.Value.ToHex()); break; case Disassembler.Operand.TypeEnum.Index: offset = (sbyte)op.Value; sign = offset < 0 ? '-' : '+'; absOffset = Math.Abs(offset); text = text.ReplaceFirst("{+i}", $"{sign}{( (byte) absOffset ).ToHex()}"); break; case Disassembler.Operand.TypeEnum.CodeRel: offset = (sbyte)op.Value; sign = offset < 0 ? '-' : '+'; var addr = (ushort)(bankOffset + line.Offset + offset + line.Instruction.Length); labels = GetLabels(bankId, addr)?.Labels; absOffset = Math.Abs(offset); if (labels != null) { text = text.ReplaceFirst("{+b}", labels[0].Name); comment = $"{sign}{( (byte) absOffset ).ToHex()} {addr.ToHex()} "; } else { text = text.ReplaceFirst("{+b}", addr.ToHex()); comment = $"{sign}{( (byte) absOffset ).ToHex()}"; } break; case Disassembler.Operand.TypeEnum.DataAddr: labels = GetLabels(bankId, op.Value)?.Labels; if (labels != null) { text = text.ReplaceFirst("{data}", labels[0].Name); comment = op.Value.ToHex(); } else { text = text.ReplaceFirst("{data}", op.Value.ToHex()); } break; case Disassembler.Operand.TypeEnum.CodeAddr: labels = GetLabels(bankId, op.Value)?.Labels; if (labels != null) { text = text.ReplaceFirst("{code}", labels[0].Name); comment = op.Value.ToHex(); } else { text = text.ReplaceFirst("{code}", op.Value.ToHex()); } break; } } } if (comment != null) { text = text.PadRight(30) + "; " + comment; } return(text); }