From 72f5785c14cccad3976bb33680d926da39b50209 Mon Sep 17 00:00:00 2001 From: feos-tas Date: Sat, 9 May 2015 17:06:07 +0000 Subject: [PATCH] Video: implemented PAL subcarrier emulation as a filter, with options in Palette dialog. --- trunk/src/boards/sb-2000.cpp | 2 +- trunk/src/drivers/common/vidblit.cpp | 165 +++++++++++++++++++++++++-- trunk/src/drivers/win/palette.cpp | 50 ++++++-- trunk/src/drivers/win/res.rc | 18 ++- trunk/src/drivers/win/resource.h | 6 +- trunk/src/drivers/win/video.cpp | 31 +++-- 6 files changed, 240 insertions(+), 32 deletions(-) diff --git a/trunk/src/boards/sb-2000.cpp b/trunk/src/boards/sb-2000.cpp index 995135e8..c2ea454a 100644 --- a/trunk/src/boards/sb-2000.cpp +++ b/trunk/src/boards/sb-2000.cpp @@ -91,7 +91,7 @@ static DECLFR(UNLSB2000Read) { default: FCEU_printf("unk read: %04x\n",A); // break; -// return 0xff; + return 0xff; // needed to prevent C4715 warning? } } diff --git a/trunk/src/drivers/common/vidblit.cpp b/trunk/src/drivers/common/vidblit.cpp index 0f3fa7de..a7d5e99a 100644 --- a/trunk/src/drivers/common/vidblit.cpp +++ b/trunk/src/drivers/common/vidblit.cpp @@ -33,14 +33,20 @@ uint8 burst_phase = 0; static uint32 CBM[3]; static uint32 *palettetranslate=0; -static uint16 *specbuf=NULL; // 8bpp -> 16bpp, pre hq2x/hq3x -static uint32 *specbuf32bpp = NULL; // Buffer to hold output of hq2x/hq3x when converting to 16bpp and 24bpp +static uint16 *specbuf=NULL; // 8bpp -> 16bpp, pre hq2x/hq3x +static uint32 *specbuf32bpp = NULL; // Buffer to hold output of hq2x/hq3x when converting to 16bpp and 24bpp static int backBpp, backshiftr[3], backshiftl[3]; //static uint32 backmask[3]; -static uint8 *specbuf8bpp = NULL; // For 2xscale, 3xscale. -static uint8 *ntscblit = NULL; // For nes_ntsc -static uint32 *prescalebuf = NULL; // Prescale pointresizes to 2x-4x to allow less blur with hardware acceleration. +static uint8 *specbuf8bpp = NULL; // For 2xscale, 3xscale. +static uint8 *ntscblit = NULL; // For nes_ntsc +static uint32 *prescalebuf = NULL; // Prescale pointresizes to 2x-4x to allow less blur with hardware acceleration. +static uint32 *palrgb = NULL; // PAL filter buffer for lookup values of RGB with applied moir phases +static float *moire = NULL; +int palhue = 100; +bool palhdtv = 0; +bool palmonochrome = 0; +bool palupdate = 1; static int silt; @@ -60,6 +66,11 @@ static int highefx; */ #define FVB_BLUR 2 +static int Round(float value) +{ + return (int) floor(value + 0.5); +} + static void CalculateShift(uint32 *CBM, int *cshiftr, int *cshiftl) { int a,x,z,y; @@ -176,6 +187,12 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int int multi = specfilt - 4; // magic assuming prescales are specfilt >= 6 prescalebuf = (uint32 *)FCEU_dmalloc(256*240*multi*sizeof(uint32)); } + else if (specfilt == 9) + { + palrgb = (uint32 *)FCEU_dmalloc(265*16*sizeof(uint32)); + moire = (float *)FCEU_dmalloc( 16*sizeof(float)); + } + silt = specfilt; Bpp=b; highefx=efx; @@ -247,6 +264,10 @@ void KillBlitToHigh(void) free(prescalebuf); prescalebuf = NULL; } + if (palrgb) { + free(palrgb); + palrgb = NULL; + } } @@ -583,8 +604,8 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, if (Bpp == 4) // are other modes really needed? { int mult = silt - 4; // magic assuming prescales are silt >= 6 - uint32 *s = prescalebuf; // use 32-bit pointers ftw - uint32 *d = (uint32 *)destbackup; + uint32 *s = prescalebuf; + uint32 *d = (uint32 *)destbackup; // use 32-bit pointers ftw for (y=0; y 0xff) R = 0xff; else if (R < 0) R = 0; + if (G > 0xff) G = 0xff; else if (G < 0) G = 0; + if (B > 0xff) B = 0xff; else if (B < 0) B = 0; + + palrgb[i*16+j] = (B<<16)|(G<<8)|R; + } + } + palupdate = 0; + } + + if (Bpp == 4) { + uint32 *d = (uint32 *)dest; + uint8 xsub = 0; + uint8 xabs = 0; + uint8 index = 0; + uint32 color; + + for (y=0; y= 4 && winspecial <= 5) specmul = 3; - else if(winspecial >= 6) + else if(winspecial >= 6 && winspecial <=8) specmul = winspecial - 4; // magic assuming prescales are winspecial >= 6 + else if(winspecial == 9) + specmul = 3; else specmul = 1; @@ -374,7 +377,7 @@ int SetVideoMode(int fs) ddsdback.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; ddsdback.dwWidth=256 * specmul; - ddsdback.dwHeight=FSettings.TotalScanlines() * specmul; + ddsdback.dwHeight=FSettings.TotalScanlines() * ((winspecial == 9) ? 1 : specmul); if (directDrawModeWindowed == DIRECTDRAW_MODE_SURFACE_IN_RAM) // create the buffer in system memory @@ -437,8 +440,10 @@ int SetVideoMode(int fs) specmul = 2; else if(vmodes[0].special >= 4 && vmodes[0].special <= 5) specmul = 3; - else if(vmodes[0].special >= 6) + else if(vmodes[0].special >= 6 && vmodes[0].special <= 8) specmul = vmodes[0].special - 4; // magic assuming prescales are vmodes[0].special >= 6 + else if(vmodes[0].special == 9) + specmul = 3; else specmul = 1; } @@ -467,7 +472,7 @@ int SetVideoMode(int fs) ddsdback.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; ddsdback.dwWidth=256 * specmul; //vmodes[vmod].srect.right; - ddsdback.dwHeight=FSettings.TotalScanlines() * specmul; //vmodes[vmod].srect.bottom; + ddsdback.dwHeight=FSettings.TotalScanlines() * ((vmodes[0].special == 9) ? 1 : specmul); //vmodes[vmod].srect.bottom; if (directDrawModeFullscreen == DIRECTDRAW_MODE_SURFACE_IN_RAM) // create the buffer in system memory @@ -603,16 +608,19 @@ static void BlitScreenWindow(unsigned char *XBuf) specialmul = 2; else if(winspecial >= 4 && winspecial <= 5) specialmul = 3; - else if(winspecial >= 6) + else if(winspecial >= 6 && winspecial <= 8) specialmul = winspecial - 4; // magic assuming prescales are winspecial >= 6 + else if(winspecial == 9) + specialmul = 3; else specialmul = 1; srect.top=srect.left=0; srect.right=VNSWID * specialmul; - srect.bottom=FSettings.TotalScanlines() * specialmul; + srect.bottom=FSettings.TotalScanlines() * ((winspecial == 9) ? 1 : specialmul); if(PaletteChanged==1) { + palupdate = 1; FixPaletteHi(); PaletteChanged=0; } @@ -743,8 +751,10 @@ static void BlitScreenFull(uint8 *XBuf) specmul = 2; else if(vmodes[0].special >= 4 && vmodes[0].special <= 5) specmul = 3; - else if(vmodes[0].special >= 6) + else if(vmodes[0].special >= 6 && vmodes[0].special <= 8) specmul = vmodes[0].special - 4; // magic assuming prescales are vmodes[0].special >= 6 + else if(vmodes[0].special == 9) + specmul = 3; else specmul = 1; @@ -757,6 +767,7 @@ static void BlitScreenFull(uint8 *XBuf) if(PaletteChanged==1) { + palupdate = 1; if(bpp>=16) FixPaletteHi(); else @@ -786,7 +797,7 @@ static void BlitScreenFull(uint8 *XBuf) srect.top=0; srect.left=0; srect.right=VNSWID * specmul; - srect.bottom=FSettings.TotalScanlines() * specmul; + srect.bottom=FSettings.TotalScanlines() * ((vmodes[0].special == 9) ? 1 : specmul); //if(vmodes[vmod].flags&VMDF_STRFS) //{ @@ -1266,9 +1277,9 @@ BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara //CheckRadioButton(hwndDlg,IDC_RADIO_SCALE,IDC_RADIO_STRETCH,(vmodes[0].flags&VMDF_STRFS)?IDC_RADIO_STRETCH:IDC_RADIO_SCALE); // -Video Modes Tag- - char *str[]={"","hq2x","Scale2x","NTSC 2x","hq3x","Scale3x","Prescale2x","Prescale3x","Prescale4x"}; + char *str[]={"","hq2x","Scale2x","NTSC 2x","hq3x","Scale3x","Prescale2x","Prescale3x","Prescale4x","PAL"}; int x; - for(x=0;x<9;x++) + for(x=0;x<10;x++) { SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_FS,CB_ADDSTRING,0,(LPARAM)(LPSTR)str[x]); SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_WIN,CB_ADDSTRING,0,(LPARAM)(LPSTR)str[x]);