← The Macintosh BASIC Handbook

The Macintosh BASIC Handbook

From the originals

34 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

PDF page 12

How to Use the Macintosh Basic Handbook

o How to Use the Macintosh Basic Handbook o • Sample Programs-one or more short sample programs, with output. These programs illustrate specific features of each command, in a succint form that you can easily type in and try out for yourself. • Applications-a discussion of the practical applications of the command and, in many cases, a long program that illustrates the command in actual use. These programs include: A line graph (PLOT) A bar graph (PAINT) A pie chart An analog clock A musical keyboard -among many others. (PaintArc) (TIME$), and (TONES) • Notes-a series of short notes on special features and advanced program- ming techniques. This fmal section often includes a cross-reference to the other keywords that are used in connection with the command. Where appropriate, a translation key shows how the command duplicates the features of keywords in two other popular forms of BASIC: Microsoft BASIC (for the Macintosh and IBM PC) and Applesoft BASIC (for the Apple II). The shorter entries may not have all five of these sections, but they all have at least the frrst two, Syntax and Description. Since commands often work together as a unit, this book has been orga- nized into main and secondary entries. The file I/O system, for example, uses a large number of minor keywords implementing a few central commands. Each minor word is included as a separate one- or two-page entry, but the comprehensive overview is contained under the central command, for example, OPEN#. You can fmd the information you are looking for either under the comprehensive entry or under the individual keyword-usually both. The following is a list of the major entries and the concepts they describe: CALL Subroutines and parameter-passing Fill Fill graphics operator (toolbox) FUNCTION User-defined functions IF Decision blocks and logical expressions

Reading notes: Line-break hyphenation and possible OCR errors such as 'succint', 'frrst', and 'fmd' in the source copy

Languages
English
PDF page 13

How to Use the Macintosh Basic Handbook

o How to Use the Macintosh Basic Handbook o MOUSEB- OPEN # OpenPoly OpenRgn PaintArc PLOT SELECT SET SetRect TOOLBOX Mouse button and programming techniques File I/0 commands Polygon shapes (toolbox) Region shapes (toolbox) Arc shapes (toolbox) Line graphics SELECT /CASE block structures Set-options Rectangle array structures (toolbox) General discussion of the toolbox command This book uses a number of typographical conventions for clarity in pro- gram listings. All BASIC keywords are boldfaced and capitalized. Toolbox words are boldfaced with initial capitals, and variables are printed with initial capitals, but no boldfacing. You are not required to follow these capitalizing conventions. Macintosh BASIC will recognize all keywords, toolbox names, and variable names, regardless of whether you type them as capitals or not. If you prefer, you can type everything as lowercase or everything as capitals-it will make no difference to the program's operation. Indentation is included in programs to highlight each level of nested control structures. You are not required to follow these indentation conventions, but you will make your programs more readable if you do. Macintosh BASIC will line up the left margin of every command according to the level of indentation that you set with the TAB key or space bar at the beginning of a line.

Reading notes: Reading order of the table-of-contents entries is partly scrambled in the extracted text

Languages
English
PDF page 14

Introduction: Oveniew of Macintosh BASIC

Introduction: Oveniew of Macintosh BASIC • Line Numbers • Control Structures • The Ten Data Types The Five Numeric Types String Type Character (Byte) Type Boolean Type Pointer Type Handles Type • Data files • QuickDraw Graphics • The Tuolbox Macintosh BASIC is a radically new approach to a programming language for a personal computer. Instead of merely adapting a version of BASIC that already existed, Apple decided to design a new language from scratch. The Macintosh is so different from the average computer that a Macintosh pro- gramming language must really be designed to fit the machine, not the tradi- tion. Only an exceptionally rich language designed specifically for the machine can tap the Macintosh's (ull speed and graphics power. The result was Macintosh BASIC, a very different language from the stan- dard BASIC used on other machines. In many ways, Macintosh BASIC ended up looking more like such powerful languages as Pascal and C, than the tradi- tional BASIC used on other machines. Macintosh BASIC, howevet; has enough of standard BASIC to allow an easy translation of programs from other forms of the language. An IBM PC or Apple Il BASIC program will usually run with only minor changes in Mac- intosh BASIC. Of course, a word-for-word translation of this kind will not take advantage of the many advanced features in the Macintosh BASIC lan- guage, but it can be very important if you're copying programs from maga- zines or from other computers. If you're translating programs, you will merely want to refer to the appropriate entries in this book, to check the differences in the commands' syntax.

Reading notes: Heading reads 'Oveniew', likely OCR error for 'Overview' Body text contains OCR-style errors such as 'Tuolbox' and 'Apple Il'

Printed product names
Macintosh BASIC · Macintosh · IBM PC · Apple Il · Pascal
Languages
English
PDF page 15

o INTRcbOUCTION o In time, however, you will learn to take Macintosh BASIC on its own level. Once you learn to use the powerful additions to the language, you will write Macintosh BASIC programs that are far more sophisticated than anything you can do with standard BASIC. Of course, the advanced commands of Macintosh BASIC cannot be easily translated into commands for the IBM PC or Apple II, but they will let your Macintosh do things you haven't seen on any other computer. This Introduction will give you an overview of the additions in the Macin- tosh BASIC language, so that you can orient yourself as you read the entries in this book. You can also find how Macintosh BASIC differs from other dia- lects (versions) of standard BASIC, so that you can know how to translate programs written on other computers. Line Numbers The most obvious difference between Macintosh BASIC and other forms of BASIC is the absence of line numbers. In most dialects of BASIC, every state- ment must have a line number, whether or not there is a GOTO or GOSUB statement that refers to it. These line numbers must be ordered consecutively, because the lines are sorted in numeric order. Typing and keeping track of line numbers can be one of the most frustrating parts of standard BASIC programming. Macintosh BASIC does away with all that. Line numbers are not required, because Macintosh BASIC uses a word-processor-like program editor. Instead, when a particular line will have to be referred to, Macintosh BASIC allows you to label it, either with a number or a word followed by a colon. You can still use statement numbers if you wish. When the line label is a number, the colon following the number is optional, so the standard BASIC statement numbers will be recognized as labels. The numbers, however, are not automatically sorted in ascending order, because in Macintosh BASIC the statements follow the order in which you place them on the screen. Control Structures You will rarely need to use either statement numbers or labels in Macintosh BASIC, because the language has a variety of control structures that let you write fully structured programs. A control structure is a block of statements that is treated differently from the standard top-to-bottom flow of the pro- gram. In Macintosh BASIC, these block structures include loops, decisions,

Reading notes: Source appears to be an introduction section of a programming manual; no primary heading is printed in the supplied copy. Source text ends mid-sentence at 'loops, decisions,'.

Printed product names
Macintosh BASIC · IBM PC · Apple II
Languages
English
PDF page 16

o INTRODUCTION o subroutines, and asynchronous interrupt blocks: • FOR/NEXT loops. The customary FOR loop block is included in Mac- intosh BASIC as the standard counting loop. An EXIT FOR statement allows for premature branching out of a loop. • DO loops with EXIT. An infinitely repeating loop block avoids the con- fusing, unstructured "GOTO loop" of standard BASIC. With the EXIT statement, a DO loop can be used to simulate both· the While-Do and Repeat-Until loops of structured languages like Pascal. • IF/THEN/ELSE blocks. In addition to the one-line IF statement of standard BASIC, Macintosh BASIC allows a block IF statement, which conditionally executes an entire block of statements. In addition, an optional ELSE block allows for a two-branch decision. • SELECT/CASE structures. For decisions involving more than two branch blocks, Macintosh BASIC allows a SELECT/CASE structure, which chooses one block out of a series of alternatives for a decision. • OOSUB subroutines. For compatibility with standard BASIC, Macin- tosh BASIC retains the OOSUB subroutine call. A OOSUB routine is introduced by a label, and shares all of its variables with the calling program. • CALL/SUB subroutines. Macintosh BASIC has added a true subroutine call, which passes values to the called routine through an argument list. CALL subroutines share the variables not in their argument list with the calling program. • PERFORM/PROGRAM calls. A Macintosh BASIC program can call up an external program from disk, execute it, and then continue with its own work. These external programs share no variables with the calling program. • Single- and multiple-line functions. Like standard BASIC, Macintosh BASIC has a DEF statement for user-dermed functions. It also has a multi-line FUNCTION definition block, which lends added flexibility to functions. Functions accept values through an argument list, and share all other variables with the calling program. A function returns a single value as a result. • Asynchronous WHEN blocks, for detecting error conditions and key- board input. A WHEN block may be def'med anywhere in the program

