diff --git a/PluginCommon/AddressTranslate.cs b/PluginCommon/AddressTranslate.cs
index 69edc9c..b3ae29d 100644
--- a/PluginCommon/AddressTranslate.cs
+++ b/PluginCommon/AddressTranslate.cs
@@ -35,6 +35,15 @@ namespace PluginCommon {
mAddrMap = addrMap;
}
+ ///
+ /// Converts a file offset to an address.
+ ///
+ /// File offset.
+ /// 24-bit address.
+ public int OffsetToAddress(int offset) {
+ return mAddrMap.OffsetToAddress(offset);
+ }
+
///
/// Determines the file offset that best contains the specified target address.
///
@@ -47,12 +56,37 @@ namespace PluginCommon {
}
///
- /// Converts a file offset to an address.
+ /// Returns the data found at the specified address. If the address is out
+ /// of bounds this throws an AddressException.
///
- /// File offset.
- /// 24-bit address.
- public int OffsetToAddress(int offset) {
- return mAddrMap.OffsetToAddress(offset);
+ /// Data array.
+ /// Offset of the address reference. Only matters when
+ /// multiple file offsets map to the same address.
+ /// Data address.
+ /// Data found.
+ public byte GetDataAtAddress(byte[] data, int srcOffset, int address) {
+ int offset = AddressToOffset(srcOffset, address);
+ if (offset == -1) {
+ Exception ex = new AddressTranslateException("Address $" + address.ToString("X4") +
+ " is outside the file bounds");
+ ex.Data.Add("Address", address);
+ throw ex;
+ }
+ try {
+ byte foo = data[offset];
+ } catch (Exception ex) {
+ throw new AddressTranslateException("FAILED at srcOff=$" + srcOffset.ToString("x4") +
+ " addr=$" + address.ToString("x4"));
+ }
+ return data[offset];
}
}
+
+ ///
+ /// Exception thrown by AddressTranslate's GetDataAtAddress().
+ ///
+ public class AddressTranslateException : Exception {
+ public AddressTranslateException() : base() { }
+ public AddressTranslateException(string msg) : base(msg) { }
+ }
}