SMB Et. Al. Similarities

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.
User avatar
segaloco
Posts: 913
Joined: Fri Aug 25, 2023 11:56 am

SMB Et. Al. Similarities

Post by segaloco »

So my disassembly projects in SMB and SMB3 are at a point now where I can start documenting a little more closely some of the specific design patterns that were recycled between the games. The primary focus of my analysis is SMB1, SMB2, and SMB3, but Doki Doki Panic/SMB2 US will feature here and there as well, I'm just not as far along with that work.

First, a short list of common Nintendo stuff in titles analyzed:
  • RNG - Up through SMB3 still uses the tried and true RNG introduced in Donkey Kong.
  • Jump Tables - For the most part, the Intelligent Systems-mod.-SRD routine is used, but some areas forego this entirely and have their own local jump table indirects.
  • NT/Background Init - The nametable setup during bootstrap is pretty darn similar to much earlier stuff, if it ain't broke don't fix it I suppose.
  • General RAM Clearing - Nintendo stuff tends to have a page-based RAM clear by which some high page number is given and everything below that is cleared out, possibly including or excluding zero page and stack by default or option. This sort of stuff shows up in the SMB games too.
  • Joypad Reading - The same basic core joypad strobe loop is in there, but it gets surrounded with different variations on debouncing and multi-player handling.
  • Audio Engine - Nintendo has a pretty general engine they use over and over again for audio stuff, adding or subbing parts depending on what they need. Those fingerprints are still all over SMB3, and all the other SRD stuff, to the point I may make a separate git repo exploring just version differences with those since I may actually be able to get the code close enough to diff between titles effectively.
As for some glaring differences:
  • Mapping - SMB1 is an NROM title, SMB2 and DDP both FDS, SMB3 is MMC3, so naturally this presents some complications in exploring some flow of code. Routines throughout these games had to probably be entirely rewritten to work with however things were split up in mapping, so it's a steep order to demonstrate that subroutine A in SMB became subroutine B in DDP, etc. when mapping plays heavily in however what that bit is works. Not to say it can't be done, common variable names help a lot in finding similarities but there are plenty of places in these games where the mapping dictates the layout and flow.
  • Tight Main Loop vs. Real Main - SMB1/2 exhibit a pattern seen in earlier Nintendo stuff in which the main thread does some system bootstrap but then settles into a tight loop, at most doing RNG. SMB1/2 don't even do this, it's just a loop with maybe an effective nop thrown in. DDP and SMB3 both contain more significant main loops that actually represent the steps of iterating over the overarching flow of the title. Both for instance come out of the system bootstrap, construct the runtime for the titlescreen, then enter the title loop. The title in both cases then transitions to some sort of selection (save screen in DDP, map in SMB3), which involves some sort of bank switch (disk flip on FDS, MMC3 swap on FC). Then the game simply runs and runs until some sort of condition kicks it back all the way to the title screen. Still, the NMI just does graphics and timing-based requests rather than ending by entering the game simulation. This is one of the compelling reasons I believe SMB3 flows pretty directly from DDP, although it could be coincidence and in general SRD and others decided to ditch the old loop pattern. It would be interesting to see if other lineages that did the same tight loop concept dropped it as well.
  • Mode Transitions - Along the same lines as DDP and SMB3 dropping the tight main loop and executing all in NMI, these titles also dropped the concept of a table of game modes then launching into processing for each of those modes states. For instance, in Super Mario Bros., there is a table for dispatching between the title, gameplay, victory, and game over modes. In DDP and SMB3, however, this is instead simply a function of the flow in the aforementioned main loop. The control simply loops around in different parts of this larger main loop, executing over portions pertinent to things like the title screen, stage selection, credits, etc. in their own little bits. At any given time, rather than a single index saying "you are in the title, credits, map, gameplay, bonus, etc." these abstract concepts become a function of several different variables that influence different things.
  • Scroll Loading - Among the more glaring differences over time is the evolution of the scrolling engine. SMB1/2 featured uni-directional scrolling along one axis. Doki Doki Panic then introduced selectable horizontal *or* vertical scrolling in both directions. SMB3 then introduced a full vertical scroll into the horizontal scroll mode such that horizontally scrolling levels could have a two-page-high vertical scroll window as well.
  • Title System - SMB1/2 use the real game engine to render the title, simply loading World 1-1, pasting the title graphics over it, and then letting the demo script run. DDP has a cinematic titlescreen so no interaction with gameplay to speak of. SMB3 is an interesting case in that there is essentially a snippet of the bare bones pieces needed to run the little demo you see play out between Mario and Luigi. For instance, each interaction with the Koopa shell is a specific subroutine, rather than generalized actor interaction with player objects. Literally just the actions needed are there. The powerups you don't touch don't have any of their other programming. Granting controls to the player characters in the intro could make for some interesting janky gameplay if it hasn't been done already. There is no metatile engine or scrolling to speak of, everything you see is loaded in via display list or OAM tables co-located with the subroutines.
