top | item 16032889

Show HN: Simple Gameboy Emulator

82 points| sacert | 8 years ago |github.com

23 comments

order

tnecniv|8 years ago

Making a Gameboy emulator was one of my favorite and most instructive personal projects.

It's worth noting that there was actual extra hardware built into the carts, so you need to implement certain features like extra RAM based on the cart ID in the ROM file.

deaddodo|8 years ago

Not the cart ID, you're looking in the cart header at byte 0147 for the actual hardware (MBC1, MBC2, MMM01, etc) functionality in conjunction with bytes 0148 (ROM size) and 0149 (RAM size) for specific bank sizing/mapping.

doomlaser|8 years ago

I love projects like these. Code looks very clear and organized. How long have you been working on it?

sacert|8 years ago

In total I've spent roughly a month and a half working on it but mostly only spending an hour or so every couple days on it. After understanding the architecture, the coding isn't too difficult and is immensely rewarding!

styfle|8 years ago

I know nothing about emulators, so it would be nice if the README provided instructions for how to build and run the emulator.

Here is some inspiration: https://github.com/dolphin-emu/dolphin

sacert|8 years ago

You're right, I should've included that from the get-go. Included one now, hope it helps :)

rebootthebox|8 years ago

Great! The CPU.c code is quite instructive since I'm writing a toy VM in my free time. Starring this :)

deaddodo|8 years ago

They're using a relatively simple opcode map, but most instructions are logically redundant as can be seen here:

http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html

The next step in emudev, with most compiled/systems languages at least, would be to create macros (such as OP_LD or OP_ADD) that generates static instructions at compilation. Another, cleanish method, in C is to generate a 256-length function pointer (void*) based static array and map those generated functions to that, to make the dispatch step simpler. Small trade off, performance-wise, but rarely matters for 8-bit CPU's (where you would usually use an opcode table over an instruction decoder).

pvinis|8 years ago

A very nice idea. I did one for this dcpu or something like that, from a potential game from Notch (Minecraft guy).

More people should do projects like these, because many many people enjoy looking at them and studying them and contribute to them :D.

andrewmcwatters|8 years ago

I'm impressed! Very clean code. I had no idea a Game Boy emulator could be expressed so simply. Thanks for sharing this, sacert.

zerr|8 years ago

Nice. Please share if this or any other of your repos help(ed) with finding new gigs/clients.

sacert|8 years ago

I personally just code for self interest and enjoy a challenge since my job is rather stale. I can't speak from experience but I'm sure having a portfolio relevant to the type of work you're aiming for would impress potential clients and enhance corresponding skills.

nukeop|8 years ago

I assure you having even a few hobby projects to show to potential employers is always beneficial. When you can talk about actual code you've written, often you don't even have to do any tests and the usual questions about the basics are skipped completely.

vinn124|8 years ago

what a lovely project - thank you for sharing