Dartendo 0 -> 1

6 min read Original article ↗

Dartendo is a Nintendo emulator written entirely in dart. Yes, Dart.

The logo for Dart. I think it’s a playing dart feather?

There are many efforts to create languages that transpiled to JavaScript including CoffeeScript, TypeScript, Google Web Toolkit (GWT), and Dart. Currently, TypeScript from Microsoft appears to be the clear winner. TypeScript has nice integrations with webpack and the ability to slowly and painlessly migrate files from JavaScript. But, this story begins long before TypeScript rose to dominate the JavaScript transpiler wars.

It was 2011 and Google was pushing Dart really hard. The brand new Google TV frontend was set to be entirely written in Dart, and many people who were writing Java for the web using GWT were excited to see a java-like syntax for the browser with nicer Javascript interop. As part of promoting Dart, the product managers for Dart organized a hackathon, where small teams of engineers work together over a 24 hour period to produce cool projects that show off the power of Dart.

I decided to enter the hackathon with the goal of converting a Java Nintendo emulator called vNES to Dart. Because the languages are similar, it was a matter of porting the logic to Dart and then porting the UI from Java2D and Java audio to the corresponding Dart interfaces. To help with the graphics and audio work, we also looked at jsnes, a javascript nes emulator.

This all seems pretty straight-forward, except for two challenges:

  1. Dart was a very immature language at the time, and many HTML5 features were not supported, so we knew we were going to have to hack a lot of it together with the help of the Dartlang developers

  2. The entire hackathon, from idea to completion, has to be done in 24 hours.

Let’s pause right here. The proposal is to port/write 15,000 lines of a language that almost no one had seen before, to build an emulator for a machine that we didn’t have the specification for, in 24 hours of wall-time, to (maybe) win a plastic trophy. It’s absurd on its face, and yet I was shocked to find more than a few people who were as excited as I was to build this. What motivated people was the vision of the finished product (super mario running in a browser window), the challenge of actually finishing the product in a day, the opportunity to work on cutting-edge technology built by people we all respected (dartlang), and the fact that anyone who joined this project also shared these values and/or was equally insane. All the talk of product-market-fit, minimum viable products, network effects, etc. doesn’t apply here. Dartendo is a maximally unviable product. Dartendo is art for art’s sake.

This is the second highest Maximally Unviable Product. Dartendo is the first.

In 2011, building an emulator for the web was extremely difficult. One of the key challenges was that fixed integer support in Javascript was very poor and things like WebAssembly didn’t exist. Thus, we needed to apply many bitmasks to the java code in places where they expected an overflow, handle integer division correctly, etc.. There were many places where we could introduce errors so we needed to have plenty of time to do tired debugging. To get this all done efficiently, we broke down the project into several tasks:

  1. Porting the core logic from java (vNES) to dart.

  2. Porting the mappers from java to dart.

  3. Porting the audio/video interfaces from javascript (jsnes) to dart

  4. Setting up AppEngine, the frontend html/css and input handling

  5. Handling ROM loading into html5 localstorage, and deserialization

Everything after that was kind of a blur. I can’t remember who worked on what but we collectively wrote over 13000 lines of code in a single evening. I remember stepping through the dart and java debuggers line-by-line to catch many numerical issues. Unlike normal game development where you can cut features, with an emulator it either works or it doesn’t. I remember being sure that there was no way this was going to work by the deadline. I remember when we saw the opening curtain of Mario 3 in the wrong shade of red and everyone huddled around the laptop and cheered while memory leaks ground the laptop to a halt. It was magical. It was epic. It was the memory leak that caused me to hard reboot my laptop and lose hours of work.

It all came together in the last few hours. We ended up winning the hackathon and each got one of these plastic trophies. The base is hollow but it holds up a ton of sentimental value.

The marble printing on the base is really well done, it looks like someone put $0.15 worth of marble on there.

Here we are, looking very tired:

We made Dartendo available on the Internet and posted it on Hacker News ( https://news.ycombinator.com/item?id=3689299 ). At the time I didn’t realize that it required a bleeding-edge version of chrome and a very fast computer. Most people couldn’t run it (as you can see from the comments).

And this is where the story would end, except that I was rummaging through some old boxes yesterday and found the dart trophy, which made me search for “Dartendo” on the web, which led me to the aforementioned hackernews post, which made me a little sad. It was such a cool project, but it was built on such an early version of dart that no one outside a few people in Google could use it. So I set out to bring Dartendo back to life.

Fortunately, the repo was still available on googlecode (a github-like website that went into archive mode years ago). Upon opening the project with the latest dart environment, I was met with hundreds of compiler errors. Fortunately, many of them could be fixed with some regular expressions applied across all the files. The biggest change was that modern browsers block websites from playing audio before user interaction with the site. As a result, I had to add a “click to play” feature. The vast majority of the fixes came from googling answers and applying them.

After about a half-day of hacking, Dartendo was alive again! https://mistertea.github.io/Dartendo/

The project is now hosted on github so anyone can easily browse at the source: https://github.com/MisterTea/Dartendo . Maybe someone will add on-screen buttons for mobile, or joystick support one day.

Dartendo was an amazing project. I still keep in contact with several of the folks I met that day. Working on emulators is incredibly satisfying, and I went on to build MAMEHub, which lets people around the World share an arcade together over the Internet.

Although Dartendo runs flawlessly now, at the time the technology and hardware wasn’t where it needed to be and the game stuttered too much to be playable.

At one point, I had to meet some sketchy guy in a Walmart parking lot because some video game company (which will go unnamed) served me with a cease-and-desist letter for working on emulators.

No project dies, it just goes into hibernation. Also, keep backups.

Discussion about this post

Ready for more?