Skip to content

Commit 31209b7

Browse files
committed
playdate: First shot at a Playdate port!
1 parent 5874d1b commit 31209b7

14 files changed

+320
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ set(PHYSFS_SRCS
8484
src/physfs_platform_os2.c
8585
src/physfs_platform_qnx.c
8686
src/physfs_platform_android.c
87+
src/physfs_platform_playdate.c
8788
src/physfs_archiver_dir.c
8889
src/physfs_archiver_unpacked.c
8990
src/physfs_archiver_grp.c

src/physfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ int PHYSFS_init(const char *argv0)
12191219

12201220
if ((allocator.Init != NULL) && (!allocator.Init())) return 0;
12211221

1222-
if (!__PHYSFS_platformInit())
1222+
if (!__PHYSFS_platformInit(argv0))
12231223
{
12241224
if (allocator.Deinit != NULL) allocator.Deinit();
12251225
return 0;
@@ -3248,6 +3248,7 @@ const PHYSFS_Allocator *PHYSFS_getAllocator(void)
32483248
} /* PHYSFS_getAllocator */
32493249

32503250

3251+
#ifndef PHYSFS_NO_CRUNTIME_MALLOC
32513252
static void *mallocAllocatorMalloc(PHYSFS_uint64 s)
32523253
{
32533254
if (!__PHYSFS_ui64FitsAddressSpace(s))
@@ -3271,16 +3272,18 @@ static void mallocAllocatorFree(void *ptr)
32713272
#undef free
32723273
free(ptr);
32733274
} /* mallocAllocatorFree */
3274-
3275+
#endif
32753276

32763277
static void setDefaultAllocator(void)
32773278
{
32783279
assert(!externalAllocator);
32793280
allocator.Init = NULL;
32803281
allocator.Deinit = NULL;
3282+
#ifndef PHYSFS_NO_CRUNTIME_MALLOC
32813283
allocator.Malloc = mallocAllocatorMalloc;
32823284
allocator.Realloc = mallocAllocatorRealloc;
32833285
allocator.Free = mallocAllocatorFree;
3286+
#endif
32843287
} /* setDefaultAllocator */
32853288

32863289

src/physfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ typedef struct PHYSFS_AndroidInit
524524
* succeed, but PHYSFS_getBaseDir() and PHYSFS_getPrefDir() will be
525525
* incorrect.
526526
*
527+
* \warning On Playdate, argv0 should be a non-NULL pointer to a PlaydateAPI
528+
* struct. PhysicsFS uses this object for system-level access and
529+
* will hold it until PHYSFS_deinit is called.
530+
* If you pass a NULL here, PhysicsFS will crash.
531+
*
527532
* \param argv0 the argv[0] string passed to your program's mainline.
528533
* This may be NULL on most platforms (such as ones without a
529534
* standard main() function), but you should always try to pass

src/physfs_internal.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ const void *__PHYSFS_winrtCalcPrefDir(void);
111111

112112
/* atomic operations. */
113113
/* increment/decrement operations return the final incremented/decremented value. */
114-
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
114+
#ifdef PHYSFS_PLATFORM_PLAYDATE
115+
#define PHYSFS_NEED_ATOMIC_OP_FALLBACK 1
116+
#elif defined(_MSC_VER) && (_MSC_VER >= 1500)
115117
#include <intrin.h>
116118
__PHYSFS_COMPILE_TIME_ASSERT(LongEqualsInt, sizeof (int) == sizeof (long));
117119
#define __PHYSFS_ATOMIC_INCR(ptrval) _InterlockedIncrement((long*)(ptrval))
@@ -130,6 +132,9 @@ extern __inline int _xadd_watcom(volatile int *a, int v);
130132
#define __PHYSFS_ATOMIC_DECR(ptrval) (_xadd_watcom(ptrval, -1)-1)
131133
#else
132134
#define PHYSFS_NEED_ATOMIC_OP_FALLBACK 1
135+
#endif
136+
137+
#ifdef PHYSFS_NEED_ATOMIC_OP_FALLBACK
133138
int __PHYSFS_ATOMIC_INCR(int *ptrval);
134139
int __PHYSFS_ATOMIC_DECR(int *ptrval);
135140
#endif
@@ -466,12 +471,14 @@ void __PHYSFS_DirTreeDeinit(__PHYSFS_DirTree *dt);
466471

467472
/*
468473
* Initialize the platform. This is called when PHYSFS_init() is called from
469-
* the application.
474+
* the application. argv[0] (or whatever the app is passing) is
475+
* supplied here, since some platforms need it immediately, but this same
476+
* pointer is also passed to __PHYSFS_platformCalcBaseDir a little later.
470477
*
471478
* Return zero if there was a catastrophic failure (which prevents you from
472479
* functioning at all), and non-zero otherwise.
473480
*/
474-
int __PHYSFS_platformInit(void);
481+
int __PHYSFS_platformInit(const char *argv0);
475482

476483

477484
/*

src/physfs_platform_android.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
static char *prefpath = NULL;
1919

2020

21-
int __PHYSFS_platformInit(void)
21+
int __PHYSFS_platformInit(const char *argv0)
2222
{
2323
return 1; /* always succeed. */
2424
} /* __PHYSFS_platformInit */

src/physfs_platform_apple.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "physfs_internal.h"
1818

19-
int __PHYSFS_platformInit(void)
19+
int __PHYSFS_platformInit(const char *argv0)
2020
{
2121
return 1; /* success. */
2222
} /* __PHYSFS_platformInit */

src/physfs_platform_haiku.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "physfs_internal.h"
2828

29-
int __PHYSFS_platformInit(void)
29+
int __PHYSFS_platformInit(const char *argv0)
3030
{
3131
return 1; /* always succeed. */
3232
} /* __PHYSFS_platformInit */

src/physfs_platform_ogc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void __PHYSFS_platformReleaseMutex(void *mutex)
378378

379379

380380

381-
int __PHYSFS_platformInit(void)
381+
int __PHYSFS_platformInit(const char *argv0)
382382
{
383383
return 1; /* always succeed. */
384384
} /* __PHYSFS_platformInit */

src/physfs_platform_os2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static void prepUnicodeSupport(void)
292292
} /* prepUnicodeSupport */
293293

294294

295-
int __PHYSFS_platformInit(void)
295+
int __PHYSFS_platformInit(const char *argv0)
296296
{
297297
prepUnicodeSupport();
298298
return 1; /* ready to go! */

0 commit comments

Comments
 (0)