/* * zazsdl12.c: the part of the SDL 1.2 API that Zaz uses, on top of SDL2, for the fredygames.com browser * build (Emscripten). See zazsdl12.h. The game draws with OpenGL; SDL_SetVideoMode opens a window with a * GL context (WebGL, through Emscripten's legacy GL emulation), and SDL_GL_SwapBuffers presents the frame. * * Copyright (C) 2026 FredyGames. GNU GPL version 3 or later, like Zaz. */ #include "zazsdl12.h" static SDL_Window *window = NULL; static SDL_GLContext context = NULL; static SDL_Surface *screen = NULL; const SDL_VideoInfo * SDL_GetVideoInfo (void) { static SDL_VideoInfo info; static SDL_PixelFormat *format = NULL; if (format == NULL) format = SDL_AllocFormat (SDL_PIXELFORMAT_RGB888); info.vfmt = format; return &info; } SDL_Rect ** SDL_ListModes (SDL_PixelFormat * format, Uint32 flags) { /* the browser build always runs at the size the page scales (see zaz-fredygames.patch) */ static SDL_Rect mode = { 0, 0, 1024, 768 }; static SDL_Rect *modes[] = { &mode, NULL }; (void) format; (void) flags; return modes; } SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) { (void) bpp; (void) flags; if (window == NULL) { window = SDL_CreateWindow ("Zaz", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL); if (window == NULL) return NULL; context = SDL_GL_CreateContext (window); if (context == NULL) return NULL; } else SDL_SetWindowSize (window, width, height); if (screen != NULL) SDL_FreeSurface (screen); /* the game only reads w and h of the screen surface */ screen = SDL_CreateRGBSurfaceWithFormat (0, width, height, 32, SDL_PIXELFORMAT_RGB888); return screen; } void SDL_GL_SwapBuffers (void) { if (window != NULL) SDL_GL_SwapWindow (window); } void SDL_WM_SetCaption (const char *title, const char *icon) { (void) icon; if (window != NULL && title != NULL) SDL_SetWindowTitle (window, title); } SDL_GrabMode SDL_WM_GrabInput (SDL_GrabMode mode) { /* Zaz aims at the absolute mouse position; in a page there is nothing to grab */ return mode == SDL_GRAB_QUERY ? SDL_GRAB_OFF : mode; } void SDL_WarpMouse (Uint16 x, Uint16 y) { if (window != NULL) SDL_WarpMouseInWindow (window, x, y); } int SDL_EnableUNICODE (int enable) { (void) enable; return 1; } Uint16 zaz_keysym_unicode (const SDL_Keysym * keysym) { SDL_Keycode sym = keysym->sym; int shift = (keysym->mod & KMOD_SHIFT) != 0; if (sym >= SDLK_a && sym <= SDLK_z) return (Uint16) (shift ? sym - 'a' + 'A' : sym); if (sym == SDLK_BACKSPACE) return 8; if (sym == SDLK_RETURN || sym == SDLK_KP_ENTER) return 13; if (sym >= 32 && sym < 127) return (Uint16) sym; return 0; }