From 19aac7a29556bf9da9b9fbe7d85c89427acd613e Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Tue, 22 Oct 2024 00:11:53 +0200 Subject: [PATCH] all working now --- src/unix/sysdep/dsp-drivers/sdl.c | 4 ++-- src/unix/video-drivers/sdl.c | 38 +++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/unix/sysdep/dsp-drivers/sdl.c b/src/unix/sysdep/dsp-drivers/sdl.c index 0663b2ce3..54045aa08 100644 --- a/src/unix/sysdep/dsp-drivers/sdl.c +++ b/src/unix/sysdep/dsp-drivers/sdl.c @@ -173,8 +173,8 @@ static int sdl_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data, // get stream from dsp const struct sdl_info *info = (struct sdl_info *)dsp->_priv; - const int result = SDL_PutAudioStreamData(info->stream, data, len); - if (result != 0) { + const bool success = SDL_PutAudioStreamData(info->stream, data, len); + if (!success) { fprintf(stderr, "error: SDL_PutAudioStreamData() failed: %s\n", SDL_GetError()); return 0; } diff --git a/src/unix/video-drivers/sdl.c b/src/unix/video-drivers/sdl.c index 393f7bbb6..7bb33e58e 100644 --- a/src/unix/video-drivers/sdl.c +++ b/src/unix/video-drivers/sdl.c @@ -152,6 +152,19 @@ void sysdep_close(void) int sysdep_create_display(int depth) { + // print all video drivers and mark the one in use + int num_drivers = SDL_GetNumVideoDrivers(); + const char *driver_name = SDL_GetCurrentVideoDriver(); + fprintf(stderr, "SDL: Info: Found %d video drivers\n", num_drivers); + for (int i = 0; i < num_drivers; i++) { + const char *driver = SDL_GetVideoDriver(i); + fprintf(stderr, "SDL: Info: Video driver %d: %s", i, driver); + if (strcmp(driver, driver_name) == 0) { + fprintf(stderr, " (in use)"); + } + fprintf(stderr, "\n"); + } + fprintf(stderr, "SDL: Info: Create display with depth %d\n", depth); int vid_modes_i; #ifdef DIRECT_HERMES @@ -160,8 +173,9 @@ int sysdep_create_display(int depth) #endif /* DIRECT_HERMES */ int vid_mode_flag; /* Flag to set the video mode */ - const SDL_DisplayMode *current_mode = SDL_GetCurrentDisplayMode(0); - if (current_mode != NULL) { + const SDL_DisplayID display = SDL_GetPrimaryDisplay(); + const SDL_DisplayMode *current_mode = SDL_GetCurrentDisplayMode(display); + if (current_mode == NULL) { fprintf(stderr, "SDL: Error getting current display mode: %s\n", SDL_GetError()); SDL_Quit(); exit (OSD_NOT_OK); @@ -189,10 +203,8 @@ int sysdep_create_display(int depth) // TODO how do we know if hardware acceleration is available? // hardware = video_info->hw_available; - - const int display_index = 0; int modes_count = 0; - SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display_index, &modes_count); + SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &modes_count); /* Best video mode found */ int best_vid_mode = -1; int best_width = -1; @@ -212,10 +224,11 @@ int sysdep_create_display(int depth) #endif - for (int mode_index = 0; mode_index <= modes_count; mode_index++) + // last mode is NULL, + for (int mode_index = 0; mode_index < modes_count; mode_index++) { const SDL_DisplayMode mode = *modes[mode_index]; - SDL_Log(" %i bpp\t%i x %i @ %iHz", + SDL_Log(" %i bpp\t%i x %i @ %fHz", SDL_BITSPERPIXEL(mode.format), mode.w, mode.h, mode.refresh_rate); #ifdef SDL_DEBUG @@ -259,6 +272,7 @@ int sysdep_create_display(int depth) Vid_height = best_height; } } + SDL_free(modes); if( depth == 16 ) { @@ -952,7 +966,13 @@ void sysdep_update_keyboard() /* added functions */ int sysdep_display_16bpp_capable(void) { - const SDL_DisplayMode *mode = SDL_GetCurrentDisplayMode(0); + const SDL_DisplayID display = SDL_GetPrimaryDisplay(); + const SDL_DisplayMode *mode = SDL_GetCurrentDisplayMode(display); + if (mode == NULL) + { + fprintf(stderr, "SDL: Error getting current display mode: %s\n", SDL_GetError()); + return false; + } const int bpp = SDL_BITSPERPIXEL(mode->format); return ( bpp >=16); } @@ -975,7 +995,7 @@ int list_sdl_modes(struct rc_option *option, const char *arg, int priority) for (int mode_index = 0; mode_index <= modes_count; mode_index++) { const SDL_DisplayMode mode = *modes[mode_index]; - printf("\t%d) Mode %d x %d @ %iHz\n", + printf("\t%d) Mode %d x %d @ %fHz\n", mode_index, mode.w, mode.h,