Mode 13h
Encyclopedia
Mode 13h is the IBM VGA BIOS
BIOS
In IBM PC compatible computers, the basic input/output system , also known as the System BIOS or ROM BIOS , is a de facto standard defining a firmware interface....

 mode number for a specific standard 256 color mode on IBM's VGA graphics hardware
Hardware
Hardware is a general term for equipment such as keys, locks, hinges, latches, handles, wire, chains, plumbing supplies, tools, utensils, cutlery and machine parts. Household hardware is typically sold in hardware stores....

. It features a resolution of 320×200 pixels and was used extensively in computer games and art/animation software of the late 1980s and early- to mid-1990s. Mode 13h provides programmers with a straightforward manner of access (nicknamed chunky graphics) to video memory at the expense of not being able to use some useful features that the VGA hardware was otherwise capable of providing. Due to the aspect ratio
Aspect ratio (image)
The aspect ratio of an image is the ratio of the width of the image to its height, expressed as two numbers separated by a colon. That is, for an x:y aspect ratio, no matter how big or small the image is, if the width is divided into x units of equal length and the height is measured using this...

 of a 320×200 resolution
Display resolution
The display resolution of a digital television or display device is the number of distinct pixels in each dimension that can be displayed. It can be an ambiguous term especially as the displayed resolution is controlled by all different factors in cathode ray tube , flat panel or projection...

 screen, 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 somewhat unsuited for chunky graphics operation. It was made possible by a hardware trick. In order to understand how Mode 13h was possible, one must consider the VGA's memory layout:
The VGA's 256KiB
Kilobyte
The kilobyte is a multiple of the unit byte for digital information. Although the prefix kilo- means 1000, the term kilobyte and symbol KB have historically been used to refer to either 1024 bytes or 1000 bytes, dependent upon context, in the fields of computer science and information...

 of video memory is not directly available to the programmer
Programmer
A programmer, computer programmer or coder is someone who writes computer software. The term computer programmer can refer to a specialist in one area of computer programming or to a generalist who writes code for many kinds of software. One who practices or professes a formal approach to...

 and is accessed via a 64KB 'window' in the PC's real mode
Real mode
Real mode, also called real address mode, is an operating mode of 80286 and later x86-compatible CPUs. Real mode is characterized by a 20 bit segmented memory address space and unlimited direct software access to all memory, I/O addresses and peripheral hardware...

 address space. The Video RAM is actually a bank of 4 planes, 64KB each. By manipulating the VGA's control registers the programmer can decide how some or all of these 4 planes will be affected by each write or read operation. In 256 color mode each byte in a plane represents a single pixel. On the first line of the screen pixels 0, 4, 8, 12 etc. are all contained in memory plane 0, while pixels 1, 5, 9, 13 etc. are contained in memory plane 1 and so on. A single byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

 written to the 64K window, when all planes are enabled can write up to 4 pixels (of the same value) at once. Through a combination of the 64K window available, and the selection of one of the four planes (an effective extra two bit
Bit
A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...

s of address space), this allows the manipulation of the total 256K video memory.

Mode 13h, however, allows the programmer to access the VGA in "chunky" (linear) fashion, where each consecutive address represents a consecutive pixel on screen. Planes need not be manipulated to select the correct pixels to modify or read.

This is made possible because in Mode 13h the hardware uses the last two bits of the address (in the 64K window) to select the plane to write to. The upshot is that the programmer has a simple access model; the downside is that three quarters of the video memory is now inaccessible (we can now only access a total of 64K of display memory through the window, rather than 256K that is accessible indirectly by manipulating the planes). A simple bank switching
Bank switching
Bank switching is a technique to increase the amount of usable memory beyond the amount directly addressable by the processor. It can be used to configure a system differently at different times; for example, a ROM required to start a system from diskette could be switched out when no longer...

 method could have made the remaining memory available, and indeed bank switching was made available on Super VGAs to access the larger VRAMs these devices sported.

Although never documented by IBM, an alternative planar 256 color mode is available by "unchaining" the video ram; video modes created using this technique are collectively called Mode X
Mode X
Mode X is an alternative video graphics display mode of the IBM VGA graphics hardware that was popularized by Michael Abrash, first published in July 1991 in Dr...

.

Unlike SVGA and higher color depths, Mode 13h, part of the MCGA
MCGA
MCGA may refer to*IBM Multicolor Graphics Array*Maritime and Coastguard Agency, in the United Kingdom...

 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
Digital-to-analog converter
In electronics, a digital-to-analog converter is a device that converts a digital code to an analog signal . An analog-to-digital converter performs the reverse operation...

 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
Gui
Gui or guee is a generic term to refer to grilled dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients. The term derives from the verb, "gupda" in Korean, which literally...

 or UI
User interface
The user interface, in the industrial design field of human–machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the...

 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
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

"; it is actually VGA mode 19 in decimal. In x86 assembly language
X86 assembly language
x86 assembly language is a family of backward-compatible assembly languages, which provide some level of compatibility all the way back to the Intel 8008. x86 assembly languages are used to produce object code for the x86 class of processors, which includes Intel's Core series and AMD's Phenom and...

 the mode is entered when AL is 13h, AH is 0 and BIOS INT 10
INT 10
INT 10H or INT 16 is shorthand for BIOS interrupt call 10hex, the 17th interrupt vector in an x86-based computer system. The BIOS typically sets up a real mode interrupt handler at this vector that provides video services...

h 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
QuickBASIC
Microsoft QuickBASIC is an Integrated Development Environment and compiler for the BASIC programming language that was developed by Microsoft. QuickBASIC runs mainly on DOS, though there was a short-lived version for Mac OS...

 and its spinoffs. In C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, hexadecimal 13 is written 0x13.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK