Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Silly_con

Get memory - optimizations

This topic is 5446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have made this procedure to save a piece of vga memory (msdos mode 13) based on a top-left coord x,y and a width and height. The proc stores in a buffer width bytes, making a scanline of the rectangle formed by x,y,w,h. Anyone knows something that can optimice this procedure, with or without using memcpy ?
void Save(int x,int y,int width,int height,char *buffer)
{
  short starty;
  short endy;
  char *VGA = (byte *)0xA0000;
  short Y;
  int i=0;

  starty = (y << 8) + (y << 6) + x;
  endy = ((y+height) << 8) + ((y+height) << 6) + x;

  for (Y=starty;Y<endy;Y+=320) {
	memcpy(buffer + i*width,VGA + Y,width);
        i++;
  }

}

Share this post


Link to post
Share on other sites
Advertisement
I might get bored enough to write it in assembly later... all I can suggest is eliminating the memcpy call and using cpu instructions directly...

since this is mode 13h, i assume you''re running a 486 or pentium 100 or so? I''ll try to keep the instructions simple

Share this post


Link to post
Share on other sites
okay okay, i'm a bit bored now so...

void Save(int x,int y,int width,int height,char *buffer)
{
char *VGA = (byte *)0xA0000;
char *endVGA;
endVGA = VGA + ((y+height) << 8) + ((y+height) << 6) + x;
VGA += (y << 8) + (y << 6) + x;
for (;VGA<=endVGA;VGA+=320,buffer+=width
memcpy(buffer,VGA,width);
}


is a faster C version. parts may be wrong however (VGA<endVGA might need to be a <=, I don't feel like finding out just yet. actually, i think it should be, changed it...

edit: fixed the lessthan crap.

[edited by - C-Junkie on July 25, 2003 9:21:09 PM]

Share this post


Link to post
Share on other sites
google after something that is called "duff''s device"; propably this could increase speed.


DJSnow
-----
this post is manually created and therefore legally valid without a signature

Share this post


Link to post
Share on other sites
@C-junkie:

"duff''s device" is a loop-unrolling technique which could (!) possibly increase your speed - i didn''t say that is definitively does it.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!