# VT27 — HD61700 virtual terminal API / ABI contract

**Member:** `lib-set-01/src/lib2/vt/27/`. **Origin:** Chapter 01 v2b donor, exact unmodified three-file source. **Status:** accepted donor-adopted member with bounded PB-2000C emulator evidence. **Contract authority:** inspected source; names in this manual do not promise untested independent integrations.  
**Source closure:** `vt27.inc` + `vt26_lcd.inc` + `export.inc`, caller-owned platform/keyboard/RAM/transport dependencies. This is not an application ROM.

## 1. Scope and entry points

VT27 is a **non-reentrant**, stateful 24-row x 80-column text viewer for a 4-row x 32-column PB-2000C LCD. Its own command loop does not own a UART, calculator, tape records, ROM images or a global menu. Client application supplies and processes documents and semantic events.

Declared public entry labels: `VT_BIND_RAM`, `VT_BIND_RO`, `VT_BIND_ROM`, `VT_BIND_RSEL`, `VT_GET_CHAR`, `VT_CLEAR`, `VT_WRITE`, `VT_INIT`, `VT_CONFIG`, `VT_VIEW`, `VT_OPEN`, `VT_OPEN_AT`, `VT_TX_ERROR`, `VT_EXPORT`, and companion renderer helpers `VT26_PUTC`, `VT26_LCD_PUTZ`, `VT26_LCD_ROM32`, `VT26_GFX_PUTC`. Internal labels with `_VT*` prefixes are **not** public contracts. `VT_EXPORT` is implemented in `export.inc`, not `vt27.inc`.

## 2. Method matrix

| Entry | Required inputs | Output / effect |
|---|---|---|
| `VT_BIND_RAM` | `$10/$11`: accessible 1,920-byte document base | Set kind 0, writable RAM; reset inverse on fresh bind; clobbers `$0`, `IX` (see source). |
| `VT_BIND_RO` | `$10/$11`: readable RAM document base | Set kind 2, read-only RAM; reset inverse. |
| `VT_BIND_ROM` | `$10/$11`: readable ROM document base | Set kind 1, read-only ROM; reset inverse. |
| `VT_BIND_RSEL` | `$10/$11`: ROM document base | Set kind 3, selectable-ROM view; **not separately donor-tested**. |
| `VT_VIEW` | Bound document and caller state | New view beginning at row 1, col 1; returns `$0` viewer event. |
| `VT_OPEN` | Already bound valid document and initialized view state | Re-enter without reinitializing the choice of inverse or viewport; returns viewer event. |
| `VT_OPEN_AT` | `$8`=requested selected row 1..24 | Set selected row/visible window and col 1; `$0=10` on invalid row without opening; valid entry returns event. |
| `VT_GET_CHAR` | `$2/$3` absolute document byte address, valid binding | `$16` byte from ROM or RAM; clobbers `$0`, `IX` or `IZ`. |
| `VT_CLEAR` | Writable RAM kind 0 | Fill exactly 1,920 bytes with ASCII spaces, `$0=0`; otherwise `$0=1` refusal. |
| `VT_WRITE` | `$8`=1-based row, `$9`=1-based column, `$10/$11` source pointer, `$12` source-kind, `$13` count | Copy/clip into writable RAM; `$0=0` accepted or `$0=1` invalid/clipped. Full generic semantics **not independently qualified**. |
| `VT_INIT` / `VT_CONFIG` | Ordinary linker environment | Both return `$0=1`; no configuration wizard is implemented. |
| `VT_TX_ERROR` | Consumer-supplied `VT_TX_DETAIL` | Delegates temporary diagnostic feedback, not a UART call. |
| `VT_EXPORT` | Valid kind 0..3; scratch and `VT_OUTBYTE`, `VT_HOST_RAM`, `VT_GET_CHAR` callbacks | 24 rows x (80 bytes + CR LF) = **1,968 bytes** into sink; `$0=0` on sink acceptance; nonzero propagates refusal/error. Transport itself is external. |
| Renderer helpers | LCD coordinates/string/character and consumer state | Draw normal or inverse glyphs; see exact source for narrower per-routine register effects. |

## 3. Calling convention and viewer events

