Thread View: pl.comp.programming
3 messages
3 total messages
Started by m... Adam Maj
Thu, 08 Feb 1996 00:00
joystick
Author: m... Adam Maj
Date: Thu, 08 Feb 1996 00:00
Date: Thu, 08 Feb 1996 00:00
3 lines
423 bytes
423 bytes
Bylbym bardzo wdzieczny za dostarczenie opisu obslugi joysticka pod Turbo Pascalem. Rafal Maj
Re: joystick
Author: ar... Marcin
Date: Thu, 08 Feb 1996 00:00
Date: Thu, 08 Feb 1996 00:00
134 lines
3325 bytes
3325 bytes
m...@deneb.ifj.edu.pl (Adam Maj) wrote:
>Bylbym bardzo wdzieczny za dostarczenie opisu obslugi joysticka pod
>Turbo Pascalem.
> Rafal Maj
Mam tu cos w moim poltoragigowym skladziku :)
Marcin
{
--------------------------------------------------
File: JOYSTICK.PAS
By: Ronny Wester, ro...@rat.se
Code to read PC sticks.
Written with kind assistance of Christian Wagner.
--------------------------------------------------
}
unit Joystick;
interface
type
JoyRec =
record
present : Boolean;
x, y : Word;
button1,
button2,
button3,
button4 : Boolean;
end;
var
gSticks : array [1..2] of JoyRec;
procedure PollSticks;
procedure InitSticks;
implementation
const
cStickPort = $0201;
{ PollSticks. Run to retrieve current values of sticks.
Only sticks with the present flag set will be polled.
Also see InitSticks below. }
procedure PollSticks;
var b : Byte;
mask : Byte;
laps : Word;
begin
mask := 0;
if gSticks[1].present then
mask := 3;
if gSticks[2].present then
mask := mask or 12;
FillChar( gSticks, SizeOf( gSticks), 0);
laps := 0;
asm cli end;
Port[ cStickPort] := $FF; { Write anything to trigger countdown }
repeat
b := Port[ cStickPort];
if b and 1 <> 0 then
Inc( gSticks[1].x);
if b and 2 <> 0 then
Inc( gSticks[1].y);
if b and 4 <> 0 then
Inc( gSticks[2].x);
if b and 8 <> 0 then
Inc( gSticks[2].y);
Inc( laps);
until (b and mask = 0) or (laps > 60000); { Timeout if no sticks
connected }
asm sti end;
gSticks[1].present := b and 3 = 0;
gSticks[2].present := b and 12 = 0;
if gSticks[1].present then
begin
gSticks[1].button1 := b and 16 = 0;
gSticks[1].button2 := b and 32 = 0;
gSticks[1].button3 := b and 64 = 0;
gSticks[1].button4 := b and 128 = 0;
end;
if gSticks[2].present then
begin
gSticks[2].button1 := b and 64 = 0;
gSticks[2].button2 := b and 128 = 0;
gSticks[2].button3 := b and 16 = 0;
gSticks[2].button4 := b and 32 = 0;
end;
end;
{ Initialization.
Assume both sticks present and do a poll.
The poll routine will clear present flags of non-connected sticks. }
procedure InitSticks;
begin
gSticks[1].present := True;
gSticks[2].present := True;
PollSticks;
end;
end.
*************************************************************
* Marcin Szumiela * ART4 Comp Group * Where any view *
* ar...@pdi.lodz.pl * PC&AMIGA progr. * of Money exists Art *
*------------------*-----------------* cannot be carried on.*
* http://www.pdi.net/~art4 * William Blake *
*************************************************************
* Private ArtGallery: http://www.pdi.net/~art4/gallery.html *
*************************************************************
Re: joystick
Author: le... Leslaw Frydel
Date: Fri, 09 Feb 1996 00:00
Date: Fri, 09 Feb 1996 00:00
152 lines
4975 bytes
4975 bytes
No to masz !
Najpierw unit potem przykladowy program!
**********************************************************
unit joystick;
interface
const
PORT1_X = 1; BUTTON1 = 1;
PORT1_Y = 2; BUTTON2 = 2;
PORT2_X = 4; BUTTON3 = 4;
PORT2_Y = 8; BUTTON4 = 8;
function ReadValue(Resistor : integer) : integer;
function ReadButton : integer;
function TestButton (Button : integer) :Boolean;
implementation
function ReadValue;
begin
inline (
$8B/$46/$06/{mov ax,[bp+6];pobierz argument funkcji}
$24/$0F/ {and al,0Fh ; }
$8A/$D8/ {mov bl,al ; }
$33/$C9/ {xor cx,cx ; }
$BA/$01/$02/{mov dx,201h ;mumer portu joysticka}
$$FA/ {cli ;wylacz przerwania}
$EC/ {HOP1:in al,dx; }
$84/$C3/ {test bl,al ;sprawdzaj bit portu 201h}
$74/$04/ {je HOP2 ; }
$E2/$F9/ {loop HOP1 ;czekaj az pojawi sie zero}
$EB/$13/ {jmp END ;czas mina-blad}
$EE/ {HOP2:out dx,al;wymus jedynke}
$EC/ {in al,dx ; }
$84/$C3/ {test bl,al ;sprawdzaj bit portu 201h}
$74/$FA/ {je HOP2 ;czekajac na jedynke}
$33/$C9/ {xor cx,cx ;ustaw licznik na 65536}
$EC/ {HOP3:in al,dx; }
$84/$C3/ {test bl,al ;sprawdzaj bit portu 201h}
$74/$04/ {je HOP4 ;czekajac na zero}
$E2/$F9/ {loop HOP3 ; }
$EB/$02/ {jmp END ;licznik wyzerowany-blad}
$F7/$D9 {HOP4:neg cx ;odwroc licznik}
$FB/ {END: sti ;wlacz przerwania}
$89/$4E/$FE){mov [bp-2],cx;umiesc wynik na stosie}
end;
function ReadButton;
begin
inline(
$BA/$01/$02/{mov dx,201h ; }
$EC/ {in al,dx ;pobierz stan klawiszy}
$D0/$E8/ {shr al,l ;wynik przesun}
$D0/$E8/ {shr al,l ;do bitow 3..0}
$D0/$E8/ {shr al,l ; }
$D0/$E8/ {shr al,l ; }
$34/$0F/ {xor al,0Fh ; 1-wcisnienty,0-nie}
$32/$E4/ {xor ah,ah ; }
$89/$46/$FE){mov [bp-2,ax ;umiesc wynik na stosie}
end;
function TestButton;
begin
TestButton:=Boolean(ReadButton and Button)
end;
end.
***************************************************************
uses
Crt,Joystick;
const
scx = 79;
scy = 24;
var
ch : Char;
r,x,y:Integer;
xmin,ymin,xmax,ymax:Integer;
begin
ch:=chr(0);
ClrScr;
GotoXY (30,10);
WriteLn ('Kalibracja joysticka');
GotoXY (10,12);
WriteLn ('W lewo w gore do oporu i nacisnij ESC');
Repeat
If (KeyPressed) then ch:=ReadKey
until ((ReadButton<>0) or (ch=chr(27)));
ch:=chr (0);
ClrScr;
xmin:=ReadValue (PORT1_X);
ymin:=ReadValue (PORT1_Y);
repeat until (ReadButton=0);
GotoXY (10,12);
WriteLn ('W prawo w dol do oporu i nacisnij ESC');
repeat
if (KeyPressed) then ch:=ReadKey
until ((ReadButton<>0) or (ch=chr(27)));
xmax:=ReadValue (PORT1_X);
ymax:=ReadValue (PORT1_Y);
ClrScr;
GotoXY (10,12);
Writeln ('Pusc joystick i nacisnij cos');
ch:=ReadKey;
if ((xmin>0) and (xmax>0) and (ymin>0) and (ymax>0)) then
if ((xmin<xmax) and (ymin<ymax))
then
begin
ClrScr;
repeat
x:=Round((ReadValue(PORT1_X)-xmin)/(xmax-xmin)*scx);
y:=Round((ReadValue(PORT1_Y)-ymin)/(ymax-ymin)*scy);
if (x<1) then x:=1;
if (y<1) then y:=1;
if (x>scx) then x:=scx;
if (y>scx) then y:=scy;
GotoXY (15,25);
Write ('Klawisze: ',ReadButton,' X:',x:4,' Y:',y:4);
GotoXY (x,y); Write ('�',chr(8));
Delay(5);Write(' ',chr(8));
until KeyPressed;
end
else
begin
ClrScr;
GotoXY (30,11);
Writeln('Cos nie gra!!!');
end
else
begin
ClrScr;
GotoXY (27,11);
Writeln ('Brak joysticka!!!');
end;
Delay (3000);
ClrScr;
end.
Pozdrawiam Leszek!
--
_/ _/_/_/ _/_/_/ _/ _/ _/ +-----------------------------+
_/ _/ _/ _/ _/ | Leslaw Frydel |
_/ _/_/ _/_/_/ _/ _/ _/ | E-mail: |
_/ _/ _/ _/ _/ _/ | le...@zeus.polsl.gliwice.pl |
_/_/_/ _/_/_/ _/_/_/ _/ _/_/ _/ | WWW: |
| www.polsl.gliwice.pl/~lesiu |
Enjoy Your Life... Play More Games! +-----------------------------+
-------------------------------------------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads