🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.programming
Article #283

Re: joystick

#283
From: le... Leslaw Frydel
Date: Fri, 09 Feb 1996 00:00
152 lines
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!        +-----------------------------+
-------------------------------------------------------------------------
Technical Details
Message-ID: <4ffsu7$1cp@hades.polsl.gliwice.pl>
Path: mbox-mo1.pugleaf.net!unknown!not-for-mail
References: <4fcp0h$4li@galaxy.uci.agh.edu.pl>

Show Full Headers
Complete Article Headers
From: le...@zeus.polsl.gliwice.pl (Leslaw Frydel)
Subject: Re: joystick
Date: 1996/02/09
Message-ID: <4ffsu7$1cp@hades.polsl.gliwice.pl>
X-Deja-AN: 138630781
references: <4fcp0h$4li@galaxy.uci.agh.edu.pl>
organization: Politechnika Slaska w Gliwicach
newsgroups: pl.comp.programming
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit