.rm CM
.nr PS 12
.ps 12
.nr VS 14
.vs 14
.\" sccsid "@(#)tut2	4.13 (Berkeley) 11/29/85"
.de (C
.nr PS -2
.nr VS -2
.nr LL 5.5i
.IP
..
.de )C
.sp .5c
.nr PS +2
.nr VS +2
.nr LL 6i
..
.DS C
.LG
.LG
.sp |2c
\fBMagic Tutorial #2: Basic Painting and Selection
.rm CH
.ds LH Magic Tutorial #2: Basic Painting and Selection
.ds RH \*(DY
.ds CF - % -
.sp 1c
.NL
\fIJohn Ousterhout\fR
.sp 1c
Computer Science Division
Electrical Engineering and Computer Sciences
University of California
Berkeley, CA  94720

\fI(Updated by others, too.)\fR

.SM
This tutorial corresponds to Magic version 6.


.DE
.SM
.LP
\fBTutorials to read first:\fR
.IP
Magic Tutorial #1: Getting Started
.DE
.LP
\fBCommands introduced in this tutorial:\fR
.IP
:box, :clockwise, :copy, :erase, :findbox :grid, :label,
:layers, :macro, :move, :paint, :redo, :save, :select,
:sideways, :undo, :upsidedown, :view, :what, :writeall, :zoom
.LP
\fBMacros introduced in this tutorial:\fR
.IP
a, A, c, d, ^D, e, E, g, G, q, Q, r, R, s, S, t, T, u, U, v, w, W, z, Z, 4
.br
.NL
.sp 1c
.NH 1
Cells and Paint
.PP
In Magic, a circuit layout is a hierarchical collection
of \fIcells\fR.  Each cell contains three things:
colored shapes, called \fIpaint\fR, that define the circuit's structure;
textual \fIlabels\fR attached to the paint;  and
\fIsubcells\fR, which are instances of other cells.  The paint
is what determines the eventual function of the VLSI circuit.  Labels
and subcells are a convenience for you in managing
the layout and provide a way of communicating information
between various synthesis and analysis tools.  This tutorial
explains how to create and edit paint and labels in simple
single-cell designs, using the basic painting commands.
``Magic Tutorial #3: Advanced Painting (Wiring and Plowing)''
describes some more advanced features for manipulating paint.
For information on how to build up cell
hierarchies, see ``Magic Tutorial #4:  Cell Hierarchies''.
.NH 1
Painting and Erasing
.PP
Enter Magic to edit the cell \fBtut2a\fR (type \fBmagic tut2a\fR
to the Unix shell;  follow the directions in ``Tutorial #1: Getting
Started'' if you have any problems with this).  The \fBtut2a\fR
cell is a sort of palette:  it shows a splotch of each of several
paint layers and gives the names that Magic uses for the layers.
.PP
The two basic layout operations are painting and erasing.  They
can be invoked using the \fB:paint\fR and \fB:erase\fR
long commands, or using the buttons.  The easiest way to paint
and erase is with the mouse buttons.  To paint, 
position the box over the area
you'd like to paint, then move the cursor over a color
and click the middle mouse button.  To erase
everything in an area, place the box over the area, move the
cursor over a blank spot, and click the middle mouse button.
Try painting and erasing various colors.  If the screen gets
totally messed up, you can always exit Magic and restart it.
While you're painting, white dots may occasionally appear
and disappear.  These are design rule violations detected
by Magic, and will be explained in ``Magic Tutorial #6: Design
Rule Checking''.  You can ignore them for now.
.PP
It's completely legal to paint one layer on top of another.
When this happens, one of three things may occur.  In some
cases, the layers are independent, so what you'll see is
a combination of the two, as if each were a transparent colored
foil.  This happens, for example, if you paint metal1 (blue) on
top of polysilicon (red).  In other cases, when you paint one
layer on top of another you'll get something different from
either of the two original layers.  For example, painting
poly on top of ndiff produces ntransistor (try
this).  In still other cases the
new layer replaces the old one:  this happens, for example,
if you paint a pcontact on top of ntransistor.
Try painting different layers on top of each other to see
what happens.  The meaning of the various layers is discussed
in more detail in Section 11 below.
.PP
There is a second way of erasing paint that allows you to
erase some layers without affecting others.  This is the
macro \fB^D\fR (control-D, for ``\fBD\fRelete paint'').  To use it,
position the box over the area to be erased, then move
the crosshair over a splotch of paint containing the
layer(s) you'd like to erase.  Type \fB^D\fR key on
the text keyboard: the colors underneath the cursor will
be erased from the area underneath the box, but no other
layers will be affected.  Experiment around with the \fB^D\fR
macro to try different combinations of paints and erases.
If the cursor is over empty space then the \fB^D\fR
macro is equivalent to the middle mouse button:  it erases
everything.
.PP
You can also paint and erase using the long commands
.DS C
\fB:paint \fIlayers\fR
\fB:erase \fIlayers\fR
.DE
In each of these commands \fIlayers\fR is one or more layer
names separated by commas (you can also use spaces for separators,
but only if you enclose the entire list in double-quotes).  Any
layer can be abbreviated as long as the abbreviation is
unambiguous.  For example, \fB:paint poly,metal1\fR will
paint the polysilicon and metal1 layers.  The macro \fB^D\fR
is predefined by Magic to be \fB:erase $\fR (\fB$\fR is a
pseudo-layer that means ``all layers underneath the cursor'').
.NH 1
Undo
.PP
There are probably going to be times when you'll do things that
you'll later wish you hadn't.  Fortunately, Magic has an
undo facility that you can use to restore things after you've
made mistakes.  The command
.DS C
\fB:undo\fR
.DE
(or, alternatively, the macro \fBu\fR) will undo the effects of
the last command you invoked.
If you made a mistake several commands back, you can type
\fB:undo\fR several times to undo successive commands.
However, there is a limit to all this:  Magic only remembers
how to undo the last ten or so commands.  If you
undo something and then decide you wanted it after all, you
can undo the undo with the command
.DS C
\fB:redo\fR
.DE
(\fBU\fR is a macro for this command).  Try making a few paints
and erases, then use \fB:undo\fR and \fB:redo\fR to work
backwards and forwards through the changes you made.
.NH 1
The Selection
.PP
Once you have painted a piece of layout, there are several commands
you can invoke to modify the layout.  Many of them are based on
the \fIselection\fR:  you select one or more pieces of the design,
and then perform operations such as copying, deletion, and rotation
on the selected things.
To see how the selection works, load cell \fBtut2b\fR.  You
can do this by typing \fB:load tut2b\fR if you're still in Magic,
or by starting up Magic with the shell command \fBmagic tut2b\fR.
.PP
The first thing to do is to learn how to select.
Move the cursor over the upper portion of the
L-shaped blue area in \fBtut2b\fR, and type \fBs\fR, which
is a macro for \fB:select\fR.  The box
will jump over to cover the vertical part of the ``L''.  This
operation selected a chunk of material.  Move the box away from
the chunk, and you'll see that a thin white outline is left
around the chunk to show that it's selected.  Now move the cursor
over the vertical red bar on the right of the cell and type \fBs\fR.
The box will move over that bar, and the selection highlighting will
disappear from the blue area.
.PP
If you type \fBs\fR several times without moving the cursor,
each command selects a slightly larger piece of material.  Move the
cursor back over the top of the blue ``L'', and type \fBs\fR three
times without moving the cursor.  The first \fBs\fR selects a
chunk (a rectangular region all of the same type of material).  The
second \fBs\fR selects a \fIregion\fR (all of the
blue material in the region underneath the cursor, rectangular or not).
The third \fBs\fR selects a \fInet\fR (all of the material that is
electrically connected to the original chunk; this includes the
blue metal, the red polysilicon, and the contact that connects them).
.PP
The macro \fBS\fR (short for \fB:select more\fR) is just like \fBs\fR
except that it adds on to the selection, rather than replacing it.
Move the cursor over the vertical red bar on the right
and type \fBS\fR to see how this works.  You can also type \fBS\fR
multiple times to add regions and nets to the selection.
.PP
If you accidentally type \fBs\fR or \fBS\fR when the cursor is
over space, you'll select a cell (\fBtut2b\fR in this case).
You can just undo this for now.  Cell selection will be discussed
in ``Magic Tutorial #4: Cell Hierarchies''.
.PP
You can also select material by area:  place the box
around the material you'd like to select and type \fBa\fR (short
for \fB:select area\fR).  This will select all of the material
underneath the box.
You can use the macro \fBA\fR to add material to the selection
by area, and you can use the long command
.DS C
\fB:select \fR[\fBmore\fR]\fB area \fIlayers\fR
.DE
to select only material on certain layers.  Place the box around
everything in \fBtut2b\fR and type \fB:select area metal1\fR
followed by \fB:select more area poly\fR.
.PP
If you'd like to clear out the selection without modifying any
of the selected material, you can use the command
.DS C
\fB:select clear\fR
.DE
or type the macro \fBC\fR.  You can clear out just a portion of
the selection by typing \fB:select less\fR or \fB:select less
area \fIlayers\fR; the former deselects paint in the order that
\fB:select\fR selects paint, while the latter deselects
paint under the box (just as \fB:select area\fR selects paint
under the box).
For a synopsis of all the options
to the \fB:select\fR command, type
.DS C
\fB:select help\fR
.DE


.NH 1
Operations on the Selection
.PP
Once you've made a selection, there are a number of operations you
can perform on it:
.DS C
\fB:delete\fR
\fB:move \fR[\fIdirection\fR [\fIdistance\fR]]
\fB:stretch \fR[\fIdirection\fR [\fIdistance\fR]]
\fB:copy\fR
\fB:upsidedown\fR
\fB:sideways\fR
\fB:clockwise \fR[\fIdegrees\fR]
.DE
The \fB:delete\fR command deletes everything that's selected.
Watch out:  \fB:delete\fR is different from \fB:erase\fR, which erases
paint from the area underneath the box.
Select the red bar on the right in \fBtut2b\fR and type \fBd\fR,
which is a macro for \fB:delete\fR.  Undo the deletion with the
\fBu\fR macro.
.PP
The \fB:move\fR command picks up both the box
and the selection and moves them so that the lower-left corner of
the box is at the cursor location.  Select the red bar on the right
and move it so that it falls on top of the vertical part of
the blue ``L''.  You can use \fBt\fR (``\fBt\fRranslate'') as a macro
for \fB:move\fR.  Practice moving various things around the screen.
The command \fB:copy\fR and its macro \fBc\fR are just like
\fB:move\fR except that a copy of the selection is left behind at
the original position.
.PP
There is also a longer form of the \fB:move\fR command that you
can use to move the selection a precise amount.  For example,
\fB:move up 10\fR will move the selection (and the box) up
10 units.  The
\fIdirection\fR argument can be any direction like \fBleft\fR,
\fBsouth\fR, \fBdown\fR, etc.  See the Magic manual page for
a complete list of the legal directions.   The macros \fBq\fR,
\fBw\fR, \fBe\fR, and \fBr\fR are defined to move the selection
left, down, up, and right (respectively) by one unit.
.PP
The \fB:stretch\fR command is similar to \fB:move\fR except that
it stretches and erases as it moves.  \fB:stretch\fR  does not
operate diagonally, so if you use the cursor to indicate where
to stretch to, Magic will either stretch up, down, left, or right,
whichever is closest.  The \fB:stretch\fR command moves the selection
and also does two additional things.  First, for each piece of paint
that moves, \fB:stretch\fR will erase that layer from the region that
the paint passes through as it moves, in order to clear material out
of its way.  Second, if the back edge of a piece of selected paint touches
non-selected material, one of the two pieces of paint is stretched to
maintain the connection.  The macros \fBQ\fR, \fBW\fR, \fBE\fR, and \fBR\fR
just like
the macros \fBq\fR, etc. described above for \fB:move\fR.  The macro
\fBT\fR is predefined to \fB:stretch\fR.
To see how stretching works, select the horizontal
piece of the green wire in \fBtut2b\fR and type \fBW\fR, then \fBE\fR.
Stretching only worries about material in front of and behind the
selection;  it ignores material to the sides (try the \fBQ\fR and \fBR\fR
macros to see).  You can use plowing (described in Tutorial #3) if this is a
problem.
.PP
The command \fB:upsidedown\fR will flip the selection upside
down, and \fB:sideways\fR flips the selection sideways.  Both
commands leave the selection so it occupies the same total area
as before, but with the contents flipped.  The command
\fB:clockwise\fR will rotate the selection clockwise, leaving the
lower-left corner of the new selection at the same place as the
lower-left corner of the old selection.  \fIDegrees\fR
must be a multiple of 90, and defaults to 90.
.PP
At this point you know enough to do quite a bit of damage
to the \fBtut2b\fR cell.  Experiment with the selection
commands.  Remember that you can use \fB:undo\fR to back
out of trouble.

.NH 1
Labels
.PP
Labels are pieces of text attached to the paint of a cell.
They are used to provide information to other tools that will
process the circuit.  Most labels are node names: they provide
an easy way of referring to nodes in tools such as routers, simulators,
and timing analyzers.  Labels may also be used for other purposes:
for example, some labels are treated as \fIattributes\fR that
give Crystal, the timing analyzer, information about the
direction of signal flow through transistors.
.PP
Load the cell \fBtut2c\fR and place a cross in the middle of
the red chunk (to make a cross, position the lower-left corner
of the box with the left button and then click the right button
to place the upper-right corner on top of the lower-left corner).
Then type
type the command \fB:label test\fR.  A new label will appear
at the position of the box.  The complete syntax of the \fB:label\fR
command is
.DS C
\fB:label \fR[\fItext \fR[\fIposition \fR[\fIlayer\fR]]]
.DE
\fIText\fR must be supplied, but the other arguments can be
defaulted.  If \fItext\fR has any spaces in it, then it must
be enclosed in double quotes.  \fIPosition\fR tells where
the text should be displayed, relative to the point of the
label.  It may be any of \fBnorth\fR, \fBsouth\fR, \fBeast\fR,
\fBwest\fR, \fBtop\fB, \fBbottom\fR, \fBleft\fR, \fBright\fR,
\fBup\fR, \fBdown\fR, \fBcenter\fR, \fBnortheast\fR, \fBne\fR,
\fBsoutheast\fR, \fBse\fR, \fBsouthwest\fR, \fBsw\fR, \fBnorthwest\fR,
\fBnw\fR.  For example,
if \fBne\fR is given, the text will be displayed above and to
the right of the label point.  If no \fIposition\fR is given,
Magic will pick a position for you.  \fILayer\fR tells which paint
layer to attach the label to.  If \fIlayer\fR covers the entire
area of the label, then the label will be associated with the
particular layer.  If \fIlayer\fR is omitted, or if it doesn't
cover the label's area, Magic initially associates the label with
the ``space'' layer, then checks to see if there's a layer that covers the
whole area.  If there is, Magic moves the label to that layer.
It is generally a bad idea to place labels
at points where there are several paint layers, since it will
be hard to tell which layer the label is attached to.
As you edit, Magic will ensure that labels are only
attached to layers that exist everywhere under the label.
To see how this works,
paint the layer pdiff (brown) over the label you just
created:  the label will
switch layers.  Finally, erase poly over the area, and
the label will move again.
.PP
Although many labels are point labels, this need not be the case.
You can label any rectangular area by setting the box to that
area before invoking the label command.  This feature is used for
labelling terminals for the router (see below), and for labelling tiles used
by Mpack, the tile packing program.  \fBTut2c\fR has examples of
point, line, and rectangular labels.
.PP
All of the selection commands apply to labels as well as paint.
Whenever you select paint, the labels attached to that paint
will also be selected.  Selected labels are highlighted in white.
Select some of the chunks of paint in \fBtut2c\fR
to see how the labels are selected too.  When you use
area selection, labels will only be selected if they are completely
contained in the area being selected.  If you'd like to select
\fIjust\fR a label without any paint, make the box into a cross
and put the cross on the label:  \fBs\fR and \fBS\fR will select
just the label.
.PP
There are several ways to erase a label.  One way is to select and then
delete it.  Another way is to erase the paint that the label is attached
to.  If the paint is erased all around the label, then Magic will delete
the label too.  Try attaching a
label to a red area, then paint blue over the red.
If you erase blue the label stays (since it's attached
to red), but if you erase the red then the label is deleted.
.PP
You can also erase labels using the \fB:erase\fR command
and the pseudo-layer \fBlabels\fR.  The command
.DS C
\fB:erase labels\fR
.DE
will erase all labels that lie completely within the area of the box.
Finally, you can erase a label by making
the box into a cross on top of the label, then clicking the middle
button with the cursor over empty space.  Technically, this will
erase all paint layers and labels too.  However, since the
box has zero area, erasing paint has no effect:  only the labels
are erased.

.NH 1
Labelling Conventions
.PP
When creating labels, Magic will permit you
to use absolutely any text whatsoever.  However, many
other tools, and even parts of Magic, expect label names
to observe certain conventions.  Except for the special cases
described below, labels shouldn't contain any of the characters
``/$@!^''.  Spaces, control characters, or parentheses
within labels are probably a bad idea too.
Many of the programs that process Magic output
have their own restrictions on label names, so you should
find out about the restrictions that apply at your site.
Most labels are node
names: each one gives a unique identification to a set of things that
are electrically connected.  There are two kinds of node
names, local and global.  Any label that ends in ``!''
is treated as a global node name;  it will be assumed
that all nodes by this name, anywere in any cell in a layout, are
electrically connected.  The most common global names are
\fBVdd!\fR and \fBGND!\fR, the power rails.  You should
always use these names exactly, since many other tools
require them.  Nobody knows why ``GND!'' is all in capital letters
and ``Vdd!'' isn't.
.PP
Any label that does not end in ``!'' or any of the other
special characters discussed below is a local node name.
It refers to a node within that particular cell.  Local
node names should be unique within the cell: there shouldn't
be two electrically distinct nodes with the same name.
On the other hand, it is perfectly legal, and sometimes
advantageous, to give more than one name to the same node.
It is also legal to use the same local node name in different
cells:  the tools will be able to distinguish between them
and will not assume that they are electrically connected.
.PP
The only other labels currently understood by the tools
are \fIattributes\fR.  Attributes are pieces of text associated
with a particular piece of the circuit:  they are not node
names, and need not be unique.  For example, an attribute
might identify a node as a chip input, or it might identify
a transistor terminal
as the source of information for that transistor.  Any label
whose last character is ``@'', ``$'', or ``^''  is an attribute.  There
are three different kinds of attributes.  Node attributes are
those ending with ``@'';  they are associated with particular
nodes.  Transistor source/drain attributes are those ending in ``$'';
they are associated with particular terminals of a transistor.
A source or drain attribute must be attached to the channel region
of the transistor and must fall exactly on the source or drain
edge of the transistor.  The third kind of attribute is a
transistor gate attribute.  It ends in ``^'' and is attached to
the channel region of the transistor.
To see examples of attributes and node names, edit the cell
\fBtut2d\fR in Magic.
.PP
Special conventions apply to labels for routing terminals.  The standard
Magic router (invoked by \fB:route\fR)
ignores all labels except for those on the edges of cells.  (This restriction
does not apply to the gate-array router, Garoute, or to the interactive
router, Iroute).  If you expect to use the 
standard router to connect to a particular node,
you should place the label for that node on its outermost edge.
The label should not be a point label, but should instead be
a horizontal or vertical line covering the entire edge of the
wire.  The router will choose a connection point somewhere
along the label.
A good rule of thumb is to label all nodes that enter or leave
the cell in this way.  For more details on how labels are used
by the standard router, see ``Magic Tutorial #7:  Netlists and Routing''.  
Other labeling conventions are used by the Garouter and Irouter, consult
their respective tutorials for details.
.NH 1
Files and Formats
.PP
Magic provides a variety of ways to save your cells on
disk.  Normally, things are saved in a special
Magic format.  Each
cell is a separate file, and the name of the file is
just the name of the cell with \fB.mag\fR appended.  For
example, the cell \fBtut2a\fR is saved in file
\fBtut2a.mag\fR.  To save cells on disk, invoke the
command
.DS C
\fB:writeall\fR
.DE
This command will run through each of the cells that you have
modified in this editing session, and ask you what to do with
the cell.  Normally, you'll type \fBwrite\fR, or just hit the
return key, in which case the cell will be written back
to the disk file from which it was read (if this is a new cell,
then you'll be asked for a name for the cell).  If you type
\fBautowrite\fR, then Magic will write out all the cells that have
changed without asking you what to do on a cell-by-cell basis.
\fBFlush\fR will cause Magic to delete its internal copy of the cell
and reload the cell from the disk copy, thereby expunging all edits
that you've made.  \fBSkip\fR will pass on to the next cell without
writing this cell (but Magic still remembers that it has
changed, so the next time you invoke \fB:writeall\fR Magic
will ask about this cell again).  \fBAbort\fR will stop
the command immediately without writing or checking any more cells.
.PP
\fBIMPORTANT NOTE:\fR  Unlike vi and other text editors, Magic
doesn't keep checkpoint files.  This means that if the system
should crash in the middle of a session, you'll lose all changes
since the last time you wrote out cells.  It's a good idea to
save your cells frequently during long editing sessions.
.PP
You can also save the cell you're currently editing with the command
.DS C
\fB:save \fIname\fR
.DE
This command will append ``.mag'' to \fIname\fR and save the cell you
are editing in that location.  If you don't provide a
name, Magic will use the cell's name (plus the ``.mag''
extension) as the file name, and it will prompt you for
a name if the cell hasn't yet been named.
.PP
Once a cell has been saved on disk you can edit it by
invoking Magic with the command
.DS C
\fBmagic \fIname\fR
.DE
where \fIname\fR is the same name you used to save the
cell (no ``.mag'' extension).
.PP
Magic can also read and write files in CIF and Calma Stream formats.
See ``Magic Tutorial #9: Format Conversion for CIF and Calma''
for details.

.NH 1
Plotting
.PP
Magic can generate hardcopy plots of layouts in four ways: versatec 
(black-and-white or color), gremlin and pixels (a generalized pixel-file that can be massaged in many ways).  The first style
is for printers like the black-and-white Versatec family: for these,
Magic will output a raster file and spool the file for printing.  To
plot part of your design, place the box around the part you'd like
to plot and type
.DS C
\fB:plot versatec \fR[\fIwidth\fR [\fIlayers\fR]]
.DE
This will generate a plot of the area of the box.  Everything
visible underneath the box will appear in more-or-less the same way
in the plot.  \fIWidth\fR specifies how wide the plot will be, in
inches.  Magic will scale the plot so that the area of the box comes
out this wide.  The default for \fIwidth\fR is the width of the
plotter (if \fIwidth\fR is larger than the plotter width, it's
reduced to the plotter width).  If \fIlayers\fR is given, it
specifies exactly what information is to be plotted.  Only those
layers will appear in the plot.  The special ``layer'' \fBlabels\fR
will enable label plotting.
.PP
The second form is for driving printers like color Versatecs.
It  is enabled by setting the \fIcolor\fR plot parameter to
\fItrue\fR.  A table of stipples for the primary colors (black, cyan,
magenta abd yellow) is given in the technology file.  When the
\fIplot\fR command is given, four rasters (one for each of the colors)
are generated, separated with the proper control sequences for the printer.
Otherwise, operation is exactly as for the black-and-white case.
.PP
The third form of plotting is for generating Gremlin-format files,
which can then be edited with the Gremlin drawing system or
included in documents processed by Grn and Ditroff.  The command
to get Gremlin files is
.DS C
\fB:plot gremlin \fIfile \fR[\fIlayers\fR]
.DE
It will generate a Gremlin-format file in \fIfile\fR that describes
everything underneath the box.  If \fIlayers\fR is specified, it
indicates which layers are to appear in the file;  otherwise everything
visible on the screen is output.  The Gremlin file is output without
any particular scale;  use the \fBwidth\fR or \fBheight\fR commands
in Grn to scale the plot when it's printed.  You should use the \fBmg\fR
stipples when printing Magic Gremlin plots;  these will produce the
same stipple patterns as \fB:plot versatec\fR.
.PP
Finally, the ``pixels'' style of plotting generates a file of pixel
values for the region to be plotted.  This can be useful for input to
other image tools, or for generation of slides and viewgraphs for
presentations.  The file consists of a sequence of bytes, three for
each pixel, written from left to right and top to bottom.  Each three
bytes represent the red, green and blue values used to display the
pixel.  Thus, if the upper-left-most pixel were to be red, the first
three bytes of the file would have values of 255, 0 and 0.
.PP
The resolution of the generated file is normally 512, but can be
controlled by setting the plot parameter \fIpixWidth\fR.  It must be a
multiple of 8; Magic will round up if an inappropriate value is
entered.
The height
of the file is determined by the shape of the box.  In any case, the
actual resolution of the file is appended to the file name.  For
example, plotting a square region,  2048 pixels across, will result in
a file named something like ``magicPlot1234a-2048-2048''.
.PP
There are several plotting parameters used internally to Magic, such
as the width of the Versatec printer and the number of dots per inch
on the Versatec printer.  You can modify most of these to work with
different printers.  For details, read about the various \fB:plot\fR
command options in the \fIman\fR page.

.NH 1
Utility Commands
.PP
There are several additional commands that you will probably find useful
once you start working on real cells.  The command
.DS C
\fB:grid \fR[\fIspacing\fR]
\fB:grid \fIxSpacing ySpacing\fR
\fB:grid \fIxSpacing ySpacing xOrigin yOrigin\fR
\fB:grid off\fR
.DE
will display a grid over your layout.  Initially, the grid has
a one-unit spacing.  Typing \fB:grid\fR with no arguments
will toggle the grid on and off.
If a single numerical argument is given, the grid
will be turned on, and the grid lines will be \fIspacing\fR
units apart.  The
macro \fBg\fR provides a short form for \fB:grid\fR and \fBG\fR
is short for \fB:grid 2\fR.  If you provide two arguments to
\fB:grid\fR, they are the x- and y-spacings, which may be different.
If you provide four arguments, the last two specify a reference
point through which horizontal and vertical grid lines pass;  the
default is to use (0,0) as the grid origin.  The command \fB:grid off\fR
always turns the grid off, regardless of whether or not is was
previously on.
When the grid is on, a small black box is displayed to mark the
(0,0) coordinate of the cell you're editing.
.PP
If you want to create a cell that doesn't fit on the screen,
you'll need to know how to change the screen view.  This
can be done with three commands:
.DS C
\fB:zoom \fIfactor\fR
\fB:findbox \fR[\fBzoom\fR]
\fB:view\fR
.DE
If \fIfactor\fR is given to the zoom command, 
it is a zoom-out factor.  For example,
the command \fB:zoom 2\fR will change the view so that there are
twice as many units across the screen as there used to be (\fBZ\fR
is a macro for this).  The
new view will have the same center as the old one.  The command
\fB:zoom .5\fR will increase the magnification so that
only half as much of the circuit is visible.
.PP
The \fB:findbox\fR command is used to change the view according to the box.
The command alone just moves the view (without changing the scale
factor) so that the box is in the center of the screen.  If the \fBzoom\fR
argument is given then the magnification is changed too, so that the area of
the box nearly fills the screen.  \fBz\fR is a macro for \fB:findbox zoom\fR
and \fBB\fR is a macro for \fB:findbox\fR.
.PP
The command \fB:view\fR resets the view so that the entire cell is visible
in the window.  It comes in handy if you get lost in a big layout.
The macro \fBv\fR is equivalent to \fB:view\fR.
.PP
The command \fB:box\fR prints out the size and location of the box
in case you'd like to measure something in your layout.  The macro
\fBb\fR is predefined to \fB:box\fR.  The \fB:box\fR command can also
be used to set the box to a particular location, height, or
width.  See the man page for details.
.PP
The command
.DS C
\fB:what\fR
.DE
will print out information about what's selected.  This may be helpful
if you're not sure what layer a particular piece of material is, or
what layer a particular label is attached to.
.PP
If you forget what a macro means, you can invoke the command
.DS C
\fB:macro \fR[\fIchar\fR]
.DE
This command will print out the long command that's associated
with the macro \fIchar\fR.  If you omit \fIchar\fR, Magic will
print out all of the macro associations.  The command
.DS C
\fB:macro \fIchar command\fR
.DE
We set up \fIchar\fR to be a macro for \fIcommand\fR, replacing the old
\fIchar\fR macro if there was one.  If \fIcommand\fR contains any spaces
then it must be enclosed in double-quotes.  To see how this works, type
the command \fB:macro 1 "echo You just typed the 1 key."\fR, then type
the 1 key.
.PP
One of the macros, ``\fB.\fR'', has special meaning in Magic.  This
macro is always defined by the system to be the last long command
you typed.  Whenever you'd like to repeat a long command, all you
have to do is use the dot macro.

.NH 1
What the Layers Mean
.PP
The paint layers available in Magic are different from those
that you may be used to in Caesar and other systems because
they don't correspond
exactly to the masks used in fabrication.  We call them
\fIabstract layers\fR because they correspond to constructs
such as wires and contacts, rather than mask layers.  We
also call them \fIlogs\fR because they look like sticks
except that the geometry is drawn fully fleshed instead of
as lines. In Magic there
is one paint layer for each kind of conducting material
(polysilicon, ndiffusion, metal1, etc.),
plus one additional paint layer for each kind of transistor
(ntransistor, ptransistor, etc.), and, finally, one further
paint layer for each kind of contact (pcontact, ndcontact,
m2contact, etc.) Each
layer has one or more names that are
used to refer to that layer in commands.  To find out the
layers available in the current technology, type the command
.DS C
\fB:layers\fR
.DE
In addition to the mask layers, there are a few pseudo-layers
that are valid in all technologies;  these are listed in
Table I.
Each Magic technology also has a technology manual describing
the features of that technology, such as design rules, routing
layers, CIF styles, etc.  If you haven't seen any of the technology
manuals yet, this is a good time to take a look at the one for
your process.
.KF
.TS
center box;
l.
\fBerrors\fR (design-rule violations)
\fBlabels\fR
\fBsubcells\fR
\fB*\fR (all mask layers)
\fB$\fR (all mask layers visible under cursor)
.TE
.(C
\fBTable I.\fR  Pseudo-layers available in all technologies.
.)C
.KE
.PP
If you're used to designing with mask layers (e.g. you've
been reading the Mead-Conway book), Magic's log style
will take some getting used to.
One of the reasons for logs is to
save you work.  In Magic you don't draw implants, wells, buried
windows, or contact via holes.  Instead, you draw the primary
conducting layers and paint some of their overlaps with
special types such as n-transistor or polysilicon contact.
For transistors, you draw only the
actual area of the transistor channel.  Magic will generate
the polysilicon and diffusion, plus any
necessary implants, when it creates a CIF file.  For contacts,
you paint the contact layer in the area of overlap between
the conducting layers.  Magic
will generate each of the constituent mask layers plus
vias and buried windows when it writes the CIF file.  Figure 1
shows a simple cell drawn with both mask layers (as in Caesar)
and with logs (as in Magic).  If you're curious about what
the masks will look like for a particular layout, you can use
the \fB:cif see\fR command to view the mask information.
.KS
.GS C
width 5.0i
thick 9
file tut2.1.g
.GE
.(C
\fBFigure 1.\fR  An example of how the logs are
used.  The figure on the left shows actual mask layers for an
CMOS inverter cell, and the figure on the right shows the
layers used to represent the cell in Magic.
.)C
.KE
.PP
An advantage of the logs used in Magic is
that they simplify the design rules.  Most of the formation
rules (e.g. contact structure) go away, since Magic automatically
generates correctly-formed structures when it writes CIF.
All that are left are minimum size and spacing rules, and
Magic's abstract layers result in fewer of these than there
would be otherwise.  This helps to make Magic's built-in
design rule checker very fast (see ``Magic Tutorial #6:
Design Rule Checking''), and is one of the reasons
plowing is possible.
