 And we can even wire these memories together in the funky way, where it becomes stateful. So this here is a flip flop, where basically the D input is stored in the Q output whenever the clock goes to low to high. So here, you can raise the clock, and then after that, you can do whatever you want with D, the Q output will remain what it was when we raised the clock. Yeah, we can go. Okay. Next one. Yeah, so then an FPGA is basically something where you have these blocks and inside these blocks you can put your own Boolean functions that are internally built out from lookup tables that are internally built from these navigates. And then between them, you have these interconnects, and you can configure, so you can configure the content of each box, like what is the Boolean function inside each box, and there's a register inside each box, and you can configure the connections between the boxes. And you can configure, you can route some of those connections to these connectors to the outside world. Okay, so. And so how do you program this? Like what does it look like? Actually, first of all, you don't program this, it's on a computer, right? It's a circuit. So what you're doing is you're designing a circuit that is made up of the lookup tables and the register. And the model of designing the circuit that is most widely used is the so-called register transferred model. So what that means is that we pretend that we have registered the part between which size. And in a real FPGA, this could be multiple registers, like, you know, horizontally, I guess, you can cut them up. So you have these registers, and then you have a combinational circuit, so you have some functions. So this is just Boolean gates wired together, and then the function is fed the current value of the register and something from the outside world. And then the result of that combination circuit is fed back into the register. And of course, because we want this to be something useful, we also have some fact that we'll get the result of this. Of course, you can put this type either here or here, which means either we can get, you know, the value just as it's computed or just as it comes out of this circuit, or we can get it in the next cycle as it's already stored in the register. Yeah, so this is the model, and so we can build interesting and fun stuff just by choosing the right function and why we're going to be in a fun way. So yeah, then we can go on. So, yeah, this is all the Haskell stuff that doesn't matter for us. Okay, so what is the fun thing to do? What is something that's tangible and gives you immediate feedback and gives you an expectation about a game, right? So an FPG that plays a linear game means that you have a circuit that implies a particular game, so you're not building a computer. You don't have that right software for that. That's not what you're doing here. So instead, what we do is we take, we build the smallest, simplest possible game console. So these are the single button input and some video output, and it has a register containing the state of the game. And then we have some circuit between the logic of the game. So this is some combination of circuits, and then we have the video system. And then one of the output, so the video system has two outputs, the video signal, which will connect to a screen, and the other output is whether this is at the end of the frame. So, you know, because the TV is frame by frame, and in fact, we will make it a bit more constrained and we say that, okay, the only effect that the frame people have is that it enables the register update. So basically game logic runs, like we have to, sorry, doesn't run yet, that's a problem. So game logic is like this fixed circuit. The output is whether the button is present in the current game state, but we only update the game state, find the video hardware tells us that it's the end of the frame. So this way we have a regular time, like regular clock for how the game is set up, which is of course several levels of construction removed from the clock that drives the whole circuit. So what does it mean to generate video? So we want this thing to output the signal that can fly into the monitor, and then we get a game. So CRP, which is the old kind of screen, right? Okay, everyone knows that it can be very stupid, right, before as you do. The way that works is that you have an electron beam that's like standing in the screen, and it goes like a typewriter. So it's in a first line, and then it goes like the second line, third line, and so on. And it does this, and basically when it gets here, it expects to get a signal that tells it to go back to the start of the next line. And when it gets here, it expects the signal to tell it to go back to the first line. So you just give it, you know, trigger here, here, here, and then eventually here. And the screen will make sure, like a circuit inside your TV to make sure that it does the scanning. And in particular, in VGA, which is an all-denominal video standard, that is, this sweet spot that is old enough that it's super easy to understand because it's based on how these old TVs used to work. So it's very widespread. So these days, we get screens filled up and VGA input, and you know, you can order, like, a typewriter, a gadget from AliExpress that you convert in VMA, VGA, and so on. And the other direction is much better. So, yeah, we can go on. So all we need to do is we need to generate the right horizontal and vertical pulse, and there's a, and there's a specification for particular videos. So for example, for our game, we want to produce 640x480 resolution at 60 frames per second, and then we can just look up, you know, the big group of VGA timings that it takes this many microseconds to wait, and actually, if you add those two together, that's how long you have to wait until you have this pulse. The pulse has to be this many microseconds long, that's all. And this looks quite complicated to implement. Like, like, yeah, all these weird, like 1.907 microseconds, how are we going to wait exactly that? So, first of all, what you can see is that, of course, because it's a rectangle, and the vertical thing will happen at the end of the line. So the vertical timings are naturally quantized to the time that it takes to draw a full line, full horizontal row, and, and, yeah. So we did the VJC moves, so it's kind of so called pizza clock, and basically everything is quantized to that. And now, instead of all those weird numbers, we actually get 640, 1696, and 48 pixels. So if you have a timer, a clock that runs at 15.75 megabits, then what we need to generate a very video signal is to count to 656, then count to 96 while we pull the signal low, then count to 48. You do this 491 times, then you do it, you know, two more times, then you do it 41 more times, and you have a very video signal. And then it has been played, but that doesn't matter first. Okay, so then, I have one more. Yeah, so this gives us a blank screen, right, and now we have a valid signal, you can connect it to the screen, and it will show you a black screen, but it will be a well-formed black screen, like it will, it will change the way it generates it. But first, that's enough. We want to be able to draw on the screen. So how do we draw on the screen? So as the electron beam is scanning the screen, we want to change its color. Now, the color part is a bit, so I said that CRPs are good because they really do explain. Let's forget about color. Let's just pretend that they have a gray scale TV, like the old black and white TVs. The color is just a bit more complicated. So if you have a black and white TV, then you just need to change the intensity of the electron beam as it scans the screen. So our output from our circuit is this horizontal convert of sync signals and also the intensity of the beam at any given moment. So if you want to draw with this, if only we know where the electron beam is scanning at any given moment, then we can just set the intensity to what we want to show at that given point. So if you want to have a fully black screen with a single white dot in the middle, then we just count, we keep time, we count okay, okay, so here, here, here, here, here. So if you want to get to the middle line, you have to keep counting, you keep counting, all of these seconds independent of us in the screen, but we keep time. And now we know, okay, so we're now in the middle line, we keep counting, we keep counting. Now we're in the middle of the middle line. Okay, now set the intensity to high instead of the lowest, which means it's going to be the white test. And so we take these counters that already used to generate the right sync signals, and we expose those counter to the rest of the circuit. Yeah, you can go. Yep. Okay, and then we can write some fun in the week. So, I was basically asked to talk about flash, which is a cast of refugee that has to be strange that like a 15 minutes hot. So what is the game that is simply not, but we can actually build it from scratch in flash has to in that much time. The bird is actually very, very simple game except for the bird is fair because like growing the bird is very tricky. So, so what's it going to look like so. Hang on. So okay so what we want to do right is we have three missing two missing pieces right, we have the game logic so we have this combination of certain that is fed the old state and the buttons and button press and then we have the one that takes my coordinate of the electron beam on the TV, or the screen, and then give us the color or the intensity. So now I'm switching back to color but color is three, because if a color is three black and white. And each one has like a foil, a color foil on it, right, they're just matched together. That's the complicated. And so, yeah, so we're going to make a very crappy very much like a bird so I don't like it like crappy bird because, and this is the bird and then the whole game is fully in the sense that the, that the pattern of the pipes is not random and it's just going to keep scrolling the same, but that's because you know, it's not a lot to do anything more complicated. And then when the game already just flashing the red background. Okay, so. Okay, and. So, so, so the game logic is my simple. How do we draw this. So remember we have from the video system you have the X and Y coordinate of the current. It's a long that being drawn just now. So, basically, if I want to put the bird somewhere, all I need to do is to make a circuit that compares the X and Y coordinate of the current we've grown pixel to the X and Y coordinate of the bird. And we know where the bird is because the game state has the high, the bird, like if you think about the perfect bird right state is, where are you vertically or something. Right vertically, you know, keep falling unless you press the button because then it's going out. So, so, so you just compare. Yeah, if X, like, or that is here, then you say, if X, like, or it is here, you say, and same way for the pipes, if the Y coordinate is below the high of the pipe, which you are, the pipes, of course, are also needed for the game logic, because that's how you know whether you died or not. So that's, that being here and then you can try to find that in green or blue. And then if it's the end of the game, instead of blue, you do red. So, okay, so but this looks even prettier than what I think the perfect word to look like turns out that you can make a very simple improvement, which actually doesn't really, you can't really see it on the project version, but you can see because what I do here is that the X coordinate after, you know, like division by 16, or whatever, yeah, nobody's the color is not the resolution that you see. So, but what happens is that yeah, we were white and then we have like a lighter or sorry black and then lighter green and then darker green based on the remainder of dividing X for that by 16. So it gives us, which I'm, yeah, you can't see it too, but I promise you, just to get it on the screen, then, yeah, using this nice, Super Mario line, JD, 3D effect of five. And of course, to get the new verse 16, it's crazy because you get the last four bits of the X coordinate, so you don't really need any complicated division and circle. Okay, so I guess I don't have a live demo. Can we open the YouTube video. Yeah, on the test. So here this is, yeah. So this is that this is an activity in that word that's completely working up for this project, by the way. And then. Yeah, yeah, and then you can't see anything like a resolution is going by a zoo, but but at least you can see something. You can see the community. So, so yeah, so it's a, so the end result of just to summarize is that every small circuit is really simple because all it is like two counters, you know, one of them is the horizontal counter and then it feeds into the vertical counter. And I mentioned a counter, then a bunch of comparisons to compare the output of the counter with some x like ordinates of the bird and be the pipes. And that's it. And then it gives you a game that you can play. All the buttons to go out to ease the button to start. And that's it. You know, that can be answered in a smaller timeframe. What did you do. Oh, so actually, so it's not going to bunch of FG board to run on anything as long as so good to the way trash works and it's very long, which is one of the industry standard. So, or HDL so so you can synthesize anything as far as the IO, the only IO you need is video output and the single button. So, the, in this video I'm using the next three states that are completely over a field, and the video one is a good one because it's like so ancient and so so small, but I have a like that. The one that had the open source chain, you know what I, I see ice party. Yeah, so that means has some guests and so I have now with them work for that as well but I haven't infected yet. So, I think that would be a very nice work for this because it has an open source chain. So, like, why did you do it on the game. Why did I, but the whole point of this was to originally was to give a demonstration of flash is something that is simple enough that it can be fully realized. Okay, so like, if you're asking like, if you want to play, that's important. And, you know, you don't have an icon that's going to work. There are simpler ways to get to the point where you can play it when building an FPGA. I give you guys right, but this is the other way around this is more like, Oh, what is a fun thing you can. I can build an FPGA that is simple enough that it can be done in a day and explain in an hour and that's something that's recognizable. Yeah, this is not just a random circuit. You really can't all this is perfect for like, even if I didn't tell you that right if you just saw the yellow thing going with the green thing, you would have said, Oh, that's. No, so I didn't implement even that. It really is a crappy bird. It's not that bird. So this is completely like hard wire. So if I can see here, I think you can see better than in the video. It could be random. I wouldn't take much right, but it would have taken like, let's say 10 minutes of time. So yeah, and there are lots of things you can do that could be about this. And of course there's no good reason that the playfield should be the exact way from the screen so there's no good reason that anything that moves out here immediately comes back. You could have something longer. This is all everything is simplified to just make certain description. So I have often for my entire life. Maybe one hour max of experience. So, why would you go to write this project in a store and then and then custom quality. So I assume we weren't here at the previous time. Okay, so if you can actually do like this size is pretty fun. Yeah, so basically I won't go into your question. So basically, all the sense of very long and the other two mainstream part of it. The ones that are used by all the vendor tools and so on and flash compiles to very lots of it can be packed to these days. And very long and they are not used languages. If you come to it from a point of view of like a summer, someone who works with languages, and not an electrical engineer. I mean, you love it because they don't necessarily know better. The same way that I don't like, you know, the same way that I have no idea like what the power is actually where it certainly is right because I don't care. Yeah, same way. There are aspects of language design that could actually help you and make you more productive and give you more tools of attraction. So for example, I really like how using Haskell, I can write these reusable components. So this of course is itself a thing because I don't want to make it. But if I were doing it for real, I would, for example, use a reusable video signal director, where the type of it ensures that if I use Haskell, I can't use it from the wrong block. And also the type of it, you know, telling me that it's going to be 640 by 80. So that's what the next four minutes are going to be and I can't accidentally try to do anything with it. Right. So, so you have all these typing constraints that that you can use those on your stuff and the. Okay, then for example, in the, in the Intel AT-ATC that's written in Haskell, the microcode is set to be at compile and by time checking the microcode, we can ensure that there's no situation where you want to read and write at the same cycle from some memory address because there's a machine that we are re-explanating, which is, some people are too long to read and single-port read. So in any cycle, you can either write to it or read from it. And that's something that we can ensure that the microcode has this invariant at synthesis time, which is Haskell. That sounds very nice. It sounds very nice. But I can tell you, it's under any more committee. So look at my slides after this when you have time and look at the actual code that we have to write. The actual Haskell that we have to write to get where it's going. And then you will see it's very high-level, simple. It doesn't exactly what you want it to do without having to worry about one of the things that we don't want to worry about. So like, for example, we just, so to make it to counter, right, we just write the polymorphic function that accounts to anything and then we just instantiate that twice because that's for countered. And then by saying that the VJ signal generator needs you a 640 by 48 visible coordinates. Yeah, that time itself can drive the, so we have to write the comparator that we, for example, compare the counter to 640 to see if it's in the first half that invisible or the second half where you need like the same figures that get that's proven by the times. So there's lots of like neat things that you actually need to be aside, but I don't have time. And then yeah, this is not the only way to sell on flash and Haskell. So that's why I said, you know, I'm going to just talk about that.