File Format

CC2 maps are stored on disk in a binary format with an FCW file extension. Each individual file consists of a header followed by a copy of the database of entities that make up the map. With this knowledge in hand, the best place to find out about the file format is the XP toolkit.

The XP toolkit.

The toolkit is filled with many different files for both assembly language programmers and for C programmers. Since the C files are not complete, we'll look at the assembly language files. The CPY files are the assembly files. Inside the CPY files we find the blueprints for the FCW file. But, just like real blueprints, it takes some special knowledge to understand them.

Looking at the HEADER.CPY file we see what comprises the file header:

; =============================================================== 
; HEADER.CPY - Header and File ID data structures 
; =============================================================== 
; Copyright 1996 Evolution Computing 
; All rights reserved 
; Written by Susan Montooth 2/15/96 
; ===============================================================
; FILE ID (File identifier bytes) 
; =============================================================== 
 
DBVERSION	equ 24			;correct current database 
 
FileID 		struc 
ProgID 		SBYTE 	'FCW (FastCAD for Windows) ' 
VerText 	SBYTE 	versionStr 	;version # as text (4 bytes)
VerTextS 	SBYTE 	SubVer 		;beta version 
		SBYTE 	' ' 
		SBYTE 	13,10,26 	;terminating chars for DOS Type cmd. 
DBVer 		SBYTE 	DBVERSION 
Compressed 	SBYTE 	0 		;1 = compressed file 
		SBYTE 	78 dup (0) 	;filler 
		SBYTE 	0FFh 		;end marker (total 128 bytes) 
FileID 		ends 		

Lets look at a few individual lines and get general understanding of what they represent:

DBVERSION	equ 24			;correct current database

This line sets the variable DBVERSION equal to the number 24

FileID 		struc
...
FileID 		ends

The file system is organized and the different sub-systems (file-id, layers, line styles, ...) are logically grouped in something called structures. Structures begin with a name followed by the keyword 'struc' and continues until the name appears again and is followed by the keyword 'end'. For example, file FIleID holds the entire description of the file header.

ProgID 		SBYTE 	'FCW (FastCAD for Windows) '

The first line of the FileID structure defines the variable ProgID as an SBYTE and sets it equal to 'FCW (FastCAD for Windows) '. An SBYTE is the assembly language version to a string, so ProgID is 26 bytes (characters) long and are the first 26 bytes in the file.

Counting bytes we see that the 49th byte holds the Compressed flag. We can only work on Uncompressed files so the first thing we need to do as we start to delve into the file format is to check this byte to make sure that it holds a zero. The entire file header is 128 bytes long.

Looking farther down in the HEADER.CPY file, we see that within the database header:

BColor 		WORD 0 			;background color

What we are interested today is the first byte of the Bcolor word. Since CC2 only has 256 colors, the other three bytes of the WORD are not used in the current version of CC2. Counting bytes again, we see that the 157th byte holds the background color.

I’ve written a little Visual Basic program that will load a CC2 v6 file, "TEST.FCW" from the programs directory, into memory and after checking to see if the file is compressed, will change the background color to 150, a particularly vivid shade of orange. It then saves the file as "OUT.FCW".

Look at the code … run the program and do some experiments. Try to change the current color, layer or the last tag number that was used. Later we will be expanding on this simple program to add more and more functionality.


Download the XP Toolkit


Download the Visual Basic program and code for "ParseFile.exe".