Loaders and hardware emulators for SEGA games that run on the Nu and ALLS platforms https://github.com/djhackersdev/segatools
Go to file
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
.gitlab Simplified bug reporting template 2021-08-15 11:11:06 +02:00
.vscode update gitignore 2023-09-19 10:33:30 -04:00
common Fix mai2 memory leak via LED 15070 rate-limiting and enhance touch handling (#101) 2026-04-03 15:13:27 +00:00
dist ekt: add gfx hook, misc: bugfixes 2026-02-26 23:26:51 +01:00
doc doc: region improvements and vfs corrected 2026-03-24 22:10:27 +01:00
emoney emoney: improce doc and add python script 2025-04-17 19:17:42 +02:00
games Fix mai2 memory leak via LED 15070 rate-limiting and enhance touch handling (#101) 2026-04-03 15:13:27 +00:00
pki Add reference PKI 2019-11-06 21:02:49 -05:00
spike Add Chunithm Star Plus WinHTTP debug printfs 2018-11-28 11:49:16 -05:00
subprojects bump capnhook rev 2026-03-09 21:13:27 +01:00
.clang-format add changeable config path 2024-12-16 11:09:38 +08:00
.dockerignore Extend .dockerignore, ignore git related stuff 2021-05-28 20:55:47 +02:00
.editorconfig Add .editorconfig 2018-10-07 21:58:14 -04:00
.gitignore Add support for Sangokushi Taisen and Eiketsu Taisen (#85) 2026-02-26 19:31:45 +00:00
CHANGELOG.md Update CHANGELOG 2021-12-27 20:56:30 -05:00
CONTRIBUTING.md Add section about git history to contributing docs 2021-08-13 23:55:12 +02:00
cross-mingw-32.txt build: don't hardcode cross-toolchain path 2019-11-09 13:42:15 +00:00
cross-mingw-64.txt build: don't hardcode cross-toolchain path 2019-11-09 13:42:15 +00:00
docker-build.bat idac: test 2023-04-23 16:13:51 +02:00
Dockerfile update docker build system 2023-02-13 03:08:41 -05:00
initpki Add reference PKI 2019-11-06 21:02:49 -05:00
LICENSE Add the Unlicense to the repository 2021-12-27 20:55:20 -05:00
Makefile refactor all common parts and games 2025-04-17 19:40:40 +02:00
meson_options.txt Vfs: Add ability to redirect arbitary paths (= serial ports) (#62) 2026-02-08 11:12:02 +00:00
meson.build Add support for Sangokushi Taisen and Eiketsu Taisen (#85) 2026-02-26 19:31:45 +00:00
msvc-build.bat refactor all common parts and games 2025-04-17 19:40:40 +02:00
Package.mk ekt: add gfx hook, misc: bugfixes 2026-02-26 23:26:51 +01:00
package.ps1 refactor all common parts and games 2025-04-17 19:40:40 +02:00
README.md Add support for Sangokushi Taisen and Eiketsu Taisen (#85) 2026-02-26 19:31:45 +00: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.