# Joystick MZ-1X03

Operating instructions

## How to connect  Check to be sure that power to the MZ-700 series unit as well as to the peripheral equipment are all OFF.

Remove the cover on the Joy Stick connector located on the left side of the rear panel of the MZ-700 unit. Save the cover, and attach again when disconnecting the cable.

With the projection facing up, connect the cable to either the left or right connector. If both connectors are connected, 2 Joy Sticks can be used simultaneously.

## Functions related to the Joy Stick

The function JOY is completely defined in the S-Basic for the MZ-700 series.

Format: JOY ( n )
n: integer from 0 to 7
Example: M = JOY ( I )
N = JOY ( B )
Function: Inputs data from the Joy Stick
 There are 2 types of input data: For argument n, 0 – 3 Stick position meaning 0 value of the X-axis of stick 1 1 value of the Y-axis of stick 1 2 value of the X-axis of stick 2 3 value of the Y-axis of stick 2 Value of function JOY ( n ) ranges 0 – 255 For argument n, 4 – 7 State meaning 4 state of SW1 of stick 1 5 state of SW2 of stick 1 6 state of SW1 of stick 2 7 state of SW2 of stick 2 Values of function JOY ( n ) 0 switch is in OFF state -1 switch is in ON state

## Program Examples

### Program A

A program which moves the character in the direction the Joy Stick is moved. ( One space is left opened on the right edge of the screen. ) This is an example for stick 1. To use this example for stick 2, change the argument of the JOY function in lines 20 and 30. ( 0 to 2, 1 to 3 )

```   10 PRINT " "
20 X=INT(JOY(0) / 6.5)
30 Y=INT(JOY(1) / 10.6)
40 IF X=39 THEN X=38
50 CURSOR X,Y
60 PRINT " ";
70 FOR A=0 TO 20:NEXT
80 CURSOR X,Y
90 PRINT " ";
100 GOTO 20```

### Program B

This is a program which takes the input from the Joy Stick to correspond to a semi-graphic display on the screen.

If SW1 or SW2 is pressed, the color of the dot changes in sequence from 1 to 7. To use this example for stick 2 ( connected to the right connector ), change B = 0 in line 10 to B = 2.

```   10 B0=:C=1:F=1:COLOR ,,7,0:PRINT " "
20 JX=INT(JOY(B) / 3.2)
30 JY=INT(JOY(B+1) / 5.2)
40 SET JX,JY,C
50 CURSOR 2,2:PRINT JX,JY,C,
60 IF(JOY(B+4))+(JOY(B+5)) GOTO 80
70 F=0:GOTO 20
80 IF F=0 GOSUB 100
90 GOTO 20
100 F=1:C=C+1:IF C=8 THEN C=0
110 RETURN```

### Program C

This is a program which takes the input from the Joy Stick to correspond to a semi-graphic display on screen. If SW1 is pressed, the color of the dot changes in sequence from 1 to 7. If SW2 is pressed, the set and reset mode of the dot changes. If SW2 is pressed while SW1 is being pressed, and then if SW1 is released, the screen clears. To use this example for stick 2 ( connected to the right connector ), change B = 0 in line 10 to B = 2.

```   10 B=0:F=1:COLOR ,,7,0:PRINT " "
20 JX=INT(JOY(B) / 3.2
30 JY=INT(JOY(B+1) / 5.2
40 SET JX,JY,C
50 CURSOR 2,2:PRINT JX,JY,F,
60 IF JOY(B+4) GOSUB 100
70 IF JOY(B+5) GOSUB 130
80 IF F THEN RESET JX,JY
90 GOTO 20
100 W=B+4:GOSUB 150:IF JOY(B+5) THEN PRINT " ":GOTO    140
110 C=C+1:W=B+4:IF C=8 THEN C=0
120 GOTO 150
130 F=(F=0)
140 W=B+5
150 IF JOY(W) THEN 150
160 RETURN```

### How to use at machine language level A machine language program example is given which reads the state of the Joy Stick. The program given here reads the position of sticks 1 and 2, as well as the state of SW1 and SW2. The program is given as a subroutine.

It is assumed that this program will be used as a subroutine. The result is returned to register A. If the switch is pressed, the subroutine returns a value other than 0 to register A. This program can be used in the address range of \$0000 to \$CFFF. It can be used beyond \$D000 only in the V-RAM mode. You can download this program ( 4KB ), it contains the assembler input and output, and a MZF-formatted file.