END_TEST START_TEST (test_cpu_add16) { cpu_t cpu; cpu.HL = 0; cpu_set_n(&cpu, true); cpu_set_c(&cpu, true); cpu_set_h(&cpu, true); cpu_add16(&cpu, 0x1001); fail_unless(cpu.HL == 0x1001); fail_unless(!cpu_get_n(&cpu)); fail_unless(!cpu_get_c(&cpu)); fail_unless(!cpu_get_h(&cpu)); cpu_add16(&cpu, 0xFF); fail_unless(cpu.HL == 0x1100); fail_unless(!cpu_get_c(&cpu)); fail_unless(cpu_get_h(&cpu)); cpu_add16(&cpu, 0xef00); fail_unless(cpu.HL == 0); fail_unless(cpu_get_c(&cpu)); fail_unless(!cpu_get_h(&cpu)); }
void ADD(cpu_state_t *state, const enum ARG_TYPE arg0, const union REG_INPUT i0, const enum ARG_TYPE arg1, const union REG_INPUT i1) { if(arg0 == ARG_TYPE_REG16) { reg16_t d0 = cpu_load_reg16(state, i0); reg16_t d1; if(arg1 == ARG_TYPE_REG16) { d1 = cpu_load_reg16(state, i1); reg16_t out = cpu_add16(state, d0, d1); cpu_store_reg16(state, i0, out); } else if(arg1 == ARG_TYPE_REL8)//Always SP { uint8_t d8 = (uint8_t)state->arg; cpu_set_zero(state, 0); cpu_set_subtract(state, 0); cpu_set_half_carry(state, (state->sp & 0x0f) + (d8 & 0x0f) > 0x0f); cpu_set_carry(state, (state->sp & 0xff) + (d8 & 0xff) > 0xff); state->sp = state->sp + *(int8_t*)&d8; } } else if(arg0 == ARG_TYPE_REG8) { reg_t d0 = cpu_load_reg8(state, i0); reg_t d1; if(arg1 == ARG_TYPE_DATA8) { d1 = (reg_t)state->arg; } else if(arg1 == ARG_TYPE_REG16_INDIRECT) { d1 = cpu_load8_indirect(state, i1); } else if(arg1 == ARG_TYPE_REG8) { d1 = cpu_load_reg8(state, i1); } else { Error("Invalid argument type.\n"); } reg_t out = cpu_add8(state, d0, d1); cpu_store_reg8(state, i0, out); } }