Skip to content

Commit

Permalink
playdate: First shot at a Playdate port!
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 4, 2024
1 parent 5874d1b commit 31209b7
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 14 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -84,6 +84,7 @@ set(PHYSFS_SRCS
src/physfs_platform_os2.c
src/physfs_platform_qnx.c
src/physfs_platform_android.c
src/physfs_platform_playdate.c
src/physfs_archiver_dir.c
src/physfs_archiver_unpacked.c
src/physfs_archiver_grp.c
Expand Down
7 changes: 5 additions & 2 deletions src/physfs.c
Expand Up @@ -1219,7 +1219,7 @@ int PHYSFS_init(const char *argv0)

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

if (!__PHYSFS_platformInit())
if (!__PHYSFS_platformInit(argv0))
{
if (allocator.Deinit != NULL) allocator.Deinit();
return 0;
Expand Down Expand Up @@ -3248,6 +3248,7 @@ const PHYSFS_Allocator *PHYSFS_getAllocator(void)
} /* PHYSFS_getAllocator */


#ifndef PHYSFS_NO_CRUNTIME_MALLOC
static void *mallocAllocatorMalloc(PHYSFS_uint64 s)
{
if (!__PHYSFS_ui64FitsAddressSpace(s))
Expand All @@ -3271,16 +3272,18 @@ static void mallocAllocatorFree(void *ptr)
#undef free
free(ptr);
} /* mallocAllocatorFree */

#endif

static void setDefaultAllocator(void)
{
assert(!externalAllocator);
allocator.Init = NULL;
allocator.Deinit = NULL;
#ifndef PHYSFS_NO_CRUNTIME_MALLOC
allocator.Malloc = mallocAllocatorMalloc;
allocator.Realloc = mallocAllocatorRealloc;
allocator.Free = mallocAllocatorFree;
#endif
} /* setDefaultAllocator */


Expand Down
5 changes: 5 additions & 0 deletions src/physfs.h
Expand Up @@ -524,6 +524,11 @@ typedef struct PHYSFS_AndroidInit
* succeed, but PHYSFS_getBaseDir() and PHYSFS_getPrefDir() will be
* incorrect.
*
* \warning On Playdate, argv0 should be a non-NULL pointer to a PlaydateAPI
* struct. PhysicsFS uses this object for system-level access and
* will hold it until PHYSFS_deinit is called.
* If you pass a NULL here, PhysicsFS will crash.
*
* \param argv0 the argv[0] string passed to your program's mainline.
* This may be NULL on most platforms (such as ones without a
* standard main() function), but you should always try to pass
Expand Down
13 changes: 10 additions & 3 deletions src/physfs_internal.h
Expand Up @@ -111,7 +111,9 @@ const void *__PHYSFS_winrtCalcPrefDir(void);

/* atomic operations. */
/* increment/decrement operations return the final incremented/decremented value. */
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#ifdef PHYSFS_PLATFORM_PLAYDATE
#define PHYSFS_NEED_ATOMIC_OP_FALLBACK 1
#elif defined(_MSC_VER) && (_MSC_VER >= 1500)
#include <intrin.h>
__PHYSFS_COMPILE_TIME_ASSERT(LongEqualsInt, sizeof (int) == sizeof (long));
#define __PHYSFS_ATOMIC_INCR(ptrval) _InterlockedIncrement((long*)(ptrval))
Expand All @@ -130,6 +132,9 @@ extern __inline int _xadd_watcom(volatile int *a, int v);
#define __PHYSFS_ATOMIC_DECR(ptrval) (_xadd_watcom(ptrval, -1)-1)
#else
#define PHYSFS_NEED_ATOMIC_OP_FALLBACK 1
#endif

#ifdef PHYSFS_NEED_ATOMIC_OP_FALLBACK
int __PHYSFS_ATOMIC_INCR(int *ptrval);
int __PHYSFS_ATOMIC_DECR(int *ptrval);
#endif
Expand Down Expand Up @@ -466,12 +471,14 @@ void __PHYSFS_DirTreeDeinit(__PHYSFS_DirTree *dt);

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


/*
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_platform_android.c
Expand Up @@ -18,7 +18,7 @@
static char *prefpath = NULL;


int __PHYSFS_platformInit(void)
int __PHYSFS_platformInit(const char *argv0)
{
return 1; /* always succeed. */
} /* __PHYSFS_platformInit */
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_platform_apple.m
Expand Up @@ -16,7 +16,7 @@

#include "physfs_internal.h"

int __PHYSFS_platformInit(void)
int __PHYSFS_platformInit(const char *argv0)
{
return 1; /* success. */
} /* __PHYSFS_platformInit */
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_platform_haiku.cpp
Expand Up @@ -26,7 +26,7 @@

#include "physfs_internal.h"

int __PHYSFS_platformInit(void)
int __PHYSFS_platformInit(const char *argv0)
{
return 1; /* always succeed. */
} /* __PHYSFS_platformInit */
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_platform_ogc.c
Expand Up @@ -378,7 +378,7 @@ void __PHYSFS_platformReleaseMutex(void *mutex)



int __PHYSFS_platformInit(void)
int __PHYSFS_platformInit(const char *argv0)
{
return 1; /* always succeed. */
} /* __PHYSFS_platformInit */
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_platform_os2.c
Expand Up @@ -292,7 +292,7 @@ static void prepUnicodeSupport(void)
} /* prepUnicodeSupport */


int __PHYSFS_platformInit(void)
int __PHYSFS_platformInit(const char *argv0)
{
prepUnicodeSupport();
return 1; /* ready to go! */
Expand Down

0 comments on commit 31209b7

Please sign in to comment.