コード例 #1
0
        public static void PerformRegionOptimize(ROM realRom, Region region, FixConfig config)
        {
            // This is fake rom but it works anyways, just more convenient
            // Want to be safe with overwriting the whole display list
            ROM fakeRom = new ROM(region.data);
            RegionOptimizeState state = new RegionOptimizeState(config);

            DisplayListRegion dlRegion = (DisplayListRegion)region;

            byte curCmdIndex;

            do
            {
                curCmdIndex = fakeRom.Read8();
                OptimizeParserCmd func = optimizeParser[curCmdIndex];
                func(fakeRom, dlRegion, state);
                fakeRom.AddOffset(8);
            }while (fakeRom.offset < region.length);

            // Now write data to real rom + trimming
            // bzero
            fakeRom.offset = 0;
            realRom.PushOffset(region.romStart);
            {
                do
                {
                    realRom.Write64(0x0101010101010101);
                    realRom.AddOffset(8);
                    fakeRom.AddOffset(8);
                } while (fakeRom.offset < region.length);
            }
            realRom.PopOffset();

            fakeRom.offset = 0;
            realRom.PushOffset(region.romStart);
            {
                int start = region.romStart;
                do
                {
                    Int64 cmd = fakeRom.Read64();
                    fakeRom.AddOffset(8);

                    if (config.trimNOPs && cmd == 0 && dlRegion.isUnusedTrimmingAllowed)
                    {
                        continue;
                    }

                    realRom.Write64((ulong)cmd);
                    realRom.AddOffset(8);
                } while (fakeRom.offset < region.length);

                region.length = realRom.offset - start;
                region.data   = new byte[region.length];
                realRom.ReadData(region.romStart, region.length, region.data);
            }
            realRom.PopOffset();
        }
コード例 #2
0
        static DisplayList()
        {
            Type t = typeof(DisplayList);

            for (int i = 0x00; i < 0xFF; i++)
            {
                parser[i] = RegionParse_common;

                string     name = "RegionParse_cmd" + string.Format("{0:X2}", i);
                MethodInfo info = t.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static);
                if (info == null)
                {
                    continue;
                }

                RegionParseCmd cmd = Delegate.CreateDelegate(typeof(RegionParseCmd), info) as RegionParseCmd;
                if (cmd == null)
                {
                    continue;
                }

                parser[i] = cmd;
            }

            for (int i = 0; i < 0xFF; i++)
            {
                fixParser[i] = FixParse_common;

                string     name = "FixParse_cmd" + string.Format("{0:X2}", i);
                MethodInfo info = t.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static);
                if (info == null)
                {
                    continue;
                }

                FixParseCmd cmd = Delegate.CreateDelegate(typeof(FixParseCmd), info) as FixParseCmd;
                if (cmd == null)
                {
                    continue;
                }

                fixParser[i] = cmd;
            }

            for (int i = 0; i < 0xFF; i++)
            {
                optimizeParser[i] = OptimizeParse_common;

                string     name = "OptimizeParse_cmd" + string.Format("{0:X2}", i);
                MethodInfo info = t.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static);
                if (info == null)
                {
                    continue;
                }

                OptimizeParserCmd cmd = Delegate.CreateDelegate(typeof(OptimizeParserCmd), info) as OptimizeParserCmd;
                if (cmd == null)
                {
                    continue;
                }

                optimizeParser[i] = cmd;
            }

            for (int i = 0; i < 0xFF; i++)
            {
                visualMapParser[i] = VisualMapParse_common;

                string     name = "VisualMapParse_cmd" + string.Format("{0:X2}", i);
                MethodInfo info = t.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static);
                if (info == null)
                {
                    continue;
                }

                VisualMapParserCmd cmd = Delegate.CreateDelegate(typeof(VisualMapParserCmd), info) as VisualMapParserCmd;
                if (cmd == null)
                {
                    continue;
                }

                visualMapParser[i] = cmd;
            }

            for (int i = 0; i < 0xFF; i++)
            {
                triangleMapParser[i] = TriangleMapParse_common;

                string     name = "TriangleMapParse_cmd" + string.Format("{0:X2}", i);
                MethodInfo info = t.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static);
                if (info == null)
                {
                    continue;
                }

                TriangleMapParserCmd cmd = Delegate.CreateDelegate(typeof(TriangleMapParserCmd), info) as TriangleMapParserCmd;
                if (cmd == null)
                {
                    continue;
                }

                triangleMapParser[i] = cmd;
            }
        }