Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!usc!elroy.jpl.nasa.gov!netline-fddi.jpl.nasa.gov!nntp-server.caltech.edu!nathan From: nathan@cco.caltech.edu (Nathan Mates) Newsgroups: comp.sys.apple2.programmer Subject: Re: Joystick Code... Help Please! Date: 25 Nov 1994 06:39:52 GMT Organization: California Institute of Technology, Pasadena Lines: 82 Message-ID: <3b40ro$ief@gap.cco.caltech.edu> References: <3b37bu$8ag@condor.ic.net> NNTP-Posting-Host: accord.cco.caltech.edu In article <3b37bu$8ag@condor.ic.net>, Shawn Platkus wrote: >I'm in need of some code to read the joystick values from 65816 assembly. This was sent to me a while back. Nathan --- Begin included file From afcdyajim@aol.com Sat Mar 27 21:47:15 1993 From: afcdyajim@aol.com X-Mailer: America Online Mailer To: nathan@cco.caltech.edu Subject: joystick routine Path: Assembly (6502/65816)/Asm65816 Code Wanted... Subj: My code... 92-10-21 22:48:08 EST >From: AFL GaryJ Posted on: America Online Here's the code I used. There are a few things to keep in mind with this code: Because I'm using wide registers, the X and Y values of the joystick may come back with values greater than $FF. The size of the number returned depends (in part) upon the speed of the machine that the code is running on. Accellerated IIGS's will return greater values than stock 2.8 MHz machines. Having the user do a joystick calibration at the start of the program would be one way of solving this problem. Also, because the maximum joystick value returned is not "clipped off" (i.e. maxed out at $FF), the X and Y maximum returned values may differ, depending on the model and wear of your joystick. And one last thing: The timing cycles of my routine are greater than the sum of the cycles required to execute the standard paddle reading routine built into the II+ ROM. But, since my routine will execute at speeds greater than 1 MHz, the net difference results in a faster joystick read. That, coupled with the fact that both paddles are read at the same time, makes this routine much faster than the standard ROM call. I haven't looked at this code for a long time, and I'm sure there are ways to improve it. Anyone, feel free to post possible enhancements! ; ; Read the joystick controls: PRead anop php sei lda >$00C070 ; trigger paddles (6) ldy #0 ; (3) ldx #3 ; (3) PRtime dex ; (2) bne PRtime ; timing loop for 1st count (2,3) PRead2 lda >$00C064 ; check paddle 0,1 status (6) and #$8080 ; check high bits of each (3) beq PRXit ; exit if both are done (2) cmp #$0080 ; see if X only is active (3) bmi PRBoth ; > no, do both (2,3) beq PRXOnly ; > X axis only (2,3) PRYonly iny ; (2) bpl PRYmore ; (just for timing) (3) bmi PRXit ; (prevent endless loop) PRYmore bra PRead2 ; go back for more (3) PRXOnly inx ; (2) bmi PRXit ; (prevent endless loop) (2) bra PRead2 ; go back for more (3) PRBoth inx ; (2) iny ; (2) nop ; match timing of others (2) bpl PRead2 ; (3) PRXit plp rts ; x = pdl(0), y = pdl(1) ;------------------------------- Gary -- * Nathan Mates http://www.ugcs.caltech.edu/~nathan/ * * Ftp humor archiver: ftp to cco.caltech.edu, look in pub/humor * * "Always listen to experts. They'll tell what can't be done, and * * why. Then do it." -- Robert A. Heinlein, Lazarus Long *