🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #10979

Analog Joystick Driver

#10979
From: John Schultz
Date: Tue, 17 Jan 1989 01:24
140 lines
4015 bytes
  Ok, here's an analog joystick driver for the right mouse port.  I've
tried to make it as "legal" as possible.  Previous versions for my
own use locked out intuition (I starved it's input events), which
wasn't very friendly.  So this version uses the Potgo Resource.
Only one slight problem; FreePotbits doesn't seem to work.  I've
coded these routines in Benchmark and Lattice 5.0, and FreePotgobits
does nada (Or I is doing somting ron?).  So, the program works the
first time, but can't allocate the necessary bits the second time.
I've tried "freeing" my first request, then trying again as per the
RKM docs, but that no work either.  Answers anyone?

  Anyway, here's the code in Benchmark:

MODULE AJoystick;

FROM SYSTEM IMPORT ADR,ADDRESS,BYTE,INLINE,REG,SHIFT;
FROM CustomHardware IMPORT custom;
FROM Interrupts IMPORT
  Interrupt,InterruptPtr,AddIntServer,RemIntServer,
                Disable,Enable;
FROM INTHardware IMPORT INTVertB;
FROM Nodes IMPORT NTInterrupt;
FROM Memory IMPORT AllocMem,FreeMem,MemReqSet,MemPublic;
FROM Terminal IMPORT BusyRead;
FROM TermInOut IMPORT WriteCard,WriteString,Write,WriteInt,WriteLn;

FROM Resources IMPORT OpenResource;
FROM PotgoResource IMPORT
PotgoName,PotgoBase,AllocPotBits,FreePotBits,
                          WritePotgo;

CONST
  A1   = 9;
  WORD = BITSET(1);      (* Clear bits 15,13, set bit 0 *)
  MASK = BITSET(0A001H); (* Write to bits 15, 13, and 0 *)

TYPE
  cardptr = POINTER TO CARDINAL;

VAR

  ch        : CHAR;

  AStickInt : InterruptPtr;

  ajx,ajy   : INTEGER;

  allocmask : BITSET;

  pot1dat,
  temp      : cardptr;
  pot1val   : CARDINAL;

  OpenedAOK : BOOLEAN;

PROCEDURE ReadPots(): LONGCARD;
BEGIN
  temp := cardptr(REG(A1));
  INLINE(48E7H,3F3EH); (* Push *)
  Disable;

  pot1val := temp^;
  WritePotgo(WORD,MASK);

  Enable;
  INLINE(4CDFH,7CFCH); (* Pop *)
  RETURN 0D;
END ReadPots;

PROCEDURE OpenAJoystick(): BOOLEAN;
BEGIN

  OpenedAOK := FALSE;

  PotgoBase := OpenResource(ADR(PotgoName));
  IF PotgoBase = NIL THEN
    WriteString("Couldn't open PotgoResouce.\n");
    RETURN FALSE;
  END;
  
  allocmask := AllocPotBits(MASK);
  IF allocmask # MASK THEN
    WriteString("Couldn't AllocPotBits 15,13, and 0.\n");
    FreePotBits(allocmask);
    RETURN FALSE;
  END; (* IF *)

  AStickInt := AllocMem(SIZE(Interrupt),MemReqSet{MemPublic});
  IF AStickInt = NIL THEN
    WriteString("No Public Memory for AStickInt.\n");
    FreePotBits(allocmask);
    RETURN FALSE;
  END;

  WITH AStickInt^ DO
    isNode.lnType := NTInterrupt;
    isNode.lnPri  := BYTE(10);
    isNode.lnName := ADR("AnalogJoystick");
    isCode        := ADR(ReadPots);
    isData        := ADR(custom^.pot1dat);
  END; (* WITH AStickInt *) 

  AddIntServer(INTVertB,AStickInt^);

  OpenedAOK := TRUE;

END OpenAJoystick;

PROCEDURE CloseAJoystick;
BEGIN
  IF OpenedAOK THEN
    RemIntServer(INTVertB,AStickInt^);
    FreeMem(AStickInt,SIZE(Interrupt));
    FreePotBits(allocmask);
  END;
END CloseAJoystick;

PROCEDURE ReadAJoystick(VAR x,y : INTEGER);
BEGIN
  x := SHIFT(pot1val,-8); (* in C: x = potval >> 8 *)
  y := INTEGER(BITSET(pot1val)*BITSET(0FFH)); (* C: y = potval &
0xff *)
END ReadAJoystick;

BEGIN

  IF NOT OpenAJoystick() THEN RETURN; END;
  ch := 0C;
  REPEAT
    ReadAJoystick(ajx,ajy);
    WriteString(" potx: ");
    WriteInt(ajx,4);
    WriteString(" poty: ");
    WriteInt(ajy,4);
    WriteString("     \r");
    BusyRead(ch);
  UNTIL ch # 0C;
  CloseAJoystick;
END AJoystick.
Technical Details
Message-ID: <59@sdcc10.ucsd.EDU>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ames!ucsd!sdcc6!sdcc10!cs161agc

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ames!ucsd!sdcc6!sdcc10!cs161agc
From: cs161agc@sdcc10.ucsd.EDU (John Schultz)
Newsgroups: comp.sys.amiga.tech
Subject: Analog Joystick Driver
Summary: FreePotbits doesn't seem to work.
Message-ID: <59@sdcc10.ucsd.EDU>
Date: 17 Jan 89 01:24:46 GMT
Reply-To: cs161agc@sdcc10.ucsd.edu.UUCP (John Schultz)
Organization: University of California, San Diego
Lines: 140