Esempio n. 1
0
        public void PUSH_DE_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x11, 0x52, 0x23, // LD DE,2352H
                0xD5,             // PUSH DE
                0xE1              // POP HL
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            regs.HL.ShouldBe((ushort)0x2352);
            m.ShouldKeepRegisters(except: "HL, DE");
            m.ShouldKeepMemory(except: "FFFE-FFFF");

            regs.PC.ShouldBe((ushort)0x0005);
            m.Cpu.Tacts.ShouldBe(31L);
        }
Esempio n. 2
0
        public void LD_DEi_A_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x11, 0x26, 0xA9, // LD DE,A926H
                0x3E, 0x94,       // LD A,94H
                0x12              // LD (DE),A
            });

            // --- Act
            var valueBefore = m.Memory[0xA926];

            m.Run();
            var valueAfter = m.Memory[0xA926];

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "DE, A");
            m.ShouldKeepMemory(except: "A926");

            regs.DE.ShouldBe((ushort)0xA926);
            regs.A.ShouldBe((byte)0x94);
            valueBefore.ShouldBe((byte)0);
            valueAfter.ShouldBe((byte)0x94);
            regs.PC.ShouldBe((ushort)0x0006);
            m.Cpu.Tacts.ShouldBe(24L);
        }
Esempio n. 3
0
        public void INC_D_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x16, 0x43, // LD B,43H
                0x14        // INC D
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "D, F");
            m.ShouldKeepMemory();
            m.ShouldKeepCFlag();
            regs.NFlag.ShouldBeFalse();

            regs.D.ShouldBe((byte)0x44);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Esempio n. 4
0
        public void ADD_HL_BC_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x21, 0x34, 0x12, // LD HL,1234H
                0x11, 0x02, 0x11, // LD DE,1102H
                0x19              // ADD HL,DE
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "F, DE, HL");
            m.ShouldKeepMemory();
            m.ShouldKeepSFlag();
            m.ShouldKeepZFlag();
            m.ShouldKeepPVFlag();
            regs.NFlag.ShouldBeFalse();

            regs.CFlag.ShouldBeFalse();
            regs.HFlag.ShouldBeFalse();

            regs.HL.ShouldBe((ushort)0x2336);
            regs.PC.ShouldBe((ushort)0x0007);
            m.Cpu.Tacts.ShouldBe(31L);
        }
Esempio n. 5
0
        public void OUT_N_A_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0x16,       // LD A,16H
                0xD3, 0x28        // OUT (N),A
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.IoAccessLog.Count.ShouldBe(1);
            m.IoAccessLog[0].Address.ShouldBe((ushort)0x1628);
            m.IoAccessLog[0].Value.ShouldBe((byte)0x16);
            m.IoAccessLog[0].IsOutput.ShouldBeTrue();

            m.ShouldKeepRegisters(except: "AF");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(18L);
        }
Esempio n. 6
0
        public void CALL_NC_DoesNotCallWhenC()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilHalt);

            m.InitCode(new byte[]
            {
                0x3E, 0x16,       // LD A,16H
                0x37,             // SCF
                0xD4, 0x07, 0x00, // CALL NC,0007H
                0x76,             // HALT
                0x3E, 0x24,       // LD A,24H
                0xC9              // RET
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            regs.A.ShouldBe((byte)0x16);
            m.ShouldKeepRegisters(except: "AF");
            m.ShouldKeepMemory(except: "FFFE-FFFF");

            regs.PC.ShouldBe((ushort)0x0006);
            m.Cpu.Tacts.ShouldBe(25);
        }
Esempio n. 7
0
        public void JP_NC_DoesNotJumpWhenC()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilHalt);

            m.InitCode(new byte[]
            {
                0x3E, 0x16,       // LD A,16H
                0x37,             // SCF
                0xD2, 0x07, 0x00, // JP NC,0007H
                0x76,             // HALT
                0x3E, 0xAA,       // LD A,AAH
                0x76              // HALT
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            regs.A.ShouldBe((byte)0x16);
            m.ShouldKeepRegisters(except: "AF");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0006);
            m.Cpu.Tacts.ShouldBe(25);
        }
