コード例 #1
0
        public static void Check_Memptr(int launchAddress, string testDescription)
        {
            TestSystem testSystem = new TestSystem();

            string testSourcePath = "FlagsAndMemptr/z80tests-Memptr.asm";
            using (Stream stream = PlatformSpecific.GetStreamForProjectFile(testSourcePath))
            {
                testSystem.LoadProgramInMemory(testSourcePath, stream, Encoding.UTF8, false);
            }
            testSystem.CPU.InitProgramCounter((ushort)launchAddress);
            testSystem.AddBreakpointOnProgramLine(1974);

            /*StringBuilder sb = new StringBuilder();
            int counter = 1;
            foreach (string variable in testSystem.ProgramInMemory.Variables.Keys)
            {
                if (variable.Contains("LAUNCH"))
                {
                    sb.AppendLine("public static int " + variable.Replace("LAUNCH", "ADDR") + " = 0x" + testSystem.ProgramInMemory.Variables[variable].GetValue(testSystem.ProgramInMemory.Variables, null).ToString("X4") +";");
                    sb.AppendLine("public static string " + variable.Replace("LAUNCH", "DESC") + " = \"" + testSystem.ProgramInMemory.Lines.First(line => (line.Comment !=null && line.Comment.Contains("test "+counter.ToString("D2")+" : "))).Comment.Split(':')[1].Trim() + "\";");
                    counter++;
                }
            }
            sb.Clear();
            for (counter = 1; counter <= 58; counter++)
            {
                sb.AppendLine("FlagsAndMemptrTests.Check_Memptr(FlagsAndMemptrTests.MEMPTR_TEST_" + counter.ToString("D2") + "_ADDR, FlagsAndMemptrTests.MEMPTR_TEST_" + counter.ToString("D2") + "_DESC);");
            }*/

            /*CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);
            logger.StartLogging(
               CPUStateLogger.CPUStateElements.InternalState |
               CPUStateLogger.CPUStateElements.Registers,
               new Z80CPU.LifecycleEventType[] {
                    Z80CPU.LifecycleEventType.InstructionEnd
                });*/
            testSystem.ExecuteUntilNextBreakpoint();
            //logger.StopLogging();

            if (testSystem.CPU.A != 0)
            {
                throw new Exception("Memptr test for " + testDescription + " failed");
            }
        }
