public InstructionExpressionBuilder(IExpressionLibraryRegistry expressionLibrary)
 {
     _expressionLibrary = expressionLibrary;
     _programControlExpressionLibrary = expressionLibrary.GetLibrary<IProgramControlExpressionLibrary>();
     _preInstructionAdvice = new List<IInstructionAdvice>();
     _postInstructionAdvice = new List<IInstructionAdvice>();
 }
        public Expression GetExpression(InstructionInfo info, IExpressionLibraryRegistry expressionLibraries)
        {
            String opcode = info.Prefix + info.Opcode.ToString("X2");
            if (!_enabledOpcodes.Contains(opcode) && IsFilterEnabled)
                return null;

            return GetExpressionImpl(info, expressionLibraries);
        }        
Beispiel #3
0
        public Expression GetExpression(InstructionInfo info, IExpressionLibraryRegistry expressionLibraries)
        {
            var instructionSize = 0;

            switch (info.ParameterMode)
            {
                case InstructionParameterMode.None:
                    instructionSize = 1;
                    break;
                case InstructionParameterMode.Byte:
                    instructionSize = 2;
                    break;
                case InstructionParameterMode.Word:
                    instructionSize = 3;
                    break;
                case InstructionParameterMode.Index:
                    instructionSize = 2;
                    break;
                case InstructionParameterMode.Address:
                    instructionSize = 3;
                    break;
                case InstructionParameterMode.IndexAndByte:
                    instructionSize = 3;
                    break;
                default:
                    break;
            }

            if (info.Prefix == "DDCB" || info.Prefix == "FDCB")
            {
                instructionSize++;
            }

            if (!String.IsNullOrEmpty(info.Prefix))
                instructionSize += info.Prefix.Length / 2;

            var progExpr = expressionLibraries.GetLibrary<IProgramControlExpressionLibrary>();
            return Expression.Call(Expression.Constant(this), _enqueMethod,
                Expression.New(_historyItemConsturctor,
                    Expression.Constant(info.Mnemonic),
                    Expression.Subtract(progExpr.ProgramCounterRegister,
                        Expression.Constant(instructionSize)),
                    progExpr.ParameterByte1,
                    progExpr.ParameterByte2)
                );
        }
        protected override Expression GetExpressionImpl(InstructionInfo info, IExpressionLibraryRegistry expressionLibraries)
        {
            var dataExpLib = expressionLibraries.GetLibrary<IDataAccessExpressionLibrary>();
            var progLib = expressionLibraries.GetLibrary<IProgramControlExpressionLibrary>();

            return Expression.Call(Expression.Constant(this), _instructionRanEvent, Expression.New(_eventArgsConstructor,
                    dataExpLib.RegisterA,
                    dataExpLib.RegisterB,
                    dataExpLib.RegisterC,
                    dataExpLib.RegisterD,
                    dataExpLib.RegisterE,
                    dataExpLib.RegisterH,
                    dataExpLib.RegisterL,
                    dataExpLib.FlagsRegister,
                    progLib.ProgramCounterRegister,
                    dataExpLib.StackPointerRegister,
                    progLib.CycleCounter,
                    Expression.Constant(info),
                    ((DataAccessExpressionLibrary)dataExpLib).SystemBusParameter
                )
            );
        }
 public ExpressionBuilder(IExpressionLibraryRegistry registry)
 {
     _registry = registry;
 }
