Prepare for SDL3

This commit is contained in:
kanjitalk755 2023-09-13 20:45:03 +09:00
parent 0942bdcbf9
commit 9a7751f1a2
16 changed files with 3370 additions and 77 deletions

View File

@ -62,10 +62,16 @@ bool is_fullscreen_osx(SDL_Window * window)
}
SDL_SysWMinfo wmInfo;
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!SDL_GetWindowWMInfo(window, &wmInfo, SDL_SYSWM_CURRENT_VERSION)) {
return false;
}
#else
SDL_VERSION(&wmInfo.version);
if (!SDL_GetWindowWMInfo(window, &wmInfo)) {
return false;
}
#endif
const NSWindowStyleMask styleMask = [wmInfo.info.cocoa.window styleMask];
return (styleMask & NSWindowStyleMaskFullScreen) != 0;

View File

@ -31,6 +31,8 @@
#include <SDL_version.h>
#include <SDL_timer.h>
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#define DEBUG 0
#include "debug.h"
@ -402,3 +404,5 @@ void PlayStartupSound() {
// Not implemented
}
#endif
#endif // SDL_VERSION_ATLEAST

View File

@ -0,0 +1,380 @@
/*
* audio_sdl.cpp - Audio support, SDL implementation
*
* Basilisk II (C) 1997-2008 Christian Bauer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sysdeps.h"
#include "cpu_emulation.h"
#include "main.h"
#include "prefs.h"
#include "user_strings.h"
#include "audio.h"
#include "audio_defs.h"
#include <SDL_mutex.h>
#include <SDL_audio.h>
#include <SDL_version.h>
#include <SDL_timer.h>
#if SDL_VERSION_ATLEAST(3, 0, 0)
#include <SDL_init.h>
#define DEBUG 0
#include "debug.h"
#if defined(BINCUE)
#include "bincue.h"
#endif
#define MAC_MAX_VOLUME 0x0100
// The currently selected audio parameters (indices in audio_sample_rates[] etc. vectors)
static int audio_sample_rate_index = 0;
static int audio_sample_size_index = 0;
static int audio_channel_count_index = 0;
// Global variables
static SDL_Semaphore *audio_irq_done_sem = NULL; // Signal from interrupt to streaming thread: data block read
static uint8 silence_byte; // Byte value to use to fill sound buffers with silence
static int main_volume = MAC_MAX_VOLUME;
static int speaker_volume = MAC_MAX_VOLUME;
static bool main_mute = false;
static bool speaker_mute = false;
SDL_AudioSpec audio_spec;
// Prototypes
static void SDLCALL stream_func(void *arg, SDL_AudioStream *stream, int stream_len);
static int get_audio_volume();
/*
* Initialization
*/
// Set AudioStatus to reflect current audio stream format
static void set_audio_status_format(void)
{
AudioStatus.sample_rate = audio_sample_rates[audio_sample_rate_index];
AudioStatus.sample_size = audio_sample_sizes[audio_sample_size_index];
AudioStatus.channels = audio_channel_counts[audio_channel_count_index];
}
// Init SDL audio system
static bool open_sdl_audio(void)
{
// SDL supports a variety of twisted little audio formats, all different
if (audio_sample_sizes.empty()) {
audio_sample_rates.push_back(11025 << 16);
audio_sample_rates.push_back(22050 << 16);
audio_sample_rates.push_back(44100 << 16);
audio_sample_sizes.push_back(8);
audio_sample_sizes.push_back(16);
audio_channel_counts.push_back(1);
audio_channel_counts.push_back(2);
// Default to highest supported values
audio_sample_rate_index = (int)audio_sample_rates.size() - 1;
audio_sample_size_index = (int)audio_sample_sizes.size() - 1;
audio_channel_count_index = (int)audio_channel_counts.size() - 1;
}
//memset(&audio_spec, 0, sizeof(audio_spec));
audio_spec.format = (audio_sample_sizes[audio_sample_size_index] == 8) ? SDL_AUDIO_U8 : SDL_AUDIO_S16BE;
audio_spec.channels = audio_channel_counts[audio_channel_count_index];
audio_spec.freq = audio_sample_rates[audio_sample_rate_index] >> 16;
// Open the audio device, forcing the desired format
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &audio_spec, stream_func, NULL);
if (stream == NULL) {
fprintf(stderr, "WARNING: Cannot open audio: %s\n", SDL_GetError());
return false;
}
silence_byte = SDL_GetSilenceValueForFormat(audio_spec.format);
#if defined(BINCUE)
OpenAudio_bincue(audio_spec.freq, audio_spec.format, audio_spec.channels, silence_byte, get_audio_volume());
#endif
printf("Using SDL/%s audio output\n", SDL_GetCurrentAudioDriver());
audio_frames_per_block = 4096 >> PrefsFindInt32("sound_buffer");
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
return true;
}
static bool open_audio(void)
{
// Try to open SDL audio
if (!open_sdl_audio()) {
WarningAlert(GetString(STR_NO_AUDIO_WARN));
return false;
}
// Device opened, set AudioStatus
set_audio_status_format();
// Everything went fine
audio_open = true;
return true;
}
void AudioInit(void)
{
// Init audio status and feature flags
AudioStatus.sample_rate = 44100 << 16;
AudioStatus.sample_size = 16;
AudioStatus.channels = 2;
AudioStatus.mixer = 0;
AudioStatus.num_sources = 0;
audio_component_flags = cmpWantsRegisterMessage | kStereoOut | k16BitOut;
// Sound disabled in prefs? Then do nothing
if (PrefsFindBool("nosound"))
return;
// Init semaphore
audio_irq_done_sem = SDL_CreateSemaphore(0);
// Open and initialize audio device
open_audio();
}
/*
* Deinitialization
*/
static void close_audio(void)
{
// Close audio device
SDL_QuitSubSystem(SDL_INIT_AUDIO);
audio_open = false;
}
void AudioExit(void)
{
// Close audio device
close_audio();
// Delete semaphore
if (audio_irq_done_sem)
SDL_DestroySemaphore(audio_irq_done_sem);
}
/*
* First source added, start audio stream
*/
void audio_enter_stream()
{
}
/*
* Last source removed, stop audio stream
*/
void audio_exit_stream()
{
}
/*
* Streaming function
*/
#include <queue>
static void SDLCALL stream_func(void *, SDL_AudioStream *stream, int stream_len)
{
static std::queue<uint8> q;
if (AudioStatus.num_sources) {
while (q.size() < stream_len) {
// Trigger audio interrupt to get new buffer
D(bug("stream: triggering irq\n"));
SetInterruptFlag(INTFLAG_AUDIO);
TriggerInterrupt();
D(bug("stream: waiting for ack\n"));
SDL_WaitSemaphore(audio_irq_done_sem);
D(bug("stream: ack received\n"));
// Get size of audio data
uint32 apple_stream_info = ReadMacInt32(audio_data + adatStreamInfo);
if (apple_stream_info && !main_mute && !speaker_mute) {
int work_size = ReadMacInt32(apple_stream_info + scd_sampleCount) * (AudioStatus.sample_size >> 3) * AudioStatus.channels;
uint8 buf[work_size];
Mac2Host_memcpy(buf, ReadMacInt32(apple_stream_info + scd_buffer), work_size);
for (int i = 0; i < work_size; i++) q.push(buf[i]);
}
else {
while (!q.empty()) q.pop();
break;
}
}
}
uint8 src[stream_len], dst[stream_len];
for (int i = 0; i < stream_len; i++)
if (q.empty()) src[i] = silence_byte;
else {
src[i] = q.front();
q.pop();
}
memset(dst, silence_byte, stream_len);
//SDL_AudioSpec audio_spec;
//int r = SDL_GetAudioStreamFormat(stream, NULL, &audio_spec);// little endianが帰ってくる
SDL_MixAudioFormat(dst, src, audio_spec.format, stream_len, get_audio_volume());
#if defined(BINCUE)
MixAudio_bincue(dst, stream_len, get_audio_volume());
#endif
SDL_PutAudioStreamData(stream, dst, stream_len);
}
/*
* MacOS audio interrupt, read next data block
*/
void AudioInterrupt(void)
{
D(bug("AudioInterrupt\n"));
// Get data from apple mixer
if (AudioStatus.mixer) {
M68kRegisters r;
r.a[0] = audio_data + adatStreamInfo;
r.a[1] = AudioStatus.mixer;
Execute68k(audio_data + adatGetSourceData, &r);
D(bug(" GetSourceData() returns %08lx\n", r.d[0]));
} else
WriteMacInt32(audio_data + adatStreamInfo, 0);
// Signal stream function
SDL_PostSemaphore(audio_irq_done_sem);
D(bug("AudioInterrupt done\n"));
}
/*
* Set sampling parameters
* "index" is an index into the audio_sample_rates[] etc. vectors
* It is guaranteed that AudioStatus.num_sources == 0
*/
bool audio_set_sample_rate(int index)
{
close_audio();
audio_sample_rate_index = index;
return open_audio();
}
bool audio_set_sample_size(int index)
{
close_audio();
audio_sample_size_index = index;
return open_audio();
}
bool audio_set_channels(int index)
{
close_audio();
audio_channel_count_index = index;
return open_audio();
}
/*
* Get/set volume controls (volume values received/returned have the left channel
* volume in the upper 16 bits and the right channel volume in the lower 16 bits;
* both volumes are 8.8 fixed point values with 0x0100 meaning "maximum volume"))
*/
bool audio_get_main_mute(void)
{
return main_mute;
}
uint32 audio_get_main_volume(void)
{
uint32 chan = main_volume;
return (chan << 16) + chan;
}
bool audio_get_speaker_mute(void)
{
return speaker_mute;
}
uint32 audio_get_speaker_volume(void)
{
uint32 chan = speaker_volume;
return (chan << 16) + chan;
}
void audio_set_main_mute(bool mute)
{
main_mute = mute;
}
void audio_set_main_volume(uint32 vol)
{
// We only have one-channel volume right now.
main_volume = ((vol >> 16) + (vol & 0xffff)) / 2;
if (main_volume > MAC_MAX_VOLUME)
main_volume = MAC_MAX_VOLUME;
}
void audio_set_speaker_mute(bool mute)
{
speaker_mute = mute;
}
void audio_set_speaker_volume(uint32 vol)
{
// We only have one-channel volume right now.
speaker_volume = ((vol >> 16) + (vol & 0xffff)) / 2;
if (speaker_volume > MAC_MAX_VOLUME)
speaker_volume = MAC_MAX_VOLUME;
}
static int get_audio_volume() {
return main_volume * speaker_volume * SDL_MIX_MAXVOLUME / (MAC_MAX_VOLUME * MAC_MAX_VOLUME);
}
static int play_startup(void *arg) {
SDL_AudioSpec wav_spec;
Uint8 *wav_buffer;
Uint32 wav_length;
if (!SDL_LoadWAV("startup.wav", &wav_spec, &wav_buffer, &wav_length)) {
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wav_spec, NULL, NULL);
if (stream) {
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
SDL_PutAudioStreamData(stream, wav_buffer, wav_length);
while (SDL_GetAudioStreamAvailable(stream)) SDL_Delay(10);
SDL_Delay(500);
SDL_DestroyAudioStream(stream);
}
else printf("play_startup: Audio driver failed to initialize\n");
SDL_free(wav_buffer);
}
return 0;
}
void PlayStartupSound() {
SDL_CreateThread(play_startup, "", NULL);
}
#endif // SDL_VERSION_ATLEAST

