DXGL r823 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r822‎ | r823 | r824 >
Date:14:47, 30 June 2018
Author:admin
Status:new
Tags:
Comment:
Change Expand 512x448 to 640x480 hack to an integer and add a manual (and INI) setting to scale only in X direction.
Implement part of the Save .ini File button in DXGL Config.
Modified paths:
  • /Help/html/config/hacks/expand512448to640480.htmlbody (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /dxgl-example.ini (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)
  • /dxglcfg/dxglcfg.rc (modified) (history)

Diff [purge]

Index: Help/html/config/hacks/expand512448to640480.htmlbody
@@ -1,4 +1,5 @@
22 <p>If the display is set to 640&#215;480, this hack will test if there is a border around the display, and if so, expands the inner 512&#215;448 pixels to the 640&#215;480 screen. In addition, if the display is set to 320&#215;240, this will expand the inner 256&#215;224 pixels to the display.</p>
33 <p>This hack is intended for emulators and similar applications that render at 256&#215;224 or 512&#215;448 resolution, while allowing menus to continue to display properly.</p>
44 <p>For best quality, use a scaled display mode when using this hack.</p>
 5+<p>In DXGL 0.5.14, you can manually edit the registry and use a value of 2 to scale the image only in the horizontal direction.  This can help with image quality on CRT displays.</p>
56 <p>Currently, this hack only reads the upper-left pixel of the display.</p>
\ No newline at end of file
Index: cfgmgr/cfgmgr.c
@@ -667,7 +667,7 @@
668668 cfg->DebugMaxGLVersionMajor = ReadDWORD(hKey, cfg->DebugMaxGLVersionMajor, &cfgmask->DebugMaxGLVersionMajor, _T("DebugMaxGLVersionMajor"));
669669 cfg->DebugMaxGLVersionMinor = ReadDWORD(hKey, cfg->DebugMaxGLVersionMinor, &cfgmask->DebugMaxGLVersionMinor, _T("DebugMaxGLVersionMinor"));
670670 cfg->HackCrop640480to640400 = ReadBool(hKey, cfg->HackCrop640480to640400, &cfgmask->HackCrop640480to640400, _T("HackCrop640480to640400"));
671 - cfg->HackAutoScale512448to640480 = ReadBool(hKey, cfg->HackAutoScale512448to640480, &cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
 671+ cfg->HackAutoScale512448to640480 = ReadDWORD(hKey, cfg->HackAutoScale512448to640480, &cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
672672 cfg->HackNoTVRefresh = ReadBool(hKey, cfg->HackNoTVRefresh, &cfgmask->HackNoTVRefresh, _T("HackNoTVRefresh"));
673673 cfg->HackSetCursor = ReadBool(hKey, cfg->HackSetCursor, &cfgmask->HackSetCursor, _T("HackSetCursor"));
674674 if(!global && dll)
@@ -830,7 +830,7 @@
831831 WriteDWORD(hKey, cfg->DebugMaxGLVersionMajor, cfgmask->DebugMaxGLVersionMajor, _T("DebugMaxGLVersionMajor"));
832832 WriteDWORD(hKey, cfg->DebugMaxGLVersionMinor, cfgmask->DebugMaxGLVersionMinor, _T("DebugMaxGLVersionMinor"));
833833 WriteBool(hKey, cfg->HackCrop640480to640400, cfgmask->HackCrop640480to640400, _T("HackCrop640480to640400"));
834 - WriteBool(hKey, cfg->HackAutoScale512448to640480, cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
 834+ WriteDWORD(hKey, cfg->HackAutoScale512448to640480, cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
835835 WriteBool(hKey, cfg->HackNoTVRefresh, cfgmask->HackNoTVRefresh, _T("HackNoTVRefresh"));
836836 WriteBool(hKey, cfg->HackSetCursor, cfgmask->HackSetCursor, _T("HackSetCursor"));
837837 }
@@ -964,6 +964,15 @@
965965 return atoi(value);
966966 }
967967
 968+DWORD INIIntBoolValue(const char *value)
 969+{
 970+ if (value[0] == 'F') return 0;
 971+ if (value[0] == 'f') return 0;
 972+ if (value[0] == 'T') return 1;
 973+ if (value[0] == 't') return 1;
 974+ return atoi(value);
 975+}
 976+
968977 DWORD INIHexValue(const char *value)
969978 {
970979 return (DWORD)strtoul(value, NULL, 0);
@@ -1116,7 +1125,7 @@
11171126 if (!_stricmp(section, "hacks"))
11181127 {
11191128 if (!_stricmp(section, "HackCrop640480to640400")) cfg->HackCrop640480to640400 = INIBoolValue(value);
1120 - if (!_stricmp(section, "HackAutoScale512448to640480")) cfg->HackAutoScale512448to640480 = INIBoolValue(value);
 1129+ if (!_stricmp(section, "HackAutoScale512448to640480")) cfg->HackAutoScale512448to640480 = INIIntBoolValue(value);
11211130 if (!_stricmp(section, "HackNoTVRefresh")) cfg->HackNoTVRefresh = INIBoolValue(value);
11221131 if (!_stricmp(section, "HackSetCursor")) cfg->HackSetCursor = INIBoolValue(value);
11231132 }
@@ -1138,6 +1147,12 @@
11391148 }
11401149 }
11411150
 1151+DWORD WriteINI(DXGLCFG *cfg, DXGLCFG *mask, LPCTSTR path)
 1152+{
 1153+ //TODO: Write INI file.
 1154+ return ERROR_CALL_NOT_IMPLEMENTED;
 1155+}
 1156+
11421157 void GetCurrentConfig(DXGLCFG *cfg, BOOL initial)
11431158 {
11441159 HKEY hKey;
Index: cfgmgr/cfgmgr.h
@@ -128,6 +128,7 @@
129129
130130 void ReadSettings(HKEY hKey, DXGLCFG *cfg, DXGLCFG *mask, BOOL global, BOOL dll, LPTSTR dir);
131131 void WriteSettings(HKEY hKey, const DXGLCFG *cfg, const DXGLCFG *mask);
 132+DWORD WriteINI(DXGLCFG *cfg, DXGLCFG *mask, LPCTSTR path);
132133 void GetCurrentConfig(DXGLCFG *cfg, BOOL initial);
133134 void GetGlobalConfig(DXGLCFG *cfg, BOOL initial);
134135 void GetGlobalConfigWithMask(DXGLCFG *cfg, DXGLCFG *mask, BOOL initial);
Index: ddraw/glRenderer.cpp
@@ -3855,10 +3855,18 @@
38563856 }
38573857 if (scale512448)
38583858 {
3859 - This->bltvertices[0].s = This->bltvertices[2].s = 0.9f;
3860 - This->bltvertices[0].t = This->bltvertices[1].t = 0.966666667f;
3861 - This->bltvertices[1].s = This->bltvertices[3].s = 0.1f;
3862 - This->bltvertices[2].t = This->bltvertices[3].t = 0.0333333333f;
 3859+ if (dxglcfg.HackAutoScale512448to640480 == 1)
 3860+ {
 3861+ This->bltvertices[0].s = This->bltvertices[2].s = 0.9f;
 3862+ This->bltvertices[0].t = This->bltvertices[1].t = 0.966666667f;
 3863+ This->bltvertices[1].s = This->bltvertices[3].s = 0.1f;
 3864+ This->bltvertices[2].t = This->bltvertices[3].t = 0.0333333333f;
 3865+ }
 3866+ else if (dxglcfg.HackAutoScale512448to640480 == 2)
 3867+ {
 3868+ This->bltvertices[0].s = This->bltvertices[2].s = 0.9f;
 3869+ This->bltvertices[1].s = This->bltvertices[3].s = 0.1f;
 3870+ }
38633871 }
38643872 else
38653873 {
Index: dxgl-example.ini
@@ -608,8 +608,10 @@
609609 ; when when it is detected the out-of-bounds area is clear, like going back
610610 ; in-game. This hack should only be enabled on games that render 512x448 with
611611 ; black bars in 640x480 mode.
612 -; Default is false
613 -HackAutoScale512448to640480 = false
 612+; If set to 1, this will scale in both X and Y directions. If set to 1, this
 613+; will scale only in the X direction.
 614+; Default is 0
 615+HackAutoScale512448to640480 = 0
614616
615617 ; HackNoTVRefresh - Boolean
616618 ; Removes TV-compatible refresh rates that may be added by Windows 7 and
Index: dxglcfg/dxglcfg.cpp
@@ -1953,6 +1953,8 @@
19541954
19551955 LRESULT CALLBACK SaveINICallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
19561956 {
 1957+ DWORD error;
 1958+ TCHAR errormsg[2048];
19571959 switch(Msg)
19581960 {
19591961 case WM_INITDIALOG:
@@ -1966,6 +1968,18 @@
19671969 switch (LOWORD(wParam))
19681970 {
19691971 case IDOK:
 1972+ error = WriteINI(cfg, cfgmask, apps[current_app].path);
 1973+ if (error == 5)
 1974+ {
 1975+ MessageBox(hWnd, _T("Access denied error writing .ini file. Please re-launch DXGL Config as Administrator and try again."),
 1976+ _T("Error"), MB_OK | MB_ICONWARNING);
 1977+ }
 1978+ else if (error != 0)
 1979+ {
 1980+ _tcscpy(errormsg, _T("Error writing .ini file:\r\n"));
 1981+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errormsg + _tcslen(errormsg), 2048 - _tcslen(errormsg), NULL);
 1982+ MessageBox(hWnd, errormsg, _T("Error"), MB_OK | MB_ICONERROR);
 1983+ }
19701984 EndDialog(hWnd, IDOK);
19711985 return TRUE;
19721986 case IDCANCEL:
Index: dxglcfg/dxglcfg.rc
@@ -270,7 +270,7 @@
271271 AUTOCHECKBOX "Save SHA-256 signature of existing ddraw.dll", IDC_SAVESHA256, 11, 46, 157, 8, 0, WS_EX_LEFT
272272 AUTOCHECKBOX "Prevent DXGL Config from deleting ddraw.dll", IDC_NOUNINSTALL, 11, 56, 156, 8, 0, WS_EX_LEFT
273273 PUSHBUTTON "Cancel", IDCANCEL, 131, 76, 50, 14, 0, WS_EX_LEFT
274 - DEFPUSHBUTTON "&Save...", IDOK, 76, 76, 50, 14, 0, WS_EX_LEFT
 274+ DEFPUSHBUTTON "&Save", IDOK, 76, 76, 50, 14, 0, WS_EX_LEFT
275275 }
276276
277277