How it works
From a 16-bit DOS program to a .NET application, one function at a time.
From CIV.EXE to C#
Every function of the original CIV.EXE was translated into a C# method. At first the translation
followed the machine code closely: registers, the stack and memory addresses, all kept as they were. Step by step
that code was rewritten into ordinary C#, with names, parameters and return values, while tests checked that the
game still behaved exactly like the first translation.
Some places still read the game's memory by address. That memory is an emulated 8086 machine: the game's data, the saved game and the tables of the original live there, and the game reads them the way the original did.
Pictures, sound and data
Pictures, palettes, fonts and texts come from the files of your copy of the game. The data of the program itself
is unpacked from the original CIV.EXE at startup. Sound drivers of the original run in a small machine
code interpreter, which drives an emulated AdLib synthesizer or translates Roland MT-32 music to General MIDI.
Projects
| Project | What it holds |
|---|---|
Machine | The emulated processor, memory and the C runtime of the original |
Imaging | Screens, pictures and fonts |
Acoustics | Sound drivers and synthesizers |
Foundation | Streams, compression, randomness, logging |
GameModel | Game state and rules |
Core.Shared | Service interfaces, game memory, tables and texts |
Core.Engine | Drawing, sessions and platform services |
Core.Game | The game logic |
Core.UI | The game screens |
Core | GameEngine, which puts the services together |
Desktop | The Avalonia window |
Tests | Tests, one folder per project |
Tests
The tests play turns of saved games without a window and compare the result with recordings of the first translation. A call journal records which functions the game called and with what, so a rewrite that changes the behaviour shows up as a difference. Without a window time does not pass, so the test clock ticks with the game's own memory reads and every run is the same.
History
The repository keeps every change with its date, but only the latest commits build: files that are no longer part
of the project were removed from the whole history. To build and play, use the tip of main.