public static void Check_Instruction_17_BIT_Bit_IndexedAddress()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD IX,10100000000000B");
            testProgram.AppendLine("LD (IX+1),00000001B");
            testProgram.AppendLine("BIT 0,(IX+1)");
            testProgram.AppendLine("LD (IX+1),10000000B");
            testProgram.AppendLine("BIT 7,(IX+1)");
            testProgram.AppendLine("BIT 4,(IX+1)");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(6);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/BitSetResetAndTest/Logs/Check_Instruction_17_BIT_Bit_IndexedAddress"))
            {
                throw new Exception("Log compare failed");
            }
        }
        /// <summary>
        /// Utility method used to compare execution log with arithmetic operations results (8 bits arithmetic)
        /// </summary>
        private static void CompareExecutionResultsWithSample(string sampleProgramFileName, string sampleResultFileName, int instructionsPerLine, int accColumn)
        {
            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(sampleProgramFileName, Encoding.UTF8, false);

            Stream stream = PlatformSpecific.GetStreamForProjectFile(sampleResultFileName);

            using (StreamReader reader = new StreamReader(stream))
            {
                string line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    testSystem.ExecuteInstructionCount(instructionsPerLine);

                    string[] columns    = line.Split(';');
                    string   AHexValue  = columns[accColumn];
                    byte     AByteValue = Convert.ToByte(AHexValue, 16);
                    string   FBinValue  = columns[accColumn + 1];
                    byte     FByteValue = Convert.ToByte(FBinValue, 2);

                    if (testSystem.CPU.A != AByteValue)
                    {
                        throw new Exception(String.Format("Error line {0}, A = {1}", line, String.Format("{0:X}", testSystem.CPU.A)));
                    }
                    else if ((testSystem.CPU.F) != FByteValue)
                    {
                        throw new Exception(String.Format("Error line {0}, F = {1}", line, Convert.ToString(testSystem.CPU.F, 2)));
                    }
                }
            }
        }
        public static void Check_Instruction_35_DI()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("EI");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("DI");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(2);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/CPUControl/Logs/Check_Instruction_35_DI"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_93_RES_Bit_Register16Address()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD HL,100");
            testProgram.AppendLine("LD (HL),0FFH");
            testProgram.AppendLine("RES 2,(HL)");
            testProgram.AppendLine("LD A,(HL)");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(4);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/BitSetResetAndTest/Logs/Check_Instruction_93_RES_Bit_Register16Address"))
            {
                throw new Exception("Log compare failed");
            }
        }
Example #5
0
        public static void Check_Instruction_39_EX_Register16Address_Register16()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD BC,1000");
            testProgram.AppendLine("LD HL,2000");
            testProgram.AppendLine("LD IX,3000");
            testProgram.AppendLine("LD IY,4000");
            testProgram.AppendLine("PUSH BC");
            testProgram.AppendLine("EX (SP),HL");
            testProgram.AppendLine("EX (SP),IX");
            testProgram.AppendLine("EX (SP),IY");
            testProgram.AppendLine("POP BC");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(9);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/ExchangeBlockTransferAndSearch/Logs/Check_Instruction_39_EX_Register16Address_Register16"))
            {
                throw new Exception("Log compare failed");
            }
        }
Example #6
0
        public static void Check_Instruction_25_CPD()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD HL,100");
            testProgram.AppendLine("LD (HL),1");
            testProgram.AppendLine("LD HL,101");
            testProgram.AppendLine("LD (HL),2");
            testProgram.AppendLine("LD HL,102");
            testProgram.AppendLine("LD (HL),3");
            testProgram.AppendLine("LD BC,3");
            testProgram.AppendLine("LD A,1");
            testProgram.AppendLine("CPD");
            testProgram.AppendLine("CPD");
            testProgram.AppendLine("CPD");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(11);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/ExchangeBlockTransferAndSearch/Logs/Check_Instruction_25_CPD"))
            {
                throw new Exception("Log compare failed");
            }
        }
