summaryrefslogtreecommitdiff
path: root/src/gfx.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gfx.h')
-rw-r--r--src/gfx.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/gfx.h b/src/gfx.h
index f873531..362da1d 100644
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -64,8 +64,11 @@ typedef struct
// Setup in call to S9xGraphicsInit()
int Delta;
+#if defined(USE_OLD_COLOUR_OPS)
+ /* Pre-1.60 colour operations */
uint16* X2;
uint16* ZERO_OR_X2;
+#endif
uint16* ZERO;
uint8* S;
uint8* DB;
@@ -202,6 +205,8 @@ extern uint8 mul_brightness [16][32];
#define SUB_SCREEN_DEPTH 0
#define MAIN_SCREEN_DEPTH 32
+#if defined(USE_OLD_COLOUR_OPS)
+/* Pre-1.60 colour operations */
#if defined(OLD_COLOUR_BLENDING)
#define COLOR_ADD(C1, C2) \
GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
@@ -214,12 +219,34 @@ GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
((C1) & (C2) & RGB_LOW_BITS_MASK)] | \
(((C1) ^ (C2)) & RGB_LOW_BITS_MASK))
#endif
+#else
+static INLINE uint16_t COLOR_ADD(uint16_t C1, uint16_t C2)
+{
+ const int RED_MASK = 0x1F << RED_SHIFT_BITS;
+ const int GREEN_MASK = 0x1F << GREEN_SHIFT_BITS;
+ const int BLUE_MASK = 0x1F;
+
+ int rb = (C1 & (RED_MASK | BLUE_MASK)) + (C2 & (RED_MASK | BLUE_MASK));
+ int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
+ int g = (C1 & (GREEN_MASK)) + (C2 & (GREEN_MASK));
+ int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f;
+ uint16_t retval = (rb & (RED_MASK | BLUE_MASK)) | (g & GREEN_MASK) | rgbsaturate;
+
+#if GREEN_SHIFT_BITS == 6
+ retval |= (retval & 0x0400) >> 5;
+#endif
+
+ return retval;
+}
+#endif
#define COLOR_ADD1_2(C1, C2) \
(((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
((C1) & (C2) & RGB_LOW_BITS_MASK) | ALPHA_BITS_MASK)
+#if defined(USE_OLD_COLOUR_OPS)
+/* Pre-1.60 colour operations */
#if defined(OLD_COLOUR_BLENDING)
#define COLOR_SUB(C1, C2) \
GFX.ZERO_OR_X2 [(((C1) | RGB_HI_BITS_MASKx2) - \
@@ -230,6 +257,24 @@ GFX.ZERO_OR_X2 [(((C1) | RGB_HI_BITS_MASKx2) - \
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1] + \
((C1) & RGB_LOW_BITS_MASK) - ((C2) & RGB_LOW_BITS_MASK))
#endif
+#else
+static INLINE uint16_t COLOR_SUB(uint16_t C1, uint16_t C2)
+{
+ int rb1 = (C1 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | ((0x20 << 0) | (0x20 << RED_SHIFT_BITS));
+ int rb2 = C2 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK);
+ int rb = rb1 - rb2;
+ int rbcarry = rb & ((0x20 << RED_SHIFT_BITS) | (0x20 << 0));
+ int g = ((C1 & (SECOND_COLOR_MASK)) | (0x20 << GREEN_SHIFT_BITS)) - (C2 & (SECOND_COLOR_MASK));
+ int rgbsaturate = (((g & (0x20 << GREEN_SHIFT_BITS)) | rbcarry) >> 5) * 0x1f;
+ uint16_t 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;
+}
+#endif
#define COLOR_SUB1_2(C1, C2) \
GFX.ZERO [(((C1) | RGB_HI_BITS_MASKx2) - \