<!-- Canonical page: https://reversedwithai.com/p/rea-th04-bullet-patterns -->
Canonical page: https://reversedwithai.com/p/rea-th04-bullet-patterns

# Recovered Touhou 4's bullet-ring logic from its PC-98 DOS binary with REA

> Touhou 4's aimed bullet rings, recovered as C++ that matches the original bytes.

An agent used REA to analyse TH04's 16-bit MAIN.EXE and recover the aimed bullet-ring angle maths as C++; compiler checks match 2,139 bytes of the original as part of a full source reconstruction.

## Key facts

- Target: Touhou 4: Lotus Land Story
- Category: Games and mods
- Platform: PC-98 (DOS)
- Tools: REA
- Outcome: Partial
- License: MIT
- Checks: Source available: yes; Repro steps: yes; Real hardware: not reported; Verified by others: not reported
- Author: [N0zoM1z0](https://github.com/N0zoM1z0)
- Added: 2026-10-14
- Updated: 2026-10-14
- Sources reviewed: 2026-10-14 (editor)

## What was done

N0zoM1z0's TH04 project reconstructs the Japanese PC-98 game Touhou 4: Lotus Land Story as maintained C++ and assembly, with a C++17 port for Windows and Linux that runs without a DOS emulator. An REA case study shows an agent reading the 16-bit MAIN.EXE to explain how aimed bullet rings are calculated, and compiler checks show the bullet-generation code matching a 2,139-byte section of the original.

### What REA recovered

The example prompt asks the agent to find how TH04 creates a ring of bullets and aims it at the player. REA first verified the DOS load image against the supplied executable, then returned instructions and pseudocode for bullet_velocity_and_angle_set(). The code multiplies the bullet index by 256 and divides by the ring count, subtracts to form player-minus-origin coordinates, calls a direction helper, and adds the template rotation stored in one byte. The case study maps each step to the maintained C++, which uses iatan2. TH04 stores a full turn in 256 angle units, so a 16-bullet ring places bullets 16 units apart. Elly's attack requests an aimed ring with a count of 16.

### Build and checks

The DOS reconstruction on the main branch builds with pinned Turbo C++ 4.0J, TASM and TLINK under Wine, and uses the community ReC98 project as a migration input and validation reference. All four DOS executables build from maintained source. The README reports original and rebuilt runs agreeing on input, score, RNG and many state blocks across four bundled demos; full Boss defeat, process transitions and physical scanout timing remain open.

### Playing the port

A Windows x64 portable preview on the releases page supports Normal, Extra, Music Room, endings and saves, with sound. You need your own Japanese full-version game files (MAIN.EXE, the ED data file and the main data file, checked by hash). A bundled Python script builds a disk image from them, plus a font and sound data file, in one step. No game data is shipped. The portable source is on the port/modern-64 branch, with a Linux x86-64 build using CMake and SDL2.

### How AI was used

The README says the reconstruction was built with AI coding agents and invites contributions. It names no model. The REA case study shows REA being used by an agent for inspection.

Sources:
- https://github.com/N0zoM1z0/th04
- https://rea.tools/showcase/th04/

## What the commit history shows

None of the 1,189 commits in the public repository credits an AI. Many tools add no credit, so this does not show the AI was not used.

Measured by this site from public git history.

## Sources

- [Repository](https://github.com/N0zoM1z0/th04)
- [Write-up](https://rea.tools/showcase/th04/)

Figures are reported by the author and not measured by this site, except the commit history. Entry drafted with AI from the linked sources and checked against them.

Cite as: N0zoM1z0 (2026). Recovered Touhou 4's bullet-ring logic from its PC-98 DOS binary with REA. Reversed with AI. https://reversedwithai.com/p/rea-th04-bullet-patterns
