From SpecNext official Wiki
Jump to: navigation, search

The Spectrum Next has a PS/2 port for connecting a PS/2 keyboard or mouse (or both via a splitter).

WARNING: Do not plug in or remove PS/2 devices with the power on.

A USB mouse plugged in via a USB-to-PS/2 converter will only work if the mouse itself supports the PS/2 protocol.

PS/2 Port and modes of operation

The "ps2" setting in the /machines/next/config.ini file determines the PS/2 port mode:

PS2=0 is KEYBOARD mode where a PS/2 keyboard is plugged into the Next, or with a splitter you can use both a mouse and a keyboard.

PS2=1 is MOUSE mode where the mouse should be plugged in directly. Do not use a splitter in this mode as it can have funny effects.

You can set this on boot by holding down SPACE, then pressing "E" to edit, moving down to "PS2" with the down arrow, and changing from Keyboard to Mouse with the right arrow.

You can use the "ps2mode" dot command to see which mode is active. The best place to set the value is in the tbblue .ini file, but if you start in the wrong mode then on the Next (or a membrane) keyboard you can type ps2mode -m to select MOUSE or ps2mode -k to select KEYBOARD.


The NextZXOS distribution includes a mouse driver from version 1.95 onwards.

All you need is the file MOUSE.DRV in the NextZXOS folder. The mouse can then be used from BASIC with the new DRIVER command.

This mouse driver is driver number 126. There will be a supported list of driver codes and any that use streams (this does not) will need to be allocated one from 65-90/A-Z or the lower case range (or both) so this avoids that area.

The driver is stopped and started with the 'install' and 'uninstall' DOT commands in the BIN directory:

.install /nextzxos/mouse.drv

Sample BASIC programs

There is a demo program called NXMOUSE.BAS that uses Sprite and Text features for you to play with (in the /demos/mouse folder). The NXMOUSET.BAS program uses some of the features of the sprite cursor and lets you play with acceleration settings in Timex HiRes mode.

They both use sprites from the BREAKOUT test but, you can change line 300 to load any set you wish. Note that if you hold the 's' button and move it around at times the sprite cursor will seem to disappear - that is because you have reached the maximum 12 sprites per display line.

You could modify the code to remove the tail of previously used sprites if you want but, it is quite fun to play with.

Mouse Driver API

DRIVER supports the following parameters:

DRIVER 126,1 TO %b,x,y

This will get the current location of the mouse on a 192 x 640 grid with 0,0 in the top left of the outer border where sprites can go. It uses the higher X number to allow use in Timex mode where there are twice as many horizontal pixels.


will be the three buttons bit activated in combination so 1,2,4 or 3,5,6,7 for combinations.


will be the current value of the wheel mouse from 0 to 15.

DRIVER 126,2{,sprite{,pattern}}

The optional sprite number 0-63 and pattern number 0-63 will default to 0. This will cause that sprite to always be displayed (anywhere that clipping is not in effect) at the current X,Y coordinate - over a Timex screen it will sit between two pixels of course.

DRIVER 126,3

Will disable the sprite cursor.

DRIVER 126,4{,attribute}

will display an attribute based character cursor using the ULA attributes - this will cope with some screen changes but, not scrolling so remember to disable it when changing the screen wholesale.

So using the new features of NextOS to include a binary number (@) in an integer statement (%)

DRIVER 126,4,%@11100111

Will set a Bright, Flashing, Green and White cursor. The first two 1's are Bright and Flash the next two groups of three are the paper and ink:


- where T=Bright.

DRIVER 126,5

will remove the Attribute based cursor.

DRIVER 126,6,x_threshold

Where x_threshold is forced to be in the range 0-255 by using LSB only:

  • 0 Means always accelerate the X direction
  • 255 Means never accelerate the X direction

By default x_threshold is set at 32 which will trigger more rapid movement if you move the mouse quickly. You can adjust to suit your own preference.

The Y does not have the option as 0-192 pixels probably would not benefit but, it is not ruled out and you have the source to hack...


Based on the distribution readme by Tim Gilberts.