From efa98aafe31cace711f9516c7f4fa1631e3f9107 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 22 Nov 2014 01:29:32 +0000 Subject: [PATCH] revert r3037 (video-related 'refactors'). seemed to go ok, didnt touch as much stuff as the input-related stuff) --- trunk/src/driver.h | 6 - trunk/src/drivers/win/aviout.cpp | 3 +- trunk/src/drivers/win/config.cpp | 30 +- trunk/src/drivers/win/config.h | 4 - trunk/src/drivers/win/input.cpp | 16 +- trunk/src/drivers/win/input.h | 2 +- trunk/src/drivers/win/main.cpp | 20 +- trunk/src/drivers/win/main.h | 5 +- trunk/src/drivers/win/taseditor.cpp | 3 +- .../drivers/win/taseditor/popup_display.cpp | 4 +- trunk/src/drivers/win/texthook.cpp | 1 + trunk/src/drivers/win/video.cpp | 1942 +++++++++-------- trunk/src/drivers/win/video.h | 125 +- trunk/src/drivers/win/window.cpp | 46 +- trunk/src/drivers/win/window.h | 4 - trunk/src/input.cpp | 9 +- trunk/src/state.cpp | 5 - trunk/src/utils/bitflags.h | 10 - 18 files changed, 1200 insertions(+), 1035 deletions(-) delete mode 100644 trunk/src/utils/bitflags.h diff --git a/trunk/src/driver.h b/trunk/src/driver.h index 84b4af68..d7474aa5 100644 --- a/trunk/src/driver.h +++ b/trunk/src/driver.h @@ -25,9 +25,6 @@ void FCEU_printf(char *format, ...); #define FCEUI_printf FCEU_printf //Video interface -// FIXME: these functions are declared in windows video driver header, but not in linux video driver header; -// eventually both platform video drivers should be brought to same set of functions and single shared header, -// which then can be included where access to video driver functions is needed instead of driver.h void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b); void FCEUD_GetPalette(uint8 i,uint8 *r, uint8 *g, uint8 *b); @@ -262,9 +259,6 @@ void FCEUI_SetEmulationPaused(int val); void FCEUI_ToggleEmulationPause(); //indicates whether input aids should be drawn (such as crosshairs, etc; usually in fullscreen mode) -// FIXME: this function is already declared in both platform video driver headers; -// eventually both platform video drivers should be brought to same set of functions and single shared header, -// which then can be included where access to video driver functions is needed instead of driver.h bool FCEUD_ShouldDrawInputAids(); ///called when the emulator closes a game diff --git a/trunk/src/drivers/win/aviout.cpp b/trunk/src/drivers/win/aviout.cpp index 705449a5..e2a6e31d 100644 --- a/trunk/src/drivers/win/aviout.cpp +++ b/trunk/src/drivers/win/aviout.cpp @@ -4,8 +4,8 @@ #include "common.h" #include "fceu.h" -#include "drivers/win/video.h" +extern PALETTEENTRY *color_palette; //extern WAVEFORMATEX wf; //extern int soundo; @@ -292,7 +292,6 @@ static void do_video_conversion(const unsigned char* buffer) // memset(avi_file->convert_buffer, 0, VIDEO_WIDTH*(avi_file->end_scanline-avi_file->start_scanline)*3); buffer += avi_file->start_scanline * VIDEO_WIDTH; - PALETTEENTRY* color_palette = GetPalette(); for(int y=avi_file->start_scanline; yend_scanline; ++y) { diff --git a/trunk/src/drivers/win/config.cpp b/trunk/src/drivers/win/config.cpp index 17198463..90548920 100644 --- a/trunk/src/drivers/win/config.cpp +++ b/trunk/src/drivers/win/config.cpp @@ -185,8 +185,8 @@ static CFGSTRUCT fceuconfig[] = NAC("palyo",pal_emulation), NAC("genie",genie), - NAC("fs",_FIXME_getFullscreenVar()), - NAC("vgamode",_FIXME_getVModeIdxVar()), + NAC("fs",fullscreen), + NAC("vgamode",vmod), NAC("sound",soundo), NAC("sicon",status_icon), @@ -206,8 +206,8 @@ static CFGSTRUCT fceuconfig[] = NACS("odavi",directory_names[12]), NACS("odbase",directory_names[13]), - NAC("winspecial", _FIXME_getFilterModeWindowedIdxVar()), - NAC("NTSCwinspecial", _FIXME_getFilterOptionVar()), + AC(winspecial), + AC(NTSCwinspecial), AC(winsizemulx), AC(winsizemuly), AC(tvAspectX), @@ -231,23 +231,23 @@ static CFGSTRUCT fceuconfig[] = NACA("InputType",InputType), - NAC("vmcx",_FIXME_getCustomVideoModeVar().width), - NAC("vmcy",_FIXME_getCustomVideoModeVar().height), - NAC("vmcb",_FIXME_getCustomVideoModeVar().bpp), - NAC("vmcf",_FIXME_getCustomVideoModeVar().flags), - NAC("vmcxs",_FIXME_getCustomVideoModeVar().xscale), - NAC("vmcys",_FIXME_getCustomVideoModeVar().yscale), - NAC("vmspecial",_FIXME_getCustomVideoModeVar().filter), + NAC("vmcx",vmodes[0].x), + NAC("vmcy",vmodes[0].y), + NAC("vmcb",vmodes[0].bpp), + NAC("vmcf",vmodes[0].flags), + NAC("vmcxs",vmodes[0].xscale), + NAC("vmcys",vmodes[0].yscale), + NAC("vmspecial",vmodes[0].special), NAC("srendline",srendlinen), NAC("erendline",erendlinen), NAC("srendlinep",srendlinep), NAC("erendlinep",erendlinep), - NAC("directDrawModeWindowed", _FIXME_getDDrawModeWindowedVar()), - NAC("directDrawModeFullscreen", _FIXME_getDDrawModeFullscreenVar()), - NAC("winsync", _FIXME_getWindowedSyncModeIdxVar()), - NAC("988fssync",_FIXME_getFullscreenSyncModeIdxVar()), + AC(directDrawModeWindowed), + AC(directDrawModeFullscreen), + AC(winsync), + NAC("988fssync",fssync), AC(ismaximized), AC(maxconbskip), diff --git a/trunk/src/drivers/win/config.h b/trunk/src/drivers/win/config.h index 6606f695..1b163101 100644 --- a/trunk/src/drivers/win/config.h +++ b/trunk/src/drivers/win/config.h @@ -1,7 +1,3 @@ -// FIXME for Windows, make use of Config class the way linux version does -// old config registers variables by placing their addresses into static array, which makes -// many modules expose their internal vars and pollute globals; there is also no way to know when a -// setting was changed by it, which spawns auxillary functions intended to push new values through void SaveConfig(const char *filename); void LoadConfig(const char *filename); diff --git a/trunk/src/drivers/win/input.cpp b/trunk/src/drivers/win/input.cpp index 43848db9..deb2bd78 100644 --- a/trunk/src/drivers/win/input.cpp +++ b/trunk/src/drivers/win/input.cpp @@ -28,7 +28,6 @@ #include #include -#include "video.h" #include "input.h" #include "keyboard.h" #include "joystick.h" @@ -43,8 +42,9 @@ LPDIRECTINPUT7 lpDI=0; void InitInputPorts(bool fourscore); -VSYNCMODE tempwinsync = SYNCMODE_NONE; //Temp variable used by turbo to turn of sync settings +int tempwinsync = 0; //Temp variable used by turbo to turn of sync settings int tempsoundquality = 0; //Temp variable used by turbo to turn of sound quality settings +extern int winsync; extern int soundquality; extern bool replaceP2StartWithMicrophone; //UsrInputType[] is user-specified. InputType[] is current @@ -1575,8 +1575,8 @@ int FCEUD_TestCommandState(int c) void FCEUD_TurboOn (void) { - tempwinsync = GetWindowedSyncModeIdx(); //Store wndSyncMode setting - SetWindowedSyncModeIdx(SYNCMODE_NONE); //turn off wndSyncMode for turbo (so that turbo can function even with VBlank sync methods + tempwinsync = winsync; //Store winsync setting + winsync = 0; //turn off winsync for turbo (so that turbo can function even with VBlank sync methods tempsoundquality = soundquality; //Store sound quality settings FCEUI_SetSoundQuality(0); //Turn sound quality to low turbo = true; @@ -1584,7 +1584,7 @@ void FCEUD_TurboOn (void) } void FCEUD_TurboOff (void) { - SetWindowedSyncModeIdx(tempwinsync); //Restore wndSyncMode setting + winsync = tempwinsync; //Restore winsync setting soundquality = tempsoundquality; //Restore sound quality settings FCEUI_SetSoundQuality(soundquality); turbo = false; @@ -1593,15 +1593,15 @@ void FCEUD_TurboOff (void) void FCEUD_TurboToggle(void) { if (turbo) { - SetWindowedSyncModeIdx(tempwinsync); //If turbo was on, restore wndSyncMode + winsync = tempwinsync; //If turbo was on, restore winsync soundquality = tempsoundquality; //and restore sound quality setting FCEUI_SetSoundQuality(soundquality); } else { - tempwinsync = GetWindowedSyncModeIdx(); //Store video sync settings + tempwinsync = winsync; //Store video sync settings tempsoundquality = soundquality; //Store sound quality settings - SetWindowedSyncModeIdx(SYNCMODE_NONE); //If turbo was off, turn off wndSyncMode (so that turbo can function even with VBlank sync methods + winsync = 0; //If turbo was off, turn off winsync (so that turbo can function even with VBlank sync methods FCEUI_SetSoundQuality(0); //Set sound quality to low } diff --git a/trunk/src/drivers/win/input.h b/trunk/src/drivers/win/input.h index b60b1ddf..015eec49 100644 --- a/trunk/src/drivers/win/input.h +++ b/trunk/src/drivers/win/input.h @@ -19,7 +19,7 @@ int InitDInput(void); void CreateInputStuff(void); void InitInputStuff(void); void DestroyInput(void); -void InputScreenChanged(int fs); // FIXME defined nowhere used nowhere +void InputScreenChanged(int fs); void SetAutoFireDesynch(int DesynchOn); int GetAutoFireDesynch(); uint32 GetGamepadPressedImmediate(); diff --git a/trunk/src/drivers/win/main.cpp b/trunk/src/drivers/win/main.cpp index f00427be..1814d42a 100644 --- a/trunk/src/drivers/win/main.cpp +++ b/trunk/src/drivers/win/main.cpp @@ -43,7 +43,6 @@ #include "../../movie.h" #include "../../fceulua.h" -#include "window.h" #include "archive.h" #include "input.h" #include "netplay.h" @@ -110,6 +109,7 @@ extern bool taseditorEnableAcceleratorKeys; // External functions extern std::string cfgFile; //Contains the filename of the config file used. extern bool turbo; //Is game in turbo mode? +void ResetVideo(void); void ShowCursorAbs(int w); void HideFWindow(int h); void FixWXY(int pref, bool shift_held); @@ -167,12 +167,15 @@ int ffbskip = 32; //Blit skips per blit when FF-ing HINSTANCE fceu_hInstance; HACCEL fceu_hAccel; +HRESULT ddrval; + static char TempArray[2048]; static int exiting = 0; static volatile int moocow = 0; int windowedfailed = 0; +int fullscreen = 0; //Windows files only, variable that keeps track of fullscreen status static volatile int _userpause = 0; //mbg merge 7/18/06 changed tasbuild was using this only in a couple of places @@ -387,12 +390,12 @@ void FCEUD_PrintError(const char *errormsg) { AddLogText(errormsg, 1); - if (GetIsFullscreen() && (eoptions & EO_HIDEMOUSE)) + if (fullscreen && (eoptions & EO_HIDEMOUSE)) ShowCursorAbs(1); MessageBox(0, errormsg, FCEU_NAME" Error", MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST); - if (GetIsFullscreen() && (eoptions & EO_HIDEMOUSE)) + if (fullscreen && (eoptions & EO_HIDEMOUSE)) ShowCursorAbs(0); } @@ -488,7 +491,7 @@ int DriverInitialize() if(soundo) soundo = InitSound(); - InitVideoDriver(); + SetVideoMode(fullscreen); InitInputStuff(); /* Initialize DInput interfaces. */ return 1; @@ -503,7 +506,7 @@ static void DriverKill(void) DestroyInput(); - ShutdownVideoDriver(); + ResetVideo(); if(soundo) { @@ -646,6 +649,7 @@ int main(int argc,char *argv[]) { FCEUI_SetGameGenie(genie!=0); + fullscreen = !!fullscreen; soundo = !!soundo; frame_display = !!frame_display; allowUDLR = !!allowUDLR; @@ -683,7 +687,7 @@ int main(int argc,char *argv[]) if(!t) { - SetIsFullscreen(false); + fullscreen=0; } CreateMainWindow(); @@ -915,10 +919,8 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) } //blit the framebuffer - if(XBuf) { - xbsave = XBuf; + if(XBuf) FCEUD_BlitScreen(XBuf); - } //update debugging displays _updateWindow(); diff --git a/trunk/src/drivers/win/main.h b/trunk/src/drivers/win/main.h index 4c23c336..7b71077e 100644 --- a/trunk/src/drivers/win/main.h +++ b/trunk/src/drivers/win/main.h @@ -34,6 +34,7 @@ extern int maxconbskip; extern int ffbskip; extern void LoadNewGamey(HWND hParent, const char *initialdir); extern void CloseGame(); +extern int fullscreen; //Windows files only, keeps track of fullscreen status // Flag that indicates whether Game Genie is enabled or not. extern int genie; @@ -54,6 +55,8 @@ extern int AFon; extern int AFoff; extern int AutoFireOffset; +extern int vmod; + extern char* directory_names[14]; char *GetRomName(); //Checks if rom is loaded, if so, outputs the Rom name with no directory path or file extension @@ -120,13 +123,13 @@ extern int soundo; extern int eoptions; extern int soundoptions; extern uint8 *xbsave; +extern HRESULT ddrval; extern int windowedfailed; extern uint32 goptions; void DoFCEUExit(); void ShowAboutBox(); int BlockingCheck(); -void UpdateRendBounds(void); void DoPriority(); void RemoveDirs(); void CreateDirs(); diff --git a/trunk/src/drivers/win/taseditor.cpp b/trunk/src/drivers/win/taseditor.cpp index c1a645b3..6104e3af 100644 --- a/trunk/src/drivers/win/taseditor.cpp +++ b/trunk/src/drivers/win/taseditor.cpp @@ -22,7 +22,6 @@ Main - Main gate between emulator and Taseditor #include "main.h" // for GetRomName #include "taseditor.h" #include "window.h" -#include "video.h" #include "../../input.h" #include "../keyboard.h" #include "../joystick.h" @@ -57,6 +56,7 @@ extern int joysticksPerFrame[INPUT_TYPES_TOTAL]; extern bool turbo; extern int pal_emulation; extern int newppu; +extern void PushCurrentVideoSettings(); extern void RefreshThrottleFPS(); extern bool LoadFM2(MovieData& movieData, EMUFILE* fp, int size, bool stopAfterHeader); // temporarily saved FCEUX config @@ -883,6 +883,7 @@ void applyMovieInputConfig() pal_emulation = currMovieData.palFlag; FCEUI_SetVidSystem(pal_emulation); RefreshThrottleFPS(); + PushCurrentVideoSettings(); // update PPU type newppu = currMovieData.PPUflag; SetMainWindowText(); diff --git a/trunk/src/drivers/win/taseditor/popup_display.cpp b/trunk/src/drivers/win/taseditor/popup_display.cpp index c4528db4..ffa7c4b3 100644 --- a/trunk/src/drivers/win/taseditor/popup_display.cpp +++ b/trunk/src/drivers/win/taseditor/popup_display.cpp @@ -19,8 +19,6 @@ Popup display - Manager of popup windows #include "taseditor_project.h" #include "zlib.h" -#include "drivers/win/video.h" - extern TASEDITOR_CONFIG taseditorConfig; extern TASEDITOR_WINDOW taseditorWindow; extern BOOKMARKS bookmarks; @@ -93,7 +91,7 @@ void POPUP_DISPLAY::init() { free(); // fill scr_bmp palette with current palette colors - PALETTEENTRY* color_palette = GetPalette(); + extern PALETTEENTRY *color_palette; for (int i = 0; i < 256; ++i) { screenshotBmi->bmiColors[i].rgbRed = color_palette[i].peRed; diff --git a/trunk/src/drivers/win/texthook.cpp b/trunk/src/drivers/win/texthook.cpp index 748aa9f1..934e946c 100644 --- a/trunk/src/drivers/win/texthook.cpp +++ b/trunk/src/drivers/win/texthook.cpp @@ -46,6 +46,7 @@ char *textToTrans; // buffer to hold the text that needs translating char *transText; //holds the translated text +extern void FCEUD_BlitScreen(uint8 *XBuf); //needed for pause, not sure where this is defined... //adelikat merge 7/1/08 - had to add these extern variables //------------------------------ extern uint8 PALRAM[0x20]; diff --git a/trunk/src/drivers/win/video.cpp b/trunk/src/drivers/win/video.cpp index 8ab4626f..14ca1aed 100644 --- a/trunk/src/drivers/win/video.cpp +++ b/trunk/src/drivers/win/video.cpp @@ -19,9 +19,6 @@ */ #include "video.h" -#include "ddraw.h" -#include "main.h" -#include "window.h" #include "../../drawing.h" #include "gui.h" #include "../../fceu.h" @@ -29,893 +26,1179 @@ #include "input.h" #include "mapinput.h" #include -#include "utils/bitflags.h" +extern bool fullscreenByDoubleclick; -static bool dispModeWasChanged = false; // tells if driver should reset display mode on shutdown; set on fullscreen -static DWORD colorsBitMask[3]; // masks to extract components from color data with different bpp +static int RecalcCustom(void); +void InputScreenChanged(int fs); +void UpdateRendBounds(); -static int bpp; // bits per pixel -static bool wipeSurface = true; // tells mode/resolution was changed and we should wipe surface +static DDCAPS caps; +static int mustrestore=0; +static DWORD CBM[3]; -// Surface modes selected for windowed and fullscreen -static DIRECTDRAW_MODE directDrawModeWindowed = DIRECTDRAW_MODE_SOFTWARE; -static DIRECTDRAW_MODE directDrawModeFullscreen = DIRECTDRAW_MODE_FULL; +static int bpp; +static int vflags; +static int veflags; -// vertical sync modes for windowed and fullscreen -static VSYNCMODE idxFullscreenSyncMode = SYNCMODE_NONE; -static VSYNCMODE idxWindowedSyncMode = SYNCMODE_NONE; - // apparently sync settings are ignored during netplay +int directDrawModeWindowed = DIRECTDRAW_MODE_SOFTWARE; +int directDrawModeFullscreen = DIRECTDRAW_MODE_FULL; -static VFILTER idxFilterModeWindowed = FILTER_NONE; // filter selected for windowed mode - // fullscreen mode filter index is taken from active VideoMode struct -static int ntscFilterOption = 0; // special NTSC filter effect - // never changed in code; might be loaded from config I guess -static int vmodeIdx; // current video mode index - // never changed in code, can be loaded from config +int fssync=0; +int winsync=0; -static VideoMode videoModes[11] = +int winspecial = 0; +int NTSCwinspecial = 0; +int vmod = 0; + +vmdef vmodes[11] = { - {0,0,0,VIDEOMODEFLAG_DXBLT|VIDEOMODEFLAG_STRFS,1,1,0}, // Custom - set to current resolution at the first launch + {0,0,0,VMDF_DXBLT|VMDF_STRFS,1,1,0}, // Custom - set to current resolution at the first launch {320,240,8,0,1,1,0}, //1 {512,384,8,0,1,1,0}, //2 {640,480,32,0,1,1,0}, //3 {640,480,32,0,1,1,0}, //4 {640,480,32,0,1,1,0}, //5 - {640,480,32,VIDEOMODEFLAG_DXBLT,2,2,0}, //6 - {1024,768,32,VIDEOMODEFLAG_DXBLT,4,3,0}, //7 - {1280,1024,32,VIDEOMODEFLAG_DXBLT,5,4,0}, //8 - {1600,1200,32,VIDEOMODEFLAG_DXBLT,6,5,0}, //9 - {800,600,32,VIDEOMODEFLAG_DXBLT|VIDEOMODEFLAG_STRFS,0,0} //10 + {640,480,32,VMDF_DXBLT,2,2,0}, //6 + {1024,768,32,VMDF_DXBLT,4,3,0}, //7 + {1280,1024,32,VMDF_DXBLT,5,4,0}, //8 + {1600,1200,32,VMDF_DXBLT,6,5,0}, //9 + {800,600,32,VMDF_DXBLT|VMDF_STRFS,0,0} //10 }; -extern uint8 PALRAM[0x20]; // NES palette ram +extern uint8 PALRAM[0x20]; -static PALETTEENTRY color_palette[256]; // driver palette +PALETTEENTRY *color_palette; -static bool updateDDPalette = true; // flag to update DirectDraw palette +static int PaletteChanged=0; -static LPDIRECTDRAW7 ddraw7Handle = 0; // our working DirectDraw -static LPDIRECTDRAWCLIPPER ddClipperHandle = 0; // DD clipper to keep image within window boundaries -static LPDIRECTDRAWPALETTE ddPaletteHandle = 0; // DD palette +LPDIRECTDRAWCLIPPER lpClipper=0; +LPDIRECTDRAW lpDD=0; +LPDIRECTDRAW7 lpDD7=0; +LPDIRECTDRAWPALETTE lpddpal = 0; -// surface descriptions -static DDSURFACEDESC2 surfaceDescScreen; -static DDSURFACEDESC2 surfaceDescOffscreen; +DDSURFACEDESC2 ddsd; +DDSURFACEDESC2 ddsdback; -// surfaces -static LPDIRECTDRAWSURFACE7 lpScreenSurface=0; // screen surface -static LPDIRECTDRAWSURFACE7 lpBackBuffer=0; // back buffer of screen surface - // in doublebuffer mode image ends up here, then surface is flipped -static LPDIRECTDRAWSURFACE7 lpOffscreenSurface=0; // offscreen surface +LPDIRECTDRAWSURFACE7 lpDDSPrimary=0; +LPDIRECTDRAWSURFACE7 lpDDSDBack=0; +LPDIRECTDRAWSURFACE7 lpDDSBack=0; -static RECT activeRect = {0}; // active area of the screen where image is displayed and mouse input is processed +DDBLTFX blitfx = { sizeof(DDBLTFX) }; -static bool fullscreenDesired = false; // 'Desired' fullscreen status -static bool fullscreenActual = false; // Internal 'actual' fullscreen status +RECT bestfitRect = {0}; -static int filterScaleMultiplier[6] = {1,2,2,2,3,3}; // scale multipliers for defined filters +#define RELEASE(x) if(x) { x->Release(); x = 0; } - -static void RestoreLostScreenSurface() +static void ShowDDErr(char *s) { - if(lpScreenSurface) { - IDirectDrawSurface7_Restore(lpScreenSurface); - wipeSurface = true; - } + char tempo[512]; + sprintf(tempo,"DirectDraw: %s",s); + FCEUD_PrintError(tempo); } -static void RestoreLostOffscreenSurface() +int RestoreDD(int w) { - if(lpOffscreenSurface) { - IDirectDrawSurface7_Restore(lpOffscreenSurface); - wipeSurface = true; - } -} - -static bool CreateDDraw() -{ - ShutdownVideoDriver(); - - HRESULT status; + if (w == 1) // lpDDSBack { - GUID FAR *guid; - if ((GetIsFullscreen() && directDrawModeFullscreen == DIRECTDRAW_MODE_SOFTWARE) || (!GetIsFullscreen() && directDrawModeWindowed == DIRECTDRAW_MODE_SOFTWARE)) - guid = (GUID FAR *)DDCREATE_EMULATIONONLY; + if(!lpDDSBack) return 0; + if(IDirectDrawSurface7_Restore(lpDDSBack)!=DD_OK) return 0; + } else // 0 means lpDDSPrimary + { + if(!lpDDSPrimary) return 0; + if(IDirectDrawSurface7_Restore(lpDDSPrimary)!=DD_OK) return 0; + } + veflags|=1; + return 1; +} + +void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b) +{ + if (force_grayscale) + { + // convert the palette entry to grayscale + int gray = ((float)r * 0.299 + (float)g * 0.587 + (float)b * 0.114); + color_palette[index].peRed = gray; + color_palette[index].peGreen = gray; + color_palette[index].peBlue = gray; + } else + { + color_palette[index].peRed = r; + color_palette[index].peGreen = g; + color_palette[index].peBlue = b; + } + PaletteChanged=1; +} + +void FCEUD_GetPalette(unsigned char i, unsigned char *r, unsigned char *g, unsigned char *b) +{ + *r=color_palette[i].peRed; + *g=color_palette[i].peGreen; + *b=color_palette[i].peBlue; +} + +static bool firstInitialize = true; +static int InitializeDDraw(int fs) +{ + //only init the palette the first time through + if (firstInitialize) + { + firstInitialize = false; + color_palette = (PALETTEENTRY*)malloc(256 * sizeof(PALETTEENTRY)); + } + + if ((fs && directDrawModeFullscreen == DIRECTDRAW_MODE_SOFTWARE) || (!fs && directDrawModeWindowed == DIRECTDRAW_MODE_SOFTWARE)) + ddrval = DirectDrawCreate((GUID FAR *)DDCREATE_EMULATIONONLY, &lpDD, NULL); else - guid = NULL; + ddrval = DirectDrawCreate(NULL, &lpDD, NULL); - LPDIRECTDRAW ddrawHandle; - status = DirectDrawCreate(guid, &ddrawHandle, NULL); - if (status != DD_OK) + if (ddrval != DD_OK) { + //ShowDDErr("Error creating DirectDraw object."); FCEU_printf("Error creating DirectDraw object.\n"); - return false; + return 0; } - status = IDirectDraw_QueryInterface(ddrawHandle,IID_IDirectDraw7,(LPVOID *)&ddraw7Handle); - IDirectDraw_Release(ddrawHandle); - if (status != DD_OK) + //mbg merge 7/17/06 changed: + ddrval = IDirectDraw_QueryInterface(lpDD,IID_IDirectDraw7,(LPVOID *)&lpDD7); + //ddrval = IDirectDraw_QueryInterface(lpDD,&IID_IDirectDraw7,(LPVOID *)&lpDD7); + IDirectDraw_Release(lpDD); + + if (ddrval != DD_OK) { + //ShowDDErr("Error querying interface."); FCEU_printf("Error querying interface.\n"); - return false; - } + return 0; } - DDCAPS caps; - memset(&caps,0,sizeof(caps)); caps.dwSize=sizeof(caps); - if(IDirectDraw7_GetCaps(ddraw7Handle,&caps,0)!=DD_OK) + if(IDirectDraw7_GetCaps(lpDD7,&caps,0)!=DD_OK) { + //ShowDDErr("Error getting capabilities."); FCEU_printf("Error getting capabilities.\n"); - return false; + return 0; } - - return true; + return 1; } -static bool InitBPPStuff(bool fullscreen) +static int GetBPP(void) { DDPIXELFORMAT ddpix; + memset(&ddpix,0,sizeof(ddpix)); ddpix.dwSize=sizeof(ddpix); - HRESULT status = IDirectDrawSurface7_GetPixelFormat(lpScreenSurface,&ddpix); - if (status == DD_OK) { - if (FL_TEST(ddpix.dwFlags, DDPF_RGB)) { - bpp=ddpix.dwRGBBitCount; - colorsBitMask[0]=ddpix.dwRBitMask; - colorsBitMask[1]=ddpix.dwGBitMask; - colorsBitMask[2]=ddpix.dwBBitMask; - - if (bpp==15) bpp=16; - - if (!fullscreen || (bpp==16 || bpp==24 || bpp==32)) { // in fullscreen check for supported bitcount - if (bpp >= 16) - { - int filterIdx = (fullscreen)? videoModes[vmodeIdx].filter:idxFilterModeWindowed; - int ntscFiltOpt = 0; - if (filterIdx == FILTER_NTSC2X) { - ntscFiltOpt = ntscFilterOption; - } - - InitBlitToHigh(bpp/8, - colorsBitMask[0], - colorsBitMask[1], - colorsBitMask[2], - 0, - filterIdx, - ntscFiltOpt); - - return true; - } - else if (bpp==8) - { - HRESULT status = IDirectDraw7_CreatePalette( ddraw7Handle, - DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_INITIALIZE, - color_palette, - &ddPaletteHandle, - NULL); - if (status == DD_OK) { - status = IDirectDrawSurface7_SetPalette(lpScreenSurface, ddPaletteHandle); - if (status == DD_OK) { - return true; - } - else { - FCEU_printf("Error setting palette object.\n"); - } - } - else { - FCEU_printf("Error creating palette object.\n"); - } - } - } // if(supported bpp) - } - else { - FCEU_printf("RGB data not valid.\n"); - } - } - else { + ddrval=IDirectDrawSurface7_GetPixelFormat(lpDDSPrimary,&ddpix); + if (ddrval != DD_OK) + { + //ShowDDErr("Error getting primary surface pixel format."); FCEU_printf("Error getting primary surface pixel format.\n"); + return 0; } - return false; + if(ddpix.dwFlags&DDPF_RGB) + { + //mbg merge 7/17/06 removed silly dummy union stuff now that we have c++ + bpp=ddpix.dwRGBBitCount; + CBM[0]=ddpix.dwRBitMask; + CBM[1]=ddpix.dwGBitMask; + CBM[2]=ddpix.dwBBitMask; + } + else + { + //ShowDDErr("RGB data not valid."); + FCEU_printf("RGB data not valid.\n"); + return 0; + } + if(bpp==15) bpp=16; + + return 1; } -void OnWindowSizeChange(int wndWidth, int wndHeight) +static int InitBPPStuff(int fs) { - if (!ddraw7Handle) + + int specfilteropt = 0; + switch (winspecial) + { + case 3: + specfilteropt = NTSCwinspecial; + break; + } + + if(bpp >= 16) + { + InitBlitToHigh(bpp >> 3, CBM[0], CBM[1], CBM[2], 0, fs?vmodes[vmod].special:winspecial,specfilteropt); + } + else if(bpp==8) + { + ddrval=IDirectDraw7_CreatePalette( lpDD7, DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_INITIALIZE,color_palette,&lpddpal,NULL); + if (ddrval != DD_OK) + { + //ShowDDErr("Error creating palette object."); + FCEU_printf("Error creating palette object.\n"); + return 0; + } + ddrval=IDirectDrawSurface7_SetPalette(lpDDSPrimary, lpddpal); + if (ddrval != DD_OK) + { + //ShowDDErr("Error setting palette object."); + FCEU_printf("Error setting palette object.\n"); + return 0; + } + } + return 1; +} + +void recalculateBestFitRect(int width, int height) +{ + if (!lpDD7) return; // DirectDraw isn't initialized yet - double srcHeight = FSettings.TotalScanlines(); - double srcWidth = VNSWID; - if (FL_TEST(eoptions, EO_TVASPECT)) - srcWidth = ceil(srcHeight * (srcWidth / 256) * (tvAspectX / tvAspectY)); + double screen_width = VNSWID; + double screen_height = FSettings.TotalScanlines(); + if (eoptions & EO_TVASPECT) + screen_width = ceil(screen_height * (screen_width / 256) * (tvAspectX / tvAspectY)); - double current_aspectratio = (double)wndWidth / (double)wndHeight; - double needed_aspectratio = srcWidth / srcHeight; + int center_x = width / 2; + int center_y = height / 2; - double new_width; - double new_height; - if (current_aspectratio >= needed_aspectratio) { - // the window is wider or match emulated screen - new_height = wndHeight; - if (FL_TEST(eoptions, EO_SQUAREPIXELS)) { - new_height = srcHeight * int((double)wndHeight / srcHeight); // integer scale of src + // calculate bestfitRect + double current_aspectratio = (double)width / (double)height; + double needed_aspectratio = screen_width / screen_height; + if (current_aspectratio >= needed_aspectratio) + { + // the window is wider than emulated screen + double new_height = height; + if (eoptions & EO_SQUAREPIXELS) + { + new_height = int((double)height / screen_height) * screen_height; if (new_height == 0) - new_height = wndHeight; // window is smaller than src (or srcHeight is zero, which I hope never the case) + new_height = height; } - - new_width = (new_height * needed_aspectratio); - if (FL_TEST(eoptions, EO_SQUAREPIXELS) && !FL_TEST(eoptions, EO_TVASPECT)) { - int new_width_integer = int((double)new_width / srcWidth) * srcWidth; + bestfitRect.top = center_y - (int)(new_height / 2); + bestfitRect.bottom = bestfitRect.top + new_height; + double new_width = (new_height * needed_aspectratio); + if (eoptions & EO_SQUAREPIXELS && !(eoptions & EO_TVASPECT)) + { + int new_width_integer = int((double)new_width / screen_width) * screen_width; if (new_width_integer > 0) new_width = new_width_integer; } - } - else { + bestfitRect.left = center_x - (int)(new_width / 2); + bestfitRect.right = bestfitRect.left + new_width; + } else + { // the window is taller than emulated screen - new_width = wndWidth; - if (FL_TEST(eoptions, EO_SQUAREPIXELS)) + double new_width = width; + if (eoptions & EO_SQUAREPIXELS) { - new_width = int((double)wndWidth / srcWidth) * srcWidth; + new_width = int((double)width / screen_width) * screen_width; if (new_width == 0) - new_width = wndWidth; + new_width = width; } - - new_height = (new_width / needed_aspectratio); - if (FL_TEST(eoptions, EO_SQUAREPIXELS) && !FL_TEST(eoptions, EO_TVASPECT)) + bestfitRect.left = center_x - (int)(new_width / 2); + bestfitRect.right = bestfitRect.left + new_width; + double new_height = (new_width / needed_aspectratio); + if (eoptions & EO_SQUAREPIXELS && !(eoptions & EO_TVASPECT)) { - int new_height_integer = int((double)new_height / srcHeight) * srcHeight; + int new_height_integer = int((double)new_height / screen_height) * screen_height; if (new_height_integer > 0) new_height = new_height_integer; } - } - - activeRect.left = (int)((wndWidth - new_width) / 2); - activeRect.right = activeRect.left + new_width; - activeRect.top = (int)((wndHeight - new_height) / 2); - activeRect.bottom = activeRect.top + new_height; -} - -static void ResetVideoModeParams() -{ - // use current display settings - if (!ddraw7Handle) - return; - - DDSURFACEDESC2 surfaceDescription; - memset(&surfaceDescription,0,sizeof(surfaceDescription)); - surfaceDescription.dwSize = sizeof(DDSURFACEDESC2); - HRESULT status = IDirectDraw7_GetDisplayMode(ddraw7Handle, &surfaceDescription); - if (SUCCEEDED(status)) { - videoModes[vmodeIdx].width = surfaceDescription.dwWidth; - videoModes[vmodeIdx].height = surfaceDescription.dwHeight; - videoModes[vmodeIdx].bpp = surfaceDescription.ddpfPixelFormat.dwRGBBitCount; - videoModes[vmodeIdx].xscale = videoModes[vmodeIdx].yscale = 1; - videoModes[vmodeIdx].flags = VIDEOMODEFLAG_DXBLT|VIDEOMODEFLAG_STRFS; + bestfitRect.top = center_y - (int)(new_height / 2); + bestfitRect.bottom = bestfitRect.top + new_height; } } -static bool RecalcVideoModeParams() -{ - VideoMode& vmode = videoModes[0]; - if ((vmode.width <= 0) || (vmode.height <= 0)) - ResetVideoModeParams(); - - if(FL_TEST(vmode.flags, VIDEOMODEFLAG_STRFS)) { - FL_SET(vmode.flags, VIDEOMODEFLAG_DXBLT); - } - else if(vmode.xscale!=1 || vmode.yscale!=1 || vmode.filter!=FILTER_NONE) { - // if scaled or have filter (which may have scale) - FL_SET(vmode.flags, VIDEOMODEFLAG_DXBLT); - - if(vmode.filter != FILTER_NONE) { - // adjust vmode scale to be no less than filter scale - int mult = filterScaleMultiplier[vmode.filter]; - - if(vmode.xscale < mult) - vmode.xscale = mult; - if(vmode.yscale < mult) - vmode.yscale = mult; - - if(vmode.xscale == mult && vmode.yscale == mult) - FL_CLEAR(vmode.flags, VIDEOMODEFLAG_DXBLT); // exact match, no need for "region blit"? - } - - if(VNSWID*vmode.xscale > vmode.width) { - // videomode scale makes image too wide for it - if(vmode.filter == FILTER_NONE) { - FCEUD_PrintError("Scaled width is out of range. Reverting to no horizontal scaling."); - vmode.xscale=1; - } - else { - FCEUD_PrintError("Scaled width is out of range."); - return false; - } - } - - if(FSettings.TotalScanlines()*vmode.yscale > vmode.height) { - // videomode scale makes image too tall for it - if(vmode.filter == FILTER_NONE) { - FCEUD_PrintError("Scaled height is out of range. Reverting to no vertical scaling."); - vmode.yscale=1; - } - else { - FCEUD_PrintError("Scaled height is out of range."); - return false; - } - } - - vmode.srcRect.left = VNSCLIP; - vmode.srcRect.top = FSettings.FirstSLine; - vmode.srcRect.right = 256-VNSCLIP; - vmode.srcRect.bottom = FSettings.LastSLine+1; - - vmode.dstRect.top = (vmode.height-(FSettings.TotalScanlines()*vmode.yscale)) / 2; - vmode.dstRect.bottom = vmode.dstRect.top+FSettings.TotalScanlines()*vmode.yscale; - vmode.dstRect.left = (vmode.width-(VNSWID*vmode.xscale)) / 2; - vmode.dstRect.right = vmode.dstRect.left+VNSWID*vmode.xscale; - } - - // -Video Modes Tag- - if((vmode.filter == FILTER_HQ2X || vmode.filter == FILTER_HQ3X) && vmode.bpp == 8) - { - // HQ2x/HQ3x requires 16bpp or 32bpp(best) - vmode.bpp = 32; - } - - if(vmode.width= 1) + specmul = 2; + else if(winspecial >= 4 && winspecial <= 5) + specmul = 3; + else + specmul = 1; + + ShowCursorAbs(1); + windowedfailed=1; + HideFWindow(0); + + ddrval = IDirectDraw7_SetCooperativeLevel ( lpDD7, hAppWnd, DDSCL_NORMAL); + if (ddrval != DD_OK) + { + //ShowDDErr("Error setting cooperative level."); + FCEU_printf("Error setting cooperative level.\n"); + return 1; } - HideFWindow(1); + //Beginning + memset(&ddsd,0,sizeof(ddsd)); + ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_CAPS; + ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - HRESULT status = IDirectDraw7_SetCooperativeLevel ( ddraw7Handle, hAppWnd,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT); - if (status == DD_OK) { - status = IDirectDraw7_SetDisplayMode(ddraw7Handle, videoModes[vmodeIdx].width, videoModes[vmodeIdx].height, videoModes[vmodeIdx].bpp,0,0); - if (status == DD_OK) { - if(FL_TEST(videoModes[vmodeIdx].flags, VIDEOMODEFLAG_DXBLT)) { - memset(&surfaceDescOffscreen,0,sizeof(surfaceDescOffscreen)); - surfaceDescOffscreen.dwSize=sizeof(surfaceDescOffscreen); - surfaceDescOffscreen.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; - surfaceDescOffscreen.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; + ddrval = IDirectDraw7_CreateSurface ( lpDD7, &ddsd, &lpDDSPrimary,(IUnknown FAR*)NULL); + if (ddrval != DD_OK) + { + //ShowDDErr("Error creating primary surface."); + FCEU_printf("Error creating primary surface.\n"); + return 1; + } - surfaceDescOffscreen.dwWidth=256 * specmul; //videoModes[vmodeIdx].srcRect.right; - surfaceDescOffscreen.dwHeight=FSettings.TotalScanlines() * specmul; //videoModes[vmodeIdx].srcRect.bottom; + memset(&ddsdback,0,sizeof(ddsdback)); + ddsdback.dwSize=sizeof(ddsdback); + ddsdback.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; + ddsdback.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; + + ddsdback.dwWidth=256 * specmul; + ddsdback.dwHeight=FSettings.TotalScanlines() * specmul; + + if (directDrawModeWindowed == DIRECTDRAW_MODE_SURFACE_IN_RAM) + // create the buffer in system memory + ddsdback.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; + + ddrval = IDirectDraw7_CreateSurface(lpDD7, &ddsdback, &lpDDSBack, (IUnknown FAR*)NULL); + if (ddrval != DD_OK) + { + //ShowDDErr("Error creating secondary surface."); + FCEU_printf("Error creating secondary surface.\n"); + return 0; + } + + if(!GetBPP()) + return 0; + + if(bpp!=16 && bpp!=24 && bpp!=32) + { + //ShowDDErr("Current bit depth not supported!"); + FCEU_printf("Current bit depth not supported!\n"); + return 0; + } + + if(!InitBPPStuff(fs)) + return 0; + + ddrval=IDirectDraw7_CreateClipper(lpDD7,0,&lpClipper,0); + if (ddrval != DD_OK) + { + //ShowDDErr("Error creating clipper."); + FCEU_printf("Error creating clipper.\n"); + return 0; + } + + ddrval=IDirectDrawClipper_SetHWnd(lpClipper,0,hAppWnd); + if (ddrval != DD_OK) + { + //ShowDDErr("Error setting clipper window."); + FCEU_printf("Error setting clipper window.\n"); + return 0; + } + ddrval=IDirectDrawSurface7_SetClipper(lpDDSPrimary,lpClipper); + if (ddrval != DD_OK) + { + //ShowDDErr("Error attaching clipper to primary surface."); + FCEU_printf("Error attaching clipper to primary surface.\n"); + return 0; + } + + windowedfailed=0; + SetMainWindowStuff(); + } else + { + //Following is full-screen + if(vmod == 0) // Custom mode + { + // -Video Modes Tag- + if(vmodes[0].special <= 3 && vmodes[0].special >= 1) + specmul = 2; + else if(vmodes[0].special >= 4 && vmodes[0].special <= 5) + specmul = 3; + else + specmul = 1; + } + HideFWindow(1); + + ddrval = IDirectDraw7_SetCooperativeLevel ( lpDD7, hAppWnd,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT); + if (ddrval != DD_OK) + { + //ShowDDErr("Error setting cooperative level."); + FCEU_printf("Error setting cooperative level.\n"); + return 0; + } + + ddrval = IDirectDraw7_SetDisplayMode(lpDD7, vmodes[vmod].x, vmodes[vmod].y,vmodes[vmod].bpp,0,0); + if (ddrval != DD_OK) + { + //ShowDDErr("Error setting display mode."); + FCEU_printf("Error setting display mode.\n"); + return 0; + } + if(vmodes[vmod].flags&VMDF_DXBLT) + { + memset(&ddsdback,0,sizeof(ddsdback)); + ddsdback.dwSize=sizeof(ddsdback); + ddsdback.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; + ddsdback.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; + + ddsdback.dwWidth=256 * specmul; //vmodes[vmod].srect.right; + ddsdback.dwHeight=FSettings.TotalScanlines() * specmul; //vmodes[vmod].srect.bottom; if (directDrawModeFullscreen == DIRECTDRAW_MODE_SURFACE_IN_RAM) // create the buffer in system memory - FL_SET(surfaceDescOffscreen.ddsCaps.dwCaps, DDSCAPS_SYSTEMMEMORY); + ddsdback.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; - status = IDirectDraw7_CreateSurface(ddraw7Handle, &surfaceDescOffscreen, &lpOffscreenSurface, (IUnknown FAR*)NULL); + ddrval = IDirectDraw7_CreateSurface ( lpDD7, &ddsdback, &lpDDSBack, (IUnknown FAR*)NULL); + if(ddrval!=DD_OK) + { + //ShowDDErr("Error creating secondary surface."); + FCEU_printf("Error creating secondary surface.\n"); + return 0; + } } - if(status == DD_OK) { - OnWindowSizeChange(videoModes[vmodeIdx].width, videoModes[vmodeIdx].height); + if (eoptions & EO_BESTFIT) + recalculateBestFitRect(vmodes[vmod].x, vmodes[vmod].y); // create foreground surface - memset(&surfaceDescScreen,0,sizeof(surfaceDescScreen)); - surfaceDescScreen.dwSize = sizeof(surfaceDescScreen); + memset(&ddsd,0,sizeof(ddsd)); + ddsd.dwSize = sizeof(ddsd); - surfaceDescScreen.dwFlags = DDSD_CAPS; - surfaceDescScreen.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + ddsd.dwFlags = DDSD_CAPS; + ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - if(idxFullscreenSyncMode == SYNCMODE_DOUBLEBUF) + if(fssync==3) // Double buffering. { - FL_SET(surfaceDescScreen.dwFlags, DDSD_BACKBUFFERCOUNT); - surfaceDescScreen.dwBackBufferCount = 1; - FL_SET(surfaceDescScreen.ddsCaps.dwCaps, DDSCAPS_COMPLEX | DDSCAPS_FLIP); + ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; + ddsd.dwBackBufferCount = 1; + ddsd.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_FLIP; + } + + ddrval = IDirectDraw7_CreateSurface ( lpDD7, &ddsd, &lpDDSPrimary,(IUnknown FAR*)NULL); + if (ddrval != DD_OK) + { + //ShowDDErr("Error creating primary surface."); + FCEU_printf("Error creating primary surface.\n"); + return 0; } - status = IDirectDraw7_CreateSurface ( ddraw7Handle, &surfaceDescScreen, &lpScreenSurface,(IUnknown FAR*)NULL); - if (status == DD_OK) { - if(idxFullscreenSyncMode == SYNCMODE_DOUBLEBUF) + if(fssync==3) { DDSCAPS2 tmp; memset(&tmp,0,sizeof(tmp)); tmp.dwCaps=DDSCAPS_BACKBUFFER; - status = IDirectDrawSurface7_GetAttachedSurface(lpScreenSurface,&tmp,&lpBackBuffer); + if(IDirectDrawSurface7_GetAttachedSurface(lpDDSPrimary,&tmp,&lpDDSDBack)!=DD_OK) + { + //ShowDDErr("Error getting attached surface."); + FCEU_printf("Error getting attached surface.\n"); + return 0; + } } - if(status == DD_OK) { - if(InitBPPStuff(fullscreenDesired!=0)) { - dispModeWasChanged = true; - if (FL_TEST(eoptions, EO_HIDEMOUSE)) + if(!GetBPP()) + return 0; + if(!InitBPPStuff(fs)) + return 0; + + mustrestore=1; + + if (eoptions & EO_HIDEMOUSE) ShowCursorAbs(0); + } - fullscreenActual = true; // now in actual fullscreen mode - return true; - } - } - else { - FCEU_printf("Error getting attached surface.\n"); - } - } - else { - FCEU_printf("Error creating primary surface.\n"); - } - } - else { - FCEU_printf("Error creating secondary surface.\n"); - } - } - else { - FCEU_printf("Error setting display mode.\n"); - } - } - else { - FCEU_printf("Error setting cooperative level.\n"); - } - } - else { - // windowed - specmul = filterScaleMultiplier[idxFilterModeWindowed]; + fullscreen=fs; + return 1; +} - ShowCursorAbs(1); - windowedfailed=1; - HideFWindow(0); +//draw input aids if we are fullscreen +bool FCEUD_ShouldDrawInputAids() +{ + return fullscreen!=0; +} - HRESULT status = IDirectDraw7_SetCooperativeLevel ( ddraw7Handle, hAppWnd, DDSCL_NORMAL); - if(status == DD_OK) { - //Beginning - memset(&surfaceDescScreen,0,sizeof(surfaceDescScreen)); - surfaceDescScreen.dwSize = sizeof(surfaceDescScreen); - surfaceDescScreen.dwFlags = DDSD_CAPS; - surfaceDescScreen.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; +static void BlitScreenWindow(uint8 *XBuf); +static void BlitScreenFull(uint8 *XBuf); - status = IDirectDraw7_CreateSurface ( ddraw7Handle, &surfaceDescScreen, &lpScreenSurface,(IUnknown FAR*)NULL); - if (status == DD_OK) { - memset(&surfaceDescOffscreen,0,sizeof(surfaceDescOffscreen)); - surfaceDescOffscreen.dwSize=sizeof(surfaceDescOffscreen); - surfaceDescOffscreen.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; - surfaceDescOffscreen.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; +static void FCEUD_VerticalSync() +{ + if(!NoWaiting) + { + int ws; - surfaceDescOffscreen.dwWidth=256 * specmul; - surfaceDescOffscreen.dwHeight=FSettings.TotalScanlines() * specmul; + if(fullscreen) ws=fssync; + else ws = winsync; - if (directDrawModeWindowed == DIRECTDRAW_MODE_SURFACE_IN_RAM) - // create the buffer in system memory - FL_SET(surfaceDescOffscreen.ddsCaps.dwCaps, DDSCAPS_SYSTEMMEMORY); + if(ws==1) + IDirectDraw7_WaitForVerticalBlank(lpDD7,DDWAITVB_BLOCKBEGIN,0); + else if(ws == 2) + { + BOOL invb = 0; - status = IDirectDraw7_CreateSurface(ddraw7Handle, &surfaceDescOffscreen, &lpOffscreenSurface, (IUnknown FAR*)NULL); - if (status == DD_OK) { - if(InitBPPStuff(fullscreenDesired!=0)) { - status=IDirectDraw7_CreateClipper(ddraw7Handle,0,&ddClipperHandle,0); - if (status == DD_OK) { - status=IDirectDrawClipper_SetHWnd(ddClipperHandle,0,hAppWnd); - if (status == DD_OK) { - status=IDirectDrawSurface7_SetClipper(lpScreenSurface,ddClipperHandle); - if (status == DD_OK) { - windowedfailed=0; - SetMainWindowStuff(); - - fullscreenActual = false; // now in actual windowed mode - return true; - } - else { - FCEU_printf("Error attaching clipper to primary surface.\n"); - } - } - else { - FCEU_printf("Error setting clipper window.\n"); - } - } - else { - FCEU_printf("Error creating clipper.\n"); - } - } - } - else { - FCEU_printf("Error creating secondary surface.\n"); - } - } - else { - FCEU_printf("Error creating primary surface.\n"); - } - } - else { - FCEU_printf("Error setting cooperative level.\n"); - } - } + while((DD_OK == IDirectDraw7_GetVerticalBlankStatus(lpDD7,&invb)) && !invb) + Sleep(0); } } - - fullscreenDesired = fullscreenActual; // restore fullscreen var - return false; } -static void VerticalSync() +//static uint8 *XBSave; +void FCEUD_BlitScreen(uint8 *XBuf) { - if(!NoWaiting) // apparently NoWaiting is set during netplay, which means there will be no vsync + xbsave = XBuf; + + if(fullscreen) { - int syncMode = (fullscreenActual)? idxFullscreenSyncMode:idxWindowedSyncMode; - switch(syncMode) { - case SYNCMODE_WAIT: - IDirectDraw7_WaitForVerticalBlank(ddraw7Handle,DDWAITVB_BLOCKBEGIN,0); - break; - case SYNCMODE_LAZYWAIT: - BOOL invb = 0; - while((DD_OK == IDirectDraw7_GetVerticalBlankStatus(ddraw7Handle,&invb)) && !invb) - Sleep(0); - break; + BlitScreenFull(XBuf); } + else + { + if(!windowedfailed) + BlitScreenWindow(XBuf); } } -/* Renders XBuf into offscreen surface -// Blits offscreen into screen with either stretch or integer scale -// FIXME doublebuffering settings are ignored, is this correct? */ +static void FixPaletteHi(void) +{ + SetPaletteBlitToHigh((uint8*)color_palette); //mbg merge 7/17/06 added cast +} + static void BlitScreenWindow(unsigned char *XBuf) { - if (!lpOffscreenSurface) return; + int pitch; + unsigned char *ScreenLoc; + static RECT srect, wrect, blitRect; + int specialmul; - RECT rectWindow; // window client area in screen space - if(!GetClientAbsRect(&rectWindow)) return; + if (!lpDDSBack) return; - int scale = filterScaleMultiplier[idxFilterModeWindowed]; + // -Video Modes Tag- + if(winspecial <= 3 && winspecial >= 1) + specialmul = 2; + else if(winspecial >= 4 && winspecial <= 5) + specialmul = 3; + else specialmul = 1; - if(updateDDPalette) { - SetPaletteBlitToHigh((uint8*)color_palette); - updateDDPalette = false; - } + srect.top=srect.left=0; + srect.right=VNSWID * specialmul; + srect.bottom=FSettings.TotalScanlines() * specialmul; - // Render XBuf into offscreen surface + if(PaletteChanged==1) { - HRESULT status = IDirectDrawSurface7_Lock(lpOffscreenSurface, - NULL, - &surfaceDescOffscreen, - 0, - NULL); - - if (status != DD_OK) { - if (status == DDERR_SURFACELOST) - RestoreLostOffscreenSurface(); - return; + FixPaletteHi(); + PaletteChanged=0; } - int pitch = surfaceDescOffscreen.lPitch; - unsigned char *dstOffscreenBuf = (unsigned char*)surfaceDescOffscreen.lpSurface; + if(!GetClientAbsRect(&wrect)) return; - if(wipeSurface) { - memset(dstOffscreenBuf, 0, pitch * surfaceDescOffscreen.dwHeight); - wipeSurface = false; - } - Blit8ToHigh(XBuf + FSettings.FirstSLine * 256 + VNSCLIP, - dstOffscreenBuf, - VNSWID, - FSettings.TotalScanlines(), - pitch, - scale, - scale); - - IDirectDrawSurface7_Unlock(lpOffscreenSurface, NULL); - } - - VerticalSync(); - - // Blit offscreen to screen surface + ddrval=IDirectDrawSurface7_Lock(lpDDSBack,NULL,&ddsdback, 0, NULL); + if (ddrval != DD_OK) { - RECT rectSrc; // size of bitmap in offscreen surface - rectSrc.left = 0; - rectSrc.top = 0; - rectSrc.right = VNSWID * scale; - rectSrc.bottom = FSettings.TotalScanlines() * scale; + if (ddrval == DDERR_SURFACELOST) + RestoreDD(1); + return; + } - RECT rectDst; - bool fillBorder = false; - if (FL_TEST(eoptions, EO_BESTFIT) && (activeRect.top || activeRect.left)) + //mbg merge 7/17/06 removing dummyunion stuff + pitch=ddsdback.lPitch; + ScreenLoc=(unsigned char*)ddsdback.lpSurface; //mbg merge 7/17/06 added cst + if(veflags&1) + { + memset(ScreenLoc,0,pitch*ddsdback.dwHeight); + veflags&=~1; + } + Blit8ToHigh(XBuf+FSettings.FirstSLine*256+VNSCLIP,ScreenLoc, VNSWID, FSettings.TotalScanlines(), pitch,specialmul,specialmul); + + IDirectDrawSurface7_Unlock(lpDDSBack, NULL); + + FCEUD_VerticalSync(); // aquanull 2011-11-28 fix tearing + if (eoptions & EO_BESTFIT && (bestfitRect.top || bestfitRect.left)) + { + // blit with resizing + blitRect.top = wrect.top + bestfitRect.top; + blitRect.bottom = blitRect.top + bestfitRect.bottom - bestfitRect.top; + blitRect.left = wrect.left + bestfitRect.left; + blitRect.right = blitRect.left + bestfitRect.right - bestfitRect.left; + if (IDirectDrawSurface7_Blt(lpDDSPrimary, &blitRect, lpDDSBack, &srect, DDBLT_ASYNC, 0) != DD_OK) + { + ddrval = IDirectDrawSurface7_Blt(lpDDSPrimary, &blitRect, lpDDSBack, &srect, DDBLT_WAIT, 0); + if(ddrval != DD_OK) + { + if(ddrval == DDERR_SURFACELOST) { - // blit into activeRect - rectDst.top = rectWindow.top + activeRect.top; - rectDst.bottom = rectDst.top + activeRect.bottom - activeRect.top; - rectDst.left = rectWindow.left + activeRect.left; - rectDst.right = rectDst.left + activeRect.right - activeRect.left; - - fillBorder = true; - } - else { - // blit into window rect - rectDst = rectWindow; - } - - if(IDirectDrawSurface7_Blt(lpScreenSurface, &rectDst, lpOffscreenSurface, &rectSrc, DDBLT_ASYNC, 0) != DD_OK) { - HRESULT status = IDirectDrawSurface7_Blt(lpScreenSurface, &rectDst, lpOffscreenSurface, &rectSrc, DDBLT_WAIT, 0); - if(status != DD_OK) { - if(status == DDERR_SURFACELOST) { - RestoreLostOffscreenSurface(); - RestoreLostScreenSurface(); + RestoreDD(1); + RestoreDD(0); } return; } } - - if (fillBorder) { - DDBLTFX blitfx = { sizeof(DDBLTFX) }; - if (FL_TEST(eoptions, EO_BGCOLOR)) { + // clear borders + if (eoptions & EO_BGCOLOR) + { // fill the surface using BG color from PPU unsigned char r, g, b; FCEUD_GetPalette(0x80 | PALRAM[0], &r, &g, &b); blitfx.dwFillColor = (r << 16) + (g << 8) + b; - } - else { + } else + { blitfx.dwFillColor = 0; } - - if (activeRect.top) { + if (bestfitRect.top) + { // upper border - rectDst = rectWindow; - rectDst.bottom = rectWindow.top + activeRect.top; - IDirectDrawSurface7_Blt(lpScreenSurface, &rectDst, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + blitRect.top = wrect.top; + blitRect.bottom = wrect.top + bestfitRect.top; + blitRect.left = wrect.left; + blitRect.right = wrect.right; + IDirectDrawSurface7_Blt(lpDDSPrimary, &blitRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); // lower border - rectDst.top += activeRect.bottom; - rectDst.bottom = rectWindow.bottom; - IDirectDrawSurface7_Blt(lpScreenSurface, &rectDst, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + blitRect.top += bestfitRect.bottom; + blitRect.bottom = wrect.bottom; + IDirectDrawSurface7_Blt(lpDDSPrimary, &blitRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); } - - if (activeRect.left) { + if (bestfitRect.left) + { // left border - rectDst = rectWindow; - rectDst.right = rectWindow.left + activeRect.left; - IDirectDrawSurface7_Blt(lpScreenSurface, &rectDst, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + blitRect.top = wrect.top; + blitRect.bottom = wrect.bottom; + blitRect.left = wrect.left; + blitRect.right = wrect.left + bestfitRect.left; + IDirectDrawSurface7_Blt(lpDDSPrimary, &blitRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); // right border - rectDst.left += activeRect.right; - rectDst.right = rectWindow.right; - IDirectDrawSurface7_Blt(lpScreenSurface, &rectDst, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + blitRect.left += bestfitRect.right; + blitRect.right = wrect.right; + IDirectDrawSurface7_Blt(lpDDSPrimary, &blitRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); } + } else + { + // blit without resizing + if(IDirectDrawSurface7_Blt(lpDDSPrimary, &wrect, lpDDSBack, &srect, DDBLT_ASYNC, 0) != DD_OK) + { + ddrval = IDirectDrawSurface7_Blt(lpDDSPrimary, &wrect, lpDDSBack, &srect, DDBLT_WAIT, 0); + if(ddrval != DD_OK) + { + if(ddrval == DDERR_SURFACELOST) + { + RestoreDD(1); + RestoreDD(0); + } + return; } } + } } -// Renders XBuf into one of three buffers depending on current settings -// If rendered into offscreen will blit into one of screen surface buffers with either stretch or integer scale -// If doublebuffering enabled, when transferring image to screen surface its back buffer is selected, then -// surface is flipped +static void DD_FillRect(LPDIRECTDRAWSURFACE7 surf, int left, int top, int right, int bottom, DWORD color) +{ + RECT r; + SetRect(&r,left,top,right,bottom); + DDBLTFX fx; + memset(&fx,0,sizeof(DDBLTFX)); + fx.dwSize = sizeof(DDBLTFX); + //fx.dwFillColor = color; + fx.dwFillColor = 0; //color is just for debug + surf->Blt(&r,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&fx); +} + + static void BlitScreenFull(uint8 *XBuf) { - // in doublebuffer mode image should end up in screen surface back buffer - LPDIRECTDRAWSURFACE7 targetScreenSurface = (idxFullscreenSyncMode == SYNCMODE_DOUBLEBUF)? lpBackBuffer:lpScreenSurface; - if (!targetScreenSurface) return; + static int pitch; + char *ScreenLoc; + //unsigned long x; //mbg merge 7/17/06 removed + //uint8 y; //mbg merge 7/17/06 removed + RECT srect, drect; + LPDIRECTDRAWSURFACE7 lpDDSVPrimary; + int specmul; // Special scaler size multiplier + // -Video Modes Tag- + if(vmodes[0].special <= 3 && vmodes[0].special >= 1) + specmul = 2; + else if(vmodes[0].special >= 4 && vmodes[0].special <= 5) + specmul = 3; + else + specmul = 1; - if(updateDDPalette) { - if(bpp>=16) SetPaletteBlitToHigh((uint8*)color_palette); - else { - HRESULT status = IDirectDrawPalette_SetEntries(ddPaletteHandle,0,0,256,color_palette); - if(status != DD_OK) { - if(status == DDERR_SURFACELOST) RestoreLostScreenSurface(); + if(fssync==3) + lpDDSVPrimary=lpDDSDBack; + else + lpDDSVPrimary=lpDDSPrimary; + + if (!lpDDSVPrimary) return; + + if(PaletteChanged==1) + { + if(bpp>=16) + FixPaletteHi(); + else + { + ddrval=IDirectDrawPalette_SetEntries(lpddpal,0,0,256,color_palette); + if(ddrval!=DD_OK) + { + if(ddrval==DDERR_SURFACELOST) RestoreDD(0); return; } } - updateDDPalette = false; + PaletteChanged=0; } - char* targetBuf; - int pitch; - RECT srcRect; - RECT displayRect; - int scale = filterScaleMultiplier[videoModes[vmodeIdx].filter]; - if(FL_TEST(videoModes[vmodeIdx].flags, VIDEOMODEFLAG_DXBLT)) { - // will render to offscreen surface - DDSURFACEDESC2 offscreenDesc; - memset(&offscreenDesc,0,sizeof(offscreenDesc)); - offscreenDesc.dwSize = sizeof(DDSURFACEDESC2); - HRESULT status = IDirectDrawSurface7_Lock(lpOffscreenSurface,NULL,&offscreenDesc, 0, NULL); - if(status != DD_OK) { - if(status==DDERR_SURFACELOST) RestoreLostOffscreenSurface(); + if(vmodes[vmod].flags&VMDF_DXBLT) + { + // start rendering into backbuffer + ddrval=IDirectDrawSurface7_Lock(lpDDSBack,NULL,&ddsdback, 0, NULL); + if(ddrval!=DD_OK) + { + if(ddrval==DDERR_SURFACELOST) RestoreDD(1); + return; + } + ScreenLoc=(char *)ddsdback.lpSurface; //mbg merge 7/17/06 added cast + pitch=ddsdback.lPitch; //mbg merge 7/17/06 removed dummyunion stuff + + srect.top=0; + srect.left=0; + srect.right=VNSWID * specmul; + srect.bottom=FSettings.TotalScanlines() * specmul; + + //if(vmodes[vmod].flags&VMDF_STRFS) + //{ + drect.top=0; + drect.left=0; + drect.right=vmodes[vmod].x; + drect.bottom=vmodes[vmod].y; + /* + } + else + { + drect.top=(vmodes[vmod].y-(FSettings.TotalScanlines()*vmodes[vmod].yscale))>>1; + drect.bottom=drect.top+(FSettings.TotalScanlines()*vmodes[vmod].yscale); + drect.left=(vmodes[vmod].x-VNSWID*vmodes[vmod].xscale)>>1; + drect.right=drect.left+VNSWID*vmodes[vmod].xscale; + RECT fullScreen; + fullScreen.left = fullScreen.top = 0; + fullScreen.right = vmodes[vmod].x; + fullScreen.bottom = vmodes[vmod].y; + RECT r; + r = drect; + int left = r.left; + int top = r.top; + int right = r.right; + int bottom = r.bottom; + DD_FillRect(lpDDSVPrimary,0,0,left,top,RGB(255,0,0)); //topleft + DD_FillRect(lpDDSVPrimary,left,0,right,top,RGB(128,0,0)); //topcenter + DD_FillRect(lpDDSVPrimary,right,0,fullScreen.right,top,RGB(0,255,0)); //topright + DD_FillRect(lpDDSVPrimary,0,top,left,bottom,RGB(0,128,0)); //left + DD_FillRect(lpDDSVPrimary,right,top,fullScreen.right,bottom,RGB(0,0,255)); //right + DD_FillRect(lpDDSVPrimary,0,bottom,left,fullScreen.bottom,RGB(0,0,128)); //bottomleft + DD_FillRect(lpDDSVPrimary,left,bottom,right,fullScreen.bottom,RGB(255,0,255)); //bottomcenter + DD_FillRect(lpDDSVPrimary,right,bottom,fullScreen.right,fullScreen.bottom,RGB(0,255,255)); //bottomright + } + */ + } else + { + // start rendering directly to screen + FCEUD_VerticalSync(); + ddrval=IDirectDrawSurface7_Lock(lpDDSVPrimary,NULL,&ddsd, 0, NULL); + if(ddrval!=DD_OK) + { + if(ddrval==DDERR_SURFACELOST) RestoreDD(0); return; } - targetBuf = (char *)offscreenDesc.lpSurface; - pitch = offscreenDesc.lPitch; - - srcRect.top = 0; - srcRect.left = 0; - srcRect.right = VNSWID * scale; - srcRect.bottom = FSettings.TotalScanlines() * scale; - - displayRect.top = 0; - displayRect.left = 0; - displayRect.right = videoModes[vmodeIdx].width; - displayRect.bottom = videoModes[vmodeIdx].height; - } - else { - // will render to selected screen buffer - VerticalSync(); - - DDSURFACEDESC2 screenDesc; - memset(&screenDesc,0,sizeof(screenDesc)); - screenDesc.dwSize = sizeof(DDSURFACEDESC2); - HRESULT status = IDirectDrawSurface7_Lock(targetScreenSurface,NULL,&screenDesc, 0, NULL); - if(status != DD_OK) { - if(status == DDERR_SURFACELOST) RestoreLostScreenSurface(); - return; + ScreenLoc=(char*)ddsd.lpSurface; //mbg merge 7/17/06 added cast + pitch=ddsd.lPitch; //mbg merge 7/17/06 removing dummyunion stuff } - targetBuf = (char*)screenDesc.lpSurface; - pitch = screenDesc.lPitch; - } - - if(wipeSurface) { - int lineCount = (FL_TEST(videoModes[vmodeIdx].flags, VIDEOMODEFLAG_DXBLT))? srcRect.bottom:videoModes[vmodeIdx].height; - memset(targetBuf, 0, pitch * lineCount); - updateDDPalette = true; - wipeSurface = false; + if(veflags&1) + { + if(vmodes[vmod].flags&VMDF_DXBLT) + { + veflags|=2; + memset((char *)ScreenLoc,0,pitch*srect.bottom); } + else + { + memset((char *)ScreenLoc,0,pitch*vmodes[vmod].y); + } + PaletteChanged=1; + veflags&=~1; + } - if(!FL_TEST(videoModes[vmodeIdx].flags, VIDEOMODEFLAG_DXBLT)) { + //mbg 6/29/06 merge +#ifndef MSVC + if(vmod==5) + { + if(eoptions&EO_CLIPSIDES) + { + asm volatile( + "xorl %%edx, %%edx\n\t" + "akoop1:\n\t" + "movb $120,%%al \n\t" + "akoop2:\n\t" + "movb 1(%%esi),%%dl\n\t" + "shl $16,%%edx\n\t" + "movb (%%esi),%%dl\n\t" + "movl %%edx,(%%edi)\n\t" + "addl $2,%%esi\n\t" + "addl $4,%%edi\n\t" + "decb %%al\n\t" + "jne akoop2\n\t" + "addl $16,%%esi\n\t" + "addl %%ecx,%%edi\n\t" + "decb %%bl\n\t" + "jne akoop1\n\t" + : + : "S" (XBuf+FSettings.FirstSLine*256+VNSCLIP), "D" (ScreenLoc+((240-FSettings.TotalScanlines())/2)*pitch+(640-(VNSWID<<1))/2),"b" (FSettings.TotalScanlines()), "c" ((pitch-VNSWID)<<1) + : "%al", "%edx", "%cc" ); + } + else + { + asm volatile( + "xorl %%edx, %%edx\n\t" + "koop1:\n\t" + "movb $128,%%al \n\t" + "koop2:\n\t" + "movb 1(%%esi),%%dl\n\t" + "shl $16,%%edx\n\t" + "movb (%%esi),%%dl\n\t" + "movl %%edx,(%%edi)\n\t" + "addl $2,%%esi\n\t" + "addl $4,%%edi\n\t" + "decb %%al\n\t" + "jne koop2\n\t" + "addl %%ecx,%%edi\n\t" + "decb %%bl\n\t" + "jne koop1\n\t" + : + : "S" (XBuf+FSettings.FirstSLine*256), "D" (ScreenLoc+((240-FSettings.TotalScanlines())/2)*pitch+(640-512)/2),"b" (FSettings.TotalScanlines()), "c" (pitch-512+pitch) + : "%al", "%edx", "%cc" ); + } + } + else if(vmod==4) + { + if(eoptions&EO_CLIPSIDES) + { + asm volatile( + "ayoop1:\n\t" + "movb $120,%%al \n\t" + "ayoop2:\n\t" + "movb 1(%%esi),%%dh\n\t" + "movb %%dh,%%dl\n\t" + "shl $16,%%edx\n\t" + "movb (%%esi),%%dl\n\t" + "movb %%dl,%%dh\n\t" // Ugh + "movl %%edx,(%%edi)\n\t" + "addl $2,%%esi\n\t" + "addl $4,%%edi\n\t" + "decb %%al\n\t" + "jne ayoop2\n\t" + "addl $16,%%esi\n\t" + "addl %%ecx,%%edi\n\t" + "decb %%bl\n\t" + "jne ayoop1\n\t" + : + : "S" (XBuf+FSettings.FirstSLine*256+VNSCLIP), "D" (ScreenLoc+((240-FSettings.TotalScanlines())/2)*pitch+(640-(VNSWID<<1))/2),"b" (FSettings.TotalScanlines()), "c" ((pitch-VNSWID)<<1) + : "%al", "%edx", "%cc" ); + } + else + { + asm volatile( + "yoop1:\n\t" + "movb $128,%%al \n\t" + "yoop2:\n\t" + "movb 1(%%esi),%%dh\n\t" + "movb %%dh,%%dl\n\t" + "shl $16,%%edx\n\t" + "movb (%%esi),%%dl\n\t" + "movb %%dl,%%dh\n\t" // Ugh + "movl %%edx,(%%edi)\n\t" + "addl $2,%%esi\n\t" + "addl $4,%%edi\n\t" + "decb %%al\n\t" + "jne yoop2\n\t" + "addl %%ecx,%%edi\n\t" + "decb %%bl\n\t" + "jne yoop1\n\t" + : + : "S" (XBuf+FSettings.FirstSLine*256), "D" (ScreenLoc+((240-FSettings.TotalScanlines())/2)*pitch+(640-512)/2),"b" (FSettings.TotalScanlines()), "c" (pitch-512+pitch) + : "%al", "%edx", "%cc" ); + } + } + else +#endif + //mbg 6/29/06 merge + { + if(!(vmodes[vmod].flags&VMDF_DXBLT)) + { // -Video Modes Tag- - if(videoModes[vmodeIdx].filter != FILTER_NONE) - targetBuf += (videoModes[vmodeIdx].dstRect.left * (bpp/8)) + (videoModes[vmodeIdx].dstRect.top * pitch); + if(vmodes[vmod].special) + ScreenLoc += (vmodes[vmod].drect.left*(bpp>>3)) + ((vmodes[vmod].drect.top)*pitch); else - targetBuf += ((videoModes[vmodeIdx].width-VNSWID)/2)*(bpp/8)+(((videoModes[vmodeIdx].height-FSettings.TotalScanlines())/2))*pitch; - } - - // Render XBuf into selected target buf - if(bpp >= 16) { - Blit8ToHigh(XBuf+FSettings.FirstSLine*256+VNSCLIP, - (uint8*)targetBuf, - VNSWID, - FSettings.TotalScanlines(), - pitch, - scale, - scale); - } - else { - // 8 bpp - Blit8To8(XBuf+FSettings.FirstSLine*256+VNSCLIP, - (uint8*)targetBuf, - VNSWID, - FSettings.TotalScanlines(), - pitch, - (videoModes[vmodeIdx].filter != FILTER_NONE)? videoModes[vmodeIdx].xscale:1, - (videoModes[vmodeIdx].filter != FILTER_NONE)? videoModes[vmodeIdx].yscale:1, - 0, - videoModes[vmodeIdx].filter); - } - - if(FL_TEST(videoModes[vmodeIdx].flags, VIDEOMODEFLAG_DXBLT)) { - IDirectDrawSurface7_Unlock(lpOffscreenSurface, NULL); - - VerticalSync(); - - bool fillBorder = false; - RECT* pDstRect; - if (FL_TEST(eoptions, EO_BESTFIT) && (activeRect.top || activeRect.left) && vmodeIdx==0) { - pDstRect = &activeRect; // blit offscreen to activeRect - fillBorder = true; - } - else { - pDstRect = NULL; // blit offscreen to entire surface + ScreenLoc+=((vmodes[vmod].x-VNSWID)>>1)*(bpp>>3)+(((vmodes[vmod].y-FSettings.TotalScanlines())>>1))*pitch; } - if (IDirectDrawSurface7_Blt(targetScreenSurface, pDstRect, lpOffscreenSurface, &srcRect, DDBLT_ASYNC, 0) != DD_OK) { - HRESULT status = IDirectDrawSurface7_Blt(targetScreenSurface, pDstRect, lpOffscreenSurface, &srcRect, DDBLT_WAIT, 0); - if(status != DD_OK) + if(bpp>=16) + { + Blit8ToHigh(XBuf+FSettings.FirstSLine*256+VNSCLIP,(uint8*)ScreenLoc, VNSWID, FSettings.TotalScanlines(), pitch,specmul,specmul); //mbg merge 7/17/06 added cast + } + else + { + XBuf+=FSettings.FirstSLine*256+VNSCLIP; + // -Video Modes Tag- + if(vmodes[vmod].special) + Blit8To8(XBuf,(uint8*)ScreenLoc, VNSWID, FSettings.TotalScanlines(), pitch,vmodes[vmod].xscale,vmodes[vmod].yscale,0,vmodes[vmod].special); //mbg merge 7/17/06 added cast + else + Blit8To8(XBuf,(uint8*)ScreenLoc, VNSWID, FSettings.TotalScanlines(), pitch,1,1,0,0); //mbg merge 7/17/06 added cast + } + } + + if(vmodes[vmod].flags&VMDF_DXBLT) + { + IDirectDrawSurface7_Unlock(lpDDSBack, NULL); + FCEUD_VerticalSync(); + if (eoptions & EO_BESTFIT && (bestfitRect.top || bestfitRect.left) && !vmod) + { + // blit with resizing + if (IDirectDrawSurface7_Blt(lpDDSVPrimary, &bestfitRect, lpDDSBack, &srect, DDBLT_ASYNC, 0) != DD_OK) { - if(status == DDERR_SURFACELOST) + ddrval = IDirectDrawSurface7_Blt(lpDDSVPrimary, &bestfitRect, lpDDSBack, &srect, DDBLT_WAIT, 0); + if(ddrval != DD_OK) { - RestoreLostOffscreenSurface(); - RestoreLostScreenSurface(); + if(ddrval == DDERR_SURFACELOST) + { + RestoreDD(1); + RestoreDD(0); } return; } } - - if(fillBorder) { - DDBLTFX blitfx = { sizeof(DDBLTFX) }; - if (FL_TEST(eoptions, EO_BGCOLOR)) { + // clear borders + if (eoptions & EO_BGCOLOR) + { // fill the surface using BG color from PPU unsigned char r, g, b; FCEUD_GetPalette(0x80 | PALRAM[0], &r, &g, &b); blitfx.dwFillColor = (r << 16) + (g << 8) + b; - } - else { + } else + { blitfx.dwFillColor = 0; } - - RECT borderRect; - if (pDstRect->top) { + static RECT borderRect; + if (bestfitRect.top) + { // upper border - borderRect = displayRect; - borderRect.bottom = displayRect.top + pDstRect->top; - IDirectDrawSurface7_Blt(lpScreenSurface, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + borderRect.top = drect.top; + borderRect.bottom = drect.top + bestfitRect.top; + borderRect.left = drect.left; + borderRect.right = drect.right; + IDirectDrawSurface7_Blt(lpDDSPrimary, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); // lower border - borderRect.top += pDstRect->bottom; - borderRect.bottom = displayRect.bottom; - IDirectDrawSurface7_Blt(lpScreenSurface, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + borderRect.top += bestfitRect.bottom; + borderRect.bottom = drect.bottom; + IDirectDrawSurface7_Blt(lpDDSPrimary, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); } - if (activeRect.left) + if (bestfitRect.left) { // left border - borderRect = displayRect; - borderRect.right = displayRect.left + pDstRect->left; - IDirectDrawSurface7_Blt(lpScreenSurface, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + borderRect.top = drect.top; + borderRect.bottom = drect.bottom; + borderRect.left = drect.left; + borderRect.right = drect.left + bestfitRect.left; + IDirectDrawSurface7_Blt(lpDDSPrimary, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); // right border - borderRect.left += activeRect.right; - borderRect.right = displayRect.right; - IDirectDrawSurface7_Blt(lpScreenSurface, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + borderRect.left += bestfitRect.right; + borderRect.right = drect.right; + IDirectDrawSurface7_Blt(lpDDSPrimary, &borderRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ASYNC, &blitfx); + } + } else + { + /* + if(veflags&2) + { + // clear screen surface (is that really necessary?) + if(IDirectDrawSurface7_Lock(lpDDSVPrimary, NULL, &ddsd, 0, NULL)==DD_OK) + { + memset(ddsd.lpSurface,0,ddsd.lPitch*vmodes[vmod].y); //mbg merge 7/17/06 removing dummyunion stuff + IDirectDrawSurface7_Unlock(lpDDSVPrimary, NULL); + veflags&=~2; + } + } + */ + // blit without resizing + if(IDirectDrawSurface7_Blt(lpDDSVPrimary, NULL, lpDDSBack, &srect, DDBLT_ASYNC,0)!=DD_OK) + { + ddrval=IDirectDrawSurface7_Blt(lpDDSVPrimary, NULL, lpDDSBack, &srect, DDBLT_WAIT,0); + if(ddrval!=DD_OK) + { + if(ddrval==DDERR_SURFACELOST) + { + RestoreDD(1); + RestoreDD(0); + } + return; } } } - else { - IDirectDrawSurface7_Unlock(targetScreenSurface, NULL); + } else + { + IDirectDrawSurface7_Unlock(lpDDSVPrimary, NULL); } - if(idxFullscreenSyncMode == SYNCMODE_DOUBLEBUF) { - IDirectDrawSurface7_Flip(lpScreenSurface,0,0); + if(fssync==3) + { + IDirectDrawSurface7_Flip(lpDDSPrimary,0,0); } } -void InitVideoDriver() { - SetVideoMode(); -} - -void ShutdownVideoDriver(void) +void ResetVideo(void) { ShowCursorAbs(1); KillBlitToHigh(); - if(ddraw7Handle) { - if(dispModeWasChanged) + if(lpDD7) + if(mustrestore) { - IDirectDraw7_RestoreDisplayMode(ddraw7Handle); - dispModeWasChanged = false; - } + IDirectDraw7_RestoreDisplayMode(lpDD7); + mustrestore=0; } - if(ddPaletteHandle) { - ddPaletteHandle->Release(); - ddPaletteHandle = NULL; - } - if(lpOffscreenSurface) { - lpOffscreenSurface->Release(); - lpOffscreenSurface = NULL; - } - if(lpScreenSurface) { - lpScreenSurface->Release(); - lpScreenSurface = NULL; - } - if(ddClipperHandle) { - ddClipperHandle->Release(); - ddClipperHandle = NULL; - } - if(ddraw7Handle) { - ddraw7Handle->Release(); - ddraw7Handle = NULL; - } + RELEASE(lpddpal); + RELEASE(lpDDSBack); + RELEASE(lpDDSPrimary); + RELEASE(lpClipper); + RELEASE(lpDD7); +} + +int specialmlut[5] = {1,2,2,3,3}; + +void ResetCustomMode() +{ + // use current display settings + if (!lpDD7) + return; + + vmdef *cmode = &vmodes[0]; + + DDSURFACEDESC2 temp_ddsd; + temp_ddsd.dwSize = sizeof(DDSURFACEDESC2); + IDirectDraw7_GetDisplayMode(lpDD7, &temp_ddsd); + if (FAILED(ddrval)) + return; + cmode->x = temp_ddsd.dwWidth; + cmode->y = temp_ddsd.dwHeight; + cmode->bpp = temp_ddsd.ddpfPixelFormat.dwRGBBitCount; + cmode->xscale = cmode->yscale = 1; + cmode->flags = VMDF_DXBLT|VMDF_STRFS; +} + +static int RecalcCustom(void) +{ + vmdef *cmode = &vmodes[0]; + + if ((cmode->x <= 0) || (cmode->y <= 0)) + ResetCustomMode(); + + if(cmode->flags&VMDF_STRFS) + { + cmode->flags |= VMDF_DXBLT; + } else if(cmode->xscale!=1 || cmode->yscale!=1 || cmode->special) + { + cmode->flags &= ~VMDF_DXBLT; + if(cmode->special) + { + int mult = specialmlut[cmode->special]; + + if(cmode->xscale < mult) + cmode->xscale = mult; + if(cmode->yscale < mult) + cmode->yscale = mult; + + if(cmode->xscale != mult || cmode->yscale != mult) + cmode->flags|=VMDF_DXBLT; + } + else + cmode->flags|=VMDF_DXBLT; + + + if(VNSWID*cmode->xscale>cmode->x) + { + if(cmode->special) + { + FCEUD_PrintError("Scaled width is out of range."); + return(0); + } + else + { + FCEUD_PrintError("Scaled width is out of range. Reverting to no horizontal scaling."); + cmode->xscale=1; + } + } + if(FSettings.TotalScanlines()*cmode->yscale>cmode->y) + { + if(cmode->special) + { + FCEUD_PrintError("Scaled height is out of range."); + return(0); + } + else + { + FCEUD_PrintError("Scaled height is out of range. Reverting to no vertical scaling."); + cmode->yscale=1; + } + } + + cmode->srect.left=VNSCLIP; + cmode->srect.top=FSettings.FirstSLine; + cmode->srect.right=256-VNSCLIP; + cmode->srect.bottom=FSettings.LastSLine+1; + + cmode->drect.top=(cmode->y-(FSettings.TotalScanlines()*cmode->yscale))>>1; + cmode->drect.bottom=cmode->drect.top+FSettings.TotalScanlines()*cmode->yscale; + + cmode->drect.left=(cmode->x-(VNSWID*cmode->xscale))>>1; + cmode->drect.right=cmode->drect.left+VNSWID*cmode->xscale; + } + + // -Video Modes Tag- + if((cmode->special == 1 || cmode->special == 4) && cmode->bpp == 8) + { + cmode->bpp = 32; + //FCEUD_PrintError("HQ2x/HQ3x requires 16bpp or 32bpp(best)."); + //return(0); + } + + if(cmode->xyflags&VMDF_STRFS)) + { + FCEUD_PrintError("Vertical resolution must not be less than the total number of drawn scanlines."); + return(0); + } + + return(1); } -//====================== -// Settings dialog -//====================== -// TODO: here's couple of things that should reside in now-empy gui.cpp BOOL SetDlgItemDouble(HWND hDlg, int item, double value) { char buf[16]; @@ -933,7 +1216,7 @@ double GetDlgItemDouble(HWND hDlg, int item) return(ret); } -static BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static char *vmstr[11]={ "Custom", @@ -954,18 +1237,24 @@ static BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA { case WM_INITDIALOG: { + /* + for(x=0;x<11;x++) + SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_MODE,CB_ADDSTRING,0,(LPARAM)(LPSTR)vmstr[x]); + SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_MODE,CB_SETCURSEL,vmod,(LPARAM)(LPSTR)0); + */ + SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_ADDSTRING,0,(LPARAM)(LPSTR)"8"); SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_ADDSTRING,0,(LPARAM)(LPSTR)"16"); SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_ADDSTRING,0,(LPARAM)(LPSTR)"24"); SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_ADDSTRING,0,(LPARAM)(LPSTR)"32"); - SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_SETCURSEL,(videoModes[vmodeIdx].bpp/8)-1,(LPARAM)(LPSTR)0); + SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_SETCURSEL,(vmodes[0].bpp>>3)-1,(LPARAM)(LPSTR)0); - SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_XRES,videoModes[vmodeIdx].width,0); - SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_YRES,videoModes[vmodeIdx].height,0); + SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_XRES,vmodes[0].x,0); + SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_YRES,vmodes[0].y,0); - //SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_XSCALE,videoModes[vmodeIdx].xscale,0); - //SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_YSCALE,videoModes[vmodeIdx].yscale,0); - //CheckRadioButton(hwndDlg,IDC_RADIO_SCALE,IDC_RADIO_STRETCH,FL_TEST(videoModes[vmodeIdx].flags, VIDEOMODEFLAG_STRFS)?IDC_RADIO_STRETCH:IDC_RADIO_SCALE); + //SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_XSCALE,vmodes[0].xscale,0); + //SetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_YSCALE,vmodes[0].yscale,0); + //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"}; @@ -976,8 +1265,8 @@ static BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_WIN,CB_ADDSTRING,0,(LPARAM)(LPSTR)str[x]); } - SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_SCALER_FS, CB_SETCURSEL, videoModes[vmodeIdx].filter, (LPARAM)(LPSTR)0); - SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_SCALER_WIN, CB_SETCURSEL, idxFilterModeWindowed, (LPARAM)(LPSTR)0); + SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_SCALER_FS, CB_SETCURSEL, vmodes[0].special, (LPARAM)(LPSTR)0); + SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_SCALER_WIN, CB_SETCURSEL, winspecial, (LPARAM)(LPSTR)0); // Direct Draw modes SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_DIRECTDRAW_WIN, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"No hardware acceleration"); @@ -992,31 +1281,31 @@ static BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_DIRECTDRAW_FS, CB_SETCURSEL, directDrawModeFullscreen, (LPARAM)(LPSTR)0); - if(FL_TEST(eoptions, EO_FSAFTERLOAD)) + if(eoptions&EO_FSAFTERLOAD) CheckDlgButton(hwndDlg,IDC_VIDEOCONFIG_AUTO_FS,BST_CHECKED); - if(FL_TEST(eoptions, EO_HIDEMOUSE)) + if(eoptions&EO_HIDEMOUSE) CheckDlgButton(hwndDlg,IDC_VIDEOCONFIG_HIDEMOUSE,BST_CHECKED); - if(FL_TEST(eoptions, EO_CLIPSIDES)) + if(eoptions&EO_CLIPSIDES) CheckDlgButton(hwndDlg,IDC_VIDEOCONFIG_CLIPSIDES,BST_CHECKED); - if(FL_TEST(eoptions, EO_BESTFIT)) + if(eoptions&EO_BESTFIT) CheckDlgButton(hwndDlg, IDC_VIDEOCONFIG_BESTFIT, BST_CHECKED); - if(FL_TEST(eoptions, EO_BGCOLOR)) + if(eoptions&EO_BGCOLOR) CheckDlgButton(hwndDlg,IDC_VIDEOCONFIG_CONSOLE_BGCOLOR,BST_CHECKED); - if(FL_TEST(eoptions, EO_SQUAREPIXELS)) + if(eoptions&EO_SQUAREPIXELS) CheckDlgButton(hwndDlg, IDC_VIDEOCONFIG_SQUARE_PIXELS, BST_CHECKED); - if(FL_TEST(eoptions, EO_TVASPECT)) + if(eoptions&EO_TVASPECT) CheckDlgButton(hwndDlg, IDC_VIDEOCONFIG_TVASPECT, BST_CHECKED); - if(FL_TEST(eoptions, EO_FORCEISCALE)) + if(eoptions&EO_FORCEISCALE) CheckDlgButton(hwndDlg,IDC_FORCE_INT_VIDEO_SCALARS,BST_CHECKED); - if(FL_TEST(eoptions, EO_FORCEASPECT)) + if(eoptions&EO_FORCEASPECT) CheckDlgButton(hwndDlg,IDC_FORCE_ASPECT_CORRECTION,BST_CHECKED); SetDlgItemInt(hwndDlg,IDC_SCANLINE_FIRST_NTSC,srendlinen,0); @@ -1041,10 +1330,10 @@ static BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_FS,CB_ADDSTRING,0,(LPARAM)(LPSTR)"Lazy wait for VBlank"); SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_FS,CB_ADDSTRING,0,(LPARAM)(LPSTR)"Double Buffering"); - SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_WIN,CB_SETCURSEL,idxWindowedSyncMode,(LPARAM)(LPSTR)0); - SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_FS,CB_SETCURSEL,idxFullscreenSyncMode,(LPARAM)(LPSTR)0); + SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_WIN,CB_SETCURSEL,winsync,(LPARAM)(LPSTR)0); + SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_FS,CB_SETCURSEL,fssync,(LPARAM)(LPSTR)0); - if(FL_TEST(eoptions, EO_NOSPRLIM)) + if(eoptions&EO_NOSPRLIM) CheckDlgButton(hwndDlg,IDC_VIDEOCONFIG_NO8LIM,BST_CHECKED); char buf[1024] = "Full Screen"; @@ -1053,11 +1342,11 @@ static BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA { strcat(buf, " ("); strcat(buf, GetKeyComboName(c)); - if (GetIsFullscreenOnDoubleclick()) + if (fullscreenByDoubleclick) strcat(buf, " or double-click)"); else strcat(buf, ")"); - } else if (GetIsFullscreenOnDoubleclick()) + } else if (fullscreenByDoubleclick) { strcat(buf, " (double-click anywhere)"); } @@ -1075,20 +1364,39 @@ gornk: if(IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_CLIPSIDES)==BST_CHECKED) { - FL_SET(eoptions, EO_CLIPSIDES); + eoptions|=EO_CLIPSIDES; ClipSidesOffset = 8; } else { - FL_CLEAR(eoptions, EO_CLIPSIDES); + eoptions&=~EO_CLIPSIDES; ClipSidesOffset = 0; } - FL_FROMBOOL(eoptions, EO_BESTFIT, IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_BESTFIT) == BST_CHECKED); - FL_FROMBOOL(eoptions, EO_BGCOLOR, IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_CONSOLE_BGCOLOR) == BST_CHECKED); - FL_FROMBOOL(eoptions, EO_SQUAREPIXELS, IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_SQUARE_PIXELS) == BST_CHECKED); - FL_FROMBOOL(eoptions, EO_TVASPECT, IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_TVASPECT) == BST_CHECKED); - FL_FROMBOOL(eoptions, EO_NOSPRLIM, IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_NO8LIM) == BST_CHECKED); + if (IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_BESTFIT) == BST_CHECKED) + eoptions |= EO_BESTFIT; + else + eoptions &= ~EO_BESTFIT; + + if (IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_CONSOLE_BGCOLOR) == BST_CHECKED) + eoptions |= EO_BGCOLOR; + else + eoptions &= ~EO_BGCOLOR; + + if (IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_SQUARE_PIXELS) == BST_CHECKED) + eoptions |= EO_SQUAREPIXELS; + else + eoptions &= ~EO_SQUAREPIXELS; + + if (IsDlgButtonChecked(hwndDlg, IDC_VIDEOCONFIG_TVASPECT) == BST_CHECKED) + eoptions |= EO_TVASPECT; + else + eoptions &= ~EO_TVASPECT; + + if(IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_NO8LIM)==BST_CHECKED) + eoptions|=EO_NOSPRLIM; + else + eoptions&=~EO_NOSPRLIM; srendlinen=GetDlgItemInt(hwndDlg,IDC_SCANLINE_FIRST_NTSC,0,0); erendlinen=GetDlgItemInt(hwndDlg,IDC_SCANLINE_LAST_NTSC,0,0); @@ -1104,33 +1412,45 @@ gornk: UpdateRendBounds(); - videoModes[0].width=GetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_XRES,0,0); - videoModes[0].height=GetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_YRES,0,0); - videoModes[0].bpp=(SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_GETCURSEL,0,(LPARAM)(LPSTR)0)+1)<<3; + /* + if(IsDlgButtonChecked(hwndDlg,IDC_RADIO_STRETCH)==BST_CHECKED) + vmodes[0].flags |= VMDF_STRFS|VMDF_DXBLT; + else + vmodes[0].flags &= ~(VMDF_STRFS|VMDF_DXBLT); + vmod=SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_MODE,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); + */ + vmodes[0].x=GetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_XRES,0,0); + vmodes[0].y=GetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_YRES,0,0); + vmodes[0].bpp=(SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_BPP,CB_GETCURSEL,0,(LPARAM)(LPSTR)0)+1)<<3; - videoModes[0].filter = static_cast(SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_FS,CB_GETCURSEL,0,(LPARAM)(LPSTR)0)); + //vmodes[0].xscale=GetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_XSCALE,0,0); + //vmodes[0].yscale=GetDlgItemInt(hwndDlg,IDC_VIDEOCONFIG_YSCALE,0,0); + vmodes[0].special=SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_FS,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - idxFilterModeWindowed = static_cast(SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_SCALER_WIN, CB_GETCURSEL, 0, (LPARAM)(LPSTR)0)); + winspecial = SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_SCALER_WIN, CB_GETCURSEL, 0, (LPARAM)(LPSTR)0); + directDrawModeWindowed = SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_DIRECTDRAW_WIN, CB_GETCURSEL, 0, (LPARAM)(LPSTR)0) % DIRECTDRAW_MODES_TOTAL; + directDrawModeFullscreen = SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_DIRECTDRAW_FS, CB_GETCURSEL, 0, (LPARAM)(LPSTR)0) % DIRECTDRAW_MODES_TOTAL; - directDrawModeWindowed = static_cast(SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_DIRECTDRAW_WIN, CB_GETCURSEL, 0, (LPARAM)(LPSTR)0)); - if(directDrawModeWindowed >= DIRECTDRAW_MODES_TOTAL) { - FCEU_printf("DirectDraw windowed mode index out of bounds.\n"); - directDrawModeWindowed = DIRECTDRAW_MODE_SOFTWARE; - } + if(IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_FS)==BST_CHECKED) + fullscreen=1; + else + fullscreen=0; - directDrawModeFullscreen = static_cast(SendDlgItemMessage(hwndDlg, IDC_VIDEOCONFIG_DIRECTDRAW_FS, CB_GETCURSEL, 0, (LPARAM)(LPSTR)0)); - if(directDrawModeFullscreen >= DIRECTDRAW_MODES_TOTAL) { - FCEU_printf("DirectDraw fullscreen mode index out of bounds.\n"); - directDrawModeFullscreen = DIRECTDRAW_MODE_SOFTWARE; - } + if(IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_AUTO_FS)==BST_CHECKED) + eoptions|=EO_FSAFTERLOAD; + else + eoptions&=~EO_FSAFTERLOAD; - SetIsFullscreen( IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_FS)==BST_CHECKED ); + if(IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_HIDEMOUSE)==BST_CHECKED) + eoptions|=EO_HIDEMOUSE; + else + eoptions&=~EO_HIDEMOUSE; - FL_FROMBOOL(eoptions, EO_FSAFTERLOAD, IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_AUTO_FS)==BST_CHECKED); - FL_FROMBOOL(eoptions, EO_HIDEMOUSE, IsDlgButtonChecked(hwndDlg,IDC_VIDEOCONFIG_HIDEMOUSE)==BST_CHECKED); - - FL_FROMBOOL(eoptions, EO_FORCEISCALE, IsDlgButtonChecked(hwndDlg,IDC_FORCE_INT_VIDEO_SCALARS)==BST_CHECKED); - FL_FROMBOOL(eoptions, EO_FORCEASPECT, IsDlgButtonChecked(hwndDlg,IDC_FORCE_ASPECT_CORRECTION)==BST_CHECKED); + eoptions &= ~(EO_FORCEISCALE | EO_FORCEASPECT); + if(IsDlgButtonChecked(hwndDlg,IDC_FORCE_INT_VIDEO_SCALARS)==BST_CHECKED) + eoptions|=EO_FORCEISCALE; + if(IsDlgButtonChecked(hwndDlg,IDC_FORCE_ASPECT_CORRECTION)==BST_CHECKED) + eoptions|=EO_FORCEASPECT; winsizemulx = GetDlgItemDouble(hwndDlg, IDC_WINSIZE_MUL_X); winsizemuly = GetDlgItemDouble(hwndDlg, IDC_WINSIZE_MUL_Y); @@ -1142,8 +1462,8 @@ gornk: if (tvAspectY < 0.1) tvAspectY = 0.1; - idxWindowedSyncMode = static_cast(SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_WIN,CB_GETCURSEL,0,(LPARAM)(LPSTR)0)); - idxFullscreenSyncMode = static_cast(SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_FS,CB_GETCURSEL,0,(LPARAM)(LPSTR)0)); + winsync=SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_WIN,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); + fssync=SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SYNC_METHOD_FS,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); EndDialog(hwndDlg,0); break; } @@ -1151,143 +1471,47 @@ gornk: return 0; } -void DoVideoConfigFix() +void SetFSVideoMode() { - FCEUI_DisableSpriteLimitation(FL_TEST(eoptions, EO_NOSPRLIM)); + changerecursive=1; + if(!SetVideoMode(1)) + SetVideoMode(0); + changerecursive=0; +} + + +void DoVideoConfigFix(void) +{ + FCEUI_DisableSpriteLimitation(eoptions&EO_NOSPRLIM); UpdateRendBounds(); } -//Shows the Video configuration dialog. -void ShowConfigVideoDialog(void) +void PushCurrentVideoSettings() { - if ((videoModes[0].width <= 0) || (videoModes[0].height <= 0)) - ResetVideoModeParams(); - DialogBox(fceu_hInstance, "VIDEOCONFIG", hAppWnd, VideoConCallB); - DoVideoConfigFix(); - FCEUD_VideoChanged(); -} - - -//====================== -// Get/Set -//====================== - -RECT GetActiveRect() { - return activeRect; -} - -PALETTEENTRY* GetPalette() { - return color_palette; -} - -bool GetIsFullscreen() { - return (fullscreenActual != 0); -} - -void SetIsFullscreen(bool f) { - fullscreenDesired = f; -} - -VSYNCMODE GetWindowedSyncModeIdx() { - return idxWindowedSyncMode; -} - -void SetWindowedSyncModeIdx(VSYNCMODE idx) { - idxWindowedSyncMode = idx; -} - - -//====================== -// FCEUD -//====================== -//draw input aids if we are fullscreen -bool FCEUD_ShouldDrawInputAids() -{ - return GetIsFullscreen(); -} - -//static uint8 *XBSave; -void FCEUD_BlitScreen(uint8 *XBuf) -{ - if(fullscreenActual) + if(fullscreen) { - BlitScreenFull(XBuf); + SetFSVideoMode(); } else { - if(!windowedfailed) - BlitScreenWindow(XBuf); + changerecursive = 1; + SetVideoMode(0); + changerecursive = 0; + //SetMainWindowStuff(); // it's already called inside SetVideoMode() } } +//Shows the Video configuration dialog. +void ConfigVideo(void) +{ + if ((vmodes[0].x <= 0) || (vmodes[0].y <= 0)) + ResetCustomMode(); + DialogBox(fceu_hInstance, "VIDEOCONFIG", hAppWnd, VideoConCallB); + DoVideoConfigFix(); + PushCurrentVideoSettings(); +} + void FCEUD_VideoChanged() { - changerecursive = 1; - if(!SetVideoMode()) { - SetIsFullscreen(false); - SetVideoMode(); - } - changerecursive = 0; -} - -void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b) -{ - if (force_grayscale) - { - // convert the palette entry to grayscale - int gray = ((float)r * 0.299 + (float)g * 0.587 + (float)b * 0.114); - color_palette[index].peRed = gray; - color_palette[index].peGreen = gray; - color_palette[index].peBlue = gray; - } else - { - color_palette[index].peRed = r; - color_palette[index].peGreen = g; - color_palette[index].peBlue = b; - } - updateDDPalette = true; -} - -void FCEUD_GetPalette(unsigned char i, unsigned char *r, unsigned char *g, unsigned char *b) -{ - *r=color_palette[i].peRed; - *g=color_palette[i].peGreen; - *b=color_palette[i].peBlue; -} - - -bool& _FIXME_getFullscreenVar() { - return fullscreenActual; // provide config with actual fullscreen state, not desired -} - -int& _FIXME_getVModeIdxVar() { - return vmodeIdx; -} - -VSYNCMODE& _FIXME_getFullscreenSyncModeIdxVar() { - return idxFullscreenSyncMode; -} - -VSYNCMODE& _FIXME_getWindowedSyncModeIdxVar() { - return idxWindowedSyncMode; -} - -VFILTER& _FIXME_getFilterModeWindowedIdxVar() { - return idxFilterModeWindowed; -} - -int& _FIXME_getFilterOptionVar() { - return ntscFilterOption; -} - -DIRECTDRAW_MODE& _FIXME_getDDrawModeWindowedVar() { - return directDrawModeWindowed; -} - -DIRECTDRAW_MODE& _FIXME_getDDrawModeFullscreenVar() { - return directDrawModeFullscreen; -} - -VideoMode& _FIXME_getCustomVideoModeVar() { - return videoModes[0]; -} + PushCurrentVideoSettings(); +} \ No newline at end of file diff --git a/trunk/src/drivers/win/video.h b/trunk/src/drivers/win/video.h index 367bd35e..201e5f44 100644 --- a/trunk/src/drivers/win/video.h +++ b/trunk/src/drivers/win/video.h @@ -1,96 +1,71 @@ #ifndef WIN_VIDEO_H #define WIN_VIDEO_H -#include -#include "types.h" +#include "common.h" -typedef enum +// I like hacks. +#define uint8 __UNO492032 +#include +#include "ddraw.h" +#undef LPCWAVEFORMATEX +#include "dsound.h" +#include "dinput.h" +#include +#include // For directories configuration dialog. +#undef uint8 + +#include "main.h" +#include "window.h" + +enum DIRECTDRAW_MODES { - DIRECTDRAW_MODE_SOFTWARE = 0, // all features are emulated in software - DIRECTDRAW_MODE_SURFACE_IN_RAM, // place offscreen surface in RAM rather than in VRAM; may or may not use hardware acceleration - DIRECTDRAW_MODE_FULL, // use available hardware features, emulate the rest + DIRECTDRAW_MODE_SOFTWARE, + DIRECTDRAW_MODE_SURFACE_IN_RAM, + DIRECTDRAW_MODE_FULL, // ... DIRECTDRAW_MODES_TOTAL -} DIRECTDRAW_MODE; +}; -#define VIDEOMODEFLAG_DXBLT 1 -#define VIDEOMODEFLAG_STRFS 2 +#define VF_DDSTRETCHED 1 -typedef enum -{ - FILTER_NONE = 0, - FILTER_HQ2X, - FILTER_SCALE2X, - FILTER_NTSC2X, - FILTER_HQ3X, - FILTER_SCALE3X -} VFILTER; +#define VEF_LOSTSURFACE 1 +#define VEF____INTERNAL 2 + +#define VMDF_DXBLT 1 +#define VMDF_STRFS 2 typedef struct { - int width; - int height; + int x; + int y; int bpp; int flags; int xscale; int yscale; - RECT srcRect; - RECT dstRect; - VFILTER filter; -} VideoMode; + RECT srect; + RECT drect; + int special; +} vmdef; -typedef enum { - SYNCMODE_NONE = 0, - SYNCMODE_WAIT, - SYNCMODE_LAZYWAIT, - SYNCMODE_DOUBLEBUF -} VSYNCMODE; +// left, top, right, bottom +extern vmdef vmodes[11]; +extern int winspecial; +extern int NTSCwinspecial; -void InitVideoDriver(void); -void ShutdownVideoDriver(); +extern int directDrawModeWindowed; +extern int directDrawModeFullscreen; -// Recalculate blit rectangle within window of given size -void OnWindowSizeChange(int width, int height); +extern int fssync; +extern int winsync; -// Get current blit rectangle -RECT GetActiveRect(void); - -// Get driver palette -PALETTEENTRY* GetPalette(void); - -// Returns true when in fullscreen mode, false when in windowed -bool GetIsFullscreen(void); - -// Set fullscreen mode flag -// FCEUD_VideoChanged() must be called in order to make value take effect -void SetIsFullscreen(bool f); - -VSYNCMODE GetWindowedSyncModeIdx(void); -void SetWindowedSyncModeIdx(VSYNCMODE idx); - - -// Bring up the Video configuration dialog -void ShowConfigVideoDialog(); - -// (Re)apply render lines and sprite limitation to FCE -void DoVideoConfigFix(); - - -// Implements FCEUD requirements -bool FCEUD_ShouldDrawInputAids(void); +void SetFSVideoMode(); void FCEUD_BlitScreen(uint8 *XBuf); -void FCEUD_VideoChanged(void); // this one should be declared here -void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b); -void FCEUD_GetPalette(unsigned char i, unsigned char *r, unsigned char *g, unsigned char *b); - - -// see win/config.h -bool& _FIXME_getFullscreenVar(void); -int& _FIXME_getVModeIdxVar(void); -VSYNCMODE& _FIXME_getFullscreenSyncModeIdxVar(void); -VSYNCMODE& _FIXME_getWindowedSyncModeIdxVar(void); -VFILTER& _FIXME_getFilterModeWindowedIdxVar(void); -int& _FIXME_getFilterOptionVar(void); -DIRECTDRAW_MODE& _FIXME_getDDrawModeWindowedVar(void); -DIRECTDRAW_MODE& _FIXME_getDDrawModeFullscreenVar(void); -VideoMode& _FIXME_getCustomVideoModeVar(void); +void ConfigVideo(); +void recalculateBestFitRect(int width, int height); +int SetVideoMode(int fs); +void DoVideoConfigFix(); +void FCEUD_BlitScreen(uint8 *XBuf); +void ResetVideo(); +void SetFSVideoMode(); +void PushCurrentVideoSettings(); +void ResetCustomMode(); #endif diff --git a/trunk/src/drivers/win/window.cpp b/trunk/src/drivers/win/window.cpp index 536add32..a2e16e88 100644 --- a/trunk/src/drivers/win/window.cpp +++ b/trunk/src/drivers/win/window.cpp @@ -83,6 +83,8 @@ extern PLAYBACK playback; #include "Win32InputBox.h" extern int32 fps_scale_unpaused; +//extern void ToggleFullscreen(); + using namespace std; //----Context Menu - Some dynamically added menu items @@ -993,7 +995,7 @@ void HideFWindow(int h) //Toggles the display status of the main menu. void ToggleHideMenu(void) { - if(!GetIsFullscreen() && !nofocus && (GameInfo || tog)) + if(!fullscreen && !nofocus && (GameInfo || tog)) { tog ^= 1; HideMenu(tog); @@ -1032,7 +1034,7 @@ bool ALoad(const char *nameo, char* innerFilename, bool silent) UpdateCheckedMenuItems(); - FCEUD_VideoChanged(); + PushCurrentVideoSettings(); std::string recentFileName = nameo; if(GameInfo->archiveFilename && GameInfo->archiveCount>1) @@ -1051,10 +1053,7 @@ bool ALoad(const char *nameo, char* innerFilename, bool silent) if(eoptions & EO_FSAFTERLOAD) { - changerecursive=1; - SetIsFullscreen(true); - FCEUD_VideoChanged(); - changerecursive=0; + SetFSVideoMode(); } @@ -1120,7 +1119,7 @@ void LoadNewGamey(HWND hParent, const char *initialdir) void GetMouseData(uint32 (&md)[3]) { - RECT bestfitRect = GetActiveRect(); + extern RECT bestfitRect; double screen_width = VNSWID; double screen_height = FSettings.TotalScanlines(); @@ -1272,10 +1271,8 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) { if (fullscreenByDoubleclick) { - changerecursive=1; - SetIsFullscreen(!GetIsFullscreen()); - FCEUD_VideoChanged(); - changerecursive=0; + extern void ToggleFullscreen(); + ToggleFullscreen(); return 0; } else { @@ -1382,7 +1379,7 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) goto proco; case WM_SIZE: - if (!GetIsFullscreen() && !changerecursive && !windowedfailed) + if (!fullscreen && !changerecursive && !windowedfailed) { switch(wParam) { @@ -1442,7 +1439,7 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) //break; goto proco; case WM_DISPLAYCHANGE: - if(!GetIsFullscreen() && !changerecursive) + if(!fullscreen && !changerecursive) vchanged=1; goto proco; case WM_DROPFILES: @@ -1973,7 +1970,7 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) FCEUI_SetVidSystem(pal_emulation); RefreshThrottleFPS(); UpdateCheckedMenuItems(); - FCEUD_VideoChanged(); + PushCurrentVideoSettings(); break; case MENU_DIRECTORIES: ConfigDirectories(); @@ -1997,7 +1994,7 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) ConfigTiming(); break; case MENU_VIDEO: - ShowConfigVideoDialog(); + ConfigVideo(); break; case MENU_HOTKEYS: MapInput(); @@ -2295,14 +2292,14 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) { if(GameInfo && ((InputType[2]==SIFC_FKB) || (InputType[2]==SIFC_SUBORKB) || (InputType[2]==SIFC_PEC586KB)) && cidisabled) break; - if(lParam == VK_RETURN || GetIsFullscreen() || tog) break; + if(lParam == VK_RETURN || fullscreen || tog) break; } goto proco; case WM_SYSKEYDOWN: if(GameInfo && ((InputType[2]==SIFC_FKB) || (InputType[2]==SIFC_SUBORKB) || (InputType[2]==SIFC_PEC586KB)) && cidisabled) break; // Hopefully this won't break DInput... - if(GetIsFullscreen() || tog) + if(fullscreen || tog) { if(wParam==VK_MENU) break; @@ -2465,10 +2462,9 @@ void FixWXY(int pref, bool shift_held) void UpdateFCEUWindow(void) { - if(vchanged && !GetIsFullscreen() && !changerecursive && !nofocus) + if(vchanged && !fullscreen && !changerecursive && !nofocus) { - SetIsFullscreen(false); - FCEUD_VideoChanged(); + SetVideoMode(0); vchanged = 0; } @@ -2609,13 +2605,11 @@ void SetMainWindowStuff() ShowWindow(hAppWnd, SW_SHOWNORMAL); } - // removed check for EO_BESTFIT flag - // OnWindowSizeChange() now is a general purpose window resize handler on video driver side - if (!windowedfailed) + if (eoptions & EO_BESTFIT && !windowedfailed) { RECT client_recr; GetClientRect(hAppWnd, &client_recr); - OnWindowSizeChange(client_recr.right - client_recr.left, client_recr.bottom - client_recr.top); + recalculateBestFitRect(client_recr.right - client_recr.left, client_recr.bottom - client_recr.top); } } @@ -2983,10 +2977,6 @@ void UpdateMenuHotkeys() ChangeMenuItemText(MENU_CDLOGGER, combined); } -bool GetIsFullscreenOnDoubleclick() { - return fullscreenByDoubleclick; -} - //This function is for the context menu item Save Movie As... //It gets a filename from the user then calls CreateMovie() void SaveMovieAs() diff --git a/trunk/src/drivers/win/window.h b/trunk/src/drivers/win/window.h index ddc49f3c..b600c317 100644 --- a/trunk/src/drivers/win/window.h +++ b/trunk/src/drivers/win/window.h @@ -40,10 +40,6 @@ void GetMouseData(uint32 (&md)[3]); //void ChangeMenuItemText(int menuitem, string text); void UpdateMenuHotkeys(); -// Returns true if fullscreen via double click is enabled -// TODO: replace fullscreenByDoubleclick references with a call to this -bool GetIsFullscreenOnDoubleclick(void); - template inline std::string GetDlgItemText(HWND hDlg, int nIDDlgItem) { char buf[BUFSIZE]; diff --git a/trunk/src/input.cpp b/trunk/src/input.cpp index 3a403452..a88ea165 100644 --- a/trunk/src/input.cpp +++ b/trunk/src/input.cpp @@ -38,7 +38,6 @@ #ifdef WIN32 #include "drivers/win/main.h" -#include "drivers/win/video.h" #include "drivers/win/memwatch.h" #include "drivers/win/cheat.h" #include "drivers/win/debugger.h" @@ -1182,13 +1181,15 @@ static void FCEUI_DoExit(void) void ToggleFullscreen() { #ifdef WIN32 + extern int SetVideoMode(int fs); //adelikat: Yeah, I know, hacky extern void UpdateCheckedMenuItems(); UpdateCheckedMenuItems(); - changerecursive=1; - SetIsFullscreen(!GetIsFullscreen()); - FCEUD_VideoChanged(); + + int oldmode = fullscreen; + if(!SetVideoMode(oldmode ^ 1)) + SetVideoMode(oldmode); changerecursive=0; #endif } diff --git a/trunk/src/state.cpp b/trunk/src/state.cpp index f4da8e0c..30593544 100644 --- a/trunk/src/state.cpp +++ b/trunk/src/state.cpp @@ -47,7 +47,6 @@ #include "drivers/win/main.h" #include "drivers/win/ram_search.h" #include "drivers/win/ramwatch.h" -#include "drivers/win/video.h" #endif #include @@ -244,11 +243,7 @@ static bool ReadStateChunk(EMUFILE* is, SFORMAT *sf, int size) static int read_sfcpuc=0, read_snd=0; -#ifndef WIN32 -// included corresponding header on Windows, no longer needed -// TODO do the same for SDL and remove declaration completely void FCEUD_BlitScreen(uint8 *XBuf); //mbg merge 7/17/06 YUCKY had to add -#endif void UpdateFCEUWindow(void); //mbg merge 7/17/06 YUCKY had to add static bool ReadStateChunks(EMUFILE* is, int32 totalsize) { diff --git a/trunk/src/utils/bitflags.h b/trunk/src/utils/bitflags.h deleted file mode 100644 index c198766a..00000000 --- a/trunk/src/utils/bitflags.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef BITFLAGS_H -#define BITFLAGS_H - -// Flag test / set / clear macros for convenience and clarity -#define FL_TEST(var, mask) (var & mask) -#define FL_SET(var, mask) (var |= mask) -#define FL_CLEAR(var, mask) (var &= ~mask) -#define FL_FROMBOOL(var, mask, b) (var = (b)? var|mask:var&(~mask)) - -#endif // BITFLAGS_H