예제 #1
0
        public static bool TryGetOffset(string addrVar, RomVersion version, out int v)
        {
            Block block;

            v = 0;

            if (!TryGetBlock(version, addrVar, out block))
            {
                return(false);
            }

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

            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);
        }
예제 #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);
        }