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

Nintendo Switch #181

Merged
merged 8 commits into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ jobs:
- run: cd build && cmake -DNIGHTLY_BUILD=ON -DCMAKE_TOOLCHAIN_FILE=../CMake/mingwcc.cmake ..
- run: cd build && cmake --build . -j $(nproc)
- store_artifacts: {path: ./build/devilutionx.exe, destination: devilutionx_x86.exe}
switch:
docker:
- image: devkitpro/devkita64:latest
AJenbo marked this conversation as resolved.
Show resolved Hide resolved
working_directory: ~/repo
steps:
- checkout
- run: echo deb http://deb.debian.org/debian stretch-backports main > /etc/apt/sources.list.d/debian-backports.list
- run: apt-get update && apt-get install -y -t stretch-backports cmake
- run: dkp-pacman -Syu --noconfirm
# Install cmake files (https://github.com/devkitPro/docker/issues/3)
- run: dkp-pacman -S --needed --noconfirm --quiet devkitpro-pkgbuild-helpers
- run: cd build && cmake .. -DBINARY_RELEASE=ON -DNONET=ON -DPREFILL_PLAYER_NAME=ON -DCMAKE_TOOLCHAIN_FILE=../CMake/switch/devkita64-libnx.cmake
- run: cd build && cmake --build . -j $(nproc)
- store_artifacts: {path: ./build/devilutionx.nro, destination: devilutionx.nro}

workflows:
version: 2
Expand All @@ -67,3 +81,4 @@ workflows:
- linux_x86
- windows_x86
- linux_x86_64_sdl1
- switch
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,6 @@ DerivedData/

# Don't accidently commit the diabdat.mpq
*.mpq

