Page 1 of 2

NTSC pattern torture test ROM

Posted: Sat Nov 05, 2016 7:50 pm
by rainwarrior
I found myself a little bit interested in the pattern of colour artifacts the NTSC NES produces. I decided to make a test ROM that shows off the patterns easily. Most of the shapes are arranged in groups of 3 pixels so they tend to align with diagonal 3-pixel groupings the artifacts seem to have.

Basically it's just a screen with some dot patterns. You can scroll it around with the D-pad. Press select to modify the background or foreground colours. Press start to reset.
comparison picture captured from my NES
comparison picture captured from my NES
Of particular interest I think is the square of dots at the top right, and the stripes at the top left. Both of these will appear as a single "colour", which you should be able to see three distinct states of depending what pixel they are scrolled to. As expected, I also notice that the phase changes when I reset my NES (there are two groups of states with red/green/blue vs cyan/magenta/yellow patterns). These effects aren't really new information or anything, but I thought a good visual demonstration might help understand the nature of these patterns.

(Note: the image is just a raw capture from my cheap capture device. It is an interlaced image, so it represents two consecutive frames. The specific colour depends on the startup alignment of the PPU, and the sharpness/definition of various things is highly specific to this capture device. It's not meant to represent any kind of ideal target for emulation.)

Re: NTSC pattern torture test ROM

Posted: Mon Dec 26, 2016 3:09 pm
by Sour
I decided to have a stab at implementing bisqwit's NTSC filter code (the one he posted earlier this year with integer math).

This is what it ends up looking like at full resolution (the top left part makes me wonder if the coloring is correct - it doesn't match neither your screen capture nor blargg's filter, but any change I make produces the wrong palette in games).
ntsc_torture (2048x1920)
ntsc_torture (2048x1920)
I'm not completely certain my implementation is correct though - the old tvfailpass/tv.nes test doesn't look that great compared to blargg's filter.
Though I can't test on an actual console/TV, so I have no way to know.
tvpassfail.png
And this is what it looks like on an actual game:
smb3.png
Performance-wise, the code is pretty mean (although I'm sure my code is far from optimal). Between creating the NTSC signal from the palette output, converting it to RGB, and resampling the height to 1920px, it takes 2 threads to run the filter at 70fps (on my 7-year-old i5) while a 3rd core is running the emulation.
At quarter resolution though (1024x960), it's not that bad (approx 140fps)

Re: NTSC pattern torture test ROM

Posted: Wed Dec 28, 2016 10:58 pm
by rainwarrior
Sour wrote:the top left part makes me wonder if the coloring is correct
There are six possible colourings depending on the phase of the PPU at time of reset.

On any given reset, you should be able to see three of the six possibilities by using the d-pad to move the screen around in 1 pixel increments.

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 1:25 am
by Bisqwit
Here are some sample pictures of what my QuickBASIC NES emulator produces for this test ROM:

Image Image Image
The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).

The QuickBASIC code has a newer version of the filter that runs much much faster than the C++ version does (if the language difference is ignored), because it updates a running variable only once per channel per pixel, instead of doing 12 or 24 multiplications per pixel. But it is also less accurate, because it rounds to integers. It is unique compared to (probably) every other NES emulator in the world in that it simulates a full frame of television signal, with borders, syncs, colorbursts and all, with the NTSC decoder knowing absolutely nothing about what is happening inside the PPU (things like current scanline number, etc). The only interface between the NTSC decoder and the rest of the emulator is the 1 integer that represents the current voltage level of the NTSC signal that changes about 5 million times in a second.

The older and more accurate C++ version (the one that is documented in the Wiki) flickers between these two (click to zoom):
Image Image Image

The third picture is produced if the code merges all three fields.

Note that any possible hardware screen captures depend entirely on what ever postprocessing your television set / composite decoder happens to do with the signal.
If I change my (C++) emulator to merge two fields into one (which a television is certainly not required to do), here is one of the outcomes:

Image
It is quite a close match to the first sample posted by rainwarrior, if we ignore saturation differences.

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 4:33 am
by Eugene.S
MESEN implementation:

feos want to modify this algorithm for PAL-Filter in near future.
But sines must be recalculated.

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 8:26 am
by feos
I'd be really grateful if someone modifies the constants to the PAL standard.
Bisqwit wrote:The QuickBASIC code has a newer version of the filter that runs much much faster than the C++ version does (if the language difference is ignored), because it updates a running variable only once per channel per pixel, instead of doing 12 or 24 multiplications per pixel. But it is also less accurate, because it rounds to integers. It is unique compared to (probably) every other NES emulator in the world in that it simulates a full frame of television signal, with borders, syncs, colorbursts and all, with the NTSC decoder knowing absolutely nothing about what is happening inside the PPU (things like current scanline number, etc). The only interface between the NTSC decoder and the rest of the emulator is the 1 integer that represents the current voltage level of the NTSC signal that changes about 5 million times in a second.
Is it here?

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 11:48 am
by rainwarrior
Bisqwit wrote:The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).
Is there some explanation as to why they appear at all in your emulator? The ROM isn't doing any kind of raster manipulation, it's just a static screen.

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 12:27 pm
by tepples
feos wrote:I'd be really grateful if someone modifies the constants to the PAL standard.
That depends on someone with a PAL NES being willing to run test patterns on hardware on short notice. Are you such a someone?

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 12:53 pm
by feos
I meant the constants in the Bisqwit's filter, and yes, myself and Eugene.S will run any tests that are needed.

