Re: [cc65] Optimizing C code

Date view Thread view Subject view

From: Shawn Jefferson (sjefferson_at_sd62.bc.ca)
Date: 2003-09-09 17:28:28


>>> MagerValp <MagerValp_at_cling.gu.se> 09/09/03 02:20AM >>>

>Is there a reason why you're not writing this routine in assembler? It
>would benefit a lot from it...

I thought that I would see how far I can get it with just optimizing the C code.  There is also the fact that I can do some basic coding in assembly, but mutliplications and such are a little confusing (to me.)  I will eventually code all the functions up in assembly, I guess.  This has been a good learning experience for me for optimizing the rest of my C code, in general and I thank those of you who have helped me!

Here's the current code (for Nick):

void __fastcall__ plot_4colmode_nc(BITMAP *bmp, unsigned int x, unsigned int y, unsigned char creg)
{
  unsigned char bit;
  unsigned char data;
  unsigned int index;


  bit  = (x % 4);
  index = (bmp->bpl * y) + (x / 4);

  data = bmp->dat[index];
  data &= plot4cmask[bit];                      // clear the pixel first

  if (creg != BAKCOL(bmp->mode)) {              // not background color?
    //++creg;                                     // creg 0->01, 1->10, 2->11
    data |= ((creg+1) << plot4cshift[bit]);
  }

  bmp->dat[index] = data;
  return;
}

plot4cmask and plot4cshift are the values to mask out the pixel, and the amount of bits to shift the color register value (0-3) passed in.  bmp is a structure that lets us pass information around about the bitmap (data pointer, graphics mode and the newly added value bytes per line, as well as width and height.)

The library is sort of modeled after the Allegro cross platform graphics library that I've used on and off for a couple of years on the PC.

¯
Shawn Jefferson


----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-09-09 17:31:24 CEST