Exemplo n.º 1
0
 protected void AssertFlagsSame(CPUConfig initialState, CPUResults stats)
 {
     Assert.Equal(initialState.Flags.AuxCarry, stats.Flags.AuxCarry);
     Assert.Equal(initialState.Flags.Carry, stats.Flags.Carry);
     Assert.Equal(initialState.Flags.Parity, stats.Flags.Parity);
     Assert.Equal(initialState.Flags.Sign, stats.Flags.Sign);
     Assert.Equal(initialState.Flags.Zero, stats.Flags.Zero);
 }
Exemplo n.º 2
0
 protected void AssertFlagsFalse(CPUResults stats)
 {
     Assert.False(stats.Flags.AuxCarry);
     Assert.False(stats.Flags.Carry);
     Assert.False(stats.Flags.Parity);
     Assert.False(stats.Flags.Sign);
     Assert.False(stats.Flags.Zero);
 }
Exemplo n.º 3
0
        protected CPUResults Execute(byte[] memory, CPU cpu)
        {
            cpu.LoadMemory(memory);

            // Record the number of iterations (instructions), CPU cycles, and the address of the
            // program counter after each instruction is executed. This allows tests to assert each
            // of these values in addition to the CPU state.
            var iterations  = 0;
            var cycles      = 0;
            var pcAddresses = new List <UInt16>();

            while (!cpu.Finished)
            {
                // Ensure we don't have a run away program.
                if (iterations > 100)
                {
                    throw new Exception("More than 100 iterations occurred.");
                }

                pcAddresses.Add(cpu.ProgramCounter);

                cycles += cpu.Step();

                iterations++;
            }

            // Return the state of the CPU so tests can do verification.

            var results = new CPUResults()
            {
                Iterations = iterations,
                Cycles     = cycles,
                ProgramCounterAddresses = pcAddresses,
                Memory            = cpu.Memory,
                Registers         = cpu.Registers,
                Flags             = cpu.Flags,
                ProgramCounter    = cpu.ProgramCounter,
                StackPointer      = cpu.StackPointer,
                InterruptsEnabled = cpu.InterruptsEnabled,
            };

            return(results);
        }