コード例 #2
0
        public static void Check_InstructionSet(int launchAddress, string testDescription)
        {
            TestSystem testSystem = new TestSystem();

            string testSourcePath = "Zexall/zexall2-Tests.asm";
            using (Stream stream = PlatformSpecific.GetStreamForProjectFile(testSourcePath))
            {
                testSystem.LoadProgramInMemory(testSourcePath, stream, Encoding.UTF8, false);
            }

            /*string[] testNames = new string[] { "SCFOP","CCFOP","SCFCCF","CCFSCF","BITA","BITHL","BITX","BITZ80","DAAOP","CPLOP","ADC16","ADD16","ADD16X",
            "ADD16Y","ALU8I","ALU8R","ALU8RX","ALU8X","CPD1","CPI1","INCA","INCB","INCBC","INCC","INCD","INCDE","INCE","INCH","INCHL","INCIX","INCIY",
            "INCL","INCM","INCSP","INCX","INCXH","INCXL","INCYH","INCYL","LD161","LD162","LD163","LD164","LD165","LD166","LD167","LD168","LD16IM","LD16IX",
            "LD8BD","LD8IM","LD8IMX","LD8IX1","LD8IX2","LD8IX3","LD8IXY","LD8RR","LD8RRX","LDA","LDD1","LDD2","LDI1","LDI2","NEGOP","RLDOP","ROT8080",
            "ROTXY","ROTZ80","SRZ80","SRZX","ST8IX1","ST8IX2","ST8IX3","STABD" };
            string[] testDescriptions = new string[] {"scf","ccf","scf+ccf","ccf+scf","bit n,a","bit n,(hl)","bit n,(<ix,iy>+1)","bit n,<b,c,d,e,h,l,(hl),a>",
            "daa","cpl","<adc,sbc> hl,<bc,de,hl,sp>","add hl,<bc,de,hl,sp>","add ix,<bc,de,ix,sp>","add iy,<bc,de,iy,sp>","aluop a,nn","aluop a,<b,c,d,e,h,l,(hl),a>",
            "aluop a,<ixh,ixl,iyh,iyl>","aluop a,(<ix,iy>+1)","cpd<r>","cpi<r>","<inc,dec> a","<inc,dec> b","<inc,dec> bc","<inc,dec> c","<inc,dec> d","<inc,dec> de",
            "<inc,dec> e","<inc,dec> h","<inc,dec> hl","<inc,dec> ix","<inc,dec> iy","<inc,dec> l","<inc,dec> (hl)","<inc,dec> sp","<inc,dec> (<ix,iy>+1)","<inc,dec> ixh",
            "<inc,dec> ixl","<inc,dec> iyh","<inc,dec> iyl","ld <bc,de>,(nnnn)","ld hl,(nnnn)","ld sp,(nnnn)","ld <ix,iy>,(nnnn)","ld (nnnn),<bc,de>","ld (nnnn),hl",
            "ld (nnnn),sp","ld (nnnn),<ix,iy>","ld <bc,de,hl,sp>,nnnn","ld <ix,iy>,nnnn","ld a,<(bc),(de)>","ld <b,c,d,e,h,l,(hl),a>,nn","ld (<ix,iy>+1),nn",
            "ld <b,c,d,e>,(<ix,iy>+1)","ld <h,l>,(<ix,iy>+1)","ld a,(<ix,iy>+1)","ld <ixh,ixl,iyh,iyl>,nn","ld <bcdehla>,<bcdehla>","ld <bcdexya>,<bcdexya>",
            "ld a,(nnnn) / ld (nnnn),a","ldd<r> (1)","ldd<r> (2)","ldi<r> (1)","ldi<r> (2)","neg","<rrd,rld>","<rlca,rrca,rla,rra>","shf/rot (<ix,iy>+1)",
            "shf/rot <b,c,d,e,h,l,(hl),a>","<set,res> n,<bcdehl(hl)a>","<set,res> n,(<ix,iy>+1)","ld (<ix,iy>+1),<b,c,d,e>","ld (<ix,iy>+1),<h,l>","ld (<ix,iy>+1),a",
            "ld (<bc,de>),a" };

            StringBuilder sb = new StringBuilder();
            int testIndex = 0;
            foreach (string testName in testNames)
            {
                sb.AppendLine("public static int ZEXALL2_TEST_"+testName+"_ADDR = 0x" + testSystem.ProgramInMemory.Variables[testName].GetValue(testSystem.ProgramInMemory.Variables, null).ToString("X4") +";");
                sb.AppendLine("public static string ZEXALL2_TEST_"+testName+"_DESC = \"" + testDescriptions[testIndex++] + "\";");
                //sb.AppendLine("ZexallTests.Check_InstructionSet(ZexallTests.ZEXALL2_TEST_" + testName + "_ADDR, ZexallTests.ZEXALL2_TEST_" + testName + "_DESC);");
            }*/

            // Sample results :
            // scf............................
            // CRC: 9e4dbc94 expected: ff4ceb48
            // ccf............................
            // CRC: 363b6874 expected: 573a3fa8
            // scf+ccf........................OK
            // ccf+scf........................OK

            // Input parameter :
            // HL = test address
            testSystem.CPU.InitRegister16(Register16.HL, (ushort)launchAddress);

            // Test execution routine : STT - address 1B86
            // Exit point : address 1BFB
            testSystem.CPU.InitProgramCounter(0x1B86);
            testSystem.AddBreakpointOnProgramLine(7190);

            /*CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);
            logger.StartLogging(
               CPUStateLogger.CPUStateElements.InternalState |
               CPUStateLogger.CPUStateElements.Registers,
               new Z80CPU.LifecycleEventType[] {
                    Z80CPU.LifecycleEventType.InstructionEnd
                });*/
            testSystem.ExecuteUntilNextBreakpoint();
            //logger.StopLogging();

            // Output parameters :
            // A = 0 success
            // A = 1 error
            // =>  HL points to expected CRC, CRCVAL is the address of observed CRC
            if (testSystem.CPU.A != 0)
            {
                int expCRCAddress = testSystem.CPU.HL; // Pointer in CRCTAB
                int obsCRCAddress = 0x1E5E; // CRCVAL

                int expCRC = 0x1000000 * testSystem.Memory.Cells[expCRCAddress] + 0x10000 * testSystem.Memory.Cells[expCRCAddress + 1] + 0x100 * testSystem.Memory.Cells[expCRCAddress + 2] + testSystem.Memory.Cells[expCRCAddress + 3];
                int obsCRC = 0x1000000 * testSystem.Memory.Cells[obsCRCAddress] + 0x10000 * testSystem.Memory.Cells[obsCRCAddress + 1] + 0x100 * testSystem.Memory.Cells[obsCRCAddress + 2] + testSystem.Memory.Cells[obsCRCAddress + 3];

                throw new Exception("Zexall instruction test for " + testDescription + " failed : observed CRC = " + obsCRC.ToString("X8") + ", expected CRC = " + expCRC.ToString("X8"));
            }
        }
