DIY - PS2 mouse AMX and Marconi adapter for BBC Compact

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
aotta
Posts: 21
Joined: Fri May 26, 2017 8:57 am
Location: Italy

DIY - PS2 mouse AMX and Marconi adapter for BBC Compact

Postby aotta » Sun Jul 30, 2017 12:42 pm

After reading the great Marek'sproject on his blog about an "acorn-arduino-ps2-mouse-adapter", i decided to adapt his project for my Olivetti Prodest PC128S (The italian version of the Master Compact), adding a nice feature: if resetting the adapter while pressing the left mouse button, it will work as "AMX compatible" mouse, in default mode, it acts like a Marconi/BBC standard mouse.
Here the arduino files and some pics of my works:

Code: Select all

/*
 * ps2.h - a library to interface with ps2 devices. See comments in
 * ps2.cpp.
 * Written by Chris J. Kiick, January 2008.
 *
 * Release into public domain.
 */

#include "ps2.h"

/*
 * an arduino sketch to interface with a ps/2 mouse.
 * Also uses serial protocol to talk back to the host
 * and report what it finds.
 */

//--> 9-pin mini DIN  Arduino
//Pin 1 Pin 8 (XREF)
//Pin 2 Pin 2 (Switch 1)
//Pin 3 Pin 3 (Switch 2)
//Pin 4 GND
//Pin 5 Pin 7 (XDIR)
//Pin 6 5V
//Pin 7 Pin 10 (YREF)
//Pin 8 Pin 4 (Switch 3)
//Pin 9 Pin 9 (YDIR)


//--> PS/2 female connector Arduino
// CLK Pin 6
// DATA  Pin 5
// 5V  5V
// GND GND

int AMX = 0;
int xrot = 0;
int yrot = 0;

int MBUTTON1 = 2; //XDIR for AMX
int MBUTTON2 = 3;
int MBUTTON3 = 4; //YDIR for AMX
int XDIR = 7; //
int XREF = 8;
int YDIR = 9;
int YREF = 10;

/*
 * Pin 5 is the mouse data pin, pin 6 is the clock pin
 * Feel free to use whatever pins are convenient.
 */
PS2 mouse(6, 5);

/*
 * initialize the mouse. Reset it, and place it into remote
 * mode, so we can get the encoder data on demand.
 */
void mouse_init()
{
  char mstat;
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
 
 
  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mouse.read();      // ignore ack
  mouse.read();      // ignore ack

  /* if left button is pressed while initializing, AMX mode is setted of and the right ports assigned  */
  if (mstat & 0b001) {
    AMX=1;
    MBUTTON1=8; // Button Left
    MBUTTON2=10; // Button Middle
    MBUTTON3=4; // Button Right
    XDIR=7; // 7 ok
    XREF=2;  // OK 2
    YDIR=9; //  ok 9
    YREF=3; // ok 3 
 
  /*int MBUTTON1 = 2; //XDIR for AMX
    int MBUTTON2 = 3;
    int MBUTTON3 = 4; //YDIR for AMX
    int XDIR = 7; //
    int XREF = 8;
    int YDIR = 9;
    int YREF = 10; */
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level);
    delayMicroseconds(300);
    digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level);
    delayMicroseconds(100);
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level);
    delayMicroseconds(300);
    digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level);
  }
 
}

void setup()
{
  Serial.begin(9600);
    // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(XREF,OUTPUT);
  pinMode(YREF,OUTPUT);
  pinMode(XDIR,OUTPUT);
  pinMode(YDIR,OUTPUT);
  pinMode(MBUTTON1,OUTPUT);
  pinMode(MBUTTON2,OUTPUT);
  pinMode(MBUTTON3,OUTPUT);
 
  mouse_init();
}

/*
 * get a reading from the mouse and report it back to the
 * host via the serial line.
 */
void loop()
{
  char mstat;
  char mx;
  char my;

  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();

  /* send the data back up */
  /* 
  Serial.print(mstat, BIN);
  Serial.print("\tX=");
  Serial.print(mx, DEC);
  Serial.print("\tY=");
  Serial.print(my, DEC);
  Serial.println();
   */
 
  if (mstat & 0b001) {
    digitalWrite(MBUTTON1, LOW);
    // poi via
    digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level);
   
  }
  else {
    digitalWrite(MBUTTON1, HIGH); 
    digitalWrite(LED_BUILTIN, HIGH);
  }

  if (mstat & 0b010) {
    digitalWrite(MBUTTON2, LOW);
  }
  else {
    digitalWrite(MBUTTON2, HIGH);   
  }

  if (mstat & 0b100) {
    digitalWrite(MBUTTON3, LOW);
  }
  else {
    digitalWrite(MBUTTON3, HIGH);   
  }

 
 // delay(20);  /* twiddle */

/* Destra e su: */
  if (mx > 0) {
    if (xrot == 0) xrot = 1;
    else if (xrot == 1) xrot = 3;
    else if (xrot == 3) xrot = 2;
    else if (xrot == 2) xrot = 0;
  }

  if (my > 0) {
    if (yrot == 0) yrot = 1;
    else if (yrot == 1) yrot = 3;
    else if (yrot == 3) yrot = 2;
    else if (yrot == 2) yrot = 0;
  }

  /* Sinistra e giù: */
   if (mx < 0) {
    if (xrot == 2) xrot = 3;
    else if (xrot == 3) xrot = 1;
    else if (xrot == 1) xrot = 0;
    else if (xrot == 0) xrot = 2;
  }

  if (my < 0) {
    if (yrot == 2) yrot = 3;
    else if (yrot == 3) yrot = 1;
    else if (yrot == 1) yrot = 0;
    else if (yrot == 0) yrot = 2;
  }

  /* Encoding  most significant byte (MSB) to the REF signal and the least significant byte (LSB) to the DIR signa */

  if (xrot & 0b01) {
    digitalWrite(XDIR, HIGH);
    }
  else {
    digitalWrite(XDIR, LOW);
  } 

  if (xrot & 0b10) {
    digitalWrite(XREF, HIGH);   
  }
  else {
    digitalWrite(XREF, LOW);
  } 

  if (yrot & 0b01) {
    digitalWrite(YDIR, HIGH);   
  }
  else {
    digitalWrite(YDIR, LOW);
  } 

  if (yrot & 0b10) {
    digitalWrite(YREF, HIGH);
  }
  else {
    digitalWrite(YREF, LOW);       
  } 

 
}

my work finished and glued..
Inside.jpg


..connected to an optical usb mouse...
adapt1.jpg


..and using with Welcome disk!
welcomedisk.jpg


And AMX super ART too! :)
AMXSuperart.jpg


p.s.: for the AMX emulation, i had to add 3 wires on the user 6522, since some pin aren't connected to DB9 port: i connected pin 11 to 16, 13 to 15 and and 14 to 17.
And, in AMX mode, only left button works... maybe next days i'll find a solution, or someone of you will do

Return to “hardware”

Who is online

Users browsing this forum: Bing [Bot] and 10 guests