home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / assembler / thesource / volume4 / source / misc / 3buttons.lha / 3buttons.s
Encoding:
Text File  |  1993-02-13  |  3.9 KB  |  84 lines

  1.  
  2. ;    Hi there everybody. After some discussion on comp.sys.amiga.games on the
  3. ;subject of multi-button joysticks, I started doing some research on the Sega
  4. ;Genesis joysticks (hereafter referred to as "Sega" sticks; I'm not sure what
  5. ;the Sega Master System joysticks are like...). A post in rec.games.video
  6. ;asking for tech info netted me a pinout of the stick, a description of how to
  7. ;use it, and even a bit of sample code from Sonic the Hedgehog. This info lay
  8. ;dormant for a while until I got the parts together, including a Sega pad.
  9. ;    The Sega joystick, unlike most familiar Amiga-compatible joysticks, is
  10. ;multiplexed. "No problem", you say. "Which pin do I boink to do it?" Well,
  11. ;that's the catch. The pin that toggles between reading (UDLRBC) and reading
  12. ;(A and START) is pin 7, which is the power pin on the Amiga. A quick
  13. ;hacked-up adaptor based on two DB-9 connectors easily solves this problem;
  14. ;just swap pins 5 and 7. Now, when pin 5 on the Amiga side is high, the pad
  15. ;will output (UDLRBC). Clearing pin 5 to a low state gives you (A and START).
  16. ;A reads as button B( the good ol' fire button), and START reads as button C
  17. ;(Y Pot). U and D also come in as normal when 5 is low; however, L and R
  18. ;are set low. One presumes that the way has been left open for two more
  19. ;buttons in future sticks, coming in over the L and R lines.
  20. ;    Now that you've made the adaptor, here's the second catch: Your routine
  21. ;has to be written carefully, as pins 5 and 9 are the pot pins. These two
  22. ;lines can take up to 300 microseconds to change state, so you have to write
  23. ;your joystick-reading routine around this.
  24. ;    Here's one that I've successfully run on my 68000 machine. If you have
  25. ;a faster processor, you'll almost definitely have to re-work it to allow for
  26. ;lines 5 and 9 to change state. If you do this, please post the new version,
  27. ;especially if it works without significant degradation to a 68000 (i.e., no
  28. ;padding with NOPs...) Admittedly, it's nasty direct-to-the-hardware code,
  29. ;but it _does_ work.
  30. ;     [You should probably try and time it off of a couple of copper interrupts
  31. ;- that will probably work like a charm, as long as you control the screen
  32. ;mode.]
  33. ;    Spread this info around as much as you like. And more importantly, if
  34. ;you write games, SUPPORT IT. I'd like to see a game that can be configured
  35. ;to use a 1-button joystick, a 2-button joystick, OR a 3-button joystick,
  36. ;with inceasingly annoying and cryptic controls as the number of buttons is
  37. ;lowered.
  38.  
  39. ;Routine to read a Sega Genesis - type stick in port B
  40. ;Expects to have CUSTOM ($dff000) in A6
  41. ;Returns state of all 8 switches in d0 -> 0=up 1=dn 2=lf 3=rt
  42. ;Stomps on d0-d2, a0                      4=fA 5=fB 6=fC 7=s
  43. ReadJoyB
  44.     clr.b   d0                  ;Clear output byte
  45.     move.w  joy1dat(a6),d1      ;Get UDLR status
  46.     move.w  d1,d2               ;Decode annoying format
  47.     add.w   d2,d2
  48.     eor.w   d1,d2               ;Now d1-> =R 9=L  d2-> 1=D 9=U
  49.     btst    #7,$bfe001          ;Check B
  50.     beq.s   .1
  51.     bset    #5,d0
  52. .1  btst    #14,potinp(a6)      ;Check C
  53.     beq.s   .2
  54.     bset    #6,d0
  55. .2  move.w  #$e001,potgo(a6)    ;Ask for START A
  56.     btst    #9,d2               ;Check U
  57.     bne.s   .3
  58.     bset    #0,d0
  59. .3  btst    #1,d2               ;Check D
  60.     bne.s   .4
  61.     bset    #1,d0
  62. .4  btst    #9,d1               ;Check L
  63.     bne.s   .5
  64.     bset    #2,d0
  65. .5  btst    #1,d1               ;Check R
  66.     bne.s   .6
  67.     bset    #3,d0
  68. .6  btst    #7,$bfe001          ;Check A
  69.     beq.s   .7
  70.     bset    #4,d0
  71. .7  btst    #14,potinp(a6)      ;Check START
  72.     beq.s   .8
  73.     bset    #7,d0
  74. .8  move.w  #$f001,potgo(a6)    ;Ask for UDLRBC for next pass
  75.     rts
  76.  
  77. ;Comments, flames, gifts, etc can be sent to me at:
  78. ;         Fido: paul trauth on 1:396/36.0 (I don't understand Fido addresses
  79. ;               too well. hope this works.)
  80. ;       Usenet: paul_trauth@agwbbs.new-orleans.LA.US
  81. ;    Real Life: Paul Trauth/4752 Press Dr/New Orleans,LA/70126/USA
  82.  
  83.  
  84.