Skip to content

Commit

Permalink
Merge pull request #39 from iyzsong/master
Browse files Browse the repository at this point in the history
libretro: Support build for android
  • Loading branch information
YuriSizuku authored Nov 30, 2024
2 parents 7972706 + 7a14a06 commit 7d20ba9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/onsyuri/BaseReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define __BASE_READER_H__

#include <stdio.h>
#if defined(ANDROID)
#if defined(ANDROID) && !defined(__LIBRETRO__)
extern "C" int stat_ons(const char *path, struct stat *statbuf);
extern "C" FILE *fopen_ons(const char *str, const char *mode);
#define fopen fopen_ons
Expand Down
4 changes: 4 additions & 0 deletions src/onsyuri/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#ifndef __UTILS_H__
#define __UTILS_H__

#if defined(__LIBRETRO__)
#undef ANDROID
#endif

#ifdef ANDROID
#include <android/log.h>
#elif defined(WINRT)
Expand Down
4 changes: 3 additions & 1 deletion src/onsyuri_libretro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set(SOURCES
# configure SDL2 for libretro
file(COPY deps/SDL_config.h DESTINATION ${CMAKE_SOURCE_DIR}/deps/SDL/include)
file(COPY deps/SDL_dynapi.h DESTINATION ${CMAKE_SOURCE_DIR}/deps/SDL/src/dynapi)
file(COPY deps/close_code.h DESTINATION ${CMAKE_SOURCE_DIR}/deps/SDL/include)

# prepare <SDL2/*.h> headers directory for onsyuri
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/deps/SDL/include
Expand Down Expand Up @@ -302,7 +303,8 @@ target_include_directories(onsyuri_libretro PRIVATE
../onsyuri
)
target_compile_definitions(onsyuri_libretro PRIVATE
-DUSE_BUILTIN_LAYER_EFFECTS -DENABLE_1BYTE_CHAR
__LIBRETRO__
USE_BUILTIN_LAYER_EFFECTS ENABLE_1BYTE_CHAR
)
if (HAVE_NEON)
target_compile_definitions(onsyuri_libretro PRIVATE USE_SIMD USE_SIMD_ARM_NEON)
Expand Down
13 changes: 11 additions & 2 deletions src/onsyuri_libretro/SDL_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ VideoInit(SDL_VideoDevice* device)
SDL_DisplayMode mode;
SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 1920;
mode.h = 1080;
/* We set screen size in CreateWindowFramebuffer later */
mode.w = 1;
mode.h = 1;
mode.refresh_rate = 60;
mode.driverdata = NULL;
SDL_AddBasicVideoDisplay(&mode);
Expand Down Expand Up @@ -85,6 +86,14 @@ CreateWindowFramebuffer(SDL_VideoDevice* device,
*pixels = _surface_fb->pixels;
*pitch = _surface_fb->pitch;

/* Set screen size to the same as window */
SDL_DisplayMode mode;
SDL_VideoDisplay* display = SDL_GetDisplayForWindow(window);
SDL_GetCurrentDisplayMode(SDL_GetIndexOfDisplay(display), &mode);
mode.w = w;
mode.h = h;
SDL_SetCurrentDisplayMode(display, &mode);

return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions src/onsyuri_libretro/deps/SDL_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#define HAVE_ALLOCA_H 1
#define HAVE_CTYPE_H 1
#define HAVE_FLOAT_H 1
#define HAVE_ICONV_H 1
/* #define HAVE_ICONV_H 1 */
#define HAVE_INTTYPES_H 1
#define HAVE_LIMITS_H 1
#define HAVE_MALLOC_H 1
Expand Down Expand Up @@ -187,9 +187,9 @@
#define HAVE_TANF 1
#define HAVE_TRUNC 1
#define HAVE_TRUNCF 1
#define HAVE_FOPEN64 1
/* #define HAVE_FOPEN64 1 */
#define HAVE_FSEEKO 1
#define HAVE_FSEEKO64 1
/* #define HAVE_FSEEKO64 1 */
#define HAVE_MEMFD_CREATE 1
#define HAVE_POSIX_FALLOCATE 1
#define HAVE_SIGACTION 1
Expand All @@ -201,7 +201,7 @@
#define HAVE_CLOCK_GETTIME 1
/* #undef HAVE_GETPAGESIZE */
#define HAVE_MPROTECT 1
#define HAVE_ICONV 1
/* #define HAVE_ICONV 1 */
/* #undef SDL_USE_LIBICONV */
#define HAVE_PTHREAD_SETNAME_NP 1
/* #undef HAVE_PTHREAD_SET_NAME_NP */
Expand Down
44 changes: 44 additions & 0 deletions src/onsyuri_libretro/deps/close_code.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/**
* \file close_code.h
*
* This file reverses the effects of begin_code.h and should be included
* after you finish any function and structure declarations in your headers
*/

#ifndef SDL_begin_code_h
#error close_code.h included without matching begin_code.h
#endif
#undef SDL_begin_code_h

/* Reset structure packing at previous byte alignment */
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
#ifdef __BORLANDC__
#pragma nopackwarning
#endif
#pragma pack(pop)
#endif /* Compiler needs structure packing set */

/* libretro: Treat Android as Linux */
#undef ANDROID
#undef __ANDROID__
9 changes: 8 additions & 1 deletion src/onsyuri_libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#include <stdio.h>
#include <unistd.h>
#include <string>

#ifdef __ANDROID__
#define DEFAULT_MOUSE_MODE "Touch"
#else
#define DEFAULT_MOUSE_MODE "Classical"
#endif

#include "ONScripter.h"
#include "SDL_libretro.h"
#include "gbk2utf16.h"
Expand Down Expand Up @@ -59,7 +66,7 @@ retro_set_environment(retro_environment_t cb)
.desc = "Mouse Mode",
.info = NULL,
.values = { { "Touch" }, { "Classical" }, { NULL } },
.default_value = "Classical",
.default_value = DEFAULT_MOUSE_MODE,
},
{
.key = "onsyuri_mouse_sensitivity",
Expand Down

0 comments on commit 7d20ba9

Please sign in to comment.