A Taste of MicroScript

Steven J. Searle

Web Master, TRON Web


Three Types of Programming in the World of BTRON

One of the most innovative personal computing architectures developed to date is the BTRON-specification architecture, which is one of the subarchitectures of the "total architecture" known as the TRON Architecture. BTRON was conceived in the mid 1980s as an architecture for networked users in a networked world long before the Internet became accessible to ordinary people. Its inventor, Prof. Ken Sakamura of the University of Tokyo--who is also the TRON Project Leader--designed BTRON for single-user, multitask personal computing devices with real-time responsiveness so that people connected to networks could "communicate" with themselves, with others, and with multifarious embedded systems ("intelligent objects") placed throughout human living and work environments. Accordingly, he dubbed the BTRON-specification computer the "communication machine."

BTRON-specification operating systems, which have already been commercialized in the form of several subsets in Japan, are equipped with various types of software that enable users to perform the three types of communication mentioned above. To communicate with oneself, the operating system is has full-feature word processor and graphic software applications built in at the operating system level. To communicate with others, the operating system can avail itself of personal computer communication software, a basic World Wide Web browser, and multilingual electronic mail software. Finally, to communicate with networked embedded systems in human living and work environments, a special environment for running the Java programming language has been developed for the BTRON-specification operating system. This is referred to as JTRON, which is a specification for running the Java Virtual Machine on top of the high-speed ITRON kernel that provides the core functions for BTRON-specification computers.

In addition to this "communication software" developed, maintained, and updated by computer software professionals, BTRON-specification computer users have yet another option when it comes to communicating with themselves, others and intelligent objects--creating their own software using the MicroScript programming language. Personal Media Corporation, which is the firm that has taken the lead in the development of BTRON-specification operating systems and software applications in Japan, developed this scripting language expressly for end users with little or no programming experience. Accordingly, MicroScript is a graphically oriented, high-level programming language along the lines of Apple Computer Inc.'s HyperTalk. It enables users to quickly and easily create a wide variety of programs for communicative purposes. To date, it has been used to create games, presentation software, simulations, and other types of useful software, such as educational software for the mentally disabled.

However, unlike HyperTalk, which disappeared from the scene many years ago, MicroScript is also employed as a development tool by professional BTRON programmers, who it aids in two ways. First, it helps them port software--with minor modifications for screen size, color selection, etc.--among the three commercial versions of the BTRON-specification operating system currently on the market in Japan. These are: (1) 1B/V3, a 16-bit BTRON1-specification operating system that runs on IBM-PC/AT compatibles; (2) micro-BTRON, a 32-bit BTRON3-specification operating system for personal digital assistants (PDAs) such as BrainPad TiPO; and (3) B-right/V, a 32-bit BTRON3-specification for IBM-PC/AT compatibles. Second, it enables professional programmers to easily and quickly write device drivers for hardware devices that depend on the serial (RS-232) and printer ports that come as standard equipment with IBM-PC/AT compatible personal computers. This is possible thanks to special commands for that purpose that have been included in the MicroScript programming language.

MicroScript Based on Powerful System Resources

People who are unfamiliar with personal computer operating system design may be wondering if it is really necessary to put powerful text and graphics editors at the system level in the BTRON-specification operating system. After all, even if they were created as separate applications by other companies, people could still communicate with themselves and others. However, there is another reason for having these editors (in TRON parlance, they are referred to as the "Basic Text Editor" and the "Basic Figure Editor") at the system level--they provide powerful, standardized resources for developers of other programs to take advantage of. One of the programs that takes advantage of these editors is none other than the MicroScript programming language. As a result, MicroScript does not need a large, specialized environment of its own. That, needless to say, reduced development time and cost on the side of the developer, Personal Media. Moreover, since MicroScript employs the standard text and graphics editors that BTRON users already know how to use, training time and training difficult are reduced on the side of the end user.

Scripting languages such as MicroScript are high-level languages that have been developed for quickly banging together concise programs called "scripts" that do neat things when run through an interpreter. To that end, scripting languages are usually based on simple programming models and procedures that even people beginning to program for the first time can readily understand. In the case of the MicroScript programming language, for example, the programming model is based on the "segment," which can be thought of as a kind of "data chunk." There are three types of segments: (1) a figure (graphic) segment, (2) a text segment, and (3) a virtual object segment (a "virtual object" is a "link" to a file, or real object, in the BTRON filing system). These segments are created in a graphics window, labels are written for them, and then the segments and their labels are jointly selected and "grouped" together using a simple command from a pop-up menu. Once they have been grouped together, they become objects for manipulation using scripts that the MicroScript programmer creates in a separate text window that he/she embeds in the graphics window. The graphics window is a slightly modified version of the standard BTRON graphics window, and the text window is a standard BTRON text window.

As with all programming languages, there are a few conventions that must be followed when writing a MicroScript program. First, the name of text file into which the script is to be written must begin with the word SCRIPT. This has to be written in capital letters, because the MicroScript interpreter is case sensitive. Of course, any name can follow this expression, such as SCRIPT 1 or SCRIPT My Program. Second, the first line of the program must begin with the version number of the MicroScript version being employed. The latest version as of this writing is VERSION 2, which comes as standard equipment with the B-right/V operating system currently on the market. If the version number is not written, then it will be impossible to use all of the features of the language. Third, the procedural statement PROLOGUE must appear somewhere within the program, although not necessarily on the second line. This statement serves as an initializer, and it is used together in conjunction with the statement END. If both PROLOGUE and END are not in a program, then nothing will happen when the window opening that launches the program takes place.

As is the case with all modern computer languages, MicroScript programs do not use line numbers. However, line numbers are used in manuals to make it easier to explain features within a script. Moreover, the lines of the program can be indented to make it easier to read a script, which is also the case with other modern languages. Depending on the size of the graphic elements included in a script, MicroScript programs can vary greatly in size. A very tiny program that does nothing more than display a simple segment will be roughly about one kilobyte in size. On the other hand, larger programs that include very complex graphics and complex processing routines will easily attain several megabytes in size. This is also the case with other scripting languages. However, MicroScript also has some features that other scripting languages, particularly those aimed at beginners, do not have. First, MicroScript can utilize all the character sets and input methods in the B-right/V operating system, which makes it an ideal scripting language for producing multilingual presentation materials, especially for Asian languages. Second, it can handle various types of tasking procedures. Specifically, MicroScript can handle single-task procedures, multitask procedures, and parallel-task procedures. Third, it has special instructions for utilizing the RS-232C port and virtual objects, which are the equivalent of hypertext links on the World Wide Web.

Creating a Simple MicroScript Program

Let's now create a short program to show how easy it is to write a script using the MicroScript programming language. Please note that the number of instructions in this program are being kept to a minimum so that even beginners can follow along.

The process of writing a MicroScript program begins the same way that any other type of work begins on a BTRON-specification operating system--the user peels a leaf, or stencil, from the appropriate virtual object in the Stencil Box, which in this case is the MicroScript virtual object. It should be noted that this is the reverse of what is done in other operating systems, where an application is first opened and then a file is created. In BTRON, you create the file first, and then the application starts up.

When the leaf or stencil is moved to an open window, a virtual object, which looks something like a title bar, is generated and a panel appears asking the user to input a file name of his/her choosing. Since this MicroScript program will move a square around the screen, let's call it "square dance." (Fig. 1; the panel in the says: "Please input the name of the new real object.")

Once the file name is input and the user pushes the "Set" button, a window opens. This window is a graphics window that can use all the tools employed by the Basic Figure Editor, which is a system-level graphics program in the BTRON-specification operating system. First we set the size of this window to appropriate dimensions, and then we create within it a small square.

Now comes the unique part. In order for MicroScript to recognize and manipulate this square as a "segment," we must first create a label for it and then group that label together with the square. We do this by writing the label "@SQUARE" below the square, simultaneously selecting both the square and the label, and then choosing the "Make group G" command from the Edit menu (Fig. 2). When this simple operation is completed, we have a segment ready for manipulation.

Next we create the script, or program, that will move the segment SQUARE around the window. This is done by first creating a word processing file inside the graphics window. To do this, we open the Stencil Box once again, peel off a leaf of writing paper, and insert it in the opened graphics window. A panel appears asking the user to input the name of the real object. In order for the MicroScript interpreter to recognize this as a MicroScript program, the file name must begin with "SCRIPT." Thus let's use "SCRIPT: square dance" as the file name (Fig. 3).

