Commit Graph
45 Commits
Author SHA1 Message Date
LibretroAdmin 2806bb5a18 led: drop the driver on free, log the driver chosen
led_driver_free() leaves no driver behind, so nothing can reach a
freed one before the next led_driver_init(). The init log names the
driver actually chosen, by its ident, and stays quiet for the null
driver, an unknown name included. A compile-time check keeps MAX_LEDS
within the output store's slots.

samples/frontend/led_driver checks that a freed driver is not
called and what the init logs.
2026-10-17 01:06:09 +02:00
Codex 421e7d9859 input: publish output values and pending state atomically
Pack a 16-bit rumble strength or boolean LED state with its pending bit in one 32-bit mailbox. Taking a slot atomically consumes its value, so a concurrent post cannot replace a taken value and be delivered twice.

Keep repeated-value refreshes and zero-strength stops. Normalize LED states at the boolean libretro boundary. Add a forced take/post race and shared-slot producer coverage.
2026-10-09 19:26:13 +02:00
LibretroAdmin 9c7bdc3855 input: a core's rumble and LED calls are stored, and written after the frame
A core calls set_rumble_state and set_led_state from inside
retro_run(), and both went straight to the driver: an ioctl or a
transfer for a motor; for an LED a sysfs open, write and close, an X11
round trip, or an injected key press. As many times a frame as the
core called, on the core's own stack. A core that reports its rumble
level every frame paid for a device write every frame, and one that
sets it several times a frame paid for each.

The calls now store what was asked for (input/input_output_store.h),
and the frame loop writes it once the core has run: one driver call
for each motor or LED that was set, with the frame's last value.

- An output set to the value it already had is still written once
  that frame. Drivers whose effects run out rely on a core repeating
  itself, so the store remembers that a slot was set, not only what
  to.
- The write happens after the cheats, which can rumble too, and so
  after run-ahead and netplay replays: several runs of the core in
  one iterate are one write.
- What a core sets while loading or unloading is written when that
  call returns. No frame follows an unload to write an LED it turned
  off.
- CMD_EVENT_RUMBLE_STOP writes its zeros at once, as before, and
  drops whatever was waiting so it cannot restart a motor.
- Posting is safe from any thread, since some cores call from one of
  their own; the driver is now only ever called from the main thread.

What a core can notice:

- A motor or LED changes up to a frame later than it did: at the end
  of the frame in which the core asked, not in the middle of it.
- set_rumble_state returns what the driver answered the last time
  that motor was written, and before the first write whether a driver
  with motors is loaded, where it used to return the answer to this
  very call. The port and effect are now checked: a port past
  MAX_USERS indexed the joypad-index setting out of bounds.

This is the first part of the output scheduler in the input plan
(WP-09). The write is still on the main thread; moving it to the
device's own thread comes with per-device sessions.

Tests:

- samples/input/output_store builds the store on a host: a post
  writes nothing, many posts in a frame are one write with the last
  value, a repeat is still written, a drop forgets, and with three
  threads posting against a taker every output ends on its last
  value. Run under ASan + UBSan and under TSan.
- samples/runloop/frontend_overhead gains a lane in which the
  harness core makes six rumble calls a frame and the joypad driver's
  set_rumble is counted. Before: 1800 calls, 1800 driver writes inside
  retro_run(). After: none inside, one per motor after it, each with
  the last strength; a stop writes zeros and leaves nothing behind.

The frame costs 2.9 us in the harness before and after. Compiled
through the Android unity build; the menu harnesses pass.
2026-10-02 23:20:14 +02:00
LibretroAdmin cbcc8696ec overlay: LED images are the pack's to name; ledN_map reaches nul buttons only
A pack names the image that shows an LED with overlayN_descM_led = K
(1-based, as ledN_map counts): under led_driver = "overlay" that image
shows while the core has LED K lit, and a pack that names any LED image
is not mapped at all. For a pack that names none, ledN_map still picks
slots of the page, but only the image of a "nul" button answers to it:
a desc that does something when pressed is never an LED, so a config
made for an LED overlay leaves a gamepad pack's controls where they are.

The LED driver reports the core's LEDs (input_overlay_set_led) and
input/input_overlay_leds.c decides what they hide. The per-slot
visibility array, its enum and the parameter threaded through the
alpha and poll paths are gone.

