From f4e3a9d3f7a81243661135102de4c48bbd193800 Mon Sep 17 00:00:00 2001 From: Stian Skjelstad Date: Tue, 27 Nov 2018 08:07:17 +0100 Subject: [PATCH] Support for SDL2-video --- Makefile.in | 3 + Rules.make.in | 4 + config.h.in | 3 + configure | 437 ++++++++++- configure.ac | 25 +- filesel/pfilesel.c | 10 + filesel/pfilesel.h | 1 + filesel/pfsmain.c | 13 +- m4/sdl2.m4 | 234 ++++++ ocp-sdl2 | 2 + stuff/Makefile | 15 + stuff/console.c | 31 + stuff/poutput-sdl2.c | 1748 ++++++++++++++++++++++++++++++++++++++++++ stuff/poutput-sdl2.h | 7 + stuff/poutput.h | 7 +- 15 files changed, 2535 insertions(+), 5 deletions(-) create mode 100644 m4/sdl2.m4 create mode 100755 ocp-sdl2 create mode 100644 stuff/poutput-sdl2.c create mode 100644 stuff/poutput-sdl2.h diff --git a/Makefile.in b/Makefile.in index 913a672d..6ecb30d7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -57,6 +57,9 @@ endif ifeq ($(HAVE_SDL),1) $(CP) ocp-sdl "$(DESTDIR)$(BINDIR)/ocp-sdl" endif +ifeq ($(HAVE_SDL2),1) + $(CP) ocp-sdl2 "$(DESTDIR)$(BINDIR)/ocp-sdl2" +endif ifeq ($(HAVE_X11),1) $(CP) ocp-x11 "$(DESTDIR)$(BINDIR)/ocp-x11" endif diff --git a/Rules.make.in b/Rules.make.in index c0b691b9..bc49a89c 100644 --- a/Rules.make.in +++ b/Rules.make.in @@ -56,6 +56,10 @@ SDL_CFLAGS=@SDL_CFLAGS@ SDL_LIBS=@SDL_LIBS@ HAVE_SDL=@HAVE_SDL@ +SDL2_CFLAGS=@SDL2_CFLAGS@ +SDL2_LIBS=@SDL2_LIBS@ +HAVE_SDL2=@HAVE_SDL2@ + # These affect what plugins are compiled in at some points CDROM_SUPPORT=@CDROM_SUPPORT@ LINUX=@LINUX@ diff --git a/config.h.in b/config.h.in index ff06f1fa..038a6b0c 100644 --- a/config.h.in +++ b/config.h.in @@ -194,6 +194,7 @@ /* #define MCP_DEBUG 1 */ /* #define COREAUDIO_DEBUG 1 */ /* #define SDL_DEBUG 1 */ +/* #define SDL2_DEBUG 1 */ /* #define CPIFACE_DEBUG 1 */ #define VERBOSE_FRAMEBUFFER 1 @@ -276,6 +277,8 @@ #undef HAVE_SDL +#undef HAVE_SDL2 + #undef HAVE_MAD #undef HAVE_ERRNO_H diff --git a/configure b/configure index dd8f968b..9295fb20 100755 --- a/configure +++ b/configure @@ -661,8 +661,13 @@ ALSA_CFLAGS ADPLUG_LIBS ADPLUG_CXXFLAGS HAVE_SDL +HAVE_SDL2 +SDL2_CONFIG SDL_LIBS SDL_CFLAGS +SDL2_FRAMEWORK +SDL2_LIBS +SDL2_CFLAGS HAVE_X11 FLAC_INI HAVE_FLAC @@ -797,10 +802,15 @@ with_lzh with_coreaudio with_flac with_sdl +with_sdl2 with_desktop_file_install with_timidity_default_path with_ncurses with_ncursesw +with_sdl_prefix +with_sdl_exec_prefix +enable_sdltest +enable_sdlframework with_ultradir with_freepats with_efence @@ -824,7 +834,10 @@ CURSES_LIB CURSES_CPPFLAGS PKG_CONFIG PKG_CONFIG_PATH -PKG_CONFIG_LIBDIR' +PKG_CONFIG_LIBDIR +SDL2_FRAMEWORK +SDL_CFLAGS +SDL_LIBS' # Initialize some variables set by options. @@ -1445,6 +1458,13 @@ if test -n "$ac_init_help"; then esac cat <<\_ACEOF +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-sdltest Do not try to compile and run a test SDL program + --disable-sdlframework Do not search for SDL2.framework + Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) @@ -1461,11 +1481,14 @@ Optional Packages: --with-coreaudio force/disable osx coreaudio support (autodetect by default) --with-flac force/disable FLAC support (autodetect by default) --with-sdl force/disable SDL video support (autodetect by default) + --with-sdl2 force/disable SDL2 video support (autodetect by default) --without-desktop_file_install Do not install .desktop file (SDL and X11 normally does this) --with-timidity-default-path=DIR Where timidity.cfg is (PREFIX/share/timidity) --with-ncurses force the use of Ncurses or NcursesW --without-ncursesw do not use NcursesW (wide character support) + --with-sdl-prefix=PFX Prefix where SDL is installed (optional) + --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional) --with-ultradir= default ultradir path to put into ocp.ini --with-freepats= default path for freepats to put into ocp.ini --with-efence Enable usage of efence @@ -1493,6 +1516,10 @@ Some influential environment variables: directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path + SDL2_FRAMEWORK + Path to SDL2.framework + SDL_CFLAGS C compiler flags for SDL, overriding pkg-config + SDL_LIBS linker flags for SDL, overriding pkg-config Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. @@ -6054,6 +6081,14 @@ else fi +# Check whether --with-sdl2 was given. +if test "${with_sdl2+set}" = set; then : + withval=$with_sdl2; +else + with_sdl2=auto +fi + + # Check whether --with-desktop_file_install was given. if test "${with_desktop_file_install+set}" = set; then : withval=$with_desktop_file_install; @@ -8898,6 +8933,399 @@ else fi + + +if test "x$with_sdl2" != "xno"; then + +# Check whether --with-sdl-prefix was given. +if test "${with_sdl_prefix+set}" = set; then : + withval=$with_sdl_prefix; sdl_prefix="$withval" +else + sdl_prefix="" +fi + + +# Check whether --with-sdl-exec-prefix was given. +if test "${with_sdl_exec_prefix+set}" = set; then : + withval=$with_sdl_exec_prefix; sdl_exec_prefix="$withval" +else + sdl_exec_prefix="" +fi + +# Check whether --enable-sdltest was given. +if test "${enable_sdltest+set}" = set; then : + enableval=$enable_sdltest; +else + enable_sdltest=yes +fi + +# Check whether --enable-sdlframework was given. +if test "${enable_sdlframework+set}" = set; then : + enableval=$enable_sdlframework; +else + search_sdl_framework=yes +fi + + + + + min_sdl_version="2.0.0" + + if test "x$sdl_prefix$sdl_exec_prefix" = x ; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SDL" >&5 +$as_echo_n "checking for SDL... " >&6; } + +if test -n "$SDL_CFLAGS"; then + pkg_cv_SDL_CFLAGS="$SDL_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sdl2 >= \$min_sdl_version\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sdl2 >= $min_sdl_version") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_SDL_CFLAGS=`$PKG_CONFIG --cflags "sdl2 >= $min_sdl_version" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$SDL_LIBS"; then + pkg_cv_SDL_LIBS="$SDL_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sdl2 >= \$min_sdl_version\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sdl2 >= $min_sdl_version") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_SDL_LIBS=`$PKG_CONFIG --libs "sdl2 >= $min_sdl_version" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + SDL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "sdl2 >= $min_sdl_version" 2>&1` + else + SDL_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "sdl2 >= $min_sdl_version" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$SDL_PKG_ERRORS" >&5 + + sdl_pc=no +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + sdl_pc=no +else + SDL_CFLAGS=$pkg_cv_SDL_CFLAGS + SDL_LIBS=$pkg_cv_SDL_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + sdl_pc=yes +fi + else + sdl_pc=no + if test x$sdl_exec_prefix != x ; then + sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" + if test x${SDL2_CONFIG+set} != xset ; then + SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config + fi + fi + if test x$sdl_prefix != x ; then + sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" + if test x${SDL2_CONFIG+set} != xset ; then + SDL2_CONFIG=$sdl_prefix/bin/sdl2-config + fi + fi + fi + + if test "x$sdl_pc" = xyes ; then + no_sdl="" + SDL2_CONFIG="pkg-config sdl2" + else + as_save_PATH="$PATH" + if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then + PATH="$prefix/bin:$prefix/usr/bin:$PATH" + fi + # Extract the first word of "sdl2-config", so it can be a program name with args. +set dummy sdl2-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_SDL2_CONFIG+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $SDL2_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_SDL2_CONFIG="$SDL2_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_SDL2_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_SDL2_CONFIG" && ac_cv_path_SDL2_CONFIG="no" + ;; +esac +fi +SDL2_CONFIG=$ac_cv_path_SDL2_CONFIG +if test -n "$SDL2_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SDL2_CONFIG" >&5 +$as_echo "$SDL2_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + PATH="$as_save_PATH" + no_sdl="" + + if test "$SDL2_CONFIG" = "no" -a "x$search_sdl_framework" = "xyes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SDL2.framework" >&5 +$as_echo_n "checking for SDL2.framework... " >&6; } + if test "x$SDL2_FRAMEWORK" != x; then + sdl_framework=$SDL2_FRAMEWORK + else + for d in / ~/ /System/; do + if test -d "$dLibrary/Frameworks/SDL2.framework"; then + sdl_framework="$dLibrary/Frameworks/SDL2.framework" + fi + done + fi + + if test -d $sdl_framework; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $sdl_framework" >&5 +$as_echo "$sdl_framework" >&6; } + sdl_framework_dir=`dirname $sdl_framework` + SDL_CFLAGS="-F$sdl_framework_dir -Wl,-framework,SDL2 -I$sdl_framework/include" + SDL_LIBS="-F$sdl_framework_dir -Wl,-framework,SDL2" + else + no_sdl=yes + fi + fi + + if test "$SDL2_CONFIG" != "no"; then + if test "x$sdl_pc" = "xno"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SDL - version >= $min_sdl_version" >&5 +$as_echo_n "checking for SDL - version >= $min_sdl_version... " >&6; } + SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags` + SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs` + fi + + sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/'` + sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/'` + sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'` + if test "x$enable_sdltest" = "xyes" ; then + ac_save_CFLAGS="$CFLAGS" + ac_save_CXXFLAGS="$CXXFLAGS" + ac_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + rm -f conf.sdltest + if test "$cross_compiling" = yes; then : + echo $ac_n "cross compiling; assumed OK... $ac_c" +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +#include +#include "SDL.h" + +char* +my_strdup (char *str) +{ + char *new_str; + + if (str) + { + new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); + strcpy (new_str, str); + } + else + new_str = NULL; + + return new_str; +} + +int main (int argc, char *argv[]) +{ + int major, minor, micro; + char *tmp_version; + + /* This hangs on some systems (?) + system ("touch conf.sdltest"); + */ + { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); } + + /* HP/UX 9 (%@#!) writes to sscanf strings */ + tmp_version = my_strdup("$min_sdl_version"); + if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + printf("%s, bad version string\n", "$min_sdl_version"); + exit(1); + } + + if (($sdl_major_version > major) || + (($sdl_major_version == major) && ($sdl_minor_version > minor)) || + (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) + { + return 0; + } + else + { + printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); + printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro); + printf("*** best to upgrade to the required version.\n"); + printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n"); + printf("*** to point to the correct copy of sdl2-config, and remove the file\n"); + printf("*** config.cache before re-running configure\n"); + return 1; + } +} + + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + no_sdl=yes +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + + fi + if test "x$sdl_pc" = "xno"; then + if test "x$no_sdl" = "xyes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + fi + fi + fi + fi + if test "x$no_sdl" = x ; then + with_sdl2=yes; + else + if test "$SDL2_CONFIG" = "no" ; then + echo "*** The sdl2-config script installed by SDL could not be found" + echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" + echo "*** your path, or set the SDL2_CONFIG environment variable to the" + echo "*** full path to sdl2-config." + else + if test -f conf.sdltest ; then + : + else + echo "*** Could not run SDL test program, checking why..." + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include "SDL.h" + +int main(int argc, char *argv[]) +{ return 0; } +#undef main +#define main K_and_R_C_main + +int +main () +{ + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + echo "*** The test program compiled, but did not run. This usually means" + echo "*** that the run-time linker is not finding SDL or finding the wrong" + echo "*** version of SDL. If it is not finding SDL, you'll need to set your" + echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" + echo "*** to the installed location Also, make sure you have run ldconfig if that" + echo "*** is required on your system" + echo "***" + echo "*** If you have an old version installed, it is best to remove it, although" + echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" +else + echo "*** The test program failed to compile or link. See the file config.log for the" + echo "*** exact error that occured. This usually means SDL was incorrectly installed" + echo "*** or that you have moved SDL since it was installed. In the latter case, you" + echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + SDL_CFLAGS="" + SDL_LIBS="" + if test "x$with_sdl2" = "xyes"; then as_fn_error $? "\"libSDL2 was not found\"" "$LINENO" 5; else with_sdl2="no"; fi + fi + + + rm -f conf.sdltest + +fi +SDL2_CFLAGS=$SDL_CFLAGS +SDL2_LIBS=$SDL_LIBS +SDL_CFLAGS= +SDL_LIBS= + +if test "x$with_sdl2" = "xno"; then + HAVE_SDL2= +else + HAVE_SDL2=1 + $as_echo "#define HAVE_SDL2 1" >>confdefs.h + +fi + org_cflags="$CFLAGS" org_cppflags="$CPPFLAGS" @@ -9916,7 +10344,7 @@ $as_echo "#define USE_LIBICONV_NATIVE 1" >>confdefs.h esac if ! test "x$with_desktop_file_install" = "xno"; then - if test "x$with_x11" != "xno" || test "x$with_sdl" != "xno"; then + if test "x$with_x11" != "xno" || test "x$with_sdl" != "xno" || test "x$with_sdl2" != "xno"; then # Extract the first word of "desktop-file-install", so it can be a program name with args. set dummy desktop-file-install; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 @@ -11300,6 +11728,11 @@ if test "x$with_sdl" = "xno"; then else echo "SDL: ON" fi +if test "x$with_sdl2" = "xno"; then + echo "SDL2: OFF" +else + echo "SDL2: ON" +fi if test "x$with_alsa" = "xno"; then echo "ALSA: OFF" else diff --git a/configure.ac b/configure.ac index 0e42bcd8..abe8dabe 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,7 @@ AC_ARG_WITH(coreaudio, [ --with-coreaudio force/disable osx coreaudio su AC_ARG_WITH(flac, [ --with-flac force/disable FLAC support (autodetect by default)],, with_flac=auto) AC_ARG_WITH(sdl, [ --with-sdl force/disable SDL video support (autodetect by default)],, with_sdl=auto) +AC_ARG_WITH(sdl2, [ --with-sdl2 force/disable SDL2 video support (autodetect by default)],, with_sdl2=auto) AC_ARG_WITH(desktop_file_install, [ --without-desktop_file_install Do not install .desktop file (SDL and X11 normally does this)],, with_desktop_file_install=auto) @@ -509,6 +510,23 @@ else AC_DEFINE(HAVE_X11) fi +AC_SUBST(SDL2_CFLAGS) +AC_SUBST(SDL2_LIBS) +if test "x$with_sdl2" != "xno"; then + AM_PATH_SDL2(["2.0.0"], with_sdl2=yes;, if test "x$with_sdl2" = "xyes"; then AC_MSG_ERROR("libSDL2 was not found"); else with_sdl2="no"; fi) +fi +SDL2_CFLAGS=$SDL_CFLAGS +SDL2_LIBS=$SDL_LIBS +SDL_CFLAGS= +SDL_LIBS= +AC_SUBST(HAVE_SDL2) +if test "x$with_sdl2" = "xno"; then + HAVE_SDL2= +else + HAVE_SDL2=1 + AC_DEFINE(HAVE_SDL2) +fi + org_cflags="$CFLAGS" org_cppflags="$CPPFLAGS" AC_SUBST(SDL_CFLAGS) @@ -841,7 +859,7 @@ case $with_libiconv in esac if ! test "x$with_desktop_file_install" = "xno"; then - if test "x$with_x11" != "xno" || test "x$with_sdl" != "xno"; then + if test "x$with_x11" != "xno" || test "x$with_sdl" != "xno" || test "x$with_sdl2" != "xno"; then AC_CHECK_PROG(DESKTOP_FILE_INSTALL,desktop-file-install,desktop-file-install,failed) if test "x$DESKTOP_FILE_INSTALL" = "xfailed"; then AC_MSG_ERROR(Cannot find desktop-file-install (required by x11 and SDL driver).) @@ -899,6 +917,11 @@ if test "x$with_sdl" = "xno"; then else echo "SDL: ON" fi +if test "x$with_sdl2" = "xno"; then + echo "SDL2: OFF" +else + echo "SDL2: ON" +fi if test "x$with_alsa" = "xno"; then echo "ALSA: OFF" else diff --git a/filesel/pfilesel.c b/filesel/pfilesel.c index 94c48783..1c89d431 100644 --- a/filesel/pfilesel.c +++ b/filesel/pfilesel.c @@ -801,6 +801,16 @@ int fsPreInit(void) return 1; } +int fsLateInit(void) +{ + if (plVidType == vidModern) + { + fsScrType=8; + } + + return 1; +} + int fsInit(void) { /* diff --git a/filesel/pfilesel.h b/filesel/pfilesel.h index 5cb6df69..60d7e833 100644 --- a/filesel/pfilesel.h +++ b/filesel/pfilesel.h @@ -10,6 +10,7 @@ extern int fsFilesLeft(void); extern signed int fsFileSelect(void); /* extern char fsAddFiles(const char *); use the playlist instead..*/ extern int fsPreInit(void); +extern int fsLateInit(void); extern int fsInit(void); extern void fsClose(void); diff --git a/filesel/pfsmain.c b/filesel/pfsmain.c index 1ac1118b..811af687 100644 --- a/filesel/pfsmain.c +++ b/filesel/pfsmain.c @@ -398,6 +398,17 @@ static int fsint(void) return errOk; } +static int fslateint(void) +{ + if (!fsLateInit()) + { + fprintf(stderr, "fileselector post-init failed!\n"); + return errGen; + } + + return errOk; +} + static void fsclose() { mdbUnregisterReadDir(&adbReadDirReg); @@ -617,4 +628,4 @@ static void __attribute__((destructor))done(void) char *dllinfo = ""; #endif -DLLEXTINFO_PREFIX struct linkinfostruct dllextinfo = {.name = "pfilesel", .desc = "OpenCP Fileselector (c) 1994-10 Niklas Beisert, Tammo Hinrichs, Stian Skjelstad", .ver = DLLVERSION, .size = 0, .PreInit = fspreint, .Init = fsint, .LateClose = fsclose}; +DLLEXTINFO_PREFIX struct linkinfostruct dllextinfo = {.name = "pfilesel", .desc = "OpenCP Fileselector (c) 1994-10 Niklas Beisert, Tammo Hinrichs, Stian Skjelstad", .ver = DLLVERSION, .size = 0, .PreInit = fspreint, .Init = fsint, .LateInit = fslateint, .LateClose = fsclose}; diff --git a/m4/sdl2.m4 b/m4/sdl2.m4 new file mode 100644 index 00000000..b915f99e --- /dev/null +++ b/m4/sdl2.m4 @@ -0,0 +1,234 @@ +# Configure paths for SDL +# Sam Lantinga 9/21/99 +# stolen from Manish Singh +# stolen back from Frank Belew +# stolen from Manish Singh +# Shamelessly stolen from Owen Taylor +# +# Changelog: +# * also look for SDL2.framework under Mac OS X + +# serial 1 + +dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) +dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS +dnl +AC_DEFUN([AM_PATH_SDL2], +[dnl +dnl Get the cflags and libraries from the sdl2-config script +dnl +AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], + sdl_prefix="$withval", sdl_prefix="") +AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)], + sdl_exec_prefix="$withval", sdl_exec_prefix="") +AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], + , enable_sdltest=yes) +AC_ARG_ENABLE(sdlframework, [ --disable-sdlframework Do not search for SDL2.framework], + , search_sdl_framework=yes) + +AC_ARG_VAR(SDL2_FRAMEWORK, [Path to SDL2.framework]) + + min_sdl_version=ifelse([$1], ,2.0.0,$1) + + if test "x$sdl_prefix$sdl_exec_prefix" = x ; then + PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version], + [sdl_pc=yes], + [sdl_pc=no]) + else + sdl_pc=no + if test x$sdl_exec_prefix != x ; then + sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" + if test x${SDL2_CONFIG+set} != xset ; then + SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config + fi + fi + if test x$sdl_prefix != x ; then + sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" + if test x${SDL2_CONFIG+set} != xset ; then + SDL2_CONFIG=$sdl_prefix/bin/sdl2-config + fi + fi + fi + + if test "x$sdl_pc" = xyes ; then + no_sdl="" + SDL2_CONFIG="pkg-config sdl2" + else + as_save_PATH="$PATH" + if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then + PATH="$prefix/bin:$prefix/usr/bin:$PATH" + fi + AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH]) + PATH="$as_save_PATH" + no_sdl="" + + if test "$SDL2_CONFIG" = "no" -a "x$search_sdl_framework" = "xyes"; then + AC_MSG_CHECKING(for SDL2.framework) + if test "x$SDL2_FRAMEWORK" != x; then + sdl_framework=$SDL2_FRAMEWORK + else + for d in / ~/ /System/; do + if test -d "$dLibrary/Frameworks/SDL2.framework"; then + sdl_framework="$dLibrary/Frameworks/SDL2.framework" + fi + done + fi + + if test -d $sdl_framework; then + AC_MSG_RESULT($sdl_framework) + sdl_framework_dir=`dirname $sdl_framework` + SDL_CFLAGS="-F$sdl_framework_dir -Wl,-framework,SDL2 -I$sdl_framework/include" + SDL_LIBS="-F$sdl_framework_dir -Wl,-framework,SDL2" + else + no_sdl=yes + fi + fi + + if test "$SDL2_CONFIG" != "no"; then + if test "x$sdl_pc" = "xno"; then + AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) + SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags` + SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs` + fi + + sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` + sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` + sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` + if test "x$enable_sdltest" = "xyes" ; then + ac_save_CFLAGS="$CFLAGS" + ac_save_CXXFLAGS="$CXXFLAGS" + ac_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" +dnl +dnl Now check if the installed SDL is sufficiently new. (Also sanity +dnl checks the results of sdl2-config to some extent +dnl + rm -f conf.sdltest + AC_TRY_RUN([ +#include +#include +#include +#include "SDL.h" + +char* +my_strdup (char *str) +{ + char *new_str; + + if (str) + { + new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); + strcpy (new_str, str); + } + else + new_str = NULL; + + return new_str; +} + +int main (int argc, char *argv[]) +{ + int major, minor, micro; + char *tmp_version; + + /* This hangs on some systems (?) + system ("touch conf.sdltest"); + */ + { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); } + + /* HP/UX 9 (%@#!) writes to sscanf strings */ + tmp_version = my_strdup("$min_sdl_version"); + if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + printf("%s, bad version string\n", "$min_sdl_version"); + exit(1); + } + + if (($sdl_major_version > major) || + (($sdl_major_version == major) && ($sdl_minor_version > minor)) || + (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) + { + return 0; + } + else + { + printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); + printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro); + printf("*** best to upgrade to the required version.\n"); + printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n"); + printf("*** to point to the correct copy of sdl2-config, and remove the file\n"); + printf("*** config.cache before re-running configure\n"); + return 1; + } +} + +],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + + fi + if test "x$sdl_pc" = "xno"; then + if test "x$no_sdl" = "xyes"; then + AC_MSG_RESULT(no) + else + AC_MSG_RESULT(yes) + fi + fi + fi + fi + if test "x$no_sdl" = x ; then + ifelse([$2], , :, [$2]) + else + if test "$SDL2_CONFIG" = "no" ; then + echo "*** The sdl2-config script installed by SDL could not be found" + echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" + echo "*** your path, or set the SDL2_CONFIG environment variable to the" + echo "*** full path to sdl2-config." + else + if test -f conf.sdltest ; then + : + else + echo "*** Could not run SDL test program, checking why..." + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + AC_TRY_LINK([ +#include +#include "SDL.h" + +int main(int argc, char *argv[]) +{ return 0; } +#undef main +#define main K_and_R_C_main +], [ return 0; ], + [ echo "*** The test program compiled, but did not run. This usually means" + echo "*** that the run-time linker is not finding SDL or finding the wrong" + echo "*** version of SDL. If it is not finding SDL, you'll need to set your" + echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" + echo "*** to the installed location Also, make sure you have run ldconfig if that" + echo "*** is required on your system" + echo "***" + echo "*** If you have an old version installed, it is best to remove it, although" + echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], + [ echo "*** The test program failed to compile or link. See the file config.log for the" + echo "*** exact error that occured. This usually means SDL was incorrectly installed" + echo "*** or that you have moved SDL since it was installed. In the latter case, you" + echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ]) + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + SDL_CFLAGS="" + SDL_LIBS="" + ifelse([$3], , :, [$3]) + fi + AC_SUBST(SDL_CFLAGS) + AC_SUBST(SDL_LIBS) + rm -f conf.sdltest +]) diff --git a/ocp-sdl2 b/ocp-sdl2 new file mode 100755 index 00000000..ee80027c --- /dev/null +++ b/ocp-sdl2 @@ -0,0 +1,2 @@ +#!/bin/sh +exec ocp -dsdl2 "$@" diff --git a/stuff/Makefile b/stuff/Makefile index a765834b..54ca3ef6 100644 --- a/stuff/Makefile +++ b/stuff/Makefile @@ -20,6 +20,10 @@ ifeq ($(HAVE_SDL),1) poutput_so+=poutput-sdl.o poutput_so_libs+=$(SDL_LIBS) endif +ifeq ($(HAVE_SDL2),1) +poutput_so+=poutput-sdl2.o +poutput_so_libs+=$(SDL2_LIBS) +endif ifeq ($(STATIC_BUILD),1) all: err.o $(compat_so) $(framelock_so) $(hardware_so) $(sets_so) $(poutput_so) @@ -121,6 +125,16 @@ poutput-sdl.o: poutput-sdl.c poutput-sdl.h \ pfonts.h $(CC) $(SDL_CFLAGS) poutput-sdl.c -o $@ -c +poutput-sdl2.o: poutput-sdl2.c poutput-sdl2.h \ + ../config.h \ + ../types.h \ + ../boot/console.h \ + ../boot/psetting.h \ + ../stuff/framelock.h \ + poutput.h \ + pfonts.h + $(CC) $(SDL2_CFLAGS) poutput-sdl2.c -o $@ -c + poutput-x11.o: poutput-x11.c poutput-x11.h \ ../config.h \ ../types.h \ @@ -170,6 +184,7 @@ console.o: console.c \ poutput-curses.h \ poutput-fb.h \ poutput-sdl.h \ + poutput-sdl2.h \ poutput-x11.h \ poutput-vcsa.h $(CC) console.c -o $@ -c diff --git a/stuff/console.c b/stuff/console.c index 02226f63..d20aa614 100644 --- a/stuff/console.c +++ b/stuff/console.c @@ -47,6 +47,9 @@ #ifdef HAVE_SDL #include "poutput-sdl.h" #endif +#ifdef HAVE_SDL2 +#include "poutput-sdl2.h" +#endif #ifdef HAVE_FRAMEBUFFER #include "poutput-vcsa.h" #endif @@ -164,6 +167,18 @@ static int console_init(void) fprintf(stderr, "SDL driver not compiled in\n"); #endif return -1; + } else if (!strcmp(driver, "sdl2")) + { +#ifdef HAVE_SDL2 + if (!sdl2_init()) + { + console_clean=sdl2_done; + return 0; + } + fprintf(stderr, "SDL2 init failed\n"); +#else + fprintf(stderr, "SDL2 driver not compiled in\n"); +#endif } } } @@ -193,6 +208,14 @@ static int console_init(void) return 0; } #endif +#ifdef HAVE_SDL2 + fprintf(stderr, "stdout and stdin does not come from the same device, trying SDL2\n"); + if (!sdl2_init()) + { + console_clean=sdl2_done; + return 0; + } +#endif #ifdef HAVE_SDL fprintf(stderr, "stdout and stdin does not come from the same device, trying SDL\n"); if (!sdl_init()) @@ -302,6 +325,14 @@ static int console_init(void) } #endif +#ifdef HAVE_SDL2 + if (!sdl2_init()) + { + console_clean=sdl2_done; + return 0; + } +#endif + #ifdef HAVE_SDL if (!sdl_init()) { diff --git a/stuff/poutput-sdl2.c b/stuff/poutput-sdl2.c new file mode 100644 index 00000000..de8f36c4 --- /dev/null +++ b/stuff/poutput-sdl2.c @@ -0,0 +1,1748 @@ +/* OpenCP Module Player + * copyright (c) '94-'10 Niklas Beisert + * + * SDL graphic driver + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define _CONSOLE_DRIVER +#include "config.h" +#include +#include +#include +#include "boot/psetting.h" +#include "types.h" +#include "cpiface/cpiface.h" +#include "poutput-sdl2.h" +#include "boot/console.h" +#include "poutput.h" +#include "pfonts.h" +#include "stuff/framelock.h" + +typedef enum +{ + MODE_320_200 = 0, + MODE_640_400 = 1, + MODE_640_480 = 2, + MODE_1024_768 = 3, + MODE_1280_1024 = 4, + MODE_BIGGEST = 5 +} mode_gui_t; + +typedef struct +{ + const mode_t mode; + int width; + int height; +} mode_gui_data_t; + +static const mode_gui_data_t mode_gui_data[] = +{ + {MODE_320_200, 320, 200}, + {MODE_640_400, 640, 400}, + {MODE_640_480, 640, 480}, + {MODE_1024_768, 1024, 768}, + {MODE_1280_1024, 1280, 1024}, + {-1, -1, -1} +}; + +struct FontSizeInfo_t +{ + int w, h; +}; + +typedef enum { + _4x4 = 0, + _8x8 = 1, + _8x16 = 2, + _FONT_MAX = 2 +} FontSizeEnum; + +const struct FontSizeInfo_t FontSizeInfo[] = +{ + {4, 4}, + {8, 8}, + {8, 16} +}; + +static FontSizeEnum plCurrentFont; +static FontSizeEnum plCurrentFontWanted; + + +typedef struct +{ + int text_width; + int text_height; + mode_gui_t gui_mode; + FontSizeEnum font; +} mode_tui_data_t; + +static const mode_tui_data_t mode_tui_data[] = +{ + { 80, 25, MODE_640_400, _8x16/*, MODE_640x400*/}, + { 80, 30, MODE_640_480, _8x16/*, MODE_640x480*/}, + { 80, 50, MODE_640_400, _8x8/*, MODE_640x400*/}, + { 80, 60, MODE_640_480, _8x8/*, MODE_640x480*/}, + { 128, 48, MODE_1024_768, _8x16/*, MODE_1024x768*/}, + { 160, 64, MODE_1280_1024, _8x16/*, MODE_1280x1024*/}, + { 128, 96, MODE_1024_768, _8x8/*, MODE_1024x768*/}, + { 160, 128, MODE_1280_1024, _8x8/*, MODE_1280x1024*/}, + { -1, -1, -1, -1} +}; + +static SDL_Window *current_window = NULL; +static SDL_Renderer *current_renderer = NULL; +static SDL_Texture *current_texture = NULL; + +static int last_text_height; +static int last_text_width; + +static void (*set_state)(int fullscreen, int width, int height) = 0; +static int do_fullscreen = 0; +static uint8_t *vgatextram = 0; +static int plScrRowBytes = 0; +static int ekbhit(void); +static int ___valid_key(uint16_t key); +static void sdl2_gflushpal(void); +static void sdl2_gupdatepal(unsigned char color, unsigned char _red, unsigned char _green, unsigned char _blue); +static void displayvoid(uint16_t y, uint16_t x, uint16_t len); +static void displaystrattr(uint16_t y, uint16_t x, const uint16_t *buf, uint16_t len); +static void displaystr(uint16_t y, uint16_t x, uint8_t attr, const char *str, uint16_t len); +static void drawbar(uint16_t x, uint16_t yb, uint16_t yh, uint32_t hgt, uint32_t c); +static void idrawbar(uint16_t x, uint16_t yb, uint16_t yh, uint32_t hgt, uint32_t c); +static void setcur(uint8_t y, uint8_t x); +static void setcurshape(uint16_t shape); + +#ifdef PFONT_IDRAWBAR +static uint8_t bartops[18]="\xB5\xB6\xB6\xB7\xB7\xB8\xBD\xBD\xBE\xC6\xC6\xC7\xC7\xCF\xCF\xD7\xD7"; +static uint8_t ibartops[18]="\xB5\xD0\xD0\xD1\xD1\xD2\xD2\xD3\xD3\xD4\xD4\xD5\xD5\xD6\xD6\xD7\xD7"; +#else +static uint8_t bartops[18]="\xB5\xB6\xB7\xB8\xBD\xBE\xC6\xC7\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7"; +#endif +static uint32_t sdl2_palette[256] = { + 0xff000000, + 0xff0000aa, + 0xff00aa00, + 0xff00aaaa, + 0xffaa0000, + 0xffaa00aa, + 0xffaa5500, + 0xffaaaaaa, + 0xff555555, + 0xff5555ff, + 0xff55ff55, + 0xff55ffff, + 0xffff5555, + 0xffff55ff, + 0xffffff55, + 0xffffffff, +}; + + +static unsigned int curshape=0, curposx=0, curposy=0; +static char *virtual_framebuffer = 0; + +static void sdl2_close_window(void) +{ + if (current_texture) + { + SDL_DestroyTexture (current_texture); + current_texture = 0; + } + if (current_renderer) + { + SDL_DestroyRenderer (current_renderer); + current_renderer = 0; + } + if (current_window) + { + SDL_DestroyWindow (current_window); + current_window = 0; + } +} + +static void sdl2_dump_renderer (void) +{ +#ifdef SDL2_DEBUG + SDL_RendererInfo info; + if (!SDL_GetRendererInfo (current_renderer, &info)) + { + int i; + fprintf (stderr, "[SDL2-video] Renderer.name = \"%s\"\n", info.name); + fprintf (stderr, " Renderer.flags = %d%s%s%s%s\n", info.flags, + (info.flags&SDL_RENDERER_SOFTWARE)?" SDL_RENDERER_SOFTWARE":"", + (info.flags&SDL_RENDERER_ACCELERATED)?" SDL_RENDERER_ACCELERATED":"", + (info.flags&SDL_RENDERER_PRESENTVSYNC)?" SDL_RENDERER_PRESENTVSYNC":"", + (info.flags&SDL_RENDERER_TARGETTEXTURE)?" SDL_RENDERER_TARGETTEXTURE":""); + for (i=0; (i<16) && info.texture_formats[i]; i++) + { + int bitmap = 0; + int packed = 0; + int array = 0; + fprintf (stderr, " Renderer.texture_formats[%d] = %d", i, info.texture_formats[i]); + + if (info.texture_formats[i] == SDL_PIXELFORMAT_UNKNOWN) fprintf (stderr, " (SDL_PIXELFORMAT_UNKNOWN)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_INDEX1LSB) fprintf (stderr, " (SDL_PIXELFORMAT_INDEX1LSB)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_INDEX1MSB) fprintf (stderr, " (SDL_PIXELFORMAT_INDEX1MSB)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_INDEX4LSB) fprintf (stderr, " (SDL_PIXELFORMAT_INDEX4LSB)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_INDEX4MSB) fprintf (stderr, " (SDL_PIXELFORMAT_INDEX4MSB)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_INDEX8) fprintf (stderr, " (SDL_PIXELFORMAT_INDEX8)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGB332) fprintf (stderr, " (SDL_PIXELFORMAT_RGB332)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGB444) fprintf (stderr, " (SDL_PIXELFORMAT_RGB444)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGB555) fprintf (stderr, " (SDL_PIXELFORMAT_RGB555)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGR555) fprintf (stderr, " (SDL_PIXELFORMAT_BGR555)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ARGB4444) fprintf (stderr, " (SDL_PIXELFORMAT_ARGB4444)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGBA4444) fprintf (stderr, " (SDL_PIXELFORMAT_RGBA4444)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ABGR4444) fprintf (stderr, " (SDL_PIXELFORMAT_ABGR4444)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGRA4444) fprintf (stderr, " (SDL_PIXELFORMAT_BGRA4444)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ARGB1555) fprintf (stderr, " (SDL_PIXELFORMAT_ARGB1555)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGBA5551) fprintf (stderr, " (SDL_PIXELFORMAT_RGBA5551)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ABGR1555) fprintf (stderr, " (SDL_PIXELFORMAT_ABGR1555)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGRA5551) fprintf (stderr, " (SDL_PIXELFORMAT_BGRA5551)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGB565) fprintf (stderr, " (SDL_PIXELFORMAT_RGB565)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGR565) fprintf (stderr, " (SDL_PIXELFORMAT_BGR565)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGB24) fprintf (stderr, " (SDL_PIXELFORMAT_RGB24)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGR24) fprintf (stderr, " (SDL_PIXELFORMAT_BGR24)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGB888) fprintf (stderr, " (SDL_PIXELFORMAT_RGB888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGBX8888) fprintf (stderr, " (SDL_PIXELFORMAT_RGBX8888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGR888) fprintf (stderr, " (SDL_PIXELFORMAT_BGR888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGRX8888) fprintf (stderr, " (SDL_PIXELFORMAT_BGRX8888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ARGB8888) fprintf (stderr, " (SDL_PIXELFORMAT_ARGB8888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGBA8888) fprintf (stderr, " (SDL_PIXELFORMAT_RGBA8888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ABGR8888) fprintf (stderr, " (SDL_PIXELFORMAT_ABGR8888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGRA8888) fprintf (stderr, " (SDL_PIXELFORMAT_BGRA8888)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ARGB2101010) fprintf (stderr, " (SDL_PIXELFORMAT_ARGB2101010)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_RGBA32) fprintf (stderr, " ((SDL_PIXELFORMAT_RGBA32))"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ARGB32) fprintf (stderr, " ((SDL_PIXELFORMAT_ARGB32))"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_BGRA32) fprintf (stderr, " ((SDL_PIXELFORMAT_BGRA32))"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_ABGR32) fprintf (stderr, " ((SDL_PIXELFORMAT_ABGR32))"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_YV12) fprintf (stderr, " (SDL_PIXELFORMAT_YV12)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_IYUV) fprintf (stderr, " (SDL_PIXELFORMAT_IYUV)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_YUY2) fprintf (stderr, " (SDL_PIXELFORMAT_YUY2)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_UYVY) fprintf (stderr, " (SDL_PIXELFORMAT_UYVY)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_YVYU) fprintf (stderr, " (SDL_PIXELFORMAT_YVYU)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_NV12) fprintf (stderr, " (SDL_PIXELFORMAT_NV12)"); + if (info.texture_formats[i] == SDL_PIXELFORMAT_NV21) fprintf (stderr, " (SDL_PIXELFORMAT_NV21)"); + + switch (SDL_PIXELTYPE (info.texture_formats[i])) + { + default: + case SDL_PIXELTYPE_UNKNOWN: fprintf (stderr, " SDL_PIXELTYPE_UNKNOWN"); break; + case SDL_PIXELTYPE_INDEX1: fprintf (stderr, " SDL_PIXELTYPE_INDEX1"); bitmap = 1; break; + case SDL_PIXELTYPE_INDEX4: fprintf (stderr, " SDL_PIXELTYPE_INDEX4"); bitmap = 1; break; + case SDL_PIXELTYPE_INDEX8: fprintf (stderr, " SDL_PIXELTYPE_INDEX8"); bitmap = 1; break; + case SDL_PIXELTYPE_PACKED8: fprintf (stderr, " SDL_PIXELTYPE_PACKED8"); packed = 1; break; + case SDL_PIXELTYPE_PACKED16: fprintf (stderr, " SDL_PIXELTYPE_PACKED16"); packed = 1; break; + case SDL_PIXELTYPE_PACKED32: fprintf (stderr, " SDL_PIXELTYPE_PACKED32"); packed = 1; break; + case SDL_PIXELTYPE_ARRAYU8: fprintf (stderr, " SDL_PIXELTYPE_ARRAYU8"); array = 1; break; + case SDL_PIXELTYPE_ARRAYU16: fprintf (stderr, " SDL_PIXELTYPE_ARRAYU16"); array = 1; break; + case SDL_PIXELTYPE_ARRAYF16: fprintf (stderr, " SDL_PIXELTYPE_ARRAYF16"); array = 1; break; + case SDL_PIXELTYPE_ARRAYF32: fprintf (stderr, " SDL_PIXELTYPE_ARRAYF32"); array = 1; break; + } + if (bitmap) + { + switch (SDL_PIXELORDER (info.texture_formats[i])) + { + default: + case SDL_BITMAPORDER_NONE: fprintf (stderr, " SDL_BITMAPORDER_NONE"); break; + case SDL_BITMAPORDER_4321: fprintf (stderr, " SDL_BITMAPORDER_4321"); break; + case SDL_BITMAPORDER_1234: fprintf (stderr, " SDL_BITMAPORDER_1234"); break; + } + } + if (packed) + { + switch (SDL_PIXELORDER (info.texture_formats[i])) + { + default: + case SDL_PACKEDORDER_NONE: fprintf (stderr, " SDL_PACKEDORDER_NONE"); break; + case SDL_PACKEDORDER_XRGB: fprintf (stderr, " SDL_PACKEDORDER_XRGB"); break; + case SDL_PACKEDORDER_RGBX: fprintf (stderr, " SDL_PACKEDORDER_RGBX"); break; + case SDL_PACKEDORDER_ARGB: fprintf (stderr, " SDL_PACKEDORDER_ARGB"); break; + case SDL_PACKEDORDER_RGBA: fprintf (stderr, " SDL_PACKEDORDER_RGBA"); break; + case SDL_PACKEDORDER_XBGR: fprintf (stderr, " SDL_PACKEDORDER_XBGR"); break; + case SDL_PACKEDORDER_BGRX: fprintf (stderr, " SDL_PACKEDORDER_BGRX"); break; + case SDL_PACKEDORDER_ABGR: fprintf (stderr, " SDL_PACKEDORDER_ABGR"); break; + case SDL_PACKEDORDER_BGRA: fprintf (stderr, " SDL_PACKEDORDER_BGRA"); break; + } + switch (SDL_PIXELLAYOUT (info.texture_formats[i])) + { + default: + case SDL_PACKEDLAYOUT_NONE: fprintf (stderr, " SDL_PACKEDLAYOUT_NONE"); break; + case SDL_PACKEDLAYOUT_332: fprintf (stderr, " SDL_PACKEDLAYOUT_332"); break; + case SDL_PACKEDLAYOUT_4444: fprintf (stderr, " SDL_PACKEDLAYOUT_4444"); break; + case SDL_PACKEDLAYOUT_1555: fprintf (stderr, " SDL_PACKEDLAYOUT_1555"); break; + case SDL_PACKEDLAYOUT_5551: fprintf (stderr, " SDL_PACKEDLAYOUT_5551"); break; + case SDL_PACKEDLAYOUT_565: fprintf (stderr, " SDL_PACKEDLAYOUT_565"); break; + case SDL_PACKEDLAYOUT_8888: fprintf (stderr, " SDL_PACKEDLAYOUT_8888"); break; + case SDL_PACKEDLAYOUT_2101010: fprintf (stderr, " SDL_PACKEDLAYOUT_2101010"); break; + case SDL_PACKEDLAYOUT_1010102: fprintf (stderr, " SDL_PACKEDLAYOUT_1010102"); break; + } + } + if (array) + { + switch (SDL_PIXELORDER (info.texture_formats[i])) + { + default: + case SDL_ARRAYORDER_NONE: fprintf (stderr, " SDL_ARRAYORDER_NONE"); break; + case SDL_ARRAYORDER_RGB: fprintf (stderr, " SDL_ARRAYORDER_RGB"); break; + case SDL_ARRAYORDER_RGBA: fprintf (stderr, " SDL_ARRAYORDER_RGBA"); break; + case SDL_ARRAYORDER_ARGB: fprintf (stderr, " SDL_ARRAYORDER_ARGB"); break; + case SDL_ARRAYORDER_BGR: fprintf (stderr, " SDL_ARRAYORDER_BGR"); break; + case SDL_ARRAYORDER_BGRA: fprintf (stderr, " SDL_ARRAYORDER_BGRA"); break; + case SDL_ARRAYORDER_ABGR: fprintf (stderr, " SDL_ARRAYORDER_ABGR"); break; + } + } + fprintf (stderr, " bits_per_pixel=%d", SDL_BITSPERPIXEL (info.texture_formats[i])); + fprintf (stderr, " bytes_per_pixel=%d\n", SDL_BYTESPERPIXEL (info.texture_formats[i])); + } + } +#endif +} + +static void set_state_textmode(int fullscreen, int width, int height) +{ + /* texture WILL for sure resize, so just get rid of it! */ + if (current_texture) + { + SDL_DestroyTexture (current_texture); + current_texture = 0; + } + + /* vgatextram WILL for sure resize, so just get tid of it! */ + if (vgatextram) + { + free(vgatextram); + vgatextram=0; + } + + if (fullscreen != do_fullscreen) + { + if (fullscreen) + { + last_text_width = plScrLineBytes; + last_text_height = plScrLines; + } else { + width = last_text_width; + height = last_text_height; + } + } + + if ((fullscreen != do_fullscreen) || (!current_window)) + { + sdl2_close_window(); + + do_fullscreen = fullscreen; + + if (fullscreen) + { + current_window = SDL_CreateWindow ("Open Cubic Player", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 0, 0, + SDL_WINDOW_FULLSCREEN_DESKTOP); + if (current_window) + { + SDL_GetWindowSize (current_window, &width, &height); + } + } else { + if (!width) + { +#ifdef SDL2_DEBUG + fprintf (stderr, "[SDL2-video] set_state_textmode() width==0 ???\n"); +#endif + width = 640; + } + if (!height) + { +#ifdef SDL2_DEBUG + fprintf (stderr, "[SDL2-video] set_state_textmode() height==0 ???\n"); +#endif + height = 480; + } + current_window = SDL_CreateWindow ("Open Cubic Player", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + width, height, + SDL_WINDOW_RESIZABLE); + } + + if (!current_window) + { + fprintf (stderr, "[SDL2-video]: SDL_CreateWindow: %s (fullscreen=%d %dx%d)\n", SDL_GetError(), fullscreen, width, height); + SDL_ClearError(); + } + } + + while ( ((width/FontSizeInfo[plCurrentFont].w) < 80) || ((height/FontSizeInfo[plCurrentFont].h) < 25)) + { +#ifdef SDL2_DEBUG + fprintf (stderr, "[SDL2-video] find a smaller font, since (%d/%d)=%d < 80 or (%d/%d)=%d < 25\n", + width, FontSizeInfo[plCurrentFont].w, width/FontSizeInfo[plCurrentFont].w, + height, FontSizeInfo[plCurrentFont].h, width/FontSizeInfo[plCurrentFont].h); +#endif + if (plCurrentFont) + plCurrentFont--; + else { + if (!fullscreen) + { + fprintf(stderr, "[SDL2-video] unable to find a small enough font for %d x %d, increasing window size\n", width, height); + width = FontSizeInfo[plCurrentFont].w * 80; + height = FontSizeInfo[plCurrentFont].h * 25; + SDL_SetWindowSize (current_window, width, height); + } else { + fprintf(stderr, "[SDL2-video] unable to find a small enough font for %d x %d\n", width, height); + exit(-1); + } + } + } + + plScrWidth = width/FontSizeInfo[plCurrentFont].w; + plScrHeight = height/FontSizeInfo[plCurrentFont].h; + plScrLineBytes = width; + plScrLines = height; + + plScrRowBytes = plScrWidth*2; + + if (!current_renderer) + { + current_renderer = SDL_CreateRenderer (current_window, -1, 0); + + if (!current_renderer) + { + fprintf (stderr, "[SD2-video]: SDL_CreateRenderer: %s\n", SDL_GetError()); + SDL_ClearError(); + exit(-1); + } else { + sdl2_dump_renderer(); + } + } + + if (!current_texture) + { + current_texture = SDL_CreateTexture (current_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); + if (!current_texture) + { + fprintf (stderr, "[SDL2-video]: SDL_CreateTexture: %s\n", SDL_GetError()); + SDL_ClearError(); + current_texture = SDL_CreateTexture (current_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height); + if (!current_texture) + { + fprintf (stderr, "[SDL2-video]: SDL_CreateTexture: %s\n", SDL_GetError()); + SDL_ClearError(); + exit(-1); + } + } + } + + vgatextram = calloc (plScrHeight * 2, plScrWidth); + if (!vgatextram) + { + fprintf(stderr, "[SDL2-video] calloc() failed\n"); + exit(-1); + } + + sdl2_gflushpal(); + + ___push_key(VIRT_KEY_RESIZE); +} + +static void plSetTextMode(unsigned char x) +{ + set_state = set_state_textmode; + + ___setup_key(ekbhit, ekbhit); + _validkey=___valid_key; + + if ((x==plScrMode) && (current_window)) + { + memset(vgatextram, 0, plScrHeight * 2 * plScrWidth); + return; + } + + _plSetGraphMode(-1); /* closes the window, so gdb helper below will have a clear screen */ + + if (x==255) + { + plScrMode=255; + return; /* gdb helper */ + } + + /* if invalid mode, set it to custom */ + if (x>7) + { + x=8; + + set_state_textmode( + do_fullscreen, + last_text_width, + last_text_height); + } else { + plCurrentFont = mode_tui_data[x].font; + + set_state_textmode( + do_fullscreen, + mode_gui_data[mode_tui_data[x].gui_mode].width, + mode_gui_data[mode_tui_data[x].gui_mode].height); + } + + plScrType = plScrMode = x; +} + +static int cachemode = -1; + +static void set_state_graphmode(int fullscreen, int width, int height) +{ + mode_gui_t mode; + + /* texture WILL for sure resize, so just get rid of it! */ + if (current_texture) + { + SDL_DestroyTexture (current_texture); + current_texture = 0; + } + + /* vgatextram WILL for sure resize, so just get tid of it! */ + if (vgatextram) + { + free(vgatextram); + vgatextram=0; + } + + switch (cachemode) + { + case 13: + plScrMode=13; + mode = MODE_320_200; + break; + case 0: + plScrMode=100; + mode = MODE_640_480; + break; + case 1: + plScrMode=101; + mode = MODE_1024_768; + break; + default: + fprintf(stderr, "[SDL2-video] plSetGraphMode helper: invalid graphmode\n"); + exit(-1); + } + width = mode_gui_data[mode].width; + height = mode_gui_data[mode].height; + + if ((fullscreen != do_fullscreen) || (!current_window)) + { + sdl2_close_window(); + + do_fullscreen = fullscreen; + + if (fullscreen) + { + current_window = SDL_CreateWindow ("Open Cubic Player", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 0, 0, + SDL_WINDOW_FULLSCREEN_DESKTOP); + } else { + current_window = SDL_CreateWindow ("Open Cubic Player", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + width, height, + 0); + } + } + + if (!current_renderer) + { + current_renderer = SDL_CreateRenderer (current_window, -1, 0); + + if (!current_renderer) + { + fprintf (stderr, "[SD2-video]: SDL_CreateRenderer: %s\n", SDL_GetError()); + SDL_ClearError(); + exit(-1); + } else { + sdl2_dump_renderer(); + } + } + + if (!current_texture) + { + current_texture = SDL_CreateTexture (current_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); + if (!current_texture) + { + fprintf (stderr, "[SDL2-video]: SDL_CreateTexture: %s\n", SDL_GetError()); + SDL_ClearError(); + current_texture = SDL_CreateTexture (current_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height); + if (!current_texture) + { + fprintf (stderr, "[SDL2-video]: SDL_CreateTexture: %s\n", SDL_GetError()); + SDL_ClearError(); + exit(-1); + } + } + } + + plScrLineBytes=width; + plScrLines=height; + plScrWidth=plScrLineBytes/8; + plScrHeight=plScrLines/16; + + plScrRowBytes=plScrWidth*2; + + vgatextram = calloc (plScrHeight * 2, plScrWidth); + if (!vgatextram) + { + fprintf(stderr, "[SDL2-video] calloc() failed\n"); + exit(-1); + } + + sdl2_gflushpal(); + + ___push_key(VIRT_KEY_RESIZE); + return; +} + +static int __plSetGraphMode(int high) +{ + if (high>=0) + set_state = set_state_graphmode; + + if ((high==cachemode)&&(high>=0)) + goto quick; + cachemode=high; + + if (virtual_framebuffer) + { + free (virtual_framebuffer); + plVidMem=virtual_framebuffer=0; + } + sdl2_close_window(); + + if (high<0) + { + return 0; + } + + ___setup_key(ekbhit, ekbhit); + _validkey=___valid_key; + + set_state_graphmode(do_fullscreen, 0, 0); + + virtual_framebuffer=malloc(plScrLineBytes * plScrLines); + plVidMem=virtual_framebuffer; + +quick: + if (virtual_framebuffer) + memset(virtual_framebuffer, 0, plScrLineBytes * plScrLines); + + sdl2_gflushpal(); + return 0; +} + +static void __vga13(void) +{ + _plSetGraphMode(13); +} + +static int conRestore(void) +{ + return 0; +} +static void conSave(void) +{ +} + +static void plDisplaySetupTextMode(void) +{ + while (1) + { + uint16_t c; + + memset(vgatextram, 0, plScrHeight * 2 * plScrWidth); + + make_title("sdl2-driver setup"); + displaystr(1, 0, 0x07, "1: font-size:", 14); + displaystr(1, 15, plCurrentFont == _4x4 ? 0x0f : 0x07, "4x4", 3); + displaystr(1, 19, plCurrentFont == _8x8 ? 0x0f : 0x07, "8x8", 3); + displaystr(1, 23, plCurrentFont == _8x16 ? 0x0f : 0x07, "8x16", 4); +/* + displaystr(2, 0, 0x07, "2: fullscreen: ", 16); + displaystr(3, 0, 0x07, "3: resolution in fullscreen:", 29);*/ + + displaystr(plScrHeight-1, 0, 0x17, " press the number of the item you wish to change and ESC when done", plScrWidth); + + while (!_ekbhit()) + framelock(); + c=_egetch(); + + switch (c) + { + case '1': + /* we can assume that we are in text-mode if we are here */ + plCurrentFontWanted = plCurrentFont = (plCurrentFont+1)%3; + set_state_textmode(do_fullscreen, plScrLineBytes, plScrLines); + cfSetProfileInt("x11", "font", plCurrentFont, 10); + break; + case 27: return; + } + } +} + +static const char *plGetDisplayTextModeName(void) +{ + static char mode[48]; + snprintf(mode, sizeof(mode), "res(%dx%d), font(%s)%s", plScrWidth, plScrHeight, + plCurrentFont == _4x4 ? "4x4" + : plCurrentFont == _8x8 ? "8x8" : "8x16", do_fullscreen?" fullscreen":""); + return mode; +} + +static int need_quit = 0; + +int sdl2_init(void) +{ + if ( SDL_Init(/*SDL_INIT_AUDIO|*/SDL_INIT_VIDEO) < 0 ) + { + fprintf(stderr, "[SDL2 video] Unable to init SDL: %s\n", SDL_GetError()); + SDL_ClearError(); + return 1; + } + + /* we now test-spawn one window, and so we can fallback to other drivers */ + + current_window = SDL_CreateWindow ("Open Cubic Player detection", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 320, 200, + 0); + + if (!current_window) + { + fprintf(stderr, "[SDL2 video] Unable to create window: %s\n", SDL_GetError()); + SDL_ClearError (); + SDL_Quit(); + return 1; + } + + current_renderer = SDL_CreateRenderer (current_window, -1, 0); + if (!current_renderer) + { + fprintf (stderr, "[SD2-video]: Unable to create renderer: %s\n", SDL_GetError()); + SDL_ClearError (); + sdl2_close_window (); + SDL_Quit(); + return -1; + } + + current_texture = SDL_CreateTexture (current_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 200); + if (!current_texture) + { + fprintf (stderr, "[SDL2-video]: Unable to create texture (will do one more attempt): %s\n", SDL_GetError()); + SDL_ClearError(); + current_texture = SDL_CreateTexture (current_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, 320, 200); + if (!current_texture) + { + fprintf (stderr, "[SDL2-video]: Unable to create texture: %s\n", SDL_GetError()); + SDL_ClearError(); + sdl2_close_window (); + SDL_Quit(); + return -1; + } + } + + sdl2_close_window (); + + SDL_EventState (SDL_WINDOWEVENT, SDL_ENABLE); + SDL_EventState (SDL_MOUSEBUTTONDOWN, SDL_ENABLE); + SDL_EventState (SDL_KEYDOWN, SDL_ENABLE); + + /* Fill some default font and window sizes */ + plCurrentFontWanted = plCurrentFont = cfGetProfileInt("x11", "font", _8x16, 10); + if (plCurrentFont > _FONT_MAX) + { + plCurrentFont = _8x16; + } + last_text_width = plScrLineBytes = 640; + last_text_height = plScrLines = 480; + plScrType = plScrMode = 8; + + need_quit = 1; + + _plSetTextMode=plSetTextMode; + _plSetGraphMode=__plSetGraphMode; + _gdrawstr=generic_gdrawstr; + _gdrawchar8=generic_gdrawchar8; + _gdrawchar8p=generic_gdrawchar8p; + _gdrawchar8t=generic_gdrawchar8t; + _gdrawcharp=generic_gdrawcharp; + _gdrawchar=generic_gdrawchar; + _gupdatestr=generic_gupdatestr; + _gupdatepal=sdl2_gupdatepal; + _gflushpal=sdl2_gflushpal; + _vga13=__vga13; + + _displayvoid=displayvoid; + _displaystrattr=displaystrattr; + _displaystr=displaystr; + _drawbar=drawbar; +#ifdef PFONT_IDRAWBAR + _idrawbar=idrawbar; +#else + _idrawbar=drawbar; +#endif + _setcur=setcur; + _setcurshape=setcurshape; + _conRestore=conRestore; + _conSave=conSave; + + _plGetDisplayTextModeName = plGetDisplayTextModeName; + _plDisplaySetupTextMode = plDisplaySetupTextMode; + + plVidType=vidModern; + + return 0; +} + +void sdl2_done(void) +{ + sdl2_close_window (); + + if (!need_quit) + return; + + SDL_Quit(); + + if (vgatextram) + { + free(vgatextram); + vgatextram=0; + } + + need_quit = 0; +} + +struct keytranslate_t +{ + SDL_Keycode SDL; + uint16_t OCP; +}; + +struct keytranslate_t translate[] = +{ + {SDLK_BACKSPACE, KEY_BACKSPACE}, + {SDLK_TAB, KEY_TAB}, + {SDLK_DELETE, KEY_DELETE}, /* ??? */ + {SDLK_RETURN, _KEY_ENTER}, + {SDLK_RETURN2, _KEY_ENTER}, + /*SDLK_PAUSE*/ + {SDLK_ESCAPE, KEY_ESC}, + {SDLK_SPACE, ' '}, + {SDLK_EXCLAIM, '!'}, + {SDLK_QUOTEDBL, '\"'}, + {SDLK_HASH, '#'}, + {SDLK_DOLLAR, '$'}, + {SDLK_AMPERSAND, '&'}, + {SDLK_QUOTE, '\''}, + {SDLK_LEFTPAREN, '('}, + {SDLK_RIGHTPAREN, ')'}, + {SDLK_ASTERISK, '*'}, + {SDLK_PLUS, '+'}, + {SDLK_COMMA, ','}, + {SDLK_MINUS, '-'}, + {SDLK_PERIOD, '.'}, + {SDLK_SLASH, '/'}, + {SDLK_0, '0'}, + {SDLK_1, '1'}, + {SDLK_2, '2'}, + {SDLK_3, '3'}, + {SDLK_4, '4'}, + {SDLK_5, '5'}, + {SDLK_6, '6'}, + {SDLK_7, '7'}, + {SDLK_8, '8'}, + {SDLK_9, '9'}, + {SDLK_COLON, ':'}, + {SDLK_SEMICOLON, ';'}, + {SDLK_LESS, '<'}, + {SDLK_EQUALS, '='}, + {SDLK_GREATER, '>'}, + {SDLK_QUESTION, '?'}, + {SDLK_AT, '@'}, + {65, 'A'}, + {66, 'B'}, + {67, 'C'}, + {68, 'D'}, + {69, 'E'}, + {70, 'F'}, + {71, 'G'}, + {72, 'H'}, + {73, 'I'}, + {74, 'J'}, + {75, 'K'}, + {76, 'L'}, + {77, 'M'}, + {78, 'N'}, + {79, 'O'}, + {80, 'P'}, + {81, 'Q'}, + {82, 'R'}, + {83, 'S'}, + {84, 'T'}, + {85, 'U'}, + {86, 'V'}, + {87, 'W'}, + {88, 'X'}, + {89, 'Y'}, + {90, 'Z'}, + {SDLK_LEFTBRACKET, '['}, + {SDLK_BACKSLASH, '\\'}, + {SDLK_RIGHTBRACKET, ']'}, + {SDLK_CARET, '^'}, + {SDLK_UNDERSCORE, '_'}, + {SDLK_BACKQUOTE, '`'}, + {SDLK_a, 'a'}, + {SDLK_b, 'b'}, + {SDLK_c, 'c'}, + {SDLK_d, 'd'}, + {SDLK_e, 'e'}, + {SDLK_f, 'f'}, + {SDLK_g, 'g'}, + {SDLK_h, 'h'}, + {SDLK_i, 'i'}, + {SDLK_j, 'j'}, + {SDLK_k, 'k'}, + {SDLK_l, 'l'}, + {SDLK_m, 'm'}, + {SDLK_n, 'n'}, + {SDLK_o, 'o'}, + {SDLK_p, 'p'}, + {SDLK_q, 'q'}, + {SDLK_r, 'r'}, + {SDLK_s, 's'}, + {SDLK_t, 't'}, + {SDLK_u, 'u'}, + {SDLK_v, 'v'}, + {SDLK_w, 'w'}, + {SDLK_x, 'x'}, + {SDLK_y, 'y'}, + {SDLK_z, 'z'}, + {SDLK_KP_0, '0'}, + {SDLK_KP_1, '1'}, + {SDLK_KP_2, '2'}, + {SDLK_KP_3, '3'}, + {SDLK_KP_4, '4'}, + {SDLK_KP_5, '5'}, + {SDLK_KP_6, '6'}, + {SDLK_KP_7, '7'}, + {SDLK_KP_8, '8'}, + {SDLK_KP_9, '9'}, + {SDLK_KP_PERIOD, ','}, + {SDLK_KP_DIVIDE, '/'}, + {SDLK_KP_MULTIPLY, '*'}, + {SDLK_KP_MINUS, '-'}, + {SDLK_KP_PLUS, '+'}, + {SDLK_KP_ENTER, _KEY_ENTER}, + {SDLK_KP_EQUALS, '='}, + {SDLK_UP, KEY_UP}, + {SDLK_DOWN, KEY_DOWN}, + {SDLK_RIGHT, KEY_RIGHT}, + {SDLK_LEFT, KEY_LEFT}, + {SDLK_INSERT, KEY_INSERT}, + {SDLK_HOME, KEY_HOME}, + {SDLK_END, KEY_END}, + {SDLK_PAGEUP, KEY_PPAGE}, + {SDLK_PAGEDOWN, KEY_NPAGE}, + {SDLK_F1, KEY_F(1)}, + {SDLK_F2, KEY_F(2)}, + {SDLK_F3, KEY_F(3)}, + {SDLK_F4, KEY_F(4)}, + {SDLK_F5, KEY_F(5)}, + {SDLK_F6, KEY_F(6)}, + {SDLK_F7, KEY_F(7)}, + {SDLK_F8, KEY_F(8)}, + {SDLK_F9, KEY_F(9)}, + {SDLK_F10, KEY_F(10)}, + {SDLK_F11, KEY_F(11)}, + {SDLK_F12, KEY_F(12)}, + /*SDLK_F13*/ + /*SDLK_F14*/ + /*SDLK_F15*/ + {-1, 0xffff}, +}; + +struct keytranslate_t translate_shift[] = +{ + {SDLK_TAB, KEY_SHIFT_TAB}, + {SDLK_a, 'A'}, + {SDLK_b, 'B'}, + {SDLK_c, 'C'}, + {SDLK_d, 'D'}, + {SDLK_e, 'E'}, + {SDLK_f, 'F'}, + {SDLK_g, 'G'}, + {SDLK_h, 'H'}, + {SDLK_i, 'I'}, + {SDLK_j, 'J'}, + {SDLK_k, 'K'}, + {SDLK_l, 'L'}, + {SDLK_m, 'M'}, + {SDLK_n, 'N'}, + {SDLK_o, 'O'}, + {SDLK_p, 'P'}, + {SDLK_q, 'Q'}, + {SDLK_r, 'R'}, + {SDLK_s, 'S'}, + {SDLK_t, 'T'}, + {SDLK_u, 'U'}, + {SDLK_v, 'V'}, + {SDLK_w, 'W'}, + {SDLK_x, 'X'}, + {SDLK_y, 'Y'}, + {SDLK_z, 'Z'}, + {-1, 0xffff}, +}; + +struct keytranslate_t translate_ctrl[] = +{ + {SDLK_BACKSPACE, KEY_CTRL_BS}, + {SDLK_RETURN, KEY_CTRL_ENTER}, + /*{65, 'A'}, + {66, 'B'}, + {67, 'C'},*/ + {68, KEY_CTRL_D}, + /*{69, 'E'}, + {70, 'F'}, + {71, 'G'},*/ + {72, KEY_CTRL_H}, + /*{73, 'I'},*/ + {74, KEY_CTRL_J}, + {75, KEY_CTRL_K}, + {76, KEY_CTRL_L}, + /*{77, 'M'}, + {78, 'N'}, + {79, 'O'},*/ + {80, KEY_CTRL_P}, + {81, KEY_CTRL_Q}, + /*{82, 'R'},*/ + {83, KEY_CTRL_S}, + /*{84, 'T'}, + {85, 'U'}, + {86, 'V'}, + {87, 'W'}, + {88, 'X'}, + {89, 'Y'},*/ + {90, KEY_CTRL_Z}, + /*{SDLK_a, 'a'}, + {SDLK_b, 'b'}, + {SDLK_c, 'c'},*/ + {SDLK_d, KEY_CTRL_D}, + /*{SDLK_e, 'e'}, + {SDLK_f, 'f'}, + {SDLK_g, 'g'},*/ + {SDLK_h, KEY_CTRL_H}, + /*{SDLK_i, 'i'},*/ + {SDLK_j, KEY_CTRL_J}, + {SDLK_k, KEY_CTRL_K}, + {SDLK_l, KEY_CTRL_L}, + /*{SDLK_m, 'm'}, + {SDLK_n, 'n'}, + {SDLK_o, 'o'},*/ + {SDLK_p, KEY_CTRL_P}, + {SDLK_q, KEY_CTRL_Q}, + /*{SDLK_r, 'r'},*/ + {SDLK_s, KEY_CTRL_S}, + /*{SDLK_t, 't'}, + {SDLK_u, 'u'}, + {SDLK_v, 'v'}, + {SDLK_w, 'w'}, + {SDLK_x, 'x'}, + {SDLK_y, 'y'},*/ + {SDLK_z, KEY_CTRL_Z}, + {SDLK_KP_ENTER, KEY_CTRL_ENTER}, + {SDLK_UP, KEY_CTRL_UP}, + {SDLK_DOWN, KEY_CTRL_DOWN}, + {SDLK_RIGHT, KEY_CTRL_RIGHT}, + {SDLK_LEFT, KEY_CTRL_LEFT}, + {SDLK_PAGEUP, KEY_CTRL_PGUP}, + {SDLK_PAGEDOWN, KEY_CTRL_PGDN}, + {-1, 0xffff}, +}; + +struct keytranslate_t translate_alt[] = +{ + {65, KEY_ALT_A}, + {66, KEY_ALT_B}, + {67, KEY_ALT_C}, + /*{68, 'D'},*/ + {69, KEY_ALT_E}, + /*{70, 'F'},*/ + {71, KEY_ALT_G}, + /*{72, 'H'},*/ + {73, KEY_ALT_I}, + /*{74, 'J'},*/ + {75, KEY_ALT_K}, + {76, KEY_ALT_L}, + {77, KEY_ALT_M}, + /*{78, 'N'},*/ + {79, KEY_ALT_O}, + {80, KEY_ALT_P}, + /*{81, 'Q'},*/ + {82, KEY_ALT_R}, + {83, KEY_ALT_S}, + /*{84, 'T'}, + {85, 'U'}, + {86, 'V'}, + {87, 'W'},*/ + {88, KEY_ALT_X}, + /*{89, 'Y'},*/ + {90, KEY_ALT_Z}, + {SDLK_a, KEY_ALT_A}, + {SDLK_b, KEY_ALT_B}, + {SDLK_c, KEY_ALT_C}, + /*{SDLK_d, 'd'},*/ + {SDLK_e, KEY_ALT_E}, + /*{SDLK_f, 'f'},*/ + {SDLK_g, KEY_ALT_G}, + /*{SDLK_h, 'h'},*/ + {SDLK_i, KEY_ALT_I}, + /*{SDLK_j, 'j'},*/ + {SDLK_k, KEY_ALT_K}, + {SDLK_l, KEY_ALT_L}, + {SDLK_m, KEY_ALT_M}, + /*{SDLK_n, 'n'},*/ + {SDLK_o, KEY_ALT_O}, + {SDLK_p, KEY_ALT_P}, + /*{SDLK_q, 'q'},*/ + {SDLK_r, KEY_ALT_R}, + {SDLK_s, KEY_ALT_S}, + /*{SDLK_t, 't'}, + {SDLK_u, 'u'}, + {SDLK_v, 'v'}, + {SDLK_w, 'w'},*/ + {SDLK_x, KEY_ALT_X}, + /*{SDLK_y, 'y'},*/ + {SDLK_z, KEY_ALT_Z}, + {-1, 0xffff}, +}; + +static int ___valid_key(uint16_t key) +{ + int index; + + if (key==KEY_ALT_ENTER) + return 0; + + for (index=0;translate[index].OCP!=0xffff;index++) + if (translate[index].OCP==key) + return 1; + for (index=0;translate_shift[index].OCP!=0xffff;index++) + if (translate_shift[index].OCP==key) + return 1; + for (index=0;translate_ctrl[index].OCP!=0xffff;index++) + if (translate_ctrl[index].OCP==key) + return 1; + for (index=0;translate_alt[index].OCP!=0xffff;index++) + if (translate_alt[index].OCP==key) + return 1; + + fprintf(stderr, __FILE__ ": unknown key 0x%04x\n", (int)key); + return 0; +} + +static void RefreshScreenText(void) +{ + unsigned int x, y; + uint8_t *mem=vgatextram; + int doshape=0; + uint8_t save=save; + int precalc_linelength; + + void *pixels; + int pitch; + + if (!current_texture) + return; + + if (curshape) + if (time(NULL)&1) + doshape=curshape; + + if (doshape==2) + { + save=vgatextram[curposy*plScrRowBytes+curposx*2]; + vgatextram[curposy*plScrRowBytes+curposx*2]=219; + } + + SDL_LockTexture (current_texture, NULL, &pixels, &pitch); + +#define BLOCK8x16(BASETYPE) \ + precalc_linelength = /*current_surface->*/pitch/sizeof(BASETYPE); \ + for (y=0;y*/pixels)+y*16*precalc_linelength; \ + for (x=0;x>4]; \ + for (i=0; i<16; i++) \ + { \ + uint8_t bitmap=*cp++; \ + for (j=0; j<8; j++) \ + { \ + *scr++=(bitmap&128)?f:b; \ + bitmap<<=1; \ + } \ + scr+=precalc_linelength-8; \ + } \ + if ((doshape==1)&&(curposy==y)&&(curposx==x)) \ + { \ + cp=plFont816['_']+15; \ + scr+=8; \ + for (i=0; i<16; i++) \ + { \ + uint8_t bitmap=*cp--; \ + scr-=precalc_linelength+8; \ + for (j=0; j<8; j++) \ + { \ + if (bitmap&1) \ + *scr=f; \ + bitmap>>=1; \ + scr++; \ + } \ + } \ + } \ + } \ + } + +#define BLOCK8x8(BASETYPE) \ + precalc_linelength = /*current_surface->*/pitch/sizeof(BASETYPE); \ + for (y=0;y*/pixels)+y*8*precalc_linelength; \ + for (x=0;x>4]; \ + for (i=0; i<8; i++) \ + { \ + uint8_t bitmap=*cp++; \ + for (j=0; j<8; j++) \ + { \ + *scr++=(bitmap&128)?f:b; \ + bitmap<<=1; \ + } \ + scr+=precalc_linelength-8; \ + } \ + if ((doshape==1)&&(curposy==y)&&(curposx==x)) \ + { \ + cp=plFont88['_']+7; \ + scr+=8; \ + for (i=0; i<8; i++) \ + { \ + uint8_t bitmap=*cp--; \ + scr-=precalc_linelength+8; \ + for (j=0; j<8; j++) \ + { \ + if (bitmap&1) \ + *scr=f; \ + bitmap>>=1; \ + scr++; \ + } \ + } \ + } \ + }\ + } + +#define BLOCK4x4(BASETYPE) \ + precalc_linelength = /*current_surface->*/pitch/sizeof(BASETYPE); \ + for (y=0;y*/pixels)+y*4*precalc_linelength; \ + for (x=0;x>4]; \ + for (i=0; i<2; i++) \ + { \ + uint8_t bitmap=*cp++; \ + for (j=0; j<4; j++) \ + { \ + *scr++=(bitmap&128)?f:b; \ + bitmap<<=1; \ + } \ + scr+=precalc_linelength-4; \ + for (j=0; j<4; j++) \ + { \ + *scr++=(bitmap&128)?f:b; \ + bitmap<<=1; \ + } \ + scr+=precalc_linelength-4; \ + } \ + if ((doshape==1)&&(curposy==y)&&(curposx==x)) \ + { \ + cp=plFont44['_']+1; \ + scr+=4; \ + for (i=0; i<2; i++) \ + { \ + uint8_t bitmap=*cp--; \ + scr-=precalc_linelength+4; \ + for (j=0; j<4; j++) \ + { \ + if (bitmap&1) \ + *scr=f; \ + bitmap>>=1; \ + scr++; \ + } \ + scr-=precalc_linelength+4; \ + for (j=0; j<4; j++) \ + { \ + if (bitmap&1) \ + *scr=f; \ + bitmap>>=1; \ + scr++; \ + } \ + } \ + } \ + } \ + } + + switch (plCurrentFont) + { + case _8x16: + BLOCK8x16(uint32_t) + break; + case _8x8: + BLOCK8x8(uint32_t) + break; + case _4x4: + BLOCK4x4(uint32_t) + break; + } + + if (doshape==2) + vgatextram[curposy*plScrRowBytes+curposx*2]=save; + + SDL_UnlockTexture(current_texture); + + SDL_RenderCopy (current_renderer, current_texture, NULL, NULL); + SDL_RenderPresent (current_renderer); +} + +static void RefreshScreenGraph(void) +{ + void *pixels; + int pitch; + + if (!current_texture) + return; + + if (!virtual_framebuffer) + return; + + SDL_LockTexture (current_texture, NULL, &pixels, &pitch); + + { + uint8_t *src=(uint8_t *)virtual_framebuffer; + uint8_t *dst_line = (uint8_t *)/*current_surface->*/pixels; + int Y=0; + + uint32_t *dst; + + while (1) + { + int j; + + dst = (uint32_t *)dst_line; + for (j=0;j=plScrLines) + break; + dst_line += /*current_surface->*/pitch; + } + } + + SDL_UnlockTexture (current_texture); + + SDL_RenderCopy (current_renderer, current_texture, NULL, NULL); + SDL_RenderPresent (current_renderer); +} + +static int ekbhit(void) +{ + SDL_Event event; + + if (plScrMode<=8) + { + RefreshScreenText(); + } else { + RefreshScreenGraph(); + } + + while(SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_WINDOWEVENT: + { + switch (event.window.event) + { + case SDL_WINDOWEVENT_CLOSE: + { +#ifdef SDL2_DEBUG + fprintf(stderr, "[SDL2-video] CLOSE:\n"); +#endif + break; + } + case SDL_WINDOWEVENT_SIZE_CHANGED: + { +#ifdef SDL2_DEBUG + fprintf(stderr, "[SDL2-video] SIZE_CHANGED:\n"); + fprintf(stderr, " w: %d\n", event.window.data1); + fprintf(stderr, " h: %d\n", event.window.data2); + fprintf(stderr, " windowID: %d\n", event.window.windowID); +#endif + break; + } + + case SDL_WINDOWEVENT_RESIZED: + { +#ifdef SDL2_DEBUG + fprintf(stderr, "[SDL2-video] RESIZED:\n"); + fprintf(stderr, " w: %d\n", event.window.data1); + fprintf(stderr, " h: %d\n", event.window.data2); + fprintf(stderr, " windowID: %d\n", event.window.windowID); +#endif + if (current_window && (SDL_GetWindowID(current_window) == event.window.windowID)) + { + plCurrentFont = plCurrentFontWanted; + if (!do_fullscreen && (plScrMode == plScrType)) + { + last_text_height = event.window.data2; + last_text_width = event.window.data1; + } + set_state(do_fullscreen, event.window.data1, event.window.data2); + if (!do_fullscreen) + { + if (plScrType == plScrMode) /* if we are in text-mode, make it a custom one */ + { + fprintf (stderr, "CUSTOM MODE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + plScrType = plScrMode = 8; + } + } + } else { +#ifdef SDL2_DEBUG + fprintf (stderr, "[SDL2-video] we ignored that event, it does not belong to our window...\n"); +#endif + } + break; + } + } + break; + } + case SDL_MOUSEBUTTONDOWN: + { +#ifdef SDL2_DEBUG + fprintf(stderr, "[SDL2-video] MOUSEBUTTONDOWN\n"); + fprintf(stderr, " which: %d\n", (int)event.button.which); + fprintf(stderr, " button: %d\n", (int)event.button.button); + fprintf(stderr, " state: %d\n", (int)event.button.state); + fprintf(stderr, " x,y: %d, %d\n", (int)event.button.x, (int)event.button.y); +#endif + switch (event.button.button) + { + case 1: + ___push_key(_KEY_ENTER); + break; + + case 3: + set_state(!do_fullscreen, plScrLineBytes, plScrLines); + break; + + case 4: + ___push_key(KEY_UP); + break; + + case 5: + ___push_key(KEY_DOWN); + break; + } + break; + } + case SDL_KEYUP: + { +#ifdef SDL2_DEBUG + fprintf(stderr, "[SDL2-video] KEYUP\n"); + fprintf(stderr, " keysym.mod: 0x%04x%s%s%s%s%s%s%s%s%s%s%s\n", (int)event.key.keysym.mod, + (event.key.keysym.mod & KMOD_LSHIFT) ? " KMOD_LSHIFT":"", + (event.key.keysym.mod & KMOD_RSHIFT) ? " KMOD_RSHIFT":"", + (event.key.keysym.mod & KMOD_LCTRL) ? " KMOD_LCTRL":"", + (event.key.keysym.mod & KMOD_RCTRL) ? " KMOD_RCTRL":"", + (event.key.keysym.mod & KMOD_LALT) ? " KMOD_LALT":"", + (event.key.keysym.mod & KMOD_RALT) ? " KMOD_RALT":"", + (event.key.keysym.mod & KMOD_LGUI) ? " KMOD_LGUI":"", + (event.key.keysym.mod & KMOD_RGUI) ? " KMOD_RGUI":"", + (event.key.keysym.mod & KMOD_NUM) ? " KMOD_NUM":"", + (event.key.keysym.mod & KMOD_CAPS) ? " KMOD_CAPS":"", + (event.key.keysym.mod & KMOD_MODE) ? " KMOD_MODE":""); + fprintf (stderr, " keysym.sym: 0x%08x\n", (int)event.key.keysym.sym); +#endif + break; + } + case SDL_KEYDOWN: + { + int index; + +#ifdef SDL2_DEBUG + fprintf(stderr, "[SDL2-video] KEYDOWN\n"); + fprintf(stderr, " keysym.mod: 0x%04x%s%s%s%s%s%s%s%s%s%s%s\n", (int)event.key.keysym.mod, + (event.key.keysym.mod & KMOD_LSHIFT) ? " KMOD_LSHIFT":"", + (event.key.keysym.mod & KMOD_RSHIFT) ? " KMOD_RSHIFT":"", + (event.key.keysym.mod & KMOD_LCTRL) ? " KMOD_LCTRL":"", + (event.key.keysym.mod & KMOD_RCTRL) ? " KMOD_RCTRL":"", + (event.key.keysym.mod & KMOD_LALT) ? " KMOD_LALT":"", + (event.key.keysym.mod & KMOD_RALT) ? " KMOD_RALT":"", + (event.key.keysym.mod & KMOD_LGUI) ? " KMOD_LGUI":"", + (event.key.keysym.mod & KMOD_RGUI) ? " KMOD_RGUI":"", + (event.key.keysym.mod & KMOD_NUM) ? " KMOD_NUM":"", + (event.key.keysym.mod & KMOD_CAPS) ? " KMOD_CAPS":"", + (event.key.keysym.mod & KMOD_MODE) ? " KMOD_MODE":""); + fprintf (stderr, " keysym.sym: 0x%08x\n", (int)event.key.keysym.sym); +#endif + + if ((event.key.keysym.mod & KMOD_CTRL) && (!(event.key.keysym.mod & ~(KMOD_CTRL|KMOD_SHIFT|KMOD_ALT|KMOD_NUM)))) + { + for (index=0;translate_ctrl[index].OCP!=0xffff;index++) + if (translate_ctrl[index].SDL==event.key.keysym.sym) + { + ___push_key(translate_ctrl[index].OCP); + break; + } + break; + } + + if ((event.key.keysym.mod & KMOD_SHIFT) && (!(event.key.keysym.mod & ~(KMOD_CTRL|KMOD_SHIFT|KMOD_ALT|KMOD_NUM)))) + { + for (index=0;translate_shift[index].OCP!=0xffff;index++) + if (translate_shift[index].SDL==event.key.keysym.sym) + { + ___push_key(translate_shift[index].OCP); + break; + } + /* no break here */ + } + + if ((event.key.keysym.mod & KMOD_ALT) && (!(event.key.keysym.mod & ~(KMOD_CTRL|KMOD_SHIFT|KMOD_ALT|KMOD_NUM)))) + { + /* TODO, handle ALT-ENTER */ + if (event.key.keysym.sym==SDLK_RETURN) + { + set_state(!do_fullscreen, plScrLineBytes, plScrLines); + } else { + for (index=0;translate_alt[index].OCP!=0xffff;index++) + if (translate_alt[index].SDL==event.key.keysym.sym) + { + ___push_key(translate_alt[index].OCP); + break; + } + } + break; + } + + if (event.key.keysym.mod & (KMOD_CTRL|KMOD_SHIFT|KMOD_ALT)) + break; + + for (index=0;translate[index].OCP!=0xffff;index++) + { + if (translate[index].SDL==event.key.keysym.sym) + { + ___push_key(translate[index].OCP); + break; + } + } + break; + } + } + } + + return 0; +} + +static void sdl2_gflushpal(void) +{ +} + +static void sdl2_gupdatepal(unsigned char index, unsigned char _red, unsigned char _green, unsigned char _blue) +{ + uint8_t *pal = (uint8_t *)sdl2_palette; + pal[(index<<2)+3] = 0xff; + pal[(index<<2)+2] = _red<<2; + pal[(index<<2)+1] = _green<<2; + pal[(index<<2)+0] = _blue<<2; +} + +static void displayvoid(uint16_t y, uint16_t x, uint16_t len) +{ + uint8_t *addr=vgatextram+y*plScrRowBytes+x*2; + while (len--) + { + *addr++=0; + *addr++=plpalette[0]; + } +} + +static void displaystrattr(uint16_t y, uint16_t x, const uint16_t *buf, uint16_t len) +{ + uint8_t *p=vgatextram+(y*plScrRowBytes+x*2); + while (len) + { + *(p++)=(*buf)&0x0ff; + *(p++)=plpalette[((*buf)>>8)]; + buf++; + len--; + } +} + +static void displaystr(uint16_t y, uint16_t x, uint8_t attr, const char *str, uint16_t len) +{ + uint8_t *p=vgatextram+(y*plScrRowBytes+x*2); + int i; + attr=plpalette[attr]; + for (i=0; i((yh*(unsigned)16)-4)) + hgt=(yh*16)-4; + for (i=0; i=16) + { + buf[i]=bartops[16]; + hgt-=16; + } else { + buf[i]=bartops[hgt]; + hgt=0; + } + } + scrptr=vgatextram+(2*x+yb*plScrRowBytes); + yh1=(yh+2)/3; + yh2=(yh+yh1+1)/2; + for (i=0; i>=8; + for (i=yh1; i>=8; + for (i=yh2; i((yh*(unsigned)16)-4)) + hgt=(yh*16)-4; + + scrptr=vgatextram+(2*x+(yb-yh+1)*plScrRowBytes); + + for (i=0; i=16) + { + buf[i]=ibartops[16]; + hgt-=16; + } else { + buf[i]=ibartops[hgt]; + hgt=0; + } + } + yh1=(yh+2)/3; + yh2=(yh+yh1+1)/2; + for (i=0; i>=8; + for (i=yh1; i>=8; + for (i=yh2; i