Sunday, July 25, 2010

Hacking the Mario - First steps


Hi everybody! With this post I would like to start talking about my new project: a study of the Super Mario Bross code for NES. Why I'm doing this? for no particular reasons. I don't want to make an hacked Super Mario game, there are already tons of them around. I'm just curious to see what techniques they used to program the NES (and a girl dumped me so I have a lot of free time to throw away). Very likely there are already several guides explaining the internals of the game, but there is no fun in simply reading them and this will be a simple log of what I am understanding of the code that I'm reading. I can't guarantee that the information I'll write here are accurate: I'm not a programmer, so if you're interested and you find some errors, don't be too much upset and just let me know :)
Some basic requisites if you would like to follow me:
  1. Knowledge of 6502 asm.
  2. A basic idea of how the NES works.
For the first point, I would recommend you to read the "Using 6502 Assembly Language" book that you can find at the bottom of this page. Just ignore the parts regarding the Apple II (NES and Apple II have nearly the same processor). For the second point, a good starting point is the info that you can find here. The Jeremy Chadwick is a very good reference txt. There are also a couple of useful tutorials in that page that can help moving the first steps with the system. Another useful tutorial is the Nerdy Nights one (with also a part about sound).

The last question before starting is: Why SMB? While it's not the smallest game of the NES library, it's been the first big hit of the system (it was actually among the first titles available for the system in USA). It doesn't use any mapper, only 32kb of PRG-ROM and only one CHR-ROM. Coming out 2 years after the release of the system, I expect that the programmers of the game used some sort of "from manual" code: they programmed what the hardware was supposed to do without "dirty tricks" that could make the code harder to read. We will see :)

The tools that I use are:
  • Disassembler: dcc6502 that you can find here: www.neshq.com. If you want to run it under windows 7 64-bit, you can simply recompile the source file with something like Visual Studio Express (It uses the standard C libraries).
  • HexEditor: no preferences.
  • Emulator: FCEUX with its integrated debugging tools
To get the same disassembled code as mine from an iNES rom, first use the hex editor to delete the first 16 bytes from the file (the iNES header) then you can use the disassembler on it.

Stay tuned, in the next post we will start watching the code!

No comments: