quicknes: implement the crop settings

This commit is contained in:
goyuken 2014-01-10 01:45:06 +00:00
parent db386e4dee
commit adf7f01102
4 changed files with 28 additions and 9 deletions

View File

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

View File

@ -470,6 +470,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
{ {
Settings = (QuickNESSettings)o; Settings = (QuickNESSettings)o;
LibQuickNES.qn_set_sprite_limit(Context, Settings.NumSprites); LibQuickNES.qn_set_sprite_limit(Context, Settings.NumSprites);
RecalculateCrops();
return false; return false;
} }
@ -506,6 +507,19 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
GCHandle VideoInputH; GCHandle VideoInputH;
GCHandle VideoOutputH; GCHandle VideoOutputH;
int cropleft = 0;
int cropright = 0;
int croptop = 0;
int cropbottom = 0;
void RecalculateCrops()
{
cropright = cropleft = Settings.ClipLeftAndRight ? 8 : 0;
cropbottom = croptop = Settings.ClipTopAndBottom ? 8 : 0;
BufferWidth = 256 - cropleft - cropright;
BufferHeight = 240 - croptop - cropbottom;
}
void InitVideo() void InitVideo()
{ {
int w = 0, h = 0; int w = 0, h = 0;
@ -519,14 +533,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
void Blit() void Blit()
{ {
LibQuickNES.qn_blit(Context, VideoOutputH.AddrOfPinnedObject(), Settings.Palette); LibQuickNES.qn_blit(Context, VideoOutputH.AddrOfPinnedObject(), Settings.Palette, cropleft, croptop, cropright, cropbottom);
} }
public IVideoProvider VideoProvider { get { return this; } } public IVideoProvider VideoProvider { get { return this; } }
public int[] GetVideoBuffer() { return VideoOutput; } public int[] GetVideoBuffer() { return VideoOutput; }
public int VirtualWidth { get { return 292; } } // probably different on pal public int VirtualWidth { get { return (int)(BufferWidth * 1.14); } }
public int BufferWidth { get { return 256; } } public int BufferWidth { get; private set; }
public int BufferHeight { get { return 240; } } public int BufferHeight { get; private set; }
public int BackgroundColor { get { return unchecked((int)0xff000000); } } public int BackgroundColor { get { return unchecked((int)0xff000000); } }
#endregion #endregion

Binary file not shown.

View File

@ -67,20 +67,25 @@ EXPORT const char *qn_emulate_frame(Nes_Emu *e, int pad1, int pad2)
return e->emulate_frame(pad1, pad2); return e->emulate_frame(pad1, pad2);
} }
EXPORT void qn_blit(Nes_Emu *e, char *dest, const Nes_Emu::rgb_t *colors) EXPORT void qn_blit(Nes_Emu *e, char *dest, const Nes_Emu::rgb_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? // 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? // why not just render directly to a 512 color bitmap with static palette positions?
const unsigned char *src = e->frame().pixels;
const int srcpitch = e->frame().pitch; const int srcpitch = e->frame().pitch;
const unsigned char *srcend = src + e->image_height * srcpitch; const unsigned char *src = e->frame().pixels;
const unsigned char *const srcend = src + (e->image_height - cropbottom) * srcpitch;
const short *lut = e->frame().palette; const short *lut = e->frame().palette;
const int rowlen = 256 - cropleft - cropright;
src += cropleft;
src += croptop * srcpitch;
for (; src < srcend; src += srcpitch) for (; src < srcend; src += srcpitch)
{ {
for (int i = 0; i < 256; i++) for (int i = 0; i < rowlen; i++)
{ {
const Nes_Emu::rgb_t *c = colors + lut[src[i]]; const Nes_Emu::rgb_t *c = colors + lut[src[i]];
*dest++ = c->blue; *dest++ = c->blue;