quicknes: simplify blitting logic, giving a 15% overall speedup in some cases

This commit is contained in:
goyuken 2014-08-13 17:06:01 +00:00
parent 9910cfae6a
commit d7a1dd3846
4 changed files with 17 additions and 20 deletions

View File

@ -58,9 +58,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
/// </summary>
/// <param name="e">Context</param>
/// <param name="dest">rgb32 256x240 packed</param>
/// <param name="colors">rgb 24 colors, red first, 512 of them (1536 bytes)</param>
/// <param name="colors">rgb32 colors, 512 of them</param>
[DllImport(dllname, CallingConvention = CallingConvention.Cdecl)]
public static extern void qn_blit(IntPtr e, IntPtr dest, byte[] colors, int cropleft, int croptop, int cropright, int cropbottom);
public static extern void qn_blit(IntPtr e, int[] dest, int[] colors, int cropleft, int croptop, int cropright, int cropbottom);
/// <summary>
/// get quicknes's default palette
/// </summary>

View File

@ -74,7 +74,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
InitSaveRamBuff();
InitSaveStateBuff();
InitVideo();
InitAudio();
InitMemoryDomains();
@ -536,6 +535,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
_Settings = (QuickNESSettings)o;
LibQuickNES.qn_set_sprite_limit(Context, _Settings.NumSprites);
RecalculateCrops();
CalculatePalette();
return false;
}
@ -553,17 +553,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
LibQuickNES.qn_delete(Context);
Context = IntPtr.Zero;
}
if (VideoOutput != null)
{
VideoOutputH.Free();
VideoOutput = null;
}
}
#region VideoProvider
int[] VideoOutput;
GCHandle VideoOutputH;
int[] VideoOutput = new int[256 * 240];
int[] VideoPalette = new int[512];
int cropleft = 0;
int cropright = 0;
@ -578,15 +573,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
BufferHeight = 240 - croptop - cropbottom;
}
void InitVideo()
void CalculatePalette()
{
VideoOutput = new int[256 * 240];
VideoOutputH = GCHandle.Alloc(VideoOutput, GCHandleType.Pinned);
for (int i = 0; i < 512; i++)
{
VideoPalette[i] =
_Settings.Palette[i * 3] << 16 |
_Settings.Palette[i * 3 + 1] << 8 |
_Settings.Palette[i * 3 + 2] |
unchecked((int)0xff000000);
}
}
void Blit()
{
LibQuickNES.qn_blit(Context, VideoOutputH.AddrOfPinnedObject(), _Settings.Palette, cropleft, croptop, cropright, cropbottom);
LibQuickNES.qn_blit(Context, VideoOutput, VideoPalette, cropleft, croptop, cropright, cropbottom);
}
public IVideoProvider VideoProvider { get { return this; } }

Binary file not shown.

View File

@ -54,7 +54,7 @@ EXPORT const char *qn_emulate_frame(Nes_Emu *e, int pad1, int pad2)
return e->emulate_frame(pad1, pad2);
}
EXPORT void qn_blit(Nes_Emu *e, char *dest, const Nes_Emu::rgb_t *colors, int cropleft, int croptop, int cropright, int cropbottom)
EXPORT void qn_blit(Nes_Emu *e, int32_t *dest, const int32_t *colors, int cropleft, int croptop, int cropright, int cropbottom)
{
// what is the point of the 256 color bitmap and the dynamic color allocation to it?
// why not just render directly to a 512 color bitmap with static palette positions?
@ -74,11 +74,7 @@ EXPORT void qn_blit(Nes_Emu *e, char *dest, const Nes_Emu::rgb_t *colors, int cr
{
for (int i = 0; i < rowlen; i++)
{
const Nes_Emu::rgb_t *c = colors + lut[src[i]];
*dest++ = c->blue;
*dest++ = c->green;
*dest++ = c->red;
*dest++ = 0xff;
*dest++ = colors[lut[src[i]]];
}
}
}