Mode 13h

From Infogalactic: the planetary knowledge core
Jump to: navigation, search
Default VGA 256-color palette

Mode 13h is an IBM VGA BIOS mode. It is the specific standard 256-color mode on IBM's VGA graphics hardware. It features a resolution of 320×200 pixels.[1] It was used extensively in computer games and art/animation software of the late 1980s and early to mid-1990s. Since the earlier CGA and EGA graphics standards provided a similar resolution mode, its use simplified conversions to those formats.

Mode 13h provided programmers with a straightforward manner of accessing video memory (nicknamed chunky graphics), at the expense of not being able to access other useful features of the VGA hardware.

Given the aspect ratio of a 320×200 resolution screen for use on a 4:3 display, Mode 13h does not have square pixels.

Technical layout

Mode 13h is something of a curiosity, because the VGA is a planar device from a hardware perspective, and not suited to chunky graphics operation. The VGA has 256 KiB of video memory consisting of 4 banks of 64 KiB, known as planes (or 'maps' in IBM's documentation). Planar memory arrangement splits the pixels horizontally into groups of four. For any given byte in the PC's 64 KiB video memory aperture, four pixels can be accessed on screen by selecting the required plane(s). This is more complicated for the programmer, but allows access to all of the available video memory and other benefits (see Mode X).

Mode 13h, however, allows the programmer to access the VGA in "chunky" (linear) fashion, where each consecutive address in the aperture represents a consecutive pixel on screen. Planes need not be manipulated to select the correct pixels to modify or read. This is achieved using the VGA 'Chain 4' setting in which the lowest two bits of the 16 bit aperture address are used to select the plane to write to/read from. The upshot is that the programmer has a simple access model; the downside is that now only 214 (16 KiB) of the video plane's address space are accessible (the other 2 bits being used to select planes) so only a total of 64 KiB is addressable (4 × 16 KiB). The upper 48 KiB of each plane remains unused in this mode.

Accessing larger amounts of video RAM in a linear 256-colour mode was made possible in later Super VGAs using a Bank Switching technique.

Although undocumented and not a standard mode in the Video BIOS, an alternative planar 256-color mode is available by disabling Chain 4 mode (unchaining); video modes created using this technique are collectively called Mode X.

Unlike SVGA and higher color depths, Mode 13h, part of the MCGA set of video modes, has 18 bits of color, 6 per channel. The palette data is not stored in memory per se, but rather modified, read and written to by low level I/O port calls, to the DAC registers.

The color palette data was often copied from the low level ports one at a time to a spot in memory after the screen data so the colors could be saved along with the pixels they belonged to. A mode 13h screen capture is merely 64000 bytes of values from 0 to 255, each an index of a color from a known palette of multiple colors. If the color palette is jumbled or totally wrong, a green leaf will appear blue, or any other possible color, depending on what that particular color was set for, which particular one out of 256.

Due to the way chunks of memory are allocated in such an environment, the bytes at high address &hA000 low address 64000 to 64768, can be written to with no negative effects. This lets the programmer save the additional bytes, 256 (colors) × 3 (color channels) = 768 bytes, at the end of the screen capture file. These have to be read back out again and written to the color port for them to change, when an image containing a footer of color info gets loaded. A method used with this was to have a global palette, and match the colors from an old color palette, to a new color palette. This meant changing the index of each pixel, where it would point to a near perfect match of one color from old to new color set. This also had drawbacks, as sometimes there were not enough gradients, and artifacts and such would appear.

It was also good sense to keep the first 16 colors, as they were, and modify colors 16 - 255. This would make sure any GUI or UI had reliable colors. Otherwise a user might be presented with a message or bit of text which was unreadable, or very difficult to read.

It is not essential to set the graphics mode through the BIOS; it is possible to switch graphics mode in 32-bit protected mode, if a little more complicated. It involves writing size data to the VGA controller. Set VGA graphics mode without BIOS in C

Notation

The "h" in Mode 13h stands for "hexadecimal"; it is actually VGA mode 19 in decimal. In x86 assembly language the mode is entered when AL is 13h, AH is 0 and BIOS INT 10h is executed.[1] However, the "h" is sometimes dropped for languages that don't support that method of notation; for example, it is known as screen mode 13 in QuickBasic and its spinoffs.[2] In C, hexadecimal 13 is written 0x13.

References

  1. 1.0 1.1 Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.

External links