$D.var pageno=1
$D.var Pic=0
$D.var NewChap,YTrap,PicH,TexH
$D.var(40) ChapTitle=''
$D.var(40) PicTitle=''

$D.format OddEven
=$y0.05"
=$Q(pageno&1) $x0.6" $10[$ChapTitle] $x2" $list12[$v(pageno)]$x>7.7"
=$Q(pageno&1) $O(0.6",0.4",7.4",10.5")[]
=$Q(1-pageno&1) $X0.2"$list12[$v(pageno)]$x1"
=$Q(1-pageno&1) $10[Microprogramming Exercise]$x>7.3"
=$Q(1-pageno&1) $O(0.2",0.4",7.2",10.5")[]
=$Q(1-pageno&1)$X0.2" $Y0.20" $G i3e7.1"
=$Q(pageno&1) $X0.6" $Y0.20" $G i3e7.1"
=$pageno=pageno+1
=$C
=$OddEven

$D.format dualcol
=$TexH=10.5"
=$Q(NewChap) $b1 $u(0.02",0.08")$17[$ChapTitle $ $ ] $NewChap=0 $TexH=TexH-1"
=$O(0   ,10.5"-TexH,3.4",TexH)[]
=$Q(Pic) $X0 $Y(10.5"-TexH+YTrap+0.1") $G i4e7.1"s(PicH)w7.1"n(PicH)
=$Q(Pic) $Y(10.5"-TexH+YTrap+PicH-0.1") $10[$PicTitle] $b^0
=$Q(Pic) $O(3.7",10.5"-TexH,3.4",Ytrap)[]
=$Q(Pic) $O(0,10.5"-TexH+Ytrap+PicH+0.2",3.4",TexH-Ytrap-PicH-0.2")[]
=$Q(Pic) $O(3.7",10.5"-TexH+Ytrap+PicH+0.2",3.4",TexH-Ytrap+PicH-0.2")[]
=$Q(1-Pic) $O(3.7",10.5"-TexH,3.4",TexH)[]
=$Pic=0
=$C
=$dualcol

$D pages
=$OddEven
=$dualcol

$D picture(title,height)
=$Ytrap=Y $Pic=1 $PicTitle='$title' $PicH=$height $C
$D chapter(title)
=$NewChap=1 $ChapTitle='$title' $C.OddEven
$D section(title)
=$b2,1" $14$u[$title] $b0.5
$D item='$k183 $x*+0.1"'

$J1 $Times12
$T=0.25",0.5",0.75",1",1.25",1.5",1.75",2",2.5",3",3.5",4",4.5",5",5.3"
$pageno=10

$pages
$Chapter'Graphics Interpreter: Specification'
$Section'Arguments and data structures'
$b2
$item[All pointers are 32-bit integers, interpreted as absolute 
byte addresses in the machine address space.
]$b0.5
$item[Additive/subtractive arguments are represented as 16-bit 2's 
complement integers.
]$b0.5
$item[Scaling factors are signed 16-bit numbers with
binary point between bits 7 and 8 of the word.
]$b0.5
$p0.5
There are a number of data structures that can appear as arguments in the
nodes.
$b1
pixelmap $t*3[is represented by 2 16-bit words specifying the width and the
height of the map, followed by the map itelf, stored as width-long
sequence of 1 pixel-wide vertical lines; one byte per pixel.
Following the increasing addresses
of the representation pixels will be drawn on the screen from bottom upwards, 
with consecutive vertical lines appearing to the right of their predecessors.
]
$b1
template $t*3[consists of a 4 half-words header followed by
the bitmap of the template.
The half-words 0 and 1 contain template offsets in X and Y from the current 
working coordinates and half-words 2 and 3 specify width and height
of the template. 
Offsets are primarily used for positioning templates of the
characters relatively to the baseline and the in-line horizontal positioning
coordinate. They will be usually 0 for non-character type templates.
The template itself is stored as 
(width/16 + 1)-long sequence of height-long vertical strips. Following the
increasing addresses in the representation, individual strips will be drawn
on the screen from bottom upwards, with most significant bits on the left.
Consecutive strips are placed to the right of their predecessors.
]
$b1
font $t*3[is stored as a list of templates for individual characters.
Such list of templates is preceeded by an
array indexed by the codes of characters and containing pairs of short
integers.
The first integer in each pair
contains offset from the base of array to the template of the corresponding
character and the second contains the formatting width of the character.
Entries of 0 in the first element of the pair indicate characters for which
templates have not been defined in that particular font and their
occurence is used by the protocol as one of termination conditions 
when drawing character strings.
Width of the character represents the distance to the base of the
next character to the right.
]
$b1
arrays $t*3[are always 1-dimensional short-integer arrays, with the
lowest element having index 0.
]
$Section'Evaluation environment'
$p0.5
Each node is executed within the environment inherited from the previous node,
and it may modify this environment prior to passing it to the next nodes: down, to
the right or up.
$p0.5
The environment consists of:
$b0.5 currink $x+0.1" current colour for the subordinate drawing nodes
$b0.5 currplan $x+0.1" a mask of planes with enabled write operation for the 
subordinate drawing nodes
$b0.5 (workX,workY) $x+0.1" a pair of current working coordinates
$b0.5 (bblX,bbbY) $x+0.1" left-hand bottom corner of the image bounding box
$b0.5 (bbrX,bbtY) $x+0.1" right-hand top corner of the image bounding box
$b0.5 (cblX,cbbY) $x+0.1" left-hand bottom corner of the environmental clipping
box
$b0.5 (cbrX,cbtY) $x+0.1" right-hand top corner of the environmental clipping box.
Clip boundaries are the intersection of all the clipping boundaries set by
the clipping nodes above the current position. Deferred scaling node
maps them (division) into the virtual coordinates of the subordinate image.
$b0.5 (dscaleX,dscaleY) $x+0.1" A deferred scaling 
factor provided to support virtual to physical coordinate transformation. 
Deferred factor is applied to the coordinates and arguments in drawing
nodes, thus alowing the construction of the image above them to be expressed
in the virtual design coordinates.
Deferred scaling factor applies immediately only to the inherited
clipping coordinates, where reverse scaling of environmental coordinate 
information allows to implement physical clipping of images expressed in virtual
coordinates. Clipping in virtual coordinates is achieved through
positioning deferred scaling node above the clipping nodes.
$b0.5 iteration $x+0.1" factor which must be greater then 0 for the interpreter
to follow the vertical exit edge from the node.
$b0.5 currfont $x+0.1" pointer indicates the base of the current font to be
used in all the subordinate string drawing operations.
$b0.5 currargarray $x+0.1" points to a one-dimensional array of shortwords
which can be used as arguments in the subordinate graph.
Entering the same subgraph with different array of arguments, is similar
to the passing of arguments to a drawing procedure.
Such subgraph should contain appropriate index flags set
for the nodes to which such arguments are
to be passed and appropriate array indexing information in its argument fields.
$b0.5 currcursor $x+0.1" points to a graph
currently responsible for drawing of cursors. Nodes of such graph
will be usually designed to pick up arguments from the environment
which invoked the graph.
$b0.5 reportaddr $x+0.1" address in user processor address space for
inter-processor communication
$b0.5 (refX,refY) $x+0.1" current (0,0) reference point for nodes using absolute
positioning coordinates.
$section'Summary of node format'
$b1
Byte 0 of half-word 0 contains the instruction code.
$b1
Byte 1 contains flags, part of which parameterize the execution of
the instruction or of its subordinate subgraph.
Flags (Optimise, Wait, Pointer, IndexA, IndexB, Cursor, Down, Right)
correspond to bits [7:0] of the byte.
$b1
Optimise $t*3[flag invokes optimised evaluation of the subordinate graph,
where the interpreter will follow only those vertical edges, where
the bounding box of the image is expected to intersect with the current 
clipping box.
Such evaluation, although fairly simple to maintain at the top level nodes
e.g. with multiwindow textual displays becomes more complicated for
more sophisticated structures and may require significant monitoring of
differential changes in the graph.
]$b0.5
Wait $t*3[when 1 forces the interpreter to execute a partial completion
sequence and halt immediately after executing the return phase of the node.
]$b0.5
Pointer $t*3[flag when 0 indicates that arguments are stored immediately
in the instruction starting with halfwords 2 and 3.
For Pointer=1 halfwords 2 and 3 form a 32-bit argument pointer.
]$b0.5
IndexA $t*3[flag when 0 indicates that argument A is directly accessible
immediately or through a pointer, depending on the Pointer flag.
IndexA=1 signals that the value obtained through such access
is the argument index in the current argument array 
(See the description of individual nodes for
the declaration of the current argument array). 
]$b0.5
IndexB $t*3[has the same function as IndexA but applies to argument B.
]$b0.5
Cursor $t*3[flag set to 1 results in temporary replacement of the
current argument array pointer with a pointer to the bounding box
coordinates of the node, followed by a call to the
current cursor drawing graph.
]$b0.5
Down $t*3[flag indicates that half-words 7 and 8 contain a valid pointer
to the first instruction of a chain in the subordinate subgraph.
For Down=0 the interpreter will execute return phase of the instruction
without entering the evaluation of the subordinate graph.
Down=1 will be ignored for the iteration index in the current environment
being 0.
]$b0.5
Right $t*3[indicates that half-words 9 and 10 contain a valid pointer
to the next of horizontally linked chain of instructions. 
Upon encountering Right=0
the interpreter will execute the "return" part of the instruction
which invoked the currently terminated chain. Right=0 encountered at
the level at which the evaluation was invoked will terminate the evaluation.
The flag can be used for temporary disabling of manipulated parts of the 
picture. When modelling execution of a command stream
the Right=0 marks the last instruction of the stream.
]$p0.5
Half-words 1 and 2 contain information about the arguments for the node,
subject to interpretation under flags Pointer and Index.
$p0.5
The node contains also the information about the bounding box of the
subordinate picture.
This information, depending on the invoked mode of evaluation can be:
$b0.5
$item[updated by the evaluation process through the evaluation of the
subgraph
]
$b0.5
$item[used by the evaluation process during the optimised evaluation
where subordinate images with bounding boxes outside the clipping 
coordinates are not evaluated.
]
$b0.5
Bounding box coordinates relative to the current working (X,Y) coordinates
of the interpreter are stored in half-words 3-6. Half-words (3,4) and
(5,6) contain (X,Y) coordinates of left-hand bottom and right-hand top
corners of the box.
$section'Nodes of the graphics data structure'
$b0.5
In the following descriptions arguments
of operation are shown in $i[italics] and represent values
obtained from half-words 1 and 2 through appropriate interpretation of
flags Pointer and Index. OpCodes are given in hex.
$b2
$h[Non-drawing, environment modification nodes]
$b0.5
$h[SetFont]($i[fontbase])
$b0
The subordinate graph will use the font starting at $i[fontbase].
$b0.5
$h[SetInk]($i[colour]) $x1" $list12[OpC: 01] $b>0
$i[colour] becomes the colour for all the subordinate drawing operations.
$b0.5
$h[SetPmask]($i[mask]) $x1" $list12[OpC: 02] $b>0
Planes indicated by 1's in $i[mask] will be enabled for writing in the
subordinate graph.
$b0.5
$h[SetCursor]($i[cursorpointer]) $x1" $list12[OpC: 03] $b>0
$i[cursorpointer] points the top node of the cursor drawing structure
for the subordinate nodes.
$b0.5
$h[SetArguments]($i[arraypointer]) $x1" $list12[OpC: 04] $b>0
$i[arraypointer] points to the first element (indexed 0) of the argument array
for the subordinate nodes
$b0.5
$h[SetClip]($i[sizeX,sizeY]) $x1" $list12[OpC: 05] $b>0
Clipping in a rectangle of size ($i[sizeX,sizeY]), starting from the
current position. As an environmental attribute subject to retrospective
inverse scaling by the deferred scaling node.
$b0.5
$h[SetRefPoint]($i[refX,refY]) $x1" $list12[OpC: 12] $b>0
Current X and Y coordinates modified by $i[refX] and $i[refY] become
a reference (0,0) point for the absolute (X,Y) arguments used by the
subordinate nodes.
$b0.5
$h[Move]($i[modX,modY]) $x1" $list12[OpC: 06] $b>0
Current X and Y coordinates are modified by $i[modX] and $i[modY] 
respectively. $i[modX,modY] may have to be prescaled by the current
immediate scaling factors.
$b0.5
$h[MoveTo]($i[absX,absY]) $x1" $list12[OpC: 13] $b>0
Current X and Y coordinates are moved to $i[absX,absY] relative to the
current reference point.
$b0.5
$h[SetDScale]($i[factorX,factorY]) $x1" $list12[OpC: 07] $b>0
Declaration of deferred scaling. Excludes presence of any other scaling
nodes in any of the vertical paths containing this node.
$b0.5
$h[SetIteration]($i[iteration]) $x1" $list12[OpC: 08] $b>0
Declares iteration index $i[iteration] for the subordinate picture.
During execution flag "Down" is ignored if iteration index in the
environment is 0.
$b0.5
$h[DecIteration] $x1" $list12[OpC: 09] $b>0
Decrements iteration index in the environment.
$b1
$h[Drawing nodes]
$p0.5
Drawing nodes are responsible for the final drawing operations.
In most applications they will appear as leaf nodes (flag Down=0) and
the evaluation will subsequently move to the next horizontally linked node or
to the return phase of the node above.
$b0.5
$h[DrawBox]($i[Xsize,Ysize]) $x1" $list12[OpC: 00] $b>0
Fills with current colour a box of size ($i[Xsize,Ysize]), starting at current 
evaluation coordinates. Evaluation coordinates for X and Y are modified
by $i[Xsize] and $i[Ysize] respectively.
($i[Xsize,Ysize]) are subject to scaling by the cummulated immediate or by
the deferred scaling factors.
$b0.5
$h[BoxTo]($i[absX,absY]) $x1" $list12[OpC: 14] $b>0
Similar to $h[DrawBox] but the fill area is defined by its corners: one in
current evaluation coordinates and the other ($i[absX,absY]) away from
the current reference point.
$b0.5
$h[Polygon]($i[argumentlist]) $x1" $list12[OpC: XX] $b>0
Fills with current colour a polygon starting at current evaluation
coordinates and outlined by consecutive relative movements specified in
in $i[argumentlist].
$b0.5
$h[DrawLine]($i[Xsize,Ysize]) $x1" $list12[OpC: 0E] $b>0
Draws a straigh line from the current evaluation coordinates to a point
distant by ($i[Xsize,Ysize]).
$b0.5
$h[LineTo]($i[absX,absY]) $x1" $list12[OpC: 15] $b>0
$b0.5
$h[PutTemplate]($i[template]) $x1" $list12[OpC: 11] $b>0
A pattern defined by the template is filled with current colour at the
current evaluation coordinates. 
$b0.5
$h[Pixelmap]($i[pixelmap]) $x1" $list12[OpC: XX] $b>0
$h[String]($i[stringpointer]) $x1" $list12[OpC: XX] $b>0
Draws in current colour and with current font a string of characters.
Interpretation continues up to a character defined as a terminator by
the selected font.
$b0.5
$h[PutVString]($i[stringpointer]) $x1" $list12[OpC: 10] $b>0
$h[PutBString]($i[stringpointer]) $x1" $list12[OpC: 0E] $b>0
Draw strings of characters using fonts from VISUAL200 and Perkin Elmer
terminals.
$b1
$h[Control nodes]
$b0.5
$h[FlyBackY] $x1" $list12[OpC: 0A] $b>0
Withholds execution of the following instruction till the beginning of the
nearest framestore vertical flyback. Most of the following instructions 
require such synchronization.
$b0.5
$h[CmapLoad]($i[colourmappointer]) $x1" $list12[OpC: 16] $b>0
Consecutive locations of the framestore colourmap are loaded with the
consecutive store values starting at $i[colourmappointer]. 
8-bit intensities for  red, green and blue
are represented by bits [7:0], [15:8] and [23:16] of 
consecutive 32-bit words.
$b0.5
$h[SetXY]($i[Xoffset,Yoffset]) $x1" $list12[OpC: 0B] $b>0
Explicitly sets $h[X] and $h[Y] evaluation coordinates.
Intended for support of dual-buffering scheme with two such nodes
used alternately as entry points to the structure.
$b0.5
$h[Pan]($i[Xoffset,Yoffset]) $x1" $list12[OpC: 0C] $b>0
Left-hand bottom corner of the display will is placed at 
(($i[Xoffset]/16)*16,$12(Yoffset)) in the framestore. Can be used with
$h[SetXY] and $h[FlyBackY] to implement dual-buffering.
$b0.5
$h[DepositEnv]($i[environmentpointer]) $x1" $list12[OpC: XX] $b>0
This node deposits at the location indicated by the [environmentpointer]
the contents of its current working environment.
$b0.5
$h[PickUpEnv]($i[environmentpointer]) $x1" $list12[OpC: XX] $b>0
Partial evaluation of the structure starting from a chosen node
may be invoked through setting up the working environment to that of
the current environment of the node from the previous full evaluation.
$i[environmentpointer] will be usually the same as in $h[DepositEnv]
node which should preceed the chosen entry node in the structure.
Such optimised evaluation can be invoked when activities are
concentrated within the topmost windows.
$b0.5
$h[Report]($i[reportvalue]) $x1" $list12[OpC: 0D] $b>0
Will deposit $i[reportvalue] at the location $i[reportpointer].
Can be used to trace the progress of evaluation.
$b1
$section'Interaction between the user processor and the interpreter'
$p0.5
After initialisation, as well as after each completed evaluation the graphics
processor-interpreter puts itself into a wait state. 
$b0.5
The process requiring the evaluation should set up all the necessary
startup environment including the required action on completion 
(e.g. $h[Report] node) and then wake up the graphics processor through
a write into location E04000.
$b0.5
The processor picks up from the environment its starting execution pointer
and performs depth-first scan of the structure. It will halt upon completion,
upon encountering flag Wait=1 or upon invalid opcode.
$b1
$h[Startup environment]
$p0.5
Local graphics processor memory is under addresses 16_E0E000-16_E0FFFE
in the APM address space.
$b0.5
$h[$i0 address $t3 attribute]
$b0.5
$i0 E0E000 $t3 Execution pointer $b0 $t*3[Prior to evaluation should be loaded
with a pointer to the required entry node (or to the first command in stream
execution). During evaluation it contains the current execution pointer.
]$b0.5
$i0 E0E004 $t3 Execution flags
$b0.5
$i0 E0E006 $t3 Current colour
$b0.5
$i0 E0E008 $t3 Current planes $b0 $t*3[16-bit mask with 1's indicating planes
with enabled write operation
]$b0.5
$i0 E0E00A $t3 Current X
$b0.5
$i0 E0E00C $t3 Current Y
$b0.5
$i0 E0E00E $t3 Bounding box $x2" left X
$b0.5
$i0 E0E010 $x2" bottom Y
$b0
$i0 E0E012 $x2" right X 
$b0
$i0 E0E014 $x2" top Y
$b0.5
$i0 E0E016 $t3 Clipping box $x2" left X
$b0
$i0 E0E018 $x2" bottom Y
$b0
$i0 E0E01A $x2" right X
$b0
$i0 E0E01C $x2" top Y
$b0.5
$i0 E0E01E $t3 base point $x2" X
$b0
$i0 E0E020 $x2" Y
$b0.5
$i0 E0E022 $t3 reference point $x2" X
$b0
$i0 E0E024 $x2" Y
$b0.5
$i0 E0E026 $t3 deferred scaling $x2" X scaling factor
$b0
$i0 E0E028 $x2" Y scaling factor
$b0.5
$i0 E0E02A $t3 Iteration index $b0 $t*3[Iteration index can be explicitly set
or it can be decremented. When 0 it inhibits evaluation of the subgraph of
the node.
]$b0.5
$i0 E0E02C $t3 current font $b0 $t*3[Current font pointer contains the address
of the base of the current font definition.
]$b0.5
$i0 E0E030 $t3 Argument array $b0 $t*3[It is a pointer to the base of the current
argument array.
]$b0.5
$i0 E0E034 $t3 Cursor $b0 $t*3[Cursor pointer addresses a graph currently used
for drawing cursors. Such graph will usually contain indexed argument
references in the array defining the bounding box of the image.
]
$C.OddEven
$E*
