home *** CD-ROM | disk | FTP | other *** search
- Program Joystick;
- Var
- I : integer;
- Temp : byte;
-
- Function ButtonPressed(WhichOne: Char):Boolean; {True if button pressed}
- Const
- Joyport = $201; {Location of the game port}
- Var
- Mask : Byte;
- Begin
- If not (WhichOne in ['A'..'D']) then WhichOne := 'A';
- Case WhichOne of
- 'A' : Mask := 16;
- 'B' : Mask := 32;
- 'C' : Mask := 64;
- 'D' : Mask := 128;
- end;
- ButtonPressed := (Port[Joyport] and Mask) = 0;
- End; {ButtonPressed}
-
- Function JoystickPos(WhichOne : Char): integer;
- {With a kraft joystick, values returned are in the range of 4 to
- about 140. If your machine runs faster than a standard IBM PC or
- if you modify your game adapter card with bigger capacitors, you
- will get larger counts and you must modify "MaxCount". Calling
- a joystick that is not in use or one that has gone over range (count
- reached maxcount) yields a value of 0. }
- Const
- Maxcount = 500; {Modify this if you can get longer counts}
- Joyport = $201; {Location of game input port}
- Var
- Counter : integer;
- Mask : byte;
- Begin
- If not (WhichOne in ['A'..'D']) then WhichOne := 'A';
- Case WhichOne of
- 'A' : Mask := 1;
- 'B' : Mask := 2;
- 'C' : Mask := 4;
- 'D' : Mask := 8;
- end;
- {This assembly code causes the CX register to count down from MAXCOUNT
- toward zero. When CX reaches zero or when the one-shot on the game
- adapter times out, the looping stops and counter is assigned the
- number of counts that took place. MAXCOUNT should be chosen so that CX
- never reaches 0 so that the usable range of the joystick will not be
- limited. }
- InLine(
- $B9/MAXCOUNT/ { MOV CX,MAXCOUNT Initialize down counter}
- $BA/JOYPORT/ { MOV DX,JOYPORT Port address of Joysticks}
- $8A/$A6/MASK/ { MOV AH,MASK[BP] Mask for desired one-shot}
- $EE/ { OUT DX,AL Start the one-shot}
- $EC/ {Read: IN AL,DX Read the one-shot}
- $84/$C4/ { TEST AL,AH Check desired one-shot}
- $E0/$FB/ { LOOPNZ READ Repeat until timed out}
- $89/$8E/COUNTER); { MOV COUNTER[BP],CX This makes CX available to turbo}
- If Counter = 0 then
- JoystickPos := 0 {Over range or not in use}
- else
- JoystickPos := Maxcount - Counter;
- End; {JoystickPos}
-
- Begin {********* Demo Program Main Code *********}
- ClrScr;
- GotoXY(1,2);
- Writeln('Joysticks':10, 'Buttons':10);
- Write('A':5, 'B':5, 'A':5, 'B':5);
- While True do {Press CTRL-C to stop the program}
- Begin
- GotoXY(1,5);
- Write(JoystickPos('A'):5, JoystickPos('B'):5);
- If ButtonPressed('A') then
- Write('Pres':5)
- else
- Write('Up':5);
- If ButtonPressed('B') then
- Write('Pres':5)
- else
- Write('Up':5);
- End;
- END.