Skip to content

Bus Mouse

hasu@tmk edited this page Mar 31, 2026 · 11 revisions

Quadrature output

Output sequence with bitwise operation

Q = S ^ (S >> 1)
    Q: Quadrature output { 00, 01, 11, 10 }
    S: State { 0, 1, 2, 3 }
S Q_a Q_b
0 0 0
1 0 1
2 1 1
3 1 0

Quadrature output code

    // X:PB0,PB1  Y:PB2,PB3  B1:PB4  B2:PB5  B3:PB6
    DDRB |= (1<<6) | (1<<5) | (1<<4) | (1<<3) | (1<<2) | (1<<1) | (1<<0);

    // Quadrature output
    static const uint8_t mode = 1;      // steps per count  x4:1, x2:2, x1:4
    static uint8_t state_x = 0;         // state: 0-3 { 00, 01, 11, 10 }
    static uint8_t state_y = 0;
    uint8_t dir_x = (x > 0) ? 1 : -1;   // 0: clockwise, 1: counter-clockwise
    uint8_t dir_y = (y > 0) ? 1 : -1;
    uint16_t step_x = (x > 0) ? x : -x;
    uint16_t step_y = (y > 0) ? y : -y;
    for (uint16_t i = 0; i < step_x * mode; i++) {
        for (uint8_t j = 0; j < mode; j++) {
            state_x = (state_x + dir_x + 4) % 4;
            int q = state_x ^ (state_x >> 1);
            PORTB = (PORTB & 0xF3) | ((q & 0x3) << 2);
            wait_us(60);
        }
    }
    for (uint16_t i = 0; i < step_y * mode; i++) {
        for (uint8_t j = 0; j < mode; j++) {
            state_y = (state_y + dir_y + 4) % 4;
            int q = state_y ^ (state_y >> 1);
            PORTB = (PORTB & 0xFC) | (q & 0x3);
            wait_us(60);
        }
    }
    //if (buttons & MOUSE_BTN1) PORTB |=  (1<<4); else PORTB &= ~(1<<4);
    if (buttons & MOUSE_BTN1) PORTB &= ~(1<<4); else PORTB |= (1<<4);
    if (buttons & MOUSE_BTN2) PORTB &= ~(1<<5); else PORTB |= (1<<5);
    if (buttons & MOUSE_BTN3) PORTB &= ~(1<<6); else PORTB |= (1<<6);
    if (buttons & MOUSE_BTN4) PORTB &= ~(1<<7); else PORTB |= (1<<7);

Pinout

https://web.archive.org/web/20250115003301/https://deskthority.net/wiki/Bus_mouse#9-pin_mini-DIN

https://www.waitingforfriday.com/?p=827#Example_cables

NeXT

https://github.com/tmk/tmk_keyboard/wiki/NeXT#mouse-pinouts

NeXT mouse Mini-DIN-8P plug/male
   ,-___-.      1 5V        6 RIGHT
  / 6 7 8 \     2 XA        7 LEFT  
 | 3 4   5 |    3 XB        8 GND
  \  1 2  /     4 YA
   `-----'      5 YB

Acorn Archimedes

https://github.com/tmk/tmk_keyboard/wiki/ACORN-ARCHIMEDES-Keyboard#mouse

Archimedes mouse Mini-DIN-9P plug/male
   ,-___-.      1 XB        6 5V
  / 7 8 9 \     2 LEFT      7 YB
 | 3 4 5 6 |    3 MIDDLE    8 RIGHT
  \  1 2  /     4 GND       9 YA 
   `-----'      5 XA

NEC PC-9801

https://radioc.web.fc2.com/column/pc98bas/pc98kbdmouse_en.htm

PC-9801 mouse DE-9 plug/male
,-----------.   1 5V        6 LEFT
\ 1 2 3 4 5 /   2 XA        7 NC
 \ 6 7 8 9 /    3 XB        8 RIGHT
  `-------'     4 YA        9 GND
                5 YB

PC-9801 mouse Mini-DIN-9P plug/male
   ,-___-.      1 5V        6 LEFT
  / 7 8 9 \     2 XA        7 NC   
 | 3 4 5 6 |    3 XB        8 RIGHT
  \  1 2  /     4 YA        9 GND
   `-----'      5 YB

Apple M0100

M0100 mouse DE-9 plug/male
,-----------.   1 GND       6 NC
\ 1 2 3 4 5 /   2 5V        7 BTN
 \ 6 7 8 9 /    3 GND       8 Y
  `-------'     4 X         9 Y
                5 X

Atari

https://wiki.techtangents.net/wiki/Atari_520ST#Game_Controller_Support

Atari ST mouse DE-9 plug/female
,-----------.   1 X         6 LEFT
\ 5 4 3 2 1 /   2 X         7 5V  
 \ 9 8 7 6 /    3 Y         8 GND
  `-------'     4 Y         9 RIGHT
                5 MIDDLE

Amiga

https://allpinouts.org/pinouts/connectors/input_device/mouse-joystick-amiga-9-pin/

Amiga mouse DE-9 plug/female
,-----------.   1 V         6 LEFT
\ 5 4 3 2 1 /   2 H         7 5V
 \ 9 8 7 6 /    3 VQ        8 GND
  `-------'     4 HQ        9 RIGHT
                5 MIDDLE

Resources

SmallyMouse2

https://www.waitingforfriday.com/?p=827

Clone this wiki locally