Exemplo n.º 1
0
        private void DisassembleDDCBandFDCBOpcodesCorrectly()
        {
            var fakeBus = A.Fake <IBus>();
            var ram     = HexFileReader.Read("../../../HexFiles/TestDDCBandFDCB.hex");

            var expectedDisassembly = new Dictionary <ushort, string>
            {
                { 0x8000, "RL (IX+2)" },
                { 0x8004, "RL (IY-3)" },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);


            var cpu = new Z80()
            {
                A = 0x00, PC = 0x8000
            };

            cpu.ConnectToBus(fakeBus);
            var disassembledCode = cpu.Disassemble(0x8000, 0x8007);

            Assert.Equal(expectedDisassembly, disassembledCode);
        }
Exemplo n.º 2
0
        private void DisassembleMultiplicationHexFileCorrectly()
        {
            var fakeBus = A.Fake <IBus>();
            var ram     = HexFileReader.Read("../../../HexFiles/Multiplication.hex");

            var expectedDisassembly = new Dictionary <ushort, string>
            {
                { 0x8000, "LD BC,&0015" },
                { 0x8003, "LD B,&08" },
                { 0x8005, "LD DE,&002A" },
                { 0x8008, "LD D,&00" },
                { 0x800A, "LD HL,&0000" },
                { 0x800D, "SRL C" },
                { 0x800F, "JR C,$+3" },
                { 0x8011, "ADD HL,DE" },
                { 0x8012, "SLA E" },
                { 0x8014, "RL D" },
                { 0x8016, "DEC B" },
                { 0x8017, "JP NZ,&800D" },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);


            var cpu = new Z80()
            {
                A = 0x00, PC = 0x8000
            };

            cpu.ConnectToBus(fakeBus);
            var disassembledCode = cpu.Disassemble(0x8000, 0x8017);

            Assert.Equal(expectedDisassembly, disassembledCode);
        }
Exemplo n.º 3
0
        private void DisassembleArithmetic1HexFileCorrectly()
        {
            var fakeBus = A.Fake <IBus>();

            var expectedDisassembly = new Dictionary <ushort, string>
            {
                { 0x0080, "LD A,&05" },
                { 0x0082, "LD B,&0A" },
                { 0x0084, "ADD A,B" },
                { 0x0085, "ADD A,A" },
                { 0x0086, "LD C,&0F" },
                { 0x0088, "SUB A,C" },
                { 0x0089, "LD H,&08" },
                { 0x008B, "LD L,&FF" },
                { 0x008D, "LD (HL),A" },
                { 0x008E, "NOP" },
            };

            var ram = HexFileReader.Read("../../../HexFiles/Arithmetic1.hex");

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);

            var cpu = new Z80()
            {
                A = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);
            var disassembledCode = cpu.Disassemble(0x0080, 0x008E);

            Assert.Equal(expectedDisassembly, disassembledCode);
        }
Exemplo n.º 4
0
        private void ExecuteArithmeticTestRoutine1Successfully()
        {
            var fakeBus = A.Fake <IBus>();

            //` Arithmetic Test Routine #1 - 10 instructions
            //` Filename: Arithmetic1.hex
            //`
            //` 0080                          .ORG   0080h
            //`
            //` 0080   3E 05                  LD A,05h
            //` 0082   06 0A                  LD B,0Ah
            //` 0084   80                     ADD A,B
            //` 0085   87                     ADD A,A
            //` 0086   0E 0F                  LD C,0Fh
            //` 0088   91                     SUB C
            //` 0089   26 08                  LD H,08h
            //` 008B   2E FF                  LD L,0FFh
            //` 008D   77                     LD (HL),A
            //` 008E   00                     NOP

            var ram = HexFileReader.Read("../../../HexFiles/Arithmetic1.hex");

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);
            A.CallTo(() => fakeBus.Write(A <ushort> ._, A <byte> ._))
            .Invokes((ushort addr, byte data) => UpdateMemory(addr, data));

            var cpu = new Z80()
            {
                A = 0x00, B = 0x00, C = 0x00, H = 0x00, L = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            // Run 10 instructions
            for (int i = 0; i < 10; i++)
            {
                cpu.Step();
                Debug.WriteLine($"A = {cpu.A} B = {cpu.B} C = {cpu.C} H = {cpu.H} L = {cpu.L}");
            }

            Assert.Equal(0x0F, ram[0x08FF]);

            void UpdateMemory(ushort addr, byte data)
            {
                ram[addr] = data;
            }
        }
Exemplo n.º 5
0
        private void ReadSimpleHexFileWithOnlySingleDataRecord()
        {
            var fakeBus = A.Fake <IBus>();

            // Routine #1 - 58 T-Cycles
            // .ORG   0080h
            //
            // LD A,05h
            // LD   B,0Ah
            // ADD A, B
            // ADD A, A
            // LD C,0Fh
            // SUB C
            // LD H,08h
            // LD   L,0FFh
            // LD(HL),A
            // NOP

            var ram = HexFileReader.Read("../../../HexFiles/Arithmetic1.hex");

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);
            A.CallTo(() => fakeBus.Write(A <ushort> ._, A <byte> ._))
            .Invokes((ushort addr, byte data) => UpdateMemory(addr, data));

            var cpu = new Z80()
            {
                A = 0x00, B = 0x00, C = 0x00, H = 0x00, L = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            for (int i = 0; i < 10; i++)
            {
                cpu.Step();
            }

            Assert.Equal(0x0F, ram[0x08FF]);

            void UpdateMemory(ushort addr, byte data)
            {
                ram[addr] = data;
            }
        }
Exemplo n.º 6
0
        private void ExecuteEightBitMultiplicationRoutineSuccessfully()
        {
            var fakeBus = A.Fake <IBus>();

            //` Arithmetic Test Routine #2
            //` Filename: Multiplication.hex
            //`
            //` 8000                          .ORG   8000h
            //`
            //`8000   01 15 00               LD BC,21
            //`8003   06 08                  LD B,8
            //`8005   11 2A 00               LD DE,42
            //`8008   16 00                  LD D,0
            //`800A   21 00 00               LD HL,0
            //`800D   CB 39         MULTI:   SRL C; LSB in Carry Flag
            //`800F   30 01                  JR NC, NOADD
            //`8011   19                     ADD HL, DE
            //`8012   CB 23        NOADD:    SLA E
            //`8014   CB 12                  RL D
            //`8016   05                     DEC B
            //`8017   C2 0D 80               JP NZ, MULTI

            var ram = HexFileReader.Read("../../../HexFiles/Multiplication.hex");

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);

            var cpu = new Z80()
            {
                A = 0x00, B = 0x00, C = 0x00, H = 0x00, L = 0x00, PC = 0x8000
            };

            cpu.ConnectToBus(fakeBus);

            while (cpu.PC < 0x8020)
            {
                cpu.Step();
            }

            Assert.Equal(0x0372, cpu.HL);
        }