/-------------------------------------------------------------------------\
|                                                                         |
| The ALLIANCE presents : Amiga Graphics Inside and Out from Abacus.      |
|                                                                         |
| This is the second in our series of complete books and due to the sheer |
| size of it this one will be spread across the next 2 or 3 of our docs   |
| disks.                                                                  |
|                                                                         |
| Typed By RAZOR BLADE of Alliance.                                       |
|                                                                         |
| Greets to the rest of Alliance :                                        |
|                                                                         |
| Alchemist                                                               |
|   Asterisk                                                              |
|     Chaos                                                               |
|       Mit                                                               |
|         Shadowfax                                                       |
|           Viper                                                         |
|                                                                         |
\_________________________________________________________________________/


----------------------------------------------------------------------------

3.6 THE RASTPORT.

With this data block, we get even closer to the basic elements of Amiga
graphics, the so called "graphic primitives". We'll leave intuition to go
deeper into the Amiga system architecture. We'll now explore the graphic
libraries.

The RastPort, which contains the data that controls how a drawing takes
place, manages a drawing plane. The starting address of the data block for
an actual window is always in the variable WINDOW(8). This address can be
read directly from the window data structure.

        PRINT WINDOW(8) 
        PRINT PEEKL(WINDOW(7)+50)

The RastPort structure is constructred as follows:

Data Structure: RastPort/Graphics/100 Bytes.

Offset  Type    Description.            
------- ------- ------------------------------------------------------
+000    Long    Pointer to the layer structure.
+004    Long    Pointer to the Bit-map structure.
+008    Long    Pointer to the AreaFill pattern.
+012    Long    Pointer to the TmpRas structure.
+016    Long    Pointer to the AreaInfo structure.
+020    Long    Pointer to the GelsInfo structure.
+024    Byte    Mask: Writemask for this raster.
+025    Byte    Foreground colour.
+026    Byte    Background colour.
+027    Byte    AreaFill outline colour.
+028    Byte    Drawing mode:
                        JAM1            = 0
                        JAM2            = 1
                        COMPLEMENT      = 2
                        INVERSVID       = 4
+029    Byte    AreaPtSz: 2^n Words for AreaFill pattern.
+030    Byte    Unused.
+031    Byte    Line draw pattern preshift.
+032    Word    various control bits.
                FIRST DOT       = 1 : Draw first pixel?
                ONE DOT         = 2 : one dot mode for lines.
                DBUFFER         = 4 : Double buffered set.
+034    Word    LinePtrn: 16 bits for line pattern.
+036    Word    X coordinate of graphic cursor.

                                PAGE 122

----------------------------------------------------------------------------

+038    Word    Y coordinate of graphic cursor.
+040    ----    8*1 byte minterms.
+048    Word    Cursor Width.
+050    Word    Cursor Height.
+052    Long    Pointer to character set.
+056    Byte    Character set mode (bold, italics etc...)
+057    Byte    textspecific flags.
+058    Word    Height of characterset.
+060    Word    Average character width.
+062    Word    Text height without underline.
+064    Word    Character spacing.
+066    Long    Pointer to user data.
+070    Word    Reserved (7x)
+084    Long    Reserved (2x)
+092    Byte    Reserved (8x)

                ------------------------------------------

3.6.1 THE RASTPORT STRUCTURE.

The following explains the RastPort structure by offset the same manner we
did for windows and screens:

OFFSET 0 : THE LAYER.

The Amiga uses layers to keep each drawing plane separate from the other
planes. These layers are actually the principle elements of each Intuition
window. You might think layers are very complicated and, compared to
windows, relatively useless. However, layers are important and a closer
look (as seen in a later chapter) will prove that they are really a
storehouse of graphic possibilities.


OFFSET 4: THE BITMAP.

You have already learned about the Bitmap, which is a pointer to the
bit-map structure. With this pointer you have indirect access to the screen
address through the RastPort:

        scr& = PEEKL(WINDOW(8)+4)-184

The bit-map is the intersection between the data structure and the RAM
banks where the window and screen contents are stored.

                                PAGE 123

----------------------------------------------------------------------------

OFFSET 8 : POINTER TO THE AREAFILL PATTERN.

You have seen how to fill areas with a single colour or with a pattern. If
you use a pattern, then that pattern has to be stored somewhere in memory.
This offset contains the address pointer to where the pattern is stored.

We will provide more information and examples after the offset
explanations. One of our subjects will show you how to use multi-colour
patterns of up to 32 colours.


OFFSET 12: THE TmpRas.

TmpRas stands for Temporary Raster. This is a pointer to an area of free
RAM used for certain operations. Whenever you use the fill commands like
PAINT or LINE BF, this RAM is used as a temporary holding area for the
entire object being filled.


OFFSET 16: AREA INFO.

This pointer is for a data structure used when drawing polygon shapes.
There is not much use for this from BASIC, but we will discuss it later.


OFFSET 20: GELSINFO.

Gels are Graphic Elements, such as sprites and Bobs (Blitter Objects), and
also the complete automatic Amiga animation system. Before this system can
be activated the GelsInfo structure has to be defined. This structure
contains some very important parameters.


OFFSET 24: WRITEMASK.

This variable allows individual bit-planes of the drawing plane to fade.
The default value is normally 255. All bits are set which means that all
available bit-planes are used. The POKE,

        POKE WINDOW(8) + 24,0

makes all bit-planes inactive and nothing more will be drawn on the
screen. You can also select specific bit planes to be active or inactive.


OFFSET 25,26 AND 27: DRAWING COLOUR.

These registers determine the drawing colours. The first contains the
number of the colour register for the drawing colour. The second has the
background and the third the AreaOutlineMode.

                                PAGE 124