Esempio n. 8
0
        public void RET_NC_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilHalt);

            m.InitCode(new byte[]
            {
                0x3E, 0x16,       // LD A,16H
                0xCD, 0x06, 0x00, // CALL 0006H
                0x76,             // HALT
                0xA7,             // AND A
                0xD0,             // RET NC
                0x3E, 0x24,       // LD A,24H
                0xC9              // RET
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            regs.A.ShouldBe((byte)0x16);
            m.ShouldKeepRegisters(except: "AF");
            m.ShouldKeepMemory(except: "FFFE-FFFF");

            regs.PC.ShouldBe((ushort)0x0005);
            m.Cpu.Tacts.ShouldBe(43L);
        }
Esempio n. 9
0
        public void XRLC_B_SetsCarry()
        {
            // --- Arrange
            const byte OFFS = 0x32;
            var        m    = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0XFD, 0xCB, OFFS, 0x00 // RLC (IY+32H),B
            });
            var regs = m.Cpu.Registers;

            regs.IY = 0x1000;
            m.Memory[regs.IY + OFFS] = 0x84;

            // --- Act
            m.Run();

            // --- Assert
            regs.B.ShouldBe(m.Memory[regs.IY + OFFS]);
            regs.B.ShouldBe((byte)0x09);

            regs.SFlag.ShouldBeFalse();
            regs.ZFlag.ShouldBeFalse();
            regs.CFlag.ShouldBeTrue();
            regs.PFlag.ShouldBeTrue();

            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "F, B");
            m.ShouldKeepMemory(except: "1032");

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(23L);
        }
Esempio n. 10
0
        public void JP_NC_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilHalt);

            m.InitCode(new byte[]
            {
                0x3E, 0x16,       // LD A,16H
                0xA7,             // AND A
                0xD2, 0x07, 0x00, // JP NC,0007H
                0x76,             // HALT
                0x3E, 0xAA,       // LD A,AAH
                0x76              // HALT
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            regs.A.ShouldBe((byte)0xAA);
            m.ShouldKeepRegisters(except: "AF");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0009);
            m.Cpu.Tacts.ShouldBe(32L);
        }
Esempio n. 11
0
        public void XRLC_B_WorksWithNegativeOffset()
        {
            // --- Arrange
            const byte OFFS = 0xFE;
            var        m    = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0XFD, 0xCB, OFFS, 0x00 // RLC (IY+32H),B
            });
            var regs = m.Cpu.Registers;

            regs.IY = 0x1000;
            m.Memory[regs.IY - 256 + OFFS] = 0x08;

            // --- Act
            m.Run();

            // --- Assert
            regs.B.ShouldBe(m.Memory[regs.IY - 256 + OFFS]);
            regs.B.ShouldBe((byte)0x10);

            regs.SFlag.ShouldBeFalse();
            regs.ZFlag.ShouldBeFalse();
            regs.CFlag.ShouldBeFalse();
            regs.PFlag.ShouldBeFalse();

            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "F, B");
            m.ShouldKeepMemory(except: "0FFE");

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(23L);
        }
Esempio n. 12
0
        public void XRRC_A_WorksAsExpected()
        {
            // --- Arrange
            const byte OFFS = 0x32;
            var        m    = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0XFD, 0xCB, OFFS, 0x0F // RRC (IY+32H),A
            });
            var regs = m.Cpu.Registers;

            regs.IY = 0x1000;
            m.Memory[regs.IY + OFFS] = 0x08;

            // --- Act
            m.Run();

            // --- Assert
            regs.A.ShouldBe(m.Memory[regs.IY + OFFS]);
            regs.A.ShouldBe((byte)0x04);

            regs.SFlag.ShouldBeFalse();
            regs.ZFlag.ShouldBeFalse();
            regs.CFlag.ShouldBeFalse();
            regs.PFlag.ShouldBeFalse();

            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "F, A");
            m.ShouldKeepMemory(except: "1032");

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(23L);
        }