overlay_visibility_bounds_test now builds input_overlay_leds.c with
the LED driver and pins the map/named/off cases and the page bound;
overlay_led_hidden_test runs a mapped pack and a named pack under Xvfb
with Up held.
2026-09-23 03:16:29 +02:00
LibretroAdmin bc0cf2adef led/win32: read the published modifier mask instead of GetKeyState
keyboard_led() runs on the main thread: led_driver_init from
retroarch.c and led_driver_set_led wired into the core LED interface in
runloop.c. Under video_threaded the main window and its message pump
belong to the video thread, so the main thread's synchronous key table
is never advanced and GetKeyState reports every lock as clear.

That made keyboard_init() record all three locks as off, and every
subsequent set saw status 0 and fired keybd_event to toggle a lock that
was already lit. keyboard_free() then "restored" all of them to off.

Take the lock state from the mask win32_update_keyboard_mods()
publishes from the owning thread, which is correct in both video
threading configurations.

The mask advances when the window procedure sees a key event, so a lock
changed while RetroArch is not focused is still not observed until the
next key reaches the window. That is a smaller window than before and
matches what the rest of the Win32 input path already assumes.
2026-09-01 05:11:39 +02:00
LibretroAdmin a872dc1135 led/win32: mask GetKeyState to the toggle bit
keyboard_led() tested the whole GetKeyState return for truth. A lock key
that is physically held reads as 0xFF80 or 0xFF81, which is truthy even
when the lock itself is off, so the initial state captured at
keyboard_init() could be recorded as lit for a key whose LED was dark -
and then "restored" to on at deinit. The same conflation misfires on
every subsequent set, since state and status are compared as booleans.

Mask to bit 0, which is the documented toggle bit.
2026-09-01 04:49:54 +02:00
LibretroAdmin b9be38fd55 strl: copy string literals without scanning them at runtime
strlcpy() begins with strlen() of its source. It lives in another
translation unit, so with no LTO that scan happens at runtime even when
the source is a literal whose length the compiler already measured, and
the call itself cannot be folded away either.

strlcpy_lit() passes the length over as sizeof(). When the destination
size is also a constant -- sizeof(buf), the usual case -- nothing is
left but the stores memcpy() compiles to:

  strlcpy      "core_options"  sizeof(buf)   7.01 ns
  strlcpy_lit  "core_options"  sizeof(buf)   0.42 ns
  strlcpy      41-char literal sizeof(buf)   7.74 ns
  strlcpy_lit  41-char literal sizeof(buf)   0.71 ns
  strlcpy      "core_options"  runtime len   7.11 ns
  strlcpy_lit  "core_options"  runtime len   0.70 ns

The destination bound is kept. When the literal does not fit it defers
to strlcpy(), so the copy truncates as before rather than overrunning;
a form that took only the literal would have turned every one of these
sites into an overflow waiting for a small buffer. The literal is
concatenated with "" so a non-literal source is a compile error rather
than a sizeof() that silently measures a pointer.

818 sites across 104 files were converted by parsing arguments rather
than by pattern-matching text: only a three-argument call whose second
argument is a bare string literal is rewritten, so a macro that happens
to expand to a literal is left alone. Line endings are preserved, so
the CRLF files carry only their own changed lines.

