(*
 * Svgalib-Gpc - Pascal porting of Svgalib header files.
 * Copyright 1999, 2000 (C) Nicola Girardi <girardi@vicenza.linux.it>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *)

unit VgaJoystick;

interface

const JOY_EVENTBUTTONDOWN = 1;
      JOY_EVENTBUTTONUP = 2;
      JOY_EVENTAXIS = 3;

(* Here we won't use a JoystickOutput proc, we assume we don't need
 * any kind of calibration.
 *
 * To simplify things for the end unit-user, the defaulteventhandler
 * is used.
 *)

function JoystickInit(which: Integer) : Boolean;
procedure JoystickClose(which: Integer); asmname 'joystick_close';

(* polls the joystick and calls the defaulteventhandler *)
function JoystickUpdate : Integer; asmname 'joystick_update';

function JoystickGetNumAxes(joydev: Integer) : Byte; asmname 'joystick_getnumaxes';
function JoystickGetNumButtons(joydev: Integer) : Byte; asmname 'joystick_getnumbuttons';

(* queries the default handler *)
function JoystickGetAxis(joydev, a: Integer) : Byte; asmname 'joystick_getaxis';
function joystickGetButton(joydev, b: Integer) : Byte; asmname 'joystick_getbutton';

(* some define statements which are translated with functions *)
function JoystickButton1(dev: Integer) : Byte;
function JoystickButton2(dev: Integer) : Byte;
function JoystickButton3(dev: Integer) : Byte;
function JoystickButton4(dev: Integer) : Byte;
function JoystickGetB1 : Byte;
function JoystickGetB2 : Byte;
function JoystickGetB3 : Byte;
function JoystickGetB4 : Byte;
function JoystickX(dev: Integer) : Byte;
function JoystickY(dev: Integer) : Byte;
function JoystickZ(dev: Integer) : Byte;
function JoystickGetX : Byte;
function JoystickGetY : Byte;
function JoystickGetZ : Byte;

implementation

type JoystickOutput = ^procedure(msg: CString);
(* Look out, it's CString *)

function JoystickInit(which: Integer) : Boolean;
function svgalib_joystick_init(joydev: Integer; jo: JoystickOutput) : Integer; asmname 'joystick_init';
begin
  JoystickInit:= ( svgalib_joystick_init(which, JoystickOutput(nil)) >= 0 );
  (* nowadays "= 1" should be safe, if you have seen the svgalib sources *)
end;

(* some define statements which are translated with functions *)
function JoystickButton1(dev: Integer) : Byte;
begin JoystickButton1:= JoystickGetButton(dev, 0) end;
function JoystickButton2(dev: Integer) : Byte;
begin JoystickButton2:= JoystickGetButton(dev, 1) end;
function JoystickButton3(dev: Integer) : Byte;
begin JoystickButton3:= JoystickGetButton(dev, 2) end;
function JoystickButton4(dev: Integer) : Byte;
begin JoystickButton4:= JoystickGetButton(dev, 3) end;

function JoystickGetB1 : Byte;
begin JoystickGetB1:= JoystickGetButton(0, 0) end;
function JoystickGetB2 : Byte;
begin JoystickGetB2:= JoystickGetButton(0, 1) end;
function JoystickGetB3 : Byte;
begin JoystickGetB3:= JoystickGetButton(0, 2) end;
function JoystickGetB4 : Byte;
begin JoystickGetB4:= JoystickGetButton(0, 3) end;

function JoystickX(dev: Integer) : Byte;
begin JoystickX:= JoystickGetAxis(dev, 0) end;
function JoystickY(dev: Integer) : Byte;
begin JoystickY:= JoystickGetAxis(dev, 1) end;
function JoystickZ(dev: Integer) : Byte;
begin JoystickZ:= JoystickGetAxis(dev, 2) end;

function JoystickGetX : Byte;
begin JoystickGetX:= JoystickGetAxis(0, 0) end;
function JoystickGetY : Byte;
begin JoystickGetY:= JoystickGetAxis(0, 1) end;
function JoystickGetZ : Byte;
begin JoystickGetZ:= JoystickGetAxis(0, 2) end;


end.


syntax highlighted by Code2HTML, v. 0.8.8b