Skip to main content

Macintosh BASIC BYTE magazine 04 1984

  • PublicationBYTE
  • Pages11
  • SourceMacintosh_BASIC_BYTE_magazine_04_1984.pdf
← Magazines Macintosh BASIC BYTE magazine 04 1984
/ 11
Source: VintageApple.org — Complete 1975–1998 run, restored by Steve M.
Page 1
Loading…
Text content (OCR)
Macintosh BASIC A semicompiled language with tools designed to simplify the writing of code Scot Kamins Technology Translated Inc. Since so many things about Apple's new Macintosh computer are differ- ent from other computers, it should come as no surprise that Donn Denman’s Macintosh BASIC is also different. Briefly stated, Macintosh BASIC is a semicompiled, multitask- ing, structured language system (without line numbers), complete with a full-screen text editor and a highly sophisticated debugger, that takes advantage of many of the Macintosh’s unique features. This ar- ticle describes what is unique about the language. Macintosh BASIC is semicompiled. When you type in a new program line, the line is immediately passed to a part of the system called the B- F. Source of RECTANGLES @ Edit Search Program Operate code generator. This generator com- piles the program line and updates the program data structures. The system checks the syntax of the line as the line is compiled and provides immediate feedback as to the line's general lexical correctness. Later, when the program is executed, the compiler makes another quick pass through the program (about 2 sec- onds for a 50K-byte program) to check the integrity of its control struc- tures. Assuming there are no final compilation errors, program execu- tion continues. The compact B-code is then interpreted, making for a very fast BASIC. Macintosh BASIC is quite large (48K bytes), and it can grow. It is v2=v2-5 FRAME RECT hI,vih2,v2 IF v1=380 then EXIT Test Pattern Source of MIRRORS Figure 1: Multitasking in Macintosh BASIC. 318 BYTE April 1964 INVERT ROUNDRECT h1,v1:2,V Do IF vi= 0 then EXIT x=mousex y=mousey gosub drawit: RECTANGLE x=300-x MIRRORS drawit: = wi] ee = ne CG Te segmented; about 32K bytes live in memory at any time, leaving about 50K bytes for program and variable table space. (Actually, because of the CALL command, programs can be virtually any length.) If a program needs a part of BASIC that isn’t in RAM (random-access read/write memory), such as formatted output, the editor, the debugger, or some other large code segment, it loads in from the disk. Macintosh BASIC lets you execute any number of programs simultane- ously and develop one or more ad- ditional programs at the same time (see figure 1). Each time a line of code is interpreted, the system checks for other events that might need atten- tion and handles them accordingly. Each program is granted a fixed amount of execution time in 1/60-sec- ond increments or any interval set by the programmer. When a program’s time slice is up, the system moves to the next program for interpretation. No line numbers are required in Macintosh BASIC. You get around the program by branching to sections of code identified by labels. You can use numbers, but labels tend to be a lot more meaningful and make trac- ing program flow much easier. Environment In most BASICs, the entire display area is ordinarily occupied by the program listing or by the output. In Macintosh BASIC, the display area, called the desktop, is typically oc- cupied by a variety of graphics-and text material. Most material appears in windows, sections of the desktop that can grow, shrink, or move at the discretion of the programmer. Figure 2a shows the BASIC desktop with three copies of the same program in windows of different sizes. Listing 1 shows what the whole program looks like; you can't see all of it because all of it won't fit in the viewing area of the Listing window. Figure 2b shows what running the program produces. Note that none of these windows shows an entire program; there are more lines in the program than will fit in any of the visible areas. To see the rest of the program listing, you press the mouse button with the pointer on the down arrow in the scroll bar (located at the right of the window), revealing the rest of the code. When a Macintosh BASIC program is executed, the Listing window is overlaid by an Output window that displays any text or graphics pro- duced by the executing program. Both the Listing window and the Output window can be (and often are) displayed at the same time, mak- ing program development and debugging easier than in traditional environments. Macintosh BASIC’s tools and com- mand words (verbs that affect pro- grams as a whole, like RUN, LOAD, and SAVE) appear in menus whose titles are listed in the menu bar run- ning across the top of the desktop. To choose a menu item, use the mouse to move the pointer to the menu you want, press and hold the mouse button, and drag the pointer down to the specific tool or command you want. The Macintosh BASIC interactive programming environment makes writing code a lot easier than do most other BASICs because of the huge variety of tools. The tools include those available to every Macintosh application (specifically, the desk ac- cessories, the screen-oriented editor, | and the Clipboard) and a set of special development and debugging aids designed for the language, in- cluding flexible search and replace capabilities, several printing options, and a very sophisticated debugger. Desk Accessories Among the desk accessories, ac- cessible from the desktop menu, pro- grammers will find the Calculator, the Note Pad, and the Clock most useful (see figure 3). The Calculator is a simple four-function calculator useful for doing quick operations; you can use the system editor to transfer calculation results into your program code. The Note Pad lets you write memos to yourself about spe- cial sections of code that need atten- tion, or anything else you need to remember but don’t want to scribble on a piece of paper that will quickly get lost. The Clock is extremely useful, either to time program execu- Macintosh BASIC tion or to remind a hacker when to eat lunch. You can have all these tools (and any others, for that matter) operating while you develop and run programs. Using the mouse and the screen- oriented editor, you can cut, copy, paste, or entirely remove all or part of a program. In combination with the Clipboard, the system-wide text and graphics buffer, you can quickly and easily move whole blocks of code from one section of a program to another section of the same program or to a different program (see figure 4). Additionally, you can move material into (or out of) the BASIC programming environment from any other Macintosh application in- cluding a spreadsheet, a word pro- cessor, or the Mac Paint graphics application. Also on the Menu The other menus provide access to tools specific to Macintosh BASIC. Among the tools seldom seen in other systems are Search and Re- place, in the Search menu; Debug, in the Program menu; and Directory, in the Operate menu. The search tools help you to locate and/or change any group of charac- ters, either once or repeatedly, match- ing or ignoring the case of the alpha- BYTE April 1984 319 (2a) @ Edit Sd&rch Program Operate Source of whizbang.city ! Whizbang.City ! by John Scribblemonger | V2.0 12/25/83 horiz.cord=512/4 vert. cord=342/4 object.size=3 F flag=1 obj Fi DO IF flag then gosub Frame Oval: ELSE object.Size-object.Size+1 gosubd Invert Rectangle: ENDIF object.Size-object.Size+2 IF mouseB THEN ra obiect.Size=3 =| Je Source of whizbang.cit ENDIF object. Size=object.Size IF mouseB THEN object. Size=3 Flag=1 - Flag ENDIF LOOP Temp.Set: tishoriz.cord-object si t2=vert.cord-object.siz t3=horiz.cord+object.si t4=vert.cord+object.siz = Whizbang.Cit Figure 2: Three “views” of the same program in windows of different sizes (2a). None of these windows shows an entire listing (see listing 1 below). Figure 2b shows the Output window for the program Whizbang.city (listing 1). betic characters. These search tools can be extremely useful for changing a nondescriptive variable to one that makes more sense—say, changing all occurrences of the variable E7 to EMPLOYEE.7—or to replace im- proper spellings in variable names, labels, or prompting phrases. Listing 1: The Whizbang.city program. . Whizbang.City ; by John Scribbl emonger ‘ V2.0 12/25/83 horiz.cord=512/4 vert.cord=342/4 object.size=3 flag=i dO IF flag then gosub Frame.Oval: ELSE object.Size=object.Size+i gosub Invert.Rectangle: ENDIF object.Size=object.Size+2 IF mouseB THEN object.Size=3 Flag=1l - Flag ENDIF LOOP Temp .Set: ti=horiz.cord-object.size t2=vert.cord-object.size t3=horiz.cord+tobject.size t4=vert.cordtobject.size Return Frame .Oval: Gosub Temp.Set: Frame Oval t1,t2; t3,t4 Return Invert.Rectangle: Gosub Temp.Set: Invert Rect t1,t2; t3,t4 Return 320 BYTE April 1984 The Program menu (see figure 5) lists the command verbs, or menu selections, programmers tend to use most during code development, in- cluding certain commands not avail- able or meaningful in other BASIC systems. Most notable here are the two Save commands, the Update command, and the Debug com- mand. NotePad Try changing variable MAXOFF to some other permutation of the OFFSET Then see if Donn can make the PENPSe DSSS Source of LINETEST = € Edit Search Program Opegate Selecting Save Source sends an ASCII (American National Standard Code for Information Interchange) text copy of the program to the disk, just as it appears in the Listing win- dow. Save Object stores only the pro- gram’s B-code—that is, the code in its compiled form. You can retrieve, edit, and execute a program saved as text, but a program saved as code can be Clock Tue, Dec 06, 1963 11:34:56 AN Calculator efficy DO MAX= 100 SPACING= 10 FOR DELTA=1 TO SPACING stuff LET OFF SET=X+DELTA PLOT 0,MAXOFF ; PLOT MAXOFF MAX; FOR X=SPACING TO MAX-SPACING STEP Sh LET MAXOFF =[MAX-OFF SET SET PENPOS OFF SET,0 Figure 3: Macintosh desk accessories run concurrently with program development. The Note Pad (in the background) has eight pages and holds 256 bytes per page. executed only. Code files are safe from tampering; once they go to disk, they cannot be viewed or changed. Thus, profit-minded programmers can protect their code from the pry- ing eyes of unscrupulous code pilferers. Update lets you modify running programs. You can change a program line in the Listing window, select Update from the Program menu, and watch the immediate ef- fects of the change in the Output window. Choosing Debug turns on the de- bugging environment. When this command is in effect, the normal Listing window is replaced by the one in figure 6. The finger symbol moves up and down the listing, pointing to the line of code currently being executed. Simultaneously, the system displays a dynamic variable and breakpoint table showing the current values of all non-array variables; all of these values can be changed while the code being de- bugged is executing (updating is automatic). You can set and clear breakpoints for any or all variables. The program can break whenever a particular var- iable is referenced or changed or is equal to, less than, or greater than some value or other variable. When the program hits a breakpoint, execu- tion halts and it waits for the pro- grammer to determine what happens next. By using the mouse to press a button displayed on the desktop beneath the Listing window, you can make execution resume at full speed until the next breakpoint, full speed through the next control block (a DO/LOOP, FOR/NEXT, SELECT CASE, subroutine, etc.), or go im- mediately into a single-step mode. In single-step mode, only one line of code is executed; the programmer tells BASIC to execute each subse- quent line of code by pressing the space bar. Additionally, there’s an alphabetical list of all the labels in the program. This feature makes it easy for you to see why you got that “undefined label” error when your program is trying to branch to CALL.YOUR. MOTHER: instead of to CALL. YOUR.MOM:. Function BIN DIAL FORMATS KBD MENU MOUSEB | MOUSEX | MOUSEY | TYP Description tells which interactive button has been pushed tells which interactive dial has been activated Macintosh BASIC equivalent of PRINT USING gives the ASCII code of the most recent key pressed tells when an interactive menu is chosen yields the state of the mouse button returns the horizontal position of the mouse pointer returns the vertical position of the mouse pointer tells the data type of the next item in the input stream (numeric, string, or picture) Table 1: Macintosh BASIC numeric data types. Range 1E +— 1022 1E +- 126 1E +-4000 +-— 32767 +-—9E18 Oorl Storage Form Symbol Accuracy Double-precision real none 15 Single-precision real | 7 Extended-precision real \ 18+ Short integer % 4+ Long integer # 18 + Boolean z 1 Table 2: Some Macintosh BASIC functions not available in most other BASICs. “Interac- tive” refers to graphics objects (menus, buttons, dials) that appear on the screen and can |_be manipulated with the mouse. i * tlshoriz.cord-object size t2=vert.cord-object size Source of linetest SET PENPOS OFF SET,O Select All A PLOT O,MAXOFF ; Copy Picture PLOT MAXOFF MAX; PLOT MAX ,OFF SET; The Clipboard FOR X=SPACING TO MAX-SPACING STEP SPAQ LET OFFSET=X+DELTA _ TOR X=SPACING TO MAX-SPACING STEP] {LET OFFSET=X+DELTA LET MAXOFF -MAX-OFF SET PLOT OFF SET,0; Figure 4: Material in the Clipboard, just copied from the Linetest program on the right, is about to be pasted into a second program. The source lines in Linetest remain undisturbed. BYTE April 1984 321 The Operate menu holds com- mands you might typically use to test programs. RUN is the usual BASIC command to execute a program (something in this language has to be usual). In Macintosh BASIC, Halt and Continue are useful for checking the program’s Output window and variable table from time to time. The Directory selection produces a menu of all BASIC programs on the disk; drag the pointer to one of the pro- gram names and BASIC loads the program for you. The Quit command is your way out of BASIC, returning you to the main Macintosh system (called the Finder). With Macintosh BASIC, you can obtain four kinds of hard-copy print- outs: everything on the screen, everything in the Listing window in- cluding material you can't see, all text and graphics in the Output window, and material sent to the printer by the running program itself. The listings in this article were all printed directly from the Macintosh. The Language Variable names in Macintosh BASIC can be of any length, and all characters in the name are signifi- cant. The first character must be alphabetic; the rest can be nearly anything you can type from the key- board, which includes the entire ASCII code set plus nonroman and other special characters. The only ex- ceptions are arithmetic symbols and other delimiters (comma, semicolon, colon, and space). Macintosh BASIC supports array variables for all eight data types and subtypes discussed later. Arrays can have any number of dimensions, and each dimension can have 32,767 elements. All arrays must be dimen- sioned before use. When you DIM an array, you can specify ranges for ele- ment numbers. Thus, you can say DIM YEAR%(1900 TO 1986) to specify an 87-element integer (the % denotes integer) array whose first number is 1900 and whose last number is 1986. You can also stipulate ranges for separate dimensions, as in DIM NAME&(10 TO 75, 165 TO 300). There are three main data types in the language: strings, pictures, and numerics. Strings are pretty stan- dard; they are enclosed in quotes, either single or double, and their variable names end in the usual BASIC symbol, §. You create a picture data type by either creating a shape or a whole picture in a graphics application (like Mac Paint) and transferring it to BASIC through the Clipboard or by drawing a shape in BASIC using various graphics commands. You can then assign the shape to a picture variable; the variable name ends in the symbol @. The numeric data type is further divided into six subtypes: Booleans, two types of integers, and three types of reals. Table 1 shows the storage form, symbol, range, and digits of ac- curacy for each subtype. In addition to the five standard arithmetic operators (+, —, * /,*), Macintosh BASIC includes DIV for integer division and MOD for modulo, defined as the arithmetic re- mainder of integer division. The rela- tional operators (<, =, >, <>, ><) and logical operators (AND, OR, and NOT) are standard; the string concatenation symbol is &. Macintosh BASIC has the usual range of arithmetic, trigonometric, and string functions, including DEF FN (user-defined functions) for both numbers and strings. Table 2 de- scribes many of the functions that don’t appear in most other BASICs or are unique to Macintosh BASIC in some major way. The term “interac- tive,” appearing in several of the descriptions, refers to graphics ob- jects (entire menus, buttons, dials) you can make appear on the screen and can manipulate with the mouse. Control Structures Most flow of control statements in Macintosh BASIC take the form of control structures. The language has a GOTO statement, but you never have to use it. In fact, the only place the GOTO statement appears in the language manual as part of a code ex- ample is in the section describing GOTO itself. Besides the familiar FOR/NEXT structure and the DO/EXIT/LOOP structure, in which all statements be- tween the keywords DO and LOOP are repeated infinitely (EXIT lets you escape the loop), this BASIC includes some variations on new structures proposed in the 1982 ANSI (Ameri- can National Standards Institute) BASIC proposal. A multiline IF/ THEN/ELSE/ENDIF lets you execute DOUBLE PRECISION e FORTRAN e INDEXED ARRAYS e CHARACTER VARIABLES e UNLIMITED Circle 349 on inquiry card. CASES © VARIABLE RECORD LENGTHS e MISSING DATA ¢ RELATIONAL DATABASE ¢ REPORT GENERATION e NUMERICAL AND CHARACTER MULTIPLE KEY SORT/MERGE e IF... THEN...ELSE ¢ FOR...NEXT ¢ GOTO e INTERACTIVE/BATCH ¢ ASCII/BINARY FILES e SCATTERPLOTS « HISTOGRAMS e CONTOUR PLOTS e MULTI-FUNCTION PLOTS ¢ BOX PLOTS ¢ STEM-AND-LEAF DIAGRAMS ¢ PROBABILITY PLOTS ¢ BASIC.STATISTICS ¢ BREAKDOWNS e MULTI-WAY TABLES ¢ LOG-LINEAR MODELS ¢ PAIRWISE/LISTWISE CORRELATIONS ¢ MULTIPLE REGRESSION ¢ POLYNOMIAL REGRESSION ¢ STEPWISE REGRESSION e WEIGHTED LEAST SQUARES e MULTIVARIATE REGRESSION e LEAST SQUARES ANOVA ¢ ANOCOVA « REPEATED MEASURES ¢ MANOVA e GENERAL LINEAR MODEL ¢ PRINCIPAL COMPONENTS ¢ MULTIDIMENSIONAL SCALING ¢ CLUSTER ANALYSIS SYSTAT MS-DOS,” PC-DOS,”" CP/M,” UNIX 1127 ASBURY AVENUE EVANSTON, IL 60202 BYTE April 1984 CALL REPUBLICAN PRIMARY BALLOU! CASE “COMMUNIST” (312) 864-5670 323 Sa The Operate menu holds com- mands you might typically use to test programs. RUN is the usual BASIC command to execute a program (something in this language has to be usual). In Macintosh BASIC, Halt and Continue are useful for checking the program’s Output window and variable table from time to time. The Directory selection produces a menu of all BASIC programs on the disk; drag the pointer to one of the pro- gram names and BASIC loads the program for you. The Quit command is your way out of BASIC, returning you to the main Macintosh system (called the Finder). With Macintosh BASIC, you can obtain four kinds of hard-copy print- outs: everything on the screen, everything in the Listing window in- cluding material you can't see, all text and graphics in the Output window, and material sent to the printer by the running program itself. The listings in this article were all printed directly from the Macintosh. The Language Variable names in Macintosh BASIC can be of any length, and all characters in the name are signifi- cant. The first character must be alphabetic; the rest can be nearly anything you can type from the key- board, which includes the entire ASCII code set plus nonroman and other special characters. The only ex- ceptions are arithmetic symbols and other delimiters (comma, semicolon, colon, and space). Macintosh BASIC supports array variables for all eight data types and subtypes discussed later. Arrays can have any number of dimensions, and each dimension can have 32,767 elements. All arrays must be dimen- sioned before use. When you DIM an array, you can specify ranges for ele- ment numbers. Thus, you can say DIM YEAR%(1900 TO 1986) to specify an 87-element integer (the % denotes integer) array whose first number is 1900 and whose last number is 1986. You can also stipulate ranges for separate dimensions, as in DIM NAME3(10 TO 75, 165 TO 300). There are three main data types in the language: strings, pictures, and numerics. Strings are pretty stan- dard; they are enclosed in quotes, either single or double, and their variable names end in the usual BASIC symbol, $. You create a picture data type by either creating a shape or a whole picture in a graphics application (like Mac Paint) and transferring it to BASIC through the Clipboard or by drawing a shape in BASIC using various graphics commands. You can then assign the shape to a picture variable; the variable name ends in the symbol @. The numeric data type is further divided into six subtypes: Booleans, two types of integers, and three types of reals. Table 1 shows the storage form, symbol, range, and digits of ac- curacy for each subtype. In addition to the five standard arithmetic operators (+, —, * /,*), Macintosh BASIC includes DIV for integer division and MOD for modulo, defined as the arithmetic re- mainder of integer division. The rela- tional operators (<, =, >, <>, ><) and logical operators (AND, OR, and NOT) are standard; the string concatenation symbol is &. Macintosh BASIC has the usual range of arithmetic, trigonometric, and string functions, including DEF EN (user-defined functions) for both numbers and strings. Table 2 de- scribes many of the functions that don't appear in most other BASICs or are unique to Macintosh BASIC in some major way. The term “interac- tive,’ appearing in several of the descriptions, refers to graphics ob- jects (entire menus, buttons, dials) you can make appear on the screen and can manipulate with the mouse. Control Structures Most flow of control statements in Macintosh BASIC take the form of control structures. The language has a GOTO statement, but you never have to use it. In fact, the only place the GOTO statement appears in the language manual as part of a code ex- ample is in the section describing GOTO itself. Besides the familiar FOR/NEXT structure and the DO/EXIT/LOOP structure, in which all statements be- tween the keywords DO and LOOP are repeated infinitely (EXIT lets you escape the loop), this BASIC includes some variations on new structures proposed in the 1982 ANSI (Ameri- can National Standards Institute) BASIC proposal. A multiline IF/ THEN/ELSE/ENDIF lets you execute DOUBLE PRECISION e@ FORTRAN e INDEXED ARRAYS e CHARACTER VARIABLES e UNLIMITED CASES ¢ VARIABLE RECORD LENGTHS e MISSING DATA ¢ RELATIONAL DATABASE ¢ REPORT GENERATION e NUMERICAL AND CHARACTER MULTIPLE KEY SORT/MERGE e IF... THEN ...ELSE e FOR...NEXT e GOTO @ INTERACTIVE/BATCH e¢ ASCII/BINARY FILES e¢ SCATTERPLOTS «© HISTOGRAMS e CONTOUR PLOTS e MULTI-FUNCTION PLOTS @ BOX PLOTS ¢ STEM-AND-LEAF DIAGRAMS ¢ PROBABILITY PLOTS ¢ BASIC. STATISTICS ¢ BREAKDOWNS e¢ MULTI-WAY TABLES ¢ LOG-LINEAR MODELS ¢ PAIRWISE/LISTWISE CORRELATIONS ¢ MULTIPLE REGRESSION e POLYNOMIAL REGRESSION ¢ STEPWISE REGRESSION e¢ WEIGHTED LEAST SQUARES e¢ MULTIVARIATE REGRESSION e LEAST SQUARES ANOVA « ANOCOVA « REPEATED MEASURES © MANOVA e GENERAL LINEAR MODEL ¢ PRINCIPAL COMPONENTS ¢ MULTIDIMENSIONAL SCALING @ CLUSTER ANALYSIS SYSTAT Circle 349 on inquiry card. MS-DOS,” PC-DOS,” CP/M,” UNIX 1127 ASBURY AVENUE EVANSTON, IL 60202 (312) 864-5670 BYTE April 1984 323 Listing 2: A multiple-line IF control block. BOE Source of IF...THEN/ELSE/ENDIF IF DAY.TEMP > HOT THEN CLOTHES$ = SWIMSTUFF$ | GOSUB BEACH: ELSE CLOTHES$ = WALK.STUFF$ GOSUB CITY: ENDIF as many statements as you want if a condition is either true or false (see listing 2). An extremely flexible SELECT CASE/ENDCASE construct takes the place of the restrictive ON...GOSUB statement. It enables nee oa Pies : the program to transfer execution to ss Hea )—2> | sets of statements based on the value pare feed 770 <A . of some expression. There can be Mansar 40 ets multiple statements for each case or a 739 ‘GE range of cases (see listing 3). The lan- i oF tele _ 5 | guage has several interrupt control got ae | structures, all of which are based on “99 eu} a structure bounded by the keywords Se ue ee ; 3) WHEN and ENDWHEN; these inter- DeMatha | rupts let you determine which code is executed if any one of a number of events occurs anytime during pro- gram execution. You can plan inter- oe, rupts to occur whenever a key is rSi9 Zemin 1236 "| pressed, when the mouse is moved 497 | Amdek 300 198 (RSF or its button pushed, when an error etoile =) occurs, or at other times (see listing : oo 4). eee err IBM Apple Subroutines are handled in the Dave Nn ce ie Tarn, “mH Usual way (except that the language wane ie ™ | uses GOSUB labels); additionally Fail 299 BFS: Soluhons 7) there's a CALL statement that enables PP Mecae 2560 He ae >| entire programs to act as subroutines. 2 Mes tl 7 CALL lets you pass parameters back rsa and forth with the summoned pro- gram; when the called program ends, control returns to the statement following CALL in the source - 1019 Sweet-P THis. TV.920.. 0... Qume 1028. pb erly Management 329 OP || Graphics sen ag] ee ee Macintosh BASIC provides com- mands for both static and animated graphics on a bit-mapped 512- by 342- point screen. You can plot points with the PLOT command (controlling the size of the pixels with PENSIZE) or create shapes with the keywords RECT (for rectangle), ROUNDRECT (a rectangle with rounded corners), or OVAL. Shapes can be outlined “—= Circle 93 on inquiry card. Listing 3: A SELECT CASE construct using strings (3a) and a SELECT CASE construct using numerics (3b). (3a) = Je Suurce of SELECT CASE/ENDCASE (STRINGS) SELECT CASE PARTY$ CASE “REPUBLICAN” CASE “COMMUNIST CALL MILITIA CASE ELSE ENDSELECT CALL REPUBLICAN PRIMARY BALLOT CASE “DEMOCRAT”, “TORY”, INDEPENDENT$ GOSUB FURTHER.CHOICE: CALL GENERAL PARTY BALLOT CASE LEFTS(PARTY$, 3) = “SEP” CALL SEPARITIST PRIMARY BALLOT CALL GENERAL PRIMARY BALLOT (3b) [EOS Source of SELECT CASE/ENDCASE (NUMBERS © RANGES) SELECT CASE AGE CASE 2, 4,5 GOSUB PRESCHOOL : CASE 6 TO 12 CASE >70 ENDSELECT (FRAME), filled in (PAINT) with a preestablished shade or pattern (SET PATTERN), complemented from the last appearance (INVERT), or erased altogether (ERASE). The various shapes can then be combined into a single picture and stored in a picture variable (RECORD PICTURE) and re- called (DRAW PICTURE). For ani- mated sequences, you can ROTATE, SCALE, and ANIMATE a picture, moving it across the display. All graphics appear within the Output window, so your Listing and Debug- ging windows can coexist with a run- ning graphics program. Disk File Structures Disk file structures have many op- tions. I will cover only the major highlights; many of the available statements and options are not ex- amined here. GOSUB GRAMMAR. SCHOOL: CASE 15, 18 TO 35, VAL (OLD$) CALL CHECK DEMOGRAPHICS GOSUB MIGHT BE RETIRED: There are three types of file organization: sequential (serial access for text data), stream (serial access for binary data), and relative (random ac- cess, usually for text data). Length of a record in a relative file must be set in advance, but it can be any length Listing 4: The interrupt construct for errors and keypress. ff Source of WHEN / ENDWHEN WHEN ERR CALL ERROR.CHECK GOSUB SECOND.CHANCE: END WHEN | WHEN KBD PRINT “WHICH MENU DO YOU NEED?” | GOSUB MENU CHOICE: CALL MENU$ END WHEN Circle 58 on inquiry card. IBM-PC/XT or PC compatible IEEE-488 INTERFACE BOARD e Implements the entire IEEE-488 standard — transfer commands and data, perform serial and parallel polling. e A resident firmware interpreter simplifies programming and accepts any ASCII string or code including Tektronix Standard Codes and Formats and IEEE-488 command mnemonics. Interpreter routines support BASIC, PASCAL, C and other languages. e Supports the PrtSc (print screen) key, and all BASIC print statements for IEEE-488 printers and devices e Small size— see BYTE 11/83, p. 314 e Accepts a standard IEEE-488 cable. e Uses only 16 bytes of RAM and no I/O ports. e A 116 page Reference Manual provides a tutorial and programming examples for digitizing, interactive bus control, bus diagnostics, and many other applications. e $395 complete. There are no extra software or cabling charges. CAPITAL EQUIPMENT CORP 10 Evergreen Avenue Burlington, MA. 01803 (617) 273-1818 ss Machines ( BYTE April 1984 325 326 BYTE April 1984 Circle 121 on inquiry card. | you choose; there is no limit (beyond memory) to the number of records in a file. The keyword RECTYPE deter- mines how data is stored: display files are standard ASCII and can be shown in a window or be printed; in- ternal files are binary and are for storage only. You can designate any file, no matter what type, to be an in- put file (a file which can only be read), an output file (to which data is sent but not retrieved), or OUTIN (accessible for both input and out- put). You can later change a file's ac- cess designation. You create a file, and later make it accessible for use, with the OPEN statement. OPEN sets the channel number (1 through 99) that links the file to the system and the name of the file associated with the channel: OPEN #3: NAME “Macmumble” The preceding statement opens a file named Macmumble and assigns it to channel #3. Since no further param- eters are given, the file uses the default parameters, which makes it a sequential display file enabling OUTIN access. The following state- ment opens a relative file with a record length of 250 characters for the storage of ASCII text data. OPEN #54: NAME “Foobar”, AC- CESS OUTPUT, ORGANIZA- TION RELATIVE, RECSIZE 250 The OPEN statement is intelligent: after you've opened a file, you don't have to restate the organization, record size, or RECTYPE each time you use it. Assuming you've issued the CLOSE statement for the file “Foobar” described above, you can later access it again by just saying OPEN #54: NAME “Foobar”. Up to 10 channels can be open at the same time. All devices (like the serial port, the printer, windows on the desktop) can be accessed in the same manner as files. Device names are specified in the same way as any filename except that the first character in the name is a period. ERG/68000 a) O Go OOOO00000 MINI-SYSTEMS Full IEEE 696/S100 Compatibility HARDWARE OPTIONS 8MHz, 10 MHz, or 12 MHz 68000/68010 CPU 68451 Memory Management Hardware Floating Point Multiple Port Intelligent 1/0 64K/128K Static RAM (70 nsec) 256K/512K/1MB Dynamic RAM (150 SMD Disk Interface %" or Ye" Tape Backup 5%" or 8" Floppy Disk Drives 5MB-474MB Hard Disk Drives 7/10/20 Siot Back Plane 20 or 30A Power Supply Desk Top or Rack Mount Encl. SOFTWARE OPTIONS 68KFORTH' Systems Language CP/M-68K?0/S with C, 68K-BASIC', 68KFORTH', FORTRAN 77, EM80 Emulator, Whitesmiths’ C, PASCAL IDRIS? O/S with C, PASCAL, FORTRAN 77, 68K-BASIC', CIS COBOL‘, INFORMIX: Relational DBMS UNIX® SYS V O/S with C, PASCAL, FORTRAN 77, BASIC, RM COBOL’, ADA‘, INFORMIX:, Relational DBMS VED 68K Screen Editor Motorola's MACSBUG and FFP Package Trademark ‘ERG, “Digital Research, Whtitesmiths, “Micro Focus, *RDS, Inc., Bell Labs, "Ryan McFarland, "U.S. DoD 30 Day Delivery - OEM Discounts since 1974 Empirical Research Group, Inc. 328 P.O. Box 1176 Milton, WA 98354 (206) 872-7665 BYTE April 1984 Listing 5: Five programs used for benchmark tests (5a). Listing 5b is the Sieve benchtest pro- gram using Print Quick from the Program menu. (5a) a= Suurte of gusubs B= print time$; at start’ | for x=1 to 5000 gosub foo: next x print time$; when done’ end foo: return EL= Source of loops = | Loops Print “Start at “:time$ FOR I=1 TO 5000 NEXT | PRINT “Done at “times EL Source of divs print time$; at start’ for x=1 to 5000 Yy=x div 3 next x print time$;' when done’ | = Source of divides print time$; at start’ for x=1 to 5000 y=x/3 next x print time$;’ when done’ | = J= Source of mid$ B® print time$; at start’ b$=‘Apple Computer Inc’ for x=1 to 5000 a$=mid$(b$,6,7) next x print time$; when done’ print a$ end (5b) ! Sieve $4=8190 dim flags%(s%+1) print “start "“;times count%=0 for iz%=0 to s% Fflags“z(izd=1 next iZ% for i%=0 to s% if flags%CiZ)=0 then goto 250 primexz=i+ixz+3 K“~=i“~A+primer% 200 if KZ~>s% then goto 240 flags“ kx%)=0 K“~=KA~A+ pr ime% goto 200 240 countZ%=count%+1 250 next ix print ‘done ‘’;times print count% 3° primes’ Time Test (seconds) Empty GOSUBs 3.0 Empty FOR/NEXT loop 15 Midstring search 9.0 Real divide (by 3) 18.0 Integer divide (by 3) 3.0 Eratosthenes Sieve (1899 primes) 31.5 Table 3: Benchmark results. OPEN #1: NAME “.PRINTER”’ OPEN #35: NAME “SERIAL”, ACCESS INPUT OPEN #17: NAME “WINDOW: FOOBAR’” The first of the three lines above assigns channel 1 to the printer. Because printers by their nature are write-only devices, you don’t need to specify the file as access output. The second line provides the serial port channel #35; its access mode is specified because serial ports are two- way. The third line addresses the Output window created by the pro- gram FOOBAR. This enables some other file either to add to the Output window or to read the window’s contents. To send and retrieve data, use the keywords PRINT and INPUT for ASCII text (display files) and WRITE and READ for binary data (internal files). Potential overwriting or “out of data” problems are handled with the key phrases IF THERE and IF MISSING. PRINT #7, RECORD 53, IF THERE THEN GOSUB DONTWRITE. OVER:: A$ The preceding statement sends a field of text data (A$) to record 53 of the relative file on channel #7. If that record already exists, then program control branches to the subroutine called DONTWRITE.OVER:. The first colon after the subroutine name is re- quired by label syntax, the second by file syntax. The following example retrieves two fields of binary data from an in- ternal file hooked to channel 67 and stores them in real variable NUMBER and string variable NAMES; if there’s no data there, control branches to a program named PROTECTIT. READ #67, IF MISSING THEN CALL PROTECTIT: NUMBER, NAME$ The Macintosh provides some fairly sophisticated sound stuff, and BASIC takes advantage of it. You can control the volume, pitch, timbre, and amplitude of each of four in- dividual tones. You can also play any note over a four-octave range. (You can play over a greater range, but really low notes sound too soft and really high ones sound too shrill for my ears.) Set-options are system parameters that you can control. You can ASK or SET the current value of any set- option. There are set-options for nearly all parts of the language, but the most important ones have to do with graphics, windows, and text. Graphics options include the height and width of the penstroke and the pattern the penstroke produces. Win- dow options control how much of a program’s output is displayed on the desktop in pixels, how large the en- tire graphics area is, and what logical boundaries to associate with physical ones. Text set-options include the current position of the insertion point (the mouse’s footprint), margins within which text is to appear, and the number of characters between tab stops. 330 BYTE April 1984 " @ Edit Search a === Source New he=512/4 Load #1 vc=384/4 Save Source #§ x=10 Save Object a a Print Quick — Debug z F nog Seen laa ag ENDIF X=X+10 IF MOUSEB THEN X=10 FLAG=1-FLAG ENDIF LOOP Zoic Operate INVERT RECT HC-X, YC-X;HC + X, VC+X ELSE INVERT OVAL HC-X,VC-XHC+X,VC+X Figure 5: A program menu with Save Object selected by the mouse. This command is used to save a binary version of a program. é@ Edit Search Program Operate labels from whizbang.cit Comment 1J== Source of whizbang.city = 006 DO 00? 008 cr IF flag then gosub Frame Oval: ELSE object .Size=object. 3] Frame Oval Invert.Rectangle draw an oval invert a rectangle Establish temp coo 010 O11 gosub Invert.Rectangl ENDIF Variable name Yalue Breakpoint 012 013 014 015 016 017 object.Size-object.Size+ IF mouseB THEN object. Size=3 Flag=1 - Flag ENDIF LOOP <> 128 = =66 Figure 6: The Macintosh BASIC Dynamic Debugger. The windows have been “shrunk” so that the major parts of all three would show. The Debugger adds line numbers for easy reference. Table 3 shows the results of some standard benchmark tests I ran on my Macintosh; the programs are shown in listing 5. I used the Macin- tosh’s internal clock to do the timing; the smallest increment it reports is in full seconds. I ran each test five times; all but the Sieve were run for 5000 iterations. The results of two similar trials were sometimes dif- ferent because the timing started in midsecond.™ Macintosh BASIC will be available in the summer of 1984 at a price of $99. The language will be known officially as Macin- tosh BASIC. This would seem to preclude its use on other Apple computers. Micro- soft BASIC also is available for the Macin- tosh; the price is $150. Scot Kamins is senior writer for Technology Trans- lated Inc. (1047 Sutter St., San Francisco, CA 94109), a technical writing firm.
mp.ls