From a73be564883371c1b30645aa385da80725c05209 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Wed, 24 Jan 2024 18:26:34 +0100 Subject: [PATCH 01/14] wip: xpinmame on linux using sdl2 for video and audio --- .github/workflows/xpinmame.yml | 2 +- cmake/xpinmame/CMakeLists_linux-x64.txt | 22 +- src/unix/sysdep/dsp-drivers/sdl.c | 183 ++++++--------- src/unix/video-drivers/sdl.c | 288 ++++++++++++++++-------- 4 files changed, 277 insertions(+), 218 deletions(-) diff --git a/.github/workflows/xpinmame.yml b/.github/workflows/xpinmame.yml index 92f40981f..76900cc8d 100644 --- a/.github/workflows/xpinmame.yml +++ b/.github/workflows/xpinmame.yml @@ -62,7 +62,7 @@ jobs: - if: matrix.os == 'ubuntu-latest' run: | - sudo apt install libx11-dev libxv-dev libasound2-dev + sudo apt install libx11-dev libxv-dev libasound2-dev sdl2-dev - name: Build xpinmame-${{ matrix.platform }} run: | cp cmake/xpinmame/CMakeLists_${{ matrix.platform }}.txt CMakeLists.txt diff --git a/cmake/xpinmame/CMakeLists_linux-x64.txt b/cmake/xpinmame/CMakeLists_linux-x64.txt index 010f0b680..383431c14 100644 --- a/cmake/xpinmame/CMakeLists_linux-x64.txt +++ b/cmake/xpinmame/CMakeLists_linux-x64.txt @@ -107,9 +107,10 @@ add_compile_definitions( XMAMEROOT="/usr/local/share/xpinmame" HAVE_SNPRINTF HAVE_GETTIMEOFDAY - #SYSDEP_DSP_ALSA - #SYSDEP_MIXER_ALSA - SYSDEP_DSP_OSS +# SYSDEP_DSP_ALSA +# SYSDEP_MIXER_ALSA + SYSDEP_DSP_SDL + SDL_DEBUG ) add_executable(xpinmame @@ -625,10 +626,11 @@ add_executable(xpinmame src/unix/sysdep/sysdep_mixer.c # src/unix/sysdep/dsp-drivers/alsa.c # src/unix/sysdep/mixer-drivers/alsa.c - src/unix/sysdep/dsp-drivers/oss.c - src/unix/video-drivers/x11.c - src/unix/video-drivers/xinput.c - src/unix/video-drivers/x11_window.c + src/unix/sysdep/dsp-drivers/sdl.c +# src/unix/video-drivers/x11.c +# src/unix/video-drivers/xinput.c +# src/unix/video-drivers/x11_window.c + src/unix/video-drivers/sdl.c src/unix/joystick-drivers/joy_i386.c src/unix/joystick-drivers/joy_pad.c src/unix/joystick-drivers/joy_x11.c @@ -649,6 +651,10 @@ find_package( ALSA ) +find_package( + SDL2 +) + target_include_directories(xpinmame PUBLIC src src/wpc @@ -659,6 +665,7 @@ target_include_directories(xpinmame PUBLIC ${X11_X11_INCLUDE_PATH} ${X11_Xv_INCLUDE_PATH} ${ALSA_INCLUDE_DIRS} + ${SDL2_INCLUDE_DIRS} ) target_link_libraries(xpinmame PUBLIC @@ -667,6 +674,7 @@ target_link_libraries(xpinmame PUBLIC ${X11_Xv_LIB} ${X11_Xext_LIB} ${ALSA_LIBRARIES} + ${SDL2_LIBRARIES} ) set_target_properties(xpinmame PROPERTIES diff --git a/src/unix/sysdep/dsp-drivers/sdl.c b/src/unix/sysdep/dsp-drivers/sdl.c index b9dd358d8..cf396ecb9 100644 --- a/src/unix/sysdep/dsp-drivers/sdl.c +++ b/src/unix/sysdep/dsp-drivers/sdl.c @@ -30,34 +30,23 @@ Version 0.1, January 2002 */ + +// SDL defines this to __inline__ which no longer works with gcc 5+ ? +// TODO find the correct way to handle this, similar issue with ALSA +#ifndef SDL_FORCE_INLINE +#if ( (defined(__GNUC__) && (__GNUC__ >= 5))) +#define SDL_FORCE_INLINE __attribute__((always_inline)) static inline +#endif +#endif /* take the definition from SDL */ + #include #include #include -#include -#include "SDL.h" +#include "SDL2/SDL.h" #include "sysdep/sysdep_dsp.h" #include "sysdep/sysdep_dsp_priv.h" #include "sysdep/plugin_manager.h" -#ifdef __BEOS__ -#define BUFFERSIZE 1470 * 4 /* in my experience, BeOS likes buffers to be 4x */ -#else -#define BUFFERSIZE 1024 -#endif - -/* private variables */ -static struct { - Uint8 *data; - int amountRemain; - int amountWrite; - int amountRead; - int tmp; - Uint32 soundlen; - int sound_n_pos; - int sound_w_pos; - int sound_r_pos; -} sample; - /* callback function prototype */ static void sdl_fill_sound(void *unused, Uint8 *stream, int len); @@ -80,6 +69,10 @@ const struct plugin_struct sysdep_dsp_sdl = { 3 /* high priority */ }; +struct sdl_info { + SDL_AudioDeviceID id; +}; + /* public methods (static but exported through the sysdep_dsp or plugin struct) */ static void *sdl_dsp_create(const void *flags) @@ -105,14 +98,6 @@ static void *sdl_dsp_create(const void *flags) sdl_dsp_destroy(dsp); return NULL; } - - - if (!(sample.data = calloc(BUFFERSIZE, sizeof(Uint8)))) - { - fprintf(stderr, "error malloc failed for data\n"); - sdl_dsp_destroy(dsp); - return NULL; - } /* fill in the functions and some data */ dsp->_priv = priv; @@ -120,39 +105,58 @@ static void *sdl_dsp_create(const void *flags) dsp->destroy = sdl_dsp_destroy; dsp->hw_info.type = params->type; dsp->hw_info.samplerate = params->samplerate; - - - /* set the number of bits */ + audiospec->format = (dsp->hw_info.type & SYSDEP_DSP_16BIT)? AUDIO_S16SYS : AUDIO_S8; - - /* set the number of channels */ audiospec->channels = (dsp->hw_info.type & SYSDEP_DSP_STEREO)? 2:1; - - /* set the samplerate */ audiospec->freq = dsp->hw_info.samplerate; - - /* set samples size */ - audiospec->samples = BUFFERSIZE; - - /* set callback funcion */ - audiospec->callback = sdl_fill_sound; - - audiospec->userdata = NULL; - + /* Open audio device */ if(SDL_WasInit(SDL_INIT_VIDEO)!=0) /* If sdl video system is already */ SDL_InitSubSystem(SDL_INIT_AUDIO);/* initialized, we just initialize */ else /* the audio subsystem */ SDL_Init(SDL_INIT_AUDIO); /* else we MUST use "SDL_Init" */ /* (untested) */ - if (SDL_OpenAudio(audiospec, NULL) != 0) { - fprintf(stderr, "failed opening audio device\n"); - return NULL; - } - SDL_PauseAudio(0); + + fprintf(stderr, "sdl info: driver = %s\n", SDL_GetCurrentAudioDriver()); + + // get audio subsystem and open a queue with above spec + SDL_AudioSpec *obtained; + if (!(obtained = calloc(1, sizeof(SDL_AudioSpec)))) + { + fprintf(stderr, "sdl error: malloc failed for SDL_AudioSpec\n"); + sdl_dsp_destroy(dsp); + return NULL; + } + + const SDL_AudioDeviceID id = SDL_OpenAudioDevice(NULL, 0, audiospec, obtained, 0); + if (id == 0) { + fprintf(stderr, "sdl error: SDL_OpenAudioDevice() failed: %s\n", SDL_GetError()); + return NULL; + } + + // free the spec + free(audiospec); + + // print the id + fprintf(stderr, "sdl info: device id = %d\n", id); + // print the obtained contents + fprintf(stderr, "sdl info: obtained->format = %d\n", obtained->format); + fprintf(stderr, "sdl info: obtained->channels = %d\n", obtained->channels); + fprintf(stderr, "sdl info: obtained->freq = %d\n", obtained->freq); + fprintf(stderr, "sdl info: obtained->samples = %d\n", obtained->samples); + fprintf(stderr, "sdl info: obtained->callback = %p\n", obtained->callback); + fprintf(stderr, "sdl info: obtained->userdata = %p\n", obtained->userdata); + + // resume playing on device + SDL_PauseAudioDevice(id, 0); + + struct sdl_info *info = (struct sdl_info *)calloc(1, sizeof(struct sdl_info)); + info->id = id; + + dsp->_priv = info; - fprintf(stderr, "info: audiodevice %s set to %dbit linear %s %dHz\n", + fprintf(stderr, "sdl info: audiodevice %s set to %dbit linear %s %dHz\n", device, (dsp->hw_info.type & SYSDEP_DSP_16BIT)? 16:8, (dsp->hw_info.type & SYSDEP_DSP_STEREO)? "stereo":"mono", dsp->hw_info.samplerate); @@ -171,74 +175,19 @@ static void sdl_dsp_destroy(struct sysdep_dsp_struct *dsp) static int sdl_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data, int count) { - /* sound_n_pos = normal position - sound_r_pos = read position - and so on. */ - int result = 0; - Uint8 *src; - SDL_LockAudio(); - - sample.amountRemain = BUFFERSIZE - sample.sound_n_pos; - sample.amountWrite = (dsp->hw_info.type & SYSDEP_DSP_STEREO)? count * 4 : count * 2; - - if(sample.amountRemain <= 0) { - SDL_UnlockAudio(); - return(result); - } - - if(sample.amountRemain < sample.amountWrite) sample.amountWrite = sample.amountRemain; - result = (int)sample.amountWrite; - sample.sound_n_pos += sample.amountWrite; - - src = (Uint8 *)data; - sample.tmp = BUFFERSIZE - sample.sound_w_pos; - - if(sample.tmp < sample.amountWrite){ - memcpy(sample.data + sample.sound_w_pos, src, sample.tmp); - sample.amountWrite -= sample.tmp; - src += sample.tmp; - memcpy(sample.data, src, sample.amountWrite); - sample.sound_w_pos = sample.amountWrite; - } - else{ - memcpy( sample.data + sample.sound_w_pos, src, sample.amountWrite); - sample.sound_w_pos += sample.amountWrite; - } - SDL_UnlockAudio(); - - return count; -} + // count is the number of samples to write + const int len = (dsp->hw_info.type & SYSDEP_DSP_STEREO)? count * 4 : count * 2; -/* Private method */ -static void sdl_fill_sound(void *unused, Uint8 *stream, int len) -{ - int result; - Uint8 *dst; - SDL_LockAudio(); - sample.amountRead = len; - if(sample.sound_n_pos <= 0) - SDL_UnlockAudio(); - - if(sample.sound_n_pos_priv; + const SDL_AudioDeviceID dev = info->id; + const int result = SDL_QueueAudio(dev, data, len); + if (result != 0) { + fprintf(stderr, "error: SDL_QueueAudio() failed: %s\n", SDL_GetError()); + return 0; + } + return count; } #endif /* ifdef SYSDEP_DSP_SDL */ diff --git a/src/unix/video-drivers/sdl.c b/src/unix/video-drivers/sdl.c index 9115b14c5..5dccfab44 100644 --- a/src/unix/video-drivers/sdl.c +++ b/src/unix/video-drivers/sdl.c @@ -29,12 +29,19 @@ /* #define PARANOIC */ #define __SDL_C -#undef SDL_DEBUG /* #define DIRECT_HERMES */ +// SDL defines this to __inline__ which no longer works with gcc 5+ ? +// TODO find the correct way to handle this, similar issue with ALSA +#ifndef SDL_FORCE_INLINE +#if ( (defined(__GNUC__) && (__GNUC__ >= 5))) +#define SDL_FORCE_INLINE __attribute__((always_inline)) static inline +#endif +#endif /* take the definition from SDL */ + #include #include -#include +#include #include "xmame.h" #include "devices.h" #include "keyboard.h" @@ -48,6 +55,7 @@ static int Vid_width; static int Vid_height; static int Vid_depth = 8; +static SDL_Window *Window; static SDL_Surface* Surface; static SDL_Surface* Offscreen_surface; static int hardware=1; @@ -101,7 +109,7 @@ void sdl_update_rgb_direct_32bpp(struct mame_bitmap *bitmap); int sysdep_init(void) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf (stderr, "SDL: Error: %s\n",SDL_GetError()); + fprintf (stderr, "SDL: Init error: %s\n",SDL_GetError()); return OSD_NOT_OK; } #ifdef DIRECT_HERMES @@ -119,8 +127,7 @@ void sysdep_close(void) int sysdep_create_display(int depth) { - SDL_Rect** vid_modes; - const SDL_VideoInfo* video_info; + fprintf(stderr, "SDL: Info: Create display with depth %d\n", depth); int vid_modes_i; #ifdef DIRECT_HERMES HermesFormat* H_src_format; @@ -128,72 +135,84 @@ int sysdep_create_display(int depth) #endif /* DIRECT_HERMES */ int vid_mode_flag; /* Flag to set the video mode */ - video_info = SDL_GetVideoInfo(); + SDL_DisplayMode current_mode; + SDL_GetCurrentDisplayMode(0, ¤t_mode); + + SDL_PixelFormat *format = SDL_AllocFormat(current_mode.format); #ifdef SDL_DEBUG fprintf (stderr,"SDL: create_display(%d): \n",depth); - fprintf (stderr,"SDL: Info: HW blits %d\n" - "SDL: Info: SW blits %d\n" - "SDL: Info: Vid mem %d\n" + fprintf (stderr, + // "SDL: Info: HW blits %d\n" + // "SDL: Info: SW blits %d\n" + // "SDL: Info: Vid mem %d\n" "SDL: Info: Best supported depth %d\n", - video_info->blit_hw, - video_info->blit_sw, - video_info->video_mem, - video_info->vfmt->BitsPerPixel); + // video_info->blit_hw, + // video_info->blit_sw, + // video_info->video_mem, + format->BitsPerPixel); #endif - Vid_depth = video_info->vfmt->BitsPerPixel; + // get SDL_PixelFormat from mode.format - vid_modes = SDL_ListModes(NULL,SDL_FULLSCREEN); - vid_modes_i = 0; + Vid_depth = format->BitsPerPixel; - hardware = video_info->hw_available; + // TODO how do we know if hardware acceleration is available? + // hardware = video_info->hw_available; - if ( (! vid_modes) || ((long)vid_modes == -1)) { + + const int display_index = 0; + const int modes_count = SDL_GetNumDisplayModes(display_index); + /* Best video mode found */ + int best_vid_mode = -1; + int best_width = -1; + int best_height = -1; + if (modes_count < 1) + { #ifdef SDL_DEBUG - fprintf (stderr, "SDL: Info: Possible all video modes available\n"); + fprintf (stderr, "SDL: Error listing display modes: %s\n",SDL_GetError()); #endif Vid_height = visual_height*heightscale; Vid_width = visual_width*widthscale; - } else { - int best_vid_mode; /* Best video mode found */ - int best_width,best_height; - int i; + }else + { #ifdef SDL_DEBUG fprintf (stderr, "SDL: visual w:%d visual h:%d\n", visual_width, visual_height); #endif - best_vid_mode = 0; - best_width = vid_modes[best_vid_mode]->w; - best_height = vid_modes[best_vid_mode]->h; - for (i=0;vid_modes[i];++i) + + + for (int mode_index = 0; mode_index <= modes_count; mode_index++) { - int cur_width, cur_height; + SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; - cur_width = vid_modes[i]->w; - cur_height = vid_modes[i]->h; + if (SDL_GetDisplayMode(display_index, mode_index, &mode) == 0) + { + SDL_Log(" %i bpp\t%i x %i @ %iHz", + SDL_BITSPERPIXEL(mode.format), mode.w, mode.h, mode.refresh_rate); #ifdef SDL_DEBUG - fprintf (stderr, "SDL: Info: Found mode %d x %d\n", cur_width, cur_height); + fprintf (stderr, "SDL: Info: Found mode %d x %d\n", mode.w, mode.h); #endif /* SDL_DEBUG */ - /* If width and height too small, skip to next mode */ - if ((cur_width < visual_width*widthscale) || (cur_height < visual_height*heightscale)) { - continue; - } + /* If width and height too small, skip to next mode */ + if ((mode.w < visual_width*widthscale) || (mode.h < visual_height*heightscale)) { + continue; + } - /* If width or height smaller than current best, keep it */ - if ((cur_width < best_width) || (cur_height < best_height)) { - best_vid_mode = i; - best_width = cur_width; - best_height = cur_height; + /* If width or height smaller than current best, keep it */ + if ((mode.w < best_width) || (mode.h < best_height)) { + best_vid_mode = mode_index; + best_width = mode.w; + best_height = mode.h; + } } } #ifdef SDL_DEBUG fprintf (stderr, "SDL: Info: Best mode found : %d x %d\n", - vid_modes[best_vid_mode]->w, - vid_modes[best_vid_mode]->h); + best_width, + best_height); #endif /* SDL_DEBUG */ vid_modes_i = best_vid_mode; @@ -210,11 +229,8 @@ int sysdep_create_display(int depth) Vid_height = visual_height*heightscale; Vid_width = visual_width*widthscale; } else { - if(*(vid_modes+vid_modes_i)==NULL) - vid_modes_i--; - - Vid_width = (*(vid_modes + vid_modes_i))->w; - Vid_height = (*(vid_modes + vid_modes_i))->h; + Vid_width = best_width; + Vid_height = best_height; } } @@ -260,18 +276,29 @@ int sysdep_create_display(int depth) /* Set video mode according to flags */ - vid_mode_flag = SDL_HWSURFACE; + vid_mode_flag = SDL_WINDOW_SHOWN; if (start_fullscreen) { - vid_mode_flag |= SDL_FULLSCREEN; + vid_mode_flag |= SDL_WINDOW_FULLSCREEN; } - if(! (Surface = SDL_SetVideoMode(Vid_width, Vid_height,Vid_depth, vid_mode_flag))) { + // TODO set scaling factor on canvas + // enable hidpi/scaling support + // on Linux this requires SDL_VIDEODRIVER=wayland + // vid_mode_flag |= SDL_WINDOW_ALLOW_HIGHDPI; + + // https://nlguillemot.wordpress.com/2016/12/11/high-dpi-rendering/ + + // TODO set Vid_dep? + + if(! (Window = SDL_CreateWindow(title,SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED,Vid_width, Vid_height, vid_mode_flag))) { fprintf (stderr, "SDL: Error: Setting video mode failed\n"); SDL_Quit(); exit (OSD_NOT_OK); } else { fprintf (stderr, "SDL: Info: Video mode set as %d x %d, depth %d\n", Vid_width, Vid_height, Vid_depth); } + Surface = SDL_GetWindowSurface(Window); #ifndef DIRECT_HERMES Offscreen_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,Vid_width,Vid_height,Vid_depth,0,0,0,0); @@ -297,8 +324,10 @@ int sysdep_create_display(int depth) /* Creating event mask */ SDL_EventState(SDL_KEYUP, SDL_ENABLE); SDL_EventState(SDL_KEYDOWN, SDL_ENABLE); - SDL_EnableUNICODE(1); - + + // TODO no longer exists + //SDL_EnableUNICODE(1); + /* fill the display_palette_info struct */ memset(&display_palette_info, 0, sizeof(struct sysdep_palette_info)); display_palette_info.depth = Vid_depth; @@ -318,9 +347,6 @@ int sysdep_create_display(int depth) /* Hide mouse cursor and save its previous status */ cursor_state = SDL_ShowCursor(0); - /* Set window title */ - SDL_WM_SetCaption(title, NULL); - effect_init2(depth, Vid_depth, Vid_width); return OSD_OK; @@ -339,7 +365,7 @@ static int sdl_mapkey(struct rc_option *option, const char *arg, int priority) { /* perform tests */ /* fprintf(stderr,"trying to map %x to %x\n", from, to); */ - if (from >= SDLK_FIRST && from < SDLK_LAST && to >= 0 && to <= 127) + if (from < SDL_NUM_SCANCODES && to <= 127) { klookup[from] = to; return OSD_OK; @@ -446,8 +472,12 @@ void sysdep_update_display(struct mame_bitmap *bitmap) if(SDL_BlitSurface (Offscreen_surface, &srect, Surface, &drect)<0) fprintf (stderr,"SDL: Warn: Unsuccessful blitting\n"); - if(hardware==0) - SDL_UpdateRects(Surface,1, &drect); + // FIXME how do we do this? + // if(hardware==0) + // SDL_UpdateRects(Surface,1, &drect); + + // switch buffer + SDL_UpdateWindowSurface(Window); } #else /* DIRECT_HERMES */ void sysdep_update_display(struct mame_bitmap *bitmap) @@ -606,10 +636,14 @@ void sysdep_update_display(struct mame_bitmap *bitmap) /* shut up the display */ void sysdep_display_close(void) { + fprintf(stderr, "SDL: Info: Shutting down display\n"); SDL_FreeSurface(Offscreen_surface); /* Restore cursor state */ SDL_ShowCursor(cursor_state); + + // close the window + SDL_DestroyWindow(Window); } /* @@ -618,9 +652,7 @@ void sysdep_display_close(void) */ int sysdep_display_alloc_palette(int totalcolors) { - int ncolors; - int i; - ncolors = totalcolors; + int ncolors = totalcolors; fprintf (stderr, "SDL: sysdep_display_alloc_palette(%d);\n",totalcolors); if (Vid_depth != 8) @@ -630,12 +662,12 @@ int sysdep_display_alloc_palette(int totalcolors) Colors = (SDL_Color*) malloc (totalcolors * sizeof(SDL_Color)); if( !Colors ) return 1; - for (i=0;ir = 0xFF; (Colors + i)->g = 0x00; (Colors + i)->b = 0x00; } - SDL_SetColors (Offscreen_surface,Colors,0,totalcolors-1); + SDL_SetPaletteColors (Offscreen_surface->format->palette,Colors,0,totalcolors-1); #else /* DIRECT_HERMES */ H_PaletteHandle = Hermes_PaletteInstance(); if ( !(H_Palette = Hermes_PaletteGet(H_PaletteHandle)) ) { @@ -660,7 +692,7 @@ int sysdep_display_set_pen(int pen,unsigned char red, unsigned char green, unsig (Colors + pen)->r = red; (Colors + pen)->g = green; (Colors + pen)->b = blue; - if ( (! SDL_SetColors(Offscreen_surface, Colors + pen, pen,1)) && (! warned)) { + if ( (! SDL_SetPaletteColors(Offscreen_surface->format->palette, Colors + pen, pen,1)) && (! warned)) { printf ("Color allocation failed, or > 8 bit display\n"); warned = 0; } @@ -678,14 +710,12 @@ int sysdep_display_set_pen(int pen,unsigned char red, unsigned char green, unsig void sysdep_mouse_poll (void) { - int i; int x,y; - Uint8 buttons; - buttons = SDL_GetRelativeMouseState( &x, &y); + Uint8 buttons = SDL_GetRelativeMouseState(&x, &y); mouse_data[0].deltas[0] = x; mouse_data[0].deltas[1] = y; - for(i=0;ivfmt->BitsPerPixel >=16); + SDL_DisplayMode mode; + SDL_GetCurrentDisplayMode(0, &mode); + return ( mode.format >=16); } int list_sdl_modes(struct rc_option *option, const char *arg, int priority) { - SDL_Rect** vid_modes; - int vid_modes_i; - - vid_modes = SDL_ListModes(NULL,SDL_FULLSCREEN); - vid_modes_i = 0; - - if ( (! vid_modes) || ((long)vid_modes == -1)) { + // TODO we might want to go over all displays + const int display_index = 0; + const int modes_count = SDL_GetNumDisplayModes(display_index); + if (modes_count < 1) + { printf("This option only works in a full-screen mode (eg: linux's framebuffer)\n"); return - 1; } + // print modes available printf("Modes available:\n"); - while( *(vid_modes+vid_modes_i) ) { - printf("\t%d) Mode %d x %d\n", - vid_modes_i, - (*(vid_modes+vid_modes_i))->w, - (*(vid_modes+vid_modes_i))->h - ); - - vid_modes_i++; + for (int mode_index = 0; mode_index <= modes_count; mode_index++) + { + SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; + + if (SDL_GetDisplayMode(display_index, mode_index, &mode) == 0) + { + printf("\t%d) Mode %d x %d @ %iHz\n", + mode_index, + mode.w, + mode.h, + mode.refresh_rate + ); + } } return -1; From 61f8402f1afb4d4390f08fd7b94d4fd1ff7b5df1 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Thu, 25 Jan 2024 21:18:19 +0100 Subject: [PATCH 02/14] ci: install libsdl2-dev --- .github/workflows/xpinmame.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/xpinmame.yml b/.github/workflows/xpinmame.yml index 76900cc8d..96a33e2af 100644 --- a/.github/workflows/xpinmame.yml +++ b/.github/workflows/xpinmame.yml @@ -62,7 +62,7 @@ jobs: - if: matrix.os == 'ubuntu-latest' run: | - sudo apt install libx11-dev libxv-dev libasound2-dev sdl2-dev + sudo apt install libx11-dev libxv-dev libasound2-dev libsdl2-dev - name: Build xpinmame-${{ matrix.platform }} run: | cp cmake/xpinmame/CMakeLists_${{ matrix.platform }}.txt CMakeLists.txt From 9ede336454ccbd4b67c6d42847f19f6bbfe48789 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Thu, 25 Jan 2024 22:01:13 +0100 Subject: [PATCH 03/14] chore: define more key bindings --- src/unix/video-drivers/sdl.c | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/unix/video-drivers/sdl.c b/src/unix/video-drivers/sdl.c index 5dccfab44..51ad845e4 100644 --- a/src/unix/video-drivers/sdl.c +++ b/src/unix/video-drivers/sdl.c @@ -782,6 +782,54 @@ int sdl_keycode_to_key(const SDL_Keycode key_code) return KEY_ALT; case SDLK_RALT: return KEY_ALTGR; + case SDLK_CAPSLOCK: + return KEY_CAPSLOCK; + case SDLK_INSERT: + return KEY_INSERT; + case SDLK_DELETE: + return KEY_DEL; + case SDLK_HOME: + return KEY_HOME; + case SDLK_END: + return KEY_END; + case SDLK_PAGEUP: + return KEY_PGUP; + case SDLK_PAGEDOWN: + return KEY_PGDN; + case SDLK_MENU: + return KEY_MENU; + case SDLK_KP_ENTER: + return KEYCODE_ENTER_PAD; + case SDLK_KP_PLUS: + return KEY_PLUS_PAD; + case SDLK_KP_MINUS: + return KEY_MINUS_PAD; + // case SDLK_KP_MULTIPLY: + // return KEY_ASTERISK; + case SDLK_KP_DIVIDE: + return KEY_SLASH_PAD; + // case SDLK_KP_PERIOD: + // return KEY_PERIOD_PAD; + case SDLK_KP_0: + return KEY_0_PAD; + case SDLK_KP_1: + return KEY_1_PAD; + case SDLK_KP_2: + return KEY_2_PAD; + case SDLK_KP_3: + return KEY_3_PAD; + case SDLK_KP_4: + return KEY_4_PAD; + case SDLK_KP_5: + return KEY_5_PAD; + case SDLK_KP_6: + return KEY_6_PAD; + case SDLK_KP_7: + return KEY_7_PAD; + case SDLK_KP_8: + return KEY_8_PAD; + case SDLK_KP_9: + return KEY_9_PAD; default: return KEY_NONE; } From 5d46368ff8cd613dfc33c22b1e8f16ac31e1f2c1 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Thu, 25 Jan 2024 22:20:42 +0100 Subject: [PATCH 04/14] chore: implement unicode text input --- src/unix/video-drivers/sdl.c | 93 +++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/src/unix/video-drivers/sdl.c b/src/unix/video-drivers/sdl.c index 51ad845e4..9969c151c 100644 --- a/src/unix/video-drivers/sdl.c +++ b/src/unix/video-drivers/sdl.c @@ -844,66 +844,73 @@ void sysdep_update_keyboard() if (Surface) { while(SDL_PollEvent(&event)) { kevent.press = 0; - + switch (event.type) { - case SDL_KEYDOWN: - kevent.press = 1; + case SDL_KEYDOWN: + kevent.press = 1; - /* ALT-Enter: toggle fullscreen */ - if ( event.key.keysym.sym == SDLK_RETURN ) + /* ALT-Enter: toggle fullscreen */ + if (event.key.keysym.sym == SDLK_RETURN) + { + if (event.key.keysym.mod & KMOD_ALT) { - if(event.key.keysym.mod & KMOD_ALT) - { - SDL_Window *window = SDL_GetWindowFromID(event.key.windowID); - const Uint32 is_fullscreen = SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP; - SDL_SetWindowFullscreen(window, is_fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); - } + SDL_Window* window = SDL_GetWindowFromID(event.key.windowID); + const Uint32 is_fullscreen = SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP; + SDL_SetWindowFullscreen(window, is_fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); } + } - case SDL_KEYUP: - printf("scancode: %d, sym: %d\n", event.key.keysym.scancode, event.key.keysym.sym); - kevent.unicode = 0; - kevent.scancode = 0; - kevent.scancode = sdl_keycode_to_key(event.key.keysym.sym); - xmame_keyboard_register_event(&kevent); - if(kevent.scancode == KEY_NONE) - fprintf (stderr, "SDL: Unknown symbol 0x%x\n", - event.key.keysym.sym); + case SDL_KEYUP: + kevent.unicode = 0; + kevent.scancode = sdl_keycode_to_key(event.key.keysym.sym); + xmame_keyboard_register_event(&kevent); + if (kevent.scancode == KEY_NONE) + fprintf(stderr, "SDL unknown symbol 0x%x scancode: %d, sym: %d\n", event.key.keysym.sym, + event.key.keysym.scancode, event.key.keysym.sym); + +#ifdef SDL_DEBUG + fprintf(stderr, "Key %s %ssed\n", + SDL_GetKeyName(event.key.keysym.sym), + kevent.press ? "pres" : "relea"); +#endif + break; + case SDL_TEXTINPUT: #ifdef SDL_DEBUG - fprintf (stderr, "Key %s %ssed\n", - SDL_GetKeyName(event.key.keysym.sym), - kevent.press? "pres":"relea"); + fprintf(stderr, "SDL: Text input: %s\n", event.text.text); #endif - break; - case SDL_QUIT: - /* Shoult leave this to application */ - exit(OSD_OK); - break; - - case SDL_JOYAXISMOTION: - if (event.jaxis.which < JOY_AXIS) - joy_data[event.jaxis.which].axis[event.jaxis.axis].val = event.jaxis.value; + kevent.unicode = event.text.text[0]; + kevent.scancode = KEYCODE_OTHER; + xmame_keyboard_register_event(&kevent); + break; + case SDL_QUIT: + /* Shoult leave this to application */ + exit(OSD_OK); + break; + + case SDL_JOYAXISMOTION: + if (event.jaxis.which < JOY_AXIS) + joy_data[event.jaxis.which].axis[event.jaxis.axis].val = event.jaxis.value; #ifdef SDL_DEBUG - fprintf (stderr,"Axis=%d,value=%d\n",event.jaxis.axis ,event.jaxis.value); + fprintf(stderr, "Axis=%d,value=%d\n", event.jaxis.axis, event.jaxis.value); #endif - break; - case SDL_JOYBUTTONDOWN: + break; + case SDL_JOYBUTTONDOWN: - case SDL_JOYBUTTONUP: - if (event.jbutton.which < JOY_BUTTONS) - joy_data[event.jbutton.which].buttons[event.jbutton.button] = event.jbutton.state; + case SDL_JOYBUTTONUP: + if (event.jbutton.which < JOY_BUTTONS) + joy_data[event.jbutton.which].buttons[event.jbutton.button] = event.jbutton.state; #ifdef SDL_DEBUG - fprintf (stderr, "Button=%d,value=%d\n",event.jbutton.button ,event.jbutton.state); + fprintf(stderr, "Button=%d,value=%d\n", event.jbutton.button, event.jbutton.state); #endif - break; + break; - default: + default: #ifdef SDL_DEBUG - fprintf(stderr, "SDL: Debug: Other event %d\n", event.type); + fprintf(stderr, "SDL: Debug: Other event %d\n", event.type); #endif /* SDL_DEBUG */ - break; + break; } joy_evaluate_moves (); } From c50ee560253bd77c6d732be10d0da84e99e6ec84 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Thu, 25 Jan 2024 22:34:17 +0100 Subject: [PATCH 05/14] chore: enable all joysticks --- src/unix/video-drivers/sdl.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/unix/video-drivers/sdl.c b/src/unix/video-drivers/sdl.c index 9969c151c..f72b0a5a4 100644 --- a/src/unix/video-drivers/sdl.c +++ b/src/unix/video-drivers/sdl.c @@ -108,10 +108,30 @@ void sdl_update_rgb_direct_32bpp(struct mame_bitmap *bitmap); int sysdep_init(void) { - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { fprintf (stderr, "SDL: Init error: %s\n",SDL_GetError()); return OSD_NOT_OK; - } + } + const int enabled = SDL_JoystickEventState(SDL_ENABLE); + if (enabled != SDL_ENABLE) { + fprintf (stderr, "SDL: Error enabling joystick events: %s\n", SDL_GetError()); + SDL_Quit(); + exit (OSD_NOT_OK); + } + // list all joysticks + const int num_joysticks = SDL_NumJoysticks(); + fprintf (stderr, "SDL: Info: Found %d joysticks\n", num_joysticks); + for (int i = 0; i < num_joysticks; i++) { + SDL_Joystick *joystick = SDL_JoystickOpen(i); + if (joystick == NULL) { + fprintf (stderr, "SDL: Error opening joystick %d: %s\n", i, SDL_GetError()); + SDL_Quit(); + exit (OSD_NOT_OK); + } + fprintf (stderr, "SDL: Info: Joystick %d: %s\n", i, SDL_JoystickName(joystick)); + //SDL_JoystickClose(joystick); + } + #ifdef DIRECT_HERMES Hermes_Init(0); #endif /* DIRECT_HERMES */ @@ -136,7 +156,12 @@ int sysdep_create_display(int depth) int vid_mode_flag; /* Flag to set the video mode */ SDL_DisplayMode current_mode; - SDL_GetCurrentDisplayMode(0, ¤t_mode); + int res = SDL_GetCurrentDisplayMode(0, ¤t_mode); + if (res != 0) { + fprintf(stderr, "SDL: Error getting current display mode: %s\n", SDL_GetError()); + SDL_Quit(); + exit (OSD_NOT_OK); + } SDL_PixelFormat *format = SDL_AllocFormat(current_mode.format); From 405fa22f70b6505f6480ec45bcb1a0f3c5b00ff0 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 26 Jan 2024 23:49:30 +0100 Subject: [PATCH 06/14] fix scancode for text input --- src/unix/video-drivers/sdl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/video-drivers/sdl.c b/src/unix/video-drivers/sdl.c index f72b0a5a4..89854b84e 100644 --- a/src/unix/video-drivers/sdl.c +++ b/src/unix/video-drivers/sdl.c @@ -905,7 +905,7 @@ void sysdep_update_keyboard() fprintf(stderr, "SDL: Text input: %s\n", event.text.text); #endif kevent.unicode = event.text.text[0]; - kevent.scancode = KEYCODE_OTHER; + kevent.scancode = KEY_NONE; xmame_keyboard_register_event(&kevent); break; case SDL_QUIT: From 409da57187531407f7f5b214abece790fd3d682f Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 16 Feb 2024 12:36:48 +0100 Subject: [PATCH 07/14] Also switch the mac build to sdl2 --- .github/workflows/xpinmame.yml | 4 ++-- cmake/xpinmame/CMakeLists_linux-x64.txt | 20 +++++++++--------- cmake/xpinmame/CMakeLists_osx-x64.txt | 27 ++++++++++++++++--------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.github/workflows/xpinmame.yml b/.github/workflows/xpinmame.yml index 96a33e2af..63529300a 100644 --- a/.github/workflows/xpinmame.yml +++ b/.github/workflows/xpinmame.yml @@ -58,11 +58,11 @@ jobs: - uses: actions/checkout@v4 - if: matrix.os == 'macos-latest' run: | - brew install xquartz + brew install sdl2 - if: matrix.os == 'ubuntu-latest' run: | - sudo apt install libx11-dev libxv-dev libasound2-dev libsdl2-dev + sudo apt install libasound2-dev libsdl2-dev - name: Build xpinmame-${{ matrix.platform }} run: | cp cmake/xpinmame/CMakeLists_${{ matrix.platform }}.txt CMakeLists.txt diff --git a/cmake/xpinmame/CMakeLists_linux-x64.txt b/cmake/xpinmame/CMakeLists_linux-x64.txt index 383431c14..c496ec794 100644 --- a/cmake/xpinmame/CMakeLists_linux-x64.txt +++ b/cmake/xpinmame/CMakeLists_linux-x64.txt @@ -103,7 +103,7 @@ add_compile_definitions( USE_MITSHM USE_XV USE_HWSCALE - DISPLAY_METHOD="x11" + DISPLAY_METHOD="SDL2" XMAMEROOT="/usr/local/share/xpinmame" HAVE_SNPRINTF HAVE_GETTIMEOFDAY @@ -643,16 +643,16 @@ find_package( ZLIB REQUIRED ) -find_package( - X11 REQUIRED -) +#find_package( +# X11 +#) find_package( ALSA ) find_package( - SDL2 + SDL2 REQUIRED ) target_include_directories(xpinmame PUBLIC @@ -662,17 +662,17 @@ target_include_directories(xpinmame PUBLIC src/cpu/m68000/generated_by_m68kmake src/unix src/unix/sysdep - ${X11_X11_INCLUDE_PATH} - ${X11_Xv_INCLUDE_PATH} +# ${X11_X11_INCLUDE_PATH} +# ${X11_Xv_INCLUDE_PATH} ${ALSA_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS} ) target_link_libraries(xpinmame PUBLIC ZLIB::ZLIB - ${X11_X11_LIB} - ${X11_Xv_LIB} - ${X11_Xext_LIB} +# ${X11_X11_LIB} +# ${X11_Xv_LIB} +# ${X11_Xext_LIB} ${ALSA_LIBRARIES} ${SDL2_LIBRARIES} ) diff --git a/cmake/xpinmame/CMakeLists_osx-x64.txt b/cmake/xpinmame/CMakeLists_osx-x64.txt index f569b2201..5d8212a81 100644 --- a/cmake/xpinmame/CMakeLists_osx-x64.txt +++ b/cmake/xpinmame/CMakeLists_osx-x64.txt @@ -94,7 +94,7 @@ add_compile_definitions( USE_XV USE_HWSCALE NAME="xpinmame" - DISPLAY_METHOD="x11" + DISPLAY_METHOD="SDL2" XMAMEROOT="/usr/local/share/xpinmame" HAVE_SNPRINTF HAVE_GETTIMEOFDAY @@ -612,9 +612,10 @@ add_executable(xpinmame src/unix/sysdep/sysdep_dsp.c src/unix/sysdep/sysdep_mixer.c src/unix/sysdep/dsp-drivers/coreaudio.c - src/unix/video-drivers/x11.c - src/unix/video-drivers/xinput.c - src/unix/video-drivers/x11_window.c +# src/unix/video-drivers/x11.c +# src/unix/video-drivers/xinput.c +# src/unix/video-drivers/x11_window.c + src/unix/video-drivers/sdl.c src/unix/joystick-drivers/joy_i386.c src/unix/joystick-drivers/joy_pad.c src/unix/joystick-drivers/joy_x11.c @@ -627,8 +628,12 @@ find_package( ZLIB ) +#find_package( +# X11 +#) + find_package( - X11 + SDL2 REQUIRED ) find_library( @@ -641,16 +646,18 @@ target_include_directories(xpinmame PUBLIC src/cpu/m68000 src/cpu/m68000/generated_by_m68kmake src/unix - ${X11_X11_INCLUDE_PATH} - ${X11_Xv_INCLUDE_PATH} +# ${X11_X11_INCLUDE_PATH} +# ${X11_Xv_INCLUDE_PATH} + ${SDL2_INCLUDE_DIRS} ) target_link_libraries(xpinmame PUBLIC ZLIB::ZLIB - ${X11_X11_LIB} - ${X11_Xv_LIB} - ${X11_Xext_LIB} + # ${X11_X11_LIB} + # ${X11_Xv_LIB} + # ${X11_Xext_LIB} ${COREAUDIO_FRAMEWORK} + ${SDL2_LIBRARIES} ) set_target_properties(xpinmame PROPERTIES From a068cc4bb2be66bd0add3475337932c14a21f70d Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 16 Feb 2024 12:50:20 +0100 Subject: [PATCH 08/14] apt update before installing packages --- .github/workflows/xpinmame.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/xpinmame.yml b/.github/workflows/xpinmame.yml index 63529300a..17da4a5ee 100644 --- a/.github/workflows/xpinmame.yml +++ b/.github/workflows/xpinmame.yml @@ -61,8 +61,8 @@ jobs: brew install sdl2 - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt install libasound2-dev libsdl2-dev + run: | + sudo apt update && sudo apt install libasound2-dev libsdl2-dev - name: Build xpinmame-${{ matrix.platform }} run: | cp cmake/xpinmame/CMakeLists_${{ matrix.platform }}.txt CMakeLists.txt From 62f6928d8b4031e1be3648e928596ce5ad0f4212 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 16 Feb 2024 13:12:31 +0100 Subject: [PATCH 09/14] inline issues when building on github --- cmake/xpinmame/CMakeLists_osx-x64.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/xpinmame/CMakeLists_osx-x64.txt b/cmake/xpinmame/CMakeLists_osx-x64.txt index 5d8212a81..bb1f07690 100644 --- a/cmake/xpinmame/CMakeLists_osx-x64.txt +++ b/cmake/xpinmame/CMakeLists_osx-x64.txt @@ -102,6 +102,10 @@ add_compile_definitions( SYSDEP_DSP_COREAUDIO ) +add_definitions( + "-D__forceinline=__attribute__((always_inline)) inline" +) + add_executable(xpinmame src/artwork.c src/artwork.h From e55315fb7d4370f3791cdca8293c60793282c054 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 16 Feb 2024 13:16:43 +0100 Subject: [PATCH 10/14] inline issues when building on github --- cmake/xpinmame/CMakeLists_osx-x64.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/xpinmame/CMakeLists_osx-x64.txt b/cmake/xpinmame/CMakeLists_osx-x64.txt index bb1f07690..aa47ac2f9 100644 --- a/cmake/xpinmame/CMakeLists_osx-x64.txt +++ b/cmake/xpinmame/CMakeLists_osx-x64.txt @@ -77,7 +77,6 @@ add_compile_definitions( HAS_SAA1099=1 HAS_QSOUND=1 - INLINE=static __inline LSB_FIRST x11 stricmp=strcasecmp From 276b687b2f19946de311b5eface207938d1bddf0 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 16 Feb 2024 13:37:20 +0100 Subject: [PATCH 11/14] inline issues when building on github --- cmake/xpinmame/CMakeLists_osx-x64.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmake/xpinmame/CMakeLists_osx-x64.txt b/cmake/xpinmame/CMakeLists_osx-x64.txt index aa47ac2f9..e98a46444 100644 --- a/cmake/xpinmame/CMakeLists_osx-x64.txt +++ b/cmake/xpinmame/CMakeLists_osx-x64.txt @@ -77,6 +77,7 @@ add_compile_definitions( HAS_SAA1099=1 HAS_QSOUND=1 + INLINE=__inline LSB_FIRST x11 stricmp=strcasecmp @@ -101,10 +102,6 @@ add_compile_definitions( SYSDEP_DSP_COREAUDIO ) -add_definitions( - "-D__forceinline=__attribute__((always_inline)) inline" -) - add_executable(xpinmame src/artwork.c src/artwork.h From 972ef540092b87cf6d3eb127628af9c2a0de3870 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 16 Feb 2024 13:39:07 +0100 Subject: [PATCH 12/14] inline issues when building on github --- cmake/xpinmame/CMakeLists_osx-x64.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/xpinmame/CMakeLists_osx-x64.txt b/cmake/xpinmame/CMakeLists_osx-x64.txt index e98a46444..5d8212a81 100644 --- a/cmake/xpinmame/CMakeLists_osx-x64.txt +++ b/cmake/xpinmame/CMakeLists_osx-x64.txt @@ -77,7 +77,7 @@ add_compile_definitions( HAS_SAA1099=1 HAS_QSOUND=1 - INLINE=__inline + INLINE=static __inline LSB_FIRST x11 stricmp=strcasecmp From 7da967b1d4e86c119445c8680355150282e7136c Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 16 Feb 2024 14:57:19 +0100 Subject: [PATCH 13/14] final fix for inline issue --- cmake/xpinmame/CMakeLists_osx-x64.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/xpinmame/CMakeLists_osx-x64.txt b/cmake/xpinmame/CMakeLists_osx-x64.txt index 5d8212a81..f1c9110a4 100644 --- a/cmake/xpinmame/CMakeLists_osx-x64.txt +++ b/cmake/xpinmame/CMakeLists_osx-x64.txt @@ -77,7 +77,6 @@ add_compile_definitions( HAS_SAA1099=1 HAS_QSOUND=1 - INLINE=static __inline LSB_FIRST x11 stricmp=strcasecmp @@ -102,6 +101,10 @@ add_compile_definitions( SYSDEP_DSP_COREAUDIO ) +add_definitions( + "-DINLINE=static inline __attribute__((always_inline))" +) + add_executable(xpinmame src/artwork.c src/artwork.h From aa5144c5dc8dad7edc15b756681193cb16b5c288 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Mon, 21 Oct 2024 14:23:42 +0200 Subject: [PATCH 14/14] fix build on ubuntu 24.10 --- src/driver.h | 2 +- src/wpc/driver.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver.h b/src/driver.h index 089dae005..f19abcbd5 100644 --- a/src/driver.h +++ b/src/driver.h @@ -628,7 +628,7 @@ const struct GameDriver driver_##NAME = \ ***************************************************************************/ -extern struct GameDriver *drivers[]; +extern const struct GameDriver *drivers[]; extern const struct GameDriver *test_drivers[]; #endif diff --git a/src/wpc/driver.c b/src/wpc/driver.c index f976e945b..6bf095f23 100644 --- a/src/wpc/driver.c +++ b/src/wpc/driver.c @@ -12,7 +12,7 @@ const struct GameDriver driver_0 = { # undef DRIVERNV # define DRIVER(name, ver) &driver_##name##_##ver, # define DRIVERNV(name) &driver_##name, -struct GameDriver *drivers[] = { +const struct GameDriver *drivers[] = { # include "driver.c" 0 /* end of array */ };