From b6cc37c04791042b354ae31e6cc083c6be7e6564 Mon Sep 17 00:00:00 2001 From: jbo_85 Date: Wed, 13 Feb 2008 23:16:16 +0000 Subject: [PATCH] Optimized some stuff in the renderer. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@368 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/GBA-arm.cpp | 1 - src/GBA-thumb.cpp | 1 - src/Gfx.h | 142 ++++++++++++---------------------- src/Mode0.cpp | 193 ++++++++++++++++++---------------------------- src/Mode1.cpp | 149 ++++++++++++++--------------------- src/Mode2.cpp | 134 ++++++++++++-------------------- src/Mode3.cpp | 112 ++++++++++----------------- src/Mode4.cpp | 112 ++++++++++----------------- src/Mode5.cpp | 112 ++++++++++----------------- 9 files changed, 356 insertions(+), 600 deletions(-) diff --git a/src/GBA-arm.cpp b/src/GBA-arm.cpp index 500c3858..bda12b4f 100644 --- a/src/GBA-arm.cpp +++ b/src/GBA-arm.cpp @@ -27,7 +27,6 @@ #include "GBAcpu.h" #include "GBAinline.h" #include "Globals.h" -#include "Gfx.h" #include "EEprom.h" #include "Flash.h" #include "Sound.h" diff --git a/src/GBA-thumb.cpp b/src/GBA-thumb.cpp index aa1534d6..1cc22697 100644 --- a/src/GBA-thumb.cpp +++ b/src/GBA-thumb.cpp @@ -27,7 +27,6 @@ #include "GBAcpu.h" #include "GBAinline.h" #include "Globals.h" -#include "Gfx.h" #include "EEprom.h" #include "Flash.h" #include "Sound.h" diff --git a/src/Gfx.h b/src/Gfx.h index ced03e5a..597148ca 100644 --- a/src/Gfx.h +++ b/src/Gfx.h @@ -159,7 +159,7 @@ static inline void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs, if(mosaicOn) { if((VCOUNT % mosaicY) != 0) { - mosaicY = (VCOUNT / mosaicY) * mosaicY; + mosaicY = VCOUNT - (VCOUNT % mosaicY); yyy = (vofs + mosaicY) & maskY; } } @@ -181,6 +181,9 @@ static inline void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs, int tileX = (xxx & 7); int tileY = yyy & 7; + if(tileX == 7) + screenSource++; + if(data & 0x0400) tileX = 7 - tileX; if(data & 0x0800) @@ -190,11 +193,6 @@ static inline void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs, line[x] = color ? (READ16LE(&palette[color]) | prio): 0x80000000; - if(data & 0x0400) { - if(tileX == 0) - screenSource++; - } else if(tileX == 7) - screenSource++; xxx++; if(xxx == 256) { if(sizeX > 256) @@ -218,6 +216,9 @@ static inline void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs, int tileX = (xxx & 7); int tileY = yyy & 7; + if(tileX == 7) + screenSource++; + if(data & 0x0400) tileX = 7 - tileX; if(data & 0x0800) @@ -231,14 +232,9 @@ static inline void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs, color &= 0x0F; } - int pal = (READ16LE(screenSource)>>8) & 0xF0; + int pal = (data>>8) & 0xF0; line[x] = color ? (READ16LE(&palette[pal + color])|prio): 0x80000000; - if(data & 0x0400) { - if(tileX == 0) - screenSource++; - } else if(tileX == 7) - screenSource++; xxx++; if(xxx == 256) { if(sizeX > 256) @@ -345,44 +341,28 @@ static inline void gfxDrawRotScreen(u16 control, realY -= y*dmy; } - int xxx = (realX >> 8); - int yyy = (realY >> 8); - if(control & 0x2000) { - xxx &= maskX; - yyy &= maskY; - } - - if(control & 0x80) { for(int x = 0; x < 240; x++) { - if(xxx < 0 || - yyy < 0 || - xxx >= sizeX || - yyy >= sizeY) { - line[x] = 0x80000000; - } else { - int tile = screenBase[(xxx>>3) + ((yyy>>3)<> 8) & maskX; + int yyy = (realY >> 8) & maskY; - int tileX = (xxx & 7); - int tileY = yyy & 7; + int tile = screenBase[(xxx>>3) + ((yyy>>3)<> 8); - yyy = (realY >> 8); - - if(control & 0x2000) { - xxx &= maskX; - yyy &= maskY; - } } } else { for(int x = 0; x < 240; x++) { + int xxx = (realX >> 8); + int yyy = (realY >> 8); + if(xxx < 0 || yyy < 0 || xxx >= sizeX || @@ -400,14 +380,6 @@ static inline void gfxDrawRotScreen(u16 control, } realX += dx; realY += dy; - - xxx = (realX >> 8); - yyy = (realY >> 8); - - if(control & 0x2000) { - xxx &= maskX; - yyy &= maskY; - } } } @@ -583,7 +555,7 @@ static inline void gfxDrawRotScreen256(u16 control, if(control & 0x40) { int mosaicY = ((MOSAIC & 0xF0)>>4) + 1; - int y = (VCOUNT / mosaicY) * mosaicY; + int y = VCOUNT - (VCOUNT % mosaicY); realX = startX + y*dmx; realY = startY + y*dmy; } @@ -684,7 +656,7 @@ static inline void gfxDrawRotScreen16Bit160(u16 control, if(control & 0x40) { int mosaicY = ((MOSAIC & 0xF0)>>4) + 1; - int y = (VCOUNT / mosaicY) * mosaicY; + int y = VCOUNT - (VCOUNT % mosaicY); realX = startX + y*dmx; realY = startY + y*dmy; } @@ -1508,21 +1480,13 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin) static inline u32 gfxIncreaseBrightness(u32 color, int coeff) { - int r = (color & 0x1F); - int g = ((color >> 5) & 0x1F); - int b = ((color >> 10) & 0x1F); + color &= 0xffff; + color = ((color << 16) | color) & 0x3E07C1F; - r = r + (((31 - r) * coeff) >> 4); - g = g + (((31 - g) * coeff) >> 4); - b = b + (((31 - b) * coeff) >> 4); - if(r > 31) - r = 31; - if(g > 31) - g = 31; - if(b > 31) - b = 31; - color = (color & 0xFFFF0000) | (b << 10) | (g << 5) | r; - return color; + color = color + (((0x3E07C1F - color) * coeff) >> 4); + color &= 0x3E07C1F; + + return (color >> 16) | color; } static inline void gfxIncreaseBrightness(u32 *line, int coeff) @@ -1548,22 +1512,12 @@ static inline void gfxIncreaseBrightness(u32 *line, int coeff) static inline u32 gfxDecreaseBrightness(u32 color, int coeff) { - int r = (color & 0x1F); - int g = ((color >> 5) & 0x1F); - int b = ((color >> 10) & 0x1F); + color &= 0xffff; + color = ((color << 16) | color) & 0x3E07C1F; - r = r - ((r * coeff) >> 4); - g = g - ((g * coeff) >> 4); - b = b - ((b * coeff) >> 4); - if(r < 0) - r = 0; - if(g < 0) - g = 0; - if(b < 0) - b = 0; - color = (color & 0xFFFF0000) | (b << 10) | (g << 5) | r; + color = color - (((color * coeff) >> 4) & 0x3E07C1F); - return color; + return (color >> 16) | color; } static inline void gfxDecreaseBrightness(u32 *line, int coeff) @@ -1590,25 +1544,25 @@ static inline void gfxDecreaseBrightness(u32 *line, int coeff) static inline u32 gfxAlphaBlend(u32 color, u32 color2, int ca, int cb) { if(color < 0x80000000) { - int r = (color & 0x1F); - int g = ((color >> 5) & 0x1F); - int b = ((color >> 10) & 0x1F); - int r0 = (color2 & 0x1F); - int g0 = ((color2 >> 5) & 0x1F); - int b0 = ((color2 >> 10) & 0x1F); + color&=0xffff; + color2&=0xffff; - r = ((r * ca) + (r0 * cb)) >> 4; - g = ((g * ca) + (g0 * cb)) >> 4; - b = ((b * ca) + (b0 * cb)) >> 4; + color = ((color << 16) | color) & 0x03E07C1F; + color2 = ((color2 << 16) | color2) & 0x03E07C1F; + color = ((color * ca) + (color2 * cb)) >> 4; - if(r > 31) - r = 31; - if(g > 31) - g = 31; - if(b > 31) - b = 31; + if ((ca + cb)>16) + { + if (color & 0x20) + color |= 0x1f; + if (color & 0x8000) + color |= 0x7C00; + if (color & 0x4000000) + color |= 0x03E00000; + } - return (color & 0xFFFF0000) | (b << 10) | (g << 5) | r; + color &= 0x03E07C1F; + color = (color >> 16) | color; } return color; } diff --git a/src/Mode0.cpp b/src/Mode0.cpp index 438812ca..1f5ed2e4 100644 --- a/src/Mode0.cpp +++ b/src/Mode0.cpp @@ -109,18 +109,18 @@ void mode0RenderLine() color = gfxAlphaBlend(color, back, coeff[COLEV & 0x1F], coeff[(COLEV >> 8) & 0x1F]); - else { - switch((BLDMOD >> 6) & 3) { - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } + else { + switch((BLDMOD >> 6) & 3) { + case 2: + if(BLDMOD & top) + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); + break; + case 3: + if(BLDMOD & top) + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); + break; } + } } lineMix[x] = color; @@ -400,111 +400,7 @@ void mode0RenderLineAll() top = 0x10; } - // special FX on in the window - if(mask & 32) { - if(!(color & 0x00010000)) { - switch((BLDMOD >> 6) & 3) { - case 0: - break; - case 1: - { - if(top & BLDMOD) { - u32 back = backdrop; - u8 top2 = 0x20; - if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) { - if(top != 0x01) { - back = line0[x]; - top2 = 0x01; - } - } - - if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) { - if(top != 0x02) { - back = line1[x]; - top2 = 0x02; - } - } - - if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) { - if(top != 0x04) { - back = line2[x]; - top2 = 0x04; - } - } - - if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) { - if(top != 0x08) { - back = line3[x]; - top2 = 0x08; - } - } - - if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { - if(top != 0x10) { - back = lineOBJ[x]; - top2 = 0x10; - } - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - } - } - break; - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } else { - // semi-transparent OBJ - u32 back = backdrop; - u8 top2 = 0x20; - - if((mask & 1) && ((u8)(line0[x]>>24) < (u8)(back >> 24))) { - back = line0[x]; - top2 = 0x01; - } - - if((mask & 2) && ((u8)(line1[x]>>24) < (u8)(back >> 24))) { - back = line1[x]; - top2 = 0x02; - } - - if((mask & 4) && ((u8)(line2[x]>>24) < (u8)(back >> 24))) { - back = line2[x]; - top2 = 0x04; - } - - if((mask & 8) && ((u8)(line3[x]>>24) < (u8)(back >> 24))) { - back = line3[x]; - top2 = 0x08; - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - else { - switch((BLDMOD >> 6) & 3) { - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } - } - } else if(color & 0x00010000) { + if(color & 0x00010000) { // semi-transparent OBJ u32 back = backdrop; u8 top2 = 0x20; @@ -531,8 +427,8 @@ void mode0RenderLineAll() if(top2 & (BLDMOD>>8)) color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); else { switch((BLDMOD >> 6) & 3) { case 2: @@ -545,6 +441,67 @@ void mode0RenderLineAll() break; } } + } else if(mask & 32) { + // special FX on in the window + switch((BLDMOD >> 6) & 3) { + case 0: + break; + case 1: + { + if(top & BLDMOD) { + u32 back = backdrop; + u8 top2 = 0x20; + if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) { + if(top != 0x01) { + back = line0[x]; + top2 = 0x01; + } + } + + if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) { + if(top != 0x02) { + back = line1[x]; + top2 = 0x02; + } + } + + if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) { + if(top != 0x04) { + back = line2[x]; + top2 = 0x04; + } + } + + if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) { + if(top != 0x08) { + back = line3[x]; + top2 = 0x08; + } + } + + if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { + if(top != 0x10) { + back = lineOBJ[x]; + top2 = 0x10; + } + } + + if(top2 & (BLDMOD>>8)) + color = gfxAlphaBlend(color, back, + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); + } + } + break; + case 2: + if(BLDMOD & top) + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); + break; + case 3: + if(BLDMOD & top) + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); + break; + } } lineMix[x] = color; diff --git a/src/Mode1.cpp b/src/Mode1.cpp index 7f706e7a..85f30383 100644 --- a/src/Mode1.cpp +++ b/src/Mode1.cpp @@ -376,99 +376,7 @@ void mode1RenderLineAll() top = 0x10; } - // special FX on the window - if(mask & 32) { - if(!(color & 0x00010000)) { - switch((BLDMOD >> 6) & 3) { - case 0: - break; - case 1: - { - if(top & BLDMOD) { - u32 back = backdrop; - u8 top2 = 0x20; - if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) { - if(top != 0x01) { - back = line0[x]; - top2 = 0x01; - } - } - - if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) { - if(top != 0x02) { - back = line1[x]; - top2 = 0x02; - } - } - - if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) { - if(top != 0x04) { - back = line2[x]; - top2 = 0x04; - } - } - - if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { - if(top != 0x10) { - back = lineOBJ[x]; - top2 = 0x10; - } - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - } - } - break; - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } else { - // semi-transparent OBJ - u32 back = backdrop; - u8 top2 = 0x20; - - if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) { - back = line0[x]; - top2 = 0x01; - } - - if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) { - back = line1[x]; - top2 = 0x02; - } - - if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) { - back = line2[x]; - top2 = 0x04; - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - else { - switch((BLDMOD >> 6) & 3) { - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } - } - } else if(color & 0x00010000) { + if(color & 0x00010000) { // semi-transparent OBJ u32 back = backdrop; u8 top2 = 0x20; @@ -504,6 +412,61 @@ void mode1RenderLineAll() break; } } + } else if(mask & 32) { + // special FX on the window + switch((BLDMOD >> 6) & 3) { + case 0: + break; + case 1: + { + if(top & BLDMOD) { + u32 back = backdrop; + u8 top2 = 0x20; + + if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) { + if(top != 0x01) { + back = line0[x]; + top2 = 0x01; + } + } + + if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) { + if(top != 0x02) { + back = line1[x]; + top2 = 0x02; + } + } + + if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) { + if(top != 0x04) { + back = line2[x]; + top2 = 0x04; + } + } + + if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { + if(top != 0x10) { + back = lineOBJ[x]; + top2 = 0x10; + } + } + + if(top2 & (BLDMOD>>8)) + color = gfxAlphaBlend(color, back, + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); + } + } + break; + case 2: + if(BLDMOD & top) + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); + break; + case 3: + if(BLDMOD & top) + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); + break; + } } lineMix[x] = color; diff --git a/src/Mode2.cpp b/src/Mode2.cpp index a3f746af..132be0cd 100644 --- a/src/Mode2.cpp +++ b/src/Mode2.cpp @@ -357,87 +357,7 @@ void mode2RenderLineAll() top = 0x10; } - if(mask & 32) { - if(!(color & 0x00010000)) { - switch((BLDMOD >> 6) & 3) { - case 0: - break; - case 1: - { - if(top & BLDMOD) { - u32 back = backdrop; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - if(top != 0x04) { - back = line2[x]; - top2 = 0x04; - } - } - - if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) { - if(top != 0x08) { - back = line3[x]; - top2 = 0x08; - } - } - - if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { - if(top != 0x10) { - back = lineOBJ[x]; - top2 = 0x10; - } - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - } - } - break; - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } else { - // semi-transparent OBJ - u32 back = backdrop; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - back = line2[x]; - top2 = 0x04; - } - - if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) { - back = line3[x]; - top2 = 0x08; - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - else { - switch((BLDMOD >> 6) & 3) { - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } - } - } else if(color & 0x00010000) { + if(color & 0x00010000) { // semi-transparent OBJ u32 back = backdrop; u8 top2 = 0x20; @@ -454,8 +374,8 @@ void mode2RenderLineAll() if(top2 & (BLDMOD>>8)) color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); else { switch((BLDMOD >> 6) & 3) { case 2: @@ -468,6 +388,54 @@ void mode2RenderLineAll() break; } } + } else if(mask & 32) { + // special FX on the window + switch((BLDMOD >> 6) & 3) { + case 0: + break; + case 1: + { + if(top & BLDMOD) { + u32 back = backdrop; + u8 top2 = 0x20; + + if((mask & 4) && line2[x] < back) { + if(top != 0x04) { + back = line2[x]; + top2 = 0x04; + } + } + + if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) { + if(top != 0x08) { + back = line3[x]; + top2 = 0x08; + } + } + + if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { + if(top != 0x10) { + back = lineOBJ[x]; + top2 = 0x10; + } + } + + if(top2 & (BLDMOD>>8)) + color = gfxAlphaBlend(color, back, + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); + } + } + break; + case 2: + if(BLDMOD & top) + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); + break; + case 3: + if(BLDMOD & top) + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); + break; + } } lineMix[x] = color; diff --git a/src/Mode3.cpp b/src/Mode3.cpp index 273e8731..6dd2067f 100644 --- a/src/Mode3.cpp +++ b/src/Mode3.cpp @@ -301,76 +301,7 @@ void mode3RenderLineAll() top = 0x10; } - if(mask & 32) { - if(!(color & 0x00010000)) { - switch((BLDMOD >> 6) & 3) { - case 0: - break; - case 1: - { - if(top & BLDMOD) { - u32 back = background; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - if(top != 0x04) { - back = line2[x]; - top2 = 0x04; - } - } - - if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { - if(top != 0x10) { - back = lineOBJ[x]; - top2 = 0x10; - } - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - - } - } - break; - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } else { - // semi-transparent OBJ - u32 back = background; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - back = line2[x]; - top2 = 0x04; - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - else { - switch((BLDMOD >> 6) & 3) { - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } - } - } else if(color & 0x00010000) { + if(color & 0x00010000) { // semi-transparent OBJ u32 back = background; u8 top2 = 0x20; @@ -396,6 +327,47 @@ void mode3RenderLineAll() break; } } + } else if(mask & 32) { + switch((BLDMOD >> 6) & 3) { + case 0: + break; + case 1: + { + if(top & BLDMOD) { + u32 back = background; + u8 top2 = 0x20; + + if((mask & 4) && line2[x] < back) { + if(top != 0x04) { + back = line2[x]; + top2 = 0x04; + } + } + + if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { + if(top != 0x10) { + back = lineOBJ[x]; + top2 = 0x10; + } + } + + if(top2 & (BLDMOD>>8)) + color = gfxAlphaBlend(color, back, + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); + + } + } + break; + case 2: + if(BLDMOD & top) + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); + break; + case 3: + if(BLDMOD & top) + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); + break; + } } lineMix[x] = color; diff --git a/src/Mode4.cpp b/src/Mode4.cpp index c370b05f..4b6d3e8d 100644 --- a/src/Mode4.cpp +++ b/src/Mode4.cpp @@ -298,76 +298,7 @@ void mode4RenderLineAll() top = 0x10; } - if(mask & 32) { - if(!(color & 0x00010000)) { - switch((BLDMOD >> 6) & 3) { - case 0: - break; - case 1: - { - if(top & BLDMOD) { - u32 back = backdrop; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - if(top != 0x04) { - back = line2[x]; - top2 = 0x04; - } - } - - if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { - if(top != 0x10) { - back = lineOBJ[x]; - top2 = 0x10; - } - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - - } - } - break; - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } else { - // semi-transparent OBJ - u32 back = backdrop; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - back = line2[x]; - top2 = 0x04; - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - else { - switch((BLDMOD >> 6) & 3) { - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } - } - } else if(color & 0x00010000) { + if(color & 0x00010000) { // semi-transparent OBJ u32 back = backdrop; u8 top2 = 0x20; @@ -393,6 +324,47 @@ void mode4RenderLineAll() break; } } + } else if(mask & 32) { + switch((BLDMOD >> 6) & 3) { + case 0: + break; + case 1: + { + if(top & BLDMOD) { + u32 back = backdrop; + u8 top2 = 0x20; + + if((mask & 4) && line2[x] < back) { + if(top != 0x04) { + back = line2[x]; + top2 = 0x04; + } + } + + if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { + if(top != 0x10) { + back = lineOBJ[x]; + top2 = 0x10; + } + } + + if(top2 & (BLDMOD>>8)) + color = gfxAlphaBlend(color, back, + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); + + } + } + break; + case 2: + if(BLDMOD & top) + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); + break; + case 3: + if(BLDMOD & top) + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); + break; + } } lineMix[x] = color; diff --git a/src/Mode5.cpp b/src/Mode5.cpp index 250a9d62..a2378e1a 100644 --- a/src/Mode5.cpp +++ b/src/Mode5.cpp @@ -301,76 +301,7 @@ void mode5RenderLineAll() top = 0x10; } - if(mask & 32) { - if(!(color & 0x00010000)) { - switch((BLDMOD >> 6) & 3) { - case 0: - break; - case 1: - { - if(top & BLDMOD) { - u32 back = background; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - if(top != 0x04) { - back = line2[x]; - top2 = 0x04; - } - } - - if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { - if(top != 0x10) { - back = lineOBJ[x]; - top2 = 0x10; - } - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - - } - } - break; - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } else { - // semi-transparent OBJ - u32 back = background; - u8 top2 = 0x20; - - if((mask & 4) && line2[x] < back) { - back = line2[x]; - top2 = 0x04; - } - - if(top2 & (BLDMOD>>8)) - color = gfxAlphaBlend(color, back, - coeff[COLEV & 0x1F], - coeff[(COLEV >> 8) & 0x1F]); - else { - switch((BLDMOD >> 6) & 3) { - case 2: - if(BLDMOD & top) - color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); - break; - case 3: - if(BLDMOD & top) - color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); - break; - } - } - } - } else if(color & 0x00010000) { + if(color & 0x00010000) { // semi-transparent OBJ u32 back = background; u8 top2 = 0x20; @@ -396,6 +327,47 @@ void mode5RenderLineAll() break; } } + } else if(mask & 32) { + switch((BLDMOD >> 6) & 3) { + case 0: + break; + case 1: + { + if(top & BLDMOD) { + u32 back = background; + u8 top2 = 0x20; + + if((mask & 4) && line2[x] < back) { + if(top != 0x04) { + back = line2[x]; + top2 = 0x04; + } + } + + if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) { + if(top != 0x10) { + back = lineOBJ[x]; + top2 = 0x10; + } + } + + if(top2 & (BLDMOD>>8)) + color = gfxAlphaBlend(color, back, + coeff[COLEV & 0x1F], + coeff[(COLEV >> 8) & 0x1F]); + + } + } + break; + case 2: + if(BLDMOD & top) + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); + break; + case 3: + if(BLDMOD & top) + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); + break; + } } lineMix[x] = color;