コード例 #1
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");
            }
        }
コード例 #2
0
        public static void Check_TwoBytesOpCodesAndDDFDPrefixes()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("INC A");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("INC B");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("INC C");
            testProgram.AppendLine("INC IX");
            testProgram.AppendLine("INC IY");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("DEC IY");

            int[][] startAfterTStatesAndActivateDuringTStates = new int[][] {
                new int[] { 40, 26 }
            };

            TestSystemWithTestSignals testSystem = new TestSystemWithTestSignals(null, null, startAfterTStatesAndActivateDuringTStates, null, null);

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

            logger.StartLogging(
                CPUStateLogger.CPUStateElements.InternalState |
                CPUStateLogger.CPUStateElements.Registers |
                CPUStateLogger.CPUStateElements.ControlPins,
                new Z80CPU.LifecycleEventType[] {
                Z80CPU.LifecycleEventType.MachineCycleEnd
            });
            testSystem.Clock.Tick(74);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_TwoBytesOpCodesAndDDFDPrefixes"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #3
0
        public static void Check_FourBytesOpCodes()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD IX,100");
            testProgram.AppendLine("LD (IX+0),1000000B");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("INC B");
            testProgram.AppendLine("INC IY");
            testProgram.AppendLine("BIT 0,(IX+0)");
            testProgram.AppendLine("LD IY,200");
            testProgram.AppendLine("LD (IY+0),0000001B");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("INC C");
            testProgram.AppendLine("INC IX");
            testProgram.AppendLine("BIT 0,(IY+0)");

            int[][] startAfterTStatesAndActivateDuringTStates = new int[][] {
                new int[] { 51, 18 }
            };

            TestSystemWithTestSignals testSystem = new TestSystemWithTestSignals(null, null, startAfterTStatesAndActivateDuringTStates, null, null);

            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);

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

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_FourBytesOpCodes"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #4
0
        public static void Check_BusRequestAcknowledge()
        {
            StringBuilder testProgram = new StringBuilder();

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

            int[][] startAfterTStatesAndActivateDuringTStates = new int[][] {
                new int[] { 1, 1 },
                new int[] { 12, 4 },
                new int[] { 20, 3 },
                new int[] { 29, 10 }
            };

            TestSystemWithTestSignals testSystem = new TestSystemWithTestSignals(startAfterTStatesAndActivateDuringTStates, null, null, null, null);

            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.Clock.Tick(50);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_BusRequestAcknowledge"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #5
0
        public static void Check_BusRequestAcknowledge()
        {
            StringBuilder testProgram = new StringBuilder();
            testProgram.AppendLine("START: INC A");
            testProgram.AppendLine("JR START");

            int[][] startAfterTStatesAndActivateDuringTStates = new int[][] {
                new int[] { 1, 1 },
                new int[] { 12, 4 },
                new int[] { 20, 3 },
                new int[] { 29, 10 }
            };

            TestSystemWithTestSignals testSystem = new TestSystemWithTestSignals(startAfterTStatesAndActivateDuringTStates, null, null, null, null);
            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.Clock.Tick(50);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_BusRequestAcknowledge"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #6
0
        public static void Check_Output(bool simulateSlowMemoryAndDevices)
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD A,23");
            testProgram.AppendLine("OUT (1),A");
            testProgram.AppendLine("LD A,0");
            testProgram.AppendLine("OUT (2),A");
            testProgram.AppendLine("IN A,(1)");
            testProgram.AppendLine("IN A,(2)");

            TestSystem testSystem = new TestSystemWithTwoDevices(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(6);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_Output" + GetSlowSuffix(simulateSlowMemoryAndDevices)))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #7
0
        public static void Check_Instruction_124_SBC_Register_Register()
        {
            StringBuilder testProgram = new StringBuilder();

            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD A,10");
            // TStatesByMachineCycle = "7 (4,3)"
            testProgram.AppendLine("LD B,5");
            // TStatesByMachineCycle = 1 (4)
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = 1 (4)
            testProgram.AppendLine("SBC A,B");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("LD IXh,2");
            // TStatesByMachineCycle = 1 (4)
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = 8 (4, 4)
            testProgram.AppendLine("SBC A,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(7);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/Arithmetic_8bits/Logs/Check_Instruction_124_SBC_Register_Register"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #8
0
        public static void Check_Instruction_129_SET_Bit_Register()
        {
            StringBuilder testProgram = new StringBuilder();

            testProgram.AppendLine("LD A,0");
            testProgram.AppendLine("SET 3,A");

            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("ALU/BitSetResetAndTest/Logs/Check_Instruction_129_SET_Bit_Register"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #9
0
        public static void Check_FourBytesOpCodes()
        {
            StringBuilder testProgram = new StringBuilder();
            testProgram.AppendLine("LD IX,100");
            testProgram.AppendLine("LD (IX+0),1000000B");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("INC B");
            testProgram.AppendLine("INC IY");
            testProgram.AppendLine("BIT 0,(IX+0)");
            testProgram.AppendLine("LD IY,200");
            testProgram.AppendLine("LD (IY+0),0000001B");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("INC C");
            testProgram.AppendLine("INC IX");
            testProgram.AppendLine("BIT 0,(IY+0)");

            int[][] startAfterTStatesAndActivateDuringTStates = new int[][] {
                new int[] { 51, 18 }
            };

            TestSystemWithTestSignals testSystem = new TestSystemWithTestSignals(null, null, startAfterTStatesAndActivateDuringTStates, null, null);
            testSystem.LoadProgramInMemory(testProgram.ToString());

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

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_FourBytesOpCodes"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #10
0
        public static void Check_TwoBytesOpCodesAndDDFDPrefixes()
        {
            StringBuilder testProgram = new StringBuilder();
            testProgram.AppendLine("INC A");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("INC B");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("INC C");
            testProgram.AppendLine("INC IX");
            testProgram.AppendLine("INC IY");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("DEFB 0DDH");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("DEFB 0FDH");
            testProgram.AppendLine("DEC IY");

            int[][] startAfterTStatesAndActivateDuringTStates = new int[][] {
                new int[] { 40, 26 }
            };

            TestSystemWithTestSignals testSystem = new TestSystemWithTestSignals(null, null, startAfterTStatesAndActivateDuringTStates, null, null);
            testSystem.LoadProgramInMemory(testProgram.ToString());

            CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);
            logger.StartLogging(
               CPUStateLogger.CPUStateElements.InternalState |
               CPUStateLogger.CPUStateElements.Registers |
               CPUStateLogger.CPUStateElements.ControlPins,
               new Z80CPU.LifecycleEventType[] {
                    Z80CPU.LifecycleEventType.MachineCycleEnd
                });
            testSystem.Clock.Tick(74);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_TwoBytesOpCodesAndDDFDPrefixes"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #11
0
        public static void Check_StackMemoryReadAndWrite()
        {
            StringBuilder testProgram = new StringBuilder();
            testProgram.AppendLine("LD A,10");
            testProgram.AppendLine("PUSH AF");
            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 |
               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(3);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("MachineCycles/Logs/Check_StackMemoryReadAndWrite"))
            {
                throw new Exception("Log compare failed");
            }
        }
コード例 #12
0
        public static void Check_Instruction_10_ADD_Register16_Register16()
        {
            string sampleProgramFileName = "ALU/Arithmetic16bits/Samples/testadd16.asm";
            string sampleResultFileName  = "ALU/Arithmetic16bits/Samples/resultadd16.csv";

            Compare16bitsExecutionResultsWithSample(sampleProgramFileName, sampleResultFileName, 3);

            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,3");
            // TStatesByMachineCycle = "10 (4,3,3)"
            testProgram.AppendLine("LD SP,4");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("ADD HL,BC");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("ADD HL,DE");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("ADD HL,HL");
            // TStatesByMachineCycle = "4"
            testProgram.AppendLine("SCF");
            // TStatesByMachineCycle = "11 (4,4,3)"
            testProgram.AppendLine("ADD HL,SP");

            testProgram.AppendLine("LD IX,3");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IX,BC");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IX,DE");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IX,IX");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IX,SP");

            testProgram.AppendLine("LD IY,3");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IY,BC");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IY,DE");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IY,IY");
            testProgram.AppendLine("SCF");
            testProgram.AppendLine("ADD IY,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(30);
            logger.StopLogging();

            if (!logger.CompareWithSavedLog("ALU/Arithmetic16bits/Logs/Check_Instruction_10_ADD_Register16_Register16"))
            {
                throw new Exception("Log compare failed");
            }
        }