diff --git a/src/sdl2/main.c b/src/sdl2/main.c
index a6b98d6813f6020130572574a6ea010cc6025694..67387dba6b6d8bf2cabfc2e1382ceeb00628e2fb 100644 (file)
--- a/src/sdl2/main.c
+++ b/src/sdl2/main.c
#include "system.h"
#include "input.h"
+#include "cp866.h"
+
#include "my.h" // fexists
#include "player.h" // pl1 pl2
#include "menu.h" // G_keyf
static SDL_Window *window;
static SDL_GLContext context;
static SDL_Surface *surf;
+static videomode_t vlist;
/* --- error.h --- */
}
}
+static void init_videomode_list (void) {
+ int i, j, k;
+ SDL_DisplayMode m;
+ int n = SDL_GetNumDisplayModes(0);
+ if (vlist.modes != NULL) {
+ free(vlist.modes);
+ vlist.modes = NULL;
+ vlist.n = 0;
+ }
+ if (n > 0) {
+ vlist.modes = malloc(n * sizeof(videomode_size_t));
+ if (vlist.modes != NULL) {
+ j = 0;
+ for (i = 0; i < n; i++) {
+ SDL_GetDisplayMode(0, i, &m);
+ k = 0;
+ while (k < j && (m.w != vlist.modes[k].w || m.h != vlist.modes[k].h)) {
+ k++;
+ }
+ if (k >= j) {
+ vlist.modes[j] = (videomode_size_t) {
+ .w = m.w,
+ .h = m.h
+ };
+ j++;
+ }
+ }
+ vlist.n = j;
+ }
+ }
+}
+
+const videomode_t *Y_get_videomode_list_opengl (int fullscreen) {
+ init_videomode_list();
+ return &vlist;
+}
+
+const videomode_t *Y_get_videomode_list_software (int fullscreen) {
+ init_videomode_list();
+ return &vlist;
+}
+
void Y_set_fullscreen (int yes) {
if (window != NULL) {
SDL_SetWindowFullscreen(window, yes ? SDL_WINDOW_FULLSCREEN : 0);
return i;
}
-static int wchar_to_cp866 (int uch) {
- if (uch <= 0x7f) {
- return uch;
- } else if (uch >= 0x410 && uch <= 0x43f) {
- return uch - 0x410 + 0x80;
- } else if (uch >= 0x440 && uch <= 0x44f) {
- return uch - 0x440 + 0xe0;
- } else {
- switch (uch) {
- // TODO graphics from 0xb0..0xdf
- case 0x401: return 0xf0;
- case 0x451: return 0xf1;
- case 0x404: return 0xf2;
- case 0x454: return 0xf3;
- case 0x407: return 0xf4;
- case 0x457: return 0xf5;
- case 0x40e: return 0xf6;
- case 0x45e: return 0xf7;
- case 0xb0: return 0xf8;
- case 0x2219: return 0xf9;
- case 0xb7: return 0xfa;
- case 0x221a: return 0xfb;
- case 0x2116: return 0xfc;
- case 0xa4: return 0xfd;
- case 0x25a0: return 0xfe;
- case 0xa0: return 0xff;
- default: return 0; // unknown
- }
- }
-}
-
static void poll_events (void) {
int key, down, uch, ch;
SDL_Event ev;
break;
case SDL_TEXTINPUT:
uch = utf8_to_wchar(ev.text.text);
- ch = wchar_to_cp866(uch);
- GM_input(ch);
+ ch = cp866_utoc(uch);
+ if (ch >= 0) {
+ GM_input(ch);
+ }
break;
}
}