NTSC pattern torture test ROM
Moderator: Moderators
- rainwarrior
- Posts: 8759
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
NTSC pattern torture test ROM
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.
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.)
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.
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.)
- Attachments
-
- ntsc_torture.nes
- NTSC pattern torture test ROM
- (40.02 KiB) Downloaded 2043 times
-
- ntsc_torture_src.zip
- source code for ntsc_torture.nes
- (5.66 KiB) Downloaded 995 times
Last edited by rainwarrior on Fri Dec 30, 2016 6:06 pm, edited 2 times in total.
Re: NTSC pattern torture test ROM
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). 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. And this is what it looks like on an actual game: 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)
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). 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. And this is what it looks like on an actual game: 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)
- rainwarrior
- Posts: 8759
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: NTSC pattern torture test ROM
There are six possible colourings depending on the phase of the PPU at time of reset.Sour wrote:the top left part makes me wonder if the coloring is correct
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
Here are some sample pictures of what my QuickBASIC NES emulator produces for this test ROM:

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):

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:

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



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):



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:

It is quite a close match to the first sample posted by rainwarrior, if we ignore saturation differences.
Re: NTSC pattern torture test ROM
MESEN implementation:
feos want to modify this algorithm for PAL-Filter in near future.
But sines must be recalculated.
feos want to modify this algorithm for PAL-Filter in near future.
But sines must be recalculated.
- Attachments
-
- tor.mp4
- (1.54 MiB) Downloaded 14261 times
Re: NTSC pattern torture test ROM
I'd be really grateful if someone modifies the constants to the PAL standard.
Is it here?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.
- rainwarrior
- Posts: 8759
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: NTSC pattern torture test ROM
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.Bisqwit wrote:The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).
Re: NTSC pattern torture test ROM
That depends on someone with a PAL NES being willing to run test patterns on hardware on short notice. Are you such a someone?feos wrote:I'd be really grateful if someone modifies the constants to the PAL standard.
Re: NTSC pattern torture test ROM
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
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
It is not only the matter of modifying the constant.feos wrote:I'd be really grateful if someone modifies the constants to the PAL standard.
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, that would be it.feos wrote:Is it here?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.
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.rainwarrior wrote: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.Bisqwit wrote:The horizontal lines in the bottom left of the screen (border region) disappear if I scroll it upwards (00 EF or lower).
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.Eugene.S wrote:<video attachment>
-
- Posts: 780
- Joined: Tue Nov 23, 2004 9:35 pm
Re: NTSC pattern torture test ROM
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.
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.
- rainwarrior
- Posts: 8759
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: NTSC pattern torture test ROM
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.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.
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
Yes. Here's what I used in my FCEUX attempt (with a lookup table and 768 pixel long line):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).
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
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:

Last edited by feos on Fri Dec 30, 2016 2:59 pm, edited 1 time in total.
Re: NTSC pattern torture test ROM
I was wondering why the per-scanline color alterations appear to be twice as thin/frequent as in my screenshots.rainwarrior wrote:My captured picture is actually an interlaced image.
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
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".
---------------------------
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".