rea.run

← Showcase

case-study 2026-10-13 gamereconstructioncommunity

How TH04 aims a ring of bullets

A ring of bullets starts as a short angle calculation. TH04 stores one clockwise turn in 256 angle units. For 16 bullets each index adds 16 units: 0, 16, 32, …, 240. Adding the player’s direction rotates the whole ring together. REA reads that helper from the DOS executable; the MIT reconstruction supplies the maintained C++ and the compiler checks. The figure above draws count 16, player direction 40, and template rotation 0.

Source meta

16 GitHub stars (snapshot)

Language: Python

License: MIT

Updated: 2026-10-10

GitHub source ↗

rea.run rating

5/5 — Bullet ring checked in bytes

Quality. DOS helper, readable C++, and a compiler match on the bullet-add section.

Evidence. Verified DOS MZ image, aim sequence, 2,139 matching bytes.

Limits. Historical reconstruction. Not a modern DRM-strip guide.

For. Readers of PC-98 bullet code and the open TH04 reconstruction.

Aimed ring of 16 bullets: index spaced by 16 angle units, plus player direction 40.
Aimed ring of 16 bullets: index spaced by 16 angle units, plus player direction 40.

The firing template

Elly’s attack asks for an aimed ring whose initial count is 16. The same helper can also face a fixed direction. These lines select the pattern before difficulty tuning:

bullet_template.angle = 0;
bullet_template.group = BG_RING_AIMED;
bullet_template.count = 16;
bullet_template_tune();
Use REA to find how TH04 creates a ring of bullets and aims it at the player. Explain the calculation and show the code.

The function under inspection is bullet_velocity_and_angle_set(), which sets each bullet’s velocity and angle. REA returns its instructions, pseudocode, and references. Three slices of that result explain the ring.

Check the DOS image first

Before trusting addresses, confirm the loaded image is the file you opened.

open_binary
{"path": "MAIN.EXE"}

inspect_native_load_image
{}

status: "verified"
format: "dos-mz"
load_segment: 4096
header_bytes: 6144
module_bytes: 150114

Load segment 4096 is 0x1000. Header plus module is 6,144 + 150,114 = 156,258 bytes, the size of this MAIN.EXE. The check ties code and relocation records to that executable. The path above is shortened for display.

Space the ring, then aim

Analyze 0x2cfc8. SI holds the bullet index. SHL AX, 8 multiplies by 256. The count is read from DS:53AF, which the maintained source calls bullet_template.count, zero-extended, and used as the IDIV divisor.

0x2d0eb: MOV AX, SI
0x2d0ed: SHL AX, 0x8
0x2d0f0: MOV DL, byte ptr [0x53af]
0x2d0f9: IDIV BX

For count 16, index 0 stays 0, index 1 becomes 16, index 15 becomes 240. The aim excerpt then subtracts origin from player and calls a direction helper:

0x2d190: SUB AX, word ptr [0x53a6]
0x2d198: SUB AX, word ptr [0x53a4]
0x2d19d: CALLF 0x1000:1da8
0x2d1a2: ADD word ptr [BP + -0x2], AX
group_angle_offset += iatan2(
  player_pos.cur.y - bullet_template.origin.y,
  player_pos.cur.x - bullet_template.origin.x
);

The two subtractions are player-minus-origin coordinates. iatan2 returns an angle in the same 256-unit circle. Adding it turns every bullet in the ring toward the player. Source names make the addresses readable; the instructions are what REA checks them against.

Assembly and a readable summary

This listing is the aimed-ring path: index, spacing, aim, template rotation, and the byte store. The full function also handles spreads, stacks, and random patterns. REA reports 503 body bytes in two ranges across a 517-byte span; the instructions below sit in those ranges. File offset of the helper entry, from address_to_file_offset, is 0x1e7c8.

