示例#1
0
        public void TestRepeater()
        {
            var gs       = new GamesharkCode(0x50002040, 0xFFF0);
            var repeater = new GamesharkCode.Repeater(gs);

            Assert.AreEqual(0x20, repeater.Count);
            Assert.AreEqual(0x40, repeater.AddressStep);
            Assert.AreEqual(-16, repeater.ValueStep);
        }
示例#2
0
        public static IEnumerable <GamesharkCode> ExpandRepeaters(this IEnumerable <GamesharkCode> codes)
        {
            GamesharkCode?preceding = null,
                         repeater   = null;

            foreach (var code in codes)
            {
                if (repeater.HasValue)
                {
                    var x             = new GamesharkCode.Repeater(repeater.Value);
                    var canBeRepeated = preceding?.IsConditional == true;

                    for (var i = 0; i < x.Count; i++)
                    {
                        if (canBeRepeated)
                        {
                            yield return(preceding.Value);
                        }

                        yield return(new GamesharkCode(
                                         code.CodeType,
                                         (UInt32)(code.Address + i * x.AddressStep),
                                         (UInt16)(code.Value + i * x.ValueStep)
                                         ));
                    }

                    preceding = null;
                    repeater  = null;

                    continue;
                }
                else if (code.CodeType == GamesharkCode.Type.Repeater)
                {
                    repeater = code;
                    continue;
                }

                if (!code.IsConditional)
                {
                    yield return(code);
                }

                preceding = code;
            }
        }