private static bool TryGetBlock(RomVersion version, AddressToken token, out Block block) { string ident = token.ToString(); var game = (from a in AddressDoc.Game where a.name.ToString() == version.Game.ToString() select a).Single(); block = (from b in game.Block where b.Identifier.Any(x => x.id == ident) select b).SingleOrDefault(); if (block != null) { return(true); } return(false); }
public static bool TryGetSymbolRef(AddressToken token, RomVersion version, out MapBinding o) { o = null; if (!TryGetBlock(version, token, out Block block)) { return(false); } var identifier = block.Identifier.SingleOrDefault(x => x.id == token.ToString()); if (identifier == null) { return(false); } o = identifier.MapBinding; return(true); }
public static bool TryGetOffset(AddressToken token, RomVersion version, out int v) { v = 0; if (!TryGetBlock(version, token, out Block block)) { return(false); } var lookupAddr = block.Identifier.SingleOrDefault(x => x.id == token.ToString()); if (!(lookupAddr.Item.Count > 0 && lookupAddr.Item[0] is Offset)) { return(false); } var lookupSet = lookupAddr.Item.Cast <Offset>().ToList(); var group = version.GetGroup(); Offset offset = lookupSet.SingleOrDefault(x => x.id == version.GetGroup()); if (offset == null && group != null) { offset = lookupSet.SingleOrDefault(x => x.id == null); } if (offset == null) { return(false); } if (!TryGetOffsetValue(offset, out v)) { return(false); } return(true); }
private static bool TryMagicConverter(Block block, AddressToken token, RomVersion version, Domain domain, out int result) { string ident = token.ToString(); result = 0; int lookup = 0; var lookupAddr = block.Identifier.SingleOrDefault(x => x.id == ident); if (lookupAddr == null) { return(false); } if (lookupAddr.Item.Count > 0) { if (lookupAddr.Item[0] is Addr addr) { if (!TryGetAddrValue(addr, version, out lookup)) { return(false); } //if lookup is absolute, and in the same space, we have it if (addr.reftype == AddressType.absolute && addr.domain == domain) { result = lookup; return(true); } //if lookup is absolute, but not in the same space, convert to offset if (addr.reftype == AddressType.absolute && addr.domain != domain) { Addr altStartAddr; altStartAddr = block.Start.SingleOrDefault(x => x.domain == addr.domain); if (altStartAddr == null || !TryGetAddrValue(altStartAddr, version, out int altStart)) { return(false); } lookup -= altStart; } } else if (lookupAddr.Item[0] is Offset) { var lookupSet = lookupAddr.Item.Cast <Offset>().ToList(); Offset offset = lookupSet.SingleOrDefault(x => x.id == version.GetGroup()); if (offset == null) { return(false); } if (!TryGetOffsetValue(offset, out lookup)) { return(false); } } } if (!TryGetStart(block, version, domain, out int start)) { return(false); } result = start + lookup; return(true); }