10 ms·
Why did I spend 1.5 months creating a Gameboy emulator? (2017)
- jbschirtzinger 9y agoI 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.
- duxup 9y agoI'm actually cleaning up my GitHub repos at this very moment. So much basic stuff not really useful to anyone, things that other people clearly have done many times better. Old messy code, new messy code .... but to me they're experiences and represent invaluable learning that I've done. I look at some repo that is a mess, but I remember making widget X work and how great that felt. When someone says they created something I always think about what they must have learned to do that something, and not so much about the actual something. I get a bit frustrated when folks critique something about "Yeah but this other thing" and so forth. For me that's almost never the point...
- kodablah 9y 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 https://github.com/konsoletyper/teavm to WASM and abstract graphics calls and what not :-)
- ashleyn 9y agoIn "science projects" like these, you pay in time to recieve experience. By day I do Javascript at work, but my work on a passion project resulted in a wealth of OpenGL and C++ experience. Enough that when I was tapped to do work on our C backend, I hit the ground running quick.
- Endy 9y agoNext, the OP should try out a real challenge - take the crown of link emulation away from TGB-Dual.
- middleclick 9y agoI don't know where to start with writing an emulator. Any ideas?
- leggomylibro 9y agoDitto - I've been wanting to do one on a small ARM Cortex-M core, but it's bewildering to even think about where to start. It seems like people have put together a lot of good documentation for old systems though, which could at least be a good place to start reading: https://problemkaputt.de/gbatek.htm https://problemkaputt.de/gbatek.htm
- jwhitlark 9y agoChip8 is a good one to cut your teeth on. Very simple, good examples, does not take too long, but once you've done it, its much easier to see how more complex ones could work.
- pjmlp 9y agoTry this Assembly tutorial https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ It has enough for doing 2D games bare metal on ARM. And then you can jump into PiFox. https://www.raspberrypi.org/blog/pifox-bare-metal-arm-assembly-language-star-fox/ https://www.raspberrypi.org/blog/pifox-bare-metal-arm-assemb...
- burfog 9y agoThe upside is that the Raspberry Pi has good documentation. The downside is that you'll need to emulate 4 cores plus a GPU. Guest software (the stuff being emulated) may fail if the cores aren't decently fast. You may also need to do USB, audio, wireless LAN, and Ethernet.
- pjmlp 9y agoI understood that leggomylibro would like to learn the hardware first, before getting into emulation. Hence the idea of learning ARM Assembly, I guess I got it wrong.
- chaseha 9y agoWario Land 3 was a great game. Hmm, makes me want to find that old GBC I have lying around somewhere
- qop 9y agoHave you played wario land 4? WL4 is my favorite hand-held platformer of all time. Love that game! I've played 3 too, but it just didn't get me.
- netrap 9y agoAlways 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!
- bananatron 9y agoThis seems really common. I categorize 'finishing' as a whole other skill/category than programming/hacking/building stuff. Recognizing that the last 10% is the hardest part is daunting and not as fun a lot of the time, but the reward and payoff can be worth it.
- mysticmode 9y agoYup, that's true that finishing a project is more than programming skills. You would have to do a lot of boring work on the way. For me, the last 10% of the work which contains more polishing to what you have built so far and making it ready is the hardest part. But somehow I have successfully done that for my project https://github.com/joyread/server https://github.com/joyread/server when I launched v1.0 and it is indeed rewarding.
- justherefortart 9y agoThe fun is in the dreaming and starting. The work is in the finishing. I'm terrible at finishing personal projects. For paying projects it's much easier ($$$).
- pjmlp 9y agoI do the same. For work there is a deadline and the compromise to meet expectations. And being paid, of course. Hobby projects hop at snail pace towards the years.
- AnIdiotOnTheNet 9y agoOne thing I think people discount about this is the subconscious cost/benefit analysis. When something is an interesting puzzle to solve, the benefit is really high and the cost of a POC version is really low. Once it comes time to turn that POC into a workable product the cost/benefit changes. It loses all the value it had for being interesting and the cost shoots way up. It's easier to not have this problem when the lost value is replaced by money.
- nathell 9y agoSo 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 https://github.com/nathell/haze
- anyfoo 9y agoGame 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 https://www.youtube.com/watch?v=HyzD8pNlpwI
- anyfoo 9y agoHeh, should have read the article before writing my comment, the author mentions the same and even links to the Ultimate Game Boy talk as well. I hope I was able to add some detail.
- bandwitch 9y agoCoincidentally, the "Practice of object-oriented programming" course in EPFL has as a project this semester to build a Game Boy emulator in Java. You can have a look here (https://cs108.epfl.ch/ https://cs108.epfl.ch/). Although it's in French, google translate does a decent job.
- sjrd 9y agoOMG, I had no idea. I TA'ed this course 3 years ago. I wish the project had been the GB emulator at the time ... I would have had so much fun :-p
- near 9y agoThe Game Boy is only simple in the early stages of emulator development. You find quickly that it is full of excruciatingly complex edge cases that aren't documented, and aren't well understood by anyone. We're still making significant progress to this day on it. And even in the early stages, the Z80-like Sharp LR35902 is quite a hassle. If you want an educational project, consider an NES emulator instead. Still has lots of edge cases, but the documentation and reverse engineering work is far ahead of the Game Boy. Some reading if you like: https://mgba.io/2017/05/29/holy-grail-bugs/#pinball-fantasies https://mgba.io/2017/05/29/holy-grail-bugs/#pinball-fantasie... https://mgba.io/2018/03/09/holy-grail-bugs-revisited/#the-phantom-of-pinball-fantasies https://mgba.io/2018/03/09/holy-grail-bugs-revisited/#the-ph...
- baxtr 9y agoIs there a good one that works on a smartphone?
- djmips 9y 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
- flohofwoe 9y agoThe Gameboy CPU looks more like a stripped-down Z80 to me, it doesn't have the ED, DD and FD extended instruction ranges of the Z80 (most of those aren't that useful anyway), and the shadow register set is also missing, but the complete CB instruction range exists (bit twiddling and additional shift/rotate instructions). Also the relative jump instructions of the Z80 are there which are redundant NOPs in the 8080 instruction set.
- djmips 9y agoI think the missing IX and IY are definitive Z80 instructions. The 'Ultimate Gameboy talk' has a nice Venn diagram and they tend to agree that the GB is missing the 'interesting' instructions from the Z80. However the added shifts etc from Z80 are quite useful. But on the continuum between 8080 to Z80 the GB80 is closer to 8080
- djhworld 9y agoDoing 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 https://github.com/djhworld/gomeboycolor
- Andrex 9y agoKinda-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/ https://littlewebdj.com/ [1] https://twitter.com/andrewrabon/status/966551415358451712 https://twitter.com/andrewrabon/status/966551415358451712 [2] https://github.com/taisel/GameBoy-Online https://github.com/taisel/GameBoy-Online
- nategri 9y agoRe: Sound quality: I wonder if you might have more success compiling a more well-known C (or similar) based emulator down to webasm and running it that way.
- Andrex 9y agoWebASM is definitely the way to go today. Just wish I had the low-level know-how. Maybe I should take on the task myself like the OP did...
- kleiba 9y 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! :-)
- aquova 9y agoI'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.
- ixtli 9y 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.
- lcfcjs 9y agoThis is awesome! Not sure why you made it in Java (puke) but very cool nonetheless!
- pressurefree 9y agofor 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
- apple4ever 9y agoI 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.
- qop 9y agoMost 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?
- tw1010 9y agoIt's funny how incredibly highly the money and success narrative is emphasized in the news, and the drug-like high aspect of the work is rarely mentioned. The truth is that a lot of us would do it (and do do it) for free, and the high demand aspect of it is to a large extent just a blessing on the side.
- qop 9y agoI started for the glory. Refurbishing keygens and writing ddos perl scripts for irssi. But the more I learned, the bigger the problems I want to solve, (and create, in some cases) and that drove me to become more dedicated to the discipline of it all. I'm blessed to have the opportunity to do contracts or work a 9-5 with my skillset, and I can basically live whatever lifestyle I can afford that way. But yeah, even if I was getting paid 1/5 of what I have now, as long as I can spend my days browsing through disassembly, outsmarting someone, I'd still show up.
- basementcat 9y agoI don't think this is specific to programming, but generalizes to any kind of problem solving (as you write in your second sentence). I was once taking a shower when I cried out in joy as I had just figured out how to shave off an extra fraction of a micron from the side of a large state machine (we had a last minute change order and it hogged a bunch of area on the chip). I grabbed some clothes and jumped into my car (didn't think to rinse the shampoo out of my hair) and floored it down the freeway to the office (VPN? hah!)
- t0mek 9y agoHi, 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.
- khedoros1 9y agoI wrote my own GBC emu about a year after you, and an NES emulator, working on and off, from about 2008-2014, doing bits at a time. It's amazingly gratifying when more and more games start working in it. I'm going into Game Boy Advance now. Even just efficiently decoding ARM opcodes is an adventure on its own. Different timings and bus widths in different parts of the memory map....but a large enough map that you don't have to worry about banking at all. Although I suspect that it's fast enough that it might start making sense to look at dynarec/jit techniques.
- avilopro 9y agoyou 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 9y agobecause you are amazing for doing that homeboy! get it
- sytelus 9y agoTLDR; 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.
- KennyCason 9y agoHaving written most of a Gameboy emulator I can acknowledge how fun/tedious they are to write. I now feel motivated to go finish it. :)
- sgt 9y agoThis 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/ http://blog.rekawek.eu/2016/12/08/mac-plus/ Hoping he'll post more soon.