Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!sdd.hp.com!hp-pcd!hpcvlx!bill From: bill@hpcvlx.cv.hp.com (Bill Frolik) Newsgroups: comp.os.msdos.programmer Subject: Re: Joysticks Message-ID: <111360001@hpcvlx.cv.hp.com> Date: 30 Jan 91 18:35:38 GMT References: <26542@uflorida.cis.ufl.EDU> Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 28 Reading the joystick is pretty straightforward in assembly. You just do an arbitrary write to port 201h to trigger the card, then you monitor the bits read back from port 201h. The low 4 bits go low, I believe, and individually flip back to 1 at some later time dependent on the stick positions. In Microsoft C you can do the same thing by using the "inp(port)" and "outp(port,data)" functions. The only tricky part is keeping track of elapsed time in a way that isn't related to CPU speed (i.e., you shouldn't just count the number of iterations you sit in a loop polling the stick position bits). The best way to do this is probably to note the value of Timer 0's countdown register when you first trigger the card, then read it again each time you see one of the position bits change back. The timer counts down from 65535 to 0 every 55ms or so, and is used to generate the Timer Tick interrupt (int 08h and subsequently int 1Ch). The bits you get back from port 201h look something like this: 7 6 5 4 3 2 1 0 --- --- --- --- --- --- --- --- BUTTN2 BUTTN1 STICK2 STICK1 B A B A Y X Y X ___________________________________________ Bill Frolik Hewlett-Packard Co. hp-pcd!bill Corvallis, Oregon bill@hpcvlx.cv.hp.com (503)750-4082