Games & PackagedEnvironment: NSA Ghidra with ghidra-dos extension module installedMCP Tool: decompile_dos

How to REA 16-Bit DOS & Retro Binaries: PC-98 Segmented Code & Ghidra DOS

Decompile vintage 16-bit real-mode x86 executables (NEC PC-98, MS-DOS): parse segmented memory models (CS:IP, DS, ES), recover fixed-point mathematical algorithms, and synthesize verified modern C/C++ replacements.

AI Overview Direct AnswerHow to REA: 16-Bit DOS & Retro Binaries (PC-98 / MS-DOS) Quickstart Summary

In this official REA guide for 16-Bit DOS & Retro Binaries (PC-98 / MS-DOS), AI coding agents (Claude Code, Cursor, Windsurf) execute 'rea decompile ./game.exe 0x2000:0x0410 --provider ghidra --json' to safely extract file layout, symbols, and code logic without launching unverified binaries.

Investigation ScenarioReal-World Objective

The Problem & Target Artifact

Retro game preservation and algorithmic archaeology: You are analyzing a classic 1990s PC-98 game (e.g. Touhou 04). You need to reverse engineer its bullet-ring angle calculation and reconstruct the exact mathematical formula into modern C++.

Target Artifact: 16-bit DOS executable (.exe with MZ header, or .com flat binary).
AI PromptClaude Code / Cursor / Windsurf

Natural Language Agent Instructions

Copy and paste this prompt directly into your AI coding agent when REA is registered via Model Context Protocol (MCP):

Prompt Template:Select All to Copy
Decompile the segmented routine at 0x2000:0x0410 in ./th04.exe using Ghidra. Recover the fixed-point angle calculations and compare the reconstructed C++ with historical compiler output.
ExecutionTerminal & MCP Tool Call

Run REA Analysis Command

Execute the following command in your terminal or inspect the MCP JSON-RPC call executed by your agent:

CLI Command Execution
rea decompile ./game.exe 0x2000:0x0410 --provider ghidra --json

What REA Extracts & Returns

16-bit MZ executable header parsing: initial CS:IP, relocation table pointers, and memory requirements
Real-mode segmented memory addressing resolution (Segment:Offset to linear physical address)
Disassembly of 16-bit instructions: mov ax, dx, sub ax, cx, and fixed-point lookup table indexes
Standalone modern C++ algorithmic reconstruction matching compiled binary byte-for-byte

Reconstructed 16-Bit Trigonometric Bullet Ring (C++)

The verified findings and synthesized clean-room structures generated from this investigation:

Reconstructed 16-Bit Trigonometric Bullet Ring (C++)
// Verified C++ reconstruction of 16-bit PC-98 bullet ring calculation
void calculate_bullet_ring(int center_x, int center_y, int count, int base_angle) {
    for (int i = 0; i < count; ++i) {
        int angle = (base_angle + (i * 256 / count)) & 0xFF;
        int dx = costable[angle] * 4;
        int dy = sintable[angle] * 4;
        spawn_bullet(center_x + dx, center_y + dy, angle);
    }
}
Internal MechanicsProduction Engineering

Segmented Architecture & Fixed-Point Sleigh Modeling

16-bit real-mode code uses 20-bit physical addressing computed as `(Segment * 16) + Offset`. Modern decompilers fail because they assume flat 32/64-bit address spaces. REA bridges to Ghidra's `ghidra-dos` module, configuring the Sleigh processor spec with segment registers (CS, DS, ES, SS) to decompile segmented calls and far pointers cleanly.

Security Guardrails & Analysis Boundary Rules

Resolves far calls (CALL FAR) and inter-segment jumps without losing register context.
Accurately models 16-bit integer overflow and wrap-around semantics in generated C code.
Recovers historical compiler artifacts (Borland Turbo C++, Microsoft C 6.0 conventions).