Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Tutorial - Mode13H
Author:Arkon
Category:DOS Graphics
Uploaded at:29-May-03
Views:7831
Mode13h is a screen resolution of 320x200 pixels with 256 colors (8bit color depth). This means each pixel 'takes' one byte (8bits, 0 - 255).
The screen contains (320x200=)64000 pixels. These 64000 pixels are stored in the Video Memory.
The video card reads the data from the Video Memory and sends it to the Monitor automatically.
You access the Video Memory as an array of 64000 bytes.
The Video Memory starting address (segment) is 0xA000 (0x means Hex), this value is constant in every computer and allocated for the Video Memory.

First you need to change the screen resolution to Mode 13h.

void init_mode13h()
{
 asm { 
  mov ax, 0x13 // We set ax to our mode number (13h)
  int 0x10     // We tell the BIOS to switch mode
 } 
}

The basic of drawing anything on the screen is drawing a PIXEL.
To draw a pixel by X,Y coordinates you need to calculate its position (offset) on the Video Memory:
You see the screen as a 2D surface, but in the Video Memory it is stored as a 1D array, like a line (linear).
For example: The first row starts at offset 0, all the pixels of the first row are stored from 0 to 319, the second row starts at offset 320 and ends at offset 639 and so on...
The Monitor passes a row every 320 pixels.
Therefore, the formula of getting to the offset of a certain row is: Y*320 and to get the pixel's offset we just add the column number: Y*320+X
We just treat the screen as a 2D array for comfort.

Here is an example of a coordinate on the screen.
Its coordinates: X = 3, Y = 4, Color = RED:

Here is the offset of that coordinate in the video memory:

Put Pixel:

unsigned char *video_memory = (unsigned char *) 0xA0000000L;

void put_pixel(int x, int y, unsigned char color)
{
 video_memory[y * 320 + x] = color;
} 

In the end of your program you better return to text-mode:

void init_textmode() // 80x25 Chars with 16 colors
{
 asm
 {
  mov ax, 0x3 // We set ax to textmode's number (3)
  int 0x10
 }
}

Source Code:
DJGPP - mode13h.c
Turbo C - mode13h.cpp

NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[117061]
2D Rotated Rectangles Collision Detection[88987]
Keyboard Hook[77325]
UDP[65879]
HTTP Proxy[41217]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11561]
PS2 Mouse Driver[6959]
Wave Format Player[5792]
Reading FAT12[5620]
CodeGuru[5360]


All rights reserved to RageStorm © 2009