public void StopsAtTerminationPointWhenRequested()
        {
            // --- Arrange
            var pars          = new ScreenConfiguration();
            var pixels        = new TestPixelRenderer(pars);
            var spectrum      = new SpectrumAdvancedTestMachine(pars, pixels);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
                0x76              // HALT
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None,
                                  new ExecuteCycleOptions(EmulationMode.UntilExecutionPoint, terminationPoint: 0x8003));

            // --- Assert
            regs.A.ShouldBe((byte)0x20);
            regs.B.ShouldBe((byte)0x00);
            regs.C.ShouldBe((byte)0x00);
            regs.PC.ShouldBe((ushort)0x8003);
        }
        public void RegisterRWorksWithTrueCondition()
        {
            // --- Arrange
            var spectrum = new SpectrumAdvancedTestMachine();

            spectrum.DebugExpressionContext = new SpectrumEvaluationContext(spectrum);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x06, 0x80,       // LD B,$80
                0x78,             // LD A,B
                0xED, 0x47,       // LD I,A
                0x10, 0xFB,       // DJNZ -5
                0x76,             // HALT
            });

            var bp = CreateBreakpoint(null, "R == 14");

            debugProvider.Breakpoints.Add(0x8003, bp);
            debugProvider.Breakpoints.Add(0x8007, MinimumBreakpointInfo.EmptyBreakpointInfo);
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Assert
            regs.R.ShouldBe((byte)0x0E);
            regs.I.ShouldBe((byte)0x7E);
            regs.B.ShouldBe((byte)0x7D);
            regs.PC.ShouldBe((ushort)0x8003);
        }
        public void RegisterIxlWorksWithFalseCondition()
        {
            // --- Arrange
            var spectrum = new SpectrumAdvancedTestMachine();

            spectrum.DebugExpressionContext = new SpectrumEvaluationContext(spectrum);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x06, 0x80,       // LD B,$80
                0xDD, 0x2E, 0x00, // LD XL,$00
                0xDD, 0x2C,       // INC XL
                0x10, 0xFC,       // DJNZ -4
                0x76,             // HALT
            });

            var bp = CreateBreakpoint(null, "IXL == 0xFF");

            debugProvider.Breakpoints.Add(0x8005, bp);
            debugProvider.Breakpoints.Add(0x8009, MinimumBreakpointInfo.EmptyBreakpointInfo);
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Assert
            regs.XL.ShouldBe((byte)0x80);
            regs.B.ShouldBe((byte)0x00);
            regs.PC.ShouldBe((ushort)0x8009);
        }
        public void MachineWorksWithNoDebugCondition()
        {
            // --- Arrange
            var spectrum = new SpectrumAdvancedTestMachine();

            spectrum.DebugExpressionContext = new SpectrumEvaluationContext(spectrum);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
            });

            var bp = CreateBreakpoint(null, null);

            debugProvider.Breakpoints.Add(0x8000, bp);
            debugProvider.Breakpoints.Add(0x8007, MinimumBreakpointInfo.EmptyBreakpointInfo);
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Assert
            regs.A.ShouldBe((byte)0x00);
            regs.B.ShouldBe((byte)0x00);
            regs.C.ShouldBe((byte)0x00);
            regs.PC.ShouldBe((ushort)0x8000);
        }
        public void CycleWorksWithMultiplyHitCondition1()
        {
            // --- Arrange
            var spectrum = new SpectrumAdvancedTestMachine();

            spectrum.DebugExpressionContext = new SpectrumEvaluationContext(spectrum);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x06, 0x80,       // LD B,$80
                0x3E, 0x00,       // LD A,$00
                0x3C,             // INC A
                0x10, 0xFD,       // DJNZ -3
                0x76,             // HALT
            });

            var bp = CreateBreakpoint("*8", null);

            debugProvider.Breakpoints.Add(0x8004, bp);
            debugProvider.Breakpoints.Add(0x8007, MinimumBreakpointInfo.EmptyBreakpointInfo);
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Assert
            regs.A.ShouldBe((byte)0x07);
            regs.B.ShouldBe((byte)0x79);
            regs.PC.ShouldBe((ushort)0x8004);
        }
Esempio n. 6
0
        public void DoesNotStopAtTerminationPointInNormalExecutionMode()
        {
            // --- Arrange
            var spectrum      = new SpectrumAdvancedTestMachine();
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
                0x76              // HALT
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None,
                                  new ExecuteCycleOptions(EmulationMode.UntilHalt, terminationPoint: 0x0002));

            // --- Assert
            regs.A.ShouldBe((byte)0x20);
            regs.B.ShouldBe((byte)0x20);
            regs.C.ShouldBe((byte)0x20);
            regs.PC.ShouldBe((ushort)0x8005);
        }
Esempio n. 7
0
        public void StepIntoStopsAtNextInstruction()
        {
            // --- Arrange
            var pars          = new ScreenConfiguration();
            var pixels        = new TestPixelRenderer(pars);
            var spectrum      = new SpectrumAdvancedTestMachine(pars, pixels);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepInto));

            // --- Assert
            regs.A.ShouldBe((byte)0x10);
            regs.B.ShouldBe((byte)0x00);
            regs.C.ShouldBe((byte)0x00);
            regs.PC.ShouldBe((ushort)0x8002);
        }
