0dmg

Learning Rust by building a partial Game Boy emulator.

This project is maintained by jeremyBanks

I have hit a threshold of basic understanding of the Game Boy and Rust now, and feel confident enough to try to refactor my spagetti soup into something sensible, if not idiomatic.

GameBoy { CPU, MemoryController, VideoController, AudioContoller, … }

The components will still be more tightly coupled than they should be, but at least things like the (hypothetical) AudioController should be standalone.

I was starting to feel really good about potential performance, with one major exception: generating the log messages for each opcode would be a lot of overhead, way more than the operations themselves.

But it looks like defining a macro to exclude my logging from compilation in optimized builds won’t be too hard. The code may just be something like this:

macro_rules! log_unless_optimized {
    ($($arg:tt)*) => (if cfg!(debug_assertions) { Some($($arg)*) } else { None })
}

Which I apply to my logging expressions like this:

log_unless_optimized!(format!("..."), format!("..."))

Hey, I did that. It works!

I think I’m still failing to set the appropriate flag bits on a bunch of operations. The half-carry bit seems like a wierd implementation detail; I wonder if anything really depends on it.