main() is where all C programs start.
This one is:
int cdecl main(int argc, char *argv[]) { init_header(); init_setup(); os_init_setup(); os_process_arguments(argc, argv); init_buffer(); init_err(); init_memory(); init_process(); init_sound(); os_init_screen(); init_undo(); z_restart(); interpret(); reset_screen(); reset_memory(); os_reset_screen(); os_quit(EXIT_SUCCESS); return 0; }
Several of these routines seem to fall pretty neatly into "set something up" - "do something else" - "reset the first thing" groups.
I think the code can usefully be visualised as:
int cdecl main(int argc, char *argv[]) { init_header(); init_setup(); os_init_setup(); os_process_arguments(argc, argv); init_buffer(); init_err(); init_memory(); init_process(); init_sound(); os_init_screen(); init_undo(); z_restart(); interpret(); reset_screen(); reset_memory(); os_reset_screen(); os_quit(EXIT_SUCCESS); return 0; }
As above but with annotations from the code where available:
int cdecl main(int argc, char *argv[]) { init_header(); Claim to support Z-machine Standard 1.1. init_setup(); (Set various variables, mostly to NULL) os_init_setup(); - os_process_arguments(argc, argv); - init_buffer(); Initialize buffer variables. init_err(); Initialise error reporting. init_memory(); Allocate memory and load the story file. init_process(); Initialize process variables. init_sound(); Initialize sound variables. os_init_screen(); - init_undo(); Allocate memory for multiple undo. z_restart(); re-load dynamic area, clear the stack and set the PC. interpret(); Z-code interpreter main loop reset_screen(); Do any interface-independent screen cleanup prior to exiting the game. reset_memory(); Close the story file and deallocate memory. os_reset_screen(); - os_quit(EXIT_SUCCESS); - return 0; }
Of the above named routines, interpret() "Z-code interpreter main loop" sounds the most interesting, from the point of view os how the game actually works, although init_memory() "Allocate memory and load the story file" might be interesting depending on how much interpretation of the story file is actually done at that stage.
It's not yet clear to me whether Frotz loads a game file and works out what it means, in terms of all the locations, the connections between them, the objects in them and what they are for, or whether it simply loads a compressed / tokenised (cryptic) game file into memory and then interprets things as the player moves around and interacts with stuff.
Go up
Return to main index.