

Mode 13h is the standard 256-color mode on
VGA
Video Graphics Array (VGA) is a video display controller and accompanying de facto graphics standard, first introduced with the IBM PS/2 line of computers in 1987, which became ubiquitous in the IBM PC compatible industry within three years. T ...
graphics hardware
Graphics hardware is computer hardware that generates computer graphics and allows them to be shown on a display, usually using a graphics card (video card) in combination with a device driver to create the images on the screen.
Types
Grap ...
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 Personal Computer, IBM PC, IBM Personal Computer XT, XT, IBM Personal Computer/AT, AT, and IBM PC Convertible, PC Co ...
. It has a resolution of
pixels
In digital imaging, a pixel (abbreviated px), pel, or picture element is the smallest addressable element in a raster image, or the smallest addressable element in a dot matrix display device. In most digital display devices, pixels are the sma ...
.
It was used in
computer games
A video game or computer game is an electronic game that involves interaction with a user interface or input device (such as a joystick, game controller, controller, computer keyboard, keyboard, or motion sensing device) to generate visual fe ...
and
art
Art is a diverse range of cultural activity centered around ''works'' utilizing creative or imaginative talents, which are expected to evoke a worthwhile experience, generally through an expression of emotional power, conceptual ideas, tec ...
/
animation software
Computer animation is the process used for digitally generating moving images. The more general term computer-generated imagery (CGI) encompasses both still images and moving images, while computer animation refers to moving images. Modern ...
of the late 1980s and early to mid-1990s. "13h" refers to the number of the mode in the VGA
BIOS
In computing, BIOS (, ; Basic Input/Output System, also known as the System BIOS, ROM BIOS, BIOS ROM or PC BIOS) is a type of firmware used to provide runtime services for operating systems and programs and to perform hardware initialization d ...
. The "h" stands for
hexadecimal
Hexadecimal (also known as base-16 or simply hex) is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of sixteen. Unlike the decimal system representing numbers using ten symbo ...
.
Mode 13h provides
programmers
A programmer, computer programmer or coder is an author of computer source code someone with skill in computer programming.
The professional titles ''software developer'' and ''software engineer'' are used for jobs that require a program ...
with a linear block of
video memory
Video random-access memory (VRAM) is dedicated computer memory used to store the pixels and other graphics data as a framebuffer to be rendered on a computer monitor. It often uses a different technology than other computer memory, in order to b ...
, 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
The aspect ratio of a geometry, geometric shape is the ratio of its sizes in different dimensions. For example, the aspect ratio of a rectangle is the ratio of its longer side to its shorter side—the ratio of width to height, when the rectangl ...
of a
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 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 2
14 (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 RGB channel. The
color palette
In color theory, a color scheme is a combination of 2 or more colors used in aesthetic or practical design. Aesthetic color schemes are used to create style and appeal. Colors that create a color harmony, harmonious feeling when viewed togethe ...
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 palette data was often copied from the low level ports one at a time to a spot in memory after the screen
data
Data ( , ) are a collection of discrete or continuous values that convey information, describing the quantity, quality, fact, statistics, other basic units of meaning, or simply sequences of symbols that may be further interpreted for ...
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, 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
13h
refers to the number 19 written in the hexadecimal notation in a format typical of assembly code for Intel processors. In
the C programming language
''The C Programming Language'' (sometimes termed ''K&R'', after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the C programming langu ...
, hexadecimal 13 is written
0x13
.
In
x86 assembly language
x86 assembly language is a family of Low-level programming language, low-level programming languages that are used to produce object code for the x86 class of processors. These languages provide backward compatibility with CPUs dating back to th ...
the video mode is entered by setting the ''AL'' register to 13h, the ''AH'' register to 0, and then calling
BIOS interrupt 10h.
The two 8-bit registers ''AL'' and ''AH'' comprise the 16-bit ''AX'' register.
Although 13
hex is 19 in decimal, 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 ...
's screen mode numbering scheme it is simply screen mode 13 (not hexadecimal).
Many QuickBASIC screen modes have numbers which differ from the BIOS modes on which they are based.
Source code examples
Assembly code to enter Mode 13h:
mov ax, 0013h
int 10h
As an illustration of mode 13h in a video game source code,
Wolfenstein 3D
''Wolfenstein 3D'' is a 1992 first-person shooter game developed by id Software and published by Apogee Software and FormGen for DOS. It was inspired by the 1981 Muse Software video game '' Castle Wolfenstein'', and is the third installment ...
includes this function in a file named "ID_VL.C". It enters mode 13h by using two assembly instructions (prefixed with
asm
) embedded in the C source code.
[https://github.com/id-Software/wolf3d/blob/master/WOLFSRC/ID_VL.C#L108] This function also executes three other functions.
void VL_SetVGAPlaneMode (void)
''
Wolfenstein 3D
''Wolfenstein 3D'' is a 1992 first-person shooter game developed by id Software and published by Apogee Software and FormGen for DOS. It was inspired by the 1981 Muse Software video game '' Castle Wolfenstein'', and is the third installment ...
source code (circa 1992) which calls the BIOS to change to mode 13h.''
References
{{reflist
External links
David Brackeen's 256-Color VGA Programming in CAssembler for Dummies: Mode 13hIBM PS 2 Hardware Interface Technical Reference
Computer display standards