home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / apple2 / 27299 < prev    next >
Encoding:
Text File  |  1993-01-21  |  3.6 KB  |  72 lines

  1. Newsgroups: comp.sys.apple2
  2. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!spool.mu.edu!agate!dog.ee.lbl.gov!news!nosc!crash!pro-nbs!pro-harold!pro-cajun!pro-gumbo!tgeer
  3.     (Smail3.1.28.1 #7) id m0nEz5Z-0000l2C; Thu, 21 Jan 93 02: 24 PST
  4. From: tgeer@pro-gumbo.cts.com (System Administrator)
  5. Subject: Re: Attention assembly programmers...
  6. Organization: Apple Gumbo BBS
  7. Date: Tue, 19 Jan 93 20:29:30 CST
  8. Message-ID: <aj74842@pro-gumbo.cts.com>
  9. In-Reply-To: andrep@balboa.eng.uci.edu (Andre Prellwitz)
  10. References: <2B59CDAB.12197@news.service.uci.edu>
  11. Lines: 59
  12.  
  13. In <2B59CDAB.12197@news.service.uci.edu>
  14. andrep@balboa.eng.uci.edu (Andre Prellwitz) writes:
  15.  
  16. >A while ago someone posted about how to read the joystick on a //gs in native
  17. >mode.  They said that it was possible to read both paddles at once and there-
  18. >fore get much more accurate readings.  I don't recall exactly how to do this,
  19. >but I've been trying the following: strobe the analog paddle reset ($c070)
  20. >and then read locations $c064 and $c065 and wait until both return to zero.
  21.                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  22.  
  23. Only the high bit of these locations is valid.  When the high bit of either
  24. location becomes 0 then the corresponding analog input has timed out.  You
  25. will actually get more accurate results by reading them one after the other
  26. with the accumulator set to 8 bits wide and the index registers used to hold
  27. the counts (16 bits wide).  This allows for a much faster loop, giving better
  28. resolution.  Assuming that this routine is called from full native mode, the
  29. following code will do the trick:
  30.  
  31. strobe   equ   $C070       ; analog input timing reset
  32. pdl0     equ   $C064       ; analog input 0
  33. pdl1     equ   $C065       ; analog input 1
  34.  
  35. start    php               ; save processor status register
  36.          phb               ; and data bank register
  37.          sep   #%100000    ; make accumulator 8 bits wide
  38.          lda   #0          ; make data bank = 0
  39.          pha
  40.          plb
  41.          ldx   #0          ; initialize the counters
  42.          txy
  43.          lda   strobe      ; strobe the timing reset
  44. loop1    inx               ; increment pdl0 count
  45.          lda   pdl0        ; is high bit = 0?
  46.          bmi   loop1       ; no, keep checking
  47.          lda   strobe      ; yes, strobe the timing reset again
  48. loop2    iny               ; increment pdl1 counter
  49.          lda   pdl1        ; is high bit = 0?
  50.          bmi   loop2       ; no, keep checking
  51.          plb               ; yes, restore data bank
  52.          plp               ; and processor status register
  53.          rts               ; return to caller (could be RTL)
  54.  
  55. Notice that the actual counting loops are only 9 cycles long.  This gives the
  56. best possible resolution.  You will need your counters to be 16 bits wide as
  57. the results will easily overflow the capacity of an 8 bit counter.  Using
  58. memory locations as counters will only serve to slow the counting loop down.
  59. If X and Y contain valid data before entry, you will need to save them off to
  60. the stack and pull them back in after interpreting the joystick results.
  61. I have used this exact method to read the analog inputs on my Science Toolkit
  62. box which connects to the joystick port.  The results have been extremely
  63. accurate (much more than would be needed for a game which reads the joystick).
  64.  
  65.  
  66. ----------------------------------------------------------------------------
  67. ProLine: tgeer@pro-gumbo          Internet: tgeer@pro-gumbo.cts.com
  68. UUCP:    crash!pro-gumbo!tgeer    Fidonet:  tom.geer@f20.n380.z1.fidonet.org
  69. ----------------------------------------------------------------------------
  70. "My wife is a bargain hunter - I just carry the ammunition."
  71.  
  72.