Sega Genesis Dev Kit (SGDK)

SGDK only sub forum

Moderator: Stef

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

Post by Chilly Willy »

KanedaFr wrote:little bug on the joy support :
readJoypad return joy state and type
unfortunatly type is also used when it calls joyEventCB
so change is not 0 when released but type << 12 ...
I would prefer to keep the initial mode : 0 for release, button for press
The "backwards compatibility" has its limits... for controllers, there is now a mask you should use for just the buttons - use (val & BUTTON_ALL) instead of plain old (val). If you force the support for pads to three button pad mode (for example, JOY_setSupport(PORT_1, JOY_SUPPORT_3BTN); ), then you'll have complete backwards compatibility since the TYPE for 3 button pads is 0.
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Well that is not a big deal anyway, i separated type and state because i think it is less confusing this way too :)

Now we have :

Code: Select all

u8 JOY_getJoypadType(u16 joy);
which return type for the specified joypad and the readJoypadState(..) does not return anymore joypad type in high nibble.
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

I assume you changed the example, too, right? :D
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

yep :)
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch »

I'm seeing what looks like to be a bug with fastMemsetU16.

Code: Select all


#define MAX_COINS_IN_LEVEL 256
u16 coinMap[MAX_COINS_IN_LEVEL];

fastMemsetU16((u16*)coinMap, 1, MAX_COINS_IN_LEVEL);

PrintNumber(coinMap[0]); // helper printing function 
PrintNumber(coinMap[1]);
PrintNumber(coinMap[2]);

Output (values are in hexidecimal):

Code: Select all

Message : 00000001 
Message : 00000101
Message : 00000101


switching to memsetU16 gives the correct output:

Code: Select all

Message : 00000001
Message : 00000001
Message : 00000001
I kept wondering why my coins were all screwed up :)

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

Post by Chilly Willy »

Change line 347 of memory.c from

Code: Select all

    value32 = cnv_8to32_tab[value];
to

Code: Select all

    asm("move.w %0,%1\n\t"
        "swap %1\n\t"
        "move.w %0,%1\n"
        : "=d" (value),  "=d" (value32) : : "cc" );
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch »

Tried it out and now it's giving me:

Code: Select all

Message : 00000001 
Message : 00000000 
Message : 00000000 
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

A first word can be written by itself for odd word addresses, then it tries writing longs. So it seems like the asm isn't working... okay, try this:

Code: Select all

    asm("move.w %1,%0\n\t"
        "swap %0\n\t"
        "move.w %1,%0\n"
        : "=d" (value32) : "=d" (value) : "cc" );
Had value as an output register, which was probably the problem.
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch »

That doesn't compile.

/sgdk092/src/memory.c:356: error: input operand constraint contains `='
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

djcouchycouch wrote:That doesn't compile.

/sgdk092/src/memory.c:356: error: input operand constraint contains `='
Get rid of the second =... just use "d" (value). The = is for indicating write access, if I remember correctly.
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch »

That seems to work. Thanks!
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

djcouchycouch wrote:That seems to work. Thanks!
No problem. Glad it finally worked out. Pulling inline assembly off the top of my head is fun, but takes a little debugging. I always forget which field is inputs and which are the outputs... things like that.
:lol:
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Very stupid bug, to keep all C you just need to change the

Code: Select all

value32 = cnv_8to32_tab[value];

by

Code: Select all

value32 = (value << 16) | value;


but asm part is faster as you can use the swap instruction.
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

Stef wrote:Very stupid bug, to keep all C you just need to change the

Code: Select all

value32 = cnv_8to32_tab[value];

by

Code: Select all

value32 = (value << 16) | value;


but asm part is faster as you can use the swap instruction.
I was fairly certain << 16 wasn't going to use swap, which is why I recommended the asm. If it didn't use swap, it wouldn't be "fast" at that point, and it was supposed to be the fast version of the routine.
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Chilly Willy wrote: I was fairly certain << 16 wasn't going to use swap, which is why I recommended the asm. If it didn't use swap, it wouldn't be "fast" at that point, and it was supposed to be the fast version of the routine.
Hehe is was sure that it wouldn't too but in fact it does use the swap instruction ! But the rest of the code is really not the best we can do so i finally rewrote all these methods in pure asm.
I made fastxxx deprecated as now the normal memset and memcpy methods use fast asm code now :)
Last edited by Stef on Mon Sep 24, 2012 2:14 pm, edited 1 time in total.
Post Reply