Skip to content

Commit 9cdfcc0

Browse files
committed
Update MZX to work with SDL3 8ea38ebe.
1 parent 7f1ee51 commit 9cdfcc0

File tree

6 files changed

+54
-21
lines changed

6 files changed

+54
-21
lines changed

src/SDLmzx.h

-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ static inline void SDL_SetJoystickEventsEnabled(SDL_bool enabled)
319319
#define SDL_KMOD_ALT KMOD_ALT
320320
#define SDL_KMOD_NUM KMOD_NUM
321321
#define SDL_KMOD_CAPS KMOD_CAPS
322-
#define SDL_TextInputActive(w) SDL_IsTextInputActive()
323322
#endif
324323

325324
/**

src/audio/driver_sdl3.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void sdl_audio_callback(void *userdata, SDL_AudioStream *stream,
5050

5151
void init_audio_platform(struct config_info *conf)
5252
{
53-
SDL_AudioDeviceID audio_device = SDL_AUDIO_DEVICE_DEFAULT_OUTPUT;
53+
SDL_AudioDeviceID audio_device = SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
5454
int frames = 0;
5555
char hint[16];
5656
void *tmp;
@@ -59,7 +59,7 @@ void init_audio_platform(struct config_info *conf)
5959
audio_format = SAMPLE_S16;
6060

6161
memset(&audio_settings, 0, sizeof(audio_settings));
62-
if(SDL_GetAudioDeviceFormat(audio_device, &audio_settings, &frames) < 0)
62+
if(!SDL_GetAudioDeviceFormat(audio_device, &audio_settings, &frames))
6363
{
6464
// Can't query, try to continue anyway...
6565
audio_settings.freq = 48000;

src/editor/clipboard_sdl2.c

+4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ void copy_buffer_to_clipboard(char **buffer, int lines, int total_length)
4444
}
4545

4646
dest_ptr[-1] = 0;
47+
#if SDL_VERSION_ATLEAST(3,0,0)
48+
if(!SDL_SetClipboardText(dest_data))
49+
#else
4750
if(SDL_SetClipboardText(dest_data) < 0)
51+
#endif
4852
warn("SDL_SetClipboardText failed: %s\n", SDL_GetError());
4953

5054
free(dest_data);

src/event_sdl.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,13 @@ static boolean process_event(SDL_Event *event)
974974
struct buffered_status *status = store_status();
975975
enum keycode ckey;
976976

977-
#if SDL_VERSION_ATLEAST(2,0,0)
977+
#if SDL_VERSION_ATLEAST(3,0,0)
978+
boolean unicode_fallback = false; // FIXME: this is per-window now
979+
#elif SDL_VERSION_ATLEAST(2,0,0)
978980
/* Enable converting keycodes to fake unicode presses when text input isn't
979981
* active. Enabling text input also enables an onscreen keyboard in some
980982
* ports, so it isn't always desired. */
981-
boolean unicode_fallback = !SDL_TextInputActive(NULL); // FIXME
983+
boolean unicode_fallback = !SDL_IsTextInputActive();
982984
#else
983985
/* SDL 1.2 might also need this (Pandora? doesn't generate unicode presses). */
984986
static boolean unicode_fallback = true;

src/platform_sdl.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ boolean platform_init(void)
164164
}
165165
}
166166

167-
#if SDL_VERSION_ATLEAST(2,0,0)
167+
#if SDL_VERSION_ATLEAST(3,0,0)
168+
// FIXME: Can't do this here, because it is per-window.
169+
#elif SDL_VERSION_ATLEAST(2,0,0)
168170
/* Most platforms want text input events always on so they can generate
169171
* convenient unicode text values, but in Android this causes some problems:
170172
*
@@ -178,7 +180,7 @@ boolean platform_init(void)
178180
* TODO: this probably redundant with behavior already in SDL.
179181
*/
180182
if(!SDL_HasScreenKeyboardSupport())
181-
SDL_StartTextInput(NULL); // FIXME
183+
SDL_StartTextInput();
182184
#else
183185
SDL_EnableUNICODE(1);
184186
#endif

src/render_sdl.c

+40-14
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ static boolean sdl_get_desktop_display_mode(SDL_DisplayMode *display_mode)
8181
const SDL_DisplayMode *mode;
8282
int count;
8383

