$ show sdlpal/sdlpal
SDLPAL is a cross-platform, open-source reimplementation of the classic Chinese RPG "Legend of Sword and Fairy" (PAL). The engine loads original game data (provided separately by the user) and reproduces the full game experience including battle systems, map exploration, menu interactions, script-driven events, and cutscenes. It is built as a monolithic C/C++ application using SDL for input, video, and audio, with optional OpenGL rendering and GLSL shader support. The codebase includes a comprehensive platform abstraction layer supporting Windows (desktop and UWP), Linux, macOS, Android, iOS, 3DS, Wii, Emscripten (web), and libretro. Audio is handled through a modular player interface that can use native MIDI, software synthesis (TiMidity, OPL emulation via MAME/DOSBox/Nuked cores), or compressed codecs (MP3 via libmad, Ogg Vorbis, Opus). The project is actively maintained, with recent commits and multiple CI workflows. While the core game logic is tightly coupled to PAL's data formats, many individual subsystems (configuration, audio players, OPL emulation wrappers, binary I/O, resamplers, font loaders, and decompression routines) are cleanly abstracted and could be reused in other projects with minimal adaptation.
The LLM identified 7 files worth highlighting for reuse:
A minimal, self-contained MIDI file parser implemented as a single header. It loads a MIDI file from disk or memory into a linked list of events (note on/off, tempo, etc.). No external dependencies beyond standard C. Easily extractable for any project needing simple MIDI parsing.
A header-only wrapper that loads images (PNG, JPEG, BMP, etc.) into SDL surfaces using the stb_image library. Provides two functions: STBIMG_Load (filename) and STBIMG_Load_RW (SDL_RWops). Ideal for any SDL project that needs simple image loading without additional dependencies.
A high-quality audio resampler supporting four interpolation modes: zero-order hold, linear, cubic spline, and sinc (windowed sinc with adjustable window width). The API is simple (Resample, ResampleGetBufferSize) and operates on float arrays. Can be extracted and reused in any audio processing pipeline.
A configuration system that defines a fixed set of typed items (booleans, integers, strings) using an enum. Provides getter/setter functions that validate types and handle defaults. Also includes load/save to file. The design is clean and could be reused for any application needing a simple, type-safe config store.
A set of C++ classes (binistream, binostream, binfstream) that wrap file/stream I/O with endian-aware reading and writing of integers and floats. Supports seek, tell, and optional byte swapping. The abstraction is lightweight and could be reused in any project needing portable binary data handling.
Implementation of YJ1 and YJ2 decompression algorithms (a combination of Huffman coding and LZSS) used to decompress game assets. The code is self-contained, uses only SDL endian macros for portability, and exposes two functions (YJ1_Decompress, YJ2_Decompress). Could be reused in other projects dealing with similarly compressed data.
A font system that loads bitmap fonts from embedded data or external BDF files, supporting multiple encodings (GBK, Big5, Japanese). Provides glyph lookup by Unicode codepoint and drawing onto SDL surfaces. The modular design allows extraction for any game or tool needing text rendering.