Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayStation Vita support #1440

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/vita.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: PlayStation Vita CI

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ubuntu-latest
container: vitasdk/vitasdk:latest

strategy:
matrix:
config:
- {name: standalone, destDir: vita}

steps:
- name: Set up build environment
run: |
apk add --no-cache aws-cli ccache git ninja
vdpm curl libzip openssl SceShaccCgExt vitaShaRK taihen zlib
git clone -b exceptions_mprotect --depth 1 https://github.com/bythos14/kubridge.git
cmake -S kubridge -B kubridge_build -G Ninja -DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build kubridge_build --config Release --target kubridge_all
cmake --install kubridge_build
git clone --depth 1 https://github.com/Rinnegatamante/vitaGL.git
make -C vitaGL HAVE_WRAPPED_ALLOCATORS=1 HAVE_SHADER_CACHE=1 NO_DEBUG=1 -j4 install
git clone -b vitagl --depth 1 https://github.com/Northfear/SDL.git
cmake -S SDL -B SDL_build -G Ninja -DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DVIDEO_VITA_VGL=ON
cmake --build SDL_build --config Release
cmake --install SDL_build

- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Mark git repository as safe
run: git config --global --add safe.directory $PWD

- uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-vita-${{ matrix.config.name }}-${{ github.sha }}
restore-keys: ccache-vita-${{ matrix.config.name }}-

- name: CMake
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake -G Ninja ${{ matrix.config.cmakeArgs }}
cmake --build build --config Release --target Flycast.vpk-vpk

- uses: actions/upload-artifact@v4
with:
name: flycast-vita-${{ matrix.config.name }}
path: build/flycast

- uses: actions/upload-artifact@v4
with:
name: flycast-vita-${{ matrix.config.name }}.vpk
path: build/Flycast.vpk

- name: Configure AWS Credentials
id: aws-credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: AKIAJOZQS4H2PHQWYFCA
aws-secret-access-key: ${{ secrets.S3_SECRET_KEY }}
aws-region: us-east-2
if: github.repository == 'flyinghead/flycast' && github.event_name == 'push' && matrix.config.destDir != ''

- name: Upload to S3
run: aws s3 sync artifact/bin s3://flycast-builds/${{ matrix.config.destDir }}/${GITHUB_REF#refs/}-$GITHUB_SHA --acl public-read --follow-symlinks
if: ${{ steps.aws-credentials.outputs.aws-account-id != '' }}
107 changes: 100 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ if(APPLE)
endif()
endif()

if (VITA)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{VITASDK})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
else()
message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
endif()
endif()
endif()

if(LIBRETRO)
project(flycast_libretro)
else()
Expand All @@ -31,7 +41,7 @@ endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NINTENDO_SWITCH)
if(NINTENDO_SWITCH OR VITA)
set(CMAKE_CXX_EXTENSIONS ON)
else()
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down Expand Up @@ -118,7 +128,32 @@ endif()
string(TIMESTAMP BUILD_TIMESTAMP UTC)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/core/version.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/core/version.h" @ONLY)

if(NINTENDO_SWITCH)
if(VITA)
include("${VITASDK}/share/vita.cmake" REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${VITASDK}/arm-vita-eabi/include/SDL2 -Wl,-q,--wrap,memcpy,--wrap,memset,--wrap,malloc,--wrap,memalign,--wrap,free,--wrap,calloc,--wrap,realloc -O3 -DNDEBUG -fno-optimize-sibling-calls -fsigned-char -fno-short-enums -marm")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${VITASDK}/arm-vita-eabi/include/SDL2 -Wl,-q,--wrap,malloc,--wrap,memalign,--wrap,free,--wrap,calloc,--wrap,realloc -O3 -DNDEBUG -fno-optimize-sibling-calls -fsigned-char -fno-short-enums -marm")

set(VITA_APP_NAME "Flycast")
set(VITA_TITLEID "FLYCASTDC")
set(VITA_VPKNAME "Flycast")
set(VITA_VERSION "01.00")
set(VITA_MKSFOEX_FLAGS "-d ATTRIBUTE2=12")

set(USE_VULKAN OFF)
set(USE_GLES2 ON)
enable_language(ASM)

if(LIBRETRO)
add_library(${PROJECT_NAME} STATIC core/emulator.cpp)
target_compile_definitions(${PROJECT_NAME} PRIVATE LIBRETRO VITA)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "flycast_libretro_vita")
else()
add_executable(${PROJECT_NAME} core/emulator.cpp)
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE GLES)
elseif(NINTENDO_SWITCH)
set(USE_VULKAN OFF)
enable_language(ASM)

