6 button

For anything related to IO (joypad, serial, XE...)

Moderator: BigEvilCorporation

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Sun Nov 28, 2010 7:00 pm

KanedaFr It is possible more in detail about it?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Nov 29, 2010 12:48 am

Except that you forgot the input again...

Code: Select all

     pad1 = get_pad (0); 
or

Code: Select all

     pad2 = get_pad (1); 
The comments in the assembly tell you which bits stand for which button, and the bit is set when the button is pressed. If you like the bit clear for when the button is pressed, you would need to remove the eor from the end of the function.

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Mon Nov 29, 2010 5:03 pm

When I write

Code: Select all

 pad1 = get_pad (0);
The screen starts to flicker. What buttons are read out.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Nov 29, 2010 7:33 pm

Mixail wrote:When I write

Code: Select all

 pad1 = get_pad (0);
The screen starts to flicker. What buttons are read out.
Sigh :roll:

From the code I pasted in the previos page

Code: Select all

| buttons = get_pad(pad)
| entry: arg = pad control port
| exit:  d0 = pad value (0 0 0 1 M X Y Z S A C B R L D U) or (0 0 0 0 0 0 0 0 S A C B R L D U)
That's binary... each letter is a bit that is set for a pressed button... as I already mentioned.

The C defines I use in main.c are

Code: Select all

#define SEGA_CTRL_BUTTONS   0x0FFF
#define SEGA_CTRL_UP        0x0001
#define SEGA_CTRL_DOWN      0x0002
#define SEGA_CTRL_LEFT      0x0004
#define SEGA_CTRL_RIGHT     0x0008
#define SEGA_CTRL_B         0x0010
#define SEGA_CTRL_C         0x0020
#define SEGA_CTRL_A         0x0040
#define SEGA_CTRL_START     0x0080
#define SEGA_CTRL_Z         0x0100
#define SEGA_CTRL_Y         0x0200
#define SEGA_CTRL_X         0x0400
#define SEGA_CTRL_MODE      0x0800

#define SEGA_CTRL_TYPE      0xF000
#define SEGA_CTRL_THREE     0x0000
#define SEGA_CTRL_SIX       0x1000
#define SEGA_CTRL_NONE      0xF000

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Mon Nov 29, 2010 8:40 pm

main

Code: Select all

#include <genesis.h>

extern unsigned short int get_pad(int pad);

int main() {
   u32 pad1;

   VDP_init();
   VDP_drawText(APLAN, "----------------------------------------", 0, 0, 25);
   
   for (;;) {
     pad1 = get_pad (0);
     if (pad1 & 0x0100){//button Z
       VDP_drawText(APLAN, "-----------------ZZZ--------------------", 0, 0, 14);
     }
     VDP_waitVSync();
   }

   return 0;
}
asm

Code: Select all

.global get_pad
get_pad:
        move.l  %d2,-(%sp)
        move.l  8(%sp),%d0        /* first arg is pad number */
        cmpi.w  #1,%d0
        bhi     no_pad
        add.w   %d0,%d0
        addi.l  #0xA10003,%d0    /* pad control register */
        movea.l %d0,%a0
        bsr.b   get_input       /* - 0 s a 0 0 d u - 1 c b r l d u */
        move.w  %d0,%d1
        andi.w  #0x0C00,%d0
        bne.b   no_pad
        bsr.b   get_input       /* - 0 s a 0 0 d u - 1 c b r l d u */
        bsr.b   get_input       /* - 0 s a 0 0 0 0 - 1 c b m x y z */
        move.w  %d0,%d2
        bsr.b   get_input       /* - 0 s a 1 1 1 1 - 1 c b r l d u */
        andi.w  #0x0F00,%d0      /* 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 */
        cmpi.w  #0x0F00,%d0
        beq.b   common          /* six button pad */
        move.w  #0x010F,%d2      /* three button pad */
common:
        lsl.b   #4,%d2           /* - 0 s a 0 0 0 0 m x y z 0 0 0 0 */
        lsl.w   #4,%d2           /* 0 0 0 0 m x y z 0 0 0 0 0 0 0 0 */
        andi.w  #0x303F,%d1      /* 0 0 s a 0 0 0 0 0 0 c b r l d u */
        move.b  %d1,%d2           /* 0 0 0 0 m x y z 0 0 c b r l d u */
        lsr.w   #6,%d1           /* 0 0 0 0 0 0 0 0 s a 0 0 0 0 0 0 */
        or.w    %d1,%d2           /* 0 0 0 0 m x y z s a c b r l d u */
        eori.w  #0x1FFF,%d2      /* 0 0 0 1 M X Y Z S A C B R L D U */
        move.w  %d2,%d0
        move.l  (%sp)+,%d2
        rts

| no pad found, so we're going to ASSUME an SMS (compatible) pad
no_pad:
        lea     0xA10003,%a0
        move.b  (%a0),%d0         /* - 1 c b r l d u */
        andi.w  #0x003F,%d0      /* 0 0 0 0 0 0 0 0 0 0 c b r l d u */
        eori.w  #0x003F,%d0      /* 0 0 0 0 0 0 0 0 0 0 C B R L D U */
        move.l  (%sp)+,%d2
        rts

| read single phase from controller
get_input:
        move.b  #0x00,(%a0)
        nop
        nop
        move.b  (%a0),%d0
        move.b  #0x40,(%a0)
        lsl.w   #8,%d0
        move.b  (%a0),%d0
        rts 
Why it blinks?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Nov 29, 2010 8:45 pm

Because you're drawing directly to the visible display. Depending on how and when you do so, the display may "blink" or tear.

KanedaFr
Administrateur
Posts: 1150
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Nov 30, 2010 9:08 am

Mixail wrote:Why it blinks?
Where do you test your code ?
I don't see blink on Gens nor Fusion...

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Tue Nov 30, 2010 3:33 pm

compiler GenesisDev04
Emulations Fusion 3.51

KanedaFr
Administrateur
Posts: 1150
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Nov 30, 2010 3:50 pm

well...
no blink using GenesisDev06b
Fusion 3.6 / Kmod 0.7c / Regen 0.97D

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Tue Nov 30, 2010 4:09 pm

KanedaFr wrote:well...
no blink using GenesisDev06b
Fusion 3.6 / Kmod 0.7c / Regen 0.97D
Where it to download?

KanedaFr
Administrateur
Posts: 1150
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Nov 30, 2010 4:36 pm

which one ?

Genesis Dev 06b (and now 06c) at viewtopic.php?p=12146#12146

Fusion : google

KMod:
http://gendev.spritesmind.net/page-gensK.html

Regen:
viewforum.php?f=15

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Nov 30, 2010 7:16 pm

I prefer using Gens/GS: http://segaretro.org/Gens/GS

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Sat Dec 04, 2010 8:45 am

On version compiler 0.6. - flickers.

You can give me the source code 6 Buttons.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat Dec 04, 2010 6:15 pm

The source is right here: viewtopic.php?p=12154#12154

You aren't paying much attention to what we are saying in the thread. It's hard to help if you don't listen.

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Wed Dec 08, 2010 6:03 pm

You can give me the source code function main.

Post Reply