Event loop
Add-ons are executed by the dictionary in response to events. A pointer to event data is supplied and the add-on should act according to the type of event and the supplied data, then return a status code to the operating system. Some event types also require the event data pointed to by the supplied pointer to be updated. Unless you returned an error code your add-on will be executed again when the next event occurs.
The pointer to event data can be interpreted as an array of 32-bit integers, in which case param[0] will contain the event type number, param[1] will contain the first event parameter, param[2] will contain the second etc.
This is fairly different to how applications are typically written on other systems, where you have a main entry point, handle the application's loop yourself, and then only return when you wish to exit the application. As a result some development tools may need a bit of adjustment to ensure they are compatible with the dictionary's event loop. For example, if writing a program in C you must ensure that crt0 only performs its variable initialisation if event type 1 (low-level initialisation) is specified otherwise your program's global variables will be reset to their default values every time a new event is received.
The first three events to be run are 1, 2 and 3. After that it is generally event 4 that will occur in response to input events, though other event types may be triggered if required (such as event 11 after closing the settings dialog).
Event 1: Low-level initialisation
Add-ons use this event type to set global values to their default values.
Event 2: High-level initialisation
Add-ons use this event to perform the next stage of initialisation, such as registering the path of their guide00.htm file to be displayed when the ガイド button is pressed.
Event 3: First-time run
This is the first event where the add-on should fully display itself on the dictionary's screen. Before returning to the OS param[3] should be set to 0x803 and param[4] should be set to 0 if you want to wait for input events or 1 if you want to receive idle events twice a second in addition to input events.
Event 4: Repeated run
This event is triggered either in response to an input event or in response to an idle event (twice per second) if previously requested by setting param[4] to 1.
param[1] contains the source of the event, which may be a key number, indication that it was an idle event or indication of an event on the touch panel.
param[2] contains flags that further describe the event source, such as a bit set if the shift key was pressed or another set if the event happened in response to the dictionary switching out of standby mode.
Before returning to the OS param[3] should be set to 0x803 and param[4] should be set to 0 if you want to wait for input events or 1 if you want to receive idle events twice a second in addition to input events.
Event 11: Return from the settings dialog
After the settings dialog has been closed event 11 will happen. This presumably allows your add-on to respond to any change in system settings, should they have an effect on how your add-on operates.
Before returning to the OS param[3] should be set to 0x803 and param[4] should be set to 0 if you want to wait for input events or 1 if you want to receive idle events twice a second in addition to input events.