That was a pleasure to read through. Made me think of literate code.
Here's a sample from the file:
// For sprites, color 0 is transparency so don't draw anything.
if color == 0 {
continue;
}
This comment is probably not necessary: it would be equally clear if it were written as something like the following: if color == SPRITE_COLOR_TRANSPARENT {
continue;
}
A few lines up is another comment: // Is this specific pixel not on the screen? We already check that x_pos is not off
// the left side earlier, so only need to check that it's not off the right side.
if x_pos + p >= 160 {
continue;
}
If the code were written with a constant, then it would only need to clarify why we don't check the left side here (the only non-obvious thing about the code), so: // Note: bounds testing on the left side is handled earlier
if x_pos + p >= SCREEN_WIDTH {
continue;
}
One last example: // We want to iterate through 160 pixels to draw one scanline.
for col in 0..160u8 {
No comment, similar level of readability: for col in ppu.iterscanlines() {Quite a difference in code readability to the point where the code becomes self-evident. Few people are able to reach a more verbose level of documentation, let alone make sure the code remains understandeable in the future.