# Inside DVD-Video/Interaction Machine

DVD-Video specifies a low-level machine-language instruction set that is used to define interactions with the user. Instruction sequences are invoked when the user selects an on-screen button, and may also be triggered at various other points, such as the end of a cell or a PGC, or when the disc is inserted into the player.
The instruction set is commonly referred to as the “VM” (Virtual Machine) language, but the implication of calling it “virtual” is that there cannot be real hardware that directly implements this instruction set. But why not? That’s why I am here using the term “interaction machine”, which makes it clearer what the purpose of the instruction set is.
(Note that I’m avoiding using the term “program” for sequences of instructions in this instruction set, because that already has a completely different meaning in DVD-Video.)

## Basic Concepts
### Data Model

The only available data storage consists of 16 general-purpose parameter registers (GPRMs) and 24 system parameter registers (SPRMs). Each holds a single 16-bit unsigned integer value. As their name indicates, GPRMs may be freely used for any purpose, while the SPRMs have predefined meanings.
Any GPRM may also be put into counter mode, where its value increments once per second.

### Instruction Format

Each instruction is 8 bytes, and can encode up to 3 separate operations, up to one from each of the following categories:
* Setting a register
* Transferring control
* Performing a comparison, the result of which is used to control conditional execution of the rest of the instruction.
The top three bits of the first byte define the instruction group, as follows:
* Group 0: miscellaneous (including transfer of control within an instruction sequence). These can also be made conditional according to format 1 (below).
* Group 1: Link/Jump/Call: transfer of control between parts of the video stream. The Link instructions can be made conditional according to format 1, while Jump and Call use conditional format 2.
* Group 2: set SPRM. This also includes the instructions for setting GPRMs in counter mode. These can be made conditional according to format 2, or combined with a Link, but not both at once.
* Group 3: set GPRM. These can be made conditional according to format 3, or combined with a Link, but not both at once.
Groups 4, 5 and 6 perform a set GPRM, comparison and a link, all in one instruction, but with the three operations interacting as follows:
* Group 4: perform the set, perform the comparison, and conditionally link.
* Group 5: perform the comparison, and conditionally set and link.
* Group 6: perform the comparison, and conditionally perform the set. Always link.
Group 7 does not seem to be used.
Register numbering: fields for reading the value of a register are 8 bits wide, and can access both GPRMs and SPRMs. Bit 7 is 0 to indicate a GPRM access, 1 for an SPRM access. The actual register number is in the rest of the bits.
Literal operands: some instruction forms allow for a 16-bit literal operand value within the instruction. This is always stored in big-endian order, i.e. most significant byte first.
Interaction instructions can be found in the following places:
* a cell can end with a single instruction to be executed when the cell has finished playing.
* a button specifies a single instruction to be executed when the button is selected.
* the pre- and post-sections of a PGC can each contain a sequence of instructions, to be executed before the PGC starts playing and after it finishes, respectively.
* the FPC contains a sequence of instructions which automatically start executing when the disc is inserted into the player.
The single-instruction limitation on buttons is not a big issue in practice; it’s easy enough for the single instruction to be “set GPRM i to j and link to post-section of PGC”, to execute a longer sequence of instructions in the PGC post-section that does different things for different buttons, based on the value of GPRM i.

### System Parameter Registers

In the following table, “writable” indicates whether there is an instruction for explicitly writing into that register. Non-writable registers may be implicitly altered via control-transfer instructions or automatically as playback progresses (these can change the current title/PGC/chapter), or explicitly by the user via some device-provided interface (e.g. preferred video and language settings), or may be readonly (e.g. player audio capabilities, region mask).
ISO-639 language codes and ISO-3166 country codes are represented as integers with the first character in the high byte and the second character in the low byte.
| Number | Name | Meaning | Writable |
| 0 | | preferred menu language, ISO-639 code | N |
| 1 | ASTN | audio stream number 0-7, or 15 meaning none | Y |
| 2 | SPSTN | subpicture stream number in bits 0-5, bit 6 must also be set to display. Normal stream numbers are 0-31, but special value 62 means “none” and 63 means “forced” (needed for menus). | Y |
| 3 | AGLN | angle number, 1-9 | Y |
| 4 | TTN | title number over entire disc, 1-99 | N |
| 5 | VTS_TTN | title number within titleset, 1-99 | N |
| 6 | TT_PGCN | PGC number, 1-32767 | N |
| 7 | PTTN | chapter (PTT) number, 1-99 | N |
| 8 | HL_BTNN | highlight button number × 1024. Thus, valid values are 0 (no button highlight), 1024 (highlight button 1), 2048 (highlight button 2) .. 36864 (highlight button 36) | Y |
| 9 | NVTMR | navigation timer in seconds, 0-65535 | Y |
| 10 | NV_PGCN | PGC number to jump to when navigation timer expires, 1-32767, must be in current title | Y |
| 11 | AMXMD | karaoke audio channel mixing mode: 15-131211109-54321-0  4 → 03 → 02 → 0 4 → 13 → 12 → 1 | Y |
| 12 | CC_PLT | parental management ISO-3166 country code | N |
| 13 | PLT | parental management level, 1-8, or 15 for none | Y |
| 14 | | video preference and current mode 15-1211-109-87-0  preferred display ratio: 0 = 4:3, 1 = not specified, 3 = 16:9current video mode: 0 = normal, 1 = pan&scan, 2 = letterbox | N |
| 15 | | player audio capabilities 1514131211109-87654321-0  Dolby MPEGDTSSDDS PCM karaokeDolby karaoke MPEG karaokeDTS karaokeSDDS karaoke | N |
| 16 | | preferred audio language, ISO-639 code | N |
| 17 | | preferred audio language extension CodeMeaning 0not specified 1normal 2for visually impaired 3director’s comments 4alternate director’s comments | N |
| 18 | | preferred subpicture language, ISO-639 code | N |
| 19 | | preferred subpicture language extension CodeMeaning 0not specified 1normal 2large 3children 5normal captions 6large captions 7children’s captions 9forced 13director’s comments 14large director’s comments 15director’s comments for children | N |
| 20 | | player region code mask 15-876543210  region 8region 7region 6region 5region 4region 3region 2region 1 | N |
| 21-23 | Reserved | Reserved | Reserved |
(SPRM listing comes from here)

### Link Versus Jump Versus Call

The instructions for diverting the flow of playback are divided into Link, Jump and Call categories. Link instructions allow for transfers within a PGC/title/domain, or to a fixed set of related PGCs (“next”, “previous” and “up”), while Jump and Call allow for more wide-ranging transfers across domains, menus, titles and chapters. Titles and chapters may be entered via Jump instructions, while menus (and the FPC) may be entered via Jump or Call instructions. The Jump-to-menu and Call-to-menu sets support the same set of possible transfers, except that Jump-to-menu instructions are only allowed within menus, while the Call-to-menu equivalents are only allowed within titles.
Call instructions perform the same action as their Jump equivalents, except they also save a playback point for later resumption. (This can be the current playback point, or another point explicitly specified in the instruction.) Only a single resume point can be saved: the “resume stack” (if you can call it that) is only a single element deep.
Thus, the resume point from a Call is always within a title, never a menu. The model is that invoking a menu involves temporarily suspending the playback of a title, which can be resumed when the menu is dismissed (unless a menu option starts playback somewhere else).
Allowable transfers using Jump or Call:
| $_{from}$\to | FPC | VMG | VTSM | VTST |
| FPC | | JumpSS | JumpSS | JumpTT |
| VMG | JumpSS | JumpSS | JumpSS | JumpTT |
| VTSM | JumpSS | JumpSS | JumpSS (same titleset only) | JumpVTS_TT, JumpVTS_PTT (same titleset only) |
| VTST | CallSS | CallSS | CallSS (same titleset only) | JumpVTS_TT, JumpVTS_PTT (same titleset only) |
Note that, from a VTS (menu or title), it is not permitted to jump directly into another VTS. You have to set up indirect jumps via the VMG.
The RSM command in the Link Subset (see below) resumes playback from the last-saved resume point. The Return button on the remote does the same thing.

### Conditional Formats

Every instruction can be made conditional, where a comparison is made between two operands, and execution of the rest of the instruction depends on whether the comparison evaluates to true or not.
The layout of the conditional fields can vary between instruction groups. In the following instruction formats, the dots represent bits encoded as per the unconditional form of the instruction. The 3-bit cmp field indicates the comparison operator to be applied on the two operands:
| Code | Meaning |
| 0 | always true (unconditional form of instruction) |
| 1 | BC (“&”, true iff logical-and of operands is nonzero) |
| 2 | = |
| 3 | ≠ |
| 4 | ≥ |
| 5 | > |
| 6 | ≤ |
| 7 | < |
These particular formats are usable with instructions in groups 0, 1, 2, 3. Instructions in groups 4, 5 and 6 use the same cmp codes, but have their own arrangements for the comparison operands. Though note that the cmp field (and immediate flag for comparison operand 2) is in the same place for all instructions.

#### Format 1

This form allows for comparison between two registers, or between a register and a 16-bit literal value.
| 0 | 1:7 | 1:6-4 | 1:3-0 | 2 | 3 | 4 | 5 | 6 | 7 |
| ........ | 0 | cmp | .... | | creg1 | | creg2 | ........ | ........ |
| ........ | 1 | cmp | .... | | creg1 | cimmed2 | cimmed2 | ........ | ........ |

#### Format 2

This form allows only for comparison between two registers.
| 0 | 1:7 | 1:6-4 | 1:3-0 | 2 | 3 | 4 | 5 | 6 | 7 |
| ........ | | cmp | .... | ........ | ........ | ........ | ........ | creg1 | creg2 |

#### Format 3

This form allows for comparison between two registers, or between a register and a 16-bit literal value.
| 0 | 1:7 | 1:6-4 | 1:3-0 | 2 | 3 | 4 | 5 | 6 | 7 |
| ........ | 0 | cmp | .... | creg1 | ........ | ........ | ........ | | creg2 |
| ........ | 1 | cmp | .... | creg1 | ........ | ........ | ........ | cimmed2 | cimmed2 |

### Set-Operations

Instructions that assign a new value to a GPRM have an op field and a source-operand field (specifying either a register or a literal value). The new value for the destination is computed as a function of its existing value, the source operand, and the op. Furthermore, the swap operation alters the source as well (the others do not). Valid values of op (and corresponding restrictions on the source operand) are as follows:
| op | operation | Allowable source | Allowable source | Allowable source |
| op | operation | literal | GPRM | SPRM |
| 0 | no operation; reg unchanged | Y | Y | Y |
| 1 | straight assignment; reg := source | Y | Y | Y |
| 2 | swap values of reg and source | N | Y | N |
| 3 | add source to reg | Y | Y | N |
| 4 | subtract source from reg | Y | Y | N |
| 5 | multiply reg by source | Y | Y | N |
| 6 | divide reg by source | Y | Y | N |
| 7 | set reg to remainder on integer division by source | Y | Y | N |
| 8 | set reg to a random integer in [1 .. source] | Y | Y | N |
| 9 | bitwise-and source and reg | Y | Y | Y |
| 10 | bitwise-or source and reg | Y | Y | Y |
| 11 | bitwise-xor source and reg | Y | Y | Y |

## Instruction Set Details

See the next page.