Reading notes: Source text ends mid-sentence at the WHEN block description. OCR-style errors appear, such as 'def'med' and 'user-dermed', which may be misreadings of 'defined'.

Printed product names
Macintosh BASIC
Languages
English
PDF page 17

o INTRODUCTION o to provide for a special error-trapping action to be taken whenever a cer- tain error condition or keystroke occurs. These WHEN blocks are "asyn- chronous," because they are put in force at all times, not just at the point where the statements occur. With all of these control tools at your disposal, you can write structured programs that are logically organiz.ed into coherent blocks, each of which has a single entry point and a single exit. Such programs are much easier to plan, write, and debug, and are easier for other readers to understand. While Mac- intosh BASIC does still have a 0010 statement that lets you jump around inside a program, you would do much better to take advantage of these orga- nizing block structures. The Ten Data Types Most versions of BASIC have only two data types: numeric (for number values) and string (for letters and other text characters). Macintosh BASIC has ten specialized data types, as shown in Figure 1. The Five Numeric Types. (Identifiers: none, \, :, OJo, and#.) Macintosh BASIC has five numeric data types. Three of these are for floating-point or real numbers, which are stored in scientific notation with a decimal fraction and an exponent. The other two numeric types are for integers-whole num- bers with no decimal part. The normal integer type has only 16 bits of storage, Type of Type Bytes Significant Range of Variable Identifier Used Digits Values Double-precision real (none) 8 15.S E±308 Extended-precision real \ 10 19.S E±4932 Single-precision real I 4 7 E±38 I Integer Ofo 2 s ( - 32768 to + 32767) Comp (64-bit integer) # 8 18 ( - 1E18 to + 1B18) String $ 1 +length (2SS characters) Character of Byte © 1 2 (0 to 2SS) Boolean or Logical 1/8 (FALSE and TRUE) Pointer 1 4 indirect reference Handle } 4 +structure indirect reference Figure 1: The ten Macintosh BASIC data types, with their identifying symbols.

Reading notes: Several OCR-like character errors appear (e.g., 'organiz.ed', '0010' for GOTO, 'OJo' and 'Ofo' identifiers, '2SS' for 255, '1B18' for 1E18). Figure 1 table columns are garbled and some entries are uncertain.

Languages
English
PDF page 18

o INTRODUCTION o giving it a range from - 32768 to + 32767. The longer integer is a 64-bit comp (standing for "two's complement," the method of data storage used for both types of integers). It has a range from approximately - 9.22 x 1018 to + 9.22 x 101s. Macintosh BASIC has no equivalent to Macintosh Pascal's intermediate 32-bit long integer. By default, all calculations in Macintosh BASIC are done in its full extended precision mode, then rounded to the accuracy of the variable type you are using. The default variable type (bearing no type identifier) is the double-precision real number-see the entry under PREQSION for details. The Macintosh floating-point arithmetic system does not normally stop a program when an invalid arithmetic operation occurs. Instead, it may store the value 0 or INFINITY as the result, or it may store a NAN code, meaning "Not A Number." At the same time, it sets one of its exception fla&S, to show that an invalid operation has taken place. See the entries for INFINITY, NAN, EXCEPTION, and HALT for details on these numeric error-handling techniques. Macintosh BASIC has all of the standard BASIC operators' ( +, - , x, I, and "), plus two special operators: DIV for integer division and MOD for modulo remainder. All of the numeric variable types can be assigned to one another, using the LET statement. If the value assigned has more digits of pre- cision than the variable receiving it, the value will be rounded (not truncated, as in most other forms of BASIC.) String Type. (Identifier: $.) A string is a sequence of text characters stored under a single variable name. Strings may contain any characters, including letters, numerals, and special symbols. Numbers in string form cannot be used in numeric calculations. Up to 255 characters can be assigned to a single string, or as few as 0 (the null string contains no characters). Each character in a string is stored as its ASCII code; the codes are listed in Appendix A. A string constant may be any series of letters enclosed in double quotes ("), single quotes ('), or the Macintosh's special curved quotes (typed with Option-[ and Option-]). A double quote mark can be included inside a string; just type two quotes without leaving a space in between for every quotation mark you want to appear in the string. Alternatively, you can use single or curved quotes to enclose a string containing double quotation marks. Strings can be concatenated (joined) with the & operator. A plus sign ( +) cannot be used to concatenate strings in Macintosh BASIC. String compari- sons are made with the standard relational operators ( = , #: , >, ~' <, and <). You can choose the option of either ASCII ordering (the default) or ordi- nary alphabetical ordering-see the entry under OPTION for details.

Reading notes: Several characters are damaged or misread in the OCR text, e.g. 'fla&S' and '1018'/'101s' and symbols in the comparison operator list. No primary heading is visible in the supplied copy.

Languages
English
PDF page 19

o INTRODUCTION o Character (Byte) Type. (Identifier: c, typed as Option-0.) A special character data type is defined in Macintosh BASIC to hold a single ASCII code. This type can be assigned an integer number value from 0 to 255; however, it can- not be assigned a string value. It might therefore be more correct to call this type a byte variable, since it acts more like a short integer than as a character. Boolean Type. (Identifier: - , called a "tilde.") Unlike other types of BASIC, Macintosh BASIC has a full Boolean variable type, which can take on only two values: TRUE and FALSE. A Boolean variable can be assigned the logical result of a relational comparison of two numeric or string variables. Macin- tosh BASIC also has a number of important built-in Boolean functions (including MOUSEB- and SOUNDOVER -), which can be manipulated as logical expressions. Logical expressions can be evaluated and assigned to Boolean variables with standard assignment statements. The logical operators AND, OR, and NOT combine two Boolean values to yield a single result. See the entry under LET for details on logical assignment statements. Pointer Type. (Identifier: ].) A pointer contains the address of a location in the computer's memory. In advanced programming, a pointer is often used to refer indirectly to another structure within the computer's memory. Rather than holding the structure itself within a variable or array, a pointer is defmed that contains the address where the other structure is stored. In Macintosh BASIC, pointers are used only in connection with the TOOLBOX statement,· described below. Related to pointers is the indirect addressing symbol, @, which is used in certain types of subroutine calls and other structures. The indirect addressing symbol tells a command to treat a variable or array merely as a reference to a memory location, rather than as an actual value. This symbol should be used only where it is a required part of the syntax. It cannot be used to create a pointer variable. Handles Type. (Identifier: }. ) The handle variable type is peculiar to the Macintosh system. Like pointers, handle variables are used only with the TOOLBOX command. Technically, a handle is a pointer to a pointer-a variable that contains the address of an intermediate pointer, that, in turn, contains the address of a struc- ture in memory. This double indirection is required on the Macintosh system because all blocks of memory are dynac, that is, free to be moved by the operat- ing system. When the system moves a structure stored under handle variable, it

Reading notes: Source text ends mid-sentence at the handle type description Some characters appear damaged or OCR-like (e.g., 'defmed', 'dynac', 'Option-0')

Languages
English
PDF page 20

o INTRODUCTION o automatically adjusts the intermediate pointer so that it holds the new memory address of the moved structure. The intermediate pointer itself is not moved, so that the handle variable still points to it-and, through it, to the desired structure. The handle variable therefore can retain the address of a fixed memory location, yet point indirectly to a dynamic structure in the memory. In Macintosh BASIC, a handle variable is treated as if it contained the entire structure it points to. If a handle is assigned to another handle variable, the entire structure will be copied and stored with the new handle pointing to it. The entire structure can be stored in a data file merely by writing the name of its handle. For all ten data types, variable names may consist of any number of charac- ters, ending with the variable's type identifier symbol, shown in F1gure 1. Names must begin with a letter; numbers and certain special symbols are permitted for all characters after the first. Upper- and lowercase letters are treated as equivalent in variable names. This book uses initial capitals for all variable names. Arrays (subscripted variables) and functions may be defmed in all Macin- tosh BASIC data types. An array may have the same name as an unsub- scripted variable, but not the same name as a function. Data Files Macintosh BASIC has a sophisticated data file system, which lets you manipulate both sequential and random-access files easily. Each data file is . defmed by a set of three attributes, which specify the type of access permitted (input only, or input/output), the storage format (text, data, or binary), and the file's organization (sequential, record-size, or stream). Within file commands, Macintosh BASIC allows two special types of oper- ators, which are executed as preliminaries to the file commands. The first type are the file pointer operators, which move a file pointer to a new record within the file, before executing the file command. The other type of internal opera- tor is the file contingency, a special kind of IF statement that is executed prior to the file command only if certain exceptional conditions occur (end-of-file, missing record, etc.). These special commands add a great deal of flexibility to the file 1/0 commands. The entry for OPEN # contains a general description of the Macintosh BASIC data file system. QuickDr Graphics Macintosh BASIC has one of the most sophisticated graphics systems of any language for any personal computer. Based on the Macintosh's internal

Reading notes: Source begins mid-sentence, so the opening heading and reading order are unclear. Several OCR-like errors appear (e.g., 'defmed', 'Macin-', '1/0'), suggesting damaged characters.

Printed product names
Macintosh BASIC · QuickDr Graphics
Languages
English
PDF page 21

o INTRODUCTION o QuickDraw graphics system, Macintosh BASIC has simple commands for drawing all kinds of complex shapes. These shape graphics commands treat the shape as a unit and are all extremely fast-must faster than plotting the objects yourself. The Macintosh BASIC graphics system is based on a two-keyword syntax. All of the shape graphics commands take the form "Verb-Noun." The verbs can be chosen from the four shape graphics manipulators: ERASE (clear away an area), FRAME (draw the border), INVERT (reverse the color of all pixels) and PAINT (fill in with a pattern). For the nouns, you can choose any of the three RECT (for rectangles) OVAL (for circles or ellipses), and ROUNDRECT (for rectangles with round corners). Any of the twelve combi- nations of these four verbs and three shapes is a valid BASIC command. In addition, Macintosh BASIC has a PLOT statement for drawing points and lines. This command similar to the point- and line-drawing commands in other forms of BASIC. As in other forms of BASIC, graphics are described in terms of coordinates-a pair of numbers that names a horizontal and a vertical posi- tion for the point. In Macintosh BASIC, coordinates are normally measured in pixels from the point (0,0) at the upper-left corner of the output window. That default, however, can be changed by using the SCALE set-option. This book follows the Macintosh BASIC convention of naming coordinates {H, V), for "Horimntal/Vertical," rather than (X, Y), as in traditional mathematics. See PLOT for more details on coordinates. Most graphics operations are controlled by the graphics pen., which can be set to draw lines and shapes in various ways. With a series of graphics set- options, you can change the graphics pen so that graphics are drawn with a pattern of your choice, a wider or taller pensize, or a selection of transfer modes that determine how new graphics will overlay what is already on the screen. See the entries for PATTERN, PENSIZE, and PENMODE for details. For text output, Macintosh BASIC has a flexible GPRINT (Graphics GIPRINT) statement that allows you to draw text in different fonts, sizes, and type styles. A traditional PRINT statement is also provided, for compatibility with other languages. The Toolbox Finally, there is the toolbox, a set of graphics and system routines inside the Macintosh operating system. These machine-language routines are stored on a pair of ROM chips inside the Macintosh, and are available to all Macintosh applications and programming languages. In assembly language, for example,

Reading notes: Text reads 'GIPRINT' in the GPRINT statement description, likely an OCR or typographical error Text ends mid-sentence at 'for example,' indicating truncated source

Printed product names
Macintosh BASIC · Macintosh · QuickDraw
Languages
English
PDF page 22

o INTRODUCTION o all of the toolbox routines can be called as if they were library subroutines and functions. Macintosh BASIC gives you access to a wide variety of toolbox commands, through a special TOOLBOX statement. This statement is essentially a machine-language subroutine call, allowing you to use the toolbox routines as extensions of the BASIC language. In effect, the toolbox routines become additional commands for the Macintosh BASIC language. Macintosh BASIC does not give access to all of the 500 or so toolbox com- mands built into the Macintosh ROM. Some of the commands are of no use in a high-level language such as BASIC, and others are duplicated exactly by BASIC commands. Macintosh BASIC therefore limits its toolbox interface to a group of about 300 functions and procedures that might be of general inter- est as supplements to the language. These routines include most of the graph- ics system (including three additional shapes-arcs, polygons, and regions-that are not available in BASIC), the window manager (which arranges the windows on the screen), the menu manager (which keeps track of the pull-down menus), and the control manager (which creates scroll bars and "push buttons" for interactive programs). Some other portions of the toolbox can also be used through BASIC. If you have version 1.0 of Macintosh BASIC and are wondering why you haven't heard of the TOOLBOX statement, it's because the statement isn't mentioned in Apple's documentation. Because the toolbox interface is so com- plex, Apple decided it could not make the TOOLBOX statement work per- fectly for the initial release of Macintosh BASIC, so the company decided to omit all mention of the statement, rather than be responsible for making it bug-free. Yet, the statement is in the language and does work in the most important cases-a fertile ground for experimentation. You will find the keys to the TOOLBOX statement in this book. The most important toolbox graphics commands are discussed under their own names in the text, including all of the QuickDraw shape commands for drawing arcs, polygons, and regions. The other sections of the toolbox (windows, menus, and controls) are not given separate entries, but they are treated as a group under the TOOLBOX/TOOL entry. Finally, Appendix Dis a general refer- ence to all of the toolbox commands that are available in Macintosh BASIC- including complete syntax summaries. See the TOOLBOX/TOOL entry for a complete introduction to the toolbox.

Reading notes: Hyphenated line breaks in source text (e.g., 'com-mands', 'per-fectly') may affect exact word forms.

Printed product names
Macintosh BASIC · Macintosh ROM
Languages
English
PDF page 199

Graphics text set-option-sets the typefont for use in graphics text. Syntax []SET FONT N [1] ASK FONT N Sets or checks code number for the font that will be displayed by future GPRINT statements. Description Using the graphics text set-options and the GPRINT statement, you can exercise great control over the way the Macintosh displays text on the screen. The set-options FONT and FONTSIZE let you choose any typeface and size that are available on your disk. The set-option GTEXTFACE lets you specify a type style such as boldface or italics, and GTEXTMODE sets a transfer mode that describes how the text writes over graphics or text already present on the screen. Each font is a complete set of images of the letters of the alphabet and the special symbols. These images are used to paint each character on the screen, and to arrange the patterns of dots formed by the printer. Most computers are equipped with only one type font; the Macintosh comes with eleven. These multiple fonts, stored as resource files on the system disk, are among the features that give the machine its versatility and appeal. In Macintosh BASIC, fonts are chosen with the FONT set-option. The eleven fonts, shown in Figure 1, are chosen by their identification numbers: SET FONT Number The names of the fonts are just for reference; they are never used in BASIC commands.

Reading notes: Bracketed syntax markers such as []SET and [1] are ambiguous in the source text

Printed product names
Macintosh · Macintosh BASIC
Languages
English