### Nintendo Switch ###
exefs/main
25 changes: 16 additions & 9 deletions 3rdParty/StormLib/src/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static bool BaseFile_Create(TFileStream * pStream)
}
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
{
intptr_t handle;

Expand Down Expand Up @@ -141,7 +141,7 @@ static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD
}
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
{
struct stat64 fileinfo;
int oflag = (dwStreamFlags & STREAM_FLAG_READ_ONLY) ? O_RDONLY : O_RDWR;
Expand Down Expand Up @@ -212,7 +212,7 @@ static bool BaseFile_Read(
}
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
{
ssize_t bytes_read;

Expand Down Expand Up @@ -283,7 +283,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const
}
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
{
ssize_t bytes_written;

Expand Down Expand Up @@ -350,7 +350,7 @@ static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize)
}
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
{
if(ftruncate64((intptr_t)pStream->Base.File.hFile, (off64_t)NewFileSize) == -1)
{
Expand Down Expand Up @@ -394,7 +394,7 @@ static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream)
return (bool)MoveFile(pNewStream->szFileName, pStream->szFileName);
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
// "rename" on Linux also works if the target file exists
if(rename(pNewStream->szFileName, pStream->szFileName) == -1)
{
Expand All @@ -414,7 +414,7 @@ static void BaseFile_Close(TFileStream * pStream)
CloseHandle(pStream->Base.File.hFile);
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
close((intptr_t)pStream->Base.File.hFile);
#endif
}
Expand Down Expand Up @@ -493,7 +493,7 @@ static bool BaseMap_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD
return false;
#endif

#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
struct stat64 fileinfo;
intptr_t handle;
bool bResult = false;
Expand All @@ -506,7 +506,11 @@ static bool BaseMap_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD
if(fstat64(handle, &fileinfo) != -1)
{
#if !defined(PLATFORM_AMIGA)
#if defined(PLATFORM_SWITCH)
pStream->Base.Map.pbFile = (LPBYTE)malloc((size_t)fileinfo.st_size);
#else
pStream->Base.Map.pbFile = (LPBYTE)mmap(NULL, (size_t)fileinfo.st_size, PROT_READ, MAP_PRIVATE, handle, 0);
#endif
if(pStream->Base.Map.pbFile != NULL)
{
// time_t is number of seconds since 1.1.1970, UTC.
Expand Down Expand Up @@ -564,10 +568,13 @@ static void BaseMap_Close(TFileStream * pStream)
UnmapViewOfFile(pStream->Base.Map.pbFile);
#endif

#if (defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)) && !defined(PLATFORM_AMIGA)
#if (defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)) && !defined(PLATFORM_AMIGA) && !defined(PLATFORM_SWITCH)
//Todo(Amiga): Fix a proper solution for this
if(pStream->Base.Map.pbFile != NULL)
munmap(pStream->Base.Map.pbFile, (size_t )pStream->Base.Map.FileSize);
#elif defined(PLATFORM_SWITCH)
if(pStream->Base.Map.pbFile != NULL)
free(pStream->Base.Map.pbFile);
#endif

pStream->Base.Map.pbFile = NULL;
Expand Down
27 changes: 25 additions & 2 deletions 3rdParty/StormLib/src/StormPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@

#endif

#if !defined(PLATFORM_DEFINED) && defined(__SWITCH__)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>

#ifndef __BIG_ENDIAN__
#define PLATFORM_LITTLE_ENDIAN
#endif

#define PLATFORM_SWITCH
#define PLATFORM_DEFINED

#endif
//-----------------------------------------------------------------------------
// Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*

Expand Down Expand Up @@ -254,7 +277,7 @@
#endif // !PLATFORM_WINDOWS

// 64-bit calls are supplied by "normal" calls on Mac
#if defined(PLATFORM_MAC) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
#define stat64 stat
#define fstat64 fstat
#define lseek64 lseek
Expand All @@ -264,7 +287,7 @@
#endif

// Platform-specific error codes for UNIX-based platforms
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA)
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
#define ERROR_SUCCESS 0
#define ERROR_FILE_NOT_FOUND ENOENT
#define ERROR_ACCESS_DENIED EPERM
Expand Down
44 changes: 44 additions & 0 deletions CMake/switch/FindLIBNX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# https://github.com/switchpy/libnx-template/blob/7037982c77e1767410143103d5963d0ddc77fb64/cmake/FindLIBNX.cmake

# Tries to find libnx
# Once done, this will define:
# > LIBNX_FOUND - The system has libnx
# > LIBNX_INCLUDE_DIRS - The libnx include directories
# > LIBNX_LIBRARIES - The libnx libraries required for using it
#
# It also adds an imported target named `switch::libnx`.

include(utils) # <- devilutionX patch

if (NOT SWITCH)
cmake_panic("This helper can only be used if you are using the Switch toolchain file.")
endif ()

set(LIBNX_PATHS $ENV{LIBNX} libnx ${LIBNX} ${DEVKITPRO}/libnx)

find_path(LIBNX_INCLUDE_DIR switch.h
PATHS ${LIBNX_PATHS}
PATH_SUFFIXES include)

find_library(LIBNX_LIBRARY NAMES libnx.a
PATHS ${LIBNX_PATHS}
PATH_SUFFIXES lib)

set(LIBNX_INCLUDE_DIRS ${LIBNX_INCLUDE_DIR})
set(LIBNX_LIBRARIES ${LIBNX_LIBRARY})

# Handle the QUIETLY and REQUIRED arguments and set LIBNX_FOUND to TRUE if all above variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBNX DEFAULT_MSG
LIBNX_INCLUDE_DIR LIBNX_LIBRARY)

mark_as_advanced(LIBNX_INCLUDE_DIR LIBNX_LIBRARY)
if (LIBNX_FOUND)
set(LIBNX ${LIBNX_INCLUDE_DIR}/..)
cmake_info("Setting LIBNX to ${LIBNX}")

add_library(switch::libnx STATIC IMPORTED GLOBAL)
set_target_properties(switch::libnx PROPERTIES
IMPORTED_LOCATION ${LIBNX_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${LIBNX_INCLUDE_DIR})
endif ()
46 changes: 46 additions & 0 deletions CMake/switch/devkita64-libnx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
if(NOT DEFINED ENV{DEVKITPRO})
message(FATAL_ERROR "Please set the DEVKITPRO env var to <path to devkitpro>")
endif()

# devkitPro paths are broken on Windows. We need to use this macro to fix those.
# from https://github.com/switchpy/libnx-template/blob/7037982c77e1767410143103d5963d0ddc77fb64/devkita64-libnx.cmake
macro(msys_to_cmake_path msys_path resulting_path)
if (WIN32)
string(REGEX REPLACE "^/([a-zA-Z])/" "\\1:/" ${resulting_path} ${msys_path})
else ()
set(${resulting_path} ${msys_path})
endif ()
endmacro()
msys_to_cmake_path($ENV{DEVKITPRO} DEVKITPRO)

# Default devkitpro cmake
include(${DEVKITPRO}/switch.cmake)

# Set root paths:
set(DEVKITA64 ${DEVKITPRO}/devkitA64)
set(LIBNX ${DEVKITPRO}/libnx)
set(PORTLIBS_PATH ${DEVKITPRO}/portlibs)
set(PORTLIBS ${PORTLIBS_PATH}/switch)
set(CMAKE_FIND_ROOT_PATH ${DEVKITA64} ${LIBNX} ${PORTLIBS})

# Set absolute tool paths:
set(TOOLCHAIN_PREFIX ${DEVKITA64}/bin/aarch64-none-elf-)
if(WIN32)
set(TOOLCHAIN_SUFFIX ".exe")
else()
set(TOOLCHAIN_SUFFIX "")
endif()
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc${TOOLCHAIN_SUFFIX})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++${TOOLCHAIN_SUFFIX})
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}as${TOOLCHAIN_SUFFIX})
set(PKG_CONFIG_EXECUTABLE ${TOOLCHAIN_PREFIX}pkg-config${TOOLCHAIN_SUFFIX})
set(CMAKE_AR ${TOOLCHAIN_PREFIX}gcc-ar${TOOLCHAIN_SUFFIX} CACHE STRING "")
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}gcc-ranlib${TOOLCHAIN_SUFFIX} CACHE STRING "")
set(CMAKE_LD "/${TOOLCHAIN_PREFIX}ld${TOOLCHAIN_SUFFIX}" CACHE INTERNAL "")
set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}objcopy${TOOLCHAIN_SUFFIX}" CACHE INTERNAL "")
set(CMAKE_SIZE_UTIL "${TOOLCHAIN_PREFIX}size${TOOLCHAIN_SUFFIX}" CACHE INTERNAL "")

set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available")

set(SWITCH ON)
add_definitions(-D__SWITCH__ -DSWITCH)
Loading