@device(postscript)
@make(report)
@style(font newcenturyschoolbook, size 11)
@style(indent 0, spacing 1)
@modify(hd1, below 1 line)
@modify(hd2, below 1 line)
@modify(copyrightnotice, fixed -1 inch, flushright)
@blankspace(1.5 inch)
@begin(heading, size 30, flushright)
Programming
the Athena RT Workstation
@end(heading)
@begin(heading, size 14, flushright)
Henry Mensch
Project Athena
Revision C
February 2, 1988
@end(heading)
@copyrightnotice(Massachusetts Institute of Technology)
@newpage
@section[Introduction]

During April 1987 Project Athena RT workstations became
available for public use.  
The Athena RT/PC workstation uses IBM's RISC (@u[r]educed @u[i]nstruction
@u[s]et @u[c]omputer) technology (RT).  The RT architecture provides 
a small basic instruction set that speeds processing and 
produces efficient compiled code.

While the casual user can use an RT workstation for tasks like text
processing, the programmer will need to know about the features and
quirks peculiar to the RT.  Also, since it is desirable for faculty
curriculum development projects to develop software that works on both
the DEC VAXstations @i(and) the IBM RT/PC (where possible), they also
need information comparing the two environments.  @p(Programming the
Athena RT Workstation) summarizes these features and differences for
the experienced programmer.  It assumes that you are familiar with the
basic Unix compile/link process as described in the Athena documents
@p[Essential Fortran], @p[Essential C]  and @p(More C).

@section[Using Unix Files]

Text files created on the RT workstation can be copied to a VAXstation and
used there with no surprises.  Text files include C, Fortran and
Scribe source files, shell scripts, PostScript programs and line
printer output (@i[*.PS] and @i[*.lpt]) created by Scribe.  If you
need to know whether a particular file is a text file or not, you can
use the Unix @i[file] command:

@begin[example]
16-034-12% file @i[program.c]
program.c:     c program text
@end[example]

If @i[file] prints a description with the word "script" or "text" in
it, you should be able to use that file on either type of workstation
with no difficulty.



Binaries and data files created on the RT won't work on a VAXstation, and
binaries and data files created on a VAXstation won't work on the RT
workstation.  RT binaries won't work on a VAXstation because they use the
RISC instruction set, which is different from the VAX instruction set.
RT data files won't be useful on a VAXstation because the RT stores data in a
different format than the VAXstation.  See the Section "The IEEE 754 Standard
for Floating Point Arithmetic" for more details.
@newpage
@section[Using Software Libraries]

The chart below shows compilers and libraries (as of 2 February 1988)
available in the Athena environment.  Examine the chart to see if the
libraries you need to use are available on the RT workstation.  Those
libraries which aren't available may become available in the near
future.


@begin(format, facecode B, size 11)
@tabclear
@tabdivide(3)
@u[Software@\VAXstation@\RT] 
@end(format)
@begin(format, size 10)
@tabclear
@tabdivide(3)
Unix@\4.3 BSD@\ACIS 4.2/RT@+[*]
X Window System@\Version 11 @\Version 11 
C@\Portable C@\Portable C
@\Saber C@\port in progress
@\-@\High C@+[**]
Lisp@\Franz Lisp Opus 42.16.3@\-
Scheme@\available@\in progress
Fortan@\Berkeley f77@\Berkeley f77
ProChart@\Version 3.0@\-
20/20@\Version 1.0.21@\March 1988
RS/1@\Version 12@\-
GKS@\Version 2b@\in progress
C-Chart@\Version 2b@\-
Penplot@\available@\available
Blox@+[***]@\development only@\developent only
MATRIX@-[X]@\in /mit/beta/matrixx nfs@\-
MACSYMA@+[***]@\Version 309.2@\-
Minitab@+[***]@\-@\-
NAG (math library)@\Version 11@\-
Ingres@+[****] (database)@\-@\-

@blankspace (.25 lines)
@u[UNIX Library Functions:]
C library@\available@\available
Fortran library@\available@\available
Math library@\available@\available@+[*****]
Internet library@\available@\available
Standard I/O library@\available@\available
Curses library@\available@\available
Termcap library@\available@\available
@i[dbm] library@\available@\available
@i[assert] library@\available@\available
@i[getfsent] library@\available@\available
@i[getdiskbyname] library@\available@\available
@i[initgroups] library@\available@\available
@i[rexec] library@\available@\available
@i[rcmd] library@\available@\available
@end (format)

