64kramsystem / 64kramsystem/ghidra-vice-connector

Screen display capture from VICE (BMP 0x84)

未關閉
#23 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
priority: medium
主要語言
Python
星號
1
分支
0
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。