Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ctypes unit for c-type definitions if FPC is used for compilation #29

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bbcd1ab
Add ctypes unit to sdl2 uses clause if FPC
Free-Pascal-meets-SDL-Website Sep 30, 2021
9104d7b
Add compiler check for all c-types
Free-Pascal-meets-SDL-Website Sep 30, 2021
79de133
Add ctypes.inc for Delphi (and other non-FPC compilers)
Free-Pascal-meets-SDL-Website Oct 5, 2021
8c2ecf4
Replace SInt32 by cint32
Free-Pascal-meets-SDL-Website Oct 5, 2021
45d2613
Replace SInt64 by cint64
Free-Pascal-meets-SDL-Website Oct 5, 2021
b0aba5c
Replace SInt16 by cint16
Free-Pascal-meets-SDL-Website Oct 5, 2021
8b502d3
Replace SInt8 by cint8 (not used)
Free-Pascal-meets-SDL-Website Oct 5, 2021
f79338a
Replace UInt32 by cuint32
Free-Pascal-meets-SDL-Website Oct 5, 2021
ef894f5
Replace UInt64 by cuint64
Free-Pascal-meets-SDL-Website Oct 5, 2021
a0b9f38
Replace UInt8 by cuint8
Free-Pascal-meets-SDL-Website Oct 5, 2021
7e819d2
Add ctypes to uses clause in all units
Free-Pascal-meets-SDL-Website Oct 5, 2021
2def0b6
Fix-replace some var name to ctypes names
Free-Pascal-meets-SDL-Website Oct 5, 2021
fa30184
Fix some var names in sdl2_gfx
Free-Pascal-meets-SDL-Website Oct 5, 2021
cfeb627
Replace size_t with csize_t
Free-Pascal-meets-SDL-Website Oct 9, 2021
d496b5c
Quickfix for csize_t
Free-Pascal-meets-SDL-Website Oct 9, 2021
2842c16
Replace Integer by cint
Free-Pascal-meets-SDL-Website Oct 20, 2021
d7b2a56
Replace PSInt32 by pcint32
Free-Pascal-meets-SDL-Website Oct 20, 2021
edc4a7c
Replace SInt64/PSInt64/PUInt64 by cint64/pcint64/pcuint64 (nearly unu…
Free-Pascal-meets-SDL-Website Oct 20, 2021
be81966
Replace PUInt32 by pcuint32
Free-Pascal-meets-SDL-Website Oct 20, 2021
f0a7aae
Replace SInt16/UInt16 by pcint16/pcuint16
Free-Pascal-meets-SDL-Website Oct 20, 2021
46d8130
Replace PSint8/PUInt8/PPUint8 by pcint8/pcuint8/ppcuint8
Free-Pascal-meets-SDL-Website Oct 20, 2021
6e1a11d
Replace Single+Float/PSingle+PFloat by cfloat/pcfloat
Free-Pascal-meets-SDL-Website Oct 20, 2021
9871871
Replace PInt by pcint
Free-Pascal-meets-SDL-Website Oct 20, 2021
8158c7a
Uncomment ctypes.inc + add header comment
Free-Pascal-meets-SDL-Website Oct 20, 2021
3e191a6
Quick fix: Replace missed data type names in sdl2_gfx.pas
Free-Pascal-meets-SDL-Website Oct 20, 2021
afc6adb
Remove comp.-cond. to include ctypes.inc in all SDL units
Free-Pascal-meets-SDL-Website Oct 20, 2021
8104b96
Fix identifier (cuint8) not found error if not using ctypes unit
Free-Pascal-meets-SDL-Website Oct 20, 2021
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
97 changes: 97 additions & 0 deletions units/ctypes.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// C data types

{
Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <[email protected]>

Pascal-Header-Conversion
Copyright (C) 2012-2020 Tim Blume aka End/EV1313

SDL2-for-Pascal
Copyright (C) 2020-2021 PGD Community

This file is part of the project above. It has solely the purpose
to map common C data types correctly by Pascal compilers.

FPC: Most C data types are found in the native ctypes unit.
Delphi + others: Relies on this file for C data type mapping.

These native C types should be strictly separated from
types defined by SDL which can be found in sdlstdinc.inc.
}

{$IFNDEF FPC}
type
DWord = LongWord;

pcint = ^cint;
cint = Integer;
{$EXTERNALSYM cint}

pcint8 = ^cint8;
cint8 = ShortInt;
{$EXTERNALSYM cint8}

pcuint8 = ^cuint8;
cuint8 = Byte;
{$EXTERNALSYM cuint8}

pcint16 = ^cint16;
cint16 = SmallInt;
{$EXTERNALSYM cint16}

pcuint16 = ^cuint16;
cuint16 = Word;
{$EXTERNALSYM cuint16}

pcint32 = ^cint32;
cint32 = LongInt;
{$EXTERNALSYM cint32}

pcuint32 = ^cuint32;
cuint32 = LongWord;
{$EXTERNALSYM cuint32}

{$IFNDEF Has_Int64}
pcint64 = ^cint64;
cint64 = record
hi: cuint32;
lo: cuint32;
end;
{$EXTERNALSYM cint64}

pcuint64 = ^cuint64;
cuint64 = record
hi: cuint32;
lo: cuint32;
end;
{$EXTERNALSYM cuint64}
{$ELSE}
pcint64 = ^cint64;
cint64 = Int64;
{$EXTERNALSYM cint64}

pcuint64 = ^cuint64;
cuint64 = UInt64;
{$EXTERNALSYM cuint64}
{$ENDIF}

{$IFNDEF WIN64}
csize_t = cuint32;
{$ELSE}
csize_t = cuint64;
{$ENDIF}
{$EXTERNALSYM SIZE_T}

pcfloat = ^cfloat;
cfloat = Single;
{$EXTERNALSYM cfloat}
{$ENDIF}

{ Data types for all compilers }
type
PUInt8Array = ^TUInt8Array;
TUInt8Array = array [0..MAXINT shr 1] of cuint8;

ppcuint8 = ^pcuint8;

8 changes: 4 additions & 4 deletions units/sdl.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//from "sdl.h"

type
TSDL_Init = type UInt32;
TSDL_Init = type cuint32;

const
SDL_INIT_TIMER = TSDL_Init($00000001);
Expand Down Expand Up @@ -40,13 +40,13 @@ const
* signal handlers for some commonly ignored fatal signals (like SIGSEGV).
*}

