Example #1
0
        public static void While_Pre(Func <Condition> condition, Action <LoopLabels> block)
        {
            var labels = new LoopLabels();

            Context.Write(labels.ContinueLabel);
            var c = condition.Invoke();

            Context.New(() => {
                block(labels);
                GoTo(labels.ContinueLabel);
                var len = Context.Length;
                if (len <= HIGHEST_BRANCH_VAL)
                {
                    Context.Parent(() => {
                        Branch(c, len, true);
                    });
                }
                else
                {
                    var lblEnd       = Labels.New();
                    var lblOptionEnd = Labels.New();
                    Context.Parent(() => {
                        Branch(c, CPU6502.Asm.OC["JMP"][CPU6502.Asm.Mode.Absolute].Length);
                        GoTo(lblEnd);
                    });
                    Context.Write(lblEnd);
                }
            });
            Context.Write(labels.BreakLabel);
        }
Example #2
0
        public static void Descend_Pre(IndexingRegister reg, Action <LoopLabels> block)
        {
            var labels = new LoopLabels();

            Do_old(_ => {
                Context.Write(labels.ContinueLabel);
                reg.Dec();
                var before = reg.State.Hash;
                block.Invoke(labels);
                reg.State.Verify(before);
            }).While(() => reg is RegisterX ? X.NotEquals(0) : Y.NotEquals(0));
            Context.Write(labels.BreakLabel);
        }
Example #3
0
        public static void AscendWhile(IndexingRegister reg, Func <Condition> condition, Action <LoopLabels> block)
        {
            var labels = new LoopLabels();

            Do_old(_ => {
                var before = reg.State.Hash;
                block.Invoke(labels);
                reg.State.Verify(before);
                Context.Write(labels.ContinueLabel);
                reg.Inc();
            }).While(condition);
            Context.Write(labels.BreakLabel);
        }
Example #4
0
        public static void Infinite(Action <LoopLabels>?block = null)
        {
            var labels = new LoopLabels();

            //var lbl = Labels.New();
            Context.Write(labels.ContinueLabel);
            if (block != null)
            {
                Context.New(() => block(labels));
            }
            GoTo(labels.ContinueLabel);
            Context.Write(labels.BreakLabel);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="start">Inclusive</param>
        /// <param name="length">Exclusive</param>
        /// <param name="block"></param>
        public static void Repeat(IndexingRegister reg, int length, Action <LoopLabels> block)
        {
            var labels = new LoopLabels();
            //X.Reset();
            var lblStart = Labels.New();

            Context.Write(lblStart);
            Context.New(() => {
                var before = reg.State.Hash;
                block.Invoke(labels);
                reg.State.Verify(before);
                Context.Write(labels.ContinueLabel);
                reg.Inc();
                if (Context.StartBranchable)
                {
                    if (length < 256)
                    {
                        if (reg is RegisterX)
                        {
                            CPU6502.CPX((U8)length);
                        }
                        else
                        {
                            CPU6502.CPY((U8)length);
                        }
                    }
                    CPU6502.BNE(Context.Start);
                }
                else
                {
                    //TODO: verify this works!
                    if (length < 256)
                    {
                        if (reg is RegisterX)
                        {
                            CPU6502.CPX((U8)length);
                        }
                        else
                        {
                            CPU6502.CPY((U8)length);
                        }
                    }
                    CPU6502.BEQ(3);
                    GoTo(lblStart);
                }
            });
            Context.Write(labels.BreakLabel);
        }