Skip to content

Commit

Permalink
[libretro] Add log traces to Android build
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 16, 2024
1 parent 9279609 commit ef6aa23
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
16 changes: 10 additions & 6 deletions platforms/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static struct retro_log_callback logging;
static retro_log_printf_t log_cb;
static char retro_system_directory[4096];
static char retro_game_path[4096];
retro_log_printf_t gearsystem_log_cb = NULL;

static s16 audio_buf[GS_AUDIO_BUFFER_SIZE];
static int audio_sample_count = 0;
Expand Down Expand Up @@ -83,6 +84,14 @@ static retro_environment_t environ_cb;

void retro_init(void)
{
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
{
log_cb = logging.log;
gearsystem_log_cb = logging.log;
}
else
log_cb = fallback_log;

const char *dir = NULL;

if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) {
Expand Down Expand Up @@ -195,11 +204,6 @@ void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;

if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
log_cb = logging.log;
else
log_cb = fallback_log;

static const struct retro_controller_description port_1[] = {
{ "Sega Master System / Game Gear", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) },
};
Expand All @@ -214,7 +218,7 @@ void retro_set_environment(retro_environment_t cb)
{ NULL, 0 },
};

cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);

environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *)vars);
}
Expand Down
26 changes: 20 additions & 6 deletions src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,18 @@ struct GS_RuntimeInfo
};

#ifdef DEBUG_GEARSYSTEM

#ifdef __ANDROID__
#include <android/log.h>
#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "GEARSYSTEM", __VA_ARGS__);
#endif
#define Log(msg, ...) (Log_func(msg, ##__VA_ARGS__))
#else
#define Log(msg, ...)
#include <android/log.h>
#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "GEARSYSTEM", __VA_ARGS__);
#endif
#ifdef __LIBRETRO__
#include "../platforms/libretro/libretro.h"
extern retro_log_printf_t gearsystem_log_cb;
#endif

#define Log(msg, ...) (Log_func(msg, ##__VA_ARGS__))

inline void Log_func(const char* const msg, ...)
{
static int count = 1;
Expand All @@ -193,12 +196,23 @@ inline void Log_func(const char* const msg, ...)
vsnprintf(szBuf, 512, msg, args);
va_end(args);

#ifdef __LIBRETRO__
if (gearsystem_log_cb != NULL)
{
gearsystem_log_cb(RETRO_LOG_INFO, "%s\n", szBuf);
return;
}
#endif
printf("%d: %s\n", count, szBuf);
fflush(stdout);

count++;
}

#else // DEBUG_GEARSYSTEM
#define Log(msg, ...)
#endif

inline u8 SetBit(const u8 value, const u8 bit)
{
return value | (0x01 << bit);
Expand Down

0 comments on commit ef6aa23

Please sign in to comment.