# Controller ports: joystick, keypad, spinner Sources: **[TM]** Coleco's Technical Manual, "Hand Control Interface" (tier 2) and its oscilloscope pictures (tier 1, qualitative); **[SCH]** the KiCad redraw, sheet 6 (tier 3); **[DB]** Dan Boris's hand-traced schematic, 2002, sheet 3 (tier 3, a second independent tracing; `reference/docs/danb-colecovision-schematic-2002.pdf`); **[OS7]** Coleco's OS-7 source listing "REV 7PRIME" as reprinted in the Coding Guide, pp. 139-141 (Coleco's own code, so tier 2 for what the BIOS expects); **[CG]** the Coding Guide's own prose (tier 3); **[MiSTer]** `rtl/cv_ctrl.vhd` in the pinned ColecoVision_MiSTer tree (Arnim Laeuger's FPGA ColecoVision, tier 4); **[MAME]** `coleco.cpp` and `coleco_m.cpp` at 0.285 (tier 5). Coleco's own schematic (Technical Manual section V-1) is **not in the pinned scan**: the PDF goes from the exploded view (IV-2) straight to the assembly drawings (V-2). So the two tracings, [SCH] and [DB], are the best drawing in hand. ## The strobe model Each port is a 9-pin connector with **two ground strobes and five inputs**; "the ground strobe outputs are generated from the CPU address bus using a decoder and a flip-flop. The flip-flop ensures that one strobe is enabled at a time" [TM]. On the drawing the flip-flop is two cross-coupled NAND gates (U24A/B) set by the `$C0` write strobe and reset by the `$80` write strobe, common to both ports [SCH]: | Write to | Selects | Then a read of `$FC` (port 1) or `$FF` (port 2) returns | | --- | --- | --- | | `$C0-$DF` | the **joystick** segment | bit 0 up, 1 right, 2 down, 3 left, bit 6 the left fire button; all active low | | `$80-$9F` | the **keypad** segment | bits 0-3 a 4-bit key code, bit 6 the right fire button | [OS7] names the ports `STRB_RST_PORT EQU 0C0H` ("reset to segment 0"), `STRB_SET_PORT EQU 080H`, `CTRL_0_PORT EQU 0FCH`, `CTRL_1_PORT EQU 0FFH`; its `CONT_SCAN` reads segment 0 (joystick), writes `$80`, calls a one-`NOP` "wait 10 microsecs" delay, reads segment 1 (keypad) and writes `$C0` again. The data written is ignored. Reads are gated by `$E0-$FF` read strobes with A1 choosing the port (two 74LS541 buffers, U18 and U19) [SCH, DB]. The BIOS writes `$C0` once at start (seen in the trace). **Which pin is which bit** (traced on [DB] sheet 3 at 600 dpi, U19; agrees with [MiSTer]'s read multiplexer bit for bit): | Bit | Source | Notes | | --- | --- | --- | | 0, 1, 2, 3 | connector pins 1, 4, 2, 3 | joystick directions or the key code, by segment | | 4 | **the spinner one-shot's node**, not a connector pin | low for a while after a phase edge: [OS7] calls it the "int bit" | | 5 | connector pin 7, the spinner's **second phase**, read directly | [OS7]: "If bit 5 is set ... going right" | | 6 | connector pin 6 | the fire button of the selected segment | | 7 | **the output of the pulse-shaping NAND** (74LS00, U24C/U24D) | the first phase (pin 9, through 1.8 kΩ and 1 nF) gated by the one-shot | Pins 5 and 8 are the two segment strobes (outputs). So bits 4 and 7 come from console circuitry, not from the controller. Two independent tracings and an FPGA core agree; MAME models the same three bits by behaviour instead (below). Key codes (low nibble, as MAME returns them): none `F`, `0` `A`, `1` `D`, `2` `7`, `3` `C`, `4` `2`, `5` `3`, `6` `E`, `7` `5`, `8` `1`, `9` `B`, `*` `9`, `#` `6`; the Super Action Controller's two extra buttons `4` (blue) and `8` (purple). **Checked against the BIOS's own table**: [OS7]'s `DEC_KBD_TBL`, indexed by the complemented nibble (`CONT_READ` does `CPL`), maps all twelve keys to the same codes, and leaves raw `8`, `4` and `F` as `KDB_NULL` (so the BIOS decoder ignores the Super Action Controller's two extra buttons). The keys are a resistor/diode matrix on four wires, so **two keys pressed together read as the AND of their codes**, a third key's code [MAME's comment and code]. In keypad mode MAME returns bits 4 and 5 high. Bit 7 and the unused bits: [SCH] shows pull-ups to a 2.5 V divider on the inputs; MAME returns bit 7 = 0 in joystick mode and "set for a short period" on spinner movement, with a to-do to measure it. On the drawings bit 7 is the NAND's output, so with nothing on pin 9 it reads whatever the NAND gives for a floating, pulled-up input: what an idle bit 7 reads on a console is U14. ## The spinner and the maskable interrupt "The spinner interface uses two inputs for each port. Required inputs are two square waves 180 degrees out of phase [sic: quadrature]. Phase relationship determines direction. Pulse time determines speed. One input is used to interrupt the microprocessor" [TM]. - One phase of each port goes through a pulse shaper (a NAND gate, a capacitor and a 2N3904 per port) and the two are diode-ORed into an open-collector inverter driving the Z80's `/INT` [SCH sheet 6; DB sheet 3 shows the same parts: U24C/D, Q4/Q5, the diode pair CR1/CR2]. So **`/INT` is a short pulse per edge, not a level waiting for an acknowledge**. - The shaper is a monostable: the NAND's output drives a 2N3904 whose collector (10 kΩ pull-up) feeds back to the NAND's second input through a capacitor [DB]: R70/C103 "473" (47 nF) beside connector J6, R72/C101 "104" (100 nF) beside J5. The tracing gives the two ports different capacitors (a real difference or a misread; nothing else in hand says). The time constant, 10 kΩ x 47 nF = 470 microseconds (1 ms with 100 nF), is the same order as MAME's 500-microsecond bit-7 guess, and MiSTer's counter (1,520 counts at 3.58 MHz, about 425 microseconds) is of the same order. **These are RC products read off a tracing, not measurements**; the edge into `/INT` passes 10 nF (C65/C61) into 1.5 kΩ (R1), which suggests a pulse of some 15 microseconds, again only an order of magnitude (U15). The Technical Manual's picture of that node (p. VII-10, 500 microseconds per division, "with Spinner Interface Tester in operation") shows narrow low spikes roughly a millisecond apart, too narrow to measure at that sweep. MAME asserts the line for **11 microseconds "TODO: measure duration"** (about 39 CPU clocks) and bit 7 for 500 microseconds, also "TODO". The real width is U15; it decides whether an interrupt that arrives while interrupts are disabled is lost. - The handler reads the port and decides per port: the BIOS's `UPDATE_SPINNER_` (entry `$1F88`) reads `$FC`, and **if bit 4 is low** (the one-shot fired: "If int bit set ... Then spinner 1" skips on bit 4 high) it increments `SPIN_SW0_CT` (`$73EB`) when bit 5 is high ("going right") and decrements it when bit 5 is low; then the same for `$FF` and `SPIN_SW1_CT` (`$73EC`) [OS7 p. 141]. It does not strobe a segment first, so it reads whichever is selected; [CG]'s prose says "segment 1", while the scan routine leaves segment 0 (joystick) selected. - **MAME models the bits by behaviour, not by circuit**: on each pulse it sets bit 7 for 500 microseconds and XORs `$10` (one direction) or `$30` (the other) into the joystick byte, so bit 4 low with bit 5 giving the direction, the same contract [OS7] reads; bit 7 differs from the drawings (MAME: a flag set on movement; drawings and MiSTer: the NAND's output). Lockstep against MAME on spinner games is a detector only. - The CPU is in IM 1; the vector at `$0038` jumps through the cartridge's `IRQ_INT_VECT` (`$801E`). - For z80-python: `request_maskable_interrupt()` on the pulse's leading edge and `clear_maskable_interrupt()` when it ends. No core change. Devices that use the spinner pins: | Device | What it is | Library titles usually listed for it (from the titles and common lists; nothing was run or checked here) | | --- | --- | --- | | Super Action Controller | joystick, 12-key pad, four fire buttons (two as extra key codes), a spinner | Super Action Baseball, Super Action Football, Rocky Super Action Boxing, Front Line (two dumps: standard and Super Action) | | Roller Controller | a trackball: its X drives port 1's spinner pins and its Y port 2's; both hand controllers plug into it; a mode switch makes it a joystick | Slither, Victory | | Expansion Module 2, the driving module | a wheel on port 1's spinner pins and a pedal that is a switch (the fire bit); port 2's controller does the rest | Turbo, Destructor, Dukes of Hazzard, Bump 'n' Jump, Pitstop | [MAME's header comment describes all three.] Model them as controller-port devices that produce phase edges on a timeline, not as a counter poked into RAM: Coleco's own "spinner interface tester" (a square-wave box) is the factory's test of this path, and the Super Controller Tester cartridge is in the library. ## Tests in hand - **Final Test Cartridge** (8K, `55 AA`, CRC `3ae4b58c`): after ROM and RAM checks, video and sound, "the final test is the handcontroller test. It indicates each handcontrol function on the screen. Each function will blank out after that function has been selected" and it checks the spinner with the tester box [TM p. VI-1]. - **Super Controller Tester** (16K, `AA 55`, CRC `eb6cb4d8`; not in MAME's list): Coleco's test of the Super Action Controller.