Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a454165
ADD: Support for dynamic linking first version that can be compiled u…
PascalCorpsman Nov 20, 2024
f8d7b34
FIX: SDL_DYNAMIC_LINKING -> SDL_RUNTIME_LOADING
PascalCorpsman Nov 21, 2024
93ac06c
FIX: invalid description
PascalCorpsman Nov 21, 2024
2e90d43
FIX: filename for runtime linking
PascalCorpsman Nov 22, 2024
3aed7a8
FIX: rename _fun -> _func like requested
PascalCorpsman Nov 25, 2024
adc55c4
FIX: It seems that not "everything" was dynamic linked like it should…
PascalCorpsman Jan 5, 2025
e75f7d7
ADD: SDL_PumpEvents to port
PascalCorpsman Jan 13, 2025
b220039
ADD: Port minim needed to use gamecontroller ;)
PascalCorpsman Jan 8, 2026
e1e18d1
ADD: Split runtime linking code into separate files
PascalCorpsman Mar 22, 2026
df74cd7
FIX: compilation for windows
PascalCorpsman Mar 23, 2026
2e1b141
ADD: start adjusting code as requested by Free-Pascal-meets-SDL-Website
PascalCorpsman Mar 27, 2026
de60809
DEL: remove need for .inc file
PascalCorpsman Mar 29, 2026
6601d8e
CHG: lowercase keywords
PascalCorpsman Mar 29, 2026
f37d0e6
ADD: Start moving comments to vars
PascalCorpsman Mar 30, 2026
b376451
FIX: var needs to be above describing comment for hint to work properly
PascalCorpsman Mar 30, 2026
1de09d4
ADD: Move comment to right positions
PascalCorpsman Mar 30, 2026
e54ab86
ADD: fix more comment positions
PascalCorpsman Mar 31, 2026
34f4c9d
DEL: redundant code
PascalCorpsman Apr 1, 2026
4f4a452
CHG: apply projects formating conventions
PascalCorpsman Apr 1, 2026
a5733d1
ADD: Hint as requested
PascalCorpsman Apr 1, 2026
1cedfc5
FIX: compilation
PascalCorpsman Apr 1, 2026
00bbacc
ADD: completed mark as requested
PascalCorpsman Apr 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions units/runtime/sdl.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// based on "sdl.h"

type
PPSDL_Init = ^PSDL_Init;
PSDL_Init = ^TSDL_Init;
TSDL_Init = type cuint32;

const
SDL_INIT_TIMER = TSDL_Init($00000001);
{$EXTERNALSYM SDL_INIT_TIMER}
SDL_INIT_AUDIO = TSDL_Init($00000010);
{$EXTERNALSYM SDL_INIT_AUDIO}
SDL_INIT_VIDEO = TSDL_Init($00000020); // SDL_INIT_VIDEO implies SDL_INIT_EVENTS
{$EXTERNALSYM SDL_INIT_VIDEO}
SDL_INIT_JOYSTICK = TSDL_Init($00000200); // SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS
{$EXTERNALSYM SDL_INIT_JOYSTICK}
SDL_INIT_HAPTIC = TSDL_Init($00001000);
{$EXTERNALSYM SDL_INIT_HAPTIC}
SDL_INIT_GAMECONTROLLER = TSDL_Init($00002000); //turn on game controller also implicitly does JOYSTICK
{$EXTERNALSYM SDL_INIT_GAMECONTROLLER} // SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK
SDL_INIT_EVENTS = TSDL_Init($00004000);
{$EXTERNALSYM SDL_INIT_EVENTS}
SDL_INIT_SENSOR = TSDL_Init($00008000);
{$EXTERNALSYM SDL_INIT_SENSOR}
SDL_INIT_NOPARACHUTE = TSDL_Init($00100000); //Don't catch fatal signals
{$EXTERNALSYM SDL_INIT_NOPARACHUTE} // compatibility; this flag is ignored.
SDL_INIT_EVERYTHING = TSDL_Init(
SDL_INIT_TIMER or
SDL_INIT_AUDIO or
SDL_INIT_VIDEO or
SDL_INIT_EVENTS or
SDL_INIT_JOYSTICK or
SDL_INIT_HAPTIC or
SDL_INIT_GAMECONTROLLER or
SDL_INIT_SENSOR
);
{$EXTERNALSYM SDL_INIT_EVERYTHING}

type
TSDL_Init_func = function(flags: TSDL_Init): cint; cdecl;
var
{**
* This function initializes the subsystems specified by flags
* Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup
* signal handlers for some commonly ignored fatal signals (like SIGSEGV).
*}
SDL_Init : TSDL_Init_func = Nil;


