コード例 #1
0
        public void ExecutingInstruction_WhichDoesNotModifyPc_IncreasesPcBy2()
        {
            var cpu = new Cpu();

            cpu.Memory[Cpu.MemoryAddressOfFirstInstruction + 1] = 0xE0; // CLS instruction

            Assert.That(cpu.PC, Is.EqualTo(Cpu.MemoryAddressOfFirstInstruction));

            var instructionExecutor = new InstructionExecutor(cpu, _display, _keyboard, _instructionDecoder);
            var instruction         = instructionExecutor.ExecuteSingleInstruction();

            Assert.That(instruction, Is.InstanceOf <Instruction_00E0>());
            Assert.That(cpu.PC, Is.EqualTo(Cpu.MemoryAddressOfFirstInstruction + 2));
        }
コード例 #2
0
        public void ExecutingInstruction_WhichModifiesPc_DoesNotAdditionallyIncreasePcBy2()
        {
            var cpu = new Cpu();

            cpu.Stack.Push(Cpu.MemoryAddressOfFirstInstruction);
            cpu.Memory[Cpu.MemoryAddressOfFirstInstruction + 1] = 0xEE; // RET instruction

            Assert.That(cpu.PC, Is.EqualTo(Cpu.MemoryAddressOfFirstInstruction));

            var instructionExecutor = new InstructionExecutor(cpu, _display, _keyboard, _instructionDecoder);
            var instruction         = instructionExecutor.ExecuteSingleInstruction();

            Assert.That(instruction, Is.InstanceOf <Instruction_00EE>());
            Assert.That(cpu.PC, Is.EqualTo(Cpu.MemoryAddressOfFirstInstruction));
        }
コード例 #3
0
        public void ExecutingInstruction_WithEmptyMemory_ThrowsException()
        {
            var instructionExecutor = new InstructionExecutor(_cpu, _display, _keyboard, _instructionDecoder);

            Assert.Throws <InvalidOperationException>(() => instructionExecutor.ExecuteSingleInstruction());
        }