END_TEST START_TEST (test_cpu_or) { cpu_t cpu; cpu.A = 0x50; cpu_set_z(&cpu, true); cpu_set_n(&cpu, true); cpu_set_c(&cpu, true); cpu_set_h(&cpu, true); cpu_or(&cpu, 0x05); fail_unless(cpu.A == 0x55); 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.A = 0; cpu_or(&cpu, 0x00); fail_unless(cpu.A == 0); fail_unless(cpu_get_z(&cpu)); }
void OR(cpu_state_t *state, const enum ARG_TYPE arg0, const union REG_INPUT i0, const enum ARG_TYPE arg1, const union REG_INPUT i1) { reg_t d0, d1; if(arg0 == ARG_TYPE_DATA8) { d1 = (reg_t)state->arg; } else if(arg0 == ARG_TYPE_REG16_INDIRECT) { d1 = cpu_load8_indirect(state, i0); } else if(arg0 == ARG_TYPE_REG8) { d1 = cpu_load_reg8(state, i0); } else { Error("Invalid argument type.\n"); } d0 = cpu_load_reg8(state, A_REG); d0 = cpu_or(state, d0, d1); cpu_store_reg8(state, A_REG, d0); }
void or_test(void) { cpu_state_t state; int *test; int tests[][7] = { {0x00, 0x00, 0x00, 1, 0, 0, 0}, {0x5a, 0x5a, 0x5a, 0, 0, 0, 0}, {0x5a, 0x03, 0x5b, 0, 0, 0, 0}, {0x5a, 0x0f, 0x5f, 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); uint8_t res = cpu_or(&state, test[0], test[1]); if(res == 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)); } } }