Shop OBEX P1 Docs P2 Docs Learn Events
genesis 6 button controller — Parallax Forums

genesis 6 button controller

yllawwallyyllawwally Posts: 23
edited 2009-12-31 16:39 in General Discussion
Does anyone have code for interfacing with all the buttons on a sega 6 button? Accessing the abc and directional buttons is simple. However the xyz buttons use a different approach.

Comments

  • yllawwallyyllawwally Posts: 23
    edited 2009-12-04 20:31
    Here is the code, I stripped out everything but the code to test for buttons x,y, and z.
    Attached is a description of the interface for 6 button sega controllers, in text format.





    
    ;-------------------------- DEVICE DIRECTIVES --------------------------
    
            DEVICE        SX28,OSC4MHZ,TURBO
    
    IFDEF    __SASM  ;SASM Directives
            DEVICE        STACKX,OPTIONX
            IRC_CAL        IRC_SLOW
            
    ELSE        ;Parallax Assember Directives
            DEVICE        STACKX_OPTIONX
    ENDIF
    
            RESET        Initialize
    
    ;---------------------------- DEBUG SETTINGS ---------------------------
    
            FREQ    4_000_000
        
    ;------------------------ INITIALIZATION ROUTINE -----------------------
    
    
    Initialize
    
    
    
    
            ;Port Direction Configuration at 4mhz each clock is 4.25u sec
            Timer    = $10
            GenXYZ    EQU    24
            Joystick_Mid    equ    $0E    ;XXX,XXX,XXX,XXX,XXX,X,Y,Z
            Joystick_Low    equ    $0D    ;XXX,C Button,XXX,B Button,Right,Left,Down,Up
            Joystick_High    equ    $0F    ;XXX,XXX,XXX,A Button,B Button, X Button, Y Button, Z Button
            Joystick_M_wip  equ    $1E    
            Joystick_L_wip  equ    $1D    
            Joystick_H_wip  equ    $1F
            mov    W,#$1F            ;Allow Direction configuration
            mov    M,W
            mov    !rb,#%11111111        ;Set port B bits 0-7 to input
            mov    !ra,#%00000000        ;Set port A bits 0-7 output bit 0 is select
            mov    !rc,#%00000000        ;Set port C bits 0-7 output
            clrb    ra.0            ;turn select off
    
    
    ;------------------------
    Pause MACRO
            mov    Timer, #18 ;1 cycle
    
    :Loop
            decsz     Timer  ;2 cycles or 4 cycles
            jmp    :Loop   ;3 cycles
    ENDM
    ;------------------------
    
    bp0            
    
    
            pause  
    
    
    
            setb    ra.0        ;turn select off, setting voltage to 5
    
    
            pause  
    
    
    
            clrb    ra.0        ;turn select on, setting voltage to 0
    
            nop
    
    
    
            setb    ra.0        ;turn select off, setting voltage to 5
    
            nop
    
    
    
            clrb    ra.0        ;turn select on, setting voltage to 0
    
            nop
    
    
    
    
            setb    ra.0        ;turn select off, setting voltage to 5
    
            nop
    
    
    
    
            clrb    ra.0        ;turn select on, setting voltage to 0
    
    
            nop
    
    
    
    
    ;------------------- should be select on data now
    
            mov     w, rb
            mov     Joystick_Mid, w
    
    
            jnb    rb.0, light    ;check first bit, which should be button z
            jmp    nolight
    light:        clrb    rc.6    ;turn off led
            jmp     bp0
    nolight:    setb    rc.6    ;turn on led
    
    
            setb    ra.0        ;turn select off, setting voltage to 5
    
            nop
    
    
    
    
            clrb    ra.0        ;turn select on, setting voltage to 0
    
    
            nop
    
            jmp     bp0
    ;-----------------------------
    
    ;---------------------------- MAIN PROGRAM -----------------------------
    
    Main        
            jmp    bp0
    
    
  • PJMontyPJMonty Posts: 983
    edited 2009-12-22 18:33
    yllawwally,

    I did a Google search using the following terms...

    sega 6 button controller interface

    ...and found this:

    www.ecgf.uakron.edu/grover/web/ee263/labs/Parts/Sega%20Six%20Button%20Controller%20Hardware%20Info.pdf

    It's a PDF file 1996 called "Sega Six-Button Controller Hardware Info."

    It explains how to read not only the ABC buttons, but also the XYZ.

    I know absolutely nothing about this controller and found this information in under a minute using Google.

    Thanks,
    PeterM
  • yllawwallyyllawwally Posts: 23
    edited 2009-12-23 21:20
    I got that one and a couple of others. Actually I attached the text version of that document with my code in my previous post. The document seems to call it pulse 3, but it seems to be on the 4th pulse when you should look for XYZ. The last pulse held high I believe, while you read the buttons. I have the code set to light up, when I get a z, however it actually lights when I get an up. Looking at the pdf again, I added another toggle of the select line, and left it high, however it did not seem to make a difference. I changed the code to display the LED when the A button is held, and then also for the B button, which shows me I'm controlling the select properly. I'm running with the internal clock set to 4MHz. It seems it must be my timing that is off,below is the code I'm trying to use now.

    bp0            
    
            pause  ;93
            setb    ra.0        ;turn select off, setting voltage to 5
    
            pause  ;93
            clrb    ra.0        ;turn select on, setting voltage to 0
            nop    ;1
            nop    ;1
            nop    ;1
    
            setb    ra.0        ;turn select off, setting voltage to 5
            nop    ;1
            nop    ;1
            nop    ;1
    
            clrb    ra.0        ;turn select on, setting voltage to 0
            nop    ;1
            nop    ;1
            nop    ;1
    
            setb    ra.0        ;turn select off, setting voltage to 5
            nop    ;1
            nop    ;1
            nop    ;1
    
    
            clrb    ra.0        ;turn select on, setting voltage to 0
            nop    ;1
            nop    ;1
            nop    ;1
    
            setb    ra.0        ;turn select off, setting voltage to 5
            nop    ;1
            nop    ;1
            nop    ;1
    
            clrb    ra.0        ;turn select on, setting voltage to 0
            nop    ;1
            nop    ;1
            nop    ;1
    
            setb    ra.0        ;turn select off, setting voltage to 5
            nop    ;1
            nop    ;1
            nop    ;1
    
    ;------------------- should be select on data now
    
    ;        mov     w, rb
    ;        mov     Joystick_Mid, w
    
    
            jnb    rb.0, light    ;check first bit, which should be button z
            jmp    nolight
    light:        clrb    rc.6    ;turn off led
            jmp     bp0
    nolight:    setb    rc.6    ;turn on led
    
    
            jmp     bp0
    
  • yllawwallyyllawwally Posts: 23
    edited 2009-12-31 16:39
    OK finally got it working. There were two problems. The first is that I needed to wait at least 20,000 cycles between reads of the xyz buttons. I was trying to read them too quickly, and results were getting reset. It appears about 200 Hz is the fastest rate to sample the xyz buttons. Secondly, the documentation I found was incorrect in some places. Pulse 3, meant read XYZ on the third pulse, however there are two different timing diagrams in the document one shows read on third pulse, and the other showed read on fourth pulse. Below is the working code, in case anyone is interested.

    ;=======================================================================
    ; reads the all genesis buttons, and will turn a light on if x and z are pressed
    ;=======================================================================
    
    
    ;-------------------------- DEVICE DIRECTIVES --------------------------
    
            DEVICE        SX28,OSC4MHZ,TURBO
    
    IFDEF    __SASM  ;SASM Directives
            DEVICE        STACKX,OPTIONX
            IRC_CAL        IRC_SLOW
            
    ELSE        ;Parallax Assember Directives
            DEVICE        STACKX_OPTIONX
    ENDIF
    
            RESET        Initialize
    
    ;---------------------------- DEBUG SETTINGS ---------------------------
    
            FREQ    4_000_000
        
    ;------------------------ INITIALIZATION ROUTINE -----------------------
    
    
    Initialize
    
    
    
    
            ;Port Direction Configuration at 4mhz each clock is 4.25u sec
            Timer    = $10
            GenXYZ    EQU    24
            Joystick_Mid    equ    $0E    ;XXX,XXX,XXX,XXX,XXX,X,Y,Z
            Joystick_Low    equ    $0D    ;XXX,C Button,XXX,B Button,Right,Left,Down,Up
            Joystick_High    equ    $0F    ;XXX,XXX,XXX,A Button,B Button, X Button, Y Button, Z Button
            Joystick_M_wip  equ    $1E    
            Joystick_L_wip  equ    $1D    
            Joystick_H_wip  equ    $1F
            mov    W,#$1F            ;Allow Direction configuration
            mov    M,W
            mov    !rb,#%11111111        ;Set port B bits 0-7 to input
            mov    !ra,#%00000000        ;Set port A bits 0-7 output bit 0 is select
            mov    !rc,#%00000000        ;Set port C bits 0-7 output
            clrb    ra.0            ;turn select off
    
    
    ;------------------------ Start Pause
    Pause MACRO    
            mov    Timer, #10 ;1 cycle
    
    :Loop
            decsz     Timer  ;2 cycles or 4 cycles
            jmp    :Loop   ;3 cycles
    ENDM
    ;------------------------ End Pause
    
    ;------------------------ Start LongPause
    LongPause MACRO
            mov    Timer, #254 ;1 cycle
    
    :Loop
            decsz     Timer  ;2 cycles or 4 cycles
            jmp    :Loop   ;3 cycles
    ENDM
    ;------------------------ End LongPause
    
    ;------------------------ Start ReadJoystick
    ReadJoystick MACRO
    
            clrb    ra.0        ;turn select on, setting voltage to 0
            nop    ;1
            pause    ;~52
    
    
            setb    ra.0        ;turn select off, setting voltage to 5
            nop    ;1
            pause    ;~52
    
    
            clrb    ra.0        ;turn select on, setting voltage to 0
            nop    ;1
            pause    ;~52
    
    
            setb    ra.0        ;turn select off, setting voltage to 5
            nop    ;1
            pause    ;~52
    
    
            clrb    ra.0        ;turn select on, setting voltage to 0
            nop    ;1
            pause    ;~52
    
    
            setb    ra.0        ;turn select off, setting voltage to 5
    
    ;------------------- XYZ data is now available
    
            mov     w, rb
            mov     Joystick_Mid, w
    ENDM
    ;------------------------End ReadJoystick
    
    
    bp0    ;Main Joystick Read        
    
            ReadJoystick
    
            jnb    rb.0, light    ;check first bit, which should be button z
            jmp    nolight
    light:        clrb    rc.6    ;turn off led
            jnb    rb.2, light2
            jmp     nolight
    light2:
            jmp     dostuff
    nolight:    setb    rc.6    ;turn on led
    
    dostuff:    ;need to wait at least 20,000 cycles at 4Mhz before you attempt to read controller again 200 controller reads per sec max
            longpause    ;~2400
            longpause    ;~2400
            longpause    ;~2400
            longpause    ;~2400
            longpause    ;~2400
            longpause    ;~2400
            longpause    ;~2400
            longpause    ;~2400
    
    
    
            jmp     bp0
    ;-----------------------------
    
    ;---------------------------- MAIN PROGRAM -----------------------------
    
    Main        
            jmp    bp0
    
    
Sign In or Register to comment.