From 36219a03aaed16b3f468357160fae4b67df66e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikolas=20H=C3=A4m=C3=A4l=C3=A4inen?= Date: Sun, 25 Oct 2026 13:39:38 +0200 Subject: [PATCH 1/5] docs(spec): add virtual segment incbin carve-out specification --- VIRTUAL_SEGMENTS_SPEC.md | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 VIRTUAL_SEGMENTS_SPEC.md diff --git a/VIRTUAL_SEGMENTS_SPEC.md b/VIRTUAL_SEGMENTS_SPEC.md new file mode 100644 index 0000000..0b3cc20 --- /dev/null +++ b/VIRTUAL_SEGMENTS_SPEC.md @@ -0,0 +1,67 @@ +# Specification: Virtual Segment Carve-Outs (`incbin` + Label + Block Comment) + +## 1. Core Principles & Invariants + +1. **Unified `incbin` Mechanism (Editor Selection & Asset Viewers):** + - Any contiguous block of memory `[Start, End)` can be carved out as a Virtual Segment (`incbin`) through a single shared [`CarveRange`](file:///home/mikolas/src/hunks/internal/tui/actions.go#L148-L223) workflow: + - **In the Disassembly Editor:** Mark the start address (`v`), move the cursor to the end address (down to the exact byte via `←`/`→`), and press **`K`** to prompt for the label name (`ModalCarveName`) and create the `incbin`. + - **In Specialized Viewers (Bitplane Viewer `B` today, Music Ripper in future):** Pressing **`K`** automatically supplies `[Start, End)` from the asset's byte span, pre-fills the `ModalCarveName` prompt with a default label (e.g. `gfx_xx[i]`), and attaches the asset's metadata as a **Block Comment** above the label. +2. **Flat Binaries Only for Asset Viewers (`!seg.IsRelocatable()`):** + - Multi-hunk AmigaOS executables already partition code and data into hunks (`hunk0..hunkN`) and enforce relocation/even-alignment guards. +3. **Immutable Segment Ground Truth:** + - The underlying segment binary is **never** physically split, truncated, or modified on disk. +4. **Zero New Schema — Built on Existing Primitives (`CellIncbin` + `Label` + `BlockComment`):** + - Every carved-out virtual segment is represented at `startAddr` by: + 1. **`db.CellIncbin`** (`Confidence = 255`, `Size = endAddr - startAddr`) + `project.Carve` (`File: "assets/