Home arrow C++ arrow Page 2 - Video Memory Programming in Text Mode
C++

Video Memory Programming in Text Mode


Nowadays we take so many things for granted. This isn't necessarily a bad thing, as knowing that performing a certain task will usually yield the same result can be a blessing. Nevertheless, some basic knowledge of how a thing gets done lets you better understand the world in which we live. Therefore, today I invite anyone who likes to code in any of the popular languages to see how a word gets printed out on the console screen.

Author Info:
By: Gabor Bernat
Rating: 4 stars4 stars4 stars4 stars4 stars / 10
March 29, 2010
TABLE OF CONTENTS:
  1. · Video Memory Programming in Text Mode
  2. · Where to copy
  3. · The code
  4. · What do we have in the end?

print this article
SEARCH DEVARTICLES

Video Memory Programming in Text Mode - Where to copy
(Page 2 of 4 )

Please keep in mind that this is a really simplified view; there are a couple of limitations when implementing this in the real world that complicate the proper execution. Nevertheless, this explanation will allow you to get the basic idea. A video card has multiple modes. Some of them, in order to assure better performance, will probably do things a little differently from the way I described on the previous page. However, there exist a number of modes that all video cards know: EGA, VGA, and SVGA. In the text to follow, we will work on the latter.

The standard printing functions are slow. Most of the time this is because they perform multiple security checks, and because they are capable of executing some complex tasks (like printing both integer and double numbers and text). However, whenever we want to perform a fast print to the screen, we want to bypass all this. The solution is to copy the data from the system memory to the graphic card's memory ourselves.

The structure of the video card's memory depends on the mode it is running and the video card itself. In order to somehow bypass incompatibilities, there exist some standardized modes that all video cards can run. SVGA is just one of these, and while you run in this mode, the structure of all video cards will be the same regardless of whether the subject is a 10-year-old card or a brand new one just rolled out on the doors of NVidia or ATI.

 

 

The SVGA mode is a text-based console window that can print out 80 characters in a row and has 25 rows. The address of the used memory in this mode starts at 0XB800 with the offset of 0X000. Starting from this point, for every character on the screen we have two corresponding bytes, one after another.

The first holds the character itself (coded in the ASCI) and the second is the attribute byte. This tells to the video card how to draw out the character found in the first byte. I have have depicted the structure of this in the following image.

 

The coding used is the RGB channel (Red Green Blue). Every color comes out of the combination, at some level, of these colors. We have one bit for each channel that shows whether that color is mixed in into the resulting color, and a fourth bit (the I character in the picture above) is an intensity bit. If it is on, the color is brighter; if not, a darker style of the color appears on the screen.

The bits on 6,5,4 communicate the background color for that character. The seventh bit is the blink bit. If this is on, the text will blink, just like the cursor does in a Word document. The character set used, and the font, depend on the selected table. This is a table that the video card stores in a ROM or RAM memory of 256 elements (one for each ASCI code). If it is in the RAM, the user can modify it.

You can change the font and the colors used with some Bios functions of the video card. The default values are characters that are 9 X 16 pixels in size. The primary character set (up to the 127th ASCI code) is at the address 0XF000 to 0XFA6E. The rest of the character set is at the address returned by the break vector 0X1F. We will describe break vectors in a future article.


blog comments powered by Disqus
C++ ARTICLES

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials