Skip to content

Commit d13cf23

Browse files
committed
witch all calls to sdl3 equivalent
1 parent 1ae5636 commit d13cf23

File tree

2 files changed

+69
-75
lines changed

2 files changed

+69
-75
lines changed

src/unix/sysdep/dsp-drivers/sdl.c

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const struct plugin_struct sysdep_dsp_sdl = {
7070
};
7171

7272
struct sdl_info {
73-
SDL_AudioDeviceID id;
73+
SDL_AudioStream *stream;
7474
};
7575

7676
/* public methods (static but exported through the sysdep_dsp or plugin
@@ -107,7 +107,7 @@ static void *sdl_dsp_create(const void *flags)
107107
dsp->hw_info.samplerate = params->samplerate;
108108

109109
audiospec->format = (dsp->hw_info.type & SYSDEP_DSP_16BIT)?
110-
AUDIO_S16SYS : AUDIO_S8;
110+
SDL_AUDIO_S16 : SDL_AUDIO_S8;
111111
audiospec->channels = (dsp->hw_info.type & SYSDEP_DSP_STEREO)? 2:1;
112112
audiospec->freq = dsp->hw_info.samplerate;
113113

@@ -121,38 +121,30 @@ static void *sdl_dsp_create(const void *flags)
121121
fprintf(stderr, "sdl info: driver = %s\n", SDL_GetCurrentAudioDriver());
122122

123123
// get audio subsystem and open a queue with above spec
124-
SDL_AudioSpec *obtained;
125-
if (!(obtained = calloc(1, sizeof(SDL_AudioSpec))))
126-
{
127-
fprintf(stderr, "sdl error: malloc failed for SDL_AudioSpec\n");
128-
sdl_dsp_destroy(dsp);
129-
return NULL;
130-
}
131-
132-
const SDL_AudioDeviceID id = SDL_OpenAudioDevice(NULL, 0, audiospec, obtained, 0);
133-
if (id == 0) {
124+
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, audiospec, NULL, NULL);
125+
if (stream == NULL) {
134126
fprintf(stderr, "sdl error: SDL_OpenAudioDevice() failed: %s\n", SDL_GetError());
135127
return NULL;
136128
}
137129

138-
// free the spec
139-
free(audiospec);
130+
const SDL_AudioDeviceID device_id = SDL_GetAudioStreamDevice(stream);
131+
SDL_ResumeAudioDevice(device_id);
132+
133+
// get the actual obtained spec
134+
SDL_GetAudioStreamFormat(stream, audiospec, NULL);
140135

141136
// print the id
142-
fprintf(stderr, "sdl info: device id = %d\n", id);
137+
fprintf(stderr, "sdl info: device id = %d\n", device_id);
143138
// print the obtained contents
144-
fprintf(stderr, "sdl info: obtained->format = %d\n", obtained->format);
145-
fprintf(stderr, "sdl info: obtained->channels = %d\n", obtained->channels);
146-
fprintf(stderr, "sdl info: obtained->freq = %d\n", obtained->freq);
147-
fprintf(stderr, "sdl info: obtained->samples = %d\n", obtained->samples);
148-
fprintf(stderr, "sdl info: obtained->callback = %p\n", obtained->callback);
149-
fprintf(stderr, "sdl info: obtained->userdata = %p\n", obtained->userdata);
139+
fprintf(stderr, "sdl info: obtained->format = %d\n", audiospec->format);
140+
fprintf(stderr, "sdl info: obtained->channels = %d\n", audiospec->channels);
141+
fprintf(stderr, "sdl info: obtained->freq = %d\n", audiospec->freq);
150142

151-
// resume playing on device
152-
SDL_PauseAudioDevice(id);
143+
// free the spec
144+
free(audiospec);
153145

154146
struct sdl_info *info = (struct sdl_info *)calloc(1, sizeof(struct sdl_info));
155-
info->id = id;
147+
info->stream = stream;
156148

157149
dsp->_priv = info;
158150

@@ -165,9 +157,9 @@ static void *sdl_dsp_create(const void *flags)
165157
}
166158

167159
static void sdl_dsp_destroy(struct sysdep_dsp_struct *dsp)
168-
{
169-
SDL_CloseAudio();
170-
160+
{
161+
const struct sdl_info *info = (struct sdl_info *)dsp->_priv;
162+
SDL_DestroyAudioStream(info->stream);
171163
free(dsp);
172164
}
173165

@@ -178,13 +170,12 @@ static int sdl_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data,
178170
// count is the number of samples to write
179171
const int len = (dsp->hw_info.type & SYSDEP_DSP_STEREO)? count * 4 : count * 2;
180172

181-
// get device id from dsp
173+
// get stream from dsp
182174
const struct sdl_info *info = (struct sdl_info *)dsp->_priv;
183-
const SDL_AudioDeviceID dev = info->id;
184175

185-
const int result = SDL_QueueAudio(dev, data, len);
176+
const int result = SDL_PutAudioStreamData(info->stream, data, len);
186177
if (result != 0) {
187-
fprintf(stderr, "error: SDL_QueueAudio() failed: %s\n", SDL_GetError());
178+
fprintf(stderr, "error: SDL_PutAudioStreamData() failed: %s\n", SDL_GetError());
188179
return 0;
189180
}
190181
return count;

src/unix/video-drivers/sdl.c

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int hardware=1;
6262
static int mode_number=-1;
6363
static int start_fullscreen=0;
6464
SDL_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
6868
HermesHandle 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)
663664
void 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

737743
void 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 */
947953
int 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

954960
int 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

Comments
 (0)