phiGB: My Gameboy tool suite/emulator

So as I mentioned in the MBT thread, I’ve accidentally started working on a Gameboy emulator. Since I seem to actually be motivated to work on it, I figured I’d start this thread.

For now, I’m still working on whatever static analysis of ROMs I can do, mostly the ROM header. I’ve covered parsing out pretty much everything into a usable (to me) format, most recently the cartridge type, and decoding/encoding the 64x8 logo before that. Currently at ~1500 lines of code+comments.

I did not know cartridges came with their own RAM, or that they commonly switched between multiple ROM banks to get around the fact that the Gameboy only has a 16-bit address space. Or that the GB CPU can’t even do multiplication. Honestly, sick stuff all around.

So yeah, the Master Plan rn is as follows:

  • finish procrastinating with the header stuff (ie. some more polish there or w/e);
  • get started on the assembler, invent my own assembler format so that I can get started creating ROMs and run them on other, pre-existing emulators first;
  • get started on the actual emulator myself.

I’ll probably publish the code once I hit the “compiled my first ROM” milestone, it won’t be particularly interesting before then.

3 Likes

Just so the thread isn’t a wall of text with nothing, here’s the Nintendo logo parsed out of the header of a (legally- and manually-dumped) Pokemon Red ROM:

3 Likes

Yeah I’ve always heard that Z80 assembly is fucked and this is a good example of how

1 Like

Didn’t get much time to do work on this today, and rn I wanna relax, but I did manage to at least implement the lexer for my assembler:

Lexing is relatively trivial, but it’s nice to finish a concrete thing in a session, and I’m unlikely to go back and tinker with this either, because it’s just… finished. Maybe eventually I’ll want to track position within the input text for each token, but that’s out of scope for “just a lexer that works” for now.

I meant to ask. Why are you making a GB emulator instead of just using one of the many floating around?

Because writing it is the goal, rather than using one!

It’ll eventually get me to touch a lot of areas I just haven’t done much with, like “how to write code to make computer do sound”.

Basically, Gameboy is in that sweet spot of project size where it’s feasible to do everything yourself, so I want to.

1 Like