shithub: pt2-clone

Download patch

ref: acfeae2fca676aa20d8f43d9ce987d8db72e3b16
parent: 24b446efb8c54e276621ea1576cca183579270c8
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Jun 19 13:45:00 EDT 2023

Config: Added AUTO mode for VIDEOSCALE (is default now)

--- a/release/macos/protracker.ini
+++ b/release/macos/protracker.ini
@@ -33,21 +33,19 @@
 64K_LIMIT=TRUE
 
 [VIDEO SETTINGS]
-; Video scaling factor
-;        Syntax: 1X, 2X, 3X ... 9X
-; Default value: 2X
-;       Comment: Sets the video scaling factor (window rendering size).
+; Video upscaling factor
+;        Syntax: AUTO, 1X, 2X, 3X, 4X ... 16X
+; Default value: AUTO
+;       Comment: Sets the video upscaling factor (window size).
+;       AUTO = Auto-fit (tries to find the optimal value for the screen)
 ;         1X = 320x255 (no scaling)
-;         2X = 640x510 (default)
-;         3x = 960x765
+;         2X = 640x510
+;         3X = 960x765
 ;         4x = 1280x1020
-;         5x = 1600x1275
-;         6x = 1920x1530
-;         7x = 2240x1785
-;         8x = 2560x2040
-;         9x = 2880x2295
+;         ...and so on up to 16X
+;         (width = 320*x, height = 255*x)
 ;
-VIDEOSCALE=2X
+VIDEOSCALE=AUTO
 
 ; Start in fullscreen mode
 ;        Syntax: TRUE or FALSE
--- a/release/other/protracker.ini
+++ b/release/other/protracker.ini
@@ -33,21 +33,19 @@
 64K_LIMIT=TRUE
 
 [VIDEO SETTINGS]
-; Video scaling factor
-;        Syntax: 1X, 2X, 3X ... 9X
-; Default value: 2X
-;       Comment: Sets the video scaling factor (window rendering size).
+; Video upscaling factor
+;        Syntax: AUTO, 1X, 2X, 3X, 4X ... 16X
+; Default value: AUTO
+;       Comment: Sets the video upscaling factor (window size).
+;       AUTO = Auto-fit (tries to find the optimal value for the screen)
 ;         1X = 320x255 (no scaling)
-;         2X = 640x510 (default)
-;         3x = 960x765
+;         2X = 640x510
+;         3X = 960x765
 ;         4x = 1280x1020
-;         5x = 1600x1275
-;         6x = 1920x1530
-;         7x = 2240x1785
-;         8x = 2560x2040
-;         9x = 2880x2295
+;         ...and so on up to 16X
+;         (width = 320*x, height = 255*x)
 ;
-VIDEOSCALE=2X
+VIDEOSCALE=AUTO
 
 ; Start in fullscreen mode
 ;        Syntax: TRUE or FALSE
--- a/release/win32/protracker.ini
+++ b/release/win32/protracker.ini
@@ -33,21 +33,19 @@
 64K_LIMIT=TRUE
 
 [VIDEO SETTINGS]
-; Video scaling factor
-;        Syntax: 1X, 2X, 3X ... 9X
-; Default value: 2X
-;       Comment: Sets the video scaling factor (window rendering size).
+; Video upscaling factor
+;        Syntax: AUTO, 1X, 2X, 3X, 4X ... 16X
+; Default value: AUTO
+;       Comment: Sets the video upscaling factor (window size).
+;       AUTO = Auto-fit (tries to find the optimal value for the screen)
 ;         1X = 320x255 (no scaling)
-;         2X = 640x510 (default)
-;         3x = 960x765
+;         2X = 640x510
+;         3X = 960x765
 ;         4x = 1280x1020
-;         5x = 1600x1275
-;         6x = 1920x1530
-;         7x = 2240x1785
-;         8x = 2560x2040
-;         9x = 2880x2295
+;         ...and so on up to 16X
+;         (width = 320*x, height = 255*x)
 ;
-VIDEOSCALE=2X
+VIDEOSCALE=AUTO
 
 ; Start in fullscreen mode
 ;        Syntax: TRUE or FALSE
--- a/release/win64/protracker.ini
+++ b/release/win64/protracker.ini
@@ -33,21 +33,19 @@
 64K_LIMIT=TRUE
 
 [VIDEO SETTINGS]
-; Video scaling factor
-;        Syntax: 1X, 2X, 3X ... 9X
-; Default value: 2X
-;       Comment: Sets the video scaling factor (window rendering size).
+; Video upscaling factor
+;        Syntax: AUTO, 1X, 2X, 3X, 4X ... 16X
+; Default value: AUTO
+;       Comment: Sets the video upscaling factor (window size).
+;       AUTO = Auto-fit (tries to find the optimal value for the screen)
 ;         1X = 320x255 (no scaling)
-;         2X = 640x510 (default)
-;         3x = 960x765
+;         2X = 640x510
+;         3X = 960x765
 ;         4x = 1280x1020
-;         5x = 1600x1275
-;         6x = 1920x1530
-;         7x = 2240x1785
-;         8x = 2560x2040
-;         9x = 2880x2295
+;         ...and so on up to 16X
+;         (width = 320*x, height = 255*x)
 ;
-VIDEOSCALE=2X
+VIDEOSCALE=AUTO
 
 ; Start in fullscreen mode
 ;        Syntax: TRUE or FALSE
--- a/src/pt2_config.c
+++ b/src/pt2_config.c
@@ -18,6 +18,7 @@
 #include "pt2_tables.h"
 #include "pt2_sampler.h"
 #include "pt2_diskop.h" // changePathToDesktop(), changePathToHome()
+#include "pt2_visuals.h" // MAX_UPSCALE_FACTOR
 
 #ifndef _WIN32
 static char oldCwd[PATH_MAX];
@@ -47,7 +48,8 @@
 	config.soundFrequency = 48000;
 	config.rememberPlayMode = false;
 	config.stereoSeparation = 20;
-	config.videoScaleFactor = 2;
+	config.autoFitVideoScale = true;
+	config.videoScaleFactor = 0; // will be set later if autoFitVideoScale is set
 	config.realVuMeters = false;
 	config.modDot = false;
 	config.accidental = 0; // sharp
@@ -345,18 +347,20 @@
 			else if (!_strnicmp(&configLine[7], "FALSE", 5)) config.modDot = false;
 		}
 
-		// SCALE3X (deprecated)
-		else if (!_strnicmp(configLine, "SCALE3X=", 8))
-		{
-			     if (!_strnicmp(&configLine[8], "TRUE",  4)) config.videoScaleFactor = 3;
-			else if (!_strnicmp(&configLine[8], "FALSE", 5)) config.videoScaleFactor = 2;
-		}
-
 		// VIDEOSCALE
 		else if (!_strnicmp(configLine, "VIDEOSCALE=", 11))
 		{
-			if (lineLen >= 13 && configLine[12] == 'X' && isdigit(configLine[11]))
-				config.videoScaleFactor = configLine[11] - '0';
+			if (!_strnicmp(&configLine[11], "AUTO", 4))
+			{
+				config.autoFitVideoScale = true;
+				config.videoScaleFactor = 0; // will be set later
+			}
+			else if (lineLen >= 13 && configLine[12] == 'X' && isdigit(configLine[11]))
+			{
+				config.autoFitVideoScale = false;
+				config.videoScaleFactor = (int8_t)(configLine[11] - '0');
+				config.videoScaleFactor = CLAMP(config.videoScaleFactor, 1, MAX_UPSCALE_FACTOR);
+			}
 		}
 
 		// REMEMBERPLAYMODE
--- a/src/pt2_config.h
+++ b/src/pt2_config.h
@@ -16,7 +16,9 @@
 	bool waveformCenterLine, pattDots, compoMode, autoCloseDiskOp, hideDiskOpDates, hwMouse;
 	bool transDel, fullScreenStretch, vsyncOff, modDot, blankZeroFlag, realVuMeters, rememberPlayMode;
 	bool startInFullscreen, integerScaling, disableE8xEffect, noDownsampleOnSmpLoad, keepEditModeAfterStepPlay;
