ReC98
The Touhou PC-98 Restoration Project
Install / Use
/learn @nmlgc/ReC98README
The Touhou PC-98 Restoration Project ("ReC98")
| Reverse-engineered: |
|
|-----------------------:|:---------------|
| Finalized: |
|
| Position independence: |
|
Check the homepage for more detailed progress numbers and information about the crowdfunding!
Overview
This project aims to perfectly reconstruct the source code of the first five Touhou Project games by ZUN Soft (now Team Shanghai Alice), which were originally released exclusively for the NEC PC-9801 system.
The original games in question are:
- TH01: 東方靈異伝 ~ The Highly Responsive to Prayers (1997)
- TH02: 東方封魔録 ~ the Story of Eastern Wonderland (1997)
- TH03: 東方夢時空 ~ Phantasmagoria of Dim.Dream (1997)
- TH04: 東方幻想郷 ~ Lotus Land Story (1998)
- TH05: 東方怪綺談 ~ Mystic Square (1998)
Since we only have the binaries, we obviously can't know how ZUN named any variables and functions, and which comments the original code was surrounded with. Perfect therefore means that the binaries compiled from the code in the ReC98 repository are [indistinguishable] from ZUN's original builds, making it impossible to disprove that the original code couldn't have looked like this. This property is maintained for every Git commit along the way.
Aside from the preservation angle and the resulting deep insight into the games' mechanics, the code can then serve as the foundation for any type of mod, or any port to non-PC-98 platforms, developed by the community. This is also why ReC98 values readable and understandable code over a pure decompilation.
Why?
There are several why achieving moddability via full decompilation seems to be more worthwhile for the PC-98 games, in contrast to a PyTouhou-style black-box reimplementation:
- While stage enemies and their bullet patterns are controlled by bytecode in TH04's and TH05's .STD files that could just be interpreted by an alternate VM, midboss and boss battles are entirely hardcoded into the executables.
- Even though complete decompilation will take a long time, partial reverse-engineering results will be very useful to modders who just want to work on the original PC-98 versions of the games.
- PC-98 emulation is messy and overly complicated. It has been getting better as of 2018 thanks to DOSBox-X adding support for the platform, but even at its best, it will always consume way more system resources than what would be appropriate for those games.
- thcrap-style multilingual translation on PC-98 would be painful for languages with non-ASCII scripts. The obvious method of modifying the font ROM specifically for each language is ugly and won't work on real hardware, so a custom renderer would be needed. That by itself requires a lot of reverse-engineering and, preferably, compilable source code to avoid the limits of hex-editing. Or, even better, the prospect of doing this entirely on a more modern system.
- These games stopped being sold in 2002, ZUN has confirmed on multiple occasions to have lost all the data of the "earlier games" <sup>[citation needed]</sup>, and PC-98 hardware is long obsolete. In short, these games are as abandoned as they can possibly be, and are unlikely to ever turn a profit again.
Is this even viable?
Ever since crowdfunding has brought a continuous stream of support, progress has been steady. Decompilation of TH01 fully completed in August 2022, and the remaining games are only a matter of time.
Over the years, this project led to a deep understanding of the original compilers and PC-98 hardware, to the point where the decompilation itself has become pretty mechanical. To ensure that this project remains both worthwhile to support and interesting to work on, its focus has shifted more toward meticulous documentation and review of ZUN's original code. The [project blog] details all the findings in a more generally readable way and has arguably become the main attraction, with the source code reconstruction itself almost turning into a byproduct of the underlying deep research into these games.
The project started out pretty viable as well. During the development of the static English patches for these games, we identified two main libraries used across all 5 games, and even found their source code. These are:
- master.lib, a 16-bit x86 assembly library providing an abstraction layer for all components of a PC-98 DOS system
- as well as the Borland C/C++ runtime library, version 4.0.
- Additionally, TH01 includes the Pi loader library by 電脳科学研究所/BERO,
- and TH03's
ZUNSP.COM(accessible viaZUN.COM -4) is a rebranded version of Promisence Soft'sSPRITE16.COM, a 16-color PC-98 EGC display driver, version 0.04, which was bundled with the sample game StormySpace.
master.lib and the C/C++ runtime alone make up a sizable amount of the code in all the executables. In TH05, for example, they amount to 74% of all code in OP.EXE, and 40% of all code in MAIN.EXE. That's already quite a lot of code we do not have to deal with. Identifying the rest of the code shared across the games will further reduce the workload to a more acceptable amount.
With DOSBox-X and the Debug edition of Neko Project II, we also have two open-source PC-9821 emulators capable of running the games. These have helped to answer most hardware-related questions, together with old books about PC-98 development and occasional tests on real hardware.
Dumped executables
- TH01:
zunsoft.com,op.exe,reiiden.exe,fuuin.exe - TH02: zun.com (<s>
ongchk.com</s>,zuninit.com,zun_res.com, <s>zunsoft.com</s>),op.exe,main.exe,maine.exe - TH03: zun.com (<s>
ongchk.com</s> [-1], <s>zuninit.com</s> [-2], <s>zunsoft.com</s> [-3],zunsp.com[-4],res_yume.com[-5]),op.exe,main.exe,mainl.exe - TH04: zun.com (<s>
ongchk.com</s> [-O],zuninit.com[-I],res_huma.com[-S],memchk.com[-M]),op.exe,main.exe,maine.exe - TH05: zun.com (<s>
ongchk.com</s> [-O],zuninit.com[-I],res_kso.com[-S],gjinit.com[-G],memchk.com[-M]),op.exe,main.exe,maine.exe
Crossed-out files are identical to their version in the previous game. ONGCHK.COM is part of the PMD sound driver by KAJA, and therefore doesn't need to be disassembled either; we only need to keep the binary to allow bit-perfect rebuilds of ZUN.COM.
This project does not include any asset data from the original PC-98 releases. Running the compiled executables will still require an existing copy of the original games.
Branches
-
▶
master: ZUN's original code, without mods or bugfixes (You are here!) -
[
debloated]: Rearchitected version of ZUN's code that is easier to read and modify, and builds smaller and faster PC-98 binaries. Only removes [bloat] and [landmines]; all [bugs] and [quirks] from ZUN's original code are left in place. Ports should start from that branch, and it's also the recommended base for mods that don't care about similarity to the original binary.This branch also includes the patches from [
th03_no_gdc_frequency_check] and [th04_noems_crash_fix], as these issues are classified as landmines. -
[
anniversary]: Takesdebloatedand additionally fixes [bugs], achieving a smoother and flicker-free gameplay experience on the PC-98 platform while still leaving [quirks] in place. Might be an even better starting port for mods and ports. -
[
BossRush] -
[
th03_no_gdc_frequency_check]: Allows TH03 to be run with the GDC clock set to 5 MHz. The original game enforces 2.5 MHz, but doesn't functionally require it, even on real hardware. -
[
xJeePx]: Code changes for xJeePx's 2014 English translation patch. -
[
th01_critical_fixes]: Fixes [two critical bugs in TH01]:- Potential heap corruptions in the game's debug mode when decrementing boss HP by holding ↵ Return while the HP bar is still filling up.
- General Protection Faults when defeating bosses with diagonally moving shootout lasers on screen. These are most commonly reported for Elis or Mima, and when playing on real hardware or Anex86.
-
[
th01_end_pic_optimize]: Speeds up image blitting in TH01's cutscenes to 50% of the original runtime. Mainly serves as an example of how to get close to optimal EGC-powered blitting code out of Turbo C++ 4.0J without writing a single ASM instruction; the EGC is definitely not the best tool for this job. -
[
th01_orb_debug]: Shows the following information in TH01's debug mode:- Physics values for the Yin-Yang Orb at the b
Related Skills
node-connect
338.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.6kCommit, push, and open a PR
