More Ramblings from a Los Angeles Programmer

April 17, 2007

A great past few days

Filed under: coding, daily life, uk life — Tags: — Josh DeWald @ 9:10 am

Great Weather

First off the weather here in my neck of England has been amazing. Haven’t really needed any warm gear and there’s been absolutely no rain. Of course as I write this it’s a bit cloudy but, no matter, it’s been amazing. Rachel and I made good use of this weather on Saturday and had a great time walking around Notting Hill. I’ve never seen so many antique stands/shops in my life. Naturally we hit the first book store we found, Notting Hill Book and Comic Exchange on Pembridge Road. Ended up getting about 20 books between us for the equivalent of $2 a book (some only 10p!). In my haste I didn’t notice that one of the Len Deighton books I’d grabbed didn’t have the second half of the book contained within it. Such is life.

Super Mario Brothers 3 

On Saturday and Sunday I did some more work on my Java-based NES emulator and on Saturday managed to get Super Mario Brothers 3 and Zelda both working in fully playable states. I think this is something of a Holy Grail for me and in fact when I started this in January, my wife said all she wanted to play was her favorite game (Super Mario Brothers 3) so that has kept the drive. She had beat it already on the real system and still loved it. So it made me enormously proud when she asked excitedly if she could play it (she had seen that it looked decent). Quickly into playing as reality hit, we both wanted to have a tad more lives (how about infinite?) and to use an actual controller. Had to spend an hour or so figuring out how the Game Genie worked (more on that in a bit). Yesterday she was able to turn that on and played for 4 hours and got through most of World 3. Will have to use the GG again to get her back there (SMB3 doesn’t have save game feature and I haven’t implemented state dumping, doh!). Have also ordered an adapter for my PS2 controllers so we can hook it up, that turned out to be cheaper than getting a modified NES controller (although that would have been more authentic, but ah well). Rachel has apparently never played the NES version of Legend of Zelda, so she’ll be trying that next.

Thanks

I fixed a lot of bugs in getting SMB3 to look and play decently. I had about halfway understood the documentation around rendering 8×16 sprites but managed to combine the PPU documentation from Everything2 (btw that’s one of the greatest sites ever, easy to spend hours on) in the 2c02 Technical Reference. My predecessors have spent an amazing amount of time accurately documenting things on the real NES/Famicom and have produced awesome documentation for it. Most larger NES cartridges use circuitry-based “mappers” which handle the requests for Program ROM and Character/Pattern ROM to serve out the correct data based on internal state. So a note for people writing NES emulators is don’t make the assumption that the cartridge (or whatever your representation of it) is necessarily read-only (the Character ROM is) because writes can be performed to the registers of the mapper. They will look like writes to the program address space (0x8000 – 0xFFFF) because that’s all the NES’s CPU knows about. Anyhow, Super Mario Brothers 3 uses the MMC3 mapper and there a few documents out there but the one I found the most useful was Kevin Horton’s MMC3 guide. It looks like he has physical ones that he tests for their behavior. I actually learned that I completely wasn’t even thinking about or emulating the built-in timer of the 2A03 (The NES’s modified 6502). Thankfully SMB3 doesn’t seem to need it, as it uses raster counting from the mapper intercepting read calls from the 2c02 PPU (Picture Processing Unit). I’ve got loads of other documentation but I think those were the main ones for getting that game working (as well as tons of other things). Kevin Horton has documented some of the other mappers as well (I used his MMC1 guide for Zelda). I almost forgot, throughout I’ve used Nestopia as my “reference” emulator for how things should look and behave. It’s an open source project, but I never looked at the code.

Game Genie

 As I’ve mentioned before, I may be dense but when looking for documentation on the Game Genie I wanted something that actually said “this is how it works.” All the documentation was really around how to translate the Game Genie codes into memory address + value + check value. So what I ended up doing is loading the Game Genie as a normal game and handing it the game’s ROM. Once a write of 0x00 occurred to address 0 (0x8000 to the CPU) then I put the genie in “passthrough” mode and reset the CPU. Now any reads that occurred would be checked against what was stored in the codes and if they didn’t match it would just pass through. My holdup was that I was somehow thinking that the ROM would actually do this (but of course that’s impossible since it’s being emulated and is just a bunch of instructions to the CPU and so won’t be able to make “real” reads to the cartridge on it’s own). Once it clicked that I had to do the final step of actually checking the addresses, it all came together. I guess when I just plug in my own Game Genie it just works and so I expected this too as well 🙂

End

I still need to get sound working. Didn’t ever do that on the C64 but I want to do that on this one definitely. After that I will probably move on to another system. Writing hardware emulators is really fun, but I actually don’t care too much about playing with them. However I do have that option now and I’m sure I will take it up. When I started my Commodore 64 Emulator I had really never dealt with machine architecture except in some basic classes at University. Perhaps surprisingly, it will still take me quite a while to write anything in Assembly (at least I think so, I haven’t tried or needed to). When you are the machine you get to be “dumb” and only worry about things at the level of each instruction and store some state in registers. It’s actually up to the programmer to be “smart” and make use of those registers and instructions in a smart way, especially on the older 8-bit machines. So I really have to hand it to those who can crank out beautiful and complex programs written in 6502 Assembler. My job is actually fairly easy here, it’s all been documented by people before me and each part does one thing. I’ve learned a lot more about sprite rendering and double buffering and “interface-based” OO development than I ever really had to before. It’s been a great experience. You put it all together and you have…

 Super Mario Brothers 3 Home screen

Advertisements

2 Comments »

  1. […] (11/30/2007): Here are screenshots from the more recent version of the emulator (these are actually from April) of which I have released the […]

    Pingback by Working (sort of) NES Emulator « More Ramblings from a Los Angeles Programmer — December 2, 2007 @ 12:06 am

  2. […] wife never really played the SNES, so we shall see if I can find anything to drive me like getting SMB3 working on the NES did.  I would love to get Super Mario Kart […]

    Pingback by Holidays and a New Year « More Ramblings from a Los Angeles Programmer — January 9, 2008 @ 5:52 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: