Download 5 - Forth

Transcript
~1.33
FORTH OlmEflSlClNS
/=
t
Volume Ill
Number 5
Price: $2.=O
FORTH l l T E R E S T GROUP
I%d,(EA
f
94070
I
lflSlUE
Functional Programming and Forth
137
Harvey Glass
Forth and Artificial Linguistics
138
Raymond Weisling
146
Technotes
A Forth Assembler for The 6502
143
William F. Ragsdale
A Technical Tutorial:
Table Lookup Examples
151
Henry Laxen
The Game of Reverse
152
M. Burton
The 31 Game
154
Tony Lewis
Simulated Tektronics
4010 Graphics with Forth
156
Timothy Huang
A Video Version of Master Mind
I
158
David Butler
Transfer of Forth Screens by Modem
162
Guy T. Grotke
EDrrOR1sCOLUMN
1981 is behind us and as I look back, Iam pleased to see how
much has been accomplished for FORTH, FIG and FORTH
DIMENSIONS.
Published by
F O PIhterest
~~
Ireally appreciate a l l the help and support Ihave received
from our readers. Ihave not done everything right and some of
the best help has been your disagreement. Intelligent, constructive criticism is as welcome as earned praise.
Group
Volume 111 No. 5
Roy C. Martens
C. J. Street
Publisher
Editor
Editorial Review Board
B i l l Ragsdale
Dave Boulton
K i m Harris
John James
Dave Kilbridge
Henry Laxen
George Maverick
Bob Smith
John Bumgarner
FORTH DIMENSIONS solicits editorial material, comments
and letters. No responsibility is assumed for accuracy of material
submitted.
ALL MATERIAL PUBLISHED BY THE FORTH
INTEREST GROUP IS IN THE PUBLIC DOMAIN. Information in
FORTH DIMENSIONS may be reproduced with credit given to the
author and the Forth Interest Group.
Subscription to FORTH DIMENSIONS is free with membership
i n the Forth Interest Group a t $15.00 per year ($27.00 foreign
air).
For membership, change of address and/or t o submit
material, the address is:
1982 will be a year of continued growth.
You can look
forward to continuing responsiveness. I t is my plan to contact
every FIG chapter by telephone a t least quarterly to get feedback
and encourage reader contributions.
FORTH DIMENSIONS w i l l also be awarding AUTHOR'S
CERTIFICATES for outstanding articles that contribute to the
growth and understanding of the language. While we are not yet
i n a position to give you cash for your contributions, we a t least
w i l l give you credit.
Starting i n this issue will be a policy of putting i n tutorial
articles designed to help our entry level readers. This, however,
will not be done at the expense of our more seasoned FIGGERS
who will find an expanded base of challenging articles and
applications.
I n closing, I want to say that the writer's kits have finally
come o f f the presses and Iw i l l be glad to send one to anyone who
wants t o contribute. Please send i n applications and utilities,
philosophy, questions and problems -- i n the final analysis,
FORTH DIMENSIONS is what you make it.
C. J. Street
Forth Interest Group
P.O. Box 1105
San Carlos, CA 94070
HISTORICAL PERSPECTIVE
FORTH was created by Mr. Charles H. Moore i n 1969 a t the
National Radio Astronomy Observatory, Charlottesville, VA. It
was created out of dissatisfaction with available programming
tools, especially for observatory automation.
Mr. Moore and several associates formed FORTH, Inc. i n 1973
fo the purpose of licensing and support of the FORTH Operating
System and Programming Language, and to supply application
programming to meet customers' unique requirements.
The Forth Interest Group is centered i n Northern California.
Our membership is over 2,400 worldwide. It was formed i n 1978
by FORTH programmers to encourage use of the language by the
interchange of ideas through seminars and publications.
Page 134
PUBLISHER'S COLUMN
1981 has been a great year for FORTH, the FORTH Interest
Group and for me, personally. FORTH has spread around the
world and is being used on thousands of computer and
microprocessor-based products. It is being taught extensively i n
schools, companies and by FORTH programmers. FIG has just
completed i t s most successful national convention with almost
500 attendees, over 20 exhibitors and multiple sessions. (Thanks
to Bob Reiling, Conference Chairman and Gary Feterbach,
Program Chairman.) The FORML conference was well attended
and the Proceedings are now available--see order form.
My deepest thanks to the FORTH community for "THE
FIGGY", Man of Year Award. I t was a fantastic t h r i l l and a
surprise. Istand in good company.
Roy C. Martens
FORTH DIMENSIONS 11115
DEA- CHU-Dear Fig:
Ihave developed a process-simulation
program that occupies very l i t t l e memory
space and yet has many of the capabilities
of commercial simulation packages.
Ihave been heavily involved in rnodeling and simulation of automated manufacturing systems for over six years.
My
ultimate objective for this work is t o
develop a microprocessor-based simulation
capability which incorporates process
control structures far beyond those of
currently available languages. However,
the relatively extensive modeling power of
the current code would seem to offer interesting market potential i n its own
right.
I f you can provide information on
marketing such a product, please contact
me by mail or by phone (home (317) 4479206, office (317) 749-2946).
Joseph Talavage, Ph.D.
3907 Prange Dr.
Lafayette, IN 47905
WE CHA------ YOU TO CON---- THE
OF THI- CON------ LET---. WE
CON-CLA-- THA- THE CON---- OF A WOR- IN
COM--- ENG
CON
CON-------TO OUR ABI--- TO DEC----- I T FROTHR-- LET---- AND THE LEN---.
Dear Fig:
Iam puzzled as to why Ihave not seen
mention in your New Products announcements of fuIIFORTH+ for PET, available
also, Ibelieve for Apple. It is published by
IDPC, Co., PO Box 11594, Bethlehem
Pike, Colmar, PA 18915 a t $65. It is
advertised as "A full-featured FORTH
with extensions conforming t o Forth
Interest Group standards.
Includes assembler, string processing capabilities,
disk virtual memory, multiple dimensioned
arrays, floating point and integer processing."
Surely, fuIIFORTH+ is worth a
mention, if not a comprehensive review!
HOW----, I N COM----- PRO----- THE
CON---- IS LES- CON------ (COM-----,
WOR-- C A N BE SWA---- WIT---- CHA---THE SEM
). CON
IT CON------- CON----- ---- LES- HEL- IN IDE----THE DEF
OF A WOR-. IN FACAS THI- LET--- DEM--------- , T M - LET---- AND A LEN--- C A N LET---EVE- A CAR--REA--- OF COM--ENG----.
--,
---------
------
WE CHALLENGE YOU TO CONSIDER
THE CONTENTS OF THIS CONFUSING
LETTER.
WE CLAIM THAT THE
CONTEXT OF A WORD IN COMMON
ENGLISH CONTRIBUTES CONSIDERABLY TO OUR ABILITY TO DECIPHER
I T FROM THREE LETTERS AND THE
LENGTH.
HOWEVER, I N COMPUTER PROGRAMS
THE
CONTEXT
IS LESS
CONFINING (COMMONLY, WORDS CAN
BE SWAPPED WITHOUT CHANGING THE
SEMANTICS).
CONSEQUENTLY I T
CONTRIBUTES CONSIDERABLY LESS
HELP IN IDENTIFYING THE DEFINITION
OF A WORD. IN FACT, AS THIS LETTER
DEMONSTRATES, THREE LETTERS AND
A LENGTH C A N LETDOWN EVEN A
CAREFUL
READER
OF
COMMON
ENGLISH.
SINCERELY YOURS,
ARTHUR GOLDBERG
SPENCER SOOHOO
This was
Dear Fig:
Your letter and its "translationtt certainly
make the point2--ed.
Dear Fig:
to
Chuck's
Arthur Goldberg
Spencer SooHoo
CEDARS SINAI MEDICAL CTR.
9700 Beverly Blvd.
Los Angeles, CA 90048
FORTH DIMENSIONS In15
------
(TRANSLATION)
Francis T. Chambers
ROCK HOUSE
Ballyoroy, Westport
Co. Mayo, Ireland
This is our response
(Moore's) cute letter.
--------
Dear Chuck:
Hope printing your letter helps.--ed.
Thank you for your interest.
reviewed i n Vol. III,#3.--ed.
----
-
Niels Oesten
Brostyk~eveh189
OK-265Ci Mvidovre
Denmark
Right now Iam trying t o put together
a local Danish FIG, and Iwould therefore
like you to update me with the names and
addresses of the Danish FIG members and
possible make a note i n FORTH
DIMENSIONS about my intentions.
As the communication lines are rather
long and since our magazine is only bimonthly, please inform me on your next
deadline as soon as possible.
Thanks Niels. Good iuck an esiah!ishing a
local Danish FIG Group, Ar~yone interestcd, pleasf? cor:La?t Niels 8s listed
above. Regarding deadlines: Copy must
be in our hands 6 weelts prior to pubiication, i.e.,
4/15 is the deadline for
May!Jnne edition, etc.--ed.
Dear Fiq:
Ijest wanted to write to tell you how
much Ienjoy FORTH DIMENSIONS. Every
issue has several things of interest to me,
and I appreciate your work in seeing that
it gets done (often a thankless task). Here
in New Hampshire, Rirb Moore of SNAC
(Southern New-.FJa:npshire Apple Czrps) is
doing most of' the work in implementing
and refining a version of fig-FORTH for
the Apple 11. We have taker; as much as
possible from page :era so that we can use
the many subroutines available from the
Applesoft ROM. Ihave been working with
oirr version for some time now and am
o'oing a high-resolution graphics game
using FORTH and Applesoft hi-res
routines.
Gregg Wi!liarns
BYTE Publications
PO Box 372
Hancock, Ni-l 03449
Thanks Gregg.
Glad you enjoy
appreciate our efforts.--ed.
and
Dear Fig:
Regarding the 8080 Renovation Project's requests for bug fixes, I would like
to counter with a request that they provide a status report in FORTH DIMENSIONS that includes those bugs already
reported alonq with any solutions proposed
or implemented. It would also be of interest to find out what the goals are for the
8080 Renovation Project and how local
FIG chapters can help.
There is what Iconsider a bug i n that
She message routine uses an absolute value
of screen 4 and 5 for getting error message information. This is fine where offset
is zero but when an offset other than zero
is used and the disk has other information
on absolute screens 4 and 5, things don't
look too good.
Robert I.Demrow
P. 0. Box 158 BluSta
Andover, MA 01810
Thanks for the inpot.
--
Your request has
Page 135
been f o r w a r d e d t o the 8080 R e n o v a t i o n
P r o j e c t people as w e l l as p r i n t e d here.
SMUDGE, I M M E D I A T E , etc.) do, b u t I
would l i k e t o learn. I a m sure t h e r e are
others o u t there l i k e me, so h o w about
some t u t o r i a l a r t i c l e s on some o f these
FORTH-uiiiqus features.
Thanks f o r t h e update, M a r t i n . This points
up why we have our p o l i c y o f n o t announci n g unreleased products.--ed.
D e a r Fig:
A f t e r r e c e i v i n g m y i n s t a l l a t i o n guide, I
spent a week keying i n t h e requisite seve n t y - f i v e pages o f 6502 assembler code.
I have
Now, I a m a c o n f i r m e d figger.
w r i t t e n m y own 6502 F O R T H assembler, a
small wordprocessor ( w i t h w h i c h I a m
w r i t i n g this l e t t e r ) , and an A P P L E I1
graphics u t i l i t y resembling LOGO. I l i k e
FORTH!
Bob Wiseman
118 St. Andrews D r i v e
Cincinnati, O H 45245
Your last name says i t all!
H o w about
some a r t i c l e s f o r FD-publication?--ed.
D e a r Fig:
Ia m spreading the F O R T H gospel here
i n Taiwan. I have w r i t t e n about 20 l e c tures and numerous demonstrations t o various universities and i n s t i t u t i o n s i n t h i s
area and have generated q u i t e a b i t o f
l o c a l interest.
F r o m ground zero, I c a n now count
about 10 F O R T H systems installed a l ready. Many o f them, f r o m t h e F I G Installation Manual and source listing, I
brought w i t h me.
A n i n f o r m a l F O R T H discussion group
has already been formed, and our l a s t
m e e t i n g on O c t o b e r 2 5 t h a t t r a c t e d 20 enthusiasts. Ia m having f u n too!
M y home phone i n Taipei i s 393-1554.
I f any o f you happen t o be heading t h i s
way, be sure t o l e t m e know.
Dr. Chen-hanson T i n g
N a t i o n a l Yang M i n g M e d i c a l
College
Taipei, Taiwan, 112 R.O.C.
(02) 031-2301
Glad t o hear you are doing so well.
miss you here.--ed.
D e a r Fig:
I n t h e p a c k e t o f m a t e r i a l s Ig o t when I
joined F I G was a copy o f F O R T H D I M E N SIONS, Volume 111, /I1 w i t h a p r o d u c t rev i e w o f Timin-FORTH. The r e v i e w i n t e r ested m e i n t w o respects. One was the
benchmark tests t h a t i t contaived; t h e
o t h e r were t h e c o m m e n t s on t h e alleged
l a c k o f s u p e r i o r i t y o f t h e Z-80 compared
t o t h e 8080.
Those benchmarks gave m e a chance t o
compare m y machine w i t h m y version o f
F O R T H - - t h e results o f w h i c h surprised m e
since m y machine only runs a t 2 mhz and
t h e machine used i n t h e r e v i e w runs a t 6
mhz. I expected m y machine would t a k e
t h r e e t i m e s longer b u t i n a l l tests, it r a n
comparable or even faster. It would seem
m y i m p l e m e n t a t i o n is faster f o r involved
a r i t h m e t i c owerations.
The editors o f F O R T H DIMENSIONS
are right, I believe, i n being wary o f
t i m i n g benchmarks f o r it is easy t o draw
i n v a l i d conclusions f r o m them.
In fact,
the e d i t o r s themselves drew t h e wrong
conclusions!
The tests do n o t show t h e Z-80 runs
benchmarks slower t h a n t h e 8080--the Z80 was used f o r b o t h tests. The c o r r e c t
conclusion is t h a t some F O R T H implementations are m o r e e f f i c i e n t t h a n others and
t h a t some versions on the m a r k e t are t e r r i b l y slow.
Iarn sure you g e t a f l o o d o f l e t t e r s f o l l o w i n g a benchmark; b u t I just had t o
w r i t e t o say t h a t t h e speed o f F O R T H is
n o t necessarily just a f u n c t i o n o f p r o cessor speed as you have o f t e n claimed.
Everett Carter
Harvard University
Oivision o f A p p l i e d Sciences
Cambridge, M A 02138
We a l l
Thank you f o r your w e l l thought out contribution.--ed.
D e a r Fig:
I want to extend m y apologies t o you,
your readers and t h e F O R T H I n t e r e s t
Group. I sent i n an announcement about
F O R T H ROMS f o r t h e TRS-80, M O D I seve r a l rnonths ago.
IJnfortunately, c i r cumstances beyond m y c o n t r o l now f o r c e
m e t o revise t h e i r a v a h i l a b i l i t y schedule.
I w i l l spare everyone f u r t h e r embarrassm e n t by w a i t i n g t o send i n another announcement u n t i l I have the f i r s t chip set
i n hand.
-
Page 136
M a r t i n Schaaf
P. 0. Box 1 0 0 1
D a l y C i t y , C A 94017
D e a r Fiq:
A c o m m e n t about your p u b l i c a t i o n
FORTH DIMEr\JSIONS. The i n f o r m a t i o n is
certainly
useful (especially
the applications), however, m u c h o f the m a t e r i a l
assumes a c o m p l e t e understanding o f
F O K T I i ' S inner workings.
I don't r e a l l y
understand h o w t h e c o m p i l e r works and
w h a t a l l those c r y p t i c words (CFA, PFA,
Thomas K a s t n e r
7918 2 0 7 t h St. SE
Snohomish, WA 98290
E n t r y - l e v e l t u t o r i a l a r t i c l e s a r e an area I
have been exploring f o r t h e past year.
Check t h i s issue and you w i l l f i n d t h e f i r s t
i n a series o f a r t i c l e s c o n t r i b u t e d b y
H e n r y L a x e n o f L A X E N A N D HARRIS,
INC., a f i r m t h a t specializes i n F O R T H
instruction.--ed.
D e a r Fig:
I don't doubt F O R T H would be m o r e
useful i f m y machine had a l l o f t h e features described i n " A n Open Response"
(Volume 11, 86) b u t consider w h a t I have
gained w i t h o u t them:
1. A n
understanding
works.
of
how
FORTH
2.
A demonstration t h a t a workable subset o f F O R T H c a n b e i m p l e m e n t e d on
a very s m a l l system.
3.
Hours o f enjoyment and appreciation
o f FORTH's virtues.
4.
A useable language f a s t e r and b e t t e r
t h a n T i n y Basic and m o r e convenient
than machine language.
5.
The a b i l i t y t o i n s t a i l and i n t e r a c t i v e l y
t e s t a larger version o f F O R T H when I
expand m y machine.
I f e e l t h e a r t i c l e does users o f
s m a l l systems a disservice. Instead o f
discouraging users o f s m a l l systems,
F I G should encourage development o f
standardized subsets f o r use on s m a l l
machines.
R o g e r L. C o l e
395 E l m P a r k Avenue
Elmhurst, IL 60126
F O R T H DIMENSIONS publishes a r t i c l e s t o
encourage cornmunications, thought and
g r o w t h o f t h e F O R T H world. F a r f r o m
discouraging users o f s m a l l systems, t h e
F I G leadership is composed almost exclusively o f members w i t h s m a l l systems.
F I G has been a leader i n encouraqing t h e
development and use o f F O R T H on srnall
systems. I n f a c t , i t is probably safe t o say
t h a t i f there were no FIG, there would be
no F O R T H , f o r s m a l l users today. Most o f
t h e vendors and systerns now i n use have
been derived f r o m F I G listings provided a t
cost. The source data f o r these listinqs,
FOFiML research, st.andards, etc., w h i c h
so many take f o r qranted, have been der i v e d f r o m t h e labor and cash c o n t r i b u -
.
FORTIH DIMENSIONS 11115
tions o f volunteers serving without reimbursement.
The F O R T H DIMENSIONS
editorial staff supports F I G e f f o r t s t o
keep F O R T H i n t a c t and resist the tempt a t i o n t o obtain mere popularity and i n the
process, f a i l i n their mission t o provide
and support the finest software concepts
and tools available today.
This has n o t
been an easy task (and a l l too often, a
thankless one) b u t it is hoped t h a t i f
others w i l l least t r y t o understand, the
e f f o r t s and contributions o f these volunteers w i l l continue t o benefit us all.--ed.
Dear Fig:
Congratulations t o a l l the people who
produce FORTH DIMENSIONS on i t s quali t y and improvement. Please send me a
writer's k i t so Ican make some o f m y applications presentahle for publication.
FUNCTIONAL PROGRAMMING AND
FORTH
Harvey Glass
University o f South Florida
College o f Engineering
Department o f Computer Science
Tampa, F L 33620
The distinguished computer scientist.
John Backus, i n his 1977 Turing Award
lecture (1) describes the shortcomings o f
conventional programming languages and
suggests a new approach t o programming
i n a style described as functional proWe w i l l summarize the
gramming (FP).
faults t h a t Backus finds i n conventional
languages, b r i e f l y describe the functional
programming style, and lastly show t h a t
F O R T H meets the spirit o f this style o f
programming.
Conventional Languages
Bob Royce
Box 57 Michiana
New Buffalo, M I 49117
Your k i t is on the way! Anyone else?
Dear Fig:
Glen Haydon's nice article i n F O R T H
DIMENSIONS 11112, page 47 talks about an
algorithm he would l i k e t o have t o
determine the Julian day.
With the
background that F O R T H has i n astronomy,
I'm sure there must be several, b u t this is
the nicest Iknow. It comes f r o m the U. S.
Naval Observatory via an article i n the
Astrophysical Journal Supplement Series,
Vol. 4 1 No. 3 Nov. 1979 pp 391-2.
0
1
2
3
4
5
6
( JULIAN DATE )
: J D >R S W A P
DUP9+12/R+7+4/MINUS
OVER9-7/R+100/1+3"4/SWAP 275 9 */ +
-'
t S-> D 1.721029 Dt
367R> M I D + ;
Example: 3 20 1982 JD D.
2445049 O K
I f you are only concerned w i t h dates
between 3/1/1900 and 2/28/2000, then you
can o m i t line 3 entirely.
On another subject, there is another
correction I noticed i n the dump o f the
fig-FORTH 6502 Assembly Source
at
location OC32, 80 1 A should be D7 06.
-
P e t e r B. Dunckel
52 Seventh Avenue
San Francisco, C A 94118
Really slick! B u t the algorithm would be
hard t o explain t o most people.--ed.
FORTH DIMENSIONS 11115
An underlying prohlem o f conventional
programming languages is that they tend
t o be high level descriptions of the Von
Neumann computer.
The assignment
statement is the principal construct o f
these languages. A program becomes a
series o f these assignment statements,
each o f which requires the modification o f
a single cell. We may think o f the Von
Neumann computer as a set o f storage
cells, a separate processor, and a channel
connecting the two. If assignment statements i m i t a t e the store operation, then
branch statements i m i t a t e jump and t e s t
while variables i m i t a t e storage cells. The
high level languages provide sophisticated
constructs t o directly model the underlying Von Neumann design. Conventional
languages i n the "word a t a time" f l o w
described above require large data transfers through this small channel connecting
main storage and the CPU. Backus calls
this the Von Neumann bottleneck. It is
n o t merely a physical bottleneck but,
more importantly, i t is a bottleneck t o our
thinking
about
computer
languages.
Backus refers to i t as an "intellectual
bottleneck."
He ctiaracterizes conventional languages as both f a t and weak
since increases i n the size and complexity
o f these languages have provided only
small increases i n power. The t y p i c a l programming language requires a large fixed
set o f constructs, is inflexible, and is n o t
extensible. The problem has been eased
by approaches such as top-down design and
structured programming, b u t these have
not provided a solution to the underlying
difficulty. Backus suggests t h a t we need a
new way o f thinking about computing. He
describes a new style which he calls funct i o n a l programming.
functions using a set o f functional
forms t h a t combine these existing
functions t o form new ones.
-
The most fundamental functional
f o r m is called composition. I f the
composition operator is denoted by
o, then i n Backus' notation "fog" i s
the function where g is f i r s t applied
and then f.
-
The functions incorporate no data
and do not name their conventions
nor substitution rules.
-
A function is hierarchical; i.e.,
f r o m simpler functions.
built
Backus points out that, "FP (Functional
Programming) systems are so minimal that
some readers may find i t d i f f i c u l t t o view
them as proqramming languages."
We
have a set of predefined functions i n a
library (dictionary) and rnay define new
functions i n terms of these predefined
functions.
Functional forms are constructs denoting functions which take functions as
parameters. For example, the construct
"if-else-then",
and the construct "do
while" are functional forms. As indicated
above, composition is also a functional
form.
F O R T H o f course has predefined constructs which serve as the functional
forms o f F P systems.
I n fact, F O R T H
provides facilities f o r adding new functional forms.
A n example would be a
"case" construct t o provide a more flexible and clear decision structure than that
o f a set o f nested "if-else-thenrV's. The
capability o f language t o add new functional forms is not inherent i n F P
systems. Backus defines a language w i t h
this capability as a formal functional programming (FFP) language.
An Example o f Functional P r o q r a m m i n ~
The F a c t o r i a l Function
An example of a program w r i t t e n i n
the style o f functional programming is as
follows:
def ! ! ~ e q O + 1;" o [id ,!!subl], where
the notation o, -, and [ 1 denote functional forms. As we have seen, o denotes
composition. The notation [fl,f
1 denotes
construction where [fl,f2 1 ap$ied t o an
argument x yields the sequence <f (x),f2(x)>
The notation p +f;g applied t o an
argument x indicates t h a t the value p(x) is
t o be examined and if p(x) is true the expression yields f(x) else it yields g(x).
.
Functional Proqramminq
This new style o f programming has the
following characteristics:
-
A function (program) is constructed
f r o m a set o f previously defined
Other definitions use> i n the above
are:
eqO applied to x yields a value true if x
is 0, and yields false otherwise.
-
1 is the l i t e r a l value 1 and yields the
Page 137
value 1, regardless of t h e argument.
*
is t h e multiplication operator, and
applied t o a sequence <x,y> yields x*y.
id is the identity operator.
t o x yields x.
id applied
sub1 applied t o an argument x yields x1.
Following t h e logic of t h e above function we s e e t h a t !! applied t o an a r g u m e n t
n yields 1 if n is zero. If n is not z e r o we
g e n e r a t e n*(n-l)!
Clearly then for n s this is a definition
of t h e f a c t o r i a l function. In FORTH (if
t h e language were recursive) we would
write:
.. .,
I1
D U P O= IF l+
ELSE DUP 1 - !!
THEN ;
*
The author has recently implemented
such an o p e r a t o r in FORTH.
**
The way t h a t l i t e r a l s a r e handled c a n
be viewed a s merely a question of implementation and efficiency.
*
FORTH a s a Lanquage with C h a r a c t e r i s t i c s of Functional Proqramming
Consider t h e FORTH (outer) interpreter. Literally all t h a t t h e i n t e r p r e t e r
recognizes a r e functions; or t o be precise,
words t h a t denote functions.** The funda m e n t a l combining f o r m is composition
where in FORTH "fog" would b e expressed
a s g f. Functions need not incorporate
d a t a , do not name t h e i r arguments, and
require no substitution rules f o r p a r a m e t e r
passing. There are no assignment s t a t e m e n t s and a new function is built from
simpler previously defined functions. It is
this s t y l e of programminq in FORTH--so
different than t h a t of conventional languages--that provides a power and flexibility t h a t has sparked t h e enthusiasm of
so many of us.
Surnrnary
This very short summary of the a r t i c l e
by John Backus does not begin to do
justice t o e i t h e r the scope or depth of the
paper.
The "new" t y p e of programming has
generated considerahle i n t e r e s t within t h e
computing cornrnunity and most particu-
,
,
1. J. Oackus, "Can Programming be
Liberated f r o m t h e Von Neumann
Style?" CACM, Vol. 21, No. 8, August
1978, p. 613.
FORTH AND ARTIFICIAL UNGUISTICS
Raymond Weisling
Surakarta, J a w a Tengah
Republik Indonesia
There has not been much said about
the
linguistic
nature
of
computer
languages, principally because so f e w of
t h e m p e r m i t t h e development of syntax
s t r u c t u r e s t h a t apporach human language,
and hence f o s t e r linguistic observation.
FORTH and its o t h e r threaded-code relatives allow f o r such s t r u c t u r e s t o b e
developed, principally because of t h e
larger body of words t h a t arise f r o m i t s
extensibility and hierarchal function of
operators.
The point I wish t o address h e r e is t h e
s y n t a c t i c a l limitations of the language we
a r e building, an artificial language based
in p a r t on a human language (English) t h a t
is widely used wherever technology has
developed. But t h e r e is a fundamental
weakness in t h i s English which I think we
must be a w a r e of, since i t runs counter t o
t h e philosophy of FORTH. This is t h e syntax-sensitivity of word forms, especially
nouns and verbs, which in English a r e
commonly spelled and pronounced exactly
t h e same. We rely on t h e s t r u c t u r e (wordorder, partly) t o distinguish these often
unrelated words.
A few examples a r e in order. Consider
t h e possible function of t h e s e FORTH
words, both with r e s p e c t t o their c u r r e n t
use (some a r e nouns while o t h e r s a r e
verbs), b u t also in their opposite hypothetical use: RlJFFER , FENCE , I<EY ,
LIMIT , LOOP , SPACE , TYPE , etc.
O t h e r s which a prograrnmer might wish t o
use in developing applications might
include: OFFSET , SPAN , INSERT ,
.
FILE CATALOG OUTPUT
Since t h e
action of t h e s e words is not known f r o m
t h e word itself, b u t only f r o m e i t h e r previous a g r e e m e n t or syntax, and since synt a x sensitivity is not a common p a r t o f
FORTH (i.e., where a s y n t a c t i c a l f o r m
does not a l t e r t h e way in which a word is
compiled), some degree of confusion c a n
result.
Furthermore, use of a word in only one
f o r m rules o u t i t s use in another form, exc e p t where i t c a n reside in a different vocabulary. Thus words like KEY , LOOP ,
BLANK , and TYPE (all FORTH verbs)
cannot function a s nouns despite our
t e m p t a t i o n t o use t h e m t h a t way f o r t h e i r
inherent (English language-based) clarity.
The s a m e is t r u e of some of the FORTH
nouns like BLOCK
BUFFER
STATE ,
1-IMIT , and BASE
,
References
The syntaxes of t h e two examples a r e
different. The composition rule is applied
right t o l e f t in t h e f i r s t e x a m p l e and l e f t
t o right in FORTH. T h e rules f o r dropping
arguments a r e different. Construction is
not used in FORTH.* T h a t t h e rules of
syntax a r e different should not be surprising. The operations were defined by
different people a t different times. What
is most important is t h a t on close examination i t is apparent t h a t t h e style is essentially t h e same.
We have "words"
which denote functions which a r e evaluated following very similar rules.
P a g e 138
larly among those i n t e r e s t e d in innovative
approaches t o c o m p u t e r architectures. It
is this author's contention t h a t FORTH is
a functional programming language which
closely resembles t h e approach suggested
by John Backus in his definitive paper. I t
will b e interesting t o s e e if, a s a result of
this paper, languages which have a t t r i butes similar t o FORTH begin t o a p p e a r in
a c a d e m i c circles.
.
,
Thus it is not possible t o know t h e
nature of t h e word f r o m its name alone.
Would prefixes for verbs unnecessarily
c l u t t e r t h e language? Would s o m e prefix
or suffix t o d i f f e r e n t i a t e constants f r o m
variables be useful? O r should we leave i t
alone. The TO and FROM words help clarify things but a r e not without problems,
whereas ! and @ a r e perfectly uniform in
function. Could a FORTH-like language
b e built t h a t allows t h e word-type t o bec o m e p a r t of t h e header, with t h e compiler choosing which f o r m of t h e samenamed word t o use based on i t s s y n t a c t i c a l
position, like nouns (variables, constants,
arrays) being objects of TO and FROM ?
O r does this push us back into the horrible
mess of artificial syntax forms such a s
algebraic notation (something we a r e perhaps proud t o have departed from)?
I offer no solution per se. I only wish
t o point out a weakness t h a t we all should
be sensitive t o when we assign names t o
our words. Since FORTH is still in evolution, this is y e t another a s p e c t t o consider when standards a r e defined, I wish
t o disclairn any implication t h a t I a m a
linguist of any sort o t h e r than Armchair
Linguist. My sensitivity t o this is a result
of living in a different c r ~ l t u r ewhere I a m
learning a human language t h a t p e r ~ n i t s
f a r g r e a t e r fluidity of s t r u c t u r e due t o t h e
inherent differences in nouns and verbs,
shown hy a well codified system of prefixes and suffixes ( m ~ r ~ h e r n o l o g i c adifl
ferentiators).
Those h e r e who learn
Enqlish struggle with t h e s t r u c t u r a l differentiation of all t h e p a r t s of speech
while our rnorpherne differentiators a r e
used f o r relatively useless things like verb
conjugation, plurality, cases, arid tenses
(which a r e all essentially absent in this
p a r t of the world). As technology spreads,
an artificial language f o r man-machine
manipulation ( a two way s t r e e t ) should be
more universally based, a t least with res p e c t t o linguistic modelirrg. As FORTH is
already in use in many p a r t s of t h e world,
t h e channel for feedback is already open.
FORTH DIMENSIONS 11115
FORTH STANDARDS CORNER
R o b e r t L. S m i t h
fig-FORTH).
F i r s t , we define a digit:
M o r e Words on W O R D
I n m y last column, I discussed WORD.
I neglected to rnention an i m p o r t a n t t o p i c
r e l a t i n g t o the i ~ n p l e m e n t a t i o n so f WORD
w h i c h m a y i n f l u e n c e transportability.
P r i o r t o the 79-Standard, the execution o f
WORD caused the s t r i n q f r o m t h e i n p u t
m e d i u m t o be moved t o the d i c t i o n a r y
area, s t a r t i n g a t H E R E w i t h t h e c h a r a c t e r
count.
Sorne implementers would be
t e m p t e d to define t h e 79-Standard WORD
f r o m the older WORD i n a manner somewhat l i k e this:
: WORD
WORD H E R E ;
O t h e r implementers would probably p u t
the s t r i n g elsewhere. N o w suppose t h a t
t h e user wished t o reverse t h e c h a r a c t e r
s t r i n g and emplace the m o d i f i e d s t r i n g i n
t h e dictionary. The r e s u l t f r o m t h e f o r m e r irnplementer's system w i l l n o t be as
expected, and w i l l n o t result i n "equival e n t execution" on t h e l a t e r implementer's
systern. A s i m i l a r b u t m u c h less serious
p r o b l e m occurs w i t h PAD.
P A D is
conventionally o f f s e t f r o m H E R E by a
f i x e d amount (68 bytes i n fig-FORTH).
There are a t least t h r e e d i f f e r e n t solutions:
(1)
Implementatioris which place the
string a t H E R E could be considered non-standard,
and the
p r o b l e m goes away.
(2)
A c l a r i f i c a t i o n could be added t o
t h e Standard i n d i c a t i n g e i t h e r t h a t
t h e s t r i n g w i l l always be a t HERE,
or t h a t it may be a t HERE.
(3)
The problem could be f o r c e d upon
users by r e q u i r i n g t h a t t h e characters f r o m WORD be stored i n a
user-defined area p r i o r t o t h e i r
movement t o the f i n a l destination.
L e t Me Number the w
a
...
...
Next, we add t o t h e o r i g i n a l d e f i n i t i o n o f
number as follows:
number
A number is represented i n the i n p u t
s t r e a m as a w o r d composed o f a sequence
o f one or m o r e digits w i t h a leading ASCII
m i n u s (-) i f t h e number is negative and a
t r a i l i n g ASCII d o t (.) i f the value is t o be
considered double precision.
I r e c o m m e n d t h a t implementers a l l o w
t h e above f o r m a t , and t h a t authors o f
transportable programs adhere t o the
same f o r m a t . I n any case, when t h e Standards T e a m m e e t s again, they should cert a i n l y c l a r i f y t h i s area.
U n d e r t h e Spreading FIG-TREE
As many o f you are aware, there is a
C o m p u t e r Conference Tree (now n i c k named the FIG-TREE) which contains
i t e m s o f i n t e r e s t t o t h e F O R T H comI would l i k e t o encourage a l l
munity.
persons i n t e r e s t e d i n t h e 79-Standard t o
read and c o n t r i b u t e t o the branch o f the
F I G - T R E E c a l l e d 79-STANDARD. A l l you
need is a t e r m i n a l (110 or 300 baud), a
modem, and a telephone. The number is
(415) 538-3580. See back issues o f F O R T H
DIMENSIONS f o r f u r t h e r i n f o r m a t i o n , or
just c a l l up and send a f e w carriage
r e t u r n s u n t i l t h e system responds.
~
I n many areas t h e 79-Standard defines
l i m i t s and f o r m a t s i n p a i n f u l detail. There
is an i m p o r t a n t area i n which very l i t t l e is
said, namely the f o r m a t f o r single and
double precision numbers i n t h e i n p u t
stream. I n the section "interpreter, t e x t "
i t is c l e a r t h a t "numbers" are allowed i n
the i n p u t t e x t s t r e a m and may e i t h e r be
compiled or placed on t h e p a r a m e t e r
stack.
A d e f i n i t i o n o f the f o r m a t o f a
number should include a t a m i n i m u m t h e
d i s t i n c t i o n between double and single precision, t h e sign o f t h e number, and t h e s e t
o f allowed characters f r o m which the
number is constructed.
I n keeping w i t h
the s p i r i t o f the rest o f the Standard, I
would l i k e t o propose a f e w d e f i n i t i o n s
w h i c h should be f a i r l y easy t o i m p l e m e n t
and which appear t o be c o m p a t i b l e w i t h
most c u r r e n t implementations (including
F O R T H DIMENSIONS 11115
A d i g i t is any one o f a set o f ASCIl
characters which represent n u m e r i c values
i n t h e range f r o m 0 t o base-1. F o r bases
g r e a t e r t h a n d e c i m a l 10, t h e set o f chara c t e r s is 0
9 A B C
where the ascending A S C I I sequence is used f o r A and
above.
C o n t r o l and D a t a Acquisition". IEEE
Journal o f Quantum Electronics, Vol
QE-17 No. 9.
N e w York, N e w
Y ork: IEEE, September, 1981.
.
----.Towards More Usable
Systems: - The L S R A D Report.
( L a r g e Systems Requirements f o r
A p p l i c a t i o n Development). Chicago:
Share, Inc., 1979.
------
.
N e w York:
IEEE Standard
IEEE, 1975.
583-1975.
.
------ 1977 L a b o r a t o r y f o r Laser
Energetics
Annual
Report.
Rochester. NY:
Laboratorv f o r
Laser Energetics, 1978.
Moore, Charles.
"Forth:
A New
Way t o P r o g r a m Minicoimputers"
.Journal o f Astronomy and A s t r o N e w York:
physics Supplement
AAAS, September, 1974.
15.
"Forth, The Past
Moore, Charles.
Ten Y e a r s , and t h e N e x t T w o
Weeks". F o r t h Dinlensions. Vol.
San Carlos, CA:
F o r t h Interest
Group, 1979.
16
Rather,
E l i z a b e t h and
Charles
Moore.
"The F O R T H Approach t o
Operating Systems".
A C M '76 Proceedings.
N e w York:
ACM,
October, 1976.
R i t c h i e , D. M. and K. Thompson.
"The U N I X Time-sharing System".
The B e l l System Technical Journal.
Vol. 57 No. 6 P a r t 2. N e w P r o v i dence, NJ: A.T. and T., July-August,
1978.
R i t c h i e , D. M., e t al. "The C Prog r a m m i n g Language". The B e l l Syst e m Technical Journal. V o l 57 No. 6
P a r t 2. N e w Providence, NJ: A.T.
and T., July-August, 1978.
Change: FDIII/4, pg. 118, para 3 to:
The T O concept y a s developed b y
D r . P a u l B a r t h o l d i as an a l t e r n a t i v e
t o constants and variables.
CORRECTIONS
A d d to: F D III/4, pg. 102 t h e following:
REFERENCES
1.
2.
Forsley, L a w r e n c e P.
The B e t a
Laser C o n t r o l System. A t a l k given
a t t h e L a b o r a t o r v f o r Laser Eneraeti c s on M a r c h 9, i 9 7 7 and on 3ulf16,
1977 a t the Wilson Synchrotron,
C o r n e l l University.
Forslev. L a w r e n c e P. " F o r t h M u l t i t a s k i n g ' i n URTH". The Best o f the
San
C o m p u t e r F a i r e s Volume
Francisco: 1979.
x.
3.
Boles, J. A., Pessel, D. and L. P.
Forsley. "Omega A u t o m a t e d Laser
EDITOR'S NOTE:
P e t e r aengtson o f D A T A T R O N I C A B i n
Stockholm, Sweden sent us a copy o f t h e
September, 1981 e d i t i o n o f E l e c t r o n i c s
And C o m p u t i n q Monthly. F e a t u r e a r t i c l e
was FORTH, "The Language o f t h e E i g h t ies" i n which F I G is mentioned prominently. More c o n f i r m a t i o n we are a l l r i d i n g
t h e crest!
Page 139
TECHNOTES, BUGS AND FIXES
T H A T MYSTERIOUS fig-FORTH
AMNESIA
1 have three questions about FORTH:
Many fig-FORTH users have probably
QI I Itnow of two CP/M FORTHs that have
noticed the curious p h @ n ~ m e n ~I refer
il
to
their own way of dealing with the BIOS
and BDOS and as a result cannot read each
other's screens.
What I'm leading t o is
this: CP/M and fig-FORTH are both supposed to be machine independent systems
but cannot read each other's source code
files. CP/M figgers ought t o get together
on this one.
as "amnesia" i n their computers, and those
who understand the method of the fig-F O R T H dictionary search, no doubt understand i t as well. It is an amusing, often
perplexing, but usually useful property
peculiar to fig-FORTH dictionaries.
A. Differences between disk organizations
are sector skewing and location. It is easy
to add definitions t o a FORTH which uses
BIOS so it can read other organizations; it
is not possible the other direction.
2. When selecting a new drive, you need
t o do a COLD start or you'll remain on the
last drive--this is only true i f you are
accessing the same screen number. I f you
ieave an empty line between two definitions on the screen, a L O A D w i l l stop
loading at the empty line.
Are these
F O R T H conventions Ihaven't heard about
yet or are they peculiar to m y Timin
FORTH?
A. Both of these are bugs--demand fixes
f r o m Timin.
3. Somehow(?), I've been leaving a l o t of
control characters behind when using the
editor. They don't show up on a screen l i s t
but they sure r u i n any a t t e m p t a t loading
I am not sure if this is a
the screen.
common problem but I have enclosed a
short routine to replace control charaters
with spaces for anyone else who has this
problem.
SCREEN: 95
( HUNT FOR CONTROL CHARACTERS)
:H U N T ( SCREEN l/ --- )
BLOCK
1024 0 DO DUP C@ DUP 32 <
I F CR . I 1 + " 64 + EMIT
.'I
:I1
DUP U. ELSE DROP
ENDIF 1+ LOOP DROP ;
: FIXSCREEN ( SCREEN 1/ --- )
BLOCK
1024 0 DO DUP C @ 32 < IF
DUP 32 SWAP C! ENDIF
1+ LOOP DROP ;
( ACTUALLY HUNT AND FIXSCREEN
ARE QUITE SIMILAR, HUNT JUST
SHOWS U P ANY GUILLTY CHARACTERS
AND F IXSCREEN REPLACES THEM)
A. Don't know. May be an editor bug or
the way you are using it. I f you add a line
w i t h #P followed immediately by a carriage return i n the f i g editor, a n u l l is
introduced i n t o the line which stops compiling. (editor fix should be supplied)
Page 140
Because names i n fig-FORTH may
have variable length, the distance between
the start of the name and the link to the
next name i n the dictionary is also variable. aecause the width (number of characters saved) i s also allowed t o be less
than the actual number of characters i n
the name, one cannot rely on the count to
provide the address of the link-field, given
the address o f the name-field. This is why
the fig-FORTH compiler automatically
sets the most significant b i t of the f i r s t
character and the last character i n every
name.
By this device, one can scan a
name forward or backward by looking f o r
this bit.
I n a dictionary search, the address i n
the link-field is followed to the beginning
o f the name-field o f the previous word. I f
i t is not a match to the key you are looking for, we scan forward i n memory u n t i l
the most significant b i t tells us we have
found the link-field t o the next word.
When a dictionary link is "broken" by clobbering RAM, an erroneous address is followed, and the system i s said t o "crash".
However, i n fig-FORTH, the system
does not always "die1'. I n many cases, i t is
merely "wounded", displaying a strange
kind of amnesia i n which it has no recollection o f recent definitions, h u t remembers w i t h c l a r i t y i t s "childhood".
What
happens is this: the broken link sends the
dictionary search o f f t o a totally random
p a r t o f memory ( i f you do not have 64K, it
may address R A M where there are no
boards!).
Since i t is not IikeQ to find a
match a t this address, i t scans forward f o r
the most significant b i t that marks the
end of the "name".
The odds are that i t
w i l l eventually f i n d one, mistake the next
two bytes for a link, and follow another
wild address somewhere else.
Now, depending on how much o f your
mernory is filled w i t h dictionary, and depending on what is i n your unused RAM,
the odds are not bad that after bouncing
aimlessly around for awhile, the search
may land i n the middle of a valid name.
One does not expect a match t o compare
w i t h the middle of a name, but the search
then scans f o r the most significant bit,
finds a valid link, and gets back into the
dictionary. What the "amnesia" has actually forgotten, then, is everything between the broken link and the point where
the search re-enters the dictionary.
I f your used R A M is large i n comparison t o FORTH, you are likely to find most
o f F O R T H s t i l l available as a k i n d of crippled monitor to help you find out what
went wrong without re-booting the systeni
(which destroys the damage). Furthermore, since you now know the cause of
this illness, you can exploit i t t o your advantage.
Simply modify your boot-up
RAM-check routine so that it leaves a
pattern i n your unused RAM, such that no
m a t t e r how it is viewed, it w i l l appear t o
be an address somewhere i n the middle o f
a name-field, somewhere near the top o f
your basic F O R T H and utilities. You w i l l
now find, to your delight, that when you
"crash",
you usually have your most
powerful tools s t i l l a t your disposal.
Users of FORTH, Inc. Micro-FORTH
are not likely t o observe this phenomenon.
Because names are always exactly four
characters long, the link f i e l d does not
have to be scanned for; instead, it is found
by simple arithmetic. I n order to re-enter
the dictionary, one must land by chance on
the exact beginning o f a name-field.
Much more likely than this, is t h a t the
search w i l l enter a loop i n which i t goes
again t o an address it has already visited,
and get caught forever. Remember t h a t
the addresses found are by no means random. A l l you have to do is cover the most
common ones.
Steve Munson
3071 E. 7 t h Street, 814
Buena Park, C A 90621
TRANSIENT DEFINITIONS
These u t i l i i t e s allow you t o have temporary definition (such as compiler
words:
CASE, OF ENDOF, ENDCASE,
GODO, etc.) i n the dictionary during
compilation and then remove them a f t e r
compilation.
The word TRANSIENT
moves the dictionary pointer to the
"transient area'' which must be above the
end of the current dictionary. The temporery definitions are then compiled into
this area. Next, the word PERMANENT
restores the dictionary to its norrna!
location. Now the application program is
compiled and the temporary definitions
are rernoved with the word DISPOSE.
DISPOSE w i l l take a few seconds because
i t goes through every link (includinq vocabulary links) and palches thern t o bypass
a l l words above the dictionary pointer.
NOTE: These words are w r i t t e n i n
MicroMotionls FORTH-79 b u t some
nun-79-Standard words are used. The
non-Standard words have the figF O R T H definitions.
Philip Wasson
FORTH DIMENSIONS-
MORE WORDS ABOUT WORD
R o b e r t 13. Villwock
Microsystems, Inc.
in analyzing or proposinq changes t o
any Standard definition, i t is very import a n t t o c o n c e n t r a t e on t h e details of t h e
needed function and t o avoid any preconceived notion of internal implementation
details, unless, of course, ckge two a r e inseparable.
If this is not done, we c a n
severely
and unnecessarily constrain
f u t u r e implementors Frorn doing their b e s t
possible job, or, worse yei:, find t h e m avoiding t h e Standard entirely,
A good c a s e in point is t h e word
WORD. Since most FORT;-1 irnplementors
have favored using the "free space" above
t h e dictionary t o s t o r e tokens e x t r a c t e d
by WORD, and f u r t h e r siin-e their experience s e e m s t o be c e n t e r e d around small
t o medium sized appilcation programs, i t
is tacitly assumed t h a t this f r e e space is
arbitrarily large. In addition to storing
tokens a t HERE, PAD is usually also defined t o float above t h e dictionary in this
"unbounded" f r e e space.
Therefore,
whether WORD handles tokens o f length
128, 256 or even 1024 bytes is innocerrtly
discussed with the idea t h a t the only issue
involved is t h e length descriptor preceding
the string!
However, whether this token buffer
and PAD float above HERE or a r e fixed
location buffers or some different s c h e m e
is devised, they consume real rnernory and
a r e not really "free space". To illustrate,
suppose we assume t h e traditional implementation for a moment and use HERE a s
t h e s t a r t of t h e token buffer used by
WORD. The PAD is then usually f l o a t e d
a t a location equal t o HERE plus s o m e
constant. if WORD must handle tokens a s
long a s 255 bytes, then PAD must be
floated a t least 256 bytes above HERE t o
prevent token e x t r a c t i o n from corrupting
t h e c o n t e n t s of PAD. The 79-STANDARD
requires t h a t PAD be able t o hold a t l e a s t
64 bytes, so now we're a t HERE + 320
bytes.
If one is compiling a larqe application
program, t h e dictionary will grow until
eventually HERE + 320 hits t h e peg
(whether it is a fixed boundary or t h e
PSTACK bottom or whatever). When it
does, no m o r e compilation c a n t a k e place
(even though t h e r e is a t least 320 b y t e s of
unused dictionary left) without violating
t h e Standard. If you perinit f u r t h e r compilation, t h e size of P A D begins t o drop
below t h e minimum 64, which is not allowed. Even if you s t a r t automatically
reducing t h e P A D o f f s e t so t h a t i t remains
fixed in size, t h e token buffer begins
shrinking and c a n no longer satisfy t h e 256
byte string requirement.
I'm trying t o illustrate t h a t "free
space" is only "free" a s long a s all of
FORTH DIMENSIONS I1115
menlory isn't rreedrtl, When memory fills,
these " f r e e space" buffers p r e v e n t c o d e
f r o m being conlpiled into their space. The
floating buffer concept s e e m s t o obscure
this f a c e more than i f t h e token buffer and
t h e PAD were given fixed, dedicated a r e a s
of menrory.
If t h e token buffer must handle 1024
byte strings, t h e situation is even worse.
We then have to stop cornpiling when t h e
dictionary has over 1K bytes of s p a c e
left! Since most of t h e t i m e t h e tokens
e x t r a c t e d by WORD a r e very s h o r t (31
c h a r a c t e r s or less), we pay a dear price t o
be able t o handle Lhe occasional long
string, given t h a t WORD rnust handle it,
and WORD is defined a s a t present.
If you discard tile notion t h a t a more
or less unbounded "free space'' exists
somewhere in memory, the approach t o
WORD'S definitior-i t a k e s on a new f a c e t .
A t Mic~*osysterns, we have developed
several large applications using FORTH,
which resulted in t a r g e t cornpiled code in
t h e range of 32K Lo 481< bytes, exclusive
of the dictionary headers and t h e FORTH
operating sysem software. When applications become t h a t large, there isn't even
room t o hold all t h e names in memory a t
one t i n e (even if constrained t o 3 chara c t e r s and length), l e t alone room t o burn
for large "free space" buffers! Our implementati
which
is
called
proFORTHm,
handles this problem by
rneans of
multiple dictionaries and
ROMiRAM segment control with selective
symbol purging. Names a r e classified a s
t o their needed lifetimes during compilation. When t h e names are no longer
needed, they a r e purged and their memory
s p a c e is reclaimed. This allows much of
the memory devoted t o dictionary headers
t o be reused many t i m e s during c o m pilation, thereby enabling very large applications t o be compiied.
The foregoing is not a commercial f o r
proFORTH, but r a t h e r is intended t o illust r a t e t h a t the scope of usage t o which
FORTH can be applied is very broad. In a
situation where you have multiple dictionaries and a r e fighting f o r every byte of
memory available, thinking in t e r m s of
storing unbounded tokens a t HERE and
floating PADS of arbitrary length becomes
very incongruous. Admittedly, I've described a somewhat e x t r e m e situation, b u t
i t is not a s r a r e a s you may think. Microprocessor applications a r e getting m o r e
ambitious every day and sooner or l a t e r
you will have a crowded memory
condition. I think FORTH should be able
t o handle t h e s e situations gracefully,
without having t o deviate from t h e
Standard.
When defining WORD, then, one objective should be t o enable users t o
e x t r a c t arbitrarily long tokens f r o m the
t e x t s t r e a m b u t not f o r c e t h e implementor
t o provide an arbitrarily long memory
buffer t o accomplish it. While this inay
sound a little like trying t o "have your
c a k e arid e a t it too", a r a t h e r simple
factoring of WORD r a n easiiy accomplish
it.
To illustrate my point, suppose we
devise a more basic \VOP,D called (WORD)
and define it a s follows:
where ENCILOSE is defined a s in t h e FIG
glossary and -ROT is equivalent t o ROT
ROT.
This new (WORD) e x t r a c t s t h e next
token from the t e x t s t r e a m , delimited by
c, and l e a v e s its address and length on the
stack.. Actualiy, the token is merely l e f t
in t h e input buffer (keyboard or disk) and a
pointer t o i t is given. Thus, no additional
or temporary buffer is needed. The user
may now do anything he (she) wants with
t h e string, including niovinq it t o HERE if
desired (and if it will fit).
F o r example, if you want t o compile
t h e token a s a "dot-quote" string, a definition such a s WORD, c a n be used.
:
WORD,
( r -- )
(WORD)
IIFRE O\ITH If
('P;OVE
COUN'I'
;$Ll.OT SwkP
OVER ?!
;
If you want a blank-filled line put in
PAD, t h e following could be used:
:
TEXT
(liORL))
(
c -- ) I'AD
('/I.
I+ 6LAURS
C/L >!IN P:li)
C!
Phi>
COUNI CC:OYI ;
For t h e routine compiler/interpreter
job of extracting small (31 c h a r a c t e r s or
less) tokens from t h e t e x t s t r e a m , t h e following could be used:
where WBFR is a "small" word buffer
limited t o WDSZ + 2. Note t h a t e x c e p t
possibly for the self-imposed size limitation*, t h e last definition satisfies t h e
79-STANDARD definition of WORD.
If you will carefully examine t h e s e
constructs, you c a n quickly discover t h a t
given (WORD) a s t h e elementary f o r m , t h e
user c a n e x t r a c t tokens of any size, put
t h e m wherever he wants, and f o r m a t t h e m
with or without t h e trailing delimiter, or
f o r t h a t m a t t e r , t h e leading count byte (or
1 6 bit word if you prefer:. In other words,
t h e user ought to be able t o do essentially
anything t h a t he may desire, b u t , the implementor need not provide any special,
temporary buffers or arbitrary size just t o
P a g e 141
satisfy the Standard.
Using (WORD) as the fundamental
token e x t r a c t o r allows i m p l e m e n t o r s t o
c o m p i l e dot quote strings, f o r example,
w i t h o u t t h e need f o r any t r a n s i t i o n a l b u f fers (see WORD,).
O n the o t h e r hand, i f
dot quote strings are acquired by t h e
present f o r m o f WORD i n the Standard,
then t h e token b u f f e r m u s t be a t least as
large as the longest dot quote string,
which is presently specified t o be 127
characters.
One m i g h t argue t h a t i f the b u f f e r is
a t HERE, t h e r e is no p e n a l t y since t h a t is
where the s t r i n g must go anyway, and i f it
won't f i t it can't be compiled. However,
this l i n e o f reasoning is again l i m i t e d b y a
parochial v i e w t h a t a l l F O R T H implementations must be alike.
I f a system l i k e
p r o F O R T H is being used, t h e t a r g e t defini t i o n body can optionally b e compiled " i n
place" separate f r o m t h e d i c t i o n a r y
header. There may b e r o o m f o r the s t r i n g
i n t h e t a r g e t segment o f m e m o r y b u t n o t
enough i n the dictionary.
I n conclusion, l e t m e say t h a t i f t h e r e
is s u f f i c i e n t memory, t h e user may
declare a l l t h e b u f f e r s he wants, b u t we
should not require t h a t these b u f f e r s b e
p r e a l l o c a t e d by the i m p l e m e n t o r i n order
t o satisfy the Standard. Therefore, I subm i t t h a t m y d e f i n i t i o n o f (WORD) is a
m o r e fundamentally valuable f u n c t i o n
than WORD (as c u r r e n t l y defined i n t h e
79-STANDARD,)
f r o m which a l l others
can be b u i l t w i t h o u t burning sometimes
precious m e m o r y space.
There are already enough b u f f e r s and such r e q u i r e d
( d i r e c t l y or i n d i r e c t l y ) b y the Standard.
Let's n o t a r b i t r a r i l y insist on m o r e by acc i d e n t l y defining words i n such a way as t o
f o r c e an i m p l e m e n t o r t o p r o v i d e them.
*
I emphasize "possibly" because f o r t u n -
a t e l y the Standard is n o t e x p l i c i t as t o t h e
l e n g t h o f tokens t h a t m u s t ' b e handled by
WORD.
Sorry you had t r o u b l e w i t h FEDIT. The
l i s t i n g was r e t y p e d a t F I G and several
typos creeped in. They are:
1+
be
CALL FOR PAPERS
1982 Rochester F O R T H Conference
on
D a t a Bases and Process C o n t r o l
M a y 17 through M a y 21, 1982
U n i v e r s i t y o f Rochester
Rochester, N e w Y o r k
.
L e t m e k n o w how it works f o r you. If
you would l i k e a machine produced listing,
I could r u n one f o r you f r o m m y c u r r e n t
version.
Edgar H. Fey, 3r.
1 8 Calendar C o u r t
L a Grange, IL 60525
The second annual Rochester F O R T H
Conference w i l l be h e l d i n May, and w i l l
be hosted by t h e U n i v e r s i t y o f Rochester's
L a b o r a t o r y f o r Laser Energetics.
This
year's topics complement and e x t e n d t h e
w o r k described a t the 1 9 8 1 F O R M L Conference and t h e previous Rochester Conference.
We believe t h a t the areas of
data bases and process c o n t r o l c a n b e
uniquely d e a l t w i t h using F O R T H .
There is a c a l l f o r papers on t h e f o l l o w i n g topics:
1.
D a t a Bases, including, b u t n o t l i m i t e d to: hierarchical, n e t w o r k and
r e l a t i o n a l models; s c i e n t i f i c use;
process control; and c o m m e r c i a l
systems.
2.
Process Control, including, b u t n o t
l i m i t e d to:
multitasking, m e t a compilation, data acquisition and
r e a l t i m e systems; video games.
3.
R e l a t e d concepts of:
speed/space
implementation,
tradeoffs; user interactions; designer tools; and graphics.
A HELPFUL UTILITY
Here's a short F O R T H w o r d o f g r e a t
u t i l i t y t h a t I use h e a v i l y i n m y screens. I
hope you l i k e it. I t s name is CVD, w h i c h
stands f o r "convert t o decimal".
DECIMAL
: CVD
BASE @ SWAP
OVER / M O D
ROT /MOD
10 * +
10 * +
I l i k e t o w o r k i n hexidecimal, b u t o f t e n
m a k e mistakes when using t h e words
L O A D , LIST, and many o f the F O R T H
screen e d i t o r words because I ' m t h i n k i n g
i n d e c i m a l when the system's i n hex. I f I
do t h e following:
C V D LIST ;
t h e n 130 L I S T l i s t s screen 130 whether I ' m
i n d e c i m a l or hex. It also works f o r any
other base, as long as t h a t base accepts
the number.
be
As t o h o w it works, a l i t t l e work w i l l
show t h a t C V D splits a t h r e e - d i g i t number
i n t o i t s respective d i g i t s (IE, 130 becomes
1, 3, and 0) and reassembles t h e d i g i t s i n t o
t h e number t h a t is, i n decimal, the same
as t h e keys pressed b y the user.
Papers w i l l be handled i n e i t h e r o r a l
sessions or poster sessions, although o r a l
papers w i l l be r e f e r e e d i n accordance w i t h
conference direction, paper q u a l i t y and
topic. Please s u b m i t a 200 word a b s t r a c t
b y M a r c h 15, 1982. The o r a l papers deadline is A p r i l 15, 1982, and t h e poster
papers deadline is May 1, 1982. Send abstracts and papers t o t h e conference
chairman, L a w r e n c e Forsley, b y those
dates. Please keep papers t o a m a x i m u m
o f 10 p r i n t e d pages.
I f this r e s t r i c t i o n
causes a serious problem, c o n t a c t us.
F o r m o r e i n f o r m a t i o n , please c o n t a c t
the conference chairman at:
L a w r e n c e P. Forsley
L a b o r a t o r y f o r Laser Energetics
U n i v e r s i t y o f Rochester
250 East R i v e r R o a d
Rochester, N e w Y o r k 14623
be
You are p e r f e c t l y r i g h t t h a t source
t e x t should be loadable. I t a l k e d t o some
Page 142
R E P L is a pseudonym f o r t h e F i g F O R T H l i n e e d i t o r definition, R
I used
the pseudonym because F E D I T was t h e
f i r s t p r o g r a m I w r o t e i n F O R T H and I
r e a l l y wasn't f a m i l i a r enough w i t h Vocabularies t o c o m f o r t a b l y use a w o r d t h a t was
already used i n t h e F O R T H vocabulary.
: LIST
CORRECTION TO F E D I T
1. SCR 64 L i n e 10: c o m p i l e should
COMPILE
2. SCR 65 L i n e 23: l + / M O D should be
16 /MOD
3. SCR 67 L i n e 48: B / B U D should
B/BUF
4. SCR 67 L i n e 49: :e should be : .E
5. SCR 67 L i n e 50:
+ A L I N should
+ALIN
o f the people a t F I G about t h i s and they
were a c u t e l y aware o f t h e p r o b l e m b u t
they are simply n o t set up t o d i r e c t l y
reproduce listings i n t o F D a t t h e present
time. They do the best job they can w i t h
t h e resources available t o them, and they
w o r k darn h a r d a t it. Ican't f a u l t them.
Gregg Williams
B Y T E Publications
PO Box 372
Hancock, N H 03449
F O R T H DIMENSIONS III/5
A FORTH ASSEMBLER
FOR THE 6502
b y Williarri F. Raqsdale
ASSEMBLER (now C O N T E X T )
FORTH
(chained t o ASSEMBLER)
user's
( C U R R E N T i f one exits)
FORTH
(chained t o user" vocab)
t r y f o r l i t e r a l number
else, do e r r o r a b o r t
INTRODUCTION
This a r t i c l e should f u r t h e r p o l a r i z e t h e
a t t i t u d e s o f those outside t h e growing
c o m m u n i t y o f F O R T H users. Some w i l l be
fascinated
by
a
label-less,
macroassembler whose source code is only 96
lines long!
Others w i l l be r e p e l l e d b y
reverse Polish syntax and t h e absence o f
labels.
The author irnmodestly c l a i m s t h a t t h i s
is t h e best F O R T H assembler e v e r d i s t r i buted. It is the only such assembler t h a t
detects a l l errors i n op-code generation
and c o n d i t i o n a l structuring. It is released
t o t h e public domain as a defense mechanism.
Three good 6502 assemblers were
s u b m i t t e d t o t h e F O R T H I n t e r e s t Group
b u t each had some lack.
Rather than
merge and e d i t f o r publication, I chose t o
publish mine w i t h a l l the s u b m i t t e d features plus several more.
Imagine having an assembler i n 1300
bytes o f o b j e c t code with:
1.
User macros ( l i k e IF, UNTIL,) definable a t any time.
2.
L i t e r a l values
numeric base,
time.
3.
Expressions using any
c o m p u t a t i o n capability.
4.
5.
expressed i n any
a l t e r a b l e a t any
resident
Nested c o n t r o l s t r u c t u r e s w i t h o u t
labels, w i t h e r r o r control.
Assembler source i t s e l f i n a p o r t able h i g h l e v e l language.
The above sequence is t h e usual a c t i o n
o f Forth's t e x t i n t e r p r e t e r , w h i c h remains
i n c o n t r o l during assembly.
D u r i n g assembly o f C O D E definitions,
F o r t h continues i n t e r p r e t a t i o n o f each
w o r d encountered i n t h e i n p u t s t r e a m ( n o t
i n t h e c o m p i l e mode).
These assembler
words specify operands, address modes,
and op-codes.
A t t h e conclusion o f t h e
C O D E d e f i n i t i o n a f i n a l e r r o r check verifies c o r r e c t c o m p l e t i o n b y "unsmudging"
t h e definition's name, t o rnake it available
f o r d i c t i o n a r y searches.
1.
The c o m m a shows the conclusion
o f a l o g i c a l g r o u p i ~ i gt h a t would be
one l i n e of classical assembly
source code.
2.
"," compiles i n t o t h e dictionary;
thus a c o m m a i m p l i e s t h e p o i n t a t
which code is generated.
3.
The "," distinguishes op-codes
f r o m possible hex numbers A D C
and ADD.
NEXT
F o r t h executes your word definitions
under c o n t r o l o f t h e address i n t e r p r e t e r ,
named NEXT.
This short code r o u t i n e
moves execution f r o m one definition, t o
the next. A t the end o f your code definition, you must r e t u r n c o n t r o l t o N E X T or
else t o code which r e t u r n s t o NEXT.
RUN-TIME, ASSEMBLY-TIME
RETURN OF CONTROL
One must b e c a r e f u l t o understand a t
w h a t t i m e a p a r t i c u l a r word d e f i n i t i o n
executes.
D u r i n g assembly, each assembler w o r d i n t e r p r e t e d executes.
Its
f u n c t i o n a t t h a t i n s t a n t is called 'assembling' o r 'assembly-time'.
This f u n c t i o n
m a y involve op-code generation, address
calculation, mode selection, etc.
The l a t e r execution o f t h e generated
code is c a l l e d 'run-time'.
This d i s t i n c t i o n
is p a r t i c u l a r y i m p o r t a n t w i t h the conditionals. A t assembly t i m e each such w o r d
(i.e., IF, U N T I L , BEGIN, etc.) i t s e l f 'runs'
t o produce machine code which w i l l l a t e r
execute a t what is labeled 'run-time' when
i t s named code d e f i n i t i o n is used.
M o s t 6502 systems can resume execut i o n a f t e r a break, since the m o n i t o r saves
t h e C P U r e g i s t e r contents. Therefore, we
must r e t u r n c o n t r o l t o F o r t h a f t e r a
r e t u r n f r o m the monitor. N E X T is a constant t h a t specifies t h e machine address
of
Forth's
address
interpreter
(say
$0242). H e r e i t is t h e operand f o r JMP,.
As JMP, executes, it assembles a machine
code jump t o t h e address o f N E X T f r o m
t h e assembly t i m e stack value.
SECURITY
Numerous tests are made w i t h i n the
assembler f o r user errors:
A N EXAMPLE
1.
A l l parameters used i n C O D E
definitions m u s t be removed.
As a p r a c t i c a l example, here's a simple
c a l l t o t h e system monitor, via t h e N M I
address v e c t o r (using t h e B R K opcode).
2.
Conditionals must
nested and paired.
3.
Address modes and operands must
be allowable f o r t h e op-codes
be
properly
OVERVIEW
F o r t h is provided w i t h a machine language assembler t o c r e a t e execution procedures t h a t would be t i m e i n e f f i c i e n t , i f
w r i t t e n as colon-definitions. It is intended
t h a t "code" be w r i t t e n s i m i l a r l y t o high
level, f o r c l a r i t y o f expression. Functions
may be w r i t t e n f i r s t i n high-level, tested,
and then re-coded i n t o assembly, w i t h a
m i n i m u m o f restructuring.
T H E ASSEMBLY PROCESS
Code assembly just consists o f i n t e r p r e t i n g w i t h t h e ASSEMBLER vocabulary
as CONTEXT. Thus, each word i n t h e inp u t stream w i l l be m a t c h e d according t h e
F o r t h p r a c t i c e o f searching C O N T E X T
first then CURRENT.
CODE M O N ( exit to monitor )
BRK, N E X T JMP, E N D - C O D E
The w o r d C O D E is f i r s t encountered,
and executed b y F o r t h . C O D E builds the
f o l l o w i n g name "MON" i n t o a dictiorlary
header and calls ASSEMBLER as the
C O N T E X T vocabularly.
The "(" is n e x t found i n F O R T H and
executed t o skip t i 1 ")". This m e t h o d skips
over comments. N o t e t h a t the name a f t e r
C O D E and t h e 'I)'' a f t e r "(" must be on t h e
same t e x t line.
OP-CODES
BRK, is n e x t found i n t h e assembler as
t h e op-code. When BRK, executes, it assembles the b y t e value 00 i n t o the dict i o n a r y as t h e op-code f o r "break t o m o n i t o r v i a "NMI".
These tests are accomplished by
checking t h e stack position ( i n CSP) a t t h e
c r e a t i o n o f t h e d e f i n i t i o n name and
comparing it w i t h t h e position a t E N D CODE.
ILegality of address modes and
operands is insured b y lneans o f a h i t mask
associated w i t h each operand.
Remember t h a t i f an e r r o r occurs
during assembly, E N D - C O D E never executes. The result is t h a t t h e "smudged"
c o n d i t i o n of the d e f i n i t i o n name remains
i n t h e "smudged" c o n d i t i o n and w i l l n o t be
found during d i c t i o n a r y searches.
The user should be aware t h a t one
e r r o r n o t trapped is referencing a definit i o n i n t h e wrong vocabl!lary:
i.e.,
Many assembler words narnes end i n
The significance o f t h i s is:
",".
F O R T H DIMENSIONS
III/5
O= o f ASSEMBLER when you want
0= o f F O R T H
Page 143
(Editor's note: the listing assumes that
the figFORTH error messages are already
available i n the system, as follows:
?CSP
NITION
position
the user
creation
i 9 2 the
~ ~@PFCrr
~
message "DEFINOT FINISHED" if the stack
differs f r o m the value saved i n
variable CSP, which is set a t the
o f teh definition name.
EXAMPLES
Here are examples o f F o r t h vs. conventional assembler. Note t h a t the operand comes first, followed by any mode
modifier,
2nd
then
the
op-code
mnemonic.
This makes best use o f the
stack a t assembly time. Also, each assembler word is set o f f by blanks, as is
required f o r a l l F o r t h source text.
BOT LDA,
BOT 1+ORA,
SEC ORA,
L D A (0,X)
O R A (1,X)
ORA (2,X)
5EC l+ORA,
ORB ( 3 3 )
To obtain the 14-th byte on the stack:
BOT 13 + L D A ,
RETURN STACK
?PAIRS issues the error message
"CONDITIONALS NOT IMPAIRED1' i f i t s
two arguments do not match.
3 ERROR prints the error message
"HAS INCORRECT ADDRESS MODE".)
SUMMARY
The object code o f our example is:
CODE M O N
link f i e l d
code field
BRK
JMP N E X T
OP-CODES, revisited
The bulk of the assembler consists of
dictionary entries for each op-code. The
6502 one mode op-codes are:
.A ROL,
111 L D Y ,
D A T A ,X STA,
D A T A ,Y CMP,
6 X) ADC,
POINT ) Y STA,
VECTOR ) JMP,
ROL A
L D Y Ill
STA DATA,X
C M P DATA,Y
A D C (06,X)
STA (POINT),Y
JMP (VECTOR)
(.A distinguishes f r o m hex number OA)
The words D A T A and VECTOR specify
machine addresses. I n the case o f "6 ) X
ADC," the operand memory address $0006
was given directly. This is occasionally
done i f the usage o f a value doesn't justify
devoting the dictionary space t o a symboli c value.
The F o r t h Return Stack is located i n
the 6502 machine stack i n Page 1. It
starts at $OlFE and builds downward. N o
lower bound is set or checked as Page 1
has sufficient capacity f o r a l l (non-recursive) applications.
By 6502 convention the CPU's register
points t o the next free byte below the bott o m o f the Return Stack. The byte order
follows the convention of low significance
byte a t the lower address.
Return stack values may be obtained
by: PLA, PLA, which w i l l p u l l the low
byte, then the high byte f r o m the return
stack. To operate on aribitrary bytes, the
method is:
6502 CONVENTIONS
1)
save X i n XSAVE
2)
execute TSX,
register t o X.
3)
use RP) t o address the lowest
byte o f the r e t u r n stack. Offset
the value t o address higher
bytes.
(Address
mode
is
automatically set t o ,X.)
4)
Restore X f r o m
Stack Addressing
BRK,
DEX,
PHA,
RTS,
TAY,
CLC,
DEY,
PHP,
SEC,
TSX,
CLD,
INX,
PLA,
SED,
TXS,
CLI,
INY,
PLP,
SEI,
TXA,
CLV,
NOP,
RTI,
TAX,
TYA,
When any of these are executed, the
corresponding op-code byte is assembled
into the dictionary.
The multi-mode op-codes are:
ADC,
ORA,
INC,
CPX,
JSR,
AND,
SBC,
LSR,
CPY,
JMP,
CMP,
STA,
ROL,
LDX,
BIT,
EOR,
ASL,
ROR,
LDY,
LDA,
DEC,
STX,
STY,
These usually take an operand, which
must already be on the stack. An address
mode may also be specified. I f none is
given, the op-code uses z-page or absolute
addressing. The address rnodes are determined by:
Symbol
.A
Mode
,X
accumulator
immediate
indexed X
,Y
indexed Y
1
X)
)Y
)
none
indexed indirect X
indirect indexed Y
indirect
memory
Operand
none
8 b i t s only
z-page or
absolute
z-page or
absolute
z-page only
z-page only
absolute only
z-page or
absolute
The data stack is located i n z-page,
The
usually addressed by "Z-PAGE,X1'.
stack starts near $009E and grows downward.
The X index register is the data
stack pointer. Thus, incrementing X by
t w o removes a data stack value; decrementing X twice makes room f o r one new
data stack value.
Sixteen b i t values are placed on the
stack according t o the 6502 convention;
the low byte is a t low memory, w i t h the
high byte following. This allows "indexed,
indirect X" directly o f f a stack value.
The b o t t o m and second stack values
are referenced o f t e n enough that the supp o r t words BOT and SEC are included.
Using
ROT LDA, assembles L D A (0,X) and
SEC ADC, assembles ADC (2,X)
BOT leaves 0 on the stack and sets the
address mode t o ,X. SEC leaves 2 on the
stack also setting the address mode to ,X.
Here is a p i c t o r i a l representation of
the stack i n z-page.
b o t high
bot low
t o bring the
XSAVE.
As an example, this definition nondestructively tests t h a t the second i t e m
on the return stack (also the machine
stack) is zero.
CODE IS-IT ( zero ? )
XSAVE STX, TSX,
(setup for
r e t u r n stack)
RP) 2+ LDA, RP) 3 + ORA,
( or 2nd item's two bytes
together)
O= IF, INY, THEN, ( i f zeru, burnp
Y t o one)
TYA, PHA, XSAVE LDX, (save
low byte, rstore data stack)
PUSH JMP, END-CODE ( push
boolean)
Return Stack
l o byte
second
item
lo byte
bottom
item
<==X offset
above $0000
Here is an examples of code to "or" t o
the accumulator four bytes on the stack:
Page 144
S
F O R T H DIMENSIONS
11115
F O R T H REGISTERS
Several F o r t h registers are available
only a t the assembly level and have been
given names that r e t u r n t h e i r memory addresses. These are:
IP
W
address
of
the
Interpretive
Pointer, specifying the n e x t F o r t h
address which w i l l be interpreted
by NEXT.
address o f the pointer t o the code
field of the dictionary definition
just interpreted by NEXT.
W-1
contains $6C7 the op-code f o r indirect jump.
Therefore, jumping
t o W-1 wi!l indirectly jump via W
t o the machine code for the definition.
U P User Pointer containing address of the base of the user
area.
J
a dt.ility area i n 2-page f r o m
N - 1 t h r u N+7.
pointers f o r indexedtindirect addressing or
f o r temporary values. As an example o f
use, see CMOVE i n the system source
code.
t r o l words:
The assembler word N returns the
base address (cjsually $0001). The N Area
spans 9 bytes, f r o m N-1 t h r u Nd. Conventionail?, N-1 holds one b y t e and N,
N+2, N+4, N+6 are pairs which may hold
16-bit values. See SETUP f o r help on
moving values t o the N Area.
Here again, the assembler words end
w i t h a comma, t o indicate t h a t code is
being produced and t o clearly different i a t e f r o m the high-level form.
It is very important t o note t h a t many
F o r t h procedures use N. Thus, N may only
be used w i t h i n a single code definition.
Never expect t h a t a value w i l l remain
there, outside a single definition!
BEGIN,
THEN:
UNTIL,
IF,
ELSE,
HighOne rnajor difference occurs!
level f l o w is controiled b y run-time
boolean values on the data stack.
Assembly f l o w is instead controlled by processor status bits. The programmer must
indicate which status b i t t o test, just before a conditional branching word (IF,
and UNTIL,).
Examples are:
CODE DEMO HEX
6 # ILDA, N 1 - STA,
(setup a counter)
PORT LDA, 0- IF, <a> TIiEN,
(read port, i f equal t o zero do <a> )
BEGIN, 3C101 BIT,
( t i c k l e a port)
PORT 1-DA, 0- NOT IF, <a> THEN,
(read port, i f not equal t o zero
do <a>)
N 1 - DEC,
(decrement the counter)
CPU Registers
The conditional specifiers f o r 6502 are:
When F o r t h execution leaves N E X T t o
execute a CODE definition, the following
conventions apply:
O = UNTIL, N E X T JMP, END-CODE
(!oop till negative)
SETUP
1.
2.
The Y index register is zero.
may be freely used.
It
The X index register defines the
low byte o f the b o t t o m data stack
i t e m relative t o machine address
$0000.
3.
The C P U stack pointer S points
one byte below the l o w byte o f the
b o t t o m r e t u r n stack item. Executing PLA, w i l l p u l l this b y t e t o
the accumulator.
4.
The accumulator may be freely
used.
5.
The processor is i n the binary
mode and must be returned i n t h a t
mode.
O f t e n we wish t o move stack values t o
t h e N area. The sub-routine SETUP has
been provided f o r this purpose. Upon entering SETUP the accumuiator specifies
the quantity o f 16-bit stack values t o be
moved t o the N area. That is, A may
be 1, 2, 3, or 4 only:
3 !
! LDA,
stack before
H high
G-low
F
N after
stack a f t e r
H
bot--> G-
F
XSAVE is a byte b u f f e r i n z-page, f o r
temporary storage o f the X register.
Typical usage, w i t h a c a l l which w i l l
change X, is:
F o r t h discards the usual convention o f
sssembler labels.
Instead, two replacements are used. First, each F o r t h definit i o n name is permanently included i n the
dictionary. This allows procedures t o be
located and executed by name a t any t i m e
as w e l l as b e compiled w i t h i n other definitions.
When absolute memory registers are
required, use the IN Area1 i n the base
page.
These registers may be used as
FORTH DIMENSIONS III/5
C=l in
N=l
Z=1
C =O
N=O
Z=0
The overflow status b i t is so rarely
If it is
used, t h a t it is n o t included.
desired, compi!e:
ASSEMBLER DEFINITIONS HEX
(test overflow
set)
50 CONSTANT VS
CONDITIONAL LOOPING
A conditional loop is formed a t assembler level by placing the portion t o be
repeated between BEGIN, and UNTIL,:
CONTROL FLOW
N Area
test carry set
processor
status
0<
byte less than zero
O=
equal t o zero
CS NOT test carry clear
0 <NOT test positive
O= NOT test n o t equal zero
SETUP JSR,
XSAVE
CODE DEMO
XSAVE STX, USER'S JSR,
( which w i l l change X )
XSAVE LDX, N E X T JMP,
END-CODE
CS
Secondly, w i t h i n a code definition,
execution f l o w is controlled by Label-less
branching according t o "structured programming".
This method is identical t o
the f o r m used i n colon-definitions. Branch
calculations are done a t assembly t i m e by
temporary stack values placed by the con-
6 # LDA,
N STA,
(define loop counter i n N)
BEGIN, PORT DEC,
(repeated action)
N DEC,
O= UNTIL,
( N reaches zero]
First, the byte a t address N is loaded
w i t h the value 6. The beginning o f the
loop is marked (at assembly time) by
BEGIN,. Memory a t PORT is decremented, then the loop counter i n N is decremented. O f course, the C P U updates i t s
status register as N i s decremented.
Finally, a test f o r Z=1 is made; i f N hasn't
reached zero,
execution returns t o
BEGIN,. When N reaches zero (after executing PORT DEC, 6 times) execution
continues ahead a f t e r UNTIL,. Note t h a t
Page 145
BEGIN, generates no machine code, but is
only an assembly t i m e locator.
Paths of execution may be chosen a t
assembly i n a similar fashion and done i n
colon-definitions. I n this case, the branch
is chosen based on a processor status condition code.
O= IF,
PORT LDA,
THEN, (continuing code)
( f o r zero set)
I n this example, the accumulator is
loaded f r o m PORT.
The zero status is
tested i f set (Z=l). If so, the code (for
zero set) is executed. Whether the zero
status is set or not, execution w i l l resume
a t THEN,.
The conditional branching also allows a
specific action for the false case. Here
we see the addition of the ELSE, part.
PORT LDA, O= IF, < f o r zero set>
ELSE, <for zero clear>
THEN, <continuing code>
The test of PORT w i l l select one of
two execution paths, before resuming
execution a f t e r
THEN,.
The next
example increments N based on b i t D7 of
a port:
PORT LDA,
O< IF, N DEC,
ELSE,
THEN,
N INC,
( f e t c h one b y t e )
( if D7=1, decrement
N
( i f D7=O, increment
N
( continue ahead )
CONDITIONAL NESTING
Conditionals may be nested, according
t o the conventions o f structured programming.
That is, each conditional sequence begun (IF, BEGIN,) must be terminated (THEN, UNTIL,) before the next
earlier conditional is terminated.
An
ELSE,
must pair with the immediately
preceding IF,.
BEGIN, < code always executed>
CS IF, <code i f carry set)
ELSE,
<code i f carry clear>
THEN,
O= NOT UNTIL, ( loop till condition
flag is non-zero)
<code that continues onward>
Next is an error that the assembler
security w i l l reveal.
BEGIN, PORT LDA,
0- IF, BOT INC,
O = UNTIL, ENDIF,
The UNTIL, w i l l not cornplete the
pending BEGIN, since the immediately
preceding IF, is not completed. An error
trap w i l l occur a t UNTIL, saying "conditionals not paired".
Page 146
RETURN OF CONTROL, revisited
FOOLING SECURITY
When concluding a code definition,
several r o m m o n stack manipulations often
are needed. These functions are already
i n the nucleus, so we may share their use
just by knowing their return points. Each
o f these returns control t o NEXT.
Occasionally we wish t o generate
unstructured code. To accomplish this, we
can control the assembly t i m e security
checks, to our purpose.
First, we must
note the parameters utilized by the
control structures a t assembly time. The
notation below is taken f r o m the assembler glossary. The --- indicates assembly t i m e execution, and separate input
stack values f r o m the output stack values
o f the words execution.
POP
POPTWO remove one 16-bit stack
values.
POPTWO
remove t w o 16-bit stack
values.
PUSH
add two bytes to the data
stack.
PUT
w r i t e two bytes to the
data stack,
over the
present b o t t o m of the
stack.
Our next example complements a byte
i n memory. The bytes' address is on t h e
stack when INVERT is executed.
CODE INVERT ( a memory byte ) HEX
BOT X) LDA,
( f e t c h byte addressed
by stack)
(complement accumuF F i1 EOR,
lator)
BOT X) STA, ( replace i n memory )
POP JMP, END-CODE ( discard
pointer f r o m stack,
return t o NEXT )
A new stack value may result f r o m a
code definition. We could program placing
it on the stack by:
CODE ONE ( p u t 1on the stack )
DEX, DEX, ( make room on the
data stack)
1 # LDA, BOT STA, (store low byte)
BOT 1.+ STY, ( h i byte stored f r o m Y
since = zero)
NEXT JMP, END-CODE
BEGIN, ==>
UNTIL, ==>
IF,
cc
addrI 2
addrI 2
addrE 2
-----
addrB 1
-----
addrI 2
addrE 2
---
---
The
address
values indicate the
machine location of the corresponding
'B'EGIN, 'I'F, or 'E'LSE,. cc represents the
condition code t o select the processor
status b i t referenced. The d i g i t 1 or 2 i s
tested for conditional pairing.
The general method of security control
is t o drop o f f the check digit and manipulate the addresses a t assembly time. The
security against errors is less, b u t the programmer is usually paying intense attent i o n t o detail during this effort.
To generate the equivalent of the high
level:
BEGIN <a> WHILE <b>
REPEAT
we w r i t e i n assembly:
BEGIN, DROP ( the check digit
1, leaving addrB)
<a>
( leaves addrl and digit
CS IF,
CODE ONE
1 I1 LDA, PHA, ( push low b y t e t o
machine stack )
TYA,
PUSH JMP, ( high byte to
accumulator, push to data stack )
END-CODE
PUSH w i l l place the two bytes as the
new b o t t o m o f the data stack. PUT w i l l
over-write the present b o t t o m o f the
stack w i t h the two bytes. Failure to push
exactly one byte on the machine stack w i l l
disrupt execution upon usage!
==>
ELSE, ==>
THEN, ==>
or
A simpler version could use PUSH:
The convention f o r PUSH and PUT is:
1. push the low byte onto the
machine stack.
2.
leave the high byte i n the
accumuIator.
3.
jump to PUSH or PUT.
addrB 1 cc
2)
<b>
ROT ( bring addrB to bottom)
JMP, ( t o addrB of BEGIN, )
ENDIF, ( c o ~ n p l e t efalse forward branch f r o m IF, )
It is essential t o w r i t e the assembly
time stack on paper, and run through the
assembly steps, to be sure that the check
digits are dropped and re-inserted a t the
correct points and addresses are correctly
available.
ASSEMBLER GLOSSARY
11
Specify
'immediate'
addressing
mode for the next op-code generated.
)Y
Specify 'indirect indexed Y' addressinq mode f o r the next opcode generated.
F?%RTHDIM~K%oNS-
Specify 'indexed X' addressing
mode f o r the next op-code generated.
,Y
A t assembly time, BEGIN, leaves
the dictionary pointer address
1 f o r Iater
addr and the value
testing o f conditionary pairing by
UNTIL,.
Specify 'indexed Y' addressing
mode f o r the next op-code generated.
.A
Specify accumulator addressing
mode f o r the next op-code yenerated.
0<
--- cc (assembling)
Specify t h a t the immediately f o l lowing conditional w i l l branch
based on the processor status b i t
less
being negative (Z=l), i.e.,
than zero. The flag c c is l e f t a t
assembly time; there is no run-time e f f e c t on the stack.
O=
execution continues ahead.
--- cc (assembling)
Specify that the immediately following conditional w i l l branch
based on the processor status b i t
The
being equal t o zero (Z=l).
flag cc is l e f t at assembly tirne;
there is no run-time e f f e c t on the
stack.
;CODE Used t o conclude a colon-definit i o n i n the form:
<name>.
;CODE
<assembly code> END-CODE
Stop compilation and terminate a
new defining word <name>
Set
the CONTEXT vocabulary t o ASSEMBLER, assembling t o machine
code the following nmenonics. A n
existing defining word must exist
i n name prior t o ;CODE.
BOT
BOT LDA, or BOT 1+X) STA,
Addresses the b o t t o m o f the data
stack (containing the low byte) by
selecting the ,X mode and leaving
n=O, a t assembly time. This value
o f n may be modified t o another
byte offset into the data stack.
Must be followed by a multi-mode
op-code rnnelnonic.
CODE <name>.
CPU
1
(assembling)
(run-time)
Occurs i n a CODE definition i n
the form:
c c UNTIL,
BEGJN,
A t run-time,
BEGIN, marks t h e
s t a r t o f an assembly sequence reIt serves as
peatedly executed.
the r e t u r n point for the corresponding UNTIL,.
When reaching
UNTIL, a branch t o BEGIN, w i l l
occur if the processor status b i t
given by c c is false; otherwise
---
...
FORTH DIMENSIONS III/5
---
CPU
CS
ELSE,
-----
(run-time)
addr2 2
(assembling)
Occurs w i t h i n a code definition i n
the form:
cc IF, <true part> ELSE,
<false part> THEN,
A t run-time, i f the condition code
specified by cc is false, execut i o n w i l l skip t o the machine code
following
ELSE,.
A t assembly
t i m e ELSE, assembles a forward
jump t o just a f t e r THEN, and re2
2
2
(assembly
(assernbly-
Occurs withir7 a code definition i n
the form:
cc IF, <true part> ELSE,
false p a r t THEN,
A t ndn time, IF, branches based on
the condition code cc, (0< or O=
or CS). If the specified processor
status is true, execution continues
ahead, otherwise branching occurs
t o just a f t e r ELSE,
(or THEN,
when ELSE, is not present).
At
ELSE, execution resumes a t the
corresponding THEN,.
When assembling, IF, creates an
unresolved forward branch based
on the condition code cc, and
leaves addr and 2 f o r resolution
of the branch by the corresponding
ELSE, or THEN,.
Conditionals
may be nested.
NOP,
--- cc (assembling)
Specify that the immediately following conditional w i l l branch
based on the processor carry is set
(C=l). The flag cc is l e f t a t assembly time; there is no run-time
e f f e c t on the stack.
addrl
addr
addr
time)
END-CODE
C P U creates the work NOP, w i t h
i t s op-code E A as a parameter.
When NOP,
later executes, i t
assembles € A as a one byte opcode.
ASSEMBLER
i n FORTH
Make
ASSEMBLER
the CONIt w i l l be
TEXT
vocabulary.
searched f i r s t when the input
stream i n interpreted.
--- addr
...
---
CC
tirne)
n --- (compiling assembler)
An assembler defining word used
t o crate assembler mnemonics
t h a t have only one addressing
mode:
EA
.
BEGIN,
IF,
t o create a dictionary entry f o r
<name> i n the CURRENT vocabulary. Name's code f i e l d contains
the address o f i t s parameter
field.
When <name>
is l a t e r
executed, the machine code i n this
parameter field w i l l execute.
The
CONTEXT vocabulary is
made
ASEMBLER,
t o make
available the op-code mnelnonics.
.
.
END-CODE
A n error check word marking the
Sucend of a CODE definition.
cessful execution t o and including
EZID-CODE w i l l unsmudge the
most recent CLJRRENT vocabulary definition, making it available
f o r execution.
END-CODE also
exits the ASSEMBLER rnakiny
CONTEXT
the
same
as
CURRENT. This word previously
was named C;
CODE A defining word used i n the form:
..
When <name> later executes i n
the form:
<namex>
<name>
the definition <namex> w i l l be
created w i t h i t s execution procedure given by the machine code following <name>
That is, when
<namex> is executed, the address
interpreter jumps t o the code following ;CODE i n <name>
--- n (assembling)
Used during code assembly i n the
f orm:
solves a p e i l ~ l i n qforward branch
f r o m IF. The values 2 are used f o r
error checkinq o f conditional pairing.
INDEX
--- addr (assembling)
An array used within the assembler, which holds b i t patterns of
allowable addressing modes.
IP
--- addr (assembling)
Used i n a code definition i n the
forrn:
I P STA,
or
I P )Y LDA,
A constant which leaves a t assembly t i m e the address of the
pointer t o the next F O R T H execution address i n a colon-definition t o be interpreted.
A t run-time, NEXT moves IP
ahead w i t h i n a colon-definition.
Therefore, IP points just after the
execution address being interpreted. I f an in-line data struca
ture has been compiled (i.e.,
character strins', indexing ahead
by I P can access this data:
I P STA,
or IP )Y LDA,
Page 147
loads t h e third b y t e ahead in t h e
colon-definition being interpreted.
M/CPU
- - - addr (assembling)
(run-time)
n l n2 --A c o n s t a n t which leaves (during
assembly) t h e machine address of
t h e r e t u r n point which, a t run-t i m e , will pop two 16-bit values
f r o m t h e d a t a stack and continue
interpretation.
n l n2 --- (compiling assembler)
An assembler defining word used
t o c r e a t e assembler mnemonics
t h a t have multiple address modes:
1 C 6 E 60 M/CU ADC,
M/CPU c r e a t e s t h e word ADC,
with t w o parameters.
When
ADC,
l a t e r e x e c u t e s , i t uses
t h e s e p a r a m e t e r s , along with
stack values and t h e c o n t e n t s of
MODE t o c a l c u l a t e and assemble
t h e c o r r e c t op-code and operand.
MEM
MODE
N
Used within t h e assembler t o s e t
MODE t o t h e default value f o r
d i r e c t memory addressing, z-page.
PUSH
PUT
--- addr
A variable
used within t h e
assembler, which holds a flag
indicating t h e addressing mode of
t h e op-code being generated.
--- addr (assembling)
Used in a code definition in t h e
form:
N 1
ADC,
-
RP)
STA,
or
N 2+ )Y
A c o n s t a n t which leaves t h e address of a 9 byte workspace in zpage. Within a single code definition, f r e e use may be m a d e over
t h e range N-1 t h r u N+7.
See
SETUP.
NEXT
NOT
--- addr (assembling)
A constant which leaves t h e
machine address of t h e F o r t h address interpreter. All code definitions must return execution t o
NEXT, or code t h a t r e t u r n s t o
NEXT
(i.e., PUSH, PUT, POP,
POPTWO).
c c l --- c c l (assembly-time)
When assembling, reverse t h e condition code for t h e following conditional. F o r example:
O = NOT IF, < t r u e part> THEN,
will branch based on 'not equal t o
zero'.
POP
--n ---
addr
(assembling)
(run-time)
A constant which leaves (during
assembly) t h e machine address of
t h e r e t u r n point which, a t runtime, will pop a 16-bit value from
t h e d a t a stack and continue interpretation.
P a g e 148
UNTIL,
POPTWO
---
BEGIN,
addr
--- addr (assembling)
Used in a code definition in t h e
form:
U P LDA, o r U P )Y STA,
A c o n s t a n t leaving a t assembly
t i m e t h e address of t h e pointer t o
t h e base of t h e user area. i.e.,
HEX 1 2 f LDY, U P )Y LDA,
---
(assembly-time)
Used in a code definition in t h e
form:
or RP) 3+ STA,
load t h e low b y t e of t h e sixth user
variable, DP.
W
Address t h e b o t t o m byte of t h e
r e t u r n s t a c k (containing t h e low
byte) by selecting t h e ,X mode and
leaving n=$101. n may be modified t o another b y t e offset. Bef o r e operating on t h e r e t u r n s t a c k
t h e X register must be saved in
XSAVE and TSX, be executed; bef o r e returning t o NEXT, t h e X
r e g i s t e r must be restored.
SEC
THEN,
UNTIL,
A t assembly t i m e ,
UNTIL, assembles a conditional r e l a t i v e
branch t o addr based on t h e condition c o d e cc. The number 1 is
used f o r e r r o r checking.
- - - addr (assembling)
n l - - - n2 (run-time)
A c o n s t a n t which leaves (during
assembly) t h e machine address of
t h e r e t u r n point which, a t run-t i m e , will w r i t e t h e accumulator
( a s high-byte) and t h e b o t t o m
machine s t a c k byte ( a s low-byte)
o v e r t h e existing d a t a s t a c k 16-bit
value (nl).
R P ) LDA,
. . . cc
A t run-time, UNTIL, controls t h e
conditional branching back t o
BEGIN,. If t h e processor s t a t u s
b i t specified by c c is false, execution r e t u r n s t o BEGIN,; o t h e r wise execution continues ahead.
(assembling)
(run-time)
A c o n s t a n t which ieaves (during
assembly) t h e machine address of
t h e r e t u r n point which, a t run-t i m e , will add t h e accumulator ( a s
high-byte)
and
the
bottom
machine s t a c k byte ( a s low-byte)
t o t h e d a t a stack.
---
--- (run-time)
a d d r 1 cc --- (assembling)
O c c u r s in a CODE definition in
t h e form:
W 1+ STA, o r W 1 - JMP, o r
W )Y ADC,
A c o n s t a n t which leaves a t assembly t i m e t h e address of t h e
pointer t o t h e code field (execution address) of t h e F o r t h dictionary word being executed. Indexing relative t o \N c a n yield
any b y t e in t h e definition's
p a r a m e t e r field. i.e.,
--- n (assembling)
Identical t o BOT, e x c e p t t h a t
n=2. Addresses t h e low byte of
t h e second 16-bit d a t a s t a c k value
(third b y t e on t h e d a t a stack).
2 /I LDY,
c c IF, < t r u e part> ELSE,
<false part> THEN,
A t run-time THEN, marks t h e
conclusion of a conditional structure. Execution of e i t h e r t h e t r u e
p a r t or false p a r t resumes followinq THEN,. When assembling
addr and 2 a r e used t o resolve t h e
pending forward branch t o THEN,.
W )Y LDA,
fetches the first
p a r a m e t e r field.
- - - (run-time)
- - - (assembly-time)
addr 2
O c c u r s in a code definition in t h e
form:
--- addr (assembling)
Used in a code definition in t h e
form:
byte
of
the
X)
Specify 'indexed indirect X' addressing mode f o r t h e n e x t opcode generated.
XSAVE
--- addr (assemblinq)
Used in a c o d e definition in t h e
form:
XSAVE STX, o r XSAVE LDX,
A c o n s t a n t which leaves t h e address a t assembly t i m e of a t e m porary buffer f o r saving t h e X
register. Since t h e X register indexes t o t h e d a t a s t a c k in z-page,
it must b e saved and restored
when used f o r o t h e r purposes.
FORTH DIMENSIONS III/5
FORTH Assembler for 6502 by W. F . Ragsdale
July I , 1980
SCR # 81
0 ( FORTH-65 ASSEMBLER
WFR-79JUN03 )
1 HEX
2 VOCABULARY ASSEMBLER IMMEDIATE
ASSEMBLER DEFINITIONS
3
4 ( REGISTER ASSIGNMENT SPECIFIC TO 1MPLEMENTATION )
5 EO CONSTANT XSAVE
DC CONSTANT W
D E CONSTANT UP
6 D 9 CONSTANT IP
Dl CONSTANT N
7
8 ( NUCLEUS LOCATIONS ARE IMPLEMENTATION SPECIFIC )
9 ' (DO) OE +
CONSTANT POP
lo'
(DO) OC +
CONSTANT POPTWO
11 ' LIT 13 + CONSTANT PUT
12 ' LIT 11 + CONSTANT PUSH
13 ' LIT 18 + CONSTANT NEXT
CONSTANT SETUP
14 ' EXECUTE NFA 11
15
SCR # 82
0 (
ASSEMBLER, CONT.
WFR-780CT03 )
1 0
VARIABLE INDEX
-2 ALLOT
2 0909 , 1505 , 0115 , 8011 , 8009 , IDOD , 8019 , 8080 ,
3 0080 , 1404 , 8014 , 8080 , 8080 , lC0C , 801C , 2C80 ,
4
5 2 VARIABLE MODE
OMODE ! ;
: $
lMODE!;
: MEM
2 MODE ! ;
6 : .A
7 : ,X
3MODE! ;
: ,Y
4 MODE ! ;
: X)
5MODE!;
8 : )Y
6MODE!;
:
FMODE!;
9
10 : BOT
tx
0 5
( ADDRESS THE BOTTOM OF THE STACK * )
11 : SEC
,x
2
;
( ADDRESS SECOND ITEM ON STACK * )
12 : RP)
,X 101 ;
( ADDRESS BOTTOM OF RETURN STACK * )
13
14
15
-
SCR # 83
0 ( UPMODE, CPU
1
2 : UPMODE
IF MODE @ 8 AND 0= IF 8 MOUE + I
3
1 MODE @ OF AND -DUP IF 0 DO DUP +
4
OVER 1+ @ AND O=
;
5
<BUILDS C, DOES> C@
C, MEM ;
6 : CPU
7
0 0 CPU BRK,
18 CPU CLC,
D 8 CPU CLD,
8
B8 CPU CLV,
CA CPU DEX,
88 CPU DEY,
9
C8 CPU INY,
EA CPU NOP,
4 8 CPU PHA,
10
6 8 CPU PLA,
28 CPU PLP,
4 0 CPU RTI,
11
3 8 CPU SEC,
F8 CPU SED,
78 CPU SEI,
12
A8 CPU TAY,
BA CPU TSX,
8A CPU TXA,
13
9 8 CPU TYA,
14
15
FORTH DIMENSIONS 11115
WFR-780CT23
)
THEN THEN
LOOP THEN
58 CPU CLI,
E8
08
60
AA
9A
CPU
CPU
CPU
CPU
CTU
INX,
PHP,
RTS,
TAX,
TXS,
Page 149
SCR # 8 4
o ( MICPU, MULTI-MODE OP-CODES
M/CPU
<BUILDS C, , DOES>
IF 10 MODE +! THEN
OVER
DUP 1+ @ 80 AND
I 3 MEM CR LATEST ID.
FPOO AND UPMQDE UPMODE
3 ERROR THEN C@ MODE C@
MODE C @ 7 AND
IF MODE C@
INDEX + C@ + C,
THEN MEM ;
IF C, ELSE , THEN
OF AND 7 <
1C6E
1C6E
1C6E
OCOC
ODOD
0486
OC8E
8480
SCR
0
1
2
3
4
5
6
7
B
9
10
11
12
13
14
15
SCR
O
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Page 150
60
40
EO
C1
21
EO
A0
40
M/CPU
M/CPU
M/CPU
M/CPU
MICPU
M/CPU
M/CPU
M/CPU
ADC,
EOR,
SBC,
DEC,
ROL,
CPX,
LDY,
JMP,
1C6E
1C6E
1C6C
OCOC
ODOD
0486
048C
0484
20
A0
80
EI
61
CO
80
20
M/CPU
M/CPU
M/CPU
M/CPU
M/CPU
M/CPU
M/CPU
M/CPU
AND,
LDA,
STA,
INC,
ROR,
CPY,
STY,
BIT,
1C6E
1CSE
ODOD
ODOD
0414
1496
0480
CO
00
01
41
81
A2
14
M/CPU
M/CPU
M/CPU
M/CPU
M/CPU
M/CPU
M/CPU
CMP,
ORA,
ASL,
LSR.
STX,
LDX,
JSR,
# 85
ASSEMBLER CONDITIONALS
WFR-79MAR26 )
HERE 1 ;
IMMEDIATE
: UNTIL,
?EXEC >R 1 ?PAIRS R> C, HERE 1+
C, ; IMHEDIATE
: IF,
C, HERE 0 C. 2 ;
IMMEDIATE
: THEN,
?EXEC 2 ?PAIRS HERE OVER C@
IF SWAP ! ELSE OVER 1+
SWAP C! THEN ; IMMEDIATE
: ELSE,
2 ?PAIRS HERE 1+
1 JMP,
SWAP HERE OVER 1+
SWAP C! 2
IMMEDIATE
: NOT
20 + ;
( R E V E K ~ EASSEMBLY TEST )
9 0 CONSTANT CS
( ASSEMBLE TEST FOR CARRY SET )
DO CONSTANT O=
( ASSEMBLER TEST FOR EQUAL ZERO )
10 CONSTANT O<
( ASSEMBLE TEST FOR LESS THAN ZERO )
9 0 CONSTANT > =
( ASSEMBLE TEST FOR GREATER OR EQUAL ZERO )
( >= IS ONLY CORRECT AFTER SUB, OR CMP,
)
(
: BEGIN,
-
-
-
-
# 86
(
USE OF ASSEMBLER
: END-CODE
WFR-79APR28 )
END OF CODE DEFINITION * )
?EXEC ?CSP SMUDGE ; IMMEDIATE
(
CURRENT @ CONTEXT !
FORTH DEFINITIONS
DECIMAL
: CODE
( CREATE WORD AT ASSEMBLY CODE LEVEL
?EXEC CREATZ [COMPILE] ASSEMBLER
ASSEMBLER MEM !CSP ;
IMMED IATE
LOCK ASSEMBLER INTO SYSTEM )
ASSEMBLER CFA
' ;CODE 8
LATEST 12 +ORIGIN
! ( TOP NFA
HERE
28 +ORIGIN
!
( FENCE )
HERE
30 +ORIGIN ! ( DP )
' ASSEMBLER 6 +
32 +ORIGIN
HERE FENCE !
(
*
-
+
!
(
OVER-WRITE SMUDGE
*)
)
)
!
(
VOC-LINK
)
FORTH DIMENSIONS 11115
APPLICATIONS
A T E C H M C A L TUTORIAL:
T A B L E LOOKUP EXAMPLES
Henry Laxen
Laxen and Harris, Inc.
One o f the problems w i t h FORTH, as
w i t h every r i c h language, is t h a t given an
idea, there are many ways o f expressing
it. Some are more eloquent than others,
b u t it takes practice and experience t o
create the poetry and avoid the n~undane.
This a r t i c l e is w r i t t e n t o illustrate 4
d i f f e r e n t ways o f implementing a simple
Table Lookup operation. The goal is the
following: we want to create a FORTt-I
word, named DAYS/MONTH which behaves as follows: Given an index on the
stack which is the month number, such as
1 f o r January and 12 f o r December, we
want to return the number o f days i n t h a t
month, i n a normal year. Thus i f we execute 6 DAYS/MONTH i t should r e t u r n 30,
which i s the number o f days i n the month
June. I w i l l use the Starting F O R T H dial e c t i n this paper, not fig-FORTH, so i f
you t r y t o type i n the examples, they
probably won't work unless you are running
a system t h a t behaves as described i n
Starting F O R T H (or the 79-Standard).
Our first atternpt at solving this probl e m uses the FORT14 word VARIABLE.
The code is as fo!lows:
VARIABLE 'DAYSIMONTH
22 A L L O T
I
31 'DAYS/MONTIi
28 'DAYSIMONTH
2 +
!
31tDAYS/MONTH
4 +
!
301DAYS/MONTH
6 +
!
3 1 'DAYS/MONTH
8 +
!
30 'DAYS/MONTH 10 +
!
31tDAYS/MONTH 12 +
!
3 1 'DAYS/MONTH 14 +
!
301DAYS/MONTH 16 +
!
3 1 'DAYS/MONTH 18 +
!
30 'DAYSIMONTH 20 +
!
3 1 'DAYS/MONTH 22 +
!
:DAYS/MONTH ( INDEX --- VALUE )
1- 2* 'DAYSIMONTH * @ ;
There is nothing significant about the '
(apostrophe), I only prefaced the VARIABLE name w i t h it because I want t o use
the word DAYS/MONTH later. Now, what
happened is t h a t VARIABLE allocated 2
bytes i n the dictionary f o r the value o f
DAYSIMONTH. The 22 A L L O T then allocated another 22 bytes, for a t o t a l o f 24
bytes, or 2*12 cells. We next proceeded
t o i n i t i a l i z e the values t h a t were allocated
by explicitly calculating the offsets and
storing i n the appropriate location.
Finally, we defined DAYS/MONTH as a
colon definition which performs arithm e t i c on the index, adds it t o the s t a r t o f
the table, and fetches the result.
this t h a t requires less typing and is also
more general. We w i l l f i r s t define a word
called TABLE which w i l l a i d us i n the creation o f tables l i k e the one above. What
we w i l l do is f i r s t place the i n i t i a l values
o f the TABLE on the stack, together w i t h
the number o f the i n i t i a l values. Then, we
w i l l define TARLE t o copy these into the
dictionary. Here is how i t works:
:T A B L E
( N n Nn-1
O D O , LOOP ;
...N l n ---I
CREATE 'DAYS/MONTH
3 1 30 3 1 30 3 1 3 1 30 3 1 30 3 1 28
3 1 12 TARLE
:
TABLE
(
)
CREATE
DOES>
', INDEX --- VALUE )
SWAP 1- 2* + @ ;
Now we have t r u l y generalized the
problem and solve it i n an elegant way.
We have defined a new data type, called
TABLE, which is capable o f defining new
words. P a r t o f the definition o f TABLE
was specifying the run-time behavior o f
the word being defined. This i s the code
following the DOES>. We then use the
(comma) technique discovered above t o
initialize
the
table.
Note
that
DAYSIMONTH is now just a special case
o f TARLE, and is i n f a c t defined by the
new defining word TABLE.
,
N o w this is considerably Iess typing than
the f i r s t way o f doing it, but notice t h a t I
had t o reverse the order of the days per
month since t h a t is the way stacks behave. I used CREATE instead o f VARIA B L E because it does n o t allocate any
space f o r the i n i t i a l value, b u t otherwise
behaves just like VARIABLE. The access
word DAYS/MONTH is identical to before.
I am s t i l l n o t satisfied, however, so
let's t r y it y e t another way. Instead o f
defining TABLE t o add values t o the dictionary w i t h , (comma) why not just use
directly'?
,
CREATE 'DAYS/MONTH
31,28,31,30,31,30,
31,31,30,31,30,31,
: D A Y S I M O N T H ( INDEX --- VALUE )
1- 24 'DAYSIMONTH + Q ;
Now we are getting somewhere!!
I f we
simply use the F O R T H word (comma) t o
add the value t o the dictionary, see how
The
simple and readable it becomes.
values are just typed i n and separated by
commas!! Is i t possible t o improve even on
this? Funny you should ask. There is a
quality t h a t can be abstracted f r o m the
definition o f DAYSIMONTH, namely t h a t
o f table lookup. Wouldn't it be nice i f we
didn't need t o create that extra name
'DAYS/MONTH simply so we could access
it l a t e r i n our : definition, Well, that is
where our f r i e n d CREATE D O E 9 comes
in.
,
Instead o f defining a particular instance o f a TABLE, we w i l l create a new
Defining Word called TABLE, which acts
as follows. It creates a new entry i n the
dictionary which when executed, uses the
value t h a t was placed on the stack as an
index i n t o i t s e l f and returns the contents
o f t h a t location. It would be coded as f o l lows:
The above examples illustrate the immense diversity available i n FOR.TH.
There is no obvious r i g h t o r wrong, and the
simplest and usually most general solution
t o a given problem must be discovered,
usually by t r i a l and error. FORTH's biggest virtue, i n my opinion, is that it makes
the t r i a l and error process extremely efficient, and therefore, allows people t o
experiment and discover the best solution
f o r themselves.
H E L P WANTED
Programmers needeed t o produce new
polyFORTH systems and applications.
Two t o three years extensive F O R T H
experience
working
with
minilmicro
computers and peripherals.
Contact: P a t r i c i a Jones
FORTH, INC.
2309 P a c i f i c Coast Highway
Hermosa Beach, C A 90254
(213) 372-8493
fig-FORTH NOVA GROUP
Mr. Francis Saint, 2218 Lulu, Wichita,
KS 67211, (316) 261-6280 (days) has
formed a FIG Group t o trade information
and assistance between fig-FORTH NOVA
usel's.
Pub. Comment:
Hope to see a new,
clean listing.
How about some other
specific groups!
Now, let's look a t another way o f doing
FORTH DIMENSIONS 11115
Page 151
THE GAME OF REVERSE
M. Burton
REVERSE is a number game written in
FORTH, primarily a s an exercise in array
manipulation. The abject of REVERSE is
t o arrange a list of numbers ( 1 through 9 )
in ascending numerical order from l e f t t o
right. Moves a r e made by reversing a subs e t of the list (from t h e left).
For
example, if the c u r r e n t list is
228
The Game of Reverse
[SEED, MOVES, RND, DIM, Y / N l
101281-WPB
)
VARIABLE SEED
( Seed for random number generator 1
VARIABLE NOVES
( Number of reverses s o far 1
CR
Please depress any key:" f Fertilize the seed 1
."
KEY
SEED
RND
SEED @
and four numbers a r e reversed, t h e list
will be
I
DIM
<BUILDS 1+
DOES>
Y/N
PAD
then if five numbers a r e reversed, t h e
game is won.
--
Random number generator
range
rnd#
3 + 32767 AND DUP SEED 1 32767 * /
(
259
(
2
+
n
--
;
)
;
(
80
Reserve an integer word array
ALLOT
)
EXPECT
Get a Y or N response
PAD CI CR CR 95 AND
--
89
flag 1
=
;
-->
SCR # 229
( The Game of Reverse
[Game instructi~nnl
101281-HPB 1
1
2 : INSTRUCT CR CR
18 SPACES . " The Game of REVERSE"
3
CR CR
Would you like instructions? " Y/N
4 IF
. " The object of the game is to arrange a random list"
5
CR . " of nine numbers into ascending numerical order in"
6
CR ." as few moves as possible by reversing a subset of"
7
CR . " the list. For example, given the random lint," CR
8
CR."
5 2 4 8 7 3 9 1 6 " C R
9
CR . " reversing a subset of 4 would yield the list," CR
10
CR . "
8 4 2 5 7 3 9 1 6 " C R
11
CR ." To quit the game, simply reverse 0." CR CR
12 THEN ;
13
14 -->
15
0
To leave a g a m e t h a t is in progress,
simply reverse zero numbers.
REVERSE Glossary
-SEED
The number seed for the pseudorandom
number generator. SEED is initialized
a s the REVERSE words a r e compiled,
by hitting any key on t h e console.
MOVES
--
Keeps track of the number of moves
made in a REVERSE game. If more
than fifteen moves a r e made t o win,
you haven't g o t the hang of t h e game.
range -- random.number
The pseudorandom number generator,
courtesy of FORTH DIMENSIONS.
RND generates random.number in t h e
range 0 through range-1. RND is used
t o scramble the number list.
RND
n -A defining word used in the form
n DIM xxxx
Produces an n i l length word array
named xxxx, with elements 0 through
n.
For the REVERSE application,
element 0 is not used.
DIM
."
SCW
#
0
(
1
2 9
230
The Game of Reverse
DIM
3
4 : AQ
5
2
6
7 : A!
0
.-
Page 152
ARRAY
10
14
15
CR
CR
Fetch an array word
@
4
+
(
1
DO
I
I
array.value 1
array.value\index
Initialize ARRAY
DUP A l LOOP ;
( Print ARRAY
list is now..."
SPACES 10 1 DO I
fig-FORTH Version 1.15
--
--
;
. " The
6
index
;
Store an array word
(
ARRAY
9
1 0 : AINIT
11
12
Reserve a ten word array 1
(
(
*
2
13 : A.
-- flag
Solicits an input string from the console, then checks the first character of
the string for an tippercase or lower-
Y/N
ARRAY
[ARRAY operations1
A@
3
.R
--
1
--
)
LOOP
;
-->
H. Burton
FORTH DIMENSIONS III/5
1
SCR # 231
0 ( T h e Gmme of R e v e r s e
[ARRAY operations. c o n t . 1
1
2 : ASCRAMBLE
( M i x up t h e array values
3
1 9 W I RND 1 + ( C a l c u l a t e K )
4
I
Al
( G e t ARRAY111 value 1
5
OVER A@
4 ~ e AtR R A Y ~ K I value )
6
I
A1
( StoreARRAYtKlinARRAYtIl
)
7
SUAP A1 -1 ( Store A R R A Y t I I i n ARRAYtKI 1
8
+LOOP ;
9
10 : G E T I N
( G e t m o u n t t o reverse
n I
11
B E G I N CR
" R e v e r s e how many? "
12
PAD 0 0 EXPECT PAD l 4 8
13
DUP O< OVER 9 > OR DUP
14
I F CR
O n l y 0 through 9 is alloued. " THEN 01
15
U N T I L CR ;
-->
-INSTRUCT
Prints the name of the game and then
asks i f instructions are required. If
yes, instructions are displayed.
ARRAY
-A ten word array that contains the
number list that REVERSE works oq.
Element zero o f the list is not used.
--
.
-
A@
index -- array.value
Fetches the index array.value
of
ARRAY and leaves it on the data
stack.
."
SCR # 232
0 t The Gape of Reverse
1
2 : AREVERSE
3
DUP 2
4
WDUP
5
DUP
6
I
/
I+
-
1
1+
SWAP
I
Al
Ae
SUAP A1
I
A1
LOOP DROP ;
7
8
9
10
11 : ACHECK
12
1 1 0 1 D O
13
I
14
LOOP
15 -->
SCR
0
+
AI
[ARRAY operations, c o n t . 1
100781-HPB
--
R e v e r s e a s u b s e t o f ARRAY
n
1
Loop l i m i t s are 1 t o t n / 2 1 + 1 )
(Calculateindexn-I+l)
( G e t ARRAYIn-I+11
( G e t ARRAYCII 1
( Store ARRAYCII i n ARRAYCn-I+11
1
( Store A R R A Y t n - I + 1 1
i n ARRAYtIl 1
(
(
(
DUP
C h e c k f o r ascending seq.
Al
=
--
flag 1
AND
;
233
T h e G a m e o f R e v e r s e [REVERSE d e f i n i t i o n 1
1
2 : REVERSE
( P l a y the game 1
3
INSTRUCT A I N I T
4
BEGIN
5
ASCRAMBLE 0 MOVES I
6
BEGIN
A.
G E T I N DUP O=
I F 1 ELSE
AREVERSE 1 MOVES + I ACHECK
CR
CR
."
." C a r e
Y o u m a d e " MOVES
t o piay again? "
." T h a n k s
f i g - F O R T H V e r s i o n 1.15
l
Y/N
f o r p l a y i n g REVERSE...
. ."
CR
reversals. "
CR
AINIT
-Initializes ARRAY w i t h the numbers 1
through nine i n game winning order.
A.
-Displays ARRAY i n an understandable
format.
ASCRAMBLE
-Using RND, scrambles the numbers i n
ARRAY f o r a new REVERSE game.
ACHECK
-- flag
Checks ARRAY for proper ascending
numerical order. If ARRAY is i n the
proper order, ACHECK returns a true
flag.
O=
"
array.value index -Stores array.value into the index element of ARRAY.
AREVERSE
n -Reverses the nth length subset of
ARRAY, starting from element 1.
THEN
A.
CR
UNTIL
)
GETIN
-- n
Solicits the number o f elements o f the
list t o reverse. I f any character other
than 0 through 9 is entered, GETIN
1
prints "Only 0 through 9 is allowed.",
and solicits another number.
(
UNTIL
case 'Y'.
!f a 'Y' is present, the flag
returned is true. For any other character, the flag is false.
)
;
;S
CR
--
REVERSE
The game definition.
Uses all previously defined words t o play the qame
M. Burton
ok
FORTH DIMENSIONS I1115
Page 153
THE 31 GAME
Written by Tony Lewis 11/81
SCR#51
: HClWTll31 HEME ( 3 1 GAME-TONY LEWIS)
"
1;1 GAME
BY TONY LEWIS
~ 7 :, , I S PLAYED WITH A DECK OF 24 CARDS
.
.,
The "31 Game" i s an attempt t o use
F O R T H fundamentals t o produce an entertaining result. The object is t o entice you
i n t o anlyzing b o t h th e game itslef and the
methods used t o produce it. The game
buffs might wish t o know that Ihave been
an avid "player" (not gambler!) f o r over 30
years and have made extensive practical
studies of various games.
Any phone
I am t w o
communication is welcome.
years behind i n my w r i t t e n correspondence; so sending me letters which
require replies w i l l prove futile. The program is my f i r s t e f f o r t i n FORTH. However, Ihave had extensive experience with
six different main frame assemblers plus a
l i t t l e COBOL o f the late 60's vintage.
Any constructive suggestions on general
style and technique are welcome, b u t Ia m
not really interested i n being told that I
couid have shaved 100 microseconds from
m y run time or saved fifteen bytes of
memory. I n fact, there are indeed extraneous "Cr's" which were included to get
good hard copy, also.
This program was written i n micromotion (c) FORTH-79 Version 1.2 t o be
run on a 48K *Apple 11.
Therefore, the following words are
non-standard b u t included i n the micromotion FORTH.
Home - position the cursor t o the
upper l e f t corner of the CRT and clear the
C R T t o blanks.
C V and C H are used t o position the
input cursor anywhwere on the t e x t window per Ex. 4 C V 10 CH moves the cursor
to the 4th (pun) r o w 10th column o f
screen.
sun OF THE CARDS DRAWN. THE P L ~ Y E RWHO
ClfiRIVtS Cj? THE: SUM OF 31 EXHC'TLY WINS.
I F NEITHER PLAYER CAW MAKE 31 EXACTLY.
THEN THE PLKVER WHO MUST 6 0 OVER 31
LOSES! THE GAME MAY APPEAH TOO EASY. BUT
I T I S DECEPTIVE. WHEN CUR I F 7 1 YOU HAVE"
WON THREE GAMES. TRY TO BEAT THE PROGRAM
FUR 'THE B I G BET' BY TVPiNG I N ' B '
R k i ' H t f i 'THAh
Y rJR I N ' WHEN 'NEW GAME?'
COMES UP. THE ' B I G B E T ' I S A TWO GAME
SERIES. YOli GO F I R S T I N GAME 1 AND
8ECl.iND . I N GAME 2 . YOU MAY BE SURPRISED!"
Cii
Cli CR
"
H I T ' HNY KEY TO b E 5 I N "
KEY'
-- >
DROP HOME 6 CV :
3 1 BY TONY L E W I s i
t
1. TI3 tr NOW GN STACK)
( Cirw LEFT?)
I F 1- ( UPDATE. DECK) SWAP UECk + C !
[:ANDSLIM 1G3 + Ci:FiDSIJM C ! i WEbl 'JLJM)
:! ! C A f i i ~ - I N . ~ - i j i ' l i 2FLAG)
EI.SE DFiOF' irKUP UFtOP 111
TrlEF! :
: Ui.DfiTEi>ECI<StiM
DUF ii UUP D E C ~+ ~3 UUP
C O N T A I N I N I N G ONLY THE ACES THkU SIXES.
EACH OF TWO PLAYERS ALTERNATELt DRAWS
i:ARD5 FROM ?HE: DECK. ONE CARD AT A TIME.
A RUNNING TOTAL I S KEPT OF THE COMBINED"
.
5CFtk55
r L I T I L i T Y WORDS CilluT.
SCH1152
i WO!D
iS
OF WlSijOM
2.1 BY TONY L E W I S )
c THE >ANSWERr' PAGE I S NEXT. I T DOESN'T
REOLJIRE ANY S K I L L TO FIGURE ULJT WHAT THE
CONSTANTS HEALLY ARE' THEY ARE ENCODED
SO THAT YOU CAN ENTER ANIJ COMPILE THE
GAME WITHOUl DISCDVERlNG I l S P R I N C I P L E .
REMEMBER. THE PURPOSE OF T H I S PROJECT
WfiS TCL BE.T YOLI T O F I R S T EXANINE THE GAME
B Y PLAYING IT, THEN FIGURE OLJT HOW TO
APPROACH THE PWOBLEM OF PROGRAMMINI3 I T .
AND F I N A L L Y GO BACK AND COMPARE YOUR
METHODS TO MINE. THE GAME 15 AMUSINCi
AND I S A L I T T L E KNOWN CINCH BAR BET. I F
YOU TAKE THE T I M E TO ENTER I T ONTO YOUR
FORTH DISC. YOU SHOLJLD HAVE FUN BOTH
ANALYZING I T AND THEN ENTERTeINING CCR
HUSTLING3 FRIENDS AND F A M I L V WITH I T .
OF CUURSE WHEN PLAYING AT H BAR YOU MUST
USE A REAL DECI-. OF CARDS AS I T WOULD
PFIOBABL.Y TEND T O DISCDIJRAGE WABERING I F
YOU SHOULD BRING YOUR 'MICRO' WlYH YOU.)
-- .>
. -.
SL.Rt;!l;!i
. ;";all<! 1 lqkl kOfil)C<
9 1 BY TONY L C W I S j
: TL.nYtfirlCiVE
CR L:R
" 'T':PE I N 1:AFID I
6 " KEY CFI
4Y - ( FRCJh A S C I I r DGP DUP DUP
i i'HECr.; Vc?Lti) Er4TRvi
.
,
.-
....
IF
[;&HD I -. t ')j
I F UPCATEUECtiSiifi SWAP
t!UNE.
" YClluR CHRD WAS A "
DLlP
I:,=.
( I:;
CARL, IN T H I)Si:r:"J
~
I!- DROP i FLAG BAD PLAY)
O
CR CR . ' CARD PIUT I M DEClr:"
'
SHUl.IDECV.SlJM
'i-hEhI
ELSE DKOP DROP Bi+DrLAY
THEN
til.SE DRGP DROP DRUF' BADPLAY
THEN ;
.
.
..
si:.+:tlf;7
i h / > l i . ? ~ l l v W!i~FtfiS
t
C.Rkr.
31 BY lUlrlY ILEWIS)
C k C:h
:. PI ;CARI)
.:F
< CnECC i 5 T r . . e v SWITICH)
:': RAlNDOI': 1.t DlJr
I;PDATEDECl.BLlM Dt::OP
t:t.<k
l k l 1'1lJt. ~.4k:ii!;iJ~t i,;.iJ
.t
k:2
t- 1 NI:;lj
[)LIP
LJFfiATEDFTYSrJll
i.i=( I FLAG t:)lu ' J A L l U CHOICEI
I F l>F:rJf:, 1 !A 8;)
l~P1.~iai'EI~~Ct.~~.LJl"l
1F
E:.SE
DROF ? !!PkjATEDECk.SI!M
H I I
( FL&i&-::CeKU.
YiJ NU UhrlF')
rti:.. !4
It ~ rrj
'' INy; lk3l. +ar :;: "
%,-iGdI,Fi~t.'i~.! ,I-I
-
.
.
liCt?#53.
L ENCCJDEI) CONBTANTS
31 BY TONY L E W I S )
! Mult:
1HESE CDNSTANTS AXE USED ONLY
TO i:ONCEAL 'THE 5OLUTION OF THE GAME.
NO-r r o wnk E THE ClJIj? NG HAW T O FCII-I.OW ! )
CONST/INT
i n !:.ON!;TANT
i : ~ i:Ohl;
1 ANT
O l;rJN5TANT
)6:
K1
KZ
t:'7
K4
SETINV, SETFLASH, and SETNORM
set flags i n the Apple output subroutines
which respectively cause a l l subsequent
characters t o be displayed on the t e x t
screen inverse, flashing and normal mode
without affecting charcters already displayed.
I n closing, Iwish t o thank B i l l Ragsdale
for his gracious support and I especially
acknowledge the incredibly patient treatment I received f r o m P h i l Wasson o f
Micromotion as he neatly led me through
my FORTH initiation.
Tony Le wis
100 Mariner Green Dr.
Corte Madera, C A 94925
(415) 724-1481
(415) 924-4216 (late hours)
: C~HOWIJEC:~
'?SUM I:R
THt-
nil
.
.
*Apple is a registered trademark of Apple
Computer, Inc.
C:R
l ~ i C t . NOW i:liNr'(-1JIU5, "
I ( P.I:IT J ' ' ) L*
"ECC + C 3 ( DUCk' u DU )
DUP
.I
1: i + 1 i.t3 ljlj 2
LI:IIJP
ti 1 5E DfiOP
-rHt N
LDOP
12 CH
" THE RI!NWIWG TCI'TfaL 1 5 " CAfinSUM d
.."
7 1
:
.
:
ElkDF'L AY
i?
CR CR
i F1.08 BHD PLAY1
GI4OWDEC.i SIJM :
" El,?,lj IYPE-- I N "
.
.
..
Page 154
FORTH DIMENSIONS 11115
SCR#bSI
t N ( 4 J N L l k E WOFtl)S i:iir-rl
3 1 BY TONY l.EWIL,
: M Y R I i j I 5 t T l CR CR
K 1 ,)UP i-&USUII
C.i! +
b.2' - Ptcl MOD i I L I ' L T E I ; :3L,M
~
1 !=
.
: MYitliiI5Ii 1.2
C l i CR
I F DU@ UPDATFbELk.;Un
DROP
=St k l CARDSUM C;r k2 - t.1 NOD - DUP
I.II'IJRTEDECI:SUM
il=
11: DtiOF' k 4 !)UP ILIPDCIl-EDECk.5UH DROP
T t.ltiN
'THEN
M i PL.Ay I s "
SHOWDECKSUM Z :
.
."
--
:_.LtifthI
r MAIN1 .TIIF WOt<bS CDNI'.
5 1 b r IIJNV. LEWIS,
: AJCiUlil 1
ICIUKiliiRLI
SC'D I N
1 F c TRUE FHi:lM N r B I R B E l l t
5 1 I;RF~DSUN i.d
IF v ~ r u w l l \ ~ I
I :;ElLDilP EA1.I)
I:I.SF
7 1 CAKUbLIPI 12.5 [ f - ' < l ~ ~c15;t:
Il
j
k.1
,i'liAt<1.<4i?l> <:I
i l l t !,I
1111-N
tr!.:;E
( tit 1 iJf.:N IFKurl 'i'i?iJRi.iaFilJ)
". 1 CAF:LE~LlI~~..d
SW#64
( !-'Lev THE RAHE OF 31
BY TONY L E W I S )
: M A I N Z 1 i L L J t i i C S H E L L > i l C;AMESWLJN '
B E G I N CH i R
"
NEW GAME- "
'IYr'E Y IJR PJ L1R Nil316 h E ' I ) . "
C:F: I.:R t.:'EY l ~ i i i - I E I
i CIiE[:C: Fi3R N l
I FAL.SE ILEHVtfS 7 8 ON STACK FUR ' U N T I L ' )
1 F NEWGAIIF
66 = i B )
I F GAMESWLIEI i:3 2 .:I F BIGBET
ELSE HOME z3
YijU HAVE WON "
GAMESWUN C 3 DUP
GUME" 1 =
I F
ELSE
S."
THEN CFi
" YtjLJ MUST W I N 3 DAMES 1-17 "
I-'L.ibY ' 8 1 1 9 BE'I':'."
1I-iEN
El SE NORI'IALJI
THEN
THt N
UNTIL :
: 316CiME HOWT031 CC)DECOkS 9 A I N 3 1 ;
."
."
." ."
. ."
."
.. "
THE DECt.
1 1 1
: J
u 4 4
NEW C;FIME.7 TYPE Y OH N OR R ( B I G H E T i .
DO YUlJ WPtN'l' I-IhS'1' PLAY
:.'
I YPE Y DH
-
:.,
-I
:,
fr
Y
01.1 1.08E.
: BlCjBE7
WORDS C:JNT.
5 HI3ME
-lu "13 1(: h E T '
(-
I4EW GAhk
C
,.I
h
2 1 2
3 -1.
.:
r3 C,
TtiF RIJWNlI\IC7 TO1 A I .
IS 5
il
?
;
. .> 1
.
4 4 4 4
5 5 5
6 b : : h
THE RUNNlNB TOTAL
I S if!
.."
."
."
DECIC NDW CON'YA INS
: I
2
3
4 4
5
h
I H E RUNNING TOTAL
I S is
1liE DECI::' hl6llu I:LJN'I'&~WS
i i 1
2 2 2
3 ? 3
4 4 4 4
5 5 5
6 6 6
I"IF[ R ~ R l l iBET)
.
-
.;
7 I P E Iill? N OR B ( 8 1 s BEIT).
L A X E N AND HARRIS, INC.
24301 Southland Drive
Hayward, C A 94545
(415) 887-2894
Introductory classes
Process control
Applications programming
Systems level programming
'THE
i 1
2 2
3 ''
4 4
5 5
I>ECt.:' NCJW CCJIUATNS
l
2
4 4
5
h 6 a
GREG STEVENSON
Anaheim, C A
(714) 523-4202
Introductory classes
KNOWARE
INSTITUTE
OF
NOLOGY
Box 8222
Stanford, C A 94305
(408) 338-2720 ,
Introductory classes
Graphics classes
TECH-
-
INNER ACCESS CORPORATION
Belmont, C A
(415) 591-8295
Introductory classes
THE RUNNING TOTAL I S 17
TYPE I N CARD i - 6
YOUR CARD WAS A 3
FORTH DIMENSIONS III/5
rN
1'HE DECK NClW CilN'IAIWlj
1 1 1 1
WE1 C:lJlli;
TI-iE F:INF'IL PHAhk. O F
.rt.ifi ':,I L,,-+PIL. 1wi.1 C,;>I~IL.:;
WI:L,L. I ~ E~ ~ " L . ~ ~ Y E ~ I , , ~ '
CH
YOU WILL. I;U FIFrS'l' X W BFIME ONE AND
'T HE
1 W1L.I.. b i l F 1R : X I N 6-;%ME: TWO. 1301:1D L.LJCk. "
1 1
2 2
H l(ribF-I 1
3 3
ZR CH
4 4
I-I1T At47 k-EY HND I W I L L B E G I N GAME 2.''
5 5
CR FEY DROP NEdG&hE
h b
561'PL.A8H
B l l i b t l i%ME 2 1 h E F I N A L E "
R
1
.
C;R SIL~~IPILIRM
R l [.it<[.12
ili
&>ELL. I>.[D 'iuLi tii4VE Ttii: LORRECIT ANALY5167
i F SO. iHEN SEE I t ri3U CAN t IDUHE OLIT"
i.f%
LUHO WINS ~ I T H A i S i CARD LIF OFIE OR TWO.
I T 7 S A TOUGH CUMBINHTORIAL PROBLEM!'"
1 i SET F I N q L E X I T I N M U l N 3 l i :
-->
'I LJF:
FORTH CLASSES
'THE DECK NOh CONTAINS
1 1 1 1
h b
.
I ':PE
I l i k l ~ L . l N l ~ ~ l . laT{\l...
lUl~
15; :'
TYPE I N CAR11 1 -- 6
YOUR CARD WAS A 3
4 4 ' 3 4
>: y
2 1 BY TONY L E W I S )
.!,:
1Irlt.
r If.
i .i
2 2 2
SCK#63
! MAINLI1.IE
'
r
L.,
5
--.>
I L ) l ' f ? l 1:i
~ O l HAVE
l
wOti O GkME5.
YnU MU5T k 1 ? 4
ti&MES 113 P L t i Y ' B I G BET'.
h l,
>,
l~iLll<l41
GET1 El:? LLLjLr. luII X
THE DECE NOW CONTAINS
i l l 1
2 &..
7
7
.2
5
4 4 4 4
-:.
., -. .
t:L5E UL~LJRCC~~D
,I
IHE IU
I:+ :;+, , I l ~ f ~ \ F i l J ! ~i.,J
l.ll~
I F,'
l.Il.11. rJ!,k:
1
f:l-dF
1 ,
( N I I I 151.)
PIVHILjLIE T.2
THE I\I
THEN
UW1 I L ;
I tll
C,
N.
IUiW OCIME
h:;t<+b,62
;
I 4 A I I Y L l l l i MDRDS L~ilr-IT. 3 1 B Y TONY LEWI:?)
: BlL2iltl;l
i M:BIL.tlE-11:
BEG I N
If. 31 t.nRf)SLJM lC3 =
IF' .,C,,lL- ust
"" 1
WUU C O N i A I r l S
1
: 2
THE
FORTH, INC.
2309 Pacific Coast Highway
Herrnosa Beach, C A 9-0254.
(213) 372-8493
Introductory classes
Advanced classes
RUNNING TOTAL IS 20
Page 155
SIMULATED TWTROMCS
4010 GRAPMCS
WITH FORTH
by Timothy Huang
Portland, OR 97211
II :P
V i d e o c o n t r c l s i o r i o i i : r ~ s ; . i I<X364
F3hTi: 3Ei?INITiOWS 2;ZIKZL
S.:reen
D
;
I n this article, Iam going t o t e l l a true
story. For those people wh think F O R T H
is a religion, they might just consider this
t o be my testimony.
;
Last November, I had access t o a very
l i t t l e known, but well built microcomputer
M X 96412 by Columbia Data Products,
Inc. of Maryland. This l i t t l e machine has
two Z-80A CPUs. One is for the Host and
the other f o r terminal. There are 64 K o f
R A M i n the Host, and 32 K o f the Terminal R A M is dedicated t o the 512 x 256
b i t mapped graphics. It also includes a 9"
CRT, 2 double density drives, keyboard, 4
serial ports, and 4 parallel ports. Its all i n
one piece.
It boots up with whatever
operating system is on the disk after
powered up and the carriage return key
has been pressed. Beautiful isn't i t ?
:
a
--
COTSXf
---
( z
,f
C MAX 2 3 fi;K
O XAX 7 ? H
I::
i S CXIT EW;?
hOXE i S EEZT
i
UW-C
:O
:1
27-C
iZ E X I T ,
WAi'
33
EEiT
;
3
;C
-.
3;
.
cin CLR-VIDEO HOME
:
,LR--~;CEO
CLEARSZREEN
.
ENIT .
CLXEDS
CLaLINE
il.
14
EEL:
2 3 EMIT
..
.
:
:: SMlT .
7 EMIT .
2?-l
'*
: I E3:T
CLR
,T-L
3 1
LXiT
2;
LiE,Q1
Eiqli"
$
.
EMIT ,
21
:c
s
4
Sczeen t i t
d
:
1
-
Jrrphlc Package
2 J VAj?.lABLZ
2 2 'JARLAEL;
m.,.
:
X
3 VAR:AEL;
X:
0 VARIABLE
Y
V:
3 '$ARIAELL
.I ;1
::!39,3Q
3 V A H ' " ' u- ' ,.
" :,
L
#,
j
L
>'
ESC 2 7 t 1 . 1 1 ~
;'r ; 2 EM:.^ . S C 2: LI<:'i ' v r i : l ; r .. . .
3: EM:T I h l p h a ) ,
C A N 2 : CX:T ! n ~ s - ~ ; ~ )i ~ ;
LX
2 5 f M i 7 L c l e a r < i d e a ntiuory )
VH:TC Z S C 9 7 EKl? .
: S L A C K ESZ 1 2 7 EX::
.
:
However, there is a big problem, as
w i t h most microcomputer companies, the
instruction manuals are terrible.
And I
mean terrible! L e t me just give you one
examle: "For this information, please see
only t o find there was no such
figure -'I,
figure and no page number.
TLkL
L
3S
7
.
?
i i'
* ..
6
1I
L"
Graphics are one of the most important features w i t h this machine. 512 x
256 b i t mapped graphic is the best that
can be expected under the price allowance. There are quite a f e w well known
microcomputers on the market claiming
High Resolution Graphics. But those High
Resolution ones are just like a big blob
compared with the individual pixel that b i t
mapped. So, Ihave a nice machine w i t h
a l l the fancy graphic capabilities, but
lacking the key t o open it.
Anxiety
mounts up quickly.
I have a friend who's an excellent
8080/280 assembly programmer. He irnplemented UCSD Pascal for a microcornputer. Naturally, since he was the f i r s t
one, it seemed logical to seek his help.
With a poorly written conlputer manual
i L;
;5
Screen
2
;
:: :Z
SLaphic Package
1
iO
EH:T
(LoYrHiY32
EMIT
C
PAGE
t
)
6 4
+
EX:?
'
t
tXlT ,
Y
>
HJU-
:'CE]: '$C,-,"
VECTOp.
.L.,. L
1:
,nter
EYL
.
/:?Cfi
>
.!.
-
PRC-GUT
:i
:'
iC
..,
-
32 +
. YCEK
3
s.5
X G ~ ~ J ( L o % , HAX
(r
''
Lot
.,
IWC
1023
;
a
-
*
(
-
( i i p t , ~, ros
<.U,.d
2"""
,
>
;tc:cii
TT
'J
Scieer. # i J
2 i G r a p h ~ cr a c k a q e
2
IKlT
y A C E G 9 ;Z
iM.1
'6
:MI:
3 2 ?%:1
t,5
.,I?;,
.
4
5
f:.SEAW
,
,ivi:
e
3RAL1
c
&
y
---
>
J2p Y
:
; a y
--- .
ZGh;
X
t
S A P FRE-3lJT
:3
:i
.--
1:
GZO'JE
r,5
DB.:Y
.
.
,
.
>
2
- c"
Page 156
-
FORTH DIMENSIONS 11115
Screen
0
(
# 14
Graphic P a c k a g e
2
3
.
RURAW
(
-
4
R e l a t i v e DRAW )
SWAP
X
@
Y @ +
t
SWAP
DRAW
(we a t least knew that the graphic part
simulates Tektronics 40101, he spent a
whole week just trying t o draw one mere
square along the edges ef the ZRT. Seemingly it would be an easy job, but even so
i t never came near to what he would have
liked. L a t e r on, Ispent a couple o f weeks
twiddling w i t h Microsof: BASIC compiler
and it also produced lousy results.
(I
5
6
.
RHOVE
R e l a t i v e KOVE i
GS
RDRAb'
,
1
7
U
Y
ACURSOR
C5
( .~lpli,.cursoi
ORAL
US
r
---
y
i
;0
11 : SCROLL
1Z
i3
LINE-ERASE
C1N ER . "
i4
If
I B
BLACK
5
IJ
:o
ERASESGti
INITO
7
I *
13
;4
.
l
ROT L t CUP 7 :
i : x y - - - )
IIITO
X E' L &' + 3L'F :1
@
.;
8 L ,?
+
.":
Yut
LVI)
.
x
x
% L
3 Y
a - >UP : '
e e s - nap
{
:
>.
x o
L @
Y @ L
X P
?. &,
L
I
I
@
--i
t
'
A t the same time, I received my 8080
fig-FORTH listing. So, I typed the whole
60 K o f assembly listing w i t h the lousiest
t e x t editor (i.e., ED. COM). It was a monumental job. Nevertheless, Ihad the figFORTH up and running.
--.
5
INIT
L
7
1i
-
5 Less
: ' S L C - ~ ~ L T,' I
i [ ?
S c r e e n C 15
3 : Graphic P a c k a g e
2 : ;N:TO
3
4 : SOIJARE
p r e s s FUKC
n
Y
Llii
.
;" 'l&W . . t
By now, I was very desperate t o get it
going. Equipped w i t h the F O R T H power
and the poor manual, Iset f o r t h t o t r y the
graphics again. Again, Isought help f r o m
a friend who works for Tektronics and is
experienced w i t h FORTH. With FORTH,
the whole task turned into a very simple
job, compared to the previous attempts we
had with the assembly and BASIC. Thus,
now I am steadfast i n my belief i n
FORTH.
'
Y :+ iiRAV
Y . DRXGI
Y
e
.
D R A ~
;
1 ! L;~;L-CZA~L
:)
- i:
- -*
I L::iL-E!:ASi;
! LiXt-CnAZl:
. 7.3,..+2-ERA3E
r
4 "
d i r e e n # i6
a
G r a p h i c r:.ckigc
.
; a d v a n c e n A y ,
cnacr r r n < r ;
L 2 X
X: 2
37;: LU''
2 ; 7 -- z k 2 c :':.--'.;-:'
:
.s -.
a
.
" -..!.*
'TiIlil .""..'
ZLSt
; i i nFc.>r LRLt> l' U" -"G"
.<.LA. :
Y @ y; 5
CUP
DIJ: c (
C R J ~ ;;,SF
jac: 1 :;:-:.
LLS; 7 ? 9 ) :r j R b : URSI' 7 5 ' ' LiJ:' -.Kt:: ? ; . t i : ':
-
, -
:5
.
Screen 10 and 11 sets up the variables
and the Columbia Mx96* hardware dependent words. The X-coordinate starts at
the lower l e f t corner as 0, far riqht as
1023, while Y = 0 starts a t 'the lower l e f t
corner t o the top as 779. Screen 12 t o 14
defines the basic words, which draw the
line, move the cursor, relative draw and
move.
Screen 1 5 defines the words t o
draw a square and the erasinq of it.
Screen 16 lets me draw many squares.
Iknow that there are s t i l l a l o t o f nice
words that can be written, such as, to
draw triangles, curve lines, etc. But, from
this small exercise, Iam totally convinced
the FORTH is the one Iw i l l use f r o m now
on.
,' PLATANOS ?4
F O R M DIMENSIONS 11115
Page 157
A VIDEO VERSION OF MASTER MIND
David Butler
Dorado Systems
The writing of this program served as
my introduction to FORTH. Using the figFORTH Installation Manual, Istumbled my
way through the basic concepts of FORTH
and eventually arrived a t this video
Master Mind game. The game is derived
completely from the original board version
of Master Mind, therefore, a l l credit for
the game itself goes t o the Invicta Game
Company.
The program contains many of the
functions found i n video editors, including
cursor management and character collection.
The sequence of this computer
version of the game is as follows: A f t e r
displaying the directions, the program
prompts the player to enter his skill level.
Then a 'secret code' is generated with the
help of the player tapping the space bar.
The screen is cleared, and a 'mask1 of the
Master Mind playing board is displayed.
The cursor lands a t the location where the
player is to begin entering his guess. The
program retains control o f the cursor, responding t o the player's key strokes.
Backspacing and tabbing are allowed, en-
.
.,.LP
>
#
18
O ( M a s t e r M i n d i n F o r t h b v D a v i d A.
1 --'
2
2;
1:lavid A. B u t 1 e r
3
33300 M i s s i o n B l v d
4
5
&
7
8
FIPt 1 2 6
U n i o n C i t y * CA.
( 41 5 ) 487-6033
'3
10
11
12
13
14
Butler
34587
**.*** A
n o t e ahout s t u l e :
If: t h e r e i s a n v r i t i s a n a c c i d e n t .
T h i s was ntLi f i r s t a p p l i c a t i o n i n F o r t h , s o i t may l a c k
some e l e g a n r e .
**.#**R e q u i r e m e n t s :
A video d i s p l a v 80 x 24 characters,
c u r s o r a d d r e s s i n s and c l e a r screen
+ur~cti~:nrts.
I. 5
!?CR # 19
0 i Master Mind
-notesDAB-l7nov80 )
1 -->
2
T h i s i s an implementation o f Master Mind bu I n v i c t a .
3 The same i s v e r y p o p u l a r b e c a u s e i t is e a s y t o l e a r n a n d a.
4 c h a l l e r ~ S et o ~ l a v . T h e r e i s a h i t o f l u c k t o i t , b u t i t i s
5 r n a i n l r . an e x e r c i s e i n l o $ i c a l d e d u c t i o n .
A " s e c r e t " tiode i s
b generated, and i t i s "cracked" b v a n a l v z i n s a s e t o f c l u e s .
7
:3
T h o s e * a m t i l i a r w i t h t h e o r i g i n a l b o a r d same w i l l h a v e no
8 d i f f i c u l t . ? a d j u s t i n s t o t h e computer v e r s i o n .
To newcomers.
1 0 f o l l o w t h e d i r e c t i o n s c a r e f u l l v a n d v o u w i l l h a v e i t i.n no
11 t i m e .
The F o r t t i v e r s i o n i s f u n c t i c ~ n al..,
i
identical t o the
12 bl:lard v e r s i o n .
I t i s w r . i t t e n i n Gig-Forth.
a n d 11a.s b e e n r.un
1 3 s u c c e s s f u l l r o n 1-.5(:)2. 8080, Z80. a n d 6%0OCJp r o c e s s o r s .
T t
1 4 i s a g o o d d e m o n s t r a t i o n p r o g r a m a s w e i 1 a s a n e n . j v v a b l e game.
15
SCR # :20
i:) (
Master Mind
s e t UP some v a r i a . b l e s
1.
2 : TASK
: i FI]RGE-l'T'RHLE MARKER )
.:.
4 O VhRIABLE COLORS 2 8 ALLOT
COLORS JC) FLANKS
5
/1. O VARIABL..E !?il:ODE
2 HLL.CIV
0 VAR1AHL.E GlJESS 2 ALLOT
7 O VARI ABLE SECRE'T 2 AL.L.llT
:3 O VAR IQBL..E HLQl::)::EFi
(11 VAfi'I: AHI-E: WH :[ 'TEH
9 6 VARIAHLE #i:ClL.OHS
1CI
1 1 3 VQHIABLE CUR. ROW
23 VARIABLE CUR. COL
1 2 1 V.4F:IABl-E XLUC
1 VARIfiBLE YLlllC
C) VARIFIBLE DONE
1,:s
--:,
...
14
1t",
'1"R
.-*
., # 2 1
O i Master Mind
1
2 : (1:. IZIIINSTAN-r
set
."
UP
-
YELL0WRE:li
cctnt.
DAB- 1 7 n o v g i j
BLACK GREEN WHITE FLI-IE
*I
.I
4 OVARIQHL..E CULOR.KEY
6 i
7
.-.
(
6 Al~LDT'
(
"colors"
tahlc-
)
1-Ire t h e sum of: t h e & S K I 1 c o d e o f t h e f i r s t 3 l e t t e r s
i.e.
BL,I.IE = "B" + "1-" + "I-I" = 66. + 76 + 85 = 2 2 7
)
)
.I.
9 234 I:LI:~R.
k;EY
C1
10
CI:ILOR.KEY
2 + !:I
1 1 2:3:: ~1111
.SIF?.YEY 4 + i::
!
1 ; '36 I;I:IL-OR.~:.:EY
t. + I.::!
1;:
14 t:! VAKIAHLE
#ATIEMPT'S
1.5; -->
Page 158
2L';j Cl:lLOH. KEY 1+ C !
2 2 2 CC)LOR.KEY 3 -I. C:!
227 COL.l::lR. KEY 5 + (::!
i used t n keep s c o r e
)
)
FORTH DIMENSIONS II1/5
I
SIZR # 22
O ( Master Mind
prompt and randomize
DAB-1 7nov:E:i:)
1 f
T h e s e d e f i n i t i o n s 3 e t t h e r a n d o m v a l u e s f a r t h e 3ame
!
: IVEWCll~lhlT
IF
i+
: RAND
(
CCl:lLOR# +. ! 1
!
ELSE:
DR1:lF' 1
."
C I N T I L t:+Y
DROF ;
." To r a n d o m i z e 7 t a p s p a c e b a r
I !<CODE + C ! L O i i P R:i
;
: ASK. FOR. L E V E L
IF
':
L.eve'l
3 3 = IF:
4 tlnies."
" t:::f:Y 1:iCIF' IFMI''[' t..EY t::m]1
1
F:I.,.:;E
k, #~.::I:ILI:IF~~~. ! .[HEN I..:N
1 or- 2 '1:'
7 #I:.I::IL-CIR::;
abling the player t o keep changing his
guess u n t i l he is satisfied that i t is consistent with the clues he has thus far received. A correct guess Es the result of the
player's logical deduction (or very good
luck) based on his previous clues.
The
directions on screen 3 1 explain the meani n g of the t w o types of clues.
DCIP #CC:ILC'IR$; i?.::
THEN ;
1 B E G I N NEWCOUNT ':-'TERMINAL
: 4SK.FOR.RANDOM
4 O Dl3 RAND
)
When the player signals he is ready,
the program compares the player's guess
to the secret code which was stored away
earlier.
Clues are generated and displayed, indicating t o the player how dose
he is to the solution. The player has ten
chances t o deduce the secret code.
:
--.:.
# 23
Master Mind
(
: TF<(.>N!::L.. &'T'E:'
t r a n s l a t e c o l o r to numeric
There are many improvements which
could be made to this program to take advantage of more o f FORTii'S built-in
vocabulary -- most notably PAD and related words. F o r those short o f memory,
note that the directions could be shortened, l e f t out, or read f r o m disk w i t h no
change t o the overall logic o f the program.
.
I::~II:IE
c o n v e r t s c o l o r # frcrm SC::ODE tc, CiiLfiH.KE'y'
( n u m e r i c . v a l u e i n a r r a ' i "SECRET"
.!
4 O Di3 SCilDE I -b tl@ 1 - COL..Of?.t::EY
+ @
:I
$.f:lltH[i7
I + I:!
L1:IOP
:
(
)
Further notes and comments may be
found i n the source screens.
1 .<:
1 -3
R::. R.?.
1
: ,J
1.5 --:.>
'?. .I-:R
# 24
-
Ci"i'lMF'I.LEI
.... .
f-:
::;WAF'
.::R
?;WQp
..[;:
7:;;WAp
..F> ;
~:IAB- 1 7 rl 0 v::::':!
Master Mind
c u r s o r rriotiar~
IZR'l . J e p e n d e n t .
Here i s Heath:
U t cour.se,
*+9
f +*l* s t a r t CRT d e p e r ~ r l e n t wnr-ds
i [ Y ] [ X j--.- L :I fiEtS13L..ClTt: I:I-.IRSl::lFi P i : i S I T:[ 1.IP.I i
3 : CCIR!SOR
MI
t:tqlr :
4
31. + SWAP 31 + :39 217 E M ~ T[:MI'.[
f:)
I
1
(
.:.
I
j
)
c
C:, : (::LEAF?
(
i.'l-E'QR i:::f.<-r !i;l:.:Rb,EPJ
)
27 F:t+ll!
kY11'
:
7
:3 : 1~41:111E:
( PI-IT I::L.IR!=;I:IF;
AT f.11:iME
pel!:; 1 1. I I)N ) i.! ():
( :I-lt.+.l. if.( ;
'?
(
*a*
e n d r r f I::R-i der:crlderrt w o r d 5
19 : SHI3W. CDLISRS
( D I S P L A Y CI:ILI:IF(
C'HOICES ;
11
7 1 DO 1 2 + 5% CURSOR 1 C~:IL.I:IR.
F I N D L.!ItOP
12
#C:i:tLl3RS @ 7 = I F 9 57 C:(jRS(JR
" <Bi-ANI.:.:-" £ L I[;:
1 HEN
13
12 SEi: ClJF:'.":CIR
:' TAB b e t h i e e n c.p i or.5, "
14
1 :3 58 (_UR?:i:IR
" PE T'l-fF\'hl t o g e t r 1 t . 1 ~ 5 ". ':
1 z:; --:::,
- .
!=.LR
# 25
.
C!
I
Master. M i n d
. TITLE.
1
.
.
board la.;out
trlask
Ti&R.-.j-"7r
, l!.sv:.~::
- - ."'>
!
.
;"
: DaSH
u -"
;
[ BuaEU SYf-iBLcL-S
)
21 !E;PAC;E!<
I,
M A S 1 5 R M 1: N [:I ====" :
4
5 : ClfiSHER 2 2 1 C:l-IRSnfi BAR 32 () L]u . " - f l L j i g P BAN ; :f< ;
b : CL.INE Cll,JP 21 C:l-IR!~l:lfi' BAR 54 C:IJRSilR BAR :
7
,
:3 : !%PACER 21 C:I-IRSOR
I-:"'.
.''.
.''.
.
.
9 : CBLOCI:
DUP C l L I N E 1+ SPACER :
It:! : H I D D E N :5 2 3 CURSI:I~-?
XXXXXX
XXXXXX
XXxXXX
gYxk'XX1'
2 : B&R
.'1
,.
++$*
80
. _-__
."
."
,!
..
:
11
12 : D I S P L 4 Y . BOARD
13
14
15
CLEAR
T I T L E DASHER H I D D E N 2 4 3 U i j I CBLOCK: 2 -+LO!ZlP
SHCIW. C::l:lLORS
;
-->
FORTH
DIMENSIONS III/5
Page 159
!3CR
(3
1
2
.-.
4
.:
it
!
26
:
x
Master Wind
cursor tracking definitions
e :
XLOC
:
v
DAB-l7nov8C?
)
:
YLOG @
: XBUMP x 52 =
IF
23 Ell-IF CUR. CI:IL,.
! XLJC
!
ir.
ELEiE
1 XL.01, I - ! X C:I-IR.C:iIlL @ 8
7
PF X CUR. COL
THEN
C.
c*
THEN
i
..I
._.I
9
l i 3 :: UIVBUMPX X 23 = I F 52 XLOC: !
-t.
=
E L S E -1 XLOC + ! THEN ;
.L .L
TAB
12 :
1:'3
14
15
:ii;c,
IF
ELSE
THEN
i:I-IR. i:OL
Q 47 =
23 CUR. COL !
8 CUR. C I ~ L + '
CUR. COL C XLOC: !
DROP Y X CUHSOR ; --3
27
#
O
(
Master Mind
c h a r a c t e r c o l l e c t i n n / c d i t i n ~ DAB-lSncevSO
1 : BfiCK!SPACE
X CllH. C i l L @ =
2
I F DROP
a
ELSE UNBUMPX Y X CURSOR SPACE Y X CURSOR DRClP
.. COI-12R8 X + 23 - C !
.32
4
:.I
THEN
;
)
#
.
b
7
8
r
--
F)ROCESS
I [CHAR]
DIjP E M I T CifL.OR!s X
+
Cj
23
-
PROCESSES IZHAH, MfiNAGES l::UHSOR
i:! XBIJNP Y )t C:UHSO&'
:
)
9
1.0 : I~I-~.I:HQFZ
C:EY ~II-IP 127 =
11
IF'
BfiCK!SPfiCE
C:liJP 9 =
112
IF
TAB
ELSE DUP 13 =
113
IF
1 DONE ! DROP
14
EL.SE PIT'I:ICE!?S
THEN 'THEN THEN ;
1.5 --3.
!s;,-::R #
.-.-=
. :a>.
O i
Master Mind
guess ! r o w sectior,
1
.
*
4 : ,i I ' I 1 .
2
:: + I:ll_rP YL..CII:
! l::l-IH BI:IW
' ::>:::: ;': X LiIC:
3
! CI-lR.COL ! Y X CClfiSi:~Fi
C
120 o D i i 32 1 COLORS + C! LOOP ;
7
8 : I X T . COLI:IHS
INIPT'AI. <> rli:lhiE
! B E G I N OLT. C:HAR I)ONE @ CINTSL. ;
.I:il-IES!<
1 0 : I:3.X":;E
11
1'L
1. :1
1.4
15
+ +
4 O 1,:Ii:l 1 E! a C:C:lL.C!R!=;
I $3 a l:::OLCIR!=; 1 + + !:@
I 3
C<ILI:IH~ 2 + + i:@
1: C;I-!ESS
+
1
:? : lI:L.l.IE. CHECK
:
0 HI-.NCI:..FR
4
1' (-1 l:l(:l
ii
SEil:RE T I
LTJIIIF' ;
i
Cl u e g e n e r a t i o n
!.i
WH1TE:P
+
'
-1-1
'l,N:[-IIfii,,J7E I:I-II.I~I.'~':-,
(
Gl_lE2:!3 1
1 BLACKER
IF
1;)
-F
<
c@=
I fil.,.lE'::.:;
+
CHEi:t::
.! ti
11
1. .I?
-Ti-IEN
THEN
1 0
. .%
LIIF
i ,(:I(
It:'
F[IR U:[
C'T H 11-
11.:
LI':1i.:IF
Ll1.1
'
'I - I :
(:,
:::.
I f.
i
4 !It f3li
l;l-l[t.~~ r + c-e C~:,:RET
. .
.! + !1@ =
( I:HEI.:I:
1F
1 WHITEFi + - I
1 I IGl-.ltlSS + I (
7
;:.;
1 :;'
l fl
1 5, .-.-:'..
--
C:(+
---)
SC;F; w 24
$3 i M a s t e r M i n d
Page 160
C;
+
I I,' Nlr~ H 1 -1-
!
FI:.:It? W t i I IF_ !
L.EfiVE
THE.:N
;
-
FORTH DIMENSIONS 11115
Si'R # 3 0
O
Master- M i n d
(
3.
~ r - e s e n tc 1 u e s
.
2 : G T V E C:LClE:!5
Y 1 C:I..IR!E;iJR
PARSE. GIJES!:;
C:L.CIE. CHE<:'tr(
BLACKER @
HL..AI:K
"
4
WHITER
@ .
WHUE
"
;
5 : UNMA!SK
3 23 ClJH!~i:lR
4 O DO I SCOnE + C@ COLijR. F 1, NU 1 3 =
7
1.F
" ELSE:
" THEN ~I:IL:23 1 i::URsOR
.
."
.-.
."
12
1:
14
15
.-.-
H
:.I
O
.
.
.
# .3 1
(
Master- Mind
BOSTON
FIG
MEMBERS
."
."
."
.
14 CR
15
H
:I
T.i.t=e
[RETURN3
t o r e c e i v e c l tjcs. " CR [::R
--3
CR :
.-.
-.
=,l-:R
# 32
(1) (
Master Mind
1
."
Goa2d- 1 1 j + k . "
-++ F I N G L ++
'1: : MA!:;TER
D I REi::T' 1:
!:i Ci
*&'Krt.MF"I' k.
!
4
ASK. FOR. LEVE:L
ASK. FCIH. RANDl:lM
9
D I S P L A Y . BOARD
'TRANSLATE. CI:IDE i FIJ t 1-It4MAYb:. t o d e b IJ 3
'2,
9
10
1 I.
2 :
13
14
1=;
CI 1 (:)
1 #A'T l-EpIP"r:< + 1
PAR!SE:. GLIESS
1: GET. IZOLI~R!S:
131I/E. CL..I-IES
BLACKER (!? 4 =
I F W:[NNEFr L.EAVf-1
EL:!.; E:'.. THEW
-.-I .sL(>I:.lF'
BL.AC.:t<ER @ 4 .:
I F i..l:lSE fi' EL.':;E THEN ; MA5;TE:R
:
n 6 -5 7 F n n I N o ===.,..-,._-_,.,.,.-_-..
......--,,-"--,--",*.:
====
^
( ~ h r r ra r e h l d . i r n
: RE14
d s ~ ? l r $ s ~ l a ~ l '.
., _
----
REO
BLUE
-----
GRFEN
:
:
7,
:
:-
SEEKING
:
!
FIG
CHAPTER
Interested parties i n the greater Salt Lake
C i t y area should contact:
B i l l Haywood
(801) 942-8000
,,
TECHNICAL PRODUCTS CO. MOVES
New address:
P. 0. Box 2358
Boone, NC 28607-2358
FIG NEW
CONTACT
..-,
4,
7
MOUNTAIN
WEST
ORGANIZING
.
.
.
."
CHAPTER
Interested parties should contact:
R. I.Demrow
P. 0.Box 158, Blv. Sta.
Andover, MA 01810
(617) 389-6400 x 198 - work
(617) 664-5796 - home
Directiorts t o player
C:L..EAR CR i:R CR
I
CR
We1 come t o MASTER MIND. "
CF: Cfi'
4
T h e o b . . i e c t o f M a s t e r Mir113 is t o b r e a k t h e F . C C ~ O,:,:,,je."
~
5 C:R
T h e c o n ~ ~ u t ewri ' l l p i c k t h e s e c r e t <:*:#do, a n d ..;, uu r n t l ~ t "
6 CFi
f i g ~ ~ ri et o u t .
Two k i n d s of: c l u e s a r e giver,:" CF:
7 CR
1
# BLACK
weans t h a t v o u have # p e 2 s c n r r e c l " CK
8
i n b rlt ti c ,:I 1 a r a rl d PO s j. t 1 a r! " C:R I: :H
Q
" ( 2 ) # W H I T E means t h a t v o u h a v e # p e 9 s o f t h e " i f i
1 (3
c o r r e c t c o l o r t h a t a r - e i n c o r r c c t l v " CR
11
p l a c e d . " CR
CR
12 m u B e s u r e t o s p e l l t h e c o l o r - s c o r r i - c t l - r .
Y o i j r r ~ a . ~t a
. t l an.liti.:nr
1 I"'R
"
-.
t h e 4 r e s i t i o n s u n t i l u o u ' v e make r.ol.lr-. h e s t S I J ~ S P . c:H
."
BEING
%.
1
2 : DIREC'TI1:INS
3 10 0 D!Zi L.OCIF'
CW.4PTER
-
.
.
."
FIG
Interested parties should contact:
George B. Lyons
280 Henderson St.
(212) 696-7606 days
(201) 451-2905 - eves
;
20 58 C:lJRSOR
" TYPE MUSTER r 1 2 " 2 1 58 1::- -IR!~I>R
-...
" P L A Y AG4 I N . " i-lNMASK 23 1 CI-IR!<jjR ;
: LOSER
55 II_':URSI:IR
M
NI C:E 'TRY ]L~I-IT" 17 58 c:uR!:~;IR
NO C I G A R . "
?&GAIN
:
: WINNER
16 53 CI.IRSOR
" PREC I SELY. " #A1-TEMpT'. ;2.
" TRYz. "
?AG&]:N
;
--1.:
9 : '?AGAIN
10
11
NEW JERSEY
FORMED
. ."
."
-5
YORK
CITY
MEETING
James Basile
40 Circle Drive
Westbury, NY 115900
(516) 333-1298
DALLAS-FT. WORTH METROPLEX FIG
MEETING CHANGE
Meetings now being held at:
Software Automation, Inc.
1005 Business Parkway
Richardson, TX
contact:
Marvin Elder (214) 231-9142
B i l l Drissel (214) 264-9680
VELLOW
RED
BLACK
GREEN
WHITE
.
4 HLII:I:
rr
WHI rE
, - .------- ------- ------- ------,
: HEU
RED
HLI-IE ' ILIHEEN :
_______ ___-___ -__-_-: RED
GREEN
RED
..- ,.-------BLUE
_-----------,
:_
1 BLACY 3 WHITE
0 B L K K 4 WHITE
: BLUE
_---__1
:
GREEN
RED
RED
: PRECISELY.
GREEN
BLACK
WHITE
:
:_
0 PLRCK 1 WHITE
(
: YELLOW
4 TRIES
Snapst-ot r f b o a r d a f t e r rlarins Master Mlnd
FORTH DIMENSIONS 11115
)
Page 161
PRODUCTS R N I E W
floating-point format. Numbers can be as
large as 1E38, and as small as 1E-38.
SORCERER-FORTH
by Quality Software
Transcendental functions
F o r about a year, I have been using an
excellent version of fig-FORTH tailored
f o r the Exidy Sorcerer. It is a product o f
Quality Software, 6660 Reseda Blvd.,
Suite 105, Reseda, C A 91335.
FORTH f o r the Sorcerer implernents
Release 1.1 o f 8080 fig-FOP.TH.
It includes a f u l l screen editor and input/output routines f o r the keyboard, screen,
and both serial and Centronics printers.
The Sorcerer's excellent graphics are also
available.
Disc storage i s simulated i n RAM. A
32 K Sorcerer can hold 14 screens--with
48 K, up t o 30 screens.
Tape-handling
routines are provided, to rnove data to and
f r o m the simulated disk space. The C P / M
disk interface routines are present, b u t
n o t implemented.
One o f the nicest features 07 Quality
Software's F O R T H is i t s documentation.
The 126-page manual is well-written, and
relatively complete. It includes s u f f i c i e n t
information f o r a F O R T H neophyte,
though i t does n o t delve too deeply i n t o
system operations.
Quality Software permits--even encourages--users t o m a r k e t application
programs incorporating Sorcerer FORTH.
They do ask that w r i t t e n permission be
obtained frist, b u t promise that permission
w i l l normally be granted a f t e r review o f a
sample o f the program.
I highly recommend this excellent product, and ask that you include it i n your
periodic listing o f available software.
C. K e v i n McCabe
1560 N. Sandburg Terr. 64105
Chicago, IL 60610
(312) 664-1632
A COMPARISON OF TRANSFORTH
WITH F O R T H
Insoft
Medford, OR
The floating-point format mentioned
above makes TransFORTH a natural larlquage for transcendental functions. Functions included i n the system which are not
found i n most versions o f F O R T H
include: sine, cosine, tangent, arctangent,
natural logarithm, exponential, square
root, and powers.
D a t a structures
TransFORTH contains words that w i l l
store or f e t c h 5-byte
floating-point
values, 2-byte cells, and single bytes f r o m
any location i n memory.
TransFCSRTH
does n o t have the fig-FORTH <BUILDS,
DOES> construction, but instead uses a
powerful
built-in
array
declaration.
Arrays can either f i l l space i n the dictionary, or be located absolutely i n memory.
Arrays w i t h any number o f dimensions
may b e declared, and each dimension can
have any length, within the l i m i t s o f
available memory.
Strings
Strings are merely arrays (of any dimension and size) w i t h an element length
o f one. Each character occupies one byte,
i-e., one element o f the array. Built-in
string functions included.
Disk access and the editor
TransFOKTH does not use the v i r t u a l
memory arrangement found i n most versions o f FORTH. Instead a standard DOS
3.3 f o r m a t is used, and files are called
f r o m the disk by name.
TransFORTH includes a straightforward line-based t e x t editor. The editor is
n o t added t o the dictionary as a l i s t o f defined words, b u t is included as a separate
module callable frorn TransFORTH. DOS
t e x t files are used for saving source
files. This means that any t e x t editor t h a t
uses DOS t e x t files may be used f o r editinq TransFORTH programs. I n addition,
TransFORTH program data may be shared
w i t h other programs and languages.
Grahics
A question we've been hearing a Lot
lately is "How does TransFORTH compare
w i t h fig-FORTH?"
I n structure, TransF O K T H is similar t o most version o f
FORTH, b u t is is not a FORTH-79 Standard System.
The major differences are
outlined i n this paper.
Floating-point numbers
I n TransFORTH, the stack i t s e l f contains floating-point numbers, w i t h 9 digits
o f accuracy.
N o special sequences are
required
to
retrieve
floating-point
values. Words are available f o r storing or
retrieving single bytes and two-byte cells,
b u t a l l values are stored on the stack i n
FORTH DIMENSIONS 11115
Two graphics u t i l i t i e s along w i t h a
couple o f graphics demo programs are included on the system diskette. One u t i l i t y
contains high-resolution
graphics and
Turtlegraphics commands, and the other
has l o w resolution graphics commands.
The graphics capabilities are added t o the
system by compiling these u t i l i t i e s into
the dictionary.
The hi-res package includes a c a l l t o a module which ailows
t e x t and graphics t o appear together anywhere on the screen.
Vocabulary
TransFORTH i s a
single-vocabulary
system. Related programs can be qrouped
together i n disk files, rather than i n separate vocabularies. !Multip!e vocabularies
f i n d their most usage i n multi-user systems.)
(:ompilation
and speed
A l l entries i n TransFOKTH are cornpiled d i r s c t l y i n t o 6502 machine language
f o r greater speed. N o address interpreter
is used. Even immediate keyboard entries
are compiled before being executed. This
means t h a t rootines can be tested a t the
keyboard f o r speed before being added as
colon definitions.
TransFORTIi is fast. I t is not as fast
an integer versions o f FORTH, because i t
handles 5 bytes w i t h every stack manipul a t i o n instead o f two. TransFORTH programs w i l l run faster than similar Applesoft programs, and show a great increase
i n speed when longer programs are compared.
While TransFOKTH works much l i k e
Fig-FORTH, the differences between the
t w o hecorne readily apparent under closer
examination.
F O R T H programmers w i l l
pick up TransFORTH w i t h l i t t l e trouble,
b u t nearly a l l F O R T H programs w i l l require translation into TransFORTH
to
take advantage o f i t s powerful features.
These features are accessible w i t h a mini m u m of work f r o m the user, bringing a
FORTH-like environment i n t o the realm
o f p r a c t i c a l scientific and business programming f o r the f i r s t time.
EDITOR'S RESPONSE T O
TRANSFORTH
The above material is,extracted f r o m
explanatory sales material f r o m the program vendor. Comrnentary we have indicated f r o m TransFORTH users can be
summarized:
I. This implementation should be
named as one o f the CONVERS group
of languages, as i t compiles t o assembly language rather than threaded
code.
2.
It is easier t o add floating point
m a t h t o FORTH, than t o a l t e r TransF O R T H t o use integers f o r execution
speed improvements. Why not both?
3.
I f the implementor had done his
DO5 3.3 interface using the standard
F O R T H word BLOCK, an immense gain
i n value would result. D i r e c t access
and DOS compatibility.
4. <BUILDS DOES> probably could be
added b u t apparently the implementor
doesn't know how or chooses t o deprive
his customers o f this powerful structure. Arrays are definitely not equivalent technically or philosophically.
I n conclusion,
i t appears that
TransFORTH is a reverse POLISH
BASIC,
w i t h names rather
than
labels. A small amount of additional
e f f o r t would have b u i l t upon FORTH,
rather than strip out major attributes.-ed.
--
Page 163
NEW PRODUCTS
FLEX-FORTH
"Starting FORTH" compatibie FORTH
software for a 8080 or Z8G comptiter
system with the CP/M (TM) operating
system.
POLYMORPHIC F O R T H
Abstract Systems, etc.
1686 West Main Road
Portsmouth, R I 02871
Copyright (C) 1981 by Laxen and Harris,
Inc. A l l rights reserved.
Ralph E. Kenyon, Jr.
(sol) 683-0845
Complete compiler/interpreter,
bler, editor, operating system for:
APPLE I1 computers
K I M computers
assem-
This FORTH impiernentation is compatible with the popular book "Starting
FORTH" by Leo Brodie. It Is intended to
be a companion t o the book t o aid learning
FORTH. It is also a complete environment for developing and executing FORTH
programs. It contains:
Compilers
Disk operating system
F u l l names stored, up t o 31 characters
String handling
Enhanced error checking
16-bit and 32-bit integer arithmetic
and input/output
This is a single-user, single-task system which is not ROM-able as supplied.
Floating point arithmetic and CP/M f i l e
access are not supported.
$25.00
$21.00
FLEX-FORTH is a complete structured
language with compiler,
interpreter,
editor, assembler and operating system f o r
any APPLE 11 or APPLE 11+ computer with
48K and disk or K I M w i t h 16K of memory. Most application programs run i n less
than 16K starting a t 1000 HEX and often
as l i t t l e as 12K, including the FLEXFORTH system, itself.
This is a full-featured FORTH following the F.I.G. standard, and contains a
6502 assembler for encoding machine
language algorithms i f desired.
The
assembler permits macros BEGIN UNTIL,
BEGIN WHILE
BEGIN AGAIN.
REPEAT, IF ENDIF,
and I F ELSE...
ENDIF. Editor and virtual memory files
are linked t o the Apple DOS 3.2. An application note for upgrading t o DOS 3.3 is
included. Object code on disk with user
manual sells for $25.00.
(APPLE) or on
cassette w i t h user manual for $21.00
(KIM).
...
... ...
...
...
...
This system as supplied runs comfortably i n a 8080 or Z80 computer system
w i t h at least 32K bytes of R A M memory,
a t least one floppy disk drive (8" single
density, single sided, soft sectored format
is assumed), and the "BIOS" p a r t of the
CP/M operating system. The use o f a
printer is supported but not required. This
software may be easily modified to use
other memory sizes or disk formats. It
requires 14K bytes o f memory which includes 4K bytes o f disk buffers.
A complete source listing is available
t o purchasers of FLEX-FORTH f o r
$20.00.
The source is valuable in both
showing how FORTH works and i n giving
examples o f FORTH code and integrated
assembly code.
This F O R T H system was adapted f r o m
the fig-FORTt-l model but is not fully
compatible w i t h that language dialect. It
is also not fully compatib!e with the
FORTH-79 Standard. The three dialects
are similar, but the Starting-FORTH version has advantages over the other two.
Order from:
GEOTEC, 1920 N. W.
Milford Way, Seattle, W A 98177. Be sure
t o specify machine.
M A R X F O R T H V1.1
Perkel Software Systems
1636 N. Sherman
Springfield, M O 65803
(417) 862-9830
Enhanced 280 fig-FORTH implemented
for Northstar System enhancements include link fields in front o f nalne for fast
compile speed; dynamic vocabulary relinking; case; arguments-results w i t h 'to' variables: and more. 79-Standard package includes easy to use screen editor.
Price: $75.00
Smart assembler, meta-compiler and
source code (in FORTH) sold separately.
Call for information.
TWO N E W PRODUCTS FROM
L A X M AND HARRIS, INC.
Laxen and Harris, Inc.
24301 Southland Drive
Hayward, C A 94545
(415) 887-2894
1. Working FORTH
Release 2.1
Page 164
---
Price: $33.00 - plus $2.00 - Postage and
Handling
CP/M is a registered trademark of Digital
Research, lnc.
2. Learning FORTH
Learning FORTH is a coniputer aided
instruction package that interactively
teaches the student the fundamentals o f
the FORTH programming language and
It consists of a set of
philosophy.
FORTH
screens that contain program
I t is
source code and instruction text.
based on the book, "Startinq FORTH," by
Leo i3rodie. It w i l l run with any Starting
FORTH compatible system, as well as figF O R T t i system. The manual is only one
page long and describes how t o load the
systerii.
After that, everytlhing is self
explanatory.
It is supplied on 0" sinqle
density diskettes in IBM 3740 forrnat. The
prico i s $33.00 if ordered toqether w i t h
the Workinq FORTH Disk.
Please add
$2.00 for shipping and handlinq, and allow
a t 1e:lst 3 weeks for delivery.
Buy both for $55.001 paus $2.00
Note:
postage and handling.
-
--
-
Product Description:
FORTH (PolyMorphic fig-FORTH 1.1.0).
8080 figFORTH 1.1 without asmb. or Editor (uses
PolyMorphic resident editor.)
A demo application which computes a
table o f values f o r a general quadratic
equation is included.
PolyMorphic Systems 8813, 8810 needs
only 16K. Documentation on FORTH not
included.
Manual: documentation covers particular implementation details for figFORTH t o interface to the PolyMorphic
Sorted VLIST
Systems Microconlputer.
included.
Imolementation document availabie
separately. Separate document available
for cost of postage. Product data available on PolyMorphic SSSD 5" diskette
4 copies sold t o date. Price:
format.
840.00, includes shipping, diskette, (R.I.
Warranty
residents add 6% sales tax).
limited t o replacement o f a diskette
damaged i n shipment. (We'll t r y t o f i x any
bugs discovered.)
Orders shipped out
within 3 days of receipt (usually next day).
H E A T H HB9 F O R T H
MCA
8 Newfleld Lane
Newtown, Conn. 06470
MCA announces the availability of
FORTH for the I-leath H89 computer.
M C A FORTH is 8080 fig-FORTH V1.1
configured t o run on a single disk H89 w i t h
32K or more of memory, utilizing HDOS
1.6 or later.
M C A FORTH provides the standard
FORTH facilities plus the following
special features: HDOS f i l e manipulation
capability, a control character to restart
FORTH (recover from loops), on-line
tailoring of FORTH facilities (e.g., number of disk buffers), ability t o hook t o separately assembled routines, and use of
Heath DBUG.
Items supplied w i t h FORTH include the
fig-Editor, an 8080 structured assembler,
and two games provided as examples of
1:-ORTH programming.
The documentation supplied w i t h MCA
FORTH is suitable for experienced
FORTH programmers; however, a biblioqraphy of documentation for beqinners is
provided.
MCA FORTH is available f r o m MCA
on a 5-I/&" disk for $25 including documentation.
Documentation is available
for $4.00.
(Corin. residents please add
sales tax).
FORTH DIMENSIONS 11115
N E W PRODUCTS F R O M
one 8" diskette.
Currently, there are approximately 75 installations, a f t e r 2 months on the market.
INNER ACCESS CORPORATiON
Price: $1,450.00
1. Fig-FORTH compiler/interpreter f o r
PDP-11 f o r RT11, R S X l l M or standalone w i t h source code i n native assembler. Included i n this package are
an assembler and editor w r i t t e n i n
F O R T H and installation documentation. R i c e : $80.00
5 . Zilog 28002 Development Mcdule fig-F O R T H R O M set. Contains 79-Standard F O R T H w i t h 28002 assembler and
editor i n 4 (2716) PROMS.
Price:
$280.00
CODE9
Arthur M. Gorski
2240 S. Evanston Avenue
Tulse, O K 74114
(918) 743-0113
This is available on a one 8'l single
density diskette only.
Reference Manual f o r PDP-11 figFORT14 above. Price: $20.00
2. Fig-FORTH compiler/interpreter f o r
CP/M or CROMEMCO Cl3OS system
comes complete w i t h source code w r i t ten i n native assembler.
Included i n
this package are an assembler and
editor w r i t t e n i n F O R T H and installation documentation. Price: $50.00
C 3 D E 9 is a M6809 Assembler f o r use
w i t h any fig-FORTH systern. It features
a l l M6809 addressing modes except long
relative branch instructions. It performs
syntax error checking a t assembly time.
Memory requirements: 4.75K bytes free
R A M above FORTH. CODE9 is distributed as a commented source listing and
manual. Price: $20.00
A l l diskettes are single density, w i t h 51/4" diskettes i n 128 byte, 18 sector/track format and 8" diskettes i n 128
byte, 26 sectorltrack (IBM) format.
PET-FORTH
by
Datatronic AB
Box 42094
5-126 12 Stockholm
Sweden
(0)-8-744 59 20
Peter Bengtson
Released on two 5-114" diskettes w i t h
source i n 8080 assembler.
Released on one 8" diskette
source i n 8080 assembler.
with
Released on two 5-1/4" diskettes w i t h
source i n Z80 assembler.
Released on one 8" diskette
source i n Z80 assembler.
with
Manual for CP/M (or Cromemco) figF O R T H above. Price: $20.00
3.
METAFORTH~~
Cross-compiler f o r
CP/M or Cromemco CDOS t o produce
79-Standard F O R T H on a target
machine.
The target can include an
application without dictionary heads
and link words. It is available on single
density diskettes w i t h 128 byte 26
sectorltrack format. Target compiles
may be readily produced f o r any o f the
following machines:
CROMEMCO-all models
TRS80 Model I1 under CP/M
Northstar Horizon
Prolog 280
Released on two 5-1/4" diskettes or on
one 8" diskette.
Price: $450.00
4.
Complete Zilog (AMD) 28002 development system that can be run under
C P / M or Cromemco C
System
includes a METAFORTHqHS~ross compiler which produces a 28002 79Standard F O R T H compiler/interpreter
f o r the Zilog 28000 Development
Module.
Package includes a 28002
assembler,
a Tektronix
download
program and a number o f utilities.
Released on two 5-114" diskettes or on
FORTH DIMENSIONS 11115
Product Description:
Extended figF O R T H f o r the Commodore CBM/PET
computer series.
Screeri editor, u t i l i z i n g the special C B M
screen editing possibilities f o r compactness and ease o f use, macro-assembler,
double-precision extensions, C R T handling, random numbers, real-time clock, a
very complete string package, IEEE cont r o l words, integer t r i g functions.
An expansion disk (corning soon) w i l l cont a i n floating point arithmetic including
complex numbers, transparent overlay
program
control words for data
segments, a f i l e system, and more.
A
METAFORTH compiler w i l l shortly be
available.
and
Rcrns on C B M 6032 plus an 8050 dual disk
drive. Other configurations coming: 4032,
4040, VIC, and MicroMainFrame.
Price: $290.00 Includes diskette, ROM,
manual, shipping and taxes.
PET-FORTH, as a l l other Datatronic software, carries a l i f e - t i m e guarantee. A l l
future versions w i l l be distributed t o the
registered owners without any cost whatsoever.
Delivery is immediate.
U S dealers are invited. UK sole distributor is Petalect Electronic Services Ltd,
33/35 Portugal iioad, Woking Surrey. You
may also order directly f r o m us.
Diskette o f F O R T H Application Modules
from
Tirnin Engineering Company
9575 Genessee Avenue, Ste. E-2
San Diego, C A 92121
(714) 455-9008
The diskette of FORTH application
modules, a new product by Timin Engineering, is a variety package o f F O R T H
It contains hundreds o f
source code.
F O R T H definitions not previously published. Included on the diskette are data
structures, software development aids,
string manipulators, an expanded 32-bit
vocabulary, a screen calculator, a typing
practice program, and a menu generationiselection program. I n addition, the
diskette provides examples o f recursion,
<BUILDS. ..DOES> usage, output number
formatting, assembler definitions, and
conversational programs.
One hundred
screens o f software and one hundred
screens o f instructional documentation are
supplied on the diskette. Every screen is
i n exemplary FORTH programming style.
The F O R T H screens, w r i t t e n by Scott
Pickett, may be used w i t h T i m i n F O R T H
or other fig-FORTH.
The price f o r the
diskette o f F O R T H application modules i s
$75.00 (if other than 8" standard disk, add
$15.00). To order the FORTH modules,
w r i t e Timin Engineering Company, 9575
Genesee Avenue, Suite E-2, San Diego,
C A 92121, or c a i l (714) 455-9008.
AUDIO TAPES OF
8032 version runs i n 32K only.
4032
versions w i l l r u n i n either 16 or 32K.
Manual Description:
a l l source code.
1980 F O R M L CONFERENCE
AND 1980 F I G CONVENTION
322 pages, including
Complete introduction t o FORTH. Special
chapters cover the asembler, <E)UILDS and
DOES>, IEEE handling, strings etc.
1. FORTH-79 Discussion, 200 min. R i c e :
$35.00
2.
Purpose o f FIG, 37 rnin. Price: $10.00
3. Charles Moore, 63 rnin. Price: $15.00
Manual is available separately.
4. FORTH, Alan Taylor, 47 min. Price:
Separate purchase price i s $40.00. This is
not creditable towards later purchase.
-
Product/Ordering Data: Shipped as diske t t e and an accompanying security ROM,
holding p a r t o f the Kernel.
$15.00
Complete set $65.00
edu-FORTH
1442-A Walnut Street, 8332
Berkeley, C A 94709
Page 165
FORTH VENDORS
The following vendors have versions o f
FORTH available or are consultants. (FIG
makes no judgment on any products.)
ALPHA MICRO
Professional Management Services
7 2 4 Arastradero Rd. i l l 0 9
Pa10 Alto, C A 94306
(415) 858-2218
Sierra Computer Co.
617 Mark NE
Albuquerque, N M 87123
APPLE
IDPC Company
P. 0. Box 11594
Philadelphia, PA 19116
(215) 676-3235
IUS (Cap'n Software)
281 Arlington Avenue
Berkeley, C A 94704
(415) 525-9452
George Lyons
280 Henderson St.
Jersey City, N J 07302
(201) 451-2905
MicroMotion
12077 Wilshire Blvd. 11506
Los Angeles, C A 90025
(213) 821-4340
CROSS COMPILERS
Nautilus Systems
P.O. Box 1098
Santa Cruz, C A 95061
(408) 475-7461
polyFORTH
FORTH, Inc.
2309 Pacific Coast Hwy.
Hermosa Beach, C A 90254
(213) 372-8493
LYNX
3301 Ocean Park B301
Santa Monica, C A 90405
(213) 450-2466
M & B Design
820 Sweetbay Drive
Sunnyvale, C A 94086
Micropolis
Shaw Labs, Ltd.
P. 0. Box 3471
Hayward, CA 94540
(415) 276-6050
North Star
The Software Works, Inc.
P. 0. Box 4386
Mountain View, C A 94040
(408) 736-4938
PDP-11
Laboratory Software Systems, Inc.
3634 Mandeville Canyon Rd.
Los Angeles, C A 90049
(213) 472-6995
OSI
Consumer Computers
8907 LaMesa Blvd.
LaMesa, C A 92041
(714) 698-8088
Page 166
Software Federation
44 University Dr.
Arlington Heights, IL 66064
(312) 259-1355
Technical Products Co.
P. 0. Box 12983
Gainsville, FL 32604
(904) 372-8439
Tom Zimmer
292 Falcato Dr.
Milpitas, C A 95035
1802
FSS
P. 0. Box 8403
Austin, TX 78712
(512) 477-2207
6800 & 6809
Kenyon Microsystems
1927 Curtis Avenue
Redorido Beach, CA 90278
(213) 376-9941
TRSEQ
The Micro Works
P. 0. Box 1110
D e l Mar, C A 92014
(714) 942-2400
68000
Emperical Res. Grp.
(3. Box 11'76
Milton, WA 98354
(206) 631-4855
P.
Firmware, Boards and Machines
Datricon
7911 NE 33rd Dr.
Portland, OR 97211
(503) 284-8277
Forward Technology
2595 Martin Avenue
Santa Clara, CA 95050
(408j 293-8993
Rockweii International
Microelecironics Devices
P.O. Box 3669
Anaheim, C A 92803
(714) 632-2862
Zendex Corp.
6398 Dougherty Rd.
Dublin, C A 94566
Variety of FORTH Producb
Interactive Computer Systems, Inc.
6403 D i Marco Rd.
Tampa, F L 33614
Miller Microcomputer Services
6 1 Lake Shore Rd.
Natick, M A 01760
(617) 653-6136
Mountain View Press
P. 0. Box 4646
Mountain View, C A 94040
(415) 961-4103
The Software Farm
Supersoft Associates
P.O. Box 1628
Champaign, IL 61820
(217) 359-2112
P. 0. Box 2304
Reston, VA 22090
Sirius Systems
7528 Oak Ridge Hwy.
Knoxville, T N 37921
(615) 693-6583
6502
Eric C. Rehnke
540 5. Ranch View Circle #61
Anaheim Hills, C A 92087
Consultants
Creative Solutions, Inc.
4801 Randolph Rd.
Kockville, M D 20852
Dave Boulton
581 Oakridge Dr.
Redwood City, C A 94062
(415) 368-3257
Saturn Software, Ltd.
P. 0. Box 397
New Westininister, BC
V 3 L 4Y7 CANADA
8080/ZEQ/CP/M
Laboratory Microsystems
4147 Beethoven St.
Los Angeles, C A 90066
(213) 390-9292
Timin Engineering Co.
9575 Genessn Ave. #E-2
San Diego, C A 92121
(714) 455-9008
Application Packages
InnoSys
2150 Shattuck Avenue
Berkeley, C A 94704
(415) 843-8114
Decision Resources Corp.
28203 Ridgefern Ct.
Rancho Palo Verde, C A 90274
(213) 377-3533
Go FORTH
501: Lakemead Way
Redwood City, C A 94062
(415) 366-6124
Inner Access
517K Marine View
Belmont, C A 94002
(415) 591-8295
.Inhi1 S. James
P, 0. Bcx 3aG
Derkeiey, C A 94701
Laxen & Harris, Inc.
24701 Southland Drive, 6 3 0 3
Hayward, C A 94545
(015) 007-2894
Microsystems, Inc.
2500 E. Foothill Blvd., W102
Pasadena, C A 91107
(213) 577-1471
FORTH DIMENSIONS 11115
FORTH lNTEREST GROUP
MAIL ORDER
USA
FOREIGN
AIR
Membership in FORTH INTEREST GROUP and Volume 111 (6 issues) of
FORTH DIMENSIONS.
Volume II of FORTH DIMENSIONS (6issues)
Volume Iof FORTH DIMENSIONS (6 issues)
fig-FORTH Installation Manual, containing the language model of
fig-FORTH, a complete glossary, memory map and installation instructions
Assembly Language Source Listings of fig-FORTH for specific CPU's and
machines. The above manual is required for installation. Check appropriate
boxfes). Price per each.
1802
8080
PACE
6502
8086/8088
ALPHA MICRO
6800
17 9900
5 PDP-1 1
6809
APPLE II
17 NOVA
"Starting FORTH" by Brodie. BEST book on FORTH. (Paperback) N E W
"Starting FORTH" by Brodie. (Hard Cover) E
PROCEEDINGS 1980 FORML (FORTH Modification Lab) Conference
PROCEEDINGS 1981 FORTH Univ. of Rochester Conference
PROCEEDINGS 1981 FORML Conference, Both Volumes N E W
Volume I, Language Structure
Volume II,Systems and Applications
FORTH-79 Standard, a publication of the FORTH Standards Team
Kitt Peak Primer, by Stevens. An indepth self-study primer.
BYTE Magazine Reprints of FORTH articles, 8/80 to 4/81
FIG T-shirts:
Small 17 Medium I7 Large
X-Large
Poster, Aug 1980 BYTE cover, 16 x 22"
FORTH Programmer's Reference Card. If ordered separa.tely, send a
stamped, addressed envelope.
FREE
TOTAL
MAIL STOP/APT
(If company address)
NAME
ORGANIZATION
ADDRESS
CITY
STATELIP
VISA #
Expiration Date
MASTER CHARGE #
COUNTRY
(Minimum of $10.00 on charge cards)
Make check or money order in US Funds on US bank, payable to: FIG. All prices include postage.
purchase orders without check.
No
ORDER PHONE NUMBER: (415) 962-8653
FORTH INTEREST CROUP
PO BOX 1 105
SAN CARLOS, CA 94070
BULK RATE
U.S. POSTAGE
support
Your Local
FORTH INTEREST GROUP
P.O. Box 1 105
San Carlos, CA 94070
FIG
Address Correction Requested