Gl0w1amp 2c2b8b11b4 Fix mai2 memory leak via LED 15070 rate-limiting and enhance touch handling (#101)
## Overview
This PR addresses the severe memory leak and performance issues observed in `mai2`, while also introducing improvements to the touch emulation logic.

## Root Cause Analysis
As discussed previously, the root cause of the `mai2` memory leak is not a global `segatools` buffer bug. Instead, the game aggressively spams overlapped empty reads specifically on the `LED 15070` UART. On real hardware, the serial driver naturally throttles this. Under emulation, without a throttle, it hits approximately **260kHz of empty async reads**, which causes the memory usage to explode.

## The Fix
Instead of introducing complex locking mechanisms and condition variables globally in `uart.c`, this PR applies a targeted fix:
* Added a local `Sleep(1)` directly in `common/board/led15070.c` to rate-limit empty reads on the LED path.
* Because this is isolated to LED communications, it completely resolves the memory leak without introducing any lag, livelocks, or overhead to other critical inputs.

## Additional Changes in this PR
Alongside the memory leak fix, this PR includes a few touch-related improvements (as touch emulation was reviewed during the debugging process):
* Enhanced touch input handling and improved auto-scan state management.
* Implemented IOCTL handling for touch input to properly manage communication status.

## Testing
* **mai2:** Tested successfully on multiple machines. The memory leak is completely gone, and the game runs smoothly.
* **chusan:** Tested to ensure no regressions. Sliders and inputs work flawlessly without the lag.

Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/101
Co-authored-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe>
Co-committed-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe>
2026-04-03 15:13:27 +00:00
2021-08-15 11:11:06 +02:00
2023-09-19 10:33:30 -04:00
2026-02-26 23:26:51 +01:00
2019-11-06 21:02:49 -05:00
2026-03-09 21:13:27 +01:00
2024-12-16 11:09:38 +08:00
2018-10-07 21:58:14 -04:00
2021-12-27 20:56:30 -05:00
2023-04-23 16:13:51 +02:00
2023-02-13 03:08:41 -05:00
2019-11-06 21:02:49 -05:00
2021-12-27 20:55:20 -05:00
2025-04-17 19:40:40 +02:00
2026-02-26 23:26:51 +01:00

Segatools

Version: 2026-02-26

Loaders and hardware emulators for SEGA games that run on the Nu and ALLS platforms.

List of supported games

  • ALL.Net P-ras MULTI Version 3
    • starting from ALL.Net P-ras MULTI Version 3 1.01
  • Card Maker
    • starting from Card Maker
  • CHUNITHM
  • crossbeats REV.
    • up to crossbeats REV. SUNRISE
  • Eiketsu Taisen (英傑大戦)
    • starting from Sanzensekai no Hadou (三千世界の波動)
  • Fate/Grand Order
    • Fate/Grand Order Arcade
  • Hatsune Miku: Project DIVA Arcade
    • up to Future Tone
  • Initial D
  • Kemono Friends
    • Kemono Friends 3: Planet Tours
  • maimai DX
    • starting from maimai DX
  • Mario & Sonic
    • Mario & Sonic at the Tokyo 2020 Olympics Arcade
  • O.N.G.E.K.I.
    • starting from O.N.G.E.K.I.
  • Sangokushi Taisen (三国志大戦)
    • starting from 1.01
  • SEGA World Drivers Championship
    • SEGA World Drivers Championship 2019
  • WACCA
    • starting from WACCA

End-users

For setup and configuration guides, refer to the dedicated documents available for each game, see the links in the previous section.

Contributors

If you are/want to be a contributor of any kind, e.g. new features, bug fixes, documentation improvements, ..., please read the contributing documentation, first.

Developers

For development setup and instructions how to build the project, refer to the dedicated development documentation.

S
Description
No description provided
Readme Unlicense
3.8 MiB
Languages
C 96.6%
Meson 1.8%
Makefile 0.8%
Python 0.3%
Batchfile 0.2%
Other 0.2%