Esempio n. 13
0
        public void RRA_UsesCarry()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0x20, // LD A,20H
                0x37,       // SCF
                0x1F        // RRA
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "A, F");
            m.ShouldKeepMemory();
            m.ShouldKeepSFlag();
            m.ShouldKeepZFlag();
            m.ShouldKeepPVFlag();
            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();

            regs.CFlag.ShouldBeFalse();

            regs.A.ShouldBe((byte)0x90);
            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(15L);
        }
Esempio n. 14
0
        public void RRA_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0x81, // LD A,81H
                0x1F        // RRA
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "A, F");
            m.ShouldKeepMemory();
            m.ShouldKeepSFlag();
            m.ShouldKeepZFlag();
            m.ShouldKeepPVFlag();
            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();

            regs.CFlag.ShouldBeTrue();

            regs.A.ShouldBe((byte)0x40);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Esempio n. 15
0
        public void DEC_E_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x1E, 0x43, // LD E,43H
                0x1D        // DEC E
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "E, F");
            m.ShouldKeepMemory();
            m.ShouldKeepCFlag();
            regs.NFlag.ShouldBeTrue();

            regs.E.ShouldBe((byte)0x42);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Esempio n. 16
0
        public void RST_10_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0x3E, 0x12, // LD A,12H
                0xD7        // RST 10H
            });

            // --- Act
            m.Run();
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            regs.A.ShouldBe((byte)0x12);

            regs.SP.ShouldBe((ushort)0xFFFE);
            regs.PC.ShouldBe((ushort)0x10);
            m.Memory[0xFFFE].ShouldBe((byte)0x03);
            m.Memory[0xFFFf].ShouldBe((byte)0x00);

            m.ShouldKeepRegisters(except: "SP");
            m.ShouldKeepMemory(except: "FFFE-FFFF");

            m.Cpu.Tacts.ShouldBe(18L);
        }
Esempio n. 17
0
        public void SUB_N_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0x36, // LD A,36H
                0xD6, 0x24  // SUB 24H
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            regs.A.ShouldBe((byte)0x12);
            regs.SFlag.ShouldBeFalse();
            regs.ZFlag.ShouldBeFalse();
            regs.HFlag.ShouldBeFalse();
            regs.PFlag.ShouldBeFalse();
            regs.CFlag.ShouldBeFalse();

            regs.NFlag.ShouldBeTrue();
            m.ShouldKeepRegisters(except: "AF, B");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(14L);
        }
Esempio n. 18
0
        /// <summary>
        /// Tests if C flag keeps its value while running a test.
        /// </summary>
        /// <param name="machine">Z80 test machine</param>
        public static void ShouldKeepCFlag(this Z80TestMachine machine)
        {
            var before = (machine.RegistersBeforeRun.F & FlagsSetMask.C) != 0;
            var after  = (machine.Cpu.Registers.F & FlagsSetMask.C) != 0;

            if (after == before)
            {
                return;
            }
            Assert.Fail($"C flag expected to keep its value, but it changed from {before} to {after}");
        }
Esempio n. 19
0
        public void OTDR_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0xED, 0xBB // OTDR
            });
            var regs = m.Cpu.Registers;

            regs.BC = 0x3CC;
            regs.HL = 0x1002;
            m.Memory[regs.HL - 2] = 0x29;
            m.Memory[regs.HL - 1] = 0x2A;
            m.Memory[regs.HL]     = 0x2B;

            // --- Act
            m.Run();

            // --- Assert

            regs.B.ShouldBe((byte)0x00);
            regs.C.ShouldBe((byte)0xCC);
            regs.HL.ShouldBe((ushort)0x0FFF);

            regs.ZFlag.ShouldBeTrue();
            regs.NFlag.ShouldBeTrue();
            regs.CFlag.ShouldBeTrue();
            m.ShouldKeepRegisters(except: "F, BC, HL");
            m.ShouldKeepMemory();

            m.IoAccessLog.Count.ShouldBe(3);
            m.IoAccessLog[0].Address.ShouldBe((ushort)0x02CC);
            m.IoAccessLog[0].Value.ShouldBe((byte)0x2B);
            m.IoAccessLog[0].IsOutput.ShouldBeTrue();
            m.IoAccessLog[1].Address.ShouldBe((ushort)0x01CC);
            m.IoAccessLog[1].Value.ShouldBe((byte)0x2A);
            m.IoAccessLog[1].IsOutput.ShouldBeTrue();
            m.IoAccessLog[2].Address.ShouldBe((ushort)0x00CC);
            m.IoAccessLog[2].Value.ShouldBe((byte)0x29);
            m.IoAccessLog[2].IsOutput.ShouldBeTrue();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(58L);
        }
