Sid Meier's Civilization (civd)
Sid Meier's Civilization
About the project
Sid Meier's Civilization o Civilization I es un videojuego de estrategia por turnos creado por Sid Meier y publicado por MicroProse en 1991 para las plataformas MS-DOS, Microsoft Windows, Apple Macintosh, Commodore Amiga, Atari ST y Super NES.
Official project information
Sid Meier's Civilization
Reverse-engineered source code for the MS-DOS version of the 1991 game "Sid Meier's Civilization".
Technical book · Reading Civilization from the inside
[!WARNING] This is a reconstruction, not MicroProse's original source. Names, comments and some type declarations are inferred. An exact executable match does not prove that these match the original source.
The reconstructed C code is built with what I believe to be the original toolchain: Microsoft C 5.1, MASM 5.10 and LINK 5.01. The
resulting CIV.EXE matches version 474.05 byte for byte.
The original game was very well architected and includes separate drivers for video and audio, along with some utilities in MISC.EXE. I haven't reversed these elements to C code - my interest is only in the game logic. But the MCGA graphics driver, AdLib sound driver and
MISC.EXE have all been decompiled to assembly to make it a little easier to understand calls into them.
The build applies a four-byte startup correction, described in the build notes, which I believe is historically accurate; on the basis that I couldn't reproduce it any other way!
Other releases are kept on release/* branches; see
version differences.
See also:
- reciv which rebuilds the game for modern platforms based on this code.
- civfanatics discussion including some discussion of the process and notes from rhorvat/mghandi14, author of OpenCivOne.
AI and credit
The project used LLMs from OpenAI, Anthropic and Google for code and documentation, followed by editing and build verification.
It builds on earlier decompilation work, particularly OpenCiv1.
Contributing
I think this is pretty comprehensive however:
- it's possible that some of the assembly sections I (or the LLMS) have identified as hand coded could actually be reversed
- names may not be semantically correct or could be improved.
- Documentation can usually be improved.
Pull requests are welcome.
Documentation
- The technical book explains the game systems.
- The Docco story, Reading Civilization from the inside, follows complete source files with commentary beside the code.
To build locally, run just book and, after npm ci, just story.
Open build/book/index.html or build/story/index.html.
The book's sources are in book/; the story's are in story/.
The build workflow publishes both to GitHub Pages
after checks pass on main. Pull requests build and check the documentation
without deploying it.
Building
Microsoft MAKE 4.07 builds the source C and assembler files with Microsoft C 5.1, MASM 5.10 and LINK 5.01.
You can run the tools inside DOSBox-X. Mount the tools as C: and src/ as D:, then run make MAKEFILE in D:. Objects, listings and logs are written beside the
sources (ignored by git):
dosbox-x -conf dosbox.conf -c 'mount c build/period-tools' \
-c 'mount d src' -c 'd:' -c 'set PATH=C:\BIN;Z:\' -c 'set INCLUDE=C:\INCLUDE'
Devcontainer
Install Docker and open this repository in VS Code with the Dev Containers extension. Run Dev Containers: Reopen in Container.
The devcontainer installs the build dependencies. On first creation it downloads the Microsoft C 5.1 disk images from WinWorld, fetches MASM from Microsoft's MS-DOS repository, installs and checks the period tools, verifies the executable, and builds the book. The Dockerfile lists and links the host dependencies.
Downloads stay in the ignored data/ directory; installed tools go into
build/period-tools/. The archive checksum and
installed-tool hashes are checked before use.
If you already have the compiler disk images, just setup "path/to/images"
uses your local copies.
The original game is not needed to build. Verification uses the pinned SHA-256 hashes in civ.sha256.
Continuous integration
The GitHub build workflow uses the same Dockerfile on pushes and pull requests. It downloads and installs the tools, checks source formatting, runs the complete executable verification, and builds the book and story. Build logs are retained as workflow artifacts.
Commands
just setup # once: download missing images, install the period tools and check them
just build # lint, compile and build the book
just compile # incremental: MAKE rebuilds changed sources in build/dos/
just verify # clean compile, then require the original raw LINK output and CIV.EXE
just clean # delete build/dos/ and build/book/ (installed tools are kept)
just fmt # format src/*.C and src/*.H with GNU indent (.indent.pro)
just lint # check indent style and CRLF endings without changing files
just book # build the mdBook into build/book/
just serve-book # serve the mdBook with live reload
just story # build the Docco story (run npm ci once first)
just verify checks a clean build against the pinned hashes. Run npm ci
once before just story.
Repository map
src/ DOS C/MASM source, MAKEFILE and LINK.RSP
.devcontainer/ Build environment and automatic first-time setup
.github/ Build and verification workflow
tools/ Compiler download script and Docco story builder
justfile Host commands: setup, build, compile, verify, clean, fmt, lint, book
dosbox.conf DOSBox-X configuration for setup and compile
*.sha256 Pinned installed-tool and output hashes
book/ mdBook on the game's architecture and design
story/ Narrative commentary and current source includes for Docco