Program Entry Point

The main file in this project is main.sh:

First, a DEBUG flag is set to 1 which will be used later to determine whether to print some debug information across the top of the screen. Next, the _DIR and _ROOT variables are defined to set the current directory as the project root, and then the program library files are imported using the source command. We will examine the functions within these files soon, but first let’s take a look at how they are used here in this file:

In the main function, the input_init and screen_init functions are called to initialize the input and screen controllers respectively, and then the main program loop begins.

Within the main loop, a check is first performed to determine whether the screen has been resized, and if so, it is reset by calling the screen_reset command. Next, process_input is called to retrieve and process input from the terminal, render_init is called which will prepare the screen for drawing, and render_cursor is called, which will draw the cursor on the screen.

The DEBUG variable is checked, and if it has been set to 1 (which it is by default in this program), then print_debug is called to draw the debug info. Finally, the clock_cycle function is called which will trigger a cycle event on our simple internal timer, which we will examine momentarily.

Now let’s take a look at the files within the code library, which define the functions and variables that handle the operation of this program.