[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[coco8] How we are booting an S8 system in iOS?

We enumerate here the boot process of Coco8 application.
This boot procedure is implemented in "main.m" file of XCode Coco8 project; so, it is the very first step that execute the application.

It is not expected that the user change the main file; because we only boot an image containing ALL the code to define and start the S8 system.
Consider that any code you implement in main, or at ObjectiveC level, can be implemented at smalltalk level with S8, so ensure you need to edit the low level code before writing objetive C.

Boot of Coco8 system

The Main.m file do the following steps to start the coco8 iOS app:
  1. load iPhone bridge support
  2. load prologue.js from app internal storage
  3. load the default image
  4. load the default application
  5. start the application (UIApplicationMain)
This simple steps are executed in order and can be refined/changed by the user in the phone! w/o rebuilding the application w/xcode.
Note:Each user can change/update the installed Coco8 application in his/her device without requiring Apple tools to change the system.

load iPhone bridge support

The "iPhone" bridge support is actually a structured file (XML) that is loaded with definitions of C structures required during loading the system. Actually the bridge includes more structure definitions than required, because it is small size and can be required by the system just after booting.
The user can modify/extend the bridge definitions if required. The system search for "iPhone.bridgesupport" file in "~/Documents" and (if it was not found) in internal bundle of Coco8 application. The user can upload the file to customize contents of the mappings at C level.

load prologue.js from app internal storage

The prologue.js file include low level debug functions. Actually only print() function is included, for compatibility with other S8 platforms. At this level, the print() function send output to debug console (it is not shown on the device screen).

load the default image

The default image is searched under "~/Documents" folder, so the user can save the image in that folder while using the system; and that image will be loaded at the next execution of the Coco8 application.
Note:The Coco8 application implements a "server in the phone" feature. The user can download/upload files (& folders) to the application, and that files are instantly accessible (read/write) for the application. SO, the user can upload image files to the Coco8 application and change any aspect of the system at the next time the Coco8 application is started.
After the Upload server is started, it will be active only while the application is running foreground.
It do not work while the user is using other applications.

The code that load default image
        if ([c loadJS:@"default.snapshot.js"]) {
            [c loadJS:@"default.image.js"];
            [c loadJS:@"default.app.js"];

Look for the existence of a file named "default.snapshot.js" in the "~/Documents" folder of the application (the main folder of Upload server), and if present it is loaded as a S8 Snapshot (Browse Snapshot class in S8).

Note:The contents and behavior of the system is under the hands and responsibility of the user. The user can leave the application at a broken state (e.g. removed the method for system startup), and at that point and it can be required to delete and install the application again, to revert to a stable state, loosing all the files uploaded to the system.

load the default application

After loading the default snapshot, the user can upload an application image (or build the application with an image packaged internally). The code that load the application is
    [c loadJS:@"default.app.js"];

If the file "default.app.js" is found in "~/Documents" folder (root folder in Upload server) or in internal bundle of the application; the application image is loaded just after image startup.
This application image can overwrite/complement/remove any snapshot classes/methods to change behavior of the system, after loading, and before native application is started. So the user can change how the system works and present the UI of a custom application that hide/expose/complement the default Coco8 UI (that present the U8 tools in the tab bar).

start the application (UIApplicationMain)

The main application delegate is implemented in the loaded image, and the implementation (100% S8) is loaded and running at this point; so the UIApplicationMain() function will find that class and start executing the S8 method that build and present the UI to the user.
At any point in time, the application can access internal/external resources and inject them in the system, extending the functionality of the app on demand.