We don't exactly have PAL NES, but this thing that we have should work very well, since Dendy uses a clone of PAL PPU:
https://forums.nesdev.com/viewtopic.php?f=9&t=14861

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 1:20 pm
by Bisqwit
feos wrote:I'd be really grateful if someone modifies the constants to the PAL standard.
It is not only the matter of modifying the constant.
You have to reverse the phase of the colorburst for every other scanline, too (or something like that, I don't remember the specifics).
feos wrote:
Bisqwit wrote:The QuickBASIC code has a newer version of the filter that runs much much faster than the C++ version does (if the language difference is ignored), because it updates a running variable only once per channel per pixel, instead of doing 12 or 24 multiplications per pixel. But it is also less accurate, because it rounds to integers. It is unique compared to (probably) every other NES emulator in the world in that it simulates a full frame of television signal, with borders, syncs, colorbursts and all, with the NTSC decoder knowing absolutely nothing about what is happening inside the PPU (things like current scanline number, etc). The only interface between the NTSC decoder and the rest of the emulator is the 1 integer that represents the current voltage level of the NTSC signal that changes about 5 million times in a second.
Is it here?
Yes, that would be it.
rainwarrior wrote:
Bisqwit wrote:The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).
Is there some explanation as to why they appear at all in your emulator? The ROM isn't doing any kind of raster manipulation, it's just a static screen.
I can't offhand think of any explanation. The border color is determined by the address internally accessed by the PPU during the border rendering (i.e. if it's 3Fxx...), and/or the background color from the palette, so there may be a bug somewhere in that processing.

Eugene.S wrote:<video attachment>
The video is chroma-supersampled (YUV 420p colorspace). It rather completely defeats the purpose of trying to show something where colors of individual pixels matter.

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 6:40 pm
by Great Hierophant
I took a video capture of the ROM running in my real NES, and the capture is surprisingly faithful to what I saw on my TV screen :

https://youtu.be/l-y9gaU-pR4

When you watch this in 60fps, you can see some that combinations of colors cause the upper left square to visibly flicker, which I thought weird. I would have lingered longer, but I couldn't see it on the capture device's viewer, so I thought the effect was lost. When I converted the video to 60fps, it reappeared.

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 8:24 pm
by rainwarrior
Great Hierophant wrote:When you watch this in 60fps, you can see some that combinations of colors cause the upper left square to visibly flicker, which I thought weird. I would have lingered longer, but I couldn't see it on the capture device's viewer, so I thought the effect was lost. When I converted the video to 60fps, it reappeared.
My captured picture is actually an interlaced image. If you look closely at the top left square, you can see that it is two alternating fields of magenta and yellow, i.e. the output is alternating frames this way.

I didn't intend for the capture image to be a thing to verify your emulators against, just a sample image demonstrating some of the colour artifacts that can be produced. For instance, the edges of white text via the capture card show a lot of rainbow stripes there, but a different decoder, like the one in my TV, produces much cleaner definition on that. A lot of this stuff varies significantly from device to device. (Also don't forget there are 6 possible alignments of the PPU!)

Re: NTSC pattern torture test ROM

Posted: Thu Dec 29, 2016 10:24 pm
by feos
Bisqwit wrote:It is not only the matter of modifying the constant.
You have to reverse the phase of the colorburst for every other scanline, too (or something like that, I don't remember the specifics).
Yes. Here's what I used in my FCEUX attempt (with a lookup table and 768 pixel long line):

Code: Select all

const  float   phasex  = (float) 5/18*2;
const  float   phasey  = (float) 1/ 6*2;
const  float   pi      = 3.14f;

float alpha = (x*phasex + y*phasey)*pi;          // 2*pi*freq*t
if (y%2 == 0) alpha = -alpha;                    // phase alternating line!
moire[x+y*18] = Y + U*sin(alpha) + V*cos(alpha); // modulated composite signal
EDIT:

The 768-pixel approach was bad, because it matched neither tuner result, not TV result, because of oversampling of YUV. But I was generating too little versions of each color: tuner output (640 pixel wide) shows about 17 versions of each color, which is how pixel freq alignes with Luma sample freq. The end value is a direct average of the Luma samples present in that pixel:

Image

Re: NTSC pattern torture test ROM

Posted: Fri Dec 30, 2016 1:59 pm
by Bisqwit
rainwarrior wrote:My captured picture is actually an interlaced image.
I was wondering why the per-scanline color alterations appear to be twice as thin/frequent as in my screenshots.
Thanks for explaining.

EDIT: Hmm, I wonder if you can generate composite video in real time with e.g. Raspberry Pi GPIO DAC (or some ARM Nucleo board), for testing different outcomes.

Re: NTSC pattern torture test ROM

Posted: Fri Dec 30, 2016 5:14 pm
by Zepper
Does not work here.

---------------------------
Mesen
---------------------------
Mesen não pode iniciar pois foi incapaz de carregar MesenCore.dll devido a falta de dependências.
---------------------------
OK
---------------------------

"Mesen cannot start because it was unable to load MesenCore.dll due to the lack of dependencies".