Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!sdcsvax!sdcc6!sdcc18!cs162ffl From: cs162ffl@sdcc18.UUCP Newsgroups: comp.sys.amiga Subject: Re: How do I read the Joysticks? Message-ID: <816@sdcc18.ucsd.EDU> Date: Wed, 25-Nov-87 04:21:47 EST Article-I.D.: sdcc18.816 Posted: Wed Nov 25 04:21:47 1987 Date-Received: Sat, 28-Nov-87 14:39:07 EST References: <760@hubcap.UUCP> Reply-To: cs162ffl@sdcc18.ucsd.edu.UUCP (John Schultz) Organization: University of California, San Diego Lines: 64 Keywords: joysticks Here is a simple joystick routine in Modula-2. When operating on the BITSET type "*" is the same as "&" (AND) in C, and "/" is the same as "^" (XOR) in C. For more info, refer to the Hardware Manual, Appendix_A page 13. IMPLEMENTATION MODULE joystick; TYPE bitsetptr = POINTER TO BITSET; VAR buttonloc : POINTER TO SET OF [0..7]; joydat : ARRAY[0..1] OF bitsetptr; PROCEDURE readjoystick(VAR x,y : INTEGER; VAR buttonpressed : BOOLEAN; port : CARDINAL); BEGIN x := CARDINAL(BITSET(CARDINAL(joydat[port]^) DIV 2) * BITSET(1)) - CARDINAL(BITSET(CARDINAL(joydat[port]^) DIV 512) * BITSET(1)); y := CARDINAL(BITSET(CARDINAL(BITSET(CARDINAL(joydat[port]^) * 2) / joydat[port]^) DIV 2) * BITSET(1)) - CARDINAL(BITSET(CARDINAL(BITSET(CARDINAL(joydat[port]^) * 2) / joydat[port]^) DIV 512) * BITSET(1)); buttonpressed := NOT((6+port) IN buttonloc^); END readjoystick; BEGIN buttonloc := ADDRESS(0BFE001H); joydat[0] := bitsetptr(0DFF00AH); joydat[1] := bitsetptr(0DFF00CH); END joystick. In C: x = (((*joydat[port]) >> 1) & 1) - (((*joydat[port]) >> 9) & 1); y = (((*joydat[port]) << 1) ^ (*joydat[port])) >> 1) & 1) - (((*joydat[port]) << 1) ^ (*joydat[port])) >> 9) & 1)); buttonpressed = 1 - (((*buttonloc) >> (6 + port)) & 1); >>Haven't tested this C fragment as I don't have (or use) a C compiler<< (M2: Was using TDI, now Benchmark from Oxxi...) In both versions: x: left = -1, right = 1. y: up = -1, down = 1, buttonpressed = 1 (TRUE). If the stick is centered, x and y return 0, if the button is not pressed returns 0 (FALSE). Hope this helps. John