/-------------------------------------------------------------------------\
|                                                                         |
| 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.4 THE INTUITION SCREEN.

Intuition also manages screens. An intuition screen data structure is
similar to those of intuition windows. The pointer to the screen data is
located at offset 46 in the window data structure. To obtain the base
address of your output window use the following:

        screen& = PEEKL(WINDOW(7)+46)

To calculate the address of an individual data field you add the offset to
the base address. The data structure is as follows:

Data structure Screen/Intuition/342 bytes.

Offset  Type    Description.
------- ------- ---------------------------------------
+000    Long    Pointer to the next screen.
+004    Long    Pointer to the first window in this screen.
+008    Word    X coordinate of upper left corner.
+010    Word    Y coordinate of upper left corner.
+012    Word    Width of the screen.
+014    Word    Height of the screen.
+016    Word    Y coordinate of mouse pointer.
+018    Word    X coordinate of mouse pointer.
+020    Word    Flags
                Bit 0  : 1 = Workbench screen.
                Bit 0-3: 1 = Custom screen.
                Bit 4  : 1 = Showtitle.
                Bit 5  : 1 = Screen beeps now.
                Bit 6  : 1 = Custom bit-map.
+022    Long    Pointer to screen name text.
+026    Long    Pointer to standard title text.
+030    Byte    TitleBar height.
+031    Byte    Vertical limit of titlebar.
+032    Byte    Horizontal limit of titlebar.
+033    Byte    Vertical limit of menus.
+034    Byte    Horizontal limit of menus.
+035    Byte    Top window border.
+036    Byte    Left window border.
+037    Byte    Right window border.
+038    Byte    Bottom window border.
+039    Byte    Unused.
+040    Long    Pointer to standard font TextAttr
+044     --     Viewport of screen.
+084     --     Rastport of screen.
+184     --     Bit-map of screen.
+224     --     LAyerInfo of screen.
+326    Long    Pointer to first screen gadget.
+330    Byte    DetailPen.
+331    Byte    BlockPen.
+332    Word    Backup register for Beep(), stores col0
+334    Long    Pointer to external data.
+338    Long    Pointer to user data.

You probably noticed that the window and screen data structures are quite
similar, even though some fields are new. Again, we will explain each field
individually.

                                PAGE 114

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

3.4.1 SCREEN STRUCTURE.


OFFSET 0: NEXT SCREEN.

Screens are also organised by Intuition in the form of a data chain. When
there are other screens in a chain with your screen, the address of the
next screen's data block is at this offset.


OFFSET 4: FIRST WINDOW.

Remember the data chain used by windows: two fields, the father and child,
provide the address of the previous and next windows. By using these you
can move back and forth through the chain from one window to another.
however, this method has a small flaw. In order to go through the entire
chain, you have to find the beginning of the chain first. The active window
you access is not necessarily the first window in the chain.

If you are interested only in a window in a specific screen, there is an
easier method you can use. This field contains the address of the first
window data block. The address of the next window structure is in offset+0
of the window data structure.

        windo& = WINDOW(7)
        scr& = PEEKL(windo&+46)
        searcher&=scr&+4
        WHILE flag% = 0
            searcher& = PEEKL(searcher&)
            IF searcher& = 0 THEN
                flag% = 1
            ELSE
                counter%=counter%+1
                PRINT "Window";counter%;
                PRINT " Data block address : ";
                PRINT searcher&
            END IF
        WEND
        END

NOTE: Although this method is easier to program, it only accesses those
windows in the output window of the current screen.

                                PAGE 115

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

OFFSET 8, 10, 12 AND 14: SCREEN DIMENSIONS.

Like the window structure, there offsets contain the coordinates of the
upper left hand corner of the screen and the height and width of the
screen. The corner coordinate is relative to the top corner of the
display. The current versions of the Amiga(500-2000) do not allow
horizontal shifting of the screen. Offset field +8 is available for future
compatibility.


OFFSET 16 AND 18: THE MOUSE COORDINATES.

Here you find the X and Y coordinates of the mouse pointer relative to the
upper left hand corner of the screen. During vertical screen movements the
Y value can vary a bit.


OFFSET 20: FLAGS.

The bit descriptions a self-explanatory. Show title means that the screen's
title text is visible. A custom bit-map is suitable when you are generating
a new screen that has its own drawing plane.


OFFSET 22 AND 26: THE NAME OF THE SCREEN.

This offset contains the address of either the name string of this screen
or a standard text string which is taken as default from a window when a
name string is not specified.


OFFSET 30-39: DEFAULT PARAMETERS.

These bytes contain various standard parameters, such as the dimensions
of the title bar etc.. All windows in this screen default to these
dimensions automatically.


OFFSET 40: THE STANDARD CHARACTER SET.

