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.
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.
Show HN: Simple Gameboy Emulator
11–20 of 24 posts
Re: Show HN: Simple Gameboy Emulator
#12Great! The CPU.c code is quite instructive since I'm writing a toy VM in my free time. Starring this :)
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 point…
You can see that in octal, 1xx are all moves while 2xx is all ALU ops.
Re: Show HN: Simple Gameboy Emulator
#13Re: Show HN: Simple Gameboy Emulator
#14Earlier quoted context omitted.
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 point…
The Gameboy CPU shares the same octal-structured opcode format as the Z80 from which it was derived, so it is possible to decode it even more concisely: http://www.z80.info/decoding.htm You can see that in octal, 1xx are all moves while 2xx is all ALU ops.
My rust-based GB emulator uses a decoder based on those very docs, in fact. Though, modified slightly since the GB's CPU only supports the CB-extended range operations.
Re: Show HN: Simple Gameboy Emulator
#15Re: Show HN: Simple Gameboy Emulator
#16I love projects like these. Code looks very clear and organized. How long have you been working on it?
Re: Show HN: Simple Gameboy Emulator
#17Nice. Please share if this or any other of your repos help(ed) with finding new gigs/clients.
Re: Show HN: Simple Gameboy Emulator
#18More people should do projects like these, because many many people enjoy looking at them and studying them and contribute to them :D.
Re: Show HN: Simple Gameboy Emulator
#19Nice. Please share if this or any other of your repos help(ed) with finding new gigs/clients.
Re: Show HN: Simple Gameboy Emulator
#20Great! The CPU.c code is quite instructive since I'm writing a toy VM in my free time. Starring this :)
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 point…
Here's what such a code-generated instruction decoder looks like: https://github.com/floooh/chips/blob/master/chips/_z80_decod... (this is for a "real" Z80 with all undocumented opcodes, so it has a lot more cases to handle than the simple Gameboy Z80 variant).