Why did I spend 1.5 months creating a Gameboy emulator? (2017)

tosh | 617 points

Game Boy emulators are always great for educational or experimental projects, because the Game Boy platform is surprisingly simple, which leads to a very quick payoff, and yet very "real" in that the Game Boy was a great commercial success with thousands of software titles available, so you have plenty of software available to try in your project and actually make use of that payoff.

One example to illustrate how simple the Game Boy is: There is no operating system at all, only a 256 byte boot ROM whose sole purpose is to display the Nintendo logo from the cartridge and halt if it does not checksum correctly (for both cartridge integrity and legal reasons).

This entertaining 33c3 talk manages to describe the Game Boy hardware practically in its entirety (and with some previously unknown details, actually): https://www.youtube.com/watch?v=HyzD8pNlpwI

anyfoo | 6 years ago

Hi, it's the blog author here.

I just wanted to write I'm really happy that this post showed up on the HN front page. It's been more than a year since I wrote the post and from the time perspective I think it was the most rewarding project I've ever done. It doesn't matter that there's a plenty of more mature, accurate, user-friendly emulators - the "journey" was a reward in itself. If you're thinking about creating your own emulator, I highly recommend it.

t0mek | 6 years ago

So much of the fun rings true.

I'm reminded of the days I was writing a Z-machine emulator in Haskell [1], ostensibly as a uni class project but also as a way to teach myself Haskell and have fun; I had the infrastructure in place and was trying to run Zork, implementing opcodes, one by one, when finally I saw the familiar message "You are standing in an open field west of a white house, with a boarded front door. There is a small mailbox here." The sense of accomplishment was rewarding and elating.

2004. Good times.

[1]: https://github.com/nathell/haze

nathell | 6 years ago

"[...] every time I had a few minutes during the day and basically every evening I felt an irresistable urge to move the emulation a bit forward [...]"

Ahh, memories of the good old days... before I got married...

"[...] if I have 5 minutes of a spare time, I was trying to fix this weird GPU or sound bug. I guess it’s not too healthy (especially if you have a family) [...]"

Oh, crap, this guy apparently has family, too! Shame on me! :-)

kleiba | 6 years ago

Always impressed by people who complete things. I've had terrible luck actually FINISHING a project. I guess maybe it's ADD... or my interest in rather boring device drivers and the like. I've been able to modify large projects with many thousands of lines, but when it comes to write one from scratch it really is a lot of work. Props!

netrap | 6 years ago

I think most projects where a person is trying to learn something such that it builds on something else are often not understood by a person who is not on the same path. In the end, the tapestry formed is only understood by the one doing the journey and then in hindsight it all makes perfect sense.

jbschirtzinger | 6 years ago

Kinda-related, but a few months back I started working on a Web wrapper[0] for a specific GameBoy ROM, Little Sound Dj (LSDj.) See it in action here: [1]

I was able to get the project up and running using a third-party JavaScript emulator[2], but the library was basically abandoned years ago and the sound in modern browsers is very... odd. Unfortunately, sound is crucially important to music creation software like LSDj.

I'm also mystified that there doesn't seem to be a .SAV format that's cross-compatible between emulators, which is required for basically the entire purpose of the app. (Users would work on a project online on any device, then transfer the .SAV to real hardware for recording the tune.)

If anyone has advice on these topics I'd love to talk!

[0] https://littlewebdj.com/

[1] https://twitter.com/andrewrabon/status/966551415358451712

[2] https://github.com/taisel/GameBoy-Online

Andrex | 6 years ago

> So why did I spend all this time trying to write it? I treated it as a programming riddle [...] Maybe because of these results I got quite addicted to the project itself [...] I guess it’s not too healthy (especially if you have a family), but it also doesn’t happen that often.