Finally, some commonalities between SMB1/2 and SMB3 which have emerged in my recent study. These may feature in other titles such as DDP for instance but I haven't documented the particulars on other titles yet.
  • Metatiles - SMB1/2 and SMB3 use generally the same metatile format, although I have not yet sat with a magnifying glass over the subroutines that crunch the tables in each to see if the code bears similarities. Not only does the 16x16 format feature, but a technique for selecting the color palette for the metatiles is also shared: The high two bits of a metatile's placement in the 256-metatile table corresponds with that metatile's palette entry. In other words, the $100 metatiles are broken up into $40 metatile pages, with $00-$3F being color 0, $40-$7F color 1, $80-$BF color 2, and $C0-$FF color 3. The tiles are arranged in tables of each quadrant and some metatiles exist in more than one chunk. For instance the victory tile for the map in SMB3 is in all four metatile groups so you can get victory tiles with different colors from the same palette selections. I wouldn't be surprised if this is in other titles like Legend of Zelda, the $40-tile page corresponding with color selection is quite clever.
  • Scenery and Actor Course Arrangement - This is getting into some terms I've half made up and half borrowed but in both engines the courses are generally broken up into "scenery" and "actors", with the former being large background objects like pipes, hills, and block rows. In actual SRD code, this sort of thing tends to be referred to as "obstacles" but they need not be physically obstructive. Actors then are the acting things like enemies, powerups, and so on. Both engines generate courses by stepping over tables of these two distinct types of entities. I haven't gotten quite deep enough into the SMB3 course engine yet to compare the rest of the course generation, but SMB1/2 generally uses the scenery engine to also specify changes in the vertical "mask" for the level, basically the placement of "wall" from the top to bottom until another such scenery object triggers a transition in the masked off rows. SMB3 has a lot more complexity what with overlapping platforms and things like that, so I'm not sure if I'll encounter the masking feature or not.
  • Block Bouncing - A hallmark of Mario is hitting blocks, and nowhere is this high status more evident than the fact that blocks get their own special routines for swapping between BG and OBJ tiles for blocks which have just been bumped, animating the bump, then settling the blocks back as BG tiles when done. SMB3 generalizes it a bit more into a routine to write a block-shaped space and then calls this with blank or block tiles, but the general idea is the same: when a block is hit, overwrite the BG mapping for these tiles with blanks, at the same time placing OBJ tiles in the exact same spot. Until some timer counts down, the OBJ tiles do a bumping animation. When the animation is complete, the tiles are pushed offscreen and the original block is drawn back to the nametable. At any given time, only this block is moving, so only this block needs to temporarily become OBJ. Of note, SMB1/2 have spots for more than one active block at a time, but SMB3 reduces this to one. Only one could be active anyway as the single metatile draw uses a static buffer for the four quadrants of the tile. The flip side is this *could* be used by other things in theory, but in practice is only used for the block bumps.
Anywho, this is an ongoing project, but I'll use this thread to document ongoing matters of comparison between SMB1/2, SMB3, and other related codebases as they arise. While I'm not going to take the time to make specific citations unless incredibly necessary, I'm happy to provide any code citations upon request. I have plans for a more formal analysis that involves specific code citations when I'm actually done with the SMB3 disassembly, but for now I'd like to at least mention stuff I spot in case it is information anyone else finds helpful.
User avatar
TakuikaNinja
Posts: 427
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand

Re: SMB Et. Al. Similarities

Post by TakuikaNinja »

Here's one similarity I know: SMB3 uses stack variables for NMI and IRQ modes, which essentially expands on the interrupt vector control system used by the FDS.
User avatar
creaothceann
Posts: 863
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany

Re: SMB Et. Al. Similarities

Post by creaothceann »

segaloco wrote: Fri Oct 03, 2025 9:58 pm Block Bouncing - [...] At any given time, only this block is moving, so only this block needs to temporarily become OBJ. Of note, SMB1/2 have spots for more than one active block at a time, but SMB3 reduces this to one. Only one could be active anyway as the single metatile draw uses a static buffer for the four quadrants of the tile. The flip side is this *could* be used by other things in theory, but in practice is only used for the block bumps.
Maybe they were already planning/developing the 1986 NES Mario Bros. port of the 1983 Mario Bros. arcade game, which has two players bumping the platforms potentially at the same time.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: SMB Et. Al. Similarities

Post by Pokun »

Well SMB3 has that Mario Bros-like battle minigame which is simultaneous 2-player. But I guess it uses an entirely separate engine?
User avatar
segaloco
Posts: 913
Joined: Fri Aug 25, 2023 11:56 am

Re: SMB Et. Al. Similarities

Post by segaloco »

The 2P battle mode is a special case of the course engine with yes largely its own core routine. It is considered a type of course, just like regular courses, bonus stages, Toad houses, and even technically the map is loaded in this way. However the map only uses the basic metatile load, foregoing scenery-based level building, and battle mode similarly uses parts of the standard course loader but then has its own carve outs like the map and bonus loaders.

Only the title screen, ending credits, and castle victory animations aren't considered "courses" to some degree from what I can tell. In reality the common thread appears to be courses are things that use the general metatitle buffering system for scrolling whereas the title, ending, and other cutscenes are more explicit in how they render stuff. Maps use this for instance, horizontal scrolling of the map background is done largely the same from a metatile perspective as horizontal loading in a stage. You don't see any of the rendering overlap on the edges of the screen because the map has the black bezel around it made up of sprites.

Otherwise battle mode is pretty separate, I haven't gotten into the guts of it yet, but I plan on hitting the battle handler before the main course generator just since I already kinda know what to expect in the latter. This does make me wonder if it would behoove me to study Mario Bros. a bit to see if there is any code flow. For the record, Mario Bros. was Intelligent Systems rather than SRD, so hard to say how likely it is any code is common between the two beyond basic stuff like display lists and jump tables.
User avatar
creaothceann
Posts: 863
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany

Re: SMB Et. Al. Similarities

Post by creaothceann »

You could perhaps also look at the arcade version (though it's Z80).
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
User avatar
segaloco
Posts: 913
Joined: Fri Aug 25, 2023 11:56 am

Re: SMB Et. Al. Similarities

Post by segaloco »

If its anything like arcade vs FC Donkey Kong, resemblances are largely superficial. CPU architecture differences aside, the general structure of DK is quite different, so I wouldn't be surprised if the same is true between different platforms of Mario Bros.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: SMB Et. Al. Similarities

Post by Pokun »

There are also several versions of Mario Bros for Famicom/NES including the FDS Kaettekita Mario Bros and the PAL-exclusive Mario Bros Classic which both resembles the arcade version more and has updated jump physics, but I think those were made after SMB3.


OK so "courses" means any scene that uses the metatile buffering engine while the title screen, castle scenes and the ending uses more predetermined hardcoded animations.

It makes sense that SMB3 resembles Doki Doki since that game was made by the same team before they made SMB3. If they got into new habits in how to do things it's not strange that they adopted it again for the next game they made.
Also SMUSA was made sometime when SMB3 was in development which shows on Mario's sprite which is very similar to that of his Super form in SMB3, though his small form is more similar to his classic look (just a bigger nose). The princess is also almost identical.

I'm a little interested to know who made all the sound engines of these games, and from your description it sounds like the SRD programmers made all of them in the games they worked with. Previously I've only heard of Kaneoka and Tanaka making sound engines in Nintendo games, so that is an interesting detail.
Kondo mentioned that he had to learn to program in order to compose, but I think he mostly worked with sound engines already written by a full-time programmer as he was mainly hired as a composer.

I'm also curious if the Doki Doki and SMB3 sound engines are more advanced than the SMB1/SMB2 engine. You said in another thread that the SMB1/SMB2 engine was quite crude and used things like an in-baked tempo, instead of letting things like tempo changes being part of the sound score pattern data fed to the engine as later games (such as DQ) mainly do.