views:

556

answers:

5

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?
+11  A: 

No. At least none that I know off (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.

speeder
A: 

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

Goyuix
+3  A: 

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
+1  A: 

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
+1: Wow. Assembler, eh? Very interesting. This is just the type of information that I was looking for.
Jim G.
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
+1  A: 

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.

Try looking there for "metroid source code".

Russel
I'm thinking it was reverse engineered and not released. Regardless, the source is available.
kirk.burleson
Original question: Failing that, are there any NES games for which source code is available to study?
Russel
I thought that counted :)
Russel