45

I just played a game of RBI Baseball in a browser window.

That in and of itself strikes me as simply amazing. When I was young, the NES was a magical box, capable of providing hours of enjoyment to young kids throughout the world.

Now, decades later, I'm a programmer. And I can appreciate the programming that went into games that were developed with more primitive hardware just a couple of decades ago. In fact someday, I fully expect that code from some of these games will be enshrined in the Smithsonian.

My Programming Question:

Have any classic NES games (like RBI Baseball) been open-sourced, and if so, where can I find code to study?

Failing that, are there any NES games for which source code is available to study?

I think it would be worthwhile to learn from their example.

For instance:

  • Did they use object-oriented programming?
  • Did they use design-patterns to keep the code maintainable?
Jim G.
  • 15,141
  • 22
  • 103
  • 166
  • 2
    I'd be surprised. I suspect that Nintendo's licensing probably strongly discourages open sourcing games developed for the platform if it doesn't outright prevent it. – Michael Burr Feb 11 '10 at 02:29
  • @Robert C. Cartaino: Thanks, Robert. Now could you please retract your close vote? – Jim G. Feb 11 '10 at 02:52
  • I am surprised at you people wanting to close it, from first reading the first version of the post I understood that the author just wanted to have some code to study. – speeder Feb 11 '10 at 02:56
  • 9
    Ill vote to open if closed. Asking for open source code for something you are interrested in, sounds very programming related to me. – Stefan Feb 11 '10 at 03:34
  • for your two last questions, I'd answer No to both with almost 100% confidence (OOP and Design Patterns are from middle 90's, NES is from middle 80's). – fortran Feb 15 '10 at 16:22
  • 1
    @fortran: Ya - I agree with you; but even if they aren't using OOP and Design Patterns, I'd like to understand their code structure and see how they kept things organized and maintainable. – Jim G. Feb 16 '10 at 13:58
  • OOP is far older than "middle 90's". Even if they weren't using C++ or Java, I bet they were using some kind of OOP. Some of those games were pretty sophisticated, and needed to run in fairly constrained memory -- I think you'd naturally end up with objects in some form or other, based only on the raw requirements. – Ken Aug 31 '10 at 06:28
  • @Ken yeah, sure there had been "objects" before, but their mainstream acceptance wasn't until those languages made OOP popular... And the "Gang of Four" book on Design Patterns was written in 1995 :) – fortran Mar 10 '14 at 15:26
  • 2
    The author of the legendary "Prince of Persia" has published the source code of the original version for Apple II, together with technical documentation. It is available on GitHub: https://github.com/jmechner/Prince-of-Persia-Apple-II This game was ported to NES platrofm. – Kirill Mar 11 '16 at 20:22
  • Someone has reverse engineered Super Mario Bros. See https://gist.github.com/1wErt3r/4048722 – FusterCluck Oct 26 '16 at 13:29
  • 1
    While not a classic, Home Alone 2 source code and tools have been released: https://twitter.com/frankcifaldi/status/738136827161255938 – DBedrenko Nov 25 '16 at 17:10

7 Answers7

28