-	int8_t stereoSeparation, videoScaleFactor, accidental;
+	int8_t stereoSeparation, accidental;
+	bool autoFitVideoScale;
+	int8_t videoScaleFactor;
 	uint8_t pixelFilter, amigaModel;
 	uint16_t quantizeValue;
 	int32_t maxSampleLength;
--- a/src/pt2_header.h
+++ b/src/pt2_header.h
@@ -14,7 +14,7 @@
 #include "pt2_unicode.h"
 #include "pt2_palette.h"
 
-#define PROG_VER_STR "1.59"
+#define PROG_VER_STR "1.60"
 
 #ifdef _WIN32
 #define DIR_DELIMITER '\\'
--- a/src/pt2_mouse.c
+++ b/src/pt2_mouse.c
@@ -162,7 +162,9 @@
 {
 	freeMouseCursors();
 
-	const uint32_t scaleFactor = video.yScale;
+	uint32_t scaleFactor = video.yScale;
+	if (scaleFactor > 6) // just in case
+		scaleFactor = 6;
 
 	for (uint32_t i = 0; i < NUM_CURSORS; i++)
 	{
--- a/src/pt2_visuals.c
+++ b/src/pt2_visuals.c
@@ -1944,6 +1944,38 @@
 
 bool setupVideo(void)
 {
+	if (config.autoFitVideoScale)
+	{
+		int8_t i;
+		SDL_DisplayMode dm;
+
+		int32_t di = SDL_GetWindowDisplayIndex(video.window);
+		if (di < 0)
+			di = 0; // return display index 0 (default) on error
+
+		// find out which upscaling factor is the biggest to fit on screen
+		if (SDL_GetDesktopDisplayMode(di, &dm) == 0)
+		{
+			for (i = MAX_UPSCALE_FACTOR; i >= 1; i--)
+			{
+				// height test is slightly taller because of window title, window borders and taskbar/menu/dock
+				if (dm.w >= SCREEN_W*i && dm.h >= (SCREEN_H+64)*i)
+				{
+					config.videoScaleFactor = i;
+					break;
+				}
+			}
+
+			if (i == 0)
+				config.videoScaleFactor = 1; // 1x is not going to fit, but use 1x anyways...
+		}
+		else
+		{
+			// couldn't get screen resolution, set to 1x
+			config.videoScaleFactor = 1;
+		}
+	}
+
 	int32_t screenW = SCREEN_W * config.videoScaleFactor;
 	int32_t screenH = SCREEN_H * config.videoScaleFactor;
 
--- a/src/pt2_visuals.h
+++ b/src/pt2_visuals.h
@@ -5,6 +5,8 @@
 #include "pt2_header.h"
 #include "pt2_hpc.h"
 
+#define MAX_UPSCALE_FACTOR 16 // 5120x4080 - ought to be good enough for many years to come
+
 enum
 {
 	SPRITE_PATTERN_CURSOR = 0,
--- a/vs2019_project/pt2-clone/protracker.ini
+++ b/vs2019_project/pt2-clone/protracker.ini
@@ -33,21 +33,19 @@
 64K_LIMIT=TRUE
 
 [VIDEO SETTINGS]
-; Video scaling factor
-;        Syntax: 1X, 2X, 3X ... 9X
-; Default value: 2X
-;       Comment: Sets the video scaling factor (window rendering size).
+; Video upscaling factor
+;        Syntax: AUTO, 1X, 2X, 3X, 4X ... 16X
+; Default value: AUTO
+;       Comment: Sets the video upscaling factor (window size).
+;       AUTO = Auto-fit (tries to find the optimal value for the screen)
 ;         1X = 320x255 (no scaling)
-;         2X = 640x510 (default)
-;         3x = 960x765
+;         2X = 640x510
+;         3X = 960x765
 ;         4x = 1280x1020
-;         5x = 1600x1275
-;         6x = 1920x1530
-;         7x = 2240x1785
-;         8x = 2560x2040
-;         9x = 2880x2295
+;         ...and so on up to 16X
+;         (width = 320*x, height = 255*x)
 ;
-VIDEOSCALE=2X
+VIDEOSCALE=AUTO
 
 ; Start in fullscreen mode
 ;        Syntax: TRUE or FALSE