LIB2 / FILE VIEW

VT22_SOURCE_API.md

DOWNLOAD ORIGINAL ↓

# VT22 — lib-set-01 source candidate API (not accepted)

2026-10-31 · owner approval and native HD61/emulator qualification PENDING.

## Ownership and provenance

This is one **provisional** `lib-set-01` VT22 generation reconciling:

- Chapter 01 VT21 r021 / the RS232C-derived `vt21_core.inc` + `vt22.inc` integration candidate, preserving its `:t` SEND event 8, `c` COMM event 9, and inherited commands.
- The MathROM Phase II `vt22.s` candidate, whose private `V22_*` state avoids VT20 aliases and introduced caller-selected `OPEN_AT` focus.

The new code is kept temporarily as `vt22_candidate.inc` so the existing RS232C test ROM using the *previous paired includes* remains source-compatible. Do not include `vt21_core.inc` or the previous short `vt22.inc` with this candidate; select exactly one generation per ROM. Following acceptance, migration of old test consumers and an owner-approved canonical filename/release are separate actions. The source is NOT an accepted `stable/r012a` component.

## Public ABI — PB-2000C only for this qualification

| Entry | Input | Behavior |
|---|---|---|
| `VT22_BIND_RAM` | `$10/$11`: pointer to caller-owned, writable 1920-byte RAM canvas | Binds only; never clears |
| `VT22_BIND_RO` | `$10/$11`: read-only RAM document base | Binds only; never clears; shortened from historical 16-character `VT21_BIND_RAM_RO` |
| `VT22_BIND_ROM` | `$10/$11`: ROM document base | Binds, does not copy |
| `VT22_CLEAR` | bound writable document | Space-fills all 1920 bytes; `$0=0` success, 1 refusal |
| `VT22_WRITE` | `$8` row 1..24, `$9` col 1..80, `$10/$11` source; `$12` source type 0 ROM/1 RAM; `$13` length | Bounded document write, `$0=0` complete, 1 truncated/invalid/refused (as inherited; owner qualification open) |
| `VT22_VIEW` | document already bound | Starts selection/viewport at line 1, column 1 |
| `VT22_OPEN` | document bound, caller has retained VT22 state | Reopen preserving selection, viewport and horizontal offset |
| `VT22_OPEN_AT` | `$8`: focus line 1..24, document bound | New opt-in entry; selected focus line shown at bottom of 4-line LCD if possible, horizontal offset reset to col 1; invalid 0/25+ returns **`$0=10`**, no display and no viewport mutation |

`OPEN_AT` formula: `top=max(1,focus-3)`; focus=1/3 => rows 1..4, 20 => 17..20, 24 => 21..24. The MathROM derivative erroneously subtracted both 4 and 3 for lines >=4; the reconciled source recalculates focus before subtracting 3. This must be verified by native tests, not simply inferred from comments.

### Semantic events returned in `$0`

| Event | Trigger | Caller response |
|---|---|---|
| 0 / 1 / 2 | Q / MENU / BRK | Exit navigation |
| 3 / 4 / 5 / 6 / 7 | EXE / `:c` / `:h` / `:v` / `:e` | Existing VT21 caller-defined events, subject to document mutability guards |
| **8** | `:t` / `:T` | SEND: **caller** decides transport, not the viewer |
| **9** | plain `c` / `C` | COMM: caller optional configuration UI |
| **10** | `VT22_OPEN_AT` invalid line | Invalid argument; never interpreted as SEND/COMM |

Plain `t`/`T` remains top navigation and `s`/`S` displays status; `:s` remains status. `:c` is *not* COMM. No implicit transfer upon entering/exiting viewer, or merely navigating. `:t` exits the viewer with event 8, with cursor stopped; consumer can transport and then call `VT22_OPEN` to resume without resetting the document or the viewport. All UART/baud/CRLF/EOF policies are **outside** VT22.

### Resource and integration contract

- One **80×24 = 1920-byte** caller-owned document; no hidden tape/history manager.
- VT22 private UA14 state: `2F68..2F6F` and `2FA0..2FA2`; shared SYS540 cursor services are independently owned at `2F20..2F2B`. The previous `V20_*` scratch borrow is eliminated.
- Requires K540 keyboard, SYS540 cursor, platform LCD services and a valid owner startup/stack, registers `$SX=0`, `$SY=1`, `UA=14h` for RAM access. Final calling/clobber details require HD61 emulator inspection.
- Source uses `VT22_*` public labels and `V22_*` private labels; all newly authored labels fit 15 characters. `VT21_*` and `V20_*` are not providers or dependencies.
- A public namespace is insufficient for acceptance: full include graph, bank-aware RAM, ROM `ORG` layout, actual emulator behavior, test receipts, and owner approval remain mandatory.

## Client migration and release boundary

Chapter 01 VT21 and its accepted behavior remain immutable. Native compilation of RS232C's old `vt21_core.inc` + `vt22.inc` pair remains a separate, currently non-promoted intake. The new test client imports **only `vt22_candidate.inc`** and explicitly handles SEND/COMM. Source compatibility requires changing old entry names (`VT21_*` -> `VT22_*`, `VT21_BIND_RAM_RO` -> `VT22_BIND_RO`) and reviewing memory ownership. No automatic alias is exported because an alias would risk mixing namespaces and exceed the new 15-character naming discipline.

The working release must not be promoted until the owner observes default/focus/invalid/event/return behavior and verifies actual received serial bytes against the pinned fixture. No AI-1000 or physical FA-7 acceptance is claimed.