Matt Godbolt: Hey Ben.
Ben Rady: Hey Matt.
Matt Godbolt: It has been a while, hasn't it?
Ben Rady: Been a bit.
Matt Godbolt: I mean, not for our listener, obviously. Our listener, it's just been a month. But for us, things... life has overtaken us. A lot of things are going on. We are, in fact, on different continents right now.
Matt Godbolt: And I'm looking at my sound levels, in fact, and I'm wondering how awful this is going to sound. So I'm going to just tweak something. But, yeah, I apologize in advance to the poor editor who has to edit this because I am recording...
Matt Godbolt: on my laptop from my wife's childhood home in her bedroom where she grew up in Birmingham in the UK, which is not where I was planning on being around this time.
Ben Rady: Mm-hmm.
Matt Godbolt: But nevertheless, adult things happen and you end up in a different landmass. So that's me.
Ben Rady: Right.
Matt Godbolt: So apologies for the sound. And I still haven't actually changed it. Let me just do that now. OK. Now I'm going to start clipping and... let's see what that does. That looks... that looks better. No, maybe I am clipping now. I got excited. All right.
Matt Godbolt: This, my... this, dear listener, is going to be a heavily not edited at all podcast because Ben and I just need to record something so that you've got something to listen to.
Ben Rady: Yeah.
Matt Godbolt: Yeah. I met a number of people claiming to be our single listener at a conference recently, which was lovely. So shout out to the many single listeners that we had there. That was good to hear. It's always nice to get feedback. I mean, like, it's a funny thing that we do, right? We just chat, talk to each other. Apparently people listen to this, which is on them, in fairness. They don't have to. We're not making them.
Ben Rady: Okay.
Ben Rady: Yeah. Yeah.
Ben Rady: It's amazing. I don't understand it.
Matt Godbolt: So here we are. Yeah, we have no idea, as is normal, as is usual. But I've been doing some cool things that I would have just talked to you about because normally we would do this down the pub.
Ben Rady: Right.
Ben Rady: Yeah.
Matt Godbolt: But again, due to 4,000 miles between us, this is...
Ben Rady: Yeah. I haven't actually heard about any of this stuff, so it's not going to be... Yeah, I'm genuinely interested because I have not talked to you in a long time.
Matt Godbolt: the first time. So you know that I...
Ben Rady: Due to the aforementioned time dilation created by you going across the Atlantic Ocean that is stretched out.
Matt Godbolt: Is that what it is?
Ben Rady: Yes.
Matt Godbolt: That... it does make me wonder, because it does feel like we're in like the 1950s here in the UK, because they haven't got air conditioning and it is very, very, very hot.
Ben Rady: Uh-huh.
Ben Rady: Right. Right. That's...
Matt Godbolt: Someone should tell them about this new technology.
Ben Rady: Yeah.
Matt Godbolt: Oh, and they will not let me back in the country. Yeah. So one of the things that I got really excited about, well, you know, I love emulators. That's my thing. When I'm not forcing compilers to do things they shouldn't do, I am...
Matt Godbolt: emulating my childhood. And the thing that has really annoyed me all the time is that monitors are too crisp.
Ben Rady: Yep.
Matt Godbolt: I mean, we've talked about this before in a podcast, but like, you know, my very first computer, the first computer I programmed on was plugged into a portable color television, you know, full CRT bulbous screen,
Ben Rady: Yeah.
Ben Rady: Yeah. Right.
Ben Rady: Right.
Matt Godbolt: like analog push buttons, like when radio buttons were actual, the buttons you had on radios with a physical mechanism, you press one and the others pop out, you know, right.
Ben Rady: Right, right, right. Yeah.
Matt Godbolt: And then behind that was a tiny little thing you would tune to get it to the right channel. And then your, so your computer that you plugged in had to pretend to be a TV station, right?
Ben Rady: Right.
Matt Godbolt: It would generate radio frequency of PAL or NTSC at some frequency. You tune it into channel 36 in the UK or channel...
Ben Rady: Yeah, it was like three or four, I think. Yeah, three or four, something like that.
Matt Godbolt: Yeah. In the US, right.
Ben Rady: Right.
Matt Godbolt: And the TV didn't know that it wasn't actually plugged into an aerial listening to something off the...
Ben Rady: Right.
Matt Godbolt: But what that meant was, you know, not only was the CRT... not a perfect device. It's a very, very analog device that involves phosphors and things that... don't instantly light up and instantly fade away, which is part of their charm. But the picture quality was rubbish because you had to squirt color information down a single line. And it wasn't even like you could use a digital encoding, because this stuff had to work on like 1950s
Matt Godbolt: analog components when color TV was invented.
Ben Rady: Right.
Matt Godbolt: It's like the worst of all worlds. But it's really, really nostalgic to see the terrible picture quality that came from it.
Ben Rady: Right.
Matt Godbolt: And people would use this, right? There were tricks you could do to make colors look more blended and in some cases to achieve extra effects on a real TV that you won't get on an emulator.
Matt Godbolt: Anyway, this was annoying me.
Ben Rady: Mm-hmm.
Matt Godbolt: So I thought, right, sod it. I'm going to learn how this stuff works and I'm going to make my emulator faithfully reproduce all of the things, warts and all. And so I did one pass of this and it's a... it's kind of a fudge. It's like, yeah, we need to blur it a little bit. We need to do some of these effects. But it was like, no, this is not a first principles simulation of what's going on. So I thought I'm going to go deep rather than start by like just synthesizing the picture quality and that kind of stuff. Why don't I learn how to do it? How do I learn to be a TV person?
Matt Godbolt: I want to take a real BBC Micro or Sega Master System. I'm going to plug it into my computer. I'm going to use a software defined radio, which lets me decode radio frequency signals into essentially a stream of ones and zeros that I can read fast. And then I'm going to software decode that thing back into a color picture.
Matt Godbolt: And that's going to teach me everything I know about how the heck this works. And then I'm going to look at each bit of the code and kind of go, which things are available... What parts of that could I have done using analog electronics back in the day? Which things are like DSP tricks that you would only have had in high-end televisions and stuff like that? And now I can actually pluggably make a TV and say, I want a 1990s era
Matt Godbolt: type display, or I want... no, I want the actual 1984 Thorn TV that I had in my bedroom, which I have a photograph of, and I found... and I've got the manuals for, and I'm going to try and find an actual real one so I can do some real sampling. But you know, that's... it's been a journey, my friend. What do you want to know?
Ben Rady: Wow.
Ben Rady: Wow. Well, so, okay. So just to clarify exactly what you're saying here is you didn't have enough emulator in your emulator. So you added another layer of emulation on top of your emulator.
Ben Rady: So you have two layers of emulation.
Matt Godbolt: In fairness, I haven't put this into the emulator yet. There's a version in the emulator, but this is purely learning about the decoding. What I hadn't registered really is there's kind of two parts to the whole thing.
Ben Rady: Yeah.
Matt Godbolt: One is the RGB that is actually being generated by the computer, right? There is obviously RGB at some point.
Ben Rady: Mm-hmm.
Matt Godbolt: With the exception of NESes, which is a whole other story, and we don't have time for that, but like there is RGB, and then it goes through encoding.
Ben Rady: Yeah.
Matt Godbolt: And then the BBC Micro's output encoding circuitry would differ from the ZX Spectrum's one, from the Sega Master System.
Matt Godbolt: I'm sure all of the systems would come up with their own compromises about what's cheap to do or appropriate to do, to generate the signal. Then they would go through RF modulation, which adds a whole other thing in.
Matt Godbolt: They may or may not mix in the audio, because the audio is in there as well. And then they would send it off to the TV, right? So there's stage one is how does the output stage generate the RF signal that's coming out. And then stage two is which type of TV have you plugged it into?
Matt Godbolt: Is it a modern one? Is it a cheap and nasty color TV? Is it one of those ones where, you know, effectively over time, the heat of your... this is what I had with my friend Richard, we would go around his house.
Matt Godbolt: And after a lot of programming, the screen would start getting worse and worse and start shimmering. And we realized that, oh, you'd have to retune the TV as everything had gotten hot. And so all these analog components had gone out of lock effectively.
Matt Godbolt: And there was no... so it's...
Ben Rady: Yeah.
Matt Godbolt: Honestly, it's an amazing thing. And yeah, there's just so many layers. I've learned so much about how SDRs work, about how fast you have to sample stuff. Essentially, it's like an ADC.
Matt Godbolt: So it's like a sampler, an audio sampler, right?
Ben Rady: Right. Yeah, yeah, yeah.
Matt Godbolt: But not running at 44 kilohertz or 64 kilohertz. It's running at 32 megahertz.
Matt Godbolt: So it's 32 million samples a second, which is not totally unreasonable. It's fine. But the RF that we're looking at is a signal that varies and wiggles around a frequency that's like 400 megahertz or 300, 200 megahertz or something like that. So there's a kind of an analog trick for bringing down the signal from that really high domain down to a lower domain that you could then sample.
Ben Rady: Right.
Matt Godbolt: And how musical are you, Ben?
Ben Rady: You know, not particularly. And it's also possible that our listener is also not. So, you know, over-explaining is probably a good thing here.
Matt Godbolt: Right, that's fair. But right, so have you ever, you know when something is slightly out of tune, if you heard two notes that were slightly out of tune, they were both trying to be the same pitch.
Matt Godbolt: And so like, an A is 440 hertz, right? And now... yeah, I can't tell it's an A, right?
Ben Rady: Okay, yeah.
Matt Godbolt: I haven't got perfect pitch. But if it's... and then I also... someone played a 441 hertz sound,
Ben Rady: Right.
Matt Godbolt: I wouldn't be able to hear the difference. But if you played the two together, there's that horrible wobbling, whoa, whoa, whoa, whoa kind of thing that happens when they grate against each other.
Ben Rady: Yeah. Yeah.
Matt Godbolt: It's a crunchy, horrible thing when something is nearly in tune, but it isn't in tune, right?
Ben Rady: Mm-hmm. Mm-hmm.
Matt Godbolt: That, the frequency of the whoa, whoa, whoa of the two, beating and grating against each other, is the difference of the two frequencies.
Matt Godbolt: So 440 and 441 would give you a once a second wobbling sound.
Ben Rady: Okay, yeah, that makes sense.
Ben Rady: Right, right.
Matt Godbolt: So the trick, and anyone who knows about this for real, who's like done electronic engineering or whatever, is like screaming at their speakers right now, this is not a trick.
Ben Rady: Mm-hmm. I know.
Matt Godbolt: This is like just how it's done. But like the trick to me is, what you do is you play the two frequencies... when you want to tune to, say, 200 megahertz, you generate a local 200 megahertz signal using just your own oscillator.
Ben Rady: Okay.
Matt Godbolt: And you play that again at the same time. You multiply them. You mix them together. You multiply them in this instance. But like, go with me in this, my music analogy, right? And the result is, yes, you hear both of those tunes, but they're so high-pitched and high-frequency that they're then beyond what you can sample with your sampler. But the difference between them, the wobbling around, is much lower frequency. It's the difference of their frequencies.
Ben Rady: Okay.
Matt Godbolt: And so now you get a signal that is around about plus or minus, you know, however wide the various frequencies might be. And so by playing a 200 megahertz tone and multiplying that with whatever noise is happening off the radio,
Ben Rady: Okay.
Matt Godbolt: I can then sample that at, say, 32 megasamples a second. And what I've got is essentially a plus or minus, sort of, Nyquist limit is half of that, 16 megahertz around the 200 megahertz window.
Matt Godbolt: So I can get from minus, because it's the same, you can't tell if it's one hertz above or one hertz below.
Ben Rady: Okay.
Matt Godbolt: They both beat at once a second. So you get both the signals that are from like 200 to 216 and down to 184, whatever that... Right.
Ben Rady: Okay.
Matt Godbolt: But, and that's the band.
Ben Rady: And this is all to like bring these frequencies down into a range where you can sample them at the rate that you're able to sample them with the hardware that you have?
Matt Godbolt: Exactly. Without getting all those sort of like pointless noise of like lower frequency things that you don't care about.
Ben Rady: Okay.
Matt Godbolt: And then there's some other tricks that you have to do because, you know, again, you can't discriminate between something that's one hertz higher from what's only one hertz lower. And there's a trick. Maybe we want... if we talk about every trick here, we're going to be here for three hours.
Matt Godbolt: So I'm...
Ben Rady: And then the thing that's melting my brain here is that it's like, you know, you talk about this with audio and I can kind of like think about it, but it's like, this is television, right?
Matt Godbolt: Correct. Yes.
Ben Rady: So it's like, you know, it's not just audio. In fact, it's not even primarily audio. It's the signal that you're using to, you know, bend this, you know, electron ray, whatever the heck it is.
Matt Godbolt: Electron beam that's flashing back and forth.
Ben Rady: That's... yeah.
Matt Godbolt: Exactly.
Ben Rady: Right.
Matt Godbolt: And again, and it all had to be done in analog.
Ben Rady: Right.
Matt Godbolt: So you know this first stage I just described, you could imagine some kind of magical thing that oscillates. You get it tuning. When you're tuning the television, what you're really doing is tuning that oscillator to a frequency... that there's more...
Matt Godbolt: There's a middle stage. There's an intermediate frequency and stuff like that. But like for the purposes of this conversation, you're tuning an oscillator. And then the difference between the oscillator you tuned and the signal that's just got, of course, every TV station mixed into it will...
Matt Godbolt: will give you, will center it around the thing that you care about. And then if you filter the stuff that's higher and lower frequency, now you've just got your TV tune. But yeah, now you've got like another layer of encoding. So think about it as encoding. Now you've probably talked about, and I'm going to say a word that you're going to say a different way to me. And I don't know if it's a me thing or a UK thing, US thing. So the not-RF signal that you would plug in, the yellow lead on your old consoles where you didn't have the audio in, you would have like three leads, you'd have left and right audio, which would be red and white.
Ben Rady: Yeah.
Matt Godbolt: And then the yellow lead, which would be the video.
Ben Rady: Yeah.
Matt Godbolt: Well, that will be what kind of video?
Ben Rady: Oh, I don't know. RF video. I mean, but yeah, I always think of it as like, you've got component and comPOSite and... okay.
Matt Godbolt: COMposite is the word I was looking for there. Yes. So yes, I would say COMposite.
Ben Rady: Yeah. Oh, okay.
Matt Godbolt: I don't know if it's just a thing that I say. So, you know, our listener can have a think. But yes, so effectively there are like several layers of encoding.
Ben Rady: Yeah.
Matt Godbolt: The first thing is we're going to make something RF so we could transmit it over the... what, the waves, the airwaves, right? The composite is too low frequency and everyone would pick the same one.
Matt Godbolt: So obviously every channel has its own. But in there are two things, right? One is the composite video, which is itself composed of more things, which we'll get to.
Ben Rady: Mm-hmm.
Matt Godbolt: And then there's essentially like an FM radio signal that is the audio that is just on the edge of the video signal, either side of it, the way that it works out. And I'm a bit vague on this bit because I haven't got to that yet.
Matt Godbolt: But you can imagine, yeah, given the amount of spectrum that you're allowed to use, the bandwidth of radio range, you would kind of fiddle it around and say, okay, the FM lives in this part of it.
Ben Rady: Mm-hmm.
Matt Godbolt: And then the middle part is all this. And the much wider part, for what it's worth, is the TV signal, which is itself composed of several things, right? Red, green, blue, synchronization pulses, like this is the top of the screen. This is a new line, right? Now in our... you and me, these are packets. These are like binary encoding and you go like, how about the start frame, you know, whatever. But like, this is... it can't be the case, because we're talking analog era electronics.
Matt Godbolt: And so first of all, the first trick is that it's amplitude modulated onto the carrier. So there is the carrier, you know, the 200 megahertz that I mentioned before, is just a wiggling 200 megahertz signal.
Ben Rady: Yeah. Yeah.
Matt Godbolt: And we just turn the volume of that up and down like old AM radio, right?
Ben Rady: Yeah. Right.
Matt Godbolt: Forget frequency modulation. We're not modulating the frequency. But by flapping the amplitude up and down fast enough, we are actually using frequencies around it.
Ben Rady: Right.
Matt Godbolt: If you were to put it through a spectrum analyzer, you see that you get this bandwidth just because of the way it...
Ben Rady: OK, so just to reiterate some of this back to make sure I understand what's going on here. You've got, because it's television, you have this limited frequency in which you're allowed to use for your signal, right?
Matt Godbolt: Yeah.
Matt Godbolt: Correct.
Ben Rady: You're going to slice off some of that for the audio. You're going to slice off some of that for, you know, both channels of the audio. You're going to slice off some of that for the video. And then within that frequency, you're actually encoding the signal in the amplitude of the waves in that frequency.
Matt Godbolt: Correct, by modulating the up and down of that.
Ben Rady: Have I got that right?
Matt Godbolt: Yeah, yeah.
Ben Rady: Yeah. OK.
Matt Godbolt: And so the way that it's done is that a black picture is the brightest. So it's inverted, right? So a totally black screen would be just the normal
Ben Rady: OK.
Matt Godbolt: full amplitude... the RF signal.
Ben Rady: Yeah.
Ben Rady: Right.
Matt Godbolt: And this is also true, incidentally... Yeah, no, sorry, I'm confusing myself here. Right, forget... Go ahead.
Ben Rady: Is that true for the audio, too? This seems counterintuitive.
Matt Godbolt: I don't... I don't think so. The audio is separate from this. At this point, we've left the audio behind. It's been filtered off.
Ben Rady: OK.
Matt Godbolt: It goes into audio circuitry, and I haven't looked at that too much.
Matt Godbolt: But yeah, we've got this amplitude modulated thing where we want to extract from that essentially a single continuous analog signal from this wiggling thing.
Ben Rady: Okay.
Ben Rady: Okay. Okay.
Matt Godbolt: And the way that we do that is we treat the... Actually, I'm not sure what the circuitry does at this point, but we're looking for the amplitude. So let's just ignore the fact that it's wiggling anymore and just say it's the amplitude of this.
Matt Godbolt: We've got a thing that comes out. And now the amplitude is inverted such that the darkest picture is bright, the loudest, and the brightest picture would be almost no signal.
Matt Godbolt: It never goes completely zero, because then you don't have anything to lock onto.
Ben Rady: Yeah. Yeah.
Matt Godbolt: But it's there. So we've got a range now. We've got a range of, say, voltages. And... It's unimportant that it's inverted, other than like the very dark signal is always there. So even if the picture's black, you can tune into the stupid thing and actually know that you've picked up a black picture, right? So from now on... quickly, early on, you invert it the other way around. So it looks sane to humans where, you know, bright is high and dark is low. Let's go with that, right?
Ben Rady: Yeah.
Matt Godbolt: You with me so far? Because, yeah... the first thing is we invert it.
Ben Rady: Yeah. Is this why television static is mostly white?
Matt Godbolt: It is... we'll get to that actually. That's good, hold that thought, my friend, because this is the cool bit, right?
Ben Rady: Okay. All right. All right.
Matt Godbolt: So yes, we've got this, let's just say goes between zero and one volt, right? Where white is... one volt is bright white and zero would be black, except what we're gonna do is we're gonna say, no, no, no. We need a way of signaling the synchronization pulses.
Matt Godbolt: We need to say, this is the beginning of the screen. And we need to say, this is the beginning of a line, because what's happening behind the scenes is that there is... we want to synchronize the electromagnets in the TV with this picture so that they start at the top of the screen, they slowly go down and more quickly, they flip from left to right.
Ben Rady: Mm-hmm. Mm-hmm.
Matt Godbolt: And we wanna make sure that everything's synchronized. Otherwise the picture rolls or it's diagonally skewed because the rows aren't aligned, right?
Ben Rady: Yeah.
Matt Godbolt: But we need a way of saying, this is a big... this is like, we sort of out of band. And so the out of band is lower than black. It's like we go... we say, right, black is actually gonna be 0.3 volts.
Matt Godbolt: And anything below 0.3 volts is like blacker than black, and it's actually a signal. It's like, a thing is happening. It's our sort of out-of-band signal, because we know also that while we're between lines and while we're pulling the beam from the bottom to the top, we actually don't want to paint anything to the screen. Otherwise, you'd start seeing splurge as the light... as the beam retraces its steps, right? And you get pictures being overwritten with crap. So we want it to be low and we might as well just say, well, when it goes really low, that's a signal to you.
Ben Rady: Okay.
Matt Godbolt: Good so far?
Ben Rady: So you said blacker than black, like the amplitude... as the amplitude decreases, that is our range of signal, right?
Matt Godbolt: Yes. So we've got effectively between like 0.3 and one volt is the normal black to white.
Ben Rady: Okay.
Matt Godbolt: And then below, we're already talking... yeah, sorry, I've already inverted it so that it makes sane.
Ben Rady: So you've... we've already talked about it being flipped at this point. Got it.
Matt Godbolt: Yeah, yeah, yeah, yeah.
Ben Rady: Yeah, yeah, yeah, yeah.
Matt Godbolt: I'm sorry about that, yeah.
Ben Rady: No, that makes sense. I'm back with you again.
Matt Godbolt: Okay, yeah, I did do a bait-and-switch, changed my sort of... there, because it's just easier to think of it the right way up, right, the way you would want to see it, right, the way that it actually gets transmitted when you're using a composite cable. Because effectively by the time we have taken it away from being this amplitude modulated signal to just a signal between zero and one volts and turned it the right way up so that it makes sense, where now that's what you would get out of your composite cable.
Ben Rady: Right, yes. Right, right.
Ben Rady: Yeah.
Ben Rady: OK, got it.
Matt Godbolt: Right. So no audio, no weird wiggling, just pure something you could put into an oscilloscope directly and go, oh, I can see what that's doing, as opposed to just a mass of wiggly lines.
Ben Rady: Right.
Ben Rady: Yeah. Yeah.
Matt Godbolt: Right. And I forget...
Ben Rady: Right.
Matt Godbolt: So TVs used to be black and white. You probably remember this.
Ben Rady: I don't know. Actually, that's not true. I did actually own a black and white TV.
Matt Godbolt: You're younger than me. I never... I think we had one black and white TV, but it was in my nan's house.
Ben Rady: Yeah. We had a cheap one that was black and white. That was like an extra one.
Matt Godbolt: But yeah, so the trick is that whatever we do to get color into our signal had to be, back in the 40s and 50s, whenever it was color was, had to be backwards compatible in the worst possible way.
Ben Rady: Yeah.
Ben Rady: Mm-hmm.
Matt Godbolt: Like they couldn't squeeze three copies. They couldn't go, oh, this is now red and this is now green and this is blue, because your black and white TV would be like, well, it's just... I only show what red is, or something like that.
Ben Rady: Right, right.
Ben Rady: Yeah, yeah.
Matt Godbolt: So there was a trick here. Yeah. Oh, but I missed over the... Going below 0.3 volts is a signal to either pull the signal up to the top of the screen if it's a long period of time, or if it's a short burst below 0.3 volts, it pulls it back to the left.
Ben Rady: Mm-hmm.
Matt Godbolt: So there are like two independent circuits that are always running inside the TV, one of which is just a square, both of which are sawtoothed.
Ben Rady: Yeah.
Matt Godbolt: Sawtooths, excuse me, sawtooths.
Ben Rady: Mm-hmm.
Ben Rady: Yeah.
Matt Godbolt: And they're set to be, you know, just slightly longer than a frame and just slightly longer than a line, so that they will naturally just kind of go zero to left to right, left to right continuously, and top to bottom slower, but continuously.
Ben Rady: Mm-hmm. Mm-hmm.
Matt Godbolt: But the pulse going that low for a while is a signal to say, doesn't matter where you think you are, start dragging yourself to the top of the screen if you're the top to bottom, or left of the screen.
Matt Godbolt: So that also gives you a certain amount of slop, where... not AI slop for a change, slop where if, for example, your TV's
Ben Rady: Yeah.
Matt Godbolt: crystal oscillators, or they weren't even crystals, but the little oscillators that were doing these sawtooths, was slightly out of spec, then, you know, you just keep rewiring, pulling them back onto the right sort of thing. And if there was no signal at all, then they would sort of free run. And that's when you would see the picture rolling, for example. If there was enough to see where the picture was, but you didn't... the TV couldn't pick up that synchronization pulse anymore, then it would just free run.
Ben Rady: Yeah.
Matt Godbolt: And so the whole picture would spin over and over again. And I realize I'm gesturing wildly with my hands, which doesn't help our listener at all.
Ben Rady: Yeah. Yeah.
Matt Godbolt: So without getting into too many of the specifics, both of those things cause the TV to reset the top bit and the left to right bit. The interesting thing for me for the first time about this was like realizing that that sawtooth from top to bottom is always running.
Matt Godbolt: You know, you and I think that the beam scans from left to right, then it goes down a bit and comes back again sort of diagonally, and then it scans the next row left to right.
Matt Godbolt: But it doesn't. It's doing... it's always a slightly diagonal line from left to right.
Ben Rady: Yeah.
Matt Godbolt: And then it's a much less diagonal angle from right to left, because it's much quicker going back than it is going across.
Ben Rady: Mm-hmm.
Matt Godbolt: And so you'd think that the whole picture would be slightly wonky because it's... and it is.
Ben Rady: Yeah.
Matt Godbolt: And so they just adjust the damn magnets to turn them by half a degree backwards so that it's all the right way around again.
Matt Godbolt: It's just, you know, beautiful.
Ben Rady: Oh...
Matt Godbolt: And I had to model that because I'm like, why is everything slightly off?
Ben Rady: Right.
Matt Godbolt: Oh, yeah. Yeah.
Matt Godbolt: Okay, so that's the retrace. So we were talking about black and white. So you could imagine now it's really, really easy. We have these two electromagnets that are being dragged... dragging the electron beam up and down, left and right. They're synchronized with the signal. And then the rest of it is just the brightness.
Matt Godbolt: And that's just how many electrons we squirt at the screen in the direction the beam is currently pointing. And there you go. You've got a black and white telly. You are done. Hooray, high fives all round.
Matt Godbolt: But now we want color. And so, you know, as a computer programmer, we would say, oh, V2, you know, or you sort of come up with something.
Ben Rady: Right.
Matt Godbolt: Well, we've got the red, the green, and blue, and three channels. And then somehow, oh, there's also a black and white version. But no, they had to come up with a really clever way of getting color into the signal.
Matt Godbolt: So the trick, and this is the great thing, the trick is take... we take the color information and we break it down into three components.
Matt Godbolt: Rather than red, green and blue, we pick brightness, which we already have, because that's what the black and white signal was. And then we have two chrominance signals.
Ben Rady: Mm-hmm.
Matt Godbolt: And you know if you've ever pulled up a color picker in any of your art packages, you've probably seen the ones where you've got HSV and you know you've got brightness and then two different other sliders.
Ben Rady: Mm-hmm.
Matt Godbolt: And you can pick any color with three things. That's the beauty of like any space is that if it's a 3D space, you can have any coordinate system and you can get to all the points of the coordinate system as long as you've got three of them.
Matt Godbolt: And that's what it is. So like we have essentially a brightness, which is overall how bright something is. We have how saturated a color is, between totally that color or white,
Matt Godbolt: white, however white the brightness would let us go. And then we have a kind of color wheel for the third axis, which says, well, which color, if we're not white, which color are we tending towards?
Matt Godbolt: And you could imagine you're just, you know, just a genuine, honest kind of color wheel and like, well, it's a direction on there. And so now we've got three signals again. So that's cool. And one of them is one we're already transmitting.
Matt Godbolt: So can we hide the other two signals somewhere that a black and white telly that hasn't even... doesn't even know the color exists
Ben Rady: Right.
Matt Godbolt: doesn't see them, without using more bandwidth, because we can't add... you know, we've got all these TV channels packed into the RF spectrum.
Ben Rady: Yeah.
Matt Godbolt: And although we're talking... I'm talking about the composite part now, the width of that signal has to somehow be squished into the radio spectrum. So what we do is we observe that if we wiggle the brightness really fast and not that much, maybe the black and white TV won't notice it.
Ben Rady: Mm-hmm.
Matt Godbolt: Because it's a crap old piece of analog electronics, it's old anyway, a higher frequency wiggle in the brightness would probably go unnoticed, or at worst just makes the white areas look a little stippled in places where it's just varying quite quickly.
Ben Rady: Mm-hmm.
Matt Godbolt: Okay, but now we've got a wiggle. What do we do with this wiggle? Well, this wiggle, we can somehow encode two pieces of information with that wiggle.
Matt Godbolt: The amplitude of that wiggle could be one of the other dimensions.
Ben Rady: Oh, OK. Yeah, and the frequency is the other one?
Matt Godbolt: So now we've got one of them, but how do we get the third one?
Ben Rady: Yeah. Is it the frequency of the wiggle?
Matt Godbolt: What else... what's that, sorry?
Ben Rady: Is it the frequency of the wiggle?
Matt Godbolt: It's not the frequency... that would make sense at some level. And I think SECAM, the French thing, used something akin to that. But that would be too easy.
Ben Rady: OK.
Matt Godbolt: Also, there are limitations on what frequencies we can use for a variety of reasons, to do with the fact it has to not be a frequency that's going to interfere with this signaling itself, because all these other components are going.
Matt Godbolt: And also the RF... sorry, the audio is in there as well. So there was some careful picking of these numbers so they all don't divide into each other and you end up with like stripes or things like that.
Ben Rady: Okay.
Matt Godbolt: Because there are artifacts, which is partly why we're talking about this, because it... those are artifacts I'm trying to capture in the emulator. So the other thing that we can fiddle around that isn't the frequency is the phase.
Ben Rady: Oh, okay. Yeah.
Matt Godbolt: So you can slide that back and forth and have the peak at this point in time or push it back a little bit, and now we've got another dimension.
Ben Rady: Right.
Matt Godbolt: And so the phase, as you'll recall, can be measured as between 0 and 360 degrees, if you want to think about it, right, as a sine wave. You can like slide the sine wave back and forth. And that maps nicely into our 360 degree color wheel that we had.
Matt Godbolt: So that's how we pick the color. The color is just the phase of that wiggle.
Ben Rady: Okay.
Matt Godbolt: And then how saturated it is, is how wiggly... the brightness of that wiggle. So heavily saturated colors on a black and white television do have a grainy texture over the top of them now, because you can see the wiggle in it if you look hard.
Ben Rady: Mm-hmm.
Matt Godbolt: So that's cool. We have smuggled two pieces of extra information into our channel. Black and white TV people don't really notice it. But we've now got a new problem, which is that analog electronics is not very good at measuring things like phase differences.
Matt Godbolt: Because how accurate do you have to be with your signal to know if it's in or out of phase? And in and out of phase with what?
Ben Rady: Right.
Matt Godbolt: Maybe you need a PTP timestamp synchronization and now everyone's on the same page.
Ben Rady: Maybe.
Matt Godbolt: You're down to the... No, no, we haven't got any of that. It's got to work with crap electronics in a 1960s box.
Ben Rady: Yeah.
Ben Rady: Can I... can I take a guess?
Matt Godbolt: So we need... Yeah, please. This would be great, because I've been just jabbering.
Ben Rady: Can I... can I guess?
Matt Godbolt: So tell me, what do you think?
Ben Rady: So there's two checkpoints that you have. One is the screen reset and one is the line reset.
Matt Godbolt: Yes, go on.
Ben Rady: So it could be either of those, or maybe even both.
Matt Godbolt: You are bang on the money, my friend. And it almost makes me think you're cheating and Googling, but I can see your hands, so I know you aren't. Yeah.
Ben Rady: I am not. I am not.
Matt Godbolt: So at the beginning of each line, after we've had the little dip below the 0.3 volts that says, hey, this is the beginning of the line.
Ben Rady: Mm-hmm.
Matt Godbolt: And so we know that the electron beam has been dragged back and is currently now way off the left-hand side of the screen.
Ben Rady: Mm-hmm.
Matt Godbolt: We then come up to like a black level, because we're in the sort of border on the left-hand side.
Ben Rady: Right.
Matt Godbolt: And just before then, and there's something like... there's the front porch and the back porch.
Ben Rady: Right.
Matt Godbolt: There's some stupid names for these things, which is, you know, stupid, hilariously funny.
Ben Rady: Interesting. Yeah.
Matt Godbolt: We just do a quick burst of that color signal, just a little of it, that's short enough that, again, it's not going to be visible. It's off the side of the screen.
Matt Godbolt: But anything that's looking for it will see it and go, ah, two things. One, this is a color TV signal. It's not a black and white TV signal.
Ben Rady: Right.
Matt Godbolt: It's a color TV signal, because I've seen the color burst. Two, synchronize my very short-lived one-line's worth signal
Ben Rady: Right.
Matt Godbolt: local oscillator of this color frequency, so that I've now got a reference that I can compare everything else to, and I can compare it to see if it's in or out of phase and by how much. And so that is the trick of getting color. Now decoding that is a pain, but you mentioned something about the black, you know, static.
Matt Godbolt: So do you think you can answer your own question now?
Ben Rady: Yeah.
Matt Godbolt: Why is it black and white?
Ben Rady: Well, because it's not going to have that burst right at the right time to tell it that it's a color TV.
Matt Godbolt: Bingo. Bingo. So the color TV set will... will assume it's a black and white picture, because it can't synchronize to it and it can't find the color burst.
Ben Rady: Yeah.
Matt Godbolt: And so it will suppress all of its own color decoding circuitry. And so the noise only comes out in black and white. Congratulations, sir.
Ben Rady: Wow.
Matt Godbolt: You've won today's podcast.
Ben Rady: Well, I just want to thank everyone involved, you know, my friends, my family here to support me.
Matt Godbolt: Yeah.
Ben Rady: And I'm just really proud of this accomplishment today. So thank you. Thank you all. Really appreciate it.
Matt Godbolt: But so I guess, you know, and so emulating and simulating this has been an absolute blast, and learning all of the various things that they do to the TVs that do that, like, period appropriate. And I learned, for example, that there are delay lines for something we'll hopefully talk about in a second, which required a piece of glass that's exactly the right size so that like essentially it puts...
Ben Rady: Wow.
Matt Godbolt: There's like a piezoelectric crystal on both sides of this bit of glass, and it knows it takes 64 microseconds for the vibrations to make it through to the other side. And that's how you get a delay line, an analog delay line, for 64 micros.
Matt Godbolt: You're like, what?
Ben Rady: Wow.
Matt Godbolt: There are other things that use specially shaped piezo crystals that then can filter out frequencies. It's just so clever. But while we're here, and as we've just been talking about the color burst in particular,
Ben Rady: This sounds like an amazing project. Yeah. Yeah.
Matt Godbolt: What is the name of the European, or most of the European, TV standard?
Ben Rady: PAL.
Matt Godbolt: Do you know what PAL stands for?
Ben Rady: Oh, I do not.
Matt Godbolt: It stands for phase alternating lines. And I think that probably tells you something about what happens on each line. And maybe about the color part, because this is where NTSC, which is something like the North American Television Standards Committee or something like that, which was developed first, incidentally.
Ben Rady: Phase alternating lines.
Ben Rady: Yeah, yeah. Uh-huh.
Matt Godbolt: So NTSC predates PAL by about a decade or so. And so PAL learned from NTSC and went, we like everything about this, but... there's this one thing, and they fixed something.
Ben Rady: Yeah.
Ben Rady: And one thing, so phase alternating lines.
Matt Godbolt: Uh-huh.
Ben Rady: So if we're using phase to control color, the hue, right, then my guess here is that we shift the phase every other line.
Matt Godbolt: Okay.
Ben Rady: I'm trying to think of why that helps, though. I don't know why that helps.
Matt Godbolt: Exactly. Yeah. Well, let's talk briefly, because I've looked... we're at 35 minutes, gosh.
Ben Rady: Why does that help?
Ben Rady: Right.
Matt Godbolt: Let's talk briefly about one of the problems that NTSC had. And actually, this would be interesting, because I didn't grow up with an NTSC set. I grew up cursing them in the 90s, because we had to like try and make our graphics look good on NTSC TVs for like games.
Matt Godbolt: But they wouldn't have suffered from the problem I'm about to describe. So... The problem with the phase being the color information is that tiny, tiny errors start moving you around on that color wheel, right?
Ben Rady: Mm-hmm. Mm-hmm.
Matt Godbolt: If you're just out by one degree, you're moving around this color wheel. And so you had a... you may have had an extra control on your early analog TVs that I would not have had.
Matt Godbolt: I had color, brightness, contrast. Those were the three things. Do you remember another one? I'm really... you're younger than me, so you probably don't.
Ben Rady: You know, I don't remember.
Matt Godbolt: It's been a while.
Ben Rady: It's been a bit.
Matt Godbolt: So my understanding is that earlier American sets would have a tint as well.
Ben Rady: Oh, yeah. Yes. 100%. Mm-hmm.
Matt Godbolt: And so you would fiddle with the tint, because people's skin color would look like orangey or greeny or whatever sometimes, because... now you probably know where I'm going with this... because of small errors in the phase. Those errors commonly come from the signal being reflected off a building near you. And if you take two signals that are identical and add them together with just a tiny delay in one of them, it's similar to shifting the phase of everything.
Ben Rady: Oh, yeah.
Matt Godbolt: And I'm going to wave my hands a lot here, because I've read the math a few times and it hasn't really gone in.
Ben Rady: OK.
Matt Godbolt: But there's sort of an unfortunate thing, either if the TV is just not good at locking onto that signal and the parts aren't great, or if there's a systematic error because everything's being slightly delayed and you're getting a mirror copy coming in, then the colors would morph, and it would depend on where the TV set is.
Ben Rady: Right.
Matt Godbolt: And it depends on like how warm things are. And you... so fiddle around with this tint. So this is the thing the Germans who came up with PAL was like, how can we fix this? And they made the observation, which to this day lives on in things like JPEG.
Matt Godbolt: So, and that is, humans care about the brightness far more than they care about the color.
Ben Rady: Okay.
Matt Godbolt: Right. So, you know, in, say, a JPEG, we store the... the brightness information at a higher resolution than we store the color information, because then you tend not to notice.
Ben Rady: Okay. Yeah.
Ben Rady: Yeah. Yeah.
Matt Godbolt: This trick comes from this area.
Ben Rady: Right.
Matt Godbolt: So they said, well, what if it didn't really matter if we were storing color on every line, unique color in every line? And so it's not... it's not actually that they changed it. But what they said was like, if we flip the phase every other line and we delay the previous line's color and add it to the current line's color, we cancel out any phase error between the two of them, because they've been affected by 180 degrees different in each direction.
Matt Godbolt: And every time I say that out loud, I go, there seems like there's something wrong with that. But I sit down, I do the maths, and the phase error cancels out. But at the loss of like the fact that you are mixing together two lines' worth of color information to kind of get one blurrier line of color information.
Ben Rady: Of course it was the Germans.
Matt Godbolt: So that is the... and again, probably without a picture or even, again, without me being very confident about it, but that phase alternation and knowing that the TV is going to do obviously the reverse, any error, any fixed error that you've added in cancels out, because when you reverse it the second time, you're adding minus... if you're bouncing off a building, it's adding three degrees of error.
Ben Rady: Yeah.
Matt Godbolt: You add in three degrees of error on the first line. You subtract three degrees of error on the second line. You assume that the other part is the same.
Ben Rady: Yeah.
Matt Godbolt: And so those two cancel out. You divide by two and you get just the right phase out of it.
Ben Rady: Yeah.
Ben Rady: Okay.
Matt Godbolt: And so PAL, phase alternating lines, and NTSC, which was "never twice the same color" for that reason.
Ben Rady: PAL.
Matt Godbolt: That was the bad acronym for it.
Ben Rady: That's funny.
Matt Godbolt: So, yeah, this has been... an odyssey of discovery, as I said. I can now just about real time in software decode... without using GPU trickery, I can decode this all in software, and I can point at each bit of the code and I can say, yeah, I know what that bit's doing. And whatever... things I didn't cover, because we're already 40 minutes here, is that having done this decode, I now do a physically based electron beam simulation where I actually use a lot of
Ben Rady: Wow.
Matt Godbolt: virtual magnets to drag a virtual stream of electrons onto virtual phosphor, which then bloom.
Ben Rady: Oh, wow. Wow.
Matt Godbolt: And as the overvolting of like a too-strong, too-white signal happens, the pixels bloom. The current starts going high in the electron guns and you get more, wider spew of like electrons that hit more area of the screen.
Matt Godbolt: What else? Then you can... I can simulate the fact that like they often... the flyback, which is this hilariously named but complicated thing that builds up enough charge to have this really high voltage that's needed, you can deplete it by having too much white for too long.
Matt Godbolt: And then essentially the picture starts sagging after that, which is, you know, on... again, on cheap sets where there wasn't much capacitance, or, you know, you would put a pretty big white thing.
Ben Rady: Wow.
Matt Godbolt: And but I remember having one, my dad nicked a monitor from work. And it had this problem where if you had like a bright white title bar of like a game, everything else underneath it was kinked, because that bright white area had kind of gone and dragged all the power out of it.
Matt Godbolt: And it's like, had to recharge it up to be able to like pull the electron beam properly. It's just amazing. It's so fun. And you have been a fantastic foil listening to me. I think I needed this more than I knew, actually. I did say to people at ACCU, I said, this is therapy for us... well, for me.
Ben Rady: I will...
Ben Rady: I cannot... I cannot wait to see this working in person. I just... I really am looking forward to this.
Matt Godbolt: So the fun thing is is that I've left my desktop computer plugged in with the SDR in Chicago, 4,000 miles from where I'm sitting here, and I've left my Sega... foolishly left my Sega Master System plugged into it and turned on, with a Wonder Boy 3 cartridge in it.
Matt Godbolt: And I'm still able... I could just about stream the picture live that's being decoded, everything could just about keep up, and I could just about transmit fast enough, like some crap MJPEG stuff, to get to me here. And I've got the satisfaction of watching the little character play the attract mode in full color with, you know, all of... warts and all. It's been a journey. It's been fun. But yeah.
Ben Rady: Did it... did that survive the power outage up in Evanston a couple of weeks ago? Okay.
Matt Godbolt: No, no, I had to ask the dog sitter who was in the house to go, can you just go and press this button?
Ben Rady: Oh, my God.
Matt Godbolt: I had to send a pic... Luckily, I had a picture from one of the many times I was doing the Advent of Compiler Optimization for like the thumbnails. I said, the computer is here, like a big drawn-on arrow, press this button.
Ben Rady: Okay.
Matt Godbolt: And yeah, they were able to turn it back on for me.
Ben Rady: My god.
Matt Godbolt: And yeah, I didn't get them to go in the basement and turn the NAS on, which has also died, but... my son has now done that. But yeah, hilarious stuff, man.
Ben Rady: All right. Excellent.
Matt Godbolt: Thank you for listening, my friend. This has been fun for me. I don't know what else to do now other than go on... I'm spent. I've been talking at the screen for this time.
Matt Godbolt: But yeah, good... good shout on working out where the puzzles were.
Ben Rady: This is... this is an amazing project.
Matt Godbolt: That was... that was impressive thinking on your feet.
Ben Rady: I mean, you know, whatever. We're all just nerds here. That's how that works.
Matt Godbolt: So I'm probably going to edit this and put it out like in a couple of days' time, which I think will probably be the first time ever that we've had a Two's Complement go out within the time that we recorded it, which then unfortunately means we have none left in the bank.
Ben Rady: Oh, yeah. Within a few... Right.
Matt Godbolt: So dear listener, you will... the next one in August will be another seat-of-the-pants job. But...
Ben Rady: Hopefully it's released on time, but no promises at this point.
Matt Godbolt: Correct.
Ben Rady: Right. Yeah.
Matt Godbolt: Correct. Events may overtake us at this stage.
Ben Rady: Yeah.
Matt Godbolt: Yeah, that's true.
Ben Rady: Yeah. All right.
Ben Rady: Well, until then.
Matt Godbolt: Until then, yeah, have yourself a great time.
Ben Rady: Okay. Cool. See you later.
Matt Godbolt: Bye.