SDL3Utils.def 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. DEFINITION MODULE SDL3Utils ;
  2. (*
  3. m2SDL3 - small pure-Modula-2 helpers over the FOR "C" bindings.
  4. CStrToM2 copies NUL-terminated C strings (ADDRESS) into
  5. Modula-2 CHAR arrays (NUL-terminated, truncated to fit).
  6. PollM2Event decodes one queued SDL_Event into a small record:
  7. SDL3 puts the Uint32 type at offset 0 of every event; key events
  8. (SDL_KeyboardEvent) carry the Uint32 keycode at offset 28 (see
  9. <SDL3/SDL_events.h>, verified with offsetof). Both QUIT (0100H)
  10. and WINDOW_CLOSE_REQUESTED (0210H) map to evQuit, so a plain
  11. "close window" button press terminates DrainEvents loops.
  12. VersionMajor/Minor/Micro decode the int returned by
  13. SDL3Version.SDL_GetVersion (major*1000000+minor*1000+micro).
  14. *)
  15. FROM SYSTEM IMPORT ADDRESS;
  16. EXPORT UNQUALIFIED
  17. EventKind, M2Event,
  18. CStrToM2, GetErrorString, PollM2Event, DrainEvents,
  19. VersionMajor, VersionMinor, VersionMicro;
  20. TYPE
  21. EventKind = (evQuit, evKey, evOther);
  22. M2Event = RECORD
  23. kind: EventKind;
  24. sym: INTEGER; (* valid when kind = evKey *)
  25. pressed: BOOLEAN; (* valid when kind = evKey *)
  26. END;
  27. PROCEDURE CStrToM2 (src: ADDRESS; VAR dst: ARRAY OF CHAR);
  28. PROCEDURE GetErrorString (VAR buf: ARRAY OF CHAR);
  29. PROCEDURE PollM2Event (VAR ev: M2Event) : BOOLEAN;
  30. PROCEDURE DrainEvents (VAR quit: BOOLEAN);
  31. PROCEDURE VersionMajor (v: INTEGER) : INTEGER;
  32. PROCEDURE VersionMinor (v: INTEGER) : INTEGER;
  33. PROCEDURE VersionMicro (v: INTEGER) : INTEGER;
  34. END SDL3Utils.