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
Denmar’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-
¥
@ 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
1
== Source of RECTANGLES ==
v2=v2-5
FRAME RECT h1,v1h2,v2
IF v12380 then EXIT
h2=h2+5,
v2ev2e5
IF viz 0 thenEXIT
Figure 1: Multitasking in Macintosh BASIC.
318 BYTE April 1984
INVERT ROUNDRECT h1,v12.vq
Test Pattei
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)
r
@ Edit Sd@rch Program Operat
Source of whizbang.city
y Whizbang City FEQ2 Source of whizbang.
! by John Scribblemonger ENDIF
! V2.0 12/25/83 object Size-object Size
gos} |F mouseB THEN
horiz.cord=512/4 ENDIF object Size=3
vert.cord=342/4 object| Flag=1 - Flag
object.size=3 IF moy ENDIF
flag=1 objq LOOP
Flad
ine) ENDIF | Teme Set:
IF flag then Looe tishoriz.cord-objectsi
gosub Frame.Oval: t2=vert.cord-object siz
ELSE object Size=object.Size+!
gosub InvertRectangle:
ENDIF
object Size-object Size+2
IF mouse® THEN
obiect.Size=3
t3=horiz.cord+object.si
t4-vert.cord+object siz]
is
tell
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 windor
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.
Uhizbang.City
by John Scr i bblemonger
! v2.0 12/25/83
hor iz.cord=51274
vert .cord=342/4
object. size=3
flag=t
0
IF flag then
gosub Frame.Oval:
ELSE object.Size=object.Size+!
gosub Invert.Rectangle:
ENDIF
object .Size=object .Size+2
IF mouseB THEN
object .Size=3
Flag=1 - Flag
ENDIF
Leer
Temp .Set:
tishoriz.cord-object.size
t2=vert.cord-object.size
t3=horiz.cordtobject.size
t4=vert.cordtobject.size
Return
Frame .Qval:
Gosub Temp.Set:
Frame Oval ti,t2; t3,t4
Return
Inver t.Rectangle?
Gosub Temp.Set:
Invert Rect ti,t2; t3,t4
Return
320. BYTE April 14
w for the program Whizbang.city (listing 1).
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.
Edit Search Program Opegate
NotePad
Try changing variable MAXOFF
to some other permutation of
the OFFSET.
Then see if Donn can make the
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
Source of LINETEST
effic: DO
stuff! max: 100
SPACING=10
FOR DELTA=1 TO SPACING
LET OFFSET=X+DELTA
SET PENPOS OFFSET,O
PLOT 0,MAXOFF;
PLOT MAXOFF MAX;
FOR X=SPACING TO MAX-SPACING STEP.
LET MAXOFF=MAX-OFF SET
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 CALLYOUR.
MOTHER: instead of to CALL.
YOUR.MOM:.
Function Description
BIN tells which interactive button has been pushed
DIAL tells which interactive dial has been activated
FORMATS Macintosh BASIC equivalent of PRINT USING
KBD gives the ASCII code of the most recent key pressed
MENU tells when an interactive menu is chosen
MOUSEB yields the state of the mouse button
MOUSEX returns the horizontal position of the mouse pointer
MOUSEY returns the vertical position of the mouse pointer
TYP tells the data type of the next item in the input stream (numeric, string, or
picture)
Table 1: Macintosh BASIC numeric data types.
Storage Form Symbol Accuracy Range
Double-precision real none 15 1E +- 1022
Single-precision real | 7 164-126
Extended-precision real \ 18+ 1E+-4000
Short integer % 4+ +-32767
Long integer # 184 +-9E18
Boolean ~ 1 Oort
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.
id
|
EL
izbang.City
Cut sen [YO : Source of linetest
Copy xe fobiect Size+! TOR X=SPACING TO MAX-SPACING STEP]
potangle: | LETOFFSET=x+DELTA
LET MAXOFF =MAX-OFF SET
SET PENPOS OFFSET,O
Select All %A PLOT 0,MAXOFF
Copy Picture PLOT MAXOFF MAX;
PLOT MAX, OFFSET;
PLOT OFF SET,0;
ttshoriz.cord-object.size
t2=vert.cord-object.size
The Clipboard
FOR X=SPACING TO MAX-SPACING STEP SP;
LET OFFSET=X+DELTA
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
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/
THENIELSE/ENDIF lets you execute
DOUBLE PRECISION e
FORTRAN e INDEXED ARRAYS e CHARACTER VARIABLES e
UNLIMITED
CASES ¢ VARIABLE RECORD LENGTHS e MISSING DATA e RELATIONAL DATABASE « REPORT GENERATION e
NUMERICAL AND CHARACTER MULTIPLE KEY SORT/MERGE ¢ IF... THEN...ELSE e FOR...NEXT e GOTO e
INTERACTIVE/BATCH ¢ ASCII/BINARY FILES e¢ SCATTERPLOTS «
HISTOGRAMS e CONTOUR PLOTS ¢«
MULTI-FUNCTION PLOTS ¢ BOX PLOTS ¢ STEM-AND-LEAF DIAGRAMS e PROBABILITY PLOTS ¢ BASIC STATISTICS
BREAKDOWNS e MULTI-WAY TABLES ¢ LOG-LINEAR MODELS e PAIRWISE/LISTWISE CORRELATIONS e MULTIPLE
REGRESSION e POLYNOMIAL REGRESSION e STEPWISE REGRESSION * WEIGHTED LEAST SQUARES «
MULTIVARIATE REGRESSION ¢ LEAST SQUARES ANOVA « ANOCOVA © REPEATED MEASURES ¢ MANOVA e
GENERAL LINEAR MODEL e PRINCIPAL COMPONENTS e MULTIDIMENSIONAL SCALING ¢ CLUSTER ANALYSIS
1127 ASBURY AVENUE EVANSTON, IL 60202
Circle 349 on inquiry card.
CP/M,” UNIX™
(312) 864-5670
BYTE April 1964 323
es RI
7a UL uo a
DUD Se OR VA OL LOU OU OT vara
IBM e APPLE ¢ FRANKLIN * OSBORNE * KAYPRO *
e For Savings
e For Selection
e For Service
Other companies waste time and overhead producing expensive catalogs.
Computers and More doesn't. Putting the latest products and best prices in
our customers’ hands, not catalogs, is our goal. We challenge any catalog
company to match our pricing, selection and service.
Take the catalog challenge and save! * New Product or Price.
Desk Top Portable
eM P/C2320K 2105 columbia VP 249
1BM XT ONSALE! Corona 19208 1989
Ccoumea 1606-17289 * Panasonic Sr. Parner. -1995,
Columba tB004" 3494 Kayproil CALL
Carona 2.3204 2383 xaypro4 1659
fagle 1620 3095. Tetetoe 1289
+ cage POX 3395 ¢ TeevdeoTPC-2 1759
* nec All Models. age spirit xL 3495
fpson X10. -ONSALE!_ The Commuter by Sharp NEW!
Dre Rainbow 100. ...CALL * NECA2O1A 639
* LeauingageP/C 2199, Compag' dive... CALL
* Televideo 803 160511 CALL” Apple Compatable CALL
Fanklin0MS CALL | Epson HK20 CALL
AppleGomputers CALL * Zortagin 176
IBM Apple
Supervision by CCS ....678 * Rana s0s6CPU ....... CALL
Paradise Multispley 449 Dual latertace (Pa & Se) 159
Graphics CardbyHercules367 80CCo/64K rile, 116
STB Video Board... M9 PRASO Cara 12
faby Sue by Wieon 459 Par Interface 59
TASTSixPak 269 _ Koala Touch Tablet. 86
* ASTRON 0... -1279,* Widcat Computer... SALE!
Sard 1200 Btw/so) 428 PremumSinCdtle. 249
1 Fassword Modem. 839 SupRMod - 49
* Yangon TM 100-2. 001 219 Disk Drive 199
COCDisk Dive DS/08 «227 Dive Controter. 58
Usk Conoter by Maynard 187. Disk Emulator 294K. 519
Hall High 3208 199 Utraerm 239
vaddisk Smeg. Fed. 1588 MicroModem 259
eytonicNew 8150... 198 Smart Modem 1200 1 $29
* KratiJostcn 4 DG 149
* YSiok/Craphes v8 Pa959._KratJoysice 2a
CarvusePegasuseCorona 469 Davong 5 Meg 1389
Cvadram Quadline «469. Mcrobuter i 209
* uaa New Quod et 64K 299 80 Cole 39
Teemar ist Male... 259 BUFGrappier+ CALL
Teemar Graphes Masi. 559 Wizard 16K By
* Giena Teemnoogies. CALL Keyroniexse00.... 217
Printer Accessories
‘Sooper Spoor 26 Microbutfer (in ine 32K P)219
Micro Spooler(@ 10 16K) 189 Microbuter Inline 32 KS) 219
Micro Spoole (Pto PE4K) 22964 K lor MB 139
‘Sounatrap 89 Optimizer by ACT: CALL
Terminals Plotters
Wyse 300, 1019 Mann-Tally Pixy 3 689
Wyse 200 1019 | Sweet 528
Adds All Mocels... CALL * Sbe-Shooter CALL
TV. 910+ $69 AmdexX-¥ 569
TV. 9256 749 | Amdex6 Pen Auto... .995
T.950¢ 969 * Quagiet by Quadram. CALL
(ume 102 549°C. toh CX (Par) 549
‘Qume 1026 549. tion CS(Ser) 549
* oume 108.4 673 Strobe 8 Pen 739
Zeaitn CALL Houston ins HiPad.. 759
1 Year Warranty Available
FO ORDER. Phone orders invited using Visa. MasterCard, or bank wire
Itansfers Visa, MO, service charge of 2%. Mal otders may send charge.
‘ard number (include expiration date), cashiers check, money order, oF
‘ersoal check alow 10 business days or persona or company checks to
tea) Pease ad0 3% ($500 minim) lor UPS shonin. tanding.3d. . The Catalog Challengers!
‘insurance A¥ equipment sin factory cartons with manufactures warranty,
‘Opened products not returnable Restocking le for returned merchandsse.
Equipment subject to price change andavalabity Retal prices citer from
‘mai order pnces, Call. residents add 6% State Tax Company and schoo!
P.O accepted on anproval IBM & Apple are registered trademarks
International inquities weicomed
Telex 697120, Datamax Atta, Dept. 322
* TRANSTAR * QUADRAM * DAVONG ¢ CORVUS °
Letter Quality
NEC3560 (18M). 1695
Cannon ink Jet ea
Juxi6100 499
Silver Reew 550 599
* Silver Reed 770 CALL
Transtar 130 699
Transtar 140 1089
Neo 2010 859
NeC2015 859
NEG2050 (8M). ‘CALL
F-r0siawrier 1099
F:1OPrnimasier 1369
* Powertype by Star CALL
a) 589
HRS onsatel
Diab 630 CALL
* Daisynnter 48K. 1089,
7680-2 1089
ajother HR-25 769
Color
Princeton nK12 $469
* Poncston F-12 bag
* New Mac? 199
NEC IG1203 (18M) 519,
* Taxa A683 409
Quadiam Quadcrieme 497
Zenitn- New CALL
IBM
Base CALL
Miionare 9
Wizardry 33
Wiorestar 239
* Easywntert 259
Volkswrter 9
Visical (256%) 179
Multiplan 189
© Lotus 1-23 319
1 FS Graph a
* BES File 89
PES: Report 83
AS: Solutans. ALL
dBase lt 384
* OOEX-Any Program 49
Tax Prepare’
* O2oyFas
Infostar 259
Personal Parl 199
Home Acct. Plus 112
Peachiver CALL
Property Management 329
gia esearch SALE!
* DESO. NEW!
* select 299
Dot Matrix
©. toh 8510. 339
Cot 1550 65
Epson FXB0 CALL
Epson AX0 CALL
* oKia2n 319
OKI 838 589
Oki 80 319
OKI 928 409
Ki 93 739
* ‘Riteman 60 Col 349
Gemini Datta 10 549
* Gemini Radix 10015. CALL
Gemini 10% 259
Toshiba P1360 SALE
NEC 8025. 699
IDs Prism 132 1165
Mann-Tally 1601 619
Mann-Tally 1801 849
Transtar 315 CALL
Monochrome
Taran Amber 129
Taxan Green 129
Zemin 322 125
Zenit 123.6 37
‘Amdek 310 8 168
‘Amdek 300 159
New Max-12 199
Apple
TaxPreparec ur
Home accountant 49
Great Plans CALL
Peacniree
ES, Solutions. CALL
PFS. File 8
PES. Report rn
PFS. Graph Be
B3se!) 397
Vise 169
Versatorm 264
ThM. CALL
Ust Handler 53
Wordstar 249
Bank Steet Woter 7
Screenwriter it CAL
Magic Window 7
Magic Cab 9
Zotk 2
Zaxxon 2
CChophiter %
Frogger 2%
Wizardry 3
Jumpman 2
3620 - 30th Street
SAN DIEGO, CA 92104
TO ORDER
(619) 291-1442
ATOVG ¢ IMAL ¢ ININAD e GVdINOD ° WOOSAS ° MOGNIVA 04d ° ATOVE » NOSda ¢ VNOUOD « VIENTO ¢ SOLTV
Listing 2: A multiple-line IF control block.
Source of IF...THEN/ELSE/ENDIF
IF DAY.TEMP > HOT THEN
CLOTHESS = SWIMSTUFFS |
GOSUB BEACH
ELSE CLOTHES$ = WALK STUFFS
GOSUB CITY
ENDIF
ay
fell
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
the program to transfer execution to
sets of statements based on the value
of some expression. There can be
multiple statements for each case or
range of cases (see listing 3). The lan-
guage has several interrupt control
structures, all of which are based on
a structure bounded by the keywords
WHEN and ENDWHEN; these inter-
tupts 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-
tupts to occur whenever a key is
pressed, when the mouse is moved
or its button pushed, when an error
occurs, or at other times (see listing
4),
Subroutines are handled in the
usual way (except that the language
uses GOSUB labels); additionally
there's a CALL statement that enables
entire programs to act as subroutines.
CALL lets you pass parameters back
and forth with the summoned pro-
gram; when the called program ends,
control returns to the statement
following CALL in the source
program.
Graphics
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.
Circle 58 on inquiry card.
Listing 3: A SELECT CASE construct using strings (3a) and a SELECT CASE construct
using numerics (3b).
(3a)
ECE Source of SELECT CASE/ENDCASE (STRINGS)
SELECT CASE PARTY$ ray
CASE “REPUBLICAN”
CALL REPUBLICAN.PRIMARY BALLOT
CASE “COMMUNIST”
CALL MILITIA
CASE “DEMOCRAT”, “TORY”, INDEPENDENTS
GOSUB FURTHER.CHOICE:
CALL GENERAL PARTY BALLOT
IBM-PC/XT, or PC compatible
CASE ELSE
ENDSELECT
CASE LEFTS(PARTY$, 3) = “SEP”
CALL SEPARITIST PRIMARY BALLOT
CALL GENERAL .PRIMARY.BALLOT
resikel
(3b) EGE source of SELECT CASE/ENDCASE (NUMBEAS @ AANGES)
SELECT CASE AGE
CASE 2, 4,5
GOSUB PRESCHOOL:
CASE 6 TO 12
CASE >70
ENDSELECT
GOSUB GRAMMAR. SCHOOL:
SE 15, 18 TO 35, VAL (OLD$)
CALL CHECK.DEMOGRAPHICS
GOSUB MIGHT BE. RETIRED:
a
rel
(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.
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.
OS} Source of WHEN / ENDIUHEN
WHEN ERR
CALL ERROR.CHECK
GOSUB SECOND.CHANCE:
ENB WHEN
WHEN KBD
PRINT “WHICH MENU DO YOU NEED?’
GOSUB MENU.CHOICE:
CALL MENUS:
ENDWHEN
IT
JEEE-488 INTERFACE BOARD
« 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 |EEE-488
command mnemonics. Interpreter
routines support BASIC, PASCAL,
C and other languages.
* Supports the PrtSc (print screen)
key, and all BASIC print statements
for IEEE-488 printers and devices.
¢ Small size—see BYTE 11/83,
p. 314
¢ Accepts a standard IEEE-488
cable.
* Uses only 16 bytes of RAM and
no |/O ports.
’* A116 page Reference Manual
provides a tutorial and programming
examples for digitizing, interactive
bus control, bus diagnostics, and
many other applications.
$395 complete. There are no
extra softtvare or cabling charges.
CAPITAL EQUIPMENT CORP:
10 Evergreen Avenue
Burlington, MA. 01803
(617) 273-1818
JBM is a trademark of Intemational Busi
BYTE April 1984 325,
call otk: wie8 $239
intostar 159 words" 313
riplan $24 inde 9
Mul OY al word MOUSE <tar/ Sta" $103!
muititoe’ word WIT spells jaBase My $579 sue
ines : niailme’ tus 423 vst ge
20
words pro Pa $250 3338
y le oo 2 03
wordst2l A yickeos SNE MROMEROE ace Sous a8
apase ust 39 Spee TaniMAN soo 8
2805169 WORT AR. aBURST 3M +
solwetOunecy W a 99 panes il 139
a m si INOS $
REPLEABM GaANRE! 298 STAROU SRT soe 88
Bara ease sae ures foo 38
on 650 e105 S15 5
RIB 2 5.98 HOUSE, oy emancyn So fae
Goneton 3 sso 128 ULL Bute 38 te
3 8 HiT eson Fs
arial ANT 3M aL O°
contrengcoun™ 5269 PASHAN 28
HOMBRE . $400 52 apie! 399 -
ac * ‘i 5
yqita POSES 86 Be 200 3109 peactCe yr 5000 49
PASCAL MENT cri 8 sk PeKenTeR sanett 5! as
CRASHER onsi° feo gato prop pts sg 8
Ss 90 19 pst" St 8
ESM EE wot PB Fat Soo Regs
ROCESS GR pes Ale sy
visrso eS $265 PES Gaars 3159
Ores Guact seo 29S Sane 9889
50 $298
3000 yp XZER . se
Dow, ANAL CER sit sores uc 2 269
NAARET ANAS 5198-308 SUPERS ER is 5188
os es 310 surer Slo Yes
Foraneeunt Se Bie cor g $303 5208
ERS :S 95, 195 NSNwOr sx s
aed fe Me Wktew $300
te 3 ALE p10" 2
eeiescorr FP goo Hetneugtie ooo Ua
ra . US S84
VGreREPARES Pe ee so
on yan 100g 200
ira efe ant x15 3298 1 yooes 13308 sano
Saves Gem Sis Sas Baten 120% esd Sn
Howmet, Se a Se the
EASA LEDGE $508 52 uns. $588
GENERA eRe nLe sso gat? GUA OR ave Boar 4 3268
aC (TS) ROL si ou! »ANO!
OUN NT ‘EXP 84K 8
actenToRY OO se SE ano ex? TO ee
payroll 5198 ynDBort 2
a eX Cercle cand
yoursware®. 5600 Aarne
waco Oa GEMAN i ee At Diamond Software we
now s Offer the best selling business application soft-
wesse ware for your IBM PC, CP/Mor Apple Computer at the lowest
possible prices. And we maintain a complete technical department
to assist you before, during and after your system purchase. Not only that, we
offer same day shipment on most items and we accept Visa, Mastercard and
also American Express. Weill even pay the shipping charges if you send
us a money order, cashiers, company or personal check. Purchase orders
are gladly accepted from qualified organizations and we welcome dealer
inquiries, Call Diamond today, you'll be glad you did.
000-227-0545
TO ORDER CALL TOLL-FREE
Diamond Software Supply éssiatrarave. suite 128 Catiana, ca 99010
For price quotes. information, or in California call '-415-893-7676 We credit your order for
the call. Technical Department (415) 893-7678. Intemational Telex 336199 (atin, 149)
Support, Service and Price.
Shipping/Handling UPS surface $3.00 plus an additional $3.00 per item for UPS Blue.
©.0.0 orders add $4.00. For personal check allow 2 weeks for delivery.
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
MINI-SYSTEMS
ia)
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
nsec)
Graphics-Digital Graphics
CAT-1600
DMA Disk Interface
SMD Disk Interface
%" or ¥2" Tape Backup
5%" or 8" Floppy Disk Drives
5MB-474MB Hard Disk Drives
7/10/20 Slot Back Plane
20 or 30A Power Supply
Desk Top or Rack Mount Encl.
oo0000000 0 ooOo000 oO
SOFTWARE OPTIONS
68KFORTH' Systems Language
CP/M-68K?0/S with C, 68K-BASIC’,
68KFORTH', FORTRAN 77, EM80
Emulator, Whitesmiths’ C, PASCAL
CO tpris?0/s with Cc, PASCAL,
FORTRAN 77, 68K-BASIC’, CIS
COBOL‘, INFORMIX: Relational
DBMS
0 _unixe 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
oo
oo
Trademark ‘ERG, “Digital Research,
2Whitesmiths, ‘Micro Focus, *RDS,
Inc., Bell Labs, Ryan McFarland,
U.S. DoD
30 Day Delivery - OEM Discounts
{ = 5)
since 1974
Empirical Research Group, Inc.
P.O. Box 1176
Milton, WA 98354
(206) 872-7665
328 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.
(Sa)
= Source of yusubs
print time$;' at start’ {o
for x= 1 to 5000
gosub foo:
next x
print time$;’ when done’
end
foo: return
Whe
= Source of loops
! Loops
Print “Start at ";time$
FOR I= 1 TO 5000
NEXT I
PRINT “Done at “;time$
ource of divs
print time$;’ at start’
for x=1 to 5000
y=x div 3
next x
print times; when done’
Ei
print times; at start’ {Q]
for x= 1 to 5000
y=x/3
next xX
print time$;' when done’ [GI
Tl By
= Source of mid$
print times; at start’ (Gy
b$='Apple Cornputer Inc’
for x=1 to 5000
a$=mid$(b$,6,7)
next x
print time$; when done’
print a$ |_|
end |
l a)
(5b)
! Sieve
s%=8190
dim flags%(sx+1)
print “start ";times
coun
for
to s%
#lagsZci7
next
for
200
KARK~-
goto 200
240 coun
250 next i%
print ‘done
“times
primes’
print count% 3”
Time
Test (seconds)
Empty GOSUBs 30
Empty FOR/NEXT loop 15
Midstring search 90
Real divide (by 3) 180
Integer divide (by 3) 30
Eratosthenes Sieve (1899 primes) 315
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, RECORD53, 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 SET operate
= === Sourca New
he=512/4 Load #L
vce=384/4 Save Source
= Save Object
fa a Print Quick
aa Debug
” Fico TEN Update xu
lag
ENDIF
X=X+10
IF MOUSEB THEN
X=10
FLAG=1-FLAG
ENDIF
LOOP,
Figure 5: A program menu with Save Object
to save a binary version of a program.
& Edit Search Program Operate
INVERT RECT HC-X, VC-XHC + X, VC+X
ELSE INVERT OVAL HC-X,YC-X HC+X,VC+X
RES ‘ST PATTERN
selected by the mouse. This command is used
labels from whizbang.city
Label Comment
EDIE Source of whizbang.city ==] Frame Oval draw an oval
006 DO a] InvertRectangle invert arectangle
007 IF flag then [=| Temp.set Establish temp coo}
008 gosub Frame.Oval: f.
510 Sa eae Variables from whizbang.city
a DE ‘P9'%] Variable narne Value __Breakpoint
flag 1 °
012 7 a
ae object Size=object Sizer] | to cord is 3
014 object. Size=3 oblect size 66 +66
01s Flag=1 - Flag fl 62
016 ENDIF | t2 19 ota
jo 194
Ta _|ta ist &
Gs vert.cord 85 < hori:
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 finn.