VOGONS


First post, by danoon

User metadata
Rank Member
Rank
Member

I don't have a specific game this affects, but I've been writing some more unit tests for some code based on jDosbox which was based on Dosbox flag handling and it appears that the overflow flag for SHLD 16-bit is incorrect.

The OF flag for a 1bit shift should be set if there is a sign change. But notice how the lazy flag case looks at var1w when the 16-bit value being shifted is in the upper 16-bits of var1d (see below: load(op1)<<16)

I was just hoping that someone could verify if I was correct in my analysis. Perhaps the fix could be to use a tmp variable in the op and store the original 16-bit value in var1w (that fix would also affect the carry flag logic of DSHLw)
flags.cpp

Bit32u get_OF(void) {
...
cast t_DSHLw:
return (lf_resw ^ lf_var1w) & 0x8000;

instructions.h

#define DSHLW(op1,op2,op3,load,save)
Bit8u val=op3 & 0x1F;
if (!val) break;
lf_var2b=val;lf_var1d=(load(op1)<<16)|op2;
Bit32u tempd=lf_var1d << lf_var2b;
if (lf_var2b>16) tempd |= (op2 << (lf_var2b - 16));
lf_resw=(Bit16u)(tempd >> 16);
save(op1,lf_resw);
lflags.type=t_DSHLw;

http://www.boxedwine.org/