Whenever a window is opened in your screen, it has a standard character set
(a predetermined font). The address of this font is stored here.

We will be discussing character sets in more detail later.

                                PAGE 116

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

OFFSET 44 : THE VIEWPORT.

This is another new term we will be discussing in more detail later. In
relation to the data structure of the screen, the ViewPort is NOT a
pointer. At offset 44, it is the actual ViewPort of the screen. ViewPort,
which is a small data structure 40 bytes long, is an interface to the Amiga
graphic hardware (the COPPER graphic coprocessor).


OFFSET 84: THE RASTPORT.

This offset is not a pointer either but the actual RastPort. You received
an introduction to the RastPort in the window data structure. Since both
screen and windows are drawing planes, the screen also has a RastPort.


OFFSET 184: THE BIT-MAP.

This is a new data structure which is 40 bytes long. Bit-map is the
interface between the screen and the memory it occupies, called
"bit-planes".


OFFSET 234:THE LAYERINFO.

This is the last internal data structure of the screen. It is the core of
thw windowing system (the layers). This will be discussed in detail later.


OFFSET 326: POINTER TO SCREEN GADGETS.

Screens also recognise gadgets that move them to the background or bring
them to the foreground. This field is specifically for internal system use.


OFFSET 330 AND 331: THE SCREEN COLOURS.

Changing the screen colour values that are stored here works the same way
as for windows. The new colours take effect as soon as the screen is
refreshed, such as when you use a menu etc...


OFFSET 332: BACKUP-REGISTER.

Intuition stores the colour from register 0 here when the screen is flashed
or beeped. The following will beep the screen:

        PRINT CHR$(7)


OFFSET 334 AND 338: EXTERNAL AND USER DATA.

These allow the possibility to link other data blocks with the standard
structure.

                                PAGE 117

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

3.4.2 THE INTUITION FUNCTIONS FOR SCREEN HANDLING.

Below are the routines from the intuition library used for screen handling:

        MoveScreen()
        ScreenToBack()
        ScreenToFront()
        WBenchToBack()
        WBenchToFront()

To make things easier we have written three SUBs that use all of these
routines. They are named ScrollScreen, ScreenHere and ScreenBye.

ScrollScreen requires the number of pixels that the screen should scroll
down in the current output window (a negative value scrolls it up).
ScreenBye sends the screen behind all current screens and ScreenHere brings
the screen to the foreground.

Here are the SUBs in a small demonstration program:

        '#####################################
        '#
        '# Section: 3.4.2
        '# Program: Screen Control.
        '# Date   : 01/04/87
        '# Author : tob
        '# Version: 1.0
        '#
        '######################################

        ' Program controlled screen handling.

        PRINT "Searching for .BMAP file ........."

        'INTUITION-library
        'MoveScreen()
        'ScreenToFront()
        'ScreenToBack()

        LIBRARY "intuition.library"

        init:   CLS
                SCREEN 1,320,200,1,1
                WINDOW 2,"Hello1",,,1

        main:   '* Screen scrolling.
                PRINT "This is the second screen! "
                
                                
                                PAGE 118

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

        '* Screen 1 down.       
        WINDOW OUTPUT 2
        FOR loop% = 255 TO 0 STEP -1
            ScrollScreen(1)
        NEXT loop%

        '* Screen 0 Down.
        WINDOW OUTPUT 1
        FOR loop% = 255 TO 0 STEP -1
            ScrollScreen(1)
        NEXT loop%

        '* Screen 1 up.
        WINDOW OUTPUT 2
        FOR loop% = 0 TO 255
            ScrollScreen(-1)
        NEXT loop%

        '* Screen 0 up.
        WINDOW OUTPUT 1
        ScreenHere
        FOR loop% = 0 TO 255
            ScrollScreen(-1)
        NEXT loop%
        
        '* Swapping.
        FOR t% = 1 TO 3000:NEXT t%
        ScreenBye
        FOR t% = 1 TO 3000:NEXT t%
        ScreenHere
        FOR t% = 1 TO 3000:NEXT t%
        
        '* Closing.
        WINDOW CLOSE 2
        SCREEN CLOSE 1

        endprog:        LIBRARY CLOSE
                        END

        SUB ScrollScreen(pixel%) STATIC
                screenAddress&=PEEKL(WINDOW(7)+46)
                CALL MoveScreen(screenAddress&,0,pixel%)
        END SUB

        SUB ScreenHere STATIC
                screenAddress& = PEEKL(WINDOW(7)+46)
                CALL ScreenToFront(screenAddress&)
        END SUB

        SUB ScreenBye STATIC
                screenAddress& = PEEKL(WINDOW(7)+46)
                CALL ScreenToBack(screenAddress&)
        END SUB


                                PAGE 119

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