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.
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:
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.