Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PC"/> class.
 /// </summary>
 public PC()
 {
     this.SetupContainerGraph();
     this.processor = this.container.GetInstance <IProcessor>();
     this.memory    = this.container.GetInstance <IEmulatedMemory>();
     this.state     = this.container.GetInstance <IProcessorState>();
 }
Exemple #2
0
        /// <inheritdoc/>
        public override void PerformAction(
            IParsedInstruction instruction,
            IEmulatedMemory memory,
            IProcessorState state,
            IALU alu)
        {
            ushort addressA = (ushort)state.Registers[instruction.Register1];
            ushort addressB = (ushort)state.Registers[instruction.Register2];

            byte a = 0;
            byte b = 0;

            for (ushort i = 0; i < instruction.Immediate; i++)
            {
                a = (byte)memory.GetValue(0, (ushort)(addressA + i));
                b = (byte)memory.GetValue(0, (ushort)(addressB + i));

                if (a != b)
                {
                    break;
                }
            }

            state.High  = a > b;
            state.Equal = a == b;
            state.Low   = !state.High;
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Processor"/> class.
 /// </summary>
 /// <param name="parsedInstruction">Parsed instruction.</param>
 /// <param name="memory">Memory.</param>
 /// <param name="alu">ALU.</param>
 /// <param name="state">Processor state.</param>
 public Processor(IParsedInstruction parsedInstruction, IEmulatedMemory memory, IALU alu, IProcessorState state)
 {
     this.parsedInstruction = parsedInstruction;
     this.memory            = memory;
     this.alu   = alu;
     this.state = state;
 }
 /// <summary>
 /// Performs actions.
 /// </summary>
 /// <param name="instruction">Parsed instruction.</param>
 /// <param name="memory">Memory.</param>
 /// <param name="state">Processor state.</param>
 /// <param name="alu">ALU.</param>
 public void PerformActions(IParsedInstruction instruction, IEmulatedMemory memory, IProcessorState state, IALU alu)
 {
     foreach (var action in this.actions)
     {
         action.PerformAction(instruction, memory, state, alu);
     }
 }
Exemple #5
0
 /// <inheritdoc/>
 public override void PerformAction(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu)
 {
     alu.PerformAction(this.calculation, instruction.Immediate);
 }
Exemple #6
0
 /// <inheritdoc/>
 public void PutData(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu,
     long value)
 {
     throw new NotImplementedException();
 }
Exemple #7
0
 /// <inheritdoc/>
 public void PutData(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu,
     long value)
 {
     memory.SetValue(instruction.Width, (ulong)value, (ushort)state.Registers[instruction.Register1]);
 }
Exemple #8
0
 /// <inheritdoc/>
 public void PutData(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu,
     long value)
 {
     alu.StageValue(0, value);
 }
 /// <inheritdoc/>
 public void PutData(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu,
     long value)
 {
     state.ProgramCounter = (ushort)value;
 }
 /// <inheritdoc/>
 public void PutData(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu,
     long value)
 {
     state.Registers[instruction.Register2] = value;
 }
Exemple #11
0
 /// <inheritdoc/>
 public void PutData(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu,
     long value)
 {
     memory.SetValue(instruction.Width, (ulong)value, instruction.Address);
 }
Exemple #12
0
        /// <inheritdoc/>
        public override void PerformAction(
            IParsedInstruction instruction,
            IEmulatedMemory memory,
            IProcessorState state,
            IALU alu)
        {
            long value = this.from.GetData(instruction, memory, state, alu);

            this.to.PutData(instruction, memory, state, alu, value);
        }
Exemple #13
0
 /// <inheritdoc/>
 public override void PerformAction(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu)
 {
     if (state.Low & this.low || state.Equal & this.equal || state.High & this.high)
     {
         this.action.PerformAction(instruction, memory, state, alu);
     }
 }
Exemple #14
0
        /// <inheritdoc/>
        public override void PerformAction(
            IParsedInstruction instruction,
            IEmulatedMemory memory,
            IProcessorState state,
            IALU alu)
        {
            long a = state.Registers[instruction.Register1];
            long b = state.Registers[instruction.Register2];

            state.High  = a > b;
            state.Equal = a == b;
            state.Low   = !state.High;
        }
 /// <inheritdoc/>
 public long GetData(IParsedInstruction instruction, IEmulatedMemory memory, IProcessorState state, IALU alu)
 {
     return(state.Registers[instruction.Register2]);
 }
 /// <inheritdoc/>
 public long GetData(IParsedInstruction instruction, IEmulatedMemory memory, IProcessorState state, IALU alu)
 {
     return(state.ProgramCounter + instruction.Offset);
 }
Exemple #17
0
 /// <inheritdoc/>
 public long GetData(IParsedInstruction instruction, IEmulatedMemory memory, IProcessorState state, IALU alu)
 {
     return((long)memory.GetValue(instruction.Width, instruction.Address));
 }
Exemple #18
0
 /// <summary>
 /// Performs processor action.
 /// </summary>
 /// <param name="instruction">Parsed instruction.</param>
 /// <param name="memory">Memory.</param>
 /// <param name="state">Processor state.</param>
 /// <param name="alu">ALU.</param>
 public abstract void PerformAction(
     IParsedInstruction instruction,
     IEmulatedMemory memory,
     IProcessorState state,
     IALU alu);
Exemple #19
0
 /// <inheritdoc/>
 public long GetData(IParsedInstruction instruction, IEmulatedMemory memory, IProcessorState state, IALU alu)
 {
     return(instruction.Address);
 }
Exemple #20
0
 /// <inheritdoc/>
 public long GetData(IParsedInstruction instruction, IEmulatedMemory memory, IProcessorState state, IALU alu)
 {
     return((long)memory.GetValue(instruction.Width, (ushort)state.Registers[instruction.Register1]));
 }