6 button

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

Moderator: BigEvilCorporation

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri Nov 19, 2010 11:52 pm

I quickly set up a project on google code : http://code.google.com/p/sgdk/
For now it contains nothing except the dev kit archive.
I'll complete it with time, adding docs, tutorials etc... :)
As you'll see Kaneda i used and included some of your nice tools in the devkit :)
Some stuff changed since the v4 and i guess you'll experience some troubles to compile your projects, don't hesitate to request some help !
The logo is now activable / desactivable from the config.h file (i need to remove the "flemteam" stuff :p)

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

Post by Chilly Willy » Sat Nov 20, 2010 1:47 am

Stef wrote:
Chilly Willy wrote:
KanedaFr wrote: The only bug I found is about gas... it seems it handles wrongly the xxxi instructions :
Chilly willy's code for ex, doesn't work as is since he used andi, cmpi
I had to use cmp and not cmpi because %d0 was overwritten (?!)
perhaps I did something wrong (but I doubt since cmp worked) but it would be great if you could check this.
That says to me the version of gcc in the devkit needs to be updated. You shouldn't work around bugs like that when newer versions without the bugs are available.
Devkit uses GCC 3.4.6 but i've version 4.1.1 sitting somewhere, i never encountered this bug with 3.4.6 though... need to test more asm :p
Oh, so I guess KanedaFr wasn't using your gcc either. 3.4.6 isn't too bad. Maybe include a newer version in addition as some older stuff doesn't like the 4.x without some changes, and vice versa.

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

Post by KanedaFr » Sun Nov 21, 2010 9:24 am

Chilly Willy wrote: Oh, so I guess KanedaFr wasn't using your gcc either. 3.4.6 isn't too bad. Maybe include a newer version in addition as some older stuff doesn't like the 4.x without some changes, and vice versa.
I used gcc coming with GDK0.4

Very easy to test : use ChillyWilly joy6 code, you'll see it doesn't work with cmp.i and add.i

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

Post by KanedaFr » Sun Nov 21, 2010 9:25 am

Stef wrote:I quickly set up a project on google code : http://code.google.com/p/sgdk/
For now it contains nothing except the dev kit archive.
I'll complete it with time, adding docs, tutorials etc... :)
As you'll see Kaneda i used and included some of your nice tools in the devkit :)
Some stuff changed since the v4 and i guess you'll experience some troubles to compile your projects, don't hesitate to request some help !
The logo is now activable / desactivable from the config.h file (i need to remove the "flemteam" stuff :p)
great!
I will test it this week !

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

Post by Mixail » Mon Nov 22, 2010 4:00 pm

So it is correct?

Code: Select all

.globl get_pad
get_pad:
        bsr   get_input      
        move.w  %d0, %d1
        andi.w  #0x0C00, %d0
        bne.b   no_pad
        bsr   get_input      
        bsr   get_input       
        move.w  %d0, %d2
        bsr   get_input       
        and.w  #0x0F00, %d0     
        cmp.w  #0x0F00, %d0
        beq.b   common          
        move.w  #0x010F, %d2       
common:
        lsl.b   #4, %d2           
        lsl.w   #4, %d2           
        and.w  #0x303F, %d1      
        move.b  %d1, %d2           
        lsr.w   #6, %d1           
        or.w    %d1, %d2           
        eori.w  #0x1FFF, %d2      
        rts

no_pad:
        move.w  #0xF000, %d2
        rts
        
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 
change eori by eor?

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

Post by Chilly Willy » Mon Nov 22, 2010 7:06 pm

You missed the first andi and an eori toward the end.

Also, if you wish to also support Master System pads with the same routine, change the no_pad code to this:

Code: Select all

| 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
If you use that with that old compiler, be sure to change the imm opcodes in it too.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Nov 22, 2010 7:16 pm

KanedaFr wrote: I used gcc coming with GDK0.4

Very easy to test : use ChillyWilly joy6 code, you'll see it doesn't work with cmp.i and add.i
At least addi and cmpi seems to work in my code.
I didn't tested with the exact same portion of code though, really weird bug :-/

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

Post by Mixail » Tue Nov 23, 2010 8:24 pm

This error
Image

My code:
ASM

Code: Select all

.globl get_pad
get_pad:
        bsr   get_input      
        move.w  %d0, %d1
        and.w  #0x0C00, %d0
        bne.b   no_pad
        bsr   get_input      
        bsr   get_input       
        move.w  %d0, %d2
        bsr   get_input       
        and.w  #0x0F00, %d0     
        cmp.w  #0x0F00, %d0
        beq.b   common          
        move.w  #0x010F, %d2       
common:
        lsl.b   #4, %d2           
        lsl.w   #4, %d2           
        and.w  #0x303F, %d1      
        move.b  %d1, %d2           
        lsr.w   #6, %d1           
        or.w    %d1, %d2           
        eor.w  #0x1FFF, %d2      
        rts

no_pad:
        lea     0xA10003,a0
        move.b  (a0),d0         
        and.w  #0x003F,d0      
        eor.w  #0x003F,d0      
        move.l  (sp)+,d2
        rts 
        
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 
C code:

Code: Select all

#include <genesis.h>



extern u32 get_pad ();







int main() {



	u32 pad1 = get_pad (0xA10003);
   
    
    VDP_init();
   
	VDP_drawText(APLAN, "----------------------------------------", 0, 0, 25);
    
    for (;;) {

	if (pad1 & BUTTON_Z){
      
VDP_drawText(APLAN, "-----------------ZZZ--------------------", 0, 0, 14);} 
       
        //VDP_waitVSync();

    }


    return 0;
}
What to do?

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

Post by Chilly Willy » Tue Nov 23, 2010 9:17 pm

The line in main.c should be

Code: Select all

extern unsigned short int get_pad(int pad);
The error is because wherever get_pad() is, it's not in the linker line (or not in the correct place in the line - the object file containing get_pad() needs to be after main.o).

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

Post by Mixail » Fri Nov 26, 2010 8:24 pm

http://zalil.ru/30033285
Why it doesn't work? Deduces the black screen.

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

Post by Chilly Willy » Sat Nov 27, 2010 5:29 am

First, pad is the pad number, not an address... valid values are 0 and 1.

Second, you then don't fetch the pad number from the stack, nor save a register that needs saving.

Here's get_pad() written to be called from C

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)
        .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

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

Post by Mixail » Sat Nov 27, 2010 7:25 pm

Thanks for the code.
But how to force to work a joy stick in main?

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

Post by Chilly Willy » Sat Nov 27, 2010 7:31 pm

Assuming the code in the last post compiles (it has those imm i's again), it will work from main() as it's the exact code I use, which is called from C.

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

Post by Mixail » Sun Nov 28, 2010 7:08 am

Code: Select all

#include <genesis.h>



extern unsigned short int get_pad(int pad);







int main() {



	u32 pad1 = get_pad (0xA10003);
   
    
    VDP_init();
   
	VDP_drawText(APLAN, "----------------------------------------", 0, 0, 25);
    
    for (;;) {

	if (pad1 & 0x0400){//button Z
      
VDP_drawText(APLAN, "-----------------ZZZ--------------------", 0, 0, 14); 
       
        //VDP_waitVSync();

    }


    return 0;
}
How to interrogate the controler?

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

Post by KanedaFr » Sun Nov 28, 2010 9:57 am

I think you misunderstood one thing : get_pad doesn't return a pointer to a pad but the pad's buttons status.

So, you need to call get_pad on your for loop and keep the wait_vsync!

Code: Select all

int main() { 
   u32 pad1;

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

   return 0; 
} 
even better, I suggest you to call this on a vblank handler

Post Reply