Skip to content
Snippets Groups Projects
sdlfuncs.c 2.79 KiB
Newer Older
#include <stdlib.h> /* getenv()/exit()/atexit() */
#include <stdio.h>  /* NULL */
#include "gen_defs.h"
deuce's avatar
deuce committed
#include "threadwrap.h"
#include "sdlfuncs.h"

struct sdlfuncs xpbeep_sdl;
/* Make xp_dl do static linking */
#ifdef STATIC_SDL
#define STATIC_LINK
#endif
deuce's avatar
deuce committed
#include "xp_dl.h"
static int sdl_funcs_loaded = 0;
static bool sdl_funcs_failed = false;
static int sdl_initialized = 0;
static int sdl_audio_initialized = 0;
static dll_handle  sdl_dll;
int xpbeep_load_sdl_funcs(struct sdlfuncs *sdlf)
	const char *libnames[] = {"SDL", "SDL-1.2", "SDL-1.1", NULL};
	if (sdl_funcs_failed)
		return -1;
	sdl_funcs_failed = true;
	if (sdl_funcs_loaded)
		return 0;
deuce's avatar
deuce committed
	putenv("SDL_VIDEO_ALLOW_SCREENSAVER=1");
	sdlf->gotfuncs = 0;
	if ((sdl_dll = xp_dlopen(libnames, RTLD_LAZY | RTLD_GLOBAL, SDL_PATCHLEVEL)) == NULL)
	if ((sdlf->Init = xp_dlsym(sdl_dll, SDL_Init)) == NULL) {
	if ((sdlf->Quit = xp_dlsym(sdl_dll, SDL_Quit)) == NULL) {
	if ((sdlf->SemWait = xp_dlsym(sdl_dll, SDL_SemWait)) == NULL) {
	if ((sdlf->SemPost = xp_dlsym(sdl_dll, SDL_SemPost)) == NULL) {
	if ((sdlf->SDL_CreateSemaphore = xp_dlsym(sdl_dll, SDL_CreateSemaphore)) == NULL) {
	if ((sdlf->SDL_DestroySemaphore = xp_dlsym(sdl_dll, SDL_DestroySemaphore)) == NULL) {
	if ((sdlf->InitSubSystem = xp_dlsym(sdl_dll, SDL_InitSubSystem)) == NULL) {
	if ((sdlf->QuitSubSystem = xp_dlsym(sdl_dll, SDL_QuitSubSystem)) == NULL) {
	if ((sdlf->OpenAudio = xp_dlsym(sdl_dll, SDL_OpenAudio)) == NULL) {
	if ((sdlf->CloseAudio = xp_dlsym(sdl_dll, SDL_CloseAudio)) == NULL) {
	if ((sdlf->PauseAudio = xp_dlsym(sdl_dll, SDL_PauseAudio)) == NULL) {
	if ((sdlf->LockAudio = xp_dlsym(sdl_dll, SDL_LockAudio)) == NULL) {
	if ((sdlf->UnlockAudio = xp_dlsym(sdl_dll, SDL_UnlockAudio)) == NULL) {
	if ((sdlf->GetAudioStatus = xp_dlsym(sdl_dll, SDL_GetAudioStatus)) == NULL) {
	sdlf->gotfuncs = 1;
	sdl_funcs_loaded = 1;
	sdl_funcs_failed = false;
}

int init_sdl_audio(void)
{
	if (!sdl_funcs_loaded) {
		if (xpbeep_load_sdl_funcs(&xpbeep_sdl) != 0)
	if (!sdl_initialized) {
		if (xpbeep_sdl.Init(0) == 0)
			sdl_initialized = TRUE;
	if (sdl_audio_initialized)
	if (xpbeep_sdl.InitSubSystem(SDL_INIT_AUDIO) == 0) {
		sdl_audio_initialized = TRUE;