China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-28 03:28
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » [Repost] Introduction to VESA (VBE) Programming View 6,693 Replies 25
Original Poster Posted 2003-08-20 00:00 ·  中国 台湾 远传电信
元老会员
★★★★★
Credits 8,312
Posts 3,551
Joined 2003-03-22 00:00
23-year member
UID 1225
Gender Male
Status Offline
Purpose:

To provide a standardized software interface for Super VGA adapters, so that simple software applications can make use of the capabilities of advanced VGA adapters.

Overview:

This standard provides a set of functions that applications can use.

1. To obtain the compatibility of a specified Super VGA device and its unique features.

2. To control hardware operations such as display modes, initialization, and video memory access.

These functions are provided as extensions to the VGA BIOS video services, accessed through interrupt 10h.

Contents:

1. Introduction

2. Goals and objectives

2-1. Video environment information

2-2. Programming support

2-3. Compatibility

2-4. The status of the standard

3. Standard VGA BIOS

4. Super VGA mode numbers

5. CPU video memory control

5-1. Hardware design considerations

5-1-1. Limited by the CPU's 64K/128K address space

5-1-2. Crossing CPU video memory window boundaries

5-1-3. Processing data from different regions

5-1-4. Combining data from different windows

5-2. Different types of hardware windows

5-2-1. Single-window systems

5-2-2. Dual-window systems

6. Extended VGA BIOS

6-1. Status information

6-2. 00h - Return Super VGA information

6-3. 01h - Return Super VGA mode information

6-4. 02h - Set Super VGA mode

6-5. 03h - Return Super VGA mode

6-6. 04h - Save/restore Super VGA state

6-7. 05h - Super VGA video memory window control

6-8. 06h - Set/get logical scan line length

6-9. 07h - Set/get display start

6-10. 08h - Set/get DAC palette control

7. Application examples

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

1. Introduction

This document contains the specification of a standardized interface for extended VGA video modes and functions. It consists of the following structure: standard extended video modes and functions approved by the main VESA committee, as well as non-standard video modes. This allows independent VGA vendors to add the use of extended VGA to applications in a unified manner, by ignoring the need to understand the complex details unique to each VGA hardware implementation.

The subject of this document is to define the need for application software to understand the characteristics of extended VGA video modes and to manipulate the extended memory associated with those video modes.

Readers of this document should already have some understanding of VGA programming at the hardware level and INTEL iAPX real-mode assembly language. Readers unfamiliar with VGA programming should first read the many existing VGA programming tutorials before attempting to understand standard VGA extensions.

2. Goals and objectives

In the PC graphics world, IBM VGA has become the de facto standard. The various existing VGA vendors on the market all ensure compatibility with IBM VGA in terms of BIOS and registers. More and more VGA-compatible products have produced various VGA extensions. These extensions offer higher resolutions, more colors, and some graphics processing capabilities. Fierce competition has improved price/performance, and the end users have benefited.

However, software developers intending to take advantage of the new benefits of the Super VGA environment face some serious problems. Because there is no standard hardware, they have to deal with all kinds of different Super VGA hardware architectures. The lack of a general software interface leads to high costs in designing related software, and it is also technically very difficult. Aside from the VGA products provided by OEMs, there are hardly any VGA products whose powerful features can actually be used by software.

The introduction of the VESA VGA BIOS Extensions is precisely to make up for this deficiency. As a general software interface for Super VGA graphics products, its main purpose is to enable application software and system software to adapt to and exploit the rich features found in the broad range of VGA extensions.

Specifically, the VESA BIOS Extensions are meant to solve the following problems:

1. Return video environment information to applications.

2. Help applications initialize and program the hardware.

2-1. Video environment information

Even now, there is still no standard software mechanism to determine what kind of Super VGA hardware a program is running on. The existence of a display adapter can only be known through OEM-specific product features. This is usually done by reading and testing the I/O ports unique to each OEM vendor. If the hardware environment is unknown, very few (if any) low-level hardware features can be used.

The VESA BIOS Extensions provide some functions for returning information about the video environment. These functions return system information such as detailed data about display modes. Function 00h returns general system-level information, including an OEM identification string. The function also returns a pointer to the supported display modes. Function 01h can be used to obtain detailed information about each supported display mode. Function 03h returns the current display mode.

2-2. Programming support

Because different Super VGA products have different hardware architectures, it is difficult for software to adapt to every environment. But since they are all based on the VGA hardware architecture, the differences mainly lie in display mode initialization and memory mapping. The rest of the architecture is usually not touched, including I/O-mapped registers, the placement of the video buffer in CPU address space, and the location and functions of the DAC.

The VESA BIOS Extensions provide interface functions for different Super VGA hardware devices. The most important is function 02h, which sets the Super VGA display mode. This function frees the application from the monotonous and complicated process of setting display modes. Function 05h provides an interface to the underlying memory mapping hardware. Function 04h allows an application to save and restore Super VGA state without needing to understand any implementation details.

2-3. Compatibility

One major design goal of the VESA BIOS Extensions is to ensure maximum compatibility with the standard VGA environment. Yet it is impossible for BIOS to sacrifice performance in order to achieve compatibility. Another point is to make only minimal modifications to existing VGA BIOS. As with ROM-based devices, RAM-based extensions should also be possible.

2-4. The status of the standard

The purpose of the VESA BIOS Extensions is to provide support for the extended VGA environment. Therefore the underlying hardware is assumed to be VGA. Graphics software should drive Super VGA the same way it drives standard VGA: for example, directly writing to the VGA frame buffer, operating graphics control registers, and directly setting the palette. The hardware need not perform major graphics processing. For this reason, the VESA BIOS Extensions do not provide any graphics output functions, such as bit block transfer, line drawing, or circle drawing.

The restrictions on VESA BIOS Extension functions are due to the very limited ROM space available in existing BIOS devices.

Outside the VESA BIOS Extensions, there are also operations and timings for different monitors. These things are covered in other VESA forums. The purpose of the VESA BIOS Extensions is to provide a standard software interface to Super VGA graphics modes, independent of monitor and monitor timing issues.

3. Standard VGA BIOS

The design goal of the VESA BIOS Extensions is to minimize their impact on the standard VGA BIOS. The functions of the standard VGA BIOS should be modified as little as possible. This is because ROM extensions may exist.

However, two standard VGA BIOS functions are affected by the VESA extensions. They are function 00h (set display mode) and function 0Fh (read current video state). Programs using VESA will not use VGA BIOS function 00h to set the display mode, nor will they use function 0Fh. Instead they use VESA function 02h (set Super VGA mode) and 03h (get Super VGA mode).

To make programs work, VESA recommends that the return value of function 0Fh in the VESA BIOS Extensions (as determined by the OEM) be used with VGA BIOS function 00h to reinitialize the display mode. In this way, the BIOS will effectively record the most recent Super VGA mode.

It is recommended (but not required) that output functions (such as TTY output, scrolling, plotting, etc.) be supported in Super VGA modes. If the BIOS extension does not support these functions, then bit D2 (output function support) in the mode attributes field (returned by VESA BIOS function 01h) will be cleared.

4. Super VGA mode numbers

Standard VGA mode numbers are 7 bits, currently ranging from 00h to 13h. OEMs may define extended display modes in the range 14h-7Fh. The range 80h-FFh cannot be used, because VGA BIOS function 00h (set display mode) uses the seventh bit as a flag indicating whether video memory should be cleared.

Because of the 7-bit limitation on mode numbers, VESA display mode numbers are 15 bits wide. Their values are passed through register BX to VESA BIOS function 02h (set Super VGA mode) to initialize a Super VGA mode.

The format of a VESA mode number is as follows:

D0-D8 mode number

If D8 is 0, it is not a VESA-defined mode

If D8 is 1, it is a VESA-defined mode

D9-D14 reserved by VESA for future expansion (set to 0)

D15 reserved (set to 0)

Therefore, VESA mode numbers start from 100h. This numbering scheme effectively makes standard VGA mode numbers and OEM mode numbers part of the VESA mode number space. This means ordinary VGA display modes can also be set through VESA BIOS function 02h by putting the mode number into BL and clearing the high byte BH. OEM-defined modes can be initialized in the same way.

As an exception, VESA defines the 7-bit mode number 6Ah to represent the 800x600, 16-color, 4-plane display mode. The corresponding 15-bit mode number is 102h.

The following VESA mode numbers have already been defined:

Graphics Text

15-bit mode number 7-bit mode number Resolution Colors 15-bit mode number 7-bit mode number Columns Rows

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

100h --- 640x400 256 108h --- 80 60

101h --- 640x480 256

109h --- 132 25

102h 6Ah 800x600 16 10Ah --- 132 43

103h --- 800x600 256 10Bh --- 132 50

10Ch --- 132 60

104h --- 1024x768 16

105h --- 1024x768 256

106h --- 1280x1024 16

107h --- 1280x1024 256

10Dh --- 320x200 32K 1:5:5:5

10Eh --- 320x200 64k 6:5:5

10Fh --- 320x200 16.8M 8:8:8

110h --- 640x480 32K 1:5:5:5

111h --- 640x480 64K 6:5:5

112h --- 640x480 16.5M 8:8:8

113h --- 800x600 32K 1:5:5:5

114h --- 800x600 64K 6:5:5

115h --- 800x600 16.5M 8:8:8

116h --- 1024x768 32K 1:5:5:5

117h --- 1024x768 64K 6:5:5

118h --- 1024x768 16.5M 8:8:8

119h --- 1280x1024 32K 1:5:5:5

11Ah --- 1280x1024 64K 6:5:5

11Bh --- 1280x1024 16.5M 8:8:8

11Ch --- 1600x1200 256

11Dh --- 1600x1200 32K unverified

11Eh --- 1600x1200 64K unverified


MSN:tiqit2@hotmail.com
Floor 2 Posted 2003-08-20 00:00 ·  中国 台湾 远传电信
元老会员
★★★★★
Credits 8,312
Posts 3,551
Joined 2003-03-22 00:00
23-year member
UID 1225
Gender Male
Status Offline
5. CPU video memory windows

A standard VGA system provides 256K bytes of memory and the corresponding addressing method. Super VGA and its display modes require more than the standard 256K of memory, but for compatibility reasons, that memory address space must be limited to the standard address space. CPU video memory windows provide a way to access extended VGA memory through the standard CPU address space.

This chapter describes several hardware implementations of CPU video memory windows, their effect on software design, and examples related to the VESA VGA BIOS Extensions.

VESA CPU video memory windows do not pursue putting formal, non-standard hardware functions into the BIOS; instead they require formal, standard hardware functions to be placed in the program. This provides the convenience and efficiency of direct hardware access in VGA systems. For example, the VESA BIOS is responsible for mapping video memory into the CPU address space, while the program is responsible for the actual memory reads and writes.

This software/hardware interface is implemented by passing parameters to the program so that it can control the hardware mechanism that maps video memory into CPU address space, and by using those parameters to let the program control the mapping process.

5-1. Hardware design considerations

5-1-1. Limited by the CPU's 64K/128K address space

In order to implement expanded video memory, the first idea is to hand control of access over to the application.

The CPU address space of a typical standard 16-color VGA graphics mode is 64K starting at segment A000h. If each plane is 64K, then the standard VGA space of 256K can be accessed. Access to expanded video memory is done by mapping part of the video memory into the standard VGA CPU address space.

Each Super VGA hardware device can let the program specify where in video memory the mapping into CPU address space begins. It also provides read and write access to the mapped memory, thus giving the program the ability to manipulate video memory at the hardware level.

5-1-2. Crossing CPU video memory window boundaries

Most algorithms in programs that manipulate video have a pair of nested loops: the outer loop follows rows or scan lines, and the inner loop runs along the row or scan line. This inner loop is widely recognized as the performance bottleneck.

If there is a large rectangle in a bad position, part of the required memory may be mapped into the CPU address space, while another part may require changing the mapping before the CPU can access it. It is best to place the remapping of video memory outside the inner loop.

The typical approach is to choose some offset address in video memory for mapping as the start of the CPU address space, so that at least one complete row or scan line can be accessed by the CPU without remapping. No current Super VGA allows the offset to be specified on an 8-bit boundary, and the ability of different Super VGA devices to place the desired video memory at the start of the CPU address space varies greatly.

The number of bytes in video memory that can be positioned between any two nearest bytes in CPU address space is defined as the window function granularity. Some Super VGA systems allow any 4K region of video memory to be mapped to the start of the CPU address space, while others allow any 64K region of video memory to be mapped to the start of the CPU address space. These are examples of granularities of 4K and 64K. This concept is similar to the way an INTEL 16-bit CPU must first change the segment register when accessing bytes (here the segment register, or mapping granularity, is 16 bytes).

Note:

If the granularity is the same as the CPU address space, for example if the minimum number of bits in the video memory mapping function is greater than the maximum number of bits in the CPU address space, then the inner loop will have to contain a test for whether it has crossed out of the CPU address space. This is because if the size of the CPU address space (that is, the granularity here) cannot be evenly divided by the scan line length, then the last scan line in the address space will lie in different video memory and cannot be mapped into the CPU address space at the same time.

5-1-3. Processing data from different regions

Sometimes it is necessary and convenient to move or merge content from two regions of video memory. For example, menus can be stored in off-screen memory, because all VGA hardware supports transferring 32-bit video data through 8-bit CPU reads and writes. If the distance between the source data position and the destination position is greater than the size of the CPU video memory window, then two separate mappable CPU video memory windows must be provided.

5-1-4. Combining data from different windows

The above example of moving data from one CPU video memory window to another only requires reading from one CPU video memory window and writing to the other. Sometimes it is necessary to read from two windows and write to one window. For example, raster operations logically combine data with the source data and output the result.

5-2. Different types of hardware windows

Different hardware implementations of CPU video memory windows can all be supported by the VESA BIOS Extensions. The information needed by a program to understand the hardware type is provided by the BIOS. There are three basic hardware window implementations, discussed in detail below.

The window schemes discussed below do not include differences in granularity.

Also please remember that the CPU address space available to VGA is 128K bytes starting from A000h.

5-2-1. Single-window systems

Some hardware devices provide only one window. This window can be read and written. But if data must be moved within video memory over a distance greater than the CPU address space, performance will drop severely.

5-2-2. Dual-window systems

Many Super VGA implementations provide dual windows in order to move data within video memory. There are two different ways to provide dual windows.

5-2-2-1. Overlapping windows

Some hardware devices distinguish window A and window B by determining whether the CPU is performing a read or write operation on memory. When the two windows are distinguished by the CPU's intended read or write operation, they usually share the same CPU address space. But one window is read-only, and the other is write-only.

5-2-2-2. Non-overlapping windows

Another way a dual-window system distinguishes window A and window B is by looking at the position of the CPU address within the overall VGA CPU address space. The two cannot share CPU address space, but both can be read and written.
MSN:tiqit2@hotmail.com
Floor 3 Posted 2003-08-20 00:00 ·  中国 台湾 远传电信
元老会员
★★★★★
Credits 8,312
Posts 3,551
Joined 2003-03-22 00:00
23-year member
UID 1225
Gender Male
Status Offline
6. Extended VGA BIOS

Some new BIOS calls already support Super VGA modes. To maintain maximum compatibility with the standard VGA BIOS, these BIOS calls all belong to a single function number. This number is passed in the AH register through interrupt 10h.

The designated Super VGA extension function number is 4Fh. This function number is not used in current VGA BIOS implementations. Therefore calling function 4Fh has no effect on standard VGA. The Super VGA standard VS900602 defines subfunctions 00h through 07h; function numbers 08h through 0FFh are reserved.

6-1. Status information

Each function returns a status value in register AX. The format of the status word is as follows:

AL==4Fh function supported

AL!=4Fh function not supported

AH==00h function call succeeded

AH==01h function call failed

When the value in register AH is nonzero, software should treat it as a failure. New error codes will be defined in future VESA BIOS Extensions.

6-2. 00h - Return Super VGA information

The purpose of this function is to provide the calling program with information about the Super VGA environment. The function fills an information block at the address specified by the caller. The information block is 256 bytes in size.

Input: AH = 4Fh Super VGA support

AL = 00h Return Super VGA information

ESI = buffer pointer

Output: AX = status

(other registers unchanged)

The structure of the information block is as follows:

VgaInfoBlock STRUC

VESASignature db 'VESA' ; 4-byte signature

VESAVersion dw ? ; VESA version number

OEMStringPtr dd ? ; pointer to OEM string

Capabilities db 4 dup(?) ; video environment capabilities

VideoModePtr dd ? ; pointer to supported Super VGA modes

TotalMemory dw ? ; number of on-board 64K memory blocks

Reserved db 236 dup(?) ; remainder of VgaInfoBlock

VgaInfoBlock ENDS

This information block is valid only when the VESASignature field contains "VESA".

The VESAVersion field is represented in binary and indicates the level of the VESA standard followed by the Super VGA BIOS. The low byte indicates the minor version number. The current VESA version number is 1.2. Programs using VESA BIOS Extension features will remain valid in future versions. The VESA BIOS Extensions will be fully upward compatible.

OEMStringPtr is a far pointer to an OEM-defined null-terminated string. This string is used by hardware-specific device drivers to identify the display chip, display board, memory configuration, and so on.

The Capabilities field describes the general characteristics supported by the video environment.

The bit definitions are as follows:

D0 = DAC switchable

0 = DAC is fixed width, 6 bits per primary color

1 = DAC width switchable

D1-31 reserved

VideoModePtr points to a list containing all supported Super VGA display modes (both VESA-defined and OEM-defined). Each mode occupies one word (16 bits). The mode number table is terminated by -1 (0FFFFh). Please refer back to Chapter 2 for details of VESA mode numbers. The pointer may point to RAM or ROM depending on the implementation. The table may be a static string in ROM, or it may be an information block generated in RAM at runtime. The program is responsible for checking whether the current mode is available, based on the current mode information returned by the return mode information function (function 01h). Due to the relationship between video memory and the monitor, the current display mode may be unavailable.

TotalMemory indicates the amount of on-board memory. Its value represents the number of 64K memory blocks present on the board.

6-3. 01h - Return Super VGA mode information

This function returns information related to a specified Super VGA display mode. The function fills a mode information block according to the address given by the caller. The maximum size of the mode information block is 256K.

Some of the information returned by this function is implicitly defined by the VESA mode number. But some Super VGA hardware may support display modes other than those defined by VESA. In order to provide access to such modes, the function also returns various related information items.

Input: AH = 4Fh Super VGA support

AL = 01h Return Super VGA mode information

CX = Super VGA mode number (the mode number must be one of the values returned by function 00h)

ESI = 256-byte buffer pointer

Output: AX = status

(other registers unchanged)

The structure of the mode information block is as follows:

ModeInfoBlock STRUC

; mandatory information

ModeAttributes dw ? ; mode attributes

WinAAttributes db ? ; window A attributes

WinBAttributes db ? ; window B attributes

WinGranularity dw ? ; window granularity

WinSize dw ? ; window size

WinASegment dw ? ; window A start segment address

WinBSegment dw ? ; window B start segment address

WinFuncPtr dd ? ; window function pointer

BytesPerScanLine dw ? ; bytes per scan line

; formerly optional information (now mandatory)

XResolution dw ? ; horizontal resolution

YResolution dw ? ; vertical resolution

XCharSize db ? ; character cell width

YCharSize db ? ; character cell height

NumberOfPlanes db ? ; number of memory planes

BitsPerPixel db ? ; bits per pixel

NumberOfBanks db ? ; number of banks

MemoryModel db ? ; memory model type

BankSize db ? ; bank size in K bytes

NumberOfImagePages db ?; number of images

Reserved db 1 ; reserved for page function

; new direct color fields

RedMaskSize db ? ; number of red mask bits

RedFieldPosition db ? ; bit position of red mask

GreenMaskSize db ? ; number of green mask bits

GreenFieldPosition db ? ; bit position of green mask

BlueMaskSize db ? ; number of blue mask bits

BlueFieldPosition db ? ; bit position of blue mask

RsvdMaskSize db ? ; number of reserved mask bits for direct color

RsvdFieldPosition db ? ; bit position of reserved mask for direct color

DirectColorModeInfo db ? ; direct color mode attributes

Reserved db 216 dup(?) ; remainder of mode information block

ModeInfoBlock ENDS

The ModeAttributes field describes several important characteristics of the display mode. Bit D0 indicates whether the mode can be initialized under the current configuration. If the display mode requires a special monitor type and such a monitor is not currently connected, this bit can be used to prevent access. Before VESA BIOS Extensions version 1.2, this bit was not required in order to return correct values after BytesPerScanLine. Bit D1 indicates whether optional information is currently present. VBE 1.2 requires that all parts of ModeInfoBlock except the direct color fields (valid only when the MemoryModel field is 6 (direct color) or 7 (YUV)) be valid. Bit D1 is now reserved, but must be set to 1. Bit D2 indicates whether the BIOS supports functions such as TTY output, scrolling, and pixel output in this mode (it is recommended, not required, that the BIOS support all output functions). If D2 is 1, then the BIOS must support all standard output functions.

The definitions of this field are as follows:

D0 = mode supported by hardware

0 = mode not supported by hardware

1 = mode supported by hardware

D1 = 1 (reserved)

D2 = BIOS supports output functions

0 = BIOS does not support output functions

1 = BIOS supports output functions

D3 = monochrome/color mode (see note below)

0 = monochrome mode

1 = color mode

D4 = mode type

0 = text mode

1 = graphics mode

D5-D15 = reserved

Note: The CRTC address for monochrome mode is 3B4h. The CRTC address for color mode is 3D4h. In monochrome mode attribute controller output, only the third bit (video) and fourth bit (intensity) are significant. Therefore monochrome text mode attributes include off, video, high intensity, and blink. Monochrome graphics mode is a two-plane mode and has extended two-color mode attributes of off, video, high intensity, and blink. The CRTC address of the extended two-color mode is 3D4h. It has one plane and one bit per pixel. Standard VGA modes 06h and 11h are classified as color modes, while modes 07h and 0Fh are classified as monochrome modes.

BytesPerScanLine indicates how many bytes make up each logical scan line. A logical scan line may be equal to or greater than the actual displayed scan line.

WinAAttributes and WinBAttributes describe the attributes of the CPU window configuration, such as whether a window exists and whether it is readable or writable, as follows:

D0 = window support

0 = window not supported

1 = window supported

D1 = window readable

0 = window not readable

1 = window readable

D2 = window writable

0 = window not writable

1 = window writable

D3-D7 = reserved

If windows are not supported (bit D0 of both window A and window B is 0), then the application may assume the video buffer is located in the standard CPU address for that mode's MemoryModel.

WinGranularity indicates the minimum byte size of a window in video memory. If bit D0 of the corresponding WinAttributes is not set, then this value is undefined.

WinSize indicates the size of the window in bytes.

WinASegment and WinBSegment give the segment addresses of the windows in the CPU address space.

WinFuncPtr indicates the address of the CPU video memory window function. The window function can be called through VESA BIOS function 05h, or it can be called directly. A direct call is faster than using interrupt 10h to access the hardware page register, and can be used by high-performance programs. If its value is null, the memory window should be set through function 05h if memory paging is supported.

XResolution and YResolution indicate the width and height of the display mode. In graphics mode these values are in pixels. In text mode they are in character units. Note that in character mode, the resolution in pixels can be obtained by multiplying the X and Y resolutions by the character width and height respectively, if such extended information is available.

XCharSize and YCharSize indicate the size of a character cell.

NumberOfPlanes indicates the number of memory planes available to software in this mode. For the standard VGA 16-color graphics mode, this value is 4. For the standard packed-pixel mode, this value is 1. BitsPerPixel indicates the number of bits needed to define the color of one pixel. For example, the standard VGA 4-plane 16-color graphics mode has a value of 4, while the 256-color packed-pixel graphics mode has a value of 8. The number of bits per pixel per plane can be obtained by dividing the bits per pixel by the number of planes.

MemoryModel indicates the general organization of memory. The model definitions are as follows:

00h = text mode

01h = CGA graphics

02h = HERCULES graphics

03h = 4-plane

04h = packed pixel

05h = non-chain 4, 256-color

06h = direct color

07h = YUV

08h-0Fh = reserved, defined by VESA

10h-FFh = defined by OEM

In VESA Super VGA BIOS Extensions version 1.1 and earlier, OEMs defined direct color modes as 1:5:5:5 and 8:8:8 and 8:8:8:8 (with 16-bit, 24-bit, and 32-bit packed pixels respectively). In version 1.1 and later VESA Super VGA BIOS Extensions, it is recommended that direct color modes use the direct color memory model and the mask sizes and bit positions in the mode information block to describe the pixel format. BitsPerPixel always represents the total number of memory bits occupied by each pixel.

NumberOfBanks indicates the number of banks for grouped scan lines. Dividing the number of scan lines by the number of banks gives a remainder that indicates which bank contains the scan line, while the quotient gives the number of scan lines per bank. For example, CGA graphics mode has two banks, and HERCULES graphics mode has four banks. For modes without scan line banks (such as VGA modes 0Dh-13H), this value is 1.

BankSize indicates the size of a bank (in KB). For CGA and HERCULES graphics modes, this value is 8, meaning each bank is 8192 bytes long. For modes without scan line banks (such as VGA modes 0Dh-13H), this value is 0.

