Skip to content
Display: DRW Instruction
step 1/5

Reading — step 1 of 5

Read

~1 min readDisplay & Input

Display: DRW Instruction

DXYN: draw N-byte sprite from memory[I..I+N] at coordinates (VX, VY). Each byte = 8 horizontal pixels (1 row).

Pixels XOR with existing display. If any pixel goes from 1 to 0 (collision), VF = 1, else 0.

Display: 64x32 monochrome bitmap. Each cell is 0 (off) or 1 (on).

python

Wrapping: position wraps around the screen edges (modulo 64 / 32). Some emulators clip instead.

Sprites are typically 4-15 pixels tall, 8 wide. Stored as bytes:

byte 0: 0xF0   ████.... (top row)
byte 1: 0x90   █..█....
byte 2: 0x90   █..█....
byte 3: 0xF0   ████....

Drawing the digit "0" (5 rows tall): see the FONT at the start.

XOR semantics:

  • Drawing twice in same place erases (XOR with 1 = flip).
  • Useful for moving sprites: erase old, draw new.
  • Collision detection: VF gets set if any pixel changed from on to off.
  • Games use VF for hit detection.

Display refresh:

  • Real CHIP-8 displays every frame (60 Hz).
  • Emulator can buffer + present; or per-DRW immediate display (causes flicker, accurate to original).

Modern emulators sometimes interpret DRW as setting display dirty flag, then flush at 60 Hz.

Common bug: not handling wrap. Sprites at edge of screen disappear.

CLS (00E0): clear all display pixels to 0.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…