On return from the interactive viewer, **`$0` is a semantic event, not automatically an error**:

| `$0` | Meaning | Guard and owner |
|---:|---|---|
| `0` | Q / `:q` exit | Always a viewer exit; ensure cleanup preserves event. |
| `1` | MENU exit | Caller owns next menu. |
| `2` | BRK exit | Caller owns warm-return policy. |
| `3` | EXE selected row | Allowed for writable and read-only RAM and selectable-ROM kinds; ROM kind 1 denies. |
| `4` | `:c` action request | Denied in plain ROM kind 1; interpretation belongs to caller. |
| `6` | `:v` application-specific request | ROM kind 1 denied; Chapter 01 uses register view. **Not built in**. |
| `7` | `:e` application-specific request | Writable RAM kind 0 only; Chapter 01 asks erase confirmation. **No deletion in VT27**. |
| `8` | `:t` SEND request | `VT_SEND_CAP` must approve; caller transfers the document. |
| `9` | Plain `c/C` communication event | Distinct from `:c`, application action. |
| `10` | Invalid `VT_OPEN_AT` row | Not an ordinary interactive viewer event. |

`VT_CLEAR`, `VT_WRITE` and `VT_EXPORT` have **method-specific success/error statuses**; do not confuse those with the viewer event table. The event-register preservation repair in the Chapter 01 donor uses save/restore of `$0` in `_VT26_INV_RESET`. No blanket register preservation is promised.

Navigation controls: UP/DOWN select by 1 row; `u`/`d` by 4; LEFT/RIGHT across horizontal column origins 1, 31, 49; plain `t` top; `b` bottom; `s` status. Colon commands `:h` fixed help, `:i` inverse, `:l` row jump, `:R` redraw, `:t` SEND, `:q`, `:c`, `:v`, `:e`; commands are case-insensitive. `:h` text lists `:v/:e` even in denied modes (known accepted limitation).

## 4. Environment, caller ownership and memory

The application allocates document storage of exactly **24 x 80 = 1,920 bytes**, in the appropriate ROM/RAM bank, plus **its own non-overlapping VT scratch**. Required source-visible symbols: `VT_SELECTED`, `_VT_TOP`, `_VT_LEFT`, `_VT_DPTR` (word), `_VT_DIDX`, `_VT_INVAL`, `_VT_INLEN`, `_VT_DOC_BASE` (word), `_VT_DOC_KIND`, `_VT_INV`, `_VT_LC_TICK`, `_VT_LC_VIS`; if using export, `VT_EXP_PTR` (word), `VT_EXP_COL`, `VT_EXP_ROW`. These are caller-provided **names, not fixed addresses**. The Chapter 01 bindings at UA=14h are an example, not a universal allocation.

Dependencies from source/companion modules include K540/SYS540 services, `KEY_WAIT`, `K540_RAW`, `SYS540_INIT/HIDE/TOGGLE/POLL/PLACE/SHOW/STOP`, `CUR_OFF`, `PUTC`, `LCD_*` display/graphics adapters, `BLANK32`, key symbolic constants such as `KEYLEFT`, keyboard/platform initialization and ROM/RAM bank state. The caller supplies `VT_SEND_CAP` (nonzero allows SEND), `VT_TX_DETAIL`, `VT_OUTBYTE` (input `$16` byte, return `$0` status), `VT_HOST_RAM` (restore expected host RAM bank), and suitable external transport if the application actually sends bytes. The include code has **no library-owned `ORG`**, and source symbol resolution must cover comparison operands, not just branches.

No specific `UA`, stack depth, `SX/SY`, IX/IZ or global register-preservation guarantees are established across all viewer entries. Document type kind 0 is writable RAM; 1 ROM; 2 read-only RAM; 3 selectable ROM. Physical display/fonts must be compatible with the PB-2000C donor platform. The built-in inverse renderer is credited to a DejaVu-derived bitmap table; comply with its attribution/license before public distribution.

## 5. Register effects and non-promises

Narrow source assertions: `VT_BIND_*` receives base via `$10/$11`, clobbers `$0`, `IX`; `VT_GET_CHAR` writes `$16` and clobbers `$0`, `IX` or `IZ`; `VT_OPEN_AT` consumes `$8` and returns event/status in `$0`; the export byte sink convention uses `$16` input and `$0` result. **For all other registers, IX/IZ, UA and flags across the full viewer: NOT GUARANTEED**. Callbacks can clobber caller registers. Applications must preserve any state they require, audit bank/stack, and rebuild with the actual HD61 assembler.

## 6. Errors, limits and behavioral caveats

- `VT_OPEN_AT` range 1..24; 0 or >=25 yields `$0=10`, no viewer entry.
- Clear/write operations reject read-only document kinds. `:e` only returns a request; the caller performs confirmation and deletion.
- Fresh `VT_BIND_*` resets inverse state; `VT_OPEN` intentionally preserves the current inverse choice. Other exits may clear inverse.
- Built-in three-screen `:h` text is static and advertises `:v`/`:e` even if denied; **no descriptor-driven help** or automatic permission-aware menu has been implemented.
- `:t` is a *semantic request* only. `VT_EXPORT` writes 1,968 bytes to a provided sink; proof of physical or receiver-side delivery is absent.
- Chapter 01's 22-case owner emulator evidence is a donor-program witness, **not an independent consumer matrix**. RSEL, full register/bank portability, physical machine and AI-1000 remain open.

## 7. Minimal composition example (illustrative, not drop-in)

```asm
; Include exact VT27 generation and both companion sources from lib2/vt/27.
; Supply caller-owned VT_* workspace and K540/SYS540/LCD symbols;
; provide VT_SEND_CAP, VT_TX_DETAIL, VT_OUTBYTE, VT_HOST_RAM.
        LDW     $10,MY_TAPE_BASE
        CAL     VT_BIND_RAM
        CAL     VT_VIEW        ; $0 = semantic event, not an error code
; Dispatch $0 in caller: 0=Q, 1=MENU, 2=BRK, 3=selection,
; 4=:c, 6=:v, 7=:e, 8=:t, 9=plain c.
```

The example is pseudocomposition: `MY_TAPE_BASE` is hypothetical. Register syntax and actual include layout must be checked against your assembler and platform scaffolding. It is **not a tested standalone ROM**.

## 8. Provenance, identities and qualification

| Source file | Bytes | SHA-256 |
|---|---:|---|
| `vt27.inc` | 29,899 | `3c5ba3e4eaf0cd12937e46a6608d3975478e0e88bd7884304bbdefb2b5967972` |
| `vt26_lcd.inc` | 9,809 | `c39a081cb5324359598b4c1e939fb95e7d6d7ebb2f8fd17d7f455260c09f642c` |
| `export.inc` | 1,947 | `d33eb972b2f295e4f451293eb48f5931acc2de3e8c5ef4061ca5cb8b7f9565c9` |


Donor [Chapter 01 v2b accepted source](https://drive.google.com/drive/folders/1eiYxELJRznHn0Kdc01Uhe4ghJmv-6uDH), [owner acceptance](https://drive.google.com/file/d/19R7zNFz2u886tKHORZ19mLsUqW1Zqnsn/view), [PB-2000C R004 emulator](https://drive.google.com/file/d/1ltnIZ0qfSc3Lg43O5X2tzW6DKJSnxPUC/view), [public ROM closeout](https://drive.google.com/file/d/1VV2MmTNKtz6gKBh5tJLAroQ0wIehGr4b/view), [critical curation](https://drive.google.com/file/d/1w092yY7yr4Gv3vX2NGEGSjanZkuurvKO/view). Accepted donor ROM: **65,536 bytes**, SHA-256 `61d284da31764a8334575195ca7f56f4c813a201025ee0f38d638f9782d1f479`. The library receives the source **unchanged** and inherits only the donor's tested behavior for that composition. A new consumer must independently audit assembly, RAM/bank mapping, event protocol, renderer, callbacks and observed target behavior.

**Admission is not public library release.** `lib-set-01/stable/` and public ACLs were not altered. The library's [donor policy](https://drive.google.com/file/d/1E3Q35ZOB0JpEfJyEEwY2iS7Neso_Wdzx/view) governs any subsequent consumer qualification and public packaging.

*Praeteritum ad futurum servamus.*
