delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/11/16:04:19

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: joystick reading (gameport)
Date: Tue, 11 Mar 1997 18:40:57 +0000
Organization: None
Distribution: world
Message-ID: <DUqDCNA5caJzEwcn@talula.demon.co.uk>
References: <EMRC0HAVZCJzEw8n AT talula DOT demon DOT co DOT uk>
<199703110907 DOT KAA06763 AT gilberto DOT physik DOT rwth-aachen DOT de>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 31
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Christoph Kukulies writes:
>#include <stdio.h>
>main()
>{
>  int i;
>  while(1){
>     outportb(0x201,0xff);
>     i=inportb(0x201);
>     printf("%02x\r",i);fflush(stdout);
>  }
>}
>
>I'm getting 0xff when no button is pressed or no stick action is made.
>When I press one fire button I'm getting 0xef, the other 0xdf.

Ok, sorry: I lied :-) The button bits are usually 1, and zero when the
button is pressed. But my comments about the timing still stands. When
you do the outportb(), you reset the low four bits to 1. You should then
go into a loop, calling inportb() but not writing anything to the port,
and measure how long it takes the low bits to fall back from 1 to 0. The
time delay for bits 0 and 1 gives you the X and Y position of the stick.

btw. such PC hardware issues are really off-topic for this group: I
suggest you get a copy of the PCGPE which covers all this in some
detail...


/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Beauty is a French phonetic corruption of a short cloth neck ornament.
 */

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019