Reading the source
This book describes the MS-DOS version of Sid Meier’s Civilization,
version 474.05. It follows the C and assembly in src/, from DOS drivers
and map storage to city simulation, unit movement and diplomacy.
The code is reverse engineered. Names are inferred, and some modules still use local record declarations or casts that differ from the shared headers. Descriptions here follow the operations and stored values, including quirks that may differ from a player’s expectations. The build notes explain what the executable comparison establishes.
For a guided reading of a few complete files, see the Docco story in
story/. This book groups explanations by game system and ends with source
tables and shared declarations.
Entry point
main() in GAME.C starts MISC.EXE, runs setup, installs break handlers
and calls game_startup(). It checks available memory, loads cursor images,
starts the resident timer routines and initializes the mouse.
After game_menu() and start_game(), it calls game_turn() until leave
is set. On exit it closes the mouse, stops sound, restores timer and break
handlers, and requests BIOS text mode 3.
int main(void)
{
int j, k, n, memory, i;
run_program(load_program("misc.exe", 0));
setup_main();
*(char far *) 0x00400017L &= 0xdf;
install_break_handlers();
game_startup();
disk_insert(0, 1L);
memory = free_paragraphs();
if (small_space_check)
memory = 0;
if ((vga_modes ? 8000 : 4000) > memory) {
rect_fill(scrbuf, 0, 0, 320, 200, 12);
msgtext[0] = 0;
strcat(msgtext, itoa(memory, nstr, 10));
strcpy(message_slot, msgtext);
msgtext[0] = 0;
named_msg("*LOMEM");
show_menu(msgtext, 64, 49);
}
if (vga_modes && memory < 9150)
low_memory = 1;
sprite_arena_init();
mouse_cursor = load_cursor("torch.pic");
sprite_arena_release();
if (has_mouse)
has_mouse = init_mouse();
if (has_mouse) {
set_mousecur(0, 0, mouse_cursor);
mouse_on();
}
game_menu();
start_game();
if (main_option_result == 1) {
map_x0 = x_cap[civnow] - 7;
map_y0 = 19;
sel_player();
}
leave = 0;
do
game_turn();
while (!leave);
if (has_mouse)
mouse_close();
sound(0);
sound_shutdown();
restore_timer();
restore_break_handlers();
bios_call_reg_block_io.h.ah = 0;
bios_call_reg_block_io.h.al = 3;
int86(0x10, &bios_call_reg_block_io, &bios_call_reg_block_io);
}
GAME.C also defines the terrain, technology, improvement, unit and tribe
tables. The memory chapter explains how
shared state remains available while screens and other operations use overlays.