[WIP] Libretro core implementation#1770
Conversation
…era' into libretro-core-rtissera
…era' into libretro-core-rtissera
…era' into libretro-core-rtissera
|
This was so big, I enlisted the help of LLMs to go through it... What's Good
Concerns & IssuesHigh Priority
Medium Priority
Low Priority
Recommendations
SummaryThis is an impressive amount of work for a libretro core implementation. The platform abstraction pattern is well-designed and the right approach. The main risks are in the sysdeps.h changes (affects all builds), inconsistent use of the abstraction pattern (filesystem still uses #ifdef), and the sheer size making review difficult. Splitting out the independent code quality fixes and squashing the commit history would make this much easier to review and merge safely. |
|
Yeah, this is quite invasive. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@midwan can you reasset the PR before I move to proper rebase / squash commit re-organization ? |
There was a problem hiding this comment.
Pull request overview
Adds a Libretro core implementation (Linux amd64/aarch64) with Libretro-specific platform abstractions for audio/video/input/logging and filesystem access, plus updates to WHDLoad boot flow and CHD/FLAC handling to better suit Libretro environments.
Changes:
- Introduces platform-indirection headers (gfx/input/sound/gui/color/amiberry platform) to support both host and Libretro builds.
- Adds Libretro VFS-backed stdio/POSIX emulation and adapts filesystem usage to route through it.
- Updates WHDLoad booting (including archive slave fallback) and hardens several file/network parsing paths.
Reviewed changes
Copilot reviewed 80 out of 82 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/threaddep/thread.h | Drops SDL_thread include for Libretro shim compatibility |
| src/specialmonitors.cpp | Disables PNG/genlock loading under Libretro |
| src/sounddep/sound_platform_internal_libretro.h | Libretro audio backend hooks (batch/callback) |
| src/sounddep/sound_platform_internal_host.h | Host stub for sound platform indirection |
| src/sounddep/sound_platform_internal.h | Includes selected sound platform header |
| src/sounddep/sound.cpp | Routes audio open/output/enumeration through platform hooks |
| src/slirp/tcp_subr.cpp | Fixes unsafe snprintf sizing and bounds handling |
| src/slirp/misc.cpp | Silences unused syscall return warnings |
| src/qemuvga/qemuuaeglue.h | Adds missing stddef include |
| src/ppc/ppcd.cpp | Hardens operand formatting with bounded append helper |
| src/osdep/writelog.cpp | Preps host logging to coexist with Libretro logging |
| src/osdep/sysconfig.h | Adds Libretro JIT gating + portability tweaks |
| src/osdep/retroarch.cpp | Adds FILE*-based parsing for Libretro builds |
| src/osdep/registry.cpp | Routes filesystem checks through amiberry_fs abstraction |
| src/osdep/main.cpp | Adds standalone main() wrapper calling amiberry_main |
| src/osdep/libretro/writelog.cpp | Libretro logging implementation using log_cb/SDL_Log |
| src/osdep/libretro/stdioemu_vfs.cpp | Implements stdio emulation via Libretro VFS (cookie-based) |
| src/osdep/libretro/posixemu_vfs.cpp | Implements POSIX emulation via Libretro VFS |
| src/osdep/libretro/mp3decoder.cpp | Adds Libretro MP3 decoder (dr_mp3 + zfile) |
| src/osdep/libretro/libretro_vfs.h | Declares accessors for Libretro VFS interface availability |
| src/osdep/libretro/input_platform_internal.h | Libretro joystick enumeration/mapping defaults |
| src/osdep/libretro/input_platform.cpp | Libretro keyboard init stub |
| src/osdep/libretro/gui_handling_platform.h | Libretro GUI handling shim includes stub |
| src/osdep/libretro/gfx_platform_internal.h | Libretro gfx platform hooks (present/output/format/display) |
| src/osdep/libretro/amiberry_platform_internal.h | Libretro platform behavior hooks (SDL/event pump/etc) |
| src/osdep/libretro/amiberry_fs.h | Filesystem abstraction using VFS-backed posixemu calls |
| src/osdep/keyboard.cpp | Includes SDL.h for required key APIs |
| src/osdep/input_platform_internal_host.h | Host joystick init/mapping via SDL controller DB |
| src/osdep/input_platform_internal.h | Includes selected input platform header |
| src/osdep/input_platform.h | Declares osdep_init_keyboard() |
| src/osdep/input_platform.cpp | Host keyboard init (RetroArch config + german layout detect) |
| src/osdep/gui_handling_platform_host.h | Host GUI handling include passthrough |
| src/osdep/gui_handling_platform.h | Includes selected GUI handling header |
| src/osdep/gfx_platform_internal_host.h | Host gfx platform hooks (png/screenshots/window icon) |
| src/osdep/gfx_platform_internal.h | Includes selected gfx platform header |
| src/osdep/dpi_handler.hpp | Switches to <SDL.h>/<SDL_ttf.h> includes |
| src/osdep/bsdsocket_host.cpp | Silences unused read/write return values |
| src/osdep/amiberry_whdbooter.cpp | VFS-aware kickstart handling + slave fallback in archives |
| src/osdep/amiberry_platform_internal_host.h | Host platform hooks for SDL/UI/clipboard and event pump |
| src/osdep/amiberry_platform_internal.h | Includes selected amiberry platform header |
| src/osdep/amiberry_input.h | Includes SDL.h for controller symbols/types |
| src/osdep/amiberry_input.cpp | Refactors keyboard/joystick init through platform hooks |
| src/osdep/amiberry_gfx.cpp | Refactors gfx through platform hooks; Libretro frame output |
| src/osdep/amiberry_filesys.cpp | Routes filesystem operations through amiberry_fs/VFS when needed |
| src/osdep/amiberry.cpp | Moves platform-dependent behavior behind platform hooks; amiberry_main |
| src/jit/compemu_prefs.cpp | Adds missing includes (likely to fix build break) |
| src/include/uae/string.h | Adds standard C/C++ includes needed by string utilities |
| src/include/sysdeps.h | Adds STAT typedef + Libretro DONT_HAVE_POSIX/STDIO wiring |
| src/include/options.h | Swaps GUI color include to platform-selected header |
| src/include/gui_color_platform_host.h | Host GUI color include passthrough |
| src/include/gui_color_platform.h | Includes selected GUI color header |
| src/fpp_native.cpp | Libretro-safe x87 control word setting using inline asm |
| src/blkdev_cdimage.cpp | Makes FLAC backend selectable (dr_flac vs libFLAC) |
| src/archivers/lha/header.cpp | Fixes readlink bounds handling for LHA headers |
| src/archivers/chd/osdlib_unix.cpp | Uses <SDL.h> include path |
| src/archivers/chd/flac_platform_internal_libretro.h | Libretro FLAC platform settings/types (dr_flac) |
| src/archivers/chd/flac_platform_internal_host.h | Host FLAC platform settings (libFLAC) |
| src/archivers/chd/flac_platform_internal.h | Includes selected CHD FLAC platform header |
| src/archivers/chd/flac.h | Adds platform switch for FLAC encoder/decoder APIs |
| src/archivers/chd/flac.cpp | Adds dr_flac-based decoder + Libretro encoder stub |
| src/archivers/chd/corestr.cpp | Fixes size_t/long overflow hazards in string distance |
| src/archivers/chd/chdcd.cpp | Hardens parsing against short reads / bad fgets loops |
| libretro/libretro_stubs.cpp | Adds Libretro stubs for GUI/MIDI/ethernet/other host deps |
| libretro/libretro_shared.h | Exposes log_cb to core code |
| libretro/libretro_gui_stubs.cpp | Adds GUI/TTF/VKBD stub functions for Libretro |
| libretro/libretro-common | Adds libretro-common as submodule pointer |
| libretro/libco | Adds libco as submodule pointer |
| libretro/gui_handling_stub.h | Defines minimal GUI handling symbols for Libretro |
| libretro/gui_color_platform_libretro.h | Provides minimal gcn::Color for Libretro builds |
| libretro/SDL_ttf.h | Libretro SDL_ttf shim header |
| libretro/SDL_thread.h | Libretro SDL_thread shim header |
| libretro/SDL_mutex.h | Libretro SDL_mutex shim header |
| libretro/SDL.h | Libretro SDL shim header |
| libretro/Makefile | Builds Libretro core + wires platform headers/VFS/zlib/submodules |
| cmake/SourceFiles.cmake | Adds host platform header defines + new source files |
| .gitmodules | Registers libretro-common & libco submodules |
| .github/workflows/c-cpp.yml | Uses submodules; adds zlib support for aarch64 cross build |
Comments suppressed due to low confidence (4)
src/osdep/libretro/writelog.cpp:1
SDL_GetTicks()is time-since-start, not Unix epoch time. Converting it totime_tand passing it tolocaltime()will produce incorrect timestamps (typically near 1970). Usetime(nullptr)(orstd::chrono::system_clock) for the wall-clock portion and keepSDL_GetTicks()only for relative/elapsed timing if needed.
src/osdep/libretro/writelog.cpp:1vsnprintfcan return a negative value on encoding errors, or a value >= the provided buffer size when output is truncated. Usingbuffer[count]can write out of bounds. Clamp the index (e.g., treat negative as 0; treat >= (WRITE_LOG_BUF_SIZE - 1) as (WRITE_LOG_BUF_SIZE - 1)) before writing the terminator.
src/osdep/libretro/stdioemu_vfs.cpp:1- In Libretro builds, falling back to
::fopenbypasses the Libretro VFS and may fail in sandboxed/front-end environments (and defeats the purpose ofDONT_HAVE_STDIO). Consider returningnullptrwhen VFS isn't available/usable, or provide an alternate non-cookie implementation for non-glibc platforms instead of using the host filesystem as a fallback.
src/osdep/libretro/posixemu_vfs.cpp:1 posixemu_accessignores the requested access mode (R_OK/W_OK/X_OK), so callers will treat “exists” as “permitted”, which is not equivalent to POSIXaccess(2). If you can't reliably emulate permissions with Libretro VFS, a safer approximation is to attempt anopenin the requested mode (read/write) and return 0 only if it succeeds.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use sizeof(int16_t) for FLAC filesize/frame calculations since drflac_read_pcm_frames_s16 always outputs 16-bit samples, regardless of source bit depth (e.g. 24-bit FLAC would overallocate). Widen posixemu_seek and io_lseek from int to off_t so that seek offsets on large disk images (>2GB HDF/CHD) are not truncated to 32 bits.
Prevents tar from receiving an HTML error page on transient network failures, giving a clear error instead.
|
@midwan let me know if current failures are expected or not |
|
The build failures on the opengl targets is because that branch is behind the |
|
@midwan okay I will work on conflict resolution now |
|
Thanks for the libretro port! I'm getting a compile error with this: Can the JIT include armv7a also? |
|
This is still pretty much WIP, but the automated builds don't fail - so something must be wrong where you compiled it. Please open a new issue with more details |
Fixes #1759 .
Changes proposed in this pull request:
@midwan