playdate support
This commit is contained in:
30
source/setup_playdate.c
Normal file
30
source/setup_playdate.c
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#include "pd_api.h"
|
||||
|
||||
typedef int (PDEventHandler)(PlaydateAPI* playdate, PDSystemEvent event, uint32_t arg);
|
||||
|
||||
extern PDEventHandler eventHandler;
|
||||
|
||||
static void* (*pdrealloc)(void* ptr, size_t size);
|
||||
|
||||
int eventHandlerShim(PlaydateAPI* playdate, PDSystemEvent event, uint32_t arg)
|
||||
{
|
||||
if ( event == kEventInit )
|
||||
pdrealloc = playdate->system->realloc;
|
||||
|
||||
return eventHandler(playdate, event, arg);
|
||||
}
|
||||
|
||||
#if TARGET_PLAYDATE
|
||||
|
||||
void* _malloc_r(struct _reent* _REENT, size_t nbytes) { return pdrealloc(NULL,nbytes); }
|
||||
void* _realloc_r(struct _reent* _REENT, void* ptr, size_t nbytes) { return pdrealloc(ptr,nbytes); }
|
||||
void _free_r(struct _reent* _REENT, void* ptr ) { if ( ptr != NULL ) pdrealloc(ptr,0); }
|
||||
|
||||
#else
|
||||
|
||||
void* malloc(size_t nbytes) { return pdrealloc(NULL,nbytes); }
|
||||
void* realloc(void* ptr, size_t nbytes) { return pdrealloc(ptr,nbytes); }
|
||||
void free(void* ptr ) { if ( ptr != NULL ) pdrealloc(ptr,0); }
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user