Skip to content

Commit

Permalink
all working now
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdb committed Oct 21, 2024
1 parent d13cf23 commit 19aac7a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/unix/sysdep/dsp-drivers/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
38 changes: 29 additions & 9 deletions src/unix/video-drivers/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -259,6 +272,7 @@ int sysdep_create_display(int depth)
Vid_height = best_height;
}
}
SDL_free(modes);

if( depth == 16 )
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
Expand Down

0 comments on commit 19aac7a

Please sign in to comment.