\chapter{First steps}\label{first}  % -*- Mode:TeX -*-

This chapter introduces you to the use of the \pc\ terminal as a
``control panel'' for \cam.  As an example we'll
load and run the game of ``life''---a well-known cellular automaton
you may already be familiar with. Most of this material will be
covered in a more systematic way in the following chapters.

For ready reference, Appendix \ref{cp-summary} displays a complete
summary of \cxp\ commands.

\section{The terminal as a control panel}

The \id|CAM|\index{CAM.EXE{\tt CAM.EXE}} program takes control of all of the \pc\ hardware and
presents you with an integrated programming environment suitable for
running \cam. Most of the time the terminal\index{Terminal} (i.e., the \pc's keyboard and
monitor) is turned into a dedicated {\sl \cp},\index{Control panel} where each
key has a special function with immediate effects.  Some keys allow
you to temporarily leave the \cxp\ mode\index{Keyboard/control-panel mode} to access more generic
programming resources, such as the Forth interpreter or the
editor; in this context, the function of the terminal reverts
to that of a (smart) typewriter\index{Keyboard/typewriter mode}.

\medskip

As we've seen in the previous chapter, the \prog{CAM} program
comes up with the message
 \begin{verbatim}
    Press `m' for a menu\end{verbatim}
 if everything seems to be in working order.  Just below this message
you will notice a little ``happy face;'' this is a {\sl prompt}\index{Control panel/prompt} telling
you that the terminal is in the \cxp\ mode and is ready to accept a
command.  The prompt comes in one of two colors.  A {\sl black} face
means that an experiment is actually running; a {\sl white} face means
that no experiment is in progress, or that the experiment you were
running is temporarily stopped.

\section{Menus}\label{menus}

\index{Menus}\index{Control-panel commands/menus}If you type \id|m| now, the screen will display the {\sl master
menu} (the ``menu of menus''), which should look something like this
 \begin{verbatim}
    0m GENERAL
    1m DISPLAY/CONTROL
    2m EDITING,RUNNING
    3m PLANE-OPS
    4m DOTS,SHIFTS
    5m ALTERNATE\end{verbatim}
 If you type, say, \prog{3m} you'll get menu 3, concerned with
\cam-plane operations.  Each menu lists a whole set of one-key commands,
each accompanied by a short mnemonic name to help you remember its
function.  Once you learn which key invokes some desired function you
can type it directly, without going through a menu.  All these functions
will be discussed in detail in the next few chapters.

\section{Typing conventions}\label{typing}

\index{Typing conventions}Each \cxp\ command consists of a single
keystroke, possibly preceded by a numeric argument\footnote
        {See Appendix \ref{general} for how to enter an argument in a
base different from ten.}
        and possibly followed by a text-string argument.\index{Control
panel/numeric argument}\index{Control panel/string argument} We'll
indicate the command keystroke by a box containing the corresponding
character; for example, the {\sl Menu} command will be denoted by
\icp\keym.  The ``carriage return'' or ``enter'' key, typically the
largest on the keyboard, is indicated by the symbol \icp\keyreturn.

In general, the \cp\ and the Forth interpreter distinguish between
upper- and lower-case letters---and the case of a letter depends, as
usual, on whether you are pressing the {\sc shift} key
and on whether you are in {\sc CapsLock} mode.\footnote
    {In many \pc\ models, software is not able to control the
{\sc CapsLock} light (where it exists) in a consistent manner. This
difficulty is solved by letting the {\sl size} of the cursor on the
terminal---{\sl tall} (\vrule height1.6ex width0.4em) or {\sl short}
({\tt \_})---tell you whether or not you are in {\sc CapsLock} mode.}
    
The following typing conventions apply to the control panel (which
is always in no-{\sc Caps-Lock} mode)		;
 \begin{enumerate}
  \item A nonalphabetic symbol in a box, such as \keycolon\ or \keysemicolon,
means you have to hit the corresponding key, with a {\sc shift}
when appropriate.
  \item A lower-case letter in a box, say \keya, means that you
must simply hit the \id|A| key.
  \item An upper-case letter in a box, say \keyA, means that you
must hit the \id|A| key while holding the {\sc shift} key pressed.
  \item A small-caps word in a box, such as \keyesc, means that you
must hit the corresponding key on your keyboard (refer to the \pc\
operating manual).
  \item The function-key boxes \keyfn1\ and \keyFn1\ refer to the unshifted and
shifted versions respectively of the \id|F1| key.
  \item A word in typewriter font, such as \prog{life}, denotes
a text-string argument, to be typed character-by-character {\sl and followed
by \keyreturn.}
  \item A letter in a box starting with the prefix \id|Ctrl-| (such as
\ctrla) means that you must hit the corresponding key while holding
the {\sc control} key pressed. 
  \item A letter or function key in a box starting with the prefix \id|Alt-| (such as
\kbox{Alt-A}) means that you must hit the corresponding key while
holding the {\sc alt} key pressed.
  \item Finally, \keybreak\index{Break key} will denote ``break''---a brute-force
way of aborting execution of any command---which in
the \pc\ is actually achieved by pressing {\sc ScrollLock} while
holding the {\sc control} key pressed.
  \end{enumerate}

With the above conventions, a sequence such as \keyL\targ{life}
indicates that you must type \keyL\ (using the {\sc shift} key, since this is an
upper-case letter), and then the string \prog{life} 
followed by \keyreturn.  Note that, as soon as you enter the command \keyL,
the happy face disappears and is replaced by an appropriate prompt
message---in this case
 \begin{verbatim}
    Load.new.file:\end{verbatim}
 and the keyboard temporarily switches from \cxp\ mode to typewriter
mode\index{Keyboard/typewriter mode}, so that \prog{life} will be treated as a text string rather than
as the sequence of commands \keyl\,\keyi\,\keyf\,\keye; the keyboard
reverts to the \cxp\ mode\index{Keyboard/control-panel mode} as soon as you enter \icp\keyreturn.  You can
always escape from the typewriter mode by pressing \icp\keyesc: this
aborts the current command\index{Control-panel commands/aborting a
command} and immediately returns you to the \cxp\ mode.

\section{A first experiment}\label{first-exp}

At this point you are ready to run a simple \cam\ experiment.
 \begin{itemize}
  \item Type \keyL. You'll see the message
   \begin{verbatim}
    Load.new.file:\end{verbatim}
 \item Answer with the name of the 
experiment file you want to load.\footnote
    {The \keyL\ command expects the name of a disk file, and assumes for
this file the default extension \id|EXP|, so that you don't need to
append the extension unless your experiment file has one other than {\tt
EXP}.  Moreover, file names are passed on to DOS, which is
``case-blind;'' thus, in the present context {\tt life} and {\tt LIFE}
are equivalent.}
     In this case, type \prog{barelife}.
 \end{itemize}

Before typing anything else, {\sl wait until you again see the happy
face prompt.} The red light of your disk drive will flash briefly,
some comments will appear on the terminal, and the happy face will
reappear: the program for the experiment \iprog{BARELIFE} has been
successfully loaded.

Now we need to give some initial conditions to the experiment.  Type
\narg{0}\keysemicolon\ to fill \cam's plane 0 with random bits.  The
plane's contents is displayed on \cam's monitor; you should see a random
pattern of green dots.

If you are sharing the color
monitor\index{Monitor/sharing}\index{Control-panel commands/display}
between \cam\ and the \pc, you must use the command \keya\ (``alternate
display'') in order to see \cam's output rather than that coming from
the \pc\ (cf.\ Appendix \ref{monitor}).
    The \keya\ command is a {\sl toggle}, i.e., it will move
you back and forth between the two display modes. On the other hand,
\keyA\ will force the display to the default, \pc-output
mode.\index{Display/mode}
 \begin{equation}
  \begin{tabular}{|l|p{8cm}|} \hline
    \icp\keya & {\sl Alternate display}. Toggle between \pc\ and \cam\
display (if monitor is shared). See Appendix \ref{monitor}
for the use of an optional numerical argument.\\\hline 
    \icp\keyA & {\sl Restore \pc\ display} (if monitor is shared between
\pc\ and \cam).  \\\hline
  \end{tabular}
 \end{equation}
    The usefulness of a ``restore default state'' command such as \keyA\
is not obvious in the normal, interactive situation, since you can
easily see from the display what mode you are in.  However, such
commands are essential in certain situations (remote control, ``macros''
consisting of canned sequences of keys, etc.)  where the state of the
display (or of some other \cam\ feature) may not be known a priori.  In 
general, the shifted version of a \cxp\ command has a meaning closely
related to the unshifted version, and is used to restore
a default state, to ask for a text string as an argument, or for
some other less-frequently used variant of the command.

While the unshifted and shifted versions of keys have a predefined
meaning, the {\tt Alt-} versions available for
user-defined commands, as explained in Section \ref{attach}\index{Control-panel commands/user-defined commands}.

\section{Running control}\label{run-keys}

Now that you have loaded an experiment and set the initial conditions,
you can control the evolution of the system by using one of the
commands listed below.\index{Control-panel commands/running control}\index{Step/rate}

\begin{displaymath}
 \begin{tabular}{|c|p{10cm}|} 
  \multicolumn{2}{c}{From the {\tt EDITING,RUNNING} menu}\\\hline
  \icp\keys & {\sl Step}. Execute a single step of the evolution of the
cellular automaton. If this command is preceded by a numeric argument $n$
(in the range 1 through $2^{32}${}$-$1), it will execute $n$ steps at
the current step rate (unless stopped earlier by the {\sl Stop}
command).  \\ \hline
  \icp\keyS & {\sl Run}. Run steps continuously, at the current step rate.
The result is real-time animation on the screen. \\ \hline
  \icp\keyspace & {\sl Stop}. Stop running, and display on the control
panel the value of the step counter\index{Step/counter}. Use \keyS\ to
resume running. \\ \hline
  \icp\keyless & {\sl Slowest}. Go to the lowest step rate (approximately 1
frame/sec).  \\ \hline
  \icp\keygreater & {\sl Fastest}. Go to the highest step rate
(approximately 60 frames/sec).  \\ \hline
  \icp\keycomma & {\sl Slower}. Halve the step rate. If you hit this
key several times, the movie will turn into a slide
show. (As a mnemonic, note that \keycomma\
and \keyperiod\ are just the unshifted versions of \keyless\ and
\keygreater.)\\ \hline
  \icp\keyperiod & {\sl Faster}. Double the step rate. \\ \hline
 \end{tabular}
\end{displaymath}
\begin{displaymath}
 \begin{tabular}{|c|p{10cm}|} 
  \multicolumn{2}{c}{From the {\tt DISPLAY-CONTROL} menu}\\\hline
  \icp\keyx\ & {\sl Expand}.  Display a magnified view of the central
portion of the \cam\ screen (use the arrow keys, discussed in Section
\ref{shifts}, to move to the center of the screen the area you are
interested in). Hit \keyx\ again to return to the normal view.
The magnified view may be used even while the simulation is running, but it
will slow it down.  All \cxp\ commands can still be used while in
expanded mode. See Section \ref{magnify} for more details.\\ \hline
 \end{tabular}
\end{displaymath}

{\small The step counter\index{Step/counter} is initialized to the value $-${}$n$ by the command
\narg{$n$}\keys\ (where $n$ denotes the numeric argument), and is
incremented by 1 after each step. When the counter reaches 0 the
simulation is stopped. If you type \narg{100}\keys\ and press the
\keyspace\ bar before 100 steps have completed, the counter will
display a negative value; if you resume by typing \keyS\ with no
argument, the counter will continue incrementing up to 0 and then the
simulation will stop. If you resume again with \keyS, it will
start going through positive values.  The counter works modulo
$2^{32}$: if you type \narg{0}\keys, it will count 1, 2, 3,
\ldots\ and will stop when it reaches 0 again---after $2^{32}$ steps.
Thus, \narg{$n$}\keys\ is useful for a ``count-down'' of $n$ steps,
and \narg{0}\keys\ for counting from 0 upwards.

}


