Chapter 6. Examples of Native Compiler Language

The description of the language itself in Chapter 5, “Native Compiler Language,” is a starting point for learning about the language of video formats. However, the examples in this chapter will help solidify your understanding.

You will need the quick bit of information in “Using Examples” before you read about the examples in the book. Each of these examples is presented in source form and has brief remarks describing the important points:

Using Examples

You will rarely need to write a format completely from scratch. Most people who write formats find a format similar to what they are writing and modify it to suit their needs. If you can, you should do the same.

Many of the examples that accompany this book are provided as part of the installation image and are in the directory /usr/gfx/ucode/common/vfc/vfs/. You should refer to those files when writing your own format.

Interlaced Format

This format is similar to the PAL-I timing. Its two fields interlace spatially, as described in “Interlaced Formats”.

Example 6-1. Interlaced Format


/*
** 768x576_25i.vfs - RGB PAL standard
*/

General
{
    exported time SerrationDuration;
    exported time EqualizationDuration;

    FieldsPerFrame = 2;
    FramesPerSecond = 25;
    TotalLinesPerFrame = 625;
    TotalPixelsPerLine = 944;
    ActiveLinesPerFrame = 576;
    ActivePixelsPerLine = 768;
    FormatName = "PAL";

    SerrationDuration = 27.3 usec;
    EqualizationDuration = 2.35 usec;
}

Active Line
{
    HorizontalFrontPorch = 1.3 Usec;
    HorizontalSync = 4.7 Usec;
    HorizontalBackPorch = 5.96 usec;
}

Field
{
    swap = true;
    skip = 1;
    offset = 0;

    Vertical Sync = {
        repeat 5 {
            Length = 0.5H; 
            Low = 0 usec; 
            High = SerrationDuration;
        }
    }

    Vertical Back Porch = {
        repeat 5 {
            Length = 0.5H; 
            Low = 0 usec; 
            High = EqualizationDuration;
        }
        repeat 17 {
            Length = 1.0H; 
            Low = 0 usec; 
            High = HorizontalSync;
        }
        {
            Length = 0.5H - HorizontalFrontPorch; 
            Low = 0 usec; 
            High = HorizontalSync;
        }
    }
    
    Active = {
        {
            /* No sync edge transitions needed here. */
            Length = 0.5H + HorizontalFrontPorch;
        }
        repeat 287 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Vertical Front Porch = {
        repeat 5 {
            Length = 0.5H; 
            Low = 0 usec; 
            High = EqualizationDuration;
        }
    }
}

Field
{
    swap = true;
    skip = 1;
    offset = 1;

    Vertical Sync = {
        repeat 5 {
            Length = 0.5H; 
            Low = 0 usec; 
            High = SerrationDuration;
        }
    }

    Vertical Back Porch = {
        repeat 5 {
            Length = 0.5H; 
            Low = 0 usec; 
            High = EqualizationDuration;
        }
        {
            Length = 0.5H;
        }
        repeat 17 {
            Length = 1.0H; 
            Low = 0 usec; 
            High = HorizontalSync;
        }
    }
    
    Active =
    {
        repeat 287 {
            Length = 1.0H; 
            Low = 0 usec; 
            High = HorizontalSync;
        }
        {
            Length = 0.5H; 
            Low = 0 usec; 
            High = HorizontalSync;
        }
    }

    Vertical Front Porch = {
        repeat 5 {
            Length = 0.5H; 
            Low = 0 usec; 
            High = EqualizationDuration;
        }
    }
}

The following are the salient features of this format:

  • The skip and offset attributes describe the monitor's interlacing pattern.

    • The skip = 1; of the first field is the same as skip = 1; of the second. Both fields interlace similarly by drawing every other line, as described in “Interlaced Formats”. You can find information on the skip attribute in Table 5-3.

    • The starting line at which each field begins differs. The first field uses the attribute offset = 0; to indicate that drawing should begin on the first line of the monitor. The second field uses offset = 1; to indicate that the first line of the field is offset one line into the display of the monitor. Table 5-3 describes the offset attribute.

    The attributes are only part of the story and tell the graphics pipe how pixels should be fetched from the frame buffer. The synchronizing pulses of the vertical sync components of the field tell the monitor which frame is first.

  • This format permits motion between the two fields. This enabled with the swap = true; attribute of the first field, echoed by the swap = true; attribute of the second field. Were the second field to have its swap value set to false, no swaps would be permitted between fields. See the swap attribute in Table 5-3.

Stereo Format

This format describes a two-field stereo format, close to the size of VGA. Monitors showing field-based stereo display slightly different views in two successive fields. In one field, only one eye is permitted to view the image (usually by special glasses); the succeeding field is shown only to the other eye.

The format shown here is known as new-style stereo. It differs from old-style stereo in that the new style fetches pixels of both fields from the same location in the frame buffer; this is described in “Stereo Formats”. The old-style stereo formats used pixels in different portions of the frame buffer for each eye's field. The new-style stereo format is shown in Example 6-2.

Example 6-2. Stereo Format


/*
** 640x480_120s.vfs - stereo VGA at 60Hz/frame
*/

General
{
    ActiveLinesPerFrame = 480;
    ActivePixelsPerLine = 640;
    FramesPerSecond = 60;
    FieldsPerFrame = 2;
    TotalLinesPerFrame = 1050;
    TotalPixelsPerLine = 800;
    FormatName = "640x480_120s - 120Hz Stereo VGA";
}

Active Line
{
    HorizontalFrontPorch = 0.397 usec;
    HorizontalSync = 1.190 usec;
    HorizontalBackPorch = 1.587 usec;
}

Field
{
    eye = { Left };
    swap = true;

    Vertical Sync = {
        {
            Length = 1.0H;
            Low = 0 usec;
        }
        repeat 2 {
            Length = 1.0H;
        }
    }

    Vertical Back Porch = {
        {
            Length = 1.0H;
            High = HorizontalSync;
        }
        repeat 31 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Active = {
        repeat ActiveLinesPerFrame {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Vertical Front Porch = {
        repeat 10 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }
}

Field
{
    eye = { Right };
    swap = false;

    Vertical Sync = {
        {
            Length = 1.0H;
            Low = 0 usec;
        }
        repeat 5 {
            Length = 1.0H;
        }
    }

    Vertical Back Porch =
    {
        {
            Length = 1.0H;
            High = HorizontalSync;
        }
        repeat 28 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Active =
    {
        repeat ActiveLinesPerFrame {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Vertical Front Porch =
    {
        repeat 10 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }
}

Note these features of the format shown in Example 6-2:

  • The format has two fields, both of which have similar structure. The significant difference in timing of the two fields is the length of vertical sync: to allow monitor hardware to discriminate between the two fields, the second field's vertical sync pulse is somewhat longer than that of the first.

    How different need the sync signals of the two fields be? This is just an example; unfortunately, monitor manufacturers have not adopted a common standard for recognition of sync signals of the two fields. Check with the documentation that accompanies your monitor for details; since this information is often sketchy, you may need to contact the monitor manufacturer directly. If the monitor is distributed by Silicon Graphics with your system, the company will provide you with whatever information is available.

  • The statements eye = {Left}; in the first field and eye = {Right}; in the second field are the significant features in the example. They use the eye attribute described in Table 5-3.

  • Stereo displays should not have motion between the two fields; this would have an unsettling effect on the viewer, potentially destroying the stereo effect. To inhibit swap, the second field uses the statement swap = false;. Table 5-3 describes the swap attribute.

    It is also useful to reduce the swap interval to reduce demand on the rendering hardware of the graphics pipe. If swap were set to true for both fields, the pipe would swap at 120 Hz instead of 60 Hz, halving the time between potential swaps.

Color Field Sequential

Field sequential monitors have special hardware. Instead of displaying all three colors (red, green, and blue) simultaneously, these monitors display only one color at a time. The monitor displays the entire picture once showing only the red pixels, another field only with green, another blue. Each color field is shown at three times the normal rate so each frame passes at the normal speed. When the fields pass rapidly, it is hoped the eye merges the sequential fields successfully. See Example 6-3, below.

Example 6-3. Color Field Sequential Format


/*
** 640x480_180q.vfs - field sequential
*/

#define SER (1.0H-HorizontalSync)

General
{
    FieldsPerFrame = 3;
    FramesPerSecond = 60;
    TotalLinesPerFrame = 1560;
    TotalPixelsPerLine = 880;
    ActiveLinesPerFrame = 480;
    ActivePixelsPerLine = 640;

    FormatName = "Field Sequential 640x480_180q";
}

Active Line {
    HorizontalFrontPorch = 40 pixels;
    HorizontalSync = 80 pixels;
    HorizontalBackPorch = 120 pixels;
}

/*
** red (synchronizing) field
*/

Field
{
    Color = { red };
    swap = true;

    Vertical Sync = {
        repeat 6 {
            Length = 1.0H;
            Low = 0 usec;
            High = SER;
        }
    }

    Vertical Back Porch = {
        repeat 33 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }
    
    Active = {
        repeat 480 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Vertical Front Porch = {
        {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }
}

/*
** green field
*/

Field
{
    Color = { green };
    swap = false;
    
    Vertical Sync = {
        repeat 3 {
            Length = 1.0H;
            Low = 0 usec;
            High = SER;
        }
    }

    Vertical Back Porch = {
        repeat 36 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }
    
    Active = {
        repeat 480 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Vertical Front Porch = {
        {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }
}

/*
** blue field
*/

Field
{
    Color = { blue };
    swap = false;

    Vertical Sync = {
        repeat 3 {
            Length = 1.0H;
            Low = 0 usec;
            High = SER;
        }
    }

    Vertical Back Porch = {
        repeat 36 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
   }
    
    Active = {
        repeat 480 {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }

    Vertical Front Porch = {
        {
            Length = 1.0H;
            Low = 0 usec;
            High = HorizontalSync;
        }
    }
}

The salient features of the format shown in Example 6-3 are described below:

  • The three fields are similar in timing except for the length of vertical sync. In the first field, vertical sync is longer. This allows hardware to discriminate between color fields and the beginning of the frame.

  • The attribute of importance is that of color. This format differs because the different fields specify Color = {red};, Color = {green};, and Color = {blue};. You can find the description of this attribute in Table 5-3.

  • Swaps are enabled only for the first field (swap = true;), disabled for the second (swap = false;) and third (swap = false;). This inhibits motion between the two fields. Table 5-3 describes this attribute.