Now we can input the program "square dance," which is very simple. It is as follows:

VERSION 2
PROLOGUE
APPEAR SQUARE
SLEEP 750
MOVE SQUARE: 10, 10 @
SLEEP 750
MOVE SQUARE: 350, 10 @
SLEEP 750
MOVE SQUARE: 350, 300 @
SLEEP 750
MOVE SQUARE: 10, 300 @
SLEEP 750
MOVE SQUARE: 150, 150 @
SLEEP 750
MOVE SQUARE: 90, 90 @
SLEEP 750
MOVE SQUARE: 60, 60 @
SLEEP 750
MOVE SQUARE: 20, 20 @
SLEEP 750
MOVE SQUARE: 10, 10 @
SLEEP 750
DISAPPEAR SQUARE
END

In layperson's terms, what this program says is:

This is a program written in Version 2 of MicroScript
Initialize MicroScript interpretation resources
Make the segment SQUARE appear on the screen
Wait for 750 milliseconds
(Note: 750 milliseconds equals three-quarters of a second. MicroScript counts time in milliseconds. It is necessary to use this SLEEP command to slow down the movement. Even though MicroScript is interpreted, it executes instructions very quickly.)
Move SQUARE to point 10, 10 absolute
(Note: These are "absolute x, y coordinates," i.e., over 10, down 10 from upper left-hand corner of the window. MicroScript can move segments either to absolute coordinates, in which case they are followed by "@," or to relative coordinates, in which case they are followed by nothing.)
Wait for 750 milliseconds
Move SQUARE to point 350, 10 absolute
Wait for 750 milliseconds
Move SQUARE to point 350, 300 absolute
Wait for 750 milliseconds
Move SQUARE to point 10, 300 absolute
Wait for 750 milliseconds
Move SQUARE to point 150, 150 absolute
Wait for 750 milliseconds
Move SQUARE to point 90, 90 absolute
Wait for 750 milliseconds
Move SQUARE to point 60, 60 absolute
Wait for 750 milliseconds
Move SQUARE to point 20, 20 absolute
Wait for 750 milliseconds
Move SQUARE to point 10, 10 absolute
Wait for 750 milliseconds
Make the segment SQUARE disappear from the screen
End execution
(Note: PROLOGUE and END are used as a "set." As with all programming languages, you must tell the computer both when to start doing something and when to stop doing something. Computers are not capable of "assuming" that you would like them to stop doing something.)

Once the above program is input into the text window (Fig. 4) that has been created inside the graphics window, it is time to run the program. To do this, all the user has to do is: (1) close the text window, (2) close the graphics window, and (3) choose the MicroScript option under the Execution menu item while the "square dance" virtual object is in the selected state (Fig. 5). There are two items under Execution menu item: (1) Basic Figure Editor, which allows the programmer to edit the program; and (2) MicroScript, which allows the programmer to run the program. It is also possible to reload and run the program again while in the MicroScript mode.

That Looks Simple, So What's Next?

Just about everyone should be able to understand the above program, but there is probably more than one reader wondering what the next step is toward gaining proficiency in MicroScript. Well, the next thing is to do is to experiment with and expand on this program. For example, speed up or slow down the action by changing the SLEEP times. After you try that, try make the SQUARE change colors as it goes from one leg of its journey to another. You could also make it change shape, or instead of a simple object, have a dog or a cat run around the screen. In other words, you take your first steps in programming by studying something that works and playing with it. If you find that enjoyable, then you're qualified to be a programmer.

Once you have digested the possibilities of the above program, it is time to move onto other instructions and learn how to write longer programs in MicroScript. Writing programs using a scripting language such as MicroScript is not as difficult as writing programs with other programming languages. This is because scripting languages are based on the simple paradigm of a theater (the screen), actors (the segments), and a script (the program). Accordingly, if you have the ability to write a script for human actors who will perform on a stage in a real theater, then you probably also have the ability to write rather complex scripts using MicroScript. The only difference is that you have to master a computer language, rather than a human language, as a means of expressing the contents of the script. And that is not as difficult as it may sound, since computer languages have very small vocabularies compared to human languages (see the Appendix below).

