# Working with Pixels

Minicube64 uses a simple 64x64, 8 bits per pixel frame buffer. This can be any 4K page in memory, and may be changed at any time.

This makes drawing pixels to the screen very simple and easy.

## Setting the Frame Buffer

Setting the `VIDEO` register instructs to set the visible screen at a specific 4K page in memory.

The immediate value we load refers to the high-byte of the desired memory address. \
This can be any value from `$0` to `$f`. For example memory address `$f000`, we use `#$f`

```asm6502
  lda #$f
  sta VIDEO
```

{% hint style="info" %}
We can also use the macro `_setb #$f, VIDEO`
{% endhint %}

## Drawing a Pixel

The `VIDEO` buffer page is now set at `0xf000`

With our frame-buffer defined we can start to draw pixels. To do this we simply write a value directly to a memory address within the 4K page we defined.

```asm6502
  lda #63 ;white
  sta $f820
```

We load the immediate value `#63` into the Accumulator, and write (store) that value to `0xf820` which in this case is the middle of the screen.

![](https://1901532303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYlgFz1gOz3pvCbWdEb%2Fuploads%2Fq71qQuwix7Ku2hQwQJV8%2FScreenshot%202022-01-06%20at%2012.01.18.png?alt=media\&token=abd258ca-a08e-4bec-bd04-2ca02ae5229b)

You can also use in-line math functions to achieve the same result. In this case we start at the `VIDEO` page, add 32 multiplied by 64 for the Y position, and adding another 32 for the X position.

```asm6502
sta $f000+32*64+32
```

For example, this table shows what addresses correspond to each position of the screen, assuming the buffer is set to `0xf000`

| Address  | Position     |
| -------- | ------------ |
| `0xf000` | Top Left     |
| `0xf03f` | Top Right    |
| `0xf820` | Middle       |
| `0xffc0` | Bottom Left  |
| `0xffff` | Bottom Right |

## Example

This example simply draws a white pixel in the middle of the screen.

```asm6502
  org $200
  sei

  lda #63 ;white
  sta $0820

Loop:
  jmp Loop
```

