Civ 1.5 Remastered

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

ProjectWhat it holds
MachineThe emulated processor, memory and the C runtime of the original
ImagingScreens, pictures and fonts
AcousticsSound drivers and synthesizers
FoundationStreams, compression, randomness, logging
GameModelGame state and rules
Core.SharedService interfaces, game memory, tables and texts
Core.EngineDrawing, sessions and platform services
Core.GameThe game logic
Core.UIThe game screens
CoreGameEngine, which puts the services together
DesktopThe Avalonia window
TestsTests, 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.