repair 16bpp display mode, support more codepaths with modern deemph

This commit is contained in:
zeromus 2015-09-13 18:05:17 +00:00
parent 57ec344b1f
commit 271a82d349
4 changed files with 61 additions and 325 deletions

View File

@ -61,19 +61,6 @@ static int silt;
static int Bpp; // BYTES per pixel static int Bpp; // BYTES per pixel
static int highefx; static int highefx;
#define BLUR_RED 20
#define BLUR_GREEN 20
#define BLUR_BLUE 10
#define FVB_SCANLINES 1
/* The blur effect is only available for bpp>=16. It could be easily modified
to look like what happens on the real NES and TV, but lack of decent
synchronization to the vertical retrace period makes it look rather
blah.
*/
#define FVB_BLUR 2
static int Round(float value) static int Round(float value)
{ {
return (int) floor(value + 0.5); return (int) floor(value + 0.5);
@ -208,20 +195,8 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int
if(Bpp<=1 || Bpp>4) if(Bpp<=1 || Bpp>4)
return(0); return(0);
if(efx&FVB_BLUR) //allocate adequate room for 32bpp palette
{ palettetranslate=(uint32*)FCEU_dmalloc(256*4 + 512*4);
//if(Bpp==2)
// palettetranslate=(uint32 *)FCEU_dmalloc(65536*4);
//else if(Bpp>=3)
palettetranslate=(uint32 *)FCEU_dmalloc(65536*4);
}
else
{
//if(Bpp==2)
// palettetranslate=(uint32*)FCEU_dmalloc(65536*4);
//else if(Bpp>=3)
palettetranslate=(uint32*)FCEU_dmalloc(256*4 + 512*4);
}
if(!palettetranslate) if(!palettetranslate)
return(0); return(0);
@ -283,102 +258,56 @@ void SetPaletteBlitToHigh(uint8 *src)
{ {
int cshiftr[3]; int cshiftr[3];
int cshiftl[3]; int cshiftl[3];
int x,y;
CalculateShift(CBM, cshiftr, cshiftl); CalculateShift(CBM, cshiftr, cshiftl);
switch(Bpp) switch(Bpp)
{ {
case 2: case 2:
if(highefx&FVB_BLUR) for(int x=0;x<256;x++)
{ {
for(x=0;x<256;x++) uint32 r = src[x<<2];
{ uint32 g = src[(x<<2)+1];
uint32 r,g,b; uint32 b = src[(x<<2)+2];
for(y=0;y<256;y++) u16 color = (r>>cshiftr[0])<<cshiftl[0];
{ color |= (g>>cshiftr[1])<<cshiftl[1];
r=src[x<<2]*(100-BLUR_RED); color |= (b>>cshiftr[2])<<cshiftl[2];
g=src[(x<<2)+1]*(100-BLUR_GREEN); palettetranslate[x]=color;
b=src[(x<<2)+2]*(100-BLUR_BLUE);
r+=src[y<<2]*BLUR_RED;
g+=src[(y<<2)+1]*BLUR_GREEN;
b+=src[(y<<2)+2]*BLUR_BLUE;
r/=100;
g/=100;
b/=100;
if(r>255) r=255;
if(g>255) g=255;
if(b>255) b=255;
palettetranslate[x|(y<<8)]=
((r>>cshiftr[0])<<cshiftl[0])|
((g>>cshiftr[1])<<cshiftl[1])|
((b>>cshiftr[2])<<cshiftl[2]);
}
}
} }
else
for(x=0;x<65536;x++) //full size deemph palette
{ for(int x=0;x<512;x++)
uint16 lower,upper; {
uint32 r=palo[x].r;
lower=(src[((x&255)<<2)]>>cshiftr[0])<<cshiftl[0]; uint32 g=palo[x].g;
lower|=(src[((x&255)<<2)+1]>>cshiftr[1])<<cshiftl[1]; uint32 b=palo[x].b;
lower|=(src[((x&255)<<2)+2]>>cshiftr[2])<<cshiftl[2]; u16 color = (r>>cshiftr[0])<<cshiftl[0];
upper=(src[((x>>8)<<2)]>>cshiftr[0])<<cshiftl[0]; color |= (g>>cshiftr[1])<<cshiftl[1];
upper|=(src[((x>>8)<<2)+1]>>cshiftr[1])<<cshiftl[1]; color |= (b>>cshiftr[2])<<cshiftl[2];
upper|=(src[((x>>8)<<2)+2]>>cshiftr[2])<<cshiftl[2]; palettetranslate[256+x]=color;
}
palettetranslate[x]=lower|(upper<<16);
}
break; break;
case 3: case 3:
case 4: case 4:
for(x=0;x<256;x++) for(int x=0;x<256;x++)
{ {
uint32 r,g,b; uint32 r=src[x<<2];
uint32 g=src[(x<<2)+1];
if(!(highefx&FVB_BLUR)) uint32 b=src[(x<<2)+2];
{ palettetranslate[x]=(r<<cshiftl[0])|(g<<cshiftl[1])|(b<<cshiftl[2]);
r=src[x<<2];
g=src[(x<<2)+1];
b=src[(x<<2)+2];
palettetranslate[x]=(r<<cshiftl[0])|(g<<cshiftl[1])|(b<<cshiftl[2]);
}
else
{
for(y=0;y<256;y++)
{
r=src[x<<2]*(100-BLUR_RED);
g=src[(x<<2)+1]*(100-BLUR_GREEN);
b=src[(x<<2)+2]*(100-BLUR_BLUE);
r+=src[y<<2]*BLUR_RED;
g+=src[(y<<2)+1]*BLUR_GREEN;
b+=src[(y<<2)+2]*BLUR_BLUE;
r/=100;
g/=100;
b/=100;
if(r>255) r=255;
if(g>255) g=255;
if(b>255) b=255;
palettetranslate[x|(y<<8)]=(r<<cshiftl[0])|(g<<cshiftl[1])|(b<<cshiftl[2]);
}
}
} }
//full size deemph palette (breaks blur shit)
for(x=0;x<512;x++)
{
uint32 r,g,b;
r=palo[x].r; //full size deemph palette
g=palo[x].g; for(int x=0;x<512;x++)
b=palo[x].b; {
uint32 r=palo[x].r;
uint32 g=palo[x].g;
uint32 b=palo[x].b;
palettetranslate[256+x]=(r<<cshiftl[0])|(g<<cshiftl[1])|(b<<cshiftl[2]); palettetranslate[256+x]=(r<<cshiftl[0])|(g<<cshiftl[1])|(b<<cshiftl[2]);
} }
break; break;
} }
} }
@ -469,51 +398,24 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in
pinc=pitch-(xr*xscale); pinc=pitch-(xr*xscale);
if(xscale!=1 || yscale!=1) if(xscale!=1 || yscale!=1)
{ {
if(efx&FVB_SCANLINES) for(y=yr;y;y--,src+=256-xr)
{ {
for(y=yr;y;y--,src+=256-xr) int doo=yscale;
do
{ {
int doo=yscale-(yscale>>1); for(x=xr;x;x--,src++)
do
{ {
for(x=xr;x;x--,src++) int too=xscale;
do
{ {
int too=xscale; *(uint8 *)dest=*(uint8 *)src;
do dest++;
{ } while(--too);
*(uint8 *)dest=*(uint8 *)src; }
dest++; src-=xr;
} while(--too); dest+=pinc;
} } while(--doo);
src-=xr; src+=xr;
dest+=pinc;
} while(--doo);
//src-=xr*(yscale-(yscale>>1));
dest+=pitch*(yscale>>1);
src+=xr;
}
}
else
{
for(y=yr;y;y--,src+=256-xr)
{
int doo=yscale;
do
{
for(x=xr;x;x--,src++)
{
int too=xscale;
do
{
*(uint8 *)dest=*(uint8 *)src;
dest++;
} while(--too);
}
src-=xr;
dest+=pinc;
} while(--doo);
src+=xr;
}
} }
} }
else else
@ -802,163 +704,8 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
yscale=1; yscale=1;
} }
if(highefx&FVB_BLUR) // DONE
{/*
// highefx is hardset to 0 by this function call anyway
if(xscale!=1 || yscale!=1 || (highefx&FVB_SCANLINES)) // DONE
{
switch(Bpp)
{
case 4:
pinc=pitch-((xr*xscale)<<2);
for(y=yr;y;y--,src+=256-xr)
{
int doo=yscale;
if(highefx&FVB_SCANLINES)
doo-=yscale>>1;
do
{
uint8 last=0x00;
//if(doo == 1 && google) dest+=4;
for(x=xr;x;x--,src++)
{
int too=xscale;
do
{
*(uint32 *)dest=palettetranslate[*src|(last<<8)];
dest+=4;
} while(--too);
last=*src;
}
//if(doo == 1 && google) dest-=4;
src-=xr;
dest+=pinc;
} while(--doo);
src+=xr;
if(highefx&FVB_SCANLINES)
dest+=pitch*(yscale>>1);
}
break;
case 3:
pinc=pitch-((xr*xscale)*3);
for(y=yr;y;y--,src+=256-xr)
{
int doo=yscale;
if(highefx&FVB_SCANLINES)
doo-=yscale>>1;
do
{
uint8 last=0x00;
for(x=xr;x;x--,src++)
{
int too=xscale;
do
{
*(uint32 *)dest=palettetranslate[*src|(last<<8)];
dest+=3;
} while(--too);
last=*src;
}
src-=xr;
dest+=pinc;
} while(--doo);
src+=xr;
if(highefx&FVB_SCANLINES)
dest+=pitch*(yscale>>1);
}
break;
case 2:
pinc=pitch-((xr*xscale)<<1);
for(y=yr;y;y--,src+=256-xr)
{
int doo=yscale;
if(highefx& FVB_SCANLINES)
doo-=yscale>>1;
do
{
uint8 last=0x00;
for(x=xr;x;x--,src++)
{
int too=xscale;
do
{
*(uint16 *)dest=palettetranslate[*src|(last<<8)];
dest+=2;
} while(--too);
last=*src;
}
src-=xr;
dest+=pinc;
} while(--doo);
src+=xr;
if(highefx&FVB_SCANLINES)
dest+=pitch*(yscale>>1);
}
break;
}
}
else // No scaling, no scanlines, just blurring. - DONE
switch(Bpp)
{
case 4:
pinc=pitch-(xr<<2);
for(y=yr;y;y--,src+=256-xr)
{
uint8 last=0x00;
for(x=xr;x;x--)
{
*(uint32 *)dest=palettetranslate[*src|(last<<8)];
last=*src;
dest+=4;
src++;
}
dest+=pinc;
}
break;
case 3:
pinc=pitch-(xr+xr+xr);
for(y=yr;y;y--,src+=256-xr)
{
uint8 last=0x00;
for(x=xr;x;x--)
{
uint32 tmp=palettetranslate[*src|(last<<8)];
last=*src;
*(uint8 *)dest=tmp;
*((uint8 *)dest+1)=tmp>>8;
*((uint8 *)dest+2)=tmp>>16;
dest+=3;
src++;
}
dest+=pinc;
}
break;
case 2:
pinc=pitch-(xr<<1);
for(y=yr;y;y--,src+=256-xr)
{
uint8 last=0x00;
for(x=xr;x;x--)
{
*(uint16 *)dest=palettetranslate[*src|(last<<8)];
last=*src;
dest+=2;
src++;
}
dest+=pinc;
}
break;
}*/
}
else // No blur effects.
{ {
if(xscale!=1 || yscale!=1 || (highefx&FVB_SCANLINES)) if(xscale!=1 || yscale!=1)
{ {
switch(Bpp) switch(Bpp)
{ {
@ -978,8 +725,6 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
{ {
int doo=yscale; int doo=yscale;
if(highefx& FVB_SCANLINES)
doo-=yscale>>1;
do do
{ {
for(x=xr;x;x--,src++) for(x=xr;x;x--,src++)
@ -995,8 +740,6 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
dest+=pinc; dest+=pinc;
} while(--doo); } while(--doo);
src+=xr; src+=xr;
if(highefx&FVB_SCANLINES)
dest+=pitch*(yscale>>1);
} }
} }
break; break;
@ -1007,8 +750,6 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
{ {
int doo=yscale; int doo=yscale;
if(highefx& FVB_SCANLINES)
doo-=yscale>>1;
do do
{ {
for(x=xr;x;x--,src++) for(x=xr;x;x--,src++)
@ -1030,8 +771,6 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
dest+=pinc; dest+=pinc;
} while(--doo); } while(--doo);
src+=xr; src+=xr;
if(highefx&FVB_SCANLINES)
dest+=pitch*(yscale>>1);
} }
break; break;
@ -1042,8 +781,6 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
{ {
int doo=yscale; int doo=yscale;
if(highefx& FVB_SCANLINES)
doo-=yscale>>1;
do do
{ {
for(x=xr;x;x--,src++) for(x=xr;x;x--,src++)
@ -1059,8 +796,6 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
dest+=pinc; dest+=pinc;
} while(--doo); } while(--doo);
src+=xr; src+=xr;
if(highefx&FVB_SCANLINES)
dest+=pitch*(yscale>>1);
} }
break; break;
} }
@ -1088,7 +823,7 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
{ {
for(x=xr;x;x--) for(x=xr;x;x--)
{ {
uint32 tmp=palettetranslate[(uint32)*src]; uint32 tmp = ModernDeemphColorMap(src);
*(uint8 *)dest=tmp; *(uint8 *)dest=tmp;
*((uint8 *)dest+1)=tmp>>8; *((uint8 *)dest+1)=tmp>>8;
*((uint8 *)dest+2)=tmp>>16; *((uint8 *)dest+2)=tmp>>16;
@ -1100,14 +835,13 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
break; break;
case 2: case 2:
pinc=pitch-(xr<<1); pinc=pitch-(xr<<1);
for(y=yr;y;y--,src+=256-xr) for(y=yr;y;y--,src+=256-xr)
{ {
for(x=xr>>1;x;x--) for(x=xr;x;x--)
{ {
*(uint32 *)dest=palettetranslate[*(uint16 *)src]; *(uint16 *)dest = ModernDeemphColorMap(src);
dest+=4; dest+=2;
src+=2; src++;
} }
dest+=pinc; dest+=pinc;
} }

View File

@ -27,3 +27,6 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in
void Blit32to24(uint32 *src, uint8 *dest, int xr, int yr, int dpitch); void Blit32to24(uint32 *src, uint8 *dest, int xr, int yr, int dpitch);
void Blit32to16(uint32 *src, uint16 *dest, int xr, int yr, int dpitch, void Blit32to16(uint32 *src, uint16 *dest, int xr, int yr, int dpitch,
int shiftr[3], int shiftl[3]); int shiftr[3], int shiftl[3]);
u32 ModernDeemphColorMap(u8* src);

View File

@ -375,8 +375,8 @@ int SetVideoMode(int fs)
if(!GetBPP()) if(!GetBPP())
return 0; return 0;
//only 24 and 32bpp are supported now //only 16,24,32 bpp are supported now
if(bpp!=24 && bpp!=32) if(bpp!=16 && bpp!=24 && bpp!=32)
{ {
//ShowDDErr("Current bit depth not supported!"); //ShowDDErr("Current bit depth not supported!");
FCEU_printf("Current bit depth not supported!\n"); FCEU_printf("Current bit depth not supported!\n");

View File

@ -627,7 +627,6 @@ int SaveSnapshot(void)
dest++; dest++;
for(x=256;x;x--) for(x=256;x;x--)
{ {
extern u32 ModernDeemphColorMap(u8* src);
u32 color = ModernDeemphColorMap(tmp); u32 color = ModernDeemphColorMap(tmp);
*dest++=(color>>0x10)&0xFF; *dest++=(color>>0x10)&0xFF;
*dest++=(color>>0x08)&0xFF; *dest++=(color>>0x08)&0xFF;