More Ramblings from a Los Angeles Programmer

June 30, 2007

Combination Java NES/C64 Emulator source release

Filed under: coding, technology — Tags: — Josh DeWald @ 10:26 pm

I finally bit the bullet and “packaged” up my Java-based NES and Commodore 64 Emulator.

The delay has been for multiple reasons:

  • Laziness – I knew that I couldn’t just tar it up and send it out, but needed to do some cleanup, take out some files, etc. I had some time on my hands, so figured why not.
  • Fear – I don’t think it’s just me, but it’s kind of scary to let other people see the code you’ve written when you know that it’s not perfect and poetic and all that. However, it does in fact work so I figured that was a plus. I don’t believe the code is monumentally horendous either. There is a diagram of of the architecture available on my wiki.
  • Potential Uselessness – There are a lot of other emulators out there at have been in development for a lot longer and are open source. I did this purely out of curiosity to see if I could, so don’t download this expecting to pop in any ROM and go with it. Some work, many don’t. There’s also no sound. Nestopia is the emulator I used when I wanted to see how a game was supposed to look/work. I don’t know if it’s open source or not however.

I’ve finally overcome those and just decided to get it out there.

I’ve decided on the BSD software license. What this means is that you can take this and basically do whatever you want with it, but if you release something based on it, you have to include my license with it. I initially planned on going with GPL, but it felt too restrictive in this case. In my dream world, people will download this, fix bugs and contribute them back. That would also be highly unexpected.

It is my hope that the architecture is simple enough that a person could at least use this to see how they might go about creating an emulator (especially 6502/6510-based ones such as the Apple II). It would suck if it serves as a way to _not_ make an emulator, but I can accept that too. It’s fairly object oriented in structure, but in my testing (I modified it so that the instructions were executed as methods rather than objects) this did not prove to be a major performance issue. That said, it just barely runs at full speed on my machine and it doesn’t have any timing code in it. So clearly there are some inefficiencies in it.

As I’ve mentioned previously, the greatest moment of development (which also represented the end for the most part) was when my wife actually sat and played Super Mario Brothers 3 for 4 hours straight on it. The idea that kept me going after I had it “working” was that for her, SMB3 was what it meant to have a Nintendo. Unfortunately, at that time I didn’t have the gamepad adapter so she had to use the keyboard. By the time I got game controller stuff working, she and I were basically over it. Such is life.

Anyhow, you can download it here.

It is also available on github now:

Note that to use it easily, you should have Ant installed, but it’s not required. Please put any comments here if you do download it and have questions about usage, why it sucks, why it’s cool, or literally anything at all.


  1. I just want to encourage you here. It just so happens that NES and C64 are two of the coolest game systems ever!

    Comment by Greg — December 22, 2007 @ 7:08 pm

  2. I was browsing for NES emulator source (Java preferably) and came across your site. I’ve downloaded your code and have it running.

    Thank you for making it available.

    Comment by Bill — February 26, 2009 @ 2:10 am

  3. Greg – Thanks!

    Bill – That’s great to hear! With hobby stuff it’s easy to make it difficult for others to run, so I’m glad you’ve had some success. You’ll quickly find that there pretty much every other emulator is more feature-rich, but not all are open source. It’s also not optimized for speed but (hopefully) for readability.

    Comment by Josh DeWald — February 26, 2009 @ 2:14 am

  4. This was a Great write up, I will bookmark this post in my Clipmarks account. Have a good day.

    Comment by Sharika Ferell — June 13, 2010 @ 9:27 pm

  5. Hey, I just want to say thanks, I made a bet with a friend of mine that I could make a java based NES emulator, so I’m having a look at your source

    Comment by Matt — November 2, 2010 @ 2:43 pm

    • Matt – That’s great! Hopefully it is readable enough to be of use. I ended up breaking it out into a couple of separate modules, so that I could start work on an SNES emulator based on the same basic code base… but ended up getting a bit distracted šŸ™‚ Let me know if you need anything.

      Comment by Josh DeWald — November 2, 2010 @ 3:05 pm

  6. What compiler should I use? šŸ˜€ I’m a newbie noob noob!

    Comment by 1243235 — June 5, 2011 @ 10:24 pm

    • You should just need any Java 5/1.5+ JDK. So as long as ‘javac’ is on your path you should be good. That and Apache Ant for doing the actual build.

      Once you have the JDK and Ant, you should be able to do something like:
      ant run -Drom=path/to/your/rom/file

      To just compile, you should be able to do:
      ant compile

      It’s been a while since I looked at this, hopefully this is all accurate šŸ™‚ Shoot me and email or comment if it doesn’t get you up and running.

      Comment by Josh DeWald — June 6, 2011 @ 1:09 pm

  7. This is working nicely, yet that’s probably because I’m only using 1 nes rom. But the code is better than anything I could write. Nice job, and I’ll jab around inside the code and see if I can get the sound working. But as it seems that you didn’t add sound on purpose, I’ll be up all night.

    Comment by dookie791 — October 28, 2011 @ 3:08 pm

  8. Nice job your effort is appreciated. You posted this 5 years ago so I wonder what amazing things you have moved on to now. Do you have any advice/tutorials on how to get started programming a nes emulator? Since I started as a child falling in love with the NES my plan of attack is to start there then SNES etc. When I was in College 7 years ago I wish I had a project like this so I could have had hands on experience with a group. I have been programming professionally now for 7 years since I graduated college so I am comfortable with the basics of java programming. I will take a look at the source but I was curious about the logic to accomplish a task like this. Once again thanks for your hard effort. Any help is appreciated. Thanks

    Comment by Kevin Clauson — June 28, 2012 @ 9:38 pm

    • @Kevin – Thanks! I wish I could say that in this regard I have done bigger and better things, but not so much (the closest thing perhaps was I wrote a toy JVM using C# I have worked on the emulator here and there (there are some recent posts about it). Also, I began work on an SNES emulator and was able to get a little bit on the screen from a demo ROM I found. But that certainly has a lot of work to do. Perhaps it is something you might want to continue? I had started to split up the emulator in “core” and then specific machine bits and the SNES emulation went somewhere with that.

      In terms of the process/logic, I took a fairly literal (some might call naive) approach to it in that I tried to implement everything as described, without *too* much in the way of performance tricks. This naturally makes it relatively slow (though on my current Macbook PRO I had to put in some slowdowns). This means that for individual instructions they pretty much do exactly what they are specified to do, instruction per instruction. There isn’t any dynamic recompilation or block detection. I think some emulators will defer calculation of the various registers until they are requested; mine does not. In this sense I think my version is very straightforward and is (hopefully) good for someone wanting to learn how they might do it, or build on it. My emulator is a horrible choice if you want to run it on a phone or any lower end device.

      The emulation of the chips (CIA, VIA) are communicated with as specified in the docs (there aren’t any special hooks into them from the emulator… they simply appear as memory addresses). The trickiest part was implementing the video chip to operate as a real one does (allowing for games to do fancy things with sprites). For purposes of that it is raster line-based, generating an interrupt any time it needs to draw a line and “forgetting” what might have been in memory previously. Officially the video chip is screen based, but in real life there are vertical interrupts I believe.

      I never implemented sound so I think that might be a good addition to it if you (or anyone) is interested.

      Comment by Josh DeWald — June 29, 2012 @ 11:21 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

Create a free website or blog at

%d bloggers like this: