git: dd40da67a627 - main - emulators/flycast: New Port: Multi-platform Sega Dreamcast emulator

From: Robert Clausecker <fuz_at_FreeBSD.org>
Date: Thu, 14 Nov 2024 08:44:24 UTC
The branch main has been updated by fuz:

URL: https://cgit.FreeBSD.org/ports/commit/?id=dd40da67a627a917f2cfaacced2e1403685a6d16

commit dd40da67a627a917f2cfaacced2e1403685a6d16
Author:     Stefan Schlosser <bsdcode@disroot.org>
AuthorDate: 2024-10-24 13:07:37 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2024-11-14 08:43:27 +0000

    emulators/flycast: New Port: Multi-platform Sega Dreamcast emulator
    
    Flycast is a multi-platform Sega Dreamcast, Naomi, Naomi 2, and Atomiswave
    emulator derived from reicast.
    
    WWW: https://github.com/flyinghead/flycast
    
    PR:             282691
---
 emulators/Makefile                                 |  1 +
 emulators/flycast/Makefile                         | 66 ++++++++++++++++++++++
 emulators/flycast/Makefile.tuples                  |  4 ++
 emulators/flycast/distinfo                         |  9 +++
 emulators/flycast/files/gen_gh_tuple.sh            | 29 ++++++++++
 emulators/flycast/files/patch-CMakeLists.txt       | 57 +++++++++++++++++++
 .../files/patch-core_rend_vulkan_vmallocator.cpp   |  9 +++
 .../files/patch-core_rend_vulkan_vmallocator.h     | 38 +++++++++++++
 .../patch-core_rend_vulkan_vulkan__context.cpp     | 19 +++++++
 emulators/flycast/pkg-descr                        | 14 +++++
 emulators/flycast/pkg-plist                        | 17 ++++++
 11 files changed, 263 insertions(+)

diff --git a/emulators/Makefile b/emulators/Makefile
index d418a2b88eb3..a8cbfe618353 100644
--- a/emulators/Makefile
+++ b/emulators/Makefile
@@ -35,6 +35,7 @@
     SUBDIR += es-de
     SUBDIR += fceux
     SUBDIR += flexemu
+    SUBDIR += flycast
     SUBDIR += fmsx
     SUBDIR += frodo
     SUBDIR += fs-uae
diff --git a/emulators/flycast/Makefile b/emulators/flycast/Makefile
new file mode 100644
index 000000000000..2fd11cb548c7
--- /dev/null
+++ b/emulators/flycast/Makefile
@@ -0,0 +1,66 @@
+PORTNAME=	flycast
+DISTVERSIONPREFIX=	v
+DISTVERSION=	2.4
+CATEGORIES=	emulators
+
+MAINTAINER=	bsdcode@disroot.org
+COMMENT=	Multi-platform Sega Dreamcast emulator
+WWW=		https://github.com/flyinghead/flycast
+
+LICENSE=	GPLv2
+LICENSE_FILE=	${WRKSRC}/LICENSE
+
+LIB_DEPENDS=	libchdr.so:devel/libchdr \
+		libcurl.so:ftp/curl \
+		libminiupnpc.so:net/miniupnpc \
+		libzip.so:archivers/libzip \
+		libzstd.so:archivers/zstd
+
+USES=		cmake compiler:c++17-lang lua:52+ pkgconfig sdl
+USE_GITHUB=	yes
+GH_ACCOUNT=	flyinghead
+USE_SDL=	sdl2
+
+.include "${.CURDIR}/Makefile.tuples"
+
+OPTIONS_DEFINE=		DOCS OPENMP VULKAN
+OPTIONS_DEFAULT=	ALSA AO OPENMP OSS VULKAN
+OPTIONS_GROUP=		AUDIO
+OPTIONS_GROUP_AUDIO=	ALSA AO OSS PULSEAUDIO
+
+VULKAN_DESC=	Build with Vulkan support
+
+ALSA_LIB_DEPENDS=	libasound.so:audio/alsa-lib
+ALSA_CMAKE_BOOL=	USE_ALSA
+
+AO_LIB_DEPENDS=		libao.so:audio/libao
+AO_CMAKE_BOOL=		USE_AO
+
+OPENMP_CMAKE_BOOL=	USE_OPENMP
+
+OSS_CMAKE_BOOL=		USE_OSS
+
+PULSEAUDIO_LIB_DEPENDS=	libpulse.so:audio/pulseaudio
+PULSEAUDIO_CMAKE_BOOL=	USE_PULSEAUDIO
+
+VULKAN_BUILD_DEPENDS=	glslang:graphics/glslang \
+			vulkan-headers>0:graphics/vulkan-headers
+VULKAN_CMAKE_BOOL=	USE_HOST_GLSLANG USE_VULKAN
+
+post-install-DOCS-on:
+	${MKDIR} ${STAGEDIR}${DOCSDIR}
+	(cd ${WRKSRC}/docs && \
+		${COPYTREE_SHARE} . ${STAGEDIR}${DOCSDIR})
+
+# For maintainer (do not forget to clean up Makefile.tuples afterwards to
+# remove useless submodules)
+Makefile.tuples::
+	${RM} -f ${.CURDIR}/Makefile.tuples
+	${RM} -rf ${WRKDIR}/.maintainer.checkout
+	${MKDIR} ${WRKDIR}/.maintainer.checkout
+	(cd ${WRKDIR}/.maintainer.checkout && \
+		git clone --recursive --branch=${DISTVERSIONPREFIX}${DISTVERSION} \
+		https://github.com/${GH_ACCOUNT}/${PORTNAME} . && \
+		${SH} ${FILESDIR}/gen_gh_tuple.sh > ${.CURDIR}/Makefile.tuples)
+
+.include <bsd.port.mk>
diff --git a/emulators/flycast/Makefile.tuples b/emulators/flycast/Makefile.tuples
new file mode 100644
index 000000000000..be52324f87b1
--- /dev/null
+++ b/emulators/flycast/Makefile.tuples
@@ -0,0 +1,4 @@
+GH_TUPLE= \
+	vinniefalco:LuaBridge:fab7b33b896a42dcc865ba5ecdbacd9f409137f8:LuaBridge/core/deps/luabridge \
+	GPUOpen-LibrariesAndSDKs:VulkanMemoryAllocator:6eb62e1515072827db992c2befd80b71b2d04329:VulkanMemoryAllocator/core/deps/VulkanMemoryAllocator \
+	RetroAchievements:rcheevos:563230b1c249774b4852c944dc7cdcb952c9e8e8:rcheevos/core/deps/rcheevos \
diff --git a/emulators/flycast/distinfo b/emulators/flycast/distinfo
new file mode 100644
index 000000000000..615fcccec971
--- /dev/null
+++ b/emulators/flycast/distinfo
@@ -0,0 +1,9 @@
+TIMESTAMP = 1731443633
+SHA256 (flyinghead-flycast-v2.4_GH0.tar.gz) = 44b2ff5d172f7be2be9db613ebd22635760cfc846ddb4c25e1da0d8fa79b1a1b
+SIZE (flyinghead-flycast-v2.4_GH0.tar.gz) = 30398953
+SHA256 (vinniefalco-LuaBridge-fab7b33b896a42dcc865ba5ecdbacd9f409137f8_GH0.tar.gz) = d393adc6bf1659faf2683f6ef2766ee7223650c8087ce53f8ab529e44c1c1575
+SIZE (vinniefalco-LuaBridge-fab7b33b896a42dcc865ba5ecdbacd9f409137f8_GH0.tar.gz) = 543800
+SHA256 (GPUOpen-LibrariesAndSDKs-VulkanMemoryAllocator-6eb62e1515072827db992c2befd80b71b2d04329_GH0.tar.gz) = 9afe46ce02681799ca907fb79990ff276877dfb6324d48da21b215b92649368d
+SIZE (GPUOpen-LibrariesAndSDKs-VulkanMemoryAllocator-6eb62e1515072827db992c2befd80b71b2d04329_GH0.tar.gz) = 877925
+SHA256 (RetroAchievements-rcheevos-563230b1c249774b4852c944dc7cdcb952c9e8e8_GH0.tar.gz) = fab0809e60d8ed64a4a2bef2964315e9f4b6e770db4c963630441352d1dd21d1
+SIZE (RetroAchievements-rcheevos-563230b1c249774b4852c944dc7cdcb952c9e8e8_GH0.tar.gz) = 669618
diff --git a/emulators/flycast/files/gen_gh_tuple.sh b/emulators/flycast/files/gen_gh_tuple.sh
new file mode 100644
index 000000000000..ab014ef5f473
--- /dev/null
+++ b/emulators/flycast/files/gen_gh_tuple.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+echo "GH_TUPLE= \\"
+for _sm_root in $(find . -type f -name .gitmodules | sed 's/\.gitmodules$//' | sort)
+do
+  (
+    cd "${_sm_root}"
+
+    # Crawl name|path|url list of submodules within _sm_root
+    grep -e '^\[submodule "' -e 'path = ' -e 'url = ' .gitmodules | \
+      sed -E -e 's|.*"([^"]+)".*|\1|' -e 's|.*= ||' | \
+      paste - - - | \
+      sed -E 's/[[:space:]]+/|/g' | \
+    while read _sm
+    do
+      _sm_name=$(echo "${_sm}" | cut -d '|' -f 1)
+      _sm_path=$(echo "${_sm}" | cut -d '|' -f 2)
+      _sm_url=$(echo "${_sm}" | cut -d '|' -f 3)
+
+      _sm_prefix=$(echo "${_sm_root}" | sed 's|^\./||')
+
+      _account_project=$(echo "${_sm_url}" | sed -e 's|^https://github.com/||' -e 's|/|:|g' -e 's|\.git$||')
+      _group=$(echo "${_account_project}" | cut -d ':' -f 2 | tr -cd 'a-zA-Z0-9_')
+      _tagname_group_subdir=$(git submodule status "${_sm_path}" | sed -E -e 's|^.||' -e "s|[[:space:]]+|:${_group}/${_sm_prefix}|" -e 's|[[:space:]]+.*$||')
+      echo -e "\t${_account_project}:${_tagname_group_subdir} \\"
+    done
+  )
+done
+echo ""
diff --git a/emulators/flycast/files/patch-CMakeLists.txt b/emulators/flycast/files/patch-CMakeLists.txt
new file mode 100644
index 000000000000..1c9626e3d7e4
--- /dev/null
+++ b/emulators/flycast/files/patch-CMakeLists.txt
@@ -0,0 +1,57 @@
+--- CMakeLists.txt.orig	2024-10-21 14:13:00 UTC
++++ CMakeLists.txt
+@@ -410,9 +410,13 @@ endif()
+ 	target_link_libraries(${PROJECT_NAME} PRIVATE glslang::glslang-default-resource-limits glslang::SPIRV)
+ endif()
+ 
++if(USE_OSS)
++	target_compile_definitions(${PROJECT_NAME} PRIVATE USE_OSS)
++endif()
++
+ if(NOT LIBRETRO)
+ 	find_package(ALSA)
+-	if(ALSA_FOUND AND NOT ANDROID)
++	if(USE_ALSA AND ALSA_FOUND AND NOT ANDROID)
+ 		target_compile_definitions(${PROJECT_NAME} PRIVATE USE_ALSA)
+ 		target_include_directories(${PROJECT_NAME} PRIVATE ${ALSA_INCLUDE_DIRS})
+ 		target_link_libraries(${PROJECT_NAME} PRIVATE ${ALSA_LIBRARIES})
+@@ -471,9 +475,8 @@ endif()
+ 	endif()
+ endif()
+ 
+-add_subdirectory(core/deps/libchdr EXCLUDE_FROM_ALL)
+-target_link_libraries(${PROJECT_NAME} PRIVATE chdr-static)
+-target_include_directories(${PROJECT_NAME} PRIVATE core/deps/libchdr/include)
++pkg_check_modules(libchdr REQUIRED libchdr)
++target_link_libraries(${PROJECT_NAME} PRIVATE ${libchdr_LINK_LIBRARIES})
+ 
+ if(NOT WITH_SYSTEM_ZLIB)
+ 	set(ZLIB_RELATIVE_PATH "core/deps/libchdr/deps/zlib-1.3.1")
+@@ -490,7 +493,7 @@ if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND 
+ find_package(PkgConfig)
+ if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND NOT LIBRETRO)
+ 	pkg_check_modules(AO IMPORTED_TARGET ao)
+-	if(AO_FOUND)
++	if(USE_AO AND AO_FOUND)
+ 		target_compile_definitions(${PROJECT_NAME} PRIVATE USE_LIBAO)
+ 		target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::AO)
+ 	endif()
+@@ -510,7 +513,7 @@ if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND 
+ 	endif()
+ 
+ 	pkg_check_modules(LIBPULSE IMPORTED_TARGET libpulse)
+-	if(LIBPULSE_FOUND)
++	if(USE_PULSEAUDIO AND LIBPULSE_FOUND)
+ 		target_compile_definitions(${PROJECT_NAME} PRIVATE USE_PULSEAUDIO)
+ 		target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::LIBPULSE)
+ 	endif()
+@@ -1338,8 +1341,7 @@ if(USE_VULKAN)
+ 		target_compile_definitions(${PROJECT_NAME} PUBLIC VK_USE_PLATFORM_METAL_EXT)
+ 	endif()
+ 
+-	add_subdirectory(core/deps/Vulkan-Headers)
+-	target_link_libraries(${PROJECT_NAME} PRIVATE Vulkan::Headers)
++	find_package(VulkanHeaders)
+ 
+ 	add_subdirectory(core/deps/VulkanMemoryAllocator)
+ 	target_compile_options(VulkanMemoryAllocator INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:AppleClang,Clang>>:-Wno-nullability-completeness>)
diff --git a/emulators/flycast/files/patch-core_rend_vulkan_vmallocator.cpp b/emulators/flycast/files/patch-core_rend_vulkan_vmallocator.cpp
new file mode 100644
index 000000000000..cf15ae93245a
--- /dev/null
+++ b/emulators/flycast/files/patch-core_rend_vulkan_vmallocator.cpp
@@ -0,0 +1,9 @@
+--- core/rend/vulkan/vmallocator.cpp.orig	2024-11-10 23:58:20 UTC
++++ core/rend/vulkan/vmallocator.cpp
+@@ -71,5 +71,5 @@ void VMAllocator::Init(vk::PhysicalDevice physicalDevi
+ #endif
+ 
+ 	VkResult rc = vmaCreateAllocator(&allocatorInfo, &allocator);
+-	vk::resultCheck(static_cast<vk::Result>(rc), "vmaCreateAllocator failed");
++	vk::detail::resultCheck(static_cast<vk::Result>(rc), "vmaCreateAllocator failed");
+ }
diff --git a/emulators/flycast/files/patch-core_rend_vulkan_vmallocator.h b/emulators/flycast/files/patch-core_rend_vulkan_vmallocator.h
new file mode 100644
index 000000000000..7bb55bc9b568
--- /dev/null
+++ b/emulators/flycast/files/patch-core_rend_vulkan_vmallocator.h
@@ -0,0 +1,38 @@
+--- core/rend/vulkan/vmallocator.h.orig	2024-11-10 23:58:42 UTC
++++ core/rend/vulkan/vmallocator.h
+@@ -64,7 +64,7 @@ class Allocation (public)
+ 			return allocInfo.pMappedData;
+ 		void *p;
+ 		VkResult res = vmaMapMemory(allocator, allocation, &p);
+-		vk::resultCheck(static_cast<vk::Result>(res), "vmaMapMemory failed");
++		vk::detail::resultCheck(static_cast<vk::Result>(res), "vmaMapMemory failed");
+ 		VkMemoryPropertyFlags flags;
+ 		vmaGetMemoryTypeProperties(allocator, allocInfo.memoryType, &flags);
+ 		if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) && (flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0)
+@@ -114,7 +114,7 @@ class VMAllocator (public)
+ 		VmaAllocation vmaAllocation;
+ 		VmaAllocationInfo allocInfo;
+ 		VkResult rc = vmaAllocateMemory(allocator, (VkMemoryRequirements*)&memoryRequirements, &allocCreateInfo, &vmaAllocation, &allocInfo);
+-		vk::resultCheck(static_cast<vk::Result>(rc), "vmaAllocateMemory failed");
++		vk::detail::resultCheck(static_cast<vk::Result>(rc), "vmaAllocateMemory failed");
+ 		return Allocation(allocator, vmaAllocation, allocInfo);
+ 	}
+ 
+@@ -123,7 +123,7 @@ class VMAllocator (public)
+ 		VmaAllocation vmaAllocation;
+ 		VmaAllocationInfo allocInfo;
+ 		VkResult rc = vmaAllocateMemoryForImage(allocator, (VkImage)image, &allocCreateInfo, &vmaAllocation, &allocInfo);
+-		vk::resultCheck(static_cast<vk::Result>(rc), "vmaAllocateMemoryForImage failed");
++		vk::detail::resultCheck(static_cast<vk::Result>(rc), "vmaAllocateMemoryForImage failed");
+ 		vmaBindImageMemory(allocator, vmaAllocation, (VkImage)image);
+ 
+ 		return Allocation(allocator, vmaAllocation, allocInfo);
+@@ -134,7 +134,7 @@ class VMAllocator (public)
+ 		VmaAllocation vmaAllocation;
+ 		VmaAllocationInfo allocInfo;
+ 		VkResult rc = vmaAllocateMemoryForBuffer(allocator, (VkBuffer)buffer, &allocCreateInfo, &vmaAllocation, &allocInfo);
+-		vk::resultCheck(static_cast<vk::Result>(rc), "vmaAllocateMemoryForBuffer failed");
++		vk::detail::resultCheck(static_cast<vk::Result>(rc), "vmaAllocateMemoryForBuffer failed");
+ 		vmaBindBufferMemory(allocator, vmaAllocation, (VkBuffer)buffer);
+ 
+ 		return Allocation(allocator, vmaAllocation, allocInfo);
diff --git a/emulators/flycast/files/patch-core_rend_vulkan_vulkan__context.cpp b/emulators/flycast/files/patch-core_rend_vulkan_vulkan__context.cpp
new file mode 100644
index 000000000000..dbc4bc7501e7
--- /dev/null
+++ b/emulators/flycast/files/patch-core_rend_vulkan_vulkan__context.cpp
@@ -0,0 +1,19 @@
+--- core/rend/vulkan/vulkan_context.cpp.orig	2024-10-21 14:13:00 UTC
++++ core/rend/vulkan/vulkan_context.cpp
+@@ -42,6 +42,7 @@ VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
+ #endif
+ 
+ #include <memory>
++#include <set>
+ 
+ void ReInitOSD();
+ 
+@@ -146,7 +147,7 @@ bool VulkanContext::InitInstance(const char** extensio
+ #if defined(__ANDROID__) && HOST_CPU == CPU_ARM64
+ 		vkGetInstanceProcAddr = loadVulkanDriver();
+ #else
+-		static vk::DynamicLoader dl;
++		static vk::detail::DynamicLoader dl;
+ 		vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
+ #endif
+ 		if (vkGetInstanceProcAddr == nullptr) {
diff --git a/emulators/flycast/pkg-descr b/emulators/flycast/pkg-descr
new file mode 100644
index 000000000000..b39cc5e38a3e
--- /dev/null
+++ b/emulators/flycast/pkg-descr
@@ -0,0 +1,14 @@
+Flycast is a multi-platform Sega Dreamcast, Naomi, Naomi 2, and Atomiswave
+emulator derived from the inactive reicast project.
+
+Flycast provides high performance and high compatibility. It supports an HLE
+BIOS, so dumping a real BIOS from a console isn't required (but it is still
+recommended for increased compatibility). Furthermore it supports widescreen,
+either with a generic hack to render outside of the screen, or by auto-applying
+codes/patches to certain games which provides better results. Resolution and
+texture upscaling is supported alongside dumping and loading of custom textures.
+Flycast emulates standard Dreamcast controllers, keyboard, mouse, light-gun
+(with your mouse), Twin Sticks, and even the ASCII Mission Stick. It can emulate
+two expansion sockets per controller (VMU, Purupuru/Rumble Pack, or Microphone).
+Most if not all games compatible with Dreamcast Live servers are supported by
+Flycast.
diff --git a/emulators/flycast/pkg-plist b/emulators/flycast/pkg-plist
new file mode 100644
index 000000000000..00557a03fc4a
--- /dev/null
+++ b/emulators/flycast/pkg-plist
@@ -0,0 +1,17 @@
+bin/flycast
+share/applications/flycast.desktop
+%%PORTDOCS%%%%DOCSDIR%%/DreamCast_Specs.md
+%%PORTDOCS%%%%DOCSDIR%%/Dynarec Architecture.md
+%%PORTDOCS%%%%DOCSDIR%%/Naomi_Overview.md
+%%PORTDOCS%%%%DOCSDIR%%/Notable game bugs.md
+%%PORTDOCS%%%%DOCSDIR%%/microphone support notes.txt
+%%PORTDOCS%%%%DOCSDIR%%/neil_corlett_aica_notes.txt
+share/icons/hicolor/128x128/apps/flycast.png
+share/icons/hicolor/16x16/apps/flycast.png
+share/icons/hicolor/256x256/apps/flycast.png
+share/icons/hicolor/32x32/apps/flycast.png
+share/icons/hicolor/512x512/apps/flycast.png
+share/icons/hicolor/64x64/apps/flycast.png
+share/man/man1/flycast.1.gz
+share/metainfo/org.flycast.Flycast.metainfo.xml
+share/pixmaps/flycast.png