当前位置: 首页>>代码示例>>C#>>正文


C# Opcode.Where方法代码示例

本文整理汇总了C#中Opcode.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Opcode.Where方法的具体用法?C# Opcode.Where怎么用?C# Opcode.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Opcode的用法示例。


在下文中一共展示了Opcode.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOpcodes

        private static Opcode[] GetOpcodes(string data)
        {
            // Regex + HTML, naughty :O
            Regex rows = new Regex(@"<tr>((.|\n)*?)</tr>");
            Regex eachRow = new Regex(@"<td><abbr title=""(?<abbr>[^""]*?)"">(?<op>.*?)</abbr></td>");

            // Working for numeric regexs.
            // 0_255:    [,\s](2[0-5][0-5]|2[0-4]\d|1?\d?\d)[,\s]
            // -128_0:   [,\s](-(1[0-2][0-8]|1[01]\d|\d?\d))[,\s]
            // 0_100h:   ([0-9A-F]{1,2})h
            // Both:     [,\s]((-(1[0-2][0-8]|1[01]\d|\d?\d))|(2[0-5][0-5]|2[0-4]\d|1?\d?\d))[,\s]
            //
            // 0_65535:  [,\s](6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{1,3}|[0-5]?\d{1,4})[,\s]
            // -65536_0: [,\s](-(3276[0-8]|327[0-5]\d|32[0-6]\d\d|3[01]\d{1,3}|[0-2]?\d{1,4}))[,\s]
            // 0_10000h: [0-9A-F]h
            // Both:     [,\s]((6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{1,3}|[0-5]?\d{1,4})|(-(3276[0-8]|327[0-5]\d|32[0-6]\d\d|3[01]\d{1,3}|[0-2]?\d{1,4})))[,\s]

            // Parens left off end so it can incorporate a \w+ for matching labels in JP and JR operations
            const string byteregex = @"([0-9A-F]{1,2}h|-(1[0-2][0-8]|1[01]\d|\d?\d)|(2[0-5][0-5]|2[0-4]\d|1?\d?\d)";
            const string shortregex = @"([0-9A-F]{1,4}h|(6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{1,3}|[0-5]?\d{1,4})|(-(3276[0-8]|327[0-5]\d|32[0-6]\d\d|3[01]\d{1,3}|[0-2]?\d{1,4}))";

            var opcodes = new Opcode[256];

            MatchCollection rowmc = rows.Matches(data);
            for (int i = 0; i < rowmc.Count; i++)
            {
                string row = rowmc[i].Groups[1].Value;
                MatchCollection mc = eachRow.Matches(row);
                for (int j = 0; j < mc.Count; j++)
                {
                    int b = (i << 4) + j;

                    string op = mc[j].Groups["op"].Value;
                    op = op.Replace('n', '#');
                    int bytesFollowing = op.Where(c => c == '#').Count();

                    // Dynamically create regexs for the opcodes, so it can match for whitespace/constants etc and escapes brackets (parens)
                    string opregex = op.Replace(" ", @"\s+").Replace("(", @"\(").Replace(")", @"\)").Replace(",", @"\s*,\s*")
                                       .Replace("##", shortregex).Replace("#", byteregex);

                    // Add on an option to match labels in jump commands
                    var first2Chars = op.Substring(0, 2);
                    if ((first2Chars == "JP" || first2Chars == "CA") && bytesFollowing > 0)
                        opregex += @"|[_a-zA-Z]\w+";

                    // Close the right paren of the first capturing group
                    if (bytesFollowing > 0)
                        opregex += ")";

                    opregex += @"[\s;]";

                    opcodes[b] = new Opcode(op, opregex, (byte)b, bytesFollowing, mc[j].Groups["abbr"].Value);
                }
            }

            // Remove non-existant instructions and Extended operation ones (for now)
            return opcodes.Where(o => o.Op != "XX" && o.Op != "Ext ops").ToArray();
        }
开发者ID:CRogers,项目名称:GbcEmulator,代码行数:58,代码来源:OpcodeExtractor.cs


注:本文中的Opcode.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。