# 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.

![](/files/E03wR1aetUu3dOu4TfaK)

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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aeriform.gitbook.io/minicube64/pixels.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
