Example #1
0
File: tests.c Project: lmb/Spielbub
END_TEST

START_TEST (test_cpu_xor)
{
    cpu_t cpu;
    cpu.A = 0x55;

    cpu_set_z(&cpu, true);
    cpu_set_n(&cpu, true);
    cpu_set_c(&cpu, true);
    cpu_set_h(&cpu, true);

    cpu_xor(&cpu, 0xAA);

    fail_unless(cpu.A == 0xFF);
    fail_unless(!cpu_get_z(&cpu));
    fail_unless(!cpu_get_n(&cpu));
    fail_unless(!cpu_get_c(&cpu));
    fail_unless(!cpu_get_h(&cpu));

    cpu_xor(&cpu, 0xFF);

    fail_unless(cpu.A == 0);
    fail_unless(cpu_get_z(&cpu));
}
Example #2
0
void xor_test(void)
{
	cpu_state_t state;
	int *test;
	int tests[][7] =
	{
		{0xff, 0xff, 0x00, 1, 0, 0, 0},
		{0xff, 0x0f, 0xf0, 0, 0, 0, 0},
		{0xff, 0x8a, 0x75, 0, 0, 0, 0},
	};
	for(uint32_t i = 0; i < sizeof(tests) / sizeof(*tests); i++)
	{
		test = tests[i];
		cpu_set_half_carry(&state, rand() % 2);
		cpu_set_subtract(&state, rand() % 2);
		cpu_set_carry(&state, rand() % 2);
		state.a = test[0];
		cpu_xor(&state, test[1]);
		if(state.a          == test[2] &&
		   cpu_zero(&state)       == test[3] &&
		   cpu_half_carry(&state) == test[4] &&
		   cpu_subtract(&state)   == test[5] &&
		   cpu_carry(&state)      == test[6])
		{
			printf("Tests passed.\n");
		}
		else
		{
			printf("Tests failed.\n");
			printf("%d %d %d %d\n",  (int) cpu_zero(&state),
									 (int) cpu_half_carry(&state),
									 (int) cpu_subtract(&state),
									 (int) cpu_carry(&state));
		}
	}
}