Software Emulators vs FPGAs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you've been following the handheld emulator scene lately you've probably heard a lot about some of the fpga based devices like the analog pocket as well as some software emulators such as the Miu Mini Plus but really what's the difference between these devices aren't they pretty much the same thing well that's the question that I want to answer today and it's not a simple one so in this video I'm going to take you through how both software and Hardware ulators work so you can understand which one might be the best option for [Music] you before we jump in I want to be completely upfront I was really on the fence about making this video and that's for a couple of different reasons first I don't believe that this type of discussion can happen at a surface level I think both hardware and software emulation is pretty amazing and I want people to understand and appreciate both of them and in order to do that a technical Deep dive is in order and the second reason is because of how polarizing this debate is but the fact that we're even able to have this discussion is pretty amazing if you think about it 30 years ago when I was sitting in front of my living room TV playing Super Nintendo I would have never imagined that we'd have the technology like we have today to take it with us and to play it in so many different ways but first we need to start with a bit of a primer on how these old video game systems that we're trying to emulate actually work each system is different but pretty much all classic game systems have a few common building blocks first there's is going to be a central processor whose job is to take a series of instructions and execute them think of this guy as the brain of the video game system we need to put images onto a screen of some kind so there also needs to be something that's responsible for interacting with the display and making sure it receives the right signals to draw images also people generally like hearing music and sound effects when playing games so we need something to make those sounds and put them out onto a speaker and when you're playing a game you need to give it some input you know through a controller for example so we also need to take that input and make sure the game handles it many of these different building blocks need a place to keep data while it's doing its job so we also need some system memory and finally you need to give the system some set of instructions to run for classic video game systems the this will typically come in the form of a cartridge or some sort of disc now keep in mind that this diagram is a highle generalization if you look at any system in particular you're going to find variances for example the Nintendo entertainment system contains a lockout chip which doesn't fit into any of these building blocks now some older systems will actually have discrete chips running each of these different subsystems the Commodore 64 is really good example of this if we overlay the building block diagram on top of the Commodore 64 main board you can see how the chips on a c64 split up the responsibility but as technology progressed designer started consolidating multiple subsystems onto a single chip and a good example of this is Nintendo's Game Boy the game boy has all the same building blocks as other game systems but many fewer chips if you were to appearer inside this chip in particular which is labeled the DMG CPU you would see that all the functionality of the central processor video controller audio controller and input subsystems are all handled by this one chip the CPU label on the chip is actually misleading in this case because this chip does so much more than just the job of the CPU in fact there's a special name for this type of Chip it's called an S so or a system on a chip now as I mentioned earlier the CPU is the brain of the system when it starts up the CPU will start looking for instructions to execute and it does this by using a set of data and address pins for example let's look at the 6502 processor which you'll find inside the Nintendo Entertainment System this CPU U has an 8bit data bus and a 16bit address bus so the chip itself has eight data pins and 16 address pins when running a game the CPU fetches the instructions from the game cartridge which is usually mapped to a specific address range when the CPU needs to read an instruction it puts the address of the next instruction to read on the address bus by setting each address pin to either zero or one which turns them off or on and this causes the data at that address to be placed on the data bus which is connected to the cpu's data pins the CPU also contains a small amount of memory that resides inside the chip itself this internal memory is called a register registers are very fast temporary working space for the CPU to use while it's performing operations let's look at how this works with a real example of some game code here's a snippet of code from Super Mario Brothers on the NES which someone took the time to decompile and comment the code I want to look at here is for the level selection screen this screen will appear after you complete the game all the way through when you're back at the menu screen you can choose which world you want to start on and when you change the world by pressing the B button this is the code that runs since this code was decompiled you're seeing human readable instructions and comments but in reality this assembly code gets compiled into a series of op codes that the processor would receive so the actual ROM chip for the Super Mario Brothers cartridge stores the following data the first instruction is the ldx instruction this tells the CPU to load the value at the specific memory location into the X register in the CPU the next instruction is INX this tells the CPU to increment the X register by one next the txa instruction will transfer the value that's in the X register over to the a register and the next instruction will perform a logical and operation with the decimal number seven if the world number goes above seven it wraps back around to zero next it stores the new number for the selected world back into the memory location that it pulled it from earlier and finally this bit of code is done running so the jsr instruction jumps down to another branch of code to continue on okay now let's swap out the 6502 CPU for a z80 CPU which is found in the Sega Master System the z80 is also an 8-bit CPU with a the 16-bit address bus just like the 6502 however the design of the z80 is completely different which means that it also has a completely different instruction set so if we were to try and run the code from Super Mario Brothers on the z80 the op codes that would be read from the ROM would translate into an entirely different set of instructions recall that the first op code here AE translates to the load X instruction on the 6502 but on the z80 the same op code would execute an exclusive or instruction so you see you can't take the native code that was written for one CPU and run it on a different one even if they're somewhat similar at least not directly so now let's talk about how an emulator can help us solve that problem so as you probably guessed an emulator runs the code that was is written for one type of system on a completely different system now emulation can be done in a couple of different ways but the type of emulation that I want to talk about first is software emulation with software emulation the emulator runs on top of an existing operating system like Windows Mac OS or Linux these emulators are typically written in a higher level programming language which makes calls to the underlying operating system to do things like draw draw a picture on the screen or play sound but in order for this to work the emulator has to emulate more than just the CPU it has to mimic the job of all those different systems that we discussed earlier the way software emulators do this is by recreating the original systems architecture in software as an example let's take a look at how we might represent the architecture of the Nintendo Game Boy in a software emulator first you might represent the Game Boy CPU with its own object class now to represent the registers inside the CPU you might use a few variables the Game Boy has memory mapped to a 16bit address space so you probably need some sort of array you might also create a class to represent the display and use that to call the os's native drawing functions and perhaps another class to represent the audio subsystem which of course would wrap the operating system's audio calls now in order to emulate the CPU you might run a loop to fetch the next instruction from the memory array and then use a big switch statement to figure out what to do with it this example is by no means complete and is only one way to think about how to implement an emulator like the Game Boy now one of the great things about software emulation is that you have a variety of options for how you might want to emulate the platform that you're implementing in the language that you choose but one of the biggest advantages of software emulation is it's cost and accessibility you could go out and buy a handheld software emulator like one of these or build a console based emulator like this Raspberry Pi based console that I built a while back but it's not necessary the only thing you need to enjoy software emulation is a computer and it doesn't even need to be a powerful one as you can see I have this old laptop here that runs badera Linux just fine and allows me to play emulators with USB Joy pads and thanks to the open source Community we have projects like lib retro and retroarc which makes running emulators on your existing computer unbelievably easy and if you do want one of these neat handheld devices to take your emulators with you they're very affordable a lot of people seem to enjoy the Miu Mini Plus which you can pick up for around $50 but his greatest software emulation is there are some inherent problems with it you'll recall from the discussion earlier that the original game systems were emulating had multiple chips working in parallel so while the CPU gets clocked to execute an instruction other chips also get clocked at the same time and that causes each of them to do their job independently but with a software emulator the CPU is doing the job of multiple chips and that makes it a bottleneck but modern CPUs are so much faster than those old chips that were used in those old classic video game systems shouldn't they be able to emulate all those systems without issue well the answer may surprise you accurately emulating each chip on every tick of the clock is actually quite demanding on on a CPU in an RS Technica article back in 2011 one particular emulator developer talks about how difficult it is to accurately emulate any game console and software there's a link to this article in the description so I'd highly recommend taking the time to read through it yourself in that article the author states that in order to accurately emulate the super Nintendo's 3.5 MHz CPU you actually need a multi- gigahertz processor and you're probably thinking yeah right I'm playing Super Nintendo games just fine on my 1.2 GHz Miu Mini Plus and for the most part you're right a lot of games seem to run fine on modern arm processors but what you may not realize is that those emulators Implement certain tricks that sacrifice accuracy in favor of performance let's take a look at a couple of examples so you can see what I mean here I have the game air strike Patrol on Super Nintendo and it does something interesting let's put this game into an actual Super Nintendo and take a look now when you start a mission you'll notice that the words good luck rotate with a little animation in the middle of the screen and you also notice that the aircraft has a shadow on the ground that's projected underneath of it now let's use my hand handy ROM dumper to dump this game to a ROM file that we can run in a software emulator by the way if you want to build one of these ROM dumpers yourself check out the video I made a couple of weeks ago on how to build one from scratch okay now let's look at the same game on the Miu Mini Plus and you'll notice that instead of animating the words good luck appear twice on the screen and there's no Shadow drawn below the aircraft to understand why this is happening I need to give you a little more information first the Super Nintendo like many other classic game consoles was designed to run on a CRT display like an old television set CRTs have an electron gun inside that draws the image one line at a time from the upper left down to the lower right after the CRT finishes drawing a line there's a small window of time for the Electron Beam to move to the opposite side of the screen before starting to draw the next line This is called the horizontal blanking interval and for ntsc televisions it lasts approximately 10.9 micros and most games will take advantage of this waiting period to do additional processing but air strike Patrol doesn't wait it modifies display registers in the middle of the scan line in order to get the animation and shadow effects and this is why you see these effects missing on the Miu Mini Plus and many other software emulators those emulators aren't cycle accurate so they don't process the video chip instructions in the middle of a scan line now this is just one trick that emulators use to increase performance and you might even argue that it's not that big of a deal in this case you're probably right but let's look at another game where sacrificing accuracy really does pose a real problem let's look at another Super Nintendo game this time Speedy Gonzalez this is actually a fun little platformer that sort of reminds me of Sonic the Hedgehog in the way that it moves when you play this game you'll get to a point where you have to push a button in order to complete the level and when playing on a real Super Nintendo everything works fine however when you play this game on most software emulators it'll lock up when you push this button and this is due to a specific Hardware Edge case that's encountered with this game in particular now I do need to mention that you may find some SNES emulators out there that have programmed workarounds specifically for this game and I know that there's at least one hacked ROM that's floating around on the internet which works around the issue directly in the game ROM but the fact that Speedy Gonzalez isn't completable on many of these devices is just another example of how inaccurate software emulation can be problematic now I should also mention that this isn't all software emulators there are some that do a pretty good job of maintaining accuracy but there is a performance cost because they do require faster processors and this is fine for a standard PC but many of these smaller arm-based devices will really struggle to keep up with a high accuracy software emulator and remember that I'm talking about a 30-year-old game system here when you start talking about emulating newer consoles and software it becomes even more challenging all right I think I've talked enough about software emulation now let's switch gears and discuss emulating game systems and hardware and specifically I want to talk about fpga an fpga is a field programmable Gat array they're programmable because they can be digitally rewired to look and behave like other chips and it happens at the hardware level inside the fpga but it doesn't just stop at a single solitary chip fpgas are massively parallel in nature and because of that they can emulate multiple chips at the same time let's go back to the example I gave earlier with the Commodore 64 having separate chips for each building block of its architecture if you were to emulate the Commodore 64 in an fpga you could program the fpga to not just emulate the 6502 CPU but you could also have the fpga emulating all the other chips as well they can do this because a single fpga contains thousands and thousands of logic elements each logic element can be configured in a unique way and then connected together for example you might configure one logic element as an and gate and another one as an exor gate to build a half adder then you could duplicate this configuration multiple times and connect them together to build a full adder you can also connect logic elements to physical pins on the fpga chip itself and that allows you to take input that you can then perform some Logic on and output the result to other components on your board now to Define how an fpj is is configured you need to program it but the word program here is really a misnomer because you don't generate a sequential list of instructions for an fpga like you do with a CPU or a microcontroller instead fpgas are configured using what's called an HDL or a hardware description language rather than writing code what you're doing in an HDL is defining the configuration of the logic elements now you'll commonly see two different HDL formats used vhdl and verilog both of these were invented in the early 1980s and vhdl in particular actually originated from the US Department of Defense believe it or not when you're dealing with emulation you'll likely encounter both for example the PlayStation core here for the Mis was written mostly in vhdl while the Sega 32x core was written primarily in verilog the HDL that's written doesn't get sent to the fpga directly though it has to be run through a tool chain to perform some other tasks such as simulation and routing that's right you heard me correctly fpgas need to be routed just like printed circuit boards and that's because the logic elements inside of an fpga are physically connected together using an internal Network wires and transistors when an fpga is turned off all the logic elements get reset so every time the fpga is turned on it needs to be reconfigured for devices like the Mis or analog pocket the fpga is reconfigured whenever a core is loaded from the menu now that you understand how fpga work at a high level you're probably starting to see why many people like to use them for emulating old video game and computer systems systems first the parallel nature of fpgas means that you're going to be able to more accurately emulate the original system than if you were to use a CPU each chip that's emulated inside of the fpga can be clocked in parallel so you don't have to play timing tricks to get a system to perform well let's go back to our example of air strike Patrol that we saw earlier as you can see when you run air strike Patrol on the Miu Mini's super Super Nintendo emulator the opening text doesn't animate and you don't get that shadow from the aircraft but if you run the same game on the analog pocket you'll notice that everything renders correctly also notice that the game runs correctly on the Mis as well a well programmed fpga will pick up the nuances of the hardware that it's emulating including the various Hardware edge cases so issues like you saw earlier with the Speedy Gonzalez game won't likely happen on an fpga and many fpga developers will go out of their way to get as accurate as possible even to the point of decapping chips to get good photos of its layout but in addition to all this fpgas are becoming instrumental for the preservation of these older systems many of them used custom chips that were designed and manufactured for that particular system and they're no longer available today you can see this with the Commodore 64's Vic 2 chip it's a chip that's regularly failing and the number of Replacements available is quickly running out but fortunately there are projects like the Vic 2 Kari which are creating replica Vic 2 chips by using an fpga now as great as fpga sound not everyone's a fan and I totally get it the number one complaint that I think I he about fpga is the cost no doubt about it fpga are more expensive than the chips they emulate and the cost generally goes up when the number of logic elements and features increase for example the Cyclone 5 fpga that's used inside the analog pocket is roughly $70 off the shelf and it has 49,000 logic elements and the S Series Cyclone 5 that's used in the mis's de10 Nano Dev board has 110,000 logic elements and costs around $325 just for that one chip so prices of the fpga based emulators are inherently going to be higher than software emulators which just use standard arm processors another disadvantage of fpgas is that they're complex devices so if you're going to program one you need additional skills if you wanted to write an emulator core for an FP PGA you don't just need to understand the basics of software development you also have to understand integrated circuit design and a poorly designed core can really take its toll on the system fpgas typically aren't designed for power efficiency to begin with but the power footprint of an fpga depends heavily on how it's configured and another thing that you really need to keep in mind is that fpgas like any other chip do have limitations for example fpga all work on digital circuitry so you can't emulate any Analog Devices if you want to take an analog input or provide an analog output then you need to make sure there's an external ADC or a Dack connected to the fpga's pins wow that was a lot of technical content that we covered today if this is all new to you it might be a little overwhelming in the description below I've included some links to some other great content that you can go through to help solidify your understanding of these Concepts and go a bit deeper in certain areas as we wrap this one up I just want to say that I personally have an affinity for both software and Hardware emulators there are a number of devices that I enjoy playing and each one for different reasons but I hope this video helped you see that all emulators aren't necessarily created equal and that's okay people who advocate for either a software or a hardware emulator have good and valid reasons for doing so so when having these debates and discussions let's keep that in mind and be respectful of one another all right well that's it for this video I hope it was helpful thanks for watching and until next time go make something cool [Music]
Info
Channel: What's Ken Making
Views: 273,152
Rating: undefined out of 5
Keywords: fpga, analogue pocket, mister, miyoo
Id: sMMiBEhnizE
Channel Id: undefined
Length: 27min 8sec (1628 seconds)
Published: Fri Dec 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.