NumberOfImagePages indicates the number of additional complete display images that can fit entirely in VGA memory at one time. If this value is nonzero, the program can load more than one image into VGA memory and alternate between displaying them.

Reserved is reserved for future VESA BIOS Extensions, and for now its value must be one.

RedMaskSize, GreenMaskSize, BlueMaskSize, and RsvdMaskSize define the number of bits of the red, green, blue, and reserved components in a direct color pixel. Bit masks can be generated from these values by a simple shifting algorithm. For example, in a 5:6:5 direct color mode, the mask sizes are 5, 6, 5, and 0 for red, green, blue, and reserved respectively. Note that for the YUV memory model, red is used for V, green for Y, and blue for U. If a mode's pixels have no primary color component, the value should be 0.

RedFieldPosition, GreenFieldPosition, BlueFieldPosition, and RsvdFieldPosition define the bit position of the most significant bit of each color component in direct color mode and YUV mode. Color values can be joined to the pixel by left-shifting according to the position. For example, in a 5:6:5 direct color mode, the positions of red, green, blue, and reserved are 11, 5, 0, and 0 respectively. Note that for the YUV memory model, red is used for V, green for Y, and blue for U. If a mode's pixels have no primary color component, the value should be 0.

DirectColorModeInfo describes important characteristics of the direct color mode. Bit D0 indicates whether the DAC color ramp is fixed or programmable. If the color ramp is fixed, it cannot be changed. If it is programmable, this means the red, green, and blue lookup tables can be loaded through the standard VGA DAC color register BIOS call (AX=1012h). Bit D1 indicates whether the reserved field of the direct color pixel can be used by the program, or whether it is reserved and unusable.

D0 = color ramp fixed/programmmable

0 = color ramp fixed

1 = color ramp programmable

D1 = reserved bits usable/reserved

0 = reserved bits reserved

1 = reserved bits can be used by program

Note:

Version 1.1 and later VESA BIOS Extensions clear unused portions of the information block to zero while still keeping the size at 256 bytes. This gives it upward compatibility with future standards, because newly added fields will use zero as the default value or as an unavailable additional option. Programs intended to remain backward-compatible with VESA BIOS Extensions version 1.0 should pre-initialize a 256-byte buffer before calling return Super VGA mode information.

6-4. 02h - Set Super VGA mode

This function initializes a display mode. Register BX contains the mode to be set. The format of the VESA mode number has already been described in Chapter 2. If the mode cannot be set, the BIOS should keep the video environment unchanged and return an error code.

Input: AH = 4Fh Super VGA support

AL = 02h Set Super VGA display mode

BX = display mode

D0-D14 = display mode

D15 = clear memory flag

0 clear video memory

1 do not clear video memory

Output: AX = status

(other registers unchanged)

6-5. 03h - Return current display mode

This function returns the current display mode in register BX. VESA display mode numbers are described in detail in Chapter 2.

Input: AH = 4Fh Super VGA support

AL = 03h Return current display mode

Output: AX = status

BX = current display mode

(other registers unchanged)

Note:

In the standard VGA BIOS, function 0Fh (read current display state) returns the current display mode in register AL. Bit D7 of AL also returns the state of the memory-clear bit. If memory was not cleared, this bit is set. In the Super VGA function, because the purpose of the function is only to return the display mode, the memory-clear bit is not returned in register BX. If a program wants to obtain the memory-clear bit, it should call VGA BIOS function 0Fh.
MSN:tiqit2@hotmail.com
Floor 4 Posted 2003-08-20 00:00 ·  中国 台湾 远传电信
元老会员
★★★★★
Credits 8,312
Posts 3,551
Joined 2003-03-22 00:00
23-year member
UID 1225
Gender Male
Status Offline
6-6. 04h - Save/restore Super VGA state

This function provides a mechanism for saving and restoring the Super VGA display state. This function is a superset of the three subfunctions of standard VGA BIOS function 1Ch (save/restore display state). The complete Super VGA state (except video memory) can be saved and restored by setting the requested state mask (in register CX) to 000Fh.

Input: AH = 4Fh Super VGA support

AL = 04h Save/restore Super VGA display state

DL = 00h Return save/restore state buffer size

CX = requested state

D0 = save/restore display hardware state

D1 = save/restore display BIOS data state

D2 = save/restore display DAC state

D3 = save/restore Super VGA state

Output: AX = status

BX = number of 64-byte blocks in the state buffer

(other registers unchanged)

Input: AH = 4Fh Super VGA support

AL = 04h Save/restore Super VGA display state

DL = 01h Save Super VGA state

CX = requested state (same as above)

ES:BX = buffer pointer

Output: AX = status

(other registers unchanged)

Input: AH = 4Fh Super VGA support

AL = 04h Save/restore Super VGA display state

DL = 02h Restore Super VGA state

CX = requested state (same as above)

ES:BX = buffer pointer

Output: AX = status

(other registers unchanged)

Note:

Based on the goal of full compatibility with the VGA environment, standard VGA BIOS function 1Ch (save/restore VGA state) was not extended to save Super VGA display state. VGA BIOS compatibility requires function 1Ch to return a specific buffer size with a specific layout, and there is no longer enough space in that layout to hold the Super VGA state.

