2018-11-15 23:31:39 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
2010-09-25 15:46:12 +00:00
|
|
|
|
|
|
|
/* win32_display.cpp
|
|
|
|
Contains most of the display related functions of the win32 port.
|
|
|
|
Delegates relevant function calls to the currently selected IS9xDisplayOutput object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../snes9x.h"
|
|
|
|
#include "../ppu.h"
|
|
|
|
#include "../font.h"
|
|
|
|
#include "wsnes9x.h"
|
|
|
|
#include "win32_display.h"
|
|
|
|
#include "CDirect3D.h"
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
#include "CDirectDraw.h"
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 17:35:19 +00:00
|
|
|
#include "COpenGL.h"
|
2023-01-31 23:18:07 +00:00
|
|
|
#include "CVulkan.h"
|
2010-09-25 15:46:12 +00:00
|
|
|
#include "IS9xDisplayOutput.h"
|
|
|
|
|
|
|
|
#include "../filter/hq2x.h"
|
|
|
|
#include "../filter/2xsai.h"
|
2018-05-24 23:52:43 +00:00
|
|
|
#include "../apu/apu.h"
|
2010-09-25 15:46:12 +00:00
|
|
|
|
|
|
|
// available display output methods
|
|
|
|
CDirect3D Direct3D;
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
CDirectDraw DirectDraw;
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 17:35:19 +00:00
|
|
|
COpenGL OpenGL;
|
2023-01-31 23:18:07 +00:00
|
|
|
CVulkan VulkanDriver;
|
2011-01-30 12:32:06 +00:00
|
|
|
SSurface Src = {0};
|
2011-02-12 17:13:22 +00:00
|
|
|
extern BYTE *ScreenBufferBlend;
|
2010-09-25 15:46:12 +00:00
|
|
|
|
2019-03-04 20:40:32 +00:00
|
|
|
typedef HRESULT (*DWMFLUSHPROC)();
|
|
|
|
typedef HRESULT (*DWMISCOMPOSITIONENABLEDPROC)(BOOL *);
|
|
|
|
DWMFLUSHPROC DwmFlushProc = NULL;
|
|
|
|
DWMISCOMPOSITIONENABLEDPROC DwmIsCompositionEnabledProc = NULL;
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
// Interface used to access the display output
|
2023-03-15 20:47:35 +00:00
|
|
|
IS9xDisplayOutput *S9xDisplayOutput=&Direct3D;
|
2010-09-25 15:46:12 +00:00
|
|
|
|
|
|
|
#ifndef max
|
|
|
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
#ifndef min
|
|
|
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool8 S9xDeinitUpdate (int, int);
|
2011-02-12 15:32:53 +00:00
|
|
|
void DoAVIVideoFrame();
|
2010-09-25 15:46:12 +00:00
|
|
|
|
2018-11-01 21:36:31 +00:00
|
|
|
// cut off both top and bottom if overscan is disabled and game outputs extended height,
|
|
|
|
// center image if overscan is enabled and game outputs regular height
|
|
|
|
static void CheckOverscanOffset()
|
|
|
|
{
|
|
|
|
int lines_to_skip = 0;
|
2023-05-04 20:55:11 +00:00
|
|
|
if (!Settings.ShowOverscan)
|
2018-11-01 21:36:31 +00:00
|
|
|
{
|
|
|
|
if (Src.Height == SNES_HEIGHT_EXTENDED)
|
|
|
|
lines_to_skip = 7;
|
|
|
|
else if (Src.Height == SNES_HEIGHT_EXTENDED << 1)
|
2018-11-01 22:21:54 +00:00
|
|
|
lines_to_skip = 14;
|
2018-11-01 21:36:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Src.Height == SNES_HEIGHT)
|
|
|
|
lines_to_skip = -8;
|
|
|
|
else if (Src.Height == SNES_HEIGHT << 1)
|
|
|
|
lines_to_skip = -16;
|
|
|
|
}
|
|
|
|
|
|
|
|
Src.Surface = (BYTE*)(GFX.Screen + lines_to_skip * (int)GFX.RealPPL);
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
/* WinRefreshDisplay
|
|
|
|
repeats the last rendered frame
|
|
|
|
*/
|
|
|
|
void WinRefreshDisplay(void)
|
|
|
|
{
|
2011-02-12 17:13:22 +00:00
|
|
|
if(!Src.Width)
|
|
|
|
return;
|
|
|
|
|
2018-11-01 21:36:31 +00:00
|
|
|
CheckOverscanOffset();
|
|
|
|
|
2011-01-30 12:32:06 +00:00
|
|
|
SelectRenderMethod ();
|
2011-02-12 17:13:22 +00:00
|
|
|
|
|
|
|
S9xDisplayOutput->Render(Src);
|
|
|
|
GUI.FlipCounter++;
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WinChangeWindowSize(unsigned int newWidth, unsigned int newHeight)
|
|
|
|
{
|
2023-03-15 20:47:35 +00:00
|
|
|
S9xDisplayOutput->ChangeRenderSize(newWidth,newHeight);
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
/* WinDisplayReset
|
|
|
|
initializes the currently selected display output and
|
|
|
|
reinitializes the core graphics rendering
|
|
|
|
-----
|
|
|
|
returns true if successful, false otherwise
|
|
|
|
*/
|
|
|
|
bool WinDisplayReset(void)
|
|
|
|
{
|
2023-03-24 19:39:31 +00:00
|
|
|
const TCHAR* driverNames[] = { TEXT("DirectDraw"), TEXT("Direct3D"), TEXT("OpenGL"), TEXT("Vulkan") };
|
2023-03-15 20:54:43 +00:00
|
|
|
static bool VulkanUsed = false;
|
|
|
|
static bool OpenGLUsed = false;
|
2023-03-15 20:47:35 +00:00
|
|
|
S9xDisplayOutput->DeInitialize();
|
|
|
|
|
|
|
|
switch(GUI.outputMethod) {
|
2010-09-25 17:35:19 +00:00
|
|
|
default:
|
2010-09-25 15:46:12 +00:00
|
|
|
case DIRECT3D:
|
|
|
|
S9xDisplayOutput = &Direct3D;
|
|
|
|
break;
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
case DIRECTDRAW:
|
|
|
|
S9xDisplayOutput = &DirectDraw;
|
|
|
|
break;
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 17:35:19 +00:00
|
|
|
case OPENGL:
|
2023-03-15 20:54:43 +00:00
|
|
|
if (VulkanUsed)
|
|
|
|
{
|
|
|
|
MessageBox(GUI.hWnd, TEXT("Changing to OpenGL requires a restart if you've already used Vulkan"), TEXT("Snes9x Display Driver"), MB_OK);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-25 17:35:19 +00:00
|
|
|
S9xDisplayOutput = &OpenGL;
|
|
|
|
break;
|
2023-01-31 23:18:07 +00:00
|
|
|
case VULKAN:
|
2023-03-15 20:54:43 +00:00
|
|
|
if (OpenGLUsed)
|
|
|
|
{
|
|
|
|
MessageBox(GUI.hWnd, TEXT("Changing to Vulkan requires a restart if you've already used OpenGL"), TEXT("Snes9x Display Driver"), MB_OK);
|
|
|
|
break;
|
|
|
|
}
|
2023-01-31 23:18:07 +00:00
|
|
|
S9xDisplayOutput = &VulkanDriver;
|
|
|
|
break;
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
2023-02-20 21:15:38 +00:00
|
|
|
|
|
|
|
bool initialized = S9xDisplayOutput->Initialize(GUI.hWnd);
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
S9xDisplayOutput->DeInitialize();
|
|
|
|
Sleep(500);
|
2023-03-24 19:39:31 +00:00
|
|
|
|
|
|
|
auto oldDriverName = driverNames[GUI.outputMethod];
|
|
|
|
|
|
|
|
if (GUI.outputMethod == VULKAN)
|
|
|
|
{
|
|
|
|
GUI.outputMethod = OPENGL;
|
|
|
|
S9xDisplayOutput = &OpenGL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GUI.outputMethod = DIRECT3D;
|
|
|
|
S9xDisplayOutput = &Direct3D;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto newDriverName = driverNames[GUI.outputMethod];
|
|
|
|
TCHAR msg[512];
|
|
|
|
_stprintf(msg, TEXT("Couldn't load selected driver: %s. Trying %s."), oldDriverName, newDriverName);
|
|
|
|
MessageBox(GUI.hWnd, msg, TEXT("Snes9x Display Driver"), MB_OK | MB_ICONERROR);
|
|
|
|
|
2023-02-20 21:15:38 +00:00
|
|
|
initialized = S9xDisplayOutput->Initialize(GUI.hWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initialized) {
|
2023-03-24 19:39:31 +00:00
|
|
|
if (S9xDisplayOutput == &VulkanDriver)
|
|
|
|
VulkanUsed = true;
|
|
|
|
if (S9xDisplayOutput == &OpenGL)
|
|
|
|
OpenGLUsed = true;
|
2010-09-25 15:46:12 +00:00
|
|
|
S9xGraphicsDeinit();
|
2023-02-20 21:15:38 +00:00
|
|
|
S9xSetWinPixelFormat();
|
2010-09-25 15:46:12 +00:00
|
|
|
S9xGraphicsInit();
|
2019-02-17 23:27:50 +00:00
|
|
|
|
2023-02-20 21:15:38 +00:00
|
|
|
if (GUI.DWMSync)
|
|
|
|
{
|
|
|
|
HMODULE dwmlib = LoadLibrary(TEXT("dwmapi"));
|
2019-03-04 20:40:32 +00:00
|
|
|
DwmFlushProc = (DWMFLUSHPROC)GetProcAddress(dwmlib, "DwmFlush");
|
|
|
|
DwmIsCompositionEnabledProc = (DWMISCOMPOSITIONENABLEDPROC)GetProcAddress(dwmlib, "DwmIsCompositionEnabled");
|
|
|
|
|
|
|
|
if (!DwmFlushProc || !DwmIsCompositionEnabledProc)
|
2019-02-17 23:27:50 +00:00
|
|
|
{
|
2019-03-04 20:40:32 +00:00
|
|
|
MessageBox(GUI.hWnd, TEXT("Couldn't load DWM functions. DWM Sync is disabled."), TEXT("Warning"), MB_OK | MB_ICONWARNING);
|
|
|
|
GUI.DWMSync = false;
|
2019-02-17 23:27:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2019-02-18 21:15:28 +00:00
|
|
|
MessageBox (GUI.hWnd, Languages[ GUI.Language].errInitDD, TEXT("Snes9x - Display Failure"), MB_OK | MB_ICONSTOP);
|
2010-09-25 15:46:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WinDisplayApplyChanges()
|
|
|
|
{
|
|
|
|
S9xDisplayOutput->ApplyDisplayChanges();
|
|
|
|
}
|
|
|
|
|
2010-09-25 17:35:19 +00:00
|
|
|
RECT CalculateDisplayRect(unsigned int sourceWidth,unsigned int sourceHeight,
|
|
|
|
unsigned int displayWidth,unsigned int displayHeight)
|
|
|
|
{
|
2011-07-02 02:25:13 +00:00
|
|
|
double xFactor;
|
|
|
|
double yFactor;
|
|
|
|
double minFactor;
|
|
|
|
double renderWidthCalc,renderHeightCalc;
|
2023-05-04 20:55:11 +00:00
|
|
|
int hExtend = Settings.ShowOverscan ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT;
|
2011-07-02 02:25:13 +00:00
|
|
|
double snesAspect = (double)GUI.AspectWidth/hExtend;
|
2010-09-25 17:35:19 +00:00
|
|
|
RECT drawRect;
|
|
|
|
|
|
|
|
if(GUI.Stretch) {
|
|
|
|
if(GUI.AspectRatio) {
|
2018-06-12 22:50:24 +00:00
|
|
|
|
2018-06-13 22:25:08 +00:00
|
|
|
if (GUI.IntegerScaling && sourceHeight > 0 && sourceHeight <= displayHeight && (int)(sourceHeight * snesAspect) <= displayWidth) {
|
2018-06-12 22:50:24 +00:00
|
|
|
int h;
|
|
|
|
for (h = sourceHeight * 2; h <= displayHeight && (int)(h * snesAspect) <= displayWidth; h += sourceHeight) {}
|
|
|
|
h -= sourceHeight;
|
|
|
|
drawRect.right = (LONG)(h * snesAspect);
|
|
|
|
drawRect.bottom = h;
|
|
|
|
} else {
|
|
|
|
//fix for hi-res images with FILTER_NONE
|
|
|
|
//where we need to correct the aspect ratio
|
|
|
|
renderWidthCalc = (double)sourceWidth;
|
|
|
|
renderHeightCalc = (double)sourceHeight;
|
|
|
|
if (renderWidthCalc / renderHeightCalc > snesAspect)
|
|
|
|
renderWidthCalc = renderHeightCalc * snesAspect;
|
|
|
|
else if (renderWidthCalc / renderHeightCalc < snesAspect)
|
|
|
|
renderHeightCalc = renderWidthCalc / snesAspect;
|
|
|
|
|
|
|
|
xFactor = (double)displayWidth / renderWidthCalc;
|
|
|
|
yFactor = (double)displayHeight / renderHeightCalc;
|
|
|
|
minFactor = xFactor < yFactor ? xFactor : yFactor;
|
|
|
|
|
|
|
|
drawRect.right = (LONG)(renderWidthCalc * minFactor);
|
|
|
|
drawRect.bottom = (LONG)(renderHeightCalc * minFactor);
|
|
|
|
}
|
2010-09-25 17:35:19 +00:00
|
|
|
|
|
|
|
drawRect.left = (displayWidth - drawRect.right) / 2;
|
|
|
|
drawRect.top = (displayHeight - drawRect.bottom) / 2;
|
|
|
|
drawRect.right += drawRect.left;
|
|
|
|
drawRect.bottom += drawRect.top;
|
2018-06-12 22:50:24 +00:00
|
|
|
|
2010-09-25 17:35:19 +00:00
|
|
|
} else {
|
|
|
|
drawRect.top = 0;
|
|
|
|
drawRect.left = 0;
|
|
|
|
drawRect.right = displayWidth;
|
|
|
|
drawRect.bottom = displayHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawRect.left = ((int)(displayWidth) - (int)sourceWidth) / 2;
|
|
|
|
drawRect.top = ((int)(displayHeight) - (int)sourceHeight) / 2;
|
2010-10-17 00:47:53 +00:00
|
|
|
if(!GUI.AlwaysCenterImage) {
|
|
|
|
if(drawRect.left < 0) drawRect.left = 0;
|
|
|
|
if(drawRect.top < 0) drawRect.top = 0;
|
|
|
|
}
|
2010-09-25 17:35:19 +00:00
|
|
|
drawRect.right = drawRect.left + sourceWidth;
|
|
|
|
drawRect.bottom = drawRect.top + sourceHeight;
|
|
|
|
}
|
|
|
|
return drawRect;
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
bool8 S9xInitUpdate (void)
|
|
|
|
{
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// only necessary for avi recording
|
|
|
|
// TODO: check if this can be removed
|
|
|
|
bool8 S9xContinueUpdate(int Width, int Height)
|
|
|
|
{
|
|
|
|
// called every other frame during interlace
|
2023-02-23 01:14:05 +00:00
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
Src.Width = Width;
|
|
|
|
if(Height%SNES_HEIGHT)
|
|
|
|
Src.Height = Height;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(Height==SNES_HEIGHT)
|
|
|
|
Src.Height=SNES_HEIGHT_EXTENDED;
|
|
|
|
else Src.Height=SNES_HEIGHT_EXTENDED<<1;
|
|
|
|
}
|
|
|
|
Src.Pitch = GFX.Pitch;
|
|
|
|
Src.Surface = (BYTE*)GFX.Screen;
|
|
|
|
|
|
|
|
// avi writing
|
2011-02-12 15:32:53 +00:00
|
|
|
DoAVIVideoFrame();
|
2010-09-25 15:46:12 +00:00
|
|
|
|
2024-06-07 19:27:47 +00:00
|
|
|
WinThrottleFramerate();
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do the actual rendering of a frame
|
|
|
|
bool8 S9xDeinitUpdate (int Width, int Height)
|
|
|
|
{
|
|
|
|
Src.Width = Width;
|
2018-11-01 21:36:31 +00:00
|
|
|
Src.Height = Height;
|
2010-09-25 15:46:12 +00:00
|
|
|
Src.Pitch = GFX.Pitch;
|
2018-11-01 21:36:31 +00:00
|
|
|
|
|
|
|
CheckOverscanOffset();
|
2010-09-25 15:46:12 +00:00
|
|
|
|
2011-02-12 15:32:53 +00:00
|
|
|
// avi writing
|
|
|
|
DoAVIVideoFrame();
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
// Clear some of the old SNES rendered image
|
|
|
|
// when the resolution becomes lower in x or y,
|
|
|
|
// otherwise the image processors (filters) might access
|
|
|
|
// some of the old rendered data at the edges.
|
|
|
|
{
|
|
|
|
static int LastWidth = 0;
|
|
|
|
static int LastHeight = 0;
|
|
|
|
|
|
|
|
if (Width < LastWidth)
|
|
|
|
{
|
2011-02-12 17:13:22 +00:00
|
|
|
const int hh = max(LastHeight, Height);
|
2010-09-25 15:46:12 +00:00
|
|
|
for (int i = 0; i < hh; i++)
|
|
|
|
memset (GFX.Screen + i * (GFX.Pitch>>1) + Width*1, 0, 4);
|
|
|
|
}
|
2011-02-12 17:13:22 +00:00
|
|
|
if (Height < LastHeight)
|
2010-09-25 15:46:12 +00:00
|
|
|
{
|
|
|
|
const int ww = max(LastWidth, Width);
|
2011-02-12 17:13:22 +00:00
|
|
|
for (int i = Height; i < LastHeight ; i++)
|
2010-09-25 15:46:12 +00:00
|
|
|
memset (GFX.Screen + i * (GFX.Pitch>>1), 0, ww * 2);
|
|
|
|
|
|
|
|
// also old clear extended height stuff from drawing surface
|
2011-02-12 17:13:22 +00:00
|
|
|
if((int)Src.Height > Height)
|
|
|
|
for (int i = Height; i < (int)Src.Height ; i++)
|
2010-09-25 15:46:12 +00:00
|
|
|
memset (Src.Surface + i * Src.Pitch, 0, Src.Pitch);
|
|
|
|
}
|
|
|
|
LastWidth = Width;
|
2011-02-12 17:13:22 +00:00
|
|
|
LastHeight = Height;
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 20:25:50 +00:00
|
|
|
if (GUI.DWMSync && GUI.outputMethod == OPENGL)
|
2019-03-04 20:40:32 +00:00
|
|
|
{
|
|
|
|
BOOL DWMEnabled = false;
|
|
|
|
DwmIsCompositionEnabledProc(&DWMEnabled);
|
2019-03-05 20:25:50 +00:00
|
|
|
|
|
|
|
if (GUI.FullScreen || !DWMEnabled)
|
|
|
|
((COpenGL *)S9xDisplayOutput)->SetSwapInterval(GUI.Vsync ? 1 : 0);
|
|
|
|
else
|
|
|
|
((COpenGL *)S9xDisplayOutput)->SetSwapInterval(0);
|
|
|
|
|
|
|
|
WinRefreshDisplay();
|
|
|
|
|
|
|
|
if (DWMEnabled && !GUI.FullScreen)
|
2019-03-04 20:40:32 +00:00
|
|
|
DwmFlushProc();
|
|
|
|
}
|
2019-03-05 20:25:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WinRefreshDisplay();
|
|
|
|
}
|
2019-03-04 20:40:32 +00:00
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* S9xSetWinPixelFormat
|
|
|
|
sets default settings and calls the appropriate display object
|
|
|
|
*/
|
|
|
|
void S9xSetWinPixelFormat ()
|
|
|
|
{
|
|
|
|
GUI.NeedDepthConvert = FALSE;
|
|
|
|
GUI.DepthConverted = !GUI.NeedDepthConvert;
|
|
|
|
|
|
|
|
S9xBlit2xSaIFilterDeinit();
|
|
|
|
S9xBlitHQ2xFilterDeinit();
|
|
|
|
|
|
|
|
S9xDisplayOutput->SetSnes9xColorFormat();
|
|
|
|
}
|
|
|
|
|
2011-02-24 00:26:42 +00:00
|
|
|
char *ReadShaderFileContents(const TCHAR *filename)
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
DWORD size;
|
|
|
|
DWORD bytesRead;
|
|
|
|
char *contents;
|
|
|
|
|
|
|
|
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN , 0);
|
|
|
|
if(hFile == INVALID_HANDLE_VALUE){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
size = GetFileSize(hFile,NULL);
|
|
|
|
contents = new char[size+1];
|
|
|
|
if(!ReadFile(hFile,contents,size,&bytesRead,NULL)) {
|
|
|
|
CloseHandle(hFile);
|
|
|
|
delete[] contents;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
|
|
|
contents[size] = '\0';
|
|
|
|
return contents;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:07:02 +00:00
|
|
|
void ReduceToPath(TCHAR *filename)
|
|
|
|
{
|
|
|
|
for (int i = lstrlen(filename); i >= 0; i--) {
|
|
|
|
if (IS_SLASH(filename[i])) {
|
|
|
|
filename[i] = TEXT('\0');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
// TODO: abstract the following functions in some way - only necessary for directdraw
|
|
|
|
|
|
|
|
/* DirectDraw only begin */
|
|
|
|
void SwitchToGDI()
|
|
|
|
{
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
if(GUI.outputMethod!=DIRECTDRAW)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IPPU.ColorsChanged = true;
|
|
|
|
DirectDraw.lpDD->FlipToGDISurface();
|
|
|
|
GUI.FlipCounter = 0;
|
|
|
|
DirectDraw.lpDDSPrimary2->SetPalette (NULL);
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearSurface (LPDIRECTDRAWSURFACE2 lpDDSurface)
|
|
|
|
{
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
DDBLTFX fx;
|
|
|
|
|
|
|
|
memset (&fx, 0, sizeof (fx));
|
|
|
|
fx.dwSize = sizeof (fx);
|
|
|
|
|
|
|
|
while (lpDDSurface->Blt (NULL, DirectDraw.lpDDSPrimary2, NULL, DDBLT_WAIT, NULL) == DDERR_SURFACELOST)
|
|
|
|
lpDDSurface->Restore ();
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateBackBuffer()
|
|
|
|
{
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
if (GUI.outputMethod==DIRECTDRAW && GUI.FullScreen)
|
|
|
|
{
|
|
|
|
SwitchToGDI();
|
|
|
|
|
|
|
|
DDBLTFX fx;
|
|
|
|
|
|
|
|
memset (&fx, 0, sizeof (fx));
|
|
|
|
fx.dwSize = sizeof (fx);
|
|
|
|
|
|
|
|
while (DirectDraw.lpDDSPrimary2->Blt (NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx) == DDERR_SURFACELOST)
|
|
|
|
DirectDraw.lpDDSPrimary2->Restore ();
|
|
|
|
|
|
|
|
if (GetMenu (GUI.hWnd) != NULL)
|
|
|
|
DrawMenuBar (GUI.hWnd);
|
|
|
|
|
|
|
|
GUI.FlipCounter = 0;
|
|
|
|
DDSCAPS caps;
|
|
|
|
caps.dwCaps = DDSCAPS_BACKBUFFER;
|
|
|
|
|
|
|
|
LPDIRECTDRAWSURFACE2 pDDSurface;
|
|
|
|
|
|
|
|
if (DirectDraw.lpDDSPrimary2->GetAttachedSurface (&caps, &pDDSurface) == DD_OK &&
|
|
|
|
pDDSurface != NULL)
|
|
|
|
{
|
|
|
|
ClearSurface (pDDSurface);
|
|
|
|
DirectDraw.lpDDSPrimary2->Flip (NULL, GUI.Vsync?DDFLIP_WAIT:DDFLIP_NOVSYNC);
|
|
|
|
while (DirectDraw.lpDDSPrimary2->GetFlipStatus (DDGFS_ISFLIPDONE) != DD_OK)
|
|
|
|
Sleep (0);
|
|
|
|
if(DirectDraw.doubleBuffered)
|
|
|
|
ClearSurface (pDDSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GetMenu( GUI.hWnd) != NULL)
|
|
|
|
DrawMenuBar (GUI.hWnd);
|
|
|
|
}
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreGUIDisplay ()
|
|
|
|
{
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
if(GUI.outputMethod!=DIRECTDRAW)
|
|
|
|
return;
|
|
|
|
|
|
|
|
S9xSetPause (PAUSE_RESTORE_GUI);
|
|
|
|
|
|
|
|
if (GUI.FullScreen &&
|
|
|
|
(GUI.FullscreenMode.width < 640 || GUI.FullscreenMode.height < 400) &&
|
|
|
|
!DirectDraw.SetDisplayMode (640, 480, 1, 0, 60, !GUI.FullScreen, false))
|
|
|
|
{
|
2019-02-18 21:15:28 +00:00
|
|
|
MessageBox (GUI.hWnd, Languages[ GUI.Language].errModeDD, TEXT("Snes9x - DirectDraw(1)"), MB_OK | MB_ICONSTOP);
|
2010-09-25 15:46:12 +00:00
|
|
|
S9xClearPause (PAUSE_RESTORE_GUI);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SwitchToGDI();
|
|
|
|
S9xClearPause (PAUSE_RESTORE_GUI);
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreSNESDisplay ()
|
|
|
|
{
|
2017-04-17 11:45:43 +00:00
|
|
|
#if DIRECTDRAW_SUPPORT
|
2010-09-25 15:46:12 +00:00
|
|
|
if(GUI.outputMethod!=DIRECTDRAW)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!DirectDraw.SetFullscreen(GUI.FullScreen))
|
|
|
|
{
|
2019-02-18 21:15:28 +00:00
|
|
|
MessageBox (GUI.hWnd, Languages[ GUI.Language].errModeDD, TEXT("Snes9x - DirectDraw(4)"), MB_OK | MB_ICONSTOP);
|
2010-09-25 15:46:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateBackBuffer();
|
2017-04-02 23:12:55 +00:00
|
|
|
#endif
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DirectDraw only end */
|
|
|
|
|
2010-09-25 17:35:19 +00:00
|
|
|
void SaveMainWinPos()
|
|
|
|
{
|
|
|
|
WINDOWPLACEMENT wndPlacement={0};
|
|
|
|
wndPlacement.length = sizeof(WINDOWPLACEMENT);
|
|
|
|
GetWindowPlacement(GUI.hWnd,&wndPlacement);
|
|
|
|
GUI.window_maximized = wndPlacement.showCmd == SW_SHOWMAXIMIZED;
|
2011-11-30 18:31:59 +00:00
|
|
|
if(!GUI.FullScreen && !GUI.EmulatedFullscreen)
|
|
|
|
GUI.window_size = wndPlacement.rcNormalPosition;
|
2010-09-25 17:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreMainWinPos()
|
|
|
|
{
|
|
|
|
WINDOWPLACEMENT wndPlacement={0};
|
|
|
|
wndPlacement.length = sizeof(WINDOWPLACEMENT);
|
|
|
|
wndPlacement.showCmd = GUI.window_maximized?SW_SHOWMAXIMIZED:SW_SHOWNORMAL;
|
|
|
|
wndPlacement.rcNormalPosition = GUI.window_size;
|
|
|
|
SetWindowPlacement(GUI.hWnd,&wndPlacement);
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
/* ToggleFullScreen
|
|
|
|
switches between fullscreen and window mode and saves the window position
|
|
|
|
if EmulateFullscreen is set we simply create a borderless window that spans the screen
|
|
|
|
*/
|
|
|
|
void ToggleFullScreen ()
|
|
|
|
{
|
|
|
|
S9xSetPause (PAUSE_TOGGLE_FULL_SCREEN);
|
|
|
|
|
2016-10-12 19:49:29 +00:00
|
|
|
SaveMainWinPos();
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
if(GUI.EmulateFullscreen) {
|
|
|
|
HMONITOR hm;
|
|
|
|
MONITORINFO mi;
|
|
|
|
GUI.EmulatedFullscreen = !GUI.EmulatedFullscreen;
|
|
|
|
if(GUI.EmulatedFullscreen) {
|
|
|
|
if(GetMenu(GUI.hWnd)!=NULL)
|
|
|
|
SetMenu(GUI.hWnd,NULL);
|
2015-02-01 00:45:14 +00:00
|
|
|
SetWindowLongPtr (GUI.hWnd, GWL_STYLE, WS_POPUP|WS_VISIBLE);
|
2010-09-25 15:46:12 +00:00
|
|
|
hm = MonitorFromWindow(GUI.hWnd,MONITOR_DEFAULTTONEAREST);
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
GetMonitorInfo(hm,&mi);
|
|
|
|
SetWindowPos (GUI.hWnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_DRAWFRAME|SWP_FRAMECHANGED);
|
|
|
|
} else {
|
2015-02-01 00:45:14 +00:00
|
|
|
SetWindowLongPtr( GUI.hWnd, GWL_STYLE, WS_POPUPWINDOW|WS_CAPTION|
|
2010-09-25 15:46:12 +00:00
|
|
|
WS_THICKFRAME|WS_VISIBLE|WS_MINIMIZEBOX|WS_MAXIMIZEBOX);
|
|
|
|
SetMenu(GUI.hWnd,GUI.hMenu);
|
2010-09-25 17:35:19 +00:00
|
|
|
SetWindowPos (GUI.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_DRAWFRAME|SWP_FRAMECHANGED);
|
|
|
|
RestoreMainWinPos();
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GUI.FullScreen = !GUI.FullScreen;
|
|
|
|
if(GUI.FullScreen) {
|
|
|
|
if(GetMenu(GUI.hWnd)!=NULL)
|
|
|
|
SetMenu(GUI.hWnd,NULL);
|
2019-03-04 21:49:05 +00:00
|
|
|
SetWindowLongPtr(GUI.hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
|
|
|
|
SetWindowLongPtr(GUI.hWnd, GWL_EXSTYLE, 0);
|
2010-09-25 15:46:12 +00:00
|
|
|
if(!S9xDisplayOutput->SetFullscreen(true))
|
|
|
|
GUI.FullScreen = false;
|
2019-03-04 21:49:05 +00:00
|
|
|
else
|
|
|
|
SetWindowPos(GUI.hWnd, HWND_TOPMOST, 0, 0, GUI.FullscreenMode.width, GUI.FullscreenMode.height, SWP_DRAWFRAME | SWP_FRAMECHANGED);
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
if(!GUI.FullScreen) {
|
2019-03-04 21:49:05 +00:00
|
|
|
SetWindowLongPtr(GUI.hWnd, GWL_STYLE, WS_POPUPWINDOW|WS_CAPTION|
|
2010-09-25 15:46:12 +00:00
|
|
|
WS_THICKFRAME|WS_VISIBLE|WS_MINIMIZEBOX|WS_MAXIMIZEBOX);
|
2019-03-04 21:49:05 +00:00
|
|
|
SetWindowLongPtr(GUI.hWnd, GWL_EXSTYLE, WS_EX_ACCEPTFILES | WS_EX_APPWINDOW);
|
2010-09-25 15:46:12 +00:00
|
|
|
SetMenu(GUI.hWnd,GUI.hMenu);
|
|
|
|
S9xDisplayOutput->SetFullscreen(false);
|
2010-09-25 17:35:19 +00:00
|
|
|
SetWindowPos (GUI.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_DRAWFRAME|SWP_FRAMECHANGED);
|
|
|
|
RestoreMainWinPos();
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
2018-05-24 23:52:43 +00:00
|
|
|
if (GUI.AutomaticInputRate)
|
|
|
|
{
|
|
|
|
int rate = WinGetAutomaticInputRate();
|
|
|
|
if (rate)
|
|
|
|
{
|
|
|
|
Settings.SoundInputRate = rate;
|
|
|
|
S9xUpdateDynamicRate(1, 2);
|
|
|
|
}
|
|
|
|
}
|
2010-09-25 17:35:19 +00:00
|
|
|
S9xGraphicsDeinit();
|
|
|
|
S9xSetWinPixelFormat ();
|
|
|
|
S9xInitUpdate();
|
|
|
|
S9xGraphicsInit();
|
2010-09-25 15:46:12 +00:00
|
|
|
}
|
|
|
|
IPPU.RenderThisFrame = true;
|
|
|
|
|
|
|
|
S9xClearPause (PAUSE_TOGGLE_FULL_SCREEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* S9xOpenSoundDevice
|
|
|
|
ennumerates the available display modes of the currently selected output
|
|
|
|
*/
|
|
|
|
void WinEnumDisplayModes(std::vector<dMode> *modeVector)
|
|
|
|
{
|
|
|
|
S9xDisplayOutput->EnumModes(modeVector);
|
|
|
|
}
|
|
|
|
|
2018-05-24 23:52:43 +00:00
|
|
|
double WinGetRefreshRate(void)
|
|
|
|
{
|
2018-05-27 22:56:53 +00:00
|
|
|
typedef LONG(WINAPI *PGDCBS) (UINT32, UINT32 *, UINT32 *);
|
|
|
|
typedef LONG(WINAPI *PQDC) (UINT32, UINT32*, DISPLAYCONFIG_PATH_INFO *, UINT32*, DISPLAYCONFIG_MODE_INFO *, DISPLAYCONFIG_TOPOLOGY_ID *);
|
|
|
|
static PGDCBS pGDCBS = NULL;
|
|
|
|
static PQDC pQDC = NULL;
|
|
|
|
static int firstrun = 1;
|
|
|
|
|
|
|
|
if (firstrun)
|
|
|
|
{
|
|
|
|
HMODULE user32 = GetModuleHandleA("user32.dll");
|
|
|
|
pQDC = (PQDC) GetProcAddress(user32, "QueryDisplayConfig");
|
|
|
|
pGDCBS = (PGDCBS) GetProcAddress(user32, "GetDisplayConfigBufferSizes");
|
|
|
|
firstrun = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-24 23:52:43 +00:00
|
|
|
double refreshRate = 0.0;
|
2018-05-27 22:56:53 +00:00
|
|
|
|
|
|
|
if (!pGDCBS || !pQDC)
|
|
|
|
return refreshRate;
|
|
|
|
|
2018-05-24 23:52:43 +00:00
|
|
|
OSVERSIONINFO ovi;
|
|
|
|
DISPLAYCONFIG_TOPOLOGY_ID topologyID;
|
|
|
|
unsigned int numPathArrayElements = 0;
|
|
|
|
unsigned int numModeInfoArrayElements = 0;
|
|
|
|
DISPLAYCONFIG_PATH_INFO * pathInfoArray = NULL;
|
|
|
|
DISPLAYCONFIG_MODE_INFO * modeInfoArray = NULL;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
if (!GetVersionEx(&ovi))
|
|
|
|
return refreshRate;
|
|
|
|
|
|
|
|
if (ovi.dwMajorVersion < 6 || (ovi.dwMajorVersion == 6 && ovi.dwMinorVersion < 1))
|
|
|
|
return refreshRate;
|
|
|
|
|
2018-05-27 22:56:53 +00:00
|
|
|
result = pGDCBS(QDC_DATABASE_CURRENT,
|
2018-05-24 23:52:43 +00:00
|
|
|
&numPathArrayElements,
|
|
|
|
&numModeInfoArrayElements);
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
return refreshRate;
|
|
|
|
|
|
|
|
pathInfoArray = (DISPLAYCONFIG_PATH_INFO *)
|
|
|
|
malloc(sizeof(DISPLAYCONFIG_PATH_INFO) * numPathArrayElements);
|
|
|
|
modeInfoArray = (DISPLAYCONFIG_MODE_INFO *)
|
|
|
|
malloc(sizeof(DISPLAYCONFIG_MODE_INFO) * numModeInfoArrayElements);
|
|
|
|
|
2018-05-27 22:56:53 +00:00
|
|
|
result = pQDC(QDC_DATABASE_CURRENT,
|
2018-05-24 23:52:43 +00:00
|
|
|
&numPathArrayElements,
|
|
|
|
pathInfoArray,
|
|
|
|
&numModeInfoArrayElements,
|
|
|
|
modeInfoArray,
|
|
|
|
&topologyID);
|
|
|
|
|
|
|
|
if (result == ERROR_SUCCESS && numPathArrayElements >= 1)
|
|
|
|
{
|
|
|
|
refreshRate = (float)pathInfoArray[0].targetInfo.refreshRate.Numerator /
|
|
|
|
pathInfoArray[0].targetInfo.refreshRate.Denominator;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(modeInfoArray);
|
|
|
|
free(pathInfoArray);
|
|
|
|
|
|
|
|
return refreshRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WinGetAutomaticInputRate(void)
|
|
|
|
{
|
2018-06-07 20:49:41 +00:00
|
|
|
double refreshRate = WinGetRefreshRate();
|
2018-06-07 14:42:25 +00:00
|
|
|
|
2018-06-07 20:49:41 +00:00
|
|
|
if (refreshRate == 0.0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Try for a close multiple of 60hz
|
|
|
|
if (refreshRate > 119.0 && refreshRate < 121.0)
|
|
|
|
refreshRate /= 2.0;
|
|
|
|
if (refreshRate > 179.0 && refreshRate < 181.0)
|
|
|
|
refreshRate /= 3.0;
|
|
|
|
if (refreshRate > 239.0 && refreshRate < 241.0)
|
|
|
|
refreshRate /= 4.0;
|
|
|
|
|
2019-04-12 17:10:51 +00:00
|
|
|
double newInputRate = refreshRate * 32040.0 / 60.09881389744051 + 0.5;
|
2018-06-07 20:49:41 +00:00
|
|
|
|
2019-04-12 17:10:51 +00:00
|
|
|
if (newInputRate > 32040.0 * 1.05 || newInputRate < 32040.0 * 0.95)
|
2018-06-07 20:49:41 +00:00
|
|
|
newInputRate = 0.0;
|
2018-06-07 14:42:25 +00:00
|
|
|
|
2018-06-12 22:50:24 +00:00
|
|
|
return (int)newInputRate;
|
2018-05-24 23:52:43 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 23:20:35 +00:00
|
|
|
void WinThrottleFramerate()
|
|
|
|
{
|
|
|
|
static HANDLE throttle_timer = nullptr;
|
|
|
|
static int64_t PCBase, PCFrameTime, PCFrameTimeNTSC, PCFrameTimePAL, PCStart, PCEnd;
|
|
|
|
|
2024-05-11 23:20:34 +00:00
|
|
|
if (Settings.SkipFrames != AUTO_FRAMERATE || Settings.TurboMode)
|
2023-02-23 23:20:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!throttle_timer)
|
|
|
|
{
|
|
|
|
QueryPerformanceFrequency((LARGE_INTEGER *)&PCBase);
|
|
|
|
|
|
|
|
PCFrameTimeNTSC = (int64_t)(PCBase / NTSC_PROGRESSIVE_FRAME_RATE);
|
|
|
|
PCFrameTimePAL = (int64_t)(PCBase / PAL_PROGRESSIVE_FRAME_RATE);
|
|
|
|
|
|
|
|
throttle_timer = CreateWaitableTimer(NULL, true, NULL);
|
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&PCStart);
|
|
|
|
}
|
|
|
|
|
2023-03-16 23:46:55 +00:00
|
|
|
if (Settings.FrameTime == Settings.FrameTimeNTSC)
|
|
|
|
PCFrameTime = PCFrameTimeNTSC;
|
|
|
|
else if (Settings.FrameTime == Settings.FrameTimePAL)
|
|
|
|
PCFrameTime = PCFrameTimePAL;
|
|
|
|
else
|
|
|
|
PCFrameTime = (__int64)(PCBase * Settings.FrameTime / 1e6);
|
2023-02-23 23:20:35 +00:00
|
|
|
|
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&PCEnd);
|
|
|
|
int64_t time_left_us = ((PCFrameTime - (PCEnd - PCStart)) * 1000000) / PCBase;
|
|
|
|
|
|
|
|
int64_t PCFrameTime_us = (int64_t)(PCFrameTime * 1000000.0 / PCBase);
|
|
|
|
if (time_left_us < -PCFrameTime_us / 10)
|
|
|
|
{
|
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&PCStart);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (time_left_us > 0)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
li.QuadPart = -time_left_us * 10;
|
|
|
|
SetWaitableTimer(throttle_timer, &li, 0, NULL, NULL, false);
|
|
|
|
WaitForSingleObject(throttle_timer, INFINITE);
|
|
|
|
}
|
|
|
|
PCStart += PCFrameTime;
|
|
|
|
}
|
|
|
|
|
2023-03-11 20:49:10 +00:00
|
|
|
std::vector<ShaderParam> *WinGetShaderParameters()
|
2019-02-01 21:41:29 +00:00
|
|
|
{
|
2023-03-11 20:49:10 +00:00
|
|
|
return S9xDisplayOutput->GetShaderParameters();
|
2023-02-01 20:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void(const char*)> WinGetShaderSaveFunction()
|
|
|
|
{
|
2023-03-11 20:49:10 +00:00
|
|
|
return S9xDisplayOutput->GetShaderParametersSaveFunction();
|
2019-02-01 21:41:29 +00:00
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:12 +00:00
|
|
|
/* Depth conversion functions begin */
|
|
|
|
|
|
|
|
void Convert16To24 (SSurface *src, SSurface *dst, RECT *srect)
|
|
|
|
{
|
|
|
|
const int height = srect->bottom - srect->top;
|
|
|
|
const int width = srect->right - srect->left;
|
|
|
|
const int offset1 = srect->top * src->Pitch + srect->left * 2;
|
|
|
|
const int offset2 = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1) * 3;
|
|
|
|
const int snesWidth = src->Width;
|
|
|
|
const int snesHeight = src->Height;
|
|
|
|
const bool doubledX = (snesWidth >= width*2) ? true : false;
|
|
|
|
const bool doubledY = (snesHeight >= height*2) ? true : false;
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
2018-11-17 21:02:37 +00:00
|
|
|
uint16 *s = (uint16 *) ((uint8 *) src->Surface + (doubledY ? y*2 : y) * src->Pitch + offset1);
|
|
|
|
uint8 *d = ((uint8 *) dst->Surface + y * dst->Pitch + offset2);
|
2010-09-25 15:46:12 +00:00
|
|
|
|
|
|
|
#define Interp(c1, c2) \
|
|
|
|
(c1 == c2) ? c1 : \
|
|
|
|
(((((c1 & 0x07E0) + (c2 & 0x07E0)) >> 1) & 0x07E0) + \
|
|
|
|
((((c1 & 0xF81F) + (c2 & 0xF81F)) >> 1) & 0xF81F))
|
|
|
|
|
|
|
|
if(y >= snesHeight)
|
|
|
|
{
|
|
|
|
// beyond SNES image - make the row black
|
|
|
|
memset(d, 0, width*3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
#ifdef LSB_FIRST
|
|
|
|
if (GUI.RedShift < GUI.BlueShift)
|
|
|
|
#else
|
|
|
|
if (GUI.RedShift > GUI.BlueShift)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// Order is RGB
|
|
|
|
if(!doubledX)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
uint32 pixel = *s++;
|
|
|
|
*(d + 0) = (pixel >> (11 - 3)) & 0xf8;
|
|
|
|
*(d + 1) = (pixel >> (6 - 3)) & 0xf8;
|
|
|
|
*(d + 2) = (pixel & 0x1f) << 3;
|
|
|
|
d += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // high-res x, blend:
|
|
|
|
{
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
uint32 pixel = Interp(s[0],s[1]);
|
|
|
|
s += 2;
|
|
|
|
*(d + 0) = (pixel >> (11 - 3)) & 0xf8;
|
|
|
|
*(d + 1) = (pixel >> (6 - 3)) & 0xf8;
|
|
|
|
*(d + 2) = (pixel & 0x1f) << 3;
|
|
|
|
d += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Order is BGR
|
|
|
|
if(!doubledX)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
uint32 pixel = *s++;
|
|
|
|
*(d + 0) = (pixel & 0x1f) << 3;
|
|
|
|
*(d + 1) = (pixel >> (6 - 3)) & 0xf8;
|
|
|
|
*(d + 2) = (pixel >> (11 - 3)) & 0xf8;
|
|
|
|
d += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // high-res x, blend:
|
|
|
|
{
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
uint32 pixel = Interp(s[0],s[1]);
|
|
|
|
s += 2;
|
|
|
|
*(d + 0) = (pixel & 0x1f) << 3;
|
|
|
|
*(d + 1) = (pixel >> (6 - 3)) & 0xf8;
|
|
|
|
*(d + 2) = (pixel >> (11 - 3)) & 0xf8;
|
|
|
|
d += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Convert16To32 (SSurface *src, SSurface *dst, RECT *srect)
|
|
|
|
{
|
|
|
|
int height = srect->bottom - srect->top;
|
|
|
|
int width = srect->right - srect->left;
|
|
|
|
int offset1 = srect->top * src->Pitch + srect->left * 2;
|
|
|
|
int offset2 = 0;//((dst->Height - height) >> 1) * dst->Pitch +
|
|
|
|
//((dst->Width - width) >> 1) * sizeof (uint32);
|
|
|
|
|
2018-11-17 21:02:37 +00:00
|
|
|
for (int y = 0; y < height; y++)
|
2010-09-25 15:46:12 +00:00
|
|
|
{
|
2018-11-17 21:02:37 +00:00
|
|
|
uint16 *s = (uint16 *) ((uint8 *) src->Surface + y * src->Pitch + offset1);
|
|
|
|
uint32 *d = (uint32 *) ((uint8 *) dst->Surface +
|
2010-09-25 15:46:12 +00:00
|
|
|
y * dst->Pitch + offset2);
|
2018-11-17 21:02:37 +00:00
|
|
|
for (int x = 0; x < width; x++)
|
2010-09-25 15:46:12 +00:00
|
|
|
{
|
|
|
|
uint32 pixel = *s++;
|
|
|
|
*d++ = (((pixel >> 11) & 0x1f) << GUI.RedShift) |
|
|
|
|
(((pixel >> 6) & 0x1f) << GUI.GreenShift) |
|
|
|
|
((pixel & 0x1f) << GUI.BlueShift);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertDepth (SSurface *src, SSurface *dst, RECT *srect)
|
|
|
|
{
|
|
|
|
// SNES image has been rendered in 16-bit, RGB565 format
|
|
|
|
switch (GUI.ScreenDepth)
|
|
|
|
{
|
|
|
|
case 15: // is this right?
|
|
|
|
case 16:
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
Convert16To24 (src, dst, srect);
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
Convert16To32 (src, dst, srect);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Depth conversion functions end */
|
2023-05-04 22:36:36 +00:00
|
|
|
#include "snes9x_imgui.h"
|
|
|
|
void S9xWinDisplayString(const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap, int type)
|
|
|
|
{
|
|
|
|
if (S9xImGuiRunning() && !Settings.AutoDisplayMessages)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
S9xVariableDisplayString(string, linesFromBottom, pixelsFromLeft, allowWrap, type);
|
|
|
|
}
|