Beispiel #6
0
        private static List<Expression> BuildLoopMethod(Expression opcodeResolver, ExpressionBuilder expressionBuilder, IExpressionLibraryRegistry libRegistry)
        {
            LabelTarget beginMainLoop = Expression.Label("beginMainLoop");
            LabelTarget endMainLoop = Expression.Label("endMainLoop");

            IProgramControlExpressionLibrary pcel = libRegistry.GetLibrary<IProgramControlExpressionLibrary>();
            IInteruptExpressionLibrary iel = libRegistry.GetLibrary<IInteruptExpressionLibrary>();
            IDataAccessExpressionLibrary dael = libRegistry.GetLibrary<IDataAccessExpressionLibrary>();

            var methodBody = new List<Expression>();
            methodBody.Add(expressionBuilder.InitializeParameters());
            //methodBody.Add(Expression.Assign(pcel.CycleCounter, Expression.Constant(347)));

            methodBody.Add(Expression.Block(
                    // Handle IRQs if neccessary.
                    Expression.IfThen(Expression.Equal(iel.IFF1, Expression.Constant(true)),
                        Expression.IfThen(Expression.Equal(iel.InteruptRequested, Expression.Constant(true)),
                            Expression.Block(
                                Expression.Assign(iel.InteruptRequested, Expression.Constant(false)),
                                Expression.Assign(iel.IFF1, Expression.Constant(false)),
                                dael.Push(pcel.ProgramCounterRegister),
                                Expression.Assign(pcel.ProgramCounterRegister, Expression.Constant(0x0038)),
                                Expression.SubtractAssign(pcel.CycleCounter, Expression.Constant(13))
                            )
                        )
                    ),

                    Expression.Label(beginMainLoop),

                    Expression.IfThen(Expression.LessThanOrEqual(pcel.CycleCounter, Expression.Constant(0)),
                        Expression.Goto(endMainLoop)
                    ),

                    //Expression.SubtractAssign(pcel.CycleCounter, Expression.Constant(4)),

                    Expression.PostIncrementAssign(iel.RefreshRegister),
                    opcodeResolver,

                    Expression.Goto(beginMainLoop),
                    Expression.Label(endMainLoop)
                )
            );

            methodBody.Add(expressionBuilder.FinalizeParameters());
            return methodBody;
        }
 public InstructionScanner(IExpressionLibraryRegistry libraryRegistry)
 {
     _libraryRegistry = libraryRegistry;
 }
        public Expression GetExpression(InstructionInfo info, IExpressionLibraryRegistry expressionLibraries)
        {
            var programControl = expressionLibraries.GetLibrary<IProgramControlExpressionLibrary>();

            List<Expression> expressions = new List<Expression>();

            expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("PC: ")));

            switch (info.ParameterMode)
            {
                case InstructionParameterMode.None:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(Expression.Subtract(programControl.ProgramCounterRegister, Expression.Constant(1)), typeof(Object))));
                    break;
                case InstructionParameterMode.Byte:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(Expression.Subtract(programControl.ProgramCounterRegister, Expression.Constant(2)), typeof(Object))));
                    break;
                case InstructionParameterMode.Word:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(Expression.Subtract(programControl.ProgramCounterRegister, Expression.Constant(3)), typeof(Object))));
                    break;
                case InstructionParameterMode.Index:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(Expression.Subtract(programControl.ProgramCounterRegister, Expression.Constant(2)), typeof(Object))));
                    break;
                case InstructionParameterMode.Address:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(Expression.Subtract(programControl.ProgramCounterRegister, Expression.Constant(3)), typeof(Object))));
                    break;
                case InstructionParameterMode.IndexAndByte:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(Expression.Subtract(programControl.ProgramCounterRegister, Expression.Constant(3)), typeof(Object))));
                    break;
                default:
                    break;
            }
            expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\t")));
            
            expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant(String.Format("0x{0:X2}", info.Opcode))));
            expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\t")));

            expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant(info.Mnemonic.PadRight(15))));

            switch (info.ParameterMode)
            {
                case InstructionParameterMode.None:
                    break;
                case InstructionParameterMode.Byte:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\tn = ")));
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(programControl.ParameterByte1, typeof(Object))));
                    break;
                case InstructionParameterMode.Word:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\tnn = ")));
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(programControl.ParameterWord, typeof(Object))));
                    break;
                case InstructionParameterMode.Index:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\td = ")));
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(programControl.ParameterByte1, typeof(Object))));
                    break;
                case InstructionParameterMode.Address:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\taddress = ")));
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(programControl.ParameterWord, typeof(Object))));
                    break;
                case InstructionParameterMode.IndexAndByte:
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\tindex = ")));
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(programControl.ParameterByte2, typeof(Object))));
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant("\tn = ")));
                    expressions.Add(Expression.Call(debugWriteMethod, Expression.TypeAs(programControl.ParameterByte1, typeof(Object))));
                    break;
                default:
                    break;
            }

            expressions.Add(Expression.Call(debugWriteMethod, Expression.Constant(Environment.NewLine)));

            return Expression.Block(expressions);

            //return Expression.PostIncrementAssign(programControl.ParameterByte1);
        }
 protected abstract Expression GetExpressionImpl(InstructionInfo info, IExpressionLibraryRegistry expressionLibraries);
Beispiel #10
0
 protected override Expression GetExpressionImpl(InstructionInfo info, IExpressionLibraryRegistry expressionLibraries)
 {
     throw new NotImplementedException();
 }