English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 31 March 2020, 16:48   #1
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,162
reading CD32 buttons / detecting joystick type (and banging my head)

I thought I understood everything about this, but nooooo.

I can detect if a controller is a joypad or joystick/mouse with this code

Code:
    lea    (_ciaa),a4
    lea    (_custom),a5
; port 1
    moveq    #CIAB_GAMEPORT1,d3    ; 1rst button (red)
    moveq    #14,d4            ; 2nd button (blue)
    move.w    #$6F00,d5

    btst    d3,(a4)
    bne.b    .no_red_button
    bset    #JPB_BUTTON_RED,d0    ; fire/lmb
.no_red_button

    ; this is the joypad specific part
    ; we set bits from 16 to 0, retrieving the data from serially sent info
    bset    d3,(ciaddra,a4)
    bclr    d3,(a4)
    move.w    d5,(potgo,a5)        ; a5=$DFF034
    moveq    #10-1,d1    ; was done 24 times, not needed

    bra.b    .lbC000746    ; removed: shaving timer issue too close
                        ; 2017: reinstated (identical as Wepl timing fix)

.button_loop
    tst.b    (a4)
    tst.b    (a4)
.lbC000746
    tst.b    (a4)
    tst.b    (a4)
    tst.b    (a4)
    tst.b    (a4)
    tst.b    (a4)
    tst.b    (a4)
    move.w    (potinp,a5),d2        ; a5=$DFF016
    bset    d3,(a4)
    bclr    d3,(a4)
    btst    d4,d2
    bne.b    .lbC00077C
    bset    d1,d6
.lbC00077C
    dbra    d1,.button_loop
    ; all buttons have been read, reset data direction register

    bclr    d3,(ciaddra,a4)

    ; acknowledge port input


    move.w    #$FF00,(potgo,a5)    ; a5=$DFF034    ; correct value according to robinsonb5@eab

        
    move.b  d6,d3
    and.w   #$3,d3

in the end, if d3 == 3 then it's a CD32 joypad, else it's either a mouse or a joystick (and if you shift d6 by 14 bits left you get the button readings with matching lowlevel.i bits)

This works pretty well (used in most of my whdload slaves using joypad controls). Note that this discards the actual button inputs.

Now there's a catch: if I want to READ buttons and detect controller type at the same time, I hit a wall.

When a non-cd32 joypad is connected and no button is pressed, the routine detects it (d3 == 0). But as soon as I press the 2nd/blue button, the routine thinks that it's a CD32 joypad again... And with a joystick/mouse, the blue button is seen as pressed, even if not pressed.

In my whdload slaves, my technique works because noone presses 2nd button when slave starts... and when the game reads the buttons, it already knows which controller type is plugged in (not dynamic). I tend to detect controller type at startup, or when game menu pops up. Not during the game.

Now I want to do the same thing dynamically (emulating lowlevel ReadJoyPort.s). And I hit a wall ...

Last edited by jotd; 31 March 2020 at 16:54.
jotd is offline  
Old 31 March 2020, 20:46   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Last 2 bits (bits 7 and 8) from CD32 pad should be zero followed by one (or was it one followed by zero?) and current button state does not affect them. So if all received bits are all zero or all one: it can't be a CD32 pad.
Toni Wilen is offline  
Old 03 April 2020, 13:44   #3
Angus
Amiga Games Database
 
Angus's Avatar
 
Join Date: Jun 2006
Location: South West England
Posts: 1,240
From a completely non-technical perspective..... I believe some 1200s will detect the CD32 joypad fine, but mine didn't. When I bought AB3D, it just saw it as a joystick and would not let me use the shoulder pads to straff. Some others had no problem doing this (different revision?) I mentioned it to John Girvin and he came up with a little patch that fixed the problem.
Angus is offline  
Old 03 April 2020, 16:07   #4
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,162
I remember that some A1200s motherboards have issues with CD32 readings if not done properly. Some CD32 reading routines don't respect the exact specs (timings).

Believe me I've spent hours and hours and tons of posts to ask for help here (with 95% chance that Toni replies), now I know how to read the ports
jotd is offline  
Old 03 April 2020, 18:18   #5
Angus
Amiga Games Database
 
Angus's Avatar
 
Join Date: Jun 2006
Location: South West England
Posts: 1,240
I believe you, Sir! ;-)
Angus 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
Is there a guide to remapping joystick buttons? Photon support.WinUAE 10 05 September 2019 19:17
Joystick Buttons Lazycow Coders. Asm / Hardware 4 12 June 2016 15:25
cannot change joystick buttons fil support.WinUAE 3 19 August 2011 20:20
Music app with a guy banging his head semt-x request.Apps 5 08 June 2011 23:11
Joystick Buttons Echo Retrogaming General Discussion 19 29 January 2003 19:42

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 23:22.

Top

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