JOY (BASIC 3.5)

From C64-Wiki
(Redirected from JOY)
Jump to navigationJump to search
BASIC keyword
Keyword: JOY
Abbreviation: J Shift+O
Type: Function
Token code: 207/$CF
Handling routine
in BASIC ROM:
33283-33356
$8203-$824C
List of all BASIC keywords


Remark: This article describes the BASIC function JOY in Commodore BASIC V3.5 or higher.

Type: Numeric Function 
General Programming-Syntax: JOY(<numeric-expression>)

The JOY command is a BASIC v7 function, used for reading the status of the joysticks.

The numeric expression must be 1 or 2, referring to the two joystick ports. Using any other number generates an ?ILLEGAL QUANTITY ERROR.

The output of JOY is different from the old PEEK 56320/56321 statements- JOY returns 0 when no button is pressed, or one of the following:


8
UP
1

2
LEFT
7
RIGHT
3

6
DOWN
5

4

The most-significant bit is also activated when the fire button is pressed, so fire-down alone returns 128, or 128 added to the numbers above.


Examples[edit | edit source]

? JOY(2)

Printing out position of joystick in port 2 on screen.

5 J1=JOY(1)
6 IF J1>=128 THEN J1=J1-127+8
7 ON J1 GOSUB 11,12,13,14,15,16,17,18,20,21,22,23,24,25,26,27,28
8 GOTO 5
11 PRINT "N" : RETURN
12 PRINT "NO": RETURN
13 PRINT "O" : RETURN
14 PRINT "SO": RETURN
15 PRINT "S" : RETURN
16 PRINT "SW": RETURN
17 PRINT "W" : RETURN
18 PRINT "NW": RETURN
20 PRINT "FIRE": RETURN
21 PRINT "FIRE + N ": RETURN
22 PRINT "FIRE + NO": RETURN
23 PRINT "FIRE + O ": RETURN
24 PRINT "FIRE + SO": RETURN
25 PRINT "FIRE + S ": RETURN
26 PRINT "FIRE + SW": RETURN
27 PRINT "FIRE + W ": RETURN
28 PRINT "FIRE + NW": RETURN

Never ending joystick routine for all 18 positions of the joystick in port 1 (break with RUN/STOP ).


BASIC V3.5 Commands

ABS | ASC | ATN | AUTO | BACKUP | BOX | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLLECT | COLOR | CONT | COPY | COS | DATA | DEC | DEF | DELETE | DIM | DIRECTORY | DLOAD | DO | DRAW | DS | DS$ | DSAVE | END | EL | ELSE | ER | ERR$ | EXIT | EXP | FN | FOR | FRE | GET | GET# | GETKEY | GOSUB | GOTO | GRAPHIC | GSHAPE | HEADER | HELP | HEX$ | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOCATE | LOG | LOOP | MID$ | MONITOR | NEW | NEXT | ON | OPEN | PAINT | PEEK | POKE | POS | PRINT | PRINT USING | PRINT# | PUDEF | RCLR | RDOT | READ | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RLUM | RND | RUN | SAVE | SCALE | SCNCLR | SCRATCH | SGN | SIN | SOUND | SPC | SQR | SSHAPE | STOP | STR$ | SYS | TAB | TAN | TRAP | TROFF | TRON | UNTIL | USR | VAL | VERIFY | VOL | WHILE | WAIT