Skip to content

Commit

Permalink
Fix Playdate support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisible committed Jun 8, 2024
1 parent ff2cfc7 commit 6c8d0db
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
24 changes: 22 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,28 @@ if is_playdate_build
playdate_sdk_path = get_option('playdate_sdk_path')
playdate_sdk_incdir = playdate_sdk_path / 'C_API'
playdate_sdk_dep = declare_dependency(include_directories: playdate_sdk_incdir)
lisiblestd_c_args += '-DLSTD_PLATFORM_PLAYDATE'
lisiblestd_c_args += '-DTARGET_EXTENSION'
lisiblestd_c_args += '-DLSTD_PLATFORM_PLAYDATE=1'
lisiblestd_c_args += [
'-DTARGET_PLAYDATE=1',
'-DTARGET_EXTENSION=1',
'-mthumb',
'-mcpu=cortex-m7',
'-mfloat-abi=hard',
'-mfpu=fpv5-sp-d16',
'-D__FPU_USED=1',
'-falign-functions=16',
'-fomit-frame-pointer',
'-gdwarf-2',
'-fverbose-asm',
'-ffunction-sections',
'-fdata-sections',
'-mword-relocations',
'-fno-common',
'-fno-exceptions',
'-Wno-unknown-pragmas',
'-Wdouble-promotion',
'-O2',
]
lisiblestd_deps += playdate_sdk_dep
endif

Expand Down
8 changes: 3 additions & 5 deletions src/lisiblestd/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@

extern void exit(int);



#ifdef LSTD_PLATFORM_PLAYDATE
#include <pd_api.h>
extern PlaydateAPI* pd;
extern PlaydateAPI *pd;
#define LSTD_ASSERT(expr) \
do { \
if (!(expr)) { \
pd->system->error("Assertion failed:\n\t%s", #expr); \
pd->system->error("Assertion failed: %s", #expr); \
} \
} while (0)

#define LSTD_UNIMPLEMENTED() \
do { \
pd->system->error("Unimpemented code reached"); \
pd->system->error("Unimpemented code reached"); \
} while (0)
#else
#define LSTD_ASSERT(expr) \
Expand Down
14 changes: 14 additions & 0 deletions src/lisiblestd/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ typedef enum {

extern LogLevel lstd_log_level;

#ifdef LSTD_PLATFORM_PLAYDATE
#include <pd_api.h>
extern PlaydateAPI *pd;
#define LOG(log_level, ...) \
do { \
if (lstd_log_level <= log_level) { \
pd->system->logToConsole(LSTD_LOG_PREFIX, log_level_to_str(log_level), \
__FILE__, __LINE__); \
pd->system->logToConsole(__VA_ARGS__); \
pd->system->logToConsole("\n"); \
} \
} while (0)
#else
#define LOG(log_level, ...) \
do { \
if (lstd_log_level <= log_level) { \
Expand All @@ -24,6 +37,7 @@ extern LogLevel lstd_log_level;
fprintf(stderr, "\n"); \
} \
} while (0)
#endif
#define LOG_TRACE(...) LOG(LogLevel_Trace, __VA_ARGS__)
#define LOG_DEBUG(...) LOG(LogLevel_Debug, __VA_ARGS__)
#define LOG_WARN(...) LOG(LogLevel_Warn, __VA_ARGS__)
Expand Down
2 changes: 2 additions & 0 deletions src/lisiblestd/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void *arena_allocator_allocate_aligned(usize alignment, usize size, void *ctx) {
(void)alignment;
(void)size;
LSTD_UNIMPLEMENTED();
return NULL;
}
void *arena_allocator_allocate_array(usize count, usize item_size, void *ctx) {
LSTD_ASSERT(ctx != NULL);
Expand All @@ -80,6 +81,7 @@ void *arena_allocator_reallocate(void *ptr, usize old_size, usize new_size,
(void)new_size;
(void)ctx;
LSTD_UNIMPLEMENTED();
return NULL;
}

void arena_allocator_free(void *ptr, void *ctx) {
Expand Down
2 changes: 1 addition & 1 deletion src/lisiblestd/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ String String_new(Allocator *allocator, const char *str) {
char *value = Allocator_allocate(allocator, length + 1);
LSTD_ASSERT(value != NULL);

strncpy(value, str, length);
strncpy(value, str, length + 1);
value[length] = '\0';

return (String){.value = value, .length = length};
Expand Down

0 comments on commit 6c8d0db

Please sign in to comment.