# The sample ROM: phrase table, ADPCM data, banking **DS** is OKI's data sheet ('94 data book, printed pp. 60-63; see [bus.md](bus.md)). The local numbers come from `scripts/rom_census.py` over MAME 0.285's listing; the whole census is in [census.md](census.md). ## Address space The chip drives 18 address lines, A0-A17: **256 KB** (2 Mbit), "the maximum external ROM size is 256K bytes" (DS p. 53). The DIP42 lacks A17: 128 KB ([bus.md](bus.md)). DS p. 63 maps it: addresses 0-7 "Empty", the phrase table ("address data") from 8 to at most 0x3FF, ADPCM data after it, up to 0x3FFFF. ## The phrase table (DS pp. 60, 62) Phrase *p* (1-127) has eight bytes at address **8 x p** (the first byte's bits 6-0 become address lines A3-A9; DS p. 60's table): | Offset | Byte | Bits used | | --- | --- | --- | | 0 | SA1 | bits 1-0 = A17, A16; bits 7-2 printed as 0 | | 1 | SA2 | A15-A8 | | 2 | SA3 | A7-A0 | | 3 | EA1 | bits 1-0 = A17, A16; bits 7-2 printed as 0 | | 4 | EA2 | A15-A8 | | 5 | EA3 | A7-A0 | | 6, 7 | "EMPTY" | | Big-endian, 18 bits each. "When 1 phrase is selected, address data is written from ROM address 00008h to 0000Fh, and the rest is used as the ADPCM data section" (DS p. 63): the table is only as long as the phrases a ROM uses. **What the chip does with the bits DS prints as 0** (bits 7-2 of SA1 and EA1) is not stated. MAME and libvgm (BSD-3) mask the address to 18 bits, and jt6295 drops them too. FBNeo, as read under the old rule, does not mask the start and stop it reads: it shifts the whole first byte into place and masks only the address it finally reads, so a set high bit changes FBNeo's phrase length and can make an entry invalid (C11). In the local sample ROMs 8,068 used entries in 118 of the 601 unbanked regions set such bits (most of them are not phrase tables at all; see below). **Phrase 0.** Address 0-7 is "Empty" and phrase 0 "not valid". Every implementation reads the entry at address 0 if a program asks for it (U4). In the local ROMs, 87 of 601 unbanked regions have something other than all-0 or all-FF bytes in entry 0. ## Start, end, and how many nibbles ADPCM data is two samples a byte, **high nibble (D7-D4) first**, each nibble SIGN, MSB, 2SB, LSB from bit 3 down (DS p. 63). The figure on DS p. 63 draws the data running from the start address to the end address and puts **"Final Data" in the low nibble of the byte at the end address**, and the text says "the storage of speech data should always be ended with the lower rank bit. So, always store an even number of samples." So **the end address is inclusive**, and a phrase is **2 x (end - start + 1) nibbles**. | Implementation | nibbles played | start == end | start > end | | --- | --- | --- | --- | | Data sheet | 2(end - start + 1) | not described | not described | | MAME 0.285 | 2(end - start + 1) | not started, logged | not started, logged | | libvgm | 2(end - start + 1) | not started | not started | | FBNeo | 2(end - start) | starts with count 0: silent, BUSY set until its next render | count negative: the same | | jt6295 (HDL as read) | 2(end - start) + 1 | one nibble | one nibble | The phrase length is C6; what the chip does with start >= end is U3. If the chip's end test is an equality ("Address Compare" in the block diagram, DS p. 54) rather than an ordering, a start past the end would play until the 18-bit address counter wraps round to the end: up to a quarter of a megabyte of whatever the ROM holds. Nothing in hand decides it. These entries are not hypothetical. In CPS-1's 40 distinct sample ROMs (checked by reading every table, 2026-11-12): - **47 entries with end = start - 1**, the shape a tool produces for a phrase of zero bytes: kod 17, kodr1 15, pang3 7, megaman 5, mpumpkin 3 (kod phrase 19 is `006A00`-`0069FF`). - **1 entry with start > end otherwise**: willow phrase 36, `03B100`-`03ADFF`. - **2 entries with start = end**: nemo phrase 86 (`030000`-`030000`) and dynwarj phrase 127 (`03FFFF`-`03FFFF`). Whether the games ever ask for them is not known (the MAME tap of Final Fight did not). Across the 601 unbanked regions: 2,670 entries with start = end (99 regions), 3,742 with start > end (115 regions), 1,608 with an end beyond the region (59). ## Banking is the board's The chip sees 256 KB. 648 of the 1,249 distinct sample regions in the local sets are larger and are banked by their boards: MAME calls the device's `set_rom_bank` from 85 driver files and gives it an address map in 35. Banking schemes include: - a bank register replacing high address lines (most); - **NMK112** (NMK, Afega and others): four 64 KB banks, one per quarter of the chip's space, and optionally the phrase table too, banked in four 256-byte pieces so each channel's entries can come from a different bank (libvgm's `okim6295.c`, `NMK_TABLESIZE` and the bank table, around line 250); - Gottlieb System 3 sound, Atari JSA III: bank bits in the same latch as pin 7. So the core must never cache table or data bytes: it asks the board for each byte at the moment the chip would read it, with the 18-bit address on its pins, and the board answers from whatever its banking says at that moment. When the chip reads is part of the contract (handoff brief): the table entry when a command is taken in (jt6295 reads all six bytes then; that the chip does is an inference: DS p. 57's 5 tCYC + 90 ns access time fits six reads inside the 15 x n clocks before BUSY rises), and one data byte per two nibbles. ## VGM files libvgm (`okim6295_w`, around line 580) takes, for a VGM stream: port 0 the command byte, ports 8-11 the clock (little-endian, applied when port 11 is written), port 12 pin 7, port 14 NMK112 enable, port 15 a 256 KB bank number, ports 16-19 the four NMK112 bank registers. vgmrips.net's pages for the chip could not be fetched (an anti-bot page to curl); whether VGM rips of MSM6295 music exist in quantity was not checked.