Unofficial Guide To Expanding Your Numworks/What happens between power on and using an application
Warning, there is lots of educating guessing from reading the code, and some of the guesses may be wrong. If something is wrong here, then correct it and add a comment in the discussion page pointing to where others can read the code you based the correction on.
Power On vs ResetEdit
First thing to understand is that when you "turn the calculator off" with the power button, it's not really turning off. The system goes into a very, very low power sleep mode and waits for the power button to be pressed again or the reset to be pressed. The only way to truly have the calculator off is when the battery runs completely down. When the calculator wakes up from this low power sleep state, it skips some of the initialization that would be done on a true power up because it's not needed. The calculator will start up in the same state you turned it off in, except possibly that the "Upgrade is available" screen will be shown if that setting is turned on.
Reset (by pressing the tiny button on the back) does exactly the same thing as having the battery run down. All the initialization code will run from the very beginning and the calculator will start up at the home screen. You will lose any calculations that were in progress and your settings will be reset.
Going forward we'll use the term 'reset' to mean either pressing the reset button or having the battery run completely down and then recharging. 'Power on' will be used to indicate pressing the power button on the calculator when the battery has power, but the calculator is in the deep sleep mode.
First thing on reset, the calculator checks to see if it's plugged into USB. This is done by simply having a pin on the MCU tied to the +5V VBus on the USB connector with a pull down. If there is power, that the calculator will start in DFU mode. This is the mode used to download new firmware to the calculator and if the calculator is plugged into USB when it is reset, it will unavoidably go into DFU mode.
Next the firmware will initialize all the internal systems. The screen gets initialized and blanked out, the RGB led is turned off, and the keyboard scanning is started.
Application Container and HomeEdit
Once the hardware is up and running, the firmware will set up the Epsilon OS and then initialize the application_container. The application_container keeps track of all the applications available on the calculator. Each icon on the home screen is one application, plus there is an application for the home screen itself. One of the first things the container will do as part of it's constructor, is to create a "snapshot" for each application. The contents of the snapshot are defined by each application and contains the information needed for that application to capture it's state as the user switches between applications. The container then creates the full screen window and divides it into two areas: a status bar along the top where you see the current application, battery state, etc, and a window covering the rest of the screen where the currently running application will be displayed. The container then sets up the status bar by drawing any indicators for angle mode, the title of the current application, the battery state, etc.
The application_container is also in charge of managing the transition between applications. When the OS or an application requests to switch applications, the application_container will check to make sure the application requested exists, will capture the state of the current application, load the state of the new application, and then give the new application control of the hardware. Once the status bar and application area is setup, the application_container will switch to the first application in the list of applications, which is hard coded to be the Home application.
The Home application will then ask the container how many applications there are. For each application, other than Home itself, the Home application will ask for the name of the application in the current language and the icon for that application. Each of the icons will be arranged in two rows with the localized name below the application, and then the Home application will simply wait for keys to be pressed and adjust the selected application as needed. When EXE or OK is pressed, the Home application will ask the application_container to switch to the selected application. When the application exits or the Home button is pressed, the container will switch back to the Home application and this process will start over from the beginning.