Hi all,
Was reading squidgesnes_0.37mmu source code. Just thought id post a thread here so people can read my comments and maybe see if they help improve?
Math improvements:
I know this change would provide a marginal (possible) improvement. But would it not be more efficient working out y1*320 in the y1 loop?
---
This bit seems to be a repeat? I think its due to the double buffering? Could we not do...
---
Just a few things on this one... again some of the math and declairation could be moved out of the loop?
then
Also, with your color conversion could you not do..
a more improtant comment.. Your loop runs 4 times? (i=0, i=1, i=2, i=3)
should this not be set to 2?
---
On another note, What exactly does C4.cpp and C4emu.cpp do? - I think its something to do with special effects processing..
I would reckon that if you replace the sin and cos in c4.cpp with a lookup table, that would improve speed on that too... c4emu.cpp already has a sin and cos lookup table so would be simple (and silly not to) do this.
At a guess, i would say that this would improve mode7 functions.
---
Ok ill keep reading on, and will post anything interesting. great code so far tho!
If someone could tell me the most important parts, and possibly slowest.. Ill have a crack at 'em =)
Mike
Was reading squidgesnes_0.37mmu source code. Just thought id post a thread here so people can read my comments and maybe see if they help improve?
Math improvements:
Code:
void drawRect (unsigned short *vram, int x, int y, int w, int h)
{
for (int y1 = y; y1 < y+h; y1 ++)
for (int x1 = x; x1 < x+w; x1 ++)
vram[(y1*320)+x1] ^= 0xFFFF;
}
I know this change would provide a marginal (possible) improvement. But would it not be more efficient working out y1*320 in the y1 loop?
Code:
void drawRect (unsigned short *vram, int x, int y, int w, int h)
{
for (int y1 = y, y2 = y1 * 320; y1 < y+h; y1 ++)
for (int x1 = x; x1 < x+w; x1 ++)
vram[y2+x1] ^= 0xFFFF;
}
---
Code:
void blankscreen (void)
{
int x,y;
for (y = 0; y < 240; y ++)
for (x = 0; x < 320; x ++)
gp2x_video_RGB[0].screen16[(y*320)+x] = 0;
gp2x_video_RGB_flip(0);
for (y = 0; y < 240; y ++)
for (x = 0; x < 320; x ++)
gp2x_video_RGB[0].screen16[(y*320)+x] = 0;
gp2x_video_RGB_flip(0);
}
This bit seems to be a repeat? I think its due to the double buffering? Could we not do...
Code:
void blankscreen (void)
{
unsigned int xy = 240*320;
//memset(gp2x_video_RGB[0].screen16, 0, xy); Use ZeroMemory as snes9x complient?
ZeroMemory(gp2x_video_RGB[0].screen16, xy);
gp2x_video_RGB_flip(0);
// Is it needed?
ZeroMemory(gp2x_video_RGB[0].screen16, xy);
gp2x_video_RGB_flip(0);
}
---
Code:
void drawbackground (void)
{
int i=0;
// draw the background image onto both buffers if possible
if (!gamebg) return;
if (local_mr.wantscale) return;
unsigned short *dstpix;
unsigned char *pix;
for (i=0;i<4;i++)
{
dstpix = gp2x_video_RGB[0].screen16;
pix = gamebg->getPixels();
for (int yy = 0; yy < 240; yy ++)
for (int xx = 0; xx < 320; xx ++)
{
unsigned char r, g, b;
unsigned short p;
r = pix[(yy*(320*3))+(xx*3)+0];
g = pix[(yy*(320*3))+(xx*3)+1];
b = pix[(yy*(320*3))+(xx*3)+2];
r /= 8;
g /= 4;
b /= 8;
r &= 31;
g &= 63;
b &= 31;
p = (b << 11 ) | (g << 5) | (r);
*dstpix++ = p;
}
gp2x_video_RGB_flip(0);
}
}
Just a few things on this one... again some of the math and declairation could be moved out of the loop?
Code:
for (int xx = 0, pos = (yy*(320*3))+(xx*3)); xx < 320; xx ++)
then
Code:
r = pix[pos+0];
g = pix[pos+1];
b = pix[pos+2];
Also, with your color conversion could you not do..
Code:
// bit shifting tends to be faster, but remove's rounding (which ur &= bits did anyway)
r >>= 4;
g >>= 3;
b >>= 4;
#ifdef SAFE
// this bit isn't needed as a char can only hold a number upto 255.
r &= 31;
g &= 63;
b &= 31;
#endif
a more improtant comment.. Your loop runs 4 times? (i=0, i=1, i=2, i=3)
Code:
for (i=0;i<4;i++)
should this not be set to 2?
Code:
void drawbackground (void)
{
int i=0;
// draw the background image onto both buffers if possible
if (!gamebg) return;
if (local_mr.wantscale) return;
unsigned short *dstpix;
unsigned char *pix;
unsigned char r, g, b;
unsigned short p;
pix = gamebg->getPixels();
for (i=0;i<[b]2[/b];i++)
{
dstpix = gp2x_video_RGB[0].screen16;
for (int yy = 0, [b]ty = (yy*(320*3))[/b]; yy < 240; yy ++) for (int xx = 0, [b]pos = (ty+(xx*3))[/b]; xx < 320; xx ++)
{
[b] r = pix[pos+0] >> 4;
g = pix[pos+1] >> 3;
b = pix[pos+2] >> 4;
#ifdef SAFE
r &= 31;
g &= 63;
b &= 31;
#endif
[/b]
p = (b << 11 ) | (g << 5) | (r);
*dstpix++ = p;
}
gp2x_video_RGB_flip(0);
}
}
---
On another note, What exactly does C4.cpp and C4emu.cpp do? - I think its something to do with special effects processing..
I would reckon that if you replace the sin and cos in c4.cpp with a lookup table, that would improve speed on that too... c4emu.cpp already has a sin and cos lookup table so would be simple (and silly not to) do this.
At a guess, i would say that this would improve mode7 functions.
---
Ok ill keep reading on, and will post anything interesting. great code so far tho!
If someone could tell me the most important parts, and possibly slowest.. Ill have a crack at 'em =)
Mike