-
Notifications
You must be signed in to change notification settings - Fork 3
ScummC Internals
A short description of the ScummC structure. Hopefully it should be helpful to get a better picture of the internals and migrate to something more flexible to extend it to several versions of SCUMM.
Compiling a game is done in two steps. The compiler (scc) first generates object files from the source code. These object files are then linked together with the linker (sld) to generate the final game files ready to use with ScummVM.
The two step procedure is required because when compiling a room, the compiler can’t know everything about all the variables and other resources that will constitute the whole game. At link time, however, everything is there; the linker can allocate addresses for each resource and create the final game.
scc is based on yacc for the lexical parsing and bison for the grammar. The lexical parser basically just splits the input into tokens that can then be used by the main parser. It also handles including other source files.
The main parser first constructs the roobj in memory as the parser goes along. A namespace is constructed that holds the name of every resource. But for most resources, the compiler can’t give it an address. In such case it is given a ‘’room ID’’ that uniquely identifies the resource within the room. When generating code, every reference to a resource which doesn’t have an address uses the ‘’room ID’’ instead. For each script, a list of all these references is kept to allow the linker to patch the code later.
When a room has been successfully parsed, the roobj file is then written. The general structure of a roobj file is similar to a normal game file. Some blocks are already in their final form, but most blocks need patching, as many will at least need to carry their ‘’room ID’’ along. The roobj files also contain a few other blocks to store symbol tables, etc.
The linker is simpler. It starts by loading all the roobj files and verifying that all resources are defined, etc. If that is all right, then addresses are allocated for all resources that don’t already have them, and all the blocks that need patching are patched. After that, the final data files are generated.