# m2SDL — SDL2 bindings for GNU Modula-2 Thin `DEFINITION MODULE FOR "C"` bindings of SDL2 for `gm2` (GCC 16 / GNU Modula-2), starting with init, video, version, timer, error and a minimal event pump. ## Status Starter set, verified with gm2 + SDL 2.32.4 on Linux: | Module | C header | Contents | |---|---|---| | `SDL2` | ``, ``, `` | init/quit, `GetError`, `Delay`, ticks, performance counter | | `SDLVersion` | `` | `SDLVersion` record, `GetVersion`, `GetRevision` | | `SDLVideo` | `` | window create/destroy, title, size, show/hide | | `SDLEvents` | `` | `PumpEvents`, `PollEvent`, `WaitEvent`, `PushEvent`, quit/key/mouse type ids (opaque buffer for now) | | `SDLRect` | `` | pure-M2 `SDLPoint`/`SDLRect` + helpers | | `SDLRender` | `` | window+renderer creation, draw color, clear/present, points/lines/rects | | `SDLKey` | `` | pure-M2 keycode constants (arrows, Q/R, Escape...) | | `SDLUtils` (`lib/`) | — | `CStrToM2()` + `GetErrorString()` helpers, `DrainEvents()` quit pump, `PollM2Event()` decoded poll | Full `SDL_Event` union mapping, renderer, audio and gamepad come next. ## Layout ```text m2SDL/ src/ FOR "C" .def bindings (+ pure-M2 SDLRect) lib/ pure-M2 helpers built on the bindings (SDLUtils) tests/ gm2 smoke tests + run_tests.sh examples/ hello_window, version, event_loop showcases/ ports of SDL-main renderer examples (clear, rectangles, primitives) build/ generated binaries (git-ignored) ``` ## Prerequisites - `gm2` (tested: 16.0.1 experimental, `~/bin/Modula2/Gm2/bin/gm2`) - SDL2 dev files (`pkg-config --cflags --libs sdl2`, tested: 2.32.4) ```sh export PATH=$HOME/bin/Modula2/Gm2/bin:$PATH ``` ## Build & test ```sh make # tests + examples + showcases -> build/ ./tests/run_tests.sh SDL_VIDEODRIVER=dummy ./tests/run_tests.sh # headless ./build/examples/hello_window ./build/examples/version ./build/examples/event_loop ./build/showcases/showcase_clear # or rectangles / primitives ``` `make check` is `make tests` + the runner script. ## Usage ```modula2 FROM SDL2 IMPORT SDL_Init, SDL_Quit, SDLInitVideo; FROM SDLVideo IMPORT SDL_CreateWindow, SDL_DestroyWindow, WindowShown, WindowPosUndefined; ``` Compile your program with the binding search path and the C library: ```sh gm2 -Isrc -Ilib myprog.mod src/SDLRect.mod lib/SDLUtils.mod -o myprog -lSDL2 ``` Notes: - `CARDINAL <-> Uint32`, `INTEGER <-> int` (see gm2 "Elementary data types" node); opaque `SDL_Window *` / `char *` travel as `ADDRESS`. - `ARRAY OF CHAR` parameters map onto `char *`: string literals and `CHAR` arrays can be passed directly (see gm2 "Interface to C" node). - `VAR` record parameters map onto `T *`: `SDL_GetVersion(v)`, `SDL_GetWindowSize(win, w, h)`. ## Roadmap 1. Full `SDL_Event` variant record + typed poll/wait. 2. Renderer + texture + surface subset. 3. Audio + joystick/gamepad subset. 4. SDL3 bindings alongside (sources at `../../SDL3-3.2.28`, not yet installed).