Newsgroups: comp.sys.apple2 Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!agate!dog.ee.lbl.gov!news!nosc!crash!pro-nbs!pro-harold!pro-cajun!pro-gumbo!tgeer (Smail3.1.28.1 #7) id m0nEz5Z-0000l2C; Thu, 21 Jan 93 02: 24 PST From: tgeer@pro-gumbo.cts.com (System Administrator) Subject: Re: Attention assembly programmers... Organization: Apple Gumbo BBS Date: Tue, 19 Jan 93 20:29:30 CST Message-ID: In-Reply-To: andrep@balboa.eng.uci.edu (Andre Prellwitz) References: <2B59CDAB.12197@news.service.uci.edu> Lines: 59 In <2B59CDAB.12197@news.service.uci.edu> andrep@balboa.eng.uci.edu (Andre Prellwitz) writes: >A while ago someone posted about how to read the joystick on a //gs in native >mode. They said that it was possible to read both paddles at once and there- >fore get much more accurate readings. I don't recall exactly how to do this, >but I've been trying the following: strobe the analog paddle reset ($c070) >and then read locations $c064 and $c065 and wait until both return to zero. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Only the high bit of these locations is valid. When the high bit of either location becomes 0 then the corresponding analog input has timed out. You will actually get more accurate results by reading them one after the other with the accumulator set to 8 bits wide and the index registers used to hold the counts (16 bits wide). This allows for a much faster loop, giving better resolution. Assuming that this routine is called from full native mode, the following code will do the trick: strobe equ $C070 ; analog input timing reset pdl0 equ $C064 ; analog input 0 pdl1 equ $C065 ; analog input 1 start php ; save processor status register phb ; and data bank register sep #%100000 ; make accumulator 8 bits wide lda #0 ; make data bank = 0 pha plb ldx #0 ; initialize the counters txy lda strobe ; strobe the timing reset loop1 inx ; increment pdl0 count lda pdl0 ; is high bit = 0? bmi loop1 ; no, keep checking lda strobe ; yes, strobe the timing reset again loop2 iny ; increment pdl1 counter lda pdl1 ; is high bit = 0? bmi loop2 ; no, keep checking plb ; yes, restore data bank plp ; and processor status register rts ; return to caller (could be RTL) Notice that the actual counting loops are only 9 cycles long. This gives the best possible resolution. You will need your counters to be 16 bits wide as the results will easily overflow the capacity of an 8 bit counter. Using memory locations as counters will only serve to slow the counting loop down. If X and Y contain valid data before entry, you will need to save them off to the stack and pull them back in after interpreting the joystick results. I have used this exact method to read the analog inputs on my Science Toolkit box which connects to the joystick port. The results have been extremely accurate (much more than would be needed for a game which reads the joystick). ---------------------------------------------------------------------------- ProLine: tgeer@pro-gumbo Internet: tgeer@pro-gumbo.cts.com UUCP: crash!pro-gumbo!tgeer Fidonet: tom.geer@f20.n380.z1.fidonet.org ---------------------------------------------------------------------------- "My wife is a bargain hunter - I just carry the ammunition."