Jump to content
IGNORED

Connecting a SNES controller


playsoft

Recommended Posts

I have connected a SNES controller to my A8 and wondered if someone with better hardware knowledge can say if this should be OK.

The SNES controller pinout is shown in section 4: http://www.gamefaqs.com/snes/916396-super-nintendo/faqs/5395

I connected it to the A8 joystick port:

SNES 1 +5v to A8 7 +5v
SNES 4 data to A8 1 up
SNES 2 clock to A8 2 down
SNES 3 latch to A8 3 left
SNES 7 Ground to A8 8 Ground

I initially tried this with the cheapest SNES controller I could find. It worked OK but the d-pad was poor at giving a distinct direction.

I then brought a Retro-Bit controller that I thought would be better quality which turned out to be a pack of two. The first controller worked OK, although the d-pad still wasn't great. On the second controller only a few buttons worked. I tried it on my SNES and it was the same.

I also brought an Eaxus controller which after about 10 seconds use required opening up to reposition one of the rubber pads. However since then it's been fine and the d-pad is perfect.

Was the non-working controller likely a dud or is it possible that hooking it up to the A8 damaged it? Admittedly my soldering is not very good, so it's possible I may have shorted some wires together when connecting up.

Also, if you were running software driving a SNES controller with pins 2 and 3 as outputs but accidently left a normal joystick connected, is it likely to cause any damage to the joystick or computer?

 

Thanks,

Paul

Link to comment
Share on other sites

I wonder how strict the timing is? The 16 clock pulses at 12 us each is equal to about 3 scanlines or 142 machine cycles.

A potential problem is that the refresh cycles can screw you over. But I suspect a cycle astray here or there probably won't hurt.

 

What happens if we drive outputs with a joystick connected? I don't think it matters.

 

Another problem you might face is that the rise time when changing port outputs from 0 to 1 isn't instant or even consistent which adds additional jitter. Fall time 1 to 0 is practically instant though.

Link to comment
Share on other sites

The timing does not seem strict at all. Below is the code I'm using. I imagine my timing isn't that accurate to begin with and if I remove the HONOR_TIMING code it seems to work just as well.

 

My concern is suggesting or putting anything out that may harm hardware, whether it is the SNES controller or the A8. I have patched Dropzone, calling the routine below in its VBI routine (with the HONOR_TIMING code present) and I do not notice any slowdown, certainly not on the first couple of levels anyway.

  lda #$06       ; latch = high, clock = high
  sta PORTA

.ifdef HONOR_TIMING
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
.endif

  lda #$02       ; 2 latch = low, clock = high
  sta PORTA

.ifdef HONOR_TIMING
  nop            ; 2
  nop            ; 2
.endif

  ldx #$00       ; 2
  
loop:
  nop            ; 2
  lda #$00       ; 2 clock = low
  sta PORTA
  
.ifdef HONOR_TIMING
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
  nop            ; 2
.endif

  lda PORTA
  and #$01
  sta snes_buttons,x
  
  lda #$02       ; clock = high
  sta PORTA
  
  inx            ; 2
  cpx #16        ; 2
  bcc loop       ; 3

Link to comment
Share on other sites

IIRC, the joystick pins have limiting resistors on them which provide some protection by limiting the current to about 20mA. I think the 600XL omits them, though. The only danger is if a joystick direction is pressed for a long period when the pin is driven high, so leave the pins in a low state when not in use if possible.

Link to comment
Share on other sites

Rather than patching individual games it'd probably be way easier to just patch the OS.

Most games use the shadow registers to read controllers which makes it easy, for ones that don't it won't work.

 

There's a trick to get the OS to do a disk reboot which you can use. The way I'd go about things:

- use the 2nd character set at $CC00-$CFFF to put your patches in.

- copy the OS to Ram, have a breakaway into your patch somewhere in the VBlank, probably best right near the end before it exits.

- to get the OS to do a reboot, steal the CASINI warmstart vector @ 2,3 - in that routine, set the WARMST ( 8 ) flag to zero, and the BOOT flags (9) to zero also. This will cause the OS to attempt a disk boot without wiping Ram first.

 

So long as whatever gets loaded doesn't play around with PORTB settings your patched OS should remain in place.

Edited by Rybags
Link to comment
Share on other sites

I was able to read the controller with the port configured as an output only for the duration of the read. I also didn't have to clock out the full 16-bits, just the 12 which are used.

 

I connected up a normal Atari joystick and no damage was done, although I have left a warning in the software. If anyone is interested in trying this out there is a test program which reports the status of all the controller buttons. There is also a patched version of Dropzone with the controls mapped: d-pad = direction, B = fire, Y, A & X = bomb, top L & top R = cloak, Start & Select = pause .

 

Dropzone was reading PORTA for the stick, TRIG0 for the trigger and CH for the keys. So an OS patch wouldn't have worked for the joystick/trigger but it would have worked for the keys (assuming it allows the user to specify the mapping). I was only thinking of patching games like Dropzone with keyboard controls which would be nice to have on the SNES buttons, but a patched OS would make it more general purpose.

snes_controller.zip

Link to comment
Share on other sites

In theory you could use joystick port 2 and just store whatever direction you want the game to read in the lower 4 bits of PORTA which would ensure any software would work (so long as it didn't reconfigure the IO settings).

But you'd still have the problem with the TRIG bit, chances are if a game reads PORTA directly it also reads the TRIG registers in GTIA.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...