6-7. 05h - Super VGA video memory window control (set BANK)

This function sets or obtains the position of the specified window in video memory. The function allows direct access to the hardware page register. To make better use of this function, the program should use VESA BIOS function 01h (return Super VGA mode information) to determine the size, position, and granularity of the window.

Input: AH = 4Fh Super VGA support

AL = 05h Super VGA video memory window control

BH = 00h Select Super VGA video memory window

BL = window number

0 = window A

1 = window B

DX = position of the window in video memory (in units of window granularity)

Output: AX = status

(see note below)

Input: AH = 4Fh Super VGA support

AL = 05h Super VGA video memory window control

BH = 01h Return Super VGA video memory window

BL = window number

0 = window A

1 = window B

Output: AX = status

DX = position of the window in video memory (in units of window granularity)

(see note below)

Note:

This function can also be accessed directly by the program through a far call. The BIOS function address can be obtained through VESA BIOS function 01h (return Super VGA information). The mode information block contains the address of this function. Note that the function address is different each time the BIOS is executed, so the function pointer should be obtained after each mode set.

If it is a far call, no status information will be returned to the program. Also, registers AX and DX will be destroyed. Therefore, if the values of AX and DX need to be preserved, preparation should be made before the far call.

To make a far call, the program must load the parameters into BH, BL, and DX (for setting the window), but does not need to load AH and AL.

6-8. 06h - Set/get logical scan line length

This function sets or obtains the logical scan line length. The function allows the program to establish a logical video memory buffer larger than the display area. Function 07h can then allow the program to set the display start position.

Input: AH = 4Fh Super VGA support

AL = 06h Logical scan line length

BL = 00h Select scan line length

CX = desired width (in pixels)

Output: AX = status

BX = bytes per scan line

CX = actual pixels per scan line

DX = maximum number of scan lines

Input: AH = 4Fh Super VGA support

AL = 06h Logical scan line length

BL = 01h Return scan line length

Output: AX = status

BX = bytes per scan line

CX = actual pixels per scan line

DX = maximum number of scan lines

Note:

The desired width in pixels may not be achievable because of VGA hardware limitations. The next larger value that can provide the requested number of pixels will be chosen, and the actual pixel count will be returned in CX. When added to a pointer into video memory, BX returns the pointer increment to the next scan line. For example, in mode 13 this value is 320, but in mode 12 it is 80. DX returns the number of logical scan lines based on the new scan line length and the total loaded memory available in that mode. This function is still valid in text mode. In text mode, the program should use a BIOS function to find the current character cell width, multiply it by the desired number of characters per row, and put the result into register CX.

6-9. 07h - Set/get display start

This function selects the pixel from the logical page that will be displayed in the upper-left corner. This function can be used to pan or scroll a logical screen larger than the physical display. It can also rapidly switch between two different display screens to produce a double-buffered animation effect.

Input: AH = 4Fh Super VGA support

AL = 07h Display start control

BH = 00h Reserved, must be 0

BL = 00h Select display start

CX = first pixel in scan line

DX = first scan line

Output: AX = status

Input: AH = 4Fh Super VGA support

AL = 07h Display start control

BL = 01h Return display start

Output: AX = status

BH = 00h Reserved as 0

CX = first pixel in scan line

DX = first scan line

Note:

This function is still valid in text mode. In text mode, the program can obtain the current character cell width through a BIOS function, multiply it by the desired starting character column, and place this value into register CX. Likewise, multiply the character height by the desired row number and place this into register DX.

6-10. 08h - Set/get DAC palette control

This function queries and selects the operating mode of the DAC palette. Some DACs provide selectable 6-bit, 8-bit, or even more bits for RGB color component definitions. On a standard or VESA set Super VGA mode (AX = 4F02h) call, it is reset by default to 6 bits per color.

Input: AH = 4Fh Super VGA support

AL = 08h Set/get DAC palette control

BL = 00h Set palette width

BH = desired number of color bits (6 for standard VGA)

Output: AX = status

BH = current number of color bits (6 for standard VGA)

Input: AH = 4Fh Super VGA support

AL = 08h Set/get DAC palette control

BL = 01h Get DAC palette width

Output: AX = status

BH = current number of color bits (6 for standard VGA)

Note:

The program can determine whether the DAC is switchable by querying bit D0 of the compatibility field in the VGA information block returned by the VESA return Super VGA information function (AX = 4F00h). Only then should the program attempt to set the DAC palette to the desired width. If the VGA cannot use the requested palette width, a slightly lower value that the Super VGA can use will be selected. The final palette width is returned.

7. Application examples

The following explains in order how a program interfaces with the VESA BIOS Extensions. Assume the program already understands VESA and is able to call VESA BIOS functions. But the program is not meant to support only VESA-defined display modes. So before setting a display mode, it must first query which display modes are available.

1. The program first allocates a 256-byte buffer. This area is used to store the video environment information returned by the VESA BIOS. Some programs need to allocate space statically, while others can dynamically obtain temporary buffers through system calls.

