home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / C128CPM / JOYSTICK.LBR / JOYSTICK.INC < prev   
Encoding:
Text File  |  2019-04-13  |  1.0 KB  |  37 lines

  1. {
  2. SG Tools Pro (C) 1992 Steve Goldsmith
  3.  
  4. The Joystick module allows you to read joystick 2.  Bit masks are provided
  5. to test which switches are closed.  For example, to see if the fire button
  6. is pressed use:
  7.  
  8. if ReadJoy2 and joyFire = 0 then
  9.   Writeln ('Fire button pressed');
  10. }
  11.  
  12. const
  13.  
  14.   cia1DataPortRegA = $dc00;
  15.   cia1DataDirRegA  = $dc02;
  16.  
  17. {joystick direction masks}
  18.  
  19.   joyNone      = $1f; joyFire      = $10;
  20.   joyUp        = $01; joyDown      = $02;
  21.   joyLeft      = $04; joyRight     = $08;
  22.   joyUpLeft    = $05; joyUpRight   = $09;
  23.   joyDownLeft  = $06; joyDownRight = $0a;
  24.  
  25. function ReadJoy2 : byte;
  26.  
  27. var
  28.  
  29.   RegSave : byte;
  30.  
  31. begin
  32.   RegSave := PortIn (cia1DataDirRegA); {save ddr}
  33.   PortOut (cia1DataDirRegA,0);         {set ddr to all inputs}
  34.   ReadJoy2 := PortIn (cia1DataPortRegA) and $1f; {read joystick 2}
  35.   PortOut (cia1DataDirRegA,RegSave)    {restore ddr}
  36. end;
  37.