I can empathize, I think lots of us have GH profiles littered with projects we've hit real finish lines on but may not be useful to others. But I actually think it's healthy, especially if you have a family (assuming it's only your spare time). It provides sanity and brain maintenance simultaneously. Even better if you have an employer that doesn't track your every hour and recognizes the value of these kinds of things on down time.

> Right now I don’t have any obvious ways to move the app forward, so the addiction dissipated ;)

Run through https://github.com/konsoletyper/teavm to WASM and abstract graphics calls and what not :-)

kodablah | 6 years ago

Doing it 1.5 months is impressive, it took me almost 6! [1]

I agree with the post that it was a very rewarding (if frustrating) project. But once you see that Nintendo logo come down the screen for the first time it's almost like magic.

[1] https://github.com/djhworld/gomeboycolor

djhworld | 6 years ago

I don't know where to start with writing an emulator. Any ideas?

middleclick | 6 years ago

This blog made my morning. Started reading about this Gameboy emulator - really cool project. Then read through a few of his other posts including the one about resurrecting a Macintosh Plus: http://blog.rekawek.eu/2016/12/08/mac-plus/ Hoping he'll post more soon.

sgt | 6 years ago

> It was also very addicting - every time I had a few minutes during the day and basically every evening I felt an irresistable urge to move the emulation a bit forward - fix this strange GPU bug, pass one more compatibility test or implement one more missing feature.

This resonated strongly with me. I did a study of architectures in college where i built a bunch of emulators of real and made up chips and fiddling with the details of an emulator is incredibly engrossing.

ixtli | 6 years ago

Wario Land 3 was a great game. Hmm, makes me want to find that old GBC I have lying around somewhere

chaseha | 6 years ago

"First I implemented all the Gameboy CPU opcodes. It’s not exactly the Z80, but it’s pretty close" - The CPU is close to 8080 which the Z80 is derived from, so hence the Z80 similarity. However all the main Z80 enhancements are missing. A+B-B=A

djmips | 6 years ago

I love emulators like this person too. My dream has been to write a TI-85 emulator. I know there is a few out there, but none for the Mac. I used that calculator a ton in HS, and that's where my love for the Z80 came from.

apple4ever | 6 years ago

I've been heavily thinking about making an emulator for a while now, maybe seeing some of the sources here will motivate me to go through with it.

aquova | 6 years ago

Having written most of a Gameboy emulator I can acknowledge how fun/tedious they are to write. I now feel motivated to go finish it. :)

KennyCason | 6 years ago

you are amazing for doing that, you did it because there would be many a people who would appreciate such thing, for that we thank you.

avilopro | 6 years ago

Is there a good one that works on a smartphone?

baxtr | 6 years ago

TLDR; for the question in title:

I treated it as a programming riddle (or a series of riddles), quite similar to those you can find on the Project Euler.

sytelus | 6 years ago

because you are amazing for doing that homeboy! get it

avilopro | 6 years ago

Most hackers worth a shit know the answer to the question without even any context.

It's like a lust to solve a problem. Idk maybe it IS add, I'm there too, but sometimes there are software problems that just completely captivate me in a way that nothing else does.

Time melts away, and I'm just typing.

Y'all know that feeling, that 6am,"oh shit I work in three hours but I was hacking on this project all night and it almost works if I could just get this thing over here to- Oh, work, real world.... Right."

That mental mode of concentration is elusive and indeed a bit habit forming. There are moments where I'll be washing my car or cleaning the house and I have that "I should be in vim right now" thought and the world just seems grayer and dumber until I survive past it and sit back at my keyboard again.

Said like that, that is weirdly analogous to when I used to drink.

Is programming a drug? Are some addictions healthy?

qop | 6 years ago

This is awesome! Not sure why you made it in Java (puke) but very cool nonetheless!

lcfcjs | 6 years ago

for me. i am here to be served.

why is the half life of chromium 51 same as moon? becasue fievel went south. in dolby 5.1

pressurefree | 6 years ago

Next, the OP should try out a real challenge - take the crown of link emulation away from TGB-Dual.

Endy | 6 years ago