Example #7
0
        public static void Check_FetchOpcode(bool simulateSlowMemoryAndDevices)
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD A,B");
            testProgram.AppendLine("LD R,A");

            TestSystem testSystem = new TestSystem(simulateSlowMemoryAndDevices);

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState |
                CPUStateLogger.CPUStateElements.Registers |
                CPUStateLogger.CPUStateElements.Buses |
                CPUStateLogger.CPUStateElements.ControlPins,
                new Z80CPU.LifecycleEventType[] {
                Z80CPU.LifecycleEventType.HalfTState,
                Z80CPU.LifecycleEventType.InstructionEnd,
                Z80CPU.LifecycleEventType.InstructionStart,
                Z80CPU.LifecycleEventType.MachineCycleEnd,
                Z80CPU.LifecycleEventType.MachineCycleStart
            });
            testSystem.ExecuteInstructionCount(2);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_FetchOpcode" + GetSlowSuffix(simulateSlowMemoryAndDevices)))
            {
                throw new Exception("Log compare failed");
            }
        }
Example #8
0
        public static void Check_MicroInstructions()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("START: INC A");
            testProgram.AppendLine("JR START");

            TestSystem testSystem = new TestSystem(false);

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState |
                CPUStateLogger.CPUStateElements.Registers |
                CPUStateLogger.CPUStateElements.Buses |
                CPUStateLogger.CPUStateElements.ControlPins |
                CPUStateLogger.CPUStateElements.MicroInstructions,
                new Z80CPU.LifecycleEventType[] {
                Z80CPU.LifecycleEventType.HalfTState,
                Z80CPU.LifecycleEventType.InstructionEnd,
                Z80CPU.LifecycleEventType.InstructionStart,
                Z80CPU.LifecycleEventType.MachineCycleEnd,
                Z80CPU.LifecycleEventType.MachineCycleStart
            });
            testSystem.ExecuteInstructionCount(3);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_MicroInstructions"))
            {
                throw new Exception("Log compare failed");
            }
        }