test/compat/test_strl.c compares the two against each other over every
destination size from 0 past the literal's length, for literals that
are empty, single-character, path-shaped, adjacently concatenated and
escape-bearing, checking the return, the terminator and the whole
buffer so an overrun past the terminator is caught. ASan+UBSan+LSan and
TSan both 4/4. The full menu_displaylist_build_list walk over every
displaylist type is byte-identical to before the change
(md5 a2a081bcac09cdc8d72d67efd14ac40e).
2026-08-30 02:10:20 +02:00
U-DESKTOP-SPFP6AQ\twistedtechre ca8871c4a2 Replace string_is_equal with memcmp where possible 2026-04-02 18:18:55 +02:00
sonninnos b2ca569521 Logging unification cleanups 2025-07-10 05:59:06 +03:00
libretroadmin 7ebab640d7 Cleanups/style nits 2023-02-23 13:15:14 +01:00
zoltanvb f56cbd847d LED driver for Linux /sys/class/leds (#14981)
New driver for controlling system LEDs offered via /sys/class/leds.
Currently it handles led0, led1 etc. type of entries, which are
present on e.g. Raspberry Pi's.
2023-02-14 23:00:35 +01:00
libretroadmin 01c3684b10 Cleanups - try to remove stdio.h include where possible 2023-01-21 22:25:38 +01:00
libretroadmin 8a3686df58 Revert "Header cleanups - don't include retroarch.h everywhere"
This reverts commit 0e3b478f8c.
2023-01-08 09:05:46 +01:00
libretroadmin 0e3b478f8c Header cleanups - don't include retroarch.h everywhere 2023-01-08 08:56:57 +01:00
LibretroAdmin 0e5b2ff280 (LED drivers) Miscellaneous cleanups 2022-08-23 08:11:22 +02:00
LibretroAdmin 491cf7f2b4 Merge pull request #14010 from sonninnos/x11-led-keyboard
(X11) Add LED keyboard driver
2022-06-07 02:39:20 +01:00
Tony Jansson a8cff31420 (X11) Add LED keyboard driver 2022-06-05 08:27:41 +03:00
sonninnos 38f258c504 (WIN32) LED keyboard driver cleanup 2022-06-05 08:26:49 +03:00
twinaphex bfeffb2423 Fix local header path includes 2021-12-04 16:11:02 +01:00
Tony 09880e92d2 Logging cleanups (#13320) 2021-12-04 14:21:12 +01:00
sonninnos 054bf115ac LED win32 keyboard driver cleanup 2021-01-02 05:46:04 +02:00
twinaphex 4bdd0ac697 Uniquely name static globals 2020-09-22 03:05:58 +02:00
twinaphex 2e79940ec5 Rename led_keyboard.c to led_win32_keyboard.c - add it to Griffin
- only include it for Win32 (no Xbox or UWP)
2020-09-21 22:01:26 +02:00
Tony Jansson 82a0f647ff Keyboard LED driver 2020-09-21 17:25:11 +03:00
twinaphex 5166eebcaf for loop cleanups - use space after 'for' 2020-08-19 03:06:22 +02:00
twinaphex 2ecb6e654e Cleanups 2020-07-20 20:22:13 +02:00
twinaphex 3b2a3c1277 (led_driver) Take out settings_t dependency
(menu cbs sublabel) Add HAVE_MATERIALUI ifdefs
2020-02-14 14:05:35 +01:00
twinaphex 641662d77c Remove led_null.c 2020-01-06 16:29:25 +01:00
twinaphex 2ad394148a Revert "Remove led_null.c"
This reverts commit bef72a19d0.
2020-01-06 16:22:11 +01:00
twinaphex bef72a19d0 Remove led_null.c 2020-01-06 16:01:05 +01:00
twinaphex ee3208ac39 Integrate video_driver.c into retroarch.c 2019-06-17 15:10:22 +02:00
orbea 28ff4b391a Clean up white space. 2019-02-03 16:00:50 -08:00
orbea bfc366decc Squeeze extra blank lines with cat(1).
Example:

find . -type f -iname '*.c' | while read -r i; do
  cat -s "$i" > "$i.new"
  mv "$i.new" "$i"
done
2019-01-08 11:04:58 -08:00
orbea 58fa3bc940 Attempt to fix xcode8 travis build failure. 2019-01-06 22:47:03 -08:00
meepingsnesroms 74c8506391 Add frontend, battery level and memory amount detection to 3ds port
Also fix white spaces in led drivers, make led drivers use standard driver format.
Begin work on translation driver.
Add salamander files to gitignore.
2018-01-10 16:52:32 -08:00
twinaphex f677a7ad7e Add HAVE_OVERLAY to qb system 2018-01-05 16:10:34 +01:00
twinaphex 08abfd9208 (LED) Fix relative path includes 2018-01-05 13:47:49 +01:00
twinaphex f9e4ff3610 Cleanups 2018-01-05 13:28:50 +01:00
twinaphex a516a0a3a3 Add overlay_led_driver 2018-01-05 13:27:52 +01:00
Ian House 5311544c65 Added overlay led driver, fixed a bug in the rpi led driver 2018-01-04 12:56:57 -05:00
twinaphex 481a140c9c Buildfixes 2017-12-30 13:45:29 +01:00
twinaphex 292d506ed8 Fix more MSVC Griffin build errors 2017-12-30 13:35:47 +01:00
twinaphex 56b4d4917c One CXX_BUILD buildfix 2017-12-27 22:21:39 +01:00
twinaphex eb62b610cb (LED code) Cleanups 2017-12-27 21:17:47 +01:00
Ian House aa7c289708 Added an LED interface and a Raspberry Pi GPIO implementation 2017-12-27 11:11:08 -05:00