type
TSDL_InitSubSystem_func = function(flags: TSDL_Init): cint; cdecl;
var
{**
* This function initializes specific SDL subsystems
*}
SDL_InitSubSystem : TSDL_InitSubSystem_func = Nil;


type
TSDL_QuitSubSystem_proc = procedure(flags: TSDL_Init); cdecl;
var
{**
* This function cleans up specific SDL subsystems
*}
SDL_QuitSubSystem : TSDL_QuitSubSystem_proc = Nil;


type
TSDL_WasInit_func = function(flags: TSDL_Init): cuint32; cdecl;
var
{**
* This function returns a mask of the specified subsystems which have
* previously been initialized.
*
* If flags is 0, it returns a mask of all initialized subsystems.
*}
SDL_WasInit : TSDL_WasInit_func = Nil;


type
TSDL_Quit_proc = procedure(); cdecl;
var
{**
* This function cleans up all initialized subsystems. You should
* call it upon all exit conditions.
*}
SDL_Quit : TSDL_Quit_proc = Nil;


109 changes: 109 additions & 0 deletions units/runtime/sdlatomic.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// from SDL_atomic.h

{**
* Atomic locks are efficient spinlocks using CPU instructions,
* but are vulnerable to starvation and can spin forever if a thread
* holding a lock has been terminated. For this reason you should
* minimize the code executed inside an atomic lock and never do
* expensive things like API or system calls while holding them.
*
* The atomic locks are not safe to lock recursively.
*}
type
PPSDL_SpinLock = ^PSDL_SpinLock;
PSDL_SpinLock = ^TSDL_SpinLock;
TSDL_SpinLock = type cint;

{**
* Try to lock a spin lock by setting it to a non-zero value.
*}
function SDL_AtomicTryLock(lock: PSDL_SpinLock): TSDL_bool; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicTryLock' {$ENDIF} {$ENDIF};

{**
* Lock a spin lock by setting it to a non-zero value.
*}
function SDL_AtomicLock(lock: PSDL_SpinLock): TSDL_bool; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicLock' {$ENDIF} {$ENDIF};

{**
* Unlock a spin lock by setting it to 0.
*
* Always returns immediately.
*}
procedure SDL_AtomicUnlock(lock: PSDL_SpinLock); cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicUnlock' {$ENDIF} {$ENDIF};

{**
* The compiler barrier prevents the compiler from reordering
* reads and writes to globally visible variables across the call.
*}
procedure SDL_CompilerBarrier();

type
{**
* A type representing an atomic integer value. It is a record
* so people don't accidentally use numeric operations on it.
*}
PPSDL_Atomic = ^PSDL_Atomic;
PSDL_Atomic = ^TSDL_Atomic;
TSDL_Atomic = record
Value: cint
end;

{**
* Set an atomic variable to a new value if it is currently an old value.
*}
function SDL_AtomicCAS(atomic: PSDL_Atomic; oldValue, newValue: cint): TSDL_bool; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicCAS' {$ENDIF} {$ENDIF};

{**
* Set an atomic variable to a new value and return the old one.
*
* This function also acts as a full memory barrier.
*}
function SDL_AtomicSet(atomic: PSDL_Atomic; value: cint): cint; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicSet' {$ENDIF} {$ENDIF};

{**
* Get the value of an atomic variable.
*}
function SDL_AtomicGet(atomic: PSDL_Atomic): cint; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicGet' {$ENDIF} {$ENDIF};

{**
* Add to an atomic variable, and return the old value.
*
* This function also acts as a full memory barrier.
*}
function SDL_AtomicAdd(atomic: PSDL_Atomic; value: cint): cint; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicAdd' {$ENDIF} {$ENDIF};

{**
* Increment an atomic variable used as a reference count.
*}
function SDL_AtomicIncRef(atomic: PSDL_Atomic): cint;
{**
* Decrement an atomic variable used as a reference count
* and check if it reached zero after decrementing.
*}
function SDL_AtomicDecRef(atomic: PSDL_Atomic): Boolean;

{**
* Set a pointer to a new value if it is currently an old value.
*}
function SDL_AtomicCASPtr(ptr: PPointer; oldValue, newValue: Pointer): TSDL_bool; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicCASPtr' {$ENDIF} {$ENDIF};

{**
* Set a pointer to a new value atomically, and return the old value.
*}
function SDL_AtomicSetPtr(ptr: PPointer; value: Pointer): Pointer; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicSetPtr' {$ENDIF} {$ENDIF};

{**
* Get the value of a pointer atomically.
*}
function SDL_AtomicGetPtr(ptr: PPointer): Pointer; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AtomicGetPtr' {$ENDIF} {$ENDIF};

Loading