liveBook · Manning

CHIP-8 display

As explained in Systems Programming with Zig

The CHIP-8 display is a two-dimensional output surface whose pixels represent the virtual machine's visual screen state.

A CHIP-8 display is a 64-by-32 black-and-white grid. Represent its pixels as a two-dimensional array of single-bit values, wrapped in a struct with a method to clear the screen. section 6.3.2

Listing 6.4 Structuring input and output
pub const Display = struct {
    pixels: [32][64]u1, #1

    pub fn clear(display: *Display) void {
        @memset(&display.pixels, [1]u1{0} ** 64); #2
    }
};

pub const Keypad = struct {
    keys: [16]bool, #3
};

The Display struct stores 32 rows of 64 pixels and clears them by filling the array with zeroes. section 6.3.2

Display instructions change this stored state: 00E0 clears it, while DXYN draws a sprite by XORing its bits with pixels starting at coordinates in registers X and Y. Out-of-bounds pixels are ignored. section 6.5.7

How Systems Programming with Zig covers it

How deep it goes
Defines the pixel array and clearing operation, then describes sprite drawing and out-of-bounds handling.
Examples
Uses a 64-by-32 one-bit pixel grid, zero-filling to clear it, and XOR-based sprite drawing.
What you can do after
Build a display structure that clears its pixels and supports CHIP-8 drawing and clear instructions.
How it connects
Connects display state to CHIP-8 instructions, registers, memory, and keypad input.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.