public override void Process(ICpuStateOperations cpuStateManager)
 {
     var programCounter = cpuStateManager.IncrementProgramCounter();
     this.nextWordAddress = cpuStateManager.ReadMemoryValueAtAddress(programCounter);
     this.registerValue =
         cpuStateManager.ReadGeneralPursoseRegisterValue((ushort)(this.OperandValue % NumberOfRegisters));
 }
Пример #2
0
        public override void Write(ICpuStateOperations cpuStateManager, ushort value)
        {
            var stackPointerValue = cpuStateManager.DecrementStackPointer();
            
            if (cpuStateManager.ReadMemoryValueAtAddress(stackPointerValue) != 0x0)
            {
                throw new Exception("DCPU16 Stack overflow");
            }

            cpuStateManager.WriteMemoryValueAtAddress(stackPointerValue, value);
        }
Пример #3
0
        public Instruction Build(ushort instructionValue, ICpuStateOperations cpuState)
        {
            if (this.instructionCache.Keys.Contains(instructionValue))
            {
                return this.instructionCache[instructionValue];
            }

            this.rawInstruction = instructionValue;

            this.opcode = (ushort)(rawInstruction & OpMask);

            if (this.opcode == 0)
            {
                var op = (ushort)((instructionValue >> OperandAShift) & OperandAMask);

                if (op == 0x01)
                {
                    var operandValue = (ushort)((instructionValue >> OperandBShift) & OperandBMask);

                    this.operationA = new CpuOperation(this.operandFactory.Create(operandValue), cpuState);
                    this.operationB = null;

                    var jsrInstruction = new JsrInstruction(0, this.operationA, this.operationA);
                    this.instructionCache[instructionValue] = jsrInstruction;

                    return jsrInstruction;
                }

                return null;
            }

            var firstOperandValue = (ushort)((instructionValue >> OperandAShift) & OperandAMask);
            var secondOperandValue = (ushort)((instructionValue >> OperandBShift) & OperandBMask);

            this.operationA = new CpuOperation(this.operandFactory.Create(firstOperandValue), cpuState);
            this.operationB = new CpuOperation(this.operandFactory.Create(secondOperandValue), cpuState);

            var instruction = this.instructionMapper[(BasicOpcode)this.opcode]();

            this.instructionCache[instructionValue] = instruction;

            return instruction;
        }
Пример #4
0
 public virtual void Write(ICpuStateOperations cpuStateManager, ushort value)
 {
     throw new InvalidOperationException();
 }
Пример #5
0
 public virtual void Process(ICpuStateOperations cpuStateManager)
 {
 }
Пример #6
0
 public override void NoOp(ICpuStateOperations cpuStateManager)
 {
     cpuStateManager.IncrementProgramCounter();
 }
Пример #7
0
 public override void Process(ICpuStateOperations cpuStateManager)
 {
     this.literal = (ushort)((this.OperandValue - 0x20) % NumberOfLiterals);
 }
Пример #8
0
 public override void Write(ICpuStateOperations cpuStateManager, ushort value)
 {
     cpuStateManager.WriteGeneralPursoseRegisterValue(this.OperandValue, value);
 }
 public override void Write(ICpuStateOperations cpuStateManager, ushort value)
 {
     cpuStateManager.SetProgramCounter(value);
 }
Пример #10
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return cpuStateManager.Overflow;
 }
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return
         (ushort)(cpuStateManager.ReadMemoryValueAtAddress((ushort)(this.nextWordAddress + this.registerValue)) & ShortMask);
 }
 public override void Process(ICpuStateOperations cpuStateManager)
 {
     this.registerValue =
         cpuStateManager.ReadGeneralPursoseRegisterValue((ushort)(this.OperandValue % NumberOfRegisters));
 }
Пример #13
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     throw new InvalidOperationException();
 }
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return cpuStateManager.ReadMemoryValueAtAddress(this.registerValue);
 }
Пример #15
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return cpuStateManager.StackPointer;
 }
 public override void Write(ICpuStateOperations cpuStateManager, ushort value)
 {
     cpuStateManager.WriteMemoryValueAtAddress((this.nextWordAddress + this.registerValue) & Operand.ShortMask, value);
 }
Пример #17
0
 public virtual void NoOp(ICpuStateOperations cpuStateManager)
 {
 }
Пример #18
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return cpuStateManager.ReadMemoryValueAtAddress(cpuStateManager.StackPointer);
 }
Пример #19
0
 public CpuOperation(Operand operand, ICpuStateOperations cpuStateManager)
 {
     this.operand = operand;
     this.cpuStateManager = cpuStateManager;
 }
Пример #20
0
 public override void Write(ICpuStateOperations cpuStateManager, ushort value)
 {
     cpuStateManager.SetStackPointer(value);
 }
Пример #21
0
 public override void Write(ICpuStateOperations cpuStateManager, ushort value)
 {
     cpuStateManager.Overflow = value;
 }
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return cpuStateManager.ReadMemoryValueAtAddress(this.nextWordAddress);
 }
Пример #23
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return cpuStateManager.ReadGeneralPursoseRegisterValue(this.OperandValue);
 }
 public override void Write(ICpuStateOperations cpuStateManager, ushort value)
 {
     cpuStateManager.WriteMemoryValueAtAddress(this.nextWordAddress, value);
 }
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return cpuStateManager.ProgramCounter;
 }
 public override void Process(ICpuStateOperations cpuStateManager)
 {
     var programCounter = cpuStateManager.IncrementProgramCounter();
     this.nextWordAddress = cpuStateManager.ReadMemoryValueAtAddress(programCounter);
 }
Пример #27
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     cpuStateManager.IncrementProgramCounter();
     var value = cpuStateManager.ReadValueAtProgramCounter();
     return value;
 }
Пример #28
0
 public virtual ushort Read(ICpuStateOperations cpuStateManager)
 {
     throw new InvalidOperationException();
 }
Пример #29
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     var value = cpuStateManager.ReadMemoryValueAtAddress(cpuStateManager.StackPointer);
     cpuStateManager.IncrementStackPointer();
     return value;
 }
Пример #30
0
 public override ushort Read(ICpuStateOperations cpuStateManager)
 {
     return this.literal;
 }