• Aucun résultat trouvé

David A. Dunn

Dans le document 64/128 (Page 112-117)

Did you ever playa good game that would have been even better

if

it offered joystick instead of keyboard controls? Here's a solution. For the Commodore 64 and

128 in 64 mode.

Back in the days of the PET ICBM there was no way to hook up a joystick, so we all got pretty good at playing games using the keyboard. But it often became confusing: One game's con-trolling keys were different from another's. The addition of a joystick port on Commodore machines was more than wel-come. But I still play some of the older games that require keyboard control and occasionally still find a program or two that insists that you use the keyboard.

I wrote "Keyboard to Joystick Converter" as a solution to this problem. It allows you to use a joystick with Commodore 64 and 128 programs that don't provide joystick control.

Plan A or Plan B?

Type in Program 1 and save a copy before running it. Al-though it's written in BASIC, it includes a machine language routine in the form of DATA statements. When you run the program, it asks you to choose plan A or plan B. By making this selection you determine where in memory to put the ma-chine language to avoid interference with the main program.

Plan A uses the cassette buffer. Plan B uses the free area at 758-767. For most programs, plan A works fine, although you should avoid this option if you're using a Datassette. If plan A doesn't work, rerun the program and select plan B.

You're next asked to enter the keys corresponding to each direction and the fire button for each joystick port. Let's say a program requires you to press the

J

key to move left and the K key to move right. When Keyboard Converter asks you to

104

• •

• •

• •

• •

• •

• •

• •

• •

• •

• •

• •

I.

INPUT jOUTPUT ROUTINES

press the key for left, press J. Next, you're asked to press the key for right. Press K. If there's no need for the joystick to move in a particular direction, just press any key.

The Breaks

After you've done this for both joystick ports, the program asks for the maximum break length. Joysticks vary not only in size, shape, and price, but also in quality. Many joysticks make good, solid contact between the wires inside, but some do not. Some lesser quality joysticks will make contact one moment, break contact for a fraction of a second, then make good contact again. This makes the computer think the joy-stick has been moved twice in that direction. In some pro-grams this causes no problem; in others it may.

Keyboard Converter can make up for this deficiency by distinguishing between a break in the contacts and the true re-lease of the joystick. It does so by sensing how long the con-tacts have been broken. Generally, a period of three jiffies (one jiffy equals 1/60 second) or less is a result of a break in the contacts. Any longer than that usually indicates a true re-lease of the joystick.

When Keyboard Converter asks for maximum break length, press RETURN to indicate three jiffies. If you have any problems with repeating movements, you can increase the break length by typing a higher number.

Now move the joystick around. You should see the cor-responding letters on the screen. Now you can load and run a game, and use the joystick instead of the keyboard. Be sure not to press RUN/STOP-RESTORE after running Keyboard Converter-this will disable the joystick.

The program works by modifying the IRQ routine, which is executed 60 times per second. It normally scans the key-board and increments the internal clock. When Keykey-board Con-verter goes into effect, however, the computer scans not only the keyboard, but also the joystick ports. If the joystick has been moved, the code for the corresponding key is placed in the keyboard buffer to simulate a keypress.

A Sample Program

For demonstration purposes, type in Program 2. It's a fast-action game (based on "Worm of Berner," which appeared in

105

CHAPTER 3

the April 1984 issue of COMPUTE! magazine) that uses key-board control. After using Keykey-board Converter, you'll be able to control it with a joystick. makes it increasingly difficult to keep from running over its own tail.

Lines 160-190 determine the direction keys. By modifying the number 2S in line 260, you can change the speed of the game.

Program 1. Keyboard to Joystick Converter

For mistake-proof program entry, use "The Automatic Proofreader," Appendix B, to ty~'e in this program.

KX 10 FORI=1T0168:READA:X=X+A:NEXTI

BC 20 IFX<> 23067THENPRINT " {CLR)TYPING ERROR IN DAT A LINES": STOP

CG 30 RESTORE:TT$=CHR$(142)+CHR$(8)+"{CLR) {RVS) KE YBOARD TO JOYSTICK ":PRINTTT$

MK 40 FORI=828T0856:READA:POKEI,A:NEXT

XC 50 DATA120,169,49,141,20,3,169,234,141,21,3,88, 96

HD 60 DATA165,1,72,41,254,133,1,32 PK 70 DATA27,191,104,133,1,76,126,234 KC 80 FORI=758T0767:READA:POKEI,A:NEXT SC 90 DATA198,1,32,27,191,230,1,76,126,234

PX 100 PRINT" (DOWN) (IF PLAN A DOESN I T WORK, TRY PI.

AN B){2 UP)"

DM 110 PRINT"PLAN A OR B{2 SPACES)A{3 LEFT)";

QD 120 INPUTP$:I=758:IFP$="A"THENI=841

DC 130 POKE835,I/256:POKE830,I-PEEK(835)*256 HA 140 FORI=0T073:POKEI+48923,PEEK(I+59953):NEXT HS 150 FORI=48997T049125:READA:POKEI,A:NEXT JQ 160 DATA169,255,133,203,141,245,191,169,129 AG 170 DATA133,245,169,235,133,246,162,0,142,141 RG 180 DATA2,142,2,220,160,1,169,16,32,186,191

106

• •

XS 190 DATA232,74,144,249,136,16,244,140

PS 200 DATA2,220,173,245,191,201,16,240,35,165 ED 210 DATA203,162,3,157,230,191,189,230,191 EF 220 DATA201,255,208,6,202,16,246,76

EG 230 DATA135,234,133,203,162,0,189,231 HF 240 DATA191,157,230,191,232,224,3,144 DQ 250 DATA245,76,221,234,72,57

QR 260 DATA0,220,208,15,189,246,191,201 AE 270 DATA65,144,10,41,63,13,141,2 QM 280 DATA141,141,2,104,96,197,203,144

XQ 290 DATA7,133,203,104,141,245,191,96,72,165,203 DQ 300 DATA201,255,104,176,241,144,233

GF 310 FORI=49126T049141:POKEI,255:NEXT:FORA=0T04:

READA$ (A) : NEXT

HJ 320 DATAUP,DOWN,LEFT,RIGHT,FIRE EJ 330 FORF=1T07:READF$(F):NEXT

GX 340 DATASHIFT,LOGO,SHIFT+LOGO,CTRL,SHIFT+CTRL,L OGO+CTRL,SHIFT+LOGO+CTRL

FA 350 POKE808,239:PRINTTT$:FORI=0T01:PRINT"JOYSTI CK PORT":I+1

DJ 360 FORA=0T04:PRINT"PRESS KEY FOR ":A$(A):"? ":

QJ 370 K=PEEK(197):F=PEEK(653):IFQTHENIFK<640RFTHE NQ=0:GOT0400

CG 380 IFK=64ANDF=0THENQ=1 ES 390 GOT0370

KR 400 IFK=64THENK=K+F:A$=F$(F):POKE198,0 GA 410 POKE49142+I*5+4-A,K

JR 420 GETG$: IFG$>" "THENA$=G$ : GOT0420 QB 430 IFA$=" "THENA$="SPACE"

CG 440 IFA$=CHR$(13)THENA$="RETURN"

MS 450 POKE216,1:PRINTA$:NEXTA:PRINT:NEXTI:POKE198 ,0

QG 460 PRINT"MAXIMUM BREAK LENGTH? 3{LEFT}"::I=3 HP 470 GETA$:IFA$=CHR$(13)THENPRINT:PRINT:GOT0500 JG 480 IFA$<"0"ORA$>"9"THEN470

DS 490 I=VAL(A$):PRINTA$"{LEFT}"::GOT0470 RF 500 POKE808,237:POKE49047,I:POKE49076,I

QA 510 PRINT"{2 DOWN}ARE YOUR CHOICES SATISFACTORY

? (yiN)"

JD 520 GETA$:IFA$="N"THEN350

XB 530 IFA$="Y"THENSYS828:PRINTCHR$(9): :NEW EF 540 GOT0520

Program 2. Worm (Demo)

For mistake-proof program entry, use "The Automatic Proofreader," Appendix B, to type in this program.

HH 100 POKE53281,6:PRINT"{CLR} {CYN}"TAB(13)"*** HU NGRY LIKE A WORM ***":A=RND(0)

HB 110 POKE53280,0:POKE53281,0:FORI=0T019:POKE1083 -I,160:POKE1084+I,160:NEXTI

107

FR 120

FORI=0T019: POKE198,4+I, 160: POKE2023-I, 160 :NE XTI

PRINTTAB(2)CHR$(l8)"YOU RAN ";

IFP=81THENPRINT"OVER YOURSELF"

IFP=160THENPRINT"INTO A WALL"

PRINT:PRINTTAB(2)CHR$(18)"GAME OVER":END

• •

• •

• •

• •

• •

Dans le document 64/128 (Page 112-117)