A reconstruction of the source code of Cosmo's Cosmic Adventure.
OTHER License
by Scott Smitelli and contributors
https://www.scottsmitelli.com/projects/cosmore/
Cosmore is a reconstruction of the source code of Cosmo's Cosmic Adventure version 1.20, using the original DOS compiler and toolchain. Its goal is to duplicate every detail, quirk, and bug of the original game as faithfully as possible. A player should not be able to distinguish a Cosmore binary from the original.
The reconstruction is 96.30% accurate by the following metric: The load images (skipping the EXE headers and relocation tables), when compared byte-by-byte against the corresponding uncompressed originals, have the same byte values in the same locations 96% of the time. The remaining 4% consists of uninitialized data segment memory addresses that have not (yet!) been arranged to match the original layout.
Cosmore requires a DOS environment to compile and run. DOSBox is suitable for this purpose, but a real computer running DOS standalone should also work.
There is no game data provided with this project, so you must have a copy of COSMOx.STN
and COSMOx.VOL
for the episode(s) you wish to play. Episode 1 is shareware and the files are widely available. Episodes 2 and 3 are registered versions and the files are not free to download.
The build process requires Borland Turbo C version 2.0 and Turbo Assembler version 1.0. The original game was most likely developed with Turbo C 2.0 Professional, which included both products as well as Turbo Debugger 1.5. Borland's successor, Embarcadero Technologies, no longer hosts these exact versions of their long-discontinued products, but they do still exist out there.
Note: Turbo C was released as version 2.0 in 1988 and 2.01 in 1989. Turbo Assembler was released as version 1.0 in 1988 and 1.01 in 1989. All of these versions are interchangeable and can build correctly, but the resulting binaries will have subtle differences. For maximum accuracy, use Turbo C version 2.0 and Turbo Assembler version 1.0.
The full build process requires an obscene amount of free conventional memory -- about 630 KiB -- at peak. It's possible to shave about 45 KiB off this requirement by eschewing make
and running the compiler manually on troublesome files. Additionally, another 40 KiB can be spared by running the *.C
files through the standalone C preprocessor (cpp -P- ... *.c
) before compiling to slim down the total number of symbols, but that's all a bit Rube Goldberg-esque.
There are many different ways to set up a DOS environment depending on your host platform and individual preferences. This guide will make some reasonable assumptions and suggestions, but you are free to deviate as desired. See the DOSBox Wiki page for MOUNT for information about mapping the host filesystem into DOS and mounting installation disk images. All of the instructions in this guide should be done within the DOS environment, not the host.
For the most pleasant experience, the Turbo C and Turbo Assembler binaries should both be installed into the C:\TC20
directory, and this location should be added to the DOS %PATH%
variable. The library and support files included with these programs should be installed into subdirectories named INCLUDE
, LIB
, and STARTUP
.
This directory tree shows the relevant files and their locations:
C:\
└──TC20\
├──MAKE.EXE
├──TASM.EXE
├──TCC.EXE
├──TLINK.EXE
├──INCLUDE\
│ ├──ALLOC.H
│ ├──CONIO.H
│ ├──DOS.H
│ ├──IO.H
│ ├──MEM.H
│ ├──STDARG.H
│ ├──STDIO.H
│ ├──STDLIB.H
│ └──STRING.H
├──LIB\
│ └──CL.LIB
└──STARTUP\
├──EMUVARS.ASI
└──RULES.ASI
Your installation will undoubtedly have many more files, but these are the only ones strictly required for this project.
To append the TC20
directory to %PATH%
, making its *.EXE
files available for use regardless of the current working directory, run:
SET PATH=%PATH%;C:\TC20
To make this change persist across restarts, add the line to the [autoexec]
section of your DOSBox configuration or, for true DOS environments, add it to AUTOEXEC.BAT
.
Execute the following four commands and verify the output to test the installation of each program and its place in %PATH%
. These should work regardless of the current working directory:
>make -h
MAKE Version 2.0 Copyright (c) 1987, 1988 Borland International
Syntax: MAKE [options ...] target[s]
...
>tasm
Turbo Assembler Version 1.0 Copyright (c) 1988 by Borland International
Syntax: TASM [options] source [,object] [,listing] [,xref]
...
>tcc
Turbo C Version 2.0 Copyright (c) 1987, 1988 Borland International
Syntax is: TCC [ options ] file[s] ...
>tlink
Turbo Link Version 2.0 Copyright (c) 1987, 1988 Borland International
Syntax: TLINK objfiles, exefile, mapfile, libfiles
...
If all four commands produce the expected output, the environment is ready.
CD
into the src
directory before running any compilation commands. All compilation is performed by make
.
Note: It is not possible to compile (or even load!) the game source files in the Turbo C development environment (tc
) due to the sheer size of the files. Even if the files were sized more modestly, the use of inline assembly in some functions prevents compilation in this environment from succeeding.
Before beginning, examine the contents of Makefile
to ensure the filenames and paths match the actual setup of the environment:
C:\TC20\LIB\Cx.LIB
, with x always set to L
unless the memory model is being messed with.*.H
files are found, is expected to be at C:\TC20\INCLUDE
.*.ASI
files are found, is expected to be at C:\TC20\STARTUP
.If any of these do not match the environment, edit Makefile
as needed.
*.EXE
, *.OBJ
, and *.MAP
files:make clean
make -DEPISODE=n
where n is an episode number: 1
, 2
, or 3
.
IMPORTANT: Always run make clean
before changing the EPISODE
number. make
is not smart enough to understand that the game needs to be fully recompiled when the episode number changes, and failure to clean the directory may result in the wrong episode (or a broken game!) being generated.
The game will be built as COSMOREx.EXE
, and a map file containing the addresses of all public symbols will be built as COSMOREx.MAP
. (The x here -- and subsequently in this document -- matches the specified episode number.)
Compilation of a single episode takes about 1 minute and 50 seconds under DOSBox at the default 3,000 cycles, and about 6 seconds at 75,000 cycles. At higher cycle values, speed gains tend to be negligible on all host systems I've tried.
Ensure you have the COSMOx.STN
and COSMOx.VOL
files for the episode you intend to play in the same directory as the generated COSMOREx.EXE
file. CD
to that directory if not already there, then run COSMOREx
.
There is a build.bat
script that will compile all three episodes sequentially, and compress episodes 1 and 2 with LZEXE. (Episode 3 was not compressed before release, so Cosmore does not do it either.) To build the release, run:
build
When the script finishes, there will be a new DIST
directory containing the complete set of Cosmore binaries.
Cosmore is a meticulous reconstruction of Cosmo, but it is not perfect. Compared to the (UNLZEXE'd, where applicable) original:
This project includes a few files that are not my own work, but which are required to build and package the final binaries. These files are:
src/C0.ASM
: This is the startup code for the Turbo C runtime library version 2.0, copyright 1988 by Borland International. This file is not needed to build the vast majority of projects under Turbo C, and (in situations where it is required) the compiler ships with its own copy for the developer's use. In Cosmore's case, there is a one-line change near the very bottom of this file to include the assembly code in lowlevel.asm
, and there seemed to be no other obvious way to replicate the way the original game was built without embedding this file into the project.src/LZEXE91/LZEXE.EXE
: This is LZEXE version 0.91, copyright 1989 by Fabrice Bellard. This is used by the build script to compress the final compiled binaries in the same manner as the original game. Also included is LZEXE.DOC
, the documentation for the tool as originally released; and lzexe.txt
, a duplicate copy of this documentation with the CP437 encoding translated to UTF-8. The related tools COMTOEXE, INFOEXE, and UPACKEXE are not used and therefore not included in this project. Note that the tool and its documentation are entirely in French.Except for the aforementioned files, MIT. All rights and trademarks to this game and its associated assets belongs to Apogee Software.