Snes9x - Recorrect green bit math. (#830)

This commit is contained in:
bladeoner 2019-04-03 20:56:33 +02:00 committed by dborth
parent ff8f40e53b
commit 30b717a1d6

View File

@ -154,8 +154,12 @@ inline uint16 COLOR_ADD(uint16 C1, uint16 C2)
rb += C2 & (RED_MASK | BLUE_MASK); rb += C2 & (RED_MASK | BLUE_MASK);
int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0)); int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
int g = (C1 & (GREEN_MASK)) + (C2 & (GREEN_MASK)); int g = (C1 & (GREEN_MASK)) + (C2 & (GREEN_MASK));
int rgbsaturate = (rbcarry >> 5) * 0x1f + ((g & (0x20 << GREEN_SHIFT_BITS)) >> GREEN_SHIFT_BITS) * MAX_GREEN; int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f;
return (rb & (RED_MASK | BLUE_MASK)) | (g & GREEN_MASK) | rgbsaturate; uint16 retval = (rb & (RED_MASK | BLUE_MASK)) | (g & GREEN_MASK) | rgbsaturate;
#if GREEN_SHIFT_BITS == 6
retval |= (retval & 0x0400) >> 5;
#endif
return retval;
} }
@ -170,8 +174,12 @@ inline uint16 COLOR_SUB (uint16 C1, uint16 C2)
int rb = rb1 - rb2; int rb = rb1 - rb2;
int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0)); int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
int g = ((C1 & (SECOND_COLOR_MASK)) | (0x20 << GREEN_SHIFT_BITS)) - (C2 & (SECOND_COLOR_MASK)); int g = ((C1 & (SECOND_COLOR_MASK)) | (0x20 << GREEN_SHIFT_BITS)) - (C2 & (SECOND_COLOR_MASK));
int rgbsaturate = (rbcarry >> 5) * 0x1f + ((g & (0x20 << GREEN_SHIFT_BITS)) >> GREEN_SHIFT_BITS) * MAX_GREEN; int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f;
return ((rb & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | (g & SECOND_COLOR_MASK)) & rgbsaturate; uint16 retval = ((rb & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | (g & SECOND_COLOR_MASK)) & rgbsaturate;
#if GREEN_SHIFT_BITS == 6
retval |= (retval & 0x0400) >> 5;
#endif
return retval;
} }
void S9xStartScreenRefresh (void); void S9xStartScreenRefresh (void);