
Accurate CRT Simulation - jsnell
http://gamasutra.com/blogs/KylePittman/20150420/241442/CRT_Simulation_in_Super_Win_the_Game.php
======
jloughry
In the _analogtv.c_ source code, by Trevor Blackwell (part of XScreenSaver) is
this comment [1]:

    
    
        A maxim of technology is that failures reveal underlying
        mechanism. A good way to learn how something works is to
        push it to failure. The way it fails will usually tell you
        a lot about how it works.
    

To mimic the image on a 1970s-era colour TV, XScreenSaver uses an accurate DSP
simulation of all the analogue circuitry, including bandwidth limits, noise,
and distortion. A gigahertz processor is _just_ capable of keeping up with
this.

[1] In _XScreenSaver: a collection of free screen savers for X11 and MacOS_ by
Jamie Zawinski [2].

Edit: if you want to read the source code---highly recommended!---retype the
address below by hand or you'll become acquainted with jwz's countermeasures.

[2]
[https://www.jwz.org/xscreensaver/xscreensaver-5.34.tar.gz](https://www.jwz.org/xscreensaver/xscreensaver-5.34.tar.gz)

~~~
zaius
Ironic that JWZ takes offense to the link since the code in question is by
Trevor, who is a cofounder of YC.

Mirror here:
[http://web.mit.edu/ghudson/dev/nokrb/third/xscreensaver/hack...](http://web.mit.edu/ghudson/dev/nokrb/third/xscreensaver/hacks/analogtv.c)

~~~
alayne
I think he's had that HN redirect for years. He is blocking hotlinking
directly to files.

Try [https://www.jwz.org/xscreensaver/](https://www.jwz.org/xscreensaver/)

~~~
nitrogen
No, he blocks/redirects all traffic with HN as referrer. Kind of a jerk move,
which sucks because his site is full of useful stuff.

~~~
dekhn
jwz is a smart guy, but ultimately ... a bit inflexible and jerkish. I used to
argue with him over using C++ in xscreensaver (I wrote a couple savers,
glplanet, pulsar and glextrusion). I wanted to write a full scene graph
implementation, a physics library, and a bytecode VM to implement screensavers
without having to write a ton of low-level C++ code. Unfortunately, jwz's
constraints include "Every screensaver must be a single C file" and "no C++",
which while possibly wise when he first expressed it, has become a canard.

~~~
binarycrusader
There's nothing wrong with asserting "no C++" in systems software, especially
on *NIX. The stability of the C++ ABI has generally been terrible for a long
time, and by avoiding C++ in a component that's heavily used, a lot of
maintenance headaches are avoided.

As one of the maintainers of the C++ ABI for an operating system, I assure
you, it is best avoided for system components unless there's a compelling
justification.

~~~
dekhn
xscreensaver is not a "system" component. Nor is it systems software. It's a
game engine that only rarely takes user input.

~~~
binarycrusader
It's a system component in the sense that it's typically distributed as part
of an operating system. Not in the sense that it's a "kernel" or something
like that.

As someone that helps build an operating system distribution, we consider
Xscreensaver to be a system component.

Also, for licensing purposes, the GPL, as an example, considers software
distributed with the system to be a system component in some scenarios. For
example, "GPLv3 has adjusted the definition of System Library to include
software that may not come directly with the operating system, but that all
users of the software can reasonably be expected to have."

~~~
dekhn
Your definition is weird. Which distribution is this?

xscreensaver is X11, not GPL.

Why does a C++ ABI really matter in a system distribution? All the distros
I've used are internally consistent in their ABI and update all their deps
when the C++ ABI is updated.

~~~
binarycrusader
_Your definition is weird._

Not from a distributor's perspective ;-)

 _xscreensaver is X11, not GPL._

Correct, but since it is distributed as part of the system, or is a component
that most users will have, then, as an example, if you link your GPL'd code to
Xscreensaver's API, that's ok, because it's considered a "system library".

Really, I was referring to more for the purposes of definition than anything.

 _Why does a C++ ABI really matter in a system distribution?_

Because ABIs create a point of synchronization, and internally for that
distributor, that create a flag day where a given set of components must be
rebuilt at the same time.

Ideally, for a distributor, you don't rebuild the entire world every time one
component changes. You only rebuild what you have to, since every delivery
causes new binaries to be produced, which then in turn increases the amount of
downtime for consumers that are upgrading.

As such, changing ABIs (thankfully GCC's doesn't change as much as it used to)
create unnecessary churn, and if you can easily avoid them, you usually do (as
a distributor).

------
Animats
From the article: _" As the electron guns sweep across the screen, varying
their intensity to adjust brightness, they tend to overshoot their desired
value and bounce back a short time later. This creates alternating vertical
bands of light and dark seen at the edges of high contrast changes in
brightness."_

That's caused by a different effect. NTSC has terrible color bandwidth. The
YIQ signal is really an I (intensity) signal at full bandwidth, and YQ signals
with severely limited bandwidth (because, during the transition from black and
white to color, they had to be stuck in subcarriers of the main black and
white signal. NTSC Color TV is really greyscale TV with color tweaks
superimposed.

You can only go through the YQ color space about 10 times across the width of
the screen. The way to simulate this is to convert to YIQ, apply a low-pass
filter horizontally to the Y and Q components, then convert back. Note that
this is a horizontal issue only; in the vertical direction, every line can be
a different color without problems.

~~~
imtringued
>NTSC Color is really greyscale TV

My old CRT only supported PAL. So this is the reason why NTSC inputs were
displayed without color.

~~~
hausen
Your old CRT is probably PAL-M, a variant of PAL. Was it made in Brazil?
[https://en.wikipedia.org/wiki/PAL-M#Compatibility](https://en.wikipedia.org/wiki/PAL-M#Compatibility)

~~~
boomlinde
I (scandinavian) have a few old TVs and monitors that are able to synchronize
to the NTSC clock, but are unable to decode NTSC colors. It's not uncommon,
and even my 1084S does it. As far as I understand this, PAL is just a color
encoding standard, and the synchronization characteristics typically
associated with it are broadcast standards, e.g. PAL-M, PAL-B etc. If you have
a TV that decodes PAL at 50Hz there is a good chance that it will decode PAL
at 60 Hz even outside countries that had these broadcast standards.

For NTSC, since it's only really the timing and color encoding that differs
it's then not uncommon to get a grayscale picture from NTSC input.

------
rasz_pl
In civilized world we used SCART or JP-21 to achieve pure RGB and avoid most
of the artefacts author is so nostalgic about.

[http://retrorgb.com/rgbguide.html](http://retrorgb.com/rgbguide.html)

so no, our consoles didnt look like
[http://i.imgur.com/Pq2Yra4.png](http://i.imgur.com/Pq2Yra4.png), they did
indeed look pixel perfect
[http://retrorgb.com/images/Link%20RGB%20Compare.jpg](http://retrorgb.com/images/Link%20RGB%20Compare.jpg)

~~~
PhasmaFelis
Well, the important thing is that you got a chance to be smug about your
30-year-old TV.

~~~
rasz_pl
This whole article is a "smug about someones really BAD 30-year-old TV"

~~~
PhasmaFelis
If you think that lovingly describing the details of an obsolete technology is
"smug," then you are seriously on the wrong website.

(BTW, did you notice the part where the author specifically says he's talking
about NTSC, and other standards work differently? Because, to be honest,
getting all nationalistic over obsolete TV connection standards is kinda
weird.)

------
Sami_Lehtinen
Some claimed that low refresh rate on screen caused it to flash. But that
wasn't true, as long as the screen had slow enough phosphor. With older CRT
displays it was totally possible to read the text from the screen after three
seconds of turning the display off or giving clear screen command. You could
also play with magnets on the screen, not all screens got great degauss
feature, so little magnet play was fun. It's also important to monitor that
CRTs aren't equal. If you used regular 70s color TV it was very different from
high end 21" Trinitron CRT used before flat panels became popular. Here you
can see one nice CRT:
[https://www.youtube.com/watch?v=IweoaOb53XQ](https://www.youtube.com/watch?v=IweoaOb53XQ)
One of the reasons why many computers didn't use 80 char line length was that
TVs didn't produce sharp enough image and it was impossible to read 80 char
lines. Of course it was also possible to modify displays to produce sharper
image. With Spectravideo it was possible to use separate card to produce
sharper image and 80 columns. [http://www.samdal.com/SVIDOCS/STM-
I_SVI806.pdf](http://www.samdal.com/SVIDOCS/STM-I_SVI806.pdf)

~~~
kuschku
Funnily, my family still uses a Trinitron daily – it’s our youngest and
largest TV. Around 30", amazing quality.

~~~
Pxtl
Jeeze, that thing must weigh as much as a vw bug.

~~~
jcadam
There were CRT-based 1080i 16:9 Trinitron HDTVs available (briefly) during the
early days of HDTV. My parents had a 34-inch model. Heaviest television set
I've ever had the displeasure of moving. Definitely a two-man lift.

Awesome picture quality, though.

~~~
dekhn
Yeah, I had one of these. It was great for its day, but definitely far too
heavy to be practical. Having that device carted out of my house (the mover
said he could have carried it on his back, but they used two people and then
nearly dropped it anyway) was one of my greatest days.

------
Coincoin
At first I though the curvature was exaggerated but then I looked at some
pictures and it was actually even worse.

This reminds me the first time I used one of those flat CRT, I was so used to
the convex curve that the flat one looked concave.

~~~
makomk
Well, anything Trinitron-based didn't have nearly as much curvature for
technical reasons, so if you always used higher-end sets and monitors you
might never have had one with this kind of curvature.

------
mholt
If you're on Mac (or iOS), I highly recommend the Cathode app[1]. It's a
terminal in the style of old CRTs, and I always get a kick out of using it.

[1]:
[http://www.secretgeometry.com/apps/cathode/](http://www.secretgeometry.com/apps/cathode/)

~~~
Razengan
And it's free text-editor cousin:
[https://itunes.apple.com/us/app/blinky/id550873221?mt=12](https://itunes.apple.com/us/app/blinky/id550873221?mt=12)

Very cool and pretty fun.

~~~
karmakaze
Fun, Thanks. Noticing that 'Pokey' in the 8-bit Atari emulation is actually
the analog in/sound chip--ANTIC was display.

------
chadaustin
I love this topic and compiled a slew of related links last year:
[https://chadaustin.me/2015/11/crts-pixels-and-video-
games/](https://chadaustin.me/2015/11/crts-pixels-and-video-games/)

------
Stratoscope
This is a fun and interesting article!

There are a few minor errors in this section:

> Cathode ray tube displays work by repeatedly sweeping an electron gun back
> and forth across the extents of a fluorescent screen. The strength of the
> electron beam may vary during this sweep, and this in turn affects the
> brightness of the phosphors it illuminates. In early black-and-white models,
> only a single electron gun was necessary; with the introduction of color
> TVs, three electron guns were used, each tuned to a different phosphor,
> which would appear as the color red, green, or blue.

> The points of light created by this interaction are too diffuse to produce a
> sharp image, so a shadow mask is used to focus the electron beams before
> they reach the screen. A shadow mask consists of a metal plate with holes or
> apertures designed to filter out unwanted electrons. The shape of the shadow
> mask and the configuration of its holes vary by model and contribute greatly
> to the characteristics of the resulting image. The shadow mask also defines
> the dot pitch of the display, effectively limiting its highest possible
> resolution. As we will see later on, the dot pitch of the display does not
> necessarily correspond to the resolution of the displayed image.

The three electron guns in a color CRT aren't _tuned_ to the different color
phosphors, they are physically positioned so that the holes in the shadow mask
or the gaps in the aperture grille block the beams from hitting the unwanted
color phosphors and only hit the phosphor that each beam should light up.

In a shadow mask CRT, there is a triad of phosphor dots (or stripes in newer
TVs) for each hole in the shadow mask. The electron beam from each gun goes
through this hole at a different angle, so it only hits the correct phosphor
and is blocked from the other two.

An aperture grille CRT uses a similar concept, but instead of mask with holes
in it and triads of dots, it has a series of parallel vertical wires and
vertical phosphor stripes serving the same function.

The mask or grille is not there because the electron beam is too diffuse to
produce a sharp image. A monochrome CRT has no shadow mask or aperture grille,
and with proper focusing it can be plenty sharp. The mask or grille is there
simply to block the the beams from hitting the wrong color phosphors.

More information is in the Wikipedia articles on shadow masks and aperture
grilles:

[https://en.wikipedia.org/wiki/Shadow_mask](https://en.wikipedia.org/wiki/Shadow_mask)

[https://en.wikipedia.org/wiki/Aperture_grille](https://en.wikipedia.org/wiki/Aperture_grille)

~~~
Someone
One thing with wire-based aperture grilles: tapping the side of the monitor
will make the wires in the aperture grille vibrate, throwing of the colors.
So, if you want to emulate a Trinitron display really, really well, you need
an acceleration sensor and, for good measure, a microphone (to detect loud
noises at the right frequency to make the wires vibrate)

I also have a question some reader might be able to answer: if you do the
simple implementation, (at least) 2/3rds of your electrons will hit the
aperture mask. To improve power efficiency, you would need finer control over
the video signal. did any television ever do that? Or did they already have to
do it to prevent the electron beams for different color from interfering with
each other?

------
fake-name
Maybe it's just me, but I think the old CRTs looked horrible, and I find games
and other applications which strive to mimic them as closely as possible
extremely visually unpleasant.

Sure, there's the nostalgia factor, but 20 seconds later I'm over it. If you
have a game or something that has a CRT emulation mode, __let me turn it off
__.

------
jhallenworld
I looked into early camera tubes recently- it's amazing that they work at all
:-)

The "image orthicon"
[https://en.wikipedia.org/wiki/Video_camera_tube#Image_orthic...](https://en.wikipedia.org/wiki/Video_camera_tube#Image_orthicon)
can only be described as a Rube-Goldberg device.

------
SixSigma
NTSC - Never The Same Color

------
hellbanner
I'm seeing a game development article on the front page almost every time I
check HN now.

How many of you are making games?