Esempio n. 20
0
        public void SCF_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x37 // SCF
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "F");
            regs.CFlag.ShouldBeTrue();
            regs.PC.ShouldBe((ushort)0x0001);
            m.Cpu.Tacts.ShouldBe(4L);
        }
Esempio n. 21
0
        public void LDIR_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0xED, 0xB0 // LDIR
            });
            var regs = m.Cpu.Registers;

            regs.BC               = 0x0003;
            regs.HL               = 0x1001;
            regs.DE               = 0x1000;
            m.Memory[regs.HL]     = 0xA5;
            m.Memory[regs.HL + 1] = 0xA6;
            m.Memory[regs.HL + 2] = 0xA7;

            // --- Act
            m.Run();

            // --- Assert

            m.Memory[0x1000].ShouldBe((byte)0xA5);
            m.Memory[0x1001].ShouldBe((byte)0xA6);
            m.Memory[0x1002].ShouldBe((byte)0xA7);
            regs.BC.ShouldBe((ushort)0x0000);
            regs.HL.ShouldBe((ushort)0x1004);
            regs.DE.ShouldBe((ushort)0x1003);
            regs.PFlag.ShouldBeFalse();

            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();
            regs.CFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "F, BC, DE, HL");
            m.ShouldKeepMemory(except: "1000-1002");

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(58L);
        }
Esempio n. 22
0
        public void BIT_N_B_WorksWithBitSet()
        {
            const byte OFFS = 0x54;

            for (var n = 0; n < 8; n++)
            {
                for (var repeat = 0; repeat < 8; repeat++)
                {
                    // --- Arrange
                    var m    = new Z80TestMachine(RunMode.OneInstruction);
                    var opcn = (byte)(0x40 | (n << 3) | repeat);

                    m.InitCode(new byte[]
                    {
                        0xFD, 0xCB, OFFS, opcn // BIT N,(IY+54H)
                    });

                    var regs = m.Cpu.Registers;
                    regs.IY = 0x1000;
                    m.Memory[regs.IY + OFFS] = (byte)(0x01 << n);

                    // --- Act
                    m.Run();

                    // --- Assert
                    regs.SFlag.ShouldBe(n == 0x07);
                    regs.ZFlag.ShouldBeFalse();
                    regs.CFlag.ShouldBeFalse();
                    regs.PFlag.ShouldBeFalse();

                    regs.HFlag.ShouldBeTrue();
                    regs.NFlag.ShouldBeFalse();
                    m.ShouldKeepRegisters(except: "F");
                    m.ShouldKeepMemory();

                    regs.PC.ShouldBe((ushort)0x0004);
                    m.Cpu.Tacts.ShouldBe(20L);
                }
            }
        }
Esempio n. 23
0
        public void JR_E_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0x20, // LD A,20H
                0x18, 0x20  // JR 20H
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "A");
            m.ShouldKeepMemory();
            regs.PC.ShouldBe((ushort)0x0024);
            m.Cpu.Tacts.ShouldBe(19L);
        }
Esempio n. 24
0
        public void NopWorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0x00, // NOP
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters();
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0001);
            m.Cpu.Tacts.ShouldBe(4L);
        }
