decompile_dosHow 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.
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.
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++.
Natural Language Agent Instructions
Copy and paste this prompt directly into your AI coding agent when REA is registered via Model Context Protocol (MCP):
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.Run REA Analysis Command
Execute the following command in your terminal or inspect the MCP JSON-RPC call executed by your agent:
rea decompile ./game.exe 0x2000:0x0410 --provider ghidra --jsonWhat REA Extracts & Returns
Reconstructed 16-Bit Trigonometric Bullet Ring (C++)
The verified findings and synthesized clean-room structures generated from this investigation:
// 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);
}
}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.