2. The program then calls VESA BIOS function 00h (return Super VGA information). If after the function call the value in register AX is not 004Fh, then the program can determine that no VESA BIOS exists. If AX contains no error code, the function call succeeded. The buffer has been filled by the VESA BIOS Extensions with all kinds of information. The program can determine whether this is a valid VESA information block by checking whether the characters at the start of the block are 'VESA'. The program can also check the VESA version field to see whether the VESA BIOS Extensions provide sufficient functions. The program can also use the OEM string to locate OEM-specific information.

Finally, the program can use the display mode pointer to obtain the list of display modes supported by the Super VGA.

3. The program then creates a new buffer and calls VESA BIOS function 01h (return Super VGA mode information) to obtain detailed information about the supported display modes. Using the display mode pointer obtained in step 2, the program calls this function with each new mode number as the parameter until it finds a suitable display mode. If there is no suitable one, the program is free to give up. The return Super VGA mode information function fills a program-specified buffer with information describing the details of the display mode. The data block contains all the advantages of the display mode that the program can make use of. The program should check the mode attributes field to determine whether the mode is supported. That is, check bit D0; if D0 is cleared, then the mode is not supported by the hardware. This situation may occur when a special monitor is required or when the monitor is absent.

4. After the program selects a display mode, the next step is initialization. But first the program must save the existing display mode. As long as the program is still running, that mode can be restored. To obtain the existing display mode, VESA BIOS function 03h (get Super VGA mode) may be used. If the current mode is not VESA-defined (standard VGA or OEM-defined), then the low byte of the mode number is filled and the high byte is reserved.

5. To initialize the display mode, the program should use VESA BIOS function 02h (set Super VGA display mode). From then on the program has full access to VGA hardware and video memory.

6. When the program is about to exit, it should restore the previous display state. That is, use the previous mode number obtained in step 4 and set the display mode in the manner of step 5. Then exit the program.
MSN:tiqit2@hotmail.com
Floor 5 Posted 2003-08-23 00:00 ·  中国 福建 三明 广电网
高级用户
★★
苏醒的沉睡者
Credits 659
Posts 217
Joined 2003-02-15 00:00
23-year member
UID 930
Gender Male
From 福建
Status Offline
Thanks
好久没碰Dos,手都生了,赶紧回来练练.嘿嘿
Floor 6 Posted 2003-09-11 00:00 ·  中国 广东 深圳 南山区 电信
初级用户
★★
鹰击长空
Credits 271
Posts 61
Joined 2003-08-20 00:00
22-year member
UID 8964
Gender Male
Status Offline
Thanks in advance!
适合的,就是最好的!
DOS,永远的初恋情人。
Floor 7 Posted 2003-10-24 00:00 ·  中国 湖南 长沙 电信
初级用户
★★
Credits 255
Posts 54
Joined 2003-10-24 00:00
22-year member
UID 11864
Gender Male
Status Offline
Thanks for the hard work
Thank you ^_^
Floor 8 Posted 2003-10-27 00:00 ·  中国 广西 南宁 电信
初级用户
Credits 108
Posts 2
Joined 2003-08-12 00:00
22-year member
UID 8446
Gender Male
Status Offline
Big bump·!!~~~~~
Floor 9 Posted 2003-11-12 00:00 ·  中国 上海 联通
初级用户
Credits 182
Posts 27
Joined 2003-11-12 00:00
22-year member
UID 12731
Gender Male
Status Offline
Floor 10 Posted 2003-12-11 00:00 ·  中国 广西 桂林 教育网
初级用户
Credits 125
Posts 9
Joined 2003-12-10 00:00
22-year member
UID 13941
Gender Male
Status Offline
One word: Awesome
QQ:13688252
DOS 是我的初恋,ASM 是我的母语
Floor 11 Posted 2003-12-11 00:00 ·  中国 江苏 南京 电信
初级用户
Credits 122
Posts 6
Joined 2003-02-03 00:00
23-year member
UID 837
Gender Male
Status Offline
VESA mode codes are not fixed. For example, 114h in one graphics card's VESABIOS might be 800*600*64K, while on another card it might be 1024*768*256, so setting the mode is not that simple.
Floor 12 Posted 2003-12-12 00:00 ·  中国 浙江 温州 电信
初级用户
Credits 110
Posts 4
Joined 2003-12-09 00:00
22-year member
UID 13913
Gender Male
Status Offline
I don't understand it!!!!!!!!!!!!!!!! You idiot!!!!!!!!!!!!!!!!
Floor 13 Posted 2003-12-22 00:00 ·  中国 重庆 渝中区 电信
初级用户
Credits 106
Posts 3
Joined 2003-12-22 00:00
22-year member
UID 14347
Gender Male
Status Offline
very very good!!!
Just asking, where did you find it?
Floor 14 Posted 2003-12-31 00:00 ·  中国 北京 昌平区 联通
初级用户
Credits 123
Posts 5
Joined 2003-12-30 00:00
22-year member
UID 14638
Gender Male
Status Offline
Awesome!!!
Floor 15 Posted 2004-01-07 00:00 ·  中国 四川 成都 电信
初级用户
Credits 113
Posts 5
Joined 2004-01-06 00:00
22-year member
UID 15027
Gender Male
Status Offline
Good, nice and straightforward
Forum Jump: