Commit graph

141 commits

Author SHA1 Message Date
刘皓
ef58df103a
Remember to actually initialize exception classes in libretro builds 2025-05-18 09:42:42 -04:00
刘皓
83a6b7a1f1
Re-add missing GFX_LOCK/GFX_UNLOCK calls in binding-sandbox 2025-05-17 19:41:43 -04:00
刘皓
134e08ce6a
Allow the entire codebase to build with -fno-exceptions -fno-rtti in libretro builds 2025-05-16 21:59:54 -04:00
刘皓
3b564efd79
Remove direct dependency on Boost.Core in libretro builds 2025-05-16 15:51:51 -04:00
刘皓
e3cbed2fb3
Remove unused next_func_ptr field of binding_base 2025-05-14 21:16:50 -04:00
刘皓
28fb36af98
Capitalize /Dist, /Game, /Save and /System in libretro builds for consistency 2025-05-13 17:53:59 -04:00
刘皓
d62d6aef3e
Remove WASI_DEBUG macro 2025-05-12 13:50:48 -04:00
刘皓
67e61917a7
Apply big-endian fixes to binding-sandbox/wasi.cpp as well 2025-05-12 12:39:08 -04:00
刘皓
7347afed21
Revert "Make sure sandbox stack grows upwards in big-endian libretro builds"
This reverts commit 58e6f71ef3.

The original behaviour was the correct one. The stack should always grow
downwards.
2025-05-10 23:37:39 -04:00
刘皓
68b2067a45
Remove void pointer arithmetic in binding-sandbox/binding-base.h 2025-05-10 20:44:46 -04:00
刘皓
58e6f71ef3
Make sure sandbox stack grows upwards in big-endian libretro builds 2025-05-10 19:23:43 -04:00
刘皓
3ba12e5672
Fix handling of big-endian platforms in libretro builds
In big-endian libretro builds, the WebAssembly memory is reversed, so no
byte-swapping is required to read from/write to WebAssembly memory
(which is little-endian).

However, that means the ways to get and set values in WebAssembly memory
are endianness-dependent, so I've added the correct such ways for
big-endian platforms.
2025-05-10 18:55:14 -04:00
刘皓
09ed08c087
Fix edge case in memory reallocation algorithm in wasm-rt.cpp 2025-05-10 11:09:20 -04:00
刘皓
c5747f17c5
Fix minor issues in binding-sandbox/binding-base.h and binding-sandbox/binding-util.h 2025-05-10 09:25:43 -04:00
刘皓
8ec189e3d2
Remove always-false static_assert from binding-sandbox/binding-base.h
This is causing compilation errors with some compilers.
2025-05-09 23:28:17 -04:00
刘皓
b8d785b7e1
Implement growing VM memory in libretro builds
The binding coroutines in libretro builds are constructed on the VM
stack, so reallocating the VM memory would corrupt the memory of any
currently existing coroutines.

I've changed it so that the coroutines are no longer constructed on the
VM stack so that they're unaffected by VM memory reallocations, and
added a "slot" mechanism for storing variables on the VM stack. (Any
Ruby `VALUE`s used by a coroutine have to be stored on the VM stack so
that the Ruby garbage collector doesn't free them while they're being
used, which is why the slot mechanism is necessary.)
2025-05-09 22:49:13 -04:00
刘皓
d71cd242c7
Improve save directory creation algorithm in libretro builds
Before, if the game tried to create a save file, missing parent
directories would always be created because they could possibly exist
only in the game directory and not in the save directory, and we
wouldn't know due to the union mounting of the save and game
directories. But this is inconsistent with the behaviour of file
creation, where it should fail if parent directories don't exist.

The behaviour has been changed to only create parent directories if the
parent directories already exist. I know that sounds strange, but if the
parent directories exist, it could be that they only exist in the game
directory but not the save directory due to the union mounting, so we
need to create the parent directories, which will be created in the save
directory due to it being set as the write directory in PhysFS.
2025-05-07 22:13:45 -04:00
刘皓
c85e9554ec
Implement writing to filesystem (i.e. game saving) in libretro builds
Files are written to the libretro save directory, which is mounted at
/save in PhysFS. All filesystem calls made from Ruby in libretro builds
are routed through PhysFS, so the game can just use any ordinary
filesystem function provided by Ruby to interact with /save.

It's also union mounted on top of the game directory (located at /game
in PhysFS) so that games that write their save files to the current
working directory will have their save files saved to the libretro save
directory instead of the game directory.

For security and portability reasons, nothing outside of the libretro
save directory can be written to, and nothing outside of the libretro
save directory, the libretro game directory and the various embedded
files used by the runtime can be read from.
2025-05-07 16:01:41 -04:00
刘皓
3e3df818aa
Use C getcwd() instead of Ruby Dir.pwd() to get CWD in libretro builds 2025-05-06 18:02:03 -04:00
刘皓
13c0657691
Handle current working directory properly in libretro builds
Any relative paths that the game tries to access in libretro builds will
now be relative to whatever is the current working directory in the Ruby
sandbox, which will also now be initialized to the game directory during
initialization. Before, all of the bindings that took paths were
hardcoded to prepend the path with the game directory.
2025-05-06 16:55:28 -04:00
刘皓
74e5cc763c
Implement Graphics.play_movie in libretro builds 2025-05-03 18:27:44 -04:00
刘皓
c9e7c4d02d
Stub out the rest of the input bindings in libretro builds 2025-05-01 22:49:18 -04:00
刘皓
df559241a2
Complete almost all of the bindings in libretro builds
The only things left are the bindings for the input extensions and
possibly adding in `SANDBOX_YIELD` to the `Graphics.play_movie` binding
later.
2025-05-01 14:32:59 -04:00
刘皓
82b2ad0ef1
Add serializable-binding.h in libretro builds 2025-05-01 13:58:54 -04:00
刘皓
bdcbfd26f1
Add more helper functions for bindings in libretro builds 2025-05-01 11:18:02 -04:00
刘皓
41fc9bf7c7
Pin wasm2c version in libretro builds
To prevent incompatibilities between wasm2c and the custom wasm-rt
implementation.
2025-05-01 00:53:26 -04:00
刘皓
482f21bc2e
Fix Darwin compilation error in binding-sandbox/graphics-binding.cpp 2025-04-30 23:39:51 -04:00
刘皓
5b94ce4e80
Refactor binding-sandbox header files into .cpp files 2025-04-30 22:31:13 -04:00
刘皓
09bcb1532c
Refactor out the SANDBOX_COROUTINE() macro
Removing this macro allows the correct line numbers to show up in GDB
stack traces.
2025-04-30 19:00:48 -04:00
刘皓
2de7a050db
Use property binding helper macros in libretro builds 2025-04-30 15:47:02 -04:00
刘皓
eb0b011734
Add mouse bindings in libretro builds 2025-04-30 12:26:18 -04:00
刘皓
2373a22a70
Complete the graphics bindings in libretro builds 2025-04-29 14:51:19 -04:00
刘皓
a3412bbe41
Fix Graphics.transition(0) being ignored in libretro builds 2025-04-29 14:13:41 -04:00
刘皓
8182f3591c
Fix typo in wrap_property in libretro binding utils 2025-04-29 00:07:54 -04:00
刘皓
c51e0d2701
Complete the bitmap bindings in libretro builds 2025-04-28 16:15:11 -04:00
刘皓
c0b0816b8a
Add wrap_property helper function for bindings in libretro builds 2025-04-28 13:39:06 -04:00
刘皓
fbfb14d7ad
Implement more of the bitmap bindings for libretro builds 2025-04-27 22:18:06 -04:00
刘皓
1c6debd030
Complete the audio bindings in libretro builds 2025-04-27 18:51:30 -04:00
刘皓
0b9baa1007
Add mutex and condition variable polyfill for libretro 3DS builds 2025-04-27 00:49:47 -04:00
刘皓
380fcc0ed2
Complete the bindings for Color, Tone and Rect in libretro builds 2025-04-26 18:33:53 -04:00
刘皓
0d07aff3e2
Remove exceptions from the sandbox implementation in libretro builds 2025-04-25 13:31:32 -04:00
刘皓
003602eff8
Only poll input in libretro builds when Input.update is called 2025-04-25 11:01:12 -04:00
刘皓
2b3a97e83c
Fix frame duping bugs in libretro builds
* Fixed a bug where frames are still duped when the frontend is
  fast-forwarding

* Fixed a bug where manual frame duping (without
  `RETRO_ENVIRONMENT_GET_CAN_DUPE`) causes screen flickering during a
  `Graphics.transition` call
2025-04-25 10:45:11 -04:00
刘皓
a12e3caf77
Always run at display rate in libretro builds
Apparently we're not supposed to use
`RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO` to change the FPS. The core
should be running at the display refresh rate and resampling the game's
video output.
2025-04-24 15:08:42 -04:00
刘皓
71653549f2
Add threaded audio driver in libretro builds
This adds a new driver for audio in libretro builds for devices with
multithreading support that defers audio rendering to a worker thread
provided by the libretro frontend.

The threaded driver has the advantage that video lag will not also cause
the audio to lag, which is very noticeable since it manifests in the
form of audio crackling when it happens.
2025-04-22 12:17:15 -04:00
刘皓
52d65cfe96
Decrease Ruby stack size in libretro builds from 16 MiB to 2 MiB
I highly doubt any game needs that much stack space.
2025-04-21 13:05:17 -04:00
刘皓
c32073d200
Fix memory leak in dfree implementation in libretro builds 2025-04-20 17:48:19 -04:00
刘皓
244d88908c
Remove unnecessary reserve() in binding-base.h 2025-04-20 13:40:49 -04:00
刘皓
ced3e697bd
Fix Graphics.fadeout/.fadein causing screen flashing in libretro builds 2025-04-18 11:54:23 -04:00
刘皓
dafcb15ea5
Add enough bindings in libretro builds to play Crysalis 2025-04-17 14:17:17 -04:00