Skip to content
Shane DeSeranno edited this page Nov 4, 2015 · 12 revisions

Go Home

Part 12 - GPU

This is a huge can of worms. But at the end of the day, the entire purpose of this device is to arrange bytes into a picture. We are only implementing the classic Gameboy (no color). This makes our job a bit easier.

The Control Register (0xFF40)

This register is used to control the LCD screen.

Bit 7: LCD Display Enable             (0=Off, 1=On)
Bit 6: Window Tile Map Display Select (0=0x9800-0x9BFF, 1=0x9C00-0x9FFF)
Bit 5: Window Display Enable          (0=Off, 1=On)
Bit 4: BG & Window Tile Data Select   (0=0x8800-0x97FF, 1=0x8000-0x8FFF)
Bit 3: BG Tile Map Display Select     (0=0x9800-0x9BFF, 1=0x9C00-0x9FFF)
Bit 2: OBJ (Sprite) Size              (0=8x8, 1=8x16)
Bit 1: OBJ (Sprite) Display Enable    (0=Off, 1=On)
Bit 0: BG Display                     (0=Off, 1=On)

For example, during the boot sequence:

LD A, $91           ; $005b
LD ($FF00+$40), A   ; $005d  Turn on LCD, showing Background

This loads 0x91 into the 0xFF40 control register. This is 1001 0001 in binary. So bit 7, 4, and 0 are set to 1. Everything else is 0. This performs all of these actions:

  • Turns on the LCD display
  • Selects 0x9800-0x9BFF as the tile map
  • Disables window display
  • Selects 0x8000-0x8FFF for the BG & Window tile data
  • Selects 0x9800-0x9BFF for the BG tile map data
  • Sets OBJ size to 8x8
  • Disables OBJ display
  • Enables BG display

LCD Status Register (0xFF41)

This register query for a variety of LCD statuses. The bits are:

Bit 6: LYC=LY Coincidence Interrupt (1=Enable) (Read/Write)
Bit 5: Mode 2 OAM Interrupt         (1=Enable) (Read/Write)
Bit 4: Mode 1 V-Blank Interrupt     (1=Enable) (Read/Write)
Bit 3: Mode 0 H-Blank Interrupt     (1=Enable) (Read/Write)
Bit 2: Coincidence Flag  (0:LYC<>LY, 1:LYC=LY) (Read Only)
Bit 1-0: Mode Flag       (Mode 0-3, see below) (Read Only)
        0: During H-Blank
        1: During V-Blank
        2: During Searching OAM-RAM
        3: During Transfering Data to LCD Driver

Bit 6 is used to enable a CPU interrupt when the LCD screen is redrawing a specific line (LY=0xFF44) and the game can specify the line with the LYC register (0xFF45). Bit 2 will be enabled when LYC=LY and disabled otherwise. Bit 1/0 indicate the current mode the LCD device is in. More details on the LCD status can be found here.

Clone this wiki locally