From 02aa2d0c6af003deaaf330e519a3e85384986168 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Wed, 6 Mar 2019 20:17:07 -0600 Subject: [PATCH] Use a lookup table. A little faster. --- gfx.h | 23 +++++++---------------- globals.cpp | 2 ++ ppu.cpp | 8 ++++++++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/gfx.h b/gfx.h index 77eb344d..9bcc8b6f 100644 --- a/gfx.h +++ b/gfx.h @@ -125,6 +125,7 @@ struct SLineMatrixData extern uint16 BlackColourMap[256]; extern uint16 DirectColourMaps[8][256]; extern uint8 mul_brightness[16][32]; +extern uint8 brightness_cap[64]; extern struct SBG BG; extern struct SGFX GFX; @@ -132,8 +133,6 @@ extern struct SGFX GFX; #define V_FLIP 0x8000 #define BLANK_TILE 2 -#include "ppu.h" - #define COLOR_ADD1_2(C1, C2) \ ((((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \ ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \ @@ -147,20 +146,12 @@ extern struct SGFX GFX; inline uint16 COLOR_ADD(uint16 C1, uint16 C2) { - int r1, g1, b1, r2, g2, b2; - int cap = mul_brightness[PPU.Brightness][31]; - DECOMPOSE_PIXEL(C1, r1, g1, b1); - DECOMPOSE_PIXEL(C2, r2, g2, b2); - r1 += r2; - if (r1 > cap) - r1 = cap; - g1 += g2; - if (g1 > cap) - g1 = cap; - b1 += b2; - if (b1 > cap) - b1 = cap; - return BUILD_PIXEL(r1, g1, b1); + int r1, g1, b1, r2, g2, b2; + DECOMPOSE_PIXEL(C1, r1, g1, b1); + DECOMPOSE_PIXEL(C2, r2, g2, b2); + return BUILD_PIXEL(brightness_cap[r1 + r2], + brightness_cap[g1 + g2], + brightness_cap[b1 + b2]); } #define COLOR_SUB1_2(C1, C2) \ diff --git a/globals.cpp b/globals.cpp index 645c42a2..b671cf58 100644 --- a/globals.cpp +++ b/globals.cpp @@ -144,6 +144,8 @@ uint8 mul_brightness[16][32] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f } }; +uint8 brightness_cap[64]; + uint8 S9xOpLengthsM0X0[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F diff --git a/ppu.cpp b/ppu.cpp index a0ded291..6bca9dc4 100644 --- a/ppu.cpp +++ b/ppu.cpp @@ -189,6 +189,14 @@ void S9xFixColourBrightness (void) { IPPU.XB = mul_brightness[PPU.Brightness]; + for (int i = 0; i < 64; i++) + { + if (i > IPPU.XB[0x1f]) + brightness_cap[i] = IPPU.XB[0x1f]; + else + brightness_cap[i] = i; + } + for (int i = 0; i < 256; i++) { IPPU.Red[i] = IPPU.XB[(PPU.CGDATA[i]) & 0x1f];