Overscan: Difference between revisions
(→NTSC: Pad then scale vs. scale then pad) |
(→For emulator developers: non-square pixel ratios for scale before pad) |
||
Line 36: | Line 36: | ||
=== For emulator developers === | === For emulator developers === | ||
There are two ways to emulate the pixel aspect ratio of the NES: scale before padding and pad before scaling. | There are two ways to emulate the pixel aspect ratio of the NES: scale before padding and pad before scaling. | ||
The NES PPU hardware performs the padding first, adding 24 pixels of border to form a 280x240 pixel picture that can be resized to 320x240, 640x480, or 960x720 square pixels, or to 352x240 or 704x480 if your | The NES PPU hardware performs the padding first, adding 24 pixels of border to form a 280x240 pixel picture that can be resized to 320x240, 640x480, or 960x720 square pixels, or to 352x240 or 704x480 if your SDTV output circuit produces non-square pixels at 13.5 MHz. | ||
But as a slight optimization, you can scale first (256 * 8/7 = 292) and then pad: stretch the 256x240 pixels to 292x240, 584x480, 876x720, or 1168x960. | But as a slight optimization, you can scale first (256 * 8/7 = 292) and then pad: stretch the 256x240 pixels to 292x240, 584x480, 876x720, or 1168x960 square pixels or 320x240 or 640x480 non-square pixels. | ||
Then you can emulate the overscan by drawing a TV bezel on top of the edges of the emulated picture. | Then you can emulate the overscan by drawing a TV bezel on top of the edges of the emulated picture. | ||
Revision as of 01:16, 28 August 2011
The NES PPU always generates a 256x240 pixel picture. But there is a recurring misconception that the picture is 256x224 pixels on NTSC. This article explains how both are true.
Consumer TV monitors draw the picture slightly larger than the screen, with some of the picture hidden by the border. This is called "overscan".[1][2] The BBC recommends keeping a 5 percent margin inside the screen and putting all important information, such as text, within the center 90 percent of the width and height of the screen.[3] Most TVs show slightly more than 90 percent, so make sure to keep any glitch pixels well outside this margin.
NTSC
BT.601 (formerly CCIR 601) is a standard for digital processing of component video signals. It describes a way to sample NTSC video at exactly 13.5 MHz to produce 704x480 non-square pixels or 135/11 MHz to produce 640x480 square pixels in the "clean aperture".[4] (The commonly quoted 720x480 is slightly wider to capture signals slightly before and after the clean aperture in case of a sync shift, allowing the signal to be recentered before broadcast. There are still only 704 pixels on a scanline.) This means the signal associated with one scanline is 640/(135,000,000/11) s = 704/13.5 s = 52.148 microseconds long.
The NTSC color subcarrier is at 39,375,000/11 Hz = 3.5795 MHz. The NES master clock is always 6 times the color subcarrier frequency because there are 12 hues on the NES PPU, and the color generator uses a double-pumped counter to generate the hue signal. So the PPU's pixel rate is 1/4 of the master clock, or 6/4 of the color subcarrier, or 39,375,000*6/4/11 = 5.3693 million pixels per second. (This pixel rate appears to have originated in the TMS9918 VDP used in the ColecoVision. The NTSC Sega Master System VDP and Super NES PPU use this same rate, as does the Sega Genesis VDP in the 256-pixel mode that several multiplatform titles used.)
Multiplying the pixel rate by the scanline length gives 39,375,000*6/4/11*640/(135,000,000/11) = 280 pixels per scanline. The PPU puts signal in 256 of these and a border at the left and right sides. This makes the pixel aspect ratio on a 4:3 TV to be 240/280*4/3 = exactly 8:7, or about 1.143:1.
For game developers
For a 280x240 pixel picture, the 90 percent safe area is 252x216 pixels. Due to a quirk of the NES PPU's sync generation that places the image roughly two pixels to the right of center, these 252 pixels are actually the leftmost ones. Some CRT TVs have rounded corners; it's a good idea to keep text away from the corners if possible.
This, however, doesn't give developers a free pass to ignore glitches caused by background mirroring. Actual TVs show about 224 lines of the signal, hence the commonly reported 256x224 resolution. But the vertical position may be slightly off center. Emulators and LCD HDTVs tend to use lines 8 to 231, but some TVs have been seen to show lines 12 to 235. In fact, even some CRT SDTVs made in the 2000s show more of the bottom than the top; this may be so that tickers on cable news channels aren't cut off.
For emulator developers
There are two ways to emulate the pixel aspect ratio of the NES: scale before padding and pad before scaling. The NES PPU hardware performs the padding first, adding 24 pixels of border to form a 280x240 pixel picture that can be resized to 320x240, 640x480, or 960x720 square pixels, or to 352x240 or 704x480 if your SDTV output circuit produces non-square pixels at 13.5 MHz. But as a slight optimization, you can scale first (256 * 8/7 = 292) and then pad: stretch the 256x240 pixels to 292x240, 584x480, 876x720, or 1168x960 square pixels or 320x240 or 640x480 non-square pixels. Then you can emulate the overscan by drawing a TV bezel on top of the edges of the emulated picture.
PAL
When sampled at 14.75 MHz (768x576) or 7.375 MHz (384x288), PAL video has square pixels. The width of a scanline is 768 pixels, or 768/14750000 seconds, or 52.068 microseconds.
The PAL color subcarrier is exactly 4,433,618.75 Hz. The PAL NES master clock is six times that, and the PPU generates one pixel for every 5 master clock cycles, or 5320342.5 Hz. This makes the width of a scanline 5320342.5*768/14750000 = 277 pixels, and the pixel aspect ratio 7375000/5320342.5 = (59*125000)/(165*64489/2) = 1.3862:1.
The width of the picture is nearly the same as on NTSC, so we need not reconsider horizontal placement. However, the total picture is 288 lines tall, making the safe area roughly 260 lines tall. This means every TV shows blank bars at the top and bottom of the 240-line active area that the NES generates. So for a PAL-only title, the developer need not concern himself with TVs cutting off the status bar, but minimizing artifacts caused by nametable mirroring and sprite pop-on at the top becomes paramount.