/*
 * SDL.h for the fredygames.com browser build of Fish Fillets NG: the game was written for SDL 1.2, and
 * this header, with sdl12shim.cpp, gives it the few SDL 1.2 calls it uses on top of SDL2 (Emscripten's
 * port), using SDL2's own surface types. Only what the game calls is here.
 *
 * Keys: SDL 1.2 indexes the keyboard state by key symbol. Here every key symbol is "folded" to a small
 * index (printable keys keep their code, the keys SDL2 numbers from scancodes become 256 + scancode), the
 * SDLK_ names the game uses are redefined to those indexes, and SDL_PollEvent folds keysym.sym before the
 * game sees it.
 *
 * Copyright (C) 2026 FredyGames. GNU GPL version 2 or later, like Fish Fillets NG.
 */
#ifndef FY_SDL12_H
#define FY_SDL12_H

#include <SDL2/SDL.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef SDL_HWSURFACE
#define SDL_HWSURFACE 0x00000001
#endif
#define SDL_ANYFORMAT 0x10000000
#define SDL_HWPALETTE 0x20000000
#define SDL_FULLSCREEN 0x80000000
#define SDL_SRCCOLORKEY 0x00001000
#define SDL_SRCALPHA 0x00010000

typedef SDL_Keysym SDL_keysym;
typedef int SDLKey;

#undef SDLK_LAST
#define SDLK_LAST 1024
#define FY_SC(s) (256 + (s))
#undef SDLK_UP
#undef SDLK_DOWN
#undef SDLK_LEFT
#undef SDLK_RIGHT
#undef SDLK_F1
#undef SDLK_F2
#undef SDLK_F3
#undef SDLK_F5
#undef SDLK_F6
#undef SDLK_F10
#undef SDLK_F11
#undef SDLK_KP_PLUS
#undef SDLK_KP_MINUS
#define SDLK_UP FY_SC(SDL_SCANCODE_UP)
#define SDLK_DOWN FY_SC(SDL_SCANCODE_DOWN)
#define SDLK_LEFT FY_SC(SDL_SCANCODE_LEFT)
#define SDLK_RIGHT FY_SC(SDL_SCANCODE_RIGHT)
#define SDLK_F1 FY_SC(SDL_SCANCODE_F1)
#define SDLK_F2 FY_SC(SDL_SCANCODE_F2)
#define SDLK_F3 FY_SC(SDL_SCANCODE_F3)
#define SDLK_F5 FY_SC(SDL_SCANCODE_F5)
#define SDLK_F6 FY_SC(SDL_SCANCODE_F6)
#define SDLK_F10 FY_SC(SDL_SCANCODE_F10)
#define SDLK_F11 FY_SC(SDL_SCANCODE_F11)
#define SDLK_KP_PLUS FY_SC(SDL_SCANCODE_KP_PLUS)
#define SDLK_KP_MINUS FY_SC(SDL_SCANCODE_KP_MINUS)

SDL_Surface *fy_SetVideoMode(int width, int height, int bpp, Uint32 flags);
SDL_Surface *fy_GetVideoSurface(void);
int fy_Flip(SDL_Surface *screen);
void fy_WM_SetCaption(const char *title, const char *icon);
int fy_PollEvent(SDL_Event *event);
Uint8 *fy_GetKeyState(int *numkeys);
const char *fy_GetKeyName(int sym);
Uint16 fy_Unicode(int sym, Uint16 mod);
SDL_Surface *fy_DisplayFormat(SDL_Surface *surface);
SDL_Surface *fy_DisplayFormatAlpha(SDL_Surface *surface);
int fy_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
int fy_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
Uint32 fy_GetColorKey(SDL_Surface *surface);
void fy_WarpMouse(Uint16 x, Uint16 y);

#define SDL_SetVideoMode fy_SetVideoMode
#define SDL_GetVideoSurface fy_GetVideoSurface
#define SDL_Flip fy_Flip
#define SDL_WM_SetCaption fy_WM_SetCaption
#define SDL_WM_SetIcon(icon, mask) ((void)0)
#define SDL_WM_ToggleFullScreen(screen) 1
#define SDL_PollEvent fy_PollEvent
#define SDL_GetKeyState fy_GetKeyState
#define SDL_GetKeyName fy_GetKeyName
#define SDL_EnableUNICODE(on) 0
#define SDL_DisplayFormat fy_DisplayFormat
#define SDL_DisplayFormatAlpha fy_DisplayFormatAlpha
#define SDL_SetColorKey fy_SetColorKey
#define SDL_SetAlpha fy_SetAlpha
#define SDL_WarpMouse fy_WarpMouse

#ifdef __cplusplus
}
#endif

#endif
