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.
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.
Here is the offset of that coordinate in the video memory:
In the end of your program you better return to text-mode: