# POKEY (Atari C012294): what the chip is Phase 0 document, 2026-11-11. No code exists yet. Everything here is cited; the tier of each source is in [validation.md](validation.md). Where sources disagree the item has a `C` number, where nobody knows a `U` number, both in [undocumented-behavior.md](undocumented-behavior.md). Cycle-level detail is in [timing.md](timing.md). Short names for the sources: - **[DS]** Atari, *POKEY CHIP*, drawing CO12294 rev B, 1982, by sheet number (`reference/docs/pokey-datasheet.pdf`; PDF page = sheet - 4). - **[SCH]** Atari's seven logic schematic sheets (`reference/docs/atarimuseum-pokey.zip`; the same logic is [DS] sheets 35-41). - **[HM]** Atari, *400/800 Hardware Manual* CO16555, 1980, by section. - **[RE]** the AtariAge "Pokey decap" thread (`reference/forum/atariage-182670-*`): ijor's and phaeron's prose about ijor's schematics redrawn from the die photographs. Only the posts' prose is cited; the schematic PDF itself was never obtained (restart: see [provenance.md](provenance.md)). - **[AHRM]** Avery Lee, *Altirra Hardware Reference Manual*, 2026-01-02 edition, by section (chapter 5 is POKEY, chapter 13 the 5200). - **[ACID]** Acid800 1.2 test sources (`pokey_*.s`), expectations stated to pass on real hardware. - **[Plogue]** David Viens's recordings of a real chip run at 10 kHz (`reference/forum/plogue-pokeys.html`). - **[VHDL]** Nick Mikstas's VHDL (written from ijor's schematics, by its author's account in [RE]), run here as a **closed box**: built under GHDL and driven only through its pins by `scripts/run_vhdl.py`. Its files are never opened ([restart.md](restart.md), rules 1 and 5). A value measured through it is `OBSERVED`, never `DIE`. ## One paragraph POKEY is a 40-pin NMOS chip of about 5,000 transistors [RE p2], designed by Doug Neubauer, with no reset pin [DS 20]. It contains four 8-bit down counters fed by the phase-2 clock or by two clocks it divides from it, three free-running polynomial counters, four output flip-flop chains with 4-bit volume, an interrupt controller with eight sources, a 10-bit serial transmitter and receiver that borrow the counters as baud-rate generators, a 64-position keyboard scanner with a debounce state machine, and eight comparator inputs that time the charging of external capacitors. **The audio is a side effect of the counters**: everything else in the chip uses the same four counters, which is why the whole chip is one core and cannot be split into "sound" and "the rest". ## Pins [DS 33] | Pin | Name | Dir | What | | --- | --- | --- | --- | | 1, 17 | VSS, VDD | | ground, +5 V | | 38-40, 2-6 | D0-D7 | I/O | data bus | | 36-33 | A0-A3 | in | register address | | 30, 31 | /CS0, CS1 | in | chip selects (selected when /CS0 low and CS1 high) | | 32 | R/W | in | read high, write low | | 7 | O2 | in | **the only clock**: the CPU's phase 2 | | 29 | /IRQ | out | open drain, shared with other chips on the board | | 37 | AUDIO | out | one analogue output: the four channels' currents summed | | 14, 15, 12, 13, 10, 11, 8, 9 | P0-P7 | in | pot inputs (comparators, with dump transistors to ground) | | 23-18 | /K0-/K5 | out | keyboard scan counter, inverted | | 25 | /KR1 | in | keyboard response: the key addressed by K0-K5 is down | | 16 | /KR2 | in | second response line: Control, Shift, Break | | 24 | SID | in | serial data in | | 28 | SOD | out | serial data out | | 27 | OCLK | out | serial output clock | | 26 | BCLK | I/O | bidirectional serial clock | What the host board supplies: O2 edges (the core counts them: 1.789773 MHz on an NTSC 5200/7800/8-bit, 1.773447 MHz PAL, 1.25 or 1.5 MHz on arcade boards), bus accesses, the levels on P0-P7, /KR1, /KR2, SID and BCLK. What it gets back: /IRQ, the audio, /K0-/K5, SOD, OCLK, BCLK, and the state of the dump transistors (which the board's capacitor model needs). ## Registers [DS 32] Sixteen addresses. A write and a read at the same address are different registers. Address `$0C` has nothing in either direction; reading it or any other address with no read register returns `$FF` [AHRM 5.1]. | Addr | Write | | Read | | | --- | --- | --- | --- | --- | | `$0` | AUDF1 | channel 1 divider reload value | POT0 | pot counter latch | | `$1` | AUDC1 | channel 1 control | POT1 | | | `$2` | AUDF2 | | POT2 | | | `$3` | AUDC2 | | POT3 | | | `$4` | AUDF3 | | POT4 | | | `$5` | AUDC3 | | POT5 | | | `$6` | AUDF4 | | POT6 | | | `$7` | AUDC4 | | POT7 | | | `$8` | AUDCTL | audio control | ALLPOT | which pot lines are still below threshold | | `$9` | STIMER | strobe: reload all four dividers | KBCODE | latched key code | | `$A` | SKRES | strobe: reset SKSTAT bits 7-5 | RANDOM | eight bits of the 9/17-bit counter | | `$B` | POTGO | strobe: start a pot scan | | `$FF` | | `$C` | | | | `$FF` | | `$D` | SEROUT | serial output holding register | SERIN | serial input holding register | | `$E` | IRQEN | interrupt enables | IRQST | interrupt status, active low | | `$F` | SKCTL | serial/keyboard control ([DS] calls it SKCTLS) | SKSTAT | serial/keyboard status | **AUDCx** [DS 4-8, AHRM 5.3]: bits 3-0 volume; bit 4 volume-only (the output is forced on); bits 7-5 the distortion: | AUDC[7:5] | Output flip-flop is clocked by | and takes | | --- | --- | --- | | 000 | divider gated by poly-5 | the 9/17-bit counter's bit | | 001, 011 | divider gated by poly-5 | its own inverse (a toggle) | | 010 | divider gated by poly-5 | the 4-bit counter's bit | | 100 | divider | the 9/17-bit counter's bit | | 101, 111 | divider | its own inverse: a square wave | | 110 | divider | the 4-bit counter's bit | **AUDCTL** [HM III, AUDCTL]: bit 7 the long counter is 9 bits instead of 17; bit 6 channel 1 clocked at the machine clock; bit 5 channel 3 clocked at the machine clock; bit 4 channel 2 clocked by channel 1 (16 bits); bit 3 channel 4 clocked by channel 3 (16 bits); bit 2 high-pass on channel 1, clocked by channel 3; bit 1 high-pass on channel 2, clocked by channel 4; bit 0 the base clock is 15 kHz instead of 64 kHz. **SKCTL** [DS 20]: bit 7 force break (serial output forced to 0); bits 6-4 serial clock mode; bit 3 two-tone; bit 2 fast pot scan; bit 1 keyboard scan enable; bit 0 debounce enable. **Bits 1-0 both 0 is initialisation mode.** **SKSTAT** [DS 22], bits read 0 when true: bit 7 serial frame error; bit 6 keyboard overrun; bit 5 serial input overrun; bit 4 the SID pin itself; bit 3 Shift down; bit 2 the last key is still down; bit 1 serial input shift register busy; bit 0 always 1. Bits 7-5 are latches reset to 1 by a write to SKRES. [HM] III.18 has bits 5 and 6 swapped (C3). **IRQEN / IRQST** [DS 23]: bit 7 Break key; bit 6 other key; bit 5 serial input ready; bit 4 serial output needed; bit 3 serial transmission finished; bit 2 timer 4; bit 1 timer 2; bit 0 timer 1. There is no timer 3 interrupt. An IRQEN bit of 1 enables; an IRQST bit of 0 is a pending interrupt. Writing 0 to an IRQEN bit both disables the source and sets its IRQST bit back to 1; that is the only acknowledge. Bit 3 is not a latch: it reads 0 whenever the output shift register is idle, enabled or not. ## Clocks [AHRM 5.4, 5.2] All timing comes from O2. Inside the chip two polynomial counters divide it: by 28 (the "64 kHz" clock: 63.921 kHz at NTSC) and by 114 (the "15 kHz" clock: 15.700 kHz). **Nothing ties the 15 kHz clock to ANTIC or to any video chip**: 114 happens to be the number of CPU cycles in an Atari scan line, so on the 8-bit computers and the 5200 it runs at line rate, at whatever offset in the line the program released initialisation mode. On a board with another clock (arcade, at 1.25 or 1.5 MHz) it is simply O2/114. The 15 kHz clock also drives the keyboard scan and the slow pot scan; the 64 kHz clock is audio only. Channels 1 and 3 may take the undivided machine clock (AUDCTL bits 6, 5). Channels 2 and 4 take the base clock, or the underflow of channel 1 or 3 when joined. All four share the one base clock choice (AUDCTL bit 0). ## Dividers and timers [AHRM 5.3, DS 17] Each channel is an 8-bit down counter reloaded from AUDFx when it underflows. The pulse at underflow clocks that channel's output circuit, may set a timer interrupt (channels 1, 2 and 4), and may clock the serial port. Periods, in machine cycles for AUDF = N: | Clocking | Period | Source | | --- | --- | --- | | 15 kHz | (N + 1) x 114 | [AHRM 5.3], [HM] "normal formula" | | 64 kHz | (N + 1) x 28 | the same | | 1.79 MHz, 8-bit | N + 4 | [HM] "modified formula", [AHRM 5.3], hardware recording [Plogue], [VHDL] run here | | 1.79 MHz, 16-bit (N = low + 256 x high) | N + 7 | [HM], [AHRM 5.3] | | 15/64 kHz, 16-bit | (N + 1) x 114 or x 28 | [AHRM 5.3] | The +4 is one for counting through zero and three "of delay from the counter being split into multiple stages and for the underflow logic" [AHRM 5.3]; a joined pair adds three more because the low timer must underflow before the high one can, and only then can both reset [AHRM 5.3], hence +7. At the slow clocks the delay is hidden inside the wait for the next clock tick, so it shifts phase but not period [AHRM 5.3]. In a joined pair the low counter does not reload on its own underflow: it keeps counting through 256 until the high counter underflows, and then both reload. The low channel still clocks its own output circuit on each of its underflows (AUDF_high + 1 times per period of the pair) [AHRM 5.3, "Linked timer fire timing"]. **STIMER** reloads all four counters and forces the output flip-flops to a known state: with the high-pass filters off, channels 1 and 2 output 0 and channels 3 and 4 output 1 at the pin-side of the logic ([AHRM 5.3]; [DS 17] words it the other way round: C2). It sends no pulse to the output circuits and sets no interrupt. It does not touch the 15/64 kHz clocks' phase. ## Polynomial counters [AHRM 5.5] Three shift registers with XNOR feedback, shifting once per machine cycle while not in initialisation mode: | Counter | Length | Polynomial | Notes | | --- | --- | --- | --- | | 4-bit | 15 | 1 + x^3 + x^4 | pattern `000011101100101` ([AHRM 5.5]; the same from a real chip, [Plogue]) | | 5-bit | 31 | 1 + x^3 + x^5 | pattern `0000011100100010101111011010011`. The first release of [RE] drew the tap at x^2; corrected in version 1.2 after phaeron's report [RE p1-2] | | 9-bit | 511 | 1 + x^4 + x^9 | AUDCTL bit 7 = 1 | | 17-bit | 131,071 | 1 + x^12 + x^17 | AUDCTL bit 7 = 0; eight more stages in the same register | RANDOM reads eight bits of the long register, **inverted** with respect to what the audio circuits see, shifting right one bit per cycle [AHRM 5.5]. The noise bit reaches channels 1, 2, 3, 4 one cycle apart in that order, so two channels never sample the same bit on the same cycle [AHRM 5.5]. A channel in a noise distortion does not have its own generator. It **samples** the shared one when its divider fires. So the sound depends on the divider's period in machine cycles modulo the pattern length, and on the divider's phase against the pattern: the same register values can give different timbres, or silence, from one note to the next ([AHRM 5.3], "Noise sampling artifacts"). This is the single thing emulators most often get wrong, and it is why the phase after STIMER and after initialisation mode matters ([timing.md](timing.md)). ## Output stage [DS 4-5, AHRM 5.3] Per channel: divider pulse, optionally gated by the 5-bit counter (AUDC bit 7 = 0), clocks a flip-flop that either toggles or samples a noise bit. Channels 1 and 2 then pass through the "high-pass": a second flip-flop that copies the first when channel 3 (or 4) fires, XORed with the first. With the filter off the second flip-flop is held at 1, **so channels 1 and 2 are inverted relative to 3 and 4**: two square waves at the same pitch add on channels 1 and 2 and cancel on channels 1 and 3 [AHRM 5.3]. Last, volume-only (AUDC bit 4) forces the channel's digital output to 1, after the high-pass. The digital output selects between zero current and the channel's 4-bit volume current; the four currents are summed at one pin [DS 4]. So the digital truth of the chip's sound is four numbers per cycle: each channel's volume if its output bit is 1, else 0. The analogue truth is not linear: the per-bit drivers are mismatched (wider steps at 3-4, 7-8, 11-12) and the sum saturates above about one channel's worth; two channels at 15 give about 1.5 times one [AHRM 5.3]. No permitted source gives the curve as numbers; the core's `mix()` uses a curve fitted to the manual's words (decision 5), labelled `FITTED`. ## Serial port [DS 18-22, HM II, AHRM 5.6] Two independent 10-bit shifters (start, 8 data LSB first, stop). Output: a write to SEROUT fills a holding register; at the next output clock edge with the shifter idle the byte moves to the shifter, "output needed" (bit 4) is signalled, and "transmission finished" (bit 3) goes inactive until the shifter empties with nothing waiting. Input: a start bit starts the shifter; after the stop bit the byte goes to SERIN, "input ready" (bit 5) is signalled, frame error and overrun go to SKSTAT. Bit clocks are **half** the rate of the divider that drives them (a divide-by-two flip-flop in the serial logic). SKCTL bits 6-4 choose the clocks. The table below is [AHRM 5.6, Table 10], which corrects two cells of Atari's chart ([DS 21], [HM] II.27): C4. | 6-4 | Input clock | Output clock | BCLK pin | | --- | --- | --- | --- | | 000 | external | external | input | | 001 | channels 3+4, asynchronous | external | input | | 010 | channel 4 | channel 4 | output: channel 4 | | 011 | channels 3+4, asynchronous | channel 4, asynchronous | input | | 100 | external | channel 4 | input | | 101 | channels 3+4, asynchronous | channel 4, asynchronous | input | | 110 | channel 4 | channel 2 | output: channel 4 | | 111 | channels 3+4, asynchronous | channel 2 | input | "Asynchronous" means channels 3 and 4 are **held in reset** while the receiver waits for a start bit, and run from the start bit's leading edge, so the sampling points sit in the middle of each bit. A side effect: with bit 4 set and no data arriving, channels 3 and 4 make no sound except in volume-only mode. **Two-tone** (SKCTL bit 3): SOD carries a square wave from timer 1 while the data bit is 1 and from timer 2 while it is 0 (the logic is `(timer 1 AND data) OR timer 2` into a divide-by-two, not a switch: [AHRM] footnote 26, C5), and every time that output toggles, timers 1 and 2 are both reloaded. The reloads change what channels 1 and 2 sound like; music players use it for that, with nothing on the serial bus ([AHRM 5.6], "Two-tone resync"). **Force break** (bit 7) forces the data bit to 0, so in two-tone mode it selects timer 2. Bit 4 of SKSTAT is the SID pin, unclocked. ## Keyboard scan [DS 10-14, AHRM 5.8] A 6-bit counter steps once per 15 kHz tick and appears inverted on /K0-/K5. The board decodes it to a matrix and answers on /KR1 if that key is down. A full scan is 64 ticks. The state machine (four states, a 6-bit compare register) requires a key to be seen on two consecutive scans before it latches the code into KBCODE bits 5-0 with Shift and Control in bits 6 and 7, sets the keyboard interrupt and pulls SKSTAT bit 2 low; and requires two scans up before SKSTAT bit 2 returns. With debounce off (SKCTL bit 0 = 0) the compare always passes, so it checks consecutive codes instead of the same code twice. /KR2 is sampled at codes `$00` (Control), `$10` (Shift) and `$30` (Break); Break sets its own interrupt (bit 7) on a down transition only. A new key latched while the keyboard interrupt is still pending sets the overrun latch (SKSTAT bit 6). The 5200 wires its keypad to K1-K4 only, so every key answers at four codes; its software must run with debounce **off**, and the top fire button is on /KR2, so it reads as Shift, Control and Break [AHRM 13.3]. That is all board wiring: the core sees only /KR1 and /KR2 levels per scan code. ## Pot scan [DS 15-17, HM II, AHRM 5.9] POTGO clears a counter and turns the dump transistors off. The counter then counts 15 kHz ticks to 228. Each POTn register follows the counter while its pin is below the comparator threshold (about 2.1 V) and freezes when the pin crosses; ALLPOT shows the pins still below. At 228 the scan ends, ALLPOT reads `$00` and the dump transistors turn on again. With SKCTL bit 2 set (fast scan) the counter counts machine cycles instead, ends at 229, and the dump transistors stay off. Reading a POTn that is still counting can return the AND of two successive counts [AHRM 5.9, "Reading live counters"]. The 5200's sticks are two pots per controller on P0-P7 with a 0-228 range in scan lines; its games read them once per frame and some restart the scan early (truncated scans). The capacitors, resistors and the stick's power switch are the board's; the chip's part is the comparators, the counter, the latches and the dump transistors. ## Interrupts [DS 23, AHRM 5.7] /IRQ is low while any enabled status bit is 0, plus bit 3's special case (it asserts /IRQ only while enabled, but its status bit shows through regardless: see C6 for the two readings of [AHRM 5.7] on this). Timer interrupts are set by the divider pulse, not by the audio output, and no AUDC bit affects them. ## Initialisation mode and power-on [DS 20, AHRM 5.2] There is no reset pin and "no original power on state" [DS 20]: every register, including IRQEN, is unknown at power-on. Software writes 0 to SKCTL, which **holds in reset** the two clock dividers, the three polynomial counters, the serial input and output state machines and the SEROUT-full flag, and stops the keyboard scan. It does not touch IRQEN, IRQST, KBCODE, SERIN, AUDFx, AUDCx, AUDCTL, the divider counters, the channel outputs, or the bit standing on SOD. While it lasts, RANDOM reads `$FF`, dividers on the 15/64 kHz clocks stop, and the slow pot scan is suspended. Everything restarts on the cycle the mode is left, which is how software sets the phase of the 15 kHz clock within a scan line and of the polynomial counters against its own code. ## Variants | Part | What differs | Evidence | In scope | | --- | --- | --- | --- | | C012294, all suffixes (B-01 AMI, -03 Signetics, -19 National, -22 OKI, -31 IMP per Wikipedia's list) | nothing known in logic; analogue output levels may differ by maker | no source found that measures a difference (U8) | yes: the one engine | | 137430-001 | the arcade part number for the same chip | Wikipedia's list only (U9) | yes, as a name | | Quad POKEY (137324-1221 per Wikipedia; the task brief said C137290: C7) | four POKEYs in one package; which pins are bonded out is not established here | MAME models every quad board (Major Havoc, I Robot, Firefox, Return of the Jedi) as four ordinary `pokey` devices (`mame -listdevices`) | as four instances and a data row, when an arcade board needs it (U9) | | PokeyMAX, PokeyONE, HOKEY, Mikstas's FPGA board | modern replacements | | **non-goals** (Mikstas's VHDL is a closed-box detector here; no other HDL is used) | ## What the consumers use | Consumer | Uses | Does not connect | | --- | --- | --- | | Atari 5200 (`a5200-python`) | audio, timers and IRQs, RANDOM, pot scan (sticks), keyboard scan (keypads, top buttons on /KR2), SKCTL; serial pins go to the expansion port only | nothing on the serial port in a stock console | | Atari 7800 cartridges (`a7800-python`) | audio, RANDOM, timers as software sees them; one POKEY at `$4000` (Ballblazer, Commando) or `$0450` (XM and homebrew) | /IRQ, pots, keyboard, serial (to be confirmed by that board's Phase 0: U10) | | Atari 8-bit computers (later) | everything: SIO on the serial port, the keyboard, paddles | | | Atari arcade boards (later) | audio, RANDOM (Tempest's protection reads it), pot inputs as switch inputs through ALLPOT; O2 at 1.25 or 1.5 MHz | usually keyboard and serial |