Ejemplo n.º 1
0
 private static bool TryGetAddrValue(Addr addr, RomVersion version, out int result)
 {
     try
     {
         result = Convert.ToInt32(addr.Data.Single(x => x.ver == version.ToString()).Value, 16);
     }
     catch
     {
         result = -1;
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
        private static bool TryMagicConverter(Block block, string ident, RomVersion version, Domain domain, out int result)
        {
            int lookup;

            result = 0;
            lookup = 0;

            var lookupAddr = block.Identifier.SingleOrDefault(x => x.id == ident);

            if (lookupAddr == null)
            {
                return(false);
            }

            if (lookupAddr.Item.Count > 0 && lookupAddr.Item[0] is Addr)
            {
                Addr addr = (Addr)lookupAddr.Item[0];

                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.Count > 0 && 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);
        }