@@ -62,7 +62,7 @@ static int hardware=1;
6262static int mode_number = -1 ;
6363static int start_fullscreen = 0 ;
6464SDL_Color * Colors = NULL ;
65- static int cursor_state ; /* previous mouse cursor state */
65+ static bool cursor_state ; /* previous mouse cursor state */
6666
6767#ifdef DIRECT_HERMES
6868HermesHandle H_PaletteHandle ;
@@ -192,7 +192,7 @@ int sysdep_create_display(int depth)
192192
193193 const int display_index = 0 ;
194194 int modes_count = 0 ;
195- const SDL_DisplayMode * * modes = SDL_GetFullscreenDisplayModes (display_index , & modes_count );
195+ SDL_DisplayMode * * modes = SDL_GetFullscreenDisplayModes (display_index , & modes_count );
196196 /* Best video mode found */
197197 int best_vid_mode = -1 ;
198198 int best_width = -1 ;
@@ -371,7 +371,8 @@ int sysdep_create_display(int depth)
371371 };
372372
373373 /* Hide mouse cursor and save its previous status */
374- cursor_state = SDL_ShowCursor ();
374+ cursor_state = SDL_GetCursor ();
375+ SDL_HideCursor ();
375376
376377 effect_init2 (depth , Vid_depth , Vid_width );
377378
@@ -663,10 +664,13 @@ void sysdep_update_display(struct mame_bitmap *bitmap)
663664void sysdep_display_close (void )
664665{
665666 fprintf (stderr , "SDL: Info: Shutting down display\n" );
666- SDL_FreeSurface (Offscreen_surface );
667+ SDL_DestroySurface (Offscreen_surface );
667668
668669 /* Restore cursor state */
669- SDL_ShowCursor (cursor_state );
670+ if (cursor_state )
671+ SDL_ShowCursor ();
672+ else
673+ SDL_HideCursor ();
670674
671675 // close the window
672676 SDL_DestroyWindow (Window );
@@ -693,7 +697,8 @@ int sysdep_display_alloc_palette(int totalcolors)
693697 (Colors + i )-> g = 0x00 ;
694698 (Colors + i )-> b = 0x00 ;
695699 }
696- SDL_SetPaletteColors (Offscreen_surface -> format -> palette ,Colors ,0 ,totalcolors - 1 );
700+ SDL_Palette * palette = SDL_CreateSurfacePalette (Offscreen_surface );
701+ SDL_SetPaletteColors (palette ,Colors ,0 ,totalcolors - 1 );
697702#else /* DIRECT_HERMES */
698703 H_PaletteHandle = Hermes_PaletteInstance ();
699704 if ( !(H_Palette = Hermes_PaletteGet (H_PaletteHandle )) ) {
@@ -718,7 +723,8 @@ int sysdep_display_set_pen(int pen,unsigned char red, unsigned char green, unsig
718723 (Colors + pen )-> r = red ;
719724 (Colors + pen )-> g = green ;
720725 (Colors + pen )-> b = blue ;
721- if ( (! SDL_SetPaletteColors (Offscreen_surface -> format -> palette , Colors + pen , pen ,1 )) && (! warned )) {
726+ SDL_Palette * palette = SDL_CreateSurfacePalette (Offscreen_surface );
727+ if ( (! SDL_SetPaletteColors (palette , Colors + pen , pen ,1 )) && (! warned )) {
722728 printf ("Color allocation failed, or > 8 bit display\n" );
723729 warned = 0 ;
724730 }
@@ -736,11 +742,11 @@ int sysdep_display_set_pen(int pen,unsigned char red, unsigned char green, unsig
736742
737743void sysdep_mouse_poll (void )
738744{
739- int x ,y ;
745+ float x ,y ;
740746
741747 Uint8 buttons = SDL_GetRelativeMouseState (& x , & y );
742- mouse_data [0 ].deltas [0 ] = x ;
743- mouse_data [0 ].deltas [1 ] = y ;
748+ mouse_data [0 ].deltas [0 ] = ( int ) x ;
749+ mouse_data [0 ].deltas [1 ] = ( int ) y ;
744750 for (int i = 0 ;i < MOUSE_BUTTONS ;i ++ ) {
745751 mouse_data [0 ].buttons [i ] = buttons & (0x01 << i );
746752 }
@@ -873,61 +879,61 @@ void sysdep_update_keyboard()
873879
874880 switch (event .type )
875881 {
876- case SDL_KEYDOWN :
882+ case SDL_EVENT_KEY_DOWN :
877883 kevent .press = 1 ;
878884
879885 /* ALT-Enter: toggle fullscreen */
880- if (event .key .keysym . sym == SDLK_RETURN )
886+ if (event .key .key == SDLK_RETURN )
881887 {
882- if (event .key .keysym . mod & KMOD_ALT )
888+ if (event .key .mod & SDL_KMOD_ALT )
883889 {
884890 SDL_Window * window = SDL_GetWindowFromID (event .key .windowID );
885- const Uint32 is_fullscreen = SDL_GetWindowFlags (window ) & SDL_WINDOW_FULLSCREEN_DESKTOP ;
886- SDL_SetWindowFullscreen (window , is_fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP );
891+ const bool is_fullscreen = SDL_GetWindowFullscreenMode (window ) != NULL ;
892+ SDL_SetWindowFullscreen (window , ! is_fullscreen );
887893 }
888894 }
889895
890- case SDL_KEYUP :
896+ case SDL_EVENT_KEY_UP :
891897 kevent .unicode = 0 ;
892- kevent .scancode = sdl_keycode_to_key (event .key .keysym . sym );
898+ kevent .scancode = sdl_keycode_to_key (event .key .key );
893899 xmame_keyboard_register_event (& kevent );
894900 if (kevent .scancode == KEY_NONE )
895- fprintf (stderr , "SDL unknown symbol 0x%x scancode: %d, sym: %d\n" , event .key .keysym . sym ,
896- event .key .keysym . scancode , event .key .keysym . sym );
901+ fprintf (stderr , "SDL unknown symbol 0x%x scancode: %d, sym: %d\n" , event .key .key ,
902+ event .key .scancode , event .key .key );
897903
898904#ifdef SDL_DEBUG
899905 fprintf (stderr , "Key %s %ssed\n" ,
900- SDL_GetKeyName (event .key .keysym . sym ),
906+ SDL_GetKeyName (event .key .key ),
901907 kevent .press ? "pres" : "relea" );
902908#endif
903909 break ;
904- case SDL_TEXTINPUT :
910+ case SDL_EVENT_TEXT_INPUT :
905911#ifdef SDL_DEBUG
906912 fprintf (stderr , "SDL: Text input: %s\n" , event .text .text );
907913#endif
908914 kevent .unicode = event .text .text [0 ];
909915 kevent .scancode = KEY_NONE ;
910916 xmame_keyboard_register_event (& kevent );
911917 break ;
912- case SDL_QUIT :
918+ case SDL_EVENT_QUIT :
913919 /* Shoult leave this to application */
914920 exit (OSD_OK );
915921 break ;
916922
917- case SDL_JOYAXISMOTION :
923+ case SDL_EVENT_JOYSTICK_AXIS_MOTION :
918924 if (event .jaxis .which < JOY_AXIS )
919925 joy_data [event .jaxis .which ].axis [event .jaxis .axis ].val = event .jaxis .value ;
920926#ifdef SDL_DEBUG
921927 fprintf (stderr , "Axis=%d,value=%d\n" , event .jaxis .axis , event .jaxis .value );
922928#endif
923929 break ;
924- case SDL_JOYBUTTONDOWN :
930+ case SDL_EVENT_JOYSTICK_BUTTON_DOWN :
925931
926- case SDL_JOYBUTTONUP :
932+ case SDL_EVENT_JOYSTICK_BUTTON_UP :
927933 if (event .jbutton .which < JOY_BUTTONS )
928- joy_data [event .jbutton .which ].buttons [event .jbutton .button ] = event .jbutton .state ;
934+ joy_data [event .jbutton .which ].buttons [event .jbutton .button ] = event .jbutton .down ;
929935#ifdef SDL_DEBUG
930- fprintf (stderr , "Button=%d,value=%d\n" , event .jbutton .button , event .jbutton .state );
936+ fprintf (stderr , "Button=%d,value=%d\n" , event .jbutton .button , event .jbutton .down );
931937#endif
932938 break ;
933939
@@ -943,20 +949,21 @@ void sysdep_update_keyboard()
943949 }
944950}
945951
946- /* added funcions */
952+ /* added functions */
947953int sysdep_display_16bpp_capable (void )
948954{
949- SDL_DisplayMode mode ;
950- SDL_GetCurrentDisplayMode ( 0 , & mode );
951- return ( mode . format >=16 );
955+ const SDL_DisplayMode * mode = SDL_GetCurrentDisplayMode ( 0 ) ;
956+ const int bpp = SDL_BITSPERPIXEL ( mode -> format );
957+ return ( bpp >=16 );
952958}
953959
954960int list_sdl_modes (struct rc_option * option , const char * arg , int priority )
955961{
956962 // TODO we might want to go over all displays
957963 const int display_index = 0 ;
958- const int modes_count = SDL_GetNumDisplayModes (display_index );
959- if (modes_count < 1 )
964+ int modes_count = 0 ;
965+ SDL_DisplayMode * * modes = SDL_GetFullscreenDisplayModes (display_index , & modes_count );
966+ if (modes == NULL || modes_count == 0 )
960967 {
961968 printf ("This option only works in a full-screen mode (eg: linux's framebuffer)\n" );
962969 return - 1 ;
@@ -967,17 +974,13 @@ int list_sdl_modes(struct rc_option *option, const char *arg, int priority)
967974
968975 for (int mode_index = 0 ; mode_index <= modes_count ; mode_index ++ )
969976 {
970- SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN , 0 , 0 , 0 , 0 };
971-
972- if (SDL_GetDisplayMode (display_index , mode_index , & mode ) == 0 )
973- {
974- printf ("\t%d) Mode %d x %d @ %iHz\n" ,
975- mode_index ,
976- mode .w ,
977- mode .h ,
978- mode .refresh_rate
979- );
980- }
977+ const SDL_DisplayMode mode = * modes [mode_index ];
978+ printf ("\t%d) Mode %d x %d @ %iHz\n" ,
979+ mode_index ,
980+ mode .w ,
981+ mode .h ,
982+ mode .refresh_rate
983+ );
981984 }
982985
983986 return -1 ;
0 commit comments