Xtended Mode - Unchained 640x400x256 

-----------------------------------------------------------------------------
  Introduction
-----------------------------------------------------------------------------

  In a previous article, Mark Feldman christened this mode as "Xtended", so 
that's the name I'll stick with throughout this article. The mode works on 
most SVGA cards (though apparently not all); if anyone can add to the 
information presented here, I would be glad to hear from them.

  Xtended mode is a variation on 640x400x256 and will only work on SVGA's 
which support such a mode. Its main advantage is that once it is set up, it 
requires no SVGA bank switching to access the display memory, and, like 
ModeX, area fills and screen-to-screen copies can be much faster.

-----------------------------------------------------------------------------
  Setting Xtended Mode
-----------------------------------------------------------------------------

  Unfortunately, SVGA cards being what they are, there is some variation in 
the method used to set Xtended mode on different cards. The cards seem to 
fall into two distinct categories. Once the normal 640x400x256 is set, the 
first category requires only that the Chain4 feature is turned off. Cards in 
the second category require the 640x400x256 mode set, Chain4 off, and further
adjustment of two "clocking" registers. 

The assembly code required for each is shown below.

category 1:

    mov dx, SEQ_INDEX                   ; sequencer register (3C4h)
    mov ax, 00604h                      ; output value 06h to index 04h
    out dx, ax                          ; set Chain4 off


category 2:

    mov dx, SEQ_INDEX                   ; sequencer register (3C4h)
    mov ax, 00604h                      ; output value 06h to index 04h
    out dx, ax                          ; set Chain4 off (bit 3)
    mov dx, CRTC_INDEX                  ; CRT controller register (3D4h)
    mov ax, 0E317h                      ; output value 0E3h to index 17h
    out dx, ax                          ; disable word clocking
    mov ax, 00014h                      ; output value 00h to index 14h
    out dx, ax                          ; disable doubleword clocking

The categories for each of the cards I have tested are listed below, with 
the mode number required to set the normal 640x400x256 shown in brackets:

AHEAD-B   - couldn't get it to work at all    (   )

ATI       - category 1                        (61h)

ET3000    - couldn't get it to work at all    (   )

ET4000    - category 1                        (2Fh)

OAK       - couldn't get it to work at all    (   )

PARADISE  - category 2                        (5Eh)

TRIDENT   - category 2                        (5Ch)

VIDEO7    - category 1                        (66h)

Alternatively the mode can be set with the VESA Set SuperVGA Mode BIOS
call, the VESA SVGA mode number is 100h. Refer to the file "VESASP12.TXT"
for more information on VESA BIOS calls. If this method is used, however,
the actual SVGA chip must still be detected in order to be able to determine 
which method of changing to Xtended mode should be used.

Mode set code is listed below, using Trident as an example. Remove the 
appropriate lines as indicated to change to the category 1 code.

void InitXtended(void)
{
                                      
/* Trident 640x400x256 modeset, using  video BIOS services */
_AX = 0x005C;          
geninterrupt(0x10);    

/* disable Chain4 mode (bit 3, index 04h, port 3C4h) */
outport(0x3C4, 0x0604);

/* *** omit below this point for category 1 cards *** */

/* disable word mode clocking, by setting the Mode Control register */
/*  of the CRT Controller (index 17h, port 3D4h) */
outport(0x3D4, 0xE317);

/* disable doubleword clocking mode, by setting the Underline Location */
/*  register of the CTR controller (index 14h, port 3D4h) */
outport(0x3D4, 0x0014);
}

-----------------------------------------------------------------------------
  Drawing a Pixel
-----------------------------------------------------------------------------

Once the mode has been properly set up, drawing a pixel in Xtended mode is 
almost identical to drawing one in unchained mode 13h or ModeX. The only real 
difference is the screen resolution, which is now twice the size in both 
directions. As a result, Xtended mode has 4 times as many pixels than 320x200, 
using almost all of the 256k that can be addressed this way, so there is only 
one page in Xtended mode.

The following example code shows how to write a single pixel in Xtended mode.
All the Modex tricks, such as dividing the page into its four planes before 
writing to the screen, will work exactly the same in Xtended mode

void XtendedPutPixel (int xcoord, int ycoord, int colour)
{
char far *screen;

/* set map mask register (index 02h, port 3C4h) to required plane */
/*  calculate plane by mod-ing x coordinate by 4 */
outport(0x3C4, (0x0100 << (xcoord % 4)) + 0x0002);

/* calculate address (y * 160 + x div 4) and write pixel */
screen = MK_FP(0xA000, ycoord * 160 + xcoord / 4);
*screen = colour;
}

-----------------------------------------------------------------------------
  Conclusion
-----------------------------------------------------------------------------

  Because of the complications involved in setting up the mode, and the fact
that several brands of SVGA do not appear to support the mode at all,
Xtended mode has limited appeal. I made use of it in a product where graphics
"text" was scrolled up the screen, since it made the scrolling process almost 
twice as fast. However, I also included normal VESA support, which was 
slower but covered more cards. This is how I would recommend use of Xtended 
mode; as a performance enhancer in situations where ModeX-type operations
are useful.

1