MSX mouse implementation in BASIC

By Eugeny_Brychkov

Paragon (1097)

Eugeny_Brychkov's picture

24-08-2018, 13:29

Looking to the documentation I can not understand how to properly detect the availability of the mouse.

The problem is that I use PAD(12), PAD(13) and PAD(14), and if mouse is connected, these give correct values according to mouse movements, however if mouse is not in there, PAD(13) and PAD(14) always return 1, making cursor moving right bottom!

Is there any proper way to solve this issue?

Only one way comes to mind is to quickly poll them for a second, seeing if their values are 1s. If they always are, assume no mouse. Practically there's very small probability that user will move mouse within a second and it will always report only 1 dot of movement into right bottom direction.

Login or register to post comments

By sd_snatcher

Prophet (3068)

sd_snatcher's picture

24-08-2018, 14:36

In BASIC, use a timeout counter. You can use the TIME variable to help you with that.

If the mouse has consecutively returned only ones in both axes for more than 1 second, you can consider that the mouse was disconnected, because in real world no human can trace such a steady line for so long, specially given the noisy nature of the analog part of the circuit.

By Eugeny_Brychkov

Paragon (1097)

Eugeny_Brychkov's picture

24-08-2018, 18:19

160 TIME=0
170 A=PAD(12):IF PAD(13)<>1 OR PAD(14)<>1 THEN MD=1:GOTO190
180 IF TIME<60 THEN 170 ELSE MD=0
190 ...

Now part of my Heroes III for MSX demo.

By NYYRIKKI

Enlighted (5385)

NYYRIKKI's picture

25-08-2018, 11:02

If there is something like joystick that is pressed to some direction the PAD may return other weird values as well. How about something like this:
M=12:FORI=0TO20:A=PAD(M):IF(PAD(13)OR(PAD(14))>0THENM=MXOR28:NEXTI:M=0

By NYYRIKKI

Enlighted (5385)

NYYRIKKI's picture

25-08-2018, 12:47

Damn typo:
M=12:FORI=0TO20:A=PAD(M):IF(PAD(13)OR(PAD(14))<>0THENM=MXOR28:NEXTI:M=0
Idea is that if you read fast enough you should get 0
...then you can do something like:
IFMTHENA=PAD(M):X=X+PAD(13):Y=Y+PAD(14)