This weekend I was coming home from the meeting of theLSST Dark Energy Science Collaboration,and found myself with a few extra hours in the airport.I started passing the time by poking around on the imgurgallery, and saw a couple animated gifs based onone of my all-time favorite games, Super Mario Bros.It got me wondering: could I use matplotlib's animation tools to create thesesorts of gifs in Python? Over a few beers at an SFO bar, I started to tryto figure it out. To spoil the punchline a bit, I managed to do it, and theresult looks like this:
Super Mario Bros Hacks Download
SUPER MARIO BROS. 3MIX What it is: A major overhaul hack of Super Mario Bros. 3 using the Southbird (that's me!) 2011 Disassembly. Currently released is Rev 2B! Super Mario World. Game Title: Super Mario World; Rating: 4/5 ★★★★. Super Mario Bros. (CA) Fully Playable: 07 Nov 2020: Super Mario Bros. (ES) Fully Playable: 11 Sep 2020: Super Mario Bros. (ES) Fully Playable: 23 Jul 2020: Super Mario Bros. (FR) Fully Playable: 16 May 2019: Super Mario Bros. (IT) Fully Playable: 17 Jan 2019: Super Mario Bros. (ID) Fully Playable: 02 Oct 2018: Super Mario Bros.
This animation was created entirely in Python and matplotlib, by scraping theimage data directly from the Super Mario Bros. ROM. Below I'll explain howI managed to do it.
Scraping the Pixel Data
Clearly, the first requirement for this pursuitis to get the pixel data used to construct themario graphics. My first thought was to do something sophisticated likedictionary learning on a collection of screen-shots from the gameto build up a library of thumbnails. That would be an interesting pursuitin itself, but it turns out it's much more straightforward to directlyscrape the graphics from the source.
It's possible to find digital copies of mostNintendo Entertainment System (NES) games online.These are known as ROMs, and can be played using one ofseveral NES emulators available for various operating systems.I'm not sure about the legality of thesedigital game copies, so I won't provide a link to them here. But the internetbeing what it is, you can search Google for some variation of 'Super MarioROM' and pretty easily find a copy to download.
One interesting aspect of ROMs for the original NES is thatthey use raw byte-strings to store 2-bit (i.e. 4-color), 8x8 thumbnails fromwhich all of the game's graphics are built.The collection of these byte-stringsare known as the 'pattern table' for the game, and there is generally aseparate pattern table for foreground and background images.In the case of NES games, there are256 foreground and 256 background tiles, which can be extracted directly fromthe ROMs if you know where to look (incidentally, this is one of the thingsthat made the NES an '8-bit' system. 2^8 = 256, so eight bits are requiredto specify any single tile from the table).
Extracting Raw Bits from a File
If you're able to obtain a copy of the ROM, the first step to getting at thegraphics is to extract the raw bit information.This can be done easily in Python using numpy.unpackbits
and numpy.frombuffer
or numpy.fromfile
.Additionally, the ROMs are generally stored usingzip compression. The uncompressed data can be extracted using Python'sbuilt-in zipfile
module. Combining all of this, we extract the raw filebits using a function like the following:
This function checks whether the file is compressed using zip, and extractsthe raw bit information in the appropriate way.
Assembling the Pattern Tables
The thumbnails which contain the game's graphics patterns are not at any setlocation within the file. The location is specified within the assemblycode that comprises the program, but for our purposesit's much simpler to just visualizethe data and find it by-eye. To accomplish this,I wrote a Python script(download it here)based on the above data extraction codewhich uses matplotlib to interactively display the contents of the file.Each thumbnail is composed from 128 bits:two 64-bit chunks each representing an 8x8 image with one bit per pixel.Stacking the two results in two bits per pixel, which are able torepresent four colors within each thumbnail.The first few hundred chunks are difficult to interpret by-eye. They appearsimilar to a 2D bar code: in this case the 'bar code' represents pieces of theassembly code which store the Super Mario Bros. program.
Scrolling down toward the end of the file, however, we can quickly recognizethe thumbnails which make up the game's graphics:
This first pattern table contains all the foreground graphics for the game.Looking closely, the first few thumbnailsare clearly recognizable as pieces of Mario's head and body.Going on we see pieces of various enemies in the game, as well as the iconicmushrooms and fire-flowers.
The second pattern table contains all the background graphics for the game.Along with numbers and text, this contains the pieces which make up mario'sworld: bricks, blocks, clouds, bushes, and coins.Though all of the above tiles are shown in grayscale, we can add color bysimply changing the matplotlib Colormap, as we'll see below.
Combining Thumbnails and Adding Color
Examining the pattern tables above, we can see that big Mario is made up ofeight pattern tiles stitched together, while small Mario is made up of four.With a bit of trial and error, we can create each of the full frames andadd color to make them look more authentic. Below are all of the frames usedto animate Mario's motion throughout the game:
Similarly, we can use the thumbnails to construct some of the otherfamiliar graphics from the game, including the goombas, koopa troopas,beetle baileys, mushrooms, fire flowers, and more.
The Python code to extract, assemble, and plot these images can be downloadedhere.
Animating Mario
With all of this in place, creating an animation of Mario is relatively easy.Using matplotlib's animation tools (described in aprevious post), all ittakes is to decide on the content of each frame, and stitch the frames togetherusing matplotlib's animation toolkit. Putting together big Mario with somescenery and a few of his friends, we can create a cleanly looping animated gif.
The code used to generate this animation is shown below. We use the sameNESGraphics
class used to draw the frames above, and stitch them togetherwith a custom class that streamlines the building-up of the frames.By uncommenting the line near the bottom, the result will be saved as ananimated GIF using the ImageMagick animation writer that Irecently contributedto matplotlib. The ImageMatick plugin has not yet made it into areleased matplotlib version, so using the save command below willrequire installing the development version of matplotlib, available fordownload on github.
The result looks like this:
Pretty good! With a bit more work, it wouldbe relatively straightforward to use the above code to do some moresophisticated animations: perhaps recreate a fulllevel from the original Super Mario Bros, or even design your own customlevel. You might think about taking the extra step and trying to make Mario'smovements interactive. This could be a lot of fun, but probably very difficultto do well within matplotlib.For tackling an interactive mario in Python, another framework such asTkinter orpygame might be a better choice.
I hope you enjoyed this one as much as I did -- happy coding!
New Super Mario Bros Ds Rom Hacks Download
Name - Date | Difficulty | Demo | Length | Authors | Rating | Size | Download |
Super Mario 64 Island Added: | Intermediate | No | 31 star(s) | Milu64 | 5.0 | 3.11 MiB | Download 144 downloads |
Another Mario Adventure Added: | Intermediate | No | 120 star(s) | BroDute, Cheezepin, Mariocrash, Skillux, Toasterketchup, Tomatobird8, aglab2, mrcomit, pieordie1, scuttlebug_raiser, usernamesarentimportant | 4.7 | 10.04 MiB | Download 1,971 downloads |
Super Captain Falcon 64 Added: | Easy | No | 120 star(s) | Blakeoramo, PastaPower | None | 9.49 MiB | Download 878 downloads |
Any Other Color Added: | Kaizo | No | 16 star(s) | usernamesarentimportant | 4.0 | 3.19 MiB | Download 1,499 downloads |
Puzzles For Yoshis Added: | Easy | Yes | 39 star(s) | usernamesarentimportant | 5.0 | 3.47 MiB | Download 1,330 downloads |
Mario and the Rod of Seasons Added: | Intermediate | No | 15 star(s) | CowQuack | 5.0 | 3.57 MiB | Download 1,398 downloads |
Slask's Adventure Added: | Kaizo | No | 152 star(s) | liuzijun | None | 6.60 MiB | Download 1,449 downloads |
Super Mario Hammer Demo Added: | Easy | Yes | 22 star(s) | BanjoN64Fan | 1.0 | 3.23 MiB | Download 2,995 downloads |
you've been gnomed.z64 Added: | Easy | No | 0 star(s) | SNDBB | 5.0 | 6.51 MiB | Download 2,800 downloads |
Jammin' Journey Added: | Easy | No | 70 star(s) | goosedajuice | 5.0 | 4.46 MiB | Download 2,910 downloads |
Castle Grounds Revamp Added: | Easy | Yes | 1 star(s) | 64Modder | None | 3.36 MiB | Download 1,825 downloads |
SM64-Stars of the Beast 2.5 Beast´s memory Added: | Kaizo | No | 7 star(s) | Milgram355 | None | 3.35 MiB | Download 1,770 downloads |
SM64-Stars of the Beast 2 Added: | Kaizo | No | 67 star(s) | Milgram355 | None | 5.09 MiB | Download 3,287 downloads |
Super Thwompio Sixty URGH Added: | Hard | No | 120 star(s) | SNDBB | 4.3 | 1.49 MiB | Download 1,329 downloads |
Sunshine Secret Book 64 Added: | Intermediate | No | 40 star(s) | Dan - GPTV | 4.8 | 3.41 MiB | Download 4,173 downloads |
Star Revenge 1.5: Star Takeover Redone v2.1.1 Added: | Intermediate | No | 125 star(s) | BroDute | None | 6.90 MiB | Download 4,786 downloads |
Seaside Village Added: | Easy | No | 7 star(s) | 64Modder | 4.5 | 3.06 MiB | Download 2,428 downloads |
Luigi Before the Egg 64 DX: Direggtor's Cut Added: | Intermediate | No | 2 star(s) | Blakeoramo, SKELUXXX | None | 15.22 MiB | Download 3,939 downloads |
Sunset Ceremony Added: | Intermediate | No | 3 star(s) | usernamesarentimportant | None | 2.71 MiB | Download 1,266 downloads |
Star Revenge 7.5: Kedowser's Return v1.1 Added: | Hard | No | 130 star(s) | BroDute | None | 7.32 MiB | Download 2,693 downloads |
Star Revenge 7: Park of Time v1.1 Added: | Intermediate | No | 120 star(s) | BroDute | 5.0 | 6.69 MiB | Download 2,412 downloads |
Star Revenge 0.5: The Unused Levels v1.1.1 Added: | Intermediate | No | 65 star(s) | BroDute | 5.0 | 5.21 MiB | Download 1,910 downloads |
Isabelle 64 / Shizue 64 Added: | Intermediate | No | 120 star(s) | AloXado320 | None | 2.33 MiB | Download 2,727 downloads |
SM64: The Mushroom Cup 1.2 Added: | Hard | No | 130 star(s) | usernamesarentimportant | 5.0 | 6.42 MiB | Download 5,264 downloads |
Mario on Indigo Island 1.3c Added: | Intermediate | No | 111 star(s) | usernamesarentimportant | None | 11.04 MiB | Download 3,995 downloads |
Star Revenge 6.25: Luigi's Adventure DX - Demo v1.0.1 Added: | Intermediate | Yes | 59 star(s) | BroDute | None | 6.15 MiB | Download 2,680 downloads |
Super Mario and the Cursed Castles Added: | Easy | No | 121 star(s) | Foxen | 4.7 | 7.04 MiB | Download 9,946 downloads |
Ztar Attack Rebooted Added: | Intermediate | No | 170 star(s) | TheGael95, aglab2 | 5.0 | 8.88 MiB | Download 7,473 downloads |
Star Revenge 3.9: Dreamish Block Beats v1.1 Added: | Hard | No | 20 star(s) | BroDute | 5.0 | 22.83 MiB | Download 1,910 downloads |
Star Revenge 8: Scepter of Hope v1.3 Added: | Intermediate | No | 121 star(s) | BroDute | 5.0 | 8.83 MiB | Download 2,413 downloads |
Yoshi's Adventure 128: Attack of the Factory v1.0.1 Added: | Intermediate | No | 95 star(s) | usernamesarentimportant | 4.5 | 5.29 MiB | Download 5,688 downloads |
New Soup 64 Added: | Hard | No | 6 star(s) | Tenimental | 5.0 | 3.25 MiB | Download 4,023 downloads |
Star Revenge 4.5: The Kedama Takeover Rewritten v1.2 Added: | Intermediate | No | 100 star(s) | BroDute | 5.0 | 8.49 MiB | Download 3,026 downloads |
Star Revenge 3.5: Vacation of Cursed Dreams v1.2a Added: | Intermediate | No | 133 star(s) | BroDute | 5.0 | 10.38 MiB | Download 4,217 downloads |
Yoshi's Adventure 64 1.2b Added: | Intermediate | No | 56 star(s) | usernamesarentimportant | 5.0 | 5.07 MiB | Download 11,228 downloads |
Penguin v1.0.1 Added: | Intermediate | No | 2 star(s) | usernamesarentimportant | 3.0 | 3.61 MiB | Download 2,761 downloads |
Star Revenge 5: Neo Blue Realm v1.2 Added: | Intermediate | No | 70 star(s) | BroDute | 5.0 | 6.60 MiB | Download 2,405 downloads |
Sandy Spire Slide v1.1 Added: | Intermediate | No | 5 star(s) | usernamesarentimportant | None | 2.78 MiB | Download 1,356 downloads |
Star Revenge 6.5: Wrath of the Dim. Flower v1.1 Added: | Intermediate | No | 70 star(s) | BroDute | 5.0 | 6.77 MiB | Download 1,846 downloads |
Star Revenge 6: Luigi's Adventure v1.3 Added: | Intermediate | No | 121 star(s) | BroDute | 5.0 | 6.46 MiB | Download 5,829 downloads |
Star Revenge 1: Star Takeover v1.2a Added: | Intermediate | No | 101 star(s) | BroDute | 5.0 | 5.05 MiB | Download 4,579 downloads |
Star Revenge 2: To the Moon v1.1 Added: | Intermediate | No | 85 star(s) | BroDute | 5.0 | 7.96 MiB | Download 3,014 downloads |
Super Mario 64 HARDCORE Added: | Intermediate | No | 120 star(s) | Erableto | 3.5 | 2.99 MiB | Download 6,080 downloads |
Super Mario 64 Remastered Added: | Intermediate | No | 123 star(s) | Erableto | 3.5 | 3.15 MiB | Download 21,054 downloads |
Crash Bandicoot 64 Added: | Intermediate | No | 120 star(s) | Erableto | 4.0 | 4.56 MiB | Download 11,860 downloads |
Super Mario 64 and the Koopa Power Added: | Intermediate | No | 100 star(s) | VenusFeuerFalle | 5.0 | 8.01 MiB | Download 5,046 downloads |
Roblox 64 Added: | Intermediate | No | 1 star(s) | SwiftySky | 5.0 | 3.02 MiB | Download 15,794 downloads |
Bounce Tales 64 Added: | Intermediate | No | 39 star(s) | AloXado320 | 4.5 | 2.13 MiB | Download 2,372 downloads |
Super Mario Adventure 64 (DEMO) (Cancelled) Added: | Intermediate | Yes | 7 star(s) | Bizfurd | None | 3.12 MiB | Download 3,010 downloads |
Super Mario 64: Openworld Quest Added: | Intermediate | No | 70 star(s) | Mariocrash, TheGael95 | None | 3.56 MiB | Download 7,688 downloads |