Esempio n. 8
0
        public void MachineStopsAtMultipleBreakpoints()
        {
            // --- Arrange
            var pars          = new ScreenConfiguration();
            var pixels        = new TestPixelRenderer(pars);
            var spectrum      = new SpectrumAdvancedTestMachine(pars, pixels);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
            });
            debugProvider.Breakpoints.Add(0x8003, MinimumBreakpointInfo.EmptyBreakpointInfo);
            debugProvider.Breakpoints.Add(0x8004, MinimumBreakpointInfo.EmptyBreakpointInfo);
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));
            var pc1 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Assert
            regs.A.ShouldBe((byte)0x20);
            regs.B.ShouldBe((byte)0x20);
            regs.C.ShouldBe((byte)0x00);
            pc1.ShouldBe((ushort)0x8003);
            regs.PC.ShouldBe((ushort)0x8004);
        }
Esempio n. 9
0
        public void Flag5WorksWithFalseCondition()
        {
            // --- Arrange
            var spectrum = new SpectrumAdvancedTestMachine();

            spectrum.DebugExpressionContext = new SpectrumEvaluationContext(spectrum);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x04,       // LD A,$04
                0xB7,             // OR A
                0x47,             // LD B,A
                0x76,             // HALT
            });

            var bp = CreateBreakpoint(null, "`5");

            debugProvider.Breakpoints.Add(0x8003, bp);
            debugProvider.Breakpoints.Add(0x8004, MinimumBreakpointInfo.EmptyBreakpointInfo);
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Assert
            regs.PC.ShouldBe((ushort)0x8004);
        }
Esempio n. 10
0
        public void MachineStopsAtFirstInstructionBreakpointAndStepsFurther()
        {
            // --- Arrange
            var spectrum      = new SpectrumAdvancedTestMachine();
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
            });
            debugProvider.Breakpoints.Add(0x8000, MinimumBreakpointInfo.EmptyBreakpointInfo);
            debugProvider.Breakpoints.Add(0x8002, MinimumBreakpointInfo.EmptyBreakpointInfo);
            var regs = spectrum.Cpu.Registers;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger));

            // --- Assert
            regs.A.ShouldBe((byte)0x10);
            regs.B.ShouldBe((byte)0x00);
            regs.C.ShouldBe((byte)0x00);
            regs.PC.ShouldBe((ushort)0x8002);
        }
Esempio n. 11
0
        public void StepOverWorksWithRst()
        {
            // --- Arrange
            var spectrum      = new SpectrumAdvancedTestMachine();
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0xF3,       // DI
                0x16, 0x06, // LD D,6
                0xFF,       // RST $38
                0x7A,       // LD A,D
                0x76        // HALT
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc1 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc2 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));

            // --- Assert
            regs.D.ShouldBe((byte)0x06);
            pc1.ShouldBe((ushort)0x8003);
            pc2.ShouldBe((ushort)0x8004);
            regs.PC.ShouldBe((ushort)0x8005);
        }
Esempio n. 12
0
        public void StepOverWorksWithCallPFalse()
        {
            // --- Arrange
            var pars          = new ScreenConfiguration();
            var pixels        = new TestPixelRenderer(pars);
            var spectrum      = new SpectrumAdvancedTestMachine(pars, pixels);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x90,       // LD A,$90
                0xB7,             // OR A
                0xF4, 0x09, 0x80, // CALL P,$8009
                0x47,             // LD B,A
                0x4F,             // LD C,A
                0x76,             // HALT
                0x3E, 0x20,       // LD a,$20
                0x57,             // LD D,A
                0xC9              // RET
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc1 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc2 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));

            // --- Assert
            regs.A.ShouldBe((byte)0x90);
            regs.B.ShouldBe((byte)0x90);
            regs.C.ShouldBe((byte)0x00);
            regs.D.ShouldBe((byte)0x00);
            pc1.ShouldBe((ushort)0x8003);
            pc2.ShouldBe((ushort)0x8006);
            regs.PC.ShouldBe((ushort)0x8007);
        }
Esempio n. 13
0
        public void StepOverWorksWithMultipleSteps()
        {
            // --- Arrange
            var spectrum      = new SpectrumAdvancedTestMachine();
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc1 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc2 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc3 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));

            // --- Assert
            regs.A.ShouldBe((byte)0x20);
            regs.B.ShouldBe((byte)0x20);
            regs.C.ShouldBe((byte)0x20);
            pc1.ShouldBe((ushort)0x8002);
            pc2.ShouldBe((ushort)0x8003);
            pc3.ShouldBe((ushort)0x8004);
            regs.PC.ShouldBe((ushort)0x8005);
        }
Esempio n. 14
0
        public void StopWhenTimeout()
        {
            // --- Arrange
            var spectrum      = new SpectrumAdvancedTestMachine();
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0xC3, 0x00, 0x80  // JP #8000
            });
            var start = spectrum.Cpu.Tacts;

            // --- Act
            var result = spectrum.ExecuteCycle(CancellationToken.None,
                                               new ExecuteCycleOptions(EmulationMode.UntilHalt, timeoutTacts: 35000));

            // --- Assert
            result.ShouldBeFalse();
            (spectrum.Cpu.Tacts - start).ShouldBeGreaterThanOrEqualTo(35000);
        }