English Amiga Board


Go Back   English Amiga Board > Support > support.Hardware

 
 
Thread Tools
Old 15 April 2020, 22:56   #21
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,369
They're easy connectors to find anyway, and the pin numbers are usually embossed on the connectors themselves (albeit very small numbering). This diagram is for a serial port, but the pin numbers are the same. Bear in mind that the female pin numbering is mirrored, so that pin 1 connects to pin 1 etc.

As for reading them, I've only written Blitz Basic code to read MD pads, so you'd probably want someone writing routines in ASM instead as that would be better suited to integrating into your slaves. But it's really not that involved. Detection is easy in theory because a normal D-pad or joystick can't have left and right pressed simultaneously, but on the Amiga there's a 25% chance a mouse will give the very same signal, so you couldn't rely on it.
Daedalus is offline  
Old 15 April 2020, 23:13   #22
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,303
blitz basic routine would be a good start if you can share it. And for the detection, one can cheat by assuming that a mouse isn't likely to be plugged in port 1, or this can be forced by a slave configuration. And that would only affect 2-player games.
jotd is online now  
Old 16 April 2020, 00:55   #23
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,369
Indeed, having it as a force option in configs would be good. I'll dig up some code for it tomorrow.
Daedalus is offline  
Old 17 April 2020, 23:33   #24
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,369
Okay, sorry about the delay, but instead of just posting code segments, I put together a quick and dirty executable. It's attached, along with Blitz source, and when run from the Shell, it will detect any MD pads attached and output any button or D-pad activity. I included 6-button reading and detecting code, but I've only tested it with a 3-button pad because I don't actually have a 6-button pad. In theory it should work anyway...

There's some extra stuff in there to make it a self contained executable. I originally included management of the potgo resource for multitasking friendliness, but with most games that's out the window so I took some of it out again for simplicity. This means though that it doesn't play nice with other hardware using pin 5 of the ports at the same time, such as scroll wheel mice or CD32 pads. It still tries to be sensible by restoring the status of the register when reading is completed.

The key routines are as follows:

The joydir{} function returns a byte where the low 4 bits represent the directions, up, down, left, right from LSB up. The port parameter tells it which game port to examine. It's pretty straightforward and reads the registers directly. Running it in-line with other code might be more efficient because you could drop all the shifting that neatens things up here, but this keeps the routine self-contained.

Code:
Function.b joydir{port.b}
  SHARED debug
  result.b = 0

  If port = 1
    bytes.w = Peek.w($DFF00C)
  Else
    bytes.w = Peek.w($DFF00A)
  End If

  bit9.w = bytes & %0000001000000000
  bit8.w = bytes & %0000000100000000
  bit1.w = bytes & %0000000000000010
  bit0.w = bytes & %0000000000000001

  result = result | (((bit9 LSR 1) EOR bit8) LSR 8) ; Up
  result = result | (bit1 LSL 2)                    ; Right
  result = result | (bit1 EOR (bit0 LSL 1))         ; Down
  result = result | (bit9 LSR 7)                    ; Left

  Function Return result
End Function
Next is the joybuttons{} function. This is similar to the routine above, but returns a byte where the first two bits correspond to button 1 (pin 6) and button 2 (pin 9) of the standard 2-button configuration on the specified port. However, contrary to the first functions, these bits directly represent the signal on those ports, so 0 means the button is pressed. Again, this is achieved reading the hardware directly, and could be streamlined. Between the two functions above, the raw reading of all controller signals can be done.

Code:
Function.b joybuttons{port.b}
  SHARED debug
  result.w = 0

  buttonbyte.b = Peek.b($BFE001)

  ; Button 1 / pin 6
  If port = 1
    result = (buttonbyte & %0000000010000000) LSR 7
  Else
    result = (buttonbyte & %0000000001000000) LSR 6
  End If

  ; Button 2 / pin 9
  bytes.w = (Peek.w($DFF016) LSR (9+(port*4)))
  result = result | (bytes & %0000000000000010)
  bytes.w = (Peek.w($DFF016) LSR (6+(port*4)))
  result = result | (bytes & %0000000000000100)

  Function Return result
End Function
Controller detection is done purely on the D-pad readings, which will have both left and right active when a Megadrive pad is connected. Furthermore, a 6-button pad also has up and down active when it's connected, but only for a certain cycle of the read pattern.

!delayloop{50} is a macro that inserts a simple delay loop that does the given number of reads from a CIA. This is because a certain amount of time (something like 200-300 microseconds) is needed after switching the pin 5 state before it takes effect, and CIA reads are a predictable time, unlike simply busy-looping on the CPU which is obviously CPU speed dependent. This appears to work fine and gives a safe, reliable delay on both an 030 and an 060, but there's probably scope for fine-tuning there.

The controller is cycled high and low until the third low cycle, which makes no difference to a 3-button pad's behaviour, but a 6-button pad will use to report all D-pad directions active on this cycle. You can then check if the bit pattern matches a 3-button of 6-button controller, bearing in mind that a mouse can also generate those pattern coincidentally.

