Mode 13h
   HOME

TheInfoList



OR:

Mode 13h is the standard 256-color mode on VGA graphics hardware introduced in 1987 with the
IBM PS/2 The Personal System/2 or PS/2 is IBM's second generation of personal computers. Released in 1987, it officially replaced the IBM PC, XT, AT, and PC Convertible in IBM's lineup. Many of the PS/2's innovations, such as the 16550 UART (serial p ...
. It has a resolution of 320×200
pixels In digital imaging, a pixel (abbreviated px), pel, or picture element is the smallest addressable element in a raster image, or the smallest point in an all points addressable display device. In most digital display devices, pixels are the sm ...
. It was used extensively in computer games and
art Art is a diverse range of human activity, and resulting product, that involves creative or imaginative talent expressive of technical proficiency, beauty, emotional power, or conceptual ideas. There is no generally agreed definition of wha ...
/
animation software Computer animation is the process used for digitally generating animations. The more general term computer-generated imagery (CGI) encompasses both static scenes (still images) and dynamic images (moving images), while computer animation refer ...
of the late 1980s and early to mid-1990s. "13h" refers to the number of the mode in the VGA BIOS. The "h" stands for hexadecimal. Mode 13h provides programmers with a linear 320x200 block of
video memory Dynamic random-access memory (dynamic RAM or DRAM) is a type of random-access semiconductor memory that stores each bit of data in a memory cell, usually consisting of a tiny capacitor and a transistor, both typically based on metal-oxid ...
, where each byte represents one pixel. This allows ease of programming at the expense of access to 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 details

Mode 13h is something of a curiosity, because the VGA is a
planar Planar is an adjective meaning "relating to a plane (geometry)". Planar may also refer to: Science and technology * Planar (computer graphics), computer graphics pixel information from several bitplanes * Planar (transmission line technologies), ...
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 X is an alternative 256-color graphics display mode of the IBM VGA graphics hardware that was popularized by Michael Abrash. It was first published in July 1991 in '' Dr. Dobb's Journal'', and republished in chapters 47-49 of Abrash's ''Graph ...
). 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. 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 In the pursuit of knowledge, data (; ) is a collection of discrete Value_(semiotics), values that convey information, describing quantity, qualitative property, quality, fact, statistics, other basic units of meaning, or simply sequences of sy ...
so the colors could be saved along with the pixels they belonged to. A mode 13h screen capture is merely 64,000 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 in segment 0xA000 from offset 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 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.


Variants

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 Mode X is an alternative 256-color graphics display mode of the IBM VGA graphics hardware that was popularized by Michael Abrash. It was first published in July 1991 in '' Dr. Dobb's Journal'', and republished in chapters 47-49 of Abrash's ''Graph ...
, though the original use of that term was for a VGA mode which also had square pixels. While these modes (along with very many other possible VGA modes) were not specifically documented by IBM, the VGA hardware functions and features used to implement them were documented at least as early as 1988, in the ''PS/2 Hardware Interface Technical Reference''.


Notation

In
x86 assembly language x86 assembly language is the name for the family of assembly languages which provide some level of backward compatibility with CPUs back to the Intel 8008 microprocessor, which was launched in April 1972. It is used to produce object code for t ...
the mode is entered when ''AL'' is 13h, ''AH'' is 0 and BIOS INT 10h is executed. 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 Microsoft QuickBASIC (also QB) is an Integrated Development Environment (or IDE) and compiler for the BASIC programming language that was developed by Microsoft. QuickBASIC runs mainly on DOS, though there was also a short-lived version for the c ...
and its spinoffs. QuickBASIC has its own screen mode numbering scheme, and many QuickBASIC screen modes have numbers which differ from the BIOS modes on which they are based.A major example is QuickBASIC screen mode 0, which covers all of the BIOS text modes 00h..03h. Also, QuickBASIC screen modes 1 and 2 correspond to the CGA BIOS modes 04h through 06h. Further note that QuickBASIC has modes for the Hercules graphics mode, which has no standard BIOS support at all, and for Olivetti/AT&T extended-CGA graphics modes. In C, hexadecimal 13 is written 0x13.


References

{{reflist


External links


David Brackeen's 256-Color VGA Programming in C

Assembler for Dummies: Mode 13h
Computer display standards