How the Game Boy Advance knew it was running a Game Boy Game | MVG

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] when nintendo launched the game boy advance in 2001 it would be a radical departure from the game boy and the game boy color although it was backward compatible to those machines thanks to the inclusion of game boy hardware inside the system other than the game boy brand which was a household name the game boy advance is not compatible with game boy games at all the gba is a 32-bit handheld that uses an arm 7 tdmi cpu running at 16.8 megahertz the gameboy cpu is an 8-bit sharp lr35902 processor running at either 4.18 megahertz on original game boy mode or 8.38 megahertz if it's running in game boy color mode to handle its backward compatibility the gba simply switches the hardware into game boy mode and the sharp cpu kicks in and begins processing instructions this isn't really anything special and we've seen nintendo use this approach to backward compatibility for many generations we would see this with the nintendo ds and the ability to run game boy advance games the nintendo 3ds was backward compatible with the nintendo ds the nintendo wii could play gamecube games and the nintendo wii u was backward compatible with the nintendo wii each system had the ability to run games from its previous generation but if we consider backward compatibility on the nintendo cartridge based systems like the ds and the 3ds the game boy advance is unique in that it's pin compatible with its predecessor the game boy and the game boy color yet the architecture of the two systems is completely different but what's interesting however about the game boy advance is that it shares the exact same cartridge slot as the game boy and game boy color games and when inserting a game boy into the slot somehow it must detect and switch the hardware into game boy mode otherwise it must be a game boy advance game and must boot into gba mode which of course is the default so how does a gameboy advance know if a gameboy game has been inserted if we take a look at a gameboy cartridge it has 32 pins across and if we compare that to the gba it too also has 32 pins and if we compare the pin outs from both the game boy and the game boy advance they do share similarities for example the read and write pins are the same the address lines and the data lines are also the same the voltage and ground lines are also identical but interestingly enough game boy and game boy color games will run at 5 volts while the gba games will run at 3.3 and yet if we look at the game boy advance pin outs there is no indication that the game should be running either in game boy or game boy advance mode when you power on a game boy advance with the game boy color cartridge you'll notice it does a very quick fade before the screen boots into game boy color mode and launches into the game but behind the scenes there's actually quite a lot going on as it turns out right next to the cartridge slot there is a switch that lets the gba know once a game boy cartridge is inserted that it needs to switch into game boy mode so how does this work well it's quite simple if we take a look at the side of a game boy color game it's completely square but if we then compare it to a game boy advance game you'll notice that there is a small notch on both sides the purpose of this is to prevent from the switch being hit but if the switch is tripped it sets the voltage for pin 1 to plus 5 volts which as we said previously is compatible with game boy and game boy color cartridges but there is still more to consider when the gba is powered on it first boots from gba mode before switching to gb mode without the switch there is no way of knowing that a game boy cartridge was ever inserted in the game boy advance boot rom there is a small piece of code that handles the switching if the switch was enabled the bios contains code to detect a game boy or game boy color cartridge one of the game boy advance registers that handles weight states checks for the switch it does this by checking for a particular bit that's been set to true if the cartridge voltage was adjusted it then switches the hardware to game boy color mode and it does this by setting a bit in the display register and this in turn will disable the arm7 processor now there's also a second part to this that's quite interesting and that is there are a handful of game boy color games when plugged into a game boy advance provide enhancements and features that are not found on the original gameboy color version so we have an understanding on how the gba can switch to game boy color mode but now let's turn our attention to enhanced game boy color games there are a very small number of game boy color games that when inserted into a gba will enable additional features in the game one such example is the legend of zelda oracle of ages it will update its color palette and also add an additional store in the game another example is shantae for the game boy color if we run this game on real game boy color hardware it works as expected but when the same game is placed into a gba the color palette is altered and the spinning message gba enhanced is shown on the screen the game also features a new tinkerbet exclusive transformation specifically made for the gba version but what's interesting about all this is how does the game boy advance know that there are enhanced features on this cartridge and how does it actually unlock them after all this cartridge is fixed in other words if we dump the rom 10 times we are going to get the same rom dump every single time so how does the gba know that it needs to look for these enhanced features that are not available on the game boy color version if we dump the contents of this game and try running it under emulation you'll note that it runs the standard version to open up the gba enhanced version requires the rom to be patched with a few bytes but this is a physical cartridge and there is no concept of self-modifying code here the same code will run on the game boy color and on the game boy advance so how does shantae know that it needs to add the enhancements to the game when it's running under the gba to answer this we need to understand a little about assembly language programming but this isn't overly complicated so stay with me the sharp processor found on the gameboy color is based on the zylog z80 but it's not exactly a z80 processor but it does have the same registers think of a register as a storage area for data that the processor wants to perform work on the cpu will load values into registers that it's accessed from memory work on the data in the registers and then it might store them back into ram once it's finished with the data on the gameboy and gameboy color each register is 8 bits in size but these registers can also be combined to become 16 bits wide when the game boy is powered on these registers are set to a particular set of default values but the one that we want to focus on is register b b can also be combined with c to form a 16 bit register as well when we turn on a game boy b is set to zero and this is the register that determines if the game is running in game boy or in gba enhanced mode but how can we test this well we can use an emulator such as bgb if we load shantae right at the beginning and start stepping through the code you'll notice two things first that register b is set to zero as we said and the first time the code references b it's performing this particular function sla is an instruction that shifts all the bits left for the given register that it's trying to access in this case register b but because b is zero when we shift left the value of zero we get the result of zero so nothing actually happens but if i reset the debugger and set the value of b to equal 1 then we get a different result and you can see the game loads in gba enhanced mode this is because the sla function is shifting the bit 1 to the left therefore the result of 1 being shifted left is 1 0 in binary or 2 in hexadecimal so we can conclude that register b initially is the flag to determine if the game is running in gba enhanced or in regular game boy mode now of course this is emulation and we don't have this luxury on a physical cartridge where code cannot be modified in this fashion well quite simply the programmers took advantage of registers being set to different values when a game boy advanced is powered on and put into game boy color mode during boot up of a game boy advance when it shifts into game boy color mode register b is initialized with the value of 1. this is different than the value of 0 that was on the gameboy color this means when the code reaches the slab function call it will set the value of b to equal 2 which means it puts the game into gba enhanced mode and if we take a look at the code for a popular gameboy advance emulator mgba you can clearly see that it's initializing the value of b to equal 1 if it's running game boy color games on the gba by taking advantage of different initialized registers when the game boy color is powered on in gba mode means that it's possible to check and apply enhancements to the game for the game boy advance only finally it's worth mentioning that these gba enhancements can just as easily run on stock game boy color hardware so with the game boy color you can run the gba enhanced version of shantae on a physical cartridge should you choose to do so this unique feature ultimately meant that developers could take advantage of games running on gba hardware without requiring the creation of a unique gba enhanced cartridge or some other trick to patch bytes this was simple yet very clever the enhancements themselves generally speaking weren't too complicated usually a color palette change or perhaps new graphics could have been added but all this data is ultimately stored on the cartridge all the gba enhancements for shantae live in the shantae data and they are loaded in if register b on initialize is set to one so there you have it that's how the game boy advance handles game boy color games that simple switch in the game boy advance really begins everything without that switch there's no way that the gba knows that it needs to run in game boy color mode and i think this was a pretty simple method by nintendo and you got to feel like earlier on maybe they were trying to find a better way to do this without a switch in place where you could just detect if it was a game boy color cartridge without any circuitry involved but i think ultimately this was the smartest solution for them and the most foolproof but that will do it for this episode thank you so much for watching if you liked it don't forget to leave me a thumbs up and i'll catch you guys in the next video bye for now [Music] you
Info
Channel: Modern Vintage Gamer
Views: 387,092
Rating: undefined out of 5
Keywords: gba, game boy advance, game boy, game boy color, gba enhanced, AGS, DMG, mvg, modern vintage gamer, nintendo, handheld, 8 bit, 32 bit, best gba games, gba games, cartridge, shantae, oracle of ages, zelda, enhanced games
Id: _Qqg4VCZ0k8
Channel Id: undefined
Length: 12min 26sec (746 seconds)
Published: Mon Jun 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.