This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages) (Learn how and when to remove this message)
|


Mode 13h is the standard 256-color mode onVGAgraphics hardware introduced in 1987 with theIBM PS/2. It has a resolution of320 × 200pixels.[1] "13h" refers to the number of the mode in the VGABIOS. The "h" stands forhexadecimal.
Mode 13h providesprogrammers with a linear320 × 200 block ofvideo memory, 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 theaspect ratio of a320 × 200resolution screen for use on a4:3 display, Mode 13h does not havesquare pixels.[2]
This sectionmay containoriginal research. Pleaseimprove it byverifying the claims made and addinginline citations. Statements consisting only of original research should be removed.(February 2019) (Learn how and when to remove this message) |
Mode 13h is something of a curiosity, because the VGA is aplanar device from ahardware 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 memoryaperture, 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 (seeMode 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.
Unlike SVGA and higher color depths, Mode 13h, part of theMCGA set of video modes, has18 bits of color, 6 per RGB channel. Thecolor palette data is not stored in memoryper se, but rather modified, read and written to by low level I/O port calls, to theDAC registers.
The palette data was often copied from the low level ports one at a time to a spot in memory after the screendata 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.
An alternative planar 256-color mode is available by disabling Chain 4 mode (unchaining). Video modes created using this technique are collectively calledMode 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 thePS/2 Hardware Interface Technical Reference.
13h refers to the number 19 written in the hexadecimal notation in a format typical of assembly code for Intel processors. Inthe C programming language, hexadecimal 13 is written0x13.
Inx86 assembly language the video mode is entered by setting theAL register to 13h, theAH register to 0, and then callingBIOS interrupt 10h.[1] The two 8-bit registersAL andAH comprise the 16-bitAX register.
Although 13hex is 19 in decimal, inQuickBASIC's screen mode numbering scheme it is simply screen mode 13 (not hexadecimal).[3] Many QuickBASIC screen modes have numbers which differ from the BIOS modes on which they are based.[4]
Assembly code to enter Mode 13h:
movax,0013hint10h
As an illustration of mode 13h in a video game source code,Wolfenstein 3D includes this function in a file named "ID_VL.C". It enters mode 13h by using two assembly instructions (prefixed withasm) embedded in the C source code and the switches to a custom planar mode allowing triple buffering.[5]
voidVL_SetVGAPlaneMode(void){asmmovax,0x13asmint0x10VL_DePlaneVGA();VGAMAPMASK(15);VL_SetLineWidth(40);}
Wolfenstein 3D source code (circa 1992) which calls the BIOS to change to mode 13h.