diff --git a/src/x86_ops_misc.h b/src/x86_ops_misc.h index fb3a1b0..44ac83a 100644 --- a/src/x86_ops_misc.h +++ b/src/x86_ops_misc.h @@ -75,8 +75,8 @@ static int opF6_a16(uint32_t fetchdat) tempws = (int)((int8_t)AL) * (int)((int8_t)dst); AX = tempws & 0xffff; flags_rebuild(); - if (AH && AH != 0xff) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int16_t)AX >> 7) != 0 && ((int16_t)AX >> 7) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 14; break; case 0x30: /*DIV AL,b*/ @@ -163,8 +163,8 @@ static int opF6_a32(uint32_t fetchdat) tempws = (int)((int8_t)AL) * (int)((int8_t)dst); AX = tempws & 0xffff; flags_rebuild(); - if (AH && AH != 0xff) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int16_t)AX >> 7) != 0 && ((int16_t)AX >> 7) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 14; break; case 0x30: /*DIV AL,b*/ @@ -257,8 +257,8 @@ static int opF7_w_a16(uint32_t fetchdat) AX = templ & 0xFFFF; DX = templ >> 16; flags_rebuild(); - if (DX && DX != 0xFFFF) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int32_t)templ >> 15) != 0 && ((int32_t)templ >> 15) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 22; break; case 0x30: /*DIV AX,w*/ @@ -341,8 +341,8 @@ static int opF7_w_a32(uint32_t fetchdat) AX = templ & 0xFFFF; DX = templ >> 16; flags_rebuild(); - if (DX && DX != 0xFFFF) flags |= (C_FLAG | V_FLAG); - else flags &= ~(C_FLAG | V_FLAG); + if (((int32_t)templ >> 15) != 0 && ((int32_t)templ >> 15) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 22; break; case 0x30: /*DIV AX,w*/ @@ -425,8 +425,8 @@ static int opF7_l_a16(uint32_t fetchdat) EAX = temp64 & 0xffffffff; EDX = temp64 >> 32; flags_rebuild(); - if (EDX && EDX != 0xffffffff) flags |= (C_FLAG|V_FLAG); - else flags &= ~(C_FLAG|V_FLAG); + if (((int64_t)temp64 >> 31) != 0 && ((int64_t)temp64 >> 31) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 38; break; case 0x30: /*DIV EAX,l*/ @@ -485,8 +485,8 @@ static int opF7_l_a32(uint32_t fetchdat) EAX = temp64 & 0xffffffff; EDX = temp64 >> 32; flags_rebuild(); - if (EDX && EDX != 0xffffffff) flags |= (C_FLAG|V_FLAG); - else flags &= ~(C_FLAG|V_FLAG); + if (((int64_t)temp64 >> 31) != 0 && ((int64_t)temp64 >> 31) != -1) flags |= (C_FLAG | V_FLAG); + else flags &= ~(C_FLAG | V_FLAG); cycles -= 38; break; case 0x30: /*DIV EAX,l*/ diff --git a/src/x86_ops_mul.h b/src/x86_ops_mul.h index 8e7438b..1326cb8 100644 --- a/src/x86_ops_mul.h +++ b/src/x86_ops_mul.h @@ -1,6 +1,6 @@ static int opIMUL_w_iw_a16(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_16(fetchdat); @@ -10,8 +10,8 @@ static int opIMUL_w_iw_a16(uint32_t fetchdat) templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && (templ >> 16) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -19,7 +19,7 @@ static int opIMUL_w_iw_a16(uint32_t fetchdat) } static int opIMUL_w_iw_a32(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_32(fetchdat); @@ -29,8 +29,8 @@ static int opIMUL_w_iw_a32(uint32_t fetchdat) templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && (templ >> 16) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -49,8 +49,8 @@ static int opIMUL_l_il_a16(uint32_t fetchdat) temp64 = ((int64_t)templ) * ((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles-=25; @@ -68,8 +68,8 @@ static int opIMUL_l_il_a32(uint32_t fetchdat) temp64 = ((int64_t)templ) * ((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles-=25; @@ -78,7 +78,7 @@ static int opIMUL_l_il_a32(uint32_t fetchdat) static int opIMUL_w_ib_a16(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_16(fetchdat); @@ -89,8 +89,8 @@ static int opIMUL_w_ib_a16(uint32_t fetchdat) templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && ((templ >> 16) & 0xffff) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -98,7 +98,7 @@ static int opIMUL_w_ib_a16(uint32_t fetchdat) } static int opIMUL_w_ib_a32(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; int16_t tempw, tempw2; fetch_ea_32(fetchdat); @@ -109,8 +109,8 @@ static int opIMUL_w_ib_a32(uint32_t fetchdat) templ = ((int)tempw) * ((int)tempw2); flags_rebuild(); - if ((templ >> 16) != 0 && ((templ >> 16) & 0xffff) != 0xffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].w = templ & 0xffff; cycles -= (mod == 3) ? 14 : 17; @@ -119,7 +119,7 @@ static int opIMUL_w_ib_a32(uint32_t fetchdat) static int opIMUL_l_ib_a16(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; int32_t templ, templ2; fetch_ea_16(fetchdat); @@ -129,8 +129,8 @@ static int opIMUL_l_ib_a16(uint32_t fetchdat) temp64 = ((int64_t)templ)*((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles -= 20; @@ -138,7 +138,7 @@ static int opIMUL_l_ib_a16(uint32_t fetchdat) } static int opIMUL_l_ib_a32(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; int32_t templ, templ2; fetch_ea_32(fetchdat); @@ -148,8 +148,8 @@ static int opIMUL_l_ib_a32(uint32_t fetchdat) temp64 = ((int64_t)templ)*((int64_t)templ2); flags_rebuild(); - if ((temp64 >> 32) != 0 && (temp64 >> 32) != 0xffffffff) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); regs[reg].l = temp64 & 0xffffffff; cycles -= 20; @@ -160,30 +160,30 @@ static int opIMUL_l_ib_a32(uint32_t fetchdat) static int opIMUL_w_w_a16(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; fetch_ea_16(fetchdat); templ = (int32_t)(int16_t)regs[reg].w * (int32_t)(int16_t)geteaw(); if (abrt) return 0; regs[reg].w = templ & 0xFFFF; flags_rebuild(); - if ((templ >> 16) && (templ >> 16) != 0xFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 18; return 0; } static int opIMUL_w_w_a32(uint32_t fetchdat) { - uint32_t templ; + int32_t templ; fetch_ea_32(fetchdat); templ = (int32_t)(int16_t)regs[reg].w * (int32_t)(int16_t)geteaw(); if (abrt) return 0; regs[reg].w = templ & 0xFFFF; flags_rebuild(); - if ((templ >> 16) && (templ >> 16) != 0xFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((templ >> 15) != 0 && (templ >> 15) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 18; return 0; @@ -191,30 +191,30 @@ static int opIMUL_w_w_a32(uint32_t fetchdat) static int opIMUL_l_l_a16(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; fetch_ea_16(fetchdat); temp64 = (int64_t)(int32_t)regs[reg].l * (int64_t)(int32_t)geteal(); if (abrt) return 0; regs[reg].l = temp64 & 0xFFFFFFFF; flags_rebuild(); - if ((temp64 >> 32) && (temp64 >> 32) != 0xFFFFFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 30; return 0; } static int opIMUL_l_l_a32(uint32_t fetchdat) { - uint64_t temp64; + int64_t temp64; fetch_ea_32(fetchdat); temp64 = (int64_t)(int32_t)regs[reg].l * (int64_t)(int32_t)geteal(); if (abrt) return 0; regs[reg].l = temp64 & 0xFFFFFFFF; flags_rebuild(); - if ((temp64 >> 32) && (temp64 >> 32) != 0xFFFFFFFF) flags |= C_FLAG | V_FLAG; - else flags &= ~(C_FLAG | V_FLAG); + if ((temp64 >> 31) != 0 && (temp64 >> 31) != -1) flags |= C_FLAG | V_FLAG; + else flags &= ~(C_FLAG | V_FLAG); cycles -= 30; return 0;