84-
mode = SDL_GetDesktopDisplayMode(0);
84+
SDL_DisplayID id = SDL_GetPrimaryDisplay();
85+
if(id == 0)
86+
return false;
87+
88+
mode = SDL_GetDesktopDisplayMode(id);
8589
if(mode)
8690
{
8791
*display_mode = *mode;
@@ -129,8 +133,12 @@ static boolean sdl_get_smallest_usable_display_mode(SDL_DisplayMode *display_mod
129133
int count;
130134
int i;
131135

132-
const SDL_DisplayMode **list =
133-
(const SDL_DisplayMode **)SDL_GetFullscreenDisplayModes(0, &count);
136+
const SDL_DisplayMode **list;
137+
SDL_DisplayID id = SDL_GetPrimaryDisplay();
138+
if(id == 0)
139+
return false;
140+
141+
list = (const SDL_DisplayMode **)SDL_GetFullscreenDisplayModes(id, &count);
134142
if(!list)
135143
return false;
136144

@@ -402,9 +410,12 @@ void sdl_destruct_window(struct graphics_data *graphics)
402410
}
403411

404412
// Used for 8bpp support for the software renderer.
413+
// This is attached to the surface in SDL3 and should not be destroyed.
405414
if(render_data->palette)
406415
{
416+
#if !SDL_VERSION_ATLEAST(3,0,0)
407417
SDL_DestroyPalette(render_data->palette);
418+
#endif
408419
render_data->palette = NULL;
409420
}
410421

@@ -544,7 +555,7 @@ boolean sdl_set_video_mode(struct graphics_data *graphics, int width,
544555
struct sdl_render_data *render_data = graphics->render_data;
545556

546557
#if SDL_VERSION_ATLEAST(2,0,0)
547-
SDL_PixelFormatDetails *format;
558+
SDL_Surface *target;
548559
boolean fullscreen_windowed = graphics->fullscreen_windowed;
549560
boolean matched = false;
550561
Uint32 fmt;
@@ -620,35 +631,49 @@ boolean sdl_set_video_mode(struct graphics_data *graphics, int width,
620631
render_data->shadow = NULL;
621632
}
622633

623-
format = render_data->shadow ? render_data->shadow->format :
624-
render_data->screen->format;
625-
render_data->flat_format = format;
634+
target = render_data->shadow ? render_data->shadow : render_data->screen;
635+
#if SDL_VERSION_ATLEAST(3,0,0)
636+
render_data->flat_format = SDL_GetPixelFormatDetails(target->format);
637+
#else
638+
render_data->flat_format = target->format;
639+
#endif
626640

627641
if(fmt == SDL_PIXELFORMAT_INDEX8)
628642
{
629-
render_data->palette = SDL_CreatePalette(SMZX_PAL_SIZE);
643+
#if SDL_VERSION_ATLEAST(3,0,0)
644+
render_data->palette = SDL_CreateSurfacePalette(target);
630645
if(!render_data->palette)
631646
{
632647
warn("Failed to allocate palette: %s\n", SDL_GetError());
633648
goto err_free;
634649
}
635-
render_data->palette_colors =
636-
(SDL_Color *)ccalloc(SMZX_PAL_SIZE, sizeof(SDL_Color));
637-
if(!render_data->palette_colors)
650+
#else
651+
render_data->palette = SDL_CreatePalette(SMZX_PAL_SIZE);
652+
if(!render_data->palette)
638653
{
639-
warn("Failed to allocate palette colors\n");
654+
warn("Failed to allocate palette: %s\n", SDL_GetError());
640655
goto err_free;
641656
}
642657

643-
if(SDL_SetPixelFormatPalette(format, render_data->palette))
658+
if(SDL_SetPixelFormatPalette(target->format, render_data->palette))
644659
{
645660
warn("Failed to set pixel format palette: %s\n", SDL_GetError());
646661
goto err_free;
647662
}
663+
#endif
664+
665+
render_data->palette_colors =
666+
(SDL_Color *)ccalloc(SMZX_PAL_SIZE, sizeof(SDL_Color));
667+
if(!render_data->palette_colors)
668+
{
669+
warn("Failed to allocate palette colors\n");
670+
goto err_free;
671+
}
648672
}
649673
else
650674
{
651675
render_data->palette = NULL;
676+
render_data->palette_colors = NULL;
652677
}
653678

654679
sdl_window_id = SDL_GetWindowID(render_data->window);
@@ -964,7 +989,8 @@ boolean sdlrender_set_video_mode(struct graphics_data *graphics,
964989
if(!render_data->rgb_to_yuv)
965990
{
966991
#if SDL_VERSION_ATLEAST(3,0,0)
967-
#error wtf
992+
render_data->flat_format =
993+
SDL_GetPixelFormatDetails(render_data->texture_format);
968994
#else
969995
// This is required for SDL_MapRGBA to work, but YUV formats can ignore it.
970996
render_data->pixel_format = SDL_AllocFormat(render_data->texture_format);

0 commit comments

Comments
 (0)