function SDL_Init(flags: TSDL_Init): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Init' {$ENDIF} {$ENDIF};
function SDL_Init(flags: TSDL_Init): cint32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Init' {$ENDIF} {$ENDIF};

{**
* This function initializes specific SDL subsystems
*}

function SDL_InitSubSystem(flags: TSDL_Init): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_InitSubSystem' {$ENDIF} {$ENDIF};
function SDL_InitSubSystem(flags: TSDL_Init): cint32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_InitSubSystem' {$ENDIF} {$ENDIF};

{**
* This function cleans up specific SDL subsystems
Expand All @@ -61,7 +61,7 @@ procedure SDL_QuitSubSystem(flags: TSDL_Init) cdecl; external SDL_LibName {$IFDE
* If flags is 0, it returns a mask of all initialized subsystems.
*}

function SDL_WasInit(flags: TSDL_Init): UInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WasInit' {$ENDIF} {$ENDIF};
function SDL_WasInit(flags: TSDL_Init): cuint32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WasInit' {$ENDIF} {$ENDIF};

{**
* This function cleans up all initialized subsystems. You should
Expand Down
36 changes: 22 additions & 14 deletions units/sdl2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,17 @@ interface

{$IFDEF WINDOWS}
uses
{$IFDEF FPC}
ctypes,
{$ENDIF}
Windows;
{$ENDIF}

{$IF DEFINED(UNIX) AND NOT DEFINED(ANDROID)}
uses
{$IFDEF FPC}
ctypes,
{$ENDIF}
{$IFDEF DARWIN}
CocoaAll;
{$ELSE}
Expand Down Expand Up @@ -135,6 +141,8 @@ interface
{$ENDIF}
{$ENDIF}


{$I ctypes.inc} // C data types
{$I sdlstdinc.inc}
{$I sdlversion.inc}
{$I sdlerror.inc}
Expand Down Expand Up @@ -183,7 +191,7 @@ procedure SDL_VERSION(out x: TSDL_Version);
x.patch := SDL_PATCHLEVEL;
end;

function SDL_VERSIONNUM(X,Y,Z: UInt32): Cardinal;
function SDL_VERSIONNUM(X,Y,Z: cuint32): Cardinal;
begin
Result := X*1000 + Y*100 + Z;
end;
Expand All @@ -201,7 +209,7 @@ function SDL_VERSION_ATLEAST(X,Y,Z: Cardinal): Boolean;
end;

//from "sdl_mouse.h"
function SDL_Button(button: SInt32): SInt32;
function SDL_Button(button: cint32): cint32;
begin
Result := 1 shl (button - 1);
end;
Expand Down Expand Up @@ -237,39 +245,39 @@ function SDL_PointInRect(const p: PSDL_Point; const r: PSDL_Rect): Boolean;

//from "sdl_rwops.h"

function SDL_RWsize(ctx: PSDL_RWops): SInt64;
function SDL_RWsize(ctx: PSDL_RWops): cint64;
begin
Result := ctx^.size(ctx);
end;

function SDL_RWseek(ctx: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64;
function SDL_RWseek(ctx: PSDL_RWops; offset: cint64; whence: cint32): cint64;
begin
Result := ctx^.seek(ctx,offset,whence);
end;

function SDL_RWtell(ctx: PSDL_RWops): SInt64;
function SDL_RWtell(ctx: PSDL_RWops): cint64;
begin
Result := ctx^.seek(ctx, 0, RW_SEEK_CUR);
end;

function SDL_RWread(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t;
function SDL_RWread(ctx: PSDL_RWops; ptr: Pointer; size: csize_t; n: csize_t): csize_t;
begin
Result := ctx^.read(ctx, ptr, size, n);
end;

function SDL_RWwrite(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t;
function SDL_RWwrite(ctx: PSDL_RWops; ptr: Pointer; size: csize_t; n: csize_t): csize_t;
begin
Result := ctx^.write(ctx, ptr, size, n);
end;

function SDL_RWclose(ctx: PSDL_RWops): SInt32;
function SDL_RWclose(ctx: PSDL_RWops): cint32;
begin
Result := ctx^.close(ctx);
end;

//from "sdl_audio.h"

function SDL_LoadWAV(_file: PAnsiChar; spec: PSDL_AudioSpec; audio_buf: PPUInt8; audio_len: PUInt32): PSDL_AudioSpec;
function SDL_LoadWAV(_file: PAnsiChar; spec: PSDL_AudioSpec; audio_buf: ppcuint8; audio_len: pcuint32): PSDL_AudioSpec;
begin
Result := SDL_LoadWAV_RW(SDL_RWFromFile(_file, 'rb'), 1, spec, audio_buf, audio_len);
end;
Expand Down Expand Up @@ -349,7 +357,7 @@ function SDL_LoadBMP(_file: PAnsiChar): PSDL_Surface;
end;

function SDL_SaveBMP(const surface: PSDL_Surface; const filename: AnsiString
): sInt32;
): cint32;
begin
Result := SDL_SaveBMP_RW(surface, SDL_RWFromFile(PAnsiChar(filename), 'wb'), 1)
end;
Expand Down Expand Up @@ -393,23 +401,23 @@ function SDL_WINDOWPOS_ISCENTERED(X: Variant): Variant;

//from "sdl_events.h"

function SDL_GetEventState(type_: TSDL_EventType): UInt8;
function SDL_GetEventState(type_: TSDL_EventType): cuint8;
begin
Result := SDL_EventState(type_, SDL_QUERY);
end;

// from "sdl_timer.h"
function SDL_TICKS_PASSED(const A, B: UInt32): Boolean;
function SDL_TICKS_PASSED(const A, B: cuint32): Boolean;
begin
Result := ((Int64(B) - Int64(A)) <= 0)
Result := ((cint64(B) - cint64(A)) <= 0)
end;

// from "sdl_gamecontroller.h"
{**
* Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
*}
function SDL_GameControllerAddMappingsFromFile(const FilePath: PAnsiChar
): SInt32;
): cint32;
begin
Result := SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(FilePath, 'rb'), 1)
end;
Expand Down
Loading