PPU Palette

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

PPU Palette

Post by Anes »

Im giving a try to Blargg's "nes_ntsc.c" to have a correct pal in my emu.

First i can get image. What i do is to have a buffer of

Code: Select all

 unsigned char nes_frame[256 * 240]
.
My "multiplexer" put NES pixels there and i create an D3D9 offscreen surface of

Code: Select all

g_d3d_hr = d3ddev->CreateOffscreenPlainSurface(NES_NTSC_OUT_WIDTH(256), 240, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &d3d_screen, 0);
Now NES_NTSC_OUT_WIDTH(256) gives me a value grater than 256. Then when it my emu finish putting pixels i call:

Code: Select all

nes_ntsc_blit(ntsc_ntsc, nes_frame, ntsc_image.row_width, 0, NES_NTSC_OUT_WIDTH(ntsc_image.width),
		ntsc_image.height, g_screen_data, d3d_lock_rect.Pitch);
Width = 256, Height = 240.

Anyway to mantain PAR should i stretchblt() to a 292 x 240 surface and apply a Scale2x to make the image better?

The second big question is: how do you do to implement pal emu in your emus? With the above approach my emu doesn't pass full_palette.nes.

And the third is. I remember that someone throws me a link were it was well explain Scale2x algorithm. I have to re-make it and what it says on the net doesn't help too much.

Thxs.
ANes
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PPU Palette

Post by lidnariq »

Anes wrote:The second big question is: how do you do to implement pal emu in your emus? With the above approach my emu doesn't pass full_palette.nes.
Super lazy, and not too inaccurate:
Take output of nes_ntsc, decompose into YCbCr, average the Cb and Cr components of each scanline with the one above it, convert back to RGB.
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: PPU Palette

Post by Anes »

Christ!! how do i do that??

Do you have some code??
ANes
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PPU Palette

Post by lidnariq »

Something roughly like
  • make a copy of the pixel buffer
  • in the copy, for all the pixels
  • in the copy, from the buttom scanline and going up (reverse order removes need to make another copy)
    • add the U and V components from the pixel one scanline above, and divide that result by two
  • in the copy, for all the pixels
    • convert each YUV tuple to RGB
  • display the copy
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: PPU Palette

Post by Anes »

Code: Select all

convert each RGB tuple to YUV 
Is it well to apply this?

Code: Select all

Y = ( (  66 * R + 129 * G +  25 * B + 128) >> 8) +  16
U = ( ( -38 * R -  74 * G + 112 * B + 128) >> 8) + 128
V = ( ( 112 * R -  94 * G -  18 * B + 128) >> 8) + 128
ANes
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PPU Palette

Post by lidnariq »

Looks good enough.
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: PPU Palette

Post by Anes »

YUV it's a new world for me.
Do i have to pack those values to a 16 bit value? Where Y,V and U goes? I mean what is the standard format in memory layout for YUV??
I know there are many YUV formats, but i ask this becouse i'm new to this.
ANes
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: PPU Palette

Post by lidnariq »

If your output method can be easily switched between RGB and YUV, you should be able to look up what memory layout it expects for a YUV444 texture.

Otherwise ... you can do whatever.
Post Reply