# Native quadrature mouse on joystick port 1

An Amiga-compatible quadrature mouse can use joystick port 1. The counter
increments right/down and decrements left/up, with 8-bit wraparound. Native
movement or the left button selects this port automatically. A PS/2 left
click selects the existing PS/2 mouse again.

## Existing pin mapping

| DB9 pin | Signal | Core input |
| --- | --- | --- |
| 1 | Vertical pulse | `_joy1[3]` |
| 2 | Horizontal pulse | `_joy1[2]` |
| 3 | Vertical quadrature | `_joy1[1]` |
| 4 | Horizontal quadrature | `_joy1[0]` |
| 6 | Left button | `_joy1[4]` |
| 9 | Right button | `_joy1[5]` |

The board's existing pin assignments remain in use. There is no mapped
native middle-button input in this six-signal interface. A mouse or adapter
must output Amiga quadrature signals on these pins; this is not a USB decoder.

`JOY0DAT` exposes Y in the high byte and X in the low byte. Its two low bits
per axis preserve the native joystick truth table. `JOYTEST` writes only
the upper six bits of each counter. Phase bits and carry/borrow update
together, preventing partial counter values during wraparound. Inputs pass
through two synchronizer registers before decoding.

The regression checks 1,692 steps and 1,840 conditions, including both axes,
directions, wraparound, atomic counter reads, JOYTEST loads, all digital
joystick direction combinations, left/right buttons, PS/2 switching, and
unchanged port 2 decoding.

```sh
iverilog -g2012 -s tb_quadrature_mouse -o /tmp/mouse.vvp \
  tests/userio/tb_quadrature_mouse.v Userio.v
vvp /tmp/mouse.vvp
```

The pin roles, direction convention, register layout and quadrature truth
table follow Commodore's [Amiga Hardware Reference Manual](https://amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node010A.html),
controller-port section and Figure 8-2 (also available in the
[third-edition scan](https://www.ikod.se/wp-content/uploads/2020/08/Amiga_Hardware_Reference_Manual_3rd_Edition.pdf)).
