User Tools


reference:about_subprograms

About Subprograms

Warning!

SmileBASIC Ver.4 aims at a simple language specification as a language for beginners, but only subprograms require advanced programming ability as an exception.

What is a subprogram?

Subprogram is a new mechanism introduced in SmileBASIC4 and can execute a completely different program called a subprogram at the same time as a program that is usually executed.

(Hereafter, the normal program is called the main program. The interpreter that runs the main program is called the main interpreter, and the subprogram is called the sub interpreter.)

This subprogram mechanism is similar to so-called multitasking and multithreading, but specializes in creating tools that can be called at any time independently of the main program and can be stopped at any time, occupying part or all of the display and assisting program creation. Please note that it cannot be used for parallel processing such as letting some processing of the main program escape to the subprogram.

An important difference from the main interpreter is that the sub interpreter does not have a direct mode. Only the saved program can be executed as a subprogram. When execution is completed, the interpreter ends without returning to the direct mode.

Precautions When Writing Subprograms

Unlike normal SmileBASIC programs, there are some rules that must be observed when creating subprograms. If you do not follow the rules, the display may not be displayed or the program may not work properly.

Basic Mechanism

・The sub interpreter has exactly the same memory capacity, program slot, and display configuration as the main interpreter. The memory space, program slot, and the display of each other are completely independent, and they cannot interfere with each other except for the specific commands described below.

・There is no command to start/stop the subprogram from the main program. In other words, you cannot write a program in which two specific programs work together.

・Regardless of whether the subprogram ends normally or ends in errors, the display is also turned off when it is completed. Since it is extremely difficult to handle the execution status, it is recommended to create it as a normal main program first. Also use the STOP command with arguments.

Display Control

・Subprograms are not displayed on the display immediately after startup. To show on the display, first use the XSUBSCREEN command. XSUBSCREEN is an command that defines the area occupied by a subprogram in the display. The main program can use the entire display, while the subprogram can be used only in the area defined by XSUBSCREEN.

・The subprogram display is always drawn in front of the main program.

Input Related

・XCTRLSTYLE command is ignored. In other words, the controller settings will always depend on the settings of the main program. The setting may change suddenly during execution of the subprogram. Please note that controller ID becomes useless except number 0. Also, vibration commands cannot be used.

・Inputs such as controller, keyboard, and touch mouse are passed to the program that has "focus". The focus is usually in the sub when the subprogram is running, and the main has the rest, but by using the ENVFOCUS command, it is possible to temporarily give or take the focus from the subprogram to the main program. The focus cannot be controlled from the main program.

Interaction Between the Main and the Sub

・Subprogram related commands are used to obtain information from the main interpreter. Commands starting with ENV are related to subprograms.

・Subprogram related commands are almost ignored and return dummy values ​​even if they are used in the main programs. Conversely, when commands that can only be used in the main programs are used in subprograms, they'll be ignored mostly even if it is executed. It's a specification for the convenience of subprogram development.

・It is not guaranteed when the state of the main interpreter acquired by ENV commands will change. The main and the sub, the two interpreters operate completely independently and in parallel with each other, and exclusive control cannot be applied between the subprogram and the main interpreter.

・Interference from the sub interpreter to the main interpreter is only possible with the ENVSAVE, ENVFOCUS, and PUSHKEY commands.

・Interference from the main interpreter to the sub interpreter can be performed only stopping the subprogram using the SUBSTOP direct mode command. No information can be obtained.

・The current project is different from the main and the sub. The sub project is always the current project where the startup program is stored, but it can be synchronized with the main current project by using the ENVPROJECT command.

・The indication of the dialog is exclusive between the main and the sub, and a command that shows another dialog is blocked until the one appeared first closes.

reference/about_subprograms.txt · Last modified: 2023/12/07 15:54 (external edit)

Page Tools