/*
 * sdl12shim.h - the parts of the SDL 1.2 API that Berusky uses, on top of SDL2.
 *
 * Written for fredygames.com to build Berusky for the browser with Emscripten's SDL2 port.
 * Copyright (C) 2026 FredyGames. Same license as Berusky: GNU GPL version 2 or later.
 *
 * The game's own <SDL/SDL.h> and <SDL/SDL_image.h> resolve to this header (the build script points
 * the include path at a folder whose SDL/ headers include it). Only covers what the game calls: the
 * video mode (one window, a 32-bit software screen surface shown through a streaming texture),
 * SDL 1.2 surface flags, DisplayFormat, SetAlpha, the keyboard state array and key repeat.
 */
#ifndef SDL12SHIM_H
#define SDL12SHIM_H

#include "SDL.h"
#include "SDL_image.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef SDL_Keycode SDLKey;
typedef int SDLMod;		/* SDL2 keeps the modifiers of an event in a Uint16 */

/* SDL 1.2 flags. Values chosen so they never collide with SDL2 surface flags; any non-zero flag
 * turns SDL2's colour key on, as SDL_SRCCOLORKEY did. */
#define SDL_SRCCOLORKEY		0x00001000
#define SDL_SRCALPHA		0x00010000
#define SDL_HWSURFACE		0x00100000
#define SDL_FULLSCREEN		0x00800000

/* Old key names */
#define SDLK_KP0		SDLK_KP_0
#define SDLK_KP1		SDLK_KP_1
#define SDLK_KP2		SDLK_KP_2
#define SDLK_KP3		SDLK_KP_3
#define SDLK_KP4		SDLK_KP_4
#define SDLK_KP5		SDLK_KP_5
#define SDLK_KP6		SDLK_KP_6
#define SDLK_KP7		SDLK_KP_7
#define SDLK_KP8		SDLK_KP_8
#define SDLK_KP9		SDLK_KP_9

SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);
void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
int SDL_WM_ToggleFullScreen(SDL_Surface *surface);
void SDL_WM_SetCaption(const char *title, const char *icon);
int SDL_EnableKeyRepeat(int delay, int interval);
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flags, Uint8 alpha);
SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);

/* SDL 1.2's key state array was indexed by key symbol; SDL2's is indexed by scancode. The game
 * indexes it through SDL12_KEY (see the patch). */
#define SDL_GetKeyState(n)	((Uint8 *)SDL_GetKeyboardState(n))
#define SDL12_KEY(k)		((int)SDL_GetScancodeFromKey((SDL_Keycode)(k)))

#define SDL_DEFAULT_REPEAT_DELAY	500
#define SDL_DEFAULT_REPEAT_INTERVAL	30

#ifdef __cplusplus
}
#endif

#endif /* SDL12SHIM_H */
