BASIC Zgrass--A ~ophisticated Graphics Language for the Baliy Home Library Computer

Tom DeFanti, University of illinois at Chicago Circle Jay Fenton, Dave Nutting Associates Nola Donato, University of Illinois at Chicago Circle

Abstract Home computer users are just now discovering arcade units, its projected cost, without color computer graphics. Modest extensions to BASIC al- tv, is about $750.00, including the arcade unit. low plotting but not much more. The Bally Home Zgrass itself takes up 16k bytes of ROM Library Computer, however, has hardware to aid im- storage and has 16k bytes of RAM for user storage plementation of video games. Custom integrated and system use. An additional 16k ROM (referred circuits working on a 160XI02 pixel (2 bits per to as the 'extension' below) plugs into the side pixel) color television screen allow certain forms and provides room for a compiler and other of animation in real time. To give this power to features. Audio cassette storage and modem link- the user, BASIC Zgrass has been designed and im- age to other computers is provided. Software for plemented. It is an extension of BASIC that al- driving optional intelligent floppy disk drives is lows parallel processes, picture objects that also built-in. Further hardware in this unit in- move, scale and group together as well as several cludes four hand controls, a 24-key pocket calcu- drawing modes. There are also software controls lator keyboard, a three-voice sound generator and of a three-voice music synthesizer, interactive an IEEE Bus interface. Zgrass is the operating input devices, a film camera and an IEEE bus in- system for this computer as well. terface. We will concentrate mainly on the Zgrass design concepts are rather different language design for making it all easy to learn from those apparently underlying the current batch and use. of home computer systems. Home systems are now trying very hard to be cheap minicomputers for ex- Content Indicators pert users. These users when at home can be 1.51, 1.52, 2.12, 3.41, 3.44, 3.80, 4.13, 4.22 likened to the ham radio operators of the nineteen Keywords: interactive computer graphics, in- fifties, able to change diodes, violently shake tepreters, real-time, graphic language, art intermittent boards and, in general, understand Introduction and General Motivation the innards. These persons can also get gratifi- cation from fighting with manuals and the trials Zgrass can be called an immodest extension of of the latest software release, just as we profes- BASIC (Ted Nelson refers to it as "Super BASIC" sionals do for a living. [I]}. It is an extension in that graphics support Zgrass, however is designed for the two- and user instruction facilities have been added to hour-a-week user. This type of person is the capability of running BASIC programs copied guaranteed to continually forget the syntax and out of a hobbyist computer magazine. It is immod- semantics of whatever software exists. Zgrass is est in that great liberties have been taken to designed (certainly at the cost of computer time weed out some of BASIC's undesirable programming and memory use) so the user does not have to rely conventions. Zgrass is actually a video game pro- on a manual to decipher everything. In short, gramming language designed specifically to en- this system is trying to be the Model T of the courage creation of beautiful animations in short home computer industry, with all that implies. We order. It is also designed to teach many of the shall see. important concepts of interactive systems and 2-D Above all, Zgrass is designed to be as at- computer graphics. tractive and as fun as pinball but considerably The hardware used is the Bally Home Library more intriguing and useful. Computer built around the Bally Arcade unit. It is a Z-80 based machine with special integrated General Zgrass Concepts circuits which help the processor manage the 160xi02 2-bit-per-pixel color output connected to "Right away" is the foremost design concept any standard color tv set. The alphanumerics gen- of Zgrass. Positive experiences in the first two erated by program output and keyboard input are hours of play are essential. When it is not part video mixed over the color graphics so text is not of your job or intended career, you must be able constrained to the 160xi02 format. The two bits in to do interesting, beautiful things right away, each pixel indicate one of four bytes from which without reading a five-pound manual. an index into a 256-element color map is taken. BASIC is now the home computer language. Thus, four of 256 colors can be on the screen at BASIC was designed as a teaching language and once. The hardware also includes some tricks shines in its simplicity and easy matrix opera- which have been found useful in professional video tions. It is, however, a poor language for the

33 manipulation of anything but numbers. It has no some CAI programs in Snobol or Lisp but these are features that make writing large progams (over 200 hardly languages for novices and they are not statements) easy. Its subroutine capability is known for their lucid error message handling, or archaic. But, it is obviously a success in what availability on micros. Perhaps a graphics- the designers intended, otherwise it could not extended APL might do. It would be wonderful if presently be the universal home computer language. the experience with Zgrass encouraged others to In particular, though, BASIC is a poor design extensions to languages with teaching in language for animation. To be sure, plotter art mind. and decaying sine curves are well suited to BASIC. But our almost eight years of experience with the Zgrass Technical Details GRASS language[2] and Dan Sandin's color video Im- age Processor[3] as well as being directly or in- Zgrass is an interpreter of commands and as- directly involved with roughly half of the most signment statements stored internally as ASCII popular arcade video games, has given us insight strings. These strings may be entered and execut- into the potenti~± of a color tv set, and you just ed line by line, formed into programs (called cannot do a tv set justice in BASIC. "macros"), edited, and even built and pulled apart The next several pages will give details on by string manipulation primitives. (A compiler syntax of Zgrass, but first we will further con- which eliminates most of the interpretive overhead sider the "right away" criterion. Anyone who al- and which takes better advantage of the resident ready knows BASIC should be able to write Zgrass hardware floating point unit is part of the 16k programs immediately. For those persons in Ameri- extension ROM.) ca who do not religiously read "BYTE" or "Creative We are determined to maintain compatibility Computing" (a sizable part of the population), we with at least TINY BASIC (it is hard to say what have been developing self-paced instructional "standard" BASIC really is). Since BASIC has line software for Zgrass. The prototype system now numbers, Zgrass labels must start with a number functions quite well in GRASS (see paper by Towle (e.g. 100, 1obekenobe, 707crash, etc.). A BASIC and DeFanti, these proceedings). Both GRASS and program copied out of "BYTE" would simply have a Zgrass have enough supervisory functions and error lot of extraneous labels. Labels in Zgrass are trapping features to allow a good obviously not used to order and edit the state- programmer/educator to write programs which exe- ments as in BASIC since one would hardly like to cute and verify instructional programs written by have alphabetically ordered labels and Zgrass has beginning students. We feel that the chief prob- a good on-screen editor anyway. Our definition of lem in teaching programming is that it, as an ac- compatibility is r~stricted to executing perfect tivity, is poorly simulated by the examples and programs written in BASIC. Getting them in, edit- the Backus-Naur-type syntax information usually ing, executing and debugging them is done dif- found in manuals. Normal programmers have fellow ferently. workers, consultants or at least other students Commands are made up of a keyword followed by around to help out. The home user has no such zero or more operands. Examples of commands are: recourse. goto 4jail The essence of the teaching problem stems move deathweapon,xl,yl from the fact that novices have tremendous prob- clear lems with meaningless (to them) error messages. input dea,fbi, You really have to know nearly everything about a print beep,"who loves ya, baby?" system before you can start knowing why what you (some of the more idiosyncratic BASIC commands, have typed does not work. This is absolutely not notably "if" and "for" have their peculiar syntax an overstatement of the problem. retained for compatibility). All this commentary leads directly to comput- Commands are gentle to users. If not enough er aided instruction. While CAI has not quite arguments are supplied, if an incorrect argument lived up to its expectations for teaching other is given or the argument is non-existent, a spe- subjects, it can be used to teach people how to cial error fixup routine is entered. This routine program. It is rel~tively straightforward to lead prints out the command in error, points at the ar- the user through commands, interactively teach gument in error and says, for example, "NO! this looping concepts and verify the results of care- command wants a variable name here." The user can fully chosen problem sets. All possible errors then type in a correct argument and the command can be trapped and explained in detail. Our ex- goes on. He can also elect to enter command mode perience with this type of teaching is very to create a missing name, for example, and then supportive--non-programmers (primarily art stu- resume the above process. All this will happen dents and a few university officials) can be doing whether commands are entered line-by-line or exe- fascinating graphics of great beauty in half an cuted as part of a macro. hour. The whole process has the feeling Of a game Note that all commands are more or less self and is consistently rewarding. Providing internal documenting. You can type the command name and it system support for these teaching programs is no asks you for the operands. This error facility doubt the second most important design concept of allows one to get by trivial syntax errors without Zgrass, after "right away" of course. constant re-editing. It is also a sloppy way to Note that few (if any) programming languages get input to macros, although there are several allow you to write programs to interactively teach conceptually clearer (to computer folk) ways. programming. Smalltalk[4] and Logo[5] teach by Many commands have options indicated by post- user experimentation in surroundings not lacking fixing the command name with a hyphen plus a professional help. Plato[6] has no student pro- modifier (e.g. "input-string" which can be shor- gram or storage space (only authors can write and tened to "in-str" or even "i-s"). The hyphenated store TUTOR programs). One could probably design option construction is more English-like than

34 single-character switches and it helps keep down Macros proliferation of command names. Since every command has an internally stored Any string can be executed in Zgrass. If it list of what argument types it wants, the "help" contains meaningful commands, it can be used as a command can easily print these out with options program. Again, programs in Zgrass are called (there are about 20 different argument types in "macros." Macros can call other macros, call them- Zgrass, like number, string, expression, picture selves, execute in foreground or in parallel with prototype, array and so on). Further syntax and other macros in the background, supervise other semantic information is available in the manual macros and interact with macros running on other but the information you need most often is at your Zgrass machines. fingertips "right away." Zgrass differs from BASIC greatly when it A few more details about variables are neces- comes to subroutine linkage. Zgrass has a very sary. Variable names (macros are actually string convenient and conceptually clear way of passing variables) can ~e any length and must start with arguments--you simply make believe the macro is a an alphabetic character. Variables used as macros command and use standard command syntax• Further- may not have names ~hich conflict with system more, the "input" command (for numbers) and the names. Global variables start with lower case "input-name" and "input-string" commands (for letters and local variables start with upper case strings) fetch the arguments passed in a way that automatically request user input from the terminal letters. The system decides whether a variable is if not enough arguments are passed. This linkage a numeric or string variable by examining the con- text in which it is first used. is discussed in more detail below• Looping and control transfer is done with (Commands are terminated by semicolons or carriage returns. The alphanumeric generator "goto," "for/next" and "gosub." (Gosub is re- which is video mixed over the color graphics or tained for compatibility.) A version of goto routed to a separate monitor puts up sixteen called ',skip" has the option of jumping relative a 32-character lines. The alphanumeric handler au- number of lines, a good feature for those quick tomatically folds lines over 32 characters long loops in which you forgot to put the label• There for display purposes but does not insert a car- is also a "return" command which can pass an argu- riage return. A special character indicates folded ment back if it is a function call like "whodun- lines.) nit" above. When a macro is asked to execute (by typing Arithmetic statements are similar in format its name as the first thing on a line, like a com- to assignment statements in BASIC or FORTRAN, with mand), the system builds a macro invocation block the exception of the left arrow used. The parser (MIB). The MIB holds information about local automatically changes equals signs (which are used variables, for/next blocks, argument and data for conditionals) to left arrows to maintain com- lists and so on. When the macro is done, the MIB patibility with BASIC yet allow a sophisticated is deleted along with all the pieces hanging off expression evaluator to operate unambiguously by it. The storage allocation/reclamation algorithms not having to deal with multi-purpose operators. used are again similar to GRASS's. Examples of arithmetic assignment statements are: Numeric arguments are passed using the "in- abc~sin(argl)+cos(arg2) put" command. It is similar to "input" in BASIC [email protected] but it first checks the argument list. If there c~whodunit(f,g,huh) is an argument, it is grabbed. Otherwise, the user where the last example contains a user-defined is requested to enter the value. Input works in function (a macro, of course). concert with "print" which supresses output when Numeric variables are kept in fixed or float- arguments are present. (Of course, there are op- ing point by the system, switching mode as neces- tions to input and print which force terminal sary without user knowledge. The luxury of a I/O.) Thus, a macro that has lots of prompting in- formation can be called by another macro without floating point arithmetic unit helps calculation speed considerably. There are also reserved sys- all sorts of editing to remove the prompts, but tem variables which hold the values of the hand the macro will wake up and start asking questions controls, keypad keys, external I/O strings and if not enough arguments are supplied. One can other special things. create self-documenting macros which are effi- Strings are assigned as follows: cient, yet help out when necessary. (How many tom~'this is a single line" times have you forgotten the arguments to a sam@tom&tom&babarum ;.concatenat subroutine?) er~' The "input-name" command functions similarly ' ;.to enter a carriage return for strings and is used to get names passed as ar- mymacro@ ;. stuff gets "hell~ reference strings. For example: for a=1 to 10 getandmove@ if gettemp='',return ;.if null, return The last example shows nested assignments and a get-tape @gettemp ;.get it from tape way to create a macro. Note that acceptable move @gettemp,x3,Y3 ;.attach control3 string delimiters are ",',<,>,[, and ], the last display @gettemp ;.and show it four of which must be balanced. String decomposi- goto lagain> tion is handled by a variety of string commands in the 16k extension.

getandmove apple,witch,~itles,,

35 where the last line is the call and the lines course, there can be maDy prototypes floating above are the macro definition presumably entered around at once. before the call. Comments are lines or sub-lines Again, the user's aesthetics and perceptions which start with a " " are essential. Since everything is real-time (or The "input-string" command expects string close to it) the user can easily see the effect of delimiters around arguments passed so that whole various commands on the screen, the implications commands can be arguments (you cannot pass a comma of varying amounts of interrupt processing time, with the input-name option). This is important for the ways of using different colors, and so on. the construction of teaching and verification pro- Prototype lists and patterns can be grouped grams, among other things. If the argument is not into a tree structure which allows concatenation there, input-string will require input from the of transformations. Moreover, the "select" com- keyboard, but without the string delimiters, just mand specifies a sequence of pictures to be put up like input-name. and erased in round-robin fashion (imagine several The principle here is to make macros look views of a walking "man" being switched to provide like system-defined commands as much as possible, the illusion of walking). A simple Super 8 camera a rather loose definition of extensibility, but hookup ailows more complex, synchronized sequences one that is meaningful when speaking about inter- to be filmed, if desired. preters (a conclusion adapted from comments in [7]). Conclusions

Picture and Pattern Drawing Zgrass is designed to be a first programming language which encourages both novices and experts Zgrass has several predefined variables which to learn about color graphics, generate meaningful cause drawing on the screen when they are written and pretty displays, possibly make Super 8 movies, into. To display a point, you set variables xs and perhaps even access governmental databases and and ys to the x and y coordinate. When you set control electric train sets. The software is variable cs to a value from one to four, the point designed to be multi-leveled and rich with feed- is displayed with the color value indicated by the back. Considerable research into the teaching as- value of cs. There are also the "line," "box," and pects has been folded into the design. "circle" commands which draw vectors, and filled Continuing developmental elfort along these rectangles and ellipses on the screen. lines now concerns higher resolution displays, much faster mfcroprocessors, parallel programming Picture Animation techniques and connection to videodisks and other television equipment. Zgrass is one way you can Once a picture is drawn on the screen, all or control the amount of sex and violence on your tv part of it may be stored as a picture prototype set. with the "snap" command. Picture prototypes are pixel lists in this case and are kept in user 16k RAM rather than in the screen 4k RAM. So, a pic- ture is something you see on the screen and a pic- ture prototype (or "prototype" for short) is its representation in user memory. One then attaches the prototype to a vari- References able, time-based variable (a user-defined special variable whose value varies automatically over a [1] Nelson, Ted, The Home Compute__rr Revolution, given time period), hand control, or user-defined 1977, p. 79. function. The prototype is displayed with the [2] DeFanti, T.A., "The Digital Component of the "display" command. After that, anytime the vari- Circle Graphics Habitat," Proc. NC_~C, 1976. able or function changes, the prototype will be [3] DeFanti, T.A., Sandin, D.J., and Nelson, T.H., erased with an "exclusive or" write and rewritten "Computer Graphics as a Way of Life," with its updated translation or other transforma- Computers & Graphics, Vol. I, No. I, May tion with an "exclusive or" write. This technique 1975. lets pictures of one color pass over pictures of [4] Goldberg, A. and Kay, A., Smalltalk-72 another color without leaving holes (using stan- Instruction Manual, Xerox PARC #ss176-6, dard bit plane raster scan graphics techniques). March 1976. There is an interrupt level routine which manages [5] Papert, Seymour, A Computer Laboratory for movements of prototypes and a host of other de- Elementary Schools, Logo Memo I, MIT Artifi- tails, along the lines of a conventional refresh cial Intelligence Lab, October, 1971. graphics driver. The user has a simple way to in- [6] Alpert, D., and Bitzer, D., "Advances in dicate wha~ maximum percentage of time should be Computer-Based Education, Science, Vol. 167, allocated to interrupt level updating, the rest March 1970. being left for command processing. [7] Feldman, J.A., "Proceedings of the Extensible The same interrupt routine also manages pic- Languages Symposium," SIGPLANNOTICES, Vol. ture prototype lists made up of lists of points, 4., No. 8., August 1969. vector endpoints, box and circle drawing informa- tion. With the 16k extension, rotation and scal- Addendum: Zgrass Command List (in addition to BASIC) ing of these lists is possible. Prototype lists, of course, have to be built up rather than snapped using options to the line, box and circle com- (The commands beginning with a '*' are in the 16k mands. The user can access individual endpoints extension.) (Not all options are indicated.) and manipulate the prototype as a whole. Of

36 command name function box draws a rectangle on the screen & select causes picture prototypes to be has options for building picture switched round-robin fashion on prototype lists the screen *change changes t~e values of an endpoint snap takes a screen image in rectangu- in a picture prototype list lar bounds and makes it into a circle draws an ellipse on the screen & movable picture prototype has options for building picture sync tells the system how much time to prototype lists devote to interrupt-level updating clear clears the screen versus command processing *close closes off an open picture proto- *rip allows a macro to be executed at type list interrupt level (stands for "very colors chooses 4 colors of 256 for screen important program") use *compile compiles code for speed copy makes a copy of a picture proto- type with a new name delete deletes and reclaims storage of a named thing display causes a picture prototype to be exclusive or'ed onto the screen and be updated when necessary *film sets up filming mode for a Super 8 camera *fetch retrieves a given endpoint in a picture prototype list get gets a macro, array, picture pro- totype list, etc. from tape, disk, etc. group collects picture prototypes into a group which can be referenced with a single name. Transformations may be done to the group as a whole or to individual members. help prints commands and required argu- ment types ieee provides interface to IEEE bus input used to input numbers, strings from terminal or passed argument lists line draws a vector & has options for building picture prototype lists memory gives a usage map of memory move attaches a picture prototype to two variables, devices, etc. so that when they change, the proto- type is automatically erased and redrawn in the new position with options for "exclusive or" or "load/store" read and write to screen *onerror traps errors to a user's routines *open allocates storage and starts up a picture prototype list *pattern allows a pixel list to be directly built rather than snapped play interprets a string, array or pic- ture prototype as a musical score to be played by the three-voice synthesizer put stores a macro, array, picture prototype list, etc. on tape, disk, etc. rename renames a named thing to a new name *rotate like move but the prototype is ro- tated *scale like move but the prototype is scaled

37