libsdl-org / sdl12-compat

An SDL-1.2 compatibility layer that uses SDL 2.0 behind the scenes.
Other
194 stars 40 forks source link

Add a SDL12COMPAT_MAX_BPP hint, and use it to restrict Hyperspace Delivery Boy to 16bpp (fixes #317) #321

Closed sulix closed 1 year ago

sulix commented 1 year ago

Some games (e.g. Hyperspace Delivery Boy) only work on a 16-bit display, but request the highest bit-depth available. Add a hint which makes all queries for a mode (including the current mode, and the implicit format chosen by providng SDL_SetVideoMode() a bpp of 0) report a bit depth less than or equal to the value of SDL12COMPAT_FORCE_BPP.

We then add a quirk to force Hyperspace Delivery Boy to 16-bit, as it uses the current video mode's bpp, but for 32-bit modes relies heavily on the exact way format conversion was broken in some SDL 1.2 versions.

There are a few interesting "features" of this implementation:

Regardless, this seems, at least to me, to be a better solution than trying to emulate all of the ways different versions of SDL 1.2 could get format conversion wrong. And, if you're bored, you can force games to run at 8bpp and enjoy the horrible colour banding.

slouken commented 1 year ago

Looks good, thanks!

sezero commented 1 year ago

SDL_BITSPERPIXEL(mode.format) > max_bpp triggers -Wsign-compare If you change max_bpp to unsigned and BPPToPixelFormat to accept unsigned all is good, like

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index f3ecd3b..f089a69 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -2049 +2049 @@ static SDL_PixelFormatEnum
-BPPToPixelFormat(int bpp)
+BPPToPixelFormat(unsigned bpp)
@@ -2247 +2247 @@ Init12VidModes(void)
-    const int max_bpp = SDL12Compat_GetHintInt("SDL12COMPAT_MAX_BPP", 32);
+    const unsigned max_bpp = SDL12Compat_GetHintInt("SDL12COMPAT_MAX_BPP", 32);
@@ -2416 +2416 @@ Init12Video(void)
-    const int max_bpp = SDL12Compat_GetHintInt("SDL12COMPAT_MAX_BPP", 32);
+    const unsigned max_bpp = SDL12Compat_GetHintInt("SDL12COMPAT_MAX_BPP", 32);

OK, pushing that myself (noticed late that it's already merged)

sulix commented 1 year ago

SDL_BITSPERPIXEL(mode.format) > max_bpp triggers -Wsign-compare If you change max_bpp to unsigned and BPPToPixelFormat to accept unsigned all is good[…]

Whoops — nice catch, thanks!