Example #1
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);
        }