0x2cfcf: MOV SI, word ptr [BP + 0x4]
0x2d0eb: MOV AX, SI
0x2d0ed: SHL AX, 0x8
0x2d0f0: MOV DL, byte ptr [0x53af]
0x2d0f4: MOV DH, 0x0
0x2d0f6: PUSH DX
0x2d0f7: CWD
0x2d0f8: POP BX
0x2d0f9: IDIV BX
0x2d0fb: MOV word ptr [BP + -0x2], AX
0x2d18d: MOV AX, [0x4650]
0x2d190: SUB AX, word ptr [0x53a6]
0x2d194: PUSH AX
0x2d195: MOV AX, [0x464e]
0x2d198: SUB AX, word ptr [0x53a4]
0x2d19c: PUSH AX
0x2d19d: CALLF 0x1000:1da8
0x2d1a2: ADD word ptr [BP + -0x2], AX
0x2d1b9: MOV AL, byte ptr [BP + -0x2]
0x2d1bc: ADD AL, byte ptr [0x53ad]
0x2d1c0: MOV [0xbcc8], AL
unsigned char aimed_ring_angle(
    int index, int count,
    int player_direction,
    unsigned char rotation)
{
    int angle = index;
    angle = (angle * 256) / count;
    angle += player_direction;
    angle += rotation;
    return (unsigned char)angle;
}
  1. The stack argument lands in SI. In a 16-bullet ring the index runs from 0 through 15.
  2. SHL AX, 8 then IDIV by the count spaces one full turn. Count 16 advances 16 units per index.
  3. Player-minus-origin goes to the direction helper; its AX is added to the relative ring angle.
  4. ADD AL, [0x53ad] adds the template angle. Elly’s initial template sets it to zero.
  5. The store writes AL to the spawn-angle field. Values wrap after 255, matching the unsigned-byte cast. Surrounding code turns that angle plus speed into a velocity.

Maintained source, not only the summary

The C++ above is a reading aid. Compiler checks apply to the maintained source. Ring spacing in that tree:

angle_offset = (i * BULLET_ANGLE_FULL_TURN) / count;
if (i >= (count - 1)) {
    group_complete = true;
}
goto aim_or_no_aim;
aim:
    group_angle_offset += iatan2(
        (player_pos.cur.y - bullet_template.origin.y),
        (player_pos.cur.x - bullet_template.origin.x)
    );

no_aim:
    vector2_near(
        bullet_template.velocity,
        (group_angle_offset + bullet_template.angle),
        speed
    );
    bullet_spawn_angle = (group_angle_offset + bullet_template.angle);

BULLET_ANGLE_FULL_TURN is 256. The no_aim label is how a fixed ring skips iatan2 and still stores bullet_spawn_angle.

2,139 matching bytes

The project’s recorded checks compile the bullet-generation code, including this helper, with the pinned Turbo C++ 4.0J toolchain. The compiled section matches 2,139 bytes of the original executable. Two separate builds produce the same bytes, and the recorded input hashes match the maintained source at checkpoint 0d72e980. Those checks were recorded on 3 October 2026. They cover the whole bullet-add section, its MAP contribution, and an overlapping relocation.

FieldValue
Original targetMAIN.EXE, 156,258 bytes, DOS MZ
Helper entry0x2cfc8 in REA’s loaded image
File offset0x1e7c8
Code inspectionREA 4.1.0 · 7 October 2026

Source names and compiler checks come from that checkpoint. Earlier reconstruction notes used the project’s own scripts; this page adds a fresh REA inspection of the same pinned target. The repository manifest pins which game file was studied. Independent pristine-dump provenance is still open, which is a limit of the identity claim, not of the byte match itself.

The figure illustrates the angle math only. Full-game controls, timing, and PC-98 hardware behavior have their own runtime checks in the reconstruction. Beyond bullet generation, that tree builds the game’s four DOS products and covers stages, bosses, rendering, input, menus, endings, and score handling.

Next step

Similar browser session records can become AgentEnv replay environments

This case is not a claim that it is a specific Hugging Face environment. When REA records an authorized browser session, Scale AgentEnv can expose replay as MCP tools. rea.run mirrors the catalog only — we do not host the RL runtime.

Environments catalog → What is AgentEnv + REA? HF collection ↗ Introducing AgentEnv

Compliance

Historical game reconstruction of mechanics, with compiler checks against a pinned executable. This page does not strip modern DRM or redistribute the original game.

Takeaways

  • One clockwise turn is 256 units; 16 bullets step by 16.
  • Aim is iatan2 of player-minus-origin, added to the whole ring.
  • Verify the DOS MZ image before arguing about addresses.
  • 2,139 matching bytes belong to the maintained bullet-add section, not to a DRM bypass.

Related on rea.run

More on-site cases