コード例 #3
0
        public static void Check_Flags(int launchAddress, string testDescription)
        {
            Console.Write(testDescription + "...");

            TestSystem testSystem = new TestSystem();

            string testSourcePath = "FlagsAndMemptr/z80tests-Flags.asm";
            using (Stream stream = PlatformSpecific.GetStreamForProjectFile(testSourcePath))
            {
                testSystem.LoadProgramInMemory(testSourcePath, stream, Encoding.UTF8, false);
                ((TestSystem._TestMemory)testSystem.Memory).SetReadOnlySection(0x500,0x5FF);
            }
            testSystem.CPU.InitProgramCounter((ushort)launchAddress);
            testSystem.CPU.InitRegister(Z80Simulator.Instructions.Register.I, 63);
            testSystem.AddBreakpointOnProgramLine(619);

            /*StringBuilder sb = new StringBuilder();
            int counter = 1;
            foreach (string variable in testSystem.ProgramInMemory.Variables.Keys)
            {
                if (variable.Contains("LAUNCH"))
                {
                    sb.AppendLine("public static int " + variable.Replace("LAUNCH", "ADDR") + " = 0x" + testSystem.ProgramInMemory.Variables[variable].GetValue(testSystem.ProgramInMemory.Variables, null).ToString("X4") +";");
                    sb.AppendLine("public static string " + variable.Replace("LAUNCH", "DESC") + " = \"" + testSystem.ProgramInMemory.Lines.First(line => (line.Comment !=null && line.Comment.Contains("test "+counter.ToString("D2")+" : "))).Comment.Split(':')[1].Trim() + "\";");
                    counter++;
                }
            }
            sb.Clear();
            for (counter = 1; counter <= 45; counter++)
            {
                sb.AppendLine("FlagsAndMemptrTests.Check_Flags(FlagsAndMemptrTests.FLAGS_TEST_" + counter.ToString("D2") + "_ADDR, FlagsAndMemptrTests.FLAGS_TEST_" + counter.ToString("D2") + "_DESC);");
            }*/

            /*CPUStateLogger logger = new CPUStateLogger(testSystem.CPU);
            logger.StartLogging(
               CPUStateLogger.CPUStateElements.InternalState |
               CPUStateLogger.CPUStateElements.Registers,
               new Z80CPU.LifecycleEventType[] {
                    Z80CPU.LifecycleEventType.InstructionEnd
                });*/
            testSystem.ExecuteUntilNextBreakpoint();
            //logger.StopLogging();

            if (!(testSystem.CPU.A == 0 ||
                 (launchAddress == FLAGS_TEST_27_ADDR && testSystem.CPU.HL == 0x3063)))
            {
                throw new Exception("Flags test for " + testDescription + " failed : expected checksum " + testSystem.CPU.BC.ToString("X4") + " / computed checksum " + testSystem.CPU.HL.ToString("X4"));
            }

            Console.WriteLine("OK");
        }