/*
 * cfsdl12.h - the parts of the SDL 1.2 API that Crimson Fields uses, on top of SDL2.
 *
 * Written for fredygames.com to build Crimson Fields for the browser with Emscripten's SDL2 port.
 * Copyright (C) 2026 FredyGames. Same license as Crimson Fields: GNU GPL version 2 or later.
 *
 * Included before every source file of the game and of its data tools (emcc -include). It covers
 * only what they call:
 *   - the video mode: one window with a software screen surface, shown through a streaming texture;
 *   - SDL 1.2 surface flags, SDL_SetAlpha and SDL_DisplayFormat;
 *   - events in SDL 1.2 terms: SDL 1.2 key numbers (the game keeps them in its settings and masks
 *     them with 0x1ff), the typed character in keysym.unused (SDL 1.2's keysym.unicode), and the
 *     mouse wheel as buttons 4 and 5;
 *   - a few window calls that have no meaning in a browser page.
 */
#ifndef CFSDL12_H
#define CFSDL12_H

#include "SDL.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef SDL_Keycode SDLKey;
typedef SDL_Keysym SDL_keysym;

/* SDL 1.2 flags. Values chosen so they never collide with SDL2 surface flags. */
#define SDL_SWSURFACE		0x00000000
#define SDL_SRCCOLORKEY		0x00001000
#define SDL_SRCALPHA		0x00010000
#define SDL_HWSURFACE		0x00100000
#define SDL_FULLSCREEN		0x00800000

#define SDL_BUTTON_WHEELUP	4
#define SDL_BUTTON_WHEELDOWN	5

/* SDL 1.2 key numbers. Keys below 128 are ASCII in both versions. */
#undef SDLK_UNKNOWN
#define SDLK_UNKNOWN		0
#define SDLK_FIRST		0
#define SDLK_LAST		323
#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_ENTER
#define SDLK_KP_ENTER		271
#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_F13
#define SDLK_F13		294
#undef SDLK_F14
#define SDLK_F14		295
#undef SDLK_F15
#define SDLK_F15		296

SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
SDL_Rect **SDL_ListModes(void *format, Uint32 flags);
void SDL_WM_SetCaption(const char *title, const char *icon);
void SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask);
int SDL_WM_IconifyWindow(void);
int SDL_WM_ToggleFullScreen(SDL_Surface *surface);
int SDL_EnableUNICODE(int enable);
int SDL_EnableKeyRepeat(int delay, int interval);
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flags, Uint8 alpha);
SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);
int CF_PollEvent(SDL_Event *event);
int CF_WaitEvent(SDL_Event *event);

#define SDL_DEFAULT_REPEAT_DELAY	500
#define SDL_DEFAULT_REPEAT_INTERVAL	30

#define SDL_PollEvent(e)	CF_PollEvent(e)
#define SDL_WaitEvent(e)	CF_WaitEvent(e)

#ifdef __cplusplus
}
#endif

#endif /* CFSDL12_H */