View File

@ -42,7 +42,7 @@
#include "sysdeps.h"
#include <SDL.h>
#if SDL_VERSION_ATLEAST(2,0,0)
#if SDL_VERSION_ATLEAST(2, 0, 0) && !SDL_VERSION_ATLEAST(3, 0, 0)
#include <SDL_mutex.h>
#include <SDL_thread.h>

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,7 @@ AC_ARG_ENABLE(sdl-audio, [ --enable-sdl-audio use SDL for audio [defau
AC_ARG_ENABLE(sdl-framework, [ --enable-sdl-framework use SDL framework [default=no]], [WANT_SDL_FRAMEWORK=$enableval], [WANT_SDL_FRAMEWORK=no])
AC_ARG_ENABLE(sdl-framework-prefix, [ --enable-sdl-framework-prefix=PFX default=/Library/Frameworks], [SDL_FRAMEWORK="$enableval"], [SDL_FRAMEWORK=/Library/Frameworks])
AC_ARG_WITH(sdl1, [ --with-sdl1 use SDL 1.x, rather than SDL 2.x [default=no]], [WANT_SDL_VERSION_MAJOR=1], [])
AC_ARG_WITH(sdl3, [ --with-sdl3 use SDL 3.x, rather than SDL 2.x [default=no]], [WANT_SDL_VERSION_MAJOR=3], [])
dnl JIT compiler options.
AC_ARG_ENABLE(jit-compiler, [ --enable-jit-compiler enable JIT compiler [default=yes]], [WANT_JIT=$enableval], [WANT_JIT=yes])
@ -329,9 +330,18 @@ if [[ "x$WANT_SDL" = "xyes" ]]; then
dnl never got defined (bizarrely-enough). -- dludwig@pobox.com
PKG_PROG_PKG_CONFIG
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x3" ]]; then
PKG_CHECK_MODULES([sdl3], [sdl3 >= 3.0], [
CXXFLAGS="$CXXFLAGS $sdl3_CFLAGS"
CXXFLAGS+=`echo $sdl3_CFLAGS | sed -e 's/\(-I.*include\)/\1\/SDL3/'`
LIBS="$LIBS $sdl3_LIBS"
WANT_SDL_VERSION_MAJOR=3
], [
TEMP_WANT_SDL_VERSION_MAJOR=1
])
fi
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x2" ]]; then
PKG_CHECK_MODULES([sdl2], [sdl2 >= 2.0], [
CFLAGS="$CFLAGS $sdl2_CFLAGS"
CXXFLAGS="$CXXFLAGS $sdl2_CFLAGS"
LIBS="$LIBS $sdl2_LIBS"
WANT_SDL_VERSION_MAJOR=2
@ -845,7 +855,7 @@ if [[ "x$WANT_SDL" = "xyes" ]]; then
fi
if [[ "x$WANT_SDL_VIDEO" = "xyes" ]]; then
AC_DEFINE(USE_SDL_VIDEO, 1, [Define to enable SDL video graphics support])
VIDEOSRCS="../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp"
VIDEOSRCS="../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp ../SDL/video_sdl3.cpp "
KEYCODES="../SDL/keycodes"
if [[ "x$ac_cv_framework_Carbon" = "xyes" ]]; then
AC_MSG_CHECKING([whether __LP64__ is defined])
@ -882,7 +892,7 @@ elif [[ "x$WANT_MACOSX_GUI" != "xyes" ]]; then
fi
if [[ "x$WANT_SDL_AUDIO" = "xyes" ]]; then
AC_DEFINE(USE_SDL_AUDIO, 1, [Define to enable SDL audio support])
AUDIOSRC="../SDL/audio_sdl.cpp"
AUDIOSRC="../SDL/audio_sdl.cpp ../SDL/audio_sdl3.cpp"
fi
dnl BINCUE overrides

5
BasiliskII/src/Windows/Makefile.in Executable file → Normal file
View File

@ -66,8 +66,9 @@ SRCS = ../main.cpp main_windows.cpp ../prefs.cpp ../prefs_items.cpp prefs_window
../emul_op.cpp ../macos_util.cpp ../xpram.cpp xpram_windows.cpp ../timer.cpp \
timer_windows.cpp ../adb.cpp ../serial.cpp serial_windows.cpp \
../ether.cpp ether_windows.cpp ../sony.cpp ../disk.cpp ../cdrom.cpp \
../scsi.cpp ../dummy/scsi_dummy.cpp ../video.cpp ../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp \
video_blit.cpp ../audio.cpp ../SDL/audio_sdl.cpp clip_windows.cpp \
../scsi.cpp ../dummy/scsi_dummy.cpp ../video.cpp \
../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp ../SDL/video_sdl3.cpp \
video_blit.cpp ../audio.cpp ../SDL/audio_sdl.cpp ../SDL/audio_sdl3.cpp clip_windows.cpp \
../extfs.cpp extfs_windows.cpp ../user_strings.cpp user_strings_windows.cpp \
vm_alloc.cpp sigsegv.cpp posix_emu.cpp util_windows.cpp \
../dummy/prefs_editor_dummy.cpp BasiliskII.rc \

26
BasiliskII/src/Windows/configure.ac Executable file → Normal file
View File

@ -11,9 +11,6 @@ dnl Aliases for PACKAGE and VERSION macros.
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE_NAME", [Define this program name.])
AC_DEFINE_UNQUOTED(VERSION, "$PACKAGE_VERSION", [Define this program version.])
dnl SDL options.
#AC_ARG_ENABLE(sdl-static, [ --enable-sdl-static use SDL static libraries for linking [default=no]], [WANT_SDL_STATIC=$enableval], [WANT_SDL_STATIC=no])
dnl JIT compiler options.
AC_ARG_ENABLE(jit-compiler, [ --enable-jit-compiler enable JIT compiler [default=yes]], [WANT_JIT=$enableval], [WANT_JIT=yes])
AC_ARG_ENABLE(jit-debug, [ --enable-jit-debug activate native code disassemblers [default=no]], [WANT_JIT_DEBUG=$enableval], [WANT_JIT_DEBUG=no])
@ -53,6 +50,8 @@ AC_ARG_ENABLE(addressing,
[ ADDRESSING_TEST_ORDER="direct banks"
])
AC_ARG_WITH(sdl3, [ --with-sdl3 use SDL 3.x, rather than SDL 2.x [default=no]], [WANT_SDL_VERSION_MAJOR=3], [WANT_SDL_VERSION_MAJOR=2])
dnl Canonical system information.
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
@ -548,20 +547,14 @@ CPUINCLUDES="-I../uae_cpu"
CPUSRCS="../uae_cpu/basilisk_glue.cpp ../uae_cpu/memory.cpp ../uae_cpu/newcpu.cpp ../uae_cpu/readcpu.cpp $FPUSRCS cpustbl.cpp cpudefs.cpp $CPUSRCS $JITSRCS"
dnl We really want SDL for now
AC_CHECK_TOOL(sdl_config, sdl2-config, no)
AS_IF([test "x$sdl_config" = xno], [AC_MSG_ERROR([Sorry, you currently need SDL for this port])])
SDL_CFLAGS=`$sdl_config --cflags`
if [[ "x$WANT_SDL_VERSION_MAJOR" = "x3" ]]; then
SDL_CFLAGS=`pkg-config sdl3 --cflags`
SDL_LIBS=`pkg-config sdl3 --libs | sed -e 's/-lSDL3/-lSDL3.dll/'`
else
SDL_CFLAGS=`sdl2-config --cflags`
SDL_LIBS=`sdl2-config --static-libs`
fi
AC_SUBST(SDL_CFLAGS)
#if [[ "x$WANT_SDL_STATIC" = "xyes" ]]; then
SDL_LIBS=`$sdl_config --static-libs`
# sdl_prefix=`$sdl_config --exec-prefix`
# if [[ -n "$sdl_prefix" ]]; then
# SDL_LIBS=`echo "$SDL_LIBS" | sed -e "s,-l\(SDLmain\|SDL\),$sdl_prefix/lib/lib\1.a,g"`
# fi
# SDL_LIBS="$SDL_LIBS -lwinmm"
#else
# SDL_LIBS=`$sdl_config --libs`
#fi
AC_SUBST(SDL_LIBS)
AC_DEFINE(USE_SDL, 1, [Define to enble SDL support])
AC_DEFINE(USE_SDL_VIDEO, 1, [Define to enable SDL video graphics support])
@ -585,6 +578,7 @@ dnl Print summary.
echo
echo Basilisk II configuration summary:
echo
echo SDL major-version ...................... : $WANT_SDL_VERSION_MAJOR
echo Use JIT compiler ....................... : $WANT_JIT
echo JIT debug mode ......................... : $WANT_JIT_DEBUG
echo Floating-Point emulation core .......... : $FPE_CORE

22
BasiliskII/src/Windows/main_windows.cpp Executable file → Normal file
View File

@ -61,6 +61,11 @@ extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_suppo
#define DEBUG 0
#include "debug.h"
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#define SDL_Mutex SDL_mutex
#define SDL_EVENT_KEY_UP SDL_KEYUP
#define SDL_EVENT_KEY_DOWN SDL_KEYDOWN
#endif
// Constants
const TCHAR ROM_FILE_NAME[] = TEXT("ROM");
@ -86,7 +91,7 @@ static bool tick_thread_active = false; // Flag: 60Hz thread installed
static volatile bool tick_thread_cancel = false; // Flag: Cancel 60Hz thread
static SDL_Thread *tick_thread; // 60Hz thread
static SDL_mutex *intflag_lock = NULL; // Mutex to protect InterruptFlags
static SDL_Mutex *intflag_lock = NULL; // Mutex to protect InterruptFlags
#define LOCK_INTFLAGS SDL_LockMutex(intflag_lock)
#define UNLOCK_INTFLAGS SDL_UnlockMutex(intflag_lock)
@ -520,7 +525,7 @@ void FlushCodeCache(void *start, uint32 size)
struct B2_mutex {
B2_mutex() { m = SDL_CreateMutex(); }
~B2_mutex() { if (m) SDL_DestroyMutex(m); }
SDL_mutex *m;
SDL_Mutex *m;
};
B2_mutex *B2_create_mutex(void)
@ -649,13 +654,16 @@ extern SDL_Window *sdl_window;
HWND GetMainWindowHandle(void)
{
SDL_SysWMinfo wmInfo;
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!sdl_window || !SDL_GetWindowWMInfo(sdl_window, &wmInfo, SDL_SYSWM_CURRENT_VERSION)) {
return NULL;
}
#else
SDL_VERSION(&wmInfo.version);
if (!sdl_window) {
return NULL;
}
if (!SDL_GetWindowWMInfo(sdl_window, &wmInfo)) {
if (!sdl_window || !SDL_GetWindowWMInfo(sdl_window, &wmInfo)) {
return NULL;
}
#endif
if (wmInfo.subsystem != SDL_SYSWM_WINDOWS) {
return NULL;
}
@ -758,7 +766,7 @@ static LRESULT CALLBACK low_level_keyboard_hook(int nCode, WPARAM wParam, LPARAM
if (intercept_event) {
SDL_Event e;
memset(&e, 0, sizeof(e));
e.type = (wParam == WM_KEYDOWN) ? SDL_KEYDOWN : SDL_KEYUP;
e.type = (wParam == WM_KEYDOWN) ? SDL_EVENT_KEY_DOWN : SDL_EVENT_KEY_UP;
e.key.keysym.sym = (p->vkCode == VK_LWIN) ? SDLK_LGUI : SDLK_RGUI;
e.key.keysym.scancode = (p->vkCode == VK_LWIN) ? SDL_SCANCODE_LGUI : SDL_SCANCODE_RGUI;
SDL_PushEvent(&e);

View File

@ -769,7 +769,7 @@ bool CDPlay_bincue(void *fh, uint8 start_m, uint8 start_s, uint8 start_f,
int track;
MSF msf;
#ifdef USE_SDL_AUDIO
#if defined(USE_SDL_AUDIO) && !SDL_VERSION_ATLEAST(3, 0, 0)
SDL_LockAudio();
#endif
@ -814,7 +814,7 @@ bool CDPlay_bincue(void *fh, uint8 start_m, uint8 start_s, uint8 start_f,
else
D(bug("CDPlay_bincue: play beyond last track !\n"));
#ifdef USE_SDL_AUDIO
#if defined(USE_SDL_AUDIO) && !SDL_VERSION_ATLEAST(3, 0, 0)
SDL_UnlockAudio();
#endif
@ -963,6 +963,17 @@ void MixAudio_bincue(uint8 *stream, int stream_len, int volume)
if (player->audiostatus == CDROM_AUDIO_PLAY) {
uint8 *buf = fill_buffer(stream_len, player);
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (buf)
SDL_PutAudioStreamData(player->stream, buf, stream_len);
int avail = SDL_GetAudioStreamAvailable(player->stream);
if (avail >= stream_len) {
extern SDL_AudioSpec audio_spec;
uint8 converted[stream_len];
SDL_GetAudioStreamData(player->stream, converted, stream_len);
SDL_MixAudioFormat(stream, converted, audio_spec.format, stream_len, player->volume_mono);
}
#else
if (buf)
SDL_AudioStreamPut(player->stream, buf, stream_len);
int avail = SDL_AudioStreamAvailable(player->stream);
@ -971,6 +982,7 @@ void MixAudio_bincue(uint8 *stream, int stream_len, int volume)
SDL_AudioStreamGet(player->stream, converted, stream_len);
SDL_MixAudio(stream, converted, stream_len, player->volume_mono);
}
#endif
}
}
@ -989,7 +1001,12 @@ void OpenAudio_bincue(int freq, int format, int channels, uint8 silence, int vol
// set player volume based on SDL volume
player->volume_left = player->volume_right = player->volume_mono = volume;
// audio stream handles converting cd audio to destination output
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_AudioSpec src = { SDL_AUDIO_S16LE, 2, 44100 }, dst = { (SDL_AudioFormat)format, channels, freq };
player->stream = SDL_CreateAudioStream(&src, &dst);
#else
player->stream = SDL_NewAudioStream(AUDIO_S16LSB, 2, 44100, format, channels, freq);
#endif
if (player->stream == NULL) {
D(bug("Failed to open CD player audio stream using SDL!"));
}

View File

@ -482,7 +482,10 @@ static NSString *makeRelativeIfNecessary(NSString *path)
cancelWasClicked = NO;
// quit
SDL_Event event = { .type = SDL_QUIT };
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#define SDL_EVENT_QUIT SDL_QUIT
#endif
SDL_Event event = { .type = SDL_EVENT_QUIT };
SDL_PushEvent(&event);
}

View File

@ -71,6 +71,7 @@ AC_ARG_ENABLE(sdl-audio, [ --enable-sdl-audio use SDL for audio [defaul
AC_ARG_ENABLE(sdl-framework, [ --enable-sdl-framework use SDL framework [default=no]], [WANT_SDL_FRAMEWORK=$enableval], [WANT_SDL_FRAMEWORK=no])
AC_ARG_ENABLE(sdl-framework-prefix, [ --enable-sdl-framework-prefix=PFX default=/Library/Frameworks], [SDL_FRAMEWORK="$enableval"], [SDL_FRAMEWORK=/Library/Frameworks])
AC_ARG_WITH(sdl1, [ --with-sdl1 use SDL 1.x, rather than SDL 2.x [default=no]], [WANT_SDL_VERSION_MAJOR=1], [])
AC_ARG_WITH(sdl3, [ --with-sdl3 use SDL 3.x, rather than SDL 2.x [default=no]], [WANT_SDL_VERSION_MAJOR=3], [])
dnl Checks for programs.
AC_PROG_CC_C99
@ -210,41 +211,43 @@ if [[ "x$WANT_SDL" = "xyes" ]]; then
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x" ]]; then
TEMP_WANT_SDL_VERSION_MAJOR=2
fi
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x2" ]]; then
AC_PATH_PROG(sdl2_config, "sdl2-config")
if [[ -n "$sdl2_config" ]]; then
sdl2_cflags=`$sdl2_config --cflags`
if [[ "x$WANT_SDL_STATIC" = "xyes" ]]; then
sdl2_libs=`$sdl2_config --static-libs`
else
sdl2_libs=`$sdl2_config --libs`
fi
CFLAGS="$CFLAGS $sdl2_cflags"
CXXFLAGS="$CXXFLAGS $sdl2_cflags"
LIBS="$LIBS $sdl2_libs"
WANT_SDL_VERSION_MAJOR=2
else
dnl use PKG_PROG_PKG_CONFIG to declare PKG_CONFIG variables. Otherwise,
dnl PKG_* macros may fail, without much explanation. The lack of this
dnl was causing --with-sdl1 to fail, as SDL 1.x could not be detected,
dnl as the 2nd call to PKG_CHECK_MODULES would fail, as $PKG_CONFIG
dnl never got defined (bizarrely-enough). -- dludwig@pobox.com
PKG_PROG_PKG_CONFIG
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x3" ]]; then
PKG_CHECK_MODULES([sdl3], [sdl3 >= 3.0], [
CXXFLAGS="$CXXFLAGS $sdl3_CFLAGS"
CXXFLAGS+=`echo $sdl3_CFLAGS | sed -e 's/\(-I.*include\)/\1\/SDL3/'`
LIBS="$LIBS $sdl3_LIBS"
WANT_SDL_VERSION_MAJOR=3
], [
TEMP_WANT_SDL_VERSION_MAJOR=1
fi
])
fi
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x2" ]]; then
PKG_CHECK_MODULES([sdl2], [sdl2 >= 2.0], [
CXXFLAGS="$CXXFLAGS $sdl2_CFLAGS"
LIBS="$LIBS $sdl2_LIBS"
WANT_SDL_VERSION_MAJOR=2
], [
TEMP_WANT_SDL_VERSION_MAJOR=1
])
fi
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x1" ]]; then
AC_PATH_PROG(sdl_config, "sdl-config")
if [[ -n "$sdl_config" ]]; then
sdl_cflags=`$sdl_config --cflags`
if [[ "x$WANT_SDL_STATIC" = "xyes" ]]; then
sdl_libs=`$sdl_config --static-libs`
else
sdl_libs=`$sdl_config --libs`
fi
CFLAGS="$CFLAGS $sdl_cflags"
CXXFLAGS="$CXXFLAGS $sdl_cflags"
LIBS="$LIBS $sdl_libs"
PKG_CHECK_MODULES([sdl], [sdl >= 1.2], [
CFLAGS="$CFLAGS $sdl_CFLAGS"
CXXFLAGS="$CXXFLAGS $sdl_CFLAGS"
LIBS="$LIBS $sdl_LIBS"
WANT_SDL_VERSION_MAJOR=1
else
], [
WANT_SDL=no
WANT_SDL_VIDEO=no
WANT_SDL_AUDIO=no
fi
WANT_SDL_VERSION_MAJOR=
])
fi
fi
SDL_SUPPORT=`echo "$SDL_SUPPORT" | sed -e "s/^ //"`
@ -733,7 +736,7 @@ if [[ "x$WANT_SDL" = "xyes" ]]; then
fi
if [[ "x$WANT_SDL_VIDEO" = "xyes" ]]; then
AC_DEFINE(USE_SDL_VIDEO, 1, [Define to enable SDL video graphics support.])
VIDEOSRCS="../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp"
VIDEOSRCS="../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp ../SDL/video_sdl3.cpp"
KEYCODES="../SDL/keycodes"
if [[ "x$ac_cv_framework_Carbon" = "xyes" ]]; then
AC_MSG_CHECKING([whether __LP64__ is defined])
@ -763,7 +766,7 @@ else
fi
if [[ "x$WANT_SDL_AUDIO" = "xyes" ]]; then
AC_DEFINE(USE_SDL_AUDIO, 1, [Define to enable SDL audio support])
AUDIOSRC="../SDL/audio_sdl.cpp"
AUDIOSRC="../SDL/audio_sdl.cpp ../SDL/audio_sdl3.cpp"
fi
dnl BINCUE overrides

View File

@ -718,12 +718,15 @@ static bool init_sdl()
}
atexit(SDL_Quit);
#if SDL_VERSION_ATLEAST(2,0,0)
#if SDL_VERSION_ATLEAST(2, 0, 0)
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#define SDL_EVENT_DROP_FILE SDL_DROPFILE
#endif
const int SDL_EVENT_TIMEOUT = 100;
for (int i = 0; i < SDL_EVENT_TIMEOUT; i++) {
SDL_Event event;
SDL_PollEvent(&event);
if (event.type == SDL_DROPFILE) {
if (event.type == SDL_EVENT_DROP_FILE) {
sdl_vmdir = event.drop.file;
break;
}

5
SheepShaver/src/Windows/Makefile.in Executable file → Normal file
View File

@ -70,8 +70,9 @@ SRCS = ../main.cpp main_windows.cpp ../prefs.cpp ../prefs_items.cpp prefs_window
../rom_patches.cpp ../rsrc_patches.cpp ../emul_op.cpp ../name_registry.cpp \
../macos_util.cpp ../timer.cpp timer_windows.cpp ../xpram.cpp xpram_windows.cpp \
../adb.cpp ../sony.cpp ../disk.cpp ../cdrom.cpp ../scsi.cpp ../dummy/scsi_dummy.cpp \
../gfxaccel.cpp ../video.cpp ../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp video_blit.cpp \
../audio.cpp ../SDL/audio_sdl.cpp ../ether.cpp ether_windows.cpp \
../gfxaccel.cpp ../video.cpp \
../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp ../SDL/video_sdl3.cpp video_blit.cpp \
../audio.cpp ../SDL/audio_sdl.cpp ../SDL/audio_sdl3.cpp ../ether.cpp ether_windows.cpp \
../thunks.cpp ../serial.cpp serial_windows.cpp ../extfs.cpp extfs_windows.cpp \
about_window_windows.cpp ../user_strings.cpp user_strings_windows.cpp \
../dummy/prefs_editor_dummy.cpp clip_windows.cpp util_windows.cpp \

View File

@ -15,6 +15,7 @@ dnl Options.
AC_ARG_ENABLE(jit, [ --enable-jit enable JIT compiler [default=yes]], [WANT_JIT=$enableval], [WANT_JIT=yes])
AC_ARG_WITH(gtk, [ --with-gtk use GTK user interface [default=yes]], [WANT_GTK=$withval], [WANT_GTK=yes])
AC_ARG_ENABLE(vosf, [ --enable-vosf enable video on SEGV signals [default=no]], [WANT_VOSF=$enableval], [WANT_VOSF=no])
AC_ARG_WITH(sdl3, [ --with-sdl3 use SDL 3.x, rather than SDL 2.x [default=no]], [WANT_SDL_VERSION_MAJOR=3], [WANT_SDL_VERSION_MAJOR=2])
AC_ARG_WITH(bincue,
AS_HELP_STRING([--with-bincue], [Allow cdrom image files in bin/cue mode]))
@ -275,11 +276,14 @@ dnl Use the dummy prefs file.
CPUSRCS="$CPUSRCS ../dummy/prefs_dummy.cpp"
dnl We really want SDL for now
AC_CHECK_TOOL(sdl_config, sdl2-config, no)
AS_IF([test "x$sdl_config" = xno], [AC_MSG_ERROR([Sorry, you currently need SDL for this port])])
SDL_CFLAGS=`$sdl_config --cflags`
if [[ "x$WANT_SDL_VERSION_MAJOR" = "x3" ]]; then
SDL_CFLAGS=`pkg-config sdl3 --cflags`
SDL_LIBS=`pkg-config sdl3 --libs | sed -e 's/-lSDL3/-lSDL3.dll/'`
else
SDL_CFLAGS=`sdl2-config --cflags`
SDL_LIBS=`sdl2-config --static-libs`
fi
AC_SUBST(SDL_CFLAGS)
SDL_LIBS=`$sdl_config --static-libs`
AC_SUBST(SDL_LIBS)
AC_DEFINE(USE_SDL, 1, [Define to enble SDL support])
AC_DEFINE(USE_SDL_VIDEO, 1, [Define to enable SDL video graphics support])
@ -305,6 +309,7 @@ dnl Print summary.
echo
echo SheepShaver configuration summary:
echo
echo SDL major-version ................ : $WANT_SDL_VERSION_MAJOR
echo Enable JIT compiler .............. : $WANT_JIT
echo GTK user interface ............... : $WANT_GTK
echo BINCUE support ................... : $have_bincue

17
SheepShaver/src/Windows/main_windows.cpp Executable file → Normal file
View File

@ -53,6 +53,10 @@
#include "mon.h"
#endif
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#define SDL_EVENT_KEY_UP SDL_KEYUP
#define SDL_EVENT_KEY_DOWN SDL_KEYDOWN
#endif
// Constants
const char ROM_FILE_NAME[] = "ROM";
@ -794,13 +798,16 @@ extern SDL_Window *sdl_window;
HWND GetMainWindowHandle(void)
{
SDL_SysWMinfo wmInfo;
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!sdl_window || !SDL_GetWindowWMInfo(sdl_window, &wmInfo, SDL_SYSWM_CURRENT_VERSION)) {
return NULL;
}
#else
SDL_VERSION(&wmInfo.version);
if (!sdl_window) {
return NULL;
}
if (!SDL_GetWindowWMInfo(sdl_window, &wmInfo)) {
if (!sdl_window || !SDL_GetWindowWMInfo(sdl_window, &wmInfo)) {
return NULL;
}
#endif
if (wmInfo.subsystem != SDL_SYSWM_WINDOWS) {
return NULL;
}
@ -883,7 +890,7 @@ static LRESULT CALLBACK low_level_keyboard_hook(int nCode, WPARAM wParam, LPARAM
if (intercept_event) {
SDL_Event e;
memset(&e, 0, sizeof(e));
e.type = (wParam == WM_KEYDOWN) ? SDL_KEYDOWN : SDL_KEYUP;
e.type = (wParam == WM_KEYDOWN) ? SDL_EVENT_KEY_DOWN : SDL_EVENT_KEY_UP;
e.key.keysym.sym = (p->vkCode == VK_LWIN) ? SDLK_LGUI : SDLK_RGUI;
e.key.keysym.scancode = (p->vkCode == VK_LWIN) ? SDL_SCANCODE_LGUI : SDL_SCANCODE_RGUI;
SDL_PushEvent(&e);