Esempio n. 25
0
        public void INIR_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0xED, 0xB2 // INIR
            });
            var regs = m.Cpu.Registers;

            regs.BC = 0x03CC;
            regs.HL = 0x1000;
            m.IoInputSequence.Add(0x69);
            m.IoInputSequence.Add(0x6A);
            m.IoInputSequence.Add(0x6B);

            // --- Act
            m.Run();

            // --- Assert

            m.Memory[0x1000].ShouldBe((byte)0x69);
            m.Memory[0x1001].ShouldBe((byte)0x6A);
            m.Memory[0x1002].ShouldBe((byte)0x6B);
            regs.B.ShouldBe((byte)0x00);
            regs.C.ShouldBe((byte)0xCC);
            regs.HL.ShouldBe((ushort)0x1003);

            regs.ZFlag.ShouldBeTrue();
            regs.NFlag.ShouldBeTrue();
            regs.CFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "F, BC, HL");
            m.ShouldKeepMemory(except: "1000-1002");

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(58L);
        }
Esempio n. 26
0
        public void CPIR_WorksWithByteFound()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0xED, 0xB1 // CPIR
            });
            var regs = m.Cpu.Registers;

            regs.BC               = 0x0003;
            regs.HL               = 0x1000;
            regs.A                = 0xA6;
            m.Memory[regs.HL]     = 0xA5;
            m.Memory[regs.HL + 1] = 0xA6;
            m.Memory[regs.HL + 2] = 0xA7;

            // --- Act
            m.Run();

            // --- Assert

            regs.BC.ShouldBe((ushort)0x0001);
            regs.HL.ShouldBe((ushort)0x1002);

            regs.ZFlag.ShouldBeTrue();
            regs.PFlag.ShouldBeTrue();
            regs.HFlag.ShouldBeFalse();

            regs.NFlag.ShouldBeTrue();
            regs.CFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "F, BC, HL");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(37L);
        }
Esempio n. 27
0
        public void OUTD_WorksWithZeroedCounter()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0xED, 0xAB // OUTD
            });
            var regs = m.Cpu.Registers;

            regs.BC           = 0x01CC;
            regs.HL           = 0x1000;
            m.Memory[regs.HL] = 0x29;

            // --- Act
            m.Run();

            // --- Assert

            regs.B.ShouldBe((byte)0x00);
            regs.C.ShouldBe((byte)0xCC);
            regs.HL.ShouldBe((ushort)0x0FFF);

            regs.ZFlag.ShouldBeTrue();
            regs.NFlag.ShouldBeTrue();
            regs.CFlag.ShouldBeTrue();
            m.ShouldKeepRegisters(except: "F, BC, HL");
            m.ShouldKeepMemory(except: "1000");

            m.IoAccessLog.Count.ShouldBe(1);
            m.IoAccessLog[0].Address.ShouldBe((ushort)0x00CC);
            m.IoAccessLog[0].Value.ShouldBe((byte)0x29);
            m.IoAccessLog[0].IsOutput.ShouldBeTrue();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(16L);
        }
Esempio n. 28
0
        public void CPDR_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0xED, 0xB9 // CPDR
            });
            var regs = m.Cpu.Registers;

            regs.BC = 0x0003;
            regs.HL = 0x1002;
            regs.A  = 0x11;
            m.Memory[regs.HL - 2] = 0xA5;
            m.Memory[regs.HL - 1] = 0xA6;
            m.Memory[regs.HL]     = 0xA7;

            // --- Act
            m.Run();

            // --- Assert

            regs.BC.ShouldBe((ushort)0x0000);
            regs.HL.ShouldBe((ushort)0x0FFF);

            regs.ZFlag.ShouldBeFalse();
            regs.PFlag.ShouldBeFalse();
            regs.HFlag.ShouldBeTrue();

            regs.NFlag.ShouldBeTrue();
            regs.CFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "F, BC, HL");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(58L);
        }
Esempio n. 29
0
        public void LD_SP_NN_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0x31, 0x26, 0xA9 // LD SP,A926H
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "SP");
            m.ShouldKeepMemory();

            regs.SP.ShouldBe((ushort)0xA926);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(10L);
        }
Esempio n. 30
0
        public void LD_L_N_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0x3E, 0x26 // LD A,26H
            });

            // --- Act
            m.Run();

            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "A");
            m.ShouldKeepMemory();

            regs.A.ShouldBe((byte)0x26);
            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(7L);
        }