Skip to content

Commit

Permalink
[libretro] Fix crash in Android
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 16, 2024
1 parent c7b3eb7 commit 9295304
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
5 changes: 5 additions & 0 deletions platforms/libretro/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ else
CXXFLAGS += -O3
endif

GIT_VERSION ?= " $(shell git describe --abbrev=7 --dirty --always --tags || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
CXXFLAGS += -DEMULATOR_BUILD=\"$(GIT_VERSION)\"
endif

include Makefile.common

OBJECTS := $(SOURCES_C:.c=.o) $(SOURCES_CXX:.cpp=.o)
Expand Down
18 changes: 10 additions & 8 deletions platforms/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ static retro_environment_t environ_cb;

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

const char *dir = NULL;

if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) {
Expand All @@ -120,6 +125,8 @@ void retro_init(void)
snprintf(retro_system_directory, sizeof(retro_system_directory), "%s", ".");
}

log_cb(RETRO_LOG_INFO, "%s (%s) libretro\n", GEARCOLECO_TITLE, EMULATOR_BUILD);

core = new GearcolecoCore();

#ifdef PS2
Expand Down Expand Up @@ -151,7 +158,7 @@ unsigned retro_api_version(void)

void retro_set_controller_port_device(unsigned port, unsigned device)
{
log_cb(RETRO_LOG_INFO, "Plugging device %u into port %u.\n", device, port);
log_cb(RETRO_LOG_DEBUG, "Plugging device %u into port %u.\n", device, port);

struct retro_input_descriptor joypad[] = {

Expand Down Expand Up @@ -246,11 +253,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[] = {
{ "ColecoVision", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) },
};
Expand All @@ -265,7 +267,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 Expand Up @@ -620,7 +622,7 @@ bool retro_load_game(const struct retro_game_info *info)
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
{
log_cb(RETRO_LOG_INFO, "RGB565 is not supported.\n");
log_cb(RETRO_LOG_ERROR, "RGB565 is not supported.\n");
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Video::~Video()

void Video::Init()
{
m_pInfoBuffer = new u8[GC_RESOLUTION_WIDTH * GC_LINES_PER_FRAME_PAL];
m_pInfoBuffer = new u8[GC_RESOLUTION_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_HEIGHT_WITH_OVERSCAN];
m_pFrameBuffer = new u16[GC_RESOLUTION_WIDTH * GC_LINES_PER_FRAME_PAL];
m_pVdpVRAM = new u8[0x4000];
InitPalettes();
Expand All @@ -75,11 +75,11 @@ void Video::Reset(bool bPAL)
m_VdpBuffer = 0;
m_VdpAddress = 0;
m_VdpStatus = 0;
for (int i = 0; i < (GC_RESOLUTION_WIDTH * GC_LINES_PER_FRAME_PAL); i++)
{

for (int i = 0; i < (GC_RESOLUTION_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_HEIGHT_WITH_OVERSCAN); i++)
m_pFrameBuffer[i] = 1;
for (int i = 0; i < (GC_RESOLUTION_WIDTH * GC_LINES_PER_FRAME_PAL); i++)
m_pInfoBuffer[i] = 0;
}
for (int i = 0; i < 0x4000; i++)
m_pVdpVRAM[i] = 0;
for (int i = 0; i < 8; i++)
Expand Down
15 changes: 9 additions & 6 deletions src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,14 @@ struct GC_RuntimeInfo
};

#ifdef DEBUG_GEARCOLECO

#ifdef __ANDROID__
#include <android/log.h>
#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "GEARCOLECO", __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, "GEARCOLECO", __VA_ARGS__);
#endif

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

inline void Log_func(const char* const msg, ...)
{
static int count = 1;
Expand All @@ -202,6 +201,10 @@ inline void Log_func(const char* const msg, ...)
count++;
}

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

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

0 comments on commit 9295304

Please sign in to comment.