------------------------------------------------------------------------------

OFFSET 28: DRAWING MODE.

The Amiga has four basic drawing modes that you can use. They are:

        JAM1            = 0
        JAM2            = 1
        COMPLEMENT      = 2
        INVERSEVID      = 4

The normal drawing mode is JAM2. This means that the foreground colour is
used to draw in the drawing plane and the rest will be in the background
colour. THe following example will make this clear:

        (Enter these examples in Direct Mode!)
        LINE (0,0)-(100,100),2,bf
        LOCATE 1,1:PRINT "hello!"

Thw white text appears on a blue background. A hole is made in the original
black background.

JAM 1 is different. The foreground colour is used to draw, but the
background is not changed.
        
        LINE (0,0)-(100,100),2,bf
        POKE WINDOW(8)+28,0
        LOCATE 1,1:PRINT "hello"
        POKE WINDOW(8)+28,1

COMPLEMENT complements the graphic with the background: Where ever a pixel
is set, it will be erased and just the opposite for unset pixels:

        LINE (0,0)-(100,100),2,bf
        POKE WINDOW(8)+28,2
        LINE(50,50)-(150,150),3,bf
        POKE WINDOW(8)+28,1

INVERSEVID inverts a graphicL background and foreground are exchanged. It
looks like this:

        POKE WINDOW(8)+28,4
        PRINT "Inverse!"
        POKE WINDOW(8)+28,1

These pokes work great in direct mode. However, they do not work in a
program. Nothing will happen.

The routine SetDrMd in the graphic library sets the desired mode safely and
reliably.

                                PAGE 125

----------------------------------------------------------------------------

        LIBRARY "graphic.library"
        CALL SetDrMd(WINDOW(8),mode%)

        mode% = 0 - 255

Various modes may be combined, only JAM1 and JAM2 work against each other.


OFFSET 29: AreaPtSz.

Whenever you work with patterns, you must specify how high the pattern will
be. Patterns can only be defined using powers of two (1,2,4,8,....). This
field stored the power of two.

Using a special programming method, you can use this register to activate
the mutli-colour pattern mode. This allows you to create patterns with up
to 32 colours. ( There will be more on this in the next section).


OFFSET 30,31 AND 32. FOR SYSTEM USE.

OFFSET 34: LINE PATTERN.

Patterns are not only for areas, but for lines also. The method is easy: 16
pixels in a row can be set or unset. The amiga then uses this Sample
pattern to draw lines. Take the following line pattern for example:

        *****.*.*****.*.

A dash dot dash dot line.

First you determine the bit values of the line:

bit& = 2^15+2^14+2^13+2^12+2^11+2^9+2^7+2^6+2^5+2^4+2^3+2^1

Now the value is stored to this register:

        POKEW WINDOW(8)+34,bit&

A test:

        LINE (10,10)-(600,10)

AS you can see it works.


OFFSET 36 AND 38: COORDINATES OF THE GRAPHIC CURSOR.

These two fields are extremely important. Text on the Amiga is nothing more
than text shaded graphics. Because of this, text can be placed in any
position on the screen. The following example demonstrates this:

        WHILE INKEY$ = ""
           x% = RND(1)*600
           y% = RND(1)*160
           POKEW WINDOW(8)+36,x%
           POKEW WINDOW(8)+38,y%
           PRINT "Commodore Amiga!"
        WEND

                                PAGE 126

----------------------------------------------------------------------------

OFFSET 40-51: MINTERMS, INTERNAL USAGE.

OFFSET 52: THE CHARACTER SET.

Just as in the screen structure this is a pointer to the currently active
font. The character set determines what your text looks like. We will
return to this subject later.


OFFSET 56: ACTUAL TEXT STYLE.

The Amiga can display a font in various forms on the screen:
        
        normal          = 0
        underlined      = Bit 0 set.
        bold            = Bit 1 set.
        italics         = Bit 2 set.

The last three modes can be combined to form different combinations.


OFFSET 57: TEXT FLAGS, INTERNAL USAGE.


OFFSET 58: TEXT HEIGHT.

This field contains the height of the currently active font. This value is
used to average the line height to calculate the correct line spacing.

There is nothing to prevent you from setting you own line spacing. It can
be even closer together than normal:

        POKEW WINDOW(8)+58,5

or further apart:

        POKEW WINDOW(8)+58,12


OFFSET 60: CHARACTER WIDTH.

This register contains the average width of the font. Since the Amiga also
supports proportional fonts (characters of different widths), you can set
the average width in this register.

                                PAGE 127

----------------------------------------------------------------------------

OFFSET 62: TEXT HEIGHT WITHOUT UNDERLINE.


OFFSET 64: CHARACTER SPACING.

The following routine allows you to vary the spacing between individual
characters. The default for this field is zero. Storing larger values here
will spread the characters over a larger area as in the following example:

        text$ = "Hello World!"
        text%=LEN(text$)

        FOR loop% = 1 TO 40
            POKEW WINDOW(8)+36,280-(loop%*text%*.5)
            '(centering)
            POKEW WINDOW(8)+38,90
            POKEW WINDOW(8)+64,loop%
            PRINT text$
        NEXT loop%

        FOR loop% = 39 TO 0 STEP -1
            POKEW WINDOW(8)+36,280-(loop%*text%*.5)
            POKEW WINDOW(8)+38,90
            POKEW WINDOW(8)+64,loop%
            PRINT text%
        NEXT loop%

        END


OFFSET 66: USER DATA.

This is a pointer to more data that can be linked to this structure.


OFFSET 70 to END - Reserved Data Fields.

                                PAGE 128

---------------------------------------------------------------------------- 