@tabclear
@begin(format, facecode b)
@tabset (3.75 inches)
@&_@\
@end(format)
@tabclear

@begin(FlushLeft, size 9)
@+[*    ]ACademic Information Systems 4.2/RT with Athena enhancements.
@+[**   ]Optimized for IBM/RT, code must conform to ANSI standards.
@+[***  ]Only available on certain machines for courses.  See your applications programmer.
@+[**** ]Must see Accounts Administrator to become an Ingres User.
@+[*****]Math functions on the RT workstation use the @i[IEEE 754 Standard for Binary Floating Point Arithmetic]
@end(FlushLeft)




@section[Programming with the Penplot Library]

Penplot functions take real numbers and integers as arguments.  Not
just any type of numbers will do.  When using the Penplot routines
inside a C program, be sure to declare real variables as @i[float] and
integer variables as @i[long int].  Some programs which use Penplot
have incorrect declarations for real numbers as @i[double] or integers
as @i[short int].  These programs may work on VAXstations but they
will not work on RT workstations.

@section[Programming with Real Numbers]

The RT workstation provides some new facilities for numerical
programming.  The software and hardware behind these new capabilities
are described below.  More information about programming with real
numbers can be found in Section Two of the @i[ACIS 4.2a for the IBM RT
PC] manual, which can be found in documentation racks in RT
workstation clusters. This two-manual set is also sold at the IS
Microcomputer Store (11-209, M-F 10-4, x6325).

@section[The IEEE 754 Standard for Floating Point Arithmetic]

The IBM RT/PC uses the IEEE 754 Standard for Binary Floating Point
Arithmetic when performing arithmetic operations with floating point
quantities.  This standard provides definitions for some basic
operations, conversions (to and from integers) and number formats.  It
also provides some of its own error handling in the event of
underflows and overflows, divide by zero, etc.

An important aspect of the IEEE standard, as implemented on the RT
workstation, is that you won't get a core dump for floating point
arithmetic errors since the standard provides its own handling for
these errors.  You will know that there was an error because the
values @i[INF()] and @i[NAN] will be output wherever the erroneous
value would appear.  

If you plan to do lots of numerical programming you should read the
@i[IEEE Standard for Binary Floating-Point Arithmetic] (also known as
@i[IEEE 754]).  This is the definition of the IEEE 754 standard for
floating-point arithmetic, and it should answer many questions
regarding the storage and processing of floating-point values.  This
document is included in the manual racks in RT workstation clusters.

@section[The IBM RT/PC Floating Point Accelerator]

Every Athena RT Workstation has a Floating Point Accelerator (FPA)
card which provides hardware assistance to the CPU when performing
floating point numbers.  The FPA speeds up the processing of floating
point numbers.  The FPA isn't used by any program unless you load the
floating point accelerator routines when you compile your program.
To compile and load a Fortran program with the floating point
accelerator routines, type the following command:

@begin[example]
4-035-12% f77 @i(yourprogram.f) -lfpa
@end[example]

Include the floating point accelerator routines with your C program by
typing:

@begin[example]
4-035-12% cc @i(yourprogram.c) -lfpa
@end[example]

The @i[-lfpa] option can also be used with the @i[ld] command to
combine several pre-compiled object programs with the @i[fpa] library.
Type @i[man fpa] for more details on the FPA library.  


@newpage
@section[The High C Compiler]
@center{
@begin(box)
There are many problems (bugs) in the current version of High C.
It is not recommended for use at this time.
@end(box)}

The RT workstation is packaged with two C compilers: the Berkeley
portable C compiler, and High C from MetaWare, Inc.  The portable C
compiler (also called @i[pcc]) is the same as the compiler used on the
VAXstations and timesharing machines.  High C (also called @i[hc]) is
an implementation of the proposed ANSI standard for the C programming
language with a few extensions.

High C provides some advantages over the portable C compiler.  Since
this version of High C was built specifically for the RT/PC, it can
take advantage of the RISC architecture when compiling and producing
code.  High C also has more extensive syntax checking and it produces
better error messages.  
@comment{However, there are many problems (bugs) in the
current version of @i(hc).  It is not recommended for use at this
time.}

To learn more about High C, read its manual page by typing @i[man hc].
Also see the @i[High C Language Reference Manual], which can be found
in the documentation racks.  The @i[High C Language Reference Manual]
is also available for sale at the IS Microcomputer Store.

@section[Portable Programming With the RT Workstation]

Portability between the RT and the VS2 is an important issue to
consider when developing an application in the Athena environment.
Athena supports several workstation configurations manufactured by
different manufacturers, and each of these configurations has
different features from the others.  Most programmers can insure that
their programs are portable by following a few simple guidelines.
Listed below are some questions that many programmers ask when writing
portable programs.

@subsection[Which Compiler Should You Use During Program Development?]
@blankspace(1 line)
In general, programs which require the standard Unix libraries listed in the chart,
X, math, and curses libraries
that compile
with @i[cc] on a VAXstation system should compile and
execute correctly on an RT workstation if you use the portable C
compiler.  Many programs developed under @i[pcc] will compile under
High C also, but this is not guaranteed.  Since High C is more careful
about syntactical matters, you may find that some programs which run
under @i[pcc] won't compile under @i[hc].

If you choose to develop your programs with @i[hc] don't use the
extensions to the C language that are provided with High C.  These
extensions are described in Appendix A of the @i[High C Language
Reference Manual].

The Unix tool @i[lint] is also useful when designing portable
programs, particularly if you are using @i[pcc].  @i[lint] does the
sort of syntax and argument checking that @i[pcc] ignores.  The
obscure errors that @i[lint] finds are often the errors which cause
portability problems. (NB: Unfortunately, the current version of
@i[lint] has many bugs.)
@newpage
@subsection[Variables of type @i[char]:  Unsigned or signed?]
@blankspace(1 line)
@footnote{
This Section is copied from @i(IBM Academic Information Systems 4.3 
for the IBM RT/PC) copyright 1985, 1986, and 1987 with permission.}
Variables of type @b(char) are unsigned (range 0..255) by default on the 
RT/PC, in contrast to the VAX, wher they are signed (range -128..127) by
default.  With the High C compiler (hc(1)),
the type @b(signed char) is available, as well as a command-line option
@i(-Hoff=char_default_unsigned) to make characters signed by default.
This option generally produces less efficient code, but can be of value
in determining whether signedness is the cause of a bug.

The @b(unsigned) default uncovers a machine dependency in a common technique
for end-of-file testing.  In the following program fragment

@begin(verbatim)

         char c;
         ...
         if((c = getchar()) = = EOF) ...

@end(verbatim)
the test always fails, since EOF is -1 and c is in 0..255.   
Declaring c as an @b(int) is a good machine-independent solution.

with @i(pcc)(1), there is not type @b(signed char), but the following
macro might be useful if you need to use an unsigned character as though it
were signed:

@begin(verbatim)

   #if'\377' < 0
   #define Signed (x) (x)
   #else
   #define Signed(x) (((x)^128)-128)
   #endif

@end(verbatim)
@subsection[Byte-Ordering Problems: What Are They, Anyway?]
@blankspace(1 line)
Some computers follow a different convention for the storage of bytes
in memory.  While the RT workstations store the high-order bit in the
lowest address, the VAXstations store it in the highest address.  This
will cause compatibility problems in any program that makes assumptions about
low-level data storage formats, such as is often done
in network applications.

To solve these problems, programmers use a convention called
@i[network byte order] when writing programs which depend on
particular bits being in specific places in a byte.  There are
functions for C programs which translate between network byte order
and @i[host byte order] (the byte-ordering scheme particular to your
type of machine).  Type @i[man byteorder] to learn more about these
byte-order translating functions.

@newpage

@section(Summary of Configuration Differences:  RT Release 5.5/5.6 and
VAX Release 5.5/5.6)

@begin(format, spread .25 lines)
1. Major subsystems available on the VS2 but missing on the RT.  It
	is not known exactly when (if ever) these will be available.

 @blankspace (.25 lines)
        RTI Ingres          CLU         RS/1         Scribe for 9700
        Macsyma             NAG        Franz Lisp   
	

2. Subsystems available on the RT but not on the VS2
	hc compiler
	/usr/ibm (primarily dosread/doswrite and 3812 programs)
	/etc/landump (token-ring management utility)
	/etc/setscreen (change displays)
	/etc/fdformat (format floppy disks)
	xterm -C puts console output in a window on the RT


3. Configuration differences
	RT has one only floppy disk, VSII has two (or none), VS2000 has one
	Screen pixel count is different on RT
	Different X server is used
	Keyboards have some different function keys
	

@end(format)
