Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen Refresh/ Display

Status
Not open for further replies.

asterothe

Programmer
Sep 22, 2002
6
US


I am still a newbie to assembly. I try
to display a box in the screen and move it. I draw it pixel by pixel. It moves. Logic works ok but it flickers.
How I can refresh the picture accordingly? (to keep up with the refresh rate of monitor) I thought of creating two pages and drawing picture in the back page after it's drawn, flip the page. It doesnt work . Some distorted graphics appear. What is the best way of displaying a moving box ? (in video mode 13) And I don't use direct video access. If I'd know...

Thanks in advance

 
The easiest way is to use 320x200x256 mode where you can directly put data to video area of system memory. If you do so, many problems perish.
 
The flicker is probably caused by not using direct video access. If you're doing BIOS access (omg!) it'll be ridiculously slow even on later processors.

Also, drawing pixel by pixel is not recommended for any 16-color video mode, especially for horizontal lines since you can draw up to 8 pixels at a time in a horizontal line. For a 256-color mode, mode X can be used to draw up to 4 pixels at a time but of course that's advanced.

What is more if you're using the 320x200x256 mode (13h, is that 'mode 13' a 13decimal or 13hex??) IIRC you can only have one page, if you try to use two the two pages will overlap. To improve performance, use direct video access and if possible use mode X. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Wow, you're getting yourself into a lovely interesting area. I can think of no better introduction to PC graphics than Abrash's big black book, which is probably still available in paper form, and can be downloaded (or used to be downloadable) from various places.
You are in the right forum for this, since graphics stuff the way you want to do it inevitably requires assembler. I agree with AmkG entirely about the pixel-drawing interrupt in BIOS. It is universal to all modes (wow!) but unbelievably slow.
The last time I drew a box on screen (using 16 colour 640*480 graphics) I first did fast horizontal and vertical line drawers, and used these. I wanted to alternate pixel colour to make a dithered colour effect, which was why I was doing it myself.

There are several quite separate reasons for not drawing pixel by pixel.
(1) to avoid the bios interrupt. But if you write your own single-pixel drawer, you'll find it is still quicker than bios.
(2) because in a 16 colour mode you can draw 8 horizontal pixels together, which saves time on the horizontal lines of your box. Note that there's no such benefit for the verticals!! The code will be much messier than single-pixel code, because you have to handle the ends of the line specially, where less than 8 pixels need drawing. Remember a very small box might have its left and right edges in the same byte, which gets even messier. But this is worth dealing with, because video ram is very slow, so repeated moves to video are frowned on.
(3) because drawing a single dot requires setting up registers in the VGA card, using in and out instructions. These are hideously, dreadfully slow compared to "normal" assembler. Very often you will be setting them to the same values for a succession of pixels, so a line drawer that sets them once, and leaves them, will be more efficient than a pixel drawer called repeatedly. This is a BIG gain, so it's worth doing. In my dithered example I could set a bit-mask in the VGA just once for the entire vertical line, saving potentially hundreds of "out"s.
(4) because doing a call and rts is also time consuming, especially if associated with instructions to maintain a stack-frame and preserve registers. But this is small compared to outs.

The only sad thing about all this is that less and less people are interested or know anything, because simple things like box drawing are provided ready-made by any respectable language or graphic user interface.

hope that helps. Get Abrash's book!
Lionel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top