Use ~10€ to connect modern mouse to MSX

Page 1/19
| 2 | 3 | 4 | 5 | 6


Enlighted (6129)

NYYRIKKI's picture

27-10-2013, 18:32


Now this is DIY again, but very easy one. This requires only minimal to none soldering skills / other hardware experience.

Required hardware:
- Arduino (I used UNO R3 that costs about 7-8€ including required USB-cable for programming)
- PS/2 or USB-connector (look nearby dumpster)
- Old PS/2 or USB-mouse (-"-)
- Joystick connector & cables

Why? Because MSX-mice are getting rare & expensive and this is practically only way to get modern optical mouse for MSX. Compared to native MSX-mice this has also some advantages like possibility to adjust the resolution on the fly.
Running Naked in a Field of Flowers

See here picture of device put together:

Here is software & all the needed instructions:

   //  PS/2-mouse to MSX v1.0 //
  //  Made By: NYYRIKKI 2013 //

   Press reset = Mouse mode
   Press reset & hold right mousebutton down = Joystick emulation
   Press reset & hold left mousebutton down = Mouse + Joystick emulation *
   If you have mouse with a scrolling wheel (optional) you can use the
   wheel to adjust speed of mouse and/or sensitivity of joystick.
   If status LED does NOT blink check your PS2-mouse connection and press reset.

   (*) Please note: This mode might cause problems with some of the existing software.

  // As of Arduino 1.0 should be unpacked into arduino/libraries.
  // In ps2.h replace "WProgram.h" with "Arduino.h".

 // HW Connection instructions: //

// PS/2 connector: (Female)   USB-connetor: (Female)
//           1 2                    ---------
//          3   4                  | 4 3 2 1 |
//           5|6                    -=======-
//        Mini-DIN-6F                 USB-AF
//            (Both looking from outside)
// Connecting PS2: 
// pin 1 -> DATA
// pin 3 -> GND
// pin 4 -> +5V
// pin 5 -> CLK

// Define Arduino pins used in format: CLK , DATA

  PS2 mouse(11, 10);  
// If you use USB-connector, connect:
// pin 1 -> +5V
// pin 2 -> DATA
// pin 3 -> CLK 
// pin 4 -> GND
// Usually USB-mice that are produced before 2010 support PS/2 protocol out of the box.
// Connecting Joystick:
//  MSX-connector : Arduino pin
//     (DB9F)
  #define JoyPin1 2
  #define JoyPin2 3
  #define JoyPin3 4
  #define JoyPin4 5
  //      JoyPin5 +5V (N/C or power)
  #define JoyPin6 6
  #define JoyPin7 7
  #define JoyPin8 8
  //      JoyPin9 GND (Connect to Arduino GND)
  #define InfoPin 13 // Status LED


// Variables
  char rx=0,ry=0,rz=0,x=0,y=0,mx=0,my=0,jx=0,jy=0,scale=15,MouseID=0,EmuMode=0;
  char olimit=60, ilimit=50, solimit=0, silimit=0, mstat=0, StatCnt=0;
  long time; // No C

void mouse_init()
  mouse.write(0xff);   // reset;        // ack byte;        // Self-test passed;        // Mouse ID
  mouse.write(0xf0);   // remote mode;        // ack
  mouse.write(0xeb);   // give me data!;        // ignore ack
  EmuMode = & 3; // Read Emulation mode from buttons
  if (EmuMode==3) EmuMode=0;;        // ignore X;        // ignore Y
  mouse.write(0xf3);   // Set sample rate;        // ack
  mouse.write(200);    // Max sample rate;        // ack  
  mouse.write(0xf3);   // Set sample rate;        // ack
  mouse.write(100);;        // ack  
  mouse.write(0xf3);   // Set sample rate;        // ack
  mouse.write(80);;        // ack  
  mouse.write(0xf2);   // Get device ID;        // ack
  MouseID =;   // Mouse ID
  mouse.write(0xf3);   // Set sample rate;        // ack
  mouse.write(200);    // Max sample rate;        // ack  
  mouse.write(0xe8);   // Set Resolution;        // ack
  mouse.write(2);      // 4 counts/mm;        // ack  

void setup()

  Serial.print("\n\nPS/2-mouse to MSX-mouse converter for Arduino\n");
  Serial.print("Made By: NYYRIKKI 2013\n\n");
  Serial.print("Initializing PS/2 mouse...");
  Serial.print("Ok\n\nI'm a ");
  switch (EmuMode) {
    case 0: Serial.print ("mouse!");
    case 1: Serial.print ("mouse & joystick hybrid!");
    case 2: Serial.print("joystick!");

void loop()
  if (StatCnt==50) StatCnt=0;
  mouse.write(0xeb);    // give me data!;         // ignore ack
  mstat =; // Read buttons

  rx =;
  ry =;  

  if (MouseID==3) {;
    if (scale<5) scale=5;
    if (scale>25) scale=25;
  if(mstat&1) pinMode(JoyPin6,OUTPUT); else pinMode(JoyPin6,INPUT);
  if(mstat&2) pinMode(JoyPin7,OUTPUT); else pinMode(JoyPin7,INPUT);
  if (EmuMode==0 | EmuMode==1) {  // Mouse emulation 
    mx = mx-rx;
    my = my+ry;

    sendMSX(x);  //-X
    sendMSX(y);  //-Y
    if (millis()time) break;};

  if (EmuMode==2 | EmuMode==1){   // Joystick emulation

    if (StatCnt<40) digitalWrite(InfoPin,LOW); else digitalWrite(InfoPin,HIGH);
    if (digitalRead(JoyPin8)==LOW) {

      if (jy>solimit) jy=solimit;
      if (jy<-solimit) jy=-solimit;
      if (jx>solimit) jx=solimit;
      if (jx<-solimit) jx=-solimit;
      if (jy>silimit)  pinMode(JoyPin1,OUTPUT); else pinMode(JoyPin1,INPUT);
      if (jy<-silimit) pinMode(JoyPin2,OUTPUT); else pinMode(JoyPin2,INPUT);
      if (jx>silimit)  pinMode(JoyPin3,OUTPUT); else pinMode(JoyPin3,INPUT);
      if (jx<-silimit) pinMode(JoyPin4,OUTPUT); else pinMode(JoyPin4,INPUT);
    } else JoyHigh();

void sendMSX(char c)
    while (digitalRead(JoyPin8)==LOW) {if (millis()>time) return;};
    if(c&128) pinMode(JoyPin4,INPUT); else pinMode(JoyPin4,OUTPUT);
    if(c&64)  pinMode(JoyPin3,INPUT); else pinMode(JoyPin3,OUTPUT);
    if(c&32)  pinMode(JoyPin2,INPUT); else pinMode(JoyPin2,OUTPUT);
    if(c&16)  pinMode(JoyPin1,INPUT); else pinMode(JoyPin1,OUTPUT);
    while (digitalRead(JoyPin8)==HIGH) {if (millis()>time) return;};
    if(c&8)   pinMode(JoyPin4,INPUT); else pinMode(JoyPin4,OUTPUT);
    if(c&4)   pinMode(JoyPin3,INPUT); else pinMode(JoyPin3,OUTPUT);
    if(c&2)   pinMode(JoyPin2,INPUT); else pinMode(JoyPin2,OUTPUT);
    if(c&1)   pinMode(JoyPin1,INPUT); else pinMode(JoyPin1,OUTPUT);
void JoyHigh()
Login or register to post comments

By AxelF

Champion (398)

AxelF's picture

27-10-2013, 19:37

WOW this is awsome ..

It would be nice to make this project a standalone (without the UNO).
The ATmega168 needs very few components to run, and can be powered by the MSX Gameport.


Enlighted (6129)

NYYRIKKI's picture

27-10-2013, 20:31

@AxelF: The code should run on ATmega168 without any modifications, so if you like soldering, then go ahead. That is so small chip, that you can even mount it inside a mouse if you like. Smile

BTW the codebox seems to cut off parts of the code again, so better to download it instead... (Click here to download.)

By rogermm

Master (130)

rogermm's picture

27-10-2013, 21:23

We have plans to use the ARM and USB host interface on MSXARM( to connect modern USB mouse on MSX. Demos source code (using USB mouse) exists(like Arduino) for MSXARM ARM chip.
We will need to work on integration with the MSX(like you do). The rule in the project is: less hardware + more functionality(devices) = cheap & less complexity. Anyways this is a interesting project

By sd_snatcher

Prophet (3687)

sd_snatcher's picture

27-10-2013, 22:40

Excellent initiative, NYYRIKKI!

Here in Brazil we use the MSXpro/Anikun adapter. Do you know if your code would run in the 16F628A PIC it uses?

Some suggestions for your code:

1) Use clipping when doing math on the offsets. This allows the current optical mice, that have a much higher resolution than the original MSX mice, to be supported properly

2) Add support for the MSX-Trackball protocol too. This would allow the HAL software that only support trackballs also to be supported.


Enlighted (6129)

NYYRIKKI's picture

27-10-2013, 22:58

sd_snatcher wrote:

Here in Brazil we use the MSXpro/Anikun adapter. Do you know if your code would run in the 16F628A PIC it uses?

No, that is totally different thing.

Anyway very good improvement ideas and quite easy to implement...


Enlighted (6129)

NYYRIKKI's picture

28-10-2013, 06:41

If you like to save some money/space and build this without the Arduino UNO R3, then I think this would be quite a good option... Saves you also some money as this costs < 4€


Paladin (864)

WORP3's picture

28-10-2013, 08:49

It should even be possible to place it all inside a DB9 connector. You know something like this:

Taking a very small AVR chip and run it directly on the MSX 5V and on it's internal oscillator should make it very small.

By Jupp3

Resident (41)

Jupp3's picture

28-10-2013, 19:49

How about adding a male DB9 connector for joystick, and make it also work as mouse / joystick switcher? Way more popular on Amigas (where mouses are more widely used / needed), usually they work so, that whenever you click joystick button, it goes to joystick mode, and on mouse button to mouse mode. I guess there should be a safe way to do that in hardware on MSX aswell.

Of course this could also be updated to work as an adapter for USB joysticks, although I guess most users prefer proper atari-style sticks. Only benefit would be that it's easier to find one with >1 button Smile

Only missing emulation of C64 and Amiga mice, and we would have an Individual Computers Micromys killer. I bet the casing would look better in any case Tongue

(Okay, the latest version doesn't look quite THAT bad...)

Is the joystick mode like Commodore 1350 btw? (basically movement speed determines how often certain direction gets triggered)


Enlighted (6129)

NYYRIKKI's picture

29-10-2013, 15:46

Jupp3 wrote:

How about adding a male DB9 connector for joystick, and make it also work as mouse / joystick switcher?

That is very easy to do and you don't even need to add switch. It seems that mouse & joystick can live at the same time at the same port. (See source) You can connect joystick buttons (pins 6 & 7) in paraller with arduino and select 4 Arduino pins for directional input (joystick pins 1-4) Then modify the joystick input routine to pass the pin statuses trough. Please note how ever that current code does not work at all if PS/2 mouse is not connected.


Is the joystick mode like Commodore 1350 btw? (basically movement speed determines how often certain direction gets triggered)

No, that would not work very well on most games. The joystick emulation has just virtual box (you can alter the box size with wheel) where you can move the invisible cursor. When you are near the edge of a box the direction gets triggered and it stays triggered until you move the mouse cursor away from the edge.

By Jupp3

Resident (41)

Jupp3's picture

30-10-2013, 14:27


No, that would not work very well on most games.

I know. The fact is, though, there's NO way to do it properly. Joystick games are meant to be played with joysticks. It works the best on games, where the movement seems to be a bit too fast on joystick normally.

It works somehow, whenever you can change the movement speed, and disable any "acceleration", if any. As you probably know, next to no games support doing that, but many programs do (some of which support "real" mouse protocol anyway)

Still, that's how Commodore did that with first mouse (1350), on the next one (1351) it was already "secondary function".

Anyway, need to test that code on Roland S-330 some day Smile

Page 1/19
| 2 | 3 | 4 | 5 | 6