From: Jorge Gorbe Date: Mon, 27 May 2013 18:24:36 +0000 (+0200) Subject: Fixed opcodes E8 and F8 X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;p=wenboi.git Fixed opcodes E8 and F8 There was a problem with the carry flags due to lack of documentation. Once I found http://stackoverflow.com/questions/5159603/gbz80-how-does-ld-hl-spe-affect-h-and-c-flags it was easy :S --- diff --git a/core/GameBoy.cc b/core/GameBoy.cc index 85b6df8..6dd7b88 100644 --- a/core/GameBoy.cc +++ b/core/GameBoy.cc @@ -613,11 +613,13 @@ GameBoy::run_status GameBoy::run_cycle() case 0xF8: { s8 offset = memory.read(regs.PC++); int res = regs.SP + offset; + int res8 = (regs.SP & 0xFF) + (offset & 0xFF); + int half_res = (regs.SP & 0xF) + (offset & 0xF); + // Do the same as 0xE8 for the carry flags - // TODO: Verificar si los flags van asi - set_flag_if (res > 0xFFFF, CARRY_FLAG); + set_flag_if (res8 > 0xFF, CARRY_FLAG); + set_flag_if (half_res > 0xF, HALF_CARRY_FLAG); - // TODO: hacer lo apropiado con el half-carry flag reset_flag(ADD_SUB_FLAG); reset_flag(ZERO_FLAG); @@ -864,13 +866,18 @@ GameBoy::run_status GameBoy::run_cycle() // ADD SP, # case 0xE8: { - // FIXME: No se que hacer con el half carry, en 4 o en 11? + // Carry flag: set when carry from bit 7 to 8 + // Half-carry flag: set when carry from bit 3 to 4 + // http://stackoverflow.com/questions/5159603/gbz80-how-does-ld-hl-spe-affect-h-and-c-flags int n = static_cast(memory.read(regs.PC++)); int res = regs.SP + n; + int res8 = (regs.SP & 0xFF) + (n & 0xFF); + int half_res = (regs.SP & 0xF) + (n & 0xF); regs.SP = static_cast(res); reset_flag(ZERO_FLAG); reset_flag(ADD_SUB_FLAG); - set_flag_if(res > 0xFFFF, CARRY_FLAG); + set_flag_if(res8 > 0xFF, CARRY_FLAG); + set_flag_if(half_res > 0xF, HALF_CARRY_FLAG); cycles_until_next_instruction = 16; break; }