No. At least none that I know of (and I've been searching).

NES appeared right after the 1983 video-game crash, the main reason why the market crashed was the flood of bad games, triggering the customers to not buy a single game, because there was no way to know what game was good.

So Nintendo when introducing NES (and all other consoles from the time, like Master System from SEGA), decided that only approved games would ever get released, AND making anything open source ever being a breach of contract with heavy fines, the reason for that is that by not releasing a public API, it would make "homebrews" harder to flood the market.

Today Nintendo is much more easy on the part of allowing the games, see the flood of crappy games on the Wii, but still no console allow you to use their "true" API, to avoid the flooding, there are even a issue when someone used a GPL engine (ScummVM) on Wii, causing trouble, because releasing the source of a game for a Nintendo system is a breach of contract, and GPL demands the source to be released, in that particular case the games were pulled of the shelves.

And no, XNA and PS3 Linux are not really console APIs, both impose severe limitations on what you can do with the console.

Maybe you can find homebrew, or reverse engineered games. But I guess that this is not what you asked.

Also the source of remakes and ports sometimes can be found, but these don't use the console API.

alex
  • 479,566
  • 201
  • 878
  • 984
speeder
  • 6,197
  • 5
  • 34
  • 51
  • 2
    I know this topic is a bit old, but this page has the source for several games for three consoles (NES, Genesis, SegaCD) from one of their developers: http://shrigley.com/source_code_archive/ – Matthew Dec 11 '16 at 16:20
13

Maybe you have since found this, but Metroid (the original, for NES/Famicom) has been disassembled and the code (in beautiful ASM) posted on Romhacking.net.

Direct link.

James McMahon
  • 48,506
  • 64
  • 207
  • 283
Russel
  • 3,609
  • 8
  • 33
  • 32
12

If you're interested in NES programming you should check out Episode 91 - Tengen Reunion Roundtable of Retronauts. (Note this is episode 91 of the original run of the podcast, newer episodes can be found @ http://www.retronauts.com/)

It's basically a bunch of former NES programmers reminiscing about game development on the system (and other retro systems). They occasionally dip into the technical stuff, which is all really fascinating.

James McMahon
  • 48,506
  • 64
  • 207
  • 283
  • That link is broken, and when I looked up Episode 91 of the Retronauts, they discussed SAGA, not NES. I did listen to an episode entitled "Episode 51: An oral history of the NES", but I don't recall any part where they discussed the actual development. It was mainly marketing-based discussions. I'd love to find the episode you mentioned in your comment. – user64141 Jun 02 '17 at 01:33
  • 1
    @user64141, What makes it confusing is that since I originally posted this there has been another run of Retronauts that overlapped the original episodes numbers. Updated the answer with the proper links. – James McMahon Jun 05 '17 at 03:58
  • 1
    Thank so much for recommending the Retronauts. That episode was very interesting. For anyone else reading this, the guys in that episode were true hackers. At one point, they talk very briefly about how they were able to make assembly code look like C. Another time, they talk about reverse engineering an arcade game because the owning company wouldn't give them the source code. These guy's are often uncredited, because video-game makers didn't want other companies stealing them away. But these are the guys who make the games of our childhood. – user64141 Jun 09 '17 at 23:14
8

I've never worked in the videogames industry, but I've read quite a bit about it and I talk from time to time with friends that do, so I'll try to explain a more or less what's the difference between a game and other application, regarding programming methodologies.

The first thing to understand is that a game is a one-off product. It's not like a spreadsheet or a word processor, where you can release new versions improving and extending the previous codebase.

The second thing, is that you need to release the game as soon as possible. Usually, the more time you spend in a game, the worse will it be in comparison with the other games of the time. This is mostly true for PC games, where hardware evolves much faster than in the console world, but still applies to a large extent (games continue to get better even with the same hardware as better tools and algorithms are developed).

The third thing is that usually games need to push the hardware to the limit. So screw all the elegant patterns that would make your code more beautiful and maintainable if they make it to run slower.

So what I would expect after dissecting an old NES game source code is just spaghetti code, most of it written in assembly with plenty of low level hacks tightly tied to the architecture of the machine.

I hope my answer is useful for you.

fortran
  • 74,053
  • 25
  • 135
  • 175
3

I would recommend looking at nesdev.com if you are interested in NES game development. They have detailed documentation.

mani1986
  • 31
  • 1
  • 3
2

You won't likely find source for the original games, but there is plenty of homebrew out there and a relatively mature toolchain. As is the favorite answer, google is your friend. But to get you started, here is relatively decent tutorial:

http://www.bestdamnpodcastever.com/millerblog/?p=72 via "The Wayback Machine"

Michael Burr
  • 333,147
  • 50
  • 533
  • 760
Goyuix
  • 23,614
  • 14
  • 84
  • 128
  • @James: I've updated the link to a mirror on archive.org. I wonder if if's appropriate or permitted to mirror the article in this answer (the article isn't very long) in case it drops off archive.org? – Michael Burr Jul 16 '11 at 23:26
  • @Michael Burr, if they've allowed the original site to go down I'd think you'd be doing the internet a favor by mirroring the content. Just give credit where credit is due. – James McMahon Jul 16 '11 at 23:30
1

NES Games were developed only (as far as I know) in assembler, and I guess the source code is long lost, after those many years.
Anyway, having assembler source code is not so far from machine code, so it may not be too much revealing as it would C or Java code.
About object orientation and desgin patterns, again, it was assembler and the 80's, don't expect any of that.

Petruza
  • 11,744
  • 25
  • 84
  • 136
  • 2
    I doubt the source code is "long lost" - they continue to release new and updated versions of those games, either on the Wii Virtual Console or as handheld ports. – Zachary Wright May 12 '10 at 17:31
  • Who would lose the code to games that fueled multi-million dollar franchises? And machine instructions are far and away from C and Java code. I'm not saying that from some sort of purist perspective, it's just a matter of fact. – JSON Jun 06 '19 at 00:52
  • Crap, I bet the original source to most NES games can be sold for millions. Just because the tech is old and outdated doesn't mean the value of the games have dropped to the point that they would trash the code. – JSON Jun 06 '19 at 00:55
  • 1
    @JSON please read carefully: "assembler source code is not so far from machine code, so it *may not* be too much revealing *as it would* C or Java code" – Petruza Jun 06 '19 at 14:50