Remove SDL1 support; add SDL2 support from kanjitalk755 repository

This commit is contained in:
uyjulian 2019-09-01 14:51:28 -05:00
parent fcdfd2f799
commit 730ca109b7
No known key found for this signature in database
GPG Key ID: FEA459A8CA14685B
5 changed files with 1255 additions and 207 deletions

View File

@ -28,11 +28,13 @@
#include <SDL_mutex.h>
#include <SDL_audio.h>
#include <SDL_version.h>
#define DEBUG 0
#include "debug.h"
#define MAC_MAX_VOLUME 0x0100
// The currently selected audio parameters (indices in audio_sample_rates[] etc. vectors)
@ -83,6 +85,7 @@ static bool open_sdl_audio(void)
}
SDL_AudioSpec audio_spec;
memset(&audio_spec, 0, sizeof(audio_spec));
audio_spec.freq = audio_sample_rates[audio_sample_rate_index] >> 16;
audio_spec.format = (audio_sample_sizes[audio_sample_size_index] == 8) ? AUDIO_U8 : AUDIO_S16MSB;
audio_spec.channels = audio_channel_counts[audio_channel_count_index];
@ -95,9 +98,23 @@ static bool open_sdl_audio(void)
fprintf(stderr, "WARNING: Cannot open audio: %s\n", SDL_GetError());
return false;
}
#if SDL_VERSION_ATLEAST(2,0,0)
// HACK: workaround a bug in SDL pre-2.0.6 (reported via https://bugzilla.libsdl.org/show_bug.cgi?id=3710 )
// whereby SDL does not update audio_spec.size
if (audio_spec.size == 0) {
audio_spec.size = (SDL_AUDIO_BITSIZE(audio_spec.format) / 8) * audio_spec.channels * audio_spec.samples;
}
#endif
#if SDL_VERSION_ATLEAST(2,0,0)
const char * driver_name = SDL_GetCurrentAudioDriver();
#else
char driver_name[32];
printf("Using SDL/%s audio output\n", SDL_AudioDriverName(driver_name, sizeof(driver_name) - 1));
SDL_AudioDriverName(driver_name, sizeof(driver_name) - 1);
#endif
printf("Using SDL/%s audio output\n", driver_name ? driver_name : "");
silence_byte = audio_spec.silence;
SDL_PauseAudio(0);
@ -227,7 +244,6 @@ static void stream_func(void *arg, uint8 *stream, int stream_len)
// Audio not active, play silence
silence: memset(stream, silence_byte, stream_len);
}
}

View File

@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.0.0)
project(BasiliskII)
find_package(SDL REQUIRED)
find_package(SDL2 REQUIRED)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
find_library(IOKIT_LIBRARY IOKit)
include_directories(../include . ../CrossPlatform ../uae_cpu ${SDL_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
include_directories(../include . ../CrossPlatform ../uae_cpu ${SDL2_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
add_executable(build68k ../uae_cpu/build68k.c)
@ -55,7 +55,7 @@ set(BasiliskII_SRCS
#SYSSRC
#SDL USE_SDL USE_SDL_VIDEO USE_SDL_AUDIO
#video src
../SDL/video_sdl.cpp
../SDL/video_sdl2.cpp
#EXTFSSRC
extfs_unix.cpp
#Serial src
@ -100,7 +100,7 @@ set_source_files_properties(${BasiliskII_SRCS}
# set_property(SOURCE compemu_support.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -O0 ")
target_link_libraries(BasiliskII ${COREFOUNDATION_LIBRARY} ${IOKIT_LIBRARY} ${SDL_LIBRARY})
target_link_libraries(BasiliskII ${COREFOUNDATION_LIBRARY} ${IOKIT_LIBRARY} ${SDL2_LIBRARIES})
# set(CMAKE_POSITION_INDEPENDENT_CODE OFF)

View File

@ -450,7 +450,7 @@ int main(int argc, char **argv)
#ifdef USE_SDL
// SDL threads available, start 60Hz thread
tick_thread_active = ((tick_thread = SDL_CreateThread(tick_func, NULL)) != NULL);
tick_thread_active = ((tick_thread = SDL_CreateThread(tick_func, NULL, NULL)) != NULL);
if (!tick_thread_active) {
sprintf(str, GetString(STR_TICK_THREAD_ERR), strerror(errno));
ErrorAlert(str);
@ -464,7 +464,7 @@ int main(int argc, char **argv)
#ifdef USE_SDL
// Start XPRAM watchdog thread
memcpy(last_xpram, XPRAM, XPRAM_SIZE);
xpram_thread_active = ((xpram_thread = SDL_CreateThread(xpram_func, NULL)) != NULL);
xpram_thread_active = ((xpram_thread = SDL_CreateThread(xpram_func, NULL, NULL)) != NULL);
D(bug("XPRAM thread started\n"));
#endif

View File

@ -22,6 +22,10 @@
#include "macos_util.h"
#include "timer.h"
// #ifdef USE_SDL
// # include <SDL.h>
// #endif
#include <errno.h>
#define DEBUG 0
@ -337,10 +341,19 @@ void Delay_usec(uint32 usec)
// #endif
// #endif
// SDL_mutex *idle_lock;
// SDL_cond *idle_cond;
void idle_wait(void)
{
//This causes events to not process randomly in JIT so commented out
usleep(10);
// if (!idle_lock)
// idle_lock = SDL_CreateMutex();
// if (!idle_cond)
// idle_cond = SDL_CreateCond();
// SDL_LockMutex(idle_lock);
// SDL_CondWait(idle_cond, idle_lock);
// SDL_UnlockMutex(idle_lock);
// #ifdef IDLE_USES_COND_WAIT
// pthread_mutex_lock(&idle_lock);
@ -373,6 +386,8 @@ void idle_wait(void)
void idle_resume(void)
{
//This causes events to not process randomly in JIT so commented out
// if (idle_cond)
// SDL_CondSignal(idle_cond);
// #ifdef IDLE_USES_COND_WAIT
// pthread_cond_signal(&idle_cond);
// #else