Expand Down Expand Up @@ -209,7 +244,9 @@ if(WINDOWS_STORE)
set(USE_VULKAN OFF)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
if(NOT VITA)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
endif()
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /GR /GS-)
if(WINDOWS_STORE)
Expand Down Expand Up @@ -418,6 +455,9 @@ if(NOT LIBRETRO)
if(USE_HOST_SDL)
find_package(SDL2 2.0.9)
endif()
if(VITA)
set(SDL2_FOUND 1)
endif()
if(NOT SDL2_FOUND)
set(SDL_TEST_ENABLED_BY_DEFAULT OFF)
add_subdirectory(core/deps/SDL EXCLUDE_FROM_ALL)
Expand All @@ -430,7 +470,7 @@ if(NOT LIBRETRO)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2main)
endif()

if((APPLE OR WIN32) AND TARGET SDL2::SDL2-static)
if((APPLE OR WIN32 OR VITA) AND TARGET SDL2::SDL2-static)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2-static)
elseif(TARGET SDL2::SDL2)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2)
Expand Down Expand Up @@ -473,7 +513,7 @@ if(NOT WITH_SYSTEM_ZLIB)
# help libzip find the package
set(ZLIB_FOUND TRUE)
set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${ZLIB_RELATIVE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/${ZLIB_RELATIVE_PATH}")

cmake_policy(SET CMP0026 OLD)
get_target_property(ZLIB_LIBRARY_RELEASE zlibstatic LOCATION)
get_target_property(ZLIB_LIBRARY_DEBUG zlibstatic LOCATION_Debug)
Expand Down Expand Up @@ -526,6 +566,10 @@ if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND NOT LIBRETRO)
endif()
endif()

if(VITA)
target_link_libraries(${PROJECT_NAME} PRIVATE vitaGL vitashark SceShaccCg_stub SceShaccCgExt taihen_stub mathneon curl ssl crypto)
endif()

if(UNIX AND NOT APPLE AND NOT ANDROID)
add_definitions(
-DFLYCAST_DATADIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/"
Expand Down Expand Up @@ -601,7 +645,7 @@ add_subdirectory(core/deps/nowide EXCLUDE_FROM_ALL)
target_link_libraries(${PROJECT_NAME} PRIVATE nowide::nowide)

if(NOT MINIUPNP_FOUND)
if(NINTENDO_SWITCH)
if(NINTENDO_SWITCH OR VITA)
target_compile_definitions(${PROJECT_NAME} PRIVATE FEAT_NO_MINIUPNPC)
else()
option(UPNPC_BUILD_SHARED "Build shared library" OFF)
Expand Down Expand Up @@ -637,6 +681,32 @@ if(NOT LIBZIP_FOUND OR NINTENDO_SWITCH)
target_link_libraries(${PROJECT_NAME} PRIVATE libzip::zip)
endif()

if(VITA)
target_link_libraries(${PROJECT_NAME} PRIVATE
-Wl,--whole-archive pthread -Wl,--no-whole-archive
stdc++
SDL2
kubridge_stub
ScePgf_stub
SceHid_stub
SceAppMgr_stub
SceAppUtil_stub
SceAudio_stub
SceAudioIn_stub
SceDisplay_stub
SceKernelDmacMgr_stub
SceIme_stub
ScePower_stub
SceSysmodule_stub
SceTouch_stub
SceMotion_stub
SceCommonDialog_stub
SceCtrl_stub
SceGxm_stub
SceVshBridge_stub
)
endif()

if(WIN32)
target_include_directories(${PROJECT_NAME} PRIVATE core/deps/dirent)
endif()
Expand Down Expand Up @@ -1055,6 +1125,12 @@ if(WIN32)
core/windows/fault_handler.cpp
core/windows/unwind_info.cpp
core/windows/win_vmem.cpp)
elseif(VITA)
target_sources(${PROJECT_NAME} PRIVATE
core/linux/common.cpp
core/linux/unwind_info.cpp
core/linux/vita_fault_handler.cpp
core/linux/vita_vmem.cpp)
else()
target_sources(${PROJECT_NAME} PRIVATE
core/linux/common.cpp
Expand Down Expand Up @@ -1772,7 +1848,7 @@ if(NOT LIBRETRO)
${CMAKE_CURRENT_BINARY_DIR}/Flycast.app/Contents/Frameworks/libvulkan.dylib)
endif()
endif()
elseif(UNIX)
elseif(UNIX OR VITA)
if(NOT BUILD_TESTING)
target_sources(${PROJECT_NAME} PRIVATE
core/linux-dist/main.cpp)
Expand Down Expand Up @@ -1856,6 +1932,23 @@ if(NINTENDO_SWITCH)
endif()
endif()

if(VITA)
if(LIBRETRO)
# TODO?
else()
vita_create_self(eboot.bin ${PROJECT_NAME} UNSAFE STRIPPED NOASLR)
vita_create_vpk(${VITA_VPKNAME}.vpk ${VITA_TITLEID} eboot.bin
VERSION ${VITA_VERSION}
NAME ${VITA_APP_NAME}
FILE ${CMAKE_SOURCE_DIR}/shell/vita/icon0.png sce_sys/icon0.png
${CMAKE_SOURCE_DIR}/shell/vita/startup.png sce_sys/livearea/contents/startup.png
${CMAKE_SOURCE_DIR}/shell/vita/bg.png sce_sys/livearea/contents/bg.png
${CMAKE_SOURCE_DIR}/shell/vita/template.xml sce_sys/livearea/contents/template.xml
${VPK_INCLUDES}
)
endif()
endif()

if(IOS)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>-${CMAKE_OSX_SYSROOT}/Flycast.ipa" TYPE BIN)
elseif(NINTENDO_SWITCH AND NOT LIBRETRO)
Expand Down
2 changes: 1 addition & 1 deletion core/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
#endif

#if !defined(__ANDROID__) && !defined(TARGET_IPHONE) && !defined(TARGET_UWP) \
&& !defined(__SWITCH__) && !defined(LIBRETRO) && !defined(__NetBSD__) && !defined(__OpenBSD__)
&& !defined(__SWITCH__) && !defined(LIBRETRO) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__vita__)
#define NAOMI_MULTIBOARD
#endif

Expand Down
12 changes: 12 additions & 0 deletions core/cfg/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace config {

Option<bool> DynarecEnabled("Dynarec.Enabled", true);
Option<int> Sh4Clock("Sh4Clock", 200);
#ifdef __vita__
Option<int> DynarecSmcChecks("Dynarec.smcChecks", 0);
#endif

// General

Expand All @@ -37,8 +40,13 @@ Option<bool> AutoLoadState("Dreamcast.AutoLoadState");
Option<bool> AutoSaveState("Dreamcast.AutoSaveState");
Option<int, false> SavestateSlot("Dreamcast.SavestateSlot");
Option<bool> ForceFreePlay("ForceFreePlay", true);
#ifdef __vita__
Option<bool, false> FetchBoxart("FetchBoxart", false);
Option<bool, false> BoxartDisplayMode("BoxartDisplayMode", false);
#else
Option<bool, false> FetchBoxart("FetchBoxart", true);
Option<bool, false> BoxartDisplayMode("BoxartDisplayMode", true);
#endif
Option<int, false> UIScaling("UIScaling", 100);

// Sound
Expand Down Expand Up @@ -81,6 +89,10 @@ Option<bool> Fog("rend.Fog", true);
Option<bool> FloatVMUs("rend.FloatVMUs");
Option<bool> Rotate90("rend.Rotate90");
Option<bool> PerStripSorting("rend.PerStripSorting");
#ifdef __vita__
Option<bool> UseSimpleShaders("rend.UseSimpleShaders", true);
Option<bool> FastSorting("rend.FastSorting", true);
#endif
#ifdef __APPLE__
Option<bool> DelayFrameSwapping("rend.DelayFrameSwapping", false);
#else
Expand Down
5 changes: 5 additions & 0 deletions core/cfg/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ extern Option<bool> DynarecEnabled;
#ifndef LIBRETRO
extern Option<int> Sh4Clock;
#endif
#ifdef __vita__
extern Option<int> DynarecSmcChecks;
extern Option<bool> FastSorting;
extern Option<bool> UseSimpleShaders;
#endif

// General

Expand Down
2 changes: 1 addition & 1 deletion core/deps/ggpo/lib/ggpo/ggpo_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GGPOException : public std::runtime_error {
*/
#if defined(_WIN32)
# include "platform_windows.h"
#elif defined(__unix__) || defined(__APPLE__) || defined(__SWITCH__)
#elif defined(__unix__) || defined(__APPLE__) || defined(__SWITCH__) || defined(__vita__)
# include "platform_linux.h"
#else
# error Unsupported platform
Expand Down
2 changes: 1 addition & 1 deletion core/deps/ggpo/lib/ggpo/platform_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Use of this software is governed by the MIT license that can be found
* in the LICENSE file.
*/
#if defined(__unix__) || defined(__APPLE__) || defined(__SWITCH__)
#if defined(__unix__) || defined(__APPLE__) || defined(__SWITCH__) || defined(__vita__)

#include "platform_linux.h"
#include <time.h>
Expand Down
2 changes: 1 addition & 1 deletion core/deps/ggpo/lib/ggpo/platform_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <netinet/in.h>
#ifdef __SWITCH__
#include "nswitch.h"
#else
#elif !defined(__vita__)
#include <netinet/ip.h>
#endif
#include <netinet/tcp.h>
Expand Down