Fixed lazy V flag on SHL/SHR/SAR - IBM AT & Acer 386 BIOSes work again.

This commit is contained in:
TomW 2013-11-15 19:55:22 +00:00
commit 6c7b746bf9
2 changed files with 351 additions and 276 deletions

View file

@ -12,7 +12,19 @@ enum
FLAGS_SUB8, FLAGS_SUB8,
FLAGS_SUB16, FLAGS_SUB16,
FLAGS_SUB32 FLAGS_SUB32,
FLAGS_SHL8,
FLAGS_SHL16,
FLAGS_SHL32,
FLAGS_SHR8,
FLAGS_SHR16,
FLAGS_SHR32,
FLAGS_SAR8,
FLAGS_SAR16,
FLAGS_SAR32,
}; };
static int flags_op; static int flags_op;
@ -32,6 +44,15 @@ static inline int ZF_SET()
case FLAGS_SUB8: case FLAGS_SUB8:
case FLAGS_SUB16: case FLAGS_SUB16:
case FLAGS_SUB32: case FLAGS_SUB32:
case FLAGS_SHL8:
case FLAGS_SHL16:
case FLAGS_SHL32:
case FLAGS_SHR8:
case FLAGS_SHR16:
case FLAGS_SHR32:
case FLAGS_SAR8:
case FLAGS_SAR16:
case FLAGS_SAR32:
return !flags_res; return !flags_res;
case FLAGS_UNKNOWN: case FLAGS_UNKNOWN:
@ -46,16 +67,25 @@ static inline int NF_SET()
case FLAGS_ZN8: case FLAGS_ZN8:
case FLAGS_ADD8: case FLAGS_ADD8:
case FLAGS_SUB8: case FLAGS_SUB8:
case FLAGS_SHL8:
case FLAGS_SHR8:
case FLAGS_SAR8:
return flags_res & 0x80; return flags_res & 0x80;
case FLAGS_ZN16: case FLAGS_ZN16:
case FLAGS_ADD16: case FLAGS_ADD16:
case FLAGS_SUB16: case FLAGS_SUB16:
case FLAGS_SHL16:
case FLAGS_SHR16:
case FLAGS_SAR16:
return flags_res & 0x8000; return flags_res & 0x8000;
case FLAGS_ZN32: case FLAGS_ZN32:
case FLAGS_ADD32: case FLAGS_ADD32:
case FLAGS_SUB32: case FLAGS_SUB32:
case FLAGS_SHL32:
case FLAGS_SHR32:
case FLAGS_SAR32:
return flags_res & 0x80000000; return flags_res & 0x80000000;
case FLAGS_UNKNOWN: case FLAGS_UNKNOWN:
@ -76,6 +106,15 @@ static inline int PF_SET()
case FLAGS_SUB8: case FLAGS_SUB8:
case FLAGS_SUB16: case FLAGS_SUB16:
case FLAGS_SUB32: case FLAGS_SUB32:
case FLAGS_SHL8:
case FLAGS_SHL16:
case FLAGS_SHL32:
case FLAGS_SHR8:
case FLAGS_SHR16:
case FLAGS_SHR32:
case FLAGS_SAR8:
case FLAGS_SAR16:
case FLAGS_SAR32:
return znptable8[flags_res & 0xff] & P_FLAG; return znptable8[flags_res & 0xff] & P_FLAG;
case FLAGS_UNKNOWN: case FLAGS_UNKNOWN:
@ -90,6 +129,9 @@ static inline int VF_SET()
case FLAGS_ZN8: case FLAGS_ZN8:
case FLAGS_ZN16: case FLAGS_ZN16:
case FLAGS_ZN32: case FLAGS_ZN32:
case FLAGS_SAR8:
case FLAGS_SAR16:
case FLAGS_SAR32:
return 0; return 0;
case FLAGS_ADD8: case FLAGS_ADD8:
@ -106,6 +148,20 @@ static inline int VF_SET()
case FLAGS_SUB32: case FLAGS_SUB32:
return ((flags_op1 ^ flags_op2) & (flags_op1 ^ flags_res) & 0x80000000); return ((flags_op1 ^ flags_op2) & (flags_op1 ^ flags_res) & 0x80000000);
case FLAGS_SHL8:
return (((flags_op1 << flags_op2) ^ (flags_op1 << (flags_op2 - 1))) & 0x80);
case FLAGS_SHL16:
return (((flags_op1 << flags_op2) ^ (flags_op1 << (flags_op2 - 1))) & 0x8000);
case FLAGS_SHL32:
return (((flags_op1 << flags_op2) ^ (flags_op1 << (flags_op2 - 1))) & 0x80000000);
case FLAGS_SHR8:
return ((flags_op2 == 1) && (flags_op1 & 0x80));
case FLAGS_SHR16:
return ((flags_op2 == 1) && (flags_op1 & 0x8000));
case FLAGS_SHR32:
return ((flags_op2 == 1) && (flags_op1 & 0x80000000));
case FLAGS_UNKNOWN: case FLAGS_UNKNOWN:
return flags & V_FLAG; return flags & V_FLAG;
} }
@ -118,6 +174,15 @@ static inline int AF_SET()
case FLAGS_ZN8: case FLAGS_ZN8:
case FLAGS_ZN16: case FLAGS_ZN16:
case FLAGS_ZN32: case FLAGS_ZN32:
case FLAGS_SHL8:
case FLAGS_SHL16:
case FLAGS_SHL32:
case FLAGS_SHR8:
case FLAGS_SHR16:
case FLAGS_SHR32:
case FLAGS_SAR8:
case FLAGS_SAR16:
case FLAGS_SAR32:
return 0; return 0;
case FLAGS_ADD8: case FLAGS_ADD8:
@ -214,6 +279,13 @@ static inline void setznp32(uint32_t val)
flags &= ~C_FLAG; flags &= ~C_FLAG;
} }
#define set_flags_shift(op, orig, shift, res) \
flags_op = op; \
flags_res = res; \
flags_op1 = orig; \
flags_op2 = shift; \
flags &= ~C_FLAG;
static inline void setadd8(uint8_t a, uint8_t b) static inline void setadd8(uint8_t a, uint8_t b)
{ {
flags_op1 = a; flags_op1 = a;

View file

@ -1,4 +1,6 @@
#define OP_SHIFT_b(c) \ #define OP_SHIFT_b(c) \
{ \
uint8_t temp_orig = temp; \
if (!c) return 0; \ if (!c) return 0; \
flags_rebuild(); \ flags_rebuild(); \
switch (rmdat & 0x38) \ switch (rmdat & 0x38) \
@ -64,16 +66,14 @@
break; \ break; \
case 0x20: case 0x30: /*SHL b,CL*/ \ case 0x20: case 0x30: /*SHL b,CL*/ \
seteab(temp << c); if (abrt) return 0; \ seteab(temp << c); if (abrt) return 0; \
setznp8(temp << c); \ set_flags_shift(FLAGS_SHL8, temp_orig, c, temp << c); \
if ((temp << (c - 1)) & 0x80) flags |= C_FLAG; \ if ((temp << (c - 1)) & 0x80) flags |= C_FLAG; \
if (((temp << c) ^ (temp << (c - 1))) & 0x80) flags |= V_FLAG; \
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
case 0x28: /*SHR b,CL*/ \ case 0x28: /*SHR b,CL*/ \
seteab(temp >> c); if (abrt) return 0; \ seteab(temp >> c); if (abrt) return 0; \
setznp8(temp >> c); \ set_flags_shift(FLAGS_SHR8, temp_orig, c, temp >> c); \
if ((temp >> (c - 1)) & 1) flags |= C_FLAG; \ if ((temp >> (c - 1)) & 1) flags |= C_FLAG; \
if (c == 1 && temp & 0x80) flags |= V_FLAG; \
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
case 0x38: /*SAR b,CL*/ \ case 0x38: /*SAR b,CL*/ \
@ -85,13 +85,16 @@
c--; \ c--; \
} \ } \
seteab(temp); if (abrt) return 0; \ seteab(temp); if (abrt) return 0; \
setznp8(temp); \ set_flags_shift(FLAGS_SAR8, temp_orig, c, temp); \
if (tempc) flags |= C_FLAG; \ if (tempc) flags |= C_FLAG; \
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
} \
} }
#define OP_SHIFT_w(c) \ #define OP_SHIFT_w(c) \
{ \
uint16_t temp_orig = temp; \
if (!c) return 0; \ if (!c) return 0; \
flags_rebuild(); \ flags_rebuild(); \
switch (rmdat & 0x38) \ switch (rmdat & 0x38) \
@ -157,16 +160,14 @@
break; \ break; \
case 0x20: case 0x30: /*SHL w, c*/ \ case 0x20: case 0x30: /*SHL w, c*/ \
seteaw(temp << c); if (abrt) return 0; \ seteaw(temp << c); if (abrt) return 0; \
setznp16(temp << c); \ set_flags_shift(FLAGS_SHL16, temp_orig, c, temp << c); \
if ((temp << (c - 1)) & 0x8000) flags |= C_FLAG; \ if ((temp << (c - 1)) & 0x8000) flags |= C_FLAG; \
if (((temp << c) ^ (temp << (c - 1))) & 0x8000) flags |= V_FLAG;\
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
case 0x28: /*SHR w, c*/ \ case 0x28: /*SHR w, c*/ \
seteaw(temp >> c); if (abrt) return 0; \ seteaw(temp >> c); if (abrt) return 0; \
setznp16(temp >> c); \ set_flags_shift(FLAGS_SHR16, temp_orig, c, temp >> c); \
if ((temp >> (c - 1)) & 1) flags |= C_FLAG; \ if ((temp >> (c - 1)) & 1) flags |= C_FLAG; \
if (c == 1 && temp & 0x8000) flags |= V_FLAG; \
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
case 0x38: /*SAR w, c*/ \ case 0x38: /*SAR w, c*/ \
@ -178,13 +179,16 @@
c--; \ c--; \
} \ } \
seteaw(temp); if (abrt) return 0; \ seteaw(temp); if (abrt) return 0; \
setznp16(temp); \ set_flags_shift(FLAGS_SAR16, temp_orig, c, temp); \
if (tempc) flags |= C_FLAG; \ if (tempc) flags |= C_FLAG; \
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
} \
} }
#define OP_SHIFT_l(c) \ #define OP_SHIFT_l(c) \
{ \
uint32_t temp_orig = temp; \
if (!c) return 0; \ if (!c) return 0; \
flags_rebuild(); \ flags_rebuild(); \
switch (rmdat & 0x38) \ switch (rmdat & 0x38) \
@ -250,16 +254,14 @@
break; \ break; \
case 0x20: case 0x30: /*SHL l, c*/ \ case 0x20: case 0x30: /*SHL l, c*/ \
seteal(temp << c); if (abrt) return 0; \ seteal(temp << c); if (abrt) return 0; \
setznp32(temp << c); \ set_flags_shift(FLAGS_SHL32, temp_orig, c, temp << c); \
if ((temp << (c - 1)) & 0x80000000) flags |= C_FLAG; \ if ((temp << (c - 1)) & 0x80000000) flags |= C_FLAG; \
if (((temp << c) ^ (temp << (c - 1))) & 0x80000000) flags |= V_FLAG;\
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
case 0x28: /*SHR l, c*/ \ case 0x28: /*SHR l, c*/ \
seteal(temp >> c); if (abrt) return 0; \ seteal(temp >> c); if (abrt) return 0; \
setznp32(temp >> c); \ set_flags_shift(FLAGS_SHR32, temp_orig, c, temp >> c); \
if ((temp >> (c - 1)) & 1) flags |= C_FLAG; \ if ((temp >> (c - 1)) & 1) flags |= C_FLAG; \
if (c == 1 && temp & 0x80000000) flags |= V_FLAG; \
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
case 0x38: /*SAR l, c*/ \ case 0x38: /*SAR l, c*/ \
@ -271,10 +273,11 @@
c--; \ c--; \
} \ } \
seteal(temp); if (abrt) return 0; \ seteal(temp); if (abrt) return 0; \
setznp32(temp); \ set_flags_shift(FLAGS_SAR32, temp_orig, c, temp); \
if (tempc) flags |= C_FLAG; \ if (tempc) flags |= C_FLAG; \
cycles -= ((mod == 3) ? 3 : 7); \ cycles -= ((mod == 3) ? 3 : 7); \
break; \ break; \
} \
} }
static int opC0_a16(uint32_t fetchdat) static int opC0_a16(uint32_t fetchdat)