[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Inline asm?
Joel Stanley wrote:
> Can I rely on vga_drawpixel() to be as fast as I could make it with the
> proper asm language? Or should I even care with modern processors?
It makes much more sense to construct a bitmap inside main memory and
then have the graphics library blit the whole shebang to the video card.
This is what Sprite32 does and its newest release "Anakin" contains an
optional x86 ASM blitter routine (it handles transfers of sprites to the
backbuffer before on-screen blitting which is done by XShm or DGA). Here
are the steps that I recommend you take (since this is what I did in
Prepare a rectangle of memory, either a page of video memory or a block
of main memory, that's big enough to hold a screenful. This is to serve
as your back buffer.
Draw a screenful inside this buffer. *THIS* is the code that you're most
likely going to want to optimize. An ASM routine to blit a rectangle
with transparency, for example, will speed things up considerably if
you're creating a sprite-based game.
Get this buffer onto the screen. This will happen instantaneously if you
have the option of swapping video buffers. Otherwise, you're going to
have to copy the back buffer into the frame buffer. Generally there is a
function such as XShmPutImage in X or putbox in SVGAlib that does this
automagically for you. These are generally pretty well tweaked for
performance. You can also write your own blitter, lock the framebuffer
if you can get access to it, and do the transfers yourself. But you want
to think about an ASM function that transfers an entire *rectangle* at a
Calling a function such as vga_drawpixel() for each pixel in the
rectangle is slow, since there's function call overhead for each and
every pixel. Not good. A different approach is recommended.
The idea is to get as much performance as you possibly can without
overworking yourself, even with today's faster processors. The less time
you're spending inside slow video routines, the more depth and
complexity you can add to your game!
Jeff Read <firstname.lastname@example.org>
Unix Code Artist, Anime Fan, Really Cool Guy