# Jerry: timers, clocks, sound output, serial ports, controllers Sources: **[TRM]** p.83-99, 141 (tier 2); **[TR10]** p.2, 5-6, 10-19 (tier 2, community-amended); **[NET]** `jerry/JMISC.NET` (timers, interrupts, joystick enable), `JCLK.NET`, `I2S.NET`, `DAC.NET`, `UART2.NET`, `JIODEC.NET`, `DSP_INT.NET` (tier 2 as text; only the comments cited were read). The DSP itself (registers, instructions, flags, the modulo and MAC registers) belongs to `jrisc-python`; everything here is the board's (`jaguar_python.jerry`). ## What is in the chip [TRM p.83] The DSP; three clock dividers; two programmable timers; a stereo PWM DAC; a synchronous serial port (I2S); an asynchronous one (ComLynx/MIDI); the joystick decodes; six general-purpose I/O decodes; "two DMA channels (by way of DSP interrupts)". Jerry is a 16-bit device on the bus and the DSP reaches external memory **16 bits at a time** [TRM p.97], unlike the 64-bit GPU. ## Clock dividers (`CLK1` `F10010`, `CLK2` `F10012`, `CLK3` `F10014`) [TRM p.84-85] Divider ratios for PLL clock synthesis. The boot ROM writes `CLK3` = 4 and `CLK2` = `$B5` (measured, [mame-oracle.md](mame-oracle.md)); software is told never to touch them [TR10 p.2]. Model: store, and assert on any later write that changes them. The console's processor clock is an oscillator; nothing was found on whether `CLK1` does anything in the console (**U10**). ## Timers (PITs) [TRM p.85-86; `JMISC.NET` l.91-210] Two identical timers, each a 16-bit prescaler (system clock / (N+1)) feeding a 16-bit divider (/ (M+1)); both are down-counters, reloaded on write and at zero. Write `JPIT1` `F10000`, `JPIT2` `F10002`, `JPIT3` `F10004`, `JPIT4` `F10006` (**C1**: the manual misprints the last); read back at `F10036`, `F10038`, `F1003A`, `F1003C`. Netlist comments: a timer is "enabled if pit1 is nz" (timer 1) and "if pit3 is nz" (timer 2): **a zero prescaler stops it**. Each divider's zero can interrupt the DSP (interrupts 2 and 3) and, through `J_INT`, the 68000. The timer-1 prescaler also clocks the PWM DAC. Tom has its own timer, `PIT0`/`PIT1` at `F00050/52` (a prescaler and a divider; disabled when the first register is 0), which the manual says interrupts "the CPU and the GPU" [TRM p.16]: source 3 of `INT1`, and GPU interrupt 2, which the GPU chapter calls "timing generator" (`tom/TOM.NET` l.307 passes the PIT's `tint` into the graphics block); see [interrupts.md](interrupts.md). ## Sound output Two paths exist in the chip; which one the console's audio jack hears matters. - **PWM DACs** `DAC1` `F1A140` (left), `DAC2` `F1A144` (right): 14 bits used, split into two 7-bit pulse widths at the timer-1 prescaler rate; double buffered; reset to 0 [TRM p.88-89; `DAC.NET`: "no match if a >= 128", "stop the counter when two msbs are set"]. - **I2S transmitter** `LTXD` `F1A148`, `RTXD` `F1A14C` (the same addresses read back received data), `SCLK` `F1A150` (bit clock = system clock / (2 x (N+1))), `SMODE` `F1A154` (bit 0 internal clock, 1 32-bit mode, 2 word strobe enable, 3/4/5 interrupt on rising edge, falling edge, every word), status at `F1A150` [TRM p.90-92]. In 16-bit mode the right word is taken on the rising edge of word strobe, the left on the falling edge; one stereo frame is 32 bit clocks, so the sample rate is `system clock / (64 x (N+1))`. [TR10 p.5] lists the I2S data registers as `L_I2S`/`R_I2S` in `JAGUAR.INC` and [TR10 p.10] says the I2S pins also go to the cartridge port for the CD unit. Emulators take the console's audio from the I2S transmit registers (Virtual Jaguar; the MiSTer core adds a model of a TDA1545A serial DAC beside the netlist's `j_dac.v`: HYPOTHESIS, both read from GPL source in Phase 0). **The console schematic was not read in this phase**, so "console audio = I2S into a serial DAC; the PWM pins are unused" is the working assumption with two tier 4-5 witnesses, not a tier 2 fact (**U11**). Audio is **muted at reset**; `JOYSTICK` bit 8 unmutes [TR10 p.2]. Sound-clock sources a game can use, all visible to the model as DSP interrupts: the I2S word strobe (interrupt 1), timer 1 and timer 2 (2, 3), external 0 and 1 (4, 5). Which one a game's sound driver uses changes its pitch if that source's period is wrong, which makes pitch a cheap check of the clock model. ## Asynchronous serial port (ComLynx, MIDI) [TRM p.93-95; `UART2.NET`, 601 lines] `ASIDATA` `F10030`, `ASICTRL`/`ASISTAT` `F10032`, `ASICLK` `F10034` (baud = system clock / (N+1) / 16). One start bit, 8 data, optional parity, one stop; transmit and receive each double buffered; status bits RBF 7, TBE 8, PE 9, FE 10, OE 11, SERIN 13, TXBRK 14, ERROR 15; control bits ODD 0, PAREN 1, TXOPOL 2, RXIPOL 3, TINTEN 4, RINTEN 5, CLRERR 6, TXBRK 14. [TR10 p.5] notes the equates were dropped from the last `JAGUAR.INC`, "possibly [because] the UART bug was too big a problem". First build: registers, transmitter-empty status, loopback off; the port is a **socket** for a second console (JagLink), never needed to boot a game. The UART bug, from the 1995 *Hardware Bugs & Warnings* sheet (OCRed, page 6): a start bit detected at a certain phase of the divide-by-16 timer is shifted in twice, shifting the received byte left; Atari's workaround is a leading `$80` dummy byte and exactly aligned stop bits. `UART2.NET` decides the phase; a receiver model that samples ideally is wrong in exactly the way that sheet describes. ## Controllers [TRM p.95-96; TR10 p.13-19] - `JOYSTICK` `F14000`. **Write**: bit 15 enables the J0-J7 outputs; bits 3-0 = port 1 row select (J3-J0), bits 7-4 = port 2 (J7-J4, bit-reversed order); **bit 8 = audio unmute**; bit 0 is used by the cartridge EEPROM. **Read**: bits 15-8 = J15-J8 (four inputs per port); bit 0 = EEPROM data out. - `JOYBUTS` `F14002`, read: bits 1-0 = B1, B0 (port 1), bits 3-2 = B3, B2 (port 2); **bit 4 = 1 for NTSC, 0 for PAL**. - A row select is one-of-four active low per port (`1110` row 0 ... `0111` row 3). **Standard pad**, 0 = pressed: row 0 = Pause (B0), A (B1), Up, Down, Left, Right; row 1 = B, `*`, 7, 4, 1; row 2 = C, 0, 8, 5, 2; row 3 = Option, `#`, 9, 6, 3. The B0 column of rows 1-3 carries the controller-type bits C1-C3 (standard pad: 1, 1, 1). - **Team Tap**: a 4-to-16 decoder on the four outputs gives four sockets of four rows each; the table of codes is in [TR10 p.18]; socket 0 uses the plain pad's codes; the adaptor pulls pin 8 high. Up to eight pads. - Rotary ("Tempest") controller: a pad whose Left/Right lines carry a 2-bit Gray code. Analogue and bank-switching controllers, light gun (latches `LPH`/`LPV` on port 1's B0): sockets, later. - Paddles: the netlist carries "UNUSED PADDLE LOGIC" (`JMISC.NET` l.220) and early consoles had an ADC on GPIO5; not needed. ## General-purpose decodes [TRM p.96] `F14800-F14FFF` GPIO0 ("CD interface"), `F15000-F15FFF` GPIO1 ("DMA ACK"), `F16000-F16FFF` GPIO2 ("cartridge"), `F17000-F177FF` GPIO3, `F17800-F17BFF` GPIO4, `F17C00-F17FFF` GPIO5 ("paddle interface"). In the console GPIO0 and GPIO1 clock and select the cartridge's serial EEPROM ([eeprom.md](eeprom.md)); CoJag boards use GPIO2-5 for guns, switches and a latch (MAME `r3000_map`). ## Jerry bugs [TRM p.141] 1 reset input not a Schmitt trigger (none for us); **2 reads of DSP space by another processor work only at `IOSPEED` = 3** (6 clocks; "all manuals up to Rev 5" said 2); **3 Jerry can see the tail of a previous bus grant and write wrong data**; 4-5 32-bit-CPU issues (not the console); **6 the DSP's matrix address register reaches only the first 4 KiB of its RAM**. Tom bug 12 (one-clock bus grants to Jerry) is the same family as 3: a real model of the Tom-Jerry bus handshake is needed before either can be reproduced, and both are "writes with the wrong data", i.e. things working software avoids. Assert, do not model, in the first build.