2021-04-16

How Super Mario Bros. Does Scrolling

Disclaimer: This article was written as a YouTube Video script, and hence may make reference to audio of visual elements not available on this page.

Super Mario Brothers, released in 1985 is probably one of the most famous video games of all time, spawning countless incarnations and spin offs. Super Mario bros helped to define the modern side scroller and platformer genres. It’s simple mechanic of trying to get from the left off the level to the right by jumping on platforms whilst avoiding obstacles helped to cement it into the hearts of people everywhere. 

Before we get into this video, YouTube says that only a few percent of you guys watching are subscribed. So if you enjoy this video, don’t forget to subscribe. YouTube also has this glitch that unsubscribes people from channels that they are subscribed to, if you think you’re already subscribed, don’t forget to check.

So, let’s get back to the video…

So how does scrolling work in Super Mario Bros? One thing to keep in mind that compared to many modern computers, the 8-bit NES is fairly low powered, utilising a variety of the cheap 6502 processor that was popular at the time. Another thing to keep in mind is how graphics on the NES worked. NES games worked on the basis of a 256x240 screen. Everything that you saw on screen was made up of 8 by 8 tiles in the background, which combined into 16 by 16 groups of pixels called blocks. 8 by 8 or 8 by 16 sprites could be placed on top, which could be placed anywhere, although only 8 of these can be drawn in a given scan line.

Many early games on the NES did not even feature scrolling, instead opting to use static screens for different levels, or games like 'The Legend of Zelda' only scrolling under controlled conditions such as when changing between these static screens.

One thing that you’ll notice playing the original Super Mario Bros is that the screen can only scroll right. As you run to the right, the screen scrolls with you, but if you decide to go back the other way, the screen doesn’t scroll back with you and you hit the side of the screen. If a power up happens to go off the left side of the screen, you’ve lost it.

This mechanic of the screen only scrolling one way is intrinsic in simplifying how scrolling works, in order to allow for Super Mario Bros. to have clean scrolling like it does.

Super Mario Bros levels can be quite long. The NES can not hold an entire level in memory, instead it can only load a much smaller section of the level into memory. It holds the loaded section of the background in what is called a name table. The NES can hold 4 nametables, which consist of one byte for each 8 by 8 tile contained in those nametables, as well as space for storing colour palette information for the background. Each nametable consists of 32 tiles in width, by 30 tiles in height, for a total of 960 tiles. This is 960 bytes in size, and the attribute table, which is what stores the colour palette information, takes this up to a total of 1024 bytes, or 1 kibibyte. A screen displayed by the NES uses one of those name tables, and the tiles from them are displayed in the screen.

Scrolling on the NES basically works by applying an offset to which part of the nametable is being viewed, and as the visible portion moves past the right-most part of the nametable, it loops over back to the start.

Now, the NES could use this for scrolling with one of these nametables, but then this would just be the same screen repeating over and over again, as this is the size of the visible portion of the screen.

Instead, scrolling on the NES typically uses what is referred to as mirroring, more specifically, nametable mirroring. There are a few different types of nametable mirroring, which all join up different nametables and are generally used when doing different types of scrolling. Vertical mirroring joins nametables on a horizontal plane to each other, effectively creating a 64 by 30 sized nametable, twice the width of what is visible on the screen.

This is all well and good, but this only accounts for a level two screens wide, unless you want to have the level repeat again. If you’ve ever played or watched someone play Super Mario Bros., you’re probably very aware that levels can be much wider than two screens. So how does Super Mario Bros. achieve having much wider levels?

This has much to do with the fact that only half of the nametable when using this nametable mirroring method is visible on screen. Because only half of the nametable’s tiles are visible on screen, this leaves the other half to have its tiles freely manipulated without this change being noticeable to the end user. When a row of tiles disappears off of the left-hand side of the screen, it can be updated with the tiles that come after the last tiles on the right hand side of the nametable. This process continues as the screen scrolls further, so that when the visible portion of the screen reaches the right of the nametable and wraps back around to the start of the nametable, the tiles there have been replaced, making it seem as though the level continues past this point. To answer the question why Super Mario Bros. only allows you to scroll one way, well the answer is that it is to simplify the scrolling process, as you only need to keep track of scrolling for one direction to replace tiles, as if you allowed scrolling both ways, you would also need to account for replacing tiles as you scroll left, which makes it a lot more complicated.

Of course there are games on the NES that do allow scrolling both left and right, and games like Super Mario Bros. 3 allow you to scroll in all four directions, but how that is done can be a topic for another day.

If you enjoyed this video and want to see more like it, don’t forget to like the video, subscribe down below and hit that bell icon, so that you get notified whenever a new video is released. If you have any ideas for future videos, feel free to leave them in the comments section down below.


Give Some Support By Subscribing on YouTube

Every First Episode in the Winter 2023 Cour

Now that the Winter 2023 cour has come to an end, what better time to discuss the anime that aired this season. This season I have watched e...