- The PPU (Picture Processing Unit) and the CPU (Central Processing Unit) in the Gameboy DMG do not run at the same clock. The CPU runs at 4.194304 MHz, while the PPU runs at approximately 5.37 MHz (4.194304 MHz * 1.28). The PPU is asynchronous and does not wait for the CPU to finish its instruction before executing. Instead, it has its own internal clock and operates independently of the CPU.
- During each cycle, the PPU performs several operations related to rendering the video output. It does not render a complete frame in one cycle, as rendering a frame takes multiple cycles. Here is a high-level overview of what the PPU does during each cycle:
a. Fetches and decodes a tile from the background or window tile map, depending on the current scanline and whether the window is enabled.
b. Fetches the corresponding tile data from the background or window pattern table in VRAM.
c. Fetches and decodes a sprite from OAM (Object Attribute Memory), if there are any sprites to be rendered on the current scanline and they have not yet been processed.
d. Performs sprite and background priority checks, as well as sprite-sprite and sprite-background collision checks.
e. Applies the appropriate palette data to the background, window, and sprite pixels.
f. Combines the processed background, window, and sprite pixels to form the final output pixel.
A single scanline is rendered in approximately 456 PPU cycles (228 cycles for odd lines and 227 cycles for even lines). The entire frame is rendered in approximately 70,224 PPU cycles (456 cycles/line * 153 lines/frame + 10 lines of vertical blanking). Note that these numbers reflect the PPU's operation in double-speed mode; when the Gameboy DMG is running in single-speed mode, the PPU cycles take twice as long.