Chapter 8. Line-Based Format Definition Language

From time to time, you may come across a video format for which rules are difficult to write. Either the format is too complicated or the rules just do not quite apply. Rather than contort rules files unnecessarily, there is an escape mechanism.

Writing a video format in line-based language allows you to express some or all of the generated signals for each line.


Note: Normally, writing line-based definitions is reserved only for Silicon Graphics engineering personnel who can anticipate problems in the relationship to other signals this might cause in rules generation. If you do not understand those relationships, stop now!


The Line-Based Language

To use the line-based language, you must put the directives in a special section, declared as follows (similarly to that of the Field declaration):

Line Based {
    statement...
}

The line-based language has but two statement types, one to set initial state, the other to specify a transition:

Signal signal-name initial state = direction;
Transition Line Range signal-name = start-line to end-line direction at time-expression;

The line-based language is very simple. For each transition, you specify a line number and time on that line. The components are as follows:

  • signal-name is the signal being addressed. This is often the synchronization signal produced by the hardware. You may also use one of the user signals as the signal name (see “The User Signals for Reference”).

  • direction is high or low, as described in “The set signal Statement for Transitions”.

  • Both start-line and end-line are integer line numbers on which the transition is to occur. If you wish a transition to occur on only one line, specify both values to be the same line number.

  • For time-expression, you can use any of the time expressions specified in “Time Expressions”.

The line-based initial state has the same function as the same statement in rules generation, described in “Initial State”. The transition line range statement is similar to that described in “The set signal Statement for Transitions”.

Examples

The following example sets the signal HSYNC signal. The first statement sets the signal to the low state on each line (note the range “1 to TotalLinesPerFrame”); the second statement sets the signal to high at a different position on each line. The variable GlobalDelay is private to this format and is set elsewhere in the source file.

Example 8-1. Setting a Signal on Every Line


Line Based {
    signal “HSYNC” initial state = low;

    Transition Lines Range “HSYNC” = 1 to TotalLinesPerFrame 
        low at (GlobalDelay - HorizontalFrontPorch);

    Transition Lines Range “HSYNC” = 1 to TotalLinesPerFrame 
        high at (HorizontalSync + HorizontalBackPorch + 
                 GlobalDelay - 1.0H);

}

The following example, also using the GlobalDelay variable, sets the VSYNC signal to high on line 23 and low on line 311 (setting the low and high line numbers of the range to the same value executes the statement on only that single line).

Example 8-2. Use of Single Line Ranges


Line Based {
    signal “VSYNC” initial state = low;

    Transition Lines Range “VSYNC” = 23 to 23 
        high at (GlobalDelay - HorizontalFrontPorch );

    Transition Lines Range “VSYNC” = 311 to 311 
        low at (GlobalDelay - HorizontalFrontPorch );
}


Anticipating Line-Based Definitions in the Rules

Did you read “The Edge Database”? Most of the activity in writing a format and rules is the act of adding transitions to the edge database. Without taking some care, you can add too many transitions if you write in line-based language.

How can you add too many transitions? If you specify a transition in line-based language and then specify similar transitions in rules (see “The set signal Statement for Transitions”), you will find both transitions in the edge database.

The solution? Use the function TransitionsDefinedOnSignal, described in Table 7-5. This function allows you to detect whether the edge database already contains any transitions on a specified signal.

Example 8-3. Use of Function TransitionsDefineOnSignal


/*
 * COMP_SYNC
 */
if (!TransitionsDefinedOnSignal("COMP_SYNC")) {

    /*
     * Should follow user sync exactly 
     */
    signal "COMP_SYNC" initial state = high;
    within each (edge of user sync) {
        set signal "COMP_SYNC" CorrespondingPolarity at BeginTime;
    }
}

Example 8-3 shows proper use of the TransitionsDefinedOnSignal function. You can see that no additional transitions are added using set signal if line-based language has already been used to set the transitions.