Exemplo n.º 1
0
        //For reference:
        //(byte)(-128)==(byte)0x80
        //(byte)(127)==(byte)0x7F

        //TODO: implement AL.LastUsedRegister for determining if a CMP is still needed before a branch operation
        public void While(Func <Condition> condition)
        {
            //An outer context to account for conditions that output some code
            Context.Write(_labels.ContinueLabel);
            Context.New(() => {
                _block?.Invoke(_labels);
                var c   = condition.Invoke();
                var len = -Context.Length - 2;                 //-2 is to account for the branch instruction
                if (len >= LOWEST_BRANCH_VAL)
                {
                    Branch(c, len);
                }
                else
                {
                    Branch(c, CPU6502.Asm.OC["JMP"][CPU6502.Asm.Mode.Absolute].Length, true);
                    CPU6502.JMP(Context.StartLabel);
                }
            });
            Context.Write(_labels.BreakLabel);
        }