64kramsystem / 64kramsystem/ghidra-vice-connector

Screen display capture from VICE (BMP 0x84)

Abierto
#23 0 comentarios 0 reacciones 0 asignados Ver en GitHub
priority: medium
Lenguaje dominante
Python
Estrellas
1
Forks
0
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## Summary

Fetch the current rendered screen buffer from VICE and save it as a PNG. Seeing what the game is drawing at a given breakpoint is essential context for understanding graphics routines, raster effects, and sprite multiplexers.

Source: RetroDebugger (VIC Display window), VICE BMP `Display Get` (0x84).

---

## BMP protocol details

**Command:** `CMD_DISPLAY_GET = 0x84`

**Request payload:**
```
use_vic_ii (1) — 1 = VIC-II display, 0 = VDC (C128 only); always 1 for C64
image_format (1) — 0 = indexed (8-bit palette), 1 = RGB (24-bit)
```

**Response body (`RESP_DISPLAY_GET = 0x84`):**
```
display_w (4 LE) — full display width in pixels (incl. border)
display_h (4 LE) — full display height
inner_x (4 LE) — X offset of the inner (non-border) screen
inner_y (4 LE) — Y offset of the inner screen
inner_w (4 LE) — inner screen width (typically 320 or 160)
inner_h (4 LE) — inner screen height (typically 200)
bpp (1) — bits per pixel (8 for indexed, 24 for RGB)
pixel_data (display_w * display_h * bpp/8 bytes)
```

For indexed mode, follow up with `CMD_PALETTE_GET = 0x91`:
**Response:** `count (2 LE)` then `count × 3` bytes (R, G, B per entry).

---

## Implementation plan

### 1. `util.py`

```python
CMD_DISPLAY_GET = 0x84
CMD_PALETTE_GET = 0x91
RESP_DISPLAY_GET = 0x84
RESP_PALETTE_GET = 0x91

def display_get(self, rgb: bool = True) -> dict:
payload = struct.pack(' list[tuple[int,int,int]]:
_, body = self._command(CMD_PALETTE_GET)
count = struct.unpack_from('I', len(data)) + tag + data + s.pack('>I', c)
raw = b''.join(b'\x00' + img['data'][y*w*3:(y+1)*w*3] for y in range(h))
body = (b'\x89PNG\r\n\x1a\n'
+ png_chunk(b'IHDR', s.pack('>IIBBBBB', w, h, 8, 2, 0, 0, 0))
+ png_chunk(b'IDAT', zlib.compress(raw))
+ png_chunk(b'IEND', b''))
out = pathlib.Path('/tmp/vice_screenshot.png')
out.write_bytes(body)
log.info(f'Screenshot saved to {out}')
```

No external image library needed — the stdlib `zlib` approach works for raw RGB PNG.

---

## Files to change

- `src/main/py/src/vice/util.py` — add `CMD_DISPLAY_GET`, `CMD_PALETTE_GET`, `display_get()`, `palette_get()`
- `src/main/py/src/vice/methods.py` — add `save_screenshot` method

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.