As for intermediate and advanced programmers, there are all sorts of interesting things I can think of for you to do with MicroScript. For example, have you written a neat program in another scripting language? Why not rewrite it in MicroScript and share it with the BTRON community? See any new possibilities for a great program using MicroScript's unique instructions for manipulating peripheral devices or virtual objects? Well, then write a program using them and show it off to the rest of us. You'll probably make some new friends and get a few leads on how to make money in the world of BTRON. And there are definitely money making opportunities in the world of BTRON. Two that I can think of are: (1) a compiler for MicroScript, which does not yet exist but is a necessity for commercial developers programming in MicroScript; and (2) a set of security and communication functions that will allow hobbyists to create and program "virtual LANs" with their friends (see this month's TRON Web opinion piece about MacroScript).

And so there you have it--a taste of MicroScript. For those of you who enjoyed it, you will be pleased to learn that TRON Web will be presenting more information on the MicroScript programming language in coming updates. So please check back often and see what new things we have added to this section. Future plans include translating parts of the Personal Media's Maikuro sukuriputo nyuumon [An introduction to MicroScript], plus an on-line library of MicroScript programs to serve as examples for beginners. If there is anyone who would like to participate in the plans, plan feel free to write to me at the Web master's e-mail address on the home page.


Appendix

Instructions

Definitions and Declarations

DEFINE VARIABLE LOCAL SEGMENT SCRIPT

Procedures

PROLOGUE EPILOGUE ACTION MACTION FUNC END

Assignment, Condition Inference, Repetition

SET SETSEG COPYSEG IF SWITCH REPEAT WHILE

Control

CALL EXECUTE EXIT FINISH TERMINATE BREAK SUSPEND SLEEP WAIT

Window and Display Operations

WSIZE WMOVE WSAVE FULLWIND UPDATE SCENE APPEAR DISAPPEAR MOVE BEEP

Character Input Operations

MSEG TEXT INPUT KINPUT

Virtual Object Operations

VOPEN VCLOSE VWAIT

Process Generation

PROCESS PWAIT

Message Operations

MSEND MRECV

Real Object Operations

FOPEN FCLOSE FREAD FWRITE

Device Operations

DOPEN DCLOSE DREAD DWRITE

Event Generation

EVENT

Serial Port and Print Port Operations

RSINIT RSOUTC RSPUTN RSWAIT RSGETIN RSGETC RSCNTL PRPUT

System Management

VERSION DEBUG LOG COMMENT

Functions

Value Inference

valid number

Numeric Operations

sin cos tan asin acos atan sqrt exp log log10 floor ceil round fabs pow max min

Array Operations

asrch acmo acopy slen scmp

Character String Conversion Operations

strnum sconv srconv

System Operations

setgnm getgnm delgnm

System Time Operations

tmdate datetm

MicroScript Value Limits

DEF buffer size: 8KB (1B/V3); 32KB (TiPO, B-right/V)
Intermediate language size: 64KB
No. of script real objects: 8
No. of segments: 936 (1B/V3); 3,640 ((TiPO, B-right/V)
Maximum no. of menus: 8
No. of procedures plus variables: 2,040 (1B/V3); 8,164 (TiPO, B-right/V)
No. of arguments plus local variables to a CALL: 2,040 (1B/V3); 8,164 (TiPO, B-right/V)
REPEAT, WHILE, IF, SWITCH total nest no.: 32
DEFINE nest: 16
CALL nest: Unlimited
(Because this is limited by the thread stack size, it depends on the no. of arguments and local variables to a CALL.)
Length of a character string: 1,024
No. of formulas that can be written in a single statement: 512
No. of simultaneous threads: 32
Thread stack size: 64KB
No. of array elements in a single variable: 1,048,576
No. of array elements when it is a local variable: 4,096
No. of array elements when it is a segment array: 500 (1B/V3); 1,000 (TiPO, B-right/V)
No. of $GV: 50 (no. of shared variables)
No. of $SV: 50 (no. of saved variables)
No. of $RS: 512 (equals the input buffer size, i.e., no. of data from RS serial port)
Length of a name: 12 characters
Length of a single string: 1,024 characters
No. of characters in a bus name: 256 characters
Message size: 4,096 bytes
No. of messages retained: 16
No. of devices opened simultaneously: 16
No. of files opened simultaneously: 16
No. of processes started up simultaneously: 16
No. of copies using MOVE:DUP: 16,380