By default, without providing `with-sdl2` in configure it uses SDL1.
Users need to explicitly request SDL2.

Signed-off-by: Ricky Zhang <rickyzhang@gmail.com>
This commit is contained in:
Ricky Zhang 2020-06-25 15:18:16 -04:00
parent 5cbf07e9f5
commit a46759990d
No known key found for this signature in database
GPG Key ID: 681AFAEF6CDEDB4C
9 changed files with 2895 additions and 33 deletions

View File

@ -22,6 +22,10 @@
#include "video.h"
#include "video_blit.h"
#if USE_SDL_VIDEO
#include <SDL.h>
#endif
#include <stdio.h>
#include <stdlib.h>
@ -519,12 +523,21 @@ bool Screen_blitter_init(VisualFormat const & visual_format, bool native_byte_or
#else
const bool use_sdl_video = false;
#endif
#if REAL_ADDRESSING || DIRECT_ADDRESSING
#if REAL_ADDRESSING || DIRECT_ADDRESSING || USE_SDL_VIDEO
if (mac_depth == 1 && !use_sdl_video && !visual_format.fullscreen) {
// Windowed 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines
Screen_blit = Blit_Copy_Raw;
#if __MACOSX__ && !defined(SHEEPSHAVER)
// dludwig@pobox.com, HACK: This works on OSX (64-bit, at least), but not Linux (32-bit?). Why?
// To note, __MACOSX__ is an SDL-declared macro (for platform identification at compile time).
} else if (mac_depth == 16) {
Screen_blit = Blit_Copy_Raw;
#endif
} else {
// Compute RGB shift values

View File

@ -30,6 +30,12 @@
#include "util_windows.h"
#endif
// Import SDL-backend-specific functions
#ifdef USE_SDL_VIDEO
extern void update_sdl_video(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h);
extern void update_sdl_video(SDL_Surface *screen, int numrects, SDL_Rect *rects);
#endif
// Glue for SDL and X11 support
#ifdef TEST_VOSF_PERFORMANCE
#define MONITOR_INIT /* nothing */
@ -514,7 +520,7 @@ static void update_display_window_vosf(VIDEO_DRV_WIN_INIT)
VIDEO_DRV_UNLOCK_PIXELS;
#ifdef USE_SDL_VIDEO
SDL_UpdateRect(drv->s, 0, y1, VIDEO_MODE_X, height);
update_sdl_video(drv->s, 0, y1, VIDEO_MODE_X, height);
#else
if (VIDEO_DRV_HAVE_SHM)
XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0);
@ -558,7 +564,7 @@ static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT)
i2 += scr_bytes_per_row;
}
#ifdef USE_SDL_VIDEO
SDL_UpdateRect(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y);
update_sdl_video(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y);
#endif
VIDEO_DRV_UNLOCK_PIXELS;
return;
@ -664,7 +670,7 @@ static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT)
#endif
}
#ifdef USE_SDL_VIDEO
SDL_UpdateRects(drv->s, bbi, bb);
update_sdl_video(drv->s, bbi, bb);
#endif
VIDEO_DRV_UNLOCK_PIXELS;
}

View File

@ -87,6 +87,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];
@ -99,14 +100,27 @@ static bool open_sdl_audio(void)
fprintf(stderr, "WARNING: Cannot open audio: %s\n", SDL_GetError());
return false;
}
#ifdef ENABLE_SDL2
// 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 defined(BINCUE)
OpenAudio_bincue(audio_spec.freq, audio_spec.format, audio_spec.channels,
audio_spec.silence);
#endif
#ifdef ENABLE_SDL2
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);

View File

@ -1,5 +1,5 @@
/*
* video_sdl.cpp - Video/graphics emulation, SDL specific stuff
* video_sdl.cpp - Video/graphics emulation, SDL 1.x specific stuff
*
* Basilisk II (C) 1997-2008 Christian Bauer
*
@ -39,9 +39,9 @@
* - Backport hw cursor acceleration to Basilisk II?
* - Factor out code
*/
#include "sysdeps.h"
#ifdef ENABLE_SDL1
#include <SDL.h>
#include <SDL_mutex.h>
#include <SDL_thread.h>
@ -455,7 +455,7 @@ static inline int sdl_display_height(void)
return height;
}
// Check wether specified mode is available
// Check whether specified mode is available
static bool has_mode(int type, int width, int height, int depth)
{
#ifdef SHEEPSHAVER
@ -584,6 +584,16 @@ static void migrate_screen_prefs(void)
#endif
}
void update_sdl_video(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
{
SDL_UpdateRect(screen, x, y, w, h);
}
void update_sdl_video(SDL_Surface *screen, int numrects, SDL_Rect *rects)
{
SDL_UpdateRects(screen, numrects, rects);
}
/*
* Display "driver" classes
@ -2269,3 +2279,4 @@ void video_set_dirty_area(int x, int y, int w, int h)
// XXX handle dirty bounding boxes for non-VOSF modes
}
#endif
#endif //end of ifdef ENABLE_SDL1

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,7 @@ AC_ARG_ENABLE(sdl-video, [ --enable-sdl-video use SDL for video graphi
AC_ARG_ENABLE(sdl-audio, [ --enable-sdl-audio use SDL for audio [default=no]], [WANT_SDL_AUDIO=$enableval], [WANT_SDL_AUDIO=no])
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(sdl2, [ --with-sdl2 use SDL 2.x, rather than SDL 1.x [default=no]], [WANT_SDL_VERSION_MAJOR=2], [WANT_SDL_VERSION_MAJOR=1])
dnl JIT compiler options.
AC_ARG_ENABLE(jit-compiler, [ --enable-jit-compiler enable JIT compiler [default=no]], [WANT_JIT=$enableval], [WANT_JIT=no])
@ -255,7 +256,7 @@ AC_CHECK_LIB(rt, timer_create)
AC_CHECK_LIB(rt, shm_open)
AC_CHECK_LIB(m, cos)
dnl AC_CHECK_SDLFRAMEWORK($1=NAME, $2=INCLUDES)
dnl AC_CHECK_SDLFRAMEWORK($1=NAME, $2=INCLUDES, $3=ACTION_IF_SUCCESSFUL, $4=ACTION_IF_UNSUCCESSFUL)
dnl AC_TRY_LINK uses main() but SDL needs main to take args,
dnl therefore main is undefined with #undef.
dnl Framework can be in an custom location.
@ -265,18 +266,16 @@ AC_DEFUN([AC_CHECK_SDLFRAMEWORK], [
ac_Framework, [
saved_LIBS="$LIBS"
LIBS="$LIBS -framework $1"
if [[ "x$SDL_FRAMEWORK" != "x/Library/Frameworks" ]]; then
if [[ "x$SDL_FRAMEWORK" != "x/System/Library/Frameworks" ]]; then
LIBS="$saved_LIBS -F$SDL_FRAMEWORK -framework $1"
fi
if [[ "x$SDL_FRAMEWORK" != "x/System/Library/Frameworks" ]]; then
LIBS="$saved_LIBS -F$SDL_FRAMEWORK -framework $1"
fi
saved_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -I$SDL_FRAMEWORK/SDL.framework/Headers"
CPPFLAGS="$CPPFLAGS -I$SDL_FRAMEWORK/$1.framework/Headers"
AC_TRY_LINK(
[$2
#undef main], [],
[AS_VAR_SET(ac_Framework, yes)], [AS_VAR_SET(ac_Framework, no);
LIBS="$saved_LIBS"; CPPFLAGS="$saved_CPPFLAGS"]
[AS_VAR_SET(ac_Framework, yes); $3], [AS_VAR_SET(ac_Framework, no);
LIBS="$saved_LIBS"; CPPFLAGS="$saved_CPPFLAGS"; $4]
)
])
AS_IF([test AS_VAR_GET(ac_Framework) = yes],
@ -300,27 +299,66 @@ if [[ "x$WANT_SDL_AUDIO" = "xyes" ]]; then
fi
if [[ "x$WANT_SDL" = "xyes" ]]; then
if [[ "x$WANT_SDL_FRAMEWORK" = "xyes" ]]; then
AC_CHECK_SDLFRAMEWORK(SDL, [#include <SDL.h>])
TEMP_WANT_SDL_VERSION_MAJOR=$WANT_SDL_VERSION_MAJOR
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_CHECK_SDLFRAMEWORK(SDL2, [#include <SDL.h>], [
WANT_SDL_VERSION_MAJOR=2
], [
TEMP_WANT_SDL_VERSION_MAJOR=1
])
fi
if [[ "x$TEMP_WANT_SDL_VERSION_MAJOR" = "x1" ]]; then
AC_CHECK_SDLFRAMEWORK(SDL, [#include <SDL.h>], [
WANT_SDL_VERSION_MAJOR=1
])
fi
else
ac_cv_framework_SDL=no
fi
if [[ "x$ac_cv_framework_SDL" = "xno" ]]; 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`
if [[ "x$WANT_SDL_VERSION_MAJOR" = "x1" ]]; then
AC_DEFINE(ENABLE_SDL1, 1, [Define if using SDL1.])
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"
else
sdl_libs=`$sdl_config --libs`
WANT_SDL=no
WANT_SDL_VIDEO=no
WANT_SDL_AUDIO=no
SDL_SUPPORT="none"
fi
fi
if [[ "x$WANT_SDL_VERSION_MAJOR" = "x2" ]]; then
AC_DEFINE(ENABLE_SDL2, 1, [Define if using SDL2.])
AC_PATH_PROG(sdl_config, "sdl2-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"
else
WANT_SDL=no
WANT_SDL_VIDEO=no
WANT_SDL_AUDIO=no
SDL_SUPPORT="none"
fi
CFLAGS="$CFLAGS $sdl_cflags"
CXXFLAGS="$CXXFLAGS $sdl_cflags"
LIBS="$LIBS $sdl_libs"
else
WANT_SDL=no
WANT_SDL_VIDEO=no
WANT_SDL_AUDIO=no
SDL_SUPPORT="none"
fi
fi
SDL_SUPPORT=`echo "$SDL_SUPPORT" | sed -e "s/^ //"`
@ -448,7 +486,7 @@ if [[ "x$WANT_GTK" = "xgtk" ]]; then
dnl somehow, <gnome-i18n.h> would redefine gettext() to nothing if
dnl ENABLE_NLS is not set, thusly conflicting with C++ <string> which
dnl includes <libintl.h>
AM_GNU_GETTEXT
AM_GNU_GETTEXT([external])
B2_PATH_GNOMEUI([
AC_DEFINE(HAVE_GNOMEUI, 1, [Define if libgnomeui is available.])
GUI_CFLAGS="$GUI_CFLAGS $GNOMEUI_CFLAGS"
@ -837,7 +875,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"
VIDEOSRCS="../SDL/video_sdl.cpp ../SDL/video_sdl2.cpp"
KEYCODES="../SDL/keycodes"
if [[ "x$ac_cv_framework_Carbon" = "xyes" ]]; then
AC_MSG_CHECKING([whether __LP64__ is defined])
@ -863,6 +901,9 @@ if [[ "x$WANT_SDL_VIDEO" = "xyes" ]]; then
EXTRASYSSRCS="$EXTRASYSSRCS ../dummy/clip_dummy.cpp"
;;
esac
if [[ "$WANT_GTK" != "no" ]]; then
LIBS="$LIBS -lX11"
fi
fi
elif [[ "x$WANT_MACOSX_GUI" != "xyes" ]]; then
VIDEOSRCS="video_x.cpp"
@ -1863,6 +1904,7 @@ echo
echo Mac OS X GUI ........................... : $WANT_MACOSX_GUI
echo Mac OS X Sound ......................... : $WANT_MACOSX_SOUND
echo SDL support ............................ : $SDL_SUPPORT
echo SDL major-version ...................... : $WANT_SDL_VERSION_MAJOR
echo BINCUE support ......................... : $have_bincue
echo LIBVHD support ......................... : $have_libvhd
echo VDE support ............................ : $have_vdeplug

View File

@ -28,6 +28,7 @@
#ifdef USE_SDL
# include <SDL.h>
# include <SDL_main.h>
#endif
#ifndef USE_SDL_VIDEO
@ -62,6 +63,9 @@ struct sigstate {
# ifdef HAVE_GNOMEUI
# include <gnome.h>
# endif
# if !defined(GDK_WINDOWING_QUARTZ) && !defined(GDK_WINDOWING_WAYLAND)
# include <X11/Xlib.h>
# endif
#endif
#ifdef ENABLE_XF86_DGA
@ -386,6 +390,9 @@ static void usage(const char *prg_name)
int main(int argc, char **argv)
{
#if defined(ENABLE_GTK) && !defined(GDK_WINDOWING_QUARTZ) && !defined(GDK_WINDOWING_WAYLAND)
XInitThreads();
#endif
const char *vmdir = NULL;
char str[256];
@ -448,6 +455,19 @@ int main(int argc, char **argv)
vde_sock = argv[i];
argv[i] = NULL;
}
#if defined(__APPLE__) && defined(__MACH__)
// Mac OS X likes to pass in various options of its own, when launching an app.
// Attempt to ignore these.
if (argv[i]) {
const char * mac_psn_prefix = "-psn_";
if (strcmp(argv[i], "-NSDocumentRevisionsDebugMode") == 0) {
argv[i] = NULL;
} else if (strncmp(mac_psn_prefix, argv[i], strlen(mac_psn_prefix)) == 0) {
argv[i] = NULL;
}
}
#endif
}
// Remove processed arguments
@ -531,6 +551,18 @@ int main(int argc, char **argv)
QuitEmulator();
}
atexit(SDL_Quit);
#if __MACOSX__ && SDL_VERSION_ATLEAST(2,0,0)
// On Mac OS X hosts, SDL2 will create its own menu bar. This is mostly OK,
// except that it will also install keyboard shortcuts, such as Command + Q,
// which can interfere with keyboard shortcuts in the guest OS.
//
// HACK: disable these shortcuts, while leaving all other pieces of SDL2's
// menu bar in-place.
extern void disable_SDL2_macosx_menu_bar_keyboard_shortcuts();
disable_SDL2_macosx_menu_bar_keyboard_shortcuts();
#endif
#endif
// Init system routines
@ -643,6 +675,11 @@ int main(int argc, char **argv)
D(bug("Mac RAM starts at %p (%08x)\n", RAMBaseHost, RAMBaseMac));
D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac));
#if __MACOSX__
extern void set_current_directory();
set_current_directory();
#endif
// Get rom file path from preferences
const char *rom_path = PrefsFindString("rom");

View File

@ -243,6 +243,11 @@ enum {
STR_WINDOW_TITLE = 4000,
STR_WINDOW_TITLE_FROZEN,
STR_WINDOW_TITLE_GRABBED,
STR_WINDOW_TITLE_GRABBED0,
STR_WINDOW_TITLE_GRABBED1,
STR_WINDOW_TITLE_GRABBED2,
STR_WINDOW_TITLE_GRABBED3,
STR_WINDOW_TITLE_GRABBED4,
STR_WINDOW_MENU = 4050,
STR_WINDOW_ITEM_ABOUT,
STR_WINDOW_ITEM_REFRESH,

View File

@ -241,6 +241,7 @@ user_string_def common_strings[] = {
{STR_CPU_68040_LAB, "68040"},
{STR_ROM_FILE_CTRL, "ROM File"},
{STR_IDLEWAIT_CTRL, "Don't Use CPU When Idle"},
{STR_JIT_PANE_TITLE, "JIT Compiler"},
{STR_JIT_CTRL, "Enable JIT Compiler"},
{STR_JIT_FPU_CTRL, "Compile FPU Instructions"},
@ -255,6 +256,16 @@ user_string_def common_strings[] = {
{STR_WINDOW_TITLE, "Basilisk II"},
{STR_WINDOW_TITLE_FROZEN, "Basilisk II *** FROZEN ***"},
{STR_WINDOW_TITLE_GRABBED, "Basilisk II (mouse grabbed, press Ctrl-F5 to release)"},
{STR_WINDOW_TITLE_GRABBED0, "Basilisk II (mouse grabbed, press "},
{STR_WINDOW_TITLE_GRABBED1, "Ctrl-"},
#ifdef __APPLE__
{STR_WINDOW_TITLE_GRABBED2, "Opt-"},
{STR_WINDOW_TITLE_GRABBED3, "Cmd-"},
#else
{STR_WINDOW_TITLE_GRABBED2, "Alt-"},
{STR_WINDOW_TITLE_GRABBED3, "Win-"},
#endif
{STR_WINDOW_TITLE_GRABBED4, "F5 to release)"},
{STR_WINDOW_MENU, "Basilisk II"},
{STR_WINDOW_ITEM_ABOUT, "About Basilisk II" ELLIPSIS},
{STR_WINDOW_ITEM_REFRESH, "Refresh Rate"},