/*
 * st2sdl12.h: the part of the SDL 1.2 API that Super Transball 2 uses, on top of SDL2, for the
 * fredygames.com browser build (Emscripten). Implemented in st2sdl12.c; included before every game file
 * (-include), so the game's own "SDL.h" and "SDL/SDL.h" includes need no change.
 *
 * Keys: the game indexes the keyboard state by SDL 1.2 key symbol (keyboard[SDLK_LEFT], arrays of
 * SDLK_LAST entries) and keeps those numbers in its configuration file (transball.cfg). Here the key
 * symbols keep their SDL 1.2 values: printable keys are the same in both versions, and the others
 * (arrows, F keys, keypad, modifiers...) are redefined to their SDL 1.2 numbers. SDL_GetKeyState builds
 * a table in that numbering from SDL2's keyboard state, and SDL_PollEvent translates keysym.sym.
 *
 * Copyright (C) 2026 FredyGames. GNU GPL version 2 or later, like Super Transball 2.
 */
#ifndef ST2_SDL12_H
#define ST2_SDL12_H

#include <SDL.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef int SDLKey;
typedef SDL_Keymod SDLMod;

/* surface and video mode flags of SDL 1.2 (values that SDL2 does not use in SDL_Surface.flags) */
#define SDL_SWSURFACE 0x00000000
#define SDL_HWSURFACE 0x40000000
#define SDL_HWPALETTE 0x20000000
#define SDL_DOUBLEBUF 0x10000000
#define SDL_FULLSCREEN 0x80000000
#define SDL_SRCCOLORKEY 0x00001000
#define SDL_SRCALPHA 0x00010000

SDL_Surface *SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags);
int SDL_Flip (SDL_Surface * screen);
void SDL_WM_SetCaption (const char *title, const char *icon);
int SDL_EnableUNICODE (int enable);
Uint8 *SDL_GetKeyState (int *numkeys);
const char *st2_GetKeyName (SDLKey key);
int st2_PollEvent (SDL_Event * event);
int SDL_SetAlpha (SDL_Surface * surface, Uint32 flags, Uint8 alpha);
SDL_Surface *SDL_DisplayFormat (SDL_Surface * surface);
SDL_Surface *SDL_DisplayFormatAlpha (SDL_Surface * surface);
void st2_Delay (Uint32 ms);
#define SDL_PollEvent st2_PollEvent
#define SDL_GetKeyName st2_GetKeyName
#define SDL_Delay st2_Delay

/* key symbols of SDL 1.2 that differ from SDL2 */
#define SDLK_LAST 323
#undef SDLK_DELETE
#define SDLK_DELETE 127
#define SDLK_KP0 256
#define SDLK_KP1 257
#define SDLK_KP2 258
#define SDLK_KP3 259
#define SDLK_KP4 260
#define SDLK_KP5 261
#define SDLK_KP6 262
#define SDLK_KP7 263
#define SDLK_KP8 264
#define SDLK_KP9 265
#undef SDLK_KP_PERIOD
#define SDLK_KP_PERIOD 266
#undef SDLK_KP_DIVIDE
#define SDLK_KP_DIVIDE 267
#undef SDLK_KP_MULTIPLY
#define SDLK_KP_MULTIPLY 268
#undef SDLK_KP_MINUS
#define SDLK_KP_MINUS 269
#undef SDLK_KP_PLUS
#define SDLK_KP_PLUS 270
#undef SDLK_KP_ENTER
#define SDLK_KP_ENTER 271
#undef SDLK_KP_EQUALS
#define SDLK_KP_EQUALS 272
#undef SDLK_UP
#define SDLK_UP 273
#undef SDLK_DOWN
#define SDLK_DOWN 274
#undef SDLK_RIGHT
#define SDLK_RIGHT 275
#undef SDLK_LEFT
#define SDLK_LEFT 276
#undef SDLK_INSERT
#define SDLK_INSERT 277
#undef SDLK_HOME
#define SDLK_HOME 278
#undef SDLK_END
#define SDLK_END 279
#undef SDLK_PAGEUP
#define SDLK_PAGEUP 280
#undef SDLK_PAGEDOWN
#define SDLK_PAGEDOWN 281
#undef SDLK_F1
#define SDLK_F1 282
#undef SDLK_F2
#define SDLK_F2 283
#undef SDLK_F3
#define SDLK_F3 284
#undef SDLK_F4
#define SDLK_F4 285
#undef SDLK_F5
#define SDLK_F5 286
#undef SDLK_F6
#define SDLK_F6 287
#undef SDLK_F7
#define SDLK_F7 288
#undef SDLK_F8
#define SDLK_F8 289
#undef SDLK_F9
#define SDLK_F9 290
#undef SDLK_F10
#define SDLK_F10 291
#undef SDLK_F11
#define SDLK_F11 292
#undef SDLK_F12
#define SDLK_F12 293
#undef SDLK_CAPSLOCK
#define SDLK_CAPSLOCK 301
#undef SDLK_RSHIFT
#define SDLK_RSHIFT 303
#undef SDLK_LSHIFT
#define SDLK_LSHIFT 304
#undef SDLK_RCTRL
#define SDLK_RCTRL 305
#undef SDLK_LCTRL
#define SDLK_LCTRL 306
#undef SDLK_RALT
#define SDLK_RALT 307
#undef SDLK_LALT
#define SDLK_LALT 308

#ifdef __cplusplus
}
#endif

#endif
