Advertisement
kfg

Mednafen 0.9.36.2 SDL2

kfg
Jul 6th, 2014
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 64.54 KB | None | 0 0
  1. diff --git a/configure.ac b/configure.ac
  2. index 4337cd3..e2791e3 100644
  3. --- a/configure.ac
  4. +++ b/configure.ac
  5. @@ -467,8 +467,8 @@ fi
  6.  
  7.  if $NEED_SDL
  8.  then
  9. -   SDL_VERSION=1.2.0
  10. -   AM_PATH_SDL($SDL_VERSION, HAVE_SDL=true, HAVE_SDL=false)
  11. +   SDL_VERSION=2.0.0
  12. +   AM_PATH_SDL2($SDL_VERSION, HAVE_SDL=true, HAVE_SDL=false)
  13.     if $HAVE_SDL
  14.     then
  15.         AM_CONDITIONAL(HAVE_SDL, true)
  16. @@ -476,7 +476,7 @@ then
  17.         AC_SUBST(SDL_LIBS)
  18.         AC_SUBST(SDL_CFLAGS)
  19.     else
  20. -       AC_MSG_ERROR([*** SDL 1.2.x not found!])
  21. +       AC_MSG_ERROR([*** SDL 2.0.x not found!])
  22.     fi
  23.  fi
  24.  
  25. diff --git a/m4/sdl2.m4 b/m4/sdl2.m4
  26. new file mode 100644
  27. index 0000000..a03b2d2
  28. --- /dev/null
  29. +++ b/m4/sdl2.m4
  30. @@ -0,0 +1,202 @@
  31. +# Configure paths for SDL
  32. +# Sam Lantinga 9/21/99
  33. +# stolen from Manish Singh
  34. +# stolen back from Frank Belew
  35. +# stolen from Manish Singh
  36. +# Shamelessly stolen from Owen Taylor
  37. +
  38. +# serial 1
  39. +
  40. +dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
  41. +dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
  42. +dnl
  43. +AC_DEFUN([AM_PATH_SDL2],
  44. +[dnl
  45. +dnl Get the cflags and libraries from the sdl2-config script
  46. +dnl
  47. +AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
  48. +            sdl_prefix="$withval", sdl_prefix="")
  49. +AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
  50. +            sdl_exec_prefix="$withval", sdl_exec_prefix="")
  51. +AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
  52. +           , enable_sdltest=yes)
  53. +
  54. +  min_sdl_version=ifelse([$1], ,2.0.0,$1)
  55. +
  56. +  if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
  57. +    PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
  58. +           [sdl_pc=yes],
  59. +           [sdl_pc=no])
  60. +  else
  61. +    sdl_pc=no
  62. +    if test x$sdl_exec_prefix != x ; then
  63. +      sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
  64. +      if test x${SDL2_CONFIG+set} != xset ; then
  65. +        SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config
  66. +      fi
  67. +    fi
  68. +    if test x$sdl_prefix != x ; then
  69. +      sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
  70. +      if test x${SDL2_CONFIG+set} != xset ; then
  71. +        SDL2_CONFIG=$sdl_prefix/bin/sdl2-config
  72. +      fi
  73. +    fi
  74. +  fi
  75. +
  76. +  if test "x$sdl_pc" = xyes ; then
  77. +    no_sdl=""
  78. +    SDL2_CONFIG="pkg-config sdl2"
  79. +  else
  80. +    as_save_PATH="$PATH"
  81. +    if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
  82. +      PATH="$prefix/bin:$prefix/usr/bin:$PATH"
  83. +    fi
  84. +    AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
  85. +    PATH="$as_save_PATH"
  86. +    AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
  87. +    no_sdl=""
  88. +
  89. +    if test "$SDL2_CONFIG" = "no" ; then
  90. +      no_sdl=yes
  91. +    else
  92. +      SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags`
  93. +      SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs`
  94. +
  95. +      sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \
  96. +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)//'`
  97. +      sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \
  98. +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
  99. +      sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \
  100. +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
  101. +      if test "x$enable_sdltest" = "xyes" ; then
  102. +        ac_save_CFLAGS="$CFLAGS"
  103. +        ac_save_CXXFLAGS="$CXXFLAGS"
  104. +        ac_save_LIBS="$LIBS"
  105. +        CFLAGS="$CFLAGS $SDL_CFLAGS"
  106. +        CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  107. +        LIBS="$LIBS $SDL_LIBS"
  108. +dnl
  109. +dnl Now check if the installed SDL is sufficiently new. (Also sanity
  110. +dnl checks the results of sdl2-config to some extent
  111. +dnl
  112. +      rm -f conf.sdltest
  113. +      AC_TRY_RUN([
  114. +#include <stdio.h>
  115. +#include <stdlib.h>
  116. +#include <string.h>
  117. +#include "SDL.h"
  118. +
  119. +char*
  120. +my_strdup (char *str)
  121. +{
  122. +  char *new_str;
  123. +  
  124. +  if (str)
  125. +    {
  126. +      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
  127. +      strcpy (new_str, str);
  128. +    }
  129. +  else
  130. +    new_str = NULL;
  131. +  
  132. +  return new_str;
  133. +}
  134. +
  135. +int main (int argc, char *argv[])
  136. +{
  137. +  int major, minor, micro;
  138. +  char *tmp_version;
  139. +
  140. +  /* This hangs on some systems (?)
  141. +  system ("touch conf.sdltest");
  142. +  */
  143. +  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
  144. +
  145. +  /* HP/UX 9 (%@#!) writes to sscanf strings */
  146. +  tmp_version = my_strdup("$min_sdl_version");
  147. +  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
  148. +     printf("%s, bad version string\n", "$min_sdl_version");
  149. +     exit(1);
  150. +   }
  151. +
  152. +   if (($sdl_major_version > major) ||
  153. +      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
  154. +      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
  155. +    {
  156. +      return 0;
  157. +    }
  158. +  else
  159. +    {
  160. +      printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
  161. +      printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
  162. +      printf("*** best to upgrade to the required version.\n");
  163. +      printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
  164. +      printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
  165. +      printf("*** config.cache before re-running configure\n");
  166. +      return 1;
  167. +    }
  168. +}
  169. +
  170. +],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
  171. +        CFLAGS="$ac_save_CFLAGS"
  172. +        CXXFLAGS="$ac_save_CXXFLAGS"
  173. +        LIBS="$ac_save_LIBS"
  174. +      fi
  175. +    fi
  176. +    if test "x$no_sdl" = x ; then
  177. +      AC_MSG_RESULT(yes)
  178. +    else
  179. +      AC_MSG_RESULT(no)
  180. +    fi
  181. +  fi
  182. +  if test "x$no_sdl" = x ; then
  183. +     ifelse([$2], , :, [$2])
  184. +  else
  185. +     if test "$SDL2_CONFIG" = "no" ; then
  186. +       echo "*** The sdl2-config script installed by SDL could not be found"
  187. +       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
  188. +       echo "*** your path, or set the SDL2_CONFIG environment variable to the"
  189. +       echo "*** full path to sdl2-config."
  190. +     else
  191. +       if test -f conf.sdltest ; then
  192. +        :
  193. +       else
  194. +          echo "*** Could not run SDL test program, checking why..."
  195. +          CFLAGS="$CFLAGS $SDL_CFLAGS"
  196. +          CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  197. +          LIBS="$LIBS $SDL_LIBS"
  198. +          AC_TRY_LINK([
  199. +#include <stdio.h>
  200. +#include "SDL.h"
  201. +
  202. +int main(int argc, char *argv[])
  203. +{ return 0; }
  204. +#undef  main
  205. +#define main K_and_R_C_main
  206. +],      [ return 0; ],
  207. +        [ echo "*** The test program compiled, but did not run. This usually means"
  208. +          echo "*** that the run-time linker is not finding SDL or finding the wrong"
  209. +          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
  210. +          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
  211. +          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
  212. +          echo "*** is required on your system"
  213. +     echo "***"
  214. +          echo "*** If you have an old version installed, it is best to remove it, although"
  215. +          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
  216. +        [ echo "*** The test program failed to compile or link. See the file config.log for the"
  217. +          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
  218. +          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
  219. +          echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
  220. +          CFLAGS="$ac_save_CFLAGS"
  221. +          CXXFLAGS="$ac_save_CXXFLAGS"
  222. +          LIBS="$ac_save_LIBS"
  223. +       fi
  224. +     fi
  225. +     SDL_CFLAGS=""
  226. +     SDL_LIBS=""
  227. +     ifelse([$3], , :, [$3])
  228. +  fi
  229. +  AC_SUBST(SDL_CFLAGS)
  230. +  AC_SUBST(SDL_LIBS)
  231. +  rm -f conf.sdltest
  232. +])
  233. diff --git a/src/drivers/Joystick_SDL.cpp b/src/drivers/Joystick_SDL.cpp
  234. index 6c16b8b..dbd90ab 100644
  235. --- a/src/drivers/Joystick_SDL.cpp
  236. +++ b/src/drivers/Joystick_SDL.cpp
  237. @@ -55,7 +55,7 @@ Joystick_SDL::Joystick_SDL(unsigned index) : sdl_joy(NULL)
  238.    throw MDFN_Error(0, "SDL_JoystickOpen(%u) failed: %s", index, SDL_GetError());
  239.   }
  240.  
  241. - strncpy(name, SDL_JoystickName(index), sizeof(name));
  242. + strncpy(name, SDL_JoystickNameForIndex(index), sizeof(name));
  243.   name[sizeof(name) - 1] = 0;
  244.  
  245.   sdl_num_axes = SDL_JoystickNumAxes(sdl_joy);
  246. diff --git a/src/drivers/console.cpp b/src/drivers/console.cpp
  247. index 03289e0..276aae2 100644
  248. --- a/src/drivers/console.cpp
  249. +++ b/src/drivers/console.cpp
  250. @@ -127,20 +127,18 @@ int MDFNConsole::Event(const SDL_Event *event)
  251.                      kb_buffer.erase(kb_buffer.begin() + kb_cursor_pos, kb_buffer.begin() + kb_cursor_pos + 1);
  252.                     }
  253.                     break;
  254. -                     default:
  255. -            if(event->key.keysym.unicode >= 0x20)
  256. -                     {
  257. -                      uint8 utf8_buffer[8];
  258. -                      UTF8 *dest_ptr = utf8_buffer;
  259. -                      memset(utf8_buffer, 0, sizeof(utf8_buffer));
  260. -                      const UTF16 *start_utf16 = &event->key.keysym.unicode;
  261. -                      ConvertUTF16toUTF8(&start_utf16, (UTF16 *)&event->key.keysym.unicode + 1, &dest_ptr, &utf8_buffer[8], lenientConversion);
  262. -                 kb_buffer.insert(kb_buffer.begin() + kb_cursor_pos, std::string((char *)utf8_buffer));
  263. -                 kb_cursor_pos++;
  264. -                     }
  265. -                     break;
  266.                      }
  267.                      break;
  268. +    case SDL_TEXTINPUT:
  269. +     {
  270. +      uint8 utf8_buffer[8];
  271. +      UTF8 *dest_ptr = utf8_buffer;
  272. +      memset(utf8_buffer, 0, sizeof(utf8_buffer));
  273. +      strncpy((char*)utf8_buffer, event->text.text, sizeof(utf8_buffer));
  274. +      kb_buffer.insert(kb_buffer.begin() + kb_cursor_pos, std::string((char *)utf8_buffer));
  275. +      kb_cursor_pos++;
  276. +     }
  277. +    break;
  278.    }
  279.   return(1);
  280.  }
  281. diff --git a/src/drivers/input-config.cpp b/src/drivers/input-config.cpp
  282. index 22cc556..ef05510 100644
  283. --- a/src/drivers/input-config.cpp
  284. +++ b/src/drivers/input-config.cpp
  285. @@ -107,8 +107,10 @@ int DTestButton(std::vector<ButtConfig> &bc, const char *KeyState, const uint32
  286.   {
  287.    if(bc[x].ButtType == BUTTC_KEYBOARD)
  288.    {
  289. -   if(KeyState[bc[x].ButtonNum])
  290. +   if(KeyState[bc[x].ButtonNum & 0xFF]) {
  291. +    //printf("bc[x].ButtonNum: %d\n", bc[x].ButtonNum);
  292.      ret += maxv;
  293. +   }
  294.    }
  295.    else if(bc[x].ButtType == BUTTC_JOYSTICK)
  296.    {
  297. @@ -207,18 +209,18 @@ static int EventFilter(const SDL_Event *event)
  298.  
  299.   switch(event->type)
  300.   {
  301. -   case SDL_KEYDOWN:    if(!efck || (event->key.keysym.sym != MKK(LALT) && event->key.keysym.sym != MKK(RALT) &&
  302. -                         event->key.keysym.sym != MKK(LSHIFT) && event->key.keysym.sym != MKK(RSHIFT) &&
  303. -            event->key.keysym.sym != MKK(LCTRL) && event->key.keysym.sym != MKK(RCTRL)))
  304. +   case SDL_KEYDOWN:    if(!efck || (event->key.keysym.sym != SDLK_LALT && event->key.keysym.sym != SDLK_RALT &&
  305. +                         event->key.keysym.sym != SDLK_LSHIFT && event->key.keysym.sym != SDLK_RSHIFT &&
  306. +            event->key.keysym.sym != SDLK_LCTRL && event->key.keysym.sym != SDLK_RCTRL))
  307.                          {
  308.                                  efbc.ButtType = BUTTC_KEYBOARD;
  309.                                  efbc.DeviceNum = 0;
  310. -                                efbc.ButtonNum = event->key.keysym.sym;
  311. +                                efbc.ButtonNum = event->key.keysym.scancode;
  312.  
  313. -               if(0 == event->key.keysym.sym)
  314. +               if(0 == event->key.keysym.scancode)
  315.                  printf("*** NULL KEYSYM! ***\n");
  316.  
  317. -               //printf("%u\n", event->key.keysym.sym);
  318. +               //printf("%u\n", event->key.keysym.scancode);
  319.  
  320.                                  if(efck)
  321.                                          efbc.ButtonNum |= ((event->key.keysym.mod & KMOD_ALT) ? (ICSS_ALT<<24):0) | ((event->key.keysym.mod & KMOD_SHIFT) ? (ICSS_SHIFT<<24):0) | ((event->key.keysym.mod & KMOD_CTRL) ? (ICSS_CTRL<<24):0);
  322. diff --git a/src/drivers/input-default-buttons.h b/src/drivers/input-default-buttons.h
  323. index 4f26aaa..de31b40 100644
  324. --- a/src/drivers/input-default-buttons.h
  325. +++ b/src/drivers/input-default-buttons.h
  326. @@ -5,8 +5,8 @@
  327.  static const ButtConfig NESGamePadConfig[4][8]={
  328.          /* Gamepad 1 */
  329.          {
  330. -         MK(KP3), MK(KP2), MK(TAB), MK(RETURN), MK(w),MK(s),
  331. -                MK(a), MK(d)
  332. +         MK(KP_3), MK(KP_2), MK(TAB), MK(RETURN), MK(W),MK(S),
  333. +                MK(A), MK(D)
  334.          },
  335.  
  336.          /* Gamepad 2 */
  337. @@ -22,14 +22,14 @@ static const ButtConfig NESGamePadConfig[4][8]={
  338.  
  339.  static const ButtConfig GBPadConfig[8] =
  340.  {
  341. -         MK(KP3), MK(KP2), MK(TAB), MK(RETURN), MK(d),MK(a),
  342. -                MK(w), MK(s)
  343. +         MK(KP_3), MK(KP_2), MK(TAB), MK(RETURN), MK(D),MK(A),
  344. +                MK(W), MK(S)
  345.  };
  346.  
  347.  static const ButtConfig GBAPadConfig[10] =
  348.  {
  349. -         MK(KP3), MK(KP2), MK(TAB), MK(RETURN), MK(d),MK(a),
  350. -                MK(w), MK(s), MK(KP6), MK(KP5)
  351. +         MK(KP_3), MK(KP_2), MK(TAB), MK(RETURN), MK(D),MK(A),
  352. +                MK(W), MK(S), MK(KP_6), MK(KP_5)
  353.  };
  354.  
  355.  #define GPZ()   {MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ(), MKZ()}
  356. @@ -37,9 +37,9 @@ static const ButtConfig PCFXPadConfig[2][15]=
  357.  {
  358.          /* Gamepad 1 */
  359.          {
  360. -         MK(KP3), MK(KP2), MK(KP1), MK(KP4), MK(KP5), MK(KP6), MK(TAB), MK(RETURN),
  361. -         MK(w), MK(d), MK(s), MK(a),
  362. -    MK(KP8), MK(KP9),
  363. +         MK(KP_3), MK(KP_2), MK(KP_1), MK(KP_4), MK(KP_5), MK(KP_6), MK(TAB), MK(RETURN),
  364. +         MK(W), MK(D), MK(S), MK(A),
  365. +    MK(KP_8), MK(KP_9),
  366.          },
  367.  
  368.          /* Gamepad 2 */
  369. @@ -51,13 +51,13 @@ static const ButtConfig PCFXPadConfig[2][15]=
  370.  static const ButtConfig PCEPadConfig[5][13]={
  371.          /* Gamepad 1 */
  372.          {
  373. -         MK(KP3), MK(KP2), MK(TAB), MK(RETURN), MK(w), MK(d), MK(s), MK(a),
  374. +         MK(KP_3), MK(KP_2), MK(TAB), MK(RETURN), MK(W), MK(D), MK(S), MK(A),
  375.  
  376.           // Extra 4 buttons on 6-button pad
  377. -         MK(KP1), MK(KP4), MK(KP5), MK(KP6),
  378. +         MK(KP_1), MK(KP_4), MK(KP_5), MK(KP_6),
  379.  
  380.           // ..and special 2/6 mode select
  381. -         MK(m),
  382. +         MK(M),
  383.          },
  384.  
  385.          /* Gamepad 2 */
  386. @@ -77,14 +77,14 @@ static const ButtConfig PCEPadConfig[5][13]={
  387.  static const ButtConfig LynxPadConfig[9] =
  388.  {
  389.          // A, B, Option 2, Option 1, Left, Right, Up, Down, Pause
  390. -         MK(KP3), MK(KP2), MK(KP1), MK(KP7), MK(a),MK(d),
  391. -                MK(w), MK(s), MK(RETURN)
  392. +         MK(KP_3), MK(KP_2), MK(KP_1), MK(KP_7), MK(A),MK(D),
  393. +                MK(W), MK(S), MK(RETURN)
  394.  };
  395.  
  396.  static const ButtConfig NGPPadConfig[7 + 2] =
  397.  {
  398.          // Up, down, left, right, a(inner), b(outer), option
  399. -        MK(w), MK(s), MK(a), MK(d), MK(KP2), MK(KP3), MK(RETURN), MK(KP5), MK(KP6)
  400. +        MK(W), MK(S), MK(A), MK(D), MK(KP_2), MK(KP_3), MK(RETURN), MK(KP_5), MK(KP_6)
  401.  };
  402.  
  403.  static const ButtConfig WSwanPadConfig[12] =
  404. @@ -92,52 +92,52 @@ static const ButtConfig WSwanPadConfig[12] =
  405.          // Up, right, down, left,
  406.          // up-y, right-y, down-y, left-y,
  407.     //  start, a(outer), b(inner), option
  408. -        MK(w), MK(d), MK(s), MK(a),
  409. +        MK(W), MK(D), MK(S), MK(A),
  410.     MK(UP), MK(RIGHT), MK(DOWN), MK(LEFT),
  411. -   MK(RETURN), MK(KP3), MK(KP2), MK(RETURN)
  412. +   MK(RETURN), MK(KP_3), MK(KP_2), MK(RETURN)
  413.  };
  414.  
  415.  
  416.  static const ButtConfig PowerPadConfig[12] =
  417.  {
  418. - MK(o),MK(p),MK(LEFTBRACKET),MK(RIGHTBRACKET),
  419. - MK(k),MK(l),MK(SEMICOLON),MK(QUOTE),
  420. - MK(m),MK(COMMA),MK(PERIOD),MK(SLASH)
  421. + MK(O),MK(P),MK(LEFTBRACKET),MK(RIGHTBRACKET),
  422. + MK(K),MK(L),MK(SEMICOLON),MK(APOSTROPHE),
  423. + MK(M),MK(COMMA),MK(PERIOD),MK(SLASH)
  424.  };
  425.  
  426.  static const ButtConfig fkbmap[0x48]=
  427.  {
  428.   MK(F1),MK(F2),MK(F3),MK(F4),MK(F5),MK(F6),MK(F7),MK(F8),
  429.   MK(1),MK(2),MK(3),MK(4),MK(5),MK(6),MK(7),MK(8),MK(9),MK(0),MK(MINUS),MK(EQUALS),MK(BACKSLASH),MK(BACKSPACE),
  430. - MK(ESCAPE),MK(q),MK(w),MK(e),MK(r),MK(t),MK(y),MK(u),MK(i),MK(o),MK(p),MK(BACKQUOTE),MK(LEFTBRACKET),MK(RETURN),
  431. - MK(LCTRL),MK(a),MK(s),MK(d),MK(f),MK(g),MK(h),MK(j),MK(k),MK(l),MK(SEMICOLON),MK(QUOTE),MK(RIGHTBRACKET),MK(INSERT),
  432. - MK(LSHIFT),MK(z),MK(x),MK(c),MK(v),MK(b),MK(n),MK(m),MK(COMMA),MK(PERIOD),MK(SLASH),MK(RALT),MK(RSHIFT),MK(LALT),MK(SPACE),
  433. + MK(ESCAPE),MK(Q),MK(W),MK(E),MK(R),MK(T),MK(Y),MK(U),MK(I),MK(O),MK(P),MK(GRAVE),MK(LEFTBRACKET),MK(RETURN),
  434. + MK(LCTRL),MK(A),MK(S),MK(D),MK(F),MK(G),MK(H),MK(J),MK(K),MK(L),MK(SEMICOLON),MK(APOSTROPHE),MK(RIGHTBRACKET),MK(INSERT),
  435. + MK(LSHIFT),MK(Z),MK(X),MK(C),MK(V),MK(B),MK(N),MK(M),MK(COMMA),MK(PERIOD),MK(SLASH),MK(RALT),MK(RSHIFT),MK(LALT),MK(SPACE),
  436.   MK(DELETE),MK(END),MK(PAGEDOWN),MK(UP),MK(LEFT),MK(RIGHT),MK(DOWN)
  437.  };
  438.  
  439.  static const ButtConfig HyperShotButtons[4]=
  440.  {
  441. - MK(q),MK(w),MK(e),MK(r)
  442. + MK(Q),MK(W),MK(E),MK(R)
  443.  };
  444.  
  445.  static const ButtConfig MahjongButtons[21]=
  446.  {
  447. - MK(q),MK(w),MK(e),MK(r),MK(t),
  448. - MK(a),MK(s),MK(d),MK(f),MK(g),MK(h),MK(j),MK(k),MK(l),
  449. - MK(z),MK(x),MK(c),MK(v),MK(b),MK(n),MK(m)
  450. + MK(Q),MK(W),MK(E),MK(R),MK(T),
  451. + MK(A),MK(S),MK(D),MK(F),MK(G),MK(H),MK(J),MK(K),MK(L),
  452. + MK(Z),MK(X),MK(C),MK(V),MK(B),MK(N),MK(M)
  453.  };
  454.  
  455.  static const ButtConfig PartyTapButtons[6]=
  456.  {
  457. - MK(q),MK(w),MK(e),MK(r),MK(t),MK(y)
  458. + MK(Q),MK(W),MK(E),MK(R),MK(T),MK(Y)
  459.  };
  460.  
  461.  static const ButtConfig FTrainerButtons[12]=
  462.  {
  463. -                               MK(o),MK(p),MK(LEFTBRACKET),
  464. -                               MK(RIGHTBRACKET),MK(k),MK(l),MK(SEMICOLON),
  465. -                                MK(QUOTE),
  466. -                               MK(m),MK(COMMA),MK(PERIOD),MK(SLASH)
  467. +                               MK(O),MK(P),MK(LEFTBRACKET),
  468. +                               MK(RIGHTBRACKET),MK(K),MK(L),MK(SEMICOLON),
  469. +                                MK(APOSTROPHE),
  470. +                               MK(M),MK(COMMA),MK(PERIOD),MK(SLASH)
  471.  };
  472.  
  473.  static ButtConfig OekaKidsConfig[3] =
  474. @@ -192,7 +192,7 @@ static const ButtConfig SMSPadConfig[2][12]=
  475.  {
  476.          /* Gamepad 1 */
  477.          {
  478. -    MK(w), MK(s), MK(a), MK(d), MK(KP2), MK(KP3), MK(RETURN)
  479. +    MK(W), MK(S), MK(A), MK(D), MK(KP_2), MK(KP_3), MK(RETURN)
  480.          },
  481.  
  482.          /* Gamepad 2 */
  483. @@ -201,23 +201,23 @@ static const ButtConfig SMSPadConfig[2][12]=
  484.  
  485.  static const ButtConfig GGPadConfig[12]=
  486.  {
  487. -         MK(w), MK(s), MK(a), MK(d), MK(KP2), MK(KP3), MK(RETURN)
  488. +         MK(W), MK(S), MK(A), MK(D), MK(KP_2), MK(KP_3), MK(RETURN)
  489.  };
  490.  
  491.  static const ButtConfig TsushinKBConfig[0x80]=
  492.  {
  493.   // 0
  494. - MK(KP0),
  495. - MK(KP1),
  496. - MK(KP2),
  497. - MK(KP3),
  498. - MK(KP4),
  499. - MK(KP5),
  500. - MK(KP6),
  501. + MK(KP_0),
  502. + MK(KP_1),
  503. + MK(KP_2),
  504. + MK(KP_3),
  505. + MK(KP_4),
  506. + MK(KP_5),
  507. + MK(KP_6),
  508.  
  509.  // 1
  510. - MK(KP8),
  511. - MK(KP9),
  512. + MK(KP_8),
  513. + MK(KP_9),
  514.   MK(KP_MULTIPLY),      // Keypad Multiply
  515.   MK(KP_PLUS),          // Keypad Plus
  516.   MK(KP_EQUALS),            // Keypad Equals
  517. @@ -225,38 +225,38 @@ static const ButtConfig TsushinKBConfig[0x80]=
  518.   MK(KP_PERIOD),            // Keypad Period
  519.  
  520.  // 2
  521. - MK(BACKQUOTE),        // @
  522. - MK(a),
  523. - MK(b),
  524. - MK(c),
  525. - MK(d),
  526. - MK(e),
  527. - MK(f),
  528. + MK(GRAVE),        // @
  529. + MK(A),
  530. + MK(B),
  531. + MK(C),
  532. + MK(D),
  533. + MK(E),
  534. + MK(F),
  535.  
  536.  // 3
  537. - MK(h),
  538. - MK(i),
  539. - MK(j),
  540. - MK(k),
  541. - MK(l),
  542. - MK(m),
  543. - MK(n),
  544. + MK(H),
  545. + MK(I),
  546. + MK(J),
  547. + MK(K),
  548. + MK(L),
  549. + MK(M),
  550. + MK(N),
  551.  
  552.  // 4
  553. - MK(p),
  554. - MK(q),
  555. - MK(r),
  556. - MK(s),
  557. - MK(t),
  558. - MK(u),
  559. - MK(v),
  560. + MK(P),
  561. + MK(Q),
  562. + MK(R),
  563. + MK(S),
  564. + MK(T),
  565. + MK(U),
  566. + MK(V),
  567.  
  568.  // 5
  569. - MK(x),
  570. - MK(y),
  571. - MK(z),
  572. + MK(X),
  573. + MK(Y),
  574. + MK(Z),
  575.   MK(LEFTBRACKET),  // Left bracket
  576. - MK(PLUS),     // Yen
  577. + MK(GRAVE),        // Yen
  578.   MK(RIGHTBRACKET), // Right bracket
  579.   MK(EQUALS),       // Caret
  580.  
  581. @@ -272,7 +272,7 @@ static const ButtConfig TsushinKBConfig[0x80]=
  582.  // 7
  583.   MK(8),
  584.   MK(9),
  585. - MK(QUOTE),        // Colon
  586. + MK(APOSTROPHE),       // Colon
  587.   MK(SEMICOLON),        // Semicolon
  588.   MK(COMMA),        // Comma
  589.   MK(PERIOD),       // Period
  590. @@ -284,11 +284,11 @@ static const ButtConfig TsushinKBConfig[0x80]=
  591.   MK(RIGHT),
  592.   //MK(UNKNOWN),
  593.   MK(UNKNOWN),      // GRPH
  594. - MK(LSUPER),       // カナ
  595. + //MK(LSUPER),     // カナ
  596.   //MK(UNKNOWN),
  597.  
  598.  // 9
  599. - MK(BREAK),        // STOP
  600. + MK(STOP),     // STOP
  601.   MK(F1),
  602.   MK(F2),
  603.   MK(F3),
  604. @@ -301,7 +301,7 @@ static const ButtConfig TsushinKBConfig[0x80]=
  605.   MK(DOWN),
  606.   MK(LEFT),
  607.   MK(END),      // HELP
  608. - MK(PRINT),        // COPY
  609. + MK(PRINTSCREEN),      // COPY
  610.   MK(KP_MINUS),
  611.   MK(KP_DIVIDE),
  612.  
  613. @@ -310,9 +310,9 @@ static const ButtConfig TsushinKBConfig[0x80]=
  614.   MK(PAGEUP),       // ROLL UP
  615.   //MK(UNKNOWN),
  616.   //MK(UNKNOWN),
  617. - MK(o),
  618. + MK(O),
  619.   MK(UNKNOWN),  // TODO: Underscore
  620. - MK(g),
  621. + MK(G),
  622.  
  623.  // C
  624.   MK(F6),
  625. @@ -326,11 +326,11 @@ static const ButtConfig TsushinKBConfig[0x80]=
  626.  // D
  627.   MK(RALT),     // 変換
  628.   MK(LALT),     // 決定
  629. - MK(RSUPER),       // PC
  630. + //MK(RSUPER),     // PC
  631.   MK(RCTRL),        // 変換
  632.   MK(LCTRL),        // CTRL
  633. - MK(KP7),
  634. - MK(w),
  635. + MK(KP_7),
  636. + MK(W),
  637.  
  638.  // E
  639.   MK(RETURN),
  640. @@ -354,7 +354,7 @@ static const ButtConfig TsushinKBConfig[0x80]=
  641.  
  642.  static const ButtConfig MMPlayInputConfig[] =
  643.  {
  644. -   MK(p),
  645. +   MK(P),
  646.     MK(LEFT),
  647.     MK(RIGHT),
  648.     MK(DOWN),
  649. @@ -376,25 +376,25 @@ static const ButtConfig CDPlayInputConfig[] =
  650.  
  651.  static const ButtConfig MDPad3Config[2][8] =
  652.  {
  653. - { MK(w), MK(s), MK(a), MK(d), MK(KP2), MK(KP3), MK(KP1), MK(RETURN) },
  654. + { MK(W), MK(S), MK(A), MK(D), MK(KP_2), MK(KP_3), MK(KP_1), MK(RETURN) },
  655.   { MKZ(), MKZ(), MKZ(), MKZ(), MKZ(),   MKZ(),   MKZ(),   MKZ() },
  656.  
  657.  };
  658.  
  659.  static const ButtConfig SNESPadConfig[12] =
  660.  {
  661. - MK(KP2),
  662. - MK(KP4),
  663. + MK(KP_2),
  664. + MK(KP_4),
  665.   MK(TAB),
  666.   MK(RETURN),
  667. - MK(w),
  668. - MK(s),
  669. - MK(a),
  670. - MK(d),
  671. - MK(KP6),
  672. - MK(KP8),
  673. - MK(KP7),
  674. - MK(KP9),
  675. + MK(W),
  676. + MK(S),
  677. + MK(A),
  678. + MK(D),
  679. + MK(KP_6),
  680. + MK(KP_8),
  681. + MK(KP_7),
  682. + MK(KP_9),
  683.  };
  684.  
  685.  
  686. @@ -440,35 +440,35 @@ static const ButtConfig PSXPadConfig[14] =
  687.  {
  688.   MK(TAB),
  689.   MK(RETURN),
  690. - MK(w),
  691. - MK(d),
  692. - MK(s),
  693. - MK(a),
  694. + MK(W),
  695. + MK(D),
  696. + MK(S),
  697. + MK(A),
  698.  
  699. - MK(KP7),
  700. - MK(KP9),
  701. - MK(KP1),
  702. - MK(KP3),
  703. + MK(KP_7),
  704. + MK(KP_9),
  705. + MK(KP_1),
  706. + MK(KP_3),
  707.  
  708. - MK(KP8),
  709. - MK(KP6),
  710. - MK(KP2),
  711. - MK(KP4),
  712. + MK(KP_8),
  713. + MK(KP_6),
  714. + MK(KP_2),
  715. + MK(KP_4),
  716.  };
  717.  
  718.  static const ButtConfig PSXDancePadConfig[10] =
  719.  {
  720.   MK(KP_DIVIDE),
  721.   MK(KP_MULTIPLY),
  722. - MK(KP8),
  723. - MK(KP6),
  724. - MK(KP2),
  725. - MK(KP4),
  726. -
  727. - MK(KP1),
  728. - MK(KP9),
  729. - MK(KP7),
  730. - MK(KP3),
  731. + MK(KP_8),
  732. + MK(KP_6),
  733. + MK(KP_2),
  734. + MK(KP_4),
  735. +
  736. + MK(KP_1),
  737. + MK(KP_9),
  738. + MK(KP_7),
  739. + MK(KP_3),
  740.  };
  741.  
  742.  static ButtConfig PSXMouseConfig[2] =
  743. diff --git a/src/drivers/input.cpp b/src/drivers/input.cpp
  744. index be2756f..cbfcfab 100644
  745. --- a/src/drivers/input.cpp
  746. +++ b/src/drivers/input.cpp
  747. @@ -690,7 +690,7 @@ static const COKE CKeys[_CK_COUNT]  =
  748.     { MK_CK(F7), "load_state", ~0U, 0, gettext_noop("Load state") },
  749.     { MK_CK_SHIFT(F5), "save_movie", ~0U, 1, gettext_noop("Save movie") },
  750.     { MK_CK_SHIFT(F7), "load_movie", ~0U, 0, gettext_noop("Load movie") },
  751. -   { MK_CK_ALT(s), "toggle_state_rewind", ~0U, 1, gettext_noop("Toggle state rewind functionality") },
  752. +   { MK_CK_ALT(S), "toggle_state_rewind", ~0U, 1, gettext_noop("Toggle state rewind functionality") },
  753.  
  754.     { MK_CK(0), "0", ~0U, 1, gettext_noop("Save state 0 select")},
  755.          { MK_CK(1), "1", ~0U, 1, gettext_noop("Save state 1 select")},
  756. @@ -728,7 +728,7 @@ static const COKE CKeys[_CK_COUNT]  =
  757.     { MK_CK_SHIFT(F9), "take_scaled_snapshot", ~0U, 1, gettext_noop("Take scaled(and filtered) screen snapshot") },
  758.  
  759.     { MK_CK_ALT(RETURN), "toggle_fs", ~0U, 1, gettext_noop("Toggle fullscreen mode") },
  760. -   { MK_CK(BACKQUOTE), "fast_forward", ~0U, 1, gettext_noop("Fast-forward") },
  761. +   { MK_CK(GRAVE), "fast_forward", ~0U, 1, gettext_noop("Fast-forward") },
  762.          { MK_CK(BACKSLASH), "slow_forward", ~0U, 1, gettext_noop("Slow-forward") },
  763.  
  764.     { MK_CK(F8), "insert_coin", ~0U, 1, gettext_noop("Insert coin") },
  765. @@ -736,8 +736,8 @@ static const COKE CKeys[_CK_COUNT]  =
  766.     { MK_CK(F6), "select_disk", ~0U, 1, gettext_noop("Select disk/disc") },
  767.     { MK_CK(F8), "insert_eject_disk", ~0U, 0, gettext_noop("Insert/Eject disk/disc") },
  768.     { MK_CK(F8), "activate_barcode", ~0U, 1, gettext_noop("Activate barcode(for Famicom)") },
  769. -   { MK_CK(SCROLLOCK), "toggle_grab_input", ~0U, 1, gettext_noop("Grab input") },
  770. -   { MK_CK_SHIFT(SCROLLOCK), "toggle_cidisable", ~0U, 1, gettext_noop("Grab input and disable commands") },
  771. +   { MK_CK(SCROLLLOCK), "toggle_grab_input", ~0U, 1, gettext_noop("Grab input") },
  772. +   { MK_CK_SHIFT(SCROLLLOCK), "toggle_cidisable", ~0U, 1, gettext_noop("Grab input and disable commands") },
  773.     { MK_CK_ALT_SHIFT(1), "input_config1", ~0U, 0, gettext_noop("Configure buttons on virtual port 1") },
  774.     { MK_CK_ALT_SHIFT(2), "input_config2", ~0U, 0, gettext_noop("Configure buttons on virtual port 2")  },
  775.          { MK_CK_ALT_SHIFT(3), "input_config3", ~0U, 0, gettext_noop("Configure buttons on virtual port 3")  },
  776. @@ -755,15 +755,15 @@ static const COKE CKeys[_CK_COUNT]    =
  777.     { MK_CK(F11), "power", ~0U, 0, gettext_noop("Power toggle") },
  778.     { MK_CK2(F12, ESCAPE), "exit", ~0U, 0, gettext_noop("Exit") },
  779.     { MK_CK(BACKSPACE), "state_rewind", ~0U, 1, gettext_noop("Rewind") },
  780. -   { MK_CK_ALT(o), "rotate_screen", ~0U, 1, gettext_noop("Rotate screen") },
  781. +   { MK_CK_ALT(O), "rotate_screen", ~0U, 1, gettext_noop("Rotate screen") },
  782.  
  783. -   { MK_CK(t), "togglenetview", ~0U, 1, gettext_noop("Toggle netplay console")},
  784. -   { MK_CK_ALT(a), "advance_frame", ~0U, 1, gettext_noop("Advance frame") },
  785. -   { MK_CK_ALT(r), "run_normal", ~0U, 1, gettext_noop("Return to normal mode after advancing frames") },
  786. -   { MK_CK_ALT(c), "togglecheatview", ~0U, 1, gettext_noop("Toggle cheat console") },
  787. -   { MK_CK_ALT(t), "togglecheatactive", ~0U, 1, gettext_noop("Enable/Disable cheats") },
  788. +   { MK_CK(T), "togglenetview", ~0U, 1, gettext_noop("Toggle netplay console")},
  789. +   { MK_CK_ALT(A), "advance_frame", ~0U, 1, gettext_noop("Advance frame") },
  790. +   { MK_CK_ALT(R), "run_normal", ~0U, 1, gettext_noop("Return to normal mode after advancing frames") },
  791. +   { MK_CK_ALT(C), "togglecheatview", ~0U, 1, gettext_noop("Toggle cheat console") },
  792. +   { MK_CK_ALT(T), "togglecheatactive", ~0U, 1, gettext_noop("Enable/Disable cheats") },
  793.          { MK_CK_SHIFT(F1), "toggle_fps_view", ~0U, 1, gettext_noop("Toggle frames-per-second display") },
  794. -   { MK_CK_ALT(d), "toggle_debugger", ~0U, 1, gettext_noop("Toggle debugger") },
  795. +   { MK_CK_ALT(D), "toggle_debugger", ~0U, 1, gettext_noop("Toggle debugger") },
  796.     { MK_CK(MINUS), "state_slot_dec", ~0U, 1, gettext_noop("Decrease selected save state slot by 1") },
  797.     { MK_CK(EQUALS), "state_slot_inc", ~0U, 1, gettext_noop("Increase selected save state slot by 1") },
  798.     { MK_CK(F1), "toggle_help", ~0U, 1, gettext_noop("Toggle help screen") },
  799. @@ -932,7 +932,7 @@ static void UpdatePhysicalDeviceState(void)
  800.   //
  801.  
  802.  
  803. - memcpy(keys, SDL_GetKeyState(0), MKK_COUNT);
  804. + memcpy(keys, SDL_GetKeyboardState(0), MKK_COUNT);
  805.  
  806.   if(MDFNDHaveFocus || MDFN_GetSettingB("input.joystick.global_focus"))
  807.    joy_manager->UpdateJoysticks();
  808. @@ -1000,21 +1000,21 @@ static void DoKeyStateZeroing(void)
  809.      memcpy(keys_backup, keys, MKK_COUNT);
  810.      memset(keys, 0, sizeof(keys));
  811.  
  812. -    keys[SDLK_F1] = keys_backup[SDLK_F1];
  813. -    keys[SDLK_F2] = keys_backup[SDLK_F2];
  814. -    keys[SDLK_F3] = keys_backup[SDLK_F3];
  815. -    keys[SDLK_F4] = keys_backup[SDLK_F4];
  816. -    keys[SDLK_F5] = keys_backup[SDLK_F5];
  817. -    keys[SDLK_F6] = keys_backup[SDLK_F6];
  818. -    keys[SDLK_F7] = keys_backup[SDLK_F7];
  819. -    keys[SDLK_F8] = keys_backup[SDLK_F8];
  820. -    keys[SDLK_F9] = keys_backup[SDLK_F9];
  821. -    keys[SDLK_F10] = keys_backup[SDLK_F10];
  822. -    keys[SDLK_F11] = keys_backup[SDLK_F11];
  823. -    keys[SDLK_F12] = keys_backup[SDLK_F12];
  824. -    keys[SDLK_F13] = keys_backup[SDLK_F13];
  825. -    keys[SDLK_F14] = keys_backup[SDLK_F14];
  826. -    keys[SDLK_F15] = keys_backup[SDLK_F15];
  827. +    keys[SDL_SCANCODE_F1] = keys_backup[SDL_SCANCODE_F1];
  828. +    keys[SDL_SCANCODE_F2] = keys_backup[SDL_SCANCODE_F2];
  829. +    keys[SDL_SCANCODE_F3] = keys_backup[SDL_SCANCODE_F3];
  830. +    keys[SDL_SCANCODE_F4] = keys_backup[SDL_SCANCODE_F4];
  831. +    keys[SDL_SCANCODE_F5] = keys_backup[SDL_SCANCODE_F5];
  832. +    keys[SDL_SCANCODE_F6] = keys_backup[SDL_SCANCODE_F6];
  833. +    keys[SDL_SCANCODE_F7] = keys_backup[SDL_SCANCODE_F7];
  834. +    keys[SDL_SCANCODE_F8] = keys_backup[SDL_SCANCODE_F8];
  835. +    keys[SDL_SCANCODE_F9] = keys_backup[SDL_SCANCODE_F9];
  836. +    keys[SDL_SCANCODE_F10] = keys_backup[SDL_SCANCODE_F10];
  837. +    keys[SDL_SCANCODE_F11] = keys_backup[SDL_SCANCODE_F11];
  838. +    keys[SDL_SCANCODE_F12] = keys_backup[SDL_SCANCODE_F12];
  839. +    keys[SDL_SCANCODE_F13] = keys_backup[SDL_SCANCODE_F13];
  840. +    keys[SDL_SCANCODE_F14] = keys_backup[SDL_SCANCODE_F14];
  841. +    keys[SDL_SCANCODE_F15] = keys_backup[SDL_SCANCODE_F15];
  842.     }
  843.   }
  844.  }
  845. diff --git a/src/drivers/input.h b/src/drivers/input.h
  846. index b18a693..667b2d1 100644
  847. --- a/src/drivers/input.h
  848. +++ b/src/drivers/input.h
  849. @@ -13,8 +13,8 @@ typedef struct {
  850.  #define BUTTC_JOYSTICK          0x02
  851.  #define BUTTC_MOUSE             0x03
  852.  
  853. -#define MKK(k) SDLK_##k
  854. -#define MKK_COUNT (SDLK_LAST+1)
  855. +#define MKK(k) SDL_SCANCODE_##k
  856. +#define MKK_COUNT (SDL_NUM_SCANCODES+1)
  857.  
  858.  void Input_Event(const SDL_Event *event);
  859.  void MainSetEventHook(int (*eh)(const SDL_Event *event));  // TODO: factor out eventually.
  860. diff --git a/src/drivers/main.cpp b/src/drivers/main.cpp
  861. index 5235428..c487b72 100644
  862. --- a/src/drivers/main.cpp
  863. +++ b/src/drivers/main.cpp
  864. @@ -1298,30 +1298,12 @@ bool GT_ReinitSound(void)
  865.   return(ret);
  866.  }
  867.  
  868. -static bool krepeat = 0;
  869.  void PumpWrap(void)
  870.  {
  871.   SDL_Event event;
  872.   SDL_Event gtevents_temp[gtevents_size];
  873.   int numevents = 0;
  874.  
  875. - bool NITI;
  876. -
  877. - NITI = Netplay_IsTextInput();
  878. -
  879. - if(Debugger_IsActive() || NITI || CheatIF_Active() || Help_IsActive())
  880. - {
  881. -  if(!krepeat)
  882. -   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
  883. -  krepeat = 1;
  884. - }
  885. - else
  886. - {
  887. -  if(krepeat)
  888. -   SDL_EnableKeyRepeat(0, 0);
  889. -  krepeat = 0;
  890. - }
  891. -
  892.   #if defined(HAVE_SIGNAL) || defined(HAVE_SIGACTION)
  893.   if(SignalSafeExitWanted)
  894.    NeedExitNow = true;
  895. @@ -1337,24 +1319,34 @@ void PumpWrap(void)
  896.    /* Handle the event, and THEN hand it over to the GUI. Order is important due to global variable mayhem(CEVT_TOGGLEFS. */
  897.    switch(event.type)
  898.    {
  899. -   case SDL_ACTIVEEVENT:
  900. -               if(event.active.state & SDL_APPINPUTFOCUS)
  901. -           {
  902. -            SendCEvent_to_GT(CEVT_SET_INPUT_FOCUS, (char*)0 + (bool)event.active.gain, NULL);
  903. -           }
  904. -
  905. -           if(event.active.state & SDL_APPACTIVE)
  906. -           {
  907. -            VideoAppActive((bool)(event.active.gain));
  908. -           }
  909. +   case SDL_WINDOWEVENT:
  910. +       switch(event.window.event) {
  911. +          case SDL_WINDOWEVENT_ENTER:
  912. +          case SDL_WINDOWEVENT_SHOWN:
  913. +            VideoAppActive((bool)(1));
  914. +               //printf("windowevent enter/shown\n");
  915. +           break;
  916. +          case SDL_WINDOWEVENT_LEAVE:
  917. +          case SDL_WINDOWEVENT_HIDDEN:
  918. +               //printf("windowevent leave/hidden\n");
  919. +            VideoAppActive((bool)(0));
  920. +           break;
  921. +          case SDL_WINDOWEVENT_FOCUS_GAINED:
  922. +               //printf("windowevent focus gained\n");
  923. +            SendCEvent_to_GT(CEVT_SET_INPUT_FOCUS, (char*)0 + (bool)1, NULL);
  924. +           break;
  925. +          case SDL_WINDOWEVENT_FOCUS_LOST:
  926. +               //printf("windowevent focus lost\n");
  927. +            SendCEvent_to_GT(CEVT_SET_INPUT_FOCUS, (char*)0 + (bool)0, NULL);
  928.             break;
  929. +       }
  930. +       break;
  931.  
  932.     case SDL_SYSWMEVENT: break;
  933.     //case SDL_VIDEORESIZE: //if(VideoResize(event.resize.w, event.resize.h))
  934.              // NeedVideoChange = -1;
  935.     //           break;
  936.  
  937. -   case SDL_VIDEOEXPOSE: break;
  938.     case SDL_QUIT: NeedExitNow = 1;break;
  939.     case SDL_USEREVENT:
  940.         switch(event.user.code)
  941. @@ -1370,12 +1362,18 @@ void PumpWrap(void)
  942.              }
  943.              break;
  944.              case CEVT_SET_GRAB_INPUT:
  945. -                         SDL_WM_GrabInput(*(int *)event.user.data1 ? SDL_GRAB_ON : SDL_GRAB_OFF);
  946. +                         if(window != NULL) {
  947. +                             SDL_SetWindowGrab(window ,*(int *)event.user.data1 ? SDL_TRUE : SDL_FALSE);
  948. +                         }
  949.                           free(event.user.data1);
  950.                           break;
  951.          //case CEVT_TOGGLEFS: NeedVideoChange = 1; break;
  952.          //case CEVT_VIDEOSYNC: NeedVideoChange = -1; break;
  953. -        case CEVT_SHOWCURSOR: SDL_ShowCursor(*(int *)event.user.data1); free(event.user.data1); break;
  954. +        case CEVT_SHOWCURSOR:
  955. +                        SDL_SetRelativeMouseMode((int *)event.user.data1 ? SDL_FALSE : SDL_TRUE);
  956. +           SDL_ShowCursor(*(int *)event.user.data1);
  957. +           free(event.user.data1);
  958. +           break;
  959.          case CEVT_DISP_MESSAGE: VideoShowMessage((UTF8*)event.user.data1); break;
  960.          default:
  961.             if(numevents < gtevents_size)
  962. @@ -1425,9 +1423,13 @@ void PrintCompilerVersion(void)
  963.  
  964.  void PrintSDLVersion(void)
  965.  {
  966. - const SDL_version *sver = SDL_Linked_Version();
  967. + SDL_version sver_compiled;
  968. + SDL_version sver_linked;
  969.  
  970. - MDFN_printf(_("Compiled against SDL %u.%u.%u, running with SDL %u.%u.%u\n"), SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, sver->major, sver->minor, sver->patch);
  971. + SDL_VERSION(&sver_compiled);
  972. + SDL_GetVersion(&sver_linked);
  973. +
  974. + MDFN_printf(_("Compiled against SDL %u.%u.%u, running with SDL %u.%u.%u\n"), sver_compiled.major, sver_compiled.minor, sver_compiled.patch, sver_linked.major, sver_linked.minor, sver_linked.patch);
  975.  }
  976.  
  977.  #ifdef HAVE_LIBSNDFILE
  978. @@ -1727,8 +1729,6 @@ int main(int argc, char *argv[])
  979.          if(!MDFNI_Initialize(DrBaseDirectory, NeoDriverSettings))
  980.           return(-1);
  981.  
  982. -        SDL_EnableUNICODE(1);
  983. -
  984.          #if defined(HAVE_SIGNAL) || defined(HAVE_SIGACTION)
  985.          SetSignals(CloseStuff);
  986.          #endif
  987. @@ -1879,8 +1879,11 @@ for(int zgi = 1; zgi < argc; zgi++)// start game load test loop
  988.           }
  989.  
  990.      PumpWrap();
  991. -    if(DidVideoChange) // Do it after PumpWrap() in case there are stale SDL_ActiveEvent in the SDL event queue.
  992. -     SendCEvent_to_GT(CEVT_SET_INPUT_FOCUS, (char*)0 + (bool)(SDL_GetAppState() & SDL_APPINPUTFOCUS), NULL);
  993. +         //FIXME: Is this necessary? Got no problems without it.
  994. +    /*if(DidVideoChange) { // Do it after PumpWrap() in case there are stale SDL_ActiveEvent in the SDL event queue.
  995. +     //SendCEvent_to_GT(CEVT_SET_INPUT_FOCUS, (char*)0 + (bool)(SDL_GetAppState() & SDL_APPINPUTFOCUS), NULL);
  996. +     SendCEvent_to_GT(CEVT_SET_INPUT_FOCUS, (char*)0 + (bool)(1), NULL);
  997. +     }*/
  998.  
  999.           MDFND_UnlockMutex(VTMutex);   /* Unlock mutex */
  1000.  
  1001. diff --git a/src/drivers/memdebugger.cpp b/src/drivers/memdebugger.cpp
  1002. index 5cd80e8..105abf1 100644
  1003. --- a/src/drivers/memdebugger.cpp
  1004. +++ b/src/drivers/memdebugger.cpp
  1005. @@ -39,12 +39,6 @@ bool MemDebugger::ICV_Init(const char *newcode)
  1006.    ict_to_utf8 = (iconv_t)-1;
  1007.   }
  1008.  
  1009. - if((size_t)ict_utf16_to_game != (size_t)-1)
  1010. - {
  1011. -  iconv_close(ict_utf16_to_game);
  1012. -  ict_utf16_to_game = (iconv_t)-1;
  1013. - }
  1014. -
  1015.   ict = iconv_open(newcode, "UTF-8");
  1016.   if((size_t)ict == (size_t)-1)
  1017.   {
  1018. @@ -61,14 +55,6 @@ bool MemDebugger::ICV_Init(const char *newcode)
  1019.    return(0);
  1020.   }
  1021.  
  1022. - ict_utf16_to_game = iconv_open(newcode, "UTF-16");
  1023. - if((size_t)ict_utf16_to_game == (size_t)-1)
  1024. - {
  1025. -  error_string = trio_aprintf("iconv_open() error: %m");
  1026. -  error_time = SDL_GetTicks();
  1027. -  return(0);
  1028. - }
  1029. -
  1030.   GameCode = std::string(newcode);
  1031.   return(1);
  1032.  }
  1033. @@ -825,32 +811,9 @@ int MemDebugger::Event(const SDL_Event *event)
  1034.           myprompt->Event(event);
  1035.          }
  1036.     else if(InEditMode && InTextArea && keysym != SDLK_TAB && keysym != SDLK_INSERT && keysym != SDLK_UP && keysym != SDLK_DOWN && keysym != SDLK_LEFT
  1037. -    && keysym != SDLK_RIGHT && (event->key.keysym.unicode >= 0x20))
  1038. +    && keysym != SDLK_RIGHT)
  1039.     {
  1040. -    uint8 to_write[16];
  1041. -    int to_write_len;
  1042. -
  1043. -    size_t ibl, obl, obl_start;
  1044. -    char *inbuf, *outbuf;
  1045. -
  1046. -    ibl = 2;
  1047. -    obl_start = obl = 16;
  1048. -
  1049. -    inbuf = (char *)&event->key.keysym.unicode;
  1050. -    outbuf = (char*)to_write;
  1051. -
  1052. -    size_t result = iconv(ict_utf16_to_game, (ICONV_CONST char **)&inbuf, &ibl, &outbuf, &obl);
  1053. -    if(result != (size_t)-1)
  1054. -    {
  1055. -          to_write_len = obl_start - obl;
  1056. -
  1057. -    
  1058. -     ASpace->PutAddressSpaceBytes(ASpace->name.c_str(), ASpacePos[CurASpace], to_write_len, 1, TRUE, to_write);
  1059. -    
  1060. -
  1061. -     LowNib = 0;
  1062. -     ChangePos(to_write_len);
  1063. -    }
  1064. +            //Handled by SDL_TEXTINPUT Event
  1065.     }
  1066.     else if(InEditMode && ((event->key.keysym.sym >= SDLK_0 && event->key.keysym.sym <= SDLK_9) ||
  1067.        (event->key.keysym.sym >= SDLK_a && event->key.keysym.sym <= SDLK_f)))
  1068. @@ -994,6 +957,37 @@ int MemDebugger::Event(const SDL_Event *event)
  1069.               break;
  1070.     }
  1071.     break;
  1072. +
  1073. +  case SDL_TEXTINPUT:
  1074. +   if(InPrompt)
  1075. +   {
  1076. +    myprompt->Event(event);
  1077. +   }
  1078. +   else if(InEditMode && InTextArea) {
  1079. +    uint8 to_write[16];
  1080. +    int to_write_len;
  1081. +
  1082. +    size_t ibl, obl, obl_start;
  1083. +    char *inbuf, *outbuf;
  1084. +
  1085. +    inbuf = (char *)&event->text.text;
  1086. +    outbuf = (char*)to_write;
  1087. +
  1088. +    ibl = strlen(inbuf);
  1089. +    obl_start = obl = (ibl + 1) * 8; // Hehe, ugly maximum estimation!
  1090. +
  1091. +    size_t result = iconv(ict, (ICONV_CONST char **)&inbuf, &ibl, &outbuf, &obl);
  1092. +    if(result != (size_t)-1)
  1093. +    {
  1094. +      to_write_len = obl_start - obl;
  1095. +
  1096. +      ASpace->PutAddressSpaceBytes(ASpace->name.c_str(), ASpacePos[CurASpace], to_write_len, 1, TRUE, to_write);
  1097. +
  1098. +      LowNib = 0;
  1099. +      ChangePos(to_write_len);
  1100. +    }
  1101. +   }
  1102. +   break;
  1103.   }
  1104.   return(1);
  1105.  }
  1106. @@ -1002,7 +996,7 @@ int MemDebugger::Event(const SDL_Event *event)
  1107.  // Called after a game is loaded.
  1108.  MemDebugger::MemDebugger() : AddressSpaces(NULL), ASpace(NULL), IsActive(false), CurASpace(0),
  1109.                  LowNib(false), InEditMode(false), InTextArea(false), error_string(NULL), error_time(0),
  1110. -                ict((iconv_t)-1), ict_to_utf8((iconv_t)-1), ict_utf16_to_game((iconv_t)-1), InPrompt(None), myprompt(NULL)              
  1111. +                ict((iconv_t)-1), ict_to_utf8((iconv_t)-1), InPrompt(None), myprompt(NULL)              
  1112.  {
  1113.   if(CurGame->Debugger)
  1114.   {
  1115. @@ -1047,12 +1041,6 @@ MemDebugger::~MemDebugger()
  1116.    ict_to_utf8 = (iconv_t)-1;
  1117.   }
  1118.  
  1119. - if(ict_utf16_to_game != (iconv_t)-1)
  1120. - {
  1121. -  iconv_close(ict_utf16_to_game);
  1122. -  ict_utf16_to_game = (iconv_t)-1;
  1123. - }
  1124. -
  1125.   if(error_string)
  1126.   {
  1127.    free(error_string);
  1128. diff --git a/src/drivers/memdebugger.h b/src/drivers/memdebugger.h
  1129. index 36d69d5..4b71e55 100644
  1130. --- a/src/drivers/memdebugger.h
  1131. +++ b/src/drivers/memdebugger.h
  1132. @@ -65,7 +65,6 @@ class MemDebugger
  1133.  
  1134.   iconv_t ict;
  1135.   iconv_t ict_to_utf8;
  1136. - iconv_t ict_utf16_to_game;
  1137.  
  1138.   std::string GameCode;
  1139.  
  1140. diff --git a/src/drivers/opengl.cpp b/src/drivers/opengl.cpp
  1141. index 379e009..ba01c5b 100644
  1142. --- a/src/drivers/opengl.cpp
  1143. +++ b/src/drivers/opengl.cpp
  1144. @@ -587,7 +587,7 @@ OpenGL_Blitter::OpenGL_Blitter(int scanlines, ShaderType pixshader, const int sc
  1145.   {
  1146.   const char *extensions;
  1147.   const char *vendor;
  1148. - const char *renderer;
  1149. + const char *glrenderer;
  1150.   const char *version;
  1151.   uint32 version_h;
  1152.  
  1153. @@ -660,7 +660,7 @@ OpenGL_Blitter::OpenGL_Blitter(int scanlines, ShaderType pixshader, const int sc
  1154.   LFG(glReadPixels);
  1155.  
  1156.   vendor = (const char *)p_glGetString(GL_VENDOR);
  1157. - renderer = (const char *)p_glGetString(GL_RENDERER);
  1158. + glrenderer = (const char *)p_glGetString(GL_RENDERER);
  1159.   version = (const char *)p_glGetString(GL_VERSION);
  1160.  
  1161.   {
  1162. @@ -673,7 +673,7 @@ OpenGL_Blitter::OpenGL_Blitter(int scanlines, ShaderType pixshader, const int sc
  1163.    //printf("%08x\n", version_h);
  1164.   }
  1165.  
  1166. - MDFN_printf(_("OpenGL Implementation: %s %s %s\n"), vendor, renderer, version);
  1167. + MDFN_printf(_("OpenGL Implementation: %s %s %s\n"), vendor, glrenderer, version);
  1168.  
  1169.   extensions = (const char*)p_glGetString(GL_EXTENSIONS);
  1170.  
  1171. diff --git a/src/drivers/overlay.cpp b/src/drivers/overlay.cpp
  1172. index 207926f..62582cc 100644
  1173. --- a/src/drivers/overlay.cpp
  1174. +++ b/src/drivers/overlay.cpp
  1175. @@ -22,17 +22,17 @@
  1176.  #include "nnx.h"
  1177.  #include <math.h>
  1178.  
  1179. -static SDL_Overlay *ov = NULL;
  1180. -
  1181. +static SDL_Texture *ov = NULL;
  1182.  
  1183.  void OV_Blit(MDFN_Surface *src_surface, const MDFN_Rect *src_rect, const MDFN_Rect *original_src_rect,
  1184. -   const SDL_Rect *dest_rect, SDL_Surface *dest_surface, int softscale, int scanlines, int rotated)
  1185. +   const SDL_Rect *dest_rect, int softscale, int scanlines, int rotated)
  1186.  {
  1187.   const uint32 spitch32 = src_surface->pitchinpix;
  1188. - SDL_Rect drect = *dest_rect;
  1189.   uint16 *dpixels;
  1190.   uint32 dpitch16;
  1191.   int32 need_w, need_h;
  1192. + int32 ov_w=0;
  1193. + int32 ov_h=0;
  1194.  
  1195.   if(softscale < 1)
  1196.    softscale = 1;
  1197. @@ -53,31 +53,39 @@ void OV_Blit(MDFN_Surface *src_surface, const MDFN_Rect *src_rect, const MDFN_Re
  1198.  
  1199.   need_w = (need_w + 1) & ~1;
  1200.  
  1201. - if(!ov || ov->w != need_w || ov->h != need_h)
  1202. + if(ov) {
  1203. +    SDL_QueryTexture(ov, NULL, NULL, &ov_w, &ov_h);
  1204. + }
  1205. +
  1206. + if(!ov || ov_w != need_w || ov_h != need_h)
  1207.   {
  1208.    if(ov)
  1209.    {
  1210. -   SDL_FreeYUVOverlay(ov);
  1211. +   SDL_DestroyTexture(ov);
  1212.     ov = NULL;
  1213.    }
  1214. -  if(!(ov = SDL_CreateYUVOverlay(need_w, need_h, SDL_YUY2_OVERLAY, dest_surface)))
  1215. +  if(!(ov = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, need_w, need_h)))
  1216.    {
  1217.     puts("Overlay creation failure");
  1218.     return;
  1219.    }
  1220. -  printf("Overlay Created: %d %d %d\n", ov->hw_overlay, ov->w, ov->h);
  1221. +  SDL_QueryTexture(ov, NULL, NULL, &ov_w, &ov_h);
  1222. +  printf("Overlay Created: %d %d\n", ov_w, ov_h);
  1223.   }
  1224.  
  1225. - if(SDL_LockYUVOverlay(ov) != 0)
  1226. + void* pixels;
  1227. + int pitch;
  1228. + if(SDL_LockTexture(ov, NULL, &pixels, &pitch) != 0)
  1229.   {
  1230.    puts("Lock failure");
  1231.    return;
  1232.   }
  1233. - dpixels = (uint16 *)ov->pixels[0];
  1234.  
  1235. - assert(!(ov->pitches[0] & 1));
  1236. + dpixels = (uint16 *)pixels;
  1237. +
  1238. + assert(!(pitch & 1));
  1239.  
  1240. - dpitch16 = ov->pitches[0] >> 1;
  1241. + dpitch16 = pitch >> 1;
  1242.  
  1243.   if(rotated == MDFN_ROTATE90)
  1244.   {
  1245. @@ -286,19 +294,21 @@ void OV_Blit(MDFN_Surface *src_surface, const MDFN_Rect *src_rect, const MDFN_Re
  1246.     }
  1247.    } // End else to softscale
  1248.   }
  1249. - SDL_UnlockYUVOverlay(ov);
  1250. + SDL_UnlockTexture(ov);
  1251.  
  1252. - if(SDL_DisplayYUVOverlay(ov, &drect) != 0)
  1253. + if(SDL_UpdateTexture(ov, NULL, dpixels, pitch) != 0)
  1254.   {
  1255.    puts("Blit error");
  1256.   }
  1257. + SDL_RenderCopy(renderer, ov, NULL, dest_rect);
  1258. + SDL_RenderPresent(renderer);
  1259.  }
  1260.  
  1261.  void OV_Kill(void)
  1262.  {
  1263.   if(ov)
  1264.   {
  1265. -  SDL_FreeYUVOverlay(ov);
  1266. +  SDL_DestroyTexture(ov);
  1267.    ov = NULL;
  1268.   }
  1269.  }
  1270. diff --git a/src/drivers/overlay.h b/src/drivers/overlay.h
  1271. index 7c5f53d..d4d04f4 100644
  1272. --- a/src/drivers/overlay.h
  1273. +++ b/src/drivers/overlay.h
  1274. @@ -2,7 +2,7 @@
  1275.  #define __MDFN_DRIVERS_OVERLAY_H
  1276.  
  1277.  void OV_Blit(MDFN_Surface *src_surface, const MDFN_Rect *src_rect, const MDFN_Rect *original_src_rect,
  1278. -        const SDL_Rect *dest_rect, SDL_Surface *dest_surface, int softscale, int scanlines, int rotated);
  1279. +        const SDL_Rect *dest_rect, int softscale, int scanlines, int rotated);
  1280.  
  1281.  void OV_Kill(void);
  1282.  
  1283. diff --git a/src/drivers/prompt.cpp b/src/drivers/prompt.cpp
  1284. index 43bea5b..afd1576 100644
  1285. --- a/src/drivers/prompt.cpp
  1286. +++ b/src/drivers/prompt.cpp
  1287. @@ -25,6 +25,7 @@ HappyPrompt::HappyPrompt(void)
  1288.          PromptText = "";
  1289.     kb_buffer.clear();
  1290.          kb_cursor_pos = 0;
  1291. +        firstText = true;
  1292.  }
  1293.  
  1294.  HappyPrompt::HappyPrompt(const std::string &ptext, const std::string &zestring)
  1295. @@ -32,6 +33,7 @@ HappyPrompt::HappyPrompt(const std::string &ptext, const std::string &zestring)
  1296.          PromptText = "";
  1297.          kb_buffer.clear();
  1298.          kb_cursor_pos = 0;
  1299. +        firstText = true;
  1300.     SetText(ptext);
  1301.     SetKBB(zestring);
  1302.  }
  1303. @@ -197,13 +199,15 @@ void HappyPrompt::Event(const SDL_Event *event)
  1304.                   kb_buffer.erase(kb_buffer.begin() + kb_cursor_pos, kb_buffer.begin() + kb_cursor_pos + 1);
  1305.                  }
  1306.                  break;
  1307. -          default:
  1308. -           if(event->key.keysym.unicode)
  1309. -           {
  1310. -            kb_buffer.insert(kb_buffer.begin() + kb_cursor_pos, event->key.keysym.unicode);
  1311. -            kb_cursor_pos++;
  1312. -           }
  1313. -           break;
  1314.    }
  1315.   }
  1316. + if(event->type == SDL_TEXTINPUT) {
  1317. +   //Ignore the first textinput event as it contains the keypress that opened the prompt
  1318. +   if(firstText) {
  1319. +     firstText = false;
  1320. +   } else {
  1321. +     kb_buffer.insert(kb_buffer.begin() + kb_cursor_pos, event->text.text[0]);
  1322. +     kb_cursor_pos++;
  1323. +   }
  1324. + }
  1325.  }
  1326. diff --git a/src/drivers/prompt.h b/src/drivers/prompt.h
  1327. index 4e66957..353f4ce 100644
  1328. --- a/src/drivers/prompt.h
  1329. +++ b/src/drivers/prompt.h
  1330. @@ -25,6 +25,7 @@ class HappyPrompt
  1331.  
  1332.     std::vector<uint32> kb_buffer;
  1333.     unsigned int kb_cursor_pos;
  1334. +        bool firstText;
  1335.  };
  1336.  
  1337.  #endif
  1338. diff --git a/src/drivers/thread_sdl.cpp b/src/drivers/thread_sdl.cpp
  1339. index de4920a..6d5ae98 100644
  1340. --- a/src/drivers/thread_sdl.cpp
  1341. +++ b/src/drivers/thread_sdl.cpp
  1342. @@ -19,7 +19,7 @@
  1343.  
  1344.  MDFN_Thread *MDFND_CreateThread(int (*fn)(void *), void *data)
  1345.  {
  1346. - return (MDFN_Thread*)SDL_CreateThread(fn, data);
  1347. + return (MDFN_Thread*)SDL_CreateThread(fn, NULL, data);
  1348.  }
  1349.  
  1350.  void MDFND_WaitThread(MDFN_Thread *thread, int *status)
  1351. diff --git a/src/drivers/video.cpp b/src/drivers/video.cpp
  1352. index 901a916..c3cef24 100644
  1353. --- a/src/drivers/video.cpp
  1354. +++ b/src/drivers/video.cpp
  1355. @@ -107,11 +107,16 @@ static MDFNGI *VideoGI;
  1356.  
  1357.  static int best_xres = 0, best_yres = 0;
  1358.  
  1359. -static int cur_xres, cur_yres, cur_flags;
  1360. +static int window_w, window_h, cur_window_flags;
  1361.  
  1362.  static ScalerDefinition *CurrentScaler = NULL;
  1363.  
  1364.  static SDL_Surface *screen = NULL;
  1365. +static SDL_Texture *texture = NULL;
  1366. +SDL_Window *window = NULL;
  1367. +static SDL_GLContext glcontext = NULL;
  1368. +SDL_Renderer *renderer = NULL;
  1369. +static Uint32 renderer_flags;
  1370.  static OpenGL_Blitter *ogl_blitter = NULL;
  1371.  static SDL_Surface *IconSurface=NULL;
  1372.  
  1373. @@ -158,11 +163,11 @@ static void ClearBackBuffer(void)
  1374.    //
  1375.    // We'll do an icky #ifdef kludge instead for now.
  1376.  #ifdef WIN32
  1377. -  if(screen->flags & SDL_HWSURFACE)
  1378. +  if(renderer_flags & SDL_RENDERER_ACCELERATED)
  1379.    {
  1380.     if(SDL_MUSTLOCK(screen))
  1381.      SDL_LockSurface(screen);
  1382. -   memset(screen->pixels, 0, screen->pitch * screen->h);
  1383. +   memset(screen->pixels, 0, screen->pitch * window_h);
  1384.     if(SDL_MUSTLOCK(screen))
  1385.      SDL_UnlockSurface(screen);
  1386.    }
  1387. @@ -220,9 +225,29 @@ void KillVideo(void)
  1388.  
  1389.   screen = NULL;
  1390.   VideoGI = NULL;
  1391. - cur_xres = 0;
  1392. - cur_yres = 0;
  1393. - cur_flags = 0;
  1394. + window_w = 0;
  1395. + window_h = 0;
  1396. + cur_window_flags = 0;
  1397. + renderer_flags = 0;
  1398. +
  1399. + if(renderer != NULL) {
  1400. +    SDL_DestroyRenderer(renderer);
  1401. +    renderer = NULL;
  1402. + }
  1403. +
  1404. + if(window != NULL) {
  1405. +    SDL_DestroyWindow(window);
  1406. +    window = NULL;
  1407. + }
  1408. +
  1409. + if(glcontext != NULL) {
  1410. +    SDL_GL_DeleteContext(glcontext);
  1411. + }
  1412. +
  1413. + if(texture != NULL) {
  1414. +    SDL_DestroyTexture(texture);
  1415. +    texture = NULL;
  1416. + }
  1417.  }
  1418.  
  1419.  static void GenerateDestRect(void)
  1420. @@ -244,8 +269,8 @@ static void GenerateDestRect(void)
  1421.  
  1422.    if (_video.stretch == 2 || _video.stretch == 3 || _video.stretch == 4)   // Aspect-preserve stretch
  1423.    {
  1424. -   exs = (double)cur_xres / nom_width;
  1425. -   eys = (double)cur_yres / nom_height;
  1426. +   exs = (double)window_w / nom_width;
  1427. +   eys = (double)window_h / nom_height;
  1428.  
  1429.     if(_video.stretch == 3 || _video.stretch == 4)  // Round down to nearest int.
  1430.     {
  1431. @@ -297,32 +322,32 @@ static void GenerateDestRect(void)
  1432.     screen_dest_rect.h = (int)(eys*nom_height + 0.5); // +0.5 for rounding
  1433.  
  1434.     // Centering:
  1435. -   int nx = (int)((cur_xres - screen_dest_rect.w) / 2);
  1436. +   int nx = (int)((window_w - screen_dest_rect.w) / 2);
  1437.     if(nx < 0) nx = 0;
  1438.     screen_dest_rect.x = nx;
  1439.  
  1440. -   int ny = (int)((cur_yres - screen_dest_rect.h) / 2);
  1441. +   int ny = (int)((window_h - screen_dest_rect.h) / 2);
  1442.     if(ny < 0) ny = 0;
  1443.     screen_dest_rect.y = ny;
  1444.    }
  1445.    else     // Full-stretch
  1446.    {
  1447.     screen_dest_rect.x = 0;
  1448. -   screen_dest_rect.w = cur_xres;
  1449. +   screen_dest_rect.w = window_w;
  1450.  
  1451.     screen_dest_rect.y = 0;
  1452. -   screen_dest_rect.h = cur_yres;
  1453. +   screen_dest_rect.h = window_h;
  1454.  
  1455. -   exs = (double)cur_xres / nom_width;
  1456. -   eys = (double)cur_yres / nom_height;
  1457. +   exs = (double)window_w / nom_width;
  1458. +   eys = (double)window_h / nom_height;
  1459.    }
  1460.   }
  1461.   else
  1462.   {
  1463.    if(VideoGI->rotated)
  1464.    {
  1465. -   int32 ny = (int)((cur_yres - VideoGI->nominal_width * exs) / 2);
  1466. -   int32 nx = (int)((cur_xres - VideoGI->nominal_height * eys) / 2);
  1467. +   int32 ny = (int)((window_h - VideoGI->nominal_width * exs) / 2);
  1468. +   int32 nx = (int)((window_w - VideoGI->nominal_height * eys) / 2);
  1469.  
  1470.     //if(ny < 0) ny = 0;
  1471.     //if(nx < 0) nx = 0;
  1472. @@ -334,8 +359,8 @@ static void GenerateDestRect(void)
  1473.    }
  1474.    else
  1475.    {
  1476. -   int nx = (int)((cur_xres - VideoGI->nominal_width * exs) / 2);
  1477. -   int ny = (int)((cur_yres - VideoGI->nominal_height * eys) / 2);
  1478. +   int nx = (int)((window_w - VideoGI->nominal_width * exs) / 2);
  1479. +   int ny = (int)((window_h - VideoGI->nominal_height * eys) / 2);
  1480.  
  1481.     // Don't check to see if the coordinates go off screen here, offscreen coordinates are valid(though weird that the user would want them...)
  1482.     // in OpenGL mode, and are clipped to valid coordinates in SDL blit mode code.
  1483. @@ -424,8 +449,8 @@ static uint32 real_rs, real_gs, real_bs, real_as;
  1484.  
  1485.  int InitVideo(MDFNGI *gi)
  1486.  {
  1487. - const SDL_VideoInfo *vinf;
  1488. - int flags = 0; //SDL_RESIZABLE;
  1489. + SDL_DisplayMode mode;
  1490. + int window_flags = 0; //SDL_RESIZABLE;
  1491.   int desbpp;
  1492.  
  1493.   VideoGI = gi;
  1494. @@ -473,8 +498,6 @@ int InitVideo(MDFNGI *gi)
  1495.     IconSurface=SDL_CreateRGBSurfaceFrom((void *)mednafen_playicon128.pixel_data,128,128,32,128*4,0xFF000000,0xFF0000,0xFF00,0xFF);
  1496.     #endif
  1497.    #endif
  1498. -
  1499. -  SDL_WM_SetIcon(IconSurface, 0);
  1500.   }
  1501.  
  1502.   if(!getenv("__GL_SYNC_TO_VBLANK") || weset_glstvb)
  1503. @@ -526,12 +549,16 @@ int InitVideo(MDFNGI *gi)
  1504.  
  1505.   CurrentScaler = _video.special ? &Scalers[_video.special - 1] : NULL;
  1506.  
  1507. - vinf=SDL_GetVideoInfo();
  1508. + //FIXME only for single screen :/
  1509. + if(SDL_GetDesktopDisplayMode(0, &mode) != 0) {
  1510. +    printf("could not get display mode info\n");
  1511. +    return 0;
  1512. + }
  1513.  
  1514.   if(!best_xres)
  1515.   {
  1516. -  best_xres = vinf->current_w;
  1517. -  best_yres = vinf->current_h;
  1518. +  best_xres = mode.w;
  1519. +  best_yres = mode.h;
  1520.  
  1521.    if(!best_xres || !best_yres)
  1522.    {
  1523. @@ -540,12 +567,8 @@ int InitVideo(MDFNGI *gi)
  1524.    }
  1525.   }
  1526.  
  1527. -
  1528. - if(vinf->hw_available)
  1529. -  flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
  1530. -
  1531.   if(_fullscreen)
  1532. -  flags |= SDL_FULLSCREEN;
  1533. +  window_flags |= SDL_WINDOW_FULLSCREEN; //FIXME Maybe use fullscreen desktop?
  1534.  
  1535.   vdriver = MDFN_GetSettingI("video.driver");
  1536.  
  1537. @@ -569,21 +592,19 @@ int InitVideo(MDFNGI *gi)
  1538.  
  1539.   if(vdriver == VDRIVER_OPENGL)
  1540.   {
  1541. -  flags |= SDL_OPENGL;
  1542. +  window_flags |= SDL_WINDOW_OPENGL;
  1543.  
  1544.    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1 );
  1545.  
  1546. -  #if SDL_VERSION_ATLEAST(1, 2, 10)
  1547. -  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, MDFN_GetSettingB("video.glvsync"));
  1548. -  #endif
  1549. +  SDL_GL_SetSwapInterval(MDFN_GetSettingB("video.glvsync"));
  1550.   }
  1551.   else if(vdriver == VDRIVER_SOFTSDL)
  1552.   {
  1553. -
  1554. +    SDL_SetHint(SDL_HINT_RENDER_DRIVER, "");
  1555.   }
  1556.   else if(vdriver == VDRIVER_OVERLAY)
  1557.   {
  1558. -
  1559. +    SDL_SetHint(SDL_HINT_RENDER_DRIVER, "");
  1560.   }
  1561.  
  1562.   exs = _fullscreen ? _video.xscalefs : _video.xscale;
  1563. @@ -607,46 +628,132 @@ int InitVideo(MDFNGI *gi)
  1564.    }
  1565.   }
  1566.  
  1567. + GenerateDestRect();
  1568. +
  1569. + const char* title;
  1570. +
  1571. + if(gi && gi->name)
  1572. +  title=(char *)gi->name;
  1573. + else
  1574. +  title="Mednafen";
  1575. +
  1576. +  Uint32 rmask, gmask, bmask, amask;
  1577. +
  1578. +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
  1579. +    rmask = 0xff000000;
  1580. +    gmask = 0x00ff0000;
  1581. +    bmask = 0x0000ff00;
  1582. +    amask = 0x000000ff;
  1583. +#else
  1584. +    rmask = 0x000000ff;
  1585. +    gmask = 0x0000ff00;
  1586. +    bmask = 0x00ff0000;
  1587. +    amask = 0xff000000;
  1588. +#endif
  1589. +
  1590. + int newwidth = window_w;
  1591. + int newheight = window_h;
  1592. + int windowchanged = 0;
  1593. +
  1594. + /*printf("window_w: %d window_h: %d\n", window_w, window_h);
  1595. + printf("screen_dest_rect.w: %d screen_dest_rect.h: %d\n", screen_dest_rect.w, screen_dest_rect.h);*/
  1596. +
  1597.   if(_fullscreen)
  1598.   {
  1599. -  if(!screen || cur_xres != _video.xres || cur_yres != _video.yres || cur_flags != flags || curbpp != desbpp)
  1600. +  if(!window || window_w != _video.xres || window_h != _video.yres || cur_window_flags != window_flags || curbpp != desbpp)
  1601.    {
  1602. -   if(!(screen = SDL_SetVideoMode(_video.xres ? _video.xres : best_xres, _video.yres ? _video.yres : best_yres, desbpp, flags)))
  1603. +    newwidth = _video.xres ? _video.xres : best_xres;
  1604. +    newheight = _video.yres ? _video.yres : best_yres;
  1605. +    windowchanged = 1;
  1606. +  }
  1607. + } else {
  1608. +  if(!window || window_w != screen_dest_rect.w || window_h != screen_dest_rect.h || cur_window_flags != window_flags || curbpp != desbpp)
  1609. +  {
  1610. +    newwidth = screen_dest_rect.w;
  1611. +    newheight = screen_dest_rect.h;
  1612. +    windowchanged = 1;
  1613. +  }
  1614. + }
  1615. +
  1616. + if(windowchanged) {
  1617. +
  1618. +   if(!(window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, newwidth, newheight, window_flags)))
  1619.     {
  1620.      MDFND_PrintError(SDL_GetError());
  1621.      MDFN_indent(-1);
  1622.      return(0);
  1623.     }
  1624. -  }
  1625. - }
  1626. - else
  1627. - {
  1628. -  GenerateDestRect();
  1629. -  if(!screen || cur_xres != screen_dest_rect.w || cur_yres != screen_dest_rect.h || cur_flags != flags || curbpp != desbpp)
  1630. -  {
  1631. -   if(!(screen = SDL_SetVideoMode(screen_dest_rect.w, screen_dest_rect.h, desbpp, flags)))
  1632. +
  1633. +   SDL_SetWindowIcon(window, IconSurface);
  1634. +
  1635. +   /*const char* viddriver = SDL_GetCurrentVideoDriver();
  1636. +
  1637. +   printf("Video Driver: %s\n", viddriver ? viddriver : "null");*/
  1638. +
  1639. +   if(vdriver == VDRIVER_OPENGL) {
  1640. +    if(!(glcontext = SDL_GL_CreateContext(window))) {
  1641. +     MDFND_PrintError(SDL_GetError());
  1642. +     MDFN_indent(-1);
  1643. +     return(0);
  1644. +    }
  1645. +   }
  1646. +
  1647. +   if(!(screen = SDL_CreateRGBSurface(0, newwidth, newheight, desbpp, rmask, gmask, bmask, amask)))
  1648.     {
  1649.      MDFND_PrintError(SDL_GetError());
  1650.      MDFN_indent(-1);
  1651.      return(0);
  1652.     }
  1653. -  }
  1654. +
  1655. +   if(vdriver != VDRIVER_OPENGL) {
  1656. +       if(!(renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED)))
  1657. +       {
  1658. +        MDFND_PrintError(SDL_GetError());
  1659. +        MDFN_indent(-1);
  1660. +        return(0);
  1661. +       }
  1662. +
  1663. +       SDL_RendererInfo rinfo;
  1664. +
  1665. +       if(SDL_GetRendererInfo(renderer, &rinfo) < 0) {
  1666. +        printf("Could not get renderer info: %s\n", SDL_GetError());
  1667. +       } else {
  1668. +        renderer_flags = rinfo.flags;
  1669. +        /*printf("Renderer name: %s\n", rinfo.name);
  1670. +        printf("Renderer flags: %x\n", rinfo.flags);
  1671. +        printf("Renderer Number of texture formats: %d\n", rinfo.num_texture_formats);
  1672. +        for(uint i=0;i < rinfo.num_texture_formats;i++) {
  1673. +            printf("Renderer Supported texture format %d -- %s\n", i, SDL_GetPixelFormatName(rinfo.texture_formats[i]));
  1674. +        }
  1675. +        printf("Renderer maxtexture width: %d\n", rinfo.max_texture_width);
  1676. +        printf("Renderer maxtexture height: %d\n", rinfo.max_texture_height);*/
  1677. +       }
  1678. +
  1679. +       if(!(texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, newwidth, newheight)))
  1680. +       {
  1681. +        MDFND_PrintError(SDL_GetError());
  1682. +        MDFN_indent(-1);
  1683. +        return(0);
  1684. +       }
  1685. +   }
  1686.   }
  1687.  
  1688. - cur_xres = screen->w;
  1689. - cur_yres = screen->h;
  1690. - cur_flags = flags;
  1691. + SDL_GetWindowSize(window, &window_w, &window_h);
  1692. + cur_window_flags = window_flags;
  1693.   curbpp = screen->format->BitsPerPixel;
  1694.  
  1695. - // Kludgey, we need to clean this up(vdriver vs cur_flags and whatnot).
  1696. - if(vdriver != VDRIVER_OVERLAY)
  1697. -  vdriver = (cur_flags & SDL_OPENGL) ? VDRIVER_OPENGL : VDRIVER_SOFTSDL;
  1698. + // Kludgey, we need to clean this up(vdriver vs cur_window_flags and whatnot).
  1699. + if(vdriver != VDRIVER_OVERLAY) {
  1700. +  if(!(cur_window_flags & SDL_WINDOW_OPENGL)) {
  1701. +    vdriver = VDRIVER_SOFTSDL;
  1702. +  }
  1703. + }
  1704.  
  1705.   GenerateDestRect();
  1706.  
  1707. - MDFN_printf(_("Video Driver: %s\n"), (cur_flags & SDL_OPENGL) ? _("OpenGL") : (vdriver == VDRIVER_OVERLAY ? _("Overlay") :_("Software SDL") ) );
  1708. + MDFN_printf(_("Video Driver: %s\n"), (cur_window_flags & SDL_WINDOW_OPENGL) ? _("OpenGL") : (vdriver == VDRIVER_OVERLAY ? _("Overlay") :_("Software SDL") ) );
  1709.  
  1710. - MDFN_printf(_("Video Mode: %d x %d x %d bpp\n"),screen->w,screen->h,screen->format->BitsPerPixel);
  1711. + MDFN_printf(_("Video Mode: %d x %d x %d bpp\n"),window_w,window_h,curbpp);
  1712.   if(curbpp!=16 && curbpp!=24 && curbpp!=32)
  1713.   {
  1714.    MDFN_printf(_("Sorry, %dbpp modes are not supported by Mednafen.  Supported bit depths are 16bpp, 24bpp, and 32bpp.\n"),curbpp);
  1715. @@ -657,7 +764,7 @@ int InitVideo(MDFNGI *gi)
  1716.  
  1717.   //MDFN_printf(_("OpenGL: %s\n"), (cur_flags & SDL_OPENGL) ? _("Yes") : _("No"));
  1718.  
  1719. - if(cur_flags & SDL_OPENGL)
  1720. + if(cur_window_flags & SDL_WINDOW_OPENGL)
  1721.   {
  1722.    MDFN_indent(1);
  1723.    MDFN_printf(_("Pixel shader: %s\n"), MDFN_GetSettingS(std::string(sn + "." + std::string("pixshader")).c_str()).c_str());
  1724. @@ -673,24 +780,20 @@ int InitVideo(MDFNGI *gi)
  1725.    MDFN_printf(_("Scanlines: %d%% opacity%s\n"), abs(_video.scanlines), (_video.scanlines < 0) ? _(" (with interlace field obscure)") : "");
  1726.  
  1727.   MDFN_printf(_("Destination Rectangle: X=%d, Y=%d, W=%d, H=%d\n"), screen_dest_rect.x, screen_dest_rect.y, screen_dest_rect.w, screen_dest_rect.h);
  1728. - if(screen_dest_rect.x < 0 || screen_dest_rect.y < 0 || (screen_dest_rect.x + screen_dest_rect.w) > screen->w || (screen_dest_rect.y + screen_dest_rect.h) > screen->h)
  1729. + if(screen_dest_rect.x < 0 || screen_dest_rect.y < 0 || (screen_dest_rect.x + screen_dest_rect.w) > window_w || (screen_dest_rect.y + screen_dest_rect.h) > window_h)
  1730.   {
  1731.    MDFN_indent(1);
  1732.    MDFN_printf(_("Warning:  Destination rectangle exceeds screen dimensions.  This is ok if you really do want the clipping...\n"));
  1733.    MDFN_indent(-1);
  1734.   }
  1735. - if(gi && gi->name)
  1736. -  SDL_WM_SetCaption((char *)gi->name,(char *)gi->name);
  1737. - else
  1738. -  SDL_WM_SetCaption("Mednafen","Mednafen");
  1739.  
  1740.   int rs, gs, bs, as;
  1741.  
  1742. - if(cur_flags & SDL_OPENGL)
  1743. + if(cur_window_flags & SDL_WINDOW_OPENGL)
  1744.   {
  1745.    try
  1746.    {
  1747. -   ogl_blitter = new OpenGL_Blitter(_video.scanlines, _video.pixshader, screen->w, screen->h, &rs, &gs, &bs, &as);
  1748. +   ogl_blitter = new OpenGL_Blitter(_video.scanlines, _video.pixshader, window_w, window_h, &rs, &gs, &bs, &as);
  1749.    }
  1750.    catch(std::exception &e)
  1751.    {
  1752. @@ -714,7 +817,7 @@ int InitVideo(MDFNGI *gi)
  1753.   //printf("%d %d %d %d\n", rs, gs, bs, as);
  1754.  
  1755.   MDFN_indent(-1);
  1756. - SDL_ShowCursor(0);
  1757. + SDL_ShowCursor(SDL_DISABLE);
  1758.  
  1759.   real_rs = rs;
  1760.   real_gs = gs;
  1761. @@ -741,9 +844,9 @@ int InitVideo(MDFNGI *gi)
  1762.  #endif
  1763.   }
  1764.  
  1765. - NetSurface = new MDFN_Surface(NULL, screen->w, 18 * 5, screen->w, MDFN_PixelFormat(MDFN_COLORSPACE_RGB, real_rs, real_gs, real_bs, real_as));
  1766. + NetSurface = new MDFN_Surface(NULL, window_w, 18 * 5, window_w, MDFN_PixelFormat(MDFN_COLORSPACE_RGB, real_rs, real_gs, real_bs, real_as));
  1767.  
  1768. - NetRect.w = screen->w;
  1769. + NetRect.w = window_w;
  1770.   NetRect.h = 18 * 5;
  1771.   NetRect.x = 0;
  1772.   NetRect.y = 0;
  1773. @@ -753,20 +856,20 @@ int InitVideo(MDFNGI *gi)
  1774.    int xmu = 1;
  1775.    int ymu = 1;
  1776.  
  1777. -  if(screen->w >= 768)
  1778. -   xmu = screen->w / 384;
  1779. -  if(screen->h >= 576)
  1780. -   ymu = screen->h / 288;
  1781. +  if(window_w >= 768)
  1782. +   xmu = window_w / 384;
  1783. +  if(window_h >= 576)
  1784. +   ymu = window_h / 288;
  1785.  
  1786.    SMRect.h = 18 + 2;
  1787.    SMRect.x = 0;
  1788.    SMRect.y = 0;
  1789. -  SMRect.w = screen->w;
  1790. +  SMRect.w = window_w;
  1791.  
  1792.    SMDRect.w = SMRect.w * xmu;
  1793.    SMDRect.h = SMRect.h * ymu;
  1794. -  SMDRect.x = (screen->w - SMDRect.w) / 2;
  1795. -  SMDRect.y = screen->h - SMDRect.h;
  1796. +  SMDRect.x = (window_w - SMDRect.w) / 2;
  1797. +  SMDRect.y = window_h - SMDRect.h;
  1798.  
  1799.    if(SMDRect.x < 0)
  1800.    {
  1801. @@ -804,13 +907,17 @@ int InitVideo(MDFNGI *gi)
  1802.   {
  1803.    ClearBackBuffer();
  1804.  
  1805. -  if(cur_flags & SDL_OPENGL)
  1806. +  if(cur_window_flags & SDL_WINDOW_OPENGL)
  1807.    {
  1808. -   SDL_GL_SwapBuffers();
  1809. +   SDL_GL_SwapWindow(window);
  1810.     //ogl_blitter->HardSync();
  1811.    }
  1812. -  else
  1813. -   SDL_Flip(screen);
  1814. +  else {
  1815. +   SDL_UpdateTexture(texture, NULL, screen->pixels, screen->pitch);
  1816. +   SDL_RenderClear(renderer);
  1817. +   SDL_RenderCopy(renderer, texture, NULL, NULL);
  1818. +   SDL_RenderPresent(renderer);
  1819. +  }
  1820.   }
  1821.  
  1822.   MarkNeedBBClear();
  1823. @@ -1107,7 +1214,7 @@ static void SubBlit(MDFN_Surface *source_surface, const MDFN_Rect &src_rect, con
  1824.        tr.w = dest_rect.w;
  1825.        tr.h = dest_rect.h;
  1826.  
  1827. -      OV_Blit(bah_surface, &boohoo_rect, &eff_src_rect, &tr, screen, 0, _video.scanlines, CurGame->rotated);
  1828. +      OV_Blit(bah_surface, &boohoo_rect, &eff_src_rect, &tr, 0, _video.scanlines, CurGame->rotated);
  1829.       }
  1830.       else
  1831.       {
  1832. @@ -1133,7 +1240,7 @@ static void SubBlit(MDFN_Surface *source_surface, const MDFN_Rect &src_rect, con
  1833.        tr.w = dest_rect.w;
  1834.        tr.h = dest_rect.h;
  1835.  
  1836. -      OV_Blit(eff_source_surface, &eff_src_rect, &eff_src_rect, &tr, screen, overlay_softscale, _video.scanlines, CurGame->rotated);
  1837. +      OV_Blit(eff_source_surface, &eff_src_rect, &eff_src_rect, &tr, overlay_softscale, _video.scanlines, CurGame->rotated);
  1838.       }
  1839.       else
  1840.       {
  1841. @@ -1313,8 +1420,8 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1842.     if(sr.y < 0) { sr.h += sr.y; sr.y = 0; }
  1843.     if(sr.w < 0) sr.w = 0;
  1844.     if(sr.h < 0) sr.h = 0;
  1845. -   if(sr.w > screen->w) sr.w = screen->w;
  1846. -   if(sr.h > screen->h) sr.h = screen->h;
  1847. +   if(sr.w > window_w) sr.w = window_w;
  1848. +   if(sr.h > window_h) sr.h = window_h;
  1849.  
  1850.     ib = new MDFN_Surface(NULL, sr.w, sr.h, sr.w, MDFN_PixelFormat(MDFN_COLORSPACE_RGB, real_rs, real_gs, real_bs, real_as));
  1851.  
  1852. @@ -1350,15 +1457,15 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1853.   }
  1854.  
  1855.  
  1856. - Debugger_MT_DrawToScreen(MDFN_PixelFormat(MDFN_COLORSPACE_RGB, real_rs, real_gs, real_bs, real_as), screen->w, screen->h);
  1857. + Debugger_MT_DrawToScreen(MDFN_PixelFormat(MDFN_COLORSPACE_RGB, real_rs, real_gs, real_bs, real_as), window_w, window_h);
  1858.  
  1859.  #if 0
  1860.   if(CKGUI_IsActive())
  1861.   {
  1862.    if(!CKGUISurface)
  1863.    {
  1864. -   CKGUIRect.w = screen->w;
  1865. -   CKGUIRect.h = screen->h;
  1866. +   CKGUIRect.w = window_w;
  1867. +   CKGUIRect.h = window_h;
  1868.  
  1869.     CKGUISurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, CKGUIRect.w, CKGUIRect.h, 32, 0xFF << real_rs, 0xFF << real_gs, 0xFF << real_bs, 0xFF << real_as);
  1870.     SDL_SetColorKey(CKGUISurface, SDL_SRCCOLORKEY, 0);
  1871. @@ -1379,8 +1486,8 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1872.   {
  1873.    if(!HelpSurface)
  1874.    {
  1875. -   HelpRect.w = std::min<int>(512, screen->w);
  1876. -   HelpRect.h = std::min<int>(384, screen->h);
  1877. +   HelpRect.w = std::min<int>(512, window_w);
  1878. +   HelpRect.h = std::min<int>(384, window_h);
  1879.  
  1880.     HelpSurface = new MDFN_Surface(NULL, 512, 384, 512, MDFN_PixelFormat(MDFN_COLORSPACE_RGB, real_rs, real_gs, real_bs, real_as));
  1881.  /*
  1882. @@ -1393,11 +1500,11 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1883.  
  1884.    MDFN_Rect zederect;
  1885.  
  1886. -  zederect.w = HelpRect.w * (screen->w / HelpRect.w);
  1887. -  zederect.h = HelpRect.h * (screen->h / HelpRect.h);
  1888. +  zederect.w = HelpRect.w * (window_w / HelpRect.w);
  1889. +  zederect.h = HelpRect.h * (window_h / HelpRect.h);
  1890.  
  1891. -  zederect.x = (screen->w - zederect.w) / 2;
  1892. -  zederect.y = (screen->h - zederect.h) / 2;
  1893. +  zederect.x = (window_w - zederect.w) / 2;
  1894. +  zederect.y = (window_h - zederect.h) / 2;
  1895.  
  1896.    BlitRaw(HelpSurface, &HelpRect, &zederect, 0);
  1897.   }
  1898. @@ -1418,8 +1525,8 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1899.  
  1900.    CheatRect.x = 0;
  1901.    CheatRect.y = 0;
  1902. -  CheatRect.w = screen->w;
  1903. -  CheatRect.h = screen->h;
  1904. +  CheatRect.w = window_w;
  1905. +  CheatRect.h = window_h;
  1906.  
  1907.    while((CheatRect.h >> crs) >= 1024 && (CheatRect.w >> crs) >= 1024)
  1908.     crs++;
  1909. @@ -1462,7 +1569,7 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1910.     MDFN_Rect zederect;
  1911.  
  1912.     zederect.x = 0;
  1913. -   zederect.y = screen->h - NetRect.h;
  1914. +   zederect.y = window_h - NetRect.h;
  1915.     zederect.w = NetRect.w;
  1916.     zederect.h = NetRect.h;
  1917.  
  1918. @@ -1481,7 +1588,7 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1919.    // but that gets awfully complicated and prone to bugs when dealing with double/triple-buffered video...).
  1920.    //
  1921.    // std::max so we don't position it offscreen if the user has selected xscalefs or yscalefs values that are too large.
  1922. -  if(!(cur_flags & SDL_OPENGL))
  1923. +  if(!(cur_window_flags & SDL_WINDOW_OPENGL))
  1924.    {
  1925.     fps_offsx = std::max<int32>(screen_dest_rect.x, 0);
  1926.     fps_offsy = std::max<int32>(screen_dest_rect.y, 0);
  1927. @@ -1489,15 +1596,19 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
  1928.    FPS_DrawToScreen(screen, real_rs, real_gs, real_bs, real_as, fps_offsx, fps_offsy);
  1929.   }
  1930.  
  1931. - if(!(cur_flags & SDL_OPENGL))
  1932. + if(!(cur_window_flags & SDL_WINDOW_OPENGL))
  1933.   {
  1934. -  if(!OverlayOK)
  1935. -   SDL_Flip(screen);
  1936. +  if(!OverlayOK) {
  1937. +   SDL_UpdateTexture(texture, NULL, screen->pixels, screen->pitch);
  1938. +   SDL_RenderClear(renderer);
  1939. +   SDL_RenderCopy(renderer, texture, NULL, NULL);
  1940. +   SDL_RenderPresent(renderer);
  1941. +  }
  1942.   }
  1943.   else
  1944.   {
  1945.    PumpWrap();
  1946. -  SDL_GL_SwapBuffers();
  1947. +  SDL_GL_SwapWindow(window);
  1948.    //ogl_blitter->HardSync();
  1949.   }
  1950.  }
  1951. @@ -1547,3 +1658,8 @@ int32 PtoV_J(const int32 inv, const bool axis, const bool scr_scale)
  1952.    return (int32)floor(0.5 + ((((((int64)inv * prescale) + 0x8000) >> 16) + offs) * postscale));
  1953.   }
  1954.  }
  1955. +
  1956. +void Video_GetSize(int* width, int* height) {
  1957. +    *width = window_w;
  1958. +    *height = window_h;
  1959. +}
  1960. diff --git a/src/drivers/video.h b/src/drivers/video.h
  1961. index e526996..bbcfef0 100644
  1962. --- a/src/drivers/video.h
  1963. +++ b/src/drivers/video.h
  1964. @@ -77,6 +77,8 @@ bool Video_ScreenBlitReady(void);
  1965.  // Called from the main thread.
  1966.  void Video_BlitToScreen(void);
  1967.  
  1968. +extern SDL_Renderer* renderer;
  1969. +extern SDL_Window *window;
  1970.  
  1971.  class SDL_to_MDFN_Surface_Wrapper : public MDFN_Surface
  1972.  {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement