Newsgroups: comp.sys.apple2 Path: news.weeg.uiowa.edu!news.uiowa.edu!uunet!orca!javelin.sim.es.com!animal!mmunson From: mmunson@animal.es.com (Mark Munson) Subject: Re: Joystick readings from ML Message-ID: <1992Oct5.211758.17368@javelin.sim.es.com> Sender: news@javelin.sim.es.com Nntp-Posting-Host: animal.sim.es.com Reply-To: mmunson@animal.es.com (Mark Munson) Organization: Evans & Sutherland Computer Corp., Salt Lake City, UT References: <1992Oct2.181113.27082@cs.uow.edu.au> Date: Mon, 5 Oct 1992 21:17:58 GMT Lines: 67 Shane: Unfortunately, there isn't another ROM based routine for reading the joysticks. You'll have to write your own in machine language. It might seem like a problem, but it's really easy once you see it done. First, you need to know what the paddle (joystick) hardware is doing. When you strobe the paddles, a charge is applied to a capacitor. A variable resistor (paddle) allows the capacitor to discharge to ground. By measuring the time for this to occur, you can guage the setting of the paddle. The ROM based paddle routines use the Apple II running at 1 MHz, with a known paddle resistance in the 0 to 150 ohm range (or was that 150 K-Ohm?) Even on a GS, the call still slows the machine down during this timing sensistive process. Strobing the paddles, starts the process on all of the 4 possible paddles. If the paddle you are reading finishes quickly, and you try to read the next paddle (which hasn't finished), you will get faulty values for the second paddle. Example: PDL 0: +-----------! PDL 1: +----------------! _____________________________ 0 100 200 255 In the example above, you would get a value of 100 for PDL(0). If immediately try and read PDL(1) before it has a chance to finish, then you might get a value of 50 {150 - 100} for PDL(1). A cheap way to correct for this is to check the paddle switch location to insure that the paddle has timed out before you strobe the paddle. It works, but it wastes time. There is a faster way to get both paddle values, without running into timing problems like the one above. Read Both Paddles at the Same Time Insure both paddles are clear, then strobe the paddle switch. Start counting, and look at both paddles. As each paddle times out, save the counter value for the paddle. By strategicly placing NOP instructions into the loop paths, you can insure that the timing will stay constant for each pass of the counter. When both paddles have timed out, you are done. If you write in 65C816 code, you can read both paddle values with a single LDA instruction. In fact, the code gets a lot tighter in 65C816 code, so your resolution will be higher than the stock 0-254 of a 1 MHz 6502 call. This factor can present some problems if the game is running on an accelerated GS. So you'll want to calibrate the joystick for various speeds, and divide the joystick results by an appropriate factor. If you want the joystick routine to be of a consistent length, then you only need to add on a dummy loop that will waste the time that would have been used had both paddles been set to thier maximum (highest resistance) value. I've got copies of routines (65C816) that do this type of thing. When I unpack my GS, I'll try and upload an example. [MGM]