LinkExchange Member | Free Home Pages at GeoCities

The VESA Library
All the games have a lot of graphics to move, and is necessary to write fast routines to manage this graphics. The best way to optimize those routines is to use the assembly language, but the inline assembly of the DJGPP (with its AT&T syntax) is hard to use. But we can use the free and powerful Netwide Assembler (NASM), that use the better Intel syntax. I don't wanna explain how to programming in assembly language or interfacing assembly procedure with DJGPP, but only give you an optimized version of the graphics routines. Enjoy and remember to tell me any suggestion.
What to optimize
The `vesa.c` file contains a lot of functions to manage the VESA Bios Extension 2.0: initialize the graphics, set the video mode, put pixels and images, return to text mode. Not all of those functions should be optimized to gain more speed. For example the initialization of the video mode is executed only once in the game, so is indifferent to have a fast or a slow function. Instead the graphics routines like `put_pixel()` or `showframeb()` are very used in a game. So is necessary to optimize at least these functions:

          void vbe_clearscreen(BYTE color);
          void vbe_clearbuffer(BYTE color);
          void vbe_putpixel(int x, int y, BYTE color);
          void vbe_putpixelb(int x, int y, BYTE color);
          void vbe_showimage(int x, int y, struct IMAGE *frame);
          void vbe_showimageb(int x, int y, struct IMAGE *frame);
          void vbe_showframe(int x, int y, struct IMAGE *frame);
          void vbe_showframeb(int x, int y, struct IMAGE *frame);
          void vbe_showframerev(int x, int y, struct IMAGE *frame);
          void vbe_showframebrev(int x, int y, struct IMAGE *frame);
          void vbe_showbuffer(void);

          // **************** CLIPPING ******************
          int clip_x, clip_y, clip_width, clip_height;
          void vbe_setclipwindow(int x1, int y1, int x2, int y2);
          void vbe_putpixelclip(int x, int y, BYTE color);
          void vbe_putpixelbclip(int x, int y, BYTE color);

Remember that these routines doesn't check the values of the parameters, so you can have protection errors with strange values.
How write optimized routines
Isn't very simple to write assembly routines and interface it with the DJGPP. I hope you know how to do it (if not try to download this tutorial). I use the standard syntax for the parameters:

    	push	ebp
    	mov	ebp, esp	; [ebp+8] is the address of the firs parameter

    	; The function body

    	mov	esp, ebp	; Exits without restore changed registers
    	ret

When is possible I don't use this syntax (for example with only one parameter and simply function). I try to optimize the code for the Pentium Processor, but is a bit hard. If you know how to optimize the code for the Pentium, please give me an hand.
The new version of the `vesa.c` and the `vesa.h` is stored in this archive (files `vesalib.c` and `vesalib.h`).

[main] [prec] [next] [email]
Site Made and Maintained by The Dark Angel <DarkAngel@tin.it>
My ICQ Number is 2063026
You Visited This Page
times
This page hosted by Get your own Free Home Page