Example #9
0
        public static void Check_Instruction_96_RET()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD A,0");
            testProgram.AppendLine("CALL FUNC1");
            testProgram.AppendLine("LD A,4");
            testProgram.AppendLine("ORG 100");
            testProgram.AppendLine("FUNC1: LD A,1");
            testProgram.AppendLine("CALL FUNC2");
            testProgram.AppendLine("LD A,3");
            testProgram.AppendLine("RET");
            testProgram.AppendLine("ORG 200");
            testProgram.AppendLine("FUNC2: LD A,2");
            testProgram.AppendLine("RET");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(9);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/CallAndReturn/Logs/Check_Instruction_96_RET"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_71_LD_IndexedAddress_Number8()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "14 (4, 4, 3, 3)"
            testProgram.AppendLine("LD IX,110");
            // TStatesByMachineCycle = "19 (4, 4, 3,5,3)"
            testProgram.AppendLine("LD (IX-10),20");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD A,(100)");
            // TStatesByMachineCycle = "14 (4, 4, 3, 3)"
            testProgram.AppendLine("LD IY,95");
            // TStatesByMachineCycle = "19 (4, 4, 3,5,3)"
            testProgram.AppendLine("LD (IY+5),30");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD A,(100)");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(6);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Load_8Bit/Logs/Check_Instruction_71_LD_IndexedAddress_Number8"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_121_RRD()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD HL,100");
            testProgram.AppendLine("LD (HL),81H");
            testProgram.AppendLine("RRD");
            testProgram.AppendLine("LD B,(HL)");
            testProgram.AppendLine("RRD");
            testProgram.AppendLine("LD B,(HL)");
            testProgram.AppendLine("RRD");
            testProgram.AppendLine("LD B,(HL)");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(8);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/RotateAndShift/Logs/Check_Instruction_121_RRD"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_62_LD_Register_Register16Address()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "10 (4,3,3)"
            testProgram.AppendLine("LD HL,100");
            // TStatesByMachineCycle = "10 (4, 3, 3)"
            testProgram.AppendLine("LD (HL),32");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD E,(HL)");
            // TStatesByMachineCycle = "10 (4,3,3)"
            testProgram.AppendLine("LD BC,100");
            //  TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,(BC)");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(5);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Load_8Bit/Logs/Check_Instruction_62_LD_Register_Register16Address"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_144_SRA_IndexedAddress_Register()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD IY,100");
            testProgram.AppendLine("LD (IY+1),10000001B");
            testProgram.AppendLine("SRA (IY+1),B");
            testProgram.AppendLine("LD A,(IY+1)");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(4);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/RotateAndShift/Logs/Check_Instruction_144_SRA_IndexedAddress_Register"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_150_SUB_Register()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,10");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD B,4");
            // TStatesByMachineCycle = 1 (4)
            testProgram.AppendLine("SUB B");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("LD IXh,3");
            // TStatesByMachineCycle = "8 (4, 4)"
            testProgram.AppendLine("SUB IXh");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(5);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/Arithmetic_8bits/Logs/Check_Instruction_150_SUB_Register"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_156_XOR_IndexedAddress()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,10101010B");
            // TStatesByMachineCycle = "14 (4, 4, 3, 3)"
            testProgram.AppendLine("LD IX,97");
            // TStatesByMachineCycle = "19 (4, 4, 3,5,3)"
            testProgram.AppendLine("LD (IX+3),10001001B");
            // TStatesByMachineCycle = "19 (4, 4, 3, 5, 3)"
            testProgram.AppendLine("XOR (IX+3)");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(4);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/Arithmetic_8bits/Logs/Check_Instruction_156_XOR_IndexedAddress"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_36_DJNZ_RelativeDisplacement()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD A,0");
            testProgram.AppendLine("LD B,3");
            testProgram.AppendLine("INC A");
            testProgram.AppendLine("DJNZ -1");
            testProgram.AppendLine("LD A,0FFH");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(9);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Jump/Logs/Check_Instruction_36_DJNZ_RelativeDisplacement"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_56_JP_FlagCondition_Address()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD A,0");
            testProgram.AppendLine("JP M,100");
            testProgram.AppendLine("ORG 100");
            testProgram.AppendLine("JP P,110");
            testProgram.AppendLine("LD A,1");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(4);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Jump/Logs/Check_Instruction_56_JP_FlagCondition_Address"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_57_JR_RelativeDisplacement()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("NEAR: LD A,0");
            // TStatesByMachineCycle = "12 (4, 3, 5)"
            testProgram.AppendLine("JR FAR");

            testProgram.AppendLine("ORG 100");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("FAR: LD A,1");
            // TStatesByMachineCycle = "12 (4, 3, 5)"
            testProgram.AppendLine("JR NEAR");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(9);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Jump/Logs/Check_Instruction_57_JR_RelativeDisplacement"))
            {
                throw new Exception("Log compare failed");
            }
        }
Example #19
0
        public static void Check_Instruction_128_SCF()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "1 (4)"
            testProgram.AppendLine("CCF");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,0");
            // TStatesByMachineCycle = "1 (4)"
            testProgram.AppendLine("SCF");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(3);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/ArithmeticGeneralPurpose/Logs/Check_Instruction_128_SCF"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_65_LD_Register16_Register16()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "10 (4, 3, 3)"
            testProgram.AppendLine("LD HL,1547");
            // TStatesByMachineCycle = "1 (6)"
            testProgram.AppendLine("LD SP,HL");
            // TStatesByMachineCycle = "14 (4, 4, 3, 3)"
            testProgram.AppendLine("LD IY,3225");
            // TStatesByMachineCycle = "10 (4, 6)"
            testProgram.AppendLine("LD SP,IY");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(4);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Load16Bit/Logs/Check_Instruction_65_LD_Register16_Register16"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_59_LD_Register_Number8()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD H,30");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("LD IXl,55");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(2);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Load_8Bit/Logs/Check_Instruction_59_LD_Register_Number8"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_90_POP_Register16()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,17");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD (4253),A");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,18");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD (4252),A");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,19");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD (4251),A");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,20");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD (4250),A");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,21");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD (4249),A");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,22");
            // TStatesByMachineCycle = "13 (4, 3, 3, 3)"
            testProgram.AppendLine("LD (4248),A");
            // TStatesByMachineCycle = "10 (4, 3, 3)"
            testProgram.AppendLine("LD SP,4248");
            // TStatesByMachineCycle = "10 (4, 3, 3)",
            testProgram.AppendLine("POP AF");
            // TStatesByMachineCycle = "10 (4, 3, 3)",
            testProgram.AppendLine("POP HL");
            // TStatesByMachineCycle = "14 (4, 4, 3, 3)"
            testProgram.AppendLine("POP IX");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(16);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Load16Bit/Logs/Check_Instruction_90_POP_Register16"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_127_SBC_Register16_Register16()
        {
            string sampleProgramFileName = "ALU/Arithmetic16bits/Samples/testsbc16.asm";
            string sampleResultFileName  = "ALU/Arithmetic16bits/Samples/resultsbc16.csv";

            Compare16bitsExecutionResultsWithSample(sampleProgramFileName, sampleResultFileName, 4);

            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "10 (4,3,3)"
            testProgram.AppendLine("LD BC,1");
            // TStatesByMachineCycle = "10 (4,3,3)"
            testProgram.AppendLine("LD DE,2");
            // TStatesByMachineCycle = "10 (4,3,3)"
            testProgram.AppendLine("LD HL,10");
            // TStatesByMachineCycle = "10 (4,3,3)"
            testProgram.AppendLine("LD SP,4");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("SBC HL,BC");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("SBC HL,DE");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("SBC HL,HL");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("SBC HL,SP");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(12);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/Arithmetic16bits/Logs/Check_Instruction_127_SBC_Register16_Register16"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_60_LD_Register_Register()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD C,10");
            // TStatesByMachineCycle = "1 (4)"
            testProgram.AppendLine("LD D,C");
            // TStatesByMachineCycle = "8 (4,4)"
            testProgram.AppendLine("LD IXh,D");
            // TStatesByMachineCycle = "8 (4,4)"
            testProgram.AppendLine("LD E,IXh");
            // TStatesByMachineCycle = "8 (4,4)"
            testProgram.AppendLine("LD IXl,IXh");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("LD IYh,32");
            // TStatesByMachineCycle = "8 (4,4)"
            testProgram.AppendLine("LD IYl,IYh");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,55");
            // TStatesByMachineCycle = "9 (4, 5)"
            testProgram.AppendLine("LD R,A");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,0");
            // TStatesByMachineCycle = "9 (4, 5)"
            testProgram.AppendLine("LD A,R");
            // TStatesByMachineCycle = "9 (4, 5)"
            testProgram.AppendLine("LD A,I");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(12);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Load_8Bit/Logs/Check_Instruction_60_LD_Register_Register"))
            {
                throw new Exception("Log compare failed");
            }
        }
Example #25
0
        public static void Check_Instruction_122_RST_ResetAddress()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD A,0");
            testProgram.AppendLine("RST 08H");
            testProgram.AppendLine("ORG 08H");
            testProgram.AppendLine("LD A,1");
            testProgram.AppendLine("RST 10H");
            testProgram.AppendLine("ORG 10H");
            testProgram.AppendLine("LD A,2");
            testProgram.AppendLine("RST 18H");
            testProgram.AppendLine("ORG 18H");
            testProgram.AppendLine("LD A,3");
            testProgram.AppendLine("RST 20H");
            testProgram.AppendLine("ORG 20H");
            testProgram.AppendLine("LD A,4");
            testProgram.AppendLine("RST 28H");
            testProgram.AppendLine("ORG 28H");
            testProgram.AppendLine("LD A,5");
            testProgram.AppendLine("RST 30H");
            testProgram.AppendLine("ORG 30H");
            testProgram.AppendLine("LD A,6");
            testProgram.AppendLine("RST 38H");
            testProgram.AppendLine("ORG 38H");
            testProgram.AppendLine("LD A,7");
            testProgram.AppendLine("RST 00H");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(17);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/CallAndReturn/Logs/Check_Instruction_122_RST_ResetAddress"))
            {
                throw new Exception("Log compare failed");
            }
        }
        public static void Check_Instruction_91_PUSH_Register16()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,21");
            // TStatesByMachineCycle = "10 (4, 3, 3)"
            testProgram.AppendLine("LD BC,4370");
            // TStatesByMachineCycle = "14 (4, 4, 3, 3)"
            testProgram.AppendLine("LD IY,4884");
            // TStatesByMachineCycle = "11 (5, 3, 3)"
            testProgram.AppendLine("PUSH AF");
            // TStatesByMachineCycle = "11 (5, 3, 3)"
            testProgram.AppendLine("PUSH BC");
            // TStatesByMachineCycle = "15 (4, 5, 3, 3)"
            testProgram.AppendLine("PUSH IY");
            // TStatesByMachineCycle = "10 (4, 3, 3)",
            testProgram.AppendLine("POP DE");
            // TStatesByMachineCycle = "10 (4, 3, 3)",
            testProgram.AppendLine("POP DE");
            // TStatesByMachineCycle = "10 (4, 3, 3)",
            testProgram.AppendLine("POP DE");

            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState | CPUStateLogger.CPUStateElements.Registers,
                new Z80CPU.LifecycleEventType[] { Z80CPU.LifecycleEventType.MachineCycleEnd });
            testSystem.ExecuteInstructionCount(9);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("CPU/Load16Bit/Logs/Check_Instruction_91_PUSH_Register16"))
            {
                throw new Exception("Log compare failed");
            }
        }
        /// <summary>
        /// Utility method used to compare execution log with arithmetic operations results (16 bits arithmetic)
        /// </summary>
        private static void Compare16bitsExecutionResultsWithSample(string sampleProgramFileName, string sampleResultFileName, int instructionsPerLine)
        {
            TestSystem testSystem = new TestSystem();

            testSystem.LoadProgramInMemory(sampleProgramFileName, Encoding.UTF8, false);

            Stream stream = PlatformSpecific.GetStreamForProjectFile(sampleResultFileName);

            using (StreamReader reader = new StreamReader(stream))
            {
                string line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    testSystem.ExecuteInstructionCount(instructionsPerLine);

                    string[] columns    = line.Split(';');
                    string   HHexValue  = columns[3];
                    byte     HByteValue = Convert.ToByte(HHexValue, 16);
                    string   LHexValue  = columns[4];
                    byte     LByteValue = Convert.ToByte(LHexValue, 16);
                    string   FBinValue  = columns[5];
                    byte     FByteValue = Convert.ToByte(FBinValue, 2);

                    if (testSystem.CPU.L != LByteValue)
                    {
                        throw new Exception(String.Format("Error line {0}, L = {1}", line, String.Format("{0:X}", testSystem.CPU.L)));
                    }
                    else if (testSystem.CPU.H != HByteValue)
                    {
                        throw new Exception(String.Format("Error line {0}, H = {1}", line, String.Format("{0:X}", testSystem.CPU.H)));
                    }
                    // Ignore undocumented flags 3 and 5 : 11010111 = 215
                    else if ((testSystem.CPU.F & 215) != (FByteValue & 215))
                    {
                        throw new Exception(String.Format("Error line {0}, F = {1}", line, Convert.ToString(testSystem.CPU.F, 2)));
                    }
                }
            }
        }