Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
k, this is gonna sound pretty silly, but just bear with me for a sec. what i'm looking for here is some function, or weird method, of rapidly redrawing the characters on the screen in a dos prompt. I intend to make a silly little ascii game for my high school computer information science class where we have a computer formated with dos 7.0, and i ran into this little problem. i would like to redraw the text instantly, kinda like how direct x draws 60 frames per second, but simply with redrawing text. at such a low resolution, i assume it should be very simple, but when i do something like this, it's nasty blinky!

while(1)
{
    cout << "test string here";
    system("cls");
}


an old software doesn't make the computer old hardware, why is the graphics adapter not able to keep up with something so simple? So i guess my question is, is there a way to repaint it more rapidly? or as a bypass to said blinkiness, is there a way to redraw only individual characters on the screen so that, say, if a person hits the right arrow, and only the x in the middle of the screen moves one character space to the rigth, i don't have to redraw the entire screen, just redraw that x?

EDIT: btw, i'm not writing the program specifically for dos yet, i'm just writing it for the command prompt in windows.
Posted
Updated 13-Oct-11 19:05pm
v3
Comments
Philippe Mori 14-Oct-11 8:23am    
Done correctly, it could be pretty fast on hardware 100 time less powerfull than today machines. It was already pretty fast in the mid-1990's when writting directly to the video buffer on top-of-the art hardware at that time.

1 solution

Nobody did such things on DOS!

Instead, people would go directly to video card RAM, figure out the address of text screen buffer, depending on card type, and would write directly to it. Don't even play with the idea of using console -- it is not designed for such things. Now, the buffer of color mode text screen consists of pair of bytes: one byte is the character to output, another one is background and foreground color, one half-byte for foreground, another half-byte for background, so you have 16 colors for foreground and 16 for background. I hope I remember this correctly.

Therefore, you have an array of 16-bit words which you can write in arbitrary order. The horizontal line is usually 80 characters, so you can address the array like an array of rank 2. Changing any byte in the array changes output in any position on screen.

This is easy enough. We even used to draw all kind of pictures on screen, using pseudo-graphics characters. You also can modify fonts for text mode which are also stored in the video card RAM. This way, you can draw a very special graphics which looks almost like graphical (pixel-level) mode.

Finally, there is one more trick: reloading font for some characters dynamically. It runs in a very smooth way, so there were a popular programs addressing a mouse cursor on a pixel level (in a pure text mode!). It was done via reading of the buffer characters around mouse location, modifying character bytes and bitmap of the font for these characters dynamically.

What else? Yes, you can get a hardware interrupt triggered by the video card at the moment of diagonal motion of the electron beam when the monitor moves the beam from the position of button right pixel to the position of top left one. People install interrupt handler on this IRQ to trigger changes in the video card buffer. This is an analog of "double buffering": instead of costly double buffering, all changes were written to the card when the image update was paused to the back move of the electron beam.

[EDIT]

For rudimentary reference material, use this: http://en.wikipedia.org/wiki/VGA_compatible_text_mode[^]. When you learn terminology but miss some information, search fore more detail in the Web using basic terms and concepts.

And here is the reference for keyboard interrupt usage: http://webpages.charter.net/danrollins/techhelp/0106.HTM[^]. Look at the whole site, it looks promising.

—SA
 
Share this answer
 
v4
Comments
FatalCatharsis 14-Oct-11 1:17am    
i understood it fairly well, until that last paragraph :P, don't have any idea what an interrupt is, or what a handler is for, but that can wait for a different discussion. On to the questions:

1) how does one figure out the address of the text screen buffer, and store it in a pointer, to write to?

2) how do i do the same for the font data, and then what is the format it's in and how do i edit it?

3) just another thought that occurred to me, what you described was a single byte character with color data, does dos support the use of unicode (wide) characters?
Sergey Alexandrovich Kryukov 14-Oct-11 1:53am    
How can you be so naive? Unicode? what to advise you to read on history?.. well, this is called anachronism... Not Unicode at that time.
--SA
Sergey Alexandrovich Kryukov 14-Oct-11 1:59am    
I wish I remembered... Addresses are line B8000, C4000(?). I used to have a couple of reference books... You have very few text modes, and few types of cards: EGA, VGA, Hercules. There is documentation on each card and each mode -- addresses of all buffers are fixed.

Formats for font data depend on text modes. Just a black-and-white bitmaps like 8x8, 8x14, 9x16, a pixel per bit, a byte is arranges horizontally left to right (lo-bit on left). A card is controlled by calling a software interrupts putting parameters in registers. (Can you call interrupts? Its in assembly, usually in-line one, with "pushf" and "retf" instead of "ret"?). DOS/BIOS programming is all based on interrupts.

--SA
Sergey Alexandrovich Kryukov 14-Oct-11 2:06am    
I added an article for reference, it's good for starters. Please see after [EDIT].
--SA
Sergey Alexandrovich Kryukov 14-Oct-11 2:11am    
Referenced one more article...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900