Пример #1
0
        public void RRC_B_SetsSignFlag()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0xCB, 0x08 // RRC B
            });
            var regs = m.Cpu.Registers;

            regs.B = 0x41;

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

            // --- Assert
            regs.B.ShouldBe((byte)0xA0);

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

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

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(8L);
        }
Пример #2
0
        public void RRC_E_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0xCB, 0x0B // RRC E
            });
            var regs = m.Cpu.Registers;

            regs.E = 0x08;

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

            // --- Assert
            regs.E.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, E");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(8L);
        }
Пример #3
0
        public void LD_H_E_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x1E, 0xB9, // LD E,B9H
                0x63        // LD H,E
            });

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

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

            regs.H.ShouldBe((byte)0xB9);

            m.ShouldKeepRegisters(except: "H, E");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Пример #4
0
        public void RLC_HLi_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0xCB, 0x06 // RLC (HL)
            });
            var regs = m.Cpu.Registers;

            regs.HL           = 0x1000;
            m.Memory[regs.HL] = 0x08;

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

            // --- Assert
            m.Memory[regs.HL].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");
            m.ShouldKeepMemory(except: "1000");

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(15L);
        }
Пример #5
0
        public void CPL_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

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

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

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

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

            regs.A.ShouldBe((byte)0x7E);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Пример #6
0
        public void LD_L_HLi_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x21, 0x00, 0x10, // LD HL,1000H
                0x6E              // LD L,(HL)
            });
            m.Memory[0x1000] = 0xB9;

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

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

            regs.L.ShouldBe((byte)0xB9);

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

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(17L);
        }
Пример #7
0
        public void LD_HL_NNi_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x2A, 0x00, 0x10 // LD HL,(1000H)
            });
            m.Memory[0x1000] = 0x34;
            m.Memory[0x1001] = 0x12;

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

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

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

            regs.HL.ShouldBe((ushort)0x1234);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(16L);
        }
Пример #8
0
        public void DEC_L_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x2E, 0x43, // LD L,43H
                0x2D        // DEC L
            });

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

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

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

            regs.L.ShouldBe((byte)0x42);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Пример #9
0
        public void INC_H_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x26, 0x43, // LD H,43H
                0x24        // INC H
            });

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

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

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

            regs.H.ShouldBe((byte)0x44);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Пример #10
0
        public void ADD_HL_HL_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x21, 0x34, 0x12, // LD HL,1234H
                0x29              // ADD HL,HL
            });

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

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

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

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

            regs.HL.ShouldBe((ushort)0x2468);
            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(21L);
        }
Пример #11
0
        public void LD_NNi_HL_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x21, 0x26, 0xA9, // LD HL,A926H
                0x22, 0x00, 0x10  // LD (1000H),HL
            });

            // --- Act
            var lBefore = m.Memory[0x1000];
            var hBefore = m.Memory[0x1001];

            m.Run();
            var lAfter = m.Memory[0x1000];
            var hAfter = m.Memory[0x1001];
            // --- Assert
            var regs = m.Cpu.Registers;

            m.ShouldKeepRegisters(except: "HL");
            m.ShouldKeepMemory(except: "1000-1001");

            regs.HL.ShouldBe((ushort)0xA926);
            lBefore.ShouldBe((byte)0x00);
            hBefore.ShouldBe((byte)0x00);
            lAfter.ShouldBe((byte)0x26);
            hAfter.ShouldBe((byte)0xA9);

            regs.PC.ShouldBe((ushort)0x0006);
            m.Cpu.Tacts.ShouldBe(26L);
        }
Пример #12
0
        public void SRL_A_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0xCB, 0x3F // SRL A
            });
            var regs = m.Cpu.Registers;

            regs.F |= FlagsSetMask.C;
            regs.A  = 0x10;

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

            // --- Assert
            regs.A.ShouldBe((byte)0x08);

            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();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(8L);
        }
Пример #13
0
        public void AND_B_HandlesZeroFlag()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0xC3, // LD A,C3H
                0x06, 0x3C, // LD B,37H
                0xA0        // AND B
            });

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

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

            regs.A.ShouldBe((byte)0x00);
            regs.SFlag.ShouldBeFalse();
            regs.ZFlag.ShouldBeTrue();
            regs.PFlag.ShouldBeTrue();

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

            regs.PC.ShouldBe((ushort)0x0005);
            m.Cpu.Tacts.ShouldBe(18L);
        }
Пример #14
0
        public void XOR_A_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

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

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

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

            regs.A.ShouldBe((byte)0x00);
            regs.SFlag.ShouldBeFalse();
            regs.ZFlag.ShouldBeTrue();
            regs.PFlag.ShouldBeTrue();

            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();
            regs.CFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "AF");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(11L);
        }
Пример #15
0
        public void XOR_HLi_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0x12,       // LD A,12H
                0x21, 0x00, 0x10, // LD HL,1000H
                0xAE              // XOR (HL)
            });
            m.Memory[0x1000] = 0x23;

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

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

            regs.A.ShouldBe((byte)0x31);
            regs.SFlag.ShouldBeFalse();
            regs.ZFlag.ShouldBeFalse();
            regs.PFlag.ShouldBeFalse();

            regs.HFlag.ShouldBeFalse();
            regs.NFlag.ShouldBeFalse();
            regs.CFlag.ShouldBeFalse();
            m.ShouldKeepRegisters(except: "AF, HL");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0006);
            m.Cpu.Tacts.ShouldBe(24L);
        }
Пример #16
0
        public void DAA_WorksAsExpected()
        {
            // --- Arrange
            var samples = new[]
            {
                //new DaaSample(0x99, false, false, false, 0x998C),
                //new DaaSample(0x99, true, false, false, 0x9F8C),
                //new DaaSample(0x7A, false, false, false, 0x8090),
                //new DaaSample(0x7A, true, false, false, 0x8090),
                //new DaaSample(0xA9, false, false, false, 0x090D),
                //new DaaSample(0x87, false, false, true, 0xE7A5),
                new DaaSample(0x87, true, false, true, 0xEDAD),
                //new DaaSample(0x1B, false, false, true, 0x8195),
                //new DaaSample(0x1B, true, false, true, 0x8195),
                //new DaaSample(0xAA, false, false, false, 0x1011),
                //new DaaSample(0xAA, true, false, false, 0x1011),
                //new DaaSample(0xC6, true, false, false, 0x2C29)
            };

            // --- Act
            foreach (var sample in samples)
            {
                var m = new Z80TestMachine(RunMode.UntilEnd);
                m.InitCode(new byte[]
                {
                    0x27  // DAA
                });
                m.Cpu.Registers.A = sample.A;
                m.Cpu.Registers.F = (byte)((sample.H ? FlagsSetMask.H : 0)
                                           | (sample.N ? FlagsSetMask.N : 0)
                                           | (sample.C ? FlagsSetMask.C : 0));

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

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

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

                regs.AF.ShouldBe(sample.AF);
                regs.PC.ShouldBe((ushort)0x0001);
                m.Cpu.Tacts.ShouldBe(4L);
            }
        }
Пример #17
0
        public void LDDRX_WithNoCopyWorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd, true);

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

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

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

            // --- Assert
            m.Memory[0x2000].ShouldBe((byte)0xA5);
            m.Memory[0x2001].ShouldBe((byte)0xCC);
            m.Memory[0x2002].ShouldBe((byte)0xA7);
            regs.BC.ShouldBe((ushort)0x0000);
            regs.HL.ShouldBe((ushort)0x0FFF);
            regs.DE.ShouldBe((ushort)0x1FFF);
            regs.PFlag.ShouldBeFalse();

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

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(55L);
        }
Пример #18
0
        public void PIXELDN_DoesNopWithNoExtendedInstructionSet()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

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

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

            // --- Assert
            m.ShouldKeepRegisters();
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(8L);
        }
Пример #19
0
        public void LDIRX_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd, true);

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

            regs.A                = 0x00;
            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);
        }
Пример #20
0
        public void LDDX_WorksWithZeroedCounter()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction, true);

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

            regs.A            = 0x00;
            regs.BC           = 0x0001;
            regs.HL           = 0x1000;
            regs.DE           = 0x1001;
            m.Memory[regs.HL] = 0xA5;
            m.Memory[regs.DE] = 0x11;

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

            // --- Assert

            m.Memory[0x1001].ShouldBe((byte)0xA5);
            regs.BC.ShouldBe((ushort)0x0000);
            regs.HL.ShouldBe((ushort)0x0FFF);
            regs.DE.ShouldBe((ushort)0x1000);
            regs.PFlag.ShouldBeFalse();

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

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(16L);
        }
Пример #21
0
        public void LD_HL_NN_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

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

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

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

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

            regs.HL.ShouldBe((ushort)0xA926);
            regs.PC.ShouldBe((ushort)0x0003);
            m.Cpu.Tacts.ShouldBe(10L);
        }
Пример #22
0
        public void LD_L_N_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction);

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

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

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

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

            regs.L.ShouldBe((byte)0x26);
            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(7L);
        }
Пример #23
0
        public void LDIX_WithNoCopyWorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction, true);

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

            regs.A            = 0xA5;
            regs.BC           = 0x0010;
            regs.HL           = 0x1000;
            regs.DE           = 0x1001;
            m.Memory[regs.HL] = 0xA5;
            m.Memory[regs.DE] = 0x11;

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

            // --- Assert
            m.Memory[0x1001].ShouldBe((byte)0x11);
            regs.BC.ShouldBe((ushort)0x000F);
            regs.HL.ShouldBe((ushort)0x1001);
            regs.DE.ShouldBe((ushort)0x1002);
            regs.PFlag.ShouldBeTrue();

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

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(13L);
        }
Пример #24
0
        public void XRL_D_WorksAsExpected()
        {
            // --- Arrange
            const byte OFFS = 0x32;
            var        m    = new Z80TestMachine(RunMode.OneInstruction);

            m.InitCode(new byte[]
            {
                0xFD, 0xCB, OFFS, 0x12 // RL (IY+32H),D
            });
            var regs = m.Cpu.Registers;

            regs.IY = 0x1000;
            regs.F |= FlagsSetMask.C;
            m.Memory[regs.IY + OFFS] = 0x08;

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

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

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

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

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(23L);
        }
Пример #25
0
        public void HALTWorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilHalt);

            m.InitCode(new byte[]
            {
                0x76        // HALT
            });

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

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

            (m.Cpu.StateFlags & Z80StateFlags.Halted).ShouldBe(Z80StateFlags.Halted);

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

            regs.PC.ShouldBe((ushort)0x0000);
            m.Cpu.Tacts.ShouldBe(4L);
        }
Пример #26
0
        public void LD_HLi_L_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x21, 0x22, 0x10, // LD HL,1022H
                0x75              // LD (HL),L
            });

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

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

            m.Memory[0x1022].ShouldBe((byte)0x22);
            m.ShouldKeepRegisters(except: "HL");
            m.ShouldKeepMemory(except: "1022");

            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(17L);
        }
Пример #27
0
        public void PIXELDN_WorksAsExpected(int orig, int down)
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.OneInstruction, true);

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

            regs.HL = (ushort)orig;

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

            // --- Assert
            regs.HL.ShouldBe((ushort)down);
            m.ShouldKeepRegisters(except: "HL");
            m.ShouldKeepMemory();

            regs.PC.ShouldBe((ushort)0x0002);
            m.Cpu.Tacts.ShouldBe(8L);
        }
Пример #28
0
        public void PUSH_NN_WorksAsExpected()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd, true);

            m.InitCode(new byte[]
            {
                0xED, 0x8A, 0x52, 0x23, // PUSH 2352H
                0xE1                    // POP HL
            });

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

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

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

            regs.PC.ShouldBe((ushort)0x0005);
            m.Cpu.Tacts.ShouldBe(30L);
        }
Пример #29
0
        public void JR_NZ_E_WorksWithJump()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x3E, 0x02, // LD A,02H
                0x3D,       // DEC A
                0x20, 0x02  // JR NZ,02H
            });

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

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

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

            regs.PC.ShouldBe((ushort)0x0007);
            m.Cpu.Tacts.ShouldBe(23L);
        }
Пример #30
0
        public void DEC_HL_WorksAsExpected1()
        {
            // --- Arrange
            var m = new Z80TestMachine(RunMode.UntilEnd);

            m.InitCode(new byte[]
            {
                0x21, 0x26, 0xA9, // LD HL,A926H
                0x2B              // DEC HL
            });

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

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

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

            regs.HL.ShouldBe((ushort)0xA925);
            regs.PC.ShouldBe((ushort)0x0004);
            m.Cpu.Tacts.ShouldBe(16L);
        }