Maybe you have seen that some type of consoles have gone on sale: the Analogue Nt, Analogue Pocket, Mister FPGA or the Mister Multisystem. They all run on an FPGA. Or maybe a colleague has taken an arcade machine and put not a raspberry inside but an FPGA. And I know people who are quite up to date with video games who don't even know what an FPGA is. And those who know them have notions that they are very precise systems, that they emulate games perfectly. But when you use the word emulate, experts on the subject get angry. So we understand that FPGA is not the same as traditional emulation. So what is each thing? Let's see it in this video. Simulation The first commercial video games worked only with electronics: transistors, logic gates, things like that. If you don't know what they are, think about small components that are soldered to a board and that together can make something more or less interesting, like a pong. They were used a lot in the beginnings of video games: in the first arcades like Breakout, the first console: the Magnavox Odyssey, or the first pong consoles. All of these are systems without a processor, they are not computers, they are electronic machines, not computing. And I say without a processor, not that it doesn't have chips, one way to distribute logic gates or other components is on chips, even Pong-type games became fashionable where all the game logic came on a single chip. And in fact in these systems the game as such is found directly in the circuit design, that is, that machine only serves to play that game or the games for which it has been designed. If we want to imitate a game of this type, we can make a computer program that imitates the behavior of these components, or directly imitates the behavior of the game. In this case it is called a simulator, because we are not emulating a computer, but an electronic system. Emulation Most consoles and gaming systems have a mix of two types of chips. On the one hand there would be these chips that only do one thing, like those in pong, but in a more modern console they can be used to make music or to generate the video signal. These types of chips are called ASICs. And the other large family of chips are generalist processors, which can do many different things, and what they have to do at each moment is indicated with a program that is in memory. That is, they run associated software. Usually this is what we know as CPUs, or GPUs. But each processor has its own set of instructions, that is, it is as if it had its own language. So if we try to make a system, for example a console, run a game from another console, we find that it has different specific chips for some tasks and that is not going to work, and also the CPU speaks a different language and does not understand anything about that game. . And this is where emulation comes in, in this case it would be a program that when faced with the game behaves like the console that understands that game, but when faced with the new console it is like just another program. I would say that he acts as a “translator between languages”, although with many quotes. And in fact it would be more correct to say that they are emulators / simulators, because we really simulate the specific chips part and we emulate the general processors. But hey, it is usually just called an emulator, more importance is given to the latter. I think we are more accustomed to emulators, we even know the names of these programs: Snes9x, Dolphin, Duckstation, Citra... Each program serves to emulate one or more specific systems. There are also meta-emulators like retroarch that provide a certain common configuration, and then bring different emulators underneath which they call cores. But each one is still an emulation program. And how are emulators made? Well, it is usually done with a top-down approach. That is, we start from a system, what do I know, the NES. And what we want is a program that imitates the behavior of the NES, but without having an NES underneath, but on a computer or a mobile phone or whatever. And what is sought is to imitate the behavior, underneath the code can and is usually different than the original system, sometimes taking advantage of the characteristics of the target system. Let's give a silly example but one that you can understand. Maybe we see a MUL2 instruction in the processor of a console for which we want to make an emulator, and apparently this instruction returns the number that you pass to it multiplied by 2. Right now I can think of 3 ways to do it. If the machine I'm making the emulator for has multiplication it could do number * 2, it could also do number + number. There is even a very curious thing that can be done when you represent numbers in binary, if you move all the bits to the left and add a 0 to the right, it is the same as multiplying by 2, and many processors allow you to do that. The thing is that in principle we don't care what's underneath, it matters that the result is the same as on the original machine so that the games behave the same. And that's how most emulators start working, what matters is the result, that the game looks and plays like on the original console. But in the end little things come up that you hadn't noticed. Let's say that I am left with the option of adding the number to itself, but the original machine did the thing of moving the bits to the left and also the number that came out on the left was put in another place in memory, but we had not I realized because no game looked at that number, but suddenly trying it out, a game comes out that does use it in a specific effect. Well, this happens all the time and that's why emulation often doesn't behave well with all games. We would have to investigate these cases and improve the emulator so that it behaves faithfully in as many cases as possible. And a curiosity, I was asked in a comment about MAME because of course, each arcade that emulates is a world with a different board and many chips, sometimes even made expressly for that game. The first M in mame is for multiple, because it is actually a compendium of emulators to be able to play all the arcades. In fact, there are also simulators inside, you can play pong or breakout with MAME. It is one of the clearest cases of everything that can be played, enjoyed and preserved when there are 25 years of development in a community. And right now if we started to develop a new emulator for an arcade game in MAME, we would have to write the program that unites the data from that board and the different chips, but for example we would not rewrite the code to emulate a Z80 chip, but rather What references the version already made in MAME So basically there are two steps: 1 is to emulate each chip, and 2 is to emulate each board. If a board can have interchangeable games, you would only have to change the ROM, as in a console emulator, there is no need to make an emulator for each game. This could be the case with famous boards like Neo-Geo, CPS-2 or Naomi. Clean room design This section refers to legal rolls, we are going to talk about a way of working that is used to heal yourself. The legal bases are different in each country, most of what I am going to say here is true for the United States, but hey, since they are the empire and dominate the world, it is what it is. When you develop an emulator, the first thing you do is try not to get sued. And the first reason they could sue you is because “you copied them.” Legally, this can translate into lawsuits of various types, such as considering your work derivative of theirs, or that you have infringed a protected industrial secret. The clean room design implies having 2 separate teams, that is, there cannot be people in common between the two groups. The first group investigates what they want to emulate, sees how it works, and does the work closest to reverse engineering. But instead of copying what you find, what you do is define a specification based on your research. This specification is passed to the second team that is responsible for programming it, but without knowing the details of the original implementation. This way of doing the work means that the new code that imitates the original probably has different things in its guts, or if it is similar, They can claim that it is coincidental and not a copy. Clean Room Design can be understood as a way of reverse engineering that minimizes the chances of being sued for copying the original design. It is not infallible and it is not the only way to do it, but it is a fairly widespread one. The origin does not come from the world of emulators either, in reality the legal background of all this is from processor designers, because they copied each other's designs trying to create compatible computers, and there were many lawsuits for all this in the 80s and 90s. FPGA We're here. FPGA is a different type of processor than the ones we have seen so far. FPGA stands for Field-programmable gate array. These processors work as if they were a bunch of connected boxes and the function of each box can be configured, each box is programmable to behave like logic blocks, they normally have 4 inputs and what logic to do with that data is programmed. With these boxes you can simulate logic circuits, memory or registers. And also the connections between these boxes are also configurable. It would be like assembling a Lego, but we can choose each piece and then how each piece is going to connect with the others, but without them having to be together. It is also important to note that the FPGA chip has access to the inputs and outputs, which are the connections of the chip with the rest of the components. So we can think of a button on a controller, whose signal enters through here, the logic of the console is computed, and through this other side it emits the output signal, video, audio or whatever. This is the basis, a simplification, in reality FPGAs have more things inside to simulate clocks, that is, what tells each chip how fast it has to go, more memory, more complex blocks, even traditional processors embedded inside the FPGA to some things. But the basis is this: connections, logical blocks and the connections between those blocks. And the configuration of all this is done through a program called core, which is what configures all those boxes and their connections. And that core can be configured to behave as a specific sound chip or a generalist chip, like the CPU of a Megadrive. And you may not see the difference between generalist processors and FPGAs, because both can be "programmed", right? A generalist processor has the instructions it has and you can make programs using those instructions, but you cannot change them. THE FPGA is not about making programs, but about designing chips, it is of a lower level. If we design a chip or a complete system, we can send it to a factory to be physically manufactured, with its transistors, logic gates, and so on. But we could also run that design on an FPGA as a core. So the FPGA is like manufacturing computer chips and systems, but by software. A software that configures the hardware at the lowest level. In practice you can put a core that behaves like a Z80, the master system cpu, and after a while change it for a core that behaves like a Ricoh 2A03, the NES cpu. You have changed the instructions that the same chip is capable of executing. You have changed the language that that chip understands, because it is actually a programmable chip and we have placed the core of a specific processor on top. And we are not restricted to programming a single chip, but rather several chips and the connections between them. That is, we can put a core that is a complete and functional Super Nintendo. The most important thing here is to understand that if we want a core that imitates a console, the design is done from the bottom up, just the opposite of an emulator. Here we do not start with a game and how it should be seen, we start with the hardware, by seeing each component of each chip, each connection and trying to imitate it in an FPGA core. And if everything behaves properly and is completed, in the end we should have a system capable of running games like the original system. And that is a known advantage of FPGAs, as they are built taking into account every detail of the hardware, when they work well they are usually very precise, almost perfectly imitating the original system. +Other uses We are constantly thinking about using the FPGA as an equivalent system for emulation. To be able to play certain machines on a thing with an FPGA, but there are more uses for this technology related to video games that I would like us to see, even if it's quick. Have you noticed that the controllers of the most recent consoles also have their software updated? That means the controllers have memory and processors and stuff in them. And it is not something new, many peripherals have chips or small processors to control their operation. In the event that something a little old breaks, we can try to find a replacement, but sometimes it is not so easy to find a specific controller for an old arcade or personal computer without ruining another machine. Here you can also use FPGA, with a small one we can simulate that component and replace it while preserving the behavior. For example, I have seen that there are projects to replace with FPGAs: the Commodore 64 sound chip, the famous SID, compatible ISA cards or 6502 processors. FPGAs are also being used for image converters and scalers. To be able to connect old consoles to modern TVs or capture their image. It occurs to me that they could also make the everdrive, those cartridges for playing roms on the original hardware, have an FPGA inside to simulate any extra chip that those cartridges had. It is even interesting for prototyping new low-power hardware. Consoles like the Playdate, or if we wanted to make a peripheral like a gun that works on modern TVs carrying an image recognition chip inside. In these cases, producing a few test chips can be very expensive, especially if we want to vary them, detect problems and improve the design. A traditional chip has a large initial cost, then mass producing each chip is cheaper. If you are going to use a few for a prototype, it is better to buy generic FPGAs and design a core. With this we have already taken a look at other uses of FPGAs, you can do many more things than just simulate old consoles and arcade games. But in this video I wanted to focus mainly on that, so we are going to directly compare emulation and FPGA. Emulation vs FPGA It is quite complicated to check the first emulators and FPGA cores dedicated to video games. Furthermore, many times they are a demonstration without further presentation to the public. From what I have seen in my search, there have been usable emulators since the early 90s and they became more popular in the second half. FPGAs for video games have more movement, reaching almost 2010. So we are going to leave it at 30 years versus 15. Therefore , when we talk about the precision of FPGA cores, it is true, but sometimes they also have errors because many cores are very recent, while some emulators already have several decades of development behind them. Also there are fewer people using FPGA than emulation, so it may take a little longer to find a problem. But even so, I would say that FPGA cores mature faster and after a few iterations they give a more refined experience than emulators. But the other problem with being more recent and needing specific hardware is that there are fewer systems with a core than with an emulator. For example, many arcade boards are not supported in FPGA, not even relatively well-known consoles. I recently saw the first core of Neo Geo Pocket announced, surely when this video comes out it will already be available, but that means that until now this console could not be played via FPGA. Emulation comes at a cost in performance. That extra layer to be able to run games from another system means that we need a more powerful machine than the one we want to emulate. It depends a lot on the type of architecture and the power of the original machine, there is no fixed standard. For example, right now in the middle of the Play 5 generation, the Play 3 emulation is still a bit half done and the Switch emulation, which is the current console on sale, works better. But we could summarize that emulation normally works with systems from 1 or 2 generations ago. However, for FPGAs we have another way of measuring how far we can go: the number of boxes that the FPGA has, the number of logical elements. This limits how much we can run. That is to say, if our FPGA has 100,000 logical elements, we can program cores of systems that originally had up to 100,000 devices inside their chips between transistors, logic gates, flip flops, etc. But we will not be able to run a system that has millions of components. And how far do FPGAs currently go? Well, even Playstation and Saturn, it has been announced that the cores for Nintendo 64 are taking the first steps, but it seems difficult to jump to the next generations right now. So here we have a hard barrier, until there are more billet FPGAs, we can say goodbye to 21st century systems. To give you an idea, the current state of FPGAs allows the components they simulate to run up to 500 MHz, another restriction along the same lines. I have also read some figures that compare a physically made chip design and its FPGA core version and the result is that in the case of FPGA it takes up 40 times more space and needs 12 times more energy. Although this is not fair because in emulation we also need a more powerful system, but I don't know how much. And I think another aspect to take into account is the price. To emulate 2D game consoles, almost anything works for you right now. A TV box, a mobile phone, the cheapest Ali Express console, an old laptop, everything will move Super Nintendo, Megadrive and a few arcade machines. If you don't have anything on hand, for less than 40 euros, you have something more than competent. However, FPGAs are expensive, it depends on the brand, what we want, whether it is bought loose or already with certain connectors, but it is probably difficult to find something ready to use for less than €400. 10 times more expensive at least. I really like browsing the configuration of the emulators, many have options to change or improve the original operation. They allow you to increase resolution or frame rate, number of colors, sound or loading times. It is a very interesting addition to the emulators. And you may think that if FPGAs almost imitate a console, then improvements cannot be made . But I have seen that they do have improvements in their menu, at least in some cases. I guess what they will do is implement a kind of pro console, imitate hardware with improvements. Doubts With everything we have seen today, doubts arise in me. Can Clean Room Design be applied to FPGA? Is it easy to recycle core content for other cores if they have chips in common? How is the research part done to make a core? Does an FPGA have lower latency than emulation? Does a core work on any FPGA or are they specific to a specific chip? Will there be cheaper FPGAs in the future? As you can see, I can think of many questions about FPGAs, so I think it could be interesting to try to bring someone from this world for an interview so they can help me understand everything better. But it would only be interesting if you also have doubts. So please, leave in comments the questions you would ask an expert on the subject and if I see enough for an interview we will try to bring someone. This video ends here and we'll see you at Mind the game. See you soon.