Code:
For i.w = 0 To 1
  If controllers(i)\potalloc

    If i = 1
      potgoon.w  = %0010000000000000 ; Pin 5 low
      potgooff.w = %0011000000000000 ; Pin 5 high
    Else
      potgoon.w  = %0000001000000000
      potgooff.w = %0000001100000000
    End If

    Disable_
    savepotgo.w = Peek.w($DFF016)

    Poke.w $DFF034,potgoon
    !delayloop{50}

    Poke.w $DFF034,potgooff
    !delayloop{50}

    Poke.w $DFF034,potgoon
    !delayloop{50}

    Poke.w $DFF034,potgooff
    !delayloop{50}

    Poke.w $DFF034,potgoon
    !delayloop{50}

    dir = joydir{i}

    Poke.w $DFF034,potgooff
    !delayloop{50}

    Poke.w $DFF034,savepotgo
    Enable_
  End If

  If dir & %1100 = %1100 ;dpad\left <> 0 AND dpad\right <> 0
    NPrint "Megadrive controller detected on port ", i
    \mode = 1

    ; Now check for 6-button pad
    If dir = %1111 ;dpad\up <> 0 AND dpad\down <> 0
      NPrint "6-Button controller detected"
      \mode = 2
    Else
      NPrint "3-Button controller detected"
    End If
  End If
Next i

If controllers(0)\mode = 0 AND controllers(1)\mode = 0
  NPrint "No Megadrive controllers detected"
  End
End If
Now we have the meaty part for actually reading the buttons. As before, this function returns a byte that contains a bit pattern for each button in the order A, B, C, Start, Z, Y, X, Mode from the LSB. Again, this could be streamlined by not having to shift bits to make it a neat result, but it produces a tidy output from the routine.

The "standard buttons" are B and C, and can be read directly from the output of the joybuttons{} function. Pin 5 is set low then and joybuttons{} is used again to read A and Start before setting it high again (high should be the default resting state). Then, if a 6-button controller was detected, the pad is cycled low, high, low (the controller ID cycle) and high (the extra buttons cycle). When in this state, reading the D-pad instead reads the extra 4 buttons, with up corresponding to Z, down to Y, left to X and right to Mode. These 4 bits from joydir{} are simply added to the upper half of the results byte, so all 8 bits represent all 8 buttons.

Code:
Function.b readpad{port.b}
  SHARED allocmask, debug, controllers()
  result.b = 0

  If port = 1
    potgoon.w  = %0010000000000000
    potgooff.w = %0011000000000000
  Else
    potgoon.w  = %0000001000000000
    potgooff.w = %0000001100000000
  End If

  Disable_

  savepotgo.w = Peek.w($DFF016)

  ; Read standard buttons

  !delayloop{50}
  result=(joybuttons{port} & %0000000000000011) LSL 1
  Poke.w $DFF034,potgoon
  !delayloop{50}

  ; Read alternative buttons

  buts.w = joybuttons{port} & %0000000000000011
  result = result | ((buts & %0000000000000010) LSL 2) ; Start
  result = result | (buts & %0000000000000001) ; A

  Poke.w $DFF034,potgooff
  !delayloop{50}

  If controllers(port)\mode = 2 ; 6-button pad
    Poke.w $DFF034,potgoon
    !delayloop{50}
    Poke.w $DFF034,potgooff
    !delayloop{50}
    Poke.w $DFF034,potgoon ; Cycle 3 low
    !delayloop{50}
    Poke.w $DFF034,potgooff ; Cycle 3 high
    !delayloop{50}

    buts.w = joydir{port} LSL 4
    result = result | buts
  End If

  Poke.w $DFF034, savepotgo

  Function Return result
End Function
It's quick and dirty code, and I'm sure could be a lot more streamlined, especially in ASM, but I don't have the free time for getting into that unfortunately. I hope it helps though!
Attached Files
File Type: lha MDPadRead.lha (15.9 KB, 53 views)
Daedalus is offline  
Old 18 April 2020, 01:01   #25
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,303
That seems non-trivial. Asm conversion won't be a problem. Testing / detecting all joypads properly will take more time thanks, it helps.

(I'm currently fighting to make non-standard CD32 adapters work in some games)
jotd is online now  
Old 05 January 2023, 00:55   #26
Apollon
Registered User
 
Join Date: Nov 2017
Location: NRW/Germany
Posts: 31
Quote:
Originally Posted by Retro-Nerd View Post


2. Retrobit Sega Saturn pad, also the 2.4GHz version, which comes with an USB dongle too. The automatically mapped buttons fit better here. Just like with their Genesis/MD pad i assume.

unfortunately, the combination does not work for me. Which firmware version does the Rys MK2 adapter have?
Apollon is offline  
Old 05 January 2023, 07:40   #27
Retro-Nerd
Missile Command Champion
 
Retro-Nerd's Avatar
 
Join Date: Aug 2005
Location: Germany
Age: 52
Posts: 12,453
I don't know which version exactly. But have you tried to update?


https://retro.7-bit.pl/?lang=en&go=pomoc
Retro-Nerd is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sega Megadrive official 6 Button Pad on CD32/A1200?!? Ebster support.Hardware 60 28 December 2021 10:26
Wireless Controllers Washac support.OtherUAE 3 01 March 2012 22:21
FS: Sega Megadrive II with all leads/controllers + games Smiley MarketPlace 3 05 July 2011 00:54
Sega Saturn or Dreamcast for A1200 Memory or 030 Accelerator fitzsteve Swapshop 3 09 September 2009 14:07
Sega controllers? one1 support.Hardware 33 24 August